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
Global Atomic: initializer from another global's load() panics the compiler; top-level fetch_add + f-string fails codegen #1861
A global initialized from an Atomic method on another global crashes the compiler, and a top-level Atomic method call next to an f-string read of the same global fails codegen. Both reproduce on main (v0.15.3.0-g355c20b16) and on a1f82be6.
use std.sync
let a: Atomic[i64] = Atomic.new(4)
let v = a.load()
with build g4.w -o g4 prints panic: index out of bounds and writes no binary. The same thing happens with a fn main that prints v.
Repro 2: codegen reports the wrong argument type
use std.sync
let a: Atomic[i64] = Atomic.new(4)
a.fetch_add(3)
print(f"x{a.load()}")
The output is error: wrong argument type actual=i32 expected=ptr fn=main (x3), then code generation failed. print(f"{a.load()}"), with no literal text in the f-string, prints 7. Inside fn main the same statements work.
Expected: repro 1 compiles and v is 4. Repro 2 prints x7.
Workaround: none needed yet. I found this while building a widening matrix on fix-literals and have not investigated it.
Repro 2 does not need a global. It fails inside fn main too:
use std.sync
fn main:
let a: Atomic[i64] = Atomic.new(4)
a.store(3)
print(f"x{a.load()}")
wrong argument type actual=i32 expected=ptr fn=main (x2), code generation failed. Without the a.store(3) it prints x4. With print(f"{a.load()}") it prints 3. Same on a1f82be6.
The trigger is the omitted ordering argument. With explicit orderings the same program works:
use std.sync
fn main:
let a: Atomic[i64] = Atomic.new(4)
a.fetch_add(3, .SeqCst)
print(f"x {a.load(.SeqCst)}")
This prints x 7. When the orderings are omitted and the function also has an f-string with literal text, codegen fails with wrong argument type actual=i32 expected=ptr. The ordering is an i32, so it looks as though the default argument is spliced into another call's argument list. The same shape in a helper fn (fn f(u: u32) -> (i64, i64): let a: Atomic[i64] = Atomic.new(u); let a0 = a.load(); a.fetch_add(u); (a0, a.load())) makes the compiler panic with index out of bounds.
Fixed on main by 792351b (stack #2007, battery green on 0f13a62). Atomic methods with the ordering omitted get SeqCst materialized as the call's operand; codegen no longer reads a neighbouring call's operand.
Activity
ehartford commentedon Sep 28, 2026
Repro 2 does not need a global. It fails inside
fn maintoo:wrong argument type actual=i32 expected=ptr fn=main(x2),code generation failed. Without thea.store(3)it printsx4. Withprint(f"{a.load()}")it prints 3. Same on a1f82be6.ehartford commentedon Sep 28, 2026
The trigger is the omitted ordering argument. With explicit orderings the same program works:
This prints
x 7. When the orderings are omitted and the function also has an f-string with literal text, codegen fails withwrong argument type actual=i32 expected=ptr. The ordering is an i32, so it looks as though the default argument is spliced into another call's argument list. The same shape in a helper fn (fn f(u: u32) -> (i64, i64): let a: Atomic[i64] = Atomic.new(u); let a0 = a.load(); a.fetch_add(u); (a0, a.load())) makes the compiler panic withindex out of bounds.Atomic methods with the ordering omitted: MIR materializes SeqCst as …
Sema/MIR: CK_FN loud on a missing fn (#1859); atomics default SeqCst (#…
ehartford commentedon Oct 3, 2026
Fixed on main by 792351b (stack #2007, battery green on 0f13a62). Atomic methods with the ordering omitted get SeqCst materialized as the call's operand; codegen no longer reads a neighbouring call's operand.
#2358: Sema refuses a builtin call whose argument count is outside it…