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
3 changes: 2 additions & 1 deletion quest/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ generic std gap is planned here even when moq never calls it.
- [Wakers made from a RawWaker](/quest/m3/ts-raw-waker.md) - `Waker::from_raw` and the rest of the raw waker API translate, each vtable call where std makes it
- [Waiting: a slice object for a mutable part of other values](/quest/m3/ts-slice-object.md) - waits on a moq profile showing the `Proxy` view's traps matter, then decides on an `rt.ByteSlice`-like form
- [Port the workflow guard to kixelated/quest](/quest/m3/quest-workflow-guard.md) - quest's environment guard parses YAML as this repository's does
- [Debug of std's other iterators](/quest/m3/ts-iter-source-debug.md) - `Debug` of `str`'s searcher iterators, a `BTreeSet`'s set operations, `ExtractIf`, and `repeat`, `repeat_n`, and `once_with` writes what std's does
- [Debug of a str's searches](/quest/m3/ts-iter-source-debug.md) - `Debug` of `str`'s `Split` and its forms, `Matches`, `Lines`, and `SplitWhitespace` writes their searcher's state as std's does
- [A B-tree's extract_if](/quest/m3/ts-btree-extract-if.md) - `BTreeMap::extract_if` and `BTreeSet::extract_if` translate, with their `Debug`
- [A vector keeps the capacity its pushes grew as it shrinks](/quest/m3/ts-vec-clear-capacity.md) - every step that drops a pushed `Vec`'s length keeps its capacity, as std guarantees
- [A vector's exact capacity as it shrinks](/quest/m3/ts-vec-exact-capacity.md) - a deque made from a `Vec` splits its slices where std's does
- [A B-tree's searches call Ord as std's do](/quest/m3/ts-btree-search-order.md) - a B-tree's lookups and inserts call a key's own `Ord` in std's order and number
Expand Down
15 changes: 15 additions & 0 deletions quest/m3/ts-btree-extract-if.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# [S] A B-tree's extract_if

## Goal

[rust2-ts](/ts/README.md) translates `BTreeMap::extract_if` and `BTreeSet::extract_if`,
which it refuses now: each entry in the range its closure returns true for, taken out as it
is read in key order, the rest kept once it drops, and `Debug` of their `ExtractIf`, which
writes the entry it reads next as `peek`. Proven by differential tests against native Rust.

## Plan

The runtime's B-tree keeps its keys in linked leaves, which a removal while a `BTreeIter`
reads them may rebalance; the iterator has to survive that as std's cursor does. A map's
closure takes `&mut V`, lent as a place where JS copies the value, as `retain`'s is. No
consumer calls them yet; they are planned here as part of std.
37 changes: 15 additions & 22 deletions quest/m3/ts-iter-source-debug.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,22 @@
# [M] Debug of std's other iterators
# [M] Debug of a str's searches

## Goal

[rust2-ts](/ts/README.md) translates `Debug` of the std iterators that still have no
mapping, writing what std's does instead of being refused: `str`'s iterators other than
`Chars`, `Bytes`, `CharIndices`, and the escapes (`Split` and its forms, `Lines`,
`SplitWhitespace`, `Matches`, `MatchIndices`), a `BTreeSet`'s set operations, and each
`ExtractIf`. `iter::repeat`, `repeat_n`, and `once_with`, which are not translated at all
yet, translate with their `Debug`. Proven by differential tests against native Rust.
[rust2-ts](/ts/README.md) translates `Debug` of `str`'s searching iterators, which it
refuses now: `Split` and its forms, `Matches`, `MatchIndices`, `Lines`, and
`SplitWhitespace`, writing what std's does fresh, `{:#?}`, and after reads from either end.
Proven by differential tests against native Rust.

## Plan

The sources, `Option`'s, `Result`'s, and an array's iterators, a slice's parts, and a hash
set's operations landed on `iter_debug` in `src/lower/fmt.rs`; extend it the same way.
std writes each searcher's private state, which the runtime does not keep in std's shape:
a `CharSearcher`'s `finger` and `finger_back` in UTF-8 bytes, a `StrSearcher`'s
`TwoWaySearcher` (`crit_pos`, `period`, `byteset`, `position`, `memory`) or an empty
needle's flags, and a closure's or a char set's `CharIndices`. The runtime searches in
UTF-16 code units by a `Pattern`, so it would track std's state beside its own, replay
std's search when written, or search as std does; measure the cost to plain searches
before choosing. `Lines` and `SplitWhitespace` wrap a `SplitInclusive` and a `Split`, so
they follow from those.

What is left writes private state the runtime does not keep in std's shape:

- `str`'s searcher iterators write their searcher's fields: a `CharSearcher`'s
`finger` and `finger_back` in UTF-8 bytes, a `StrSearcher`'s `TwoWaySearcher` state
(`crit_pos`, `period`, `byteset`, `memory`), and an empty needle's flags. The runtime
searches in UTF-16 code units by a `Pattern`, so it would track std's state beside its
own, or search as std does.
- A `BTreeSet`'s `Difference` and `Intersection` write which strategy std picked
(`Stitch`, `Search`, `Iterate`, `Answer`) and its iterators, `Search` the whole other
set; `Union` and `SymmetricDifference` their `MergeIterInner`'s peeked item. The runtime
already picks std's strategy, so its state may map over.
- `Vec`'s, `LinkedList`'s, and a B-tree's `ExtractIf` write the item they peek at; a hash
map's and set's write `ExtractIf { .. }` once their `extract_if` translates.
`SplitAsciiWhitespace` has no mapping at all yet, and std writes it as a slice's `Split` of
the bytes left.
6 changes: 3 additions & 3 deletions quest/m3/ts-vec-rest.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ elements through raw pointers, so each refuses with its span.
- `VecDeque::rotate_left`, `rotate_right`, `swap`, `make_contiguous`, `binary_search`,
`binary_search_by`, `binary_search_by_key`, and `partition_point`, each placing its
items where std's does, which `as_slices` shows.
- `Vec::splice`, `extract_if` of elements JS copies, `into_flattened`, `leak`, and
`spare_capacity_mut`; the last two hand out memory past the length, which may stay
refused.
- `Vec::splice`, `extract_if` with its `Debug` (`retained`, `remainder`, and
`skipped_tail`), `into_flattened`, `leak`, and `spare_capacity_mut`; the last two hand
out memory past the length, which may stay refused.

A vector's capacity follows only std's guarantees, at least its length and what
`with_capacity` and `reserve` ask for, and doubles as it grows (decided with the
Expand Down
17 changes: 11 additions & 6 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,12 +296,17 @@ its length, as std's do. `Debug` of std's iterator adaptors, `Map` through `Flat
`DecodeUtf16`, and a `str`'s escapes, writes their fields as std's does, each iterator it
wraps by its own `Debug`, no closure, and the state each keeps, such as what a `Peekable` peeked, what a
`Skip` has left to skip, and the countdown std's `StepBy` of a small unsigned range keeps
in its end. So does `Debug` of std's sources, `Once`, `FromFn`, `RepeatWith`, and
`Successors`, an `Option`'s, a `Result`'s, and an array's iterators, a `CharIndices`, a
`String`'s `Drain`, and a slice's `Windows`, chunks, and splits, each writing what is left of
its slice as std's does, emptied where std's `nth` past the end empties a `Windows`; a hash
set's operations write the list a clone yields. A slice's `chunks_mut` and its forms are
refused, as std writes their slice's address. `Debug` of `Bound`, `Ordering`, `Reverse`, `AssertUnwindSafe`, and `ControlFlow` is
in its end. So does `Debug` of std's sources, `Once`, `OnceWith`, `FromFn`, `Repeat`,
`RepeatN`, `RepeatWith`, and `Successors`, an `Option`'s, a `Result`'s, and an array's
iterators, a `CharIndices`, a `String`'s `Drain`, and a slice's `Windows`, chunks, and
splits, each writing what is left of its slice as std's does, emptied where std's `nth` past
the end empties a `Windows`; a hash set's operations write the list a clone yields, and a
`BTreeSet`'s the way std picked to make each, by the iterators it reads, the set it looks
keys up in, and the key it peeked or holds back. A list's `ExtractIf` writes the item it
reads next, and a hash map's and set's nothing. A slice's `chunks_mut` and its forms are
refused, as std writes their slice's address, and so are a `str`'s searches, `Split` and
its forms, `Matches`, `MatchIndices`, `Lines`, and `SplitWhitespace`, as std writes its
searcher's state in UTF-8 bytes. `Debug` of `Bound`, `Ordering`, `Reverse`, `AssertUnwindSafe`, and `ControlFlow` is
their derived one, whichever way each is held, and a guard of a cell or a lock, mapped or
not, writes what it lends by its own `Debug` and `Display`. `Debug` of a `Cell`, a
`RefCell`, a `Mutex`, and an `RwLock` writes what each holds, or `<borrowed>` and
Expand Down
18 changes: 18 additions & 0 deletions ts/fixtures/lang/clones/expected/clones.Counted.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";

/** Logs its id as it is cloned, as `Logged` does, but drops as nothing. */
export interface Counted {
id: rt.u8;
log: rt.RefCell<rt.ByteVec>;
}

export function clone$Clone(self: Counted): Counted {
const _5: rt.RefCell<rt.ByteVec> = rt.refCellBorrowMut(self.log);
rt.byteVecPush(_5.value, 128 | self.id);
rt.refMutRelease(_5);
return { id: rt.u8WrappingAdd(self.id, 1), log: self.log };
}

//# sourceMappingURL=clones.Counted.ts.map
Loading