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
1 change: 0 additions & 1 deletion quest/m3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ 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
- [Checks on the differential harnesses](/quest/m3/ts-harness.md) - step lists that drift, literal op bytes, and `refs`'s coverage fail a test or get cases
- [Ordering in std](/quest/m3/ts-ordering.md) - `cmp::max`/`min`, `is_sorted`, and `BinaryHeap`, and #173's cost on integers measured
- [Arc's unique-access functions](/quest/m3/ts-arc-mut.md) - `Arc::get_mut`, `make_mut`, `pin`, and `as_deref` of an `Option<Arc>` translate
- [Debug and Display of Arc and ranges](/quest/m3/ts-fmt-wrappers.md) - `Arc<T>` formats as `T`, and ranges as std's `Debug`
Expand Down
20 changes: 0 additions & 20 deletions quest/m3/ts-harness.md

This file was deleted.

10 changes: 10 additions & 0 deletions ts/fixtures/lang/expected/refs.Held.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Generated by rust2-ts. Do not edit.

import type * as Nest from "./refs.Nest.ts";

/** A struct holding a reference, which is replaced. */
export interface Held {
at: Nest.Nest;
}

//# sourceMappingURL=refs.Held.ts.map
10 changes: 10 additions & 0 deletions ts/fixtures/lang/expected/refs.Nest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Generated by rust2-ts. Do not edit.

import type * as Pair from "./refs.Pair.ts";

/** A struct a reference points into. */
export interface Nest {
pair: Pair.Pair;
}

//# sourceMappingURL=refs.Nest.ts.map
45 changes: 45 additions & 0 deletions ts/fixtures/lang/expected/refs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ import { unwrapOr$Option_u32, unwrapOr$Option_u8, unwrapOr$Option_u8_u8, unwrapO
import * as Counts from "./refs.Counts.ts";
import * as Cursor from "./refs.Cursor.ts";
import type * as Fetch from "./refs.Fetch.ts";
import type * as Held from "./refs.Held.ts";
import * as Listing from "./refs.Listing.ts";
import type * as Nest from "./refs.Nest.ts";
import type * as Pair from "./refs.Pair.ts";
import type * as Pair2 from "./refs.Pair2.ts";

Expand Down Expand Up @@ -484,6 +486,7 @@ export function lent(data: rt.ByteSlice, out: rt.ByteVec): void {
defaulted(data, out);
taken(data, out);
elements(data, out);
kept(data, out);
}

/** Filled in place by its default, through a `&mut` and from a closure, then reset. */
Expand Down Expand Up @@ -1045,6 +1048,48 @@ export function elements(data: rt.ByteSlice, out: rt.ByteVec): void {
}
}

/**
* References kept in a tuple, read after the index or reference they were borrowed
* through changes: each part reads what it borrowed when the tuple was made.
*/
export function kept(data: rt.ByteSlice, out: rt.ByteVec): void {
const by: rt.u8 = unwrapOr$Option_u8(rt.byteSliceFirst(data), 4);
const v: Uint8Array = Uint8Array.of(1, 2, 3, 4);
const iter: rt.Iter<[rt.Place<rt.u8>, rt.u8]> = rt.iterZip(rt.iterSliceMut(rt.byteSliceView(rt.byteSliceFrom(v))), rt.iterSlice(rt.byteSliceView(data)), true);
while (true) {
const _13: [rt.Place<rt.u8>, rt.u8] | rt.Done = iter.next();
if (_13 === rt.DONE) {
break;
}
_13[0].v = _13[0].v ^ _13[1];
}
const _20: [Nest.Nest, Nest.Nest] = [{ pair: { n: by } }, { pair: { n: by ^ 255 } }];
const x: Nest.Nest = _20[0];
const y: Nest.Nest = _20[1];
let i: rt.usize = rt.usizeRem(by as rt.usize, rt.byteSliceFrom(v).length);
let r: Nest.Nest = x;
const held: Held.Held = { at: x };
const copied: Nest.Nest = r;
const _42: rt.usize = i;
if (!(_42 < 4)) {
rt.panic("index out of bounds: the len is " + 4 + " but the index is " + _42);
}
const _44: Pair.Pair = r.pair;
const _82: Nest.Nest = held.at;
const _48: Nest.Nest = held.at;
const part = v[_42];
i = rt.usizeRem(rt.usizeAdd(i, 1), rt.byteSliceFrom(v).length);
r = y;
held.at = y;
rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(part, _44.n, y.pair.n, _82.pair.n, copied.pair.n, _48.pair.n, copied.pair.n)));
const _73: rt.u8 = part ^ _44.n;
const _77: rt.usize = i;
if (!(_77 < 4)) {
rt.panic("index out of bounds: the len is " + 4 + " but the index is " + _77);
}
rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(Uint8Array.of(_73, v[_77], r.pair.n, held.at.pair.n)));
}

