Skip to content
2 changes: 1 addition & 1 deletion quest/m2/ts-model/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Public API: the translator's output for moq-net's model.
- [Shared ownership](/quest/m2/ts-shared.md) - kio's waiters are `Arc`/`Weak` with observable counts, and its atomics and locks are plain values
- [Float formatting](/quest/m2/ts-model/floats.md) - `f64` formats and parses as std does
- [The rest of std the model reaches](/quest/m2/ts-model/std-rest.md) - `Vec` and `VecDeque` capacity, and `RandomState`
- [std gaps kio reaches](/quest/m2/ts-model/kio-std.md) - `array::from_fn`, `Default` of arrays and `()`, maps of `Option`s, and `trailing_zeros`
- [std gaps kio reaches](/quest/m2/ts-model/kio-std.md) - `trailing_zeros` of every integer width and `NonZero`
- [hashbrown as the runtime's map](/quest/m2/ts-model/hashbrown.md) - hashlink's `hashbrown` tables translate as `rt.HashMap`, with std's capacity
- [A write through a mutable reference to a library object](/quest/m2/ts-model/library-place.md) - `*r = v` out of an `Option` writes the slot, not a copy, and `mem::take` of a `&mut Vec` and writes through guards and map lookups translate
- [bytes' BytesMut, Buf, and BufMut](/quest/m2/ts-model/bytes.md) - map without config, so the model's `BytesMut` binding goes
Expand Down
14 changes: 5 additions & 9 deletions quest/m2/ts-model/kio-std.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# [S] std gaps kio reaches
# [XS] std gaps kio reaches

## Goal

rust2-ts translates the std that kio reaches and no other quest owns, proven by
differential tests against native Rust: `array::from_fn`, `Default` of arrays (kio's
`[Atomic<u64>; 8]::default()`) and of `()`, a `HashMap` whose values are `Option`s
(`shared.rs`), and `trailing_zeros` of every integer width and `NonZero` (`task.rs`).
differential tests against native Rust: `trailing_zeros` of every integer width and
`NonZero` (`task.rs`).

## Plan

Expand All @@ -15,10 +14,7 @@ Found by [#167](https://github.com/kixelated/rust2/pull/167) and
[the rest of std](/quest/m2/ts-model/std-rest.md), whose capacity work is a hot-path change
of its own.

- `Default` and `from_fn` of an array run element by element in index order, which an
element whose constructor has effects or panics observes.
- A map of `Option`s needs its `Option`-returning methods (`get`, `insert`, `remove`) to
tell `None` from `Some(None)`; [#134](https://github.com/kixelated/rust2/pull/134) gave
`rt.None` for that.
- `leading_zeros` already maps per width; `trailing_zeros` can follow it, including the
wide integers' representation.

Public API: the translator's output.
2 changes: 1 addition & 1 deletion ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ These fail translation: formatting and parsing an `f64`, and `f64::clamp`, whose
that drops given to a std function that drops it beside another value that drops, as
`for_each` of items that drop does, or keeps it other than in an iterator adaptor, and
values that drop in some iterators ([drop order](/quest/m3/ts-drop-order.md)), a `Cow` of other than `str`,
a collection holding a type that can be `undefined`, as `()` and `Option` can, a std
a collection's key or item of a type that can be `undefined`, as `()` and `Option` can (a map's value can be), a std
function without a mapping of its own that makes or reads an `Option` whose `None` is
`rt.None`, as `find` over `Option`s does, an `Option` of an `Option` of `()` or another
`Option`, an instance of a generic type whose field is an `Option` of a type parameter
Expand Down
97 changes: 97 additions & 0 deletions ts/fixtures/lang/expected/arrays.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";

/** Each byte an operation, its value the operand; each puts what it read. */
export function fromFns(data: rt.ByteSlice, out: rt.ByteVec): void {
let s!: string;
for (const op of rt.byteSliceView(data)) {
const _10: rt.u8 = rt.u8Rem(op, 5);
if (_10 === 0) {
const seen: rt.usize[] = [];
const bytes: Uint8Array = rt.bytesFromFn(4, (i6: rt.usize): rt.u8 => {
seen.push(i6);
return rt.u8WrappingMul(op, rt.u8Add(i6 & 0xff, 1));
});
const wide: rt.u64[] = rt.arrayFromFn(3, (i7: rt.usize): rt.u64 => {
return rt.u64Shl(op as rt.u64, rt.usizeMul(i7, 30));
});
const _23: rt.ByteSlice = rt.byteSliceFrom(bytes);
const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(rt.byteSliceView(_23), f, rt.u8Debug), (f: rt.Formatter) => rt.fmtList(wide, f, rt.u64Debug), (f: rt.Formatter) => rt.fmtList(seen, f, rt.usizeDebug)];
s = rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2]]);
} else if (_10 === 1) {
const counts: rt.Atomic<rt.u64>[] = rt.arrayFromFn(8, (_2: rt.usize): rt.Atomic<rt.u64> => {
return new rt.Atomic(op as rt.u64);
});
const _37: rt.usize = rt.u8Rem(op, 8) as rt.usize;
if (!(_37 < 8)) {
rt.panic("index out of bounds: the len is " + 8 + " but the index is " + _37);
}
rt.atomicFetch(counts[_37], rt.u64WrappingAdd, 1, 0);
const copy: rt.Atomic<rt.u64>[] = rt.arrayFromFn(8, (i4: rt.usize): rt.Atomic<rt.u64> => {
if (!(i4 < 8)) {
rt.panic("index out of bounds: the len is " + 8 + " but the index is " + i4);
}
return new rt.Atomic(rt.atomicLoad(counts[i4], 0));
});
rt.atomicStore(copy[0], 0, 0);
const loads: rt.u64[] = rt.arrayFromFn(8, (i5: rt.usize): rt.u64 => {
if (!(i5 < 8)) {
rt.panic("index out of bounds: the len is " + 8 + " but the index is " + i5);
}
return rt.atomicLoad(counts[i5], 0);
});
const _57: rt.u64 = rt.atomicLoad(copy[0], 0);
const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(loads, f, rt.u64Debug), (f: rt.Formatter) => rt.u64Display(_57, f)];
s = rt.fmtFormat([args4[0], " ", args4[1]]);
} else if (_10 === 2) {
const args6: rt.Fmt[] = [(f: rt.Formatter) => rt.u8Display(op, f)];
const captured = rt.fmtFormat(["w", args6[0]]);
const words: string[] = rt.arrayFromFn(3, (i2: rt.usize): string => {
const args14: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtPad(f, captured), (f: rt.Formatter) => rt.usizeDisplay(i2, f)];
return rt.fmtFormat([args14[0], args14[1]]);
});
const _79: string[] = rt.arrayFromFn(0, (i3: rt.usize): string => {
return rt.fmtToString((f: rt.Formatter) => rt.usizeDisplay(i3, f));
});
const args8: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(words, f, rt.fmtStr), (f: rt.Formatter) => rt.fmtList(_79, f, rt.fmtStr)];
s = rt.fmtFormat([args8[0], " ", args8[1]]);
} else if (_10 === 3) {
const grid: Uint8Array[] = rt.arrayFromFn(3, (i: rt.usize): Uint8Array => {
return rt.bytesFromFn(2, (j: rt.usize): rt.u8 => {
return rt.u8WrappingAdd(op, rt.usizeAdd(rt.usizeMul(i, 2), j) & 0xff);
});
});
const named: rt.u16[] = rt.arrayFromFn(4, doubled);
const args10: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(grid, f, (value: Uint8Array, f: rt.Formatter) => rt.fmtList(value, f, rt.u8Debug)), (f: rt.Formatter) => rt.fmtList(named, f, rt.u16Debug)];
s = rt.fmtFormat([args10[0], " ", args10[1]]);
} else {
const _108: rt.usize[] = counted$2(op);
const _110: rt.usize[] = counted$5(op);
const args12: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtList(_108, f, rt.usizeDebug), (f: rt.Formatter) => rt.fmtList(_110, f, rt.usizeDebug)];
s = rt.fmtFormat([args12[0], " ", args12[1]]);
}
rt.byteVecExtendFromSlice(out, rt.stringAsBytes(s));
rt.byteVecPush(out, 10);
}
}

export function doubled(i: rt.usize): rt.u16 {
return rt.u16Mul(i & 0xffff, 2);
}

/** An array as long as `N` says, of `N` instances. */
export function counted$2(op: rt.u8): rt.usize[] {
return rt.arrayFromFn(2, (i: rt.usize): rt.usize => {
return rt.usizeAdd(rt.usizeMul(i, 2), op as rt.usize);
});
}

/** An array as long as `N` says, of `N` instances. */
export function counted$5(op: rt.u8): rt.usize[] {
return rt.arrayFromFn(5, (i: rt.usize): rt.usize => {
return rt.usizeAdd(rt.usizeMul(i, 5), op as rt.usize);
});
}

//# sourceMappingURL=arrays.ts.map
Loading