Repository navigation
Codegen: each type declaration gets its own LLVM type (#1446) - #1462
Merged
ehartford merged 1 commit intoSep 23, 2026
Merged
Conversation
…ules declare no longer shares one struct (#1446) Two modules each declaring `pub type Item` printed `a 1724130190`: module a's `{ i64, i64 }` values were read through b's `{ str, i32 }`. Route: codegen of a compilable input — IR, then lldb on the base compiler. Evidence. `with ir` of the repro: one `%Item = type { %str, i32 }`, used by both `make_a` and `make_b`. analyze: Sema has two TypeIds (108, 109), both `kind=6 d0=775` with different field tables. lldb on base stage2 (`ir`, breakpoint on Codegen.declare_struct_type printing w1/w2): 23 struct declarations, and name symbol 0x307 (775) twice, for declaration nodes 0x1dcd and 0x1de1 — the second call sets the body of the struct the first one defined. Root cause. Codegen.w Pass 0a/0b register a named LLVM type under the declaration's bare name symbol (`pool.get_data0(decl)` via shadow_reg_sym), and every TypeId-to-LLVM lookup goes back through that name (sema_type_to_llvm, mir_sema_type_to_llvm, place projection, enum payload lookup). The D29 `$std` alias already split a std-tier declaration from a user one; nothing split two user modules. Fix. Before registration, collect_nominal_aliases finds names more than one non-generic TypeId declares: the first declaration in decl order keeps the plain symbol, each later one registers as `name$<tid>`. The TypeId-driven lookups map a TypeId to its declaration's symbol; a type node naming a split name asks Sema which declaration it means from the declaring module (sync_decl_context), and `Self` in a split name's method is the declaration visible from the method's module. Names declared once are untouched: every hook is the identity when no name is split. Matrix (two modules, each declaring Item, Pair { first: Item }, a payload enum Shape and a disc enum Kind with different reprs): field reads, a struct holding the split type, payload enum match, u8 vs i64 disc enum match, Vec[Item] iteration, Option[Item], methods with distinct names, `-> Self` returning an `Item { }` literal, str fields dropped (debug allocator leak count=0). Base: the plain repro prints wrong values, the full program fails LLVM verification. A stage2 built by the fixed stage1 validates src/main.w. Filed, not fixed here: Sema types a `Self { .. }` literal in one module's impl as the other module's `Item`, and same-named methods on the two types collide as one symbol (#1457).
ehartford
force-pushed
the
fix-1446-module-type-identity
branch
from
September 23, 2026 09:32
7036a39 to
2629a99
Compare
ehartford
force-pushed
the
fix-1446-module-type-identity
branch
from
September 23, 2026 09:58
2629a99 to
cf36211
Compare
This was referenced Sep 23, 2026
Contributor
Author
|
Stack #1466 battery (seed-driven, new seed, cold c_import cache, with :drop-audit/:move-audit) on main 1c76062 + #1418 → #1419 → #1425 → #1428 → #1449 → #1377 → #1459 → #1460 → #1461 → #1462 (head cf36211, including the #1449/#1462 Codegen resolution and the fixed #1460): build ok, :fixpoint ok, :drop-audit ok, :move-audit ok, :test ok (no reds), :test-green ok, :last-green ok. Each branch holds exactly its tested commits on the layer below. Merge the whole stack: |
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.
Closes #1446. Top of stack #1463, above #1461.
Bug. Two modules each declaring
pub type Itemshared one LLVM struct, and module a's values were read through b's layout (a 1724130190).Evidence.
with ir: one%Item = type { %str, i32 }, used by bothmake_aandmake_b. Sema has two TypeIds with the same name symbol (775). lldb on the base compiler showsCodegen.declare_struct_typecalled twice with name symbol 0x307 (775), for declaration nodes 0x1dcd and 0x1de1.Root cause. Pass 0a/0b register a named LLVM type under the declaration's bare name symbol. Every TypeId-to-LLVM lookup goes back through that name.
Fix.
collect_nominal_aliasesgives every later declaration of a name that more than one TypeId declares its own symbol,name$<tid>. The first declaration keeps the plain name. Every lookup that goes from a TypeId, a type node orSelfnow reaches that declaration's symbol. When no name is split, every hook returns its input unchanged.Matrix. Two modules each declare Item, a Pair holding Item, a payload enum and a disc enum with different reprs. Checked: fields, the nested struct, enum matches,
Vec[Item],Option[Item], methods with distinct names,-> SelfwithItem { }literals, and str drops (leak count=0). Base prints wrong values, or fails LLVM verification once methods are involved. A stage2 from the fixed stage1 validates src/main.w.Fixtures.
behav_same_named_type_layout(the issue's repro) andbehav_same_named_types_two_modules, with modules intest/behavior/lib/issue1446/.Filed. #1457: Sema types a
Self { .. }literal in one module's impl as the other module'sItem, and same-named methods collide. Both are wrong on base too.Stack verification (top, all four fixes).
check src/main.w --validate-all: ok.behav_fn_abi_asyncandasync_tuple_awaitpass (they failed on an earlier cut of MIR/codegen: a discriminant enum's discriminant is its repr type; a local's slot is its declared type (#1444) #1460; see that PR).tools/drop_audit.wwith this stage2 as candidate: 176 cells, 0 non-PASS, 0 regressions.tools/move_audit.w: 0 vs-expected FAIL. Its output is byte-identical to the same audit run with base stage2 as candidate.Draft until the batch battery is green.