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
Codegen: an enum whose payload type is declared later is mis-laid-out — silent truncation (wrong value) or LLVM TypeSize crash; blocks §10.9 composition with a facade's <R>Error #1430
Enum payload of a later-declared enum: the match yields got 0, not got 7.
enum Outer:
Inner(i: InnerE)
fn main:
let o = Outer.Inner(InnerE.A(7))
match o:
Outer.Inner(InnerE.A(k)) => print(f"got {k}")
enum InnerE:
A(n: i32)
Enum payload of a later-declared struct: LLVM ERROR: Cannot implicitly convert a scalable size to a fixed-width size in TypeSize::operator ScalarTy(), exit 134.
§10.9 error composition: BUG: no payload value for enum type 135 variant 0 field 0 while formatting [src/CodegenDispatch.w:2966 Codegen.gen_display_enum_variant].
error AppError from DbError
fn main:
let e = AppError.Db(DbError.Failed(3))
print("x")
error DbError =
| Failed(status: i32)
A struct holding a later-declared struct is fine (type Outer { i: Inner } before type Inner).
Root cause (read, not yet proven in lldb)
src/Codegen.wdeclare_enum_type computes each variant's payload struct and then let sz = self.abi_size_of(payload_ty), which fixes the enum's [N x i8] payload array at definition time.
Pass 0b (src/Codegen.w ~6272-6308) defines struct and enum bodies in declaration order.
A payload type declared later is still a predeclared named struct with no body at that point. Its size is either 0, for a not-yet-bodied enum (so the payload array is dropped and the data is truncated), or it triggers the LLVM TypeSize crash, for a not-yet-bodied struct.
Struct bodies are unaffected because LLVM sizes named struct fields lazily. The enum path is the only one that sizes eagerly.
Why it matters now
Modeled C (D51) renders facade types (<facade NAME>) after every user declaration, so:
A user enum holding a facade resource by value crashes the compiler: enum Conn: Open(db: Database) | Closed → LLVM ERROR. Checked on stage1 of modeled-c-stage5, and the same shape applies since stage 4.
Stage 5's ok projection renders error DatabaseError = after the user's error AppError from DatabaseError, the §10.9 composition Eric asked for (2026-09-23, Modeled C stage 5: production and status (ruling §15-§19) #1426), so that composition hits the Display BUG above.
Fix direction
Define enum bodies after every struct and union body.
Order the enums among themselves so that an enum carrying another enum by value is defined after it. A cycle by value is an infinite-size type and must be a loud error.
This is an enum layout change, so it belongs alone in its batch (ABI isolation). It only changes enums that are broken today.
Expected
Declaration order never changes layout: got 7, no crash, and the error composes.
Activity
Facade: `ok CONST` projects onto Result[R, <R>Error]; a failed produc…
Facade: `ok CONST` projects onto Result[R, <R>Error]; a failed produc…
Codegen: a type's body is defined before anything sizes it — an enum …
Codegen: a type's body is defined before anything sizes it — an enum …
Modeled C stage 5: production and status (ruling §15-§19) (#1426)
Codegen: a record's embedded-alignment scan is a map lookup, not a la…
D71 facade rulings: ok lists, valid on failed, callback-scope handles…
windows-x86_64 :test: place parameters are never sized; peak RSS; aud…