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
4 changes: 3 additions & 1 deletion quest/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ generic std gap is planned here even when moq never calls it.
- [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
- [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
- [Slice windows and chunks, Vec drain, and the order of byte arrays](/quest/m3/ts-slice-gaps.md) - `windows`, `chunks`, `Vec::drain`, and byte arrays' order translate
- [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
- [The rest of a slice's chunks](/quest/m3/ts-slice-chunks.md) - `chunks_exact`, `rchunks`, and the mutable chunks translate
- [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)`
- [Port the workflow guard to kixelated/quest](/quest/m3/quest-workflow-guard.md) - quest's environment guard parses YAML as this repository's does
17 changes: 17 additions & 0 deletions quest/m3/ts-bound-ranges.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# [XS] Ranges of Bounds

## Goal

rust2-ts translates `Vec::drain`, `VecDeque::drain`, and a B-tree's `range` and
`range_mut` of a `(Bound<T>, Bound<T>)`, an excluded start included, matching std's
items and panics. Proven by differential tests against native Rust.

## Plan

Each refuses with a span since [#259](https://github.com/moq-dev/rust2/pull/259): the
runtime's `bounds` reads std's range types alone, and read a tuple as unbounded. Reading
the tuple's `rt.RangeBound`s there, and an excluded start where `slice::range` and the
B-tree's search take one, covers all four. A crate's own `RangeBounds` stays refused
until it has a consumer. rust2 aims to support all of std.

Public API: the translator's output.
18 changes: 18 additions & 0 deletions quest/m3/ts-byte-keys.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# [S] Byte arrays compared for equality and hashed

## Goal

rust2-ts translates `==` and `!=` of byte arrays such as `[u8; 2]`, and a `[u8; N]`,
`&[u8]`, or `Vec<u8>` as a hash key or inside a tuple, `Option`, or `Arc` that is one,
matching std's equality and finding each key as std's map does. Proven by differential
tests against native Rust.

## Plan

Each refuses with a span today: `==` of byte arrays as a call over a reference to an array
of bytes, and a key as "comparing" or "hashing `[u8; 2]` as a key". Their order translates
through `rt.cmpBytes`, which reads each byte form, a typed array, an `rt.ByteSlice`, or an
`rt.ByteVec`, at run time ([#259](https://github.com/moq-dev/rust2/pull/259)); equality and
hashing can take the same approach. rust2 aims to support all of std.

Public API: the translator's output.
18 changes: 18 additions & 0 deletions quest/m3/ts-slice-chunks.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# [S] The rest of a slice's chunks

## Goal

rust2-ts translates a slice's `chunks_exact`, `rchunks`, `rchunks_exact`, and their
`_mut` forms, and `chunks_mut`, matching std's parts, remainders, and panics, and writing
through a mutable chunk into the slice it came from. Proven by differential tests against
native Rust.

## Plan

Each refuses with a span today. `windows` and `chunks` map to `rt.PartsIter` in
`rt/iter.ts` ([#259](https://github.com/moq-dev/rust2/pull/259)), which the others can
extend. A mutable chunk of a slice that is not bytes is a JS array copied by `slice`, so
writes through it would be lost: it needs a view or a place, as `iter_mut` lends one.
rust2 aims to support all of std.

Public API: the translator's output.
17 changes: 0 additions & 17 deletions quest/m3/ts-slice-gaps.md

This file was deleted.

6 changes: 6 additions & 0 deletions quest/m3/ts-unsafe.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,11 @@ none of its own `unsafe`.
[#252](https://github.com/moq-dev/rust2/pull/252) mapped them to and that must track
std's by hand. The lang fixture's `orders` differential case proves the translation
still matches std's comparisons, pop order, and drops.
- `Vec::drain` translates from std's MIR, whose `Drain` reads its range out and moves the
tail back through raw pointers into the `Vec`'s storage, replacing `rt.vecDrain` and
`rt.byteVecDrain`, the runtime port that
[the slice gaps' PR](https://github.com/moq-dev/rust2/pull/259) mapped it to. The lang
fixture's `slices::drains` differential case proves the translation still matches std's
items, drops, and what a forgotten drain leaves.

Public API: the translator's output.
20 changes: 12 additions & 8 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -247,8 +247,9 @@ A collection keeps Rust's key semantics. A hash map or set keeps a key that is a
number, string, or boolean in a JS `Map`, which compares those as Rust's `Eq` does, and
finds any other key, a 64-bit one past 2^53 included, through its translated `Hash` and
`Eq`; a B-tree orders every key by its translated `Ord`. std's impls are the runtime's: an
`Option` orders `None` first, and an `Arc` compares, orders, and hashes as what it holds,
so a map of `Arc<str>` finds a `&str`. A `&mut` to a value a map holds that JS copies,
`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. 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 All @@ -274,7 +275,9 @@ drop it where std's do. So do iterators: one that owns its items, as a `Vec`'s `
map's `drain` does, drops those it still holds by `[Symbol.dispose]`, an adaptor drops
what it skips or rejects, and a consumer that takes an iterator by value drops it:
through each `rt.Iter`'s own `fold` where std's folds, which drops each adaptor's closure
as its fold ends, before what it wraps, as std's does.
as its fold ends, before what it wraps, as std's does. A `Vec`'s `drain` leaves the vector
what precedes its range until it drops, then drops what it still holds and moves the tail
back, so one never dropped, as `mem::forget` leaves it, leaks the rest, as std's does.

A trait object of the crate's own trait, or a dependency's, behind `&`, `&mut`, `Box`, or `Arc`, is an object with
a method for each function a call can dispatch to, its supertraits' included, named for
Expand Down Expand Up @@ -543,11 +546,12 @@ they need.
- A `BinaryHeap` is std's heap in an array, with std's sifts ported to the runtime: std's
move elements through raw pointers into its `Vec`, which no body of std's lowers
through, and the sifts decide which `PartialOrd` tests run and which of equal elements
leaves first. The sorts, `max` and `min`, the heap, and `is_sorted` take an integer's
tests as the runtime's `rt.lt`, `rt.le`, `rt.gt`, and `rt.ge` rather than through its
`partial_cmp`, `rt.cmpLt(rt.cmp)`: on `just ts bench`'s `order/` workloads that took
Firefox 0.8-0.86x the time on sorts and `max`/`min` and Chrome 0.66x on the heap, and
Chrome the same on the rest.
leaves first. `Vec::drain` is ported for the same reason: std's reads its range out
and moves the tail back through raw pointers. The sorts, `max` and `min`, the heap,
and `is_sorted` take an integer's tests as the runtime's `rt.lt`, `rt.le`, `rt.gt`,
and `rt.ge` rather than through its `partial_cmp`, `rt.cmpLt(rt.cmp)`: on `just ts
bench`'s `order/` workloads that took Firefox 0.8-0.86x the time on sorts and
`max`/`min` and Chrome 0.66x on the heap, and Chrome the same on the rest.
- Iterators are the runtime's lazy classes rather than generators or ES iterator
helpers: std's adaptors would lower from std's own bodies, whose slice iterators are
raw pointers, ES helpers lack most of them
Expand Down
4 changes: 4 additions & 0 deletions ts/fixtures/lang/expected/core/cmp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ export function max$u8(v1: rt.u8, v2: rt.u8): rt.u8 {
return rt.max(v1, v2);
}

export function max$u8s(v1: Uint8Array, v2: Uint8Array): Uint8Array {
return rt.ordMax(v1, v2, rt.cmpLt(rt.cmpBytes));
}

export function maxBy$Item_cmps_closure1(v1: Item.Item, v2: Item.Item, compare: (a0: Item.Item, a1: Item.Item) => rt.Ordering): Item.Item {
let _0!: Item.Item;
let _10: boolean = false;
Expand Down
44 changes: 44 additions & 0 deletions ts/fixtures/lang/expected/core/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import type * as Dir from "../shapes.Dir.ts";
import type * as Meters from "../shapes.Meters.ts";
import type * as Point from "../shapes.Point.ts";
import type * as shapes_Shape from "../shapes.Shape.ts";
import { digest, digestWords } from "../slices.ts";
import type * as slices_Item from "../slices.Item.ts";
import type * as Short from "../splits.Short.ts";

export function isSomeAnd$Option_u8_bools_closure0(self: rt.u8 | undefined, f: (a0: rt.u8) => boolean): boolean {
Expand Down Expand Up @@ -242,6 +244,13 @@ export function map$Option_Hop_u64_u64_options_closure0(self: Hop.Hop | undefine
return f(self);
}

export function map$Option_Item_u8_drains_closure10(self: slices_Item.Item | undefined, f: (a0: slices_Item.Item) => rt.u8): rt.u8 | undefined {
if (self === undefined) {
return undefined;
}
return f(self);
}

export function map$Option_Named_Nameds_from_ref(self: Named.Named | undefined, _: (a0: Named.Named) => Named.Named[]): Named.Named[] | undefined {
if (self === undefined) {
return undefined;
Expand Down Expand Up @@ -270,6 +279,20 @@ export function map$Option_str_Cow_str_Borrowed(self: string | undefined, _: (a0
return self;
}

export function map$Option_u16s_u8_digest_words(self: rt.u16[] | undefined, _: (a0: rt.u16[]) => rt.u8): rt.u8 | undefined {
if (self === undefined) {
return undefined;
}
return digestWords(self);
}

export function map$Option_u32_u8_drains_closure5(self: rt.u32 | undefined, f: (a0: rt.u32) => rt.u8): rt.u8 | undefined {
if (self === undefined) {
return undefined;
}
return f(self);
}

export function map$Option_u8_Option_u8_made_closure1_closure0(self: rt.u8 | undefined, f: (a0: rt.u8) => rt.u8 | undefined): rt.u8 | undefined | rt.None {
if (self === undefined) {
return rt.None;
Expand Down Expand Up @@ -326,6 +349,20 @@ export function map$Option_u8_u8_u8_u8_lent_closure2(self: [rt.u8, rt.u8] | unde
return f(self);
}

export function map$Option_u8s_u8_digest(self: rt.ByteSlice | undefined, _: (a0: rt.ByteSlice) => rt.u8): rt.u8 | undefined {
if (self === undefined) {
return undefined;
}
return digest(self);
}

export function map$Option_u8s_u8_parts_closure1(self: rt.ByteSlice | undefined, f: (a0: rt.ByteSlice) => rt.u8): rt.u8 | undefined {
if (self === undefined) {
return undefined;
}
return f(self);
}

export function map$Option_unit_Option_u8_made_closure3(self: undefined | rt.None, f: (a0: undefined) => rt.u8 | undefined): rt.u8 | undefined | rt.None {
if (self === rt.None) {
return rt.None;
Expand Down Expand Up @@ -662,6 +699,13 @@ export function mapOr$Option_u8s_u8_skips_closure44(self: Uint8Array | undefined
return f(self);
}

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

export function mapOr$Option_u8s_u8s_u8_splits_closure0(self: [rt.ByteSlice, rt.ByteSlice] | undefined, default_: rt.u8, f: (a0: [rt.ByteSlice, rt.ByteSlice]) => rt.u8): rt.u8 {
if (self === undefined) {
return default_;
Expand Down
9 changes: 6 additions & 3 deletions ts/fixtures/lang/expected/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ import { locals } from "./locals.ts";
import { locks, relock, rwlocks } from "./locks.ts";
import { nested } from "./nested.ts";
import { objects } from "./objects.ts";
import { orders } from "./orders.ts";
import { orders, bytes as orders_bytes } from "./orders.ts";
import { lists, shared as pointers_shared, places, unchecked, nested as pointers_nested, copies as pointers_copies, sentinels } from "./pointers.ts";
import { refs, toRefs } from "./refs.ts";
import { copies as shapes_copies, order, discriminants, loops, patterns, closures, library, flows } from "./shapes.ts";
import { parts, drains } from "./slices.ts";
import { splits } from "./splits.ts";
import { statics, cells as statics_cells } from "./statics.ts";
import { strs, slices } from "./strs.ts";
Expand Down Expand Up @@ -88,7 +89,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, _318: rt.ByteSlice, out23: rt.ByteVec): void => {
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["fmt::rounding", (_2122: rt.u8, _327: 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 @@ -158,7 +159,9 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec)
returned(data55, out56);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["hashes::values", values] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["hashes::random", (_2156: rt.u8, data56: rt.ByteSlice, out57: rt.ByteVec): void => {
random(data56, out57);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["floats::formats", formats] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["floats::parses", parses] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]]).map(copy$str_forabfnu8au8bmutstdvecVecu8);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["floats::formats", formats] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["floats::parses", parses] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["orders::bytes", (_2157: rt.u8, data57: rt.ByteSlice, out58: rt.ByteVec): void => {
orders_bytes(data57, out58);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["slices::parts", parts] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void], ["slices::drains", drains] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => void]]).map(copy$str_forabfnu8au8bmutstdvecVecu8);
}

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