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 @@ -35,7 +35,6 @@ generic std gap is planned here even when moq never calls it.
- [Fresh writes beside a zipped iterator that points at a part](/quest/m3/ts-fresh-shapes.md) - zipping slots with a `Vec<[T; N]>`, `vec![row; n]`, or `copied` of what the slot holds translates
- [Python's wake on the loop's own thread](/quest/m3/ffi-python-wake.md) - a wake on the event loop's thread resumes the future with no socket pair
- [Python's call cost](/quest/m3/ffi-python-calls.md) - a call on an object costs what BoltFFI's does, or the gap is explained
- [A map built with BuildHasherDefault](/quest/m3/ts-build-hasher-default.md) - `FxHashMap`-style maps, of `BuildHasherDefault` over a crate's own `Hasher`, translate
- [A name or an operator argument at its own Rust span](/quest/m3/ts-argument-spans.md) - a `tsc` error on a plain-name or operator argument names that argument's Rust, not the method it is passed to
- [A panic's Location](/quest/m3/ts-panic-location.md) - `Location::caller` and `#[track_caller]` translate with native Rust's locations
- [A panic hook](/quest/m3/ts-panic-hook.md) - `set_hook`, `take_hook`, and `PanicHookInfo` translate, every panic running the hook
Expand Down
21 changes: 0 additions & 21 deletions quest/m3/ts-build-hasher-default.md

This file was deleted.

2 changes: 1 addition & 1 deletion ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ crate translation reaches is refused, and so are two versions of one crate it re
| a range a drain or a B-tree's `range` takes | itself, or of a type other than std's ranges and a pair of `Bound`s, `rt.boundsOf` of it and its `start_bound` and `end_bound`, which the runtime calls where std's does; one that drops, the parameter of the call `rt.dropAfter` makes, which drops it once the call returns, as std drops it before it does anything JS can see |
| `HashMap`, `HashSet`, `BTreeMap`, `BTreeSet`, `VecDeque`, `LinkedList`, `BinaryHeap` | `rt.HashMap<K, V>` and so on, each a plain object whose functions are the runtime's: `rt.hashGet(map, key)` |
| `PeekMut<T>` | `rt.PeekMut<T>`, the `rt.Place` of a heap's greatest element, which sifts it down as it drops once `DerefMut` lent it |
| `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 |
| `Ordering`, `DefaultHasher`, `RandomState`, `BuildHasherDefault<H>` | `rt.Ordering`, which is `-1`, `0`, or `1`; `rt.Hasher`; `rt.RandomState`, the keys of the `DefaultHasher` it builds, never changed once made; `undefined`, as `PhantomData` is, whose `build_hasher` is `H::default()` |
| `Duration` | `rt.Duration`: `{ secs, nanos }`, std's whole seconds as an `rt.u64` and the nanoseconds past them, never changed once made |
| `Layout`, `alloc::alloc` | `rt.Layout`: `{ size, align }`, never changed once made, checked as std's constructors check it; `alloc` gives an `rt.Block` of its bytes, which a cast of its pointer to `*mut T` the body shows came from `alloc` or `realloc` makes a JS array of `T`s, values JS copies, as an `rt.AtIndex` of its first; a cast back to `*mut u8` only as what `dealloc` or `realloc` takes, which free the array or copy it into a new one; its bytes, read, written, or cast to any other type, are refused, and fail at run time through a pointer from elsewhere |
| closure | an arrow function, with `[Symbol.dispose]` if it owns a value that drops, and what makes its clone if a clone can't be itself |
Expand Down
6 changes: 3 additions & 3 deletions ts/fixtures/lang/cells/expected/cells.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as rt from "./rt.ts";
import { out$Option_u8, out$u64, out$u8 } from "./lib.ts";
import { thenSome$0d5am30 } from "./core/bool.ts";
import { unwrapOr$0r2bmpr as option_unwrapOr$0r2bmpr } from "./core/option.ts";
import { err$1nbmqmx, map$1ma2nl9 as result_map$1ma2nl9, map$0l5uclx as result_map$0l5uclx, map$14n87rz as result_map$14n87rz, map$0h1vl84 as result_map$0h1vl84, map$03hz3l7 as result_map$03hz3l7, map$0yqi183 as result_map$0yqi183 } from "./core/result.ts";
import { err$1nbmqmx, map$1ma2nl9 as result_map$1ma2nl9, map$0l5uclx as result_map$0l5uclx, map$14n87rz as result_map$14n87rz, map$0h1vl84 as result_map$0h1vl84, map$03hz3l7 as result_map$03hz3l7, map$1916nm0 as result_map$1916nm0 } from "./core/result.ts";

/** Steps of an operation and an operand on one cell, each putting what it read. */
export function cellOption(dataData: Uint8Array, dataStart: number, dataLen: number, out: rt.ByteVec): void {
Expand Down Expand Up @@ -907,7 +907,7 @@ export function cellUnit(dataData: Uint8Array, dataStart: number, dataLen: numbe
} else {
const _179: rt.OnceCell<undefined, rt.None> = cell;
result = rt.onceGetOrTryInit(cell, (): rt.Result<undefined, rt.u8> => {
return made$unit(make, option_unwrapOr$0r2bmpr(err$1nbmqmx(result_map$0yqi183(rt.onceGetOrTryInit(_179, (): rt.Result<undefined, rt.u8> => {
return made$unit(make, option_unwrapOr$0r2bmpr(err$1nbmqmx(result_map$1916nm0(rt.onceGetOrTryInit(_179, (): rt.Result<undefined, rt.u8> => {
return made$unit(make, v2 ^ 1);
}, undefined, rt.None), (_23: undefined): undefined => {})), v2));
}, undefined, rt.None);
Expand Down Expand Up @@ -2047,7 +2047,7 @@ export function lockUnit(dataData: Uint8Array, dataStart: number, dataLen: numbe
} else {
const _179: rt.OnceLock<undefined, rt.None> = cell;
result = rt.onceGetOrTryInit(cell, (): rt.Result<undefined, rt.u8> => {
return made$unit(make, option_unwrapOr$0r2bmpr(err$1nbmqmx(result_map$0yqi183(rt.onceGetOrTryInit(_179, (): rt.Result<undefined, rt.u8> => {
return made$unit(make, option_unwrapOr$0r2bmpr(err$1nbmqmx(result_map$1916nm0(rt.onceGetOrTryInit(_179, (): rt.Result<undefined, rt.u8> => {
return made$unit(make, v2 ^ 1);
}, undefined, rt.None), (_23: undefined): undefined => {})), v2));
}, undefined, rt.None);
Expand Down
4 changes: 2 additions & 2 deletions ts/fixtures/lang/cells/expected/core/result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ export function map$03hz3l7(self: rt.Result<rt.u8, rt.u8>, op: (a0: rt.u8) => un
return self as rt.Result<undefined, rt.u8>;
}

export function map$0yqi183(self: rt.Result<undefined, rt.u8>, op: (a0: undefined) => undefined): rt.Result<undefined, rt.u8> {
export function map$1916nm0(self: rt.Result<undefined, rt.u8>, op: (a0: undefined) => undefined): rt.Result<undefined, rt.u8> {
if (self.ok) {
op(self.value);
op(undefined);
return rt.OK;
}
return self;
Expand Down
4 changes: 4 additions & 0 deletions ts/fixtures/lang/hashes/expected/hashes.Fnv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ export interface Fnv {
_0: rt.u64;
}

export function default$Default(): Fnv {
return { _0: { hi: 0xcbf29ce4, lo: 0x84222325 } as rt.u64 };
}

export function finish$hash_Hasher(self: Fnv): rt.u64 {
return self._0;
}
Expand Down
10 changes: 10 additions & 0 deletions ts/fixtures/lang/hashes/expected/hashes.Key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

import * as rt from "./rt.ts";
import * as Fnv from "./hashes.Fnv.ts";
import * as Tally from "./hashes.Tally.ts";

export function clone$Clone(self: Key): Key {
return { _0: self._0, _1: self._1 };
}

export function eq$cmp_PartialEq(self: Key, other: Key): boolean {
if (!(self._0 === other._0)) {
Expand All @@ -20,6 +25,11 @@ export function hash$Hash_hashes_Fnv(self: Key, state: Fnv.Fnv): void {
rt.hashStr(self._1, new rt.OwnHasher(state, Fnv.hasher$hash_Hasher));
}

export function hash$Hash_hashes_Tally(self: Key, state: Tally.Tally): void {
rt.hash16(self._0, new rt.OwnHasher(state, Tally.hasher$hash_Hasher));
rt.hashStr(self._1, new rt.OwnHasher(state, Tally.hasher$hash_Hasher));
}

export function partialCmp$cmp_PartialOrd(self: Key, other: Key): rt.Ordering | undefined {
return cmp$cmp_Ord(self, other);
}
Expand Down
39 changes: 39 additions & 0 deletions ts/fixtures/lang/hashes/expected/hashes.Tallied.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Generated by rust2-ts. Do not edit.

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

export function default$Default(): Tallied {
const _1: rt.u8 = 0;
undefined;
return { tag: _1, state: undefined };
}

export function clone$Clone(self: Tallied): Tallied {
const _2: rt.u8 = self.tag;
undefined;
return { tag: _2, state: undefined };
}

export function fmt$fmt_Debug(self: Tallied, f: rt.Formatter): rt.Result<undefined, rt.FmtError> {
const _3: string = "Tallied";
const _4: string = "tag";
const _5: rt.Fmt = (f: rt.Formatter) => rt.u8Debug(self.tag, f);
const _7: string = "state";
const _8: rt.Fmt = (f: rt.Formatter) => rt.fmtWriteStr(f, "BuildHasherDefault");
return rt.debugStructFinish(rt.debugStructField(rt.debugStructField(rt.fmtDebugStruct(f, _3), _4, _5), _7, _8));
}

export function eq$cmp_PartialEq(self: Tallied, other: Tallied): boolean {
if (!(self.tag === other.tag)) {
return false;
}
return true;
}

/** `BuildHasherDefault` held in a field, its impls derived. */
export interface Tallied {
tag: rt.u8;
state: undefined;
}

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

import * as rt from "./rt.ts";
import { event } from "./hashes.ts";

/**
* A `Hasher` of the crate's own that `BuildHasherDefault` builds, logging each one
* `Default` makes, each byte written, each finish, and each drop.
*/
export class Tally {
_0: rt.u64;

constructor(_0: rt.u64) {
this._0 = _0;
}

[Symbol.dispose](): void {
drop$ops_Drop(this);
}
}

export function default$Default(): Tally {
event(110, 0);
return new Tally(0);
}

export function finish$hash_Hasher(self: Tally): rt.u64 {
event(102, rt.u64Low(self._0) & 0xff);
return self._0;
}

/** The methods of `hashes::Tally`'s impl, which the runtime's hashing calls. */
export const hasher$hash_Hasher: rt.HasherImpl<Tally> = { write: write$hash_Hasher as (a0: Tally, a1: rt.ByteSlice) => undefined, finish: finish$hash_Hasher };

export function write$hash_Hasher(self: Tally, bytes: rt.ByteSlice): void {
for (const b of rt.byteSliceView(bytes)) {
event(119, b);
self._0 = rt.u64WrappingAdd(rt.u64WrappingMul(self._0, 31), b as rt.u64);
}
}

export function drop$ops_Drop(self: Tally): void {
event(100, rt.u64Low(self._0) & 0xff);
}

//# sourceMappingURL=hashes.Tally.ts.map
97 changes: 97 additions & 0 deletions ts/fixtures/lang/hashes/expected/hashes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import * as Sided from "./hashes.Sided.ts";
import * as Small from "./hashes.Small.ts";
import * as Spread from "./hashes.Spread.ts";
import * as Switch from "./hashes.Switch.ts";
import * as Tallied from "./hashes.Tallied.ts";
import * as Tally from "./hashes.Tally.ts";

/** `DefaultHasher::new`'s hash of `value`, little-endian. */
export function digest$Option_Option_u8(value: rt.u8 | undefined | rt.None, out: rt.ByteVec): void {
Expand Down Expand Up @@ -1349,4 +1351,99 @@ export function equal(data: rt.ByteSlice, out: rt.ByteVec): void {
rt.byteVecPush(out, !hashes_Index.eq$cmp_PartialEq(_193, _175(part13)) ? 1 : 0);
}

/**
* `BuildHasherDefault`, made by `new`, `Default`, and `Clone`, which all compare equal and
* print alike whatever their `Hasher`, and each builds its hasher by the hasher's own
* `Default`, once per hash. Then hash maps and sets that hold one, which find their keys
* whatever it hashes them to, and say only sorted what they hold, as std's order is its own.
*/
export function defaults(data: rt.ByteSlice, out: rt.ByteVec): void {
((events: rt.RefCell<rt.ByteVec>): undefined => {
const _5: rt.RefCell<rt.ByteVec> = rt.refCellBorrowMut(events);
rt.byteVecClear(_5.value);
rt.refMutRelease(_5);
})(EVENTS.get());
const first: rt.u8 = option_unwrapOr$0r2bmpr(rt.byteSliceFirst(data), 7);
Tallied.default$Default();
const held: Tallied.Tallied = { tag: first, state: undefined };
const cloned: Tallied.Tallied = Tallied.clone$Clone(held);
rt.byteVecPush(out, true ? 1 : 0);
rt.byteVecPush(out, false ? 1 : 0);
rt.byteVecPush(out, Tallied.eq$cmp_PartialEq(held, cloned) ? 1 : 0);
const _36: Tallied.Tallied = Tallied.default$Default();
rt.byteVecPush(out, Tallied.eq$cmp_PartialEq(held, _36) ? 1 : 0);
const args2: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtWriteStr(f, "BuildHasherDefault"), (f: rt.Formatter) => rt.fmtOption(undefined, f, (_value: undefined, f: rt.Formatter) => rt.fmtWriteStr(f, "BuildHasherDefault"), rt.None), (f: rt.Formatter) => Tallied.fmt$fmt_Debug(cloned, f), (f: rt.Formatter) => Tallied.fmt$fmt_Debug(held, f)];
put(out, rt.fmtFormat([args2[0], " ", args2[1], " ", args2[2], " ", rt.fmtSpec({ alternate: true }, args2[3])]));
const word: string = result_unwrapOr$01jdcm7(rt.strFromUtf8(data), "✓");
const n: rt.u16 = rt.u128Low(wide(data, 0, 2)) & 0xffff;
const built: Tally.Tally = Tally.default$Default();
rt.hash16(n, new rt.OwnHasher(built, Tally.hasher$hash_Hasher));
const _66: rt.u64 = Tally.finish$hash_Hasher(built);
const _68: rt.u64 = rt.hashOne(new rt.OwnHasher(Tally.default$Default(), Tally.hasher$hash_Hasher), n, rt.hash16, undefined, rt.drop);
const _70: rt.u64 = rt.hashOne(new rt.OwnHasher(Tally.default$Default(), Tally.hasher$hash_Hasher), word, rt.hashStr, undefined, rt.drop);
const _74: [rt.u8, string] = [n & 0xff, word];
const _72: rt.u64 = rt.hashOne(new rt.OwnHasher(Tally.default$Default(), Tally.hasher$hash_Hasher), _74, rt.hashTuple([rt.hash8, rt.hashStr]), undefined, rt.drop);
const _79: Key.Key = { _0: n, _1: word };
const hashes: rt.u64[] = [_66, _68, _70, _72, rt.hashOne(new rt.OwnHasher(Tally.default$Default(), Tally.hasher$hash_Hasher), _79, rt.hashOwn(Key.hash$Hash_hashes_Tally as (a0: Key.Key, a1: Tally.Tally) => undefined), undefined, rt.drop)];
built[Symbol.dispose]();
const iter: rt.Iter<rt.u64> = rt.iterSlice(hashes);
while (true) {
const _85: rt.u64 | rt.Done = iter.next();
if (_85 === rt.DONE) {
break;
}
rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(_85).reverse()));
}
const keyed: rt.HashMap<Key.Key, rt.u8> = rt.hashNew(rt.hashing(Key.hash$Hash_hash_DefaultHasher as (a0: Key.Key, a1: rt.Hasher) => undefined, Key.eq$cmp_PartialEq), undefined) as rt.HashMap<Key.Key, rt.u8>;
const seen: rt.HashSet<rt.u8> = rt.hashWithCapacity(data.length, 469762048, undefined, undefined) as rt.HashSet<rt.u8>;
const iter2: rt.Iter<[rt.usize, rt.u8]> = rt.iterEnumerate(rt.iterSlice(rt.byteSliceView(data)));
while (true) {
const _101: [rt.usize, rt.u8] | rt.Done = iter2.next();
if (_101 === rt.DONE) {
break;
}
const i: rt.usize = _101[0];
const b: rt.u8 = _101[1];
const _110: rt.u16 = rt.u8Rem(b, 8) as rt.u16;
const bounds = rt.sliceIndexBounds(new rt.RangeInclusive(i, i, rt.usizeStep), data.length);
const _109: Key.Key = { _0: _110, _1: text(rt.byteSliceRange(data, bounds[0], bounds[1])) };
const _106: rt.Place<rt.u8> = rt.entryOrInsertWithMut(rt.entry(keyed, _109), (): rt.u8 => {
return 0;
});
_106.v = rt.u8Add(_106.v, 1);
rt.byteVecPush(out, rt.hashAdd(seen, rt.u8Rem(b, 16)) ? 1 : 0);
const _128: Key.Key = { _0: (rt.u8Rem(b, 8) ^ 1) as rt.u16, _1: text(rt.byteSliceFrom(Uint8Array.of(b ^ 1))) };
rt.byteVecPush(out, rt.hashContains(keyed, _128) ? 1 : 0);
}
const entries: [Key.Key, rt.u8][] = rt.iterToArray(rt.hashIter(keyed), "next", 8);
rt.sliceSort(entries, rt.cmpLt(rt.cmpTuple<[Key.Key, rt.u8], rt.Ordering | undefined>([Key.partialCmp$cmp_PartialOrd, rt.cmp])), 8, true);
for (const _147 of entries) {
rt.byteVecPush(out, _147[0]._0 & 0xff);
put(out, _147[0]._1);
rt.byteVecPush(out, _147[1]);
}
const probe: Key.Key = { _0: first as rt.u16, _1: text(rt.byteSliceFrom(Uint8Array.of(first))) };
rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(rt.hashOne(new rt.OwnHasher(Fnv.default$Default(), Fnv.hasher$hash_Hasher), probe, rt.hashOwn(Key.hash$Hash_hashes_Fnv as (a0: Key.Key, a1: Fnv.Fnv) => undefined))).reverse()));
rt.hashClone(seen, undefined, undefined, (_a0: undefined): undefined => {
return undefined;
}).s as undefined;
rt.byteVecExtendFromSlice(out, rt.byteSliceFrom(rt.u64ToBeBytes(rt.hashOne(new rt.OwnHasher(Fnv.default$Default(), Fnv.hasher$hash_Hasher), first, rt.hash8)).reverse()));
rt.byteVecPush(out, true ? 1 : 0);
const _195: rt.HashMap<Key.Key, rt.u8> = rt.hashClone(keyed, Key.clone$Clone, undefined, (_a02: undefined): undefined => {
return undefined;
});
rt.byteVecPush(out, rt.hashEq(rt.same)(keyed, _195) ? 1 : 0);
const args4: rt.Fmt[] = [(f: rt.Formatter) => rt.fmtWriteStr(f, "BuildHasherDefault")];
put(out, rt.fmtFormat([args4[0]]));
const _212: rt.Iter<rt.u8> = rt.iterMap(rt.iterSlice(rt.byteSliceView(data)), (b2: rt.u8): rt.u8 => {
return rt.u8Rem(b2, 4);
});
const small: rt.HashSet<rt.u8> = rt.hashExtendKeys(rt.hashNew(undefined, undefined) as rt.HashSet<rt.u8>, _212, undefined, undefined, 469762048);
rt.byteVecPush(out, rt.hashLen(rt.hashExtendKeys(rt.hashNew(undefined, undefined) as rt.HashSet<rt.u8>, rt.hashUnion(small, seen), undefined, undefined, 469762048)) & 0xff);
rt.byteVecPush(out, rt.hashIsSubset(small, seen) ? 1 : 0);
rt.byteVecExtendFromSlice(out, rt.byteVecSlice(((events2: rt.RefCell<rt.ByteVec>): rt.ByteVec => {
return rt.refCellReplace(events2, new rt.ByteVec());
})(EVENTS.get())));
}

//# sourceMappingURL=hashes.ts.map
Loading