Skip to content

feat(rengine, lean): add rejection phase that ensures an expression is in the Lean do-notation DSL#1739

Merged
clementblaudeau merged 13 commits intomainfrom
rengine-reject-not-lean-dsl
Oct 21, 2025
Merged

feat(rengine, lean): add rejection phase that ensures an expression is in the Lean do-notation DSL#1739
clementblaudeau merged 13 commits intomainfrom
rengine-reject-not-lean-dsl

Conversation

@W95Psp
Copy link
Copy Markdown
Contributor

@W95Psp W95Psp commented Oct 9, 2025

Context

The Lean backend produces code that targets Lean's do-notation, providing handy ways to chain monadic let-bindings. This notation actually defines a small internal DSL with do-expressions, do-statements and normal lean-expressions (as a fallback). This PR adds a (rust-engine) phase that rejects interleavings of expressions and statements that are outside this DSL. Eventually, it should be removed in favor of a phase that automatically hoist out let-bindings and control flow operators, in order to always stay inside the DSL (see #1741).

This PR also updates some error messages.

Examples

The following is rejected:

let x = 1 + (if true { 0 } else { 1 });
error: [HAX0008] Explicit rejection by a phase in the Hax engine:
This interleaving of expression and statements does not fit in Lean's do-notation DSL.
You may try hoisting out let-bindings and control-flow.
See issue https://github.com/cryspen/hax/issues/1741

Note: the error was labeled with context `Engine phase (RejectNotDoLeanDSLVisitor)`.

  --> lean-tests/src/ite.rs:11:17
   |
11 |     let x = 1 + (if true { 0 } else { 1 });
   |                 ^^^^^^^^^^^^^^^^^^^^^^^^^^
   |

Other cases can be found in tests/lean-tests/src/reject_do_dsl.rs

@clementblaudeau clementblaudeau force-pushed the rengine-reject-not-lean-dsl branch from 9614a1f to eccabf3 Compare October 14, 2025 07:28
Add the [Phase(String)] context, to indicate an error in a phase

Improve error message for [ExplicitRejection] errors
@clementblaudeau clementblaudeau force-pushed the rengine-reject-not-lean-dsl branch from eccabf3 to 3e12ce9 Compare October 14, 2025 09:23
@clementblaudeau clementblaudeau changed the title feat(rengine): intro rejection phase that ensures an expression is in the Lean Do DSL feat(rengine, lean): add rejection phase that ensures an expression is in the Lean do-notation DSL Oct 14, 2025
@clementblaudeau clementblaudeau force-pushed the rengine-reject-not-lean-dsl branch from d9e7ff1 to 1acf9a6 Compare October 14, 2025 09:36
@clementblaudeau clementblaudeau marked this pull request as ready for review October 14, 2025 13:35
@clementblaudeau clementblaudeau requested a review from a team as a code owner October 14, 2025 13:35
@clementblaudeau clementblaudeau requested review from karthikbhargavan and maximebuyse and removed request for karthikbhargavan October 14, 2025 13:35
Copy link
Copy Markdown
Contributor

@maximebuyse maximebuyse left a comment

Choose a reason for hiding this comment

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

I added some comments but this looks good!

@clementblaudeau clementblaudeau added this pull request to the merge queue Oct 21, 2025
Merged via the queue into main with commit 6db49b5 Oct 21, 2025
17 of 18 checks passed
@clementblaudeau clementblaudeau deleted the rengine-reject-not-lean-dsl branch October 21, 2025 09:21
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.

3 participants