You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The pt2 residual was parser-gated: the shared-XOR-exclusive rules from
pt1 (#240 UseWhileExclusivelyBorrowed / ConflictingBorrow) could never
fire from real source because `&mut e` did not parse — only shared `&e`
(OpRef) existed. This adds the exclusive-borrow expression surface.
- ast.ml: new `unary_op` variant `OpMutRef` (`&mut e`). Documented: only
the borrow checker distinguishes it from `OpRef`; every other backend
treats `&mut e` exactly like `&e` (a reference is the same runtime
pointer — exclusivity is a static property).
- parser.mly: `expr_unary | AMP MUT e -> ExprUnary (OpMutRef, e)`,
ordered before `AMP e`. `AMP MUT` is unambiguous (an expression cannot
begin with the MUT keyword) — **zero Menhir conflict delta**: 21 S/R
states + 1 R/R + 68/7 arbitrarily-resolved baseline held (ADR-012).
- borrow.ml: `OpMutRef` => *Exclusive* borrow (vs `OpRef` Shared);
`ref_target`/`is_copy` also match it. This is the soundness payload.
- typecheck/codegen: `OpMutRef` folded into the `OpRef` arm (typed
`TRef`, same heap-pointer codegen); `gen_unop` made exhaustive.
Verified: `&mut x` parses; two `&mut x` => ConflictingBorrow; read `x`
while `&mut x` live => UseWhileExclusivelyBorrowed; `return &mut local`
=> BorrowOutlivesOwner (composes with pt2 return-escape); shared `&x`
unchanged; `&mut x` emits wasm (177 B). Full gate 278 -> 281 (+3
hermetic "E2E Borrow Graph" tests + 3 fixtures); all stdlib AOT green —
zero over-rejection.
Scope: `&`-in-`#{` literals + bare block-statements already parse on
main; the `-> &T`/`&T` *type* sigil is deliberately NOT added (`ref T`/
`mut T` keyword types already express reference types — a `&T` sigil is
duplicate surface, ADR territory, not a soundness gap). The pt2 residual
is now the NLL/`outer=&x` *analysis* (expressible, no longer
parser-gated), not surface. Ledger + borrow.ml comment truthed.
Refs #177 (not Closes — NLL analysis remains).
Co-authored-by: hyperpolymath <hyperpolymath@users.noreply.github.com>
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
0 commit comments