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 @@ -28,8 +28,8 @@ generic std gap is planned here even when moq never calls it.
- [A deque's two slices](/quest/m3/ts-deque-slices.md) - `VecDeque::as_slices` and `{:?}` of a deque's `Iter`, `IterMut`, and `Drain` translate, split where std's are
- [ptr::replace whose result nothing reads](/quest/m3/ts-ptr-replace-unread.md) - `ptr::replace` with its result discarded type-checks
- [LinkedList](/quest/m3/ts-linked-list.md) - `LinkedList` and its methods translate
- [Saturating](/quest/m3/ts-saturating.md) - `Saturating<T>` and its std impls translate
- [Zip's next_back in constant time](/quest/m3/ts-zip-back.md) - a reversed zip of random-access iterators skips the longer side's excess at once
- [A B-tree's collect by std's sort and dedup](/quest/m3/ts-btree-collect-order.md) - collecting into a B-tree keeps the keys std's does when a key's impls disagree
- [Slices split by a predicate](/quest/m3/ts-slice-split.md) - `[T]::split` and its forms by a predicate translate
- [Boxed slices](/quest/m3/ts-boxed-slices.md) - `Box<[T]>` translates, made, read, and turned back into a `Vec`
- [Integers' inherent methods](/quest/m3/ts-int-methods.md) - `pow`, `abs`, and the other inherent methods of integers, `NonZero`, `Wrapping`, and `Saturating` translate
20 changes: 20 additions & 0 deletions quest/m3/ts-int-methods.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# [M] Integers' inherent methods

## Goal

[rust2-ts](/ts/README.md) translates the inherent methods of every integer width and of
`NonZero`, `Wrapping`, and `Saturating` of one with std's semantics, proven by differential
tests against native Rust at both bounds of each width.

## Plan

Found auditing `Saturating`: each of these refuses as "unsupported call", with its span:
`pow`, `abs`, `signum`, and the `checked_`, `wrapping_`, `saturating_`, and `overflowing_`
forms the runtime lacks, such as `wrapping_neg`, `saturating_pow`, and `saturating_abs`;
`NonZero`'s `saturating_pow` and `saturating_abs`; and `Wrapping`'s and `Saturating`'s own
`pow`, `abs`, `signum`, `count_ones`, `rotate_left`, `swap_bytes`, and the rest, which are
their integer's. The table of integer methods in `ts/src/lower/library.rs` is where each
goes; a wrapper's method is its integer's on the value it holds. No consumer calls them
yet; they are planned here as part of std.

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

This file was deleted.

3 changes: 2 additions & 1 deletion ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ crate translation reaches is refused, and so are two versions of one crate it re
| `u8`-`u32`, `i8`-`i32`, `usize`, `isize` | `rt.u8` and so on: a `number` branded with its type, checked: overflow panics |
| `u64`, `i64`, `u128`, `i128` | `rt.u64` and so on: a branded `number` while a safe integer, 32-bit limbs past 2^53, checked the same way |
| `Wrapping<T>` | the integer, whose operators wrap, and mask a shift's amount to the width, as std's do |
| `Saturating<T>` | the integer, whose operators saturate at its bounds, as std's do |
| `f64` | `rt.f64`: a `number` branded so, which is the same IEEE 754 double |
| `f32` | `rt.f32`: a `number` branded so, which a single holds exactly |
| `()`, `PhantomData<T>`, `PhantomPinned`, `..` | `undefined`, every value equal and hashing nothing; a type parameter only a `PhantomData` holds is `_T` in its struct's interface |
Expand Down Expand Up @@ -759,7 +760,7 @@ built natively for wasm32 and run beside its translation on the same inputs by
Bun bundles a caller of `Decoder.u8` and `Decoder.new` through `import * as Decoder`,
which must keep only those and what they call.
- `lang` covers every integer width's arithmetic and casts, `char`s next to each
encoding's edges and the surrogates, `Cow<str>` and `Cow<[T]>` borrowed and owned, `Wrapping` at every width, `Duration`s whose
encoding's edges and the surrogates, `Cow<str>` and `Cow<[T]>` borrowed and owned, `Wrapping` and `Saturating` at every width, `Duration`s whose
seconds pass 2^53 or reach `u64::MAX`, control flow,
patterns, `Copy` aggregates, those a container stores included and those written into
only in another module, behind a type parameter, or through a box, formatting, methods
Expand Down
30 changes: 29 additions & 1 deletion ts/fixtures/lang/caller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -629,4 +629,32 @@ function wraps(): Uint8Array[] {
return cases;
}

export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...singlesCases, ...singlesFormats, ...singlesParsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...closures, ...elements, ...ranges, ...reducers, ...sliceEdits, ...drains, ...iters, ...hinted, ...peekedOthers, ...hints, ...reserves, ...setOps, ...zeros, ...writes, ...floatsMulAdds, ...singlesMulAdds, ...unlikeEqs, ...ownNes, ...rangeFroms, ...compares, ...unlikeCompares, ...rangeMethods, ...wraps(), ...refOrders];
/**
* `saturates::*` of every kind at every width, over operands at the edges of its range and
* across them: 0, 1, either end, the sign bit's neighbors, which make `MIN / -1` and
* `MIN % -1`, and at 128 bits values past 2^64.
*/
function saturates(): Uint8Array[] {
const widths: [string, number][] = [["u8s", 8], ["u16s", 16], ["u32s", 32], ["u64s", 64], ["u128s", 128], ["usizes", 32], ["i8s", 8], ["i16s", 16], ["i32s", 32], ["i64s", 64], ["i128s", 128], ["isizes", 32]];
const cases: Uint8Array[] = [];
for (const [name, bits] of widths) {
const o = op(`saturates::${name}`);
const width = BigInt(bits);
const mask = (1n << width) - 1n;
const sign = 1n << (width - 1n);
const half = sign >> 1n;
const edges = [0n, 1n, 3n, mask, mask - 1n, sign, sign - 1n, sign + 1n, half, half + 1n, mask - half];
if (bits === 128) edges.push(1n << 64n, (1n << 64n) + 3n, 0x9e3779b97f4a7c150123456789abcdefn);
const be = (v: bigint) => Array.from({ length: bits / 8 }, (_, i) => Number((v >> BigInt(bits - 8 - 8 * i)) & 0xffn));
let i = 0;
for (const a of edges) {
for (const b of edges) {
const c = edges[(i++ * 5 + 3) % edges.length];
for (let kind = 0; kind < 24; kind++) cases.push(Uint8Array.of(o, kind, ...be(a), ...be(b), ...be(c)));
}
}
}
return cases;
}

export const cases: Uint8Array[] = [...loops, ...durations, ...ints(), ...utf8, ...floats, ...formats, ...parsed, ...singlesCases, ...singlesFormats, ...singlesParsed, ...dyns, ...cells, ...shared, ...locks, ...onces, ...bounds, ...unsafeCells, ...edits, ...subslices, ...consumers, ...closures, ...elements, ...ranges, ...reducers, ...sliceEdits, ...drains, ...iters, ...hinted, ...peekedOthers, ...hints, ...reserves, ...setOps, ...zeros, ...writes, ...floatsMulAdds, ...singlesMulAdds, ...unlikeEqs, ...ownNes, ...rangeFroms, ...compares, ...unlikeCompares, ...rangeMethods, ...wraps(), ...refOrders, ...saturates()];
3 changes: 2 additions & 1 deletion ts/fixtures/lang/expected/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import { objects } from "./objects.ts";
import { orders, bytes as orders_bytes, tuples as orders_tuples, held } from "./orders.ts";
import { lists, shared as pointers_shared, places as pointers_places, unchecked, nested as pointers_nested, copies as pointers_copies, sentinels, cells as pointers_cells, rebound as pointers_rebound, lapsed, writers, made as pointers_made, segments, uninitRuns, iteratedRuns } from "./pointers.ts";
import { refs, toRefs } from "./refs.ts";
import { u8s as saturates_u8s, u16s as saturates_u16s, u32s as saturates_u32s, u64s as saturates_u64s, u128s as saturates_u128s, usizes as saturates_usizes, i8s as saturates_i8s, i16s as saturates_i16s, i32s as saturates_i32s, i64s as saturates_i64s, i128s as saturates_i128s, isizes as saturates_isizes } from "./saturates.ts";
import { copies as shapes_copies, order as shapes_order, discriminants, loops, patterns, uninhabited, closures as shapes_closures, library, flows } from "./shapes.ts";
import { singles, mulAdds as singles_mulAdds, formats as singles_formats, parses as singles_parses } from "./singles.ts";
import { parts as slices_parts, chunked, subslices, drains as slices_drains, ranges as slices_ranges, edits as slices_edits } from "./slices.ts";
Expand Down Expand Up @@ -215,7 +216,7 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec)
iteratedRuns(data78, out79);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["zeros::writes", zeros_writes as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["orders::tuples", (_2179: rt.u8, data79: rt.ByteSlice, out80: rt.ByteVec): undefined => {
orders_tuples(data79, out80);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["tuples::tuples", tuples_tuples as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined]];
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["tuples::tuples", tuples_tuples as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::u8s", saturates_u8s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::u16s", saturates_u16s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::u32s", saturates_u32s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::u64s", saturates_u64s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::u128s", saturates_u128s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::usizes", saturates_usizes as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::i8s", saturates_i8s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::i16s", saturates_i16s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::i32s", saturates_i32s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::i64s", saturates_i64s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::i128s", saturates_i128s as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["saturates::isizes", saturates_isizes as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined]];
}

/** Run one case. */
Expand Down
49 changes: 49 additions & 0 deletions ts/fixtures/lang/expected/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import type * as Inner from "./pointers.Inner.ts";
import * as List from "./pointers.List.ts";
import type * as Outer from "./pointers.Outer.ts";
import type * as pointers_Pair from "./pointers.Pair.ts";
import * as saturates_Gauge from "./saturates.Gauge.ts";
import type * as shapes_Gauge from "./shapes.Gauge.ts";
import type * as shapes_Held from "./shapes.Held.ts";
import type * as Lens from "./shapes.Lens.ts";
Expand Down Expand Up @@ -265,6 +266,54 @@ export function copy$pointers_Pair(v: pointers_Pair.Pair): pointers_Pair.Pair {
return { a: v.a, b: v.b };
}

export function copy$saturates_Gauge_i128(v: saturates_Gauge.Gauge<rt.i128>): saturates_Gauge.Gauge<rt.i128> {
return new saturates_Gauge.Gauge(v._0);
}

export function copy$saturates_Gauge_i16(v: saturates_Gauge.Gauge<rt.i16>): saturates_Gauge.Gauge<rt.i16> {
return new saturates_Gauge.Gauge(v._0);
}

export function copy$saturates_Gauge_i32(v: saturates_Gauge.Gauge<rt.i32>): saturates_Gauge.Gauge<rt.i32> {
return new saturates_Gauge.Gauge(v._0);
}

export function copy$saturates_Gauge_i64(v: saturates_Gauge.Gauge<rt.i64>): saturates_Gauge.Gauge<rt.i64> {
return new saturates_Gauge.Gauge(v._0);
}

export function copy$saturates_Gauge_i8(v: saturates_Gauge.Gauge<rt.i8>): saturates_Gauge.Gauge<rt.i8> {
return new saturates_Gauge.Gauge(v._0);
}

export function copy$saturates_Gauge_isize(v: saturates_Gauge.Gauge<rt.isize>): saturates_Gauge.Gauge<rt.isize> {
return new saturates_Gauge.Gauge(v._0);
}

export function copy$saturates_Gauge_u128(v: saturates_Gauge.Gauge<rt.u128>): saturates_Gauge.Gauge<rt.u128> {
return new saturates_Gauge.Gauge(v._0);
}

export function copy$saturates_Gauge_u16(v: saturates_Gauge.Gauge<rt.u16>): saturates_Gauge.Gauge<rt.u16> {
return new saturates_Gauge.Gauge(v._0);
}

export function copy$saturates_Gauge_u32(v: saturates_Gauge.Gauge<rt.u32>): saturates_Gauge.Gauge<rt.u32> {
return new saturates_Gauge.Gauge(v._0);
}

export function copy$saturates_Gauge_u64(v: saturates_Gauge.Gauge<rt.u64>): saturates_Gauge.Gauge<rt.u64> {
return new saturates_Gauge.Gauge(v._0);
}

export function copy$saturates_Gauge_u8(v: saturates_Gauge.Gauge<rt.u8>): saturates_Gauge.Gauge<rt.u8> {
return new saturates_Gauge.Gauge(v._0);
}

export function copy$saturates_Gauge_usize(v: saturates_Gauge.Gauge<rt.usize>): saturates_Gauge.Gauge<rt.usize> {
return new saturates_Gauge.Gauge(v._0);
}

export function copy$shapes_Gauge(v: shapes_Gauge.Gauge): shapes_Gauge.Gauge {
return { level: v.level };
}
Expand Down
Loading