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 @@ -33,7 +33,7 @@ generic std gap is planned here even when moq never calls it.
- [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
- [std's impls of its zero-sized types](/quest/m3/ts-zero-sized-impls.md) - `PhantomData`'s derived impls translate, and `()` is a hash or B-tree key
- [An array's map](/quest/m3/ts-array-map.md) - `<[T; N]>::map` translates, calling its closure on each element in order
- [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
- [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
18 changes: 18 additions & 0 deletions quest/m3/ts-zero-sized-impls.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# [S] std's impls of its zero-sized types

## Goal

`PhantomData`'s `Debug`, `Default`, `PartialEq`, and the other impls `#[derive]` calls on a
field of it translate, and `()` is a hash or B-tree key and the item of a
`collect::<Option<_>>`, proven by differential tests against native Rust.

## Plan

Found by [#304](https://github.com/moq-dev/rust2/pull/304) on 2026-10-30: a struct deriving
`Debug`, `Default`, or `PartialEq` with a `PhantomData` field is refused as an unsupported
call to its impl, and `HashSet<()>`, `BTreeSet<()>`, `HashMap<(), _>`, and collecting
`Option<()>` items refuse `()` as a key, as an ordered value, and as an `Option` whose
`None` is `rt.None`. The crate's own unit structs already translate in each. Each impl
of `PhantomData` reads nothing; its `Debug` writes its type's name, `PhantomData<u8>`.

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

This file was deleted.

10 changes: 7 additions & 3 deletions ts/fixtures/lang/caller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -497,8 +497,8 @@ const hints = Array.from({ length: 24 * 8 * 8 * 8 * 2 }, (_, i) => {

/** `hints::reserves` of each collection and element type, each shape, length, and limit on what it reads. */
const reservesOp = op("hints::reserves");
const reserves = Array.from({ length: 13 * 5 * 5 * 4 * 5 }, (_, i) =>
Uint8Array.of(reservesOp, i % 65, Math.floor(i / 65) % 5, Math.floor(i / 325) % 4, Math.floor(i / 1300)),
const reserves = Array.from({ length: 13 * 6 * 5 * 4 * 5 }, (_, i) =>
Uint8Array.of(reservesOp, i % 78, Math.floor(i / 78) % 5, Math.floor(i / 390) % 4, Math.floor(i / 1560)),
);

/**
Expand All @@ -517,4 +517,8 @@ const setOps = [
].map((data) => Uint8Array.of(setOpsOp, 3, ...data)),
];

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::zeros` of each case, on up to three bytes. */
const zerosOp = op("zeros::zeros");
const zeros = Array.from({ length: 7 * 4 }, (_, i) => Uint8Array.of(zerosOp, i % 7, ...Array.from({ length: Math.floor(i / 7) }, (_, b) => b)));

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];
6 changes: 4 additions & 2 deletions ts/fixtures/lang/expected/arrays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,11 @@ export function asSlices(data: rt.ByteSlice, out: rt.ByteVec): void {
rt.sliceCopyFromSlice(all[_93], [op as rt.u32, (((op as rt.u32)) << 20) >>> 0]);
rt.sliceSwap(all, 0, 1);
} else if (_22 === 5) {
(([] as rt.u16[])).reverse();
const _108: rt.u16[] = [];
_108.reverse();
rt.byteSliceFill(rt.byteSliceFrom(Uint8Array.of()), op);
rt.byteVecPush(out, rt.u8Add((([] as rt.u16[])).length & 0xff, rt.byteSliceFrom(Uint8Array.of()).length & 0xff));
const _117: rt.u16[] = [];
rt.byteVecPush(out, rt.u8Add(_117.length & 0xff, rt.byteSliceFrom(Uint8Array.of()).length & 0xff));
} else if (_22 === 6) {
written(rt.byteSliceFrom(bytes), wide, op);
} else {
Expand Down
8 changes: 8 additions & 0 deletions ts/fixtures/lang/expected/core/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import * as Made from "../defaults.Made.ts";
import type * as Shape from "../dyns.Shape.ts";
import * as Named from "../edits.Named.ts";
import type * as Big from "../hints.Big.ts";
import type * as Unit from "../hints.Unit.ts";
import type * as Quarter from "../iters.Quarter.ts";
import type * as Tilt from "../iters.Tilt.ts";
import { side, order } from "../keys.ts";
Expand Down Expand Up @@ -719,6 +720,13 @@ export function mapOr$1cxlmys(self: Big.Big[] | undefined, default_: rt.usize, f
return f(self);
}

export function mapOr$0r2th8w(self: Unit.Unit[] | undefined, default_: rt.usize, f: (a0: Unit.Unit[]) => rt.usize): rt.usize {
if (self === undefined) {
return default_;
}
return f(self);
}

export function mapOr$1kiffmd(self: rt.u16[] | undefined, default_: rt.u8, f: (a0: rt.u16[]) => rt.u8): rt.u8 {
if (self === undefined) {
return default_;
Expand Down
3 changes: 2 additions & 1 deletion ts/fixtures/lang/expected/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import { statics, cells as statics_cells, onces } from "./statics.ts";
import { strs, slices, edits as strs_edits, parses as strs_parses, iters, drains as strs_drains, hinted } from "./strs.ts";
import { decodes } from "./utf8.ts";
import { wrappers } from "./wrappers.ts";
import { zeros } from "./zeros.ts";

/**
* Each case's name and what it runs. The first byte picks one modulo their count, so a
Expand Down Expand Up @@ -187,7 +188,7 @@ export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec)
uninhabited(data67, out68);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["keys::lent_keys", lentKeys as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["keys::lent_values", lentValues as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["singles::singles", singles as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["singles::formats", singles_formats as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["singles::parses", singles_parses as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["iters::peeked_others", (_2168: rt.u8, data68: rt.ByteSlice, out69: rt.ByteVec): undefined => {
peekedOthers(data68, out69);
}] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["hints::hints", hints as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["hints::reserves", reserves as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["collections::set_ops", setOps as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["folds::folds", folds 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], ["hints::hints", hints as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["hints::reserves", reserves as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["collections::set_ops", setOps as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["folds::folds", folds as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["zeros::zeros", zeros 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
28 changes: 28 additions & 0 deletions ts/fixtures/lang/expected/hints.Unit.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Generated by rust2-ts. Do not edit.

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

export function clone$Clone(_self: Unit): Unit {
return {};
}

export function eq$PartialEq(_self: Unit, _other: Unit): boolean {
return true;
}

export function partialCmp$PartialOrd(_self: Unit, _other: Unit): rt.Ordering | undefined {
return 0;
}

export function cmp$Ord(_self: Unit, _other: Unit): rt.Ordering {
return 0;
}

export function hash$Hash_DefaultHasher(_self: Unit, _state: rt.Hasher): void {
}

/** Zero-sized, whose derived `clone` assigns nothing. */
export interface Unit {
}

//# sourceMappingURL=hints.Unit.ts.map
Loading