Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion quest/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ generic std gap is planned here even when moq never calls it.
- [Waiting: type-check in process with tsrs](/quest/m3/ts-tsrs.md) - rust2-ts checks bindings through tsrs instead of `tsc` once it is a stable library
- [An inclusive range folded through an adaptor](/quest/m3/ts-range-fold.md) - a `RangeInclusive` folded through `map`, `filter`, or `rev` ends in core's state, and `by_ref` of one type-checks
- [Binding gaps](/quest/m3/ts-bind-gaps.md) - bound types as keys, unit returns checked, renamed dependencies
- [A B-tree's drop order](/quest/m3/ts-btree-drop.md) - dropping a whole `BTreeMap` or `BTreeSet` drops its entries node by node, as std's does
- [Drop order in std's folds and iterators](/quest/m3/ts-drop-order.md) - the values that drop still refused in std's folds, zips, flattens, and collects drop as std's do
- [Byte arrays compared for equality and hashed](/quest/m3/ts-byte-keys.md) - `==` of byte arrays, and byte arrays, slices, and vectors as hash keys, translate
- [Ranges of Bounds](/quest/m3/ts-bound-ranges.md) - drains and B-tree ranges of a `(Bound, Bound)` translate
- [A slice's edits in place](/quest/m3/ts-slice-edits.md) - `fill`, `rotate_left`, and `copy_from_slice` of other values translate
- [Mutable subslices of other values](/quest/m3/ts-mut-subslices.md) - `&mut v[a..b]` and `split_at_mut` of other than bytes translate, writing through
- [Iterator consumers over items whose None is rt.None](/quest/m3/ts-option-items.md) - `nth`, `last`, and `find` of an iterator of `Option` keep `None` apart from `Some(None)`
Expand Down
17 changes: 0 additions & 17 deletions quest/m3/ts-bound-ranges.md

This file was deleted.

22 changes: 22 additions & 0 deletions quest/m3/ts-btree-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# [S] A B-tree's drop order

## Goal

[rust2-ts](/ts/README.md) drops a whole `BTreeMap` or `BTreeSet` whose entries drop in the
order std's does, proven by the lang fixture's differential tests against native Rust.

## Plan

Found on 2026-10-30 while testing ranges of `Bound`s: at the pinned nightly, std's
`Drop for BTreeMap` calls `drop_tree` (`btree/navigate.rs`), which drops each node's
entries and then moves on in postorder, so a parent's entries drop after its children's.
The runtime drops them in key order, so a map of 12 or more entries that log as they drop
logs a separator key last natively and in place translated. Std's node size is 11 keys and
the runtime's 64, so the order depends on std's node layout, which insertion order decides:
porting it means modelling std's splits and merges for maps whose entries drop, or
refusing with a span the drop of a map whose entries drop and that may hold more than one
node.

`IntoIter`'s drop, through `dying_next`, stays in key order.

Public API: the translator's output for B-trees of values that drop.
2 changes: 2 additions & 0 deletions quest/m3/ts-drop-order.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ with a span where std's order is one JS's can't follow yet:
- `RangeInclusive::new` of bounds that drop, such as `Arc::new(a)..=Arc::new(b)`, refused
where the range is built, found by [#247](https://github.com/moq-dev/rust2/pull/247) on
2026-10-29.
- A range that drops given to a drain or a B-tree's `range`, which std drops once it has
read the range's bounds, or at once for an empty B-tree.

Each `rt.Iter` has a `fold` and `rfold` that drop what it holds where std's do, and the
by-value consumers std folds go through it: build on those rather than `rt.drop`.
Expand Down
1 change: 1 addition & 0 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ crate translation reaches is refused, and so are two versions of one crate it re
| an iterator | `rt.Iter<Item>`, whose adaptors are runtime functions: `rt.iterMap(rt.iterSlice(v), f)` |
| `a..b`, `a..=b` | `rt.Range<T>`, `rt.RangeInclusive<T>`, which are iterators too |
| `a..`, `..b`, `..=b`, `Bound<T>` | `{ start }`, `{ end }`, `{ end, inclusive: true }`; `rt.RangeBound<T>`, a union tagged by variant |
| a range a drain or a B-tree's `range` takes | itself, or of a type other than std's ranges and a pair of `Bound`s, `rt.boundsOf` of it and its `start_bound` and `end_bound`, which the runtime calls where std's does |
| `HashMap`, `HashSet`, `BTreeMap`, `BTreeSet`, `VecDeque`, `BinaryHeap` | `rt.HashMap<K, V>` and so on, each a plain object whose functions are the runtime's: `rt.hashGet(map, key)` |
| `PeekMut<T>` | `rt.PeekMut<T>`, the `rt.Place` of a heap's greatest element, which sifts it down as it drops once `DerefMut` lent it |
| `Ordering`, `DefaultHasher`, `RandomState` | `rt.Ordering`, which is `-1`, `0`, or `1`; `rt.Hasher`; `rt.RandomState`, the keys of the `DefaultHasher` it builds, never changed once made |
Expand Down
13 changes: 12 additions & 1 deletion ts/fixtures/lang/caller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,4 +299,15 @@ const locks = [[0, 1, 5, 6, 2, 7, 3, 8, 3, 0, 1], [4, 0, 4, 1], [2, 9, 2, 10, 4,
*/
const onces = [[1, 0, 1, 7], [0, 6, 1, 2, 3, 4, 5, 11], [2, 14, 8], [9], [3, 15]].map((bytes) => Uint8Array.of(op("statics::onces"), 0, ...bytes));

export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...dyns, ...cells, ...shared, ...locks, ...onces];
/**
* `bounds` with each kind of bound at each end, over every pair of values around and past
* four items, so ranges are empty, backwards, equal, and out of bounds, and of no items.
*/
const boundsOp = op("bounds::bounds");
const bounds = Array.from({ length: 6 * 9 * 36 }, (_, n) => {
const [kind, ends, at] = [n % 6, Math.floor(n / 6) % 9, Math.floor(n / 54)];
const [a, b] = [at % 6, Math.floor(at / 6)];
return [Uint8Array.of(boundsOp, kind, ends % 3, Math.floor(ends / 3), a, b, 1, 3, 2, 5), Uint8Array.of(boundsOp, kind, ends % 3, Math.floor(ends / 3), a, b)];
}).flat();

export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds];
37 changes: 37 additions & 0 deletions ts/fixtures/lang/expected/bounds.Asked.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { log } from "./bounds.ts";

/** The crate's own range, which logs each bound std asks it for: 0xa5 its start, 0xae its end. */
export class Asked<T> {
start: rt.RangeBound<T>;
end: rt.RangeBound<T>;

constructor(start: rt.RangeBound<T>, end: rt.RangeBound<T>) {
this.start = start;
this.end = end;
}
}

export function startBound$RangeBounds_u8_u8(self: Asked<rt.u8>): rt.RangeBound<rt.u8> {
log(165);
return self.start;
}

export function startBound$RangeBounds_usize_usize(self: Asked<rt.usize>): rt.RangeBound<rt.usize> {
log(165);
return self.start;
}

export function endBound$RangeBounds_u8_u8(self: Asked<rt.u8>): rt.RangeBound<rt.u8> {
log(174);
return self.end;
}

export function endBound$RangeBounds_usize_usize(self: Asked<rt.usize>): rt.RangeBound<rt.usize> {
log(174);
return self.end;
}

//# sourceMappingURL=bounds.Asked.ts.map
23 changes: 23 additions & 0 deletions ts/fixtures/lang/expected/bounds.Item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { log } from "./bounds.ts";

/** Logs its tag as it drops. */
export class Item {
tag: rt.u8;

constructor(tag: rt.u8) {
this.tag = tag;
}

[Symbol.dispose](): void {
drop$Drop(this);
}
}

export function drop$Drop(self: Item): void {
log(self.tag);
}

//# sourceMappingURL=bounds.Item.ts.map
28 changes: 28 additions & 0 deletions ts/fixtures/lang/expected/bounds.Key.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { log } from "./bounds.ts";

/**
* A key the crate orders by its own `Ord`, high to low, as rangemap's keys are by theirs,
* which logs each `==` and `partial_cmp`: 0xe9 and 0xc9.
*/
export interface Key {
_0: rt.u8;
}

export function eq$PartialEq(self: Key, other: Key): boolean {
log(233);
return self._0 === other._0;
}

export function cmp$Ord(self: Key, other: Key): rt.Ordering {
return rt.cmp(other._0, self._0);
}

export function partialCmp$PartialOrd(self: Key, other: Key): rt.Ordering | undefined {
log(201);
return cmp$Ord(self, other);
}

//# sourceMappingURL=bounds.Key.ts.map
Loading