Skip to content
This repository was archived by the owner on Mar 17, 2026. It is now read-only.

Lef/ternary hoisting#589

Open
elefthei wants to merge 5 commits intomainfrom
lef/ternary-hoisting
Open

Lef/ternary hoisting#589
elefthei wants to merge 5 commits intomainfrom
lef/ternary-hoisting

Conversation

@elefthei
Copy link

@elefthei elefthei commented Mar 9, 2026

Issue #443

gebner and others added 4 commits March 8, 2026 05:06
Add 'defer pre { handler }; body' construct that executes handler
whenever execution leaves body (both normal fall-through and goto/return).

- Syntax: Tm_Defer with handler_pre (slprop), handler, and body
- Parser: 'defer' keyword with slprop pre and braced handler block
- ElimGoto: preserve defer blocks, conditionalize body but not handler
- Extraction: defer extracted as sequential composition (body then handler)
@elefthei elefthei requested a review from gebner March 9, 2026 00:53
- Remove --cmi from all Makefiles (flag no longer recognized by F*)
- Fix make_auto_paren_lexer to track DOT_LPAREN, DOT_LBRACK,
  DOT_LBRACK_BAR, DOT_LENS_PAREN_LEFT, LENS_PAREN_LEFT, BAR_RBRACK,
  and LENS_PAREN_RIGHT for depth counting. Without this, qualified-open
  syntax like US.(expr) in if/match conditions caused the scanner to
  lose track of nesting depth and consume the entire file.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@elefthei elefthei force-pushed the lef/ternary-hoisting branch from 72e7758 to 4a0ae21 Compare March 9, 2026 06:22

```
if (if true then !r = 0 else false) { ... } // fails: !r buried in Tv_Match
```
Copy link
Contributor

Choose a reason for hiding this comment

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

FWIW, this is kind of the easy case. We could support this very easily be desugaring it during checking to:

let __tmp = (if true then !r = 0 else false);
if (__tmp) { ... }

(And indeed, after reading the PR that's exactly what you're doing, which is good.)

Maybe this wasn't clear from the issue description, but the actually hard issue is the following where a stateful expression needs to be hoisted out of an if in a pure expression.

let foo = (if b then !x + 42 else 67) + 10;

| File | Change |
|------|--------|
| `pulseparser.mly` — `ifStmt`, `matchStmt` | `IF LPAREN pulseStmt RPAREN`, `MATCH LPAREN pulseStmt RPAREN` |
| `PulseSyntaxExtension_Parser.ml` — `make_auto_paren_lexer` | Token preprocessor: auto-inserts `LPAREN`/`RPAREN` when omitted. Detects `LBRACE` at depth 0 as end-of-condition. Passes through F\*-level `if/then` and `match/with` unmodified. |
Copy link
Contributor

Choose a reason for hiding this comment

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

Please just add two productions (one for pulseStmt, one for terms) to the grammar instead.

# DPE directory above, but in a test we first run verify on DPE which
# involves verifying everything here already, so this saves some time.
OTHERFLAGS += --warn_error -342 --cmi
OTHERFLAGS += --warn_error -342
Copy link
Contributor

Choose a reason for hiding this comment

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

This requires updating CI to use the fstar2 branch.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants