Skip to content

Bug: returning a large struct (Sema field) by value breaks generic lowering #577

Closed

Description

@ehartford

Problem

Changing lower_module to move-through style — returning MirLowerOutput { mir_mod: MirModule, sema: Sema } (Sema is a multi-KB struct of Vecs/maps) — makes the built compiler emit spurious unknown type 'T' while lowering generic blanket-impl bodies in the embedded std, identical symptom to the DiagnosticList-handle bug. The in-function code is byte-identical; only the return type (and thus the sret/ABI path for a very large aggregate) changes, and the failure fires before the return is reached, pointing at a frame-layout or sret-related miscompile in the stage that built it.

Repro

At 2c8ba1a8: change fn lower_module(mut sema: Sema, ...) -> MirModule to return MirLowerOutput { mir_mod, sema }, update the single caller in Compilation.run_mir_lower, build stage2, then check the HashMap 4-liner from the sibling issue → unknown type 'T' in std/collections.w:21.

#564 shipped with the field-place box shape instead (MirLowerSemaBox in Compilation.w, commit 1f9ec56), which preserves the share semantics without the giant by-value return.

Related

Same latent-miscompile family as #568 and the DiagnosticList-handle issue.

Activity

  1. ehartford commented on Jun 13, 2026

    @ehartford
    ContributorAuthor

    Same root cause as #576 — see the full analysis there. There is no large-struct-return miscompile: the Sema-bearing return simply made the caller adopt the callee's diagnostics list, surfacing four genuine 'unknown type T' errors that lower_module has emitted into a discarded Sema copy on every compile since the blanket-impl skip predicate was left incomplete (fn_meta_tp_count only; missing the generic_fn_nodes check that codegen has). The validated fix is the lower_module skip-predicate completion; once it lands, the MirLowerOutput move-through shape from the #564 work is re-appliable and this issue can close alongside #576.

  2. ehartford commented on Jul 2, 2026

    @ehartford
    ContributorAuthor

    Closing as fixed on HEAD (verified by probe): a 24-field struct (incl. Vec + HashMap) returned by value from a generic method (Maker.make[T](self: &Maker[T]) -> Big) checks and runs correctly. The sret/classification concern doesn't reproduce at user level; the lower_module skip-predicate fix (MirLower.w:12429) covers the trigger.

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