Repository navigation
Closures reference globals in place (#1313) and S.A.tag() lowers on a variant-path receiver (#1310) - #1321
Merged
Conversation
added 2 commits
September 22, 2026 12:24
…ferenced in place (§9.1c, D52) (#1313) `check_closure` scanned the whole flat scope `bind_names[0..outer_count]` for symbols the body uses, and the flat scope holds every module global registered by `register_top_level_global_decl` (Sema.w:4819). So `() => g + 1` over `var g: i32` listed `g` as a capture; MirLower's `prepare_anonymous_body` (MirLower.w:13111-13114) then found no local for the symbol — `lookup_local` and `lookup_alias_type` both miss, MirLower resolves a global per body through `ensure_global_local` instead — and panicked "anonymous capture lacks a concrete local type: node=7474 symbol=747" (lldb: sema_phase_bug <- MirBuilder.prepare_anonymous_body, sym 747 = the global's flat-scope binding). The same scan drove the three other capture loops, which is why a non-Copy global (`var log: str`) in an escaping closure was marked MOVED and reported "closure that mutates captured place cannot escape its defining scope (§15.9)" plus "use of moved value" on every later use of the global. Fix: `Sema.binding_index_is_global(idx, sym)` (the module's `global_value_decl_bindings` slot, or a bundle interface's storage in `interface_global_index`/`interface_global_alt_binds`), and every capture scan in `check_closure` skips such a binding: the capture list, the implicit-capture pass, the capture-borrow registration, the ephemeral escape check, and the escaping-closure move/§15.9 pass. A local that shadows an unseen global holds the same symbol at another index, so the predicate is by binding index, not by name. Evidence on the fixed stage1: `--dump-mir` of the repro shows the closure body `$anonymous$…` with `_1: ty3 // g [global]`, no capture parameters, and `_2 = binop(add, copy _1, const 1)`; `with run` prints 1. Test: test/behavior/behav_closure_names_global.w — a read, `g += 10`, `{ g = 3 }`, a local captured alongside the global (`() => n + g`), and a non-Copy global `str` appended by an escaping closure; single-threaded so the §9.1c race proof holds.
…med `Type` — `S.A.tag()` lowers (#1310) `lower_expr_place`'s NK_FIELD_ACCESS branch went straight to `lower_field_access`, so a bare unit-variant receiver `S.A` in `S.A.tag()` was lowered as the field `A` projected off a place named `S`: lower_auto_ref_call_arg -> lower_field_access -> lower_field_base_place_for_field -> lower_expr_place(S) -> mark_unsupported (lldb breakpoint on MirBuilder.mark_unsupported, frames #0-#7 under lower_method_call), and the whole function failed MIR lowering (`[mir-lower-fail] kind=27`). `lower_expr` already recognized the same node as an enum variant (base ident names an enum in `named_types`, the qualified or bare variant symbol is in `variant_lookup`) and built the aggregate; only the place path lacked the check, which is why binding the variant first worked. Fix: `is_enum_variant_path(node)` — the recognition lower_expr uses — and `lower_expr_place` lets such a node fall through to its materialize-as- temporary fallback instead of projecting a field. Evidence on the fixed stage1, `--dump-mir` of the repro: `S.A.tag()` lowers as `_13 = aggregate(kind=1, tag=0, fields=[]); _14 = copy _13; _15 = ref(shared, _14); call tag(copy _15)` — the same shape as `let x = S.A; x.tag()` in the block before it. `with run` prints 1 twice. Test: test/behavior/behav_enum_variant_path_receiver.w — `S.A.tag()`, `S.B(7).tag()`, a str-returning method, the call inside an f-string, and a second payloadless enum.
Contributor
Author
|
Battery on |
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.
Two MIR-lowering bugs from today's issues, one commit each.
#1313 — a closure that names a global panicked MirLower
check_closure(SemaCheck.w) scanned the whole flat scopebind_names[0..outer_count], which holds every module global registered byregister_top_level_global_decl, so() => g + 1overvar glistedgas a capture.MirBuilder.prepare_anonymous_bodythen found no local for the symbol (lookup_local/lookup_alias_typemiss; a global is resolved per body byensure_global_local) and hitsema_phase_bug— lldb:sema_phase_bug <- MirBuilder.prepare_anonymous_body, symbol 747 = the global's flat-scope binding. The same scan drove the other capture loops, which is why a non-Copy global in an escaping closure was marked MOVED (§15.9error + "use of moved value" on every later use).Fix:
Sema.binding_index_is_global(idx, sym)(moduleglobal_value_decl_bindingsslot, or bundle-interface storage) and every capture scan incheck_closureskips it. A global is referenced in place (§9.1c, D52), never captured.Evidence (
--dump-miron the fixed stage1): the closure body has_1: ty3 // g [global], zero capture params,_2 = binop(add, copy _1, const 1);with runprints1.#1310 —
S.A.tag()failed MIR loweringlower_expr_place'sNK_FIELD_ACCESSbranch went straight tolower_field_access, projecting the fieldAoff a place namedS: lldb onMirBuilder.mark_unsupported→lower_expr_place(S) <- lower_field_base_place_for_field <- lower_field_access <- lower_auto_ref_call_arg <- … <- lower_method_call.lower_expralready recognized the node as a variant value; the place path lacked the check, which is why binding the variant first worked.Fix:
is_enum_variant_path(node)(the same recognition) andlower_expr_placelets such a node fall through to its materialize-as-temporary fallback.Evidence (
--dump-mir):S.A.tag()lowers as_13 = aggregate(kind=1, tag=0); _14 = copy _13; _15 = ref(shared, _14); call tag(copy _15)— the same shape aslet x = S.A; x.tag().Tests
test/behavior/behav_closure_names_global.w: read,g += 10,{ g = 3 }, a local captured alongside the global, a non-Copy globalstrappended by an escaping closure (single-threaded; §9.1c proof holds).test/behavior/behav_enum_variant_path_receiver.w:S.A.tag(),S.B(7).tag(), str-returning method, inside an f-string, a second payloadless enum.Iterate tier on a fresh
:devstage1: both new tests green; the closure/global/variant/enum set (76 files) green except two unrelated cases:behav_migrate_multi_declarator_globals(environmental — main's own stage1 fails it in this worktree, this branch's stage1 passes it in the main checkout; the childwith migratecannot see the build-generatedstd.re.*modules from the case dir) andenum_discriminant_flags, a pre-existing stage1-only divergence filed as #1320.:fixpoint/:testnot run (per task).Fixes #1313. Fixes #1310.