Skip to content
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

Infer mutability of borrows during Rust extraction #449

Merged
merged 53 commits into from
Jul 19, 2024
Merged

Conversation

R1kM
Copy link
Collaborator

@R1kM R1kM commented Jul 19, 2024

This PR, done jointly with @msprotz, improves the Rust backend by avoiding needless mutable borrows each time a value is borrowed.

A detailed explanation of the compilation scheme is provided at the top of lib/OptimizeMiniRust.ml. However, the core idea is the following:

  • First, the translation from Ast to MiniRust does not introduce any mutability, only shared borrows
  • In a second phase operating on the MiniRust AST, borrows and variables are marked as mutable through a backward analysis pass, only when required (e.g., when assigned to, or passed to a function expecting a mutable borrow). Importantly, this second phase is not trusted: it only modifies the mutability information in the program, which will therefore be rechecked by the Rust compiler.

In addition to the unit tests added in Rust7.fst, the currently supported part of HACL-rs also extracts, compiles, and passes tests with this PR.

msprotz and others added 30 commits July 10, 2024 09:51
@R1kM R1kM merged commit facdca2 into master Jul 19, 2024
2 checks passed
@R1kM R1kM deleted the protz_infer_mut branch July 19, 2024 16:07
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.

2 participants