Skip to content

stdlib has no sort #940

Closed
Closed

Description

@ehartford

Found in the container survey prompted by #936. grep -rn 'fn .*sort' lib/std/ finds nothing in the stdlib proper; the only sort in the tree is tool_glob_sort in lib/std/build.w (an insertion sort over strings, O(n²), fine for globbing). User code and the compiler's own tooling have no Vec.sort() / sort_by(cmp) to reach for, so the alternative is hand-rolling one (or BTreeMap, #937).

Ask

Vec[T: Ord].sort() and Vec[T].sort_by(fn(&T, &T) -> i32) in lib/std/collections.w — an in-place, deterministic algorithm (a stable merge sort or introsort; determinism matters for fixpoint-facing tooling). Element moves go through the D27 slot machinery so Drop-class elements are never bit-copied; the drop audit covers it. Fixture: ints, strings, structs by key, stability check for sort_by.

Activity

  1. ehartford commented on Sep 2, 2026

    @ehartford
    ContributorAuthor

    Ruling (Eric, 2026-09-01): not a native rewrite. The stdlib's algorithms and containers come from three C corpora migrated whole with with migrate — c-algorithms, TommyDS, STC (plus a surgical M*LIB B+ tree port) — and the With stdlib is a facade that selects engines from them. The model is "migrate the library whole, facade selectively": we never migrate pieces, the un-facaded code stays as migration coverage, alternate engines for benchmarks, and a corpus for migrator bugs.

    For sort specifically: Vec.sort / sort_by / binary_search / lower_bound facade STC's algorithm layer (with c-algorithms' sorted array and heap as the classic alternates). STC's macro/template instantiation is the deliberate migrator-hardening campaign that comes with it.

    Plan: docs/stdlib_sourcing_plan.md (landing with the next docs commit). This issue stays open as the facade deliverable for sorting/searching; it closes when Vec.sort is a facade over the migrated corpus with complexity fixtures.

  2. self-assigned this
    on Sep 3, 2026
  3. added a commit that references this issue on Oct 9, 2026
    8f678c9
  4. added a commit that references this issue on Oct 9, 2026
    503edab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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