export function seenOf(data: rt.ByteSlice): rt.u8 | undefined {
return rt.byteSliceGet(data, 2);
}
Expand Down
45 changes: 45 additions & 0 deletions ts/fixtures/lang/src/refs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ fn lent(data: &[u8], out: &mut Vec<u8>) {
defaulted(data, out);
taken(data, out);
elements(data, out);
kept(data, out);
}

/// moq-net's listing: a crate type's default, made in place only while there is none.
Expand Down Expand Up @@ -663,6 +664,50 @@ fn elements(data: &[u8], out: &mut Vec<u8>) {
}
}

/// A struct a reference points into.
struct Nest {
pair: Pair,
}

/// A struct holding a reference, which is replaced.
struct Held<'a> {
at: &'a Nest,
}

/// References kept in a tuple, read after the index or reference they were borrowed
/// through changes: each part reads what it borrowed when the tuple was made.
fn kept(data: &[u8], out: &mut Vec<u8>) {
let by = data.first().copied().unwrap_or(4);
let mut v = [1u8, 2, 3, 4];
for (x, &b) in v.iter_mut().zip(data) {
*x ^= b;
}
let (x, y) = (
Nest { pair: Pair { n: by } },
Nest {
pair: Pair { n: by ^ 0xff },
},
);
let mut i = usize::from(by) % v.len();
let (mut r, q) = (&x, &y);
let mut held = Held { at: &x };
let copied = r;
let parts = (&v[i], &r.pair, &q.pair, &held.at.pair, &copied.pair, held.at, copied);
i = (i + 1) % v.len();
r = &y;
held.at = &y;
out.extend_from_slice(&[
*parts.0,
parts.1.n,
parts.2.n,
parts.3.n,
parts.4.n,
parts.5.pair.n,
parts.6.pair.n,
]);
out.extend_from_slice(&[*parts.0 ^ parts.1.n, v[i], r.pair.n, held.at.pair.n]);
}

fn seen_of(data: &[u8]) -> Option<u8> {
data.get(2).copied()
}
Expand Down
4 changes: 2 additions & 2 deletions ts/fixtures/stock/caller.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// The harness, with inputs it names for `differential.ts`: `buf::reserves`' edges of
// `rt.BytesMut`'s limit, which only these reach, as each allocates 512 MiB.

import { cases as all, run } from "./harness.ts";
import { op, run } from "./harness.ts";

export { run };

const reserves = all().length - 1;
const reserves = op("buf::reserves");

/** Each edge but shared storage past the limit, which throws, read past by none and by some. */
export const cases: Uint8Array[] = [0, 1, 2].flatMap((kind) => [0, 3].map((read) => Uint8Array.of(reserves, ...new TextEncoder().encode("edge"), kind, read)));
27 changes: 20 additions & 7 deletions ts/fixtures/stock/expected/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,38 @@ import { bytesMut, reserves, reads, writes, edits } from "./buf.ts";
import * as Owner from "./harness.Owner.ts";

/**
* Each case, which the first byte picks modulo their count, so a case added at the end
* moves no other.
* Each case's name and what it runs. The first byte picks one modulo their count, so a
* case added at the end moves no other.
*/
export function cases(): Array<(a0: rt.ByteSlice, a1: rt.ByteVec) => void> {
return [slices, made, events, random, bytesMut, reads, writes, edits, reserves];
export function cases(): [string, (a0: rt.ByteSlice, a1: rt.ByteVec) => void][] {
return [["slices", slices] as [string, (a0: rt.ByteSlice, a1: rt.ByteVec) => void], ["made", made] as [string, (a0: rt.ByteSlice, a1: rt.ByteVec) => void], ["events", events] as [string, (a0: rt.ByteSlice, a1: rt.ByteVec) => void], ["random", random] as [string, (a0: rt.ByteSlice, a1: rt.ByteVec) => void], ["buf::bytes_mut", bytesMut] as [string, (a0: rt.ByteSlice, a1: rt.ByteVec) => void], ["buf::reads", reads] as [string, (a0: rt.ByteSlice, a1: rt.ByteVec) => void], ["buf::writes", writes] as [string, (a0: rt.ByteSlice, a1: rt.ByteVec) => void], ["buf::edits", edits] as [string, (a0: rt.ByteSlice, a1: rt.ByteVec) => void], ["buf::reserves", reserves] as [string, (a0: rt.ByteSlice, a1: rt.ByteVec) => void]];
}

/** Run one case. */
export function run(input: rt.ByteSlice): rt.ByteVec {
const out: rt.ByteVec = new rt.ByteVec();
if (input.length !== 0) {
const op: rt.u8 = input.data[input.start];
const cases_: Array<(a0: rt.ByteSlice, a1: rt.ByteVec) => void> = cases();
cases_[rt.idx(cases_, rt.usizeRem(op as rt.usize, cases_.length))](new rt.ByteSlice(input.data, input.start + 1, input.length - 1), out);
const op_: rt.u8 = input.data[input.start];
const cases_: [string, (a0: rt.ByteSlice, a1: rt.ByteVec) => void][] = cases();
cases_[rt.idx(cases_, rt.usizeRem(op_ as rt.usize, cases_.length))][1](new rt.ByteSlice(input.data, input.start + 1, input.length - 1), out);
return out;
}
return out;
}

/** The first byte that picks the case named `name`, which `caller.ts` targets by. */
export function op(name: string): rt.u8 {
const _2: rt.usize | undefined = rt.iterPosition(rt.iterSlice(cases()), (_22: [string, (a0: rt.ByteSlice, a1: rt.ByteVec) => void]): boolean => {
return _22[0] === name;
});
if (_2 === undefined) {
const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, name)];
rt.panicFmt(["no case ", args2[0]]);
} else {
return _2 & 0xff;
}
}

