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,6 +35,5 @@ 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 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
- [A string Cow's variant](/quest/m3/ts-cow-str-variant.md) - matching a `Cow<str>`'s `Borrowed` or `Owned`, and `to_mut`'s change of it, translate as std's
12 changes: 8 additions & 4 deletions quest/m3/ts-panic-hook.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,12 @@ own too, such as an index out of bounds or an overflow, at the location std's
`#[track_caller]` reports. The differential harness sets its own hook natively, so a case
that sets one must leave the harness able to read the message.

Public API: the translator's output, and the runtime's `Panic`.

## Required
The crate's own `#[track_caller]` functions already take their caller's `rt.Location`
(`ts/src/lower/caller.rs`); std's that map to the runtime, such as `unwrap`, `expect`,
indexing, and `RefCell::borrow_mut`, take none, as nothing reads it yet. Passing one to
each costs every hot call, so measure it on `just ts bench` and the moq codec, and weigh
passing it only where a hook is set. A panic inside std's own code, not under
`#[track_caller]`, is at a path in the native build's sysroot, which translation must name
as that build does.

- [A panic's Location](/quest/m3/ts-panic-location.md) - `Location::caller` and `#[track_caller]` translate
Public API: the translator's output, and the runtime's `Panic`.
29 changes: 0 additions & 29 deletions quest/m3/ts-panic-location.md

This file was deleted.

13 changes: 10 additions & 3 deletions ts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,16 @@ after one, as a wasm trap leaves it, and a caller that catches `rt.Panic` must n
again. An abort without a panic, as std's for an `RwLock` locked again while held,
throws `rt.Abort`, a `Panic` with std's abort message. So `catch_unwind` only ever returns
`Ok`, `resume_unwind` throws `rt.Abort` without running the hook, and `panic_any` panics
with its payload if that is text, or `Box<dyn Any>` as std's hook writes any other. A
`Location`, and with it `set_hook` and `take_hook`, is refused: translated panics carry
none.
with its payload if that is text, or `Box<dyn Any>` as std's hook writes any other.
Translated panics carry no `Location`, so `set_hook` and `take_hook` are refused.

`Location::caller` gives rustc's location: the file as the session names it, and line
and column. A function rustc passes its caller's location to, such as a `#[track_caller]`
one, takes it as an `rt.Location` last parameter, and so does a trait object's method
whose trait declares it so. A call the crate writes passes the call's location, or, in such
a function, its own caller's; a function pointer, or a trait object's method only the impl
tracks, passes the function's own, as rustc's shim does. One that std's code calls,
through its `Fn` impls, is refused, as its location is in std's source.

Each integer type is its own type to `tsc`, named as Rust's: `rt.u8` is a `number` with a
type-only brand, so a `u16` where a `u8` goes fails the type check, while a plain
Expand Down
12 changes: 12 additions & 0 deletions ts/fixtures/lang/panics/expected/core/bool.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Generated by rust2-ts. Do not edit.

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

export function then$142atvy(self: boolean, f: () => rt.Location): rt.Location | undefined {
if (!self) {
return undefined;
}
return f();
}

//# sourceMappingURL=bool.ts.map
13 changes: 13 additions & 0 deletions ts/fixtures/lang/panics/expected/core/cmp.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Generated by rust2-ts. Do not edit.

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

export function min$1rvi5e9(v1: rt.Location, v2: rt.Location): rt.Location {
return rt.ordMin(v1, v2, rt.cmpLt(rt.locationCmp));
}

export function max$02i836o(v1: rt.Location, v2: rt.Location): rt.Location {
return rt.ordMax(v1, v2, rt.cmpLt(rt.locationCmp));
}

//# sourceMappingURL=cmp.ts.map
7 changes: 7 additions & 0 deletions ts/fixtures/lang/panics/expected/core/option.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ export function unwrapOr$0r2bmpr(self: rt.u8 | undefined, default_: rt.u8): rt.u
return self;
}

export function mapOr$1e4a1e0(self: rt.Ordering | undefined, default_: rt.u8, f: (a0: rt.Ordering) => rt.u8): rt.u8 {
if (self === undefined) {
return default_;
}
return f(self);
}

//# sourceMappingURL=option.ts.map
43 changes: 41 additions & 2 deletions ts/fixtures/lang/panics/expected/lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

import * as rt from "./rt.ts";
import type * as Any from "./core/any.Any.ts";
import { wrapped, called, awaited, raised } from "./panics.ts";
import { via$located_Tracked_u8, at$located_Tracked_u8, called as located_called, read, panicked } from "./located.ts";
import * as Inherits from "./located.Inherits.ts";
import * as Own from "./located.Own.ts";
import { wrapped, called as panics_called, awaited, raised } from "./panics.ts";
import type * as Point from "./panics.Point.ts";

export function copy$panics_Point(v: Point.Point): Point.Point {
Expand All @@ -23,6 +26,34 @@ export class of$String {
}
}

export class of$located_Inherits {
v: Inherits.Inherits;

constructor(v: Inherits.Inherits) {
this.v = v;
}

at$Tracked(caller: rt.Location): rt.Location {
return Inherits.at$located_Tracked(this.v, caller);
}

via$Tracked(): rt.Location {
return Inherits.via$located_Tracked(this.v);
}
}

export class of$located_Own {
v: Own.Own;

constructor(v: Own.Own) {
this.v = v;
}

at$Untracked(): rt.Location {
return Own.at$located_Untracked(this.v, { file: "fixtures/lang/panics/src/located.rs", line: 86, col: 5 });
}
}

export class of$ref_str {
v: string;

Expand All @@ -37,14 +68,22 @@ export class of$u8 {
constructor(v: rt.u8) {
this.v = v;
}

at$Tracked(caller: rt.Location): rt.Location {
return at$located_Tracked_u8(this.v, caller);
}

via$Tracked(): rt.Location {
return via$located_Tracked_u8(this.v);
}
}

/**
* Each case's name and what it runs. The first two bytes, big-endian, pick one modulo
* their count, so a case added at the end moves no other.
*/
export function cases(): [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined][] {
return [["panics::wrapped", wrapped as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["panics::called", called as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["panics::awaited", awaited as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["panics::raised", raised as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined]];
return [["panics::wrapped", wrapped as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["panics::called", panics_called as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["panics::awaited", awaited as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["panics::raised", raised as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["located::called", located_called as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["located::read", read as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined], ["located::panicked", panicked as (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined] as [string, (a0: rt.u8, a1: rt.ByteSlice, a2: rt.ByteVec) => undefined]];
}

//# sourceMappingURL=lib.ts.map
26 changes: 26 additions & 0 deletions ts/fixtures/lang/panics/expected/located.Held$read.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Generated by rust2-ts. Do not edit.

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

export function fmt$read_fmt_Debug(self: Held, f: rt.Formatter): rt.Result<undefined, rt.FmtError> {
const _3: string = "Held";
const _4: string = "at";
const _5: rt.Fmt = (f: rt.Formatter) => rt.fmtLocationDebug(self.at, f);
const _7: string = "maybe";
const _8: rt.Fmt = (f: rt.Formatter) => rt.fmtOption(self.maybe, f, rt.fmtLocationDebug);
return rt.debugStructFinish(rt.debugStructField(rt.debugStructField(rt.fmtDebugStruct(f, _3), _4, _5), _7, _8));
}

export function eq$read_cmp_PartialEq(self: Held, other: Held): boolean {
if (!rt.locationEq(self.at, other.at)) {
return false;
}
return rt.eqOption(rt.locationEq)(self.maybe, other.maybe);
}

export interface Held {
at: rt.Location;
maybe: rt.Location | undefined;
}

//# sourceMappingURL=located.Held$read.ts.map
19 changes: 19 additions & 0 deletions ts/fixtures/lang/panics/expected/located.Inherits.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Generated by rust2-ts. Do not edit.

import * as rt from "./rt.ts";
import { here } from "./located.ts";

/** A default, untracked, of the tracked method. */
export function via$located_Tracked(self: Inherits): rt.Location {
return at$located_Tracked(self, { file: "fixtures/lang/panics/src/located.rs", line: 58, col: 14 });
}

/** Inherits the trait's `#[track_caller]`. */
export interface Inherits {
}

export function at$located_Tracked(_self: Inherits, caller: rt.Location): rt.Location {
return here(caller);
}

//# sourceMappingURL=located.Inherits.ts.map
13 changes: 13 additions & 0 deletions ts/fixtures/lang/panics/expected/located.Own.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Generated by rust2-ts. Do not edit.

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

/** Only the impl tracks: a call through a trait object passes the impl's own location. */
export interface Own {
}

export function at$located_Untracked(_self: Own, caller: rt.Location): rt.Location {
return caller;
}

//# sourceMappingURL=located.Own.ts.map
13 changes: 13 additions & 0 deletions ts/fixtures/lang/panics/expected/located.Places.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Generated by rust2-ts. Do not edit.

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

/** Indexing that gives where it was indexed. */
export interface Places {
}

export function index$ops_Index_u8(_self: Places, _2: rt.u8, caller: rt.Location): rt.Location {
return caller;
}

//# sourceMappingURL=located.Places.ts.map
8 changes: 8 additions & 0 deletions ts/fixtures/lang/panics/expected/located.Tracked.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Generated by rust2-ts. Do not edit.

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

export type Tracked =
| { at$Tracked: (a0: rt.Location) => rt.Location; via$Tracked: () => rt.Location };

//# sourceMappingURL=located.Tracked.ts.map
7 changes: 7 additions & 0 deletions ts/fixtures/lang/panics/expected/located.Untracked.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Generated by rust2-ts. Do not edit.

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

export type Untracked = { at$Untracked: () => rt.Location };

//# sourceMappingURL=located.Untracked.ts.map
Loading