Skip to content

D184: a script's top-level bindings are locals of the implicit main; a helper captures them (§29.15) - #2983

Merged
ehartford merged 1 commit into
mainfrom
d184-captures
Nov 2, 2026
Merged

ehartford merged 1 commit into
mainfrom
d184-captures

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Implements the amended D184 (#2979, spec v7.35 §29.15; #2951). Parser records the script's bindings and helpers; Sema injects captures into a helper checked at main's call site, settles widths, refuses consumption (Law 5) and reads before the binding's statement; MIR and both backends give captured bindings storage. Five new fixtures; 149 script-style behavior tests pass under stage1. Follow-up filed for the non-escaping rule of a view capture. Battery to follow.

…a helper that names one captures it (§29.15)

Parser: a script's named let/var stays a local of main; the pool records
the script's bindings and the file's top-level fns (its helpers), and the
marks travel through the comptime transform. Sema: a helper is checked
where main calls it, never ahead of main's body; its body sees the script's
bindings as level-0 captures (a parameter or local shadows one, D173; a
helper's read settles an integer-literal binding's width, and a later use
in main that disagrees names both sites; a binding a helper reads gets
storage both can reach; a helper that consumes a capture is refused, Law
5). A read in a helper reached before the binding's statement has run is a
compile-time error from the static call graph. MIR marks a captured
binding's local as storage-backed; both backends define the storage.

Tests: behav_d184_script_captures, behav_d184_captures_view_and_mutation,
err_d184_read_before_statement, err_d184_helper_consumes_capture,
err_d184_helper_settles_width; the 149 script-style behavior tests pass.
Follow-up: a helper that captures a view is non-escaping (a spawn or a
value use of it is refused) is not yet enforced.
@ehartford

Copy link
Copy Markdown
Contributor Author

Battery green on f338bb0 (out/battery/status.txt: rc= green), rebased on main after #2985 and #2986. Fixes on the way from the first red: capture removal ran before the function scope was popped (it popped the helper's own locals and left a stale scope index; tools/battery.w crashed the compiler), and a helper that only shadows a script binding no longer settles its integer width. All 52 tools check, the 5 fixtures and the 150 script-style behavior tests pass under stage1.

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.

1 participant