@nudojs/core 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,7 +2,7 @@ import * as _babel_types from '@babel/types';
2
2
  import { Node, ImportDeclaration, File } from '@babel/types';
3
3
 
4
4
  /** 项(Term):抽象值的身份。字面量是项的特例。 */
5
- type LiteralValue = string | number | boolean | null | undefined;
5
+ type LiteralValue = string | number | boolean | bigint | null | undefined;
6
6
  type Term = {
7
7
  op: "lit";
8
8
  value: LiteralValue;
@@ -247,7 +247,17 @@ declare function isStrPrim(a: Abs): boolean;
247
247
  declare function isBigPrim(a: Abs): boolean;
248
248
  /** 置信度:字面量全确定 */
249
249
  declare function isExactLit(a: Abs): boolean;
250
- declare function litValue(a: Abs): LiteralValue | undefined;
250
+ /**
251
+ * tagged result:把「无字面量」与「字面量 undefined」分开。
252
+ * 判定是否是字面量必须看 `ok`,禁止用 `value !== undefined` / `(litValue(...).ok ? litValue(...).value : undefined) !== undefined`。
253
+ */
254
+ type LitValueResult = {
255
+ ok: true;
256
+ value: LiteralValue;
257
+ } | {
258
+ ok: false;
259
+ };
260
+ declare function litValue(a: Abs): LitValueResult;
251
261
 
252
262
  /**
253
263
  * may-throw 效果收集(design-cli-semantics §3.3)。
@@ -321,6 +331,27 @@ declare function filterIgnoredThrows(effects: MayThrowEffect[], ignore: readonly
321
331
  */
322
332
  declare function filterDeclaredThrows(effects: MayThrowEffect[], declared: readonly string[] | "*" | undefined): MayThrowEffect[];
323
333
 
334
+ /**
335
+ * 调用 Abs 一等函数(absFunction impl)或 mock apply。
336
+ * 供 求值引擎 import 绑定包装:`(...args) => $call(absFn, args)`。
337
+ *
338
+ * 统一顺序:apply → body → relation → isRelFn(委托 applyAbsFn)。
339
+ * 行为对齐说明(与旧 $call 的差异,均属刻意):
340
+ * 1. 带 body 的函数也进 call-budget(递归会 truncated 而非爆栈)
341
+ * 2. body 抛错与 apply 同径 rethrow(不吞成 never 返回,调用边界决定吸收)
342
+ * 3. 无 impl 时 isRelFn 可走 E 路径(旧版恒 unknown)
343
+ */
344
+
345
+ /** 清空 pure memo(宿主入口 / 会话缓存失效) */
346
+ declare function clearPureMemo(): void;
347
+ /**
348
+ * apply 返回的 throws 面 → 调用方控制流通道(H1 单点路由)。
349
+ * always-throw(abs=never)→ NudoThrow,由调用边界收成 throws;
350
+ * may-throw → pushThrowExit 记入调用方 throwExits(try/catch 可吸收)。
351
+ */
352
+ declare function routeApplyThrows(r: Abs, throws: Abs | undefined): Abs;
353
+ declare function $call(fn: Abs, args: Abs[], thisVal?: Abs): Abs;
354
+
324
355
  /**
325
356
  * 求值引擎调用点记录:transpile 把 `f(args)` 改成 $callNamed,
326
357
  * 分析时可收集 call@ 所需的 AbsCallRecord。
@@ -337,6 +368,8 @@ type EvalCallRecord = {
337
368
  };
338
369
  threw?: boolean;
339
370
  };
371
+ /** 清空 pureCallMemo(宿主入口 / 会话缓存失效) */
372
+ declare function clearPureCallMemo(): void;
340
373
  /** B 赋值记录(与 ast-records.ts AbsAssignRecord 同形;structuralAssignIssues 消费) */
341
374
  type EvalAbsAssignRecord = {
342
375
  name: string;
@@ -463,6 +496,147 @@ type AstEnv = {
463
496
  hofCollect?: HofCollectCtx;
464
497
  };
465
498
 
499
+ /**
500
+ * Abs 上的一等函数:shape 是 fn,实现在旁路(不污染 Shape)。
501
+ * 与 term-registry 同一纪律:不给共享单例挂 impl。
502
+ */
503
+
504
+ /** Abs 原生 env/builtin 实现(evaluator 优先) */
505
+ type AbsSigImpl = (args: Abs[], thisVal?: Abs) => Abs | undefined;
506
+ /**
507
+ * 已知不抛的 apply 返回面(裸 Abs,无 throws 通道)。
508
+ * 等价 `Abs`,仅作意图标注:impl 作者写死「本 apply 不抛」时用它收窄签名,
509
+ * 调用侧仍应经 `absOnly` / `isAbsApplyResult` 取 abs(`AbsFnImpl.apply` 静态面是宽的)。
510
+ */
511
+ type AbsApplyNoThrow = Abs;
512
+ /**
513
+ * 已知不抛的 apply 实现签名(`AbsSigImpl` 的 apply 对偶)。
514
+ * 返回裸 `Abs` = 不抛;需要 throws 面时改用 `AbsFnImpl["apply"]`(`AbsApplyReturn`)。
515
+ */
516
+ type AbsApplyNoThrowFn = (args: Abs[], thisVal?: Abs) => AbsApplyNoThrow;
517
+ /**
518
+ * apply 契约返回的 throws 通道(H1 / DESIGN-003)。
519
+ * `throws` 必填:不抛传 `never`。$call 统一路由——
520
+ * always-throw(abs=never)→ NudoThrow 由调用边界收成 throws;
521
+ * may-throw → pushThrowExit 记入调用方 throwExits(try/catch 可吸收)。
522
+ * 包装 `callTranspiledExportFull` 必须走 `callTranspiledExportApply`,
523
+ * 不得手拆 `.result`(会静默丢 throws 面)。
524
+ *
525
+ * 构造只经 `makeAbsApplyResult`(打上 brand);`isAbsApplyResult` 只认 brand,
526
+ * 避免裸对象靠 `!shape` 误判成 apply 结果、吞掉 throws 面。
527
+ */
528
+ type AbsApplyResult = {
529
+ abs: Abs;
530
+ throws: Abs;
531
+ /** Discriminator stamped by makeAbsApplyResult. */
532
+ readonly applyResult: true;
533
+ };
534
+ /** apply 可返回裸 Abs(无 throws)或带 throws 通道的 AbsApplyResult */
535
+ type AbsApplyReturn = Abs | AbsApplyResult;
536
+ /** 唯一构造入口:打上 applyResult brand。 */
537
+ declare function makeAbsApplyResult(abs: Abs, throws: Abs): AbsApplyResult;
538
+ /** AbsApplyResult 判别:只认 brand(不靠 !shape 结构猜)。 */
539
+ declare function isAbsApplyResult(v: AbsApplyReturn): v is AbsApplyResult;
540
+ /**
541
+ * apply 返回值取 abs 面(已知不抛 / 测试面只想看结果时用)。
542
+ * 丢弃 throws 通道——若 impl 可能抛,必须走 `$call` 统一路由,不得用本函数吞 throws。
543
+ */
544
+ declare function absOnly(r: AbsApplyReturn): AbsApplyNoThrow;
545
+ type AbsFnImpl = {
546
+ params: string[];
547
+ /** 可选:无 body 时走 relation(纯关系 fn) */
548
+ body?: Node;
549
+ async?: boolean;
550
+ /** 声明时捕获的环境(闭包) */
551
+ env?: AstEnv;
552
+ kind?: string;
553
+ /**
554
+ * 调用时直接派发(mock withArgs 等),优先于 body。
555
+ * 返回裸 Abs = 不抛;返回 AbsApplyResult 时 throws 面经 $call 统一路由,
556
+ * 不得在 apply 内自行 re-throw / pushThrowExit(会与 $call 路由叠算)。
557
+ */
558
+ apply?: (args: Abs[], thisVal?: Abs) => AbsApplyReturn;
559
+ /**
560
+ * 对象方法(ObjectMethod / 方法型 FunctionExpression):$invoke 时把
561
+ * receiver 作为 apply 的**首参**注入。shape.params 仍是用户可见形参
562
+ * (不含 receiver),自由调用不注入 → this 为 unbound(JS 语义)。
563
+ */
564
+ bindThis?: boolean;
565
+ /**
566
+ * Optional content key for cache fingerprints. formatAbs cannot see
567
+ * WeakMap-side mock semantics (returns/withArgs/callsFake), so hosts that
568
+ * build mocks should stamp a stable fingerprint here.
569
+ * relation-only 必填(未传时 relationFn 自动生成)。
570
+ */
571
+ fingerprint?: string;
572
+ /** 无 body 时,按 paramTypes 做 α 替换得到返回 */
573
+ relation?: {
574
+ paramTypes: Abs[];
575
+ returnType: Abs;
576
+ /**
577
+ * 条件类型 infer:绑定 fromVar 后从 via 投出 inferVar
578
+ * (`T extends (infer E)[]` → via: "arr";`T extends Promise<infer U>` → "promise")。
579
+ */
580
+ inferFrom?: {
581
+ fromVar: string;
582
+ via: "arr" | "promise";
583
+ inferVar: string;
584
+ };
585
+ /** extends 不成立时的假分支(如 never) */
586
+ condFallback?: Abs;
587
+ };
588
+ /** `@nudo:pure`:调用结果按实参记忆化(无副作用契约) */
589
+ pureName?: string;
590
+ };
591
+ declare function attachFnImpl(a: Abs, impl: AbsFnImpl): void;
592
+ declare function getFnImpl(a: Abs): AbsFnImpl | undefined;
593
+ /** 标记纯函数(@nudo:pure):调用结果可按实参记忆化 */
594
+ declare function markPureFn(target: object, name: string): void;
595
+ /** 读纯函数标记(Abs impl 或对象属性 `_memoize`) */
596
+ declare function pureFnNameOf(fn: unknown): string | undefined;
597
+ /** 造一个带实现的 Abs 函数值 */
598
+ declare function absFunction(params: string[], impl: Omit<AbsFnImpl, "params">, opts?: {
599
+ name?: string;
600
+ paramTypes?: Abs[];
601
+ returnType?: Abs;
602
+ slots?: Record<string, {
603
+ value: Abs;
604
+ optional?: boolean;
605
+ readonly?: boolean;
606
+ }>;
607
+ conf?: Confidence;
608
+ }): Abs;
609
+ /** relationFn 稳定 fingerprint(同签名共享,见 §3.3 已知限制) */
610
+ declare function relationFingerprint(paramTypes: Abs[], returnType: Abs): string;
611
+ /**
612
+ * 无 body、纯关系的 fn Abs。params 仅记 arity。
613
+ *
614
+ * **双写纪律:** 同一份关系数据必须同时写到——
615
+ * 1. `shape.paramTypes` / `shape.returnType` —— format / leq / 展示读这里
616
+ * 2. `impl.relation` —— D 路径应用读这里
617
+ * 两槽共享同一数组/对象引用(防内容分叉);构造后请勿原地 mutate。
618
+ *
619
+ * 默认 conf="path"(与提升产物一致)。禁止静默对齐 absFunction 的 "exact"。
620
+ * fingerprint 必填(call-budget);未传时由 paramTypes+returnType 稳定序列化生成。
621
+ * 同签名 relationFn 共享 fingerprint → 共享 budget 键(见 design §3.3 已知限制)。
622
+ */
623
+ declare function relationFn(paramTypes: Abs[], returnType: Abs, opts?: {
624
+ params?: string[];
625
+ conf?: Confidence;
626
+ fingerprint?: string;
627
+ inferFrom?: {
628
+ fromVar: string;
629
+ via: "arr" | "promise";
630
+ inferVar: string;
631
+ };
632
+ condFallback?: Abs;
633
+ }): Abs;
634
+ /** 仅写 shape 槽(E 路径 / §5.2 提升产物);禁止 attachFnImpl */
635
+ declare function shapeOnlyFn(paramTypes: Abs[], returnType: Abs, opts?: {
636
+ params?: string[];
637
+ conf?: Confidence;
638
+ }): Abs;
639
+
466
640
  /**
467
641
  * Abs 模块面(无 fs):import 绑定 + export 收集。
468
642
  * 解析路径/读文件在 host;core 只吃「specifier → 导出表」。
@@ -582,5 +756,14 @@ declare function callTranspiledExportFull(exports: Record<string, unknown>, name
582
756
  }): TranspiledCallResult;
583
757
  /** 调用 runTranspiled 导出(仅结果) */
584
758
  declare function callTranspiledExport(exports: Record<string, unknown>, name: string, args: Abs[]): Abs;
759
+ /**
760
+ * 包装 runTranspiled 导出为 Abs apply 钩子——throws 面经返回值通道强制保留
761
+ * (H1 / DESIGN-003)。这是包装 `callTranspiledExportFull` 的**唯一入口**:
762
+ * 返回 AbsApplyResult(`{abs, throws}`),$call 统一路由 throws。
763
+ * 手拆 `.result` 会静默丢 throws 面(BUG-006 根因)。
764
+ *
765
+ * `exports` 可传惰性 getter(互递归模块桥:导出表在桥创建后才赋值)。
766
+ */
767
+ declare function callTranspiledExportApply(exports: Record<string, unknown> | (() => Record<string, unknown>), name: string): (args: Abs[], thisVal?: Abs) => AbsApplyResult;
585
768
 
586
- export { $tryDigestSoft as $, type Abs as A, throwAbsToKinds as B, type Confidence as C, throwsKindCovered as D, ERROR_FAMILY as E, withEvalBudgetOverride as F, type HofSite as G, type HofCollectCtx as H, type AbsModuleExports as I, type RunTranspiledOptions as J, $assignRecord as K, $callNamed as L, type MayThrowEffect as M, $recordBinding as N, type EvalAbsAssignRecord as O, type PrimName as P, type EvalCallRecord as Q, type RelSource as R, type Shape as S, type Term as T, type EvalFallback as U, type ImplicationOracle as V, type LiteralValue as W, MAX_EVAL_CALL_DEPTH as X, MAX_EVAL_TOTAL_CALLS as Y, RUNTIME_IMPORT_RE as Z, TYPEOF_NAMES as _, type Pred as a, setEvalCallCollector as a$, type TranspiledCallResult as a0, type TypeofName as a1, abs as a2, absToString as a3, and as a4, anyAbs as a5, anyVar as a6, app as a7, assumeFinite as a8, bigintLit as a9, lt as aA, ltNum as aB, namespaceAbsOf as aC, ne as aD, negatePred as aE, never as aF, not as aG, noteEvalCallRecord as aH, noteEvalFallback as aI, num as aJ, numLit as aK, numVar as aL, obj as aM, or as aN, pFalse as aO, pTrue as aP, phiAnd as aQ, predEquals as aR, predToString as aS, predVars as aT, primToTypeof as aU, ptypeof as aV, resetEvalCallBudget as aW, runTranspiled as aX, runTranspiledOptionsMemoKey as aY, setEvalAssignCollector as aZ, setEvalBindingSink as a_, bindImports as aa, bindingsOf as ab, bool as ac, boolLit as ad, callTranspiledExport as ae, callTranspiledExportFull as af, collectAbsExports as ag, confJoin as ah, emptyPhi as ai, eq as aj, evalExprAbs as ak, ge as al, geNum as am, getEvalCallCollector as an, getImplicationOracle as ao, gt as ap, gtNum as aq, implies as ar, isBigPrim as as, isExactLit as at, isNumPrim as au, isStrPrim as av, le as aw, leNum as ax, lit as ay, litValue as az, type Phi as b, setEvalFallbackCollector as b0, setImplicationOracle as b1, shapeOfTerm as b2, shapeToString as b3, simplifyTerm as b4, str as b5, strLit as b6, substPred as b7, termEquals as b8, termToString as b9, tryRunTranspiled as ba, unknown as bb, v as bc, type AstEnv as c, $tryMarkSoft as d, $tryReleaseSoft as e, type EvalFallbackStats as f, enterEvalCallBudgetSession as g, errorTypeAbs as h, exitEvalCallBudgetSession as i, filterDeclaredThrows as j, filterGateThrows as k, filterIgnoredThrows as l, flushMayThrowEffects as m, formatThrowsAbs as n, getEvalCallBudgetState as o, getEvalFallbackStats as p, getMayThrowCollector as q, isThrowsIgnored as r, mayThrowEffectsToAbs as s, orphanMayThrowEffects as t, popMayThrowFrame as u, pushMayThrowFrame as v, recordMayThrow as w, resetEvalFallbackStats as x, runWithMayThrowSession as y, setMayThrowCollector as z };
769
+ export { $tryDigestSoft as $, type Abs as A, runWithMayThrowSession as B, type Confidence as C, setMayThrowCollector as D, ERROR_FAMILY as E, throwAbsToKinds as F, throwsKindCovered as G, withEvalBudgetOverride as H, type HofCollectCtx as I, type HofSite as J, type AbsModuleExports as K, type LiteralValue as L, type MayThrowEffect as M, type RunTranspiledOptions as N, $assignRecord as O, type PrimName as P, $call as Q, type RelSource as R, type Shape as S, type Term as T, $callNamed as U, $recordBinding as V, type AbsApplyNoThrow as W, type AbsApplyNoThrowFn as X, type AbsApplyResult as Y, type AbsApplyReturn as Z, type AbsFnImpl as _, type Pred as a, num as a$, type AbsSigImpl as a0, type EvalAbsAssignRecord as a1, type EvalCallRecord as a2, type EvalFallback as a3, type ImplicationOracle as a4, type LitValueResult as a5, MAX_EVAL_CALL_DEPTH as a6, MAX_EVAL_TOTAL_CALLS as a7, RUNTIME_IMPORT_RE as a8, TYPEOF_NAMES as a9, geNum as aA, getEvalCallCollector as aB, getFnImpl as aC, getImplicationOracle as aD, gt as aE, gtNum as aF, implies as aG, isAbsApplyResult as aH, isBigPrim as aI, isExactLit as aJ, isNumPrim as aK, isStrPrim as aL, le as aM, leNum as aN, lit as aO, litValue as aP, lt as aQ, ltNum as aR, makeAbsApplyResult as aS, markPureFn as aT, namespaceAbsOf as aU, ne as aV, negatePred as aW, never as aX, not as aY, noteEvalCallRecord as aZ, noteEvalFallback as a_, type TranspiledCallResult as aa, type TypeofName as ab, abs as ac, absFunction as ad, absOnly as ae, absToString as af, and as ag, anyAbs as ah, anyVar as ai, app as aj, assumeFinite as ak, attachFnImpl as al, bigintLit as am, bindImports as an, bindingsOf as ao, bool as ap, boolLit as aq, callTranspiledExport as ar, callTranspiledExportApply as as, callTranspiledExportFull as at, collectAbsExports as au, confJoin as av, emptyPhi as aw, eq as ax, evalExprAbs as ay, ge as az, type Phi as b, numLit as b0, numVar as b1, obj as b2, or as b3, pFalse as b4, pTrue as b5, phiAnd as b6, predEquals as b7, predToString as b8, predVars as b9, primToTypeof as ba, ptypeof as bb, pureFnNameOf as bc, relationFingerprint as bd, relationFn as be, resetEvalCallBudget as bf, runTranspiled as bg, runTranspiledOptionsMemoKey as bh, setEvalAssignCollector as bi, setEvalBindingSink as bj, setEvalCallCollector as bk, setEvalFallbackCollector as bl, setImplicationOracle as bm, shapeOfTerm as bn, shapeOnlyFn as bo, shapeToString as bp, simplifyTerm as bq, str as br, strLit as bs, substPred as bt, termEquals as bu, termToString as bv, tryRunTranspiled as bw, unknown as bx, v as by, routeApplyThrows as bz, type AstEnv as c, $tryMarkSoft as d, $tryReleaseSoft as e, type EvalFallbackStats as f, clearPureCallMemo as g, clearPureMemo as h, enterEvalCallBudgetSession as i, errorTypeAbs as j, exitEvalCallBudgetSession as k, filterDeclaredThrows as l, filterGateThrows as m, filterIgnoredThrows as n, flushMayThrowEffects as o, formatThrowsAbs as p, getEvalCallBudgetState as q, getEvalFallbackStats as r, getMayThrowCollector as s, isThrowsIgnored as t, mayThrowEffectsToAbs as u, orphanMayThrowEffects as v, popMayThrowFrame as w, pushMayThrowFrame as x, recordMayThrow as y, resetEvalFallbackStats as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nudojs/core",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "engines": {
5
5
  "node": ">=20"
6
6
  },