/**
* `Bytes`'s slices by every kind of range, out of bounds included, which panic as
* `bytes` does, and what they compare equal to.
Expand Down
35 changes: 22 additions & 13 deletions ts/fixtures/stock/src/harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ use rand::RngExt;
/// What a case runs on the rest of the input.
type Case = fn(&[u8], &mut Vec<u8>);

/// Each case, which the first byte picks modulo their count, so a case added at the end
/// moves no other.
fn cases() -> Vec<Case> {
/// Each case's name and what it runs. The first byte picks one modulo their count, so a
/// case added at the end moves no other.
fn cases() -> Vec<(&'static str, Case)> {
vec![
slices,
made,
events,
random,
crate::buf::bytes_mut,
crate::buf::reads,
crate::buf::writes,
crate::buf::edits,
crate::buf::reserves,
("slices", slices),
("made", made),
("events", events),
("random", random),
("buf::bytes_mut", crate::buf::bytes_mut),
("buf::reads", crate::buf::reads),
("buf::writes", crate::buf::writes),
("buf::edits", crate::buf::edits),
("buf::reserves", crate::buf::reserves),
]
}

Expand All @@ -30,10 +30,19 @@ pub fn run(input: &[u8]) -> Vec<u8> {
return out;
};
let cases = cases();
cases[usize::from(op) % cases.len()](data, &mut out);
let (_, case) = cases[usize::from(op) % cases.len()];
case(data, &mut out);
out
}

/// The first byte that picks the case named `name`, which `caller.ts` targets by.
pub fn op(name: &str) -> u8 {
match cases().iter().position(|&(n, _)| n == name) {
Some(i) => i as u8,
None => panic!("no case {name}"),
}
}

/// `Bytes`'s slices by every kind of range, out of bounds included, which panic as
/// `bytes` does, and what they compare equal to.
fn slices(data: &[u8], out: &mut Vec<u8>) {
Expand Down
2 changes: 1 addition & 1 deletion ts/fixtures/stock/ts.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
package = "stock-fixture"
roots = ["harness::run"]
roots = ["harness::run", "harness::op"]
10 changes: 6 additions & 4 deletions ts/fixtures/task/src/harness.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
//! Runs a script of executor steps and returns the log: the native side of the
//! differential test, which `tests/task.ts` mirrors step for step on the translation.
//!
//! Each step is two bytes, an op and its argument. Channels and tasks are picked by the
//! argument, modulo how many there are; a step with nothing to pick does nothing. Once
//! the script ends, every task drops in order, then every channel.
//! Each step is two bytes, an op and its argument, and logs its name, so the two sides
//! differ wherever their lists do. Channels and tasks are picked by the argument, modulo
//! how many there are; a step with nothing to pick does nothing. Once the script ends,
//! every task drops in order, then every channel.

use crate::drops;
use crate::exec::Executor;
Expand All @@ -19,7 +20,8 @@ pub fn run(input: &[u8]) -> Vec<u8> {
let steps = steps();
for step in input.chunks(2) {
let (op, arg) = (step[0], step.get(1).copied().unwrap_or(0));
let (_, run_step) = steps[usize::from(op) % steps.len()];
let (name, run_step) = steps[usize::from(op) % steps.len()];
log.note(format!("step {name}"));
run_step(&log, &mut exec, &mut channels, arg);
}
for t in 0..exec.len() {
Expand Down
3 changes: 2 additions & 1 deletion ts/tests/task.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,8 @@ export function harness<V>(f: Fixture<V>): (input: Uint8Array) => Bytes {
const exec = new Executor(note, f.Pending);
const r: Run<V> = { f, log, note, exec, channels: [] };
for (let i = 0; i < input.length; i += 2) {
const [, step] = steps[input[i] % steps.length];
const [name, step] = steps[input[i] % steps.length];
note(`step ${name}`);
step(r, input[i + 1] ?? 0);
}
for (let t = 0; t < exec.tasks.length; t++) exec.drop(t);
Expand Down