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 @@ -23,7 +23,7 @@ generic std gap is planned here even when moq never calls it.
- [Trait objects](/quest/m3/ts-dyn.md) - `dyn Error`, `dyn Iterator`, `dyn Buf`, and `Arc<dyn Debug>` translate, so a consumer neither rewrites nor binds them
- [Placeholders written to a crate's own fmt::Write](/quest/m3/ts-fmt-calls.md) - `write!` with placeholders into a crate's own writer translates, its `write_str` seeing each call std makes
- [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
- [A zip of TrustedLen iterators folded by its size hint](/quest/m3/ts-zip-fold.md) - `count` and the other folds of a `zip` of `TrustedLen` iterators read only the pairs its size hint holds
- [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
- [References to byte arrays std takes](/quest/m3/ts-byte-refs-taken.md) - `extend` by references to arrays, adaptors' closures over held arrays, and a collection of both forms translate
Expand Down
34 changes: 0 additions & 34 deletions quest/m3/ts-range-fold.md

This file was deleted.

19 changes: 19 additions & 0 deletions quest/m3/ts-zip-fold.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# [S] A zip of TrustedLen iterators folded by its size hint

## Goal

[rust2-ts](/ts/README.md) folds a `zip` of two `TrustedLen` iterators as std's `SpecFold`
does: `fold`, and what std folds through it (`count`, `last`, `for_each`, `sum`, and a
`TrustedLen` `collect`), reads as many pairs as its size hint's upper bound and no
further, so `r.by_ref().zip(0..n).count()` of a longer `RangeInclusive` leaves `r` read
`n` times, proven by a differential test against native Rust.

## Plan

Found by [#301](https://github.com/moq-dev/rust2/pull/301) on 2026-10-30. `rt.ZipIter`
reads `a` once past a shorter `b` in every fold, as std's does only by `try_fold` (`any`,
`find`, `position`) and for iterators that aren't `TrustedLen`. `rt.Iter.folded()` serves
both `fold` and `try_fold`, which agree for every other adaptor, so the zip needs a way to
tell them apart.

Public API: the translator's output.
2 changes: 1 addition & 1 deletion ts/fixtures/codec/expected/bench.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,7 @@ export function iterate(chain: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void
} else if (chain === 2) {
putUsize(out, rt.iterToByteVec(rt.iterFilter(rt.iterSlice(rt.byteSliceView(data)), (_28: rt.u8): boolean => {
return (_28 & 1) === 1;
})).length);
}), "next").length);
} else if (chain === 3) {
putU64(out, rt.iterSum(rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (_2: rt.u8): rt.u32 => {
return _2 as rt.u32;
Expand Down
6 changes: 3 additions & 3 deletions ts/fixtures/lang/expected/bounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ export function bounds(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
rt.iterExtendBytes(out, rt.btreeValues(map), undefined, true);
const _199: rt.Iter<rt.u8> = rt.iterSlice(rt.byteSliceView(rt.byteSliceRange(data, 4)));
const set: rt.BTreeSet<rt.u8> = rt.btreeExtendKeys(rt.btreeNew(rt.cmp) as rt.BTreeSet<rt.u8>, _199, true, undefined, undefined, 1, true);
rt.iterExtendBytes(out, rt.iterRev(rt.btreeRangeKeys(set, range2)));
rt.iterExtendBytes(out, rt.iterRev(rt.btreeRangeKeys(set, range2)), "next");
rt.byteVecPush(out, within$Bound_u8_Bound_u8(set, range2) & 0xff);
} else if (_28 === 4) {
const empty: rt.BTreeMap<rt.u8, Item.Item> = rt.btreeNew(rt.cmp) as rt.BTreeMap<rt.u8, Item.Item>;
Expand Down Expand Up @@ -285,7 +285,7 @@ export function bounds(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
const _263: [rt.RangeBound<Key.Key>, rt.RangeBound<Key.Key>] = [bound$Key(s, a2), bound$Key(e, b2)];
rt.iterExtendBytes(out, rt.iterMap(rt.btreeRangeKeys(set3, _263, Key.eq$PartialEq, rt.cmpGt(Key.partialCmp$PartialOrd)), (k3: Key.Key): rt.u8 => {
return k3._0;
}));
}), "next");
flush(out);
const _272: [rt.RangeBound<Key.Key>, rt.RangeBound<Key.Key>] = [bound$Key(s, a2), bound$Key(e, b2)];
const iter6: rt.Iter<[Key.Key, rt.Place<rt.u8>]> = rt.btreeRangeMut(map2, _272, Key.eq$PartialEq, rt.cmpGt(Key.partialCmp$PartialOrd));
Expand All @@ -308,7 +308,7 @@ export function bounds(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
const _308: [rt.RangeBound<[rt.u8, Key.Key]>, rt.RangeBound<[rt.u8, Key.Key]>] = [bound$u8_Key(s, a3), bound$u8_Key(e, b3)];
rt.iterExtendBytes(out, rt.iterMap(rt.btreeRangeKeys(pairs, _308, rt.eqTuple([rt.same, Key.eq$PartialEq]), rt.cmpGt(rt.cmpTuple([rt.cmp, Key.partialCmp$PartialOrd]))), (_25: [rt.u8, Key.Key]): rt.u8 => {
return _25[0];
}));
}), "next");
flush(out);
}
flush(out);
Expand Down
2 changes: 1 addition & 1 deletion ts/fixtures/lang/expected/chars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export function chars(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
} else if (_4 === 2) {
const cs: rt.char[] = rt.iterToArray(rt.iterFilterMap(rt.iterSlice(scalars(data)), (a0: rt.u32): rt.char | undefined => {
return rt.charFromU32(a0);
}), undefined, 4);
}), "next", 4);
const sorted: rt.BTreeSet<rt.char> = rt.btreeNew(rt.cmp) as rt.BTreeSet<rt.char>;
const seen: rt.HashSet<rt.char> = rt.hashNew() as rt.HashSet<rt.char>;
const iter3: rt.Iter<[rt.usize, rt.char]> = rt.iterEnumerate(rt.iterSlice(cs));
Expand Down
Loading