Skip to content

Commit 68522a4

Browse files
committed
implements CallHistory tracking
1 parent f302a4b commit 68522a4

File tree

8 files changed

+72
-9
lines changed

8 files changed

+72
-9
lines changed

packages/playground/evaluate/config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const config = {
3232
digits: 8,
3333
shouldComputeFullStats: false,
3434
incrementBy: 100,
35-
comeUpForAirEvery: 100,
35+
comeUpForAirEvery: 1_000,
3636
transcendTheAstralPlane: 10_000,
3737
readStringFromMemory: true,
3838
} satisfies Config;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
import type { funcs } from "../../conformance-tests/from-c/conway.ts";
2-
import type { entry } from "../../conformance-tests/from-c/conway.ts";
3-
export type NextResult = entry<[0], true, 0>;
1+
import type { funcs } from "../doom/doom";
2+
import type { entry } from "../doom/doom";
3+
export type NextResult = entry<[], true, 0>;

packages/playground/final-doom-pun-intended/data/mock-machine.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export type HolyShitIfThisActuallyWorksOMGOMGROFLWHATISWRONGWITHME = {
2727
memorySize: "00000000000000000000000000000110";
2828
executionContexts: [];
2929
funcs: funcs;
30+
callHistory: [];
3031
};
3132
/** finalize */
3233
export type HoldOntoYourMonadsAndBraceForImpact = executeInstruction<HolyShitIfThisActuallyWorksOMGOMGROFLWHATISWRONGWITHME, true, 9001>;

packages/wasm-to-typescript-types/bootstrap.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ export type bootstrap<
111111
memorySize: input['memorySize'];
112112
indirect: input['indirect'];
113113
results: null;
114+
callHistory: [];
114115
},
115116
debugMode,
116117
stopAt

packages/wasm-to-typescript-types/garbageCollector.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ type blank = Satisfies<ProgramState, {
2020
memorySize: "";
2121
executionContexts: [];
2222
funcs: {};
23+
callHistory: [];
2324
}>
2425

2526
type s<

packages/wasm-to-typescript-types/instructions/control-flow.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,10 @@ export type Call<
304304
],
305305
State.Stack.set<
306306
_refreshment['stack'],
307-
state
307+
State.CallHistory.record<
308+
_funcId,
309+
state
310+
>
308311
>
309312
>
310313
>

packages/wasm-to-typescript-types/state.ts

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,10 @@ import type {
55
BranchesById,
66
SweepL1Every,
77
ExecutionContext,
8-
Func,
98
GlobalsById,
109
MemoryAddress,
11-
MemoryByAddress,
1210
ProgramState,
11+
FuncId,
1312
} from "./types"
1413
import * as TypeMath from "ts-type-math";
1514
import { WasmValue, WasmType, Convert, Wasm, evaluate, Satisfies } from 'ts-type-math';
@@ -20,6 +19,8 @@ export type Patch<Source, Update> = evaluate<
2019
& Update
2120
>;
2221

