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,13 +28,13 @@ generic std gap is planned here even when moq never calls it.
- [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
- [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
- [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
- [std accessors with no mapping](/quest/m3/ts-unmapped-accessors.md) - `VecDeque::swap_remove_*`, `HashSet::replace`, `BTreeSet::get`, `take`, and `replace`, `Vec::pop_if`, and `Arc` and `Rc::into_inner` translate
- [Equality of std containers of unlike elements](/quest/m3/ts-eq-unlike.md) - `==` and `next_if_eq` of a `Vec<Left>` against a `&[Right]`, and of `VecDeque` against `Vec`, translate
- [Integers' little- and native-endian bytes](/quest/m3/ts-int-ne-bytes.md) - each integer's `from_le_bytes`, `to_ne_bytes`, and `from_ne_bytes` translate
- [mul_add rounded once](/quest/m3/ts-mul-add.md) - `f64::mul_add` and `f32::mul_add` translate, rounding once as std's fused multiply-add does
- [Waiting: a slice object for a mutable part of other values](/quest/m3/ts-slice-object.md) - waits on a moq profile showing the `Proxy` view's traps matter, then decides on an `rt.ByteSlice`-like form
- [Port the workflow guard to kixelated/quest](/quest/m3/quest-workflow-guard.md) - quest's environment guard parses YAML as this repository's does
- [A VecDeque's Debug](/quest/m3/ts-deque-debug.md) - `{:?}` of a `VecDeque` translates, writing std's list
- [A parameter read only where lowering leaves nothing](/quest/m3/ts-unread-params.md) - an instance whose lowering drops every read of a parameter marks it unused, so `tsc` accepts it
- [Zero-sized values made out of sight](/quest/m3/ts-zero-sized.md) - unit structs and empty arrays returned, and std adaptors of only zero-sized fields, translate
- [Array keys a collection holds](/quest/m3/ts-array-keys.md) - collections of `[T; N]` keys type-check
Expand Down
15 changes: 15 additions & 0 deletions quest/m3/ts-deque-debug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# [XS] A VecDeque's Debug

## Goal

[rust2-ts](/ts/README.md) translates `{:?}` of a `VecDeque<T>`, writing the same text as
std's list, proven by a differential test against native Rust.

## Plan

Found by [#303](https://github.com/moq-dev/rust2/pull/303): `format!("{q:?}")` of a
`VecDeque<()>` refuses with `unsupported call to <VecDeque<()> as Debug>::fmt`, for any
`T`. `fmt.rs` maps `Vec`'s and `BinaryHeap`'s `Debug` to `rt.list`; a deque needs its
elements in order from its head, as its iterator reads them.

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

This file was deleted.

5 changes: 5 additions & 0 deletions quest/m3/ts-unread-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ nothing to drop the `if` lowers to nothing. `analyze` in `ts/src/lower/mir/mod.r
parameters by MIR's reads, before lowering drops the empty branch. moq's collector drops,
so no consumer hits it at the pin.

[#303](https://github.com/moq-dev/rust2/pull/303) found another: comparing `()`s folds to
`true`, so `units.iter().filter(|u| **u == ())` lowers to
`(u: undefined): boolean => { return true; }`, which `tsc` refuses as `'u' is declared but
its value is never read`.

Public API: the translator's output.
4 changes: 2 additions & 2 deletions quest/m3/ts-zero-sized.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ zero-sized fields, as `iter::from_fn` of a closure capturing nothing is.

Found by `hints.rs` in the lang fixture. The first emits `return _0` of a return place
`unassigned` skips, which `tsc` rejects, and the second refuses as "constructing
`std::iter::FromFn<..>` from another crate". Once they translate, along with
[ts-unit-closures](/quest/m3/ts-unit-closures.md), `hints::reserves` covers a `Vec` of
`std::iter::FromFn<..>` from another crate". Once they translate (a closure's `()` result
already does, since [#303](https://github.com/moq-dev/rust2/pull/303)), `hints::reserves` covers a `Vec` of
zero-sized elements, which holds `usize::MAX`, and `hints::hints` a flatten of `[T; 0]`.

Public API: the translator's output.
3 changes: 3 additions & 0 deletions ts/MIGRATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

## Unreleased

- A closure, a `fn` pointer, a `dyn Fn`, or a function item as a value returns
`undefined` for `()`, not `void`, as in `(a0: rt.u8) => undefined`: a caller passes such
a parameter a function typed `=> undefined`.
- An instance of a generic std function, such as `core/option.ts`'s, is named for a hash
of its text, `map$1cf8u0y`, rather than for its type arguments and the closure of one
of the instances merged into it, `map$Option_u64_u64_rescale_closure0`. A caller that
Expand Down
1 change: 1 addition & 0 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ crate translation reaches is refused, and so are two versions of one crate it re
| `Ordering`, `DefaultHasher`, `RandomState` | `rt.Ordering`, which is `-1`, `0`, or `1`; `rt.Hasher`; `rt.RandomState`, the keys of the `DefaultHasher` it builds, never changed once made |
| `Duration` | `rt.Duration`: `{ secs, nanos }`, std's whole seconds as an `rt.u64` and the nanoseconds past them, never changed once made |
| closure | an arrow function, with `[Symbol.dispose]` if it owns a value that drops |
| `fn` pointer, function item as a value | the function, as a closure is typed: a `()` result is `undefined`, where a declared function returns `void` |
| `&dyn Trait`, `&mut dyn Trait`, `Box<dyn Trait>`, `Arc<dyn Trait>` | an object with the trait's methods, its supertraits' included: `shape.area$Shape()`; behind an `Arc`, an `rt.ArcDyn` sharing the count of the `Arc` it was made from |
| `dyn Any` | an instance of the class its value's type was wrapped in, which a downcast checks for: `a instanceof Any.Square ? a.v : undefined` |
| `dyn Fn`, `dyn FnMut`, `dyn FnOnce` | the closure or function it was made of: `(a0: rt.u8) => rt.u32` |
Expand Down
8 changes: 4 additions & 4 deletions ts/fixtures/bind/expected/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ export function run(input: rt.ByteSlice): rt.ByteVec {
export function keys(input: rt.ByteSlice, bytes: Blob.Blob, out: rt.ByteVec): void {
let _12!: rt.usize;
let _143!: rt.u8;
const seen: rt.HashSet<Blob.Blob> = rt.hashNew(rt.hashing(Blob.hash$Hash, Blob.eq$PartialEq, true)) as rt.HashSet<Blob.Blob>;
const counts: rt.HashMap<Blob.Blob, rt.u8> = rt.hashNew(rt.hashing(Blob.hash$Hash, Blob.eq$PartialEq, true)) as rt.HashMap<Blob.Blob, rt.u8>;
const seen: rt.HashSet<Blob.Blob> = rt.hashNew(rt.hashing(Blob.hash$Hash as (a0: Blob.Blob, a1: rt.Hasher) => undefined, Blob.eq$PartialEq, true)) as rt.HashSet<Blob.Blob>;
const counts: rt.HashMap<Blob.Blob, rt.u8> = rt.hashNew(rt.hashing(Blob.hash$Hash as (a0: Blob.Blob, a1: rt.Hasher) => undefined, Blob.eq$PartialEq, true)) as rt.HashMap<Blob.Blob, rt.u8>;
const sorted: rt.BTreeSet<Blob.Blob> = rt.btreeNew(Blob.cmp$Ord) as rt.BTreeSet<Blob.Blob>;
const firsts: rt.BTreeMap<Blob.Blob, rt.u8> = rt.btreeNew(Blob.cmp$Ord) as rt.BTreeMap<Blob.Blob, rt.u8>;
const _10: rt.usize = Blob.len(bytes);
Expand Down Expand Up @@ -125,8 +125,8 @@ export function keys(input: rt.ByteSlice, bytes: Blob.Blob, out: rt.ByteVec): vo
rt.byteVecPush(out, rt.hashDelete(seen, probe) ? 1 : 0);
rt.byteVecPush(out, rt.btreeDelete(sorted, probe) ? 1 : 0);
rt.byteVecPush(out, rt.hashLen(seen) & 0xff);
const nibbles: rt.HashSet<Nibble.Nibble> = rt.hashNew(rt.hashing(Nibble.hash$Hash, Nibble.eq$PartialEq, true)) as rt.HashSet<Nibble.Nibble>;
const lasts: rt.HashMap<Nibble.Nibble, rt.u8> = rt.hashNew(rt.hashing(Nibble.hash$Hash, Nibble.eq$PartialEq, true)) as rt.HashMap<Nibble.Nibble, rt.u8>;
const nibbles: rt.HashSet<Nibble.Nibble> = rt.hashNew(rt.hashing(Nibble.hash$Hash as (a0: Nibble.Nibble, a1: rt.Hasher) => undefined, Nibble.eq$PartialEq, true)) as rt.HashSet<Nibble.Nibble>;
const lasts: rt.HashMap<Nibble.Nibble, rt.u8> = rt.hashNew(rt.hashing(Nibble.hash$Hash as (a0: Nibble.Nibble, a1: rt.Hasher) => undefined, Nibble.eq$PartialEq, true)) as rt.HashMap<Nibble.Nibble, rt.u8>;
const ordered: rt.BTreeSet<Nibble.Nibble> = rt.btreeNew(Nibble.cmp$Ord) as rt.BTreeSet<Nibble.Nibble>;
const values: rt.BTreeMap<Nibble.Nibble, rt.u8> = rt.btreeNew(Nibble.cmp$Ord) as rt.BTreeMap<Nibble.Nibble, rt.u8>;
for (const byte of rt.byteSliceView(input)) {
Expand Down
4 changes: 2 additions & 2 deletions ts/fixtures/codec/expected/coding/decode.Decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as rt from "../rt.ts";
import * as DecodeError from "../coding/decode.DecodeError.ts";
import { read } from "../coding/varint.ts";
import type * as Form from "../coding/varint.Form.ts";
import { mapErr$06mnjtr, inspectErr$0f2ndta } from "../core/result.ts";
import { mapErr$06mnjtr, inspectErr$156koiv } from "../core/result.ts";
import type * as Control from "../stats.Control.ts";

/**
Expand Down Expand Up @@ -158,7 +158,7 @@ export function bytes(self: Decoder): rt.Result<rt.ByteSlice, DecodeError.Decode
return { tag: "BoundsExceeded" } as DecodeError.DecodeError;
});
if (_3.ok) {
return inspectErr$0f2ndta(slice(self, _3.value), (_22: DecodeError.DecodeError): void => {
return inspectErr$156koiv(slice(self, _3.value), (_22: DecodeError.DecodeError): undefined => {
self.buf = start;
});
}
Expand Down
2 changes: 1 addition & 1 deletion ts/fixtures/codec/expected/core/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function mapErr$06mnjtr(self: rt.Result<rt.usize, rt.TryFromIntError>, op
return rt.Err(op(self.error));
}

export function inspectErr$0f2ndta(self: rt.Result<rt.ByteSlice, DecodeError.DecodeError>, f: (a0: DecodeError.DecodeError) => void): rt.Result<rt.ByteSlice, DecodeError.DecodeError> {
export function inspectErr$156koiv(self: rt.Result<rt.ByteSlice, DecodeError.DecodeError>, f: (a0: DecodeError.DecodeError) => undefined): rt.Result<rt.ByteSlice, DecodeError.DecodeError> {
if (!self.ok) {
f(self.error);
}
Expand Down
6 changes: 3 additions & 3 deletions ts/fixtures/codec/expected/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ import type * as Version from "./lite/version.Version.ts";
* Each case, which the first byte picks 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 [decodeScript, encodeScript, zigzag, sizes, roundtrip$Versions, roundtripLite$Group, roundtripLite$Probe, encodeMessages, errors];
export function cases(): Array<(a0: rt.ByteSlice, a1: rt.ByteVec) => undefined> {
return [decodeScript as (a0: rt.ByteSlice, a1: rt.ByteVec) => undefined, encodeScript as (a0: rt.ByteSlice, a1: rt.ByteVec) => undefined, zigzag as (a0: rt.ByteSlice, a1: rt.ByteVec) => undefined, sizes as (a0: rt.ByteSlice, a1: rt.ByteVec) => undefined, roundtrip$Versions as (a0: rt.ByteSlice, a1: rt.ByteVec) => undefined, roundtripLite$Group as (a0: rt.ByteSlice, a1: rt.ByteVec) => undefined, roundtripLite$Probe as (a0: rt.ByteSlice, a1: rt.ByteVec) => undefined, encodeMessages as (a0: rt.ByteSlice, a1: rt.ByteVec) => undefined, errors as (a0: rt.ByteSlice, a1: rt.ByteVec) => undefined];
}

/** 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();
const cases_: Array<(a0: rt.ByteSlice, a1: rt.ByteVec) => undefined> = 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);
return out;
}
Expand Down
8 changes: 4 additions & 4 deletions ts/fixtures/lang/expected/bounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ export function LOG$init(): rt.RefCell<rt.ByteVec> {
}

export function log(entry: rt.u8): void {
rt.localKeyWithBorrowMut(LOG, (log_: rt.ByteVec): void => {
rt.localKeyWithBorrowMut(LOG, (log_: rt.ByteVec): undefined => {
rt.byteVecPush(log_, entry);
});
}

/** Puts what was logged since the last flush. */
export function flush(out: rt.ByteVec): void {
rt.localKeyWithBorrowMut(LOG, (log_: rt.ByteVec): void => {
rt.localKeyWithBorrowMut(LOG, (log_: rt.ByteVec): undefined => {
rt.byteVecExtendFromSlice(out, rt.byteVecSlice(log_));
rt.byteVecClear(log_);
});
Expand Down Expand Up @@ -115,8 +115,8 @@ export function within$Bound_u8_Bound_u8(set: rt.BTreeSet<rt.u8>, range: [rt.Ran
* kinds of the range's bounds, the next two their values, and the rest are the items.
*/
export function bounds(kind: rt.u8, data: rt.ByteSlice, out: rt.ByteVec): void {
rt.localKeyWithBorrowMut(LOG, (a0: rt.ByteVec): void => {
return rt.byteVecClear(a0);
rt.localKeyWithBorrowMut(LOG, (a0: rt.ByteVec): undefined => {
rt.byteVecClear(a0);
});
if (data.length >= 4) {
const s: rt.u8 = data.data[data.start];
Expand Down
Loading