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
Sema: a by-value cycle through Option[E] (a generic spelling) escapes the dependency-loop check; TypeLayout recurses until the stack overflows #1439
A by-value cycle spelled through a generic value type is not caught by Sema's dependency-loop check, and the compiler then overflows its stack computing the (infinite) layout. enum E: A(o: Option[E]) is an infinite-size type; the compiler segfaults instead of reporting it.
enum E:
A(o: Option[E])
B
fn main:
let e = E.B
print("unreachable")
with check / with run exit 139 (EXC_BAD_ACCESS, stack guard). The same cycle through a tuple (A(t: (i32, F)) with F: C(e: E)) is reported correctly ("dependency loop with length 2").
Root cause (lldb, base stage2)
src/SemaDecl.wcollect_value_type_deps (the comment at ~1108): NK_TYPE_GENERIC is treated as an indirection and never followed ("NK_TYPE_PTR, NK_TYPE_REF, NK_TYPE_SLICE, NK_TYPE_GENERIC ... all provide indirection — do not follow"). Option[E], Result[E, X], and a user generic that holds its parameter by value (type Wrap[T] { t: T }) embed their arguments by value, so the cycle E -> Option[E] -> E never becomes an edge.
The eager layout pass then recurses forever: breakpoint on Sema.type_layout_size_of after 5000 hits shows the repeating frames TypeLayout.w:359 (type_layout_size_of) <- TypeLayout.w:295 (type_layout_enum_size_of, payload loop) <- TypeLayout.w:270 (generic-inst enum branch) <- TypeLayout.w:413 (type_layout_size_of, TY_GENERIC_INST) <- TypeLayout.w:295 ...
Expected
error: dependency loop with length 1 (or an infinite-size diagnostic naming Option[E]), as for the tuple spelling. Following a generic's arguments must stay precise: Vec[E], Box[E], HashMap[K, E] are indirections and must stay legal, so the check needs to know which parameters a generic holds by value (Option/Result: all; a user generic: those its fields/payloads hold by value). A recursion guard in TypeLayout would turn any remaining miss into a loud error instead of a stack overflow.
Found while fixing #1430 (codegen's side now refuses to size a bodiless placeholder; this cycle dies in Sema before codegen).
Activity
Sema: the type-cycle check follows a generic's by-value arguments — `…
Sema: the type-cycle check follows a generic's by-value arguments — `…
Sema: the type-cycle check follows a generic's by-value arguments — `…
ehartford commentedon Sep 26, 2026
Verified fixed on main 55739d4 (release binary): dependency loop reported cleanly.