Skip to content

feat(ts): drop as std does in B-tree collects by a key's own Ord, max_by_key, and into_keys' ends - #499

Merged
kixelated merged 8 commits into
mainfrom
quest/m3/ts-drop-order
Nov 3, 2026
Merged

kixelated merged 8 commits into
mainfrom
quest/m3/ts-drop-order

Conversation

@kixelated

@kixelated kixelated commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Problem

rust2-ts still refused values that drop in three of std's iterator paths, the last ones left by quest/m3/ts-drop-order.md:

  • collect and from into a B-tree whose keys use their own Ord, PartialOrd, or PartialEq, when the entries drop.
  • max_by_key and min_by_key by a key that drops.
  • max and min of a BTreeMap's into_keys when it holds something that drops.

No moq consumer hits these at the pinned revision. The quest covers them because rust2 aims to support all of std.

Approach

  • B-tree collect: the refusal dated from #101, when the runtime sorted with JS's sort. Since #439, rt.sliceSort ports driftsort call for call, and a panic aborts on wasm32. So the existing rt.btreeCollect and rt.btreeCollectKeys path (sort, then keep the last of each run != finds equal, dropping the others key then value) already matches std. The refusal is gone.
  • max_by_key / min_by_key: std reduces KeyAndValue { key, value } pairs. The runtime's best now takes dropKey: a losing pair drops its key and then its item, and the winner's key drops once the fold ends.
  • into_keys max / min: std overrides both with next_back and next, and the rest of the entries drop with the iterator. The new rt.ownedEnd reads that end and then disposes the iterator.
  • Tests: a new task-fixture step, orders (8 scenarios, differential against native wasm32), logs every cmp, partial_cmp, eq, key made, and drop. It covers sets and maps of keys whose impls disagree, sorts past std's insertion-sort cutoff, Cell keys, from arrays, max_by_key and min_by_key (including empty and single-item iterators), into_keys ends, and a panic in the sort. Mutating the runtime (JS sort instead of sliceSort, key dropped after its item, no dispose after ownedEnd) makes the step fail each time.
  • The reject fixture's ranked_cells now translates, so it is removed.

Impact

  • Translator output: these three cases now translate instead of failing with a span.
  • rt.iterMaxByKey and rt.iterMinByKey take dropKey after owns, before none (added to ts/MIGRATE.md).
  • New rt.ownedEnd(it, back, none?).

Alternatives

  • Keep the collect refusal. Rejected: the faithful sort already gives std's order.

Follow-ups

  • The 26-key scenario empties its trees with into_iter. Dropping a tree whole follows the runtime's key order, not std's node-by-node order, which the pinned nightly's drop_tree now walks in postorder. This was a maintainer decision on 2026-10-30 (ts/README.md), so no quest.
  • This finishes the quest and deletes it with its links.

Review

quest review, Codex gpt-6.1-sol at medium effort, 3 rounds. The last round reviewed head 3487cd55 and reported no findings. The current head adds only a conflict-free merge of origin/main (#500), and just ci passes on it.

  • Round 1, medium, collections.rs:1351: a whole multi-node tree drops in key order, not in the nightly's postorder drop_tree order. Refuted: this is the maintainer's 2026-10-30 decision in ts/README.md ("Dropping a whole map or set drops its entries in the runtime's order...", #272). It applies to every dropping B-tree whatever its keys' Ord. The reviewer accepted this in round 2.

🤖 Generated with Claude Code

kixelated and others added 6 commits November 2, 2026 22:56
Quest-Claim: 84e6372f7bea4df6
…es that drop

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and min that drop

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title Drop order in std's folds and iterators feat(ts): drop as std does in B-tree collects by a key's own Ord, max_by_key, and into_keys' ends Nov 3, 2026
@kixelated
kixelated marked this pull request as ready for review November 3, 2026 09:07
@kixelated
kixelated added this pull request to the merge queue Nov 3, 2026
Merged via the queue into main with commit 5983791 Nov 3, 2026
4 of 5 checks passed
@kixelated
kixelated deleted the quest/m3/ts-drop-order branch November 3, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant