@nudojs/core 2.1.0 → 3.0.0-beta.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/README.md +9 -5
- package/dist/check-report-BnOr1M8o.d.ts +653 -0
- package/dist/{chunk-6REHMIAE.js → chunk-LDBNOXEM.js} +11689 -7262
- package/dist/chunk-TVLM42WD.js +4920 -0
- package/dist/chunk-US532PZA.js +0 -0
- package/dist/exec.d.ts +2 -1
- package/dist/exec.js +124 -23
- package/dist/hof-types-oZFaba5a.d.ts +368 -0
- package/dist/index-BWgSZGm0.d.ts +715 -0
- package/dist/index.d.ts +464 -1077
- package/dist/index.js +1700 -5329
- package/dist/internal.d.ts +541 -0
- package/dist/internal.js +583 -0
- package/package.json +11 -7
- package/dist/index-DxjxtxOJ.d.ts +0 -855
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export {
|
|
3
|
-
import { Node
|
|
1
|
+
import { c as AstEnv, A as Abs, b as Phi, C as Confidence, T as Term, H as HofCollectCtx, S as Shape, a as Pred, R as RelSource, w as HofSite } from './hof-types-oZFaba5a.js';
|
|
2
|
+
export { I as ImplicationOracle, L as LiteralValue, P as PrimName, x as TYPEOF_NAMES, y as TypeofName, z as abs, B as absToString, D as and, F as anyAbs, G as anyVar, J as app, K as bigintLit, N as bool, O as boolLit, Q as confJoin, U as emptyPhi, V as eq, W as ge, X as geNum, Y as getImplicationOracle, Z as gt, _ as gtNum, a0 as implies, a1 as isBigPrim, a2 as isExactLit, a3 as isNumPrim, a4 as isStrPrim, a5 as le, a6 as leNum, a7 as lit, a8 as litValue, a9 as lt, aa as ltNum, ab as ne, ac as negatePred, ad as never, ae as not, af as num, ag as numLit, ah as numVar, ai as obj, aj as or, ak as pFalse, al as pTrue, am as phiAnd, an as predEquals, ao as predToString, ap as predVars, aq as primToTypeof, ar as ptypeof, as as setImplicationOracle, at as shapeOfTerm, au as shapeToString, av as simplifyTerm, aw as str, ax as strLit, ay as substPred, az as termEquals, aA as termToString, aB as unknown, aC as v } from './hof-types-oZFaba5a.js';
|
|
3
|
+
import { Node } from '@babel/types';
|
|
4
|
+
import { p as parseSource, L as LeakBudget, E as EffectiveInterfaceOpts, b as LoadDepsFingerprint, i as CheckReport, N as NudoConstraint } from './check-report-BnOr1M8o.js';
|
|
5
|
+
export { j as CheckAction, C as CheckIssue, k as CheckJson, o as CheckJsonMulti, q as ConstraintBuilder, D as Diagnostic, u as EffectiveInterface, G as GitlabCodeQualityIssue, v as InterfaceDiag, I as InterfaceSource, w as InterfaceTierInfo, a as InterfaceTierOpts, x as NamedImport, y as NudoField, z as NudoFnConstraint, A as NudoSidecarError, B as NudoSig, R as RefineDiag, F as RefineEntry, H as RefineResolveOpts, S as SELF, J as actionsForIssue, K as any, M as array, O as boolean, P as checkArg, Q as checkCall, T as constraintToEntryAbs, U as effectiveInterface, V as execNudoModule, W as extractDeclaredThrows, X as extractNudoImports, Y as extractRefineReturnFromSource, Z as extractRefinesFromSource, _ as fn, $ as fnConstraintToEntryReqs, a0 as formatCheckReport, a1 as formatConstraint, a2 as formatDiagnostics, a3 as formatEffectiveInterfaceDisplay, a4 as formatGithubAnnotations, a5 as formatGitlabCodeQuality, a6 as formatInterfaceTierLine, a7 as generatedExportNames, a8 as getParseSourceCacheSize, a9 as getTerm, aa as instantiateConstraint, ab as interfaceDiagCount, ac as interfaceSourceOf, ad as interfaceTierOf, ae as isIntFlag, af as isNodeModulesPath, ag as isNudoConstraint, ah as lenTerm, ai as localNamedExports, aj as number, ak as omit, al as partial, am as pick, an as refineDiagCount, ao as refineToIndexedFull, ap as resetNudoModuleExecCache, aq as resetParseSourceCache, ar as serializeCheckJson, as as serializeCheckJsonMulti, at as setInterfaceDiagCollector, au as setRefineDiagCollector, av as shape, aw as sidecarClosureFingerprint, ax as sidecarPathOf, ay as string, az as takeInterfaceDiags, aA as takeInterfaceDiagsSince, aB as takeRefineDiags, aC as takeRefineDiagsSince, aD as throwConstraintToKinds, aE as union } from './check-report-BnOr1M8o.js';
|
|
6
|
+
import { A as AbsModuleExports, R as RunTranspiledOptions } from './index-BWgSZGm0.js';
|
|
7
|
+
export { $ as $add, a as $arguments, b as $arr, c as $arrMutContainer, d as $arrRest, e as $arrWithHoles, f as $assignRecord, g as $async, h as $asyncReturn, i as $await, j as $bitand, k as $bitnot, l as $bitor, m as $bitxor, n as $call, o as $callNamed, p as $catchVal, q as $class, r as $classExpr, s as $collectionForEach, t as $concat, u as $copy, v as $del, w as $delRes, x as $div, y as $dynamicImport, z as $elems, B as $eq, C as $eqLoose, D as $fnVal, E as $for, F as $forInKeys, G as $forIter, H as $forOf, I as $fork, J as $ge, K as $gen, L as $get, M as $gt, N as $idx, O as $idxSet, P as $importMeta, Q as $in, S as $instanceof, T as $instanceofNonIdent, U as $invoke, V as $invokeSuper, W as $isBreakTo, X as $isForkExit, Y as $join, Z as $le, _ as $len, a0 as $lit, a1 as $loopBreak, a2 as $loopContinue, a3 as $loopReturn, a4 as $lt, a5 as $mod, a6 as $mul, a7 as $ne, a8 as $neLoose, a9 as $neg, aa as $new, ab as $not, ac as $nullishTest, ad as $obj, ae as $objAccessor, af as $objRest, ag as $optionalGet, ah as $optionalInvoke, ai as $orDefault, aj as $pow, ak as $pushLoopExit, al as $rawThis, am as $reStateCall, an as $recordBinding, ao as $regex, ap as $rethrowIfNudoReturn, aq as $set, ar as $setKey, as as $shl, at as $shr, au as $spread, av as $staticInvoke, aw as $sub, ax as $super, ay as $switch, az as $thisGet, aA as $thisSet, aB as $throw, aC as $toNumber, aD as $tryCurrentMark, aE as $tryDetachSoftCatch, aF as $tryDigestSoftCatch, aG as $tryDiscardSoft, aH as $tryMark, aI as $tryOrphanSoft, aJ as $tryPopMark, aK as $tryReleaseSoftCatch, aL as $tryReleaseSoftOut, aM as $tryTakeSince, aN as $typeof, aO as $unknown, aP as $ushr, aQ as $while, aR as $whileSeq, aS as $yield, aT as BAbsAssignRecord, aU as BCallRecord, aV as BClassSpec, aW as BPathFallback, aX as DEFAULT_MAX_LOOP_ITERS, aY as MAX_B_CALL_DEPTH, aZ as MAX_B_TOTAL_CALLS, a_ as NudoLoopSignal, a$ as NudoReturn, b0 as NudoThrow, b1 as NudoUnsupportedError, b2 as RUNTIME_IMPORT_RE, b3 as TranspileOptions, b4 as TranspiledCallResult, b5 as asAbsVal, b6 as bindImports, b7 as bindingsOf, b8 as callAtFunctionBoundary, b9 as callTranspiledExport, ba as callTranspiledExportFull, bb as clearBClasses, bc as clearStaleTermPred, bd as collectAbsExports, be as currentExecPhi, bf as evalExprAbs, bg as fillTuple, bh as foldRequireSpecArg, bi as foldStaticStringExpr, bj as getBCallCollector, bk as getBClass, bl as isArrMutator, bm as isDefinitelyFalse, bn as isDefinitelyTrue, bo as isNudoBreak, bp as isNudoContinue, bq as isNudoReturn, br as isNudoThrow, bs as litTruth, bt as lookupObjAccessor, bu as namespaceNameOf, bv as noteBCallRecord, bw as noteBPathFallback, bx as pushLoopExit, by as pushThrowExit, bz as registerBClass, bA as resetBCallBudget, bB as runTranspiled, bC as runTranspiledOptionsMemoKey, bD as runWithLoopExits, bE as runtimeImportOf, bF as setBAssignCollector, bG as setBBindingSink, bH as setBCallCollector, bI as setBPathFallbackCollector, bJ as takeLoopExits, bK as takeThrowExits, bL as transpile, bM as transpileBodyNode, bN as transpileExpression, bO as transpileFile, bP as transpileSource, bQ as tryRunTranspiled, bR as withExecPhi } from './index-BWgSZGm0.js';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* AstEnv:抽象求值环境类型(ast-eval 删除后保留的类型面)。
|
|
11
|
+
* 类型定义在 hof-types.ts(打破 ast-env ↔ hof ↔ abs-fn 类型环);
|
|
12
|
+
* 本文件保留空环境 / withVar 的便捷构造并重导出 AstEnv 供稳定路径导入。
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/** 空求值环境(分析宿主用:不带任何绑定) */
|
|
16
|
+
declare function emptyEnv(): AstEnv;
|
|
17
|
+
declare function withVar(env: AstEnv, name: string, value: Abs): AstEnv;
|
|
4
18
|
|
|
5
19
|
type Environment = {
|
|
6
20
|
lookup(name: string): Abs;
|
|
@@ -78,13 +92,6 @@ declare function mock(): MockHelper;
|
|
|
78
92
|
*/
|
|
79
93
|
declare function stripTypes<T extends Node>(ast: T): T;
|
|
80
94
|
|
|
81
|
-
declare function resetParseSourceCache(): void;
|
|
82
|
-
declare function getParseSourceCacheSize(): number;
|
|
83
|
-
declare function parseSource(source: string, opts?: {
|
|
84
|
-
errorRecovery?: boolean;
|
|
85
|
-
keepTs?: boolean;
|
|
86
|
-
}): File;
|
|
87
|
-
|
|
88
95
|
/**
|
|
89
96
|
* 路径约束栈(Φ)。
|
|
90
97
|
*
|
|
@@ -116,7 +123,7 @@ type AbsFnImpl = {
|
|
|
116
123
|
env?: AstEnv;
|
|
117
124
|
kind?: string;
|
|
118
125
|
/** 调用时直接派发(mock withArgs 等),优先于 body */
|
|
119
|
-
apply?: (args: Abs[]) => Abs;
|
|
126
|
+
apply?: (args: Abs[], thisVal?: Abs) => Abs;
|
|
120
127
|
/**
|
|
121
128
|
* 对象方法(ObjectMethod / 方法型 FunctionExpression):$invoke 时把
|
|
122
129
|
* receiver 作为 apply 的**首参**注入。shape.params 仍是用户可见形参
|
|
@@ -134,10 +141,27 @@ type AbsFnImpl = {
|
|
|
134
141
|
relation?: {
|
|
135
142
|
paramTypes: Abs[];
|
|
136
143
|
returnType: Abs;
|
|
144
|
+
/**
|
|
145
|
+
* 条件类型 infer:绑定 fromVar 后从 via 投出 inferVar
|
|
146
|
+
* (`T extends (infer E)[]` → via: "arr";`T extends Promise<infer U>` → "promise")。
|
|
147
|
+
*/
|
|
148
|
+
inferFrom?: {
|
|
149
|
+
fromVar: string;
|
|
150
|
+
via: "arr" | "promise";
|
|
151
|
+
inferVar: string;
|
|
152
|
+
};
|
|
153
|
+
/** extends 不成立时的假分支(如 never) */
|
|
154
|
+
condFallback?: Abs;
|
|
137
155
|
};
|
|
156
|
+
/** `@nudo:pure`:调用结果按实参记忆化(无副作用契约) */
|
|
157
|
+
pureName?: string;
|
|
138
158
|
};
|
|
139
159
|
declare function attachFnImpl(a: Abs, impl: AbsFnImpl): void;
|
|
140
160
|
declare function getFnImpl(a: Abs): AbsFnImpl | undefined;
|
|
161
|
+
/** 标记纯函数(@nudo:pure):调用结果可按实参记忆化 */
|
|
162
|
+
declare function markPureFn(target: object, name: string): void;
|
|
163
|
+
/** 读纯函数标记(Abs impl 或对象属性 `_memoize`) */
|
|
164
|
+
declare function pureFnNameOf(fn: unknown): string | undefined;
|
|
141
165
|
/** 造一个带实现的 Abs 函数值 */
|
|
142
166
|
declare function absFunction(params: string[], impl: Omit<AbsFnImpl, "params">): Abs;
|
|
143
167
|
/** relationFn 稳定 fingerprint(同签名共享,见 §3.3 已知限制) */
|
|
@@ -158,6 +182,12 @@ declare function relationFn(paramTypes: Abs[], returnType: Abs, opts?: {
|
|
|
158
182
|
params?: string[];
|
|
159
183
|
conf?: Confidence;
|
|
160
184
|
fingerprint?: string;
|
|
185
|
+
inferFrom?: {
|
|
186
|
+
fromVar: string;
|
|
187
|
+
via: "arr" | "promise";
|
|
188
|
+
inferVar: string;
|
|
189
|
+
};
|
|
190
|
+
condFallback?: Abs;
|
|
161
191
|
}): Abs;
|
|
162
192
|
/** 仅写 shape 槽(E 路径 / §5.2 提升产物);禁止 attachFnImpl */
|
|
163
193
|
declare function shapeOnlyFn(paramTypes: Abs[], returnType: Abs, opts?: {
|
|
@@ -165,6 +195,147 @@ declare function shapeOnlyFn(paramTypes: Abs[], returnType: Abs, opts?: {
|
|
|
165
195
|
conf?: Confidence;
|
|
166
196
|
}): Abs;
|
|
167
197
|
|
|
198
|
+
/**
|
|
199
|
+
* HOF 关系 Abs:无 body 的外延关系(paramTypes → returnType)的判定、
|
|
200
|
+
* α 替换与应用。类型变量仍是 term var;关系仍是 fn 形状上的外延槽。
|
|
201
|
+
*/
|
|
202
|
+
|
|
203
|
+
declare function createHofCollectCtx(paramNames: ReadonlySet<string>, alphaIds: Iterable<string>): HofCollectCtx;
|
|
204
|
+
/**
|
|
205
|
+
* 仅当 term 是 var 且 id ∈ alphaIds(本次 typeParams)时复用;否则 fresh α。
|
|
206
|
+
* 绝不把调用点具体值/字面量冻进关系。
|
|
207
|
+
*/
|
|
208
|
+
declare function alphaOf(absOrTerm: Abs | Term | undefined, ctx: HofCollectCtx): Term;
|
|
209
|
+
/** 共享输出变量 B:${param}(§5.1 P2 钉死) */
|
|
210
|
+
declare function betaOf(param: string): Term;
|
|
211
|
+
/**
|
|
212
|
+
* 提升写入载体:替换 env.vars map 项,禁止 mutate 共享 Abs。
|
|
213
|
+
* arrival-first:已有 fn/arr 形状 → 拒绝新观测。
|
|
214
|
+
* 返回是否真正写入。
|
|
215
|
+
*/
|
|
216
|
+
declare function promoteParamShape(env: AstEnv, param: string, promotedShape: Shape, opts?: {
|
|
217
|
+
loc?: {
|
|
218
|
+
line: number;
|
|
219
|
+
column: number;
|
|
220
|
+
};
|
|
221
|
+
recordSite?: boolean;
|
|
222
|
+
}): boolean;
|
|
223
|
+
/**
|
|
224
|
+
* 挂载点①:方法派发 miss。receiver 是形参 Identifier 且 shape 为 any/未知,
|
|
225
|
+
* 方法名为 filter/map/reduce/flatMap → 提升为 arr(自身 var)。
|
|
226
|
+
*/
|
|
227
|
+
declare function tryPromoteReceiverAsArr(env: AstEnv, receiverName: string, method: string, loc?: {
|
|
228
|
+
line: number;
|
|
229
|
+
column: number;
|
|
230
|
+
}): Abs | undefined;
|
|
231
|
+
/**
|
|
232
|
+
* for-of 迭代对象提升(applyEach 型):`for (const x of items)`,
|
|
233
|
+
* items 为形参且仍是 any/unknown → arr(自身 var)。不依赖方法名。
|
|
234
|
+
*/
|
|
235
|
+
declare function tryPromoteForOfIteratee(env: AstEnv, iterateeName: string, loc?: {
|
|
236
|
+
line: number;
|
|
237
|
+
column: number;
|
|
238
|
+
}): Abs | undefined;
|
|
239
|
+
/**
|
|
240
|
+
* 挂载点②:CallExpression callee = 形参 Identifier 直接调用 p(x) / p(a,b)。
|
|
241
|
+
* 提升为 fn(paramTypes=[αOf(args)], returnType=B:param)。
|
|
242
|
+
*/
|
|
243
|
+
declare function tryPromoteDirectCall(env: AstEnv, calleeName: string, args: Abs[], loc?: {
|
|
244
|
+
line: number;
|
|
245
|
+
column: number;
|
|
246
|
+
}): Abs | undefined;
|
|
247
|
+
/**
|
|
248
|
+
* 挂载点③:HOF 回调实参。回调是 Identifier ∈ paramNames 且尚未有 fn 形状。
|
|
249
|
+
* 按方法名提升:map/flatMap → fn([αOf(el)], B:param);filter → fn([αOf(el)], bool);
|
|
250
|
+
* reduce → fn([αOf(init), αOf(el)], B:param)。
|
|
251
|
+
*/
|
|
252
|
+
declare function tryPromoteHofCallback(env: AstEnv, cbName: string, method: string, argAbses: Abs[], loc?: {
|
|
253
|
+
line: number;
|
|
254
|
+
column: number;
|
|
255
|
+
}): Abs | undefined;
|
|
256
|
+
/** deep-ish copy for snapshot(新对象,不是 env.vars 同一引用) */
|
|
257
|
+
declare function snapshotAbs(a: Abs): Abs;
|
|
258
|
+
/**
|
|
259
|
+
* 「有可用外延签名」判定:唯一权威定义。
|
|
260
|
+
*
|
|
261
|
+
* 名实说明:isRelFn **不要求** term 是 var。完全单态的具体签名
|
|
262
|
+
* (paramTypes=[number], returnType=string)同样满足——map 有槽就用。
|
|
263
|
+
* 多态(term=var)只是其中一种形态;名字里的 Rel 指「关系槽可用」。
|
|
264
|
+
*
|
|
265
|
+
* 收紧条件——仅有 returnType 而 paramTypes 与 arity 不对齐时,不算 rel,
|
|
266
|
+
* 防止半截签名在 map 里冒充关系。
|
|
267
|
+
*/
|
|
268
|
+
declare function isRelFn(a: Abs | undefined | null): boolean;
|
|
269
|
+
/**
|
|
270
|
+
* pred 三条规则:
|
|
271
|
+
* 1. var ∈ map + 实参有 term → 换 term,可归约则归约,否则残余保留
|
|
272
|
+
* 2. var ∈ map + 实参无 term → pred → true(conf 由调用方降级)
|
|
273
|
+
* 3. var ∉ map(自由 α)→ 原样保留
|
|
274
|
+
*/
|
|
275
|
+
declare function substPredAbs(p: Pred, map: ReadonlyMap<string, Abs>): {
|
|
276
|
+
pred: Pred;
|
|
277
|
+
dropped: boolean;
|
|
278
|
+
};
|
|
279
|
+
/**
|
|
280
|
+
* α 替换:map 的 key 是 term var id,value 是替换 Abs。
|
|
281
|
+
* var ∉ map 原样保留(含自由 α 上的 term/pred)。
|
|
282
|
+
*/
|
|
283
|
+
declare function substAbs(a: Abs, map: ReadonlyMap<string, Abs>): Abs;
|
|
284
|
+
/**
|
|
285
|
+
* relation-only / isRelFn 的应用:按 paramTypes 做 α 替换得到 returnType。
|
|
286
|
+
* impl.relation 槽优先于 shape.returnType。重复 α 先绑定保留。
|
|
287
|
+
* **深度合一**:`T[]` 形参可从 `number[]` 实参绑出 T=number(lodash 泛型)。
|
|
288
|
+
*/
|
|
289
|
+
declare function instantiateReturn(fn: Abs, args: Abs[]): Abs;
|
|
290
|
+
/**
|
|
291
|
+
* 回调统一入口(单点定义)。A–F + sum:
|
|
292
|
+
* A Node inline | B apply | C body | D relation | E isRelFn | F unknown
|
|
293
|
+
*
|
|
294
|
+
* 实现委托 applyAbsFn(已含 sum / D / E / body 优先)。
|
|
295
|
+
* Identifier 解析层:env.vars 有 Abs → B–E;env.fns 有 → callFunction;否则 unknown。
|
|
296
|
+
*
|
|
297
|
+
* 为避免 hof ↔ exec 循环依赖,本函数由宿主在运行时绑定。
|
|
298
|
+
*
|
|
299
|
+
* 依赖说明:宿主在 `exec/call.ts`(B-path `$call` 宿主)加载时注册(副作用)。
|
|
300
|
+
* 只 import hof.ts 而未加载 exec/call 时,fallback 仅认 relation/isRelFn。
|
|
301
|
+
* 与 §5.1 的「禁止全局 collector」不同——这里是无状态委托钩子,不是 run 局部状态。
|
|
302
|
+
*/
|
|
303
|
+
type ApplyCallbackHost = (cb: Abs | {
|
|
304
|
+
type: string;
|
|
305
|
+
}, args: Abs[], env: unknown, phi: unknown, budget: unknown) => Abs;
|
|
306
|
+
/**
|
|
307
|
+
* B-path 宿主 `exec/call.ts` 加载时注册(副作用)。
|
|
308
|
+
* 必须经 `exec/call.ts`(或其依赖方:exec/class、generalize)加载,
|
|
309
|
+
* 才能启用 Identifier/env.fns/inline body 路径;只 import hof.ts 时 fallback
|
|
310
|
+
* 仅认 relation/isRelFn。勿在多份实例下各写各的——双包/双副本会覆盖。
|
|
311
|
+
*/
|
|
312
|
+
declare function setApplyCallbackHost(fn: ApplyCallbackHost): void;
|
|
313
|
+
/**
|
|
314
|
+
* 通用回调实参调用(exec/class invokeArrMethod 与 builtins Array.from 共用):
|
|
315
|
+
* 原始 JS 函数直调(展开实参);Abs fn 走 applyCallbackAbs(sum 分发/宿主)。
|
|
316
|
+
* B 路径 transpile 的箭头回调是 $fnVal Abs——$fnVal.apply 自带调用边界。
|
|
317
|
+
*/
|
|
318
|
+
declare function applyCallbackValue(fn: unknown, args: Abs[], env: unknown, phi: unknown, budget: unknown): Abs;
|
|
319
|
+
declare function applyCallbackAbs(cb: Abs | {
|
|
320
|
+
type: string;
|
|
321
|
+
}, args: Abs[], env: unknown, phi: unknown, budget: unknown): Abs;
|
|
322
|
+
/** undefined 值的统一 Abs 表示(forEach/find 等) */
|
|
323
|
+
declare function undefAbs(): Abs;
|
|
324
|
+
/**
|
|
325
|
+
* map 元素投影:body 在符号实参上跑出 unknown 时,
|
|
326
|
+
* 用 shape.returnType 槽,conf 由调用方按 path/partial 处理。
|
|
327
|
+
* rel 回调不会走到这里(instantiateReturn 已给出结果)。
|
|
328
|
+
*/
|
|
329
|
+
declare function mapElementFallback(cbAbs: Abs | undefined, elem: Abs, out: Abs): Abs;
|
|
330
|
+
/**
|
|
331
|
+
* flatMap 统一结果:展开后的元素 join 成 arr(γ)。
|
|
332
|
+
* JS flatMap 永远返回 Array;双路径共用此投影,禁止一边 tuple 一边 arr。
|
|
333
|
+
* 同 term 元素 first-wins(joinAbs 会丢 β 身份,见 design §5.1)。
|
|
334
|
+
*/
|
|
335
|
+
declare function projectFlatMapResult(arrConf: Confidence, mapped: Abs[]): Abs;
|
|
336
|
+
/** 从 map/filter/reduce 回调实参里取出 Abs(Identifier 已绑定或直接 Abs) */
|
|
337
|
+
declare function asAbs(v: unknown): Abs | undefined;
|
|
338
|
+
|
|
168
339
|
/**
|
|
169
340
|
* 算术核:单调性 + 常量折叠 + 约束传播。
|
|
170
341
|
* 这是「类型即计算」的主武器——x>0 时 x+1 必须得到 >1。
|
|
@@ -221,6 +392,24 @@ declare function falseConstraint(c: Abs): Pred | undefined;
|
|
|
221
392
|
* 类型即计算——一元与控制流判定与二元算术同一运算域。
|
|
222
393
|
*/
|
|
223
394
|
|
|
395
|
+
/** & —— ToInt32 两侧后按位与 */
|
|
396
|
+
declare function bitandAbs(a: Abs, b: Abs): Abs;
|
|
397
|
+
/** | —— ToInt32 两侧后按位或 */
|
|
398
|
+
declare function bitorAbs(a: Abs, b: Abs): Abs;
|
|
399
|
+
/** ^ —— ToInt32 两侧后按位异或 */
|
|
400
|
+
declare function bitxorAbs(a: Abs, b: Abs): Abs;
|
|
401
|
+
/** ~ —— ToInt32 后按位取反(bigint 无符号截断) */
|
|
402
|
+
declare function bitnotAbs(a: Abs): Abs;
|
|
403
|
+
/** << —— 左移(rhs ToUint32 & 31;bigint 不限位宽) */
|
|
404
|
+
declare function shlAbs(a: Abs, b: Abs): Abs;
|
|
405
|
+
/** >> —— 算术右移(rhs ToUint32 & 31;bigint 不限位宽) */
|
|
406
|
+
declare function shrAbs(a: Abs, b: Abs): Abs;
|
|
407
|
+
/** >>> —— 逻辑右移(rhs ToUint32 & 31;bigint 无此运算符 → 不可折叠) */
|
|
408
|
+
declare function ushrAbs(a: Abs, b: Abs): Abs;
|
|
409
|
+
/** ** —— 幂(右结合由 AST 保证);负指数 bigint 原生 RangeError → 不可折叠 */
|
|
410
|
+
declare function powAbs(a: Abs, b: Abs): Abs;
|
|
411
|
+
/** 一元 + —— ToNumber 折叠;bigint 原生恒抛 TypeError → 不可折叠 */
|
|
412
|
+
declare function toNumberAbs(a: Abs): Abs;
|
|
224
413
|
/** JS typeof:结果域永远是 string */
|
|
225
414
|
declare function typeofAbs(a: Abs): Abs;
|
|
226
415
|
/** 一元负号:字面量折叠;符号数翻转不等式 */
|
|
@@ -243,81 +432,228 @@ declare function strictEqAbs(a: Abs, b: Abs): boolean | undefined;
|
|
|
243
432
|
declare function looseEqAbs(a: Abs, b: Abs): boolean | undefined;
|
|
244
433
|
|
|
245
434
|
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
435
|
+
* 对象不变性侧表(freeze/seal/preventExtensions/defineProperty)。
|
|
436
|
+
* WeakMap 侧表:Abs 不可变,写路径读侧表复现 sloppy 静默失败。
|
|
437
|
+
*/
|
|
438
|
+
|
|
439
|
+
type ExtState = "nonext" | "sealed" | "frozen";
|
|
440
|
+
type PropFlags = {
|
|
441
|
+
writable?: boolean;
|
|
442
|
+
enumerable?: boolean;
|
|
443
|
+
configurable?: boolean;
|
|
444
|
+
};
|
|
445
|
+
declare function markExtState(o: Abs, s: ExtState): Abs;
|
|
446
|
+
declare function extStateOf(o: Abs): ExtState | undefined;
|
|
447
|
+
declare function getPropFlags(o: Abs): Map<string, PropFlags> | undefined;
|
|
448
|
+
declare function setPropFlags(o: Abs, key: string, f: PropFlags): void;
|
|
449
|
+
/** 写路径产生新副本时迁移不变性侧表(同 migrateAccessors 模式)。
|
|
450
|
+
* propFlags 深拷贝:fork/switch 的 $copy 副本不得与源共享可变 Map
|
|
451
|
+
* (一臂 defineProperty 不得污染另一臂)。 */
|
|
452
|
+
declare function migrateInvariants(from: Abs, to: Abs): void;
|
|
453
|
+
|
|
454
|
+
/**
|
|
455
|
+
* Math.* — 字面量可折叠的返回精确值,否则 number
|
|
248
456
|
*/
|
|
249
457
|
|
|
250
|
-
/** Math.* — 字面量可折叠的返回精确值,否则 number */
|
|
251
458
|
declare function evalMathMethod(name: string, args: Abs[]): Abs | undefined;
|
|
252
|
-
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Object.assign 非 obj 源键投影 + Object.* 静态方法
|
|
462
|
+
*/
|
|
463
|
+
|
|
464
|
+
declare function assignSourceSlots(src: Abs): Record<string, {
|
|
465
|
+
value: Abs;
|
|
466
|
+
}> | undefined;
|
|
467
|
+
/** Object.keys/values/entries/assign + 不变性方法 */
|
|
253
468
|
declare function evalObjectMethod(name: string, args: Abs[]): Abs | undefined;
|
|
254
|
-
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* JSON.parse / JSON.stringify
|
|
472
|
+
*/
|
|
473
|
+
|
|
474
|
+
/** JSON.parse / stringify:字面量实参真执行折叠;失败硬抛(catch 可吸收) */
|
|
255
475
|
declare function evalJsonMethod(name: string, args: Abs[]): Abs | undefined;
|
|
476
|
+
|
|
477
|
+
/**
|
|
478
|
+
* Number.* 静态方法 + parseInt 折叠
|
|
479
|
+
*/
|
|
480
|
+
|
|
256
481
|
/** Number.isInteger / isNaN / parseFloat 等 */
|
|
257
482
|
declare function evalNumberStatic(name: string, args: Abs[]): Abs | undefined;
|
|
258
|
-
|
|
483
|
+
|
|
484
|
+
/**
|
|
485
|
+
* 全局转换函数(parseInt / Number / String / Boolean / Object / Array / Symbol …)
|
|
486
|
+
*/
|
|
487
|
+
|
|
259
488
|
declare function evalGlobalFn(name: string, args: Abs[]): Abs | undefined;
|
|
489
|
+
|
|
490
|
+
/**
|
|
491
|
+
* Array 构造 / Array.* 静态方法
|
|
492
|
+
*/
|
|
493
|
+
|
|
494
|
+
declare function makeArrayCtorAbs(args: Abs[]): Abs;
|
|
260
495
|
/** Array.isArray / Array.from / Array.of */
|
|
261
496
|
declare function evalArrayStatic(name: string, args: Abs[]): Abs | undefined;
|
|
262
|
-
|
|
497
|
+
|
|
498
|
+
/**
|
|
499
|
+
* Date 构造 / Date.* / Date 实例方法(保守未建模)
|
|
500
|
+
*/
|
|
501
|
+
|
|
263
502
|
declare function evalDateCtor(args: Abs[]): Abs;
|
|
264
503
|
declare function evalDateStatic(name: string, _args: Abs[]): Abs | undefined;
|
|
265
504
|
declare function evalDateMethod(name: string, _recv: Abs, _args: Abs[]): Abs | undefined;
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
505
|
+
|
|
506
|
+
/**
|
|
507
|
+
* RegExp 构造 / brand / 实例方法
|
|
508
|
+
*/
|
|
509
|
+
|
|
510
|
+
declare function evalRegExpCtor(args: Abs[]): Abs;
|
|
511
|
+
/** RegExp brand:source/flags/lastIndex 进 slots(B-path 与 ast-eval 共用) */
|
|
512
|
+
declare function regexBrandAbsFrom(pattern: string, flags: string): Abs;
|
|
513
|
+
/**
|
|
514
|
+
* new RegExp(pattern, flags) 字面量真构造验证($new 与 evalRegExpCtor 共用):
|
|
515
|
+
* - 无参 → /(?:)/(原生 source 归一)
|
|
516
|
+
* - pattern 非字面量(抽象/RegExp 实例)→ undefined(调用方保守)
|
|
517
|
+
* - symbol pattern / flags → TypeError(ToString 抛)
|
|
518
|
+
* - 非法 pattern / 非法 flags(含 number/null/boolean flags 的 ToString)
|
|
519
|
+
* → SyntaxError;合法 → 精确 brand(source/flags 取真构造结果)
|
|
520
|
+
*/
|
|
521
|
+
declare function tryMakeRegexAbs(args: Abs[]): Abs | undefined;
|
|
522
|
+
declare function evalRegExpMethod(name: string, recv: Abs, args: Abs[]): Abs | undefined;
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* 内建构造器注册表 + prototype brand / constructor 解析 + Object.prototype 单例 brand
|
|
526
|
+
*/
|
|
527
|
+
|
|
528
|
+
declare function builtinCtorAbs(name: string): Abs;
|
|
529
|
+
/** Abs 侧内建构造器身份(与宿主构造器名对齐) */
|
|
530
|
+
declare function builtinCtorNameOf(v: unknown): string | undefined;
|
|
531
|
+
/** 宿主全局构造器身份(Number === (42).constructor 折叠用) */
|
|
532
|
+
declare function hostBuiltinCtorName(v: unknown): string | undefined;
|
|
533
|
+
/**
|
|
534
|
+
* 接收者 → 原型链 constructor 名(`.constructor` 折叠)。
|
|
535
|
+
* null-proto 无 Object.prototype.constructor → undefined(读侧走 undef)。
|
|
536
|
+
*/
|
|
537
|
+
declare function ctorNameOfRecv(recv: Abs): string | undefined;
|
|
538
|
+
/** `X.prototype` 形态(getPrototypeOf 结果;带 constructor 槽) */
|
|
539
|
+
declare function protoBrandAbs(ctorName: string): Abs;
|
|
540
|
+
/**
|
|
541
|
+
* Object.getPrototypeOf 的具体原型投影(constructor 链可解)。
|
|
542
|
+
* null-proto → null 字面量;不可判形态 → unknown(不假装精确原型)。
|
|
543
|
+
*/
|
|
544
|
+
declare function protoOfRecv(a: Abs): Abs;
|
|
545
|
+
declare const OBJECT_PROTO_METHOD_NAMES: Set<string>;
|
|
546
|
+
/** Object.prototype 单例($get(Object, "prototype") 与 host Object.prototype 共用)。
|
|
547
|
+
* 带 constructor 槽(不可枚举)供 `.constructor` / `.constructor.name` 链折叠。 */
|
|
548
|
+
declare function objectProtoBrand(): Abs;
|
|
549
|
+
declare function isObjectProtoBrand(a: Abs | undefined): boolean;
|
|
550
|
+
|
|
551
|
+
/**
|
|
552
|
+
* Promise 构造 / then 链 / 静态方法 + micro 队列
|
|
553
|
+
*/
|
|
554
|
+
|
|
555
|
+
declare function enterPromiseExecutorScope(): void;
|
|
556
|
+
declare function leavePromiseExecutorScope(): number;
|
|
557
|
+
/** $fork 在 executor 内发生时打点(多臂 resolve 需 join,不得 first-wins 假精确) */
|
|
558
|
+
declare function notePromiseExecutorFork(): void;
|
|
559
|
+
declare function queuePromiseMicro(task: () => void): void;
|
|
560
|
+
declare function drainPromiseMicros(): void;
|
|
561
|
+
/**
|
|
562
|
+
* new Promise(executor):调用 executor(resolve, reject),收集 resolve 实参作为
|
|
563
|
+
* promise inner。原生只认第一次 settle——顺序双 resolve 取第一次;执行器内
|
|
564
|
+
* $fork 分叉时各臂 settle 值 join(路径敏感,不得 first-wins 假精确)。
|
|
565
|
+
* reject 不填 resolved 通道;永不 settle / 抽象 fn / 执行抛 → promise<unknown>。
|
|
566
|
+
*/
|
|
567
|
+
declare function evalPromiseCtor(args: Abs[]): Abs;
|
|
568
|
+
/** then/catch/finally:可映射回调 → 新 inner;做不到诚实 promise<unknown> */
|
|
569
|
+
declare function evalPromiseMethod(name: string, recv: Abs, args: Abs[]): Abs | undefined;
|
|
271
570
|
declare function evalPromiseStatic(name: string, args: Abs[]): Abs | undefined;
|
|
272
|
-
|
|
571
|
+
|
|
572
|
+
/**
|
|
573
|
+
* Error 家族 + evalBuiltinNew / evalBuiltinInstanceMethod + namespace 分派
|
|
574
|
+
*/
|
|
575
|
+
|
|
273
576
|
declare function evalNamespaceCall(ns: string, method: string, args: Abs[]): Abs | undefined;
|
|
274
577
|
declare function isErrorCtorName(name: string | undefined): boolean;
|
|
275
578
|
/**
|
|
276
579
|
* Error brand:shape 带 name/message(字面量 message 保精确)。
|
|
580
|
+
* AggregateError(errors, message[, options]):message 在第二实参,errors
|
|
581
|
+
* 挂 .errors(原生是实参数组副本);options.cause 挂 .cause(闭槽 miss
|
|
582
|
+
* 会折 undefined 假精确——原生 .cause 可能有值)。
|
|
277
583
|
* $new 与 ast-eval 的 new Error 共用——catch 形参成员访问可解。
|
|
278
584
|
*/
|
|
279
|
-
declare function errorBrandAbs(name: string,
|
|
585
|
+
declare function errorBrandAbs(name: string, args: Abs[]): Abs;
|
|
280
586
|
/** new X(...) */
|
|
281
587
|
declare function evalBuiltinNew(className: string, args: Abs[]): Abs | undefined;
|
|
282
588
|
/** brand 实例方法(Date/RegExp/Map/Set) */
|
|
283
589
|
declare function evalBuiltinInstanceMethod(brandName: string, method: string, recv: Abs, args: Abs[]): Abs | undefined;
|
|
284
590
|
|
|
285
591
|
/**
|
|
286
|
-
*
|
|
287
|
-
* 类型即计算——方法结果仍是 Abs,可继续参与约束推理。
|
|
288
|
-
* 宿主 TypeValue 的 dispatchMethod 只服务 IR 兜底,不是真理源。
|
|
289
|
-
* 模板语义(前缀/后缀/固定文本/长度/谓词判定)统一在 template.ts。
|
|
592
|
+
* String.fromCharCode 等静态方法
|
|
290
593
|
*/
|
|
291
594
|
|
|
292
595
|
/**
|
|
293
|
-
*
|
|
596
|
+
* String.fromCharCode(...):
|
|
597
|
+
* - 全部字面量 → 按 ToUint16 折成精确字符串(含越界/非整数/数字字符串)
|
|
598
|
+
* - symbol 字面量 → TypeError(ToNumber 抛)
|
|
599
|
+
* - 任一抽象实参 → 抽象 string(不假精确)
|
|
294
600
|
*/
|
|
295
|
-
declare function
|
|
296
|
-
/** 属性读取:template/string.length 等 */
|
|
297
|
-
declare function getAbsProperty(recv: Abs, name: string): Abs | undefined;
|
|
601
|
+
declare function evalStringStatic(name: string, args: Abs[]): Abs | undefined;
|
|
298
602
|
|
|
299
603
|
/**
|
|
300
|
-
*
|
|
604
|
+
* Symbol 身份侧表:Symbol() 产生非具体 unique symbol(prim type=symbol,无 term)。
|
|
605
|
+
* === 按 Abs 引用 / 侧表 id 判定,不把 description 折成可比较字面量身份。
|
|
606
|
+
* 独立小模块:surface(strictEqAbs) 与 builtins(makeSymbolAbs) 共用,避免环。
|
|
301
607
|
*/
|
|
302
608
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
declare const defaultLeakBudget: LeakBudget;
|
|
308
|
-
declare function termDepth(t: Term): number;
|
|
309
|
-
declare function termNodes(t: Term): number;
|
|
310
|
-
declare function exceedsBudget(t: Term, budget?: LeakBudget): boolean;
|
|
311
|
-
declare function resetLeakCounter(): void;
|
|
609
|
+
declare function symbolIdOf(a: Abs): number | undefined;
|
|
610
|
+
declare function symbolDescriptionAbs(a: Abs): Abs | undefined;
|
|
611
|
+
declare function isSymbolAbs$1(a: Abs | undefined): boolean;
|
|
612
|
+
|
|
312
613
|
/**
|
|
313
|
-
*
|
|
314
|
-
* 未超预算则原样返回。
|
|
614
|
+
* Symbol 构造 / 描述 / 字符串化
|
|
315
615
|
*/
|
|
316
|
-
|
|
616
|
+
|
|
617
|
+
/**
|
|
618
|
+
* Symbol([description]):非具体 unique symbol(prim type=symbol,无 term)。
|
|
619
|
+
* - 身份:侧表 id(两个 Symbol() 的 === 为 false;同 Abs 引用为 true)
|
|
620
|
+
* - .description:字面量 string 或 undefined
|
|
621
|
+
* - 不折成可比较的字面量身份(description 不作 identity)
|
|
622
|
+
*/
|
|
623
|
+
declare function makeSymbolAbs(descArg?: Abs): Abs;
|
|
624
|
+
declare const isSymbolAbs: typeof isSymbolAbs$1;
|
|
625
|
+
|
|
626
|
+
/** 全局 Symbol([desc])($callNamed 身份校验后派发) */
|
|
627
|
+
declare function evalSymbolCtor(args: Abs[]): Abs;
|
|
628
|
+
/** String(sym) → SymbolDescriptiveString(原生不抛;隐式 ToString 才抛) */
|
|
629
|
+
declare function stringOfSymbol(a: Abs): Abs;
|
|
630
|
+
|
|
317
631
|
/**
|
|
318
|
-
*
|
|
632
|
+
* Object.prototype 成员(hasOwnProperty / isPrototypeOf / toString / …)
|
|
319
633
|
*/
|
|
320
|
-
|
|
634
|
+
|
|
635
|
+
/**
|
|
636
|
+
* Object.prototype 方法语义(B-path $invoke 与 Object.prototype.X.call 共用)。
|
|
637
|
+
* null-proto 接收者无这些方法——返回 undefined(调用方走 TypeError 路径)。
|
|
638
|
+
* 返回 undefined = 未接管。
|
|
639
|
+
*/
|
|
640
|
+
declare function evalObjectProtoMethod(name: string, thisVal: Abs, args: Abs[]): Abs | undefined;
|
|
641
|
+
/** Object.prototype.X 一等函数(bindThis:call/apply 把 receiver 注入首参) */
|
|
642
|
+
declare function objectProtoMethodAbs(name: string): Abs;
|
|
643
|
+
|
|
644
|
+
/**
|
|
645
|
+
* Abs 方法表:模板字符串 / 结构值上的方法与属性。
|
|
646
|
+
* 类型即计算——方法结果仍是 Abs,可继续参与约束推理。
|
|
647
|
+
* 宿主 TypeValue 的 dispatchMethod 只服务 IR 兜底,不是真理源。
|
|
648
|
+
* 模板语义(前缀/后缀/固定文本/长度/谓词判定)统一在 template.ts。
|
|
649
|
+
*/
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* 调用 Abs 方法。返回 undefined = 未接管(调用方走其它路径)。
|
|
653
|
+
*/
|
|
654
|
+
declare function callAbsMethod(recv: Abs, name: string, args: Abs[]): Abs | undefined;
|
|
655
|
+
/** 属性读取:template/string.length 等 */
|
|
656
|
+
declare function getAbsProperty(recv: Abs, name: string): Abs | undefined;
|
|
321
657
|
|
|
322
658
|
/**
|
|
323
659
|
* 结构层:对象槽位、spread、函数重载并。
|
|
@@ -329,6 +665,8 @@ type Slot = {
|
|
|
329
665
|
optional?: boolean;
|
|
330
666
|
readonly?: boolean;
|
|
331
667
|
};
|
|
668
|
+
/** ES 规范数组下标(无前导零、< 2^32-1);非规范键返回 undefined */
|
|
669
|
+
declare function canonicalArrayIndex(v: unknown): number | undefined;
|
|
332
670
|
type ObjShape = {
|
|
333
671
|
k: "obj";
|
|
334
672
|
slots: Record<string, Slot>;
|
|
@@ -389,6 +727,10 @@ declare function fnOf(params: string[], name?: string): Abs;
|
|
|
389
727
|
declare function joinFunctions(a: Abs, b: Abs): Abs;
|
|
390
728
|
/** 通用 join:分派到对象/函数/值 */
|
|
391
729
|
declare function joinAbs(a: Abs, b: Abs): Abs;
|
|
730
|
+
declare function markNullProtoObj(o: Abs): Abs;
|
|
731
|
+
declare function isNullProtoObj(o: Abs): boolean;
|
|
732
|
+
/** 同一对象的不可变更新($set/$del)迁移 nullProto 标记 */
|
|
733
|
+
declare function migrateNullProto(from: Abs, to: Abs): Abs;
|
|
392
734
|
|
|
393
735
|
/**
|
|
394
736
|
* Map / Set 字面量条目追踪(C1.1 / C1.2)。
|
|
@@ -413,7 +755,8 @@ type SetTable = {
|
|
|
413
755
|
*/
|
|
414
756
|
maybeAbsent?: true | Set<LitKey>;
|
|
415
757
|
};
|
|
416
|
-
/** $fork 抽象分支:每侧独立 overlay,避免身份表被另一侧 set
|
|
758
|
+
/** $fork 抽象分支:每侧独立 overlay,避免身份表被另一侧 set 污染。
|
|
759
|
+
* 惰性:无集合写入时不分配 WeakMap(fork 热路径上无 Map/Set 是常态)。 */
|
|
417
760
|
type ArmOverlay = WeakMap<object, {
|
|
418
761
|
map?: MapTable;
|
|
419
762
|
set?: SetTable;
|
|
@@ -424,12 +767,20 @@ declare function popCollectionArm(): ArmOverlay | undefined;
|
|
|
424
767
|
* 合并 fork 各臂 overlay → 全局表(由 endCollectionFork 实现)。
|
|
425
768
|
* 保留导出名以免外部测试/调用点漂移。
|
|
426
769
|
*/
|
|
427
|
-
declare function mergeCollectionArms(arms: Array<ArmOverlay | undefined>): void;
|
|
770
|
+
declare function mergeCollectionArms(arms: Array<ArmOverlay | undefined | null>): void;
|
|
428
771
|
declare function beginCollectionFork(): void;
|
|
429
772
|
declare function noteCollectionWrite(id: object): void;
|
|
430
|
-
declare function endCollectionFork(arms: Array<ArmOverlay | undefined>): void;
|
|
773
|
+
declare function endCollectionFork(arms: Array<ArmOverlay | undefined | null>): void;
|
|
431
774
|
declare function isMapAbs(a: Abs | undefined): boolean;
|
|
432
775
|
declare function isSetAbs(a: Abs | undefined): boolean;
|
|
776
|
+
/**
|
|
777
|
+
* 构造器实参**确定**非法(原生 TypeError 域):
|
|
778
|
+
* - 非可迭代字面量(number/boolean/symbol/bigint、闭对象字面量)→ Set/Map 都抛
|
|
779
|
+
* - Map 条目必须是对象:外层 iterable 出现 lit prim 条目(含字符串实参的
|
|
780
|
+
* 每个字符、tuple/Set 元素)→ TypeError(空串例外:零条目合法)
|
|
781
|
+
* 抽象形态不确定 → false(保守)。
|
|
782
|
+
*/
|
|
783
|
+
declare function ctorArgDefinitelyInvalid(name: "Map" | "Set", iterable: Abs | undefined): boolean;
|
|
433
784
|
declare function makeMapAbs(iterable?: Abs): Abs;
|
|
434
785
|
declare function makeSetAbs(iterable?: Abs): Abs;
|
|
435
786
|
/** Map#set:fork 内写 overlay;否则原地。返回同一 Abs(JS 可变语义) */
|
|
@@ -498,34 +849,12 @@ declare function leqAbs(src: Abs, tgt: Abs, opts?: {
|
|
|
498
849
|
}): LeqResult;
|
|
499
850
|
|
|
500
851
|
/**
|
|
501
|
-
*
|
|
502
|
-
*
|
|
852
|
+
* Abs 域记录类型(ast-eval 执行器删除后保留的类型面)。
|
|
853
|
+
* 运行时记录由 B 通道(BCallRecord/$assignRecord)产生;此处的类型是
|
|
854
|
+
* checkSource drift / 结构赋值诊断的共享形状。
|
|
503
855
|
*/
|
|
504
856
|
|
|
505
|
-
|
|
506
|
-
declare function withVar(env: AstEnv, name: string, value: Abs): AstEnv;
|
|
507
|
-
type EvalOptions = {
|
|
508
|
-
phi?: Phi;
|
|
509
|
-
budget?: LeakBudget;
|
|
510
|
-
/** 预解析 AST(check 等批量场景避免重复 parse) */
|
|
511
|
-
file?: File;
|
|
512
|
-
/** host 已求值的相对依赖导出表 */
|
|
513
|
-
modules?: Record<string, AbsModuleExports>;
|
|
514
|
-
/** host 注入(@nudo:mock 等)在求值前绑定(evalSource 也认) */
|
|
515
|
-
seedVars?: Record<string, Abs>;
|
|
516
|
-
seedFns?: Record<string, {
|
|
517
|
-
params: string[];
|
|
518
|
-
body: Node;
|
|
519
|
-
async?: boolean;
|
|
520
|
-
}>;
|
|
521
|
-
};
|
|
522
|
-
declare const MAX_CALL_DEPTH = 64;
|
|
523
|
-
declare const MAX_TOTAL_CALLS = 200000;
|
|
524
|
-
/** 宿主入口(evalProgramAbs / analyzeFn / check)前重置 */
|
|
525
|
-
declare function resetAbsCallBudget(): void;
|
|
526
|
-
/** 记录被截断的递归(service 可映射为 nudo:recursion-truncated) */
|
|
527
|
-
declare function setAbsTruncationCollector(collector: ((fnLabel: string) => void) | null): void;
|
|
528
|
-
/** Abs 域调用记录(自包含程序可不经 TypeValue evaluator) */
|
|
857
|
+
/** Abs 域调用记录(B 通道 BCallRecord 的同形投影) */
|
|
529
858
|
type AbsCallRecord = {
|
|
530
859
|
fnName: string;
|
|
531
860
|
args: Abs[];
|
|
@@ -536,10 +865,7 @@ type AbsCallRecord = {
|
|
|
536
865
|
};
|
|
537
866
|
threw?: boolean;
|
|
538
867
|
};
|
|
539
|
-
/**
|
|
540
|
-
declare function setAbsCallCollector(collector: ((r: AbsCallRecord) => void) | null): ((r: AbsCallRecord) => void) | null;
|
|
541
|
-
declare function setAbsNodeCollector(collector: ((node: Node, value: Abs) => void) | null): void;
|
|
542
|
-
/** 赋值记录:结构可赋值检查用 */
|
|
868
|
+
/** Abs 域赋值记录(B 通道 $assignRecord 的同形投影) */
|
|
543
869
|
type AbsAssignRecord = {
|
|
544
870
|
name: string;
|
|
545
871
|
prev?: Abs;
|
|
@@ -549,130 +875,6 @@ type AbsAssignRecord = {
|
|
|
549
875
|
/** 分支/循环体内发生:可变绑定在路径上取并集是合法 JS,不参与结构检查 */
|
|
550
876
|
conditional?: boolean;
|
|
551
877
|
};
|
|
552
|
-
declare function setAbsAssignCollector(collector: ((r: AbsAssignRecord) => void) | null): void;
|
|
553
|
-
type EvalResult = {
|
|
554
|
-
value: Abs;
|
|
555
|
-
phi: Phi;
|
|
556
|
-
env: AstEnv;
|
|
557
|
-
/** 函数已通过 return 跳出,块内后续语句不可达 */
|
|
558
|
-
returned?: boolean;
|
|
559
|
-
/** break 跳出最近循环 */
|
|
560
|
-
brk?: boolean;
|
|
561
|
-
/** continue 进入下一轮 */
|
|
562
|
-
cont?: boolean;
|
|
563
|
-
/** throw 了 value(未捕获时向上传播) */
|
|
564
|
-
threw?: boolean;
|
|
565
|
-
/** throw 语句源位置(1-based line,0-based column;Babel loc 口径) */
|
|
566
|
-
throwLoc?: {
|
|
567
|
-
line: number;
|
|
568
|
-
column: number;
|
|
569
|
-
};
|
|
570
|
-
/**
|
|
571
|
-
* if 无 else 且 consequent 已 return/throw:真分支已产出 value,
|
|
572
|
-
* 假分支 fall-through 仍可能走后续语句。evalBlock 需与后续结果 join。
|
|
573
|
-
*/
|
|
574
|
-
partialReturn?: boolean;
|
|
575
|
-
/** 抽象分支可能 throw(另一侧继续)— try 需并 catch 路径 */
|
|
576
|
-
partialThrow?: boolean;
|
|
577
|
-
throwValue?: Abs;
|
|
578
|
-
};
|
|
579
|
-
/**
|
|
580
|
-
* 分析一段 JS 源码。
|
|
581
|
-
* 若含多个顶层函数声明,先注册全部,再对 `main` 或最后一个有调用的函数求值。
|
|
582
|
-
* 更简单:提供 `analyzeFunction(source, fnName, args)`。
|
|
583
|
-
*/
|
|
584
|
-
declare function evalSource(source: string, entry: {
|
|
585
|
-
fn: string;
|
|
586
|
-
args: Abs[];
|
|
587
|
-
}, opts?: EvalOptions): EvalResult;
|
|
588
|
-
/**
|
|
589
|
-
* 调用具名函数并返回 throws/loc(T20)。
|
|
590
|
-
* threw 时 result=never、throws=抛出值、throwLoc=throw 语句位置。
|
|
591
|
-
*/
|
|
592
|
-
declare function callFunctionFull(env: AstEnv, name: string, args: Abs[], phi?: Phi, budget?: LeakBudget): {
|
|
593
|
-
result: Abs;
|
|
594
|
-
throws: Abs;
|
|
595
|
-
throwLoc?: {
|
|
596
|
-
line: number;
|
|
597
|
-
column: number;
|
|
598
|
-
};
|
|
599
|
-
};
|
|
600
|
-
declare function callFunction(env: AstEnv, name: string, args: Abs[], phi?: Phi, budget?: LeakBudget): Abs;
|
|
601
|
-
/**
|
|
602
|
-
* 在 this=receiver 下求值方法体。
|
|
603
|
-
* constructor 无显式 return 时返回更新后的 this(字段写入已并入 env)。
|
|
604
|
-
*/
|
|
605
|
-
declare function evalMethodBody(method: {
|
|
606
|
-
params: string[];
|
|
607
|
-
body: Node;
|
|
608
|
-
async?: boolean;
|
|
609
|
-
kind?: string;
|
|
610
|
-
}, args: Abs[], thisVal: Abs, env: AstEnv, phi?: Phi, budget?: LeakBudget,
|
|
611
|
-
/** 方法定义所在类名(用于 super 派发) */
|
|
612
|
-
ownerClass?: string): Abs;
|
|
613
|
-
/** 对外入口:求值并记入节点表(Map<Node, Abs> 由 collector 消费) */
|
|
614
|
-
declare function evalNode(node: Node, env: AstEnv, phi: Phi, budget: LeakBudget): EvalResult;
|
|
615
|
-
/**
|
|
616
|
-
* 应用 Abs 一等函数。统一顺序:apply → body → relation → isRelFn。
|
|
617
|
-
* 调用门须扩为 `getFnImpl || isRelFn`,否则 E 路径永远进不来。
|
|
618
|
-
*/
|
|
619
|
-
declare function applyAbsFn(fnVal: Abs, args: Abs[], env: AstEnv, phi: Phi, budget: LeakBudget): Abs;
|
|
620
|
-
/**
|
|
621
|
-
* 从源码分析指定函数在给定实参下的抽象结果。
|
|
622
|
-
*
|
|
623
|
-
* @example
|
|
624
|
-
* analyzeFn(`
|
|
625
|
-
* const add = (a, b) => a + b;
|
|
626
|
-
* function scale(x) { return add(x, 1); }
|
|
627
|
-
* `, "scale", [numVar("x", gtNum(v("x"), 0))], gtNum(v("x"), 0))
|
|
628
|
-
*/
|
|
629
|
-
declare function analyzeFn(source: string, fnName: string, args: Abs[], phi?: Phi, budget?: LeakBudget, file?: File, modules?: Record<string, AbsModuleExports>): Abs;
|
|
630
|
-
/**
|
|
631
|
-
* analyzeFn 的 throws/loc 感知版(T19/T20):threw 时 result=never、throws=抛出值。
|
|
632
|
-
* 供 case 兜底在 B-path 失败时仍可无损拿 throws+loc,不经 TypeValue evaluateFunctionFull。
|
|
633
|
-
*/
|
|
634
|
-
declare function analyzeFnFull(source: string, fnName: string, args: Abs[], opts?: EvalOptions): {
|
|
635
|
-
result: Abs;
|
|
636
|
-
throws: Abs;
|
|
637
|
-
throwLoc?: {
|
|
638
|
-
line: number;
|
|
639
|
-
column: number;
|
|
640
|
-
};
|
|
641
|
-
};
|
|
642
|
-
/**
|
|
643
|
-
* 程序级 Abs 求值:注册全部顶层函数/class,再顺序执行语句。
|
|
644
|
-
* 返回最终 env(vars 含导出绑定)。TypeValue 仅在调用方 bridge 时出现。
|
|
645
|
-
*
|
|
646
|
-
* seedVars / seedFns:host 注入(@nudo:mock 等)在求值前绑定。
|
|
647
|
-
* modules:host 已求值的依赖导出表(specifier → AbsModuleExports)。
|
|
648
|
-
*/
|
|
649
|
-
declare function evalProgramAbs(source: string, opts?: EvalOptions & {
|
|
650
|
-
seedVars?: Record<string, Abs>;
|
|
651
|
-
seedFns?: Record<string, {
|
|
652
|
-
params: string[];
|
|
653
|
-
body: Node;
|
|
654
|
-
async?: boolean;
|
|
655
|
-
}>;
|
|
656
|
-
modules?: Record<string, AbsModuleExports>;
|
|
657
|
-
}): {
|
|
658
|
-
env: AstEnv;
|
|
659
|
-
last: Abs;
|
|
660
|
-
phi: Phi;
|
|
661
|
-
};
|
|
662
|
-
/**
|
|
663
|
-
* 收集整文件的节点 → Abs 表(LSP 无损信息源)。
|
|
664
|
-
* 自包含源码上一次 evalProgramAbs 即可;失败返回空表。
|
|
665
|
-
*/
|
|
666
|
-
declare function collectAbsNodeTypes(source: string, opts?: EvalOptions & {
|
|
667
|
-
seedVars?: Record<string, Abs>;
|
|
668
|
-
seedFns?: Record<string, {
|
|
669
|
-
params: string[];
|
|
670
|
-
body: Node;
|
|
671
|
-
async?: boolean;
|
|
672
|
-
}>;
|
|
673
|
-
}): Map<Node, Abs>;
|
|
674
|
-
/** 按 loc 找最紧的节点 Abs(hover 用) */
|
|
675
|
-
declare function findAbsAtPosition(nodeTypes: Map<Node, Abs>, line: number, column: number): Abs | undefined;
|
|
676
878
|
|
|
677
879
|
/**
|
|
678
880
|
* 格式化:把 Abs 渲染成人类可读 / CLI 友好的字符串。
|
|
@@ -692,366 +894,9 @@ declare function formatShape(a: Abs): string;
|
|
|
692
894
|
/** 多行展示,CLI 用 */
|
|
693
895
|
declare function formatAbsMultiline(a: Abs, label?: string): string;
|
|
694
896
|
|
|
695
|
-
/**
|
|
696
|
-
* 侧车/依赖路径纯函数(leaf 模块:零依赖,供 load-deps-fp / interface /
|
|
697
|
-
* refine / LSP 共享单一定义——历史上三份内联拷贝已各自漂移过)。
|
|
698
|
-
*/
|
|
699
|
-
declare function normPath(p: string): string;
|
|
700
|
-
/** core 不引 path:相对 spec 纯字符串拼接(与 LSP resolve 对齐时双方 norm) */
|
|
701
|
-
declare function resolveDepPath(fromFile: string, spec: string): string;
|
|
702
|
-
/**
|
|
703
|
-
* 是否落在 node_modules 下(相对/绝对/盘符形态统一)。
|
|
704
|
-
* autoBind 永不 ambient 加载 node_modules 侧车(§2.2)——必须在 normPath
|
|
705
|
-
* 之后判定,否则 `node_modules/pkg/x.js`(无前导 `/`)会绕过守卫。
|
|
706
|
-
*/
|
|
707
|
-
declare function isNodeModulesPath(p: string): boolean;
|
|
708
|
-
/**
|
|
709
|
-
* 源文件的旁路侧车路径:.js/.mjs → 同名 .nudo.js;.ts/.mts → 同名 .nudo.ts。
|
|
710
|
-
* 其他扩展名(.cjs/.jsx/无扩展名…)不做替换,直接追加 .nudo.js——侧车约定
|
|
711
|
-
* 只覆盖四类入口;host loadModule 对不存在的路径返回 miss,自然无侧车来源。
|
|
712
|
-
*/
|
|
713
|
-
declare function sidecarPathOf(file: string): string;
|
|
714
|
-
|
|
715
|
-
/**
|
|
716
|
-
* 约束模板构建器(参数无关)。
|
|
717
|
-
*
|
|
718
|
-
* number().gt(0) → 占位项 self 上的 Pred
|
|
719
|
-
* number().int().ge(0) → 整数 + 下界
|
|
720
|
-
* string().min(1) → 非空串(长度)
|
|
721
|
-
* array(number().gt(0)) → 元素约束
|
|
722
|
-
* shape({ id: number().gt(0) }) → object 形状约束
|
|
723
|
-
* lit(42) → 字面量(prim + eq(self, 42))
|
|
724
|
-
* union(number().gt(0), lit(0)) → 成员析取(or / joinAbs)
|
|
725
|
-
* fn({ x: number().gt(0) }, number()) → 一等函数约束
|
|
726
|
-
* number().gt(0).shift(1) → 界平移(x>0 ⇒ x+n>1)
|
|
727
|
-
* instantiate("ms") → Pred ms > 0 / u.id > 0 ∧ …
|
|
728
|
-
*
|
|
729
|
-
* 在 *.nudo.js 里执行;不是 zod 绑定,是我们自己的运行时 API。
|
|
730
|
-
* 不需要 interface/type 语法——契约用 JS 表达式声明。
|
|
731
|
-
* 注意:本文件的 lit/and 构建器与 term/pred 同名导出在桶导出处冲突,
|
|
732
|
-
* 消费方从 "./constraint.ts" 直接路径导入。
|
|
733
|
-
*/
|
|
734
|
-
|
|
735
|
-
/** 模板占位项;instantiate 时换成真实参数名 */
|
|
736
|
-
declare const SELF = "__nudo_self__";
|
|
737
|
-
/** 字段访问项:u.id */
|
|
738
|
-
declare function getTerm(obj: Term, key: string): Term;
|
|
739
|
-
/** 长度项:length(u) */
|
|
740
|
-
declare function lenTerm(t: Term): Term;
|
|
741
|
-
type NudoField = {
|
|
742
|
-
constraint: NudoConstraint;
|
|
743
|
-
optional?: boolean;
|
|
744
|
-
};
|
|
745
|
-
type NudoConstraint = {
|
|
746
|
-
readonly __nudoConstraint: true;
|
|
747
|
-
readonly prim?: PrimName;
|
|
748
|
-
readonly preds: Pred[];
|
|
749
|
-
/** object 形状:字段名 → 嵌套约束 */
|
|
750
|
-
readonly fields?: Record<string, NudoField>;
|
|
751
|
-
/** array 元素约束 */
|
|
752
|
-
readonly element?: NudoConstraint;
|
|
753
|
-
/** 整数(number 链式 .int()) */
|
|
754
|
-
readonly int?: boolean;
|
|
755
|
-
/** 该约束整体可选(shape 字段用;不用 optional 以免与链式方法撞名) */
|
|
756
|
-
readonly isOptional?: boolean;
|
|
757
|
-
/** union 成员(析取):instantiate 为 or(...),entry Abs 为成员 join */
|
|
758
|
-
readonly members?: NudoConstraint[];
|
|
759
|
-
/** 一等函数约束(fn() 构建器产出) */
|
|
760
|
-
readonly fn?: NudoFnConstraint;
|
|
761
|
-
};
|
|
762
|
-
/** fn(params, returns?, { throws? }) 的一等函数约束形态 */
|
|
763
|
-
type NudoFnConstraint = {
|
|
764
|
-
params: Record<string, NudoConstraint>;
|
|
765
|
-
returns?: NudoConstraint;
|
|
766
|
-
throws?: NudoConstraint;
|
|
767
|
-
};
|
|
768
|
-
declare function isNudoConstraint(x: unknown): x is NudoConstraint;
|
|
769
|
-
/** 链式约束:不可变,每次 .gt() 返回新对象 */
|
|
770
|
-
type ConstraintBuilder = NudoConstraint & {
|
|
771
|
-
gt(n: number): ConstraintBuilder;
|
|
772
|
-
ge(n: number): ConstraintBuilder;
|
|
773
|
-
lt(n: number): ConstraintBuilder;
|
|
774
|
-
le(n: number): ConstraintBuilder;
|
|
775
|
-
/** number:要求整数 */
|
|
776
|
-
int(): ConstraintBuilder;
|
|
777
|
-
/** string:长度下界 */
|
|
778
|
-
min(n: number): ConstraintBuilder;
|
|
779
|
-
/** string:长度上界 */
|
|
780
|
-
max(n: number): ConstraintBuilder;
|
|
781
|
-
/** string:精确长度 */
|
|
782
|
-
length(n: number): ConstraintBuilder;
|
|
783
|
-
/**
|
|
784
|
-
* 界平移:term 平移 n 后重写常数界(x>0 ⇒ x+n>n)。
|
|
785
|
-
* 仅数值标量界链合法;length 界 / shape / array / union / fn → throw。
|
|
786
|
-
*/
|
|
787
|
-
shift(n: number): ConstraintBuilder;
|
|
788
|
-
/** 字段可选(仅在 shape 内有意义) */
|
|
789
|
-
optional(): ConstraintBuilder;
|
|
790
|
-
};
|
|
791
|
-
/**
|
|
792
|
-
* builder 与纯数据形态统一的 int 标志读取:纯数据看 `int === true`,
|
|
793
|
-
* builder(int 是链式方法)查 WeakSet。toPlainConstraint 归一化后只剩前者。
|
|
794
|
-
*/
|
|
795
|
-
declare function isIntFlag(c: NudoConstraint): boolean;
|
|
796
|
-
/** number() —— 约束 number 原语 + 后续链式界 */
|
|
797
|
-
declare function number(): ConstraintBuilder;
|
|
798
|
-
declare function string(): ConstraintBuilder;
|
|
799
|
-
declare function boolean(): ConstraintBuilder;
|
|
800
|
-
/** any() —— 无约束;formatConstraint / draft import 与显示同源 */
|
|
801
|
-
declare function any(): ConstraintBuilder;
|
|
802
|
-
/** array(item) —— 数组,元素满足 item;item 亦可为具体字面量(指令文法) */
|
|
803
|
-
declare function array(item: NudoConstraint | ConstraintBuilder | number | string | boolean | null | undefined): ConstraintBuilder;
|
|
804
|
-
/**
|
|
805
|
-
* object 形状约束(契约规范形状,无需 interface):
|
|
806
|
-
*
|
|
807
|
-
* shape({ id: number().gt(0), name: string() })
|
|
808
|
-
*
|
|
809
|
-
* 字段值亦可为具体字面量(指令文法)。
|
|
810
|
-
*/
|
|
811
|
-
declare function shape(fields: Record<string, NudoConstraint | ConstraintBuilder | number | string | boolean | null | undefined>): ConstraintBuilder;
|
|
812
|
-
/** union(...cs):成员析取;instantiate 为 or(...),entry Abs 为成员 joinAbs。空参 throw */
|
|
813
|
-
declare function union(...cs: (NudoConstraint | ConstraintBuilder | number | string | boolean | null | undefined)[]): ConstraintBuilder;
|
|
814
|
-
/**
|
|
815
|
-
* fn(params, returns?, { throws? }):一等函数约束。
|
|
816
|
-
* Phase 1 只展示不执法:参数位 instantiate 恒真(pTrue),
|
|
817
|
-
* 逐参约束经 fnConstraintToEntryReqs 消费。
|
|
818
|
-
*/
|
|
819
|
-
declare function fn(params: Record<string, NudoConstraint | ConstraintBuilder | number | string | boolean | null | undefined>, returns?: NudoConstraint | ConstraintBuilder | number | string | boolean | null | undefined, opts?: {
|
|
820
|
-
throws?: NudoConstraint | ConstraintBuilder | number | string | boolean | null | undefined;
|
|
821
|
-
}): ConstraintBuilder;
|
|
822
|
-
/** partial(c):shape 全字段变可选;非 shape throw */
|
|
823
|
-
declare function partial(c: NudoConstraint | ConstraintBuilder): ConstraintBuilder;
|
|
824
|
-
/** pick(c, keys):shape 子形状(不存在的 key 忽略);非 shape throw */
|
|
825
|
-
declare function pick(c: NudoConstraint | ConstraintBuilder, keys: string[]): ConstraintBuilder;
|
|
826
|
-
/** omit(c, keys):shape 去字段;非 shape throw */
|
|
827
|
-
declare function omit(c: NudoConstraint | ConstraintBuilder, keys: string[]): ConstraintBuilder;
|
|
828
|
-
/** 把模板绑定到参数名:self → paramName;shape 展开为字段访问 Pred */
|
|
829
|
-
declare function instantiateConstraint(c: NudoConstraint, paramName: string): Pred;
|
|
830
|
-
/**
|
|
831
|
-
* 契约 → 函数入口 param Abs(infer/hover 用)。
|
|
832
|
-
* 标量:prim + pred;shape:obj slots 递归;union:成员 joinAbs;
|
|
833
|
-
* fn 形态:退化 unknown(不是参数位标量值),逐参约束由 fnConstraintToEntryReqs 消费。
|
|
834
|
-
*/
|
|
835
|
-
declare function constraintToEntryAbs(c: NudoConstraint, paramName: string): Abs;
|
|
836
|
-
/**
|
|
837
|
-
* fn 约束 → 逐参约束表(interface 推导 / 入口签名消费)。
|
|
838
|
-
* 非 fn() 形态 throw——调用方应先判 c.fn。
|
|
839
|
-
*/
|
|
840
|
-
declare function fnConstraintToEntryReqs(c: NudoConstraint): Array<{
|
|
841
|
-
param: string;
|
|
842
|
-
constraint: NudoConstraint;
|
|
843
|
-
}>;
|
|
844
|
-
|
|
845
|
-
/**
|
|
846
|
-
* 精化契约解析:唯一形态
|
|
847
|
-
*
|
|
848
|
-
* @nudo:refine <param> <constraint> 参数精化(挂入口 Abs,参与运算)
|
|
849
|
-
* @nudo:refine return <constraint> 返回精化(推断返回值 ⊭ 时红)
|
|
850
|
-
*
|
|
851
|
-
* 不叫 requires:那只是「校验挡板」。
|
|
852
|
-
* refine 表示约束是类型的一部分——Abs = shape × term × **pred** × conf,
|
|
853
|
-
* pred 会流入代数(x>0 ⇒ x+1>1),不只是调用点挡一下。
|
|
854
|
-
*
|
|
855
|
-
* constraint 来自 *.nudo.js 导出的模板(number().gt(0) 等),
|
|
856
|
-
* 由 /// @nudo:import { delay } from "./delay.nudo.js" 引入。
|
|
857
|
-
* 不支持写 `x > 0`(绑死参数名)。
|
|
858
|
-
* 不用 JSDoc @param/@return:那是类型注解语法。
|
|
859
|
-
*
|
|
860
|
-
* `@nudo:interface` 是 `@nudo:refine` 的等价别名(渐进迁移,§design-refine-derivation)。
|
|
861
|
-
* 侧车加载:Babel 语句级改写(多行 import / 注释与字符串里的同形文本不误伤)、
|
|
862
|
-
* 相对 .nudo.js/.nudo.ts 经 loadModule 递归求值、环检测、执行失败改诊断
|
|
863
|
-
* (nudo:interface-load / nudo:interface-cycle,不再静默吞错)。
|
|
864
|
-
*/
|
|
865
|
-
|
|
866
|
-
/** `/// @nudo:import { delay, percent } from "./delay.nudo.js"` */
|
|
867
|
-
type NamedImport = {
|
|
868
|
-
names: string[];
|
|
869
|
-
spec: string;
|
|
870
|
-
};
|
|
871
|
-
declare function extractNudoImports(source: string): NamedImport[];
|
|
872
|
-
/** refine 侧车加载诊断(severity 由消费方按 code 定档,形状对齐 Issue 子集) */
|
|
873
|
-
type RefineDiag = {
|
|
874
|
-
code: string;
|
|
875
|
-
message: string;
|
|
876
|
-
file?: string;
|
|
877
|
-
};
|
|
878
|
-
/** 设置诊断观察者(null 清除);缓冲照常累积,takeRefineDiags 取走 */
|
|
879
|
-
declare function setRefineDiagCollector(fn: ((d: RefineDiag) => void) | null): void;
|
|
880
|
-
/** 当前诊断累计序号(since 锚) */
|
|
881
|
-
declare function refineDiagCount(): number;
|
|
882
|
-
/** 取走已收集的诊断(收集即清空) */
|
|
883
|
-
declare function takeRefineDiags(): RefineDiag[];
|
|
884
|
-
/** 只取走 seq > since 的增量(工具面防窃取在途诊断;全量 take 的 since 版) */
|
|
885
|
-
declare function takeRefineDiagsSince(since: number): RefineDiag[];
|
|
886
|
-
/** 侧车模块错误:code ∈ nudo:interface-cycle | nudo:interface-load */
|
|
887
|
-
declare class NudoSidecarError extends Error {
|
|
888
|
-
readonly code: string;
|
|
889
|
-
constructor(code: string, message: string);
|
|
890
|
-
}
|
|
891
|
-
/**
|
|
892
|
-
* 执行 *.nudo.js(真实 JS + 我们的构建器)。import/export 由 Babel 语句级
|
|
893
|
-
* 改写:多行 named import、注释/字符串里的同形文本不误伤;相对 .nudo 递归
|
|
894
|
-
* 求值;环 → throw NudoSidecarError。结果进 exec 缓存(依赖闭包内容指纹键)。
|
|
895
|
-
*/
|
|
896
|
-
declare function execNudoModule(src: string, opts?: RefineResolveOpts): Record<string, unknown>;
|
|
897
|
-
type RefineResolveOpts = {
|
|
898
|
-
loadModule?: (spec: string, fromFile: string) => string | undefined;
|
|
899
|
-
/** 侧车自身的路径(相对 spec 解析基准 + 环检测链起点) */
|
|
900
|
-
fromFile?: string;
|
|
901
|
-
};
|
|
902
|
-
declare function resetNudoModuleExecCache(): void;
|
|
903
|
-
/**
|
|
904
|
-
* 解析 `ms delay` / `n percent` → [param, Pred]
|
|
905
|
-
* 多条用 && 或换行连接。
|
|
906
|
-
* 同时保留原始 NudoConstraint(shape 字段检查用)。
|
|
907
|
-
*/
|
|
908
|
-
type RefineEntry = {
|
|
909
|
-
param: string;
|
|
910
|
-
pred: Pred;
|
|
911
|
-
constraint: NudoConstraint;
|
|
912
|
-
};
|
|
913
|
-
declare function extractRefinesFromSource(source: string, fnName: string, opts?: RefineResolveOpts): RefineEntry[];
|
|
914
|
-
/** refine 参数 → 带约束模板的下标表(shape 检查用) */
|
|
915
|
-
declare function refineToIndexedFull(source: string, fnName: string, paramNames: string[], opts?: RefineResolveOpts): Array<[number, RefineEntry]>;
|
|
916
|
-
/**
|
|
917
|
-
* 解析 `@nudo:refine return positive` → 返回精化。
|
|
918
|
-
* 返回 undefined = 无声明(不猜后置)。
|
|
919
|
-
*/
|
|
920
|
-
declare function extractRefineReturnFromSource(source: string, fnName: string, opts?: RefineResolveOpts): {
|
|
921
|
-
name: string;
|
|
922
|
-
constraint: NudoConstraint;
|
|
923
|
-
} | undefined;
|
|
924
|
-
|
|
925
|
-
/**
|
|
926
|
-
* Interface 分层推导(design-refine-derivation §2.1/§2.2/§11 第 0 步):
|
|
927
|
-
*
|
|
928
|
-
* effectiveInterface(source, fnName) —— 手写 ∪ 侧车同名绑定 ∪ 生成段的
|
|
929
|
-
* 唯一读取口,来源标注(handwritten / generated / implicit)随值返回。
|
|
930
|
-
*
|
|
931
|
-
* 来源三层(合并序 handwritten > generated > implicit,§4/§11):
|
|
932
|
-
* - handwritten:源码 `@nudo:refine`/`@nudo:interface` 行(复用 refine.ts 的
|
|
933
|
-
* extractRefinesFromSource / extractRefineReturnFromSource)∪ 侧车同名**手写**
|
|
934
|
-
* fn() 绑定。同名同参取合取 and()(§2.1:侧车 x>0 + 源码 x>1 → 有效契约
|
|
935
|
-
* 取合取);常数界交叉矛盾(x>0 ∧ x<0)→ conflict 标记,由调用方报
|
|
936
|
-
* nudo:interface-conflict——本函数不 throw。
|
|
937
|
-
* - generated:侧车同名导出且声明上方注释块含 @generated 标记(emit 产物)。
|
|
938
|
-
* 与手写并存时整体降级忽略(手写为准;混排由 nudo:interface-name-clash /
|
|
939
|
-
* drift 在 emit/check 侧处理)。
|
|
940
|
-
* - implicit:无任何契约 → 返回 undefined(隐式推断是调用方的事)。
|
|
941
|
-
*
|
|
942
|
-
* 自动绑定边界(§2.2):只绑源文件**本地 named export**(re-export /
|
|
943
|
-
* export default / 私有名不绑);opts.autoBind === false 或侧车路径含
|
|
944
|
-
* /node_modules/ → 不 ambient 加载(只看源码 refine)。「项目根内」检查属
|
|
945
|
-
* 宿主层(core 无 projectDir 概念),Phase 1 不在此实现。
|
|
946
|
-
*
|
|
947
|
-
* 侧车绑定 Phase 1 只承诺 fn() 形态:非 fn 的标量/shape 绑定不消费,收集
|
|
948
|
-
* nudo:interface-load 诊断(后续 Phase 再放开单参形态)。
|
|
949
|
-
*
|
|
950
|
-
* 诊断走本文件独立 side-channel(先例 refine.ts 的 setRefineDiagCollector):
|
|
951
|
-
* 侧车加载/执行失败 → nudo:interface-cycle / nudo:interface-load。
|
|
952
|
-
*/
|
|
953
|
-
|
|
954
|
-
/** interface 推导诊断(severity 由消费方按 code 定档,形状对齐 Issue 子集) */
|
|
955
|
-
type InterfaceDiag = {
|
|
956
|
-
code: string;
|
|
957
|
-
message: string;
|
|
958
|
-
file?: string;
|
|
959
|
-
};
|
|
960
|
-
/** 设置诊断观察者(null 清除);缓冲照常累积,takeInterfaceDiags 取走 */
|
|
961
|
-
declare function setInterfaceDiagCollector(fn: ((d: InterfaceDiag) => void) | null): void;
|
|
962
|
-
/** 当前诊断累计序号(since 锚:工具面只排干自身探测产生的增量) */
|
|
963
|
-
declare function interfaceDiagCount(): number;
|
|
964
|
-
/** 取走已收集的诊断(收集即清空) */
|
|
965
|
-
declare function takeInterfaceDiags(): InterfaceDiag[];
|
|
966
|
-
/**
|
|
967
|
-
* 只取走 seq > since 的诊断(清空仅限增量)——LSP 长驻进程里 lens/打印/
|
|
968
|
-
* emit 工具用它排干**自身探测**产生的诊断,不窃取在途 validateText 待消费
|
|
969
|
-
* 的接口诊断(全量 take 曾在 await 窗口偷走 checkSource 的待收诊断)。
|
|
970
|
-
*/
|
|
971
|
-
declare function takeInterfaceDiagsSince(since: number): InterfaceDiag[];
|
|
972
|
-
/** 有效契约来源:手写(源码 refine ∪ 侧车手写绑定)> 生成段 > 隐式 */
|
|
973
|
-
type InterfaceSource = "handwritten" | "generated" | "implicit";
|
|
974
|
-
/**
|
|
975
|
-
* 源文件本地导出名表(侧车自动绑定边界):
|
|
976
|
-
* - ESM:`export function/const/let/var/class` 与本地 `export { x }` /
|
|
977
|
-
* `export { local as exported }`(按**导出名**绑定);
|
|
978
|
-
* - `export default function add` / `const add = …; export default add`:
|
|
979
|
-
* 按**本地名** `add` 绑定(侧车可 `export const add = fn(…)`);
|
|
980
|
-
* 同时登记 `"default"`,供侧车 `export default fn(…)` 对齐;
|
|
981
|
-
* - CJS(C4.3):`module.exports = { a, b }`、`module.exports.a = …`、
|
|
982
|
-
* `exports.a = …`、`module.exports = localFn`(登记 localFn 名)。
|
|
983
|
-
* 排除 re-export(`export {x} from` / `export *`)。
|
|
984
|
-
*/
|
|
985
|
-
declare function localNamedExports(source: string): Set<string>;
|
|
986
|
-
/**
|
|
987
|
-
* 侧车源码的生成段导出名:export 之前(跳过紧邻的 import/const 链)的注释
|
|
988
|
-
* 行含 `@generated` → 该名为 generated。组合式下行段(§5.3)形态为
|
|
989
|
-
* `import` + `@generated 头` + prelude + export;callsite 段则是头紧贴
|
|
990
|
-
* export。隔了其他代码行 / 无标记 / re-export 列表均不算。
|
|
991
|
-
*/
|
|
992
|
-
declare function generatedExportNames(sidecarSrc: string): Set<string>;
|
|
993
|
-
type EffectiveInterfaceOpts = RefineResolveOpts & {
|
|
994
|
-
/** false(或谓词返回 false)→ 不 ambient 加载侧车;默认 true */
|
|
995
|
-
autoBind?: boolean | ((sidecarPath: string) => boolean);
|
|
996
|
-
};
|
|
997
|
-
type EffectiveInterface = {
|
|
998
|
-
fnName: string;
|
|
999
|
-
params: Array<{
|
|
1000
|
-
param: string;
|
|
1001
|
-
constraint: NudoConstraint;
|
|
1002
|
-
}>;
|
|
1003
|
-
returns?: {
|
|
1004
|
-
constraint: NudoConstraint;
|
|
1005
|
-
};
|
|
1006
|
-
source: InterfaceSource;
|
|
1007
|
-
/**
|
|
1008
|
-
* 合取不可满足标记:params = 常数界交叉矛盾(或 prim 矛盾等 and() 不可
|
|
1009
|
-
* 合取形态)的参数名;returns = 返回位同样不可满足。调用方报
|
|
1010
|
-
* nudo:interface-conflict 并跳过对应位执法。
|
|
1011
|
-
*/
|
|
1012
|
-
conflict?: {
|
|
1013
|
-
params: string[];
|
|
1014
|
-
returns?: boolean;
|
|
1015
|
-
};
|
|
1016
|
-
};
|
|
1017
|
-
/**
|
|
1018
|
-
* 单点读取口:手写 ∪ 侧车同名 ∪ 生成段 → 有效契约(含来源标注)。
|
|
1019
|
-
* 无任何契约 → undefined(implicit 由调用方处理)。
|
|
1020
|
-
*/
|
|
1021
|
-
declare function effectiveInterface(source: string, fnName: string, opts?: EffectiveInterfaceOpts): EffectiveInterface | undefined;
|
|
1022
|
-
/**
|
|
1023
|
-
* 侧车及递归 .nudo 依赖闭包的内容指纹:`${hashSource(侧车)}|路径=hash,…`。
|
|
1024
|
-
* 无 loadModule / autoBind 关闭 / node_modules / loadModule miss → undefined
|
|
1025
|
-
* (无侧车影响即无需指纹)。闭包截断 → `trunc:` 前缀,键不可信,调用方
|
|
1026
|
-
* fail-open(参照 loadModuleDepsFingerprint 的 truncated 契约)。
|
|
1027
|
-
*/
|
|
1028
|
-
declare function sidecarClosureFingerprint(fromFile: string, opts: EffectiveInterfaceOpts): string | undefined;
|
|
1029
|
-
/** 组合式显示:重建构建器调用形态(number().gt(0) / union(…) / fn(…)) */
|
|
1030
|
-
declare function formatConstraint(c: NudoConstraint): string;
|
|
1031
|
-
/** EffectiveInterface → 契约展示串(与 CLI interface 打印同口径,不含函数名) */
|
|
1032
|
-
declare function formatEffectiveInterfaceDisplay(eff: EffectiveInterface): string;
|
|
1033
|
-
/** CodeLens / hover 首行标题(design-refine-derivation §8):`● interface / <source>` */
|
|
1034
|
-
declare function formatInterfaceTierLine(source: InterfaceSource): string;
|
|
1035
|
-
type InterfaceTierInfo = {
|
|
1036
|
-
source: InterfaceSource;
|
|
1037
|
-
/** handwritten/generated 时的契约展示;implicit 为 undefined */
|
|
1038
|
-
display?: string;
|
|
1039
|
-
};
|
|
1040
|
-
type InterfaceTierOpts = EffectiveInterfaceOpts;
|
|
1041
|
-
/**
|
|
1042
|
-
* interface 档单一读取口(A7):CodeLens `● interface`、hover、inlay、
|
|
1043
|
-
* semantic tokens 共用本函数,保证「同源」。
|
|
1044
|
-
*
|
|
1045
|
-
* 与 computeInterfaceLenses 同口径:仅源文件 **本地 named export** 进档;
|
|
1046
|
-
* 私有名 / 非导出 → undefined(不进 interface 档,不假装 implicit 契约)。
|
|
1047
|
-
*/
|
|
1048
|
-
declare function interfaceTierOf(source: string, fnName: string, fromFile: string, opts?: InterfaceTierOpts): InterfaceTierInfo | undefined;
|
|
1049
|
-
/** interfaceTierOf 的来源投影;非导出 → undefined */
|
|
1050
|
-
declare function interfaceSourceOf(source: string, fnName: string, fromFile: string, opts?: InterfaceTierOpts): InterfaceSource | undefined;
|
|
1051
|
-
|
|
1052
897
|
/**
|
|
1053
898
|
* C4.1:函数形参表面(contract surface)——
|
|
1054
|
-
* 侧车 `fn({…})` / `@nudo:
|
|
899
|
+
* 侧车 `fn({…})` / `@nudo:contract` 参数名与求值形参的对齐基线。
|
|
1055
900
|
*
|
|
1056
901
|
* - Identifier / 默认参(AssignmentPattern left)→ 绑定名
|
|
1057
902
|
* - RestElement → 契约名用裸名(`args`),展示名 `...args`
|
|
@@ -1119,48 +964,6 @@ declare function locateContractParam(formals: FormalParam[], contractName: strin
|
|
|
1119
964
|
rest?: boolean;
|
|
1120
965
|
} | undefined;
|
|
1121
966
|
|
|
1122
|
-
type LoadDepsFingerprint = {
|
|
1123
|
-
fp: string;
|
|
1124
|
-
paths: string[];
|
|
1125
|
-
/**
|
|
1126
|
-
* path + loadModule-resolved content(miss → null)。调用方(磁盘缓存键)
|
|
1127
|
-
* 必须优先用这里的 content,不得回读磁盘——否则 buffer-aware loadModule
|
|
1128
|
-
* 与磁盘不一致时键会分叉。
|
|
1129
|
-
*/
|
|
1130
|
-
contents: Array<{
|
|
1131
|
-
path: string;
|
|
1132
|
-
content: string | null;
|
|
1133
|
-
}>;
|
|
1134
|
-
/** BFS 撞到节点上限:剩余 dep 未进指纹,键不可信 */
|
|
1135
|
-
truncated: boolean;
|
|
1136
|
-
};
|
|
1137
|
-
/**
|
|
1138
|
-
* All string module specs that analysis may resolve through loadModule.
|
|
1139
|
-
* Regex over-approximates (may hit comments) — extra dep fingerprint is safe
|
|
1140
|
-
* (more misses, never a stale hit).
|
|
1141
|
-
*/
|
|
1142
|
-
declare function extractAllLoadSpecs(source: string): string[];
|
|
1143
|
-
/**
|
|
1144
|
-
* 源里指向其他侧车的相对 spec(`.nudo.js`/`.nudo.ts`)。regex 过近似安全:
|
|
1145
|
-
* 多算的 dep 只带来额外 miss,绝不产生陈旧命中。LSP 隐式依赖登记共用。
|
|
1146
|
-
*/
|
|
1147
|
-
declare function sidecarSpecsOf(source: string): string[];
|
|
1148
|
-
/**
|
|
1149
|
-
* Fingerprint every loadModule-reachable dep (not only `*.nudo.js`), including
|
|
1150
|
-
* one hop of transitive specs from each dep source — plus the autoBind 侧车
|
|
1151
|
-
* 闭包(`sidecar:` 前缀条目)。
|
|
1152
|
-
*
|
|
1153
|
-
* 侧车吸收范围 = fromFile 自身 **与每一个成功加载的依赖文件**的旁路侧车及其
|
|
1154
|
-
* 递归 .nudo 依赖:跨文件被调(scan.ts checkExternalCall)会按定义文件路径
|
|
1155
|
-
* ambient 绑定其侧车,依赖侧车内容影响调用方报告——不进指纹则编辑后 memo
|
|
1156
|
-
* 陈旧命中(错诊断)。侧车 loadModule miss(无侧车文件)→ 不加任何条目。
|
|
1157
|
-
*
|
|
1158
|
-
* 注意:本扩展对 autoBind=false 与 /node_modules/ 均**不** gate(刻意过近似,
|
|
1159
|
-
* 只过度失效、绝不陈旧命中——安全方向);ambient 生效边界由
|
|
1160
|
-
* interface.ts 的 sidecarClosureFingerprint 负责,两者职责不同。
|
|
1161
|
-
*/
|
|
1162
|
-
declare function loadModuleDepsFingerprint(source: string, loadModule: (spec: string, fromFile: string) => string | undefined, fromFile: string): LoadDepsFingerprint;
|
|
1163
|
-
|
|
1164
967
|
declare function resetGeneralizeMemo(): void;
|
|
1165
968
|
declare function getGeneralizeMemoSize(): number;
|
|
1166
969
|
/**
|
|
@@ -1181,7 +984,7 @@ type PolyFn = {
|
|
|
1181
984
|
instantiate: (args: Abs[], phi?: Phi) => Abs;
|
|
1182
985
|
symbolic: Abs;
|
|
1183
986
|
display: string;
|
|
1184
|
-
/** 入口契约(@nudo:
|
|
987
|
+
/** 入口契约(@nudo:contract),供签名/inlay 展示 */
|
|
1185
988
|
entryReqs?: Array<{
|
|
1186
989
|
param: string;
|
|
1187
990
|
pred: Pred;
|
|
@@ -1218,7 +1021,7 @@ declare function extractFn(source: string, fnName: string, fileAst?: ReturnType<
|
|
|
1218
1021
|
declare function generalizeFromAst(fnName: string, source: string, opts?: {
|
|
1219
1022
|
budget?: LeakBudget;
|
|
1220
1023
|
label?: string;
|
|
1221
|
-
/** 传入则把 @nudo:
|
|
1024
|
+
/** 传入则把 @nudo:contract 挂到入口 param Abs */
|
|
1222
1025
|
refine?: EffectiveInterfaceOpts;
|
|
1223
1026
|
/** 预解析 AST,避免 check 批量场景重复 parse */
|
|
1224
1027
|
file?: ReturnType<typeof parseSource>;
|
|
@@ -1226,303 +1029,49 @@ declare function generalizeFromAst(fnName: string, source: string, opts?: {
|
|
|
1226
1029
|
depsFp?: LoadDepsFingerprint;
|
|
1227
1030
|
/** 预计算 ambient 侧车闭包指纹(checkSource 整文件一次) */
|
|
1228
1031
|
sidecarFp?: string;
|
|
1032
|
+
/** 宿主已求值的依赖导出表(specifier → AbsModuleExports) */
|
|
1033
|
+
modules?: Record<string, AbsModuleExports | Record<string, unknown>>;
|
|
1034
|
+
/** B run 注入包(modules/mocks/envGlobals/replacements/as)——透传
|
|
1035
|
+
* runTranspiled;对象身份进 memo 键(调用方同文件内复用同一对象) */
|
|
1036
|
+
inject?: RunTranspiledOptions;
|
|
1229
1037
|
}): PolyFn | undefined;
|
|
1230
1038
|
declare function generalizeAll(source: string, opts?: {
|
|
1231
1039
|
budget?: LeakBudget;
|
|
1232
1040
|
}): PolyFn[];
|
|
1233
|
-
/** 列出源码中的顶层函数名 */
|
|
1234
|
-
declare function listFunctionNames(source: string): string[];
|
|
1235
|
-
/**
|
|
1236
|
-
* 按 assume 集合构造实参:被 assume 的参数给带约束的符号,其余 unknown。
|
|
1237
|
-
*/
|
|
1238
|
-
declare function buildArgsFromAssume(source: string, fnName: string, assumeIds: Set<string>): Abs[];
|
|
1239
|
-
|
|
1240
|
-
/**
|
|
1241
|
-
* 约束诊断:检查调用点实参是否满足函数的前置约束 / 参数 shape。
|
|
1242
|
-
* 输出可行动的建议,而不是 TS 式「类型不匹配」。
|
|
1243
|
-
*/
|
|
1244
|
-
|
|
1245
|
-
type Diagnostic = {
|
|
1246
|
-
severity: "error" | "warning" | "info";
|
|
1247
|
-
code: string;
|
|
1248
|
-
message: string;
|
|
1249
|
-
suggestion?: string;
|
|
1250
|
-
fn?: string;
|
|
1251
|
-
argIndex?: number;
|
|
1252
|
-
};
|
|
1253
|
-
/**
|
|
1254
|
-
* 检查实参是否满足「期望约束」。
|
|
1255
|
-
* expect: 相对参数 term 的 pred,例如 term > 0
|
|
1256
|
-
* arg: 实际实参 Abs
|
|
1257
|
-
*/
|
|
1258
|
-
declare function checkArg(arg: Abs, expect: Pred | undefined, phi?: Phi): Diagnostic | undefined;
|
|
1259
|
-
/**
|
|
1260
|
-
* 对一次函数调用做诊断:实参 shape + 约束。
|
|
1261
|
-
*/
|
|
1262
|
-
declare function checkCall(source: string, fnName: string, args: Abs[], phi?: Phi): Diagnostic[];
|
|
1263
|
-
declare function formatDiagnostics(diags: Diagnostic[]): string;
|
|
1264
|
-
|
|
1265
1041
|
/**
|
|
1266
|
-
*
|
|
1267
|
-
*
|
|
1268
|
-
*
|
|
1269
|
-
*
|
|
1270
|
-
* 本模块是模板语义的唯一真理源:前缀/后缀/固定文本/长度/匹配/名称渲染/
|
|
1271
|
-
* 相邻合并/谓词判定等纯计算以「中性 part 视图」(TemplatePartView)暴露;
|
|
1272
|
-
* Abs 方法表(methods.ts)只做薄适配。
|
|
1042
|
+
* 列出源码中的顶层函数名。
|
|
1043
|
+
* 与 scan.listTopFunctions 对齐:解 export default / export const 箭头与函数表达式。
|
|
1044
|
+
* (不 import scan:scan 依赖本文件,避免环。完整 CJS/class 面用 listTopFunctions。)
|
|
1273
1045
|
*/
|
|
1274
|
-
|
|
1275
|
-
type TemplateMeta = {
|
|
1276
|
-
templateParts: Abs[];
|
|
1277
|
-
};
|
|
1278
|
-
/** 单个 part 的分类:固定文本,或抽象 part(携带展示文本) */
|
|
1279
|
-
type TemplatePartDesc = {
|
|
1280
|
-
fixed: string;
|
|
1281
|
-
} | {
|
|
1282
|
-
render: string;
|
|
1283
|
-
};
|
|
1284
|
-
/** 带原始 part 回引的视图:既喂语义计算,也用于重建合并结果 */
|
|
1285
|
-
type TemplatePartView<P = unknown> = {
|
|
1286
|
-
/** 固定文本;undefined = 抽象 part */
|
|
1287
|
-
fixed: string | undefined;
|
|
1288
|
-
/** 抽象 part 的展示文本(渲染 `${...}` 名时使用) */
|
|
1289
|
-
render: string;
|
|
1290
|
-
part: P;
|
|
1291
|
-
};
|
|
1292
|
-
declare function viewTemplateParts<P>(parts: P[], describe: (p: P) => TemplatePartDesc): TemplatePartView<P>[];
|
|
1293
|
-
/** 前导固定文本(遇到首个抽象 part 停止) */
|
|
1294
|
-
declare function knownPrefixOfViews(views: TemplatePartView[]): string;
|
|
1295
|
-
/** 尾部固定文本(从末尾遇到首个抽象 part 停止) */
|
|
1296
|
-
declare function knownSuffixOfViews(views: TemplatePartView[]): string;
|
|
1297
|
-
/** 全部固定文本按序拼接(跨抽象 part) */
|
|
1298
|
-
declare function allFixedTextOfViews(views: TemplatePartView[]): string;
|
|
1299
|
-
/** 全部 part 均为固定文本时的精确总长;含抽象 part 则 undefined */
|
|
1300
|
-
declare function fixedLengthOfViews(views: TemplatePartView[]): number | undefined;
|
|
1301
|
-
/** 渲染 `` `lit${render}` `` 形态的模板名 */
|
|
1302
|
-
declare function formatTemplateNameViews(views: TemplatePartView[]): string;
|
|
1303
|
-
/** 相邻固定文本合并;rebuildFixed 以合并文本重建视图(含原始 part) */
|
|
1304
|
-
declare function mergeAdjacentFixedViews<P>(views: TemplatePartView<P>[], rebuildFixed: (text: string) => TemplatePartView<P>): TemplatePartView<P>[];
|
|
1305
|
-
/** 具体字符串是否匹配模板(Refinement.check 的判定语义) */
|
|
1306
|
-
declare function templateMatchesValue(value: string, views: TemplatePartView[]): boolean;
|
|
1307
|
-
/** 三值判定;Abs 方法表把 "unknown" 适配为 boolPrim */
|
|
1308
|
-
type TemplatePredicateDecision = boolean | "unknown";
|
|
1309
|
-
declare function decideStartsWith(prefix: string, search: string): TemplatePredicateDecision;
|
|
1310
|
-
declare function decideEndsWith(suffix: string, search: string): TemplatePredicateDecision;
|
|
1311
|
-
declare function decideIncludes(fixedText: string, search: string): TemplatePredicateDecision;
|
|
1312
|
-
declare function absTemplateViews(parts: Abs[]): TemplatePartView<Abs>[];
|
|
1313
|
-
/** 从 Abs 提取 template parts(已是 template 则展开,否则 [self]) */
|
|
1314
|
-
declare function templatePartsOf(a: Abs): Abs[];
|
|
1315
|
-
/**
|
|
1316
|
-
* 构造 template Abs。
|
|
1317
|
-
* - 全字面量 → exact lit
|
|
1318
|
-
* - 单 string prim → prim
|
|
1319
|
-
* - 否则 prim(string) + pred(name=template, meta.templateParts)
|
|
1320
|
-
*/
|
|
1321
|
-
declare function createTemplateAbs(parts: Abs[]): Abs;
|
|
1322
|
-
declare function isTemplateLike(a: Abs): boolean;
|
|
1323
|
-
/** 字符串拼接:字面量折叠 + template parts 合并 */
|
|
1324
|
-
declare function concatString(a: Abs, b: Abs): Abs;
|
|
1325
|
-
|
|
1326
|
-
/**
|
|
1327
|
-
* 语言覆盖:class / new / instanceof / this / async await。
|
|
1328
|
-
* brand 表示名义类;eff("promise") 表示异步效应。
|
|
1329
|
-
*
|
|
1330
|
-
* 方法体:ClassDef.methods 存 AST body,调用时在 this=receiver 下求值。
|
|
1331
|
-
*/
|
|
1332
|
-
|
|
1333
|
-
type MethodDef = {
|
|
1334
|
-
name: string;
|
|
1335
|
-
params: string[];
|
|
1336
|
-
body: Node;
|
|
1337
|
-
kind?: string;
|
|
1338
|
-
async?: boolean;
|
|
1339
|
-
};
|
|
1340
|
-
type ClassDef = {
|
|
1341
|
-
name: string;
|
|
1342
|
-
instanceShape: Abs;
|
|
1343
|
-
ctorParams: string[];
|
|
1344
|
-
methods: Map<string, MethodDef>;
|
|
1345
|
-
superClass?: string;
|
|
1346
|
-
};
|
|
1347
|
-
declare function defineClass(env: AstEnv, def: ClassDef): void;
|
|
1348
|
-
declare function getClass(env: AstEnv, name: string): ClassDef | undefined;
|
|
1349
|
-
/** 沿继承链找类 */
|
|
1350
|
-
declare function getClassChain(env: AstEnv, name: string): ClassDef[];
|
|
1351
|
-
/** new C(...) → brand 实例;并跑 constructor 以写入字段 */
|
|
1352
|
-
declare function instantiateClass(env: AstEnv, className: string, args: Abs[], evalBody?: (fn: {
|
|
1353
|
-
params: string[];
|
|
1354
|
-
body: Node;
|
|
1355
|
-
}, args: Abs[], thisVal: Abs, env: AstEnv) => Abs): Abs;
|
|
1356
|
-
/** 读取当前 this 所属类的父类名 */
|
|
1357
|
-
declare function superNameOf(env: AstEnv, className: string): string | undefined;
|
|
1358
|
-
/**
|
|
1359
|
-
* instanceof:沿继承链匹配 brand 名。
|
|
1360
|
-
*/
|
|
1361
|
-
declare function instanceOf(left: Abs, rightClassName: string, env?: AstEnv): Abs;
|
|
1362
|
-
declare function projectBrand(self: Abs, key: string): Abs;
|
|
1363
|
-
/** 在 brand 上查找方法定义(含继承) */
|
|
1364
|
-
declare function lookupMethod(env: AstEnv, receiver: Abs, methodName: string): MethodDef | undefined;
|
|
1365
|
-
/** 沿继承链查找方法,返回定义与所在类名 */
|
|
1366
|
-
declare function lookupMethodWithOwner(env: AstEnv, receiver: Abs, methodName: string): {
|
|
1367
|
-
def: MethodDef;
|
|
1368
|
-
owner: string;
|
|
1369
|
-
} | undefined;
|
|
1370
|
-
/** super.method():从父类开始找(跳过当前类) */
|
|
1371
|
-
declare function lookupSuperMethod(env: AstEnv, receiver: Abs, fromClass: string, methodName: string): {
|
|
1372
|
-
def: MethodDef;
|
|
1373
|
-
owner: string;
|
|
1374
|
-
} | undefined;
|
|
1375
|
-
declare function wrapPromise(inner: Abs): Abs;
|
|
1376
|
-
declare function awaitAbs(v: Abs): Abs;
|
|
1377
|
-
declare function coerceAsyncReturn(value: Abs): Abs;
|
|
1378
|
-
/** 从 ClassMethod 列表构造 methods map + instance shape */
|
|
1379
|
-
declare function classFromMethods(name: string, methods: MethodDef[], superClass?: string, superShape?: Abs): ClassDef;
|
|
1380
|
-
|
|
1381
|
-
declare function hashSource(s: string): string;
|
|
1382
|
-
declare function resetHashSourceCache(): void;
|
|
1383
|
-
|
|
1384
|
-
/**
|
|
1385
|
-
* Analysis-stable source key: strip trailing noise that cannot affect types.
|
|
1386
|
-
* Keeps every line that may carry @nudo directives.
|
|
1387
|
-
*
|
|
1388
|
-
* Fast path: already-stable sources return the same string identity (O(1)
|
|
1389
|
-
* compare in B-path / analysis caches when the caller reuses the buffer).
|
|
1390
|
-
*/
|
|
1391
|
-
declare function stableAnalyzeKeySource(source: string): string;
|
|
1392
|
-
|
|
1393
|
-
/**
|
|
1394
|
-
* per-function fingerprint: after-edit only dirty fn + callers miss L0.
|
|
1395
|
-
*
|
|
1396
|
-
* - own: function declaration slice (incl. leading comments / refine)
|
|
1397
|
-
* - deps: transitively referenced sibling own hashes + non-fn top-level context
|
|
1398
|
-
* - context change (import/class/const...) -> all miss (conservative)
|
|
1399
|
-
*
|
|
1400
|
-
* Multi-declarator `const a = fn, b = fn` yields one fingerprint per function;
|
|
1401
|
-
* each own-slice is its own declarator (first also carries statement leading comments).
|
|
1402
|
-
*/
|
|
1403
|
-
|
|
1404
|
-
type FnFp = {
|
|
1405
|
-
own: string;
|
|
1406
|
-
deps: string;
|
|
1407
|
-
nRefs: number;
|
|
1408
|
-
};
|
|
1409
|
-
declare function resetFnFpCache(): void;
|
|
1410
|
-
type FnDeclInfo = {
|
|
1411
|
-
name: string;
|
|
1412
|
-
body: Node;
|
|
1413
|
-
/** Function/arrow node (own-slice end; also scanned for sibling refs incl. defaults). */
|
|
1414
|
-
fnNode: Node;
|
|
1415
|
-
/** Declarator start when from a VariableDeclaration; else undefined. */
|
|
1416
|
-
declaratorStart?: number;
|
|
1417
|
-
/** First leading-comment start on this declarator (multi-decl refine/@nudo). */
|
|
1418
|
-
declaratorLeadStart?: number;
|
|
1419
|
-
};
|
|
1420
|
-
/** Every top-level function binding in a declaration node (not just the first). */
|
|
1421
|
-
declare function getFnNameAndBodies(decl: Node): FnDeclInfo[];
|
|
1422
|
-
/** source -> (fnName -> own/deps); LRU */
|
|
1423
|
-
declare function fnFingerprints(source: string, file: File): Map<string, FnFp>;
|
|
1424
|
-
/** L0 source part: per-fn fingerprint when AST available; else full-file hash */
|
|
1425
|
-
declare function generalizeSourceKeyPart(source: string, fnName: string, file?: File): string;
|
|
1046
|
+
declare function listFunctionNames(source: string): string[];
|
|
1426
1047
|
/**
|
|
1427
|
-
*
|
|
1428
|
-
*
|
|
1429
|
-
* 只认顶层 ExpressionStatement 会漏报约束违规。
|
|
1048
|
+
* 按 assume 集合构造实参:被 assume 的参数给带约束的符号,其余 any
|
|
1049
|
+
* (design-cli-semantics §2:入口无约束 = any,不是 unknown)。
|
|
1430
1050
|
*/
|
|
1431
|
-
declare function
|
|
1051
|
+
declare function buildArgsFromAssume(source: string, fnName: string, assumeIds: Set<string>): Abs[];
|
|
1432
1052
|
|
|
1433
1053
|
/**
|
|
1434
|
-
* check
|
|
1054
|
+
* 整文件 CheckReport memo(LSP/CI 重复 check → O(1))。
|
|
1435
1055
|
*
|
|
1436
|
-
*
|
|
1437
|
-
* -
|
|
1438
|
-
*
|
|
1056
|
+
* 从 check.ts 拆出的缓存基建:键指纹 / 依赖索引 / 定向逐出 / LRU。
|
|
1057
|
+
* check.ts 通过 re-export 保持 resetCheckSourceMemo /
|
|
1058
|
+
* evictCheckSourceMemoForPaths 对外形状不变。
|
|
1439
1059
|
*/
|
|
1440
1060
|
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
params: string[];
|
|
1445
|
-
/** 符号 Abs 本体 */
|
|
1446
|
-
abs: Abs;
|
|
1447
|
-
/** formatAbs 单行 */
|
|
1448
|
-
display: string;
|
|
1449
|
-
/** formatAbsMultiline */
|
|
1450
|
-
detail: string;
|
|
1451
|
-
conf: Confidence;
|
|
1452
|
-
};
|
|
1453
|
-
type CheckIssue = Diagnostic & {
|
|
1454
|
-
fn?: string;
|
|
1455
|
-
line?: number;
|
|
1456
|
-
column?: number;
|
|
1457
|
-
/** 实参 / 实际值的 Abs 展示 */
|
|
1458
|
-
actual?: string;
|
|
1459
|
-
/** 期望约束(Pred 或 Abs 展示) */
|
|
1460
|
-
expected?: string;
|
|
1461
|
-
};
|
|
1462
|
-
type CheckReport = {
|
|
1463
|
-
file: string;
|
|
1464
|
-
issues: CheckIssue[];
|
|
1465
|
-
/** 有 error 则 CI 应失败 */
|
|
1466
|
-
ok: boolean;
|
|
1467
|
-
/** Abs 优先的签名表(替代 TS 式 display-only) */
|
|
1468
|
-
signatures: NudoSig[];
|
|
1469
|
-
summary: {
|
|
1470
|
-
errors: number;
|
|
1471
|
-
warnings: number;
|
|
1472
|
-
infos: number;
|
|
1473
|
-
functions: number;
|
|
1474
|
-
};
|
|
1475
|
-
};
|
|
1476
|
-
/**
|
|
1477
|
-
* `nudo check --json` 稳定契约(供 CI / Agent)。
|
|
1478
|
-
* 字段只增不改语义;Abs 以 formatAbs 字符串给出,不序列化内部 shape 图。
|
|
1479
|
-
*/
|
|
1480
|
-
type CheckJson = {
|
|
1481
|
-
version: 1;
|
|
1482
|
-
file: string;
|
|
1483
|
-
ok: boolean;
|
|
1484
|
-
summary: CheckReport["summary"];
|
|
1485
|
-
signatures: Array<{
|
|
1486
|
-
name: string;
|
|
1487
|
-
params: string[];
|
|
1488
|
-
display: string;
|
|
1489
|
-
detail: string;
|
|
1490
|
-
conf: string;
|
|
1491
|
-
abs: string;
|
|
1492
|
-
}>;
|
|
1493
|
-
issues: Array<{
|
|
1494
|
-
severity: string;
|
|
1495
|
-
code: string;
|
|
1496
|
-
message: string;
|
|
1497
|
-
fn?: string;
|
|
1498
|
-
line?: number;
|
|
1499
|
-
column?: number;
|
|
1500
|
-
actual?: string;
|
|
1501
|
-
expected?: string;
|
|
1502
|
-
suggestion?: string;
|
|
1503
|
-
}>;
|
|
1504
|
-
};
|
|
1505
|
-
declare function serializeCheckJson(r: CheckReport): CheckJson;
|
|
1506
|
-
/**
|
|
1507
|
-
* Nudo 原生报告:Abs 签名表 + actual ⊭ expected。
|
|
1508
|
-
* 不是 tsc 输出的换皮。
|
|
1509
|
-
*/
|
|
1510
|
-
declare function formatCheckReport(r: CheckReport, opts?: {
|
|
1511
|
-
verbose?: boolean;
|
|
1512
|
-
}): string;
|
|
1061
|
+
declare function resetCheckSourceMemo(): void;
|
|
1062
|
+
/** `*.nudo.js` 变更后定向逐出依赖它的整文件 check 缓存 */
|
|
1063
|
+
declare function evictCheckSourceMemoForPaths(paths: string[]): number;
|
|
1513
1064
|
|
|
1514
1065
|
/**
|
|
1515
1066
|
* nudo check 门禁:对源码跑代数分析,产出 error/warning。
|
|
1516
1067
|
*
|
|
1517
1068
|
* 报告是 **Nudo 原生格式**(Abs 优先),不是 TS 诊断的换皮:
|
|
1518
|
-
* - 签名表给出无损 Abs(shape/term/pred/conf
|
|
1519
|
-
* -
|
|
1520
|
-
* -
|
|
1069
|
+
* - 签名表给出无损 Abs(shape/term/pred/conf)+ throws 域
|
|
1070
|
+
* - L1:显式契约 / 调用点证据违例
|
|
1071
|
+
* - L2:export/default/CJS 入口未消化 may-throw → nudo:entry-may-throw
|
|
1072
|
+
* - 违例写清 actual ⊭ expected;成功也打印 signatures
|
|
1521
1073
|
*/
|
|
1522
1074
|
|
|
1523
|
-
declare function resetCheckSourceMemo(): void;
|
|
1524
|
-
/** `*.nudo.js` 变更后定向逐出依赖它的整文件 check 缓存 */
|
|
1525
|
-
declare function evictCheckSourceMemoForPaths(paths: string[]): number;
|
|
1526
1075
|
/**
|
|
1527
1076
|
* check 选项:core 不碰 fs;host 用 loadModule 喂 require 目标源码。
|
|
1528
1077
|
*/
|
|
@@ -1532,11 +1081,40 @@ type CheckOptions = {
|
|
|
1532
1081
|
/** 当前文件路径(供 loadModule 解析相对 spec) */
|
|
1533
1082
|
fromFile?: string;
|
|
1534
1083
|
/**
|
|
1535
|
-
* 侧车 ambient 绑定开关(host 从 package.json#nudo.
|
|
1084
|
+
* 侧车 ambient 绑定开关(host 从 package.json#nudo.contract.autoBind
|
|
1536
1085
|
* 解析后下传;默认 true)。false = check/LSP 执法路径不自动加载侧车
|
|
1537
1086
|
* (§2.2「整体关闭」承诺覆盖 CI 门禁,不只是打印路径)。
|
|
1538
1087
|
*/
|
|
1539
1088
|
autoBind?: boolean;
|
|
1089
|
+
/**
|
|
1090
|
+
* 项目根(host 从 findProjectConfig 下传):树外侧车不 ambient 绑定。
|
|
1091
|
+
* undefined = 不限(node_modules 仍拦)。
|
|
1092
|
+
*/
|
|
1093
|
+
projectDir?: string;
|
|
1094
|
+
/**
|
|
1095
|
+
* L2 入口 may-throw 执法档(design-cli-semantics §3)。
|
|
1096
|
+
* error(默认)| warning | off。仅作用于 export/default/CJS 入口函数。
|
|
1097
|
+
*/
|
|
1098
|
+
entryThrows?: "error" | "warning" | "off";
|
|
1099
|
+
/** L2 --ignore-throws:按 throws 类型名过滤;不吞 L1 */
|
|
1100
|
+
ignoreThrows?: string[];
|
|
1101
|
+
/** 宿主已求值的依赖导出表(specifier → AbsModuleExports);
|
|
1102
|
+
* B 与解释路径共用——import/require 按表解析(CLI 经
|
|
1103
|
+
* evalAbsModuleGraph 计算后下传) */
|
|
1104
|
+
modules?: Record<string, AbsModuleExports | Record<string, unknown>>;
|
|
1105
|
+
/**
|
|
1106
|
+
* B run 注入包(modules/mocks/envGlobals/replacements/as)——透传
|
|
1107
|
+
* runTranspiled(generalize / L2 / 记录通道 / drift 同源)。memo 键按
|
|
1108
|
+
* 内容指纹(非对象身份)。
|
|
1109
|
+
*/
|
|
1110
|
+
inject?: RunTranspiledOptions;
|
|
1111
|
+
/**
|
|
1112
|
+
* `@nudo:skip [returnsExpr]`(host 用 parser 解析后下传):函数名 → 声明的
|
|
1113
|
+
* 返回 Abs(null = 未声明)。命中函数不评估 body:签名按声明返回上屏
|
|
1114
|
+
* (无声明 → any,不产生 unknown-inference 噪音);返回契约仍按声明执法;
|
|
1115
|
+
* 入口 may-throw(L2)不评估。调用点参数义务(scan)不受影响。
|
|
1116
|
+
*/
|
|
1117
|
+
skips?: ReadonlyMap<string, Abs | null>;
|
|
1540
1118
|
};
|
|
1541
1119
|
/**
|
|
1542
1120
|
* 检查一个文件:
|
|
@@ -1568,52 +1146,6 @@ declare function checkSource(filePath: string, source: string, phi?: Phi, opts?:
|
|
|
1568
1146
|
/** 字面量 lv 是否落在约束 c 表达的域内(保守:判不了 → false)。 */
|
|
1569
1147
|
declare function literalMeetsConstraint(lv: number | string | boolean | null, c: NudoConstraint): boolean;
|
|
1570
1148
|
|
|
1571
|
-
/**
|
|
1572
|
-
* Abs inlay hint:把无损约束内联到源码位置。
|
|
1573
|
-
* 不是 TS 风格 type annotation 复读,而是 term/pred/conf 的计算结果。
|
|
1574
|
-
*
|
|
1575
|
-
* 参数侧只展示显式 `@nudo:refine` 契约(entryReqs)——
|
|
1576
|
-
* 不从函数体 `if` 反推前置条件(那是控制流,不是对外契约)。
|
|
1577
|
-
*
|
|
1578
|
-
* A7(design-refine-derivation §8):default 走 symbolic + entryReqs;
|
|
1579
|
-
* 与 CodeLens `● interface` 同源——interfaceTierOf 标注来源;
|
|
1580
|
-
* implicit 导出的返回 inlay 标明 `derived`(展示档,非义务契约)。
|
|
1581
|
-
*/
|
|
1582
|
-
|
|
1583
|
-
type AbsInlay = {
|
|
1584
|
-
/** 1-based 行号 */
|
|
1585
|
-
line: number;
|
|
1586
|
-
/** 0-based 列(label 插入点) */
|
|
1587
|
-
character: number;
|
|
1588
|
-
label: string;
|
|
1589
|
-
kind: "type" | "parameter";
|
|
1590
|
-
/** interface 档来源(与 CodeLens `● interface` 同源);非导出缺省 */
|
|
1591
|
-
interfaceSource?: InterfaceSource;
|
|
1592
|
-
/** true = 隐式推导展示(非义务契约),label 已带 `· derived` */
|
|
1593
|
-
derived?: boolean;
|
|
1594
|
-
};
|
|
1595
|
-
type CollectAbsInlaysOpts = InterfaceTierOpts & {
|
|
1596
|
-
loadModule?: (spec: string, fromFile: string) => string | undefined;
|
|
1597
|
-
fromFile?: string;
|
|
1598
|
-
};
|
|
1599
|
-
/**
|
|
1600
|
-
* 收集源码中函数签名的 Abs inlay:
|
|
1601
|
-
* - 参数后:仅 `@nudo:refine` / 侧车显式契约(entryReqs)
|
|
1602
|
-
* - `{` 前:返回计算形(`x | x * 2`),无 term 时退回 shape
|
|
1603
|
-
* - interface 档:导出函数带 `interfaceSource`;implicit 返回标 `derived`
|
|
1604
|
-
*/
|
|
1605
|
-
declare function collectAbsInlays(source: string, opts?: CollectAbsInlaysOpts): AbsInlay[];
|
|
1606
|
-
|
|
1607
|
-
/**
|
|
1608
|
-
* 指称:Abs → 运行时谓词(设计 §2.7)。
|
|
1609
|
-
* - 无 pred:按 shape 检查(typeof / 结构)
|
|
1610
|
-
* - 有 pred:在 `term ↦ v` 下检查可判定的数值比较
|
|
1611
|
-
* - sum:任一成员
|
|
1612
|
-
*/
|
|
1613
|
-
|
|
1614
|
-
/** Abs 上的运行时守卫表达式(JS boolean 布尔串) */
|
|
1615
|
-
declare function denoteGuard(a: Abs, v: string): string;
|
|
1616
|
-
|
|
1617
1149
|
/**
|
|
1618
1150
|
* Abs → NudoConstraint 投影(Phase 1,interface 分层推导的生成侧半边)。
|
|
1619
1151
|
*
|
|
@@ -1652,149 +1184,4 @@ declare function absToConstraint(a: Abs): NudoConstraint | undefined;
|
|
|
1652
1184
|
*/
|
|
1653
1185
|
declare function joinThenProject(absList: Abs[]): NudoConstraint | undefined;
|
|
1654
1186
|
|
|
1655
|
-
|
|
1656
|
-
* 推导图(derivation trace)side-channel(design-refine-derivation §14.3#6 / §11 Phase 2)。
|
|
1657
|
-
*
|
|
1658
|
-
* 不叫 provenance:`setProvenanceTracking` 已被 evaluator 的 TypeValue origin map
|
|
1659
|
-
* 占用。机制对齐 `setCallCollector` / `setAbsTruncationCollector` 先例——
|
|
1660
|
-
* **不进 Abs payload**;ast-eval 与 B-path 共用 core ops(`add` / `joinAbs`),
|
|
1661
|
-
* 两条路径天然都覆盖。
|
|
1662
|
-
*
|
|
1663
|
-
* 设计原则:emit 打印的是推导图的投影,**禁止**事后从最终 Abs 反编译 shift 链。
|
|
1664
|
-
* 本模块在 ops 层打点:数值常量加法 → shift 边;joinAbs → join 边。
|
|
1665
|
-
* 根约束(手写契约参数)由宿主在入口 Abs 上打 root 标签。
|
|
1666
|
-
*/
|
|
1667
|
-
|
|
1668
|
-
/** 推导节点:边带调用位点 / +k / join;root 携带可打印的约束源表达式 */
|
|
1669
|
-
type DerivationNode = {
|
|
1670
|
-
id: number;
|
|
1671
|
-
kind: "root" | "shift" | "join" | "opaque";
|
|
1672
|
-
/** root:宿主给的可读约束表达式(`positive` / `number().gt(0)`) */
|
|
1673
|
-
expr?: string;
|
|
1674
|
-
/** root:跨文件 import 源(相对 specifier,相对 root 侧车目录) */
|
|
1675
|
-
importFrom?: string;
|
|
1676
|
-
/** root:import 绑定名(与 expr 一致时省略) */
|
|
1677
|
-
importName?: string;
|
|
1678
|
-
/** shift:数值偏移 */
|
|
1679
|
-
offset?: number;
|
|
1680
|
-
/** 父节点 id(root 无父) */
|
|
1681
|
-
parents: number[];
|
|
1682
|
-
};
|
|
1683
|
-
/** 调用位点上的实参推导(供 emit 投影组合式) */
|
|
1684
|
-
type ArgDerivation = {
|
|
1685
|
-
node: DerivationNode;
|
|
1686
|
-
/** 从该节点回溯到 root 的路径(含自身,root 在末尾) */
|
|
1687
|
-
chain: DerivationNode[];
|
|
1688
|
-
};
|
|
1689
|
-
type Collector = (node: DerivationNode) => void;
|
|
1690
|
-
/** 设置观察者(null 清除);缓冲照常累积 */
|
|
1691
|
-
declare function setDerivationCollector(fn: Collector | null): void;
|
|
1692
|
-
declare function hasDerivationSession(): boolean;
|
|
1693
|
-
/** 开始一次推导会话(root 驱动下行求值前调用);与 end/abort 成对 */
|
|
1694
|
-
declare function beginDerivationSession(): void;
|
|
1695
|
-
/** 结束会话并取走全部节点(顺序 = 创建序) */
|
|
1696
|
-
declare function endDerivationSession(): DerivationNode[];
|
|
1697
|
-
/** 丢弃当前会话(求值失败时) */
|
|
1698
|
-
declare function abortDerivationSession(): void;
|
|
1699
|
-
/**
|
|
1700
|
-
* 在入口 Abs 上打 root 标签:该值来自手写契约参数约束。
|
|
1701
|
-
* expr 是可打印源(`positive`);importFrom 指向共享模板侧车。
|
|
1702
|
-
*/
|
|
1703
|
-
declare function tagDerivationRoot(abs: Abs, meta: {
|
|
1704
|
-
expr: string;
|
|
1705
|
-
importFrom?: string;
|
|
1706
|
-
importName?: string;
|
|
1707
|
-
}): DerivationNode;
|
|
1708
|
-
/** 读取 Abs 上的推导节点(无标签 → undefined) */
|
|
1709
|
-
declare function getDerivation(abs: Abs): DerivationNode | undefined;
|
|
1710
|
-
/** 手动把推导挂到结果 Abs(宿主在 analyzeFn 返回值上补标签时用) */
|
|
1711
|
-
declare function setDerivation(abs: Abs, node: DerivationNode): void;
|
|
1712
|
-
/** 从节点回溯 root 路径(含自身;环/缺失截断) */
|
|
1713
|
-
declare function derivationChain(node: DerivationNode): DerivationNode[];
|
|
1714
|
-
/**
|
|
1715
|
-
* ops 层打点:`a + k`(k 为有限数值字面量)且 a 带推导 → 结果挂 shift 节点。
|
|
1716
|
-
* 由 arithmetic.add 在返回前调用;无会话/无父标签时 no-op。
|
|
1717
|
-
*/
|
|
1718
|
-
declare function noteDerivationAdd(a: Abs, b: Abs, result: Abs): void;
|
|
1719
|
-
/**
|
|
1720
|
-
* ops 层打点:join 结果挂 join 节点(任一侧有推导即可)。
|
|
1721
|
-
* 工件聚合路径会经 join;check 分轨不依赖 join 节点。
|
|
1722
|
-
*/
|
|
1723
|
-
declare function noteDerivationJoin(inputs: Abs[], result: Abs): void;
|
|
1724
|
-
/**
|
|
1725
|
-
* 把推导链投影为组合式(§2.4:写组合式,不展开)。
|
|
1726
|
-
*
|
|
1727
|
-
* 返回 prelude(`const x = positive.shift(1);`)+ expr(`x` / `x.shift(2)`)
|
|
1728
|
-
* + 需要的 import。无 root 锚或链上出现 join/opaque → undefined(调用方
|
|
1729
|
-
* 退回展开式投影或 not-projectable)。
|
|
1730
|
-
*/
|
|
1731
|
-
declare function projectDerivationDsl(node: DerivationNode, localName: string): {
|
|
1732
|
-
prelude: string[];
|
|
1733
|
-
expr: string;
|
|
1734
|
-
imports: Array<{
|
|
1735
|
-
name: string;
|
|
1736
|
-
from: string;
|
|
1737
|
-
}>;
|
|
1738
|
-
} | undefined;
|
|
1739
|
-
/** 项结构调试用(测试断言) */
|
|
1740
|
-
declare function termKey(t: Term | undefined): string;
|
|
1741
|
-
|
|
1742
|
-
/**
|
|
1743
|
-
* 源码级调用图侦察:从 check 门禁拆出的 AST 扫描层。
|
|
1744
|
-
*
|
|
1745
|
-
* 职责:不做代数求值结论,只回答「谁在调用谁、实参长什么样」——
|
|
1746
|
-
* - listTopFunctions:顶层函数清单
|
|
1747
|
-
* - collectCallResolvers / resolveCalleeFn / collectForwarders:别名 / 对象属性 /
|
|
1748
|
-
* require / 动态 import / 无条件转发 的调用解析
|
|
1749
|
-
* - scanLiteralCalls:字面量调用点实参 vs 前置约束的违例收集
|
|
1750
|
-
*/
|
|
1751
|
-
|
|
1752
|
-
/**
|
|
1753
|
-
* 注入记录的最小结构面。Abs 为唯一真理源。
|
|
1754
|
-
*/
|
|
1755
|
-
type InjectedDomainRecord = {
|
|
1756
|
-
/** 无损参数 Abs(必填;domain 证据唯一来源) */
|
|
1757
|
-
argAbs?: Abs[];
|
|
1758
|
-
resultAbs?: Abs;
|
|
1759
|
-
throwsAbs?: Abs;
|
|
1760
|
-
};
|
|
1761
|
-
type InjectedDomainEvidenceOpts = {
|
|
1762
|
-
/** 被调函数形参名(位置序);契约按参数名对齐证据位 */
|
|
1763
|
-
paramNames: string[];
|
|
1764
|
-
loadModule?: (spec: string, fromFile: string) => string | undefined;
|
|
1765
|
-
fromFile?: string;
|
|
1766
|
-
/** 侧车 ambient 绑定开关(host 配置下传;默认 true) */
|
|
1767
|
-
autoBind?: boolean;
|
|
1768
|
-
/** 报告定位:被调函数声明处。注入证据的 loc 在使用现场文件,不属于本文件 */
|
|
1769
|
-
loc?: {
|
|
1770
|
-
line: number;
|
|
1771
|
-
column: number;
|
|
1772
|
-
};
|
|
1773
|
-
};
|
|
1774
|
-
/**
|
|
1775
|
-
* 跨文件注入的调用点域证据 vs 手写契约(设计稿 §3.3/§6 对账矩阵第一行)。
|
|
1776
|
-
*
|
|
1777
|
-
* 来源分流铁律:写在被分析文件里的调用点违例(含 scanLiteralCalls 的
|
|
1778
|
-
* checkExternalCall 跨文件被调路径)维持 `nudo:constraint-violated` 原码
|
|
1779
|
-
* 原语义——本函数**只**消费经 externalCallRecords 注入的跨文件记录(analyzer
|
|
1780
|
-
* 消费区已做归属守卫),该路径此前不查契约,是纯增量。
|
|
1781
|
-
*
|
|
1782
|
-
* 证据门槛(§6):
|
|
1783
|
-
* - 只有 plain literal 实参构成证据:union/unknown/primitive/refined 形态
|
|
1784
|
-
* 无法归因到确定值,不参与。Abs 路径直接读 `litValue` + conf
|
|
1785
|
-
* ∈ {exact, path}。
|
|
1786
|
-
* - null 证据预过滤(T4 caveat:lit(null) 编码 prim undefined + eq(self,
|
|
1787
|
-
* null),对任何约束恒不满足,不过滤必 FP);undefined/bigint/symbol
|
|
1788
|
-
* 不在字面量证据域内,一并跳过;
|
|
1789
|
-
* - resultType=never ∧ throws=never 是求值中断泄漏(analyzer 注入消费区
|
|
1790
|
-
* 同款过滤;有 resultAbs/throwsAbs 时同口径)。CallRecord 上没有截断字段
|
|
1791
|
-
* (查证于 evaluator.ts CallRecord 声明)——递归截断走
|
|
1792
|
-
* nudo:recursion-truncated 诊断通道且只 widen 结果,不产生新字面量证据;
|
|
1793
|
-
* - fn/shape/array 参数位 Phase 1 不执法(§3.3 HOF 豁免:
|
|
1794
|
-
* literalMeetsConstraint 对这些形态恒 false,直接查必 FP)。
|
|
1795
|
-
*
|
|
1796
|
-
* 每函数每参数位最多一条 issue(多证据并列在 actual 里,去重)。
|
|
1797
|
-
*/
|
|
1798
|
-
declare function checkInjectedDomainEvidence(fnName: string, source: string, records: InjectedDomainRecord[], opts: InjectedDomainEvidenceOpts): CheckIssue[];
|
|
1799
|
-
|
|
1800
|
-
export { Abs, type AbsAssignRecord, type AbsCallRecord, type AbsFnImpl, type AbsInlay, AbsModuleExports, type AbsSigImpl, type ArgDerivation, AstEnv, type CheckIssue, type CheckJson, type CheckOptions, type CheckReport, type ClassDef, type CollectAbsInlaysOpts, Confidence, type ConstraintBuilder, type DerivationNode, type Diagnostic, type EffectiveInterface, type EffectiveInterfaceOpts, type Environment, type EvalOptions, type EvalResult, type FnAbs, type FnFp, type FormalParam, type FormatOptions, HofSite, type InjectedDomainRecord, type InterfaceDiag, type InterfaceSource, type InterfaceTierInfo, type InterfaceTierOpts, type LeakBudget, type LeqResult, type LoadDepsFingerprint, MAX_CALL_DEPTH, MAX_TOTAL_CALLS, type MethodDef, type MockHelper, type NamedImport, type NudoConstraint, type NudoField, type NudoFnConstraint, NudoSidecarError, type NudoSig, type ObjShape, Phi, type PolyFn, Pred, PrimName, type RefineDiag, type RefineEntry, type RefineResolveOpts, RelSource, SELF, Shape, type Slot, type TemplateMeta, type TemplatePartDesc, type TemplatePartView, type TemplatePredicateDecision, Term, type TypeParam, abortDerivationSession, absFunction, absShapeKey, absTemplateViews, absToConstraint, add, allFixedTextOfViews, analyzeFn, analyzeFnFull, any, applyAbsFn, array, attachFnImpl, awaitAbs, beginCollectionFork, beginDerivationSession, boolean, buildArgsFromAssume, callAbsMethod, callFunction, callFunctionFull, canSkipLiteralCallScan, checkArg, checkCall, checkInjectedDomainEvidence, checkSource, classFromMethods, clearCollectionTables, cmp, coerceAsyncReturn, collectAbsFreeVars, collectAbsInlays, collectAbsNodeTypes, collectionElementJoin, collectionExactLen, concatString, constraintToEntryAbs, contractParamNameSet, createEnvironment, createTemplateAbs, currentPhi, decideEndsWith, decideIncludes, decideStartsWith, defaultLeakBudget, defineClass, definitelyNotNullishShape, denoteGuard, derivationChain, describePhi, div, effectiveInterface, emptyEnv, endCollectionFork, endDerivationSession, errorBrandAbs, evalArrayStatic, evalBuiltinInstanceMethod, evalBuiltinNew, evalDateCtor, evalDateMethod, evalDateStatic, evalGlobalFn, evalJsonMethod, evalMathMethod, evalMethodBody, evalNamespaceCall, evalNode, evalNumberStatic, evalObjectMethod, evalProgramAbs, evalPromiseCtor, evalPromiseStatic, evalRegExpCtor, evalRegExpMethod, evalSource, evictCheckSourceMemoForPaths, evictGeneralizeMemoForPaths, exceedsBudget, execNudoModule, extractAllLoadSpecs, extractFn, extractNudoImports, extractRefineReturnFromSource, extractRefinesFromSource, falseConstraint, findAbsAtPosition, fixedLengthOfViews, fn, fnConstraintToEntryReqs, fnFingerprints, fnOf, formalParamDisplayNames, formalParamsFromNodes, formatAbs, formatAbsMultiline, formatCheckReport, formatConstraint, formatDiagnostics, formatEffectiveInterfaceDisplay, formatInterfaceTierLine, formatShape, formatShapeSlot, formatTemplateNameViews, generalizeAll, generalizeFromAst, generalizeSourceKeyPart, generatedExportNames, getAbsProperty, getClass, getClassChain, getDerivation, getFnImpl, getFnNameAndBodies, getGeneralizeMemoSize, getParseSourceCacheSize, getSlot, getTerm, hasDerivationSession, hashSource, instanceOf, instantiateClass, instantiateConstraint, interfaceDiagCount, interfaceSourceOf, interfaceTierOf, isErrorCtorName, isIntFlag, isMapAbs, isNodeModulesPath, isNudoConstraint, isNullishLitAbs, isObj, isSetAbs, isTemplateLike, joinAbs, joinFunctions, joinObjects, joinThenProject, joinValues, knownPrefixOfViews, knownSuffixOfViews, leakIfNeeded, lenTerm, leqAbs, listFunctionNames, literalMeetsConstraint, loadModuleDepsFingerprint, localNamedExports, locateContractParam, lookupMethod, lookupMethodWithOwner, lookupSuperMethod, looseEqAbs, makeMapAbs, makeSetAbs, makeSum, mapClearEntries, mapDeleteEntry, mapEntriesAbs, mapGetEntry, mapHasEntry, mapSetEntry, mapSizeAbs, mapValuesAbs, matchRelIdentLit, maybeLeak, mergeAdjacentFixedViews, mergeCollectionArms, mock, mod, mul, negAbs, normPath, notAbs, noteCollectionWrite, noteDerivationAdd, noteDerivationJoin, number, objOf, omit, parseSource, partial, pick, popCollectionArm, popPhi, projectBrand, projectDerivationDsl, pushCollectionArm, pushPhi, refineAbsForRelTrue, refineDiagCount, refineToIndexedFull, relationFingerprint, relationFn, requiredFnArity, resetAbsCallBudget, resetCheckSourceMemo, resetFnFpCache, resetGeneralizeMemo, resetHashSourceCache, resetLeakCounter, resetNudoModuleExecCache, resetParseSourceCache, resetPhi, resolveDepPath, serializeCheckJson, setAbsAssignCollector, setAbsCallCollector, setAbsNodeCollector, setAbsTruncationCollector, setAddEntry, setClearEntries, setDeleteEntry, setDerivation, setDerivationCollector, setElementsAbs, setHasEntry, setInterfaceDiagCollector, setRefineDiagCollector, setSizeAbs, shape, shapeOnlyFn, sidecarClosureFingerprint, sidecarPathOf, sidecarSpecsOf, spread, spy, stableAnalyzeKeySource, strictEqAbs, string, stripTypes, stub, sub, superNameOf, tagDerivationRoot, takeInterfaceDiags, takeInterfaceDiagsSince, takeRefineDiags, takeRefineDiagsSince, templateMatchesValue, templatePartsOf, termDepth, termKey, termNodes, trueConstraint, typeofAbs, union, viewTemplateParts, withPhiConstraint, withVar, wrapPromise };
|
|
1187
|
+
export { Abs, type AbsAssignRecord, type AbsCallRecord, type AbsFnImpl, AbsModuleExports, type AbsSigImpl, AstEnv, type CheckOptions, CheckReport, Confidence, EffectiveInterfaceOpts, type Environment, type ExtState, type FnAbs, type FormalParam, type FormatOptions, HofCollectCtx, HofSite, type LeqResult, type MockHelper, NudoConstraint, OBJECT_PROTO_METHOD_NAMES, type ObjShape, Phi, type PolyFn, Pred, type PropFlags, RelSource, RunTranspiledOptions, Shape, type Slot, Term, type TypeParam, absFunction, absShapeKey, absToConstraint, add, alphaOf, applyCallbackAbs, applyCallbackValue, asAbs, assignSourceSlots, attachFnImpl, beginCollectionFork, betaOf, bitandAbs, bitnotAbs, bitorAbs, bitxorAbs, buildArgsFromAssume, builtinCtorAbs, builtinCtorNameOf, callAbsMethod, canonicalArrayIndex, checkSource, clearCollectionTables, cmp, collectAbsFreeVars, collectionElementJoin, collectionExactLen, contractParamNameSet, createEnvironment, createHofCollectCtx, ctorArgDefinitelyInvalid, ctorNameOfRecv, currentPhi, definitelyNotNullishShape, describePhi, div, drainPromiseMicros, emptyEnv, endCollectionFork, enterPromiseExecutorScope, errorBrandAbs, evalArrayStatic, evalBuiltinInstanceMethod, evalBuiltinNew, evalDateCtor, evalDateMethod, evalDateStatic, evalGlobalFn, evalJsonMethod, evalMathMethod, evalNamespaceCall, evalNumberStatic, evalObjectMethod, evalObjectProtoMethod, evalPromiseCtor, evalPromiseMethod, evalPromiseStatic, evalRegExpCtor, evalRegExpMethod, evalStringStatic, evalSymbolCtor, evictCheckSourceMemoForPaths, evictGeneralizeMemoForPaths, extStateOf, extractFn, falseConstraint, fnOf, formalParamDisplayNames, formalParamsFromNodes, formatAbs, formatAbsMultiline, formatShape, formatShapeSlot, generalizeAll, generalizeFromAst, getAbsProperty, getFnImpl, getGeneralizeMemoSize, getPropFlags, getSlot, hostBuiltinCtorName, instantiateReturn, isErrorCtorName, isMapAbs, isNullProtoObj, isNullishLitAbs, isObj, isObjectProtoBrand, isRelFn, isSetAbs, isSymbolAbs, joinAbs, joinFunctions, joinObjects, joinThenProject, joinValues, leavePromiseExecutorScope, leqAbs, listFunctionNames, literalMeetsConstraint, locateContractParam, looseEqAbs, makeArrayCtorAbs, makeMapAbs, makeSetAbs, makeSum, makeSymbolAbs, mapClearEntries, mapDeleteEntry, mapElementFallback, mapEntriesAbs, mapGetEntry, mapHasEntry, mapSetEntry, mapSizeAbs, mapValuesAbs, markExtState, markNullProtoObj, markPureFn, matchRelIdentLit, mergeCollectionArms, migrateInvariants, migrateNullProto, mock, mod, mul, negAbs, notAbs, noteCollectionWrite, notePromiseExecutorFork, objOf, objectProtoBrand, objectProtoMethodAbs, parseSource, popCollectionArm, popPhi, powAbs, projectFlatMapResult, promoteParamShape, protoBrandAbs, protoOfRecv, pureFnNameOf, pushCollectionArm, pushPhi, queuePromiseMicro, refineAbsForRelTrue, regexBrandAbsFrom, relationFingerprint, relationFn, requiredFnArity, resetCheckSourceMemo, resetGeneralizeMemo, resetPhi, setAddEntry, setApplyCallbackHost, setClearEntries, setDeleteEntry, setElementsAbs, setHasEntry, setPropFlags, setSizeAbs, shapeOnlyFn, shlAbs, shrAbs, snapshotAbs, spread, spy, strictEqAbs, stringOfSymbol, stripTypes, stub, sub, substAbs, substPredAbs, symbolDescriptionAbs, symbolIdOf, toNumberAbs, trueConstraint, tryMakeRegexAbs, tryPromoteDirectCall, tryPromoteForOfIteratee, tryPromoteHofCallback, tryPromoteReceiverAsArr, typeofAbs, undefAbs, ushrAbs, withPhiConstraint, withVar };
|