@nudojs/core 0.3.0 → 0.4.0
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/dist/chunk-N7E2A7IK.js +7216 -0
- package/dist/exec.d.ts +2 -0
- package/dist/exec.js +174 -0
- package/dist/index-DgyudAkw.d.ts +911 -0
- package/dist/index.d.ts +64 -710
- package/dist/index.js +3269 -8426
- package/package.json +18 -5
- package/CHANGELOG.md +0 -34
- package/src/__tests__/environment.test.ts +0 -48
- package/src/__tests__/fn-sig-impl.test.ts +0 -57
- package/src/__tests__/ops-refined.test.ts +0 -196
- package/src/__tests__/ops.test.ts +0 -84
- package/src/__tests__/type-value-phase2.test.ts +0 -117
- package/src/__tests__/type-value-phase3.test.ts +0 -94
- package/src/__tests__/type-value-refined.test.ts +0 -210
- package/src/__tests__/type-value.test.ts +0 -319
- package/src/algebra/__tests__/abs-native.test.ts +0 -176
- package/src/algebra/__tests__/arithmetic.test.ts +0 -170
- package/src/algebra/__tests__/ast-eval.test.ts +0 -154
- package/src/algebra/__tests__/bridge.test.ts +0 -160
- package/src/algebra/__tests__/call-budget.test.ts +0 -117
- package/src/algebra/__tests__/check-case-consistency.test.ts +0 -69
- package/src/algebra/__tests__/check-gold.test.ts +0 -290
- package/src/algebra/__tests__/check-json.test.ts +0 -57
- package/src/algebra/__tests__/check-mini-repo.test.ts +0 -49
- package/src/algebra/__tests__/check-real-commander.test.ts +0 -43
- package/src/algebra/__tests__/check-real-packages.test.ts +0 -165
- package/src/algebra/__tests__/check-recall-gold.test.ts +0 -1024
- package/src/algebra/__tests__/check-require-dep-memo.test.ts +0 -45
- package/src/algebra/__tests__/check-return-contract.test.ts +0 -90
- package/src/algebra/__tests__/check-shape-gold.test.ts +0 -303
- package/src/algebra/__tests__/check-source-memo.test.ts +0 -204
- package/src/algebra/__tests__/check.test.ts +0 -69
- package/src/algebra/__tests__/denote.test.ts +0 -77
- package/src/algebra/__tests__/diagnostics.test.ts +0 -64
- package/src/algebra/__tests__/differential.test.ts +0 -124
- package/src/algebra/__tests__/div-mod.test.ts +0 -38
- package/src/algebra/__tests__/example0.test.ts +0 -103
- package/src/algebra/__tests__/exec-analyze-throws.test.ts +0 -60
- package/src/algebra/__tests__/exec-async.test.ts +0 -46
- package/src/algebra/__tests__/exec-bpath.test.ts +0 -193
- package/src/algebra/__tests__/exec-class.test.ts +0 -56
- package/src/algebra/__tests__/exec-e2e.test.ts +0 -97
- package/src/algebra/__tests__/exec-generator.test.ts +0 -53
- package/src/algebra/__tests__/exec-inherit-default.test.ts +0 -111
- package/src/algebra/__tests__/exec-optional-nested.test.ts +0 -87
- package/src/algebra/__tests__/exec-rest.test.ts +0 -55
- package/src/algebra/__tests__/exec-spread-forof.test.ts +0 -85
- package/src/algebra/__tests__/exec-static-computed.test.ts +0 -61
- package/src/algebra/__tests__/exec-switch.test.ts +0 -74
- package/src/algebra/__tests__/exec-trycatch.test.ts +0 -71
- package/src/algebra/__tests__/fn-fp-memo.test.ts +0 -166
- package/src/algebra/__tests__/fn-fp-multidecl.test.ts +0 -49
- package/src/algebra/__tests__/format.test.ts +0 -34
- package/src/algebra/__tests__/generalize-memo.test.ts +0 -285
- package/src/algebra/__tests__/generalize.test.ts +0 -113
- package/src/algebra/__tests__/hash-source.test.ts +0 -19
- package/src/algebra/__tests__/hof.test.ts +0 -80
- package/src/algebra/__tests__/inlay.test.ts +0 -30
- package/src/algebra/__tests__/language.test.ts +0 -77
- package/src/algebra/__tests__/leq.test.ts +0 -109
- package/src/algebra/__tests__/load-deps-fp-memo.test.ts +0 -132
- package/src/algebra/__tests__/methods.test.ts +0 -37
- package/src/algebra/__tests__/node-types.test.ts +0 -26
- package/src/algebra/__tests__/nudo-constraints.ts +0 -46
- package/src/algebra/__tests__/objects.test.ts +0 -117
- package/src/algebra/__tests__/parse-source-cache.test.ts +0 -42
- package/src/algebra/__tests__/refine-import.test.ts +0 -109
- package/src/algebra/__tests__/stable-source-key-block.test.ts +0 -23
- package/src/algebra/__tests__/stable-source-key.test.ts +0 -31
- package/src/algebra/__tests__/surface.test.ts +0 -41
- package/src/algebra/__tests__/this-inherit.test.ts +0 -130
- package/src/algebra/abs-fn.ts +0 -49
- package/src/algebra/abs-modules.ts +0 -139
- package/src/algebra/abs.ts +0 -206
- package/src/algebra/arithmetic.ts +0 -691
- package/src/algebra/ast-eval.ts +0 -1763
- package/src/algebra/bridge.ts +0 -350
- package/src/algebra/builtins.ts +0 -373
- package/src/algebra/check-report.ts +0 -150
- package/src/algebra/check.ts +0 -1867
- package/src/algebra/constraint.ts +0 -304
- package/src/algebra/denote.ts +0 -166
- package/src/algebra/diagnostics.ts +0 -210
- package/src/algebra/exec/call.ts +0 -29
- package/src/algebra/exec/calls.ts +0 -96
- package/src/algebra/exec/class-registry.ts +0 -29
- package/src/algebra/exec/class.ts +0 -329
- package/src/algebra/exec/index.ts +0 -6
- package/src/algebra/exec/member-diag.ts +0 -141
- package/src/algebra/exec/run.ts +0 -341
- package/src/algebra/exec/runtime.ts +0 -583
- package/src/algebra/exec/transpile.ts +0 -993
- package/src/algebra/fn-fp.ts +0 -294
- package/src/algebra/format.ts +0 -91
- package/src/algebra/generalize.ts +0 -776
- package/src/algebra/hash-source.ts +0 -27
- package/src/algebra/index.ts +0 -34
- package/src/algebra/inlay.ts +0 -198
- package/src/algebra/language.ts +0 -289
- package/src/algebra/leak.ts +0 -68
- package/src/algebra/leq.ts +0 -301
- package/src/algebra/load-deps-fp.ts +0 -97
- package/src/algebra/methods.ts +0 -128
- package/src/algebra/objects.ts +0 -251
- package/src/algebra/parse-source.ts +0 -64
- package/src/algebra/phi.ts +0 -42
- package/src/algebra/pred.ts +0 -395
- package/src/algebra/refine.ts +0 -227
- package/src/algebra/stable-source-key.ts +0 -81
- package/src/algebra/surface.ts +0 -206
- package/src/algebra/template.ts +0 -143
- package/src/algebra/term.ts +0 -119
- package/src/environment.ts +0 -74
- package/src/index.ts +0 -73
- package/src/mock-helpers.ts +0 -166
- package/src/ops.ts +0 -191
- package/src/refinements/range.ts +0 -86
- package/src/refinements/template-predicates.ts +0 -11
- package/src/refinements/template.ts +0 -176
- package/src/strip-types.ts +0 -236
- package/src/type-value.ts +0 -513
- package/tsconfig.json +0 -8
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { Node, File
|
|
1
|
+
import { Node, File } from '@babel/types';
|
|
2
|
+
import { P as Phi, A as AstEnv, a as Abs, C as Confidence, b as Pred, S as Shape, c as PrimName, T as Term, R as RelSource, H as HofSite, L as LeakBudget } from './index-DgyudAkw.js';
|
|
3
|
+
export { $ as $add, d as $arr, e as $async, f as $asyncReturn, g as $await, h as $call, i as $callNamed, j as $catchVal, k as $class, l as $concat, m as $div, n as $elems, o as $eq, p as $fnVal, q as $for, r as $forIter, s as $forOf, t as $fork, u as $ge, v as $gen, w as $get, x as $gt, y as $idx, z as $idxSet, B as $invoke, D as $invokeSuper, E as $join, F as $le, G as $len, I as $lit, J as $lt, K as $mod, M as $mul, N as $ne, O as $neg, Q as $new, U as $not, V as $obj, W as $optionalGet, X as $optionalInvoke, Y as $orDefault, Z as $regex, _ as $set, a0 as $setKey, a1 as $spread, a2 as $staticInvoke, a3 as $sub, a4 as $super, a5 as $switch, a6 as $thisGet, a7 as $thisSet, a8 as $throw, a9 as $typeof, aa as $while, ab as $whileSeq, ac as $yield, ad as AbsAssignRecord, ae as AbsCallRecord, af as AbsModuleExports, ag as BCallRecord, ah as BClassSpec, ai as BMemberDiag, aj as DEFAULT_MAX_LOOP_ITERS, ak as EvalOptions, al as EvalResult, am as HofCollectCtx, an as MAX_CALL_DEPTH, ao as MAX_TOTAL_CALLS, ap as NudoThrow, aq as RunTranspiledOptions, ar as TranspileOptions, as as TranspiledCallResult, at as abs, au as absToString, av as alphaOf, aw as analyzeFn, ax as and, ay as anyVar, az as app, aA as applyAbsFn, aB as applyCallbackAbs, aC as asAbs, aD as asAbsVal, aE as betaOf, aF as bindImports, aG as bool, aH as boolLit, aI as callFunction, aJ as callTranspiledExport, aK as callTranspiledExportFull, aL as clearBClasses, aM as collectAbsExports, aN as collectAbsNodeTypes, aO as confJoin, aP as createHofCollectCtx, aQ as currentExecPhi, aR as defaultLeakBudget, aS as emptyEnv, aT as emptyPhi, aU as eq, aV as evalMethodBody, aW as evalNode, aX as evalProgramAbs, aY as evalSource, aZ as exceedsBudget, a_ as findAbsAtPosition, a$ as ge, b0 as geNum, b1 as getAbsOrigin, b2 as getBCallCollector, b3 as getBClass, b4 as gt, b5 as gtNum, b6 as implies, b7 as instantiateReturn, b8 as isDefinitelyFalse, b9 as isDefinitelyTrue, ba as isExactLit, bb as isNudoThrow, bc as isNumPrim, bd as isRelFn, be as isStrPrim, bf as le, bg as leNum, bh as leakIfNeeded, bi as lit, bj as litTruth, bk as litValue, bl as lt, bm as ltNum, bn as mapElementFallback, bo as maybeLeak, bp as namespaceNameOf, bq as ne, br as never, bs as not, bt as noteMemberDispatchMiss, bu as notePrimMemberMissing, bv as noteUnknownMemberMissing, bw as num, bx as numLit, by as numVar, bz as obj, bA as or, bB as pFalse, bC as pTrue, bD as phiAnd, bE as predEquals, bF as predToString, bG as predVars, bH as projectFlatMapResult, bI as promoteParamShape, bJ as ptypeof, bK as recordMemberDiag, bL as registerBClass, bM as resetAbsCallBudget, bN as resetLeakCounter, bO as runTranspiled, bP as setAbsAssignCollector, bQ as setAbsCallCollector, bR as setAbsNodeCollector, bS as setAbsTruncationCollector, bT as setApplyCallbackHost, bU as setBCallCollector, bV as setMemberDiagCollector, bW as shapeOfTerm, bX as shapeToString, bY as simplifyTerm, bZ as snapshotAbs, b_ as str, b$ as strLit, c0 as substAbs, c1 as substPred, c2 as substPredAbs, c3 as tagAbsOrigin, c4 as termDepth, c5 as termEquals, c6 as termNodes, c7 as termToString, c8 as transpile, c9 as transpileExpression, ca as transpileFile, cb as transpileSource, cc as tryPromoteDirectCall, cd as tryPromoteForOfIteratee, ce as tryPromoteHofCallback, cf as tryPromoteReceiverAsArr, cg as undefAbs, ch as unknown, ci as v, cj as withExecPhi, ck as withVar } from './index-DgyudAkw.js';
|
|
2
4
|
|
|
3
5
|
type Environment = {
|
|
4
6
|
lookup(name: string): TypeValue;
|
|
@@ -12,7 +14,7 @@ type Environment = {
|
|
|
12
14
|
};
|
|
13
15
|
declare function createEnvironment(parent?: Environment, bindings?: Map<string, TypeValue>): Environment;
|
|
14
16
|
|
|
15
|
-
type LiteralValue
|
|
17
|
+
type LiteralValue = string | number | boolean | bigint | null | undefined;
|
|
16
18
|
type SigImpl = (args: TypeValue[], thisVal?: TypeValue) => TypeValue | undefined;
|
|
17
19
|
type FunctionSignature = {
|
|
18
20
|
paramTypes: TypeValue[];
|
|
@@ -30,7 +32,7 @@ type Refinement = {
|
|
|
30
32
|
};
|
|
31
33
|
type TypeValue = {
|
|
32
34
|
kind: "literal";
|
|
33
|
-
value: LiteralValue
|
|
35
|
+
value: LiteralValue;
|
|
34
36
|
} | {
|
|
35
37
|
kind: "primitive";
|
|
36
38
|
type: "number" | "string" | "boolean" | "bigint" | "symbol";
|
|
@@ -70,7 +72,7 @@ type TypeValue = {
|
|
|
70
72
|
};
|
|
71
73
|
declare function createUnion(...members: TypeValue[]): TypeValue;
|
|
72
74
|
declare const T: {
|
|
73
|
-
readonly literal: (value: LiteralValue
|
|
75
|
+
readonly literal: (value: LiteralValue) => TypeValue;
|
|
74
76
|
readonly number: TypeValue;
|
|
75
77
|
readonly string: TypeValue;
|
|
76
78
|
readonly boolean: TypeValue;
|
|
@@ -231,102 +233,6 @@ declare function parseSource(source: string, opts?: {
|
|
|
231
233
|
errorRecovery?: boolean;
|
|
232
234
|
}): File;
|
|
233
235
|
|
|
234
|
-
/** 项(Term):抽象值的身份。字面量是项的特例。 */
|
|
235
|
-
type LiteralValue = string | number | boolean | null | undefined;
|
|
236
|
-
type Term = {
|
|
237
|
-
op: "lit";
|
|
238
|
-
value: LiteralValue;
|
|
239
|
-
} | {
|
|
240
|
-
op: "var";
|
|
241
|
-
id: string;
|
|
242
|
-
} | {
|
|
243
|
-
op: "app";
|
|
244
|
-
fn: string;
|
|
245
|
-
args: Term[];
|
|
246
|
-
};
|
|
247
|
-
declare const lit: (value: LiteralValue) => Term;
|
|
248
|
-
declare const v: (id: string) => Term;
|
|
249
|
-
declare const app: (fn: string, args: Term[]) => Term;
|
|
250
|
-
declare function termEquals(a: Term, b: Term): boolean;
|
|
251
|
-
declare function termToString(t: Term): string;
|
|
252
|
-
/** 常量折叠 + 简单代数化简 */
|
|
253
|
-
declare function simplifyTerm(t: Term): Term;
|
|
254
|
-
|
|
255
|
-
/** 约束(Pred):附着在项上的事实,可传播。 */
|
|
256
|
-
|
|
257
|
-
type PrimName = "number" | "string" | "boolean" | "bigint" | "symbol";
|
|
258
|
-
type Pred = {
|
|
259
|
-
op: "true";
|
|
260
|
-
} | {
|
|
261
|
-
op: "false";
|
|
262
|
-
} | {
|
|
263
|
-
op: "eq";
|
|
264
|
-
a: Term;
|
|
265
|
-
b: Term;
|
|
266
|
-
} | {
|
|
267
|
-
op: "ne";
|
|
268
|
-
a: Term;
|
|
269
|
-
b: Term;
|
|
270
|
-
} | {
|
|
271
|
-
op: "lt";
|
|
272
|
-
a: Term;
|
|
273
|
-
b: Term;
|
|
274
|
-
} | {
|
|
275
|
-
op: "le";
|
|
276
|
-
a: Term;
|
|
277
|
-
b: Term;
|
|
278
|
-
} | {
|
|
279
|
-
op: "gt";
|
|
280
|
-
a: Term;
|
|
281
|
-
b: Term;
|
|
282
|
-
} | {
|
|
283
|
-
op: "ge";
|
|
284
|
-
a: Term;
|
|
285
|
-
b: Term;
|
|
286
|
-
} | {
|
|
287
|
-
op: "and";
|
|
288
|
-
args: Pred[];
|
|
289
|
-
} | {
|
|
290
|
-
op: "or";
|
|
291
|
-
args: Pred[];
|
|
292
|
-
} | {
|
|
293
|
-
op: "not";
|
|
294
|
-
arg: Pred;
|
|
295
|
-
} | {
|
|
296
|
-
op: "typeof";
|
|
297
|
-
t: Term;
|
|
298
|
-
type: PrimName;
|
|
299
|
-
};
|
|
300
|
-
declare const pTrue: Pred;
|
|
301
|
-
declare const pFalse: Pred;
|
|
302
|
-
declare const eq: (a: Term, b: Term) => Pred;
|
|
303
|
-
declare const ne: (a: Term, b: Term) => Pred;
|
|
304
|
-
declare const lt: (a: Term, b: Term) => Pred;
|
|
305
|
-
declare const le: (a: Term, b: Term) => Pred;
|
|
306
|
-
declare const gt: (a: Term, b: Term) => Pred;
|
|
307
|
-
declare const ge: (a: Term, b: Term) => Pred;
|
|
308
|
-
declare const ptypeof: (t: Term, type: PrimName) => Pred;
|
|
309
|
-
declare function and(...preds: Pred[]): Pred;
|
|
310
|
-
declare function or(...preds: Pred[]): Pred;
|
|
311
|
-
declare function not(p: Pred): Pred;
|
|
312
|
-
declare function predEquals(a: Pred, b: Pred): boolean;
|
|
313
|
-
declare function predToString(p: Pred): string;
|
|
314
|
-
/** 把 pred 里的 Term 用 subst 替换(用于 bound 变量重命名等) */
|
|
315
|
-
declare function substPred(p: Pred, subst: (t: Term) => Term): Pred;
|
|
316
|
-
/** 收集 pred 中出现的自由变量 */
|
|
317
|
-
declare function predVars(p: Pred): Set<string>;
|
|
318
|
-
/** 约束环境 Φ:Pred 的合取 */
|
|
319
|
-
type Phi = Pred;
|
|
320
|
-
declare const emptyPhi: Phi;
|
|
321
|
-
declare const phiAnd: typeof and;
|
|
322
|
-
/** 简单蕴含:在区间/字面量可判定范围内判断 Φ ⊢ pred */
|
|
323
|
-
declare function implies(phi: Phi, pred: Pred): boolean;
|
|
324
|
-
/** 便捷:数字下界 */
|
|
325
|
-
declare function gtNum(term: Term, n: number): Pred;
|
|
326
|
-
declare function geNum(term: Term, n: number): Pred;
|
|
327
|
-
declare function ltNum(term: Term, n: number): Pred;
|
|
328
|
-
declare function leNum(term: Term, n: number): Pred;
|
|
329
|
-
|
|
330
236
|
/**
|
|
331
237
|
* 路径约束栈(Φ)。
|
|
332
238
|
*
|
|
@@ -342,279 +248,6 @@ declare function resetPhi(): void;
|
|
|
342
248
|
declare function withPhiConstraint(extra: Phi, body: () => void): void;
|
|
343
249
|
declare function describePhi(): string;
|
|
344
250
|
|
|
345
|
-
/** 抽象值 Abs = 形状 × 项 × 约束 × 置信度 */
|
|
346
|
-
|
|
347
|
-
type Confidence = "exact" | "path" | "widened" | "mock" | "partial" | "opaque";
|
|
348
|
-
type Shape = {
|
|
349
|
-
k: "never";
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* any:JS 里可以是任意值(无约束参数)。
|
|
353
|
-
* 运算按真实 JS 语义取并集,不是「分析失败」。
|
|
354
|
-
*/
|
|
355
|
-
| {
|
|
356
|
-
k: "any";
|
|
357
|
-
}
|
|
358
|
-
/** unknown:分析拿不到信息(求值失败/泄漏),不是「任意值」 */
|
|
359
|
-
| {
|
|
360
|
-
k: "unknown";
|
|
361
|
-
} | {
|
|
362
|
-
k: "prim";
|
|
363
|
-
type: PrimName;
|
|
364
|
-
} | {
|
|
365
|
-
k: "obj";
|
|
366
|
-
slots: Record<string, {
|
|
367
|
-
value: Abs;
|
|
368
|
-
optional?: boolean;
|
|
369
|
-
readonly?: boolean;
|
|
370
|
-
}>;
|
|
371
|
-
index?: {
|
|
372
|
-
key: Abs;
|
|
373
|
-
value: Abs;
|
|
374
|
-
};
|
|
375
|
-
open?: boolean;
|
|
376
|
-
} | {
|
|
377
|
-
k: "arr";
|
|
378
|
-
element: Abs;
|
|
379
|
-
} | {
|
|
380
|
-
k: "tuple";
|
|
381
|
-
elements: Abs[];
|
|
382
|
-
rest?: Abs;
|
|
383
|
-
} | {
|
|
384
|
-
k: "fn";
|
|
385
|
-
params: string[];
|
|
386
|
-
name?: string;
|
|
387
|
-
paramTypes?: Abs[];
|
|
388
|
-
returnType?: Abs;
|
|
389
|
-
} | {
|
|
390
|
-
k: "brand";
|
|
391
|
-
name: string;
|
|
392
|
-
shape: Abs;
|
|
393
|
-
} | {
|
|
394
|
-
k: "eff";
|
|
395
|
-
eff: "promise" | "generator";
|
|
396
|
-
inner: Abs;
|
|
397
|
-
} | {
|
|
398
|
-
k: "sum";
|
|
399
|
-
members: Abs[];
|
|
400
|
-
};
|
|
401
|
-
type Abs = {
|
|
402
|
-
shape: Shape;
|
|
403
|
-
term?: Term;
|
|
404
|
-
pred?: Pred;
|
|
405
|
-
conf: Confidence;
|
|
406
|
-
};
|
|
407
|
-
declare const never: Abs;
|
|
408
|
-
/** 分析无信息 */
|
|
409
|
-
declare const unknown: Abs;
|
|
410
|
-
/** 带 term 的 any(generalize type-var) */
|
|
411
|
-
declare function anyVar(id: string, conf?: Confidence): Abs;
|
|
412
|
-
declare function num(): Abs;
|
|
413
|
-
declare function str(): Abs;
|
|
414
|
-
declare function bool(): Abs;
|
|
415
|
-
declare function numLit(value: number): Abs;
|
|
416
|
-
declare function strLit(value: string): Abs;
|
|
417
|
-
declare function boolLit(value: boolean): Abs;
|
|
418
|
-
/** 带项的符号数,例如参数 x */
|
|
419
|
-
declare function numVar(id: string, pred?: Pred, conf?: Confidence): Abs;
|
|
420
|
-
declare function obj(slots: Record<string, {
|
|
421
|
-
value: Abs;
|
|
422
|
-
optional?: boolean;
|
|
423
|
-
}>): Abs;
|
|
424
|
-
declare function confJoin(a: Confidence, b: Confidence): Confidence;
|
|
425
|
-
declare function absToString(a: Abs): string;
|
|
426
|
-
declare function shapeToString(s: Shape): string;
|
|
427
|
-
/** 从 term 反推 prim shape */
|
|
428
|
-
declare function shapeOfTerm(t: Term): Shape;
|
|
429
|
-
/** 构造带项的结果 Abs;pred 相对 term */
|
|
430
|
-
declare function abs(shape: Shape, term: Term | undefined, pred: Pred | undefined, conf: Confidence): Abs;
|
|
431
|
-
declare function isNumPrim(a: Abs): boolean;
|
|
432
|
-
declare function isStrPrim(a: Abs): boolean;
|
|
433
|
-
/** 置信度:字面量全确定 */
|
|
434
|
-
declare function isExactLit(a: Abs): boolean;
|
|
435
|
-
declare function litValue(a: Abs): LiteralValue | undefined;
|
|
436
|
-
|
|
437
|
-
/**
|
|
438
|
-
* 项(Term)防爆炸:深度/宽度阈值 → leak 为新鲜 var + 等式约束。
|
|
439
|
-
*/
|
|
440
|
-
|
|
441
|
-
type LeakBudget = {
|
|
442
|
-
maxDepth: number;
|
|
443
|
-
maxNodes: number;
|
|
444
|
-
};
|
|
445
|
-
declare const defaultLeakBudget: LeakBudget;
|
|
446
|
-
declare function termDepth(t: Term): number;
|
|
447
|
-
declare function termNodes(t: Term): number;
|
|
448
|
-
declare function exceedsBudget(t: Term, budget?: LeakBudget): boolean;
|
|
449
|
-
declare function resetLeakCounter(): void;
|
|
450
|
-
/**
|
|
451
|
-
* 若项超预算,替换为新鲜变量,并返回附加等式 pred:fresh = originalTerm。
|
|
452
|
-
* 未超预算则原样返回。
|
|
453
|
-
*/
|
|
454
|
-
declare function maybeLeak(a: Abs, budget?: LeakBudget, label?: string): Abs;
|
|
455
|
-
/**
|
|
456
|
-
* 批量:在算术结果上应用 leak。
|
|
457
|
-
*/
|
|
458
|
-
declare function leakIfNeeded(a: Abs, budget?: LeakBudget, label?: string): Abs;
|
|
459
|
-
|
|
460
|
-
/**
|
|
461
|
-
* Abs 模块面(无 fs):import 绑定 + export 收集。
|
|
462
|
-
* 解析路径/读文件在 host;core 只吃「specifier → 导出表」。
|
|
463
|
-
*/
|
|
464
|
-
|
|
465
|
-
type AbsModuleExports = {
|
|
466
|
-
named: Record<string, Abs>;
|
|
467
|
-
default?: Abs;
|
|
468
|
-
};
|
|
469
|
-
/** 把 import 说明符绑定进 env(宿主已求值依赖) */
|
|
470
|
-
declare function bindImports(node: ImportDeclaration, env: AstEnv, modules: Record<string, AbsModuleExports>): void;
|
|
471
|
-
/**
|
|
472
|
-
* 从已求值 env + AST 收集 ESM 导出。
|
|
473
|
-
* 支持:export function/const、export { a, b as c }、export default(具名)、
|
|
474
|
-
* 以及带 source 的 re-export(`export { a } from "mod"` / `export * from "mod"`——
|
|
475
|
-
* 需 host 传入已求值 modules)。
|
|
476
|
-
*/
|
|
477
|
-
declare function collectAbsExports(file: File, env: AstEnv, modules?: Record<string, AbsModuleExports>): AbsModuleExports;
|
|
478
|
-
|
|
479
|
-
/**
|
|
480
|
-
* Babel AST 抽象求值:把「类型即计算」接到真实 JS 源码。
|
|
481
|
-
* 支持表达式、函数声明/箭头、return、if、const/let、块作用域、类、循环。
|
|
482
|
-
*/
|
|
483
|
-
|
|
484
|
-
type AstEnv = {
|
|
485
|
-
vars: Map<string, Abs>;
|
|
486
|
-
/** 用户函数:name → { params, body } */
|
|
487
|
-
fns: Map<string, {
|
|
488
|
-
params: string[];
|
|
489
|
-
body: Node;
|
|
490
|
-
async?: boolean;
|
|
491
|
-
kind?: string;
|
|
492
|
-
}>;
|
|
493
|
-
/** class 表(旁路,withVar 必须保留) */
|
|
494
|
-
classes?: Map<string, unknown>;
|
|
495
|
-
/** 当前正在求值的方法所属类名(super.x() 从它的父类派发) */
|
|
496
|
-
currentOwner?: string;
|
|
497
|
-
};
|
|
498
|
-
declare function emptyEnv(): AstEnv;
|
|
499
|
-
declare function withVar(env: AstEnv, name: string, value: Abs): AstEnv;
|
|
500
|
-
type EvalOptions = {
|
|
501
|
-
phi?: Phi;
|
|
502
|
-
budget?: LeakBudget;
|
|
503
|
-
/** 预解析 AST(check 等批量场景避免重复 parse) */
|
|
504
|
-
file?: File;
|
|
505
|
-
/** host 已求值的相对依赖导出表 */
|
|
506
|
-
modules?: Record<string, AbsModuleExports>;
|
|
507
|
-
};
|
|
508
|
-
declare const MAX_CALL_DEPTH = 64;
|
|
509
|
-
declare const MAX_TOTAL_CALLS = 200000;
|
|
510
|
-
/** 宿主入口(evalProgramAbs / analyzeFn / check)前重置 */
|
|
511
|
-
declare function resetAbsCallBudget(): void;
|
|
512
|
-
/** 记录被截断的递归(service 可映射为 nudo:recursion-truncated) */
|
|
513
|
-
declare function setAbsTruncationCollector(collector: ((fnLabel: string) => void) | null): void;
|
|
514
|
-
/** Abs 域调用记录(自包含程序可不经 TypeValue evaluator) */
|
|
515
|
-
type AbsCallRecord = {
|
|
516
|
-
fnName: string;
|
|
517
|
-
args: Abs[];
|
|
518
|
-
result: Abs;
|
|
519
|
-
callLoc?: {
|
|
520
|
-
line: number;
|
|
521
|
-
column: number;
|
|
522
|
-
};
|
|
523
|
-
threw?: boolean;
|
|
524
|
-
};
|
|
525
|
-
declare function setAbsCallCollector(collector: ((r: AbsCallRecord) => void) | null): void;
|
|
526
|
-
declare function setAbsNodeCollector(collector: ((node: Node, value: Abs) => void) | null): void;
|
|
527
|
-
/** 赋值记录:结构可赋值检查用 */
|
|
528
|
-
type AbsAssignRecord = {
|
|
529
|
-
name: string;
|
|
530
|
-
prev?: Abs;
|
|
531
|
-
next: Abs;
|
|
532
|
-
line?: number;
|
|
533
|
-
column?: number;
|
|
534
|
-
};
|
|
535
|
-
declare function setAbsAssignCollector(collector: ((r: AbsAssignRecord) => void) | null): void;
|
|
536
|
-
type EvalResult = {
|
|
537
|
-
value: Abs;
|
|
538
|
-
phi: Phi;
|
|
539
|
-
env: AstEnv;
|
|
540
|
-
/** 函数已通过 return 跳出,块内后续语句不可达 */
|
|
541
|
-
returned?: boolean;
|
|
542
|
-
/** break 跳出最近循环 */
|
|
543
|
-
brk?: boolean;
|
|
544
|
-
/** continue 进入下一轮 */
|
|
545
|
-
cont?: boolean;
|
|
546
|
-
/** throw 了 value(未捕获时向上传播) */
|
|
547
|
-
threw?: boolean;
|
|
548
|
-
};
|
|
549
|
-
/**
|
|
550
|
-
* 分析一段 JS 源码。
|
|
551
|
-
* 若含多个顶层函数声明,先注册全部,再对 `main` 或最后一个有调用的函数求值。
|
|
552
|
-
* 更简单:提供 `analyzeFunction(source, fnName, args)`。
|
|
553
|
-
*/
|
|
554
|
-
declare function evalSource(source: string, entry: {
|
|
555
|
-
fn: string;
|
|
556
|
-
args: Abs[];
|
|
557
|
-
}, opts?: EvalOptions): EvalResult;
|
|
558
|
-
declare function callFunction(env: AstEnv, name: string, args: Abs[], phi?: Phi, budget?: LeakBudget): Abs;
|
|
559
|
-
/**
|
|
560
|
-
* 在 this=receiver 下求值方法体。
|
|
561
|
-
* constructor 无显式 return 时返回更新后的 this(字段写入已并入 env)。
|
|
562
|
-
*/
|
|
563
|
-
declare function evalMethodBody(method: {
|
|
564
|
-
params: string[];
|
|
565
|
-
body: Node;
|
|
566
|
-
async?: boolean;
|
|
567
|
-
kind?: string;
|
|
568
|
-
}, args: Abs[], thisVal: Abs, env: AstEnv, phi?: Phi, budget?: LeakBudget,
|
|
569
|
-
/** 方法定义所在类名(用于 super 派发) */
|
|
570
|
-
ownerClass?: string): Abs;
|
|
571
|
-
/** 对外入口:求值并记入节点表(Map<Node, Abs> 由 collector 消费) */
|
|
572
|
-
declare function evalNode(node: Node, env: AstEnv, phi: Phi, budget: LeakBudget): EvalResult;
|
|
573
|
-
/**
|
|
574
|
-
* 从源码分析指定函数在给定实参下的抽象结果。
|
|
575
|
-
*
|
|
576
|
-
* @example
|
|
577
|
-
* analyzeFn(`
|
|
578
|
-
* const add = (a, b) => a + b;
|
|
579
|
-
* function scale(x) { return add(x, 1); }
|
|
580
|
-
* `, "scale", [numVar("x", gtNum(v("x"), 0))], gtNum(v("x"), 0))
|
|
581
|
-
*/
|
|
582
|
-
declare function analyzeFn(source: string, fnName: string, args: Abs[], phi?: Phi, budget?: LeakBudget, file?: File, modules?: Record<string, AbsModuleExports>): Abs;
|
|
583
|
-
/**
|
|
584
|
-
* 程序级 Abs 求值:注册全部顶层函数/class,再顺序执行语句。
|
|
585
|
-
* 返回最终 env(vars 含导出绑定)。TypeValue 仅在调用方 bridge 时出现。
|
|
586
|
-
*
|
|
587
|
-
* seedVars / seedFns:host 注入(@nudo:mock 等)在求值前绑定。
|
|
588
|
-
* modules:host 已求值的依赖导出表(specifier → AbsModuleExports)。
|
|
589
|
-
*/
|
|
590
|
-
declare function evalProgramAbs(source: string, opts?: EvalOptions & {
|
|
591
|
-
seedVars?: Record<string, Abs>;
|
|
592
|
-
seedFns?: Record<string, {
|
|
593
|
-
params: string[];
|
|
594
|
-
body: Node;
|
|
595
|
-
async?: boolean;
|
|
596
|
-
}>;
|
|
597
|
-
modules?: Record<string, AbsModuleExports>;
|
|
598
|
-
}): {
|
|
599
|
-
env: AstEnv;
|
|
600
|
-
last: Abs;
|
|
601
|
-
phi: Phi;
|
|
602
|
-
};
|
|
603
|
-
/**
|
|
604
|
-
* 收集整文件的节点 → Abs 表(LSP 无损信息源)。
|
|
605
|
-
* 自包含源码上一次 evalProgramAbs 即可;失败返回空表。
|
|
606
|
-
*/
|
|
607
|
-
declare function collectAbsNodeTypes(source: string, opts?: EvalOptions & {
|
|
608
|
-
seedVars?: Record<string, Abs>;
|
|
609
|
-
seedFns?: Record<string, {
|
|
610
|
-
params: string[];
|
|
611
|
-
body: Node;
|
|
612
|
-
async?: boolean;
|
|
613
|
-
}>;
|
|
614
|
-
}): Map<Node, Abs>;
|
|
615
|
-
/** 按 loc 找最紧的节点 Abs(hover 用) */
|
|
616
|
-
declare function findAbsAtPosition(nodeTypes: Map<Node, Abs>, line: number, column: number): Abs | undefined;
|
|
617
|
-
|
|
618
251
|
/**
|
|
619
252
|
* Abs 上的一等函数:shape 是 fn,实现在旁路(不污染 Shape)。
|
|
620
253
|
* 与 term-registry 同一纪律:不给共享单例挂 impl。
|
|
@@ -622,7 +255,8 @@ declare function findAbsAtPosition(nodeTypes: Map<Node, Abs>, line: number, colu
|
|
|
622
255
|
|
|
623
256
|
type AbsFnImpl = {
|
|
624
257
|
params: string[];
|
|
625
|
-
body
|
|
258
|
+
/** 可选:无 body 时走 relation(纯关系 fn) */
|
|
259
|
+
body?: Node;
|
|
626
260
|
async?: boolean;
|
|
627
261
|
/** 声明时捕获的环境(闭包) */
|
|
628
262
|
env?: AstEnv;
|
|
@@ -633,13 +267,43 @@ type AbsFnImpl = {
|
|
|
633
267
|
* Optional content key for cache fingerprints. formatAbs cannot see
|
|
634
268
|
* WeakMap-side mock semantics (returns/withArgs/callsFake), so hosts that
|
|
635
269
|
* build mocks should stamp a stable fingerprint here.
|
|
270
|
+
* relation-only 必填(未传时 relationFn 自动生成)。
|
|
636
271
|
*/
|
|
637
272
|
fingerprint?: string;
|
|
273
|
+
/** 无 body 时,按 paramTypes 做 α 替换得到返回 */
|
|
274
|
+
relation?: {
|
|
275
|
+
paramTypes: Abs[];
|
|
276
|
+
returnType: Abs;
|
|
277
|
+
};
|
|
638
278
|
};
|
|
639
279
|
declare function attachFnImpl(a: Abs, impl: AbsFnImpl): void;
|
|
640
280
|
declare function getFnImpl(a: Abs): AbsFnImpl | undefined;
|
|
641
281
|
/** 造一个带实现的 Abs 函数值 */
|
|
642
282
|
declare function absFunction(params: string[], impl: Omit<AbsFnImpl, "params">): Abs;
|
|
283
|
+
/** relationFn 稳定 fingerprint(同签名共享,见 §3.3 已知限制) */
|
|
284
|
+
declare function relationFingerprint(paramTypes: Abs[], returnType: Abs): string;
|
|
285
|
+
/**
|
|
286
|
+
* 无 body、纯关系的 fn Abs。params 仅记 arity。
|
|
287
|
+
*
|
|
288
|
+
* **双写纪律:** 同一份关系数据必须同时写到——
|
|
289
|
+
* 1. `shape.paramTypes` / `shape.returnType` —— format / leq / 展示读这里
|
|
290
|
+
* 2. `impl.relation` —— D 路径应用读这里
|
|
291
|
+
* 两槽共享同一数组/对象引用(防内容分叉);构造后请勿原地 mutate。
|
|
292
|
+
*
|
|
293
|
+
* 默认 conf="path"(与提升产物一致)。禁止静默对齐 absFunction 的 "exact"。
|
|
294
|
+
* fingerprint 必填(call-budget);未传时由 paramTypes+returnType 稳定序列化生成。
|
|
295
|
+
* 同签名 relationFn 共享 fingerprint → 共享 budget 键(见 design §3.3 已知限制)。
|
|
296
|
+
*/
|
|
297
|
+
declare function relationFn(paramTypes: Abs[], returnType: Abs, opts?: {
|
|
298
|
+
params?: string[];
|
|
299
|
+
conf?: Confidence;
|
|
300
|
+
fingerprint?: string;
|
|
301
|
+
}): Abs;
|
|
302
|
+
/** 仅写 shape 槽(E 路径 / §5.2 提升产物);禁止 attachFnImpl */
|
|
303
|
+
declare function shapeOnlyFn(paramTypes: Abs[], returnType: Abs, opts?: {
|
|
304
|
+
params?: string[];
|
|
305
|
+
conf?: Confidence;
|
|
306
|
+
}): Abs;
|
|
643
307
|
|
|
644
308
|
/**
|
|
645
309
|
* 算术核:单调性 + 常量折叠 + 约束传播。
|
|
@@ -756,7 +420,7 @@ declare function evalBuiltinInstanceMethod(brandName: string, method: string, re
|
|
|
756
420
|
* 调用 Abs 方法。返回 undefined = 未接管(调用方走其它路径)。
|
|
757
421
|
*/
|
|
758
422
|
declare function callAbsMethod(recv: Abs, name: string, args: Abs[]): Abs | undefined;
|
|
759
|
-
/** 属性读取:template.length 等 */
|
|
423
|
+
/** 属性读取:template/string.length 等 */
|
|
760
424
|
declare function getAbsProperty(recv: Abs, name: string): Abs | undefined;
|
|
761
425
|
|
|
762
426
|
/**
|
|
@@ -862,6 +526,8 @@ type FormatOptions = {
|
|
|
862
526
|
indent?: string;
|
|
863
527
|
};
|
|
864
528
|
declare function formatAbs(a: Abs, opts?: FormatOptions): string;
|
|
529
|
+
/** fn/arr 槽位:shape + 非 lit term(禁止在 format 里内联复制 term 逻辑) */
|
|
530
|
+
declare function formatShapeSlot(a: Abs): string;
|
|
865
531
|
declare function formatShape(a: Abs): string;
|
|
866
532
|
/** 多行展示,CLI 用 */
|
|
867
533
|
declare function formatAbsMultiline(a: Abs, label?: string): string;
|
|
@@ -1039,7 +705,29 @@ type PolyFn = {
|
|
|
1039
705
|
param: string;
|
|
1040
706
|
pred: Pred;
|
|
1041
707
|
}>;
|
|
708
|
+
/**
|
|
709
|
+
* 函数形参的符号外延(与 typeParams 同 α 空间)。
|
|
710
|
+
* symbolic 一次跑正常结束时从 env 快照拷出;instantiate 重跑不写。
|
|
711
|
+
*/
|
|
712
|
+
fnRels?: Map<string, {
|
|
713
|
+
abs: Abs;
|
|
714
|
+
source: RelSource;
|
|
715
|
+
}>;
|
|
716
|
+
/**
|
|
717
|
+
* 值形参(非函数)的提升快照,如 `items → arr(A1)`。
|
|
718
|
+
*/
|
|
719
|
+
entryShapes?: Map<string, {
|
|
720
|
+
abs: Abs;
|
|
721
|
+
source: RelSource;
|
|
722
|
+
}>;
|
|
723
|
+
/** body 内对该形参的应用点(check/hover/dts 用) */
|
|
724
|
+
hofSites?: HofSite[];
|
|
1042
725
|
};
|
|
726
|
+
declare function extractFn(source: string, fnName: string, fileAst?: ReturnType<typeof parseSource>): {
|
|
727
|
+
params: string[];
|
|
728
|
+
body: Node;
|
|
729
|
+
env: AstEnv;
|
|
730
|
+
} | undefined;
|
|
1043
731
|
declare function generalizeFromAst(fnName: string, source: string, opts?: {
|
|
1044
732
|
budget?: LeakBudget;
|
|
1045
733
|
label?: string;
|
|
@@ -1359,340 +1047,6 @@ declare function collectAbsInlays(source: string, refineOpts?: {
|
|
|
1359
1047
|
/** Abs 上的运行时守卫表达式(JS boolean 布尔串) */
|
|
1360
1048
|
declare function denoteGuard(a: Abs, v: string): string;
|
|
1361
1049
|
|
|
1362
|
-
/**
|
|
1363
|
-
* B 路径运行时:transpile 后的程序在 Node 上执行时,值就是 Abs。
|
|
1364
|
-
* 与 AST 解释器语义同构;TypeValue 不再是求值载体。
|
|
1365
|
-
*/
|
|
1366
|
-
|
|
1367
|
-
declare function currentExecPhi(): Phi;
|
|
1368
|
-
declare function withExecPhi<T>(p: Phi, body: () => T): T;
|
|
1369
|
-
declare function $add(a: Abs, b: Abs): Abs;
|
|
1370
|
-
declare function $sub(a: Abs, b: Abs): Abs;
|
|
1371
|
-
declare function $mul(a: Abs, b: Abs): Abs;
|
|
1372
|
-
declare function $div(a: Abs, b: Abs): Abs;
|
|
1373
|
-
declare function $mod(a: Abs, b: Abs): Abs;
|
|
1374
|
-
declare function $neg(a: Abs): Abs;
|
|
1375
|
-
declare function $typeof(a: Abs): Abs;
|
|
1376
|
-
declare function $not(a: Abs): Abs;
|
|
1377
|
-
declare function $eq(a: Abs, b: Abs): Abs;
|
|
1378
|
-
declare function $ne(a: Abs, b: Abs): Abs;
|
|
1379
|
-
declare function $lt(a: Abs, b: Abs): Abs;
|
|
1380
|
-
declare function $le(a: Abs, b: Abs): Abs;
|
|
1381
|
-
declare function $gt(a: Abs, b: Abs): Abs;
|
|
1382
|
-
declare function $ge(a: Abs, b: Abs): Abs;
|
|
1383
|
-
declare function $join(a: Abs, b: Abs): Abs;
|
|
1384
|
-
/**
|
|
1385
|
-
* transpile 泄漏的 JS 函数值 → 一等 fn Abs。
|
|
1386
|
-
* B 路径把函数声明/表达式编译成真实 JS 函数;它们流进对象槽、
|
|
1387
|
-
* 元组、join 等 Abs 结构时不能裸存——下游(bridge/leq/join)读 `.shape`。
|
|
1388
|
-
* 参数名无法从运行时函数恢复(用 fn.length → argN,与 analyzer 的
|
|
1389
|
-
* extractParamNames 回退口径一致);带真实参数名走 $fnVal(transpile 侧)。
|
|
1390
|
-
*/
|
|
1391
|
-
declare function asAbsVal(v: unknown): Abs;
|
|
1392
|
-
/** 函数表达式 → 一等 fn Abs(transpile 侧带真实参数名;异步 body 包 $async) */
|
|
1393
|
-
declare function $fnVal(params: string[], impl: (...args: Abs[]) => Abs): Abs;
|
|
1394
|
-
/** 字面量 → Abs(transpile 侧数字/字符串/布尔/null/undefined) */
|
|
1395
|
-
declare function $lit(v: unknown): Abs;
|
|
1396
|
-
declare function isDefinitelyTrue(a: Abs): boolean;
|
|
1397
|
-
declare function isDefinitelyFalse(a: Abs): boolean;
|
|
1398
|
-
/**
|
|
1399
|
-
* if:两侧都探索(抽象条件),具体条件短路。
|
|
1400
|
-
*/
|
|
1401
|
-
declare function $fork(test: Abs, consequent: () => Abs, alternate?: () => Abs): Abs;
|
|
1402
|
-
declare const DEFAULT_MAX_LOOP_ITERS = 8;
|
|
1403
|
-
/**
|
|
1404
|
-
* for 的惰性展开:生成器只负责「按上限吐状态」。
|
|
1405
|
-
* 抽象条件无法诚实终止——消费者必须自带 maxIters。
|
|
1406
|
-
*/
|
|
1407
|
-
declare function $forIter(init: Abs, test: (s: Abs) => Abs, step: (s: Abs) => Abs, body: (s: Abs) => Abs, maxIters?: number): Generator<{
|
|
1408
|
-
state: Abs;
|
|
1409
|
-
test: Abs;
|
|
1410
|
-
afterBody: Abs;
|
|
1411
|
-
}, void, void>;
|
|
1412
|
-
/**
|
|
1413
|
-
* 有界 for:unroll ≤ maxIters,每步「可能退出」的态 join;
|
|
1414
|
-
* 相邻态 leq 视为不动点提前停。
|
|
1415
|
-
*/
|
|
1416
|
-
declare function $for(init: Abs, test: (s: Abs) => Abs, step: (s: Abs) => Abs, body: (s: Abs) => Abs, maxIters?: number): Abs;
|
|
1417
|
-
/** 数组字面量 → Abs tuple(长度已知) */
|
|
1418
|
-
declare function $arr(items: Abs[]): Abs;
|
|
1419
|
-
/** 下标读 a[i];字面量 i 走 tuple 精确投影,否则并所有元素 */
|
|
1420
|
-
declare function $idx(a: Abs, i: Abs): Abs;
|
|
1421
|
-
/** 下标写 a[i]=v → 新 tuple */
|
|
1422
|
-
declare function $idxSet(a: Abs, i: Abs, value: Abs): Abs;
|
|
1423
|
-
/** 数组长度 */
|
|
1424
|
-
declare function $len(a: Abs): Abs;
|
|
1425
|
-
/** 对象字面量 → Abs obj */
|
|
1426
|
-
declare function $obj(slots: Record<string, Abs>): Abs;
|
|
1427
|
-
/** 对象展开 { ...a, b } */
|
|
1428
|
-
declare function $spread(a: Abs, b: Abs): Abs;
|
|
1429
|
-
/** 数组连接 [...a, ...b] / [...a, x] */
|
|
1430
|
-
declare function $concat(a: Abs, b: Abs): Abs;
|
|
1431
|
-
/** 元素列表(tuple 展开;arr 抽象) */
|
|
1432
|
-
declare function $elems(a: Abs): Abs[];
|
|
1433
|
-
/**
|
|
1434
|
-
* for-of:对 iterable 每个元素跑 body;有界展开。
|
|
1435
|
-
* body(item, i) 可返回 void;状态由外部 JS 变量承接。
|
|
1436
|
-
*/
|
|
1437
|
-
declare function $forOf(iterable: Abs, body: (item: Abs, index: Abs) => void, maxIters?: number): void;
|
|
1438
|
-
/** 成员读:obj.slots[key];缺失 → undefined 字面量;brand 解包内层 */
|
|
1439
|
-
declare function $get(o: Abs, key: string, opts?: {
|
|
1440
|
-
silent?: boolean;
|
|
1441
|
-
}): Abs;
|
|
1442
|
-
/** 成员写:返回新 obj/brand(不可变更新) */
|
|
1443
|
-
declare function $set(o: Abs, key: string, value: Abs): Abs;
|
|
1444
|
-
/**
|
|
1445
|
-
* 有界 while:state 线程穿 test/step(与 $for 同折叠语义)。
|
|
1446
|
-
* 抽象条件无法诚实终止——必须 maxIters。
|
|
1447
|
-
*/
|
|
1448
|
-
declare function $while(init: Abs, test: (s: Abs) => Abs, step: (s: Abs) => Abs, maxIters?: number): Abs;
|
|
1449
|
-
/**
|
|
1450
|
-
* 顺序 while(具体/可变闭包):body 内对 JS 变量赋值。
|
|
1451
|
-
* 适合 transpile `let i; while (…) { i = … }`;抽象条件仍靠预算截断,
|
|
1452
|
-
* 不保证 exit-join 健全——健全路径用 $while/$for + 状态对象。
|
|
1453
|
-
*/
|
|
1454
|
-
declare function $whileSeq(test: () => Abs, body: () => void, maxIters?: number): void;
|
|
1455
|
-
/** B 路径 throw 载荷:携带 Abs 抛出值 */
|
|
1456
|
-
declare class NudoThrow extends Error {
|
|
1457
|
-
readonly absValue: Abs;
|
|
1458
|
-
constructor(absValue: Abs);
|
|
1459
|
-
}
|
|
1460
|
-
/** transpile `throw x` → `$throw(x)` */
|
|
1461
|
-
declare function $throw(v: Abs): never;
|
|
1462
|
-
declare function isNudoThrow(e: unknown): e is NudoThrow;
|
|
1463
|
-
/** catch 参数:从 NudoThrow 取出 Abs,否则 unknown */
|
|
1464
|
-
declare function $catchVal(e: unknown): Abs;
|
|
1465
|
-
/**
|
|
1466
|
-
* async 函数体包进 thunk,返回值经 wrapPromise。
|
|
1467
|
-
*/
|
|
1468
|
-
declare function $async(thunk: () => Abs): Abs;
|
|
1469
|
-
/** await → 解包 eff("promise") */
|
|
1470
|
-
declare function $await(v: Abs): Abs;
|
|
1471
|
-
/** async 直接 return 的 coerce */
|
|
1472
|
-
declare function $asyncReturn(v: Abs): Abs;
|
|
1473
|
-
/** function* 体:收集所有 yield 值为 tuple Abs */
|
|
1474
|
-
declare function $gen(body: () => void): Abs;
|
|
1475
|
-
/** yield v:压入当前生成器收集器;表达式值用 unknown */
|
|
1476
|
-
declare function $yield(v: Abs): Abs;
|
|
1477
|
-
/**
|
|
1478
|
-
* switch:具体 disc 选中匹配 case;抽象 disc 并所有分支。
|
|
1479
|
-
*/
|
|
1480
|
-
declare function $switch(disc: Abs, cases: Array<{
|
|
1481
|
-
test: Abs;
|
|
1482
|
-
run: () => Abs;
|
|
1483
|
-
}>, dflt?: () => Abs): Abs;
|
|
1484
|
-
|
|
1485
|
-
/**
|
|
1486
|
-
* B 路径 transpile:JS AST → 可在 Node 上执行的抽象值程序(源码字符串)。
|
|
1487
|
-
* 运算符改为 $add/$sub/…;if 改为 $fork;for 改为 $for。
|
|
1488
|
-
* 值类型是 Abs;副作用与模块仍由 host mock/注入。
|
|
1489
|
-
*/
|
|
1490
|
-
|
|
1491
|
-
type TranspileOptions = {
|
|
1492
|
-
/** 运行时 import 说明符 */
|
|
1493
|
-
runtimeImport?: string;
|
|
1494
|
-
maxLoopIters?: number;
|
|
1495
|
-
/** 方法体内 this 的绑定名(transpile class 时注入) */
|
|
1496
|
-
thisParam?: string;
|
|
1497
|
-
/** 当前类名(super 派发用) */
|
|
1498
|
-
className?: string;
|
|
1499
|
-
/** 原始源码(@nudo:replace 按节点文本匹配) */
|
|
1500
|
-
source?: string;
|
|
1501
|
-
/** 替换表:归一化目标文本 → 注入变量名;可选语句范围 */
|
|
1502
|
-
replacements?: Array<{
|
|
1503
|
-
target: string;
|
|
1504
|
-
varName: string;
|
|
1505
|
-
/** 仅该语句范围内生效(1-based 行) */
|
|
1506
|
-
stmtStart?: number;
|
|
1507
|
-
stmtEnd?: number;
|
|
1508
|
-
}>;
|
|
1509
|
-
/** @nudo:as:覆盖紧随语句的 init / return */
|
|
1510
|
-
asOverrides?: Array<{
|
|
1511
|
-
varName: string;
|
|
1512
|
-
stmtStart: number;
|
|
1513
|
-
stmtEnd: number;
|
|
1514
|
-
}>;
|
|
1515
|
-
};
|
|
1516
|
-
declare function transpileSource(source: string, opts?: TranspileOptions): string;
|
|
1517
|
-
declare function transpileFile(file: File, opts?: TranspileOptions): string;
|
|
1518
|
-
declare function transpileExpression(expr: Expression, opts?: TranspileOptions): string;
|
|
1519
|
-
/** 解析 + transpile */
|
|
1520
|
-
declare function transpile(source: string, opts?: TranspileOptions): string;
|
|
1521
|
-
|
|
1522
|
-
/**
|
|
1523
|
-
* 调用 Abs 一等函数(absFunction impl)或 mock apply。
|
|
1524
|
-
* 供 B 路径 import 绑定包装:`(...args) => $call(absFn, args)`。
|
|
1525
|
-
*/
|
|
1526
|
-
|
|
1527
|
-
declare function $call(fn: Abs, args: Abs[]): Abs;
|
|
1528
|
-
|
|
1529
|
-
/**
|
|
1530
|
-
* B class 规格表(无 call/ast-eval 依赖,避免循环)。
|
|
1531
|
-
* Abs-eval registerClassDecl 与 transpile $class 共用。
|
|
1532
|
-
*/
|
|
1533
|
-
|
|
1534
|
-
type BClassSpec = {
|
|
1535
|
-
name: string;
|
|
1536
|
-
superName?: string;
|
|
1537
|
-
ctor?: (thisVal: Abs, ...args: Abs[]) => Abs;
|
|
1538
|
-
methods?: Record<string, (thisVal: Abs, ...args: Abs[]) => Abs>;
|
|
1539
|
-
staticMethods?: Record<string, (...args: Abs[]) => Abs>;
|
|
1540
|
-
statics?: Record<string, Abs>;
|
|
1541
|
-
};
|
|
1542
|
-
declare function registerBClass(spec: BClassSpec): void;
|
|
1543
|
-
declare function getBClass(name: string): BClassSpec | undefined;
|
|
1544
|
-
declare function clearBClasses(): void;
|
|
1545
|
-
|
|
1546
|
-
/**
|
|
1547
|
-
* B 路径 class:brand 实例 + ctor/method 闭包 + 继承链。
|
|
1548
|
-
* 方法内 this 由 transpile 改写为 thisVal 参数。
|
|
1549
|
-
*/
|
|
1550
|
-
|
|
1551
|
-
/** 定义类 → 可 new 的 Abs(brand 标记;静态字段挂在 slots) */
|
|
1552
|
-
declare function $class(name: string, spec: Omit<BClassSpec, "name"> & {
|
|
1553
|
-
extends?: string;
|
|
1554
|
-
}): Abs;
|
|
1555
|
-
/** new C(...) → 空 brand 实例 + ctor 写字段;非类构造走 impl/$call */
|
|
1556
|
-
declare function $new(cls: Abs | ((...a: unknown[]) => unknown), args: Abs[]): Abs;
|
|
1557
|
-
/**
|
|
1558
|
-
* super(...):父类构造写入字段(this 保持子类 brand)。
|
|
1559
|
-
* transpile: super(a,b) → __this = $super(__this, "Child", [a,b])
|
|
1560
|
-
*/
|
|
1561
|
-
declare function $super(thisVal: Abs, childName: string, args: Abs[]): Abs;
|
|
1562
|
-
/** 实例方法调用:沿继承链;类 Abs 上回落 staticMethods;obj 上回落属性函数 */
|
|
1563
|
-
declare function $invoke(thisVal: Abs, method: string, args: Abs[], loc?: [number, number]): Abs;
|
|
1564
|
-
/** super.method():从父类起找(跳过自身覆盖) */
|
|
1565
|
-
declare function $invokeSuper(thisVal: Abs, childName: string, method: string, args: Abs[]): Abs;
|
|
1566
|
-
declare function $thisGet(thisVal: Abs, key: string): Abs;
|
|
1567
|
-
declare function $thisSet(thisVal: Abs, key: string, value: Abs): Abs;
|
|
1568
|
-
/** 解构默认值:undefined 时用 default */
|
|
1569
|
-
declare function $orDefault(v: Abs, dflt: () => Abs): Abs;
|
|
1570
|
-
/** 可选链 a?.b:nullish 短路为 undefined 字面量 */
|
|
1571
|
-
declare function $optionalGet(o: Abs, key: string): Abs;
|
|
1572
|
-
/** 可选链 a?.m():nullish 短路为 undefined */
|
|
1573
|
-
declare function $optionalInvoke(thisVal: Abs, method: string, args: Abs[]): Abs;
|
|
1574
|
-
/** 静态方法:cls.staticMethod(args) */
|
|
1575
|
-
declare function $staticInvoke(cls: Abs, method: string, args: Abs[]): Abs;
|
|
1576
|
-
/** 计算属性写:o[kAbs] = v */
|
|
1577
|
-
declare function $setKey(o: Abs, key: Abs, value: Abs): Abs;
|
|
1578
|
-
|
|
1579
|
-
/**
|
|
1580
|
-
* 成员缺失诊断(B 路径 + Abs ast-eval 共用)。
|
|
1581
|
-
* 无 $call / transpile 依赖,避免 ast-eval ↔ calls 循环。
|
|
1582
|
-
*/
|
|
1583
|
-
|
|
1584
|
-
type BMemberDiag = {
|
|
1585
|
-
kind: "method" | "property";
|
|
1586
|
-
name: string;
|
|
1587
|
-
/** 接收者 prim 类型名,或 "unknown" */
|
|
1588
|
-
receiver: string;
|
|
1589
|
-
line?: number;
|
|
1590
|
-
column?: number;
|
|
1591
|
-
/** 调用点来源(provenance):实参字面量 loc 优先,否则最近 $callNamed loc */
|
|
1592
|
-
origin?: {
|
|
1593
|
-
line: number;
|
|
1594
|
-
column: number;
|
|
1595
|
-
};
|
|
1596
|
-
};
|
|
1597
|
-
/** 给实参 Abs 打 provenance(调用点参数字面量) */
|
|
1598
|
-
declare function tagAbsOrigin(a: Abs, loc: {
|
|
1599
|
-
line: number;
|
|
1600
|
-
column: number;
|
|
1601
|
-
}): void;
|
|
1602
|
-
declare function getAbsOrigin(a: Abs | undefined): {
|
|
1603
|
-
line: number;
|
|
1604
|
-
column: number;
|
|
1605
|
-
} | undefined;
|
|
1606
|
-
declare function setMemberDiagCollector(c: ((d: BMemberDiag) => void) | null): void;
|
|
1607
|
-
declare function recordMemberDiag(d: BMemberDiag): void;
|
|
1608
|
-
/**
|
|
1609
|
-
* prim 接收者上的未知成员 → 诊断。
|
|
1610
|
-
* 返回 true 表示确定缺失(number 上任意方法;string 上表外方法)。
|
|
1611
|
-
*/
|
|
1612
|
-
declare function notePrimMemberMissing(recv: Abs | undefined, name: string, kind: "method" | "property", loc?: [number, number]): boolean;
|
|
1613
|
-
/**
|
|
1614
|
-
* unknown 接收者上的成员访问 → unknown-recv(与 TypeValue 口径对齐:
|
|
1615
|
-
* object/instance/refined/promise 静默;其余记一条)。
|
|
1616
|
-
*/
|
|
1617
|
-
declare function noteUnknownMemberMissing(recv: Abs | undefined, name: string, kind: "method" | "property", loc?: [number, number]): boolean;
|
|
1618
|
-
/** 方法分派失败时的统一记账(prim / unknown;obj/brand/promise 静默) */
|
|
1619
|
-
declare function noteMemberDispatchMiss(recv: Abs | undefined, name: string, kind: "method" | "property", loc?: [number, number]): void;
|
|
1620
|
-
|
|
1621
|
-
/**
|
|
1622
|
-
* B 路径调用点记录:transpile 把 `f(args)` 改成 $callNamed,
|
|
1623
|
-
* 分析时可收集 call@ 所需的 AbsCallRecord。
|
|
1624
|
-
* 成员缺失诊断见 member-diag.ts(与 ast-eval 共用,避免循环依赖)。
|
|
1625
|
-
*/
|
|
1626
|
-
|
|
1627
|
-
type BCallRecord = {
|
|
1628
|
-
fnName: string;
|
|
1629
|
-
args: Abs[];
|
|
1630
|
-
result: Abs;
|
|
1631
|
-
callLoc?: {
|
|
1632
|
-
line: number;
|
|
1633
|
-
column: number;
|
|
1634
|
-
};
|
|
1635
|
-
threw?: boolean;
|
|
1636
|
-
};
|
|
1637
|
-
declare function setBCallCollector(collector: ((r: BCallRecord) => void) | null): void;
|
|
1638
|
-
declare function getBCallCollector(): ((r: BCallRecord) => void) | null;
|
|
1639
|
-
/**
|
|
1640
|
-
* 按名调用并记录。
|
|
1641
|
-
* loc: [line, column](1-based line,0-based column,与 Babel 一致)
|
|
1642
|
-
* argLocs: 与 args 对齐的实参字面量源位置(provenance;无 loc 用 null)
|
|
1643
|
-
*/
|
|
1644
|
-
declare function $callNamed(name: string, fn: unknown, args: Abs[], loc?: [number, number], argLocs?: Array<[number, number] | null | undefined>): Abs;
|
|
1645
|
-
|
|
1646
|
-
/**
|
|
1647
|
-
* 进程内 B 路径执行:transpile 源码 → new Function 跑在 runtime 上。
|
|
1648
|
-
* 不写临时文件;相对 import 用注入的 AbsModuleExports / JS 导出绑定。
|
|
1649
|
-
*
|
|
1650
|
-
* mode:
|
|
1651
|
-
* - "exec"(默认):执行全部顶层(含副作用)
|
|
1652
|
-
* - "analyze":只保留函数声明与纯字面量 const;跳过顶层表达式/循环/if
|
|
1653
|
-
* ——分析入口安全,不触发 fetch 等顶层副作用
|
|
1654
|
-
*/
|
|
1655
|
-
|
|
1656
|
-
type RunTranspiledOptions = {
|
|
1657
|
-
/** 说明符 → 依赖导出(host 模块图或 runTranspiled 产物) */
|
|
1658
|
-
modules?: Record<string, AbsModuleExports | Record<string, unknown>>;
|
|
1659
|
-
maxLoopIters?: number;
|
|
1660
|
-
/** analyze = 跳过效应性顶层语句 */
|
|
1661
|
-
mode?: "exec" | "analyze";
|
|
1662
|
-
/** @nudo:replace 注入值:varName → Abs */
|
|
1663
|
-
replacements?: Record<string, Abs>;
|
|
1664
|
-
/** @nudo:replace 匹配表:传给 transpile */
|
|
1665
|
-
replacementTargets?: Array<{
|
|
1666
|
-
target: string;
|
|
1667
|
-
varName: string;
|
|
1668
|
-
stmtStart?: number;
|
|
1669
|
-
stmtEnd?: number;
|
|
1670
|
-
}>;
|
|
1671
|
-
/** @nudo:as 注入值:varName → Abs */
|
|
1672
|
-
asOverrides?: Record<string, Abs>;
|
|
1673
|
-
/** @nudo:as 语句范围表 */
|
|
1674
|
-
asOverrideTargets?: Array<{
|
|
1675
|
-
varName: string;
|
|
1676
|
-
stmtStart: number;
|
|
1677
|
-
stmtEnd: number;
|
|
1678
|
-
}>;
|
|
1679
|
-
/** @nudo:env 全局 Abs(JSON/Math/console…)→ 作用域绑定 */
|
|
1680
|
-
envGlobals?: Record<string, Abs>;
|
|
1681
|
-
};
|
|
1682
|
-
/**
|
|
1683
|
-
* 执行一段 B 路径程序,返回顶层 `export function` / `export const`。
|
|
1684
|
-
*/
|
|
1685
|
-
declare function runTranspiled(source: string, opts?: RunTranspiledOptions): Record<string, unknown>;
|
|
1686
|
-
type TranspiledCallResult = {
|
|
1687
|
-
result: Abs;
|
|
1688
|
-
/** 非 never 表示函数可能 throw 该类型 */
|
|
1689
|
-
throws: Abs;
|
|
1690
|
-
};
|
|
1691
|
-
/** 调用 runTranspiled 导出(捕获 $throw) */
|
|
1692
|
-
declare function callTranspiledExportFull(exports: Record<string, unknown>, name: string, args: Abs[]): TranspiledCallResult;
|
|
1693
|
-
/** 调用 runTranspiled 导出(仅结果) */
|
|
1694
|
-
declare function callTranspiledExport(exports: Record<string, unknown>, name: string, args: Abs[]): Abs;
|
|
1695
|
-
|
|
1696
1050
|
/**
|
|
1697
1051
|
* Abs ⇄ TypeValue 桥。
|
|
1698
1052
|
*
|
|
@@ -1723,4 +1077,4 @@ declare function bridgeIsLossy(a: Abs): {
|
|
|
1723
1077
|
reasons: string[];
|
|
1724
1078
|
};
|
|
1725
1079
|
|
|
1726
|
-
export {
|
|
1080
|
+
export { Abs, type AbsFnImpl, type AbsInlay, AstEnv, type CheckIssue, type CheckJson, type CheckOptions, type CheckReport, type ClassDef, Confidence, type ConstraintBuilder, type Diagnostic, type Environment, type FnAbs, type FnFp, type FormatOptions, type FunctionSignature, HofSite, LeakBudget, type LeqResult, type LiteralValue, type LoadDepsFingerprint, type MethodDef, type MockHelper, type NamedImport, type NudoConstraint, type NudoField, type NudoSig, type ObjShape, Ops, Phi, type PolyFn, Pred, PrimName, type RangeMeta, type RefineEntry, type RefineResolveOpts, type Refinement, RelSource, SELF, Shape, type SigImpl, type Slot, T, type TemplateMeta, Term, type TypeParam, type TypeValue, absFunction, absToTypeValue, add, applyBinaryOp, array, attachFnImpl, awaitAbs, boolean, bridgeIsLossy, buildArgsFromAssume, callAbsMethod, canSkipLiteralCallScan, checkArg, checkCall, checkSource, classFromMethods, cmp, coerceAsyncReturn, collapseLiteralUnion, collapseToOptional, collectAbsInlays, concatString, concatTemplates, constraintToEntryAbs, createEnvironment, createRange, createTemplate, createTemplateAbs, currentPhi, deepCloneTypeValue, defineClass, definitelyNotNullishShape, denoteGuard, describePhi, dispatchBinaryOp, dispatchMethod, dispatchProperty, div, evalArrayStatic, evalBuiltinInstanceMethod, evalBuiltinNew, evalDateCtor, evalDateMethod, evalDateStatic, evalGlobalFn, evalJsonMethod, evalMathMethod, evalNamespaceCall, evalNumberStatic, evalObjectMethod, evalPromiseCtor, evalPromiseStatic, evalRegExpCtor, evalRegExpMethod, evictCheckSourceMemoForPaths, evictGeneralizeMemoForPaths, execNudoModule, extractAllLoadSpecs, extractFn, extractNudoImports, extractRefineReturnFromSource, extractRefinesFromSource, falseConstraint, fnFingerprints, fnOf, formatAbs, formatAbsMultiline, formatCheckReport, formatDiagnostics, formatShape, formatShapeSlot, generalizeAll, generalizeFromAst, generalizeSourceKeyPart, getAbsProperty, getCheckSourceMemoSize, getClass, getClassChain, getFnImpl, getFnNameAndBodies, getFnSig, getGeneralizeMemoSize, getKnownPrefix, getKnownSuffix, getParseSourceCacheSize, getPrimitiveTypeOf, getRangeMeta, getRefinedBase, getTemplateParts, getTerm, getTvConfidence, hashSource, instanceOf, instantiateClass, instantiateConstraint, isFnSig, isNudoConstraint, isNullishLitAbs, isObj, isRange, isSubtypeOf, isTemplate, isTemplateLike, joinAbs, joinFunctions, joinObjects, joinValues, lenTerm, leqAbs, listFunctionNames, loadModuleDepsFingerprint, lookupMethod, lookupMethodWithOwner, lookupSuperMethod, makeSum, mergeObjectProperties, mock, mockHelperToTypeValue, mod, mul, narrowType, negAbs, normPath, notAbs, number, numericBounds, objOf, parseSource, popPhi, projectBrand, pushPhi, refineToIndexedFull, relationFingerprint, relationFn, resetCheckSourceMemo, resetFnFpCache, resetGeneralizeMemo, resetHashSourceCache, resetNudoModuleExecCache, resetParseSourceCache, resetPhi, resolveDepPath, serializeCheckJson, setTvConfidence, shape, shapeOnlyFn, simplifyUnion, spread, spy, stableAnalyzeKeySource, strictEqAbs, string, stripTypes, stub, sub, subtractType, superNameOf, templatePartsOf, trueConstraint, typeValueEquals, typeValueToAbs, typeValueToString, typeofAbs, widenLiteral, withPhiConstraint, wrapPromise };
|