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
{{ message }}
Repository navigation
Option.map(it as i64) in a compiler method links to an undefined bare ___closure in the multi-unit build #2558
Building the compiler (src/main build :dev, seed nightly-20261020-local-3) with this expression in Codegen.emit_module_runtime_init_helpers (src/CodegenTraits.w):
let global_val: i64 = self.module_constants.get(name_sym).map(it as i64) ?? 0
The closure body it as i64 was emitted as a call to a bare __closure symbol with no definition in the unit object. The same shape in a user program links and runs with both the installed compiler and the seed:
use std.collections
fn main:
var m: HashMap[i32, i32] = HashMap.new()
m.insert(1, 41)
let v: i64 = m.get(1).map(it as i64) ?? 0
print(v + 1) # 42
So the miss is specific to the compiler's multi-unit build (__wcu$ unit objects): the closure's definition is not emitted into (or not named consistently across) the unit that references it. Workaround used: a plain if stored.is_some(): stored.unwrap() as i64 else: 0.
Route: --dump-mir of the method under the seed, then nm of the unit objects for the __closure definition.
Triage 2026-10-25, with v0.15.3.0 (main a261b65): could not be reproduced without editing the compiler. The shape works in a user program (a method returning self.m.get(k).map(it as i64) ?? 0 prints 42), and the compiler source on main no longer contains .map(it as i64). Reproducing needs that line put back into src/CodegenTraits.w and a :dev stage1 build, which this triage does not do.
The question: keep this open for a multi-unit closure-emission test (a fixture that builds with several codegen units), or close it as unreproducible?
Reproduced the multi-unit shape without editing the compiler, on main 279981a (installed compiler, darwin-arm64): WITH_CODEGEN_UNITS reaches a user program's build (Backend.w compile_to_object_backend), so a method holding the issue's closure can be split across units.
use std.collections
type Holder:
m: HashMap[i32, i32]
impl Holder:
fn wide(k: i32) -> i64: self.m.get(k).map(it as i64) ?? 0
fn a1(h: &Holder) -> i64: h.wide(1) + 1
fn a2(h: &Holder) -> i64: h.wide(2) + 2
fn a3(h: &Holder) -> i64: h.wide(1) * 3
fn main:
var m: HashMap[i32, i32] = HashMap.new()
m.insert(1, 41)
let h = Holder { m: m }
print(f"{a1(&h)} {a2(&h)} {a3(&h)}")
With WITH_CODEGEN_UNITS set to 1, 2, 4 and 8, it prints 42 2 123 every time. The 8-unit binary carries ___wcu$267$Holder.wide, ___wcu$269$a1 and so on, so the method and its callers are in separate units, and there is no undefined ___closure. The failure came from a stage1 built by seed nightly-20261020-local-3, and it does not reproduce on the current toolchain. To recheck: build the program above with WITH_CODEGEN_UNITS=8 with build, then run nm on the binary.
Activity
ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): could not be reproduced without editing the compiler. The shape works in a user program (a method returningself.m.get(k).map(it as i64) ?? 0prints 42), and the compiler source on main no longer contains.map(it as i64). Reproducing needs that line put back intosrc/CodegenTraits.wand a:devstage1 build, which this triage does not do.The question: keep this open for a multi-unit closure-emission test (a fixture that builds with several codegen units), or close it as unreproducible?
ehartford commentedon Oct 29, 2026
Reproduced the multi-unit shape without editing the compiler, on main 279981a (installed compiler, darwin-arm64):
WITH_CODEGEN_UNITSreaches a user program's build (Backend.w compile_to_object_backend), so a method holding the issue's closure can be split across units.With
WITH_CODEGEN_UNITSset to 1, 2, 4 and 8, it prints42 2 123every time. The 8-unit binary carries___wcu$267$Holder.wide,___wcu$269$a1and so on, so the method and its callers are in separate units, and there is no undefined___closure. The failure came from a stage1 built by seed nightly-20261020-local-3, and it does not reproduce on the current toolchain. To recheck: build the program above withWITH_CODEGEN_UNITS=8 with build, then runnmon the binary.