22+
export type IDugMyselfANiceBigHoleAndNowIHaveToDebugMyWayOutOfItSomehow = true;
23+
2324
export namespace State {
2425
export type error<
2526
reason extends string,
@@ -66,6 +67,42 @@ export namespace State {
6667
>
6768
>
6869

70+
export namespace CallHistory {
71+
export type record<
72+
funcId extends FuncId,
73+
state extends ProgramState
74+
> = Satisfies<ProgramState,
75+
IDugMyselfANiceBigHoleAndNowIHaveToDebugMyWayOutOfItSomehow extends true
76+
? {
77+
count: state['count'];
78+
stack: state['stack'];
79+
activeFuncId: state['activeFuncId'];
80+
activeStackDepth: state['activeStackDepth'];
81+
activeLocals: state['activeLocals'];
82+
instructions: state['instructions'];
83+
activeBranches: state['activeBranches'];
84+
L1Cache: state['L1Cache'];
85+
memory: state['memory'];
86+
executionContexts: state['executionContexts'];
87+
funcs: state['funcs'];
88+
garbageCollection: state['garbageCollection'];
89+
globals: state['globals'];
90+
memorySize: state['memorySize'];
91+
indirect: state['indirect'];
92+
results: state['results'];
93+
callHistory: state['callHistory'] extends []
94+
? [
95+
[funcId, state['count']] // this is the first one!
96+
]
97+
: [
98+
...state['callHistory'],
99+
[funcId, state['count']] // append
100+
]
101+
}
102+
: state
103+
>
104+
}
105+
69106
export namespace Count {
70107
export type increment<
71108
state extends ProgramState
@@ -88,6 +125,7 @@ export namespace State {
88125
memorySize: state['memorySize'];
89126
indirect: state['indirect'];
90127
results: state['results'];
128+
callHistory: state['callHistory'];
91129
}
92130
>
93131
}
@@ -116,6 +154,7 @@ export namespace State {
116154
memorySize: state['memorySize'];
117155
indirect: state['indirect'];
118156
results: state['results'];
157+
callHistory: state['callHistory'];
119158
}
120159
>
121160

@@ -182,6 +221,7 @@ export namespace State {
182221
memorySize: state['memorySize'];
183222
indirect: state['indirect'];
184223
results: state['results'];
224+
callHistory: state['callHistory'];
185225
}
186226
>
187227

@@ -236,6 +276,7 @@ export namespace State {
236276
memorySize: state['memorySize'];
237277
indirect: state['indirect'];
238278
results: state['results'];
279+
callHistory: state['callHistory'];
239280
}
240281
>
241282

@@ -264,6 +305,7 @@ export namespace State {
264305
memorySize: state['memorySize'];
265306
indirect: state['indirect'];
266307
results: state['results'];
308+
callHistory: state['callHistory'];
267309
}
268310
: state['instructions'] extends IEndFunction[] // funny story: [IEndFunction] doesn't work here
269311
? // we hit this case on the very last pop (i.e. when the program completes)
@@ -284,6 +326,7 @@ export namespace State {
284326
memorySize: state['memorySize'];
285327
indirect: state['indirect'];
286328
results: state['results'];
329+
callHistory: state['callHistory'];
287330
}
288331
: State.error<"execution contexts exhausted", Instruction, state>
289332
>
@@ -316,6 +359,7 @@ export namespace State {
316359
memorySize: state['memorySize'];
317360
indirect: state['indirect'];
318361
results: state['results'];
362+
callHistory: state['callHistory'];
319363
}
320364
>
321365
}
@@ -342,6 +386,7 @@ export namespace State {
342386
memorySize: state['memorySize'];
343387
indirect: state['indirect'];
344388
results: state['results'];
389+
callHistory: state['callHistory'];
345390
}
346391
>
347392

@@ -389,6 +434,7 @@ export namespace State {
389434
memorySize: state['memorySize'];
390435
indirect: state['indirect'];
391436
results: state['results'];
437+
callHistory: state['callHistory'];
392438
}
393439
>
394440
}
@@ -442,6 +488,7 @@ export namespace State {
442488
memorySize: state['memorySize'];
443489
indirect: state['indirect'];
444490
results: state['results'];
491+
callHistory: state['callHistory'];
445492
}
446493
// >
447494
>
@@ -468,6 +515,7 @@ export namespace State {
468515
memorySize: state['memorySize'];
469516
indirect: state['indirect'];
470517
results: state['results'];
518+
callHistory: state['callHistory'];
471519
}
472520
>
473521

@@ -505,6 +553,7 @@ export namespace State {
505553
memorySize: state['memorySize'];
506554
indirect: state['indirect'];
507555
results: state['results'];
556+
callHistory: state['callHistory'];
508557
}
509558
: state
510559
>
@@ -571,6 +620,7 @@ export namespace State {
571620
_resultTypes['length'] extends 1
572621
? WasmTypeToTSNumber<_resultTypes[0], state['stack'][0]>
573622
: CollectResults<state['stack'], _resultTypes>;
623+
callHistory: state['callHistory'];
574624
}
575625
>
576626

packages/wasm-to-typescript-types/types.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,15 @@ export type ExecutionContext = {
5757
}
5858

5959
/** matches what JS implementations do regarding returning one vs multiple values */
60-
type Results = (number | bigint)[] | (number | bigint) | null;
60+
export type Results = (number | bigint)[] | (number | bigint) | null;
61+
62+
export type Count = number;
63+
64+
export type CallHistory = [FuncId, Count];
6165

6266
export type ProgramState = {
6367
/** the number of instructions we've executed, useful for debugging */
64-
count: number;
68+
count: Count;
6569

6670
/** a stack of values */
6771
stack: WasmValue[];
@@ -104,6 +108,9 @@ export type ProgramState = {
104108

105109
/** the result of the program */
106110
results: Results;
111+
112+
/** used for debugging */
113+
callHistory: CallHistory[];
107114
}
108115

109116
export type ProgramInput = Pick<

0 commit comments

Comments
 (0)