-
Notifications
You must be signed in to change notification settings - Fork 21
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
Question mark as early returns #559
Conversation
Please add an issue and put it on the board. |
da78121
to
6cc0fca
Compare
Not a review, but I've tried this out for the ProVerif backend, basically copying the phase configuration from the F* backend and it works. (#564 is the result) |
This commit introduces a phase that simplifies the pattern: ``` /// Note `let` below is NOT monadic let hoistN = e in body ``` into `body[hoistN/e]`, when: - the local ident `hoistN` is of kind `SideEffectHoistVar` (we know it was produced by the side effect utils module); - `body` contains exactly one occurence of `hoistN`. That simplifies greatly the extracted code.
32dc2e8
to
7533949
Compare
@jschneider-bensch I rebased my PR, can you rebase yours onto that That's great that those patches work for you in the PV backend 😀 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
You are adding phases. Where is the documentation for the phases? As there's probably none yet, this is a good point to start. Please add docs to https://hacspec.org/hax with placeholders for the other phases and some infos on the ones you added here (an extended version of what you have in the PR is enough).
It should also answer questions like which other cases in "note this mechanism doesn't handle every case"?
99f6d3c
to
8d203fc
Compare
So, I had to do a bit of stupid macro things in OCaml, but now we have documentation for phases gathered in one place: https://hacspec.org/hax/engine/hax-engine/Hax_engine/Phases/index.html (this will be up to date whenever the PR is merged) |
8d203fc
to
4ce4fbc
Compare
4ce4fbc
to
f3e21a3
Compare
This PR adds a few phases:
Drop_needless_returns
;Simplify_question_marks
;Simplify_match_return
;Simplify_hoisting
.Essentially, this PR is about question marks:
Simplify_question_marks
goes through the AST and detects matches that looks like question marks (just asReconstruct_question_marks
, which is now deprecated since we want to drop it, see RemoveReconstruct_question_marks
phase andQuestion_mark
nodes from the AST #567)?
matches are produced by rustc and are quite complicated (it involves https://doc.rust-lang.org/std/ops/trait.Try.html):Simplify_question_marks
simplify them into simpleErr
/Ok
(orNone
/Some
) matches;?
-matches are early returns:Simplify_match_return
does some inlining so that those early returns are pushed to exit position, becoming non-early returns (note this mechanism doesn't handle every case);Drop_needless_returns
removes uselessreturn
statements;Simplify_hoisting
removes extrahoistN
let-bindings.This PR fixes:
return
when in end position #254RewriteControlFlow
phase (return
/continue
/break
) #393