Skip to content

Audit source field ownership and LLVM layout registry mappings #1131

Closed

Description

@ehartford

Nested generic record registration can corrupt field ownership in the LLVM layout registry while MIR validation succeeds.

Reproduction:

type Inner[T] { value: T }
type Outer[T] { left: i32, inner: Inner[T], right: i32 }
fn create() -> Outer[i32]: Outer { left: 11, inner: Inner { value: 22 }, right: 33 }
fn main:
    let value = create()
    assert(value.inner.value == 22)

At Phase 1 commit 72e1067, this fails LLVM verification: icmp eq %Outer__i32 ..., i32 22. An owning Trie variant with pointer fields instead compiles, overwrites its engine pointer with null, and traps at main + 136.

Native proof: LLDB stops in Codegen.monomorphize_struct_nodes + 2184, resolving the child's type recursively while the parent's flat field range is incomplete. Codegen.get_llvm_field_index receives source index 1 and returns 0 from the registry map. Codegen.w records struct_field_starts before recursively resolving fields and appends mapping entries after resolving them, interleaving parent and child ranges.

The implementation fix reserves complete parallel field ranges before recursion. The remaining tooling gap is that check --validate-all --dump-mir succeeds for the Trie variant: no check compares the registry's field ownership and slot mapping with the source record. Add a codegen layout audit that catches overlapping field ranges, inconsistent parallel columns, and incorrect source-to-LLVM field mappings before emitting stores. The ordinary LLVM verifier catches mismatched types but cannot detect two same-typed pointer fields being confused.

Local evidence: out/phase1-drafts/nested-layout-registry-proof.txt, trie-native-proof.txt, and trie-pre-ir.txt in the c-algorithms-phase1 worktree. No workaround is used in the facade; the compiler layout registration is being fixed in the Phase 1 batch.

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): does not reproduce.

    $ cat main.w
    type Inner[T] { value: T }
    type Outer[T] { left: i32, inner: Inner[T], right: i32 }
    fn create() -> Outer[i32]: Outer { left: 11, inner: Inner { value: 22 }, right: 33 }
    fn main:
        let value = create()
        assert(value.inner.value == 22)
        print(f"{value.left} {value.right}")
    $ with run main.w
    11 33
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions