Skip to content

Linking stage1 fails with undefined symbol ___closure when a compiler module calls List[str].sort() #2618

Closed

Description

@ehartford

Seen while adding src/CiContracts.w (D159 campaign, #2615) on main 0b6e230 under the pinned seed nightly-20261024-local-4-0cca9aee2744. A compiler module doing

var names: List[str] = List.new()
…
names.sort()

builds src/ with the seed to completion and then stage1 fails to link: ld64.lld: error: undefined symbol: ___closure. List.sort (std.algorithms) reaches ord_compare[T], which returns a closure written inside a generic function; the instantiation for T = str from a compiler module produces a reference to the closure symbol but no definition in the stage1 object set. A user program calling List[str].sort() compiles and runs (behav_list_sort), so the shape is specific to the compiler build (the seed compiling src/ as one unit set; #1135's class, a closure in a generic function, in its link form).

Workaround in CiContracts.w: an insertion sort by < on str, noted in a comment; remove it when this is fixed.

Repro: on a worktree of main, add the three lines above to any src/*.w function that runs at startup, then WITH=$PWD/src/main src/main build :dev and read the link error.

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Fixed in #2620 (main 2083b59): gen_closure created the closure function with external linkage; the multi-unit build strips every external body a unit does not own, so an instance in unit 1 returning a closure linked against an undefined ___closure. Internal linkage, as the thunks and environment helpers already had. Fixture test/behavior/behav_codegen_units_closure_in_generic.w (WITH_CODEGEN_UNITS=8) fails on the previous stage1 and passes on this one. CiContracts keeps its insertion sort until a seed carrying the fix is pinned (the pinned seed must still link stage1).

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