Skip to content

feat(ts): drop a whole B-tree node by node as std's drop_tree does - #613

Merged
kixelated merged 4 commits into
mainfrom
quest/m3/ts-btree-drop-order
Nov 7, 2026
Merged

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

Conversation

@kixelated

@kixelated kixelated commented Nov 6, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

std's Drop for BTreeMap (at the pinned nightly-2026-10-15) calls drop_tree (btree/navigate.rs). It walks the nodes in postorder and drops each node's entries in index order, so a parent's entries drop after its children's. Since moq-dev/rust2#577 ported std's node layout, the runtime can follow that walk exactly. rs.btreeDrop (glue for a whole BTreeMap or BTreeSet, and clear) now does so instead of dropping in key order. IntoIter's drop stays in key order, as std's dying_next does.

  • ts/runtime/rs/collections.ts: btreeDrop walks the tree in postorder (dropTree). Deletes flatten, which only this used.
  • ts/README.md: the 2026-10-30 decision now covers only hash maps and sets. B-trees drop as std's do.
  • Tests, each confirmed to fail on the old runtime:
    • New collections::btree_drops lang case, ported from the reproduction in moq-dev/rust2#272. It builds whole trees of up to 297 logged values, to height 2, by random, ascending, and descending inserts, collect, removals and pops, sets, nested maps, IntoIter from both ends, clear, assignment, retain and split_off, and clone, then drops them. On main: 137 differences.
    • The btree_extracts lang case and the task fixture's drops::orders case 3 now drop their maps whole instead of working around the order through into_iter. On main: 352 task differences.
    • btree_script in tests/runtime.rs, the 120k-step random script against std's BTreeMap, now hashes the drop order of every whole tree it discards (retain, extract, and collect drops, and split's clear). Those trees reach about 20k entries. On main it fails at the first one.
  • Deletes quest/m3/ts-btree-drop-order.md and its link.

Measurements

The bench's btree/ workloads hold u32 entries, which have no drop glue, so they never call btreeDrop and cannot change. Instead, a node microbench of btreeDrop with a value dropper on 200 trees per size, old against new, two runs each:

keys old ns/entry new ns/entry
16 15.1, 19.8 11.7, 8.6
256 23.3, 45.7 13.1, 9.4
4096 148, 155 36.4, 44.6

The new walk builds no intermediate arrays.

Public API

Translator output is unchanged. Only the runtime's rs.btreeDrop and rs.btreeClear change order, for B-trees whose entries drop.

Choices made without asking

  • Hash maps and sets keep the runtime's order, per the 2026-10-30 decision, which this quest leaves in place for them.

Suggested follow-ups

None.

Review

Codex (quest review), gpt-6.1-sol at medium effort, round 1 on head c5bfba9db702e29940d413fb4a51b5ce3e46b8c9 against origin/main b5f5545d0: no findings.

(Written by Claude Opus 5.5)

🤖 Generated with Claude Code

@pullfrog

pullfrog Bot commented Nov 6, 2026

Copy link
Copy Markdown

Pullfrog  | Review this ➔

kixelated and others added 3 commits November 6, 2026 14:26
The runtime's B-tree now holds std's node layout, so a whole map or set,
dropped or cleared, drops each node's entries in order after its children's,
as std's drop_tree walks it in postorder, rather than in key order. IntoIter
still drops in key order, as std's dying_next does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…p-order

# Conflicts:
#	ts/fixtures/lang/collections/expected/collections.ts
#	ts/fixtures/lang/collections/expected/lib.ts
#	ts/fixtures/lang/collections/src/collections.rs
#	ts/fixtures/lang/collections/src/lib.rs
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@kixelated kixelated changed the title A B-tree drops as std's does feat(ts): drop a whole B-tree node by node as std's drop_tree does Nov 6, 2026
@kixelated
kixelated marked this pull request as ready for review November 6, 2026 22:53
@coderabbitai

coderabbitai Bot commented Nov 6, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 53 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 66192d4b-4fac-4413-8034-288f6d61557c
Commits

Reviewing files that changed from the base of the PR and between b5f5545 and c5bfba9.

Files selected for processing: 13

  • quest/m3/README.md
  • quest/m3/ts-btree-drop-order.md
  • ts/README.md
  • ts/fixtures/lang/collections/expected/collections.Tagged.ts
  • ts/fixtures/lang/collections/expected/collections.ts
  • ts/fixtures/lang/collections/expected/lib.ts
  • ts/fixtures/lang/collections/src/collections.rs
  • ts/fixtures/lang/collections/src/lib.rs
  • ts/fixtures/task/expected/drops/orders.ts
  • ts/fixtures/task/src/drops/orders.rs
  • ts/runtime/rs/collections.ts
  • ts/tests/btree.ts
  • ts/tests/runtime.rs
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@kixelated kixelated left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated review by review (OpenAI)

Reviewed head: c5bfba9db702e29940d413fb4a51b5ce3e46b8c9 against base b5f5545d06a0774204de7befb09b05bafaa1f1fc.

No actionable defects found. The new traversal drops child nodes left to right before each parent's key/value pairs, matching std's postorder drop_tree traversal. clear still empties the map before dropping its old contents, and IntoIter remains separate. I checked the generated fixtures and the paired Rust/TypeScript drop-order tests covering different tree shapes, sets, nested maps, and partial consumption. No code changes requested from this pass.

Limits: GitHub-only static review of all 13 changed files and relevant runtime/upstream code. I did not run translation, differential tests, the 120,000-step runtime test, benchmarks, or just ci. The PR's reported regression results and measurements were not independently reproduced; the visible Queue runs are skipped.

(Written by OpenAI)

@kixelated
kixelated added this pull request to the merge queue Nov 6, 2026
Merged via the queue into main with commit 1a940bd Nov 7, 2026
10 checks passed
@kixelated
kixelated deleted the quest/m3/ts-btree-drop-order branch November 7, 2026 00:04
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