Repository navigation
Closures: every capture is found, a stored view is refused, a call through &fn calls (§12.4, D62/D63; #1698) - #1701
Merged
Merged
Conversation
added 2 commits
September 25, 2026 22:26
…rough &fn calls (§12.4, D62/D63; #1698: #1570 #1598 #1594 #1638 #1566 #1603) Capture-set completeness. Sema's expr_uses_symbol was a whitelist with a silent 0 for any node kind it did not name, so a local used only inside a `.Variant(args)` shorthand, an `unsafe` block, a `move`/`copy` argument, a multi-index, a `with` body or an asm operand was never captured and the closure read a zero or its own return slot (#1570, #1598). The walk now names every kind: the missing forms are walked, the leaves are listed, and an unknown kind is an internal error, not a 0. MirLower's own expr_mentions_symbol, which guards the string move-first rewrite, had the same shape; an unknown form there now answers "may mention" so the rewrite stays off. Indexing through a by-place capture. Codegen's index projection keyed on the LLVM `ptr` of the capture slot and treated `xs[1]` as raw-pointer indexing — it printed the high half of the Vec's data pointer. Sema owns the meaning (D65): only a raw-pointer Sema type is pointer indexing; a pointer-typed slot whose Sema type is a Vec/str/slice loads through the pointer first, as the field projection already did. Stored views (#1594, #1638, #1566's container form). A non-`move` closure holding a place of its frame is an ephemeral VALUE though `fn(A) -> R` the type is not (D63), so expr_is_ephemeral_value says so, a struct/array/map literal holding one is ephemeral, the #625 viral store (`fs.push(closure)`) propagates the captures' origins onto the container, and a returned literal holding one goes through the returned-ephemeral origin check. `fs.push(() => n * 10)` in a loop is now "view `fs` may originate from `n`, which no longer lives here"; `Cnt { f: x => x + extra }` returned is "returned ephemeral value may outlive its origin 'extra'"; the `move` spellings run. Calls through `&fn(A) -> R` (#1603). `&shout` lowered through lower_fn_address to the bare code pointer for every `&` op, so the callee's `read.*(s)` dereferenced code and ran nothing (rc 138). When Sema typed the expression `&fn`, the callable is materialized in a temp and the reference points at it; raw-ref ops and a `&f` Sema typed as the callable itself keep the code address. Verified on a stage1 of this tree: the nine new tests pass, every existing closure behavior/compile-error test is unchanged, and `check src/main.w` reaches no unlisted node kind.
…nly a `&fn(A) -> R` expectation references the callable (#1603 follow-up) The first cut materialized every `&f` Sema typed as a reference, so a raw C function pointer (`let fp: *const fn(i64) -> i64 = &take_i64`, a struct field, a call argument) received a pointer to a temp and the three fn-pointer behavior tests segfaulted in the battery. The expected type decides: a raw pointer expectation keeps the address.
Contributor
Author
|
Seed-driven battery at 9366af2 (seed nightly-20260925-local-1, WITH=src/main), alone with the drop/move audits, this host: |
ehartford
marked this pull request as ready for review
September 26, 2026 03:43
This was referenced Sep 26, 2026
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.
First slice of #1698. Fixes #1570, #1598, #1594, #1638, #1603 and the container form of #1566 (its direct-argument form was already diagnosed); #1567 and #1605 were verified fixed on main and closed.
expr_uses_symbolis exhaustive over every node kind with a loud fallthrough; MirLower'sexpr_mentions_symbolanswers conservatively for unknown forms.ptr).moveclosure with a by-place capture is an ephemeral value: stores into containers and literals propagate its origins; returning a literal holding one is refused.&ftyped&fn(A) -> Rmaterializes the callable and references it.Ownership/drop-scheduling change: alone in its battery with
:drop-auditand:move-audit. Draft until the battery is posted.