-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Preliminary support for data types when extracting from Low* to Rust #486
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ce we get rid of the insertion of lowstar::ignore
I managed to get a preliminary demo with variants, the next step is to try it out on a larger example, but this should be good for merging. |
Added some long-standing much-desired changes to extract HACL* to a multi-crate layout. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is part of a long tail of improvements for the Rust backend of krml. This PR disables pattern matching compilation, meaning:
type t = { f: ... }
).The general case is still not super well tested (inductives with multiple cases), but for HACL*, this change means that we see some
match
expressions overstruct
types in Rust, which previously would be compiled as a series oflet x = e.f
, but now are a single match with a single branch.See https://github.com/hacl-star/hacl-star/pull/982/files
Concretely:
match e with { f: x } => e2
aslet x = e.f; e2
(andmatch e with { _ } => e2
as e2), for cosmetic reasonsAt a high level, it turns out that the Rust compiler "auto-borrows" when using the syntax
let x = e.f; ...
, but not when doingmatch e with { f } => ...
-- see this Zulip discussion https://hacspec.zulipchat.com/#narrow/stream/433829-Circus/topic/semantics.20of.20let.20vs.20match.20in.20Rust/near/471101452As a consequence, we need to be a LOT more explicit with the compilation of pattern matches from Low* to Rust, and need to introduce what's known as
ref
andref mut
patterns (see https://doc.rust-lang.org/stable/reference/patterns.html) to do what the Rust compiler would automatically do in the presence of a simple field expression. In particular, we take every single pattern variable over an array-like type (borrow, vec, or box) to mean a match by reference -- this is what was previously happening. Finally, the pretty-printing MUST ignore unused pattern variables, or run the risk of having move-outs for those, too.Next steps include: