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 @@ -24,7 +24,7 @@ generic std gap is planned here even when moq never calls it.
- [Waiting: a slice of one byte behind any &mut](/quest/m3/ts-slice-of-one.md) - `slice::from_mut` and `array::from_mut` of a `&mut u8` translate once a consumer calls them
- [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 `Once`, `Repeat`, `FromFn`, an array's `IntoIter`, and std's other iterators writes what std'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
- [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
35 changes: 23 additions & 12 deletions quest/m3/ts-iter-source-debug.md
Original file line number Diff line number Diff line change
@@ -1,18 +1,29 @@
# [S] Debug of std's other iterators
# [M] Debug of std's other iterators

## Goal

[rust2-ts](/ts/README.md) translates `Debug` of std's iterators that still have no
mapping, so an adaptor over one writes what std's does instead of being refused:
iterator sources such as `Once`, `Repeat`, `RepeatN`, `FromFn`, `Successors`,
`OnceWith`, and `RepeatWith`, an array's and an `Option`'s or `Result`'s iterators, and
`str`'s iterators other than `Chars` and `Bytes`. Proven by differential tests against
native Rust.
[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.

## Plan

Found while translating `Debug` of the adaptors: `char::decode_utf16([..])` refuses at
its span, as `Debug` of `array::IntoIter` has no mapping. Read each of std's impls, which
write private fields of their own (`Once { inner: IntoIter { inner: Item { opt } } }`),
and survey which share a shape before choosing how the runtime writes them, as
`iter_debug` and `adaptor_debug` in `src/lower/fmt.rs` do.
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.

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.
7 changes: 6 additions & 1 deletion ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,12 @@ 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. `Debug` of `Bound`, `Ordering`, `Reverse`, `AssertUnwindSafe`, and `ControlFlow` is
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
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
15 changes: 15 additions & 0 deletions ts/fixtures/lang/shapes/expected/core/bool.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "../rt.ts";
import type * as Pair from "../fmt.Pair.ts";
import type * as Void from "../shapes.Void.ts";

export function thenSome$0ztng9q(self: boolean, t: rt.Result<rt.u16, Void.Void>): rt.Result<rt.u16, Void.Void> | undefined {
Expand All @@ -10,6 +11,20 @@ export function thenSome$0ztng9q(self: boolean, t: rt.Result<rt.u16, Void.Void>)
return t;
}

export function thenSome$1ou04rm(self: boolean, t: Pair.Pair): Pair.Pair | undefined {
if (!self) {
return undefined;
}
return t;
}

export function thenSome$0n2gkz4(self: boolean, t: rt.i32): rt.i32 | undefined {
if (!self) {
return undefined;
}
return t;
}

export function thenSome$0d5am30(self: boolean, t: rt.u8): rt.u8 | undefined {
if (!self) {
return undefined;
Expand Down
14 changes: 14 additions & 0 deletions ts/fixtures/lang/shapes/expected/core/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export function map$18z3v8h(self: Dir.Dir | undefined, _: (a0: Dir.Dir) => rt.u8
return from$convert_From_shapes_Dir_u8(self);
}

export function map$0phsnvg(self: rt.u8 | undefined, _: (a0: rt.u8) => rt.u8 | undefined): rt.u8 | undefined | rt.None {
if (self === undefined) {
return rt.None;
}
return self;
}

export function mapOr$1a3irjf(self: rt.ByteVec | undefined, default_: rt.u8, f: (a0: rt.ByteVec) => rt.u8): rt.u8 {
if (self === undefined) {
return default_;
Expand Down Expand Up @@ -106,6 +113,13 @@ export function okOr$1vxk0yk(self: rt.u8 | undefined, err: rt.u8): rt.Result<rt.
return rt.Ok(self);
}

export function andThen$1bd14ex(self: rt.u8 | undefined, f: (a0: rt.u8) => rt.u8 | undefined | rt.None): rt.u8 | undefined | rt.None {
if (self === undefined) {
return rt.None;
}
return f(self);
}

export function clone$0hmts8n(self: rt.u16[] | undefined): rt.u16[] | undefined {
if (self === undefined) {
return undefined;
Expand Down
Loading