-
Notifications
You must be signed in to change notification settings - Fork 62
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 a Rust backend #396
Merged
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
- External type ids - Better separation of path components
(Got an everest green locally) |
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.
Trying to merge this now as I switch my focus back to eurydice -- want to avoid bitrot. In addition to the Rust backend itself (which is profusely commented), a change in this PR is that the datatypes compilation phase now generates well-typed AST nodes from the get-go rather than rely on the Checker module to infer types. This was a historical artifact, and didn't sit well with the Rust backend, which is adamant about having fully-inferred AST nodes, so now it's fixed.
Unfortunately I don't have any tests yet as I'm weary of embarking on a CI journey. This shall be added in due time once HACL-rs is ready to be merged (branch protz_rs of HACL).
For context, I shall quote myself from Slack...
For a long while, many users (such as Election Guard, along with a sizeable chunk of the HACS community) have requested a pure Rust version of HACL* rather than Rust bindings on top of the C library.
I have just pushed a work in progress to that effect, on the protz_rs branches of HACL* and krml. This is extremely preliminary work, but already chacha20, poly1305 and chacha20poly1305 from HACL* compile, along with some of the bignum routines (UPDATE: all of the bignum routines, except for k256 -- thanks @R1kM for your crucial help).
Some additional thoughts, hoping to address questions that may arise.
sub
operation from Low*) is compiled as a call to slice_at_mut, relying on a static analysis that records the various splits operations enacted on the original (base) pointer, in order to make sure no reference to a borrowed variable is generated. I also added an optimistic compilation strategy for when there is too much loss of precision (see comments in lib/AstToMiniRust.ml), relying on Rust's bounds checks to guarantee either sound compilation, or a runtime exception if the choice made was incorrect. That latter strategy assumes that the programmer is taking offsets into the original pointer left-to-right, and kicks in whenever the offsets cannot be statically compared.fmul(x, x, y)
wherex
is both written to (first parameter, out) and read (second parameter, in). UPDATE FROM SLACK MESSAGEThe current strategy is to statically replace every call to
fmul
that is of the formfmul x x y
(there are many such functions -- fmul is just an example, for "field multiplication") withfmul_a x x y
where_a
stands for the aliased version. Thefmul_a
wrapper is inline_for_extraction, has exactly the same signature asfmul
(so it doesn't wreck the proofs), and merely doeslet fmul_a dst x y = push_frame (); let x_copy = copy x in let r = fmul dst x_copy y in pop_frame (); r
Other options would be to write a separate version of
fmul
that is in-place, but based on @karthikbhargavan's preliminary benchmarking, this doesn't necessarily translate to perf improvements.It remains to be determined what this means for HACL-C (right now these changes are not conditional on C vs Rust so this means the C code is impacted in HACL) but we can deal with it later in the HACL PR itself.
It goes without saying that there is a huge amount of room for improvement in all of the above. Stay tuned...