feat(codegen): surface &T / &mut T as SharedBorrow / ExclBorrow (closes #221)#255
Open
hyperpolymath wants to merge 1 commit into
Open
feat(codegen): surface &T / &mut T as SharedBorrow / ExclBorrow (closes #221)#255hyperpolymath wants to merge 1 commit into
hyperpolymath wants to merge 1 commit into
Conversation
#221) Extends the AST and parser to distinguish shared from exclusive borrows, then wires the distinction through codegen so the `typedwasm.ownership` custom section emits all four OwnershipKind variants instead of just `Linear` + `Unrestricted`. ## What changes - `Ty::Borrow` and `ExprKind::Borrow` (in ephapax-syntax) gain a `mutable: bool` field; the corresponding `SurfaceTy`/`SurfaceExprKind` variants gain it too. - Parser grammar adds an optional `"mut"` marker after `&` for both borrow types and borrow expressions; `mut` joins the keyword list. - Codegen replaces `UserFnInfo.param_linear: Vec<bool>` with `param_kinds: Vec<OwnershipKind>` populated via a new `ty_to_ownership_kind` helper: `&T → SharedBorrow`, `&mut T → ExclBorrow`, linear `Ref`/`String → Linear`, else `Unrestricted`. `emit_ownership_section` consumes the kinds directly; the filter is broadened from "any linear" to "any non-Unrestricted" so shared-borrow-only signatures still emit an entry. - s-expr IR encoding uses `borrow` vs `borrow-mut` discriminator atoms to preserve mutability through the IR round-trip. ## Tests - `ownership_section_emits_shared_borrow_for_borrow_param` — `&T` → `SharedBorrow`. - `ownership_section_emits_excl_borrow_for_mut_borrow_param` — `&mut T` → `ExclBorrow`. - `test_parse_mut_borrow` — `&mut x` parses with `mutable: true`. - Existing ownership round-trip + linear-param tests unchanged and green. ## Example - `examples/linear/16-shared-vs-exclusive-borrow.eph` — minimal shared-vs-exclusive contrast. ## Closes typed-wasm gap This is the producer-side counterpart to typed-wasm's L7 alias-exclusion enforcement; previously ephapax-emitted modules never produced `ExclBorrow`, so the verifier saw only 2 of 4 `OwnershipKind` variants from this producer. Both reviewers of proposal 0001 (2026-05-30) called out the gap. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ty::BorrowandExprKind::Borrowwithmutable: bool(mirrored on theSurface*enums); parser recognises&mutvia amut_markeratomic rule +mutkeyword.ty_to_ownership_kindhelper that maps&T → SharedBorrow,&mut T → ExclBorrow, linearRef/String → Linear, elseUnrestricted. ReplacesUserFnInfo.param_linear: Vec<bool>withparam_kinds: Vec<OwnershipKind>.emit_ownership_sectionbroadens its filter from "any linear" to "any non-Unrestricted" so shared-borrow-only signatures still emit an entry.borrowvsborrow-mutdiscriminator atoms to preserve mutability through the IR round-trip.Closes the producer-side gap flagged in both 2026-05-30 reviews of typed-wasm proposal 0001 —
SharedBorrow+ExclBorrowwere defined inownership.rsbut never emitted, so the verifier's L7 alias-exclusion check fired zero times against ephapax-emitted modules.Test plan
cargo test --workspacegreen (all suites)test_parse_mut_borrow—&mut xparses withmutable: trueownership_section_emits_shared_borrow_for_borrow_paramownership_section_emits_excl_borrow_for_mut_borrow_paramexamples/linear/16-shared-vs-exclusive-borrow.ephdemonstrates both polaritiesOut of scope
Closes #221.
🤖 Generated with Claude Code