Skip to content

transmute_unchecked contracts and harnesses - #185

Merged
feliperodri merged 11 commits into
model-checking:mainfrom
AlexLB99:transmute_unchecked
Feb 4, 2025
Merged

feliperodri merged 11 commits into
model-checking:mainfrom
AlexLB99:transmute_unchecked

Conversation

@AlexLB99

@AlexLB99 AlexLB99 commented Nov 25, 2024 •

Copy link
Copy Markdown

This is a pull request towards solving #19.

Changes

  • Added wrappers for transmute_unchecked()
  • Annotated these wrappers with contracts
  • Wrote harnesses that verify these wrappers

Note: the reason we write wrappers for transmute_unchecked() and we annotate those wrappers is that function contracts do not appear to be currently supported for compiler intrinsics (as discussed in #3345). Also, rather than using a single wrapper for transmute_unchecked(), we write several with different constraints on the input (since leaving the function parameters completely generic severely restricts what we can do in the contracts, e.g., testing for equality).

This is not intended to be a complete solution for verifying transmute_unchecked(), but instead a proof of concept to see how aligned this is with the expected solution. Any feedback would be greatly appreciated -- thank you!

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@patricklam

Copy link
Copy Markdown

hi @celinval and @feliperodri! Thoughts most welcome.

@AlexLB99 AlexLB99 changed the title Transmute unchecked transmute_unchecked contracts and harnesses Nov 27, 2024
@tautschnig

Copy link
Copy Markdown
Member

Can the CI failures please be addressed?

@patricklam

Copy link
Copy Markdown

I guess that we can't trigger the workflow @tautschnig

@tautschnig

Copy link
Copy Markdown
Member

You might unintentionally have reverted submodule changes?

@AlexLB99 AlexLB99 closed this Dec 2, 2024
@AlexLB99
AlexLB99 force-pushed the transmute_unchecked branch from b163ae0 to 7e8a03d Compare December 2, 2024 19:56
@AlexLB99 AlexLB99 reopened this Dec 2, 2024
@patricklam

Copy link
Copy Markdown

Is it supposed to say "this workflow requires approval from a maintainer"?

@AlexLB99

AlexLB99 commented Dec 2, 2024

Copy link
Copy Markdown
Author

You might unintentionally have reverted submodule changes?

I believe the issue may have been a merge conflict caused by a recent upstream commit that moved intrinsic.rs (which is the file being modified here) to another location. I think in theory the problem should be fixed now @tautschnig

@tautschnig

Copy link
Copy Markdown
Member

Is it supposed to say "this workflow requires approval from a maintainer"?

Yes, we have opted for those rules out of caution.

@tautschnig

Copy link
Copy Markdown
Member

You might unintentionally have reverted submodule changes?

It looks like those are still present.

@AlexLB99

AlexLB99 commented Dec 3, 2024

Copy link
Copy Markdown
Author

You might unintentionally have reverted submodule changes?

It looks like those are still present.

Ah yes I see what you meant, it looks like there were some changes to library/stdarch. I've reverted those changes, so I think everything should be good to go now 👍

@patricklam

Copy link
Copy Markdown

@tautschnig can we get the ci to run?

@tautschnig

Copy link
Copy Markdown
Member

@tautschnig can we get the ci to run?

CI run has been approved and is in progress.

@patricklam

Copy link
Copy Markdown

Requesting a review again...

Comment thread library/core/src/intrinsics/mod.rs Outdated
Comment thread library/core/src/intrinsics/mod.rs Outdated
Comment thread library/core/src/intrinsics/mod.rs Outdated
@tautschnig

Copy link
Copy Markdown
Member

@AlexLB99 Was closing this PR an intentional act?

@AlexLB99 AlexLB99 reopened this Dec 20, 2024
@AlexLB99

Copy link
Copy Markdown
Author

@AlexLB99 Was closing this PR an intentional act?

Yes, temporarily -- I was resolving some merge conflicts (so I started by deleting the previous commits, which automatically closes the pr). I also pushed some new changes to reflect the previous comments.

@AlexLB99

Copy link
Copy Markdown
Author

Hi, I'm just following up to see if anyone would be able to review this pr, to see if everything is on the right track (@celinval or anyone else interested). Thanks in advance!

@celinval celinval left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks much better. I think the main adjustment is to add a value validity clause as a pre-condition.

Comment thread library/core/src/intrinsics/mod.rs Outdated
Comment thread library/core/src/intrinsics/mod.rs Outdated
Comment thread library/core/src/intrinsics/mod.rs Outdated

@celinval celinval left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Be aware that the value validity check is not currently enabled in this repository.

Comment thread library/core/src/intrinsics/mod.rs Outdated
Comment thread library/core/src/intrinsics/mod.rs Outdated
@AlexLB99

Copy link
Copy Markdown
Author

Be aware that the value validity check is not currently enabled in this repository.

Thanks for the reviews! Just to clarify, do you mean here that -Z valid-value-checks is not enabled by default, or that the can_dereference precondition is not actually checking value validity (or something else)?

@celinval

Copy link
Copy Markdown

Be aware that the value validity check is not currently enabled in this repository.

Thanks for the reviews! Just to clarify, do you mean here that -Z valid-value-checks is not enabled by default, or that the can_dereference precondition is not actually checking value validity (or something else)?

The former. -Z valid-value-checks is not enabled by default.

@AlexLB99

Copy link
Copy Markdown
Author

I pushed a commit that just added a note about the potential bug we discussed. At this stage, should we consider merging what we have so far (pending any immediate suggestions), or would it be better to continue adding stuff here? In either case, I think the next steps on our end might be to dive a bit deeper into pointers and references (and of course, please feel free to let me know if there's anything in particular that you would like us to assign a greater priority to). Thanks!

@celinval celinval left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Let's get a second reviewer so we can merge this.

@AlexLB99
AlexLB99 marked this pull request as ready for review January 23, 2025 19:51
@AlexLB99
AlexLB99 requested a review from a team as a code owner January 23, 2025 19:51
Comment thread library/core/src/intrinsics/mod.rs Outdated
Comment thread library/core/src/intrinsics/mod.rs Outdated
Comment thread library/core/src/intrinsics/mod.rs Outdated
Comment thread library/core/src/intrinsics/mod.rs Outdated
@AlexLB99

AlexLB99 commented Feb 4, 2025

Copy link
Copy Markdown
Author

I've created a commit that addressed the previous comments. The main things are that I added macros for the suggested harnesses (as well as for the 2-way transmute harnesses). I also removed the padding-related harnesses, since it's not clear at the moment how we'd write a meaningful proof for that (i.e., we can generate many different structs with macros, but even then it wouldn't be a complete proof -- we'll probably put these aside for now while we think of a better way to approach this). Please let me know if you have any further suggestions @feliperodri -- thanks!

@patricklam

patricklam commented Feb 4, 2025 via email

Copy link
Copy Markdown

@feliperodri
feliperodri added this pull request to the merge queue Feb 4, 2025
Merged via the queue into model-checking:main with commit db8e5a7 Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants