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 @@ -28,7 +28,8 @@ generic std gap is planned here even when moq never calls it.
- [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
- [References to byte-array keys a collection yields](/quest/m3/ts-byte-key-refs.md) - `keys`, `iter`, `get_key_value`, and `HashSet::get` of a `[u8; N]` key translate
- [Set operations](/quest/m3/ts-set-ops.md) - `union`, `intersection`, `difference`, and `symmetric_difference` of hash and B-tree sets translate
- [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
- [Size hints of std's iterators](/quest/m3/ts-size-hints.md) - `size_hint` translates, and `Vec`'s collect and extend panic past `isize::MAX` as std's do
- [Peekable::next_if_eq against another type](/quest/m3/ts-next-if-eq-other.md) - `next_if_eq` with an expected value of another type than the item, such as a `&str` of `String` items, translates
- [A closure's () result as a value](/quest/m3/ts-unit-closures.md) - a closure returning `()` whose result is a value, as in a `Vec<()>` collected from `map`, type-checks
Expand Down
17 changes: 0 additions & 17 deletions quest/m3/ts-byte-key-refs.md

This file was deleted.

20 changes: 20 additions & 0 deletions quest/m3/ts-byte-refs-taken.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# [M] References to byte arrays std takes

## Goal

The calls still refused as "of a reference to an array of bytes it is generic over"
translate, proven by differential tests against native Rust: a collection of `[u8; N]`
extended by references to arrays, std's adaptors handing their closure a reference to a
`[u8; N]` item they hold (`filter` over owned arrays, `map` then `collect` over a map's
`iter`), and a collection holding a `&[u8; N]` beside a `[u8; N]`.

## Plan

The reject fixture's `byte_extended`, `filter_owned_bytes`, and `byte_key` show each.
`extend` would store the `rt.ByteSlice` it is given where the collection holds a
`Uint8Array`, so it copies each. An adaptor's closure takes a slice of the item, as
`collections::lend_closure` wraps a collection's. A collection holding both forms can't
tell a held `&[u8; N]` from a lent one by the instantiated type alone; the method's generic
signature, `&K` against `K`, can.

Public API: the translator's output.
16 changes: 16 additions & 0 deletions quest/m3/ts-set-ops.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# [S] Set operations

## Goal

`union`, `intersection`, `difference`, and `symmetric_difference` of a `HashSet` and a
`BTreeSet` translate, each yielding what std's iterator yields in std's order for a
B-tree, proven by a differential test against native Rust that covers `[u8; N]` elements.

## Plan

Each is an unsupported call today for every element type. A hash set's order is the
runtime's, so the hash forms need only yield the same elements; a B-tree's merge order is
std's. Their items are `&T`, which the collection mappings already lend as a slice where
`T` is a `[u8; N]`.

Public API: the translator's output.
5 changes: 3 additions & 2 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,9 @@ finds any other key, a 64-bit one past 2^53 included, through its translated `Ha
`Option` orders `None` first, an `Arc` compares, orders, and hashes as what it holds,
so a map of `Arc<str>` finds a `&str`, and byte arrays, slices, and vectors order by their
bytes and then their length, and compare and hash alike whatever their form, so a map of
`Vec<u8>` finds a `&[u8]`. A collection's reference to a byte array it holds as a key, as
`keys` and `HashSet::get` return, is refused. A `&mut` to a value a map holds that JS copies,
`Vec<u8>` finds a `&[u8]`. A collection's reference to a byte array it holds, as `keys`,
`HashSet::get`, and `retain`'s closure get one, is an `rt.ByteSlice` of its bytes, as a
`&[u8; N]` is elsewhere; a `&mut` writes where the collection holds them. A `&mut` to a value a map holds that JS copies,
such as a number, from `get_mut` or the entry API, is an `rt.Place` whose `v` reads and
writes the map's slot. A hash map iterates in an order
of the runtime's, mostly insertion order, which std leaves unspecified, and hashes a key
Expand Down
14 changes: 14 additions & 0 deletions ts/fixtures/lang/expected/core/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,27 @@ export function mapOr$1t0muvr(self: rt.u8 | undefined, default_: rt.usize, f: (a
return f(self);
}

export function mapOr$1w1gbwl(self: rt.ByteSlice | undefined, default_: rt.u8, f: (a0: rt.ByteSlice) => rt.u8): rt.u8 {
if (self === undefined) {
return default_;
}
return f(self);
}

export function mapOr$0sl5app(self: Uint8Array | undefined, default_: rt.u8, f: (a0: Uint8Array) => rt.u8): rt.u8 {
if (self === undefined) {
return default_;
}
return f(self);
}

export function mapOr$1be3nsj(self: [rt.ByteSlice, rt.u8] | undefined, default_: rt.u8, f: (a0: [rt.ByteSlice, rt.u8]) => rt.u8): rt.u8 {
if (self === undefined) {
return default_;
}
return f(self);
}

export function mapOr$0z7fb2w(self: rt.ByteSlice | undefined, default_: Uint8Array, f: (a0: rt.ByteSlice) => Uint8Array): Uint8Array {
if (self === undefined) {
return default_;
Expand Down
6 changes: 3 additions & 3 deletions ts/fixtures/lang/expected/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import { values, random, bytes as hashes_bytes } from "./hashes.ts";
import { holds } from "./holds.ts";
import { u8Op, u16Op, u32Op, u64Op, u128Op, usizeOp, i8Op, i16Op, i32Op, i64Op, i128Op, isizeOp, i8Neg, i16Neg, i32Neg, i64Neg, i128Neg, isizeNeg, cast as ints_cast, convert, parses as ints_parses, widenings } from "./ints.ts";
import { adaptors, consumers, reducers, skips, ranked, ranges, options, own, values as iters_values, returned } from "./iters.ts";
import { keys, overrides, bytes as keys_bytes } from "./keys.ts";
import { keys, overrides, bytes as keys_bytes, lentKeys, lentValues } from "./keys.ts";
import { locals } from "./locals.ts";
import { locks, relock, rwlocks } from "./locks.ts";
import { nested } from "./nested.ts";
Expand Down Expand Up @@ -90,7 +90,7 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec)
refs(data21, out21);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::counts", (_2121: rt.u8, data22: rt.ByteSlice, out22: rt.ByteVec): void => {
counts(data22, out22);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::rounding", (_2122: rt.u8, _399: rt.ByteSlice, out23: rt.ByteVec): void => {
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::rounding", (_2122: rt.u8, _3100: rt.ByteSlice, out23: rt.ByteVec): void => {
rounding(out23);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["iters::skips", skips] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["wrappers::wrappers", wrappers] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["edits::edits", edits] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["utf8::decodes", decodes] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["floats::floats", floats] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["atomics::atomics", atomics] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::overrides", overrides] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["dyns::dyns", (_2123: rt.u8, data23: rt.ByteSlice, out24: rt.ByteVec): void => {
dyns(data23, out24);
Expand Down Expand Up @@ -182,7 +182,7 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec)
asSlices(data66, out67);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["ints::widenings", widenings] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["shapes::uninhabited", (_2167: rt.u8, data67: rt.ByteSlice, out68: rt.ByteVec): void => {
uninhabited(data67, out68);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]];
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::lent_keys", lentKeys] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["keys::lent_values", lentValues] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]];
}

/** Run one case. */
Expand Down
Loading