numbl 0.3.0 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/binding.gyp +16 -33
- package/dist-cli/cli.js +20535 -25629
- package/dist-lib/graphics/types.d.ts +22 -0
- package/dist-lib/lib.d.ts +1 -0
- package/dist-lib/lib.js +59075 -63895
- package/dist-lib/numbl-core/executeCode.d.ts +11 -14
- package/dist-lib/numbl-core/executors/cJit/builtins.d.ts +30 -0
- package/dist-lib/numbl-core/executors/cJit/chainCodegen.d.ts +59 -0
- package/dist-lib/numbl-core/executors/cJit/chainExecutor.d.ts +27 -0
- package/dist-lib/numbl-core/executors/cJit/chainPass.d.ts +42 -0
- package/dist-lib/numbl-core/executors/cJit/codegen.d.ts +44 -0
- package/dist-lib/numbl-core/executors/cJit/compile.d.ts +45 -0
- package/dist-lib/numbl-core/executors/cJit/elemwiseCodegen.d.ts +23 -0
- package/dist-lib/numbl-core/executors/cJit/elemwiseStructural.d.ts +33 -0
- package/dist-lib/numbl-core/executors/cJit/fuseAnalyze.d.ts +39 -0
- package/dist-lib/numbl-core/executors/cJit/fuseCodegen.d.ts +16 -0
- package/dist-lib/numbl-core/executors/cJit/fuseExecutor.d.ts +28 -0
- package/dist-lib/numbl-core/executors/cJit/loopExecutor.d.ts +32 -0
- package/dist-lib/numbl-core/executors/cJit/register.d.ts +10 -0
- package/dist-lib/numbl-core/executors/cJit/whitelist.d.ts +15 -0
- package/dist-lib/numbl-core/executors/cache.d.ts +26 -0
- package/dist-lib/numbl-core/executors/context.d.ts +76 -0
- package/dist-lib/numbl-core/executors/index.d.ts +17 -0
- package/dist-lib/numbl-core/executors/jsJit/callExecutor.d.ts +25 -0
- package/dist-lib/numbl-core/{jit/js → executors/jsJit/codegen}/jitCodegen.d.ts +2 -2
- package/dist-lib/numbl-core/{jit/js → executors/jsJit/codegen}/jitCodegenHoist.d.ts +1 -1
- package/dist-lib/numbl-core/{jit/js → executors/jsJit/codegen}/jsMultiReduction.d.ts +10 -13
- package/dist-lib/numbl-core/executors/jsJit/helpers/alloc.d.ts +12 -0
- package/dist-lib/numbl-core/{jit/js → executors/jsJit/helpers}/jitHelpers.d.ts +2 -2
- package/dist-lib/numbl-core/{jit/js → executors/jsJit/helpers}/jitHelpersComplex.d.ts +1 -1
- package/dist-lib/numbl-core/executors/jsJit/helpers/jitHelpersIndex.d.ts +33 -0
- package/dist-lib/numbl-core/{jit/js → executors/jsJit/helpers}/jitHelpersTensor.d.ts +7 -7
- package/dist-lib/numbl-core/executors/jsJit/jitCall.d.ts +59 -0
- package/dist-lib/numbl-core/executors/jsJit/jitLoop.d.ts +53 -0
- package/dist-lib/numbl-core/executors/jsJit/jitTopLevel.d.ts +44 -0
- package/dist-lib/numbl-core/executors/jsJit/loopExecutor.d.ts +15 -0
- package/dist-lib/numbl-core/{jit/jitLoopAnalysis.d.ts → executors/jsJit/lower/blockAnalysis.d.ts} +5 -5
- package/dist-lib/numbl-core/{jit → executors/jsJit/lower}/jitBailSafety.d.ts +1 -1
- package/dist-lib/numbl-core/{jit → executors/jsJit/lower}/jitLower.d.ts +18 -4
- package/dist-lib/numbl-core/{jit → executors/jsJit/lower}/jitLowerExpr.d.ts +11 -2
- package/dist-lib/numbl-core/{jit → executors/jsJit/lower}/jitLowerStmt.d.ts +2 -2
- package/dist-lib/numbl-core/{jit → executors/jsJit/lower}/jitLowerTypes.d.ts +2 -2
- package/dist-lib/numbl-core/{jit → executors/jsJit/lower}/scalarEmit.d.ts +2 -2
- package/dist-lib/numbl-core/executors/jsJit/shared.d.ts +120 -0
- package/dist-lib/numbl-core/executors/jsJit/topLevelExecutor.d.ts +17 -0
- package/dist-lib/numbl-core/executors/lowering.d.ts +166 -0
- package/dist-lib/numbl-core/executors/plugins.d.ts +39 -0
- package/dist-lib/numbl-core/executors/registry.d.ts +148 -0
- package/dist-lib/numbl-core/executors/types.d.ts +103 -0
- package/dist-lib/numbl-core/functionResolve.d.ts +7 -0
- package/dist-lib/numbl-core/helpers/check-helpers.d.ts +4 -5
- package/dist-lib/numbl-core/helpers/linsolve.d.ts +2 -3
- package/dist-lib/numbl-core/helpers/prng.d.ts +1 -2
- package/dist-lib/numbl-core/interpreter/builtins/datetime.d.ts +2 -1
- package/dist-lib/numbl-core/interpreter/builtins/misc.d.ts +4 -1
- package/dist-lib/numbl-core/interpreter/builtins/types.d.ts +4 -91
- package/dist-lib/numbl-core/interpreter/interpreter.d.ts +33 -47
- package/dist-lib/numbl-core/interpreter/interpreterSpecialBuiltins.d.ts +6 -3
- package/dist-lib/numbl-core/interpreter/types.d.ts +27 -12
- package/dist-lib/numbl-core/{jit/jitTypes.d.ts → jitTypes.d.ts} +15 -1
- package/dist-lib/numbl-core/jsUserFunctions.d.ts +8 -0
- package/dist-lib/numbl-core/lowering/loweringContext.d.ts +24 -0
- package/dist-lib/numbl-core/native/lapack-bridge.d.ts +3 -3
- package/dist-lib/numbl-core/parser/types.d.ts +20 -0
- package/dist-lib/numbl-core/runtime/constructors.d.ts +6 -6
- package/dist-lib/numbl-core/runtime/cow.d.ts +33 -0
- package/dist-lib/numbl-core/runtime/index.d.ts +3 -2
- package/dist-lib/numbl-core/runtime/indexing.d.ts +6 -1
- package/dist-lib/numbl-core/runtime/plotBuiltinDispatch.d.ts +86 -0
- package/dist-lib/numbl-core/runtime/plotUtils.d.ts +17 -2
- package/dist-lib/numbl-core/runtime/refcount.d.ts +85 -0
- package/dist-lib/numbl-core/runtime/runtime.d.ts +27 -66
- package/dist-lib/numbl-core/runtime/runtimeDispatch.d.ts +2 -2
- package/dist-lib/numbl-core/runtime/runtimeIndexing.d.ts +2 -2
- package/dist-lib/numbl-core/runtime/runtimeMemberAccess.d.ts +1 -1
- package/dist-lib/numbl-core/runtime/runtimePlot.d.ts +1 -0
- package/dist-lib/numbl-core/runtime/struct-access.d.ts +2 -1
- package/dist-lib/numbl-core/runtime/types.d.ts +104 -62
- package/dist-lib/numbl-core/runtime/utils.d.ts +2 -8
- package/dist-lib/numbl-core/version.d.ts +1 -1
- package/dist-plot-viewer/assets/index-COAM8o1E.js +4426 -0
- package/dist-plot-viewer/index.html +1 -1
- package/native/lapack_linsolve.cpp +1 -1
- package/native/numbl_addon_common.h +2 -2
- package/native/ops/comparison.c +1 -1
- package/package.json +3 -6
- package/dist-lib/numbl-core/jit/c/abi.d.ts +0 -90
- package/dist-lib/numbl-core/jit/c/assemble.d.ts +0 -56
- package/dist-lib/numbl-core/jit/c/classify.d.ts +0 -70
- package/dist-lib/numbl-core/jit/c/compile.d.ts +0 -37
- package/dist-lib/numbl-core/jit/c/context.d.ts +0 -152
- package/dist-lib/numbl-core/jit/c/emit/assign.d.ts +0 -20
- package/dist-lib/numbl-core/jit/c/emit/complexScalar.d.ts +0 -18
- package/dist-lib/numbl-core/jit/c/emit/fused.d.ts +0 -42
- package/dist-lib/numbl-core/jit/c/emit/helpers.d.ts +0 -40
- package/dist-lib/numbl-core/jit/c/emit/index.d.ts +0 -14
- package/dist-lib/numbl-core/jit/c/emit/scalar.d.ts +0 -23
- package/dist-lib/numbl-core/jit/c/emit/stmt.d.ts +0 -25
- package/dist-lib/numbl-core/jit/c/emit/tensor.d.ts +0 -127
- package/dist-lib/numbl-core/jit/c/emit/userCall.d.ts +0 -58
- package/dist-lib/numbl-core/jit/c/epilogue.d.ts +0 -26
- package/dist-lib/numbl-core/jit/c/feasibility.d.ts +0 -44
- package/dist-lib/numbl-core/jit/c/prelude.d.ts +0 -37
- package/dist-lib/numbl-core/jit/c/visit.d.ts +0 -63
- package/dist-lib/numbl-core/jit/e1/complexKernelEmit.d.ts +0 -46
- package/dist-lib/numbl-core/jit/e1/hash.d.ts +0 -10
- package/dist-lib/numbl-core/jit/e1/install.d.ts +0 -13
- package/dist-lib/numbl-core/jit/e1/kernelEmit.d.ts +0 -54
- package/dist-lib/numbl-core/jit/e1/multiReductionKernel.d.ts +0 -66
- package/dist-lib/numbl-core/jit/e1/openmpFlag.d.ts +0 -13
- package/dist-lib/numbl-core/jit/e1/scalarFnKernel.d.ts +0 -44
- package/dist-lib/numbl-core/jit/e2/assignKernel.d.ts +0 -34
- package/dist-lib/numbl-core/jit/e2/astToJitExpr.d.ts +0 -25
- package/dist-lib/numbl-core/jit/e2/cache.d.ts +0 -80
- package/dist-lib/numbl-core/jit/e2/chainKernelEmit.d.ts +0 -55
- package/dist-lib/numbl-core/jit/e2/classify.d.ts +0 -119
- package/dist-lib/numbl-core/jit/e2/compileFn.d.ts +0 -16
- package/dist-lib/numbl-core/jit/e2/complexChainKernelEmit.d.ts +0 -79
- package/dist-lib/numbl-core/jit/e2/emitShared.d.ts +0 -71
- package/dist-lib/numbl-core/jit/e2/install.d.ts +0 -11
- package/dist-lib/numbl-core/jit/e2/liveness.d.ts +0 -29
- package/dist-lib/numbl-core/jit/e2/loopKernel.d.ts +0 -49
- package/dist-lib/numbl-core/jit/e2/loopKernelEmit.d.ts +0 -75
- package/dist-lib/numbl-core/jit/e2/multiReductionDriver.d.ts +0 -24
- package/dist-lib/numbl-core/jit/e2/reductionKernelEmit.d.ts +0 -72
- package/dist-lib/numbl-core/jit/e2/scalarFnDriver.d.ts +0 -29
- package/dist-lib/numbl-core/jit/fusedChainHelpers.d.ts +0 -65
- package/dist-lib/numbl-core/jit/fusedScalarEmit.d.ts +0 -69
- package/dist-lib/numbl-core/jit/fusion.d.ts +0 -71
- package/dist-lib/numbl-core/jit/fusionOps.d.ts +0 -25
- package/dist-lib/numbl-core/jit/heavyOps.d.ts +0 -15
- package/dist-lib/numbl-core/jit/index.d.ts +0 -7
- package/dist-lib/numbl-core/jit/jitLoop.d.ts +0 -25
- package/dist-lib/numbl-core/jit/jitTopLevel.d.ts +0 -22
- package/dist-lib/numbl-core/jit/js/jitHelpersIndex.d.ts +0 -33
- package/dist-lib/numbl-core/jit/js/jsFusedCodegen.d.ts +0 -17
- package/dist-lib/numbl-core/runtime/alloc.d.ts +0 -23
- package/dist-plot-viewer/assets/index-GiUNnMQg.js +0 -4426
- package/native/jit_runtime/jit_runtime.c +0 -261
- package/native/jit_runtime/jit_runtime.h +0 -204
|
@@ -3,5 +3,5 @@
|
|
|
3
3
|
*
|
|
4
4
|
* IR walkers for hoist-pass data collection are in jitCodegenHoist.ts.
|
|
5
5
|
*/
|
|
6
|
-
import { type JitStmt } from "
|
|
7
|
-
export declare function generateJS(body: JitStmt[], params: string[], outputs: string[], nargout: number, localVars: Set<string>, fileName?: string
|
|
6
|
+
import { type JitStmt } from "../../../jitTypes.js";
|
|
7
|
+
export declare function generateJS(body: JitStmt[], params: string[], outputs: string[], nargout: number, localVars: Set<string>, fileName?: string): string;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
* for hoisting tensor aliases, struct field reads, and struct array
|
|
6
6
|
* element reads to the top of the generated function.
|
|
7
7
|
*/
|
|
8
|
-
import type { JitStmt } from "
|
|
8
|
+
import type { JitStmt } from "../../../jitTypes.js";
|
|
9
9
|
/**
|
|
10
10
|
* Hoisted aliases for a tensor variable read/written in the loop body.
|
|
11
11
|
* Maps the original variable name to local JS identifiers for its
|
|
@@ -6,12 +6,11 @@
|
|
|
6
6
|
* acc = <expr tree with >=2 reductions over a single tensor Var>
|
|
7
7
|
*
|
|
8
8
|
* On match, the JS codegen emits a block that runs a single-pass
|
|
9
|
-
* reduction loop
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
* `
|
|
14
|
-
* clears around the `emitExpr` call the caller provides.
|
|
9
|
+
* inline JS reduction loop, stashes each reduction result in a local,
|
|
10
|
+
* and then emits the Assign's RHS with each reduction Call substituted
|
|
11
|
+
* by the local that holds its value. The RHS-substitution contract
|
|
12
|
+
* lives in `jitCodegen._multiReductionSubst`, which this module
|
|
13
|
+
* installs and clears around the `emitExpr` call the caller provides.
|
|
15
14
|
*
|
|
16
15
|
* Limited to:
|
|
17
16
|
* - sum / prod / max / min / mean (short-circuit any/all excluded)
|
|
@@ -24,8 +23,8 @@
|
|
|
24
23
|
* IEEE unordered compare already skips NaN, and an `any_non_nan` flag
|
|
25
24
|
* drives the all-NaN → NaN fallback.
|
|
26
25
|
*/
|
|
27
|
-
import type { JitExpr, JitStmt } from "
|
|
28
|
-
|
|
26
|
+
import type { JitExpr, JitStmt } from "../../../jitTypes.js";
|
|
27
|
+
type MultiReduceOp = "sum" | "prod" | "max" | "min" | "mean";
|
|
29
28
|
export interface MultiReductionMatch {
|
|
30
29
|
/** The scalar Assign being emitted (target + original RHS). */
|
|
31
30
|
stmt: JitStmt & {
|
|
@@ -54,17 +53,15 @@ export declare function tryMatchMultiReduction(stmt: JitStmt): MultiReductionMat
|
|
|
54
53
|
*
|
|
55
54
|
* The block:
|
|
56
55
|
* 1. Aliases `<tensorName>.data` to a local and reads its length.
|
|
57
|
-
* 2.
|
|
58
|
-
* a Float64Array scratch with the accumulator values, with an
|
|
59
|
-
* inline JS fallback at small `n`. Under non-e1, emits just the
|
|
60
|
-
* JS loop.
|
|
56
|
+
* 2. Emits a single-pass JS loop that updates each accumulator.
|
|
61
57
|
* 3. Post-loop: `mean = sum / n`, and a NaN fixup for max/min when
|
|
62
58
|
* every input element was NaN.
|
|
63
59
|
* 4. Installs `_multiReductionSubst` pointing each reduction Call at
|
|
64
60
|
* its local, emits the Assign's RHS via the caller-provided
|
|
65
61
|
* `emitExpr`, and writes the final `<target> = <rhs>;`.
|
|
66
62
|
*/
|
|
67
|
-
export declare function emitMultiReductionBlock(lines: string[], indent: string, match: MultiReductionMatch, mangleName: (n: string) => string, emitExprWithSubst: (expr: JitExpr, subst: Map<JitExpr, string>) => string
|
|
63
|
+
export declare function emitMultiReductionBlock(lines: string[], indent: string, match: MultiReductionMatch, mangleName: (n: string) => string, emitExprWithSubst: (expr: JitExpr, subst: Map<JitExpr, string>) => string): void;
|
|
68
64
|
/** Reset per-function counter so generated names stay stable between
|
|
69
65
|
* compiles of the same IR. Called from `generateJS`. */
|
|
70
66
|
export declare function resetMultiReductionState(): void;
|
|
67
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Allocate a Float64Array. Thin wrapper around `new Float64Array(x)`
|
|
2
|
+
* kept as a single allocation site so future strategies (pooling,
|
|
3
|
+
* COW-aware allocation, etc.) can be reintroduced without touching
|
|
4
|
+
* every callsite. */
|
|
5
|
+
export declare function allocFloat64Array(x: number | number[] | Float64Array): Float64Array;
|
|
6
|
+
/** No-op. Kept as a placeholder for future explicit-release strategies
|
|
7
|
+
* (e.g. pool release, arena reset). With pure JS GC, scratch buffers
|
|
8
|
+
* are reclaimed when the wrapper goes out of scope. */
|
|
9
|
+
export declare function releaseFloat64Array(_buf: Float64Array): void;
|
|
10
|
+
/** Pass-through. Kept as a placeholder for future scratch-arena
|
|
11
|
+
* strategies. Today it just runs `fn` and returns its result. */
|
|
12
|
+
export declare function withScratch<T>(fn: () => T): T;
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
export { re, im, mkc, cAdd, cSub, cMul, cDiv, cNeg, cConj, cAngle, cTruthy, } from "./jitHelpersComplex.js";
|
|
14
14
|
export { bce, idx1, idx2, idxN, idx1r, idx2r, idx3r, idx1r_h, idx2r_h, idx3r_h, set1r_h, set2r_h, set3r_h, setRange1r_h, setCol2r_h, subarrayCopy1r, subarrayCopy1rRow, } from "./jitHelpersIndex.js";
|
|
15
|
-
export { makeTensor, tensorBinaryOp, tensorCompareOp, tensorUnary, tensorNeg, vconcatGrow1r, unshare,
|
|
15
|
+
export { makeTensor, tensorBinaryOp, tensorCompareOp, tensorUnary, tensorNeg, vconcatGrow1r, unshare, asTensor, tDouble, tSum, tAdd, tSub, tMul, tDiv, tPow, tEq, tNeq, tLt, tLe, tGt, tGe, } from "./jitHelpersTensor.js";
|
|
16
16
|
export { JitBailToInterpreter } from "./jitHelpersIndex.js";
|
|
17
17
|
/**
|
|
18
18
|
* Thrown when a function handle called from JIT code returns a type
|
|
@@ -26,7 +26,7 @@ export declare class JitFuncHandleBailError extends Error {
|
|
|
26
26
|
constructor(fnName: string, expectedType: string, actualType: string);
|
|
27
27
|
}
|
|
28
28
|
export declare const jitHelpers: Record<string, unknown>;
|
|
29
|
-
import type { IBuiltin } from "
|
|
29
|
+
import type { IBuiltin } from "../../../interpreter/builtins/index.js";
|
|
30
30
|
/**
|
|
31
31
|
* Build a per-runtime jitHelpers snapshot. Uses a single spread expression
|
|
32
32
|
* for a fresh V8 hidden class (critical for inline-cache performance).
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Complex number arithmetic helpers for JIT-compiled code.
|
|
3
3
|
* These are pure functions used by the $h helpers object.
|
|
4
4
|
*/
|
|
5
|
-
import
|
|
5
|
+
import { RuntimeComplexNumber } from "../../../runtime/types.js";
|
|
6
6
|
export declare function re(v: unknown): number;
|
|
7
7
|
export declare function im(v: unknown): number;
|
|
8
8
|
export declare function mkc(r: number, i: number): number | RuntimeComplexNumber;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tensor indexing helpers for JIT-compiled code.
|
|
3
|
+
*
|
|
4
|
+
* Three tiers of helpers, from most general to most specialized:
|
|
5
|
+
* 1. Generic (idx1, idx2, idxN) — handle any base type, real or complex
|
|
6
|
+
* 2. Real-tensor fast path (idx1r, idx2r, idx3r) — skip type/imag checks
|
|
7
|
+
* 3. Hoisted-base (idx*r_h, set*r_h) — take pre-extracted data/len/shape
|
|
8
|
+
*
|
|
9
|
+
* All helpers use 1-based MATLAB indexing and include per-dimension bounds
|
|
10
|
+
* checks to ensure consistency with the interpreter.
|
|
11
|
+
*/
|
|
12
|
+
import { type RuntimeTensor } from "../../../runtime/types.js";
|
|
13
|
+
export declare class JitBailToInterpreter extends Error {
|
|
14
|
+
readonly reason: string;
|
|
15
|
+
constructor(reason: string);
|
|
16
|
+
}
|
|
17
|
+
export declare function bce(): never;
|
|
18
|
+
export declare function idx1(base: unknown, i: number): unknown;
|
|
19
|
+
export declare function idx2(base: unknown, ri: number, ci: number): unknown;
|
|
20
|
+
export declare function idxN(base: unknown, indices: number[]): unknown;
|
|
21
|
+
export declare function idx1r(base: RuntimeTensor, i: number): number;
|
|
22
|
+
export declare function idx2r(base: RuntimeTensor, ri: number, ci: number): number;
|
|
23
|
+
export declare function idx3r(base: RuntimeTensor, i1: number, i2: number, i3: number): number;
|
|
24
|
+
export declare function idx1r_h(data: Float64Array, len: number, i: number): number;
|
|
25
|
+
export declare function idx2r_h(data: Float64Array, len: number, rows: number, ri: number, ci: number): number;
|
|
26
|
+
export declare function idx3r_h(data: Float64Array, len: number, d0: number, d1: number, i1: number, i2: number, i3: number): number;
|
|
27
|
+
export declare function set1r_h(data: Float64Array, len: number, i: number, v: number): void;
|
|
28
|
+
export declare function set2r_h(data: Float64Array, len: number, rows: number, ri: number, ci: number, v: number): void;
|
|
29
|
+
export declare function set3r_h(data: Float64Array, len: number, d0: number, d1: number, i1: number, i2: number, i3: number, v: number): void;
|
|
30
|
+
export declare function setRange1r_h(dstData: Float64Array, dstLen: number, dstStart: number, dstEnd: number, srcData: Float64Array, srcLen: number, srcStart: number, srcEnd: number): void;
|
|
31
|
+
export declare function subarrayCopy1r(srcData: Float64Array, srcLen: number, start: number, end: number): RuntimeTensor;
|
|
32
|
+
export declare function subarrayCopy1rRow(srcData: Float64Array, srcLen: number, start: number, end: number): RuntimeTensor;
|
|
33
|
+
export declare function setCol2r_h(dstData: Float64Array, dstRows: number, dstLen: number, col: number, srcData: Float64Array, srcLen: number): void;
|
|
@@ -3,13 +3,9 @@
|
|
|
3
3
|
* Handles element-wise binary/unary ops, comparison ops, concat, and
|
|
4
4
|
* tensor coercion for struct-array field access.
|
|
5
5
|
*/
|
|
6
|
-
import {
|
|
7
|
-
import type { RuntimeComplexNumber } from "
|
|
8
|
-
export declare function makeTensor(data:
|
|
9
|
-
/** Bump rc on a tensor (no-op for non-tensor values). Used for var-to-var
|
|
10
|
-
* JIT assignments so the aliased tensor is no longer eligible for
|
|
11
|
-
* in-place buffer reuse. */
|
|
12
|
-
export declare function shareTensor(v: unknown): unknown;
|
|
6
|
+
import { RuntimeTensor } from "../../../runtime/types.js";
|
|
7
|
+
import type { RuntimeComplexNumber } from "../../../runtime/types.js";
|
|
8
|
+
export declare function makeTensor(data: Float64Array, imag: Float64Array | undefined, shape: number[]): RuntimeTensor;
|
|
13
9
|
type ScalarVal = number | RuntimeComplexNumber;
|
|
14
10
|
export declare function tensorBinaryOp(a: unknown, b: unknown, realOp: (x: number, y: number) => number, complexOp: (a: ScalarVal, b: ScalarVal) => ScalarVal): RuntimeTensor | ScalarVal;
|
|
15
11
|
export declare function tensorCompareOp(a: unknown, b: unknown, cmp: (x: number, y: number) => boolean): RuntimeTensor;
|
|
@@ -18,6 +14,10 @@ export declare function tensorNeg(dest: unknown, a: RuntimeTensor): RuntimeTenso
|
|
|
18
14
|
export declare function tDouble(v: unknown): unknown;
|
|
19
15
|
export declare function tSum(v: unknown): unknown;
|
|
20
16
|
export declare function vconcatGrow1r(base: unknown, v: number): RuntimeTensor;
|
|
17
|
+
/** Unconditionally allocate a fresh wrapper + buffer for `t`. The caller
|
|
18
|
+
* can mutate the result without affecting any other alias of the input.
|
|
19
|
+
* Used by the JIT path on entry to a write-target hoisted alias; the
|
|
20
|
+
* runtime indexed-store path uses the sweep instead. */
|
|
21
21
|
export declare function unshare(t: unknown): RuntimeTensor;
|
|
22
22
|
export declare function asTensor(v: unknown): RuntimeTensor;
|
|
23
23
|
export declare const tAdd: (dest: unknown, a: unknown, b: unknown) => RuntimeTensor | ScalarVal;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* User-function call — phased pipeline.
|
|
3
|
+
*
|
|
4
|
+
* 1. `classifyCall` — cheap classification + cacheKey synthesis.
|
|
5
|
+
* Type-infer args, prune `exact` for numeric scalars, type
|
|
6
|
+
* widening using fn._lastJitArgTypes. Returns null on
|
|
7
|
+
* type-unknown args or `~` placeholder params.
|
|
8
|
+
*
|
|
9
|
+
* 2. `lowerCall` — IR lowering.
|
|
10
|
+
*
|
|
11
|
+
* 3. `generateCallJS` — JS codegen + `new Function`.
|
|
12
|
+
*
|
|
13
|
+
* 4. `runCallCompiled` — push call frame + cleanup scope, invoke
|
|
14
|
+
* compiled fn, pop frame. Translates JitBailToInterpreter into
|
|
15
|
+
* a transient bail.
|
|
16
|
+
*/
|
|
17
|
+
import type { Interpreter } from "../../interpreter/interpreter.js";
|
|
18
|
+
import type { FunctionDef } from "../../interpreter/types.js";
|
|
19
|
+
import { type JitType } from "../../jitTypes.js";
|
|
20
|
+
import { type LoweringResult } from "./lower/jitLower.js";
|
|
21
|
+
/** Cheap pre-lowering data. */
|
|
22
|
+
export interface CallClassification {
|
|
23
|
+
readonly fn: FunctionDef;
|
|
24
|
+
readonly nargout: number;
|
|
25
|
+
readonly argTypes: readonly JitType[];
|
|
26
|
+
readonly cacheKey: string;
|
|
27
|
+
/**
|
|
28
|
+
* Effective JS parameter names for this specialization. Mirrors
|
|
29
|
+
* `fn.params` for non-varargin functions. For varargin functions,
|
|
30
|
+
* the trailing `varargin` is replaced with one synthetic name per
|
|
31
|
+
* variadic arg (`$va_0`, `$va_1`, …) so each variadic arg becomes
|
|
32
|
+
* a regular JS function parameter. argTypes is one-to-one with
|
|
33
|
+
* effectiveParams.
|
|
34
|
+
*/
|
|
35
|
+
readonly effectiveParams: readonly string[];
|
|
36
|
+
/** Number of variadic args (0 when fn has no varargin). */
|
|
37
|
+
readonly nVarargin: number;
|
|
38
|
+
}
|
|
39
|
+
/** Lowered IR plus the classification it came from. */
|
|
40
|
+
export interface CallLowered {
|
|
41
|
+
readonly classification: CallClassification;
|
|
42
|
+
readonly result: LoweringResult;
|
|
43
|
+
}
|
|
44
|
+
/** A compiled JS artifact ready to run. */
|
|
45
|
+
export interface CallCompiled {
|
|
46
|
+
readonly fn: (...args: unknown[]) => unknown;
|
|
47
|
+
readonly source: string;
|
|
48
|
+
}
|
|
49
|
+
export declare function classifyCall(fn: FunctionDef, args: unknown[], nargout: number, prevArgTypes: readonly JitType[] | undefined): CallClassification | null;
|
|
50
|
+
export declare function lowerCall(interp: Interpreter, classification: CallClassification): CallLowered | null;
|
|
51
|
+
export declare function generateCallJS(interp: Interpreter, lowered: CallLowered): CallCompiled | null;
|
|
52
|
+
export type CallRunOutcome = {
|
|
53
|
+
ok: true;
|
|
54
|
+
result: unknown;
|
|
55
|
+
} | {
|
|
56
|
+
ok: false;
|
|
57
|
+
transient: boolean;
|
|
58
|
+
};
|
|
59
|
+
export declare function runCallCompiled(interp: Interpreter, fn: FunctionDef, compiled: CallCompiled, args: unknown[]): CallRunOutcome;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* For/while loop body — phased pipeline.
|
|
3
|
+
*
|
|
4
|
+
* 1. `classifyLoop` — analyze loop, gather typed env inputs,
|
|
5
|
+
* live-out filter on outputs (using post-siblings), type
|
|
6
|
+
* widening, cacheKey synthesis.
|
|
7
|
+
*
|
|
8
|
+
* 2. `lowerLoop` — wrap as a synthetic `FunctionDef` and
|
|
9
|
+
* lower via `lowerSyntheticFn`.
|
|
10
|
+
*
|
|
11
|
+
* 3. `generateLoopJS` — `generateSyntheticFnJS` + diagnostics.
|
|
12
|
+
*
|
|
13
|
+
* 4. `runLoopCompiled` — `runSyntheticFnAgainstEnv`.
|
|
14
|
+
*
|
|
15
|
+
* Shared with top-level via `shared.ts`. What's loop-specific is
|
|
16
|
+
* the analysis (For/While discrimination), the live-out filter
|
|
17
|
+
* against post-siblings, the cacheKey location (per loop AST
|
|
18
|
+
* span), and the `$loop_for` / `$loop_while` synthetic name.
|
|
19
|
+
*/
|
|
20
|
+
import type { Interpreter } from "../../interpreter/interpreter.js";
|
|
21
|
+
import type { Stmt } from "../../parser/types.js";
|
|
22
|
+
import type { JitType } from "../../jitTypes.js";
|
|
23
|
+
import type { LoweringResult } from "./lower/jitLower.js";
|
|
24
|
+
import { type SyntheticFnRunResult } from "./shared.js";
|
|
25
|
+
export type LoopKind = "for" | "while";
|
|
26
|
+
export interface LoopClassification {
|
|
27
|
+
readonly stmt: Stmt & {
|
|
28
|
+
type: "For" | "While";
|
|
29
|
+
};
|
|
30
|
+
readonly kind: LoopKind;
|
|
31
|
+
readonly inputs: readonly string[];
|
|
32
|
+
readonly inputTypes: readonly JitType[];
|
|
33
|
+
readonly outputs: readonly string[];
|
|
34
|
+
readonly hasReturn: boolean;
|
|
35
|
+
readonly cacheKey: string;
|
|
36
|
+
}
|
|
37
|
+
export interface LoopLowered {
|
|
38
|
+
readonly classification: LoopClassification;
|
|
39
|
+
readonly result: LoweringResult;
|
|
40
|
+
}
|
|
41
|
+
export interface LoopCompiled {
|
|
42
|
+
readonly fn: (...args: unknown[]) => unknown;
|
|
43
|
+
readonly source: string;
|
|
44
|
+
}
|
|
45
|
+
export type LoopRunResult = SyntheticFnRunResult;
|
|
46
|
+
/** `postSiblings` / `postIdx` describe the stmt list this loop sits
|
|
47
|
+
* in; used to compute the live-out filter on outputs. */
|
|
48
|
+
export declare function classifyLoop(interp: Interpreter, stmt: Stmt & {
|
|
49
|
+
type: "For" | "While";
|
|
50
|
+
}, postSiblings: readonly Stmt[], postIdx: number, prevInputTypes: readonly JitType[] | undefined): LoopClassification | null;
|
|
51
|
+
export declare function lowerLoop(interp: Interpreter, classification: LoopClassification): LoopLowered | null;
|
|
52
|
+
export declare function generateLoopJS(interp: Interpreter, lowered: LoopLowered): LoopCompiled | null;
|
|
53
|
+
export declare function runLoopCompiled(interp: Interpreter, compiled: LoopCompiled, classification: LoopClassification): LoopRunResult;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Top-level script body — phased pipeline.
|
|
3
|
+
*
|
|
4
|
+
* 1. `classifyTopLevel` — analyze script body, gather typed env
|
|
5
|
+
* inputs, type widening, cacheKey synthesis.
|
|
6
|
+
*
|
|
7
|
+
* 2. `lowerTopLevel` — wrap as a synthetic `FunctionDef` and
|
|
8
|
+
* lower via `lowerSyntheticFn`.
|
|
9
|
+
*
|
|
10
|
+
* 3. `generateTopLevelJS` — `generateSyntheticFnJS` + diagnostics.
|
|
11
|
+
*
|
|
12
|
+
* 4. `runTopLevelCompiled` — `runSyntheticFnAgainstEnv`.
|
|
13
|
+
*
|
|
14
|
+
* The shared mechanics live in `shared.ts`; this module spells out
|
|
15
|
+
* what's actually top-level-specific (whole-script body, no
|
|
16
|
+
* post-loop liveness filter, `$top` synthetic name).
|
|
17
|
+
*/
|
|
18
|
+
import type { Interpreter } from "../../interpreter/interpreter.js";
|
|
19
|
+
import type { Stmt } from "../../parser/types.js";
|
|
20
|
+
import type { JitType } from "../../jitTypes.js";
|
|
21
|
+
import type { LoweringResult } from "./lower/jitLower.js";
|
|
22
|
+
import { type SyntheticFnRunResult } from "./shared.js";
|
|
23
|
+
export interface TopLevelClassification {
|
|
24
|
+
readonly stmts: readonly Stmt[];
|
|
25
|
+
readonly inputs: readonly string[];
|
|
26
|
+
readonly inputTypes: readonly JitType[];
|
|
27
|
+
readonly outputs: readonly string[];
|
|
28
|
+
readonly currentFile: string;
|
|
29
|
+
readonly hasReturn: boolean;
|
|
30
|
+
readonly cacheKey: string;
|
|
31
|
+
}
|
|
32
|
+
export interface TopLevelLowered {
|
|
33
|
+
readonly classification: TopLevelClassification;
|
|
34
|
+
readonly result: LoweringResult;
|
|
35
|
+
}
|
|
36
|
+
export interface TopLevelCompiled {
|
|
37
|
+
readonly fn: (...args: unknown[]) => unknown;
|
|
38
|
+
readonly source: string;
|
|
39
|
+
}
|
|
40
|
+
export type TopLevelRunResult = SyntheticFnRunResult;
|
|
41
|
+
export declare function classifyTopLevel(interp: Interpreter, stmts: readonly Stmt[], prevInputTypes: readonly JitType[] | undefined): TopLevelClassification | null;
|
|
42
|
+
export declare function lowerTopLevel(interp: Interpreter, classification: TopLevelClassification): TopLevelLowered | null;
|
|
43
|
+
export declare function generateTopLevelJS(interp: Interpreter, lowered: TopLevelLowered): TopLevelCompiled | null;
|
|
44
|
+
export declare function runTopLevelCompiled(interp: Interpreter, compiled: TopLevelCompiled, classification: TopLevelClassification): TopLevelRunResult;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* js-jit-loop — JS codegen executor for the loop shape.
|
|
3
|
+
*
|
|
4
|
+
* - `propose()` filters on `lowered.kind === "loop"`, applies
|
|
5
|
+
* JIT-feasibility checks (hasReturn, IO+bail-risk).
|
|
6
|
+
*
|
|
7
|
+
* - `compile()` calls `generateLoopJS`. Cached by the registry
|
|
8
|
+
* under the classification's cacheKey.
|
|
9
|
+
*
|
|
10
|
+
* - `run()` calls `runLoopCompiled`. JitBailToInterpreter →
|
|
11
|
+
* transient bail; JitFuncHandleBailError → permanent bail.
|
|
12
|
+
*/
|
|
13
|
+
import type { Executor } from "../types.js";
|
|
14
|
+
import { type LoopLowered, type LoopCompiled } from "./jitLoop.js";
|
|
15
|
+
export declare const jsJitLoopExecutor: Executor<LoopLowered, LoopCompiled | null>;
|
package/dist-lib/numbl-core/{jit/jitLoopAnalysis.d.ts → executors/jsJit/lower/blockAnalysis.d.ts}
RENAMED
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
* - referenced: variables read inside the loop
|
|
7
7
|
* - hasReturn: whether the loop body contains a return statement
|
|
8
8
|
*/
|
|
9
|
-
import type { Stmt } from "
|
|
10
|
-
export interface
|
|
9
|
+
import type { Stmt } from "../../../parser/types.js";
|
|
10
|
+
export interface BlockVarInfo {
|
|
11
11
|
/** Variables referenced in the loop that must come from enclosing scope */
|
|
12
12
|
inputs: string[];
|
|
13
13
|
/** Variables assigned in the loop body (written back after JIT execution) */
|
|
@@ -18,7 +18,7 @@ export interface LoopVarInfo {
|
|
|
18
18
|
/** Analyze a for loop statement for JIT compilation. */
|
|
19
19
|
export declare function analyzeForLoop(stmt: Stmt & {
|
|
20
20
|
type: "For";
|
|
21
|
-
}):
|
|
21
|
+
}): BlockVarInfo;
|
|
22
22
|
/**
|
|
23
23
|
* Collect the names of all variables read in a sibling-tail starting at
|
|
24
24
|
* `startIdx` of the given stmt list. Used by the loop JIT to filter the
|
|
@@ -30,8 +30,8 @@ export declare function collectReadsFromSiblings(stmts: Stmt[], startIdx: number
|
|
|
30
30
|
* Analyze a top-level script body (list of statements) for JIT compilation.
|
|
31
31
|
* Used by `tryJitTopLevel` to wrap the whole main script as a synthetic fn.
|
|
32
32
|
*/
|
|
33
|
-
export declare function analyzeTopLevel(stmts: Stmt[]):
|
|
33
|
+
export declare function analyzeTopLevel(stmts: Stmt[]): BlockVarInfo;
|
|
34
34
|
/** Analyze a while loop statement for JIT compilation. */
|
|
35
35
|
export declare function analyzeWhileLoop(stmt: Stmt & {
|
|
36
36
|
type: "While";
|
|
37
|
-
}):
|
|
37
|
+
}): BlockVarInfo;
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
* of `UserCall`-ed functions (via `generatedIRBodies`), since a bail
|
|
16
16
|
* inside a callee still forces the caller to re-run.
|
|
17
17
|
*/
|
|
18
|
-
import type { JitStmt } from "
|
|
18
|
+
import type { JitStmt } from "../../../jitTypes.js";
|
|
19
19
|
import type { GeneratedFn } from "./jitLower.js";
|
|
20
20
|
/**
|
|
21
21
|
* Names of I/O-emitting builtins that the JIT is willing to lower as
|
|
@@ -9,9 +9,9 @@
|
|
|
9
9
|
* Returns null if any unsupported construct is encountered, causing the
|
|
10
10
|
* entire function to fall back to interpretation.
|
|
11
11
|
*/
|
|
12
|
-
import type { FunctionDef } from "
|
|
13
|
-
import type { Interpreter } from "
|
|
14
|
-
import type { JitType, JitExpr, JitStmt } from "
|
|
12
|
+
import type { FunctionDef } from "../../../interpreter/types.js";
|
|
13
|
+
import type { Interpreter } from "../../../interpreter/interpreter.js";
|
|
14
|
+
import type { JitType, JitExpr, JitStmt } from "../../../jitTypes.js";
|
|
15
15
|
import { type TypeEnv } from "./jitLowerTypes.js";
|
|
16
16
|
/**
|
|
17
17
|
* Lowered IR for a user function reached during a top-level lowering.
|
|
@@ -111,6 +111,17 @@ export interface LowerCtx {
|
|
|
111
111
|
* the body reads the `nargout` identifier, since the JIT specializes per
|
|
112
112
|
* nargout already. */
|
|
113
113
|
nargout?: number;
|
|
114
|
+
/** The nargin this specialization was requested with. Set whenever the
|
|
115
|
+
* function is varargin (the call shape pins down nargin per spec).
|
|
116
|
+
* Reads of bare `nargin` get inlined to this constant; `nargin > K`
|
|
117
|
+
* guards then constant-fold so dead branches don't have to lower. */
|
|
118
|
+
nargin?: number;
|
|
119
|
+
/** Number of variadic args bound for this specialization (0 for
|
|
120
|
+
* non-varargin callees). Used by `varargin{i}` lowering to redirect to
|
|
121
|
+
* the synthetic `$va_*` param holding the i-th variadic arg. The
|
|
122
|
+
* varargin lowering only needs the count — the synthetic name is
|
|
123
|
+
* derived from the literal index alone. */
|
|
124
|
+
nVarargin?: number;
|
|
114
125
|
generatedFns: Map<string, string>;
|
|
115
126
|
generatedIRBodies: Map<string, GeneratedFn>;
|
|
116
127
|
loweringInProgress: Set<string>;
|
|
@@ -119,4 +130,7 @@ export interface LowerCtx {
|
|
|
119
130
|
}
|
|
120
131
|
/** Idempotent bail-reason setter. Only the first reason per function sticks. */
|
|
121
132
|
export declare function setBailReason(ctx: LowerCtx, reason: string, line?: number): void;
|
|
122
|
-
export declare function lowerFunction(fn: FunctionDef, argTypes: JitType[], nargout: number, interp?: Interpreter, generatedFns?: Map<string, string>, loweringInProgress?: Set<string>, generatedIRBodies?: Map<string, GeneratedFn
|
|
133
|
+
export declare function lowerFunction(fn: FunctionDef, argTypes: JitType[], nargout: number, interp?: Interpreter, generatedFns?: Map<string, string>, loweringInProgress?: Set<string>, generatedIRBodies?: Map<string, GeneratedFn>, varargs?: {
|
|
134
|
+
effectiveParams: string[];
|
|
135
|
+
nVarargin: number;
|
|
136
|
+
}): LoweringResult | null;
|
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* exprs may trigger nested lowering of a callee's body). jitLower.ts is
|
|
5
5
|
* the orchestrator that ties them together via LowerCtx + lowerFunction.
|
|
6
6
|
*/
|
|
7
|
-
import type { Expr } from "
|
|
8
|
-
import {
|
|
7
|
+
import type { Expr } from "../../../parser/types.js";
|
|
8
|
+
import type { Interpreter } from "../../../interpreter/interpreter.js";
|
|
9
|
+
import { type JitType, type JitExpr } from "../../../jitTypes.js";
|
|
9
10
|
import type { LowerCtx } from "./jitLower.js";
|
|
10
11
|
export declare function lowerExpr(ctx: LowerCtx, expr: Expr): JitExpr | null;
|
|
11
12
|
/**
|
|
@@ -25,3 +26,11 @@ export declare function tryLowerRangeSliceRead(ctx: LowerCtx, baseName: string,
|
|
|
25
26
|
export declare function lowerIBuiltinCall(ctx: LowerCtx, expr: Expr & {
|
|
26
27
|
type: "FuncCall";
|
|
27
28
|
}): JitExpr | null;
|
|
29
|
+
/**
|
|
30
|
+
* Multi-output variant of probeFuncHandleReturnType. Calls the handle
|
|
31
|
+
* with the requested nargout and returns one JitType per output. Bails
|
|
32
|
+
* (returns null) on the same conditions as the single-output probe
|
|
33
|
+
* (handle without jsFn, args we can't synthesize, output containing
|
|
34
|
+
* unknown), or when the result isn't an array of the expected length.
|
|
35
|
+
*/
|
|
36
|
+
export declare function probeFuncHandleMultiReturnTypes(interp: Interpreter, fnName: string, loweredArgs: JitExpr[], nargout: number): JitType[] | null;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* sides are mutually recursive. jitLower.ts is the orchestrator that ties
|
|
4
4
|
* them together via LowerCtx + lowerFunction.
|
|
5
5
|
*/
|
|
6
|
-
import type { Stmt } from "
|
|
7
|
-
import { type JitStmt } from "
|
|
6
|
+
import type { Stmt } from "../../../parser/types.js";
|
|
7
|
+
import { type JitStmt } from "../../../jitTypes.js";
|
|
8
8
|
import type { LowerCtx } from "./jitLower.js";
|
|
9
9
|
export declare function lowerStmts(ctx: LowerCtx, stmts: Stmt[]): JitStmt[] | null;
|
|
@@ -9,8 +9,8 @@
|
|
|
9
9
|
*
|
|
10
10
|
* These have no dependency on LowerCtx or the lowering state.
|
|
11
11
|
*/
|
|
12
|
-
import { BinaryOperation, UnaryOperation } from "
|
|
13
|
-
import { type JitExpr, type JitType, type SignCategory } from "
|
|
12
|
+
import { BinaryOperation, UnaryOperation } from "../../../parser/types.js";
|
|
13
|
+
import { type JitExpr, type JitType, type SignCategory } from "../../../jitTypes.js";
|
|
14
14
|
export declare const KNOWN_CONSTANTS: Record<string, number>;
|
|
15
15
|
export type TypeEnv = Map<string, JitType>;
|
|
16
16
|
export declare function cloneEnv(env: TypeEnv): TypeEnv;
|
|
@@ -11,8 +11,8 @@
|
|
|
11
11
|
* Complex-scalar and tensor ops are *not* covered here — those remain
|
|
12
12
|
* backend-specific (JS uses `$h.cAdd` etc.; C-JIT bails on complex).
|
|
13
13
|
*/
|
|
14
|
-
import { BinaryOperation, UnaryOperation } from "
|
|
15
|
-
import type { JitExpr } from "
|
|
14
|
+
import { BinaryOperation, UnaryOperation } from "../../../parser/types.js";
|
|
15
|
+
import type { JitExpr } from "../../../jitTypes.js";
|
|
16
16
|
export interface ScalarOpTarget {
|
|
17
17
|
binAdd(l: string, r: string): string;
|
|
18
18
|
binSub(l: string, r: string): string;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared helpers for the JS-JIT shape modules.
|
|
3
|
+
*
|
|
4
|
+
* The three shape modules (`jitTopLevel.ts`, `jitLoop.ts`,
|
|
5
|
+
* `jitCall.ts`) all do the same handful of things — type inference
|
|
6
|
+
* with `exact` pruning, progressive type widening, JS body assembly,
|
|
7
|
+
* `new Function` instantiation, env writeback. Those bits live here
|
|
8
|
+
* so the shape modules can stay focused on what's actually different
|
|
9
|
+
* between them (synthetic-fn shape, cacheKey scheme, run-time entry).
|
|
10
|
+
*/
|
|
11
|
+
import type { Interpreter } from "../../interpreter/interpreter.js";
|
|
12
|
+
import type { Runtime } from "../../runtime/runtime.js";
|
|
13
|
+
import type { JitType } from "../../jitTypes.js";
|
|
14
|
+
import { type LoweringResult } from "./lower/jitLower.js";
|
|
15
|
+
import type { Stmt } from "../../parser/types.js";
|
|
16
|
+
/** Names that look like variables but never resolve to env values
|
|
17
|
+
* inside the JIT (constants, literals, the special `end` slot, the
|
|
18
|
+
* imaginary unit). Skipped when collecting env inputs. */
|
|
19
|
+
export declare const KNOWN_CONSTANTS: ReadonlySet<string>;
|
|
20
|
+
/**
|
|
21
|
+
* Drop `exact` from a numeric scalar `JitType`. Numeric `exact` only
|
|
22
|
+
* survives unification when two consecutive specializations see the
|
|
23
|
+
* *same* literal — almost never the case for variables — so stripping
|
|
24
|
+
* up front means the first specialization's cacheKey already matches
|
|
25
|
+
* later calls.
|
|
26
|
+
*/
|
|
27
|
+
export declare function pruneArgType(t: JitType): JitType;
|
|
28
|
+
/**
|
|
29
|
+
* Progressive type widening: in-place unify each entry of `types`
|
|
30
|
+
* with the corresponding entry of `prev`. No-op when shapes don't
|
|
31
|
+
* match (different arity → different specialization, no widening).
|
|
32
|
+
*
|
|
33
|
+
* Widening that would collapse a known type to `unknown` is rejected
|
|
34
|
+
* — keep this call's concrete type so a fresh, specific spec gets
|
|
35
|
+
* built. Without this, a 1st call with (number, …) followed by a 2nd
|
|
36
|
+
* call with (tensor, …) would unify the first arg to `unknown` and
|
|
37
|
+
* poison every subsequent specialization with the same arg shape
|
|
38
|
+
* (chunkie hits this with `fcurve(ta)` (scalar discovery) followed
|
|
39
|
+
* by `fcurve(ts)` (tensor)).
|
|
40
|
+
*/
|
|
41
|
+
export declare function widenAgainst(types: JitType[], prev: readonly JitType[] | undefined): void;
|
|
42
|
+
/**
|
|
43
|
+
* Gather env inputs for the synthetic FunctionDef of a top-level or
|
|
44
|
+
* loop block. For each candidate name: skip known constants, skip
|
|
45
|
+
* names not in env (likely fn names), infer the JIT type, prune
|
|
46
|
+
* `exact`. Returns null if any candidate has an unknown type — that's
|
|
47
|
+
* a structural blocker for lowering.
|
|
48
|
+
*/
|
|
49
|
+
export declare function gatherTypedEnvInputs(interp: Interpreter, candidates: readonly string[]): {
|
|
50
|
+
inputs: string[];
|
|
51
|
+
inputTypes: JitType[];
|
|
52
|
+
} | null;
|
|
53
|
+
/**
|
|
54
|
+
* Build a `// File: …` + indented source-slice comment block for the
|
|
55
|
+
* code being JIT-compiled. Used by `--dump-js` so each emitted JS
|
|
56
|
+
* section is annotated with the .m source it came from. Falls back
|
|
57
|
+
* gracefully when the source isn't in `interp.fileSources`.
|
|
58
|
+
*
|
|
59
|
+
* `start` is rewound to the beginning of its line so the first line
|
|
60
|
+
* keeps its original indentation (Stmt spans start at the first
|
|
61
|
+
* non-whitespace char, which would otherwise leave the first line
|
|
62
|
+
* dedented relative to the rest).
|
|
63
|
+
*/
|
|
64
|
+
export declare function buildJitSourceComment(interp: Interpreter, file: string, start: number, end: number): string;
|
|
65
|
+
/**
|
|
66
|
+
* Read the live env values for `inputs` in order. Used at run time
|
|
67
|
+
* to bind the compiled fn's parameters before invocation.
|
|
68
|
+
*/
|
|
69
|
+
export declare function gatherEnvValues(interp: Interpreter, inputs: readonly string[]): unknown[];
|
|
70
|
+
/**
|
|
71
|
+
* Build the JS body for a synthetic FunctionDef: prepend each
|
|
72
|
+
* generated callee body (indented 2 spaces to nest inside the
|
|
73
|
+
* outer function), then append the main body.
|
|
74
|
+
*/
|
|
75
|
+
export declare function assembleJsBody(result: LoweringResult, mainBody: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Wrap a JS body string in a `new Function(...)` and bind it to the
|
|
78
|
+
* runtime's helpers and `$rt`. Returns null when the body fails to
|
|
79
|
+
* parse (defensive — should not happen for IR that lowering accepted).
|
|
80
|
+
*/
|
|
81
|
+
export declare function instantiateJsFn(rt: Runtime, paramNames: readonly string[], jsBody: string): ((...args: unknown[]) => unknown) | null;
|
|
82
|
+
/**
|
|
83
|
+
* Write a compiled fn's return value back into the interpreter env.
|
|
84
|
+
* The compiled fn returns either a single value (for one-output fns)
|
|
85
|
+
* or an array of values (for multi-output) — matching the JS-JIT
|
|
86
|
+
* convention used in the wrapper layer.
|
|
87
|
+
*/
|
|
88
|
+
export declare function writeBackOutputs(interp: Interpreter, outputs: readonly string[], result: unknown): void;
|
|
89
|
+
/**
|
|
90
|
+
* Build a synthetic `FunctionDef` from (name, inputs, outputs, body)
|
|
91
|
+
* and lower it through `lowerFunction`. Returns null when lowering
|
|
92
|
+
* declines (constructs the JS-JIT IR doesn't model).
|
|
93
|
+
*/
|
|
94
|
+
export declare function lowerSyntheticFn(interp: Interpreter, name: string, inputs: readonly string[], inputTypes: readonly JitType[], outputs: readonly string[], body: Stmt[]): LoweringResult | null;
|
|
95
|
+
/**
|
|
96
|
+
* Generate JS for a synthetic-fn lowered IR and instantiate it.
|
|
97
|
+
* Returns null when `new Function` throws (defensive — should not
|
|
98
|
+
* happen for IR that lowering accepted). Both top-level and loop
|
|
99
|
+
* codegen use this; the shape module then wraps the returned fn in
|
|
100
|
+
* its `*Compiled` shape and emits its own source/diagnostics.
|
|
101
|
+
*/
|
|
102
|
+
export declare function generateSyntheticFnJS(interp: Interpreter, result: LoweringResult, inputs: readonly string[], outputCount: number): {
|
|
103
|
+
fn: (...args: unknown[]) => unknown;
|
|
104
|
+
jsBody: string;
|
|
105
|
+
} | null;
|
|
106
|
+
/** Outcome of `runSyntheticFnAgainstEnv`. `transient` distinguishes
|
|
107
|
+
* the recoverable JitBailToInterpreter case (cache preserved) from
|
|
108
|
+
* the hard JitFuncHandleBailError case (cache invalidated). */
|
|
109
|
+
export type SyntheticFnRunResult = {
|
|
110
|
+
ok: true;
|
|
111
|
+
} | {
|
|
112
|
+
ok: false;
|
|
113
|
+
transient: boolean;
|
|
114
|
+
};
|
|
115
|
+
/**
|
|
116
|
+
* Gather input values from env, invoke the compiled fn, write back
|
|
117
|
+
* outputs. Translates JIT bails to a SyntheticFnRunResult. Used by
|
|
118
|
+
* both top-level and loop run phases.
|
|
119
|
+
*/
|
|
120
|
+
export declare function runSyntheticFnAgainstEnv(interp: Interpreter, fn: (...args: unknown[]) => unknown, inputs: readonly string[], outputs: readonly string[]): SyntheticFnRunResult;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* js-jit-top-level — JS codegen executor for the top-level shape.
|
|
3
|
+
*
|
|
4
|
+
* - `propose()` filters on `lowered.kind === "top-level"`, applies
|
|
5
|
+
* JIT-feasibility checks (hasReturn, display mode + unsuppressed
|
|
6
|
+
* assigns, IO+bail-risk).
|
|
7
|
+
*
|
|
8
|
+
* - `compile()` calls `generateTopLevelJS`. Cached by the registry
|
|
9
|
+
* under the classification's cacheKey.
|
|
10
|
+
*
|
|
11
|
+
* - `run()` calls `runTopLevelCompiled`. JitBailToInterpreter →
|
|
12
|
+
* transient bail; JitFuncHandleBailError → permanent bail.
|
|
13
|
+
* `consumed` claims the entire script body.
|
|
14
|
+
*/
|
|
15
|
+
import type { Executor } from "../types.js";
|
|
16
|
+
import { type TopLevelLowered, type TopLevelCompiled } from "./jitTopLevel.js";
|
|
17
|
+
export declare const jsJitTopLevelExecutor: Executor<TopLevelLowered, TopLevelCompiled | null>;
|