Skip to content

Handle field writes silently emit unreachable after losing source field identity #1120

Closed

Description

@ehartford

Handle[T] field assignment compiles successfully but traps at runtime. Found while preparing the SlotMap generation-exhaustion regression for #936.

use std.collections
fn main:
    var map = SlotMap[i32].new()
    var handle = map.insert(7)
    handle.generation = 2
    assert(handle.generation == 2)

Expected: assignment to the public u32 field works. This is ordinary mutable-place assignment to the Handle representation documented in specification §6; contextual numeric inference is §4.2.1. Actual: successful compilation emits unreachable at the assignment; native execution exits 133. An explicitly typed RHS has the same failure, so this is not numeric inference.

Observed on pinned local seed and candidate adae1d9. LLDB on the candidate's stage1 stopped in Codegen.mir_resolve_field_index at its final -1 return: field text generation, LLVM aggregate has two fields, result w0=0xffffffff; stack is mir_place_ptr → mir_emit_stmt → gen_function_mir. sema_type_to_llvm constructs Handle as an anonymous {i32,i32} without named-field metadata. The field resolver consults the LLVM registry but loses the source type's field identity. mir_place_ptr returns zero, and mir_emit_stmt returns false for the projected destination at CodegenDispatch.w:5308. The resulting IR block ends in unreachable instead of rejecting compilation.

The SlotMap fixture currently cannot reach its generation boundary through ordinary field assignment. No production workaround has been introduced. The fix should preserve source field identity for compiler-modeled records and make failed projected writes diagnose/exit nonzero.

The audit catches missing marshalling for an assertion after the failed assignment. With the assignment as the last source statement (remove the final assert above), however, audit:all reports facts=11366 violations=0 ok despite the emitted unreachable block. That silent lowering failure is a validator coverage defect and must be covered before this is called fixed.

The same missing field metadata affects the compiler-created SlotMap wrapper: reading map.ptr in the runtime-layout probe produced zero. LLDB observed the resulting ldr x9, [x9] with x9=0x10 at the following metadata load. The normal source field identity, not the LLVM wrapper name or a guessed physical shape, must resolve both reads and writes. A diagnostic-only raw wrapper read isolated the runtime and reached the independent generation-addition overflow at rt_core.w:2961; tracked tests will use ordinary field access.

Local evidence: out/fnabi-validation/handle-field-proof.txt, generation-current.ll, generation-typed-trap.txt, and the runner-kept slotmap-generation binaries in the fnabi-phase0 worktree.

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