@nudojs/core 1.7.10 → 1.8.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.
@@ -12,7 +12,7 @@ var lit = (value) => ({
12
12
  value
13
13
  });
14
14
  var v = (id) => ({ op: "var", id });
15
- var app = (fn, args) => ({ op: "app", fn, args });
15
+ var app = (fn2, args) => ({ op: "app", fn: fn2, args });
16
16
  function termEquals(a, b) {
17
17
  if (a === b) return true;
18
18
  if (a.op !== b.op) return false;
@@ -60,13 +60,13 @@ function termToString(t) {
60
60
  function simplifyTerm(t) {
61
61
  if (t.op !== "app") return t;
62
62
  const args = t.args.map(simplifyTerm);
63
- const fn = t.fn;
63
+ const fn2 = t.fn;
64
64
  if (args.every((a) => a.op === "lit")) {
65
65
  const xs = args.map((a) => a.value);
66
- const folded = foldLiterals(fn, xs);
66
+ const folded = foldLiterals(fn2, xs);
67
67
  if (folded !== void 0) return lit(folded);
68
68
  }
69
- if (fn === "*" && args.length === 2) {
69
+ if (fn2 === "*" && args.length === 2) {
70
70
  const [a, b] = args;
71
71
  const one = (t2) => t2.op === "lit" && t2.value === 1;
72
72
  const surviveMulOne = (t2) => {
@@ -76,36 +76,36 @@ function simplifyTerm(t) {
76
76
  if (typeof v2 === "boolean") return lit(v2 ? 1 : 0);
77
77
  if (v2 === null) return lit(0);
78
78
  if (typeof v2 === "string") return lit(Number(v2));
79
- if (typeof v2 === "bigint") return app(fn, args);
79
+ if (typeof v2 === "bigint") return app(fn2, args);
80
80
  return lit(NaN);
81
81
  };
82
82
  if (one(b)) return surviveMulOne(a);
83
83
  if (one(a)) return surviveMulOne(b);
84
84
  }
85
- if (fn === "-" && args.length === 2) {
85
+ if (fn2 === "-" && args.length === 2) {
86
86
  const [a, b] = args;
87
87
  if (b.op === "lit" && Object.is(b.value, 0)) return a;
88
88
  }
89
- return app(fn, args);
89
+ return app(fn2, args);
90
90
  }
91
- function foldLiterals(fn, xs) {
92
- if (fn === "+" && xs.length === 2) {
91
+ function foldLiterals(fn2, xs) {
92
+ if (fn2 === "+" && xs.length === 2) {
93
93
  const [a, b] = xs;
94
94
  if (typeof a === "number" && typeof b === "number") return a + b;
95
95
  if (typeof a === "string" || typeof b === "string") return String(a) + String(b);
96
96
  return void 0;
97
97
  }
98
- if (fn === "-" && xs.length === 2) {
98
+ if (fn2 === "-" && xs.length === 2) {
99
99
  const [a, b] = xs;
100
100
  if (typeof a === "number" && typeof b === "number") return a - b;
101
101
  return void 0;
102
102
  }
103
- if (fn === "*" && xs.length === 2) {
103
+ if (fn2 === "*" && xs.length === 2) {
104
104
  const [a, b] = xs;
105
105
  if (typeof a === "number" && typeof b === "number") return a * b;
106
106
  return void 0;
107
107
  }
108
- if (fn === "neg" && xs.length === 1) {
108
+ if (fn2 === "neg" && xs.length === 1) {
109
109
  const a = xs[0];
110
110
  if (typeof a === "number") return -a;
111
111
  return void 0;
@@ -378,8 +378,8 @@ var implicationOracleSlot = createScopedSlot(
378
378
  () => void 0
379
379
  );
380
380
  registerCollectorScopeParticipant((body) => implicationOracleSlot.runScoped(body));
381
- function setImplicationOracle(fn) {
382
- implicationOracleSlot.set(fn);
381
+ function setImplicationOracle(fn2) {
382
+ implicationOracleSlot.set(fn2);
383
383
  }
384
384
  function getImplicationOracle() {
385
385
  return implicationOracleSlot.get();
@@ -1172,9 +1172,9 @@ function shapeOfTerm(t) {
1172
1172
  }
1173
1173
  return { k: "unknown" };
1174
1174
  }
1175
- function abs(shape, term, pred, conf) {
1175
+ function abs(shape2, term, pred, conf) {
1176
1176
  return {
1177
- shape,
1177
+ shape: shape2,
1178
1178
  term,
1179
1179
  pred: pred && pred.op !== "true" ? pred : void 0,
1180
1180
  conf
@@ -1455,11 +1455,11 @@ function markPureFn(target, name) {
1455
1455
  const impl = implByAbs.get(target);
1456
1456
  if (impl) impl.pureName = name;
1457
1457
  }
1458
- function pureFnNameOf(fn) {
1459
- if (!fn || typeof fn !== "object" && typeof fn !== "function") return void 0;
1460
- const impl = implByAbs.get(fn);
1458
+ function pureFnNameOf(fn2) {
1459
+ if (!fn2 || typeof fn2 !== "object" && typeof fn2 !== "function") return void 0;
1460
+ const impl = implByAbs.get(fn2);
1461
1461
  if (impl?.pureName) return impl.pureName;
1462
- return fn._memoize;
1462
+ return fn2._memoize;
1463
1463
  }
1464
1464
  function absFunction(params, impl, opts) {
1465
1465
  const a = {
@@ -1608,8 +1608,8 @@ var derivationSlot = createScopedSlot(() => ({
1608
1608
  }));
1609
1609
  registerCollectorScopeParticipant((body) => derivationSlot.runScoped(body));
1610
1610
  var byAbs = /* @__PURE__ */ new WeakMap();
1611
- function setDerivationCollector(fn) {
1612
- derivationSlot.get().collector = fn;
1611
+ function setDerivationCollector(fn2) {
1612
+ derivationSlot.get().collector = fn2;
1613
1613
  }
1614
1614
  function hasDerivationSession() {
1615
1615
  return derivationSlot.get().sessionNodes !== null;
@@ -1764,10 +1764,10 @@ function propertyKeyOf(a) {
1764
1764
  return String(v2);
1765
1765
  }
1766
1766
  function objOf(slots, opts) {
1767
- const shape = { k: "obj", slots };
1768
- if (opts?.index) shape.index = opts.index;
1769
- if (opts?.open) shape.open = true;
1770
- return { shape, conf: "exact" };
1767
+ const shape2 = { k: "obj", slots };
1768
+ if (opts?.index) shape2.index = opts.index;
1769
+ if (opts?.open) shape2.open = true;
1770
+ return { shape: shape2, conf: "exact" };
1771
1771
  }
1772
1772
  function isObj(a) {
1773
1773
  return a.shape.k === "obj";
@@ -1819,9 +1819,9 @@ function spread(base, over) {
1819
1819
  if (indexSlots && isObj(base)) {
1820
1820
  const slots2 = { ...base.shape.slots };
1821
1821
  for (const [k, s] of Object.entries(indexSlots)) setSlot(slots2, k, s);
1822
- const shape2 = { k: "obj", slots: slots2 };
1823
- if (base.shape.open) shape2.open = true;
1824
- return { shape: shape2, conf: confJoin(base.conf, over.conf) };
1822
+ const shape3 = { k: "obj", slots: slots2 };
1823
+ if (base.shape.open) shape3.open = true;
1824
+ return { shape: shape3, conf: confJoin(base.conf, over.conf) };
1825
1825
  }
1826
1826
  if (!isObj(base)) return unknown;
1827
1827
  return {
@@ -1837,12 +1837,12 @@ function spread(base, over) {
1837
1837
  setSlot(slots, k, s);
1838
1838
  }
1839
1839
  const open = base.shape.open || over.shape.open || false;
1840
- const shape = { k: "obj", slots };
1841
- if (open) shape.open = true;
1840
+ const shape2 = { k: "obj", slots };
1841
+ if (open) shape2.open = true;
1842
1842
  if (base.shape.index || over.shape.index) {
1843
- shape.index = over.shape.index ?? base.shape.index;
1843
+ shape2.index = over.shape.index ?? base.shape.index;
1844
1844
  }
1845
- return { shape, conf: confJoin(base.conf, over.conf) };
1845
+ return { shape: shape2, conf: confJoin(base.conf, over.conf) };
1846
1846
  }
1847
1847
  function spreadIndexSlots(over) {
1848
1848
  const s = over.shape;
@@ -2006,9 +2006,9 @@ function absShapeKey(a, seen = /* @__PURE__ */ new Set()) {
2006
2006
  }
2007
2007
  }
2008
2008
  function fnOf(params, name) {
2009
- const shape = { k: "fn", params };
2010
- if (name) shape.name = name;
2011
- return { shape, conf: "exact" };
2009
+ const shape2 = { k: "fn", params };
2010
+ if (name) shape2.name = name;
2011
+ return { shape: shape2, conf: "exact" };
2012
2012
  }
2013
2013
  function joinFunctions(a, b) {
2014
2014
  const sa = a.shape;
@@ -2487,7 +2487,7 @@ function tryPromoteHofCallback(env, cevalName, method, argAbses, loc) {
2487
2487
  return env.vars.get(cevalName);
2488
2488
  }
2489
2489
  function snapshotAbs(a) {
2490
- const shape = a.shape;
2490
+ const shape2 = a.shape;
2491
2491
  const copyShape = (s) => {
2492
2492
  switch (s.k) {
2493
2493
  case "arr":
@@ -2542,7 +2542,7 @@ function snapshotAbs(a) {
2542
2542
  }
2543
2543
  };
2544
2544
  return {
2545
- shape: copyShape(shape),
2545
+ shape: copyShape(shape2),
2546
2546
  term: a.term,
2547
2547
  pred: a.pred,
2548
2548
  conf: a.conf
@@ -2657,17 +2657,17 @@ function mapHasShapeOnlyVar(p, map) {
2657
2657
  function substPredAbs(p, map) {
2658
2658
  if (!predUsesMappedVars(p, map)) return { pred: p, dropped: false };
2659
2659
  if (mapHasShapeOnlyVar(p, map)) return { pred: pTrue, dropped: true };
2660
- const substTerm = (t) => {
2660
+ const substTerm2 = (t) => {
2661
2661
  if (t.op === "var") {
2662
2662
  const arg = map.get(t.id);
2663
2663
  return arg?.term ?? t;
2664
2664
  }
2665
2665
  if (t.op === "app") {
2666
- return { op: "app", fn: t.fn, args: t.args.map(substTerm) };
2666
+ return { op: "app", fn: t.fn, args: t.args.map(substTerm2) };
2667
2667
  }
2668
2668
  return t;
2669
2669
  };
2670
- const replaced = substPred(p, substTerm);
2670
+ const replaced = substPred(p, substTerm2);
2671
2671
  const fold = (q) => {
2672
2672
  switch (q.op) {
2673
2673
  case "true":
@@ -2807,7 +2807,7 @@ function substAbsInner(a, map, cache, visiting) {
2807
2807
  if (hit !== void 0) return hit;
2808
2808
  if (visiting.has(a)) return a;
2809
2809
  visiting.add(a);
2810
- const shape = substShape(a.shape, map, cache, visiting);
2810
+ const shape2 = substShape(a.shape, map, cache, visiting);
2811
2811
  const term = a.term ? substTermAbs(a.term, map) : void 0;
2812
2812
  let pred = a.pred;
2813
2813
  let conf = a.conf;
@@ -2817,7 +2817,7 @@ function substAbsInner(a, map, cache, visiting) {
2817
2817
  if (r.dropped) conf = confJoin(conf, "partial");
2818
2818
  }
2819
2819
  visiting.delete(a);
2820
- const result = abs(shape, term, pred, conf);
2820
+ const result = abs(shape2, term, pred, conf);
2821
2821
  cache.set(a, result);
2822
2822
  return result;
2823
2823
  }
@@ -2872,13 +2872,13 @@ function bindTypeVars(pattern, arg, map, depth = 0) {
2872
2872
  return;
2873
2873
  }
2874
2874
  }
2875
- function instantiateReturn(fn, args) {
2876
- const shape = fn.shape;
2877
- if (!shape || shape.k !== "fn") return unknown;
2878
- const impl = getFnImpl(fn);
2875
+ function instantiateReturn(fn2, args) {
2876
+ const shape2 = fn2.shape;
2877
+ if (!shape2 || shape2.k !== "fn") return unknown;
2878
+ const impl = getFnImpl(fn2);
2879
2879
  const src = impl?.relation ?? {
2880
- paramTypes: shape.paramTypes ?? [],
2881
- returnType: shape.returnType ?? unknown
2880
+ paramTypes: shape2.paramTypes ?? [],
2881
+ returnType: shape2.returnType ?? unknown
2882
2882
  };
2883
2883
  const map = /* @__PURE__ */ new Map();
2884
2884
  src.paramTypes.forEach((p, i) => {
@@ -2897,16 +2897,16 @@ function instantiateReturn(fn, args) {
2897
2897
  return substAbs(src.returnType, map);
2898
2898
  }
2899
2899
  var applyCallbackHost;
2900
- function setApplyCallbackHost(fn) {
2901
- applyCallbackHost = fn;
2900
+ function setApplyCallbackHost(fn2) {
2901
+ applyCallbackHost = fn2;
2902
2902
  }
2903
- function applyCallbackValue(fn, args, env, phi2, budget) {
2904
- if (typeof fn === "function") {
2905
- const r = fn(...args);
2903
+ function applyCallbackValue(fn2, args, env, phi2, budget) {
2904
+ if (typeof fn2 === "function") {
2905
+ const r = fn2(...args);
2906
2906
  if (r && typeof r === "object" && "shape" in r) return r;
2907
2907
  return unknown;
2908
2908
  }
2909
- const absFn = asAbs(fn);
2909
+ const absFn = asAbs(fn2);
2910
2910
  if (absFn) return applyCallbackAbs(absFn, args, env, phi2, budget);
2911
2911
  return unknown;
2912
2912
  }
@@ -4411,8 +4411,8 @@ function str2(conf = "path") {
4411
4411
  function boolPrim(conf = "partial") {
4412
4412
  return abs({ k: "prim", type: "boolean" }, void 0, void 0, conf);
4413
4413
  }
4414
- function peelBrand(shape) {
4415
- let s = shape;
4414
+ function peelBrand(shape2) {
4415
+ let s = shape2;
4416
4416
  while (s.k === "brand") s = s.shape.shape;
4417
4417
  return s;
4418
4418
  }
@@ -5792,8 +5792,8 @@ function matchAsOverride(stmt, opts) {
5792
5792
  }
5793
5793
  return null;
5794
5794
  }
5795
- function fnBodyHasThis(fn) {
5796
- const body = fn.body;
5795
+ function fnBodyHasThis(fn2) {
5796
+ const body = fn2.body;
5797
5797
  if (!body) return false;
5798
5798
  const seen = /* @__PURE__ */ new Set();
5799
5799
  const walk = (n) => {
@@ -5817,8 +5817,8 @@ function fnBodyHasThis(fn) {
5817
5817
  };
5818
5818
  return walk(body);
5819
5819
  }
5820
- function fnBodyHasOwnArguments(fn) {
5821
- const body = fn.body;
5820
+ function fnBodyHasOwnArguments(fn2) {
5821
+ const body = fn2.body;
5822
5822
  if (!body) return false;
5823
5823
  const seen = /* @__PURE__ */ new Set();
5824
5824
  const walk = (n) => {
@@ -6343,16 +6343,16 @@ function isExpression(n) {
6343
6343
 
6344
6344
  // src/algebra/exec/transpile/transpile-dispatch.ts
6345
6345
  var dispatch = {};
6346
- function bindTranspileExpression(fn) {
6347
- dispatch.expr = fn;
6346
+ function bindTranspileExpression(fn2) {
6347
+ dispatch.expr = fn2;
6348
6348
  }
6349
- function bindTranspileShortCircuit(fn) {
6350
- dispatch.shortCircuit = fn;
6349
+ function bindTranspileShortCircuit(fn2) {
6350
+ dispatch.shortCircuit = fn2;
6351
6351
  }
6352
6352
  function emitTranspileExpression(expr, opts = {}) {
6353
- const fn = dispatch.expr;
6354
- if (!fn) throw new Error("transpileExpression not bound (expr.ts not loaded)");
6355
- return fn(expr, opts);
6353
+ const fn2 = dispatch.expr;
6354
+ if (!fn2) throw new Error("transpileExpression not bound (expr.ts not loaded)");
6355
+ return fn2(expr, opts);
6356
6356
  }
6357
6357
 
6358
6358
  // src/algebra/exec/transpile/member-path.ts
@@ -6547,7 +6547,7 @@ function emitArrMutatorRebinds(expr, opts, pad) {
6547
6547
  }
6548
6548
  if (node.type === "UpdateExpression" && node.argument) {
6549
6549
  const arg = node.argument;
6550
- const fn = node.operator === "++" ? "$updateAdd" : "$updateSub";
6550
+ const fn2 = node.operator === "++" ? "$updateAdd" : "$updateSub";
6551
6551
  if (arg.type === "MemberExpression") {
6552
6552
  const path = memberPathOf(
6553
6553
  arg,
@@ -6555,7 +6555,7 @@ function emitArrMutatorRebinds(expr, opts, pad) {
6555
6555
  );
6556
6556
  if (path) {
6557
6557
  const readSrc = readPathSrc(path);
6558
- lines.push(`${pad}${path.rootSrc} = ${setPathSrc(path, `${fn}(${readSrc})`)};`);
6558
+ lines.push(`${pad}${path.rootSrc} = ${setPathSrc(path, `${fn2}(${readSrc})`)};`);
6559
6559
  }
6560
6560
  }
6561
6561
  }
@@ -6987,6 +6987,13 @@ var memberGuardTarget = (n) => {
6987
6987
  if (key === void 0) return void 0;
6988
6988
  return { name: m.object.name, key };
6989
6989
  };
6990
+ var assignGuardTarget = (n) => {
6991
+ const t = n;
6992
+ if (t?.type === "AssignmentExpression" && t.operator === "=" && t.left?.type === "Identifier" && t.left.name) {
6993
+ return t.left.name;
6994
+ }
6995
+ return void 0;
6996
+ };
6990
6997
  function nullishGuardOf(test) {
6991
6998
  const t = test;
6992
6999
  if (t?.type === "LogicalExpression") return compositeNullishGuardOf(t);
@@ -6996,12 +7003,16 @@ function nullishGuardOf(test) {
6996
7003
  if (t?.type === "UnaryExpression" && t.operator === "!") {
6997
7004
  const m = memberGuardTarget(t.argument);
6998
7005
  if (m) return { name: m.name, arm: "alt", grain: "nullish", memberKey: m.key };
7006
+ const a = assignGuardTarget(t.argument);
7007
+ if (a) return { name: a, arm: "alt", grain: "nullish" };
6999
7008
  }
7000
7009
  if (t?.type === "Identifier" && t.name) {
7001
7010
  return { name: t.name, arm: "cons", grain: "nullish" };
7002
7011
  }
7003
7012
  const bare = memberGuardTarget(t);
7004
7013
  if (bare) return { name: bare.name, arm: "cons", grain: "nullish", memberKey: bare.key };
7014
+ const bareAssign = assignGuardTarget(t);
7015
+ if (bareAssign) return { name: bareAssign, arm: "cons", grain: "nullish" };
7005
7016
  if (t?.type !== "BinaryExpression") return void 0;
7006
7017
  const op = t.operator;
7007
7018
  if (op !== "===" && op !== "!==" && op !== "==" && op !== "!=") return void 0;
@@ -7033,6 +7044,20 @@ function nullishGuardOf(test) {
7033
7044
  const grain = litGrain(l);
7034
7045
  if (grain !== void 0) return { name: r.name, arm: truthyArm, grain };
7035
7046
  }
7047
+ if (op === "==" || op === "!=") {
7048
+ const nullishLit = (n) => {
7049
+ const ln = n;
7050
+ return ln?.type === "NullLiteral" || ln?.name === "undefined";
7051
+ };
7052
+ const lm = memberGuardTarget(t.left);
7053
+ const rm = memberGuardTarget(t.right);
7054
+ if (lm && nullishLit(t.right)) {
7055
+ return { name: lm.name, arm: truthyArm, grain: "nullish", memberKey: lm.key };
7056
+ }
7057
+ if (rm && nullishLit(t.left)) {
7058
+ return { name: rm.name, arm: truthyArm, grain: "nullish", memberKey: rm.key };
7059
+ }
7060
+ }
7036
7061
  return void 0;
7037
7062
  }
7038
7063
  function compositeNullishGuardOf(test) {
@@ -7053,6 +7078,31 @@ function compositeNullishGuardOf(test) {
7053
7078
  }
7054
7079
  return lg ?? rg;
7055
7080
  }
7081
+ function mergeGuardInto(list, g) {
7082
+ const prev = list.find((x) => x.name === g.name);
7083
+ if (!prev) {
7084
+ list.push(g);
7085
+ return;
7086
+ }
7087
+ const grainA = prev.grain ?? "nullish";
7088
+ const grainB = g.grain ?? "nullish";
7089
+ if (grainA !== grainB) prev.grain = "nullish";
7090
+ if (prev.memberKey === void 0 && g.memberKey !== void 0) prev.memberKey = g.memberKey;
7091
+ }
7092
+ function nullishGuardsOf(test) {
7093
+ const t = test;
7094
+ if (t?.type === "LogicalExpression" && (t.operator === "||" || t.operator === "&&")) {
7095
+ const wantArm = t.operator === "||" ? "alt" : "cons";
7096
+ const out = [];
7097
+ for (const g2 of [...nullishGuardsOf(t.left), ...nullishGuardsOf(t.right)]) {
7098
+ if (g2.arm !== wantArm) continue;
7099
+ mergeGuardInto(out, g2);
7100
+ }
7101
+ return out;
7102
+ }
7103
+ const g = nullishGuardOf(test);
7104
+ return g ? [g] : [];
7105
+ }
7056
7106
  function typeGuardOf(test) {
7057
7107
  const t = test;
7058
7108
  if (t?.type !== "BinaryExpression") return void 0;
@@ -7074,11 +7124,15 @@ function nullishRemoveCallOf(guard) {
7074
7124
  if (guard.grain === "null") return `$removeNull(${guard.name})`;
7075
7125
  return `$removeNullish(${guard.name})`;
7076
7126
  }
7077
- function narrowNullishArmThunk(thunk, guard, arm, forkBindingNames) {
7078
- if (!guard || guard.arm !== arm) return thunk;
7127
+ function narrowNullishArmThunks(thunk, guards, arm, forkBindingNames) {
7128
+ if (!guards || guards.length === 0) return thunk;
7129
+ const matching = guards.filter((g) => g.arm === arm);
7130
+ if (matching.length === 0) return thunk;
7079
7131
  const names = forkBindingNames instanceof Set ? forkBindingNames : new Set(forkBindingNames);
7080
- if (names.has(guard.name)) return thunk;
7081
- return `((${guard.name}) => ${thunk})(${nullishRemoveCallOf(guard)})`;
7132
+ if (matching.some((g) => names.has(g.name))) return thunk;
7133
+ const params = matching.map((g) => g.name).join(", ");
7134
+ const args = matching.map((g) => nullishRemoveCallOf(g)).join(", ");
7135
+ return `((${params}) => ${thunk})(${args})`;
7082
7136
  }
7083
7137
  function narrowTypeArmThunk(thunk, guard, arm, forkBindingNames) {
7084
7138
  if (!guard) return thunk;
@@ -7181,12 +7235,12 @@ function transpileFnBodyStmts(stmtsIn, depth, opts, varScope) {
7181
7235
  };
7182
7236
  const testRecvs = collectArrMutatorReceivers(stmt.test);
7183
7237
  const testRebinds = testRecvs.size ? emitArrMutatorRebinds(stmt.test, scopedOpts, pad) : [];
7184
- const earlyGuard = nullishGuardOf(stmt.test);
7238
+ const earlyGuards = nullishGuardsOf(stmt.test);
7185
7239
  const earlyTGuard = typeGuardOf(stmt.test);
7186
7240
  const consNarrowed = narrowTypeArmThunk(
7187
- narrowNullishArmThunk(
7241
+ narrowNullishArmThunks(
7188
7242
  transpileBlockAsThunk(stmt.consequent, depth, scopedOpts),
7189
- earlyGuard,
7243
+ earlyGuards,
7190
7244
  "cons",
7191
7245
  recvSet
7192
7246
  ),
@@ -7200,7 +7254,7 @@ function transpileFnBodyStmts(stmtsIn, depth, opts, varScope) {
7200
7254
  ${altBody}
7201
7255
  ${pad}}`;
7202
7256
  const altNarrowed = narrowTypeArmThunk(
7203
- narrowNullishArmThunk(altThunk, earlyGuard, "alt", recvSet),
7257
+ narrowNullishArmThunks(altThunk, earlyGuards, "alt", recvSet),
7204
7258
  earlyTGuard,
7205
7259
  "alt",
7206
7260
  recvSet
@@ -7530,16 +7584,16 @@ ${pad}export default ${name};`;
7530
7584
  ...opts,
7531
7585
  conditionalFlow: (opts.conditionalFlow ?? 0) + 1
7532
7586
  }) : null;
7533
- const guard = nullishGuardOf(stmt.test);
7587
+ const guards = nullishGuardsOf(stmt.test);
7534
7588
  const tguard = typeGuardOf(stmt.test);
7535
7589
  const consNarrowed = narrowTypeArmThunk(
7536
- narrowNullishArmThunk(consRaw, guard, "cons", recvSet),
7590
+ narrowNullishArmThunks(consRaw, guards, "cons", recvSet),
7537
7591
  tguard,
7538
7592
  "cons",
7539
7593
  recvSet
7540
7594
  );
7541
7595
  const altNarrowed = altRaw === null ? null : narrowTypeArmThunk(
7542
- narrowNullishArmThunk(altRaw, guard, "alt", recvSet),
7596
+ narrowNullishArmThunks(altRaw, guards, "alt", recvSet),
7543
7597
  tguard,
7544
7598
  "alt",
7545
7599
  recvSet
@@ -7987,13 +8041,24 @@ ${indent(depth + 1)}]${dflt})`;
7987
8041
  collectAssignedIds(stmt.test, assigned);
7988
8042
  const bodyLocalDecls = /* @__PURE__ */ new Set();
7989
8043
  collectLoopBodyTopLevelDeclNames(stmt.body, bodyLocalDecls);
8044
+ const bodyWrites = /* @__PURE__ */ new Set();
8045
+ collectAssignedIds(stmt.body, bodyWrites);
8046
+ collectArrMutatorReceivers(stmt.body, bodyWrites);
8047
+ const loopGuards = nullishGuardsOf(stmt.test).filter(
8048
+ (g) => g.arm === "cons" && !bodyWrites.has(g.name) && !bodyLocalDecls.has(g.name)
8049
+ );
8050
+ const bodyNarrowed = loopGuards.length === 0 ? body : [
8051
+ `${indent(depth + 1)}((${loopGuards.map((g) => g.name).join(", ")}) => {`,
8052
+ body,
8053
+ `${indent(depth + 1)}})(${loopGuards.map((g) => nullishRemoveCallOf(g)).join(", ")});`
8054
+ ].join("\n");
7990
8055
  const names = [...assigned].filter((n) => !HOST_INTRINSIC_SET.has(n) && !bodyLocalDecls.has(n));
7991
8056
  const loopOpts = opts.loopLabel ? `label: ${JSON.stringify(opts.loopLabel)}` : "";
7992
8057
  if (names.length === 0) {
7993
8058
  return [
7994
8059
  `${pad}// while \u2192 $whileSeq (bounded, max=${max})`,
7995
8060
  `${pad}$whileSeq(() => ${test}, () => {`,
7996
- body,
8061
+ bodyNarrowed,
7997
8062
  `${pad}}, ${max}${loopOpts ? `, { ${loopOpts} }` : ""});`
7998
8063
  ].join("\n");
7999
8064
  }
@@ -8002,7 +8067,7 @@ ${indent(depth + 1)}]${dflt})`;
8002
8067
  return [
8003
8068
  `${pad}// while \u2192 $whileSeq (instrumented bindings: ${names.join(", ")})`,
8004
8069
  `${pad}$whileSeq(() => ${test}, () => {`,
8005
- body,
8070
+ bodyNarrowed,
8006
8071
  `${pad}}, ${max}, { pack: () => ${packSrc}, unpack: ${unpackSrc}${loopOpts ? `, ${loopOpts}` : ""} });`
8007
8072
  ].join("\n");
8008
8073
  }
@@ -8021,6 +8086,17 @@ ${indent(depth + 1)}]${dflt})`;
8021
8086
  collectArrMutatorReceivers(stmt.body, assigned);
8022
8087
  const bodyLocalDecls = /* @__PURE__ */ new Set();
8023
8088
  collectLoopBodyTopLevelDeclNames(stmt.body, bodyLocalDecls);
8089
+ const bodyWrites = /* @__PURE__ */ new Set();
8090
+ collectAssignedIds(stmt.body, bodyWrites);
8091
+ collectArrMutatorReceivers(stmt.body, bodyWrites);
8092
+ const loopGuards = nullishGuardsOf(stmt.test).filter(
8093
+ (g) => g.arm === "cons" && !bodyWrites.has(g.name) && !bodyLocalDecls.has(g.name)
8094
+ );
8095
+ const innerBody = loopGuards.length === 0 ? bodyStmts : [
8096
+ `${indent(depth + 1)}((${loopGuards.map((g) => g.name).join(", ")}) => {`,
8097
+ bodyStmts,
8098
+ `${indent(depth + 1)}})(${loopGuards.map((g) => nullishRemoveCallOf(g)).join(", ")});`
8099
+ ].join("\n");
8024
8100
  const names = [...assigned].filter((n) => !HOST_INTRINSIC_SET.has(n) && !bodyLocalDecls.has(n));
8025
8101
  const packSrc = names.length === 0 ? null : `$obj({ ${names.map((n) => `${JSON.stringify(n)}: $copy(${n})`).join(", ")} })`;
8026
8102
  const unpackSrc = names.length === 0 ? null : `(__lp) => { ${names.map((n) => `${n} = $get(__lp, ${JSON.stringify(n)});`).join(" ")} }`;
@@ -8031,7 +8107,7 @@ ${indent(depth + 1)}]${dflt})`;
8031
8107
  `{`,
8032
8108
  bodyStmts,
8033
8109
  `${indent(depth + 1)}$whileSeq(() => ${test}, () => {`,
8034
- bodyStmts,
8110
+ innerBody,
8035
8111
  `${indent(depth + 1)}}, ${max}${optsSrc});`,
8036
8112
  `${pad}}`
8037
8113
  ].join("\n");
@@ -8437,13 +8513,15 @@ function transpileShortCircuitExpr(opts, parts) {
8437
8513
  const forkTest2 = parts.testSrc ?? parts.alwaysSrc;
8438
8514
  let consExpr = parts.consSrc === "__test" ? parts.alwaysSrc : parts.consSrc;
8439
8515
  let altExpr = parts.altSrc === "__test" ? parts.alwaysSrc : parts.altSrc;
8440
- if (parts.narrowGuard) {
8441
- if (parts.narrowGuard.arm === "cons") {
8442
- consExpr = `((${parts.narrowGuard.name}) => (${consExpr}))(${nullishRemoveCallOf(parts.narrowGuard)})`;
8443
- } else {
8444
- altExpr = `((${parts.narrowGuard.name}) => (${altExpr}))(${nullishRemoveCallOf(parts.narrowGuard)})`;
8445
- }
8446
- }
8516
+ const applyGuards = (src, arm) => {
8517
+ const gs = (parts.narrowGuards ?? []).filter((g) => g.arm === arm);
8518
+ if (gs.length === 0) return src;
8519
+ const params = gs.map((g) => g.name).join(", ");
8520
+ const args = gs.map((g) => nullishRemoveCallOf(g)).join(", ");
8521
+ return `((${params}) => (${src}))(${args})`;
8522
+ };
8523
+ consExpr = applyGuards(consExpr, "cons");
8524
+ altExpr = applyGuards(altExpr, "alt");
8447
8525
  if (parts.typeGuard) {
8448
8526
  const g = parts.typeGuard;
8449
8527
  const apply = (src, arm) => `((${g.name}) => (${src}))($narrowTypeOf(${g.name}, ${JSON.stringify(g.typeOf)}, ${arm === g.arm}))`;
@@ -8455,9 +8533,9 @@ function transpileShortCircuitExpr(opts, parts) {
8455
8533
  const consLines = parts.consSrc === "__test" ? [`return __test;`] : consRebinds.length === 0 ? [`return (${parts.consSrc});`] : [`const __v = (${parts.consSrc});`, ...consRebinds, `return __v;`];
8456
8534
  const altLines = parts.altSrc === "__test" ? [`return __test;`] : altRebinds.length === 0 ? [`return (${parts.altSrc});`] : [`const __v = (${parts.altSrc});`, ...altRebinds, `return __v;`];
8457
8535
  const forkTest = parts.testSrc ?? "__test";
8458
- const guard = parts.narrowGuard;
8459
- const consFinal = narrowNullishArmThunk(forkArmThunk(consLines, "fk1_", names), guard, "cons", names);
8460
- const altFinal = narrowNullishArmThunk(forkArmThunk(altLines, "fk2_", names), guard, "alt", names);
8536
+ const guards = parts.narrowGuards;
8537
+ const consFinal = narrowNullishArmThunks(forkArmThunk(consLines, "fk1_", names), guards, "cons", names);
8538
+ const altFinal = narrowNullishArmThunks(forkArmThunk(altLines, "fk2_", names), guards, "alt", names);
8461
8539
  return [
8462
8540
  `(() => {`,
8463
8541
  ` const __test = (${parts.alwaysSrc});`,
@@ -8679,7 +8757,7 @@ ${inner}
8679
8757
  testSrc: `$nullishTest(${l})`
8680
8758
  });
8681
8759
  }
8682
- const andGuard = nullishGuardOf(expr.left);
8760
+ const leftGuards = nullishGuardsOf(expr.left);
8683
8761
  const andTypeGuard = typeGuardOf(expr.left);
8684
8762
  return op === "&&" ? transpileShortCircuitExpr(opts, {
8685
8763
  alwaysNodes: [lNode],
@@ -8688,7 +8766,7 @@ ${inner}
8688
8766
  consNodes: [rNode],
8689
8767
  altSrc: "__test",
8690
8768
  altNodes: [],
8691
- narrowGuard: andGuard?.arm === "cons" ? andGuard : void 0,
8769
+ narrowGuards: leftGuards.filter((g) => g.arm === "cons"),
8692
8770
  typeGuard: andTypeGuard
8693
8771
  }) : transpileShortCircuitExpr(opts, {
8694
8772
  alwaysNodes: [lNode],
@@ -8697,7 +8775,7 @@ ${inner}
8697
8775
  consNodes: [],
8698
8776
  altSrc: r,
8699
8777
  altNodes: [rNode],
8700
- narrowGuard: andGuard?.arm === "alt" ? andGuard : void 0,
8778
+ narrowGuards: leftGuards.filter((g) => g.arm === "alt"),
8701
8779
  typeGuard: andTypeGuard
8702
8780
  });
8703
8781
  }
@@ -8716,8 +8794,9 @@ ${inner}
8716
8794
  altSrc: a,
8717
8795
  altNodes: [altNode],
8718
8796
  // 三元的 nullish/typeof 守卫臂收窄(issue #97:`p === null ? -1 : p.major`;
8719
- // Bug 23:`typeof v === "string" ? v + "!" : 0`)
8720
- narrowGuard: nullishGuardOf(expr.test),
8797
+ // Bug 23:`typeof v === "string" ? v + "!" : 0`;#118 v3/#120:多名复合
8798
+ // `obj == null || node.p == null ? … : node.p.name` 一臂多事实)
8799
+ narrowGuards: nullishGuardsOf(expr.test),
8721
8800
  typeGuard: typeGuardOf(expr.test)
8722
8801
  });
8723
8802
  }
@@ -8733,8 +8812,8 @@ ${inner}
8733
8812
  const r2 = isExpression(expr.right) ? transpileExpression(expr.right, opts) : "$lit(void 0)";
8734
8813
  return `$instanceofNonIdent(${l2}, ${r2})`;
8735
8814
  }
8736
- const fn = BIN_OPS[expr.operator];
8737
- if (!fn) {
8815
+ const fn2 = BIN_OPS[expr.operator];
8816
+ if (!fn2) {
8738
8817
  throw new NudoUnsupportedError(
8739
8818
  `binary:${expr.operator}`,
8740
8819
  expr.loc ? { line: expr.loc.start.line, column: expr.loc.start.column } : void 0
@@ -8742,7 +8821,7 @@ ${inner}
8742
8821
  }
8743
8822
  const l = isExpression(expr.left) ? transpileExpression(expr.left, opts) : "$lit(void 0)";
8744
8823
  const r = isExpression(expr.right) ? transpileExpression(expr.right, opts) : "$lit(void 0)";
8745
- return `${fn}(${l}, ${r})`;
8824
+ return `${fn2}(${l}, ${r})`;
8746
8825
  }
8747
8826
  case "UnaryExpression": {
8748
8827
  if (expr.operator === "delete") {
@@ -8778,20 +8857,20 @@ ${inner}
8778
8857
  }
8779
8858
  case "UpdateExpression": {
8780
8859
  const arg = expr.argument;
8781
- const fn = expr.operator === "++" ? "$updateAdd" : "$updateSub";
8860
+ const fn2 = expr.operator === "++" ? "$updateAdd" : "$updateSub";
8782
8861
  if (arg.type === "Identifier") {
8783
8862
  if (isConstAssignTarget(arg.name, opts)) {
8784
8863
  return `$throwConstAssign()`;
8785
8864
  }
8786
- if (expr.prefix) return `${arg.name} = ${fn}(${arg.name})`;
8787
- return `((__old) => (${arg.name} = ${fn}(__old), __old))($toNumeric(${arg.name}))`;
8865
+ if (expr.prefix) return `${arg.name} = ${fn2}(${arg.name})`;
8866
+ return `((__old) => (${arg.name} = ${fn2}(__old), __old))($toNumeric(${arg.name}))`;
8788
8867
  }
8789
8868
  if (arg.type === "MemberExpression") {
8790
8869
  const m = arg;
8791
8870
  const path = memberPathOf(m, opts);
8792
8871
  if (path) {
8793
8872
  const readSrc = readPathSrc(path);
8794
- if (expr.prefix) return `${fn}(${readSrc})`;
8873
+ if (expr.prefix) return `${fn2}(${readSrc})`;
8795
8874
  return `$toNumeric(${readSrc})`;
8796
8875
  }
8797
8876
  }
@@ -8971,23 +9050,23 @@ ${mBodyInner}
8971
9050
  continue;
8972
9051
  }
8973
9052
  if (prop.value.type === "FunctionExpression" && !prop.value.async) {
8974
- const fn = prop.value;
8975
- if (!fn.generator) {
8976
- const displayNames = paramDisplayNames(fn.params);
8977
- const bindNames = methodBindNames(fn.params);
8978
- const mHasArgs = fnBodyHasOwnArguments({ body: fn.body });
9053
+ const fn2 = prop.value;
9054
+ if (!fn2.generator) {
9055
+ const displayNames = paramDisplayNames(fn2.params);
9056
+ const bindNames = methodBindNames(fn2.params);
9057
+ const mHasArgs = fnBodyHasOwnArguments({ body: fn2.body });
8979
9058
  const methodOpts = {
8980
9059
  ...opts,
8981
9060
  inLoop: 0,
8982
9061
  thisParam: "__this",
8983
9062
  argsBinding: mHasArgs ? "__nudoArgs" : void 0
8984
9063
  };
8985
- let mBodyInner = emitFnBlockBody(fn.body, 1, methodOpts, {
8986
- varParams: paramNamesOfFn(fn.params)
9064
+ let mBodyInner = emitFnBlockBody(fn2.body, 1, methodOpts, {
9065
+ varParams: paramNamesOfFn(fn2.params)
8987
9066
  });
8988
9067
  let mParams = ["__this", ...bindNames];
8989
9068
  if (mHasArgs) {
8990
- const bound = emitParamBindingFromArgs(fn.params, " ", methodOpts, "__nudoArgs");
9069
+ const bound = emitParamBindingFromArgs(fn2.params, " ", methodOpts, "__nudoArgs");
8991
9070
  mBodyInner = [
8992
9071
  ` let __nudoArgs = $arguments(__margs);`,
8993
9072
  ...bound.prologue,
@@ -9329,14 +9408,14 @@ ${mBodyInner}
9329
9408
  }
9330
9409
  case "ArrowFunctionExpression":
9331
9410
  case "FunctionExpression": {
9332
- const fn = expr;
9411
+ const fn2 = expr;
9333
9412
  const isArrow = expr.type === "ArrowFunctionExpression";
9334
- const nfeName = !isArrow && fn.id?.name ? fn.id.name : null;
9413
+ const nfeName = !isArrow && fn2.id?.name ? fn2.id.name : null;
9335
9414
  const fnValSrc = (() => {
9336
- const fnCtor = isArrow || !!fn.async || !!fn.generator ? false : true;
9337
- const hasThis = !isArrow && fnBodyHasThis(fn);
9338
- const hasArgs = !isArrow && fnBodyHasOwnArguments(fn);
9339
- const { sig, rest, prologue } = emitParamBinding(fn.params, indent(1), opts);
9415
+ const fnCtor = isArrow || !!fn2.async || !!fn2.generator ? false : true;
9416
+ const hasThis = !isArrow && fnBodyHasThis(fn2);
9417
+ const hasArgs = !isArrow && fnBodyHasOwnArguments(fn2);
9418
+ const { sig, rest, prologue } = emitParamBinding(fn2.params, indent(1), opts);
9340
9419
  const fnBodyOpts = {
9341
9420
  ...opts,
9342
9421
  inLoop: 0,
@@ -9348,12 +9427,12 @@ ${mBodyInner}
9348
9427
  const restRaw = rest && !useArgsSlot ? `__rest_raw` : rest;
9349
9428
  const restPrologue = rest && !useArgsSlot && restRaw ? [` const ${rest} = $arr(${restRaw});`] : [];
9350
9429
  const paramParts = restRaw ? [...sig, `...${restRaw}`] : sig;
9351
- const nameList = `[${paramDisplayNames(fn.params).map((p) => JSON.stringify(p)).join(", ")}]`;
9430
+ const nameList = `[${paramDisplayNames(fn2.params).map((p) => JSON.stringify(p)).join(", ")}]`;
9352
9431
  const thisPrologue = hasThis ? [`let __this = $rawThis(this);`] : [];
9353
9432
  let argsSlotPrologue = [];
9354
9433
  let argsParamParts = paramParts;
9355
9434
  if (useArgsSlot) {
9356
- const bound = emitParamBindingFromArgs(fn.params, " ", fnBodyOpts, "__nudoArgs");
9435
+ const bound = emitParamBindingFromArgs(fn2.params, " ", fnBodyOpts, "__nudoArgs");
9357
9436
  argsSlotPrologue = [` let __nudoArgs = $arguments(__allArgs);`, ...bound.prologue];
9358
9437
  argsParamParts = ["...__allArgs"];
9359
9438
  } else if (hasArgs && hasThis) {
@@ -9370,27 +9449,27 @@ ${mBodyInner}
9370
9449
  ...thisPrologue,
9371
9450
  ...argsSlotPrologue
9372
9451
  ];
9373
- if (fn.body.type === "BlockStatement") {
9452
+ if (fn2.body.type === "BlockStatement") {
9374
9453
  const raw = withImplicitReturn(
9375
- fn.body,
9376
- [...allPrologue, transpileFnBodyStmts(fn.body.body, 1, fnBodyOpts, {
9454
+ fn2.body,
9455
+ [...allPrologue, transpileFnBodyStmts(fn2.body.body, 1, fnBodyOpts, {
9377
9456
  // Bug 21:函数体 var 提升边界——参数模式名已绑定,不得提升
9378
- skip: paramNamesOfFn(fn.params)
9457
+ skip: paramNamesOfFn(fn2.params)
9379
9458
  })].join("\n"),
9380
9459
  1
9381
9460
  );
9382
- const inner = fn.generator ? `return $gen(() => {
9461
+ const inner = fn2.generator ? `return $gen(() => {
9383
9462
  ${raw}
9384
9463
  });` : raw;
9385
9464
  if (hasThis) {
9386
- const wrap = fn.async && !fn.generator ? `function (${argsParamParts.join(", ")}) { return $async(() => {
9465
+ const wrap = fn2.async && !fn2.generator ? `function (${argsParamParts.join(", ")}) { return $async(() => {
9387
9466
  ${inner}
9388
9467
  }); }` : `function (${argsParamParts.join(", ")}) {
9389
9468
  ${inner}
9390
9469
  }`;
9391
9470
  return `$fnVal(${nameList}, ${wrap}, { ctor: ${fnCtor}${hasArgs ? ", padArgs: false" : ""} })`;
9392
9471
  }
9393
- if (fn.async && !fn.generator) {
9472
+ if (fn2.async && !fn2.generator) {
9394
9473
  return `$fnVal(${nameList}, (${argsParamParts.join(", ")}) => $async(() => {
9395
9474
  ${inner}
9396
9475
  }), { ctor: ${fnCtor} })`;
@@ -9399,13 +9478,13 @@ ${inner}
9399
9478
  ${inner}
9400
9479
  }, { ctor: ${fnCtor} })`;
9401
9480
  }
9402
- const bodySrc = transpileExpression(fn.body, fnBodyOpts);
9481
+ const bodySrc = transpileExpression(fn2.body, fnBodyOpts);
9403
9482
  if (allPrologue.length > 0 || hasThis) {
9404
- const rebinds2 = emitArrMutatorRebinds(fn.body, fnBodyOpts, " ");
9483
+ const rebinds2 = emitArrMutatorRebinds(fn2.body, fnBodyOpts, " ");
9405
9484
  const inner = [
9406
9485
  ...allPrologue,
9407
9486
  ...rebinds2.map((l) => ` ${l}`),
9408
- ` return ${fn.async ? `$async(() => ${bodySrc})` : bodySrc};`
9487
+ ` return ${fn2.async ? `$async(() => ${bodySrc})` : bodySrc};`
9409
9488
  ].join("\n");
9410
9489
  if (hasThis) {
9411
9490
  const wrap = `function (${argsParamParts.join(", ")}) {
@@ -9417,17 +9496,17 @@ ${inner}
9417
9496
  ${inner}
9418
9497
  }, { ctor: ${fnCtor} })`;
9419
9498
  }
9420
- const rebinds = emitArrMutatorRebinds(fn.body, fnBodyOpts, " ");
9499
+ const rebinds = emitArrMutatorRebinds(fn2.body, fnBodyOpts, " ");
9421
9500
  if (rebinds.length > 0) {
9422
9501
  const inner = [
9423
9502
  ...rebinds.map((l) => ` ${l}`),
9424
- ` return ${fn.async ? `$async(() => ${bodySrc})` : bodySrc};`
9503
+ ` return ${fn2.async ? `$async(() => ${bodySrc})` : bodySrc};`
9425
9504
  ].join("\n");
9426
9505
  return `$fnVal(${nameList}, (${argsParamParts.join(", ")}) => {
9427
9506
  ${inner}
9428
9507
  }, { ctor: ${fnCtor} })`;
9429
9508
  }
9430
- if (fn.async) {
9509
+ if (fn2.async) {
9431
9510
  return `$fnVal(${nameList}, (${argsParamParts.join(", ")}) => $async(() => ${bodySrc}), { ctor: ${fnCtor} })`;
9432
9511
  }
9433
9512
  return `$fnVal(${nameList}, (${argsParamParts.join(", ")}) => ${bodySrc}, { ctor: ${fnCtor} })`;
@@ -9742,9 +9821,9 @@ var BOOLEAN_PROTO_METHODS = /* @__PURE__ */ new Set(["toString", "valueOf"]);
9742
9821
  var SYMBOL_PROTO_METHODS = /* @__PURE__ */ new Set(["toString", "valueOf"]);
9743
9822
  var BIGINT_PROTO_METHODS = /* @__PURE__ */ new Set(["toString", "toLocaleString", "valueOf"]);
9744
9823
  function notePrimMemberMissing(recv, name, kind, loc) {
9745
- const shape = recv?.shape;
9746
- if (!shape || shape.k !== "prim") return false;
9747
- const t = shape.type;
9824
+ const shape2 = recv?.shape;
9825
+ if (!shape2 || shape2.k !== "prim") return false;
9826
+ const t = shape2.type;
9748
9827
  if (OBJECT_PROTO_NAMES.has(name)) return false;
9749
9828
  const protoMethods = t === "string" ? STRING_METHODS : t === "number" ? NUMBER_PROTO_METHODS : t === "boolean" ? BOOLEAN_PROTO_METHODS : t === "symbol" ? SYMBOL_PROTO_METHODS : t === "bigint" ? BIGINT_PROTO_METHODS : void 0;
9750
9829
  if (!protoMethods) return false;
@@ -9866,9 +9945,9 @@ function runWithEvalMissingSlot(enabled, body) {
9866
9945
  }
9867
9946
  function noteObjSlotMissing(recv, name, loc) {
9868
9947
  if (!isEvalMissingSlotEnabled()) return false;
9869
- const shape = recv?.shape;
9870
- if (!shape || shape.k !== "obj") return false;
9871
- const obj2 = shape;
9948
+ const shape2 = recv?.shape;
9949
+ if (!shape2 || shape2.k !== "obj") return false;
9950
+ const obj2 = shape2;
9872
9951
  if (obj2.open) return false;
9873
9952
  if (obj2.slots && Object.prototype.hasOwnProperty.call(obj2.slots, name)) return false;
9874
9953
  const conf = recv?.conf;
@@ -10760,23 +10839,23 @@ function clampWindow(len, target, start, end) {
10760
10839
  if (count <= 0) return null;
10761
10840
  return { t, s, e: s + count };
10762
10841
  }
10763
- function copyWithinTuple(shape, vals) {
10842
+ function copyWithinTuple(shape2, vals) {
10764
10843
  validateIndexArg(vals[0], "copyWithin target may not be convertible to a number");
10765
10844
  validateIndexArg(vals[1], "copyWithin start may not be convertible to a number");
10766
10845
  validateIndexArg(vals[2], "copyWithin end may not be convertible to a number");
10767
10846
  const t = toIOI(vals[0]);
10768
10847
  const s = toIOI(vals[1]);
10769
10848
  const e = toIOI(vals[2]);
10770
- if (shape.k === "tuple") {
10849
+ if (shape2.k === "tuple") {
10771
10850
  if (t === null || s === null || e === null) {
10772
- const joined = shape.elements.length ? shape.elements.reduce((x, y) => joinAbs(x, y)) : unknown;
10851
+ const joined = shape2.elements.length ? shape2.elements.reduce((x, y) => joinAbs(x, y)) : unknown;
10773
10852
  return abs({ k: "arr", element: joined }, void 0, void 0, "partial");
10774
10853
  }
10775
- const len = shape.elements.length;
10854
+ const len = shape2.elements.length;
10776
10855
  const win = clampWindow(len, t ?? 0, s ?? 0, e ?? len);
10777
- const origHoles = shape.holes ?? [];
10856
+ const origHoles = shape2.holes ?? [];
10778
10857
  if (win) {
10779
- const els = [...shape.elements];
10858
+ const els = [...shape2.elements];
10780
10859
  const holesSet = new Set(origHoles);
10781
10860
  const backwards = win.s < win.t && win.s + (win.e - win.s) > win.t;
10782
10861
  const count = win.e - win.s;
@@ -10804,7 +10883,7 @@ function copyWithinTuple(shape, vals) {
10804
10883
  return abs(
10805
10884
  {
10806
10885
  k: "tuple",
10807
- elements: [...shape.elements],
10886
+ elements: [...shape2.elements],
10808
10887
  holes: origHoles.length > 0 ? [...origHoles] : void 0
10809
10888
  },
10810
10889
  void 0,
@@ -10812,19 +10891,19 @@ function copyWithinTuple(shape, vals) {
10812
10891
  "path"
10813
10892
  );
10814
10893
  }
10815
- return abs({ k: "arr", element: shape.element }, void 0, void 0, "partial");
10894
+ return abs({ k: "arr", element: shape2.element }, void 0, void 0, "partial");
10816
10895
  }
10817
- function fillTuple(shape, vals, arr) {
10896
+ function fillTuple(shape2, vals, arr) {
10818
10897
  validateIndexArg(vals[1], "fill start may not be convertible to a number");
10819
10898
  validateIndexArg(vals[2], "fill end may not be convertible to a number");
10820
10899
  const v2 = vals[0] ?? unknown;
10821
10900
  const s = toIOI(vals[1]);
10822
10901
  const e = toIOI(vals[2]);
10823
- if (shape.k === "tuple") {
10824
- const len = shape.elements.length;
10902
+ if (shape2.k === "tuple") {
10903
+ const len = shape2.elements.length;
10825
10904
  if (s === null || e === null) {
10826
10905
  return abs(
10827
- { k: "tuple", elements: shape.elements.map((el) => joinAbs(el, v2)) },
10906
+ { k: "tuple", elements: shape2.elements.map((el) => joinAbs(el, v2)) },
10828
10907
  void 0,
10829
10908
  void 0,
10830
10909
  "partial"
@@ -10832,16 +10911,16 @@ function fillTuple(shape, vals, arr) {
10832
10911
  }
10833
10912
  const start = Math.max(Math.min((s ?? 0) < 0 ? len + (s ?? 0) : s ?? 0, len), 0);
10834
10913
  const end = Math.max(Math.min((e ?? len) < 0 ? len + (e ?? len) : e ?? len, len), 0);
10835
- const holes = (shape.holes ?? []).filter((h) => h < start || h >= end);
10914
+ const holes = (shape2.holes ?? []).filter((h) => h < start || h >= end);
10836
10915
  if (end <= start) {
10837
10916
  return abs(
10838
- { k: "tuple", elements: [...shape.elements], holes: holes.length > 0 ? holes : void 0 },
10917
+ { k: "tuple", elements: [...shape2.elements], holes: holes.length > 0 ? holes : void 0 },
10839
10918
  void 0,
10840
10919
  void 0,
10841
10920
  "path"
10842
10921
  );
10843
10922
  }
10844
- const els = shape.elements.map((el, i) => i >= start && i < end ? v2 : el);
10923
+ const els = shape2.elements.map((el, i) => i >= start && i < end ? v2 : el);
10845
10924
  return abs(
10846
10925
  { k: "tuple", elements: els, holes: holes.length > 0 ? holes : void 0 },
10847
10926
  void 0,
@@ -10851,7 +10930,7 @@ function fillTuple(shape, vals, arr) {
10851
10930
  }
10852
10931
  const coversAll = (s === void 0 || s === 0) && e === void 0;
10853
10932
  return abs(
10854
- { k: "arr", element: coversAll ? v2 : joinAbs(shape.element, v2) },
10933
+ { k: "arr", element: coversAll ? v2 : joinAbs(shape2.element, v2) },
10855
10934
  void 0,
10856
10935
  void 0,
10857
10936
  confJoin(arr.conf, coversAll ? arr.conf : "path")
@@ -10890,6 +10969,8 @@ function $copy(a) {
10890
10969
  open: s.open
10891
10970
  });
10892
10971
  next.conf = a.conf;
10972
+ next.term = a.term;
10973
+ next.pred = a.pred;
10893
10974
  migrateAccessors(a, next);
10894
10975
  migrateInvariants(a, next);
10895
10976
  migrateNullProto(a, next);
@@ -10914,8 +10995,8 @@ function $copy(a) {
10914
10995
  return a;
10915
10996
  }
10916
10997
  function $arrMutContainer(arr, method, args) {
10917
- const shape = arr.shape;
10918
- if (shape.k !== "tuple" && shape.k !== "arr") return arr;
10998
+ const shape2 = arr.shape;
10999
+ if (shape2.k !== "tuple" && shape2.k !== "arr") return arr;
10919
11000
  const st = extStateOf(arr);
10920
11001
  if (st === "frozen") throwStrictWrite();
10921
11002
  if ((st === "sealed" || st === "nonext") && (method === "push" || method === "unshift" || method === "splice")) {
@@ -10925,9 +11006,9 @@ function $arrMutContainer(arr, method, args) {
10925
11006
  const asArrEl = (els) => els.length > 0 ? els.reduce((x, y) => joinAbs(x, y)) : unknown;
10926
11007
  const writeBack = (next) => writeInPlace(arr, next);
10927
11008
  if (method === "push" || method === "unshift") {
10928
- if (shape.k === "tuple") {
10929
- const els = method === "push" ? [...shape.elements, ...vals] : [...vals, ...shape.elements];
10930
- const holes = shape.holes ? shape.holes.map((h) => method === "push" ? h : h + vals.length) : void 0;
11009
+ if (shape2.k === "tuple") {
11010
+ const els = method === "push" ? [...shape2.elements, ...vals] : [...vals, ...shape2.elements];
11011
+ const holes = shape2.holes ? shape2.holes.map((h) => method === "push" ? h : h + vals.length) : void 0;
10931
11012
  const conf = vals.reduce(
10932
11013
  (acc, v2) => confJoin(acc, v2.conf),
10933
11014
  arr.conf
@@ -10936,19 +11017,19 @@ function $arrMutContainer(arr, method, args) {
10936
11017
  abs({ k: "tuple", elements: els, holes }, void 0, void 0, conf)
10937
11018
  );
10938
11019
  }
10939
- const el = vals.reduce((acc, v2) => joinAbs(acc, v2), shape.element);
11020
+ const el = vals.reduce((acc, v2) => joinAbs(acc, v2), shape2.element);
10940
11021
  return writeBack(
10941
11022
  abs({ k: "arr", element: el }, void 0, void 0, confJoin(arr.conf, "path"))
10942
11023
  );
10943
11024
  }
10944
11025
  if (method === "pop") {
10945
- if (shape.k === "tuple") {
10946
- if (shape.elements.length === 0) return arr;
10947
- const newLen = shape.elements.length - 1;
10948
- const holes = shape.holes ? shape.holes.filter((h) => h < newLen) : void 0;
11026
+ if (shape2.k === "tuple") {
11027
+ if (shape2.elements.length === 0) return arr;
11028
+ const newLen = shape2.elements.length - 1;
11029
+ const holes = shape2.holes ? shape2.holes.filter((h) => h < newLen) : void 0;
10949
11030
  return writeBack(
10950
11031
  abs(
10951
- { k: "tuple", elements: shape.elements.slice(0, -1), holes: holes && holes.length > 0 ? holes : void 0 },
11032
+ { k: "tuple", elements: shape2.elements.slice(0, -1), holes: holes && holes.length > 0 ? holes : void 0 },
10952
11033
  void 0,
10953
11034
  void 0,
10954
11035
  arr.conf
@@ -10958,12 +11039,12 @@ function $arrMutContainer(arr, method, args) {
10958
11039
  return arr;
10959
11040
  }
10960
11041
  if (method === "shift") {
10961
- if (shape.k === "tuple") {
10962
- if (shape.elements.length === 0) return arr;
10963
- const holes = shape.holes ? shape.holes.map((h) => h - 1).filter((h) => h >= 0) : void 0;
11042
+ if (shape2.k === "tuple") {
11043
+ if (shape2.elements.length === 0) return arr;
11044
+ const holes = shape2.holes ? shape2.holes.map((h) => h - 1).filter((h) => h >= 0) : void 0;
10964
11045
  return writeBack(
10965
11046
  abs(
10966
- { k: "tuple", elements: shape.elements.slice(1), holes: holes && holes.length > 0 ? holes : void 0 },
11047
+ { k: "tuple", elements: shape2.elements.slice(1), holes: holes && holes.length > 0 ? holes : void 0 },
10967
11048
  void 0,
10968
11049
  void 0,
10969
11050
  arr.conf
@@ -10975,10 +11056,10 @@ function $arrMutContainer(arr, method, args) {
10975
11056
  if (method === "splice") {
10976
11057
  validateIndexArg(vals[0], "splice start may not be convertible to a number");
10977
11058
  validateIndexArg(vals[1], "splice deleteCount may not be convertible to a number");
10978
- if (shape.k === "tuple") {
11059
+ if (shape2.k === "tuple") {
10979
11060
  return writeBack(
10980
11061
  abs(
10981
- { k: "arr", element: asArrEl(shape.elements) },
11062
+ { k: "arr", element: asArrEl(shape2.elements) },
10982
11063
  void 0,
10983
11064
  void 0,
10984
11065
  confJoin(arr.conf, "path")
@@ -10988,12 +11069,12 @@ function $arrMutContainer(arr, method, args) {
10988
11069
  return arr;
10989
11070
  }
10990
11071
  if (method === "reverse") {
10991
- if (shape.k === "tuple") {
10992
- const len = shape.elements.length;
10993
- const holes = shape.holes ? shape.holes.map((h) => len - 1 - h) : void 0;
11072
+ if (shape2.k === "tuple") {
11073
+ const len = shape2.elements.length;
11074
+ const holes = shape2.holes ? shape2.holes.map((h) => len - 1 - h) : void 0;
10994
11075
  return writeBack(
10995
11076
  abs(
10996
- { k: "tuple", elements: [...shape.elements].reverse(), holes },
11077
+ { k: "tuple", elements: [...shape2.elements].reverse(), holes },
10997
11078
  void 0,
10998
11079
  void 0,
10999
11080
  arr.conf
@@ -11003,19 +11084,19 @@ function $arrMutContainer(arr, method, args) {
11003
11084
  return arr;
11004
11085
  }
11005
11086
  if (method === "copyWithin") {
11006
- return writeBack(copyWithinTuple(shape, vals));
11087
+ return writeBack(copyWithinTuple(shape2, vals));
11007
11088
  }
11008
11089
  if (method === "fill") {
11009
- return writeBack(fillTuple(shape, vals, arr));
11090
+ return writeBack(fillTuple(shape2, vals, arr));
11010
11091
  }
11011
11092
  if (method === "sort") {
11012
11093
  validateCallableArg(vals[0], "sort comparator may not be callable", {
11013
11094
  undefinedOk: true
11014
11095
  });
11015
- if (shape.k === "tuple") {
11096
+ if (shape2.k === "tuple") {
11016
11097
  return writeBack(
11017
11098
  abs(
11018
- { k: "arr", element: asArrEl(shape.elements) },
11099
+ { k: "arr", element: asArrEl(shape2.elements) },
11019
11100
  void 0,
11020
11101
  void 0,
11021
11102
  confJoin(arr.conf, "path")
@@ -11282,9 +11363,9 @@ function $spread(a, b) {
11282
11363
  if (acc && bb.shape.k === "obj") {
11283
11364
  let changed = false;
11284
11365
  const slots = { ...bb.shape.slots };
11285
- for (const [k, fn] of acc) {
11286
- if (fn.get) {
11287
- setSlot(slots, k, { value: fn.get(bb) });
11366
+ for (const [k, fn2] of acc) {
11367
+ if (fn2.get) {
11368
+ setSlot(slots, k, { value: fn2.get(bb) });
11288
11369
  changed = true;
11289
11370
  }
11290
11371
  }
@@ -11342,8 +11423,8 @@ function $objRest(o, keys) {
11342
11423
  }
11343
11424
  if (!isObj(o)) {
11344
11425
  if (o.shape.k === "any") {
11345
- const shape2 = { k: "obj", slots: {}, open: true };
11346
- return { shape: shape2, conf: "partial" };
11426
+ const shape3 = { k: "obj", slots: {}, open: true };
11427
+ return { shape: shape3, conf: "partial" };
11347
11428
  }
11348
11429
  return unknown;
11349
11430
  }
@@ -11355,9 +11436,9 @@ function $objRest(o, keys) {
11355
11436
  setSlot(slots, k, s);
11356
11437
  }
11357
11438
  if (o.shape.open) openRest = true;
11358
- const shape = { k: "obj", slots };
11359
- if (openRest) shape.open = true;
11360
- return { shape, conf: o.conf === "exact" ? "exact" : confJoin(o.conf, "partial") };
11439
+ const shape2 = { k: "obj", slots };
11440
+ if (openRest) shape2.open = true;
11441
+ return { shape: shape2, conf: o.conf === "exact" ? "exact" : confJoin(o.conf, "partial") };
11361
11442
  }
11362
11443
  function $arrRest(a, start) {
11363
11444
  const mi = matchIterElements(a);
@@ -11563,30 +11644,30 @@ function elemsOf(a) {
11563
11644
  return [unknown];
11564
11645
  }
11565
11646
  function $forInKeys(o) {
11566
- const shape = o.shape;
11567
- if (shape.k === "sum") {
11568
- const members = shape.members.map((m) => $forInKeys(m));
11647
+ const shape2 = o.shape;
11648
+ if (shape2.k === "sum") {
11649
+ const members = shape2.members.map((m) => $forInKeys(m));
11569
11650
  return members.length ? members.reduce((a, b) => joinAbs(a, b)) : unknown;
11570
11651
  }
11571
11652
  const isArrayIndexKey = (k) => {
11572
11653
  const n = Number(k);
11573
11654
  return k !== "" && String(n) === k && Number.isInteger(n) && n >= 0 && n < 4294967295;
11574
11655
  };
11575
- if (shape.k === "obj") {
11576
- const keys = enumOwnKeys(o, shape.slots);
11656
+ if (shape2.k === "obj") {
11657
+ const keys = enumOwnKeys(o, shape2.slots);
11577
11658
  const intKeys = keys.filter(isArrayIndexKey).sort((a, b) => Number(a) - Number(b));
11578
11659
  const strKeys = keys.filter((k) => !isArrayIndexKey(k));
11579
11660
  return $arr([...intKeys, ...strKeys].map((k) => $lit(k)));
11580
11661
  }
11581
- if (shape.k === "tuple") {
11662
+ if (shape2.k === "tuple") {
11582
11663
  const idxs = [];
11583
- for (let i = 0; i < shape.elements.length; i++) {
11584
- if (shape.holes?.includes(i)) continue;
11664
+ for (let i = 0; i < shape2.elements.length; i++) {
11665
+ if (shape2.holes?.includes(i)) continue;
11585
11666
  idxs.push(i);
11586
11667
  }
11587
11668
  return $arr(idxs.map((i) => $lit(String(i))));
11588
11669
  }
11589
- if (shape.k === "arr") {
11670
+ if (shape2.k === "arr") {
11590
11671
  return abs({ k: "arr", element: $lit("0") }, void 0, void 0, "partial");
11591
11672
  }
11592
11673
  const svR = litValue(o);
@@ -11595,11 +11676,11 @@ function $forInKeys(o) {
11595
11676
  return $arr(Array.from({ length: sv.length }, (_, i) => $lit(String(i))));
11596
11677
  }
11597
11678
  const isNullishLit2 = o.term?.op === "lit" && (o.term.value === null || o.term.value === void 0);
11598
- if (!isNullishLit2 && (shape.k === "any" || shape.k === "unknown" || shape.k === "prim" && shape.type === "string")) {
11679
+ if (!isNullishLit2 && (shape2.k === "any" || shape2.k === "unknown" || shape2.k === "prim" && shape2.type === "string")) {
11599
11680
  return abs({ k: "arr", element: str() }, void 0, void 0, "partial");
11600
11681
  }
11601
- if (shape.k === "brand") {
11602
- const inner = shape.shape;
11682
+ if (shape2.k === "brand") {
11683
+ const inner = shape2.shape;
11603
11684
  if (inner.shape.k === "obj") {
11604
11685
  const keys = enumOwnKeys(inner, inner.shape.slots);
11605
11686
  return $arr(keys.map((k) => $lit(k)));
@@ -11625,9 +11706,9 @@ function $forOf(iterable, body, maxIters = DEFAULT_MAX_LOOP_ITERS, opts) {
11625
11706
  if (!exitJoin || !pack || !unpack) return;
11626
11707
  unpack(joinAbs(exitJoin, pack()));
11627
11708
  };
11628
- const shape = iterable.shape;
11709
+ const shape2 = iterable.shape;
11629
11710
  const forAwait = opts?.forAwait === true;
11630
- const asyncOnly = forAwait && shape.k === "obj" && !shape.slots["@@iterator"] && !!shape.slots["@@asyncIterator"];
11711
+ const asyncOnly = forAwait && shape2.k === "obj" && !shape2.slots["@@iterator"] && !!shape2.slots["@@asyncIterator"];
11631
11712
  if (forAwait) {
11632
11713
  const kind = asyncIterabilityKind(iterable);
11633
11714
  if (kind === "definite") throw new NudoThrow(errorTypeAbs("TypeError"));
@@ -11642,7 +11723,7 @@ function $forOf(iterable, body, maxIters = DEFAULT_MAX_LOOP_ITERS, opts) {
11642
11723
  const items = asyncOnly ? [unknown] : forAwait ? elemsOf(iterable).map(awaitElem) : $elems(iterable);
11643
11724
  const svR = litValue(iterable);
11644
11725
  const sv = svR.ok ? svR.value : void 0;
11645
- const knownLen = shape.k === "tuple" ? shape.elements.length : typeof sv === "string" ? [...sv].length : collectionExactLen(iterable) ?? sideIterLen(iterable);
11726
+ const knownLen = shape2.k === "tuple" ? shape2.elements.length : typeof sv === "string" ? [...sv].length : collectionExactLen(iterable) ?? sideIterLen(iterable);
11646
11727
  const unbounded = knownLen === void 0;
11647
11728
  if (unbounded) snapExit();
11648
11729
  const concreteCap = Math.max(maxIters, MAX_CONCRETE_LOOP_ITERS);
@@ -12061,9 +12142,9 @@ function $set(o, key, value) {
12061
12142
  }
12062
12143
  return o;
12063
12144
  }
12064
- const shape = o.shape;
12145
+ const shape2 = o.shape;
12065
12146
  const st = extStateOf(o);
12066
- const hasKey = Object.prototype.hasOwnProperty.call(shape.slots, key);
12147
+ const hasKey = Object.prototype.hasOwnProperty.call(shape2.slots, key);
12067
12148
  if (st === "frozen") throwStrictWrite();
12068
12149
  if ((st === "sealed" || st === "nonext") && !hasKey) throwStrictWrite();
12069
12150
  if (getPropFlags(o)?.get(key)?.writable === false) throwStrictWrite();
@@ -12075,7 +12156,7 @@ function $set(o, key, value) {
12075
12156
  if (key === "__proto__" && !isNullProtoObj(o)) {
12076
12157
  return $setProto(o, value);
12077
12158
  }
12078
- setSlot(shape.slots, key, { value: asAbsVal(value) });
12159
+ setSlot(shape2.slots, key, { value: asAbsVal(value) });
12079
12160
  o.conf = confJoin(o.conf, value.conf);
12080
12161
  clearStaleTermPred(o);
12081
12162
  return o;
@@ -12235,7 +12316,7 @@ function instanceOf(left, rightClassName, env) {
12235
12316
  term: { op: "lit", value: v2 },
12236
12317
  conf: "exact"
12237
12318
  });
12238
- const partial = () => ({ shape: { k: "prim", type: "boolean" }, conf: "partial" });
12319
+ const partial2 = () => ({ shape: { k: "prim", type: "boolean" }, conf: "partial" });
12239
12320
  switch (left.shape.k) {
12240
12321
  case "brand": {
12241
12322
  if (rightClassName === "Object") return t(true);
@@ -12245,28 +12326,28 @@ function instanceOf(left, rightClassName, env) {
12245
12326
  case "tuple":
12246
12327
  if (rightClassName === "Array" || rightClassName === "Object") return t(true);
12247
12328
  if (BUILTIN_CTOR_NAMES2.has(rightClassName)) return t(false);
12248
- return partial();
12329
+ return partial2();
12249
12330
  // 可能是 Array 子类
12250
12331
  case "obj":
12251
12332
  if (rightClassName === "Object") return t(true);
12252
12333
  if (BUILTIN_CTOR_NAMES2.has(rightClassName)) return t(false);
12253
- return partial();
12334
+ return partial2();
12254
12335
  case "fn":
12255
12336
  if (rightClassName === "Function" || rightClassName === "Object") return t(true);
12256
12337
  if (BUILTIN_CTOR_NAMES2.has(rightClassName)) return t(false);
12257
- return partial();
12338
+ return partial2();
12258
12339
  case "eff":
12259
12340
  if (left.shape.eff === "promise") {
12260
12341
  if (rightClassName === "Promise" || rightClassName === "Object") return t(true);
12261
12342
  if (BUILTIN_CTOR_NAMES2.has(rightClassName)) return t(false);
12262
- return partial();
12343
+ return partial2();
12263
12344
  }
12264
12345
  if (left.shape.eff === "generator") {
12265
12346
  if (rightClassName === "Generator" || rightClassName === "Object") return t(true);
12266
12347
  if (BUILTIN_CTOR_NAMES2.has(rightClassName)) return t(false);
12267
- return partial();
12348
+ return partial2();
12268
12349
  }
12269
- return partial();
12350
+ return partial2();
12270
12351
  case "prim":
12271
12352
  return t(false);
12272
12353
  // 原始值无装箱
@@ -12625,13 +12706,13 @@ function setGenJoinOverride(v2) {
12625
12706
  function bumpGenPathSensitive() {
12626
12707
  genPathSensitive++;
12627
12708
  }
12628
- function withIsolatedYields(fn) {
12709
+ function withIsolatedYields(fn2) {
12629
12710
  const top = yieldStack[yieldStack.length - 1];
12630
- if (!top) return { v: fn(), ys: null };
12711
+ if (!top) return { v: fn2(), ys: null };
12631
12712
  const armYs = [];
12632
12713
  yieldStack[yieldStack.length - 1] = armYs;
12633
12714
  try {
12634
- return { v: fn(), ys: armYs };
12715
+ return { v: fn2(), ys: armYs };
12635
12716
  } finally {
12636
12717
  yieldStack[yieldStack.length - 1] = top;
12637
12718
  }
@@ -13054,10 +13135,10 @@ function $switch(disc, cases, dflt) {
13054
13135
  beginCollectionFork();
13055
13136
  const armOverlays2 = [];
13056
13137
  const armYsList = [];
13057
- const runArm = (fn) => {
13138
+ const runArm = (fn2) => {
13058
13139
  pushCollectionArm();
13059
13140
  try {
13060
- const r = withIsolatedYields(() => runForkArm(fn, exits));
13141
+ const r = withIsolatedYields(() => runForkArm(fn2, exits));
13061
13142
  armYsList.push(r.ys);
13062
13143
  return r.v;
13063
13144
  } finally {
@@ -13503,6 +13584,773 @@ var BoundedLruMap = class {
13503
13584
  }
13504
13585
  };
13505
13586
 
13587
+ // src/algebra/constraint.ts
13588
+ var SELF = "__nudo_self__";
13589
+ function selfTerm() {
13590
+ return v(SELF);
13591
+ }
13592
+ function getTerm(obj2, key) {
13593
+ return app("get", [obj2, lit(key)]);
13594
+ }
13595
+ function lenTerm(t) {
13596
+ return app("length", [t]);
13597
+ }
13598
+ function isConstraint(x) {
13599
+ return !!x && typeof x === "object" && x.__nudoConstraint === true;
13600
+ }
13601
+ function isNudoConstraint(x) {
13602
+ return isConstraint(x);
13603
+ }
13604
+ var intFlaggedBuilders = /* @__PURE__ */ new WeakSet();
13605
+ function isIntFlag(c) {
13606
+ return c.int === true || intFlaggedBuilders.has(c);
13607
+ }
13608
+ function makeBuilder(prim, preds, extra) {
13609
+ const fields = extra?.fields;
13610
+ const element = extra?.element;
13611
+ const isInt = extra?.int;
13612
+ const optional = extra?.optional;
13613
+ const members = extra?.members;
13614
+ const fnSlot = extra?.fn;
13615
+ const lazySlot = extra?.lazy;
13616
+ const base = {
13617
+ __nudoConstraint: true,
13618
+ ...prim ? { prim } : {},
13619
+ preds: [...preds],
13620
+ ...fields ? { fields } : {},
13621
+ ...element ? { element } : {},
13622
+ ...optional ? { isOptional: true } : {},
13623
+ ...members ? { members } : {},
13624
+ ...fnSlot ? { fn: fnSlot } : {},
13625
+ ...lazySlot ? { lazy: lazySlot } : {}
13626
+ };
13627
+ const add2 = (p) => makeBuilder(prim, [...preds, p], extra);
13628
+ const builder = Object.assign(
13629
+ /* @__PURE__ */ Object.create(null),
13630
+ base,
13631
+ {
13632
+ gt: (n) => add2(gt(selfTerm(), lit(n))),
13633
+ ge: (n) => add2(ge(selfTerm(), lit(n))),
13634
+ lt: (n) => add2(lt(selfTerm(), lit(n))),
13635
+ le: (n) => add2(le(selfTerm(), lit(n))),
13636
+ int: () => makeBuilder(prim ?? "number", preds, { ...extra, int: true }),
13637
+ min: (n) => add2(ge(lenTerm(selfTerm()), lit(n))),
13638
+ max: (n) => add2(le(lenTerm(selfTerm()), lit(n))),
13639
+ length: (n) => add2(and(ge(lenTerm(selfTerm()), lit(n)), le(lenTerm(selfTerm()), lit(n)))),
13640
+ shift: (n) => {
13641
+ if (!Number.isFinite(n))
13642
+ throw new Error("nudo shift(): offset must be a finite number");
13643
+ if (fields || element || members || fnSlot || lazySlot)
13644
+ throw new Error("nudo shift(): only numeric scalar constraint chains are allowed (shape/array/union/fn are not supported)");
13645
+ if (prim !== void 0 && prim !== "number")
13646
+ throw new Error(`nudo shift(): only numeric chains are allowed (prim=${prim})`);
13647
+ return makeBuilder(prim, shiftBoundPreds(preds, n), extra);
13648
+ },
13649
+ optional: () => makeBuilder(prim, preds, { ...extra, optional: true })
13650
+ }
13651
+ );
13652
+ if (isInt) intFlaggedBuilders.add(builder);
13653
+ return builder;
13654
+ }
13655
+ function shiftBoundPreds(preds, n) {
13656
+ return preds.map((p) => {
13657
+ if (p.op !== "gt" && p.op !== "ge" && p.op !== "lt" && p.op !== "le")
13658
+ throw new Error(`nudo shift(): predicate ${p.op} is not supported (only gt/ge/lt/le constant bounds)`);
13659
+ const { a, b } = p;
13660
+ if (b.op !== "lit" || typeof b.value !== "number")
13661
+ throw new Error("nudo shift(): the right-hand side of a constant bound must be a numeric literal");
13662
+ if (termHasApp(a, "length") || termHasApp(b, "length"))
13663
+ throw new Error("nudo shift(): length(...) bounds are not supported");
13664
+ return { op: p.op, a, b: lit(b.value + n) };
13665
+ });
13666
+ }
13667
+ function termHasApp(t, fn2) {
13668
+ if (t.op !== "app") return false;
13669
+ if (t.fn === fn2) return true;
13670
+ return t.args.some((x) => termHasApp(x, fn2));
13671
+ }
13672
+ function number() {
13673
+ return makeBuilder("number", []);
13674
+ }
13675
+ function string() {
13676
+ return makeBuilder("string", []);
13677
+ }
13678
+ function boolean() {
13679
+ return makeBuilder("boolean", []);
13680
+ }
13681
+ function any() {
13682
+ return makeBuilder(void 0, []);
13683
+ }
13684
+ function array(item) {
13685
+ return makeBuilder(void 0, [], {
13686
+ element: asNestedConstraint(item, "array(item)")
13687
+ });
13688
+ }
13689
+ function shape(fields) {
13690
+ const mapped = {};
13691
+ for (const [k, v2] of Object.entries(fields)) {
13692
+ const constraint = asNestedConstraint(v2, `shape \u5B57\u6BB5 '${k}'`);
13693
+ mapped[k] = {
13694
+ constraint,
13695
+ ...constraint.isOptional ? { optional: true } : {}
13696
+ };
13697
+ }
13698
+ return makeBuilder(void 0, [], { fields: mapped });
13699
+ }
13700
+ function toPlainConstraint(c) {
13701
+ if (!isConstraint(c))
13702
+ throw new Error("nudo: expected a constraint value (number()/string()/\u2026 or a combinator)");
13703
+ return {
13704
+ __nudoConstraint: true,
13705
+ ...c.prim ? { prim: c.prim } : {},
13706
+ preds: [...c.preds],
13707
+ ...c.fields ? { fields: c.fields } : {},
13708
+ ...c.element ? { element: c.element } : {},
13709
+ // isIntFlag 统一读取:builder(int 是方法)查 WeakSet,纯数据看 === true
13710
+ ...isIntFlag(c) ? { int: true } : {},
13711
+ ...c.isOptional ? { isOptional: true } : {},
13712
+ ...c.members ? { members: c.members } : {},
13713
+ ...c.fn ? { fn: c.fn } : {},
13714
+ ...c.lazy ? { lazy: c.lazy } : {}
13715
+ };
13716
+ }
13717
+ function litC(v2) {
13718
+ const prim = typeof v2 === "number" ? "number" : typeof v2 === "string" ? "string" : typeof v2 === "boolean" ? "boolean" : void 0;
13719
+ return makeBuilder(prim, [eq(selfTerm(), lit(v2))]);
13720
+ }
13721
+ function asNestedConstraint(x, ctx2) {
13722
+ if (isConstraint(x)) return toPlainConstraint(x);
13723
+ if (x === null || x === void 0 || typeof x === "number" || typeof x === "string" || typeof x === "boolean") {
13724
+ return toPlainConstraint(litC(x));
13725
+ }
13726
+ throw new Error(
13727
+ `nudo: ${ctx2} expects a constraint value (number()/string()/\u2026) or a concrete literal; received a non-constraint`
13728
+ );
13729
+ }
13730
+ function union(...cs) {
13731
+ if (cs.length === 0)
13732
+ throw new Error("nudo union(): at least one member constraint is required");
13733
+ return makeBuilder(void 0, [], {
13734
+ members: cs.map((c) => asNestedConstraint(c, "union member"))
13735
+ });
13736
+ }
13737
+ function nullable(c) {
13738
+ return makeBuilder(void 0, [], {
13739
+ members: [
13740
+ asNestedConstraint(c, "nullable()"),
13741
+ toPlainConstraint(litC(null)),
13742
+ toPlainConstraint(litC(void 0))
13743
+ ]
13744
+ });
13745
+ }
13746
+ function lazy(thunk) {
13747
+ if (typeof thunk !== "function")
13748
+ throw new Error("nudo lazy(): expects a thunk function () => constraint");
13749
+ return makeBuilder(void 0, [], { lazy: thunk });
13750
+ }
13751
+ var LAZY_TEMPLATE_DEPTH = 3;
13752
+ var lazyDerefMemo = /* @__PURE__ */ new WeakMap();
13753
+ function derefConstraint(c) {
13754
+ const thunk = c.lazy;
13755
+ if (!thunk) return c;
13756
+ const memoized = lazyDerefMemo.get(thunk);
13757
+ if (memoized) return memoized;
13758
+ const out = thunk();
13759
+ if (!isConstraint(out))
13760
+ throw new Error(
13761
+ "nudo lazy(): the thunk must return a constraint (number()/string()/shape()/\u2026)"
13762
+ );
13763
+ const normalized = toPlainConstraint(out);
13764
+ lazyDerefMemo.set(thunk, normalized);
13765
+ return normalized;
13766
+ }
13767
+ function constraintAdmitsNullish(c, seen) {
13768
+ if (c.lazy) {
13769
+ const s = seen ?? /* @__PURE__ */ new Set();
13770
+ if (s.has(c.lazy)) return false;
13771
+ s.add(c.lazy);
13772
+ return constraintAdmitsNullish(derefConstraint(c), s);
13773
+ }
13774
+ if (c.members)
13775
+ return c.members.some((m) => constraintAdmitsNullish(m, seen));
13776
+ if (!c.prim && c.preds.length === 0 && !c.fields && !c.element && !c.fn) return true;
13777
+ for (const p of c.preds) {
13778
+ for (const flat of p.op === "and" ? p.args : [p]) {
13779
+ if (flat.op !== "eq") continue;
13780
+ for (const side of [flat.a, flat.b]) {
13781
+ if (side.op === "lit" && (side.value === null || side.value === void 0)) return true;
13782
+ }
13783
+ }
13784
+ }
13785
+ return false;
13786
+ }
13787
+ function fn(params, returns, opts) {
13788
+ const normalized = {};
13789
+ for (const [k, v2] of Object.entries(params)) {
13790
+ normalized[k] = asNestedConstraint(v2, `fn param '${k}'`);
13791
+ }
13792
+ return makeBuilder(void 0, [], {
13793
+ fn: {
13794
+ params: normalized,
13795
+ ...returns !== void 0 ? { returns: asNestedConstraint(returns, "fn return value") } : {},
13796
+ ...opts?.throws !== void 0 ? { throws: asNestedConstraint(opts.throws, "fn throws") } : {}
13797
+ }
13798
+ });
13799
+ }
13800
+ function andC(...cs) {
13801
+ if (cs.length === 0)
13802
+ throw new Error("nudo and(): at least one constraint is required");
13803
+ let prim;
13804
+ let isInt = false;
13805
+ let allOptional = true;
13806
+ const preds = [];
13807
+ for (const c0 of cs) {
13808
+ if (!isConstraint(c0))
13809
+ throw new Error("nudo: expected a constraint value (number()/string()/\u2026 or a combinator)");
13810
+ const c = derefConstraint(c0);
13811
+ if (c.fields || c.element || c.members || c.fn)
13812
+ throw new Error("nudo and(): Phase 1 supports scalar constraint conjunction only (shape/array/union/fn are not supported)");
13813
+ if (c.prim) {
13814
+ if (prim !== void 0 && prim !== c.prim)
13815
+ throw new Error(`nudo and(): inconsistent prim (${prim} vs ${c.prim})`);
13816
+ prim = c.prim;
13817
+ }
13818
+ preds.push(...c.preds);
13819
+ if (isIntFlag(c)) isInt = true;
13820
+ if (!c.isOptional) allOptional = false;
13821
+ }
13822
+ return makeBuilder(prim, preds, {
13823
+ ...isInt ? { int: true } : {},
13824
+ ...allOptional ? { optional: true } : {}
13825
+ });
13826
+ }
13827
+ function partial(c) {
13828
+ if (!isConstraint(c))
13829
+ throw new Error("nudo partial(): only shape(...) constraints are accepted");
13830
+ const d = derefConstraint(c);
13831
+ if (!d.fields)
13832
+ throw new Error("nudo partial(): only shape(...) constraints are accepted");
13833
+ const fields = {};
13834
+ for (const [k, f] of Object.entries(d.fields)) {
13835
+ fields[k] = {
13836
+ constraint: { ...toPlainConstraint(f.constraint), isOptional: true },
13837
+ optional: true
13838
+ };
13839
+ }
13840
+ return makeBuilder(d.prim, d.preds, { fields });
13841
+ }
13842
+ function pick(c, keys) {
13843
+ if (!isConstraint(c))
13844
+ throw new Error("nudo pick(): only shape(...) constraints are accepted");
13845
+ const d = derefConstraint(c);
13846
+ if (!d.fields)
13847
+ throw new Error("nudo pick(): only shape(...) constraints are accepted");
13848
+ const fields = {};
13849
+ for (const k of keys) {
13850
+ const f = d.fields[k];
13851
+ if (f) fields[k] = f;
13852
+ }
13853
+ return makeBuilder(d.prim, d.preds, { fields });
13854
+ }
13855
+ function omit(c, keys) {
13856
+ if (!isConstraint(c))
13857
+ throw new Error("nudo omit(): only shape(...) constraints are accepted");
13858
+ const d = derefConstraint(c);
13859
+ if (!d.fields)
13860
+ throw new Error("nudo omit(): only shape(...) constraints are accepted");
13861
+ const drop = new Set(keys);
13862
+ const fields = {};
13863
+ for (const [k, f] of Object.entries(d.fields)) {
13864
+ if (!drop.has(k)) fields[k] = f;
13865
+ }
13866
+ return makeBuilder(d.prim, d.preds, { fields });
13867
+ }
13868
+ var CONSTRAINT_BUILDERS = {
13869
+ number,
13870
+ string,
13871
+ boolean,
13872
+ any,
13873
+ array,
13874
+ shape,
13875
+ lit: litC,
13876
+ union,
13877
+ nullable,
13878
+ lazy,
13879
+ fn,
13880
+ and: andC,
13881
+ partial,
13882
+ pick,
13883
+ omit
13884
+ };
13885
+ var CONSTRAINT_BUILDER_NAMES = Object.keys(
13886
+ CONSTRAINT_BUILDERS
13887
+ );
13888
+ var CONSTRAINT_EXPR_RE = new RegExp(
13889
+ `^(${CONSTRAINT_BUILDER_NAMES.join("|")})\\s*\\(`
13890
+ );
13891
+ function substTerm(t, paramName) {
13892
+ if (t.op === "var" && t.id === SELF) return v(paramName);
13893
+ if (t.op === "app" && t.fn === "get" && t.args.length === 2) {
13894
+ return getTerm(substTerm(t.args[0], paramName), String(
13895
+ t.args[1].op === "lit" ? t.args[1].value : ""
13896
+ ));
13897
+ }
13898
+ return t;
13899
+ }
13900
+ function substPred2(p, paramName) {
13901
+ switch (p.op) {
13902
+ case "gt":
13903
+ case "ge":
13904
+ case "lt":
13905
+ case "le":
13906
+ case "eq":
13907
+ case "ne": {
13908
+ return { op: p.op, a: substTerm(p.a, paramName), b: substTerm(p.b, paramName) };
13909
+ }
13910
+ case "typeof": {
13911
+ return { op: "typeof", t: substTerm(p.t, paramName), type: p.type };
13912
+ }
13913
+ case "and":
13914
+ return and(...p.args.map((x) => substPred2(x, paramName)));
13915
+ default:
13916
+ return p;
13917
+ }
13918
+ }
13919
+ function instantiateConstraint(c, paramName, depth = LAZY_TEMPLATE_DEPTH) {
13920
+ if (c.lazy) {
13921
+ if (depth <= 0) return pTrue;
13922
+ return instantiateConstraint(derefConstraint(c), paramName, depth - 1);
13923
+ }
13924
+ if (c.fields) {
13925
+ const parts = [];
13926
+ for (const [key, field] of Object.entries(c.fields)) {
13927
+ if (field.optional || field.constraint.isOptional) continue;
13928
+ const fieldTerm = getTerm(v(paramName), key);
13929
+ parts.push(instantiateOnTerm(field.constraint, fieldTerm, depth));
13930
+ }
13931
+ if (c.prim) parts.push(ptypeof(v(paramName), primToTypeof(c.prim)));
13932
+ if (parts.length === 0) return { op: "true" };
13933
+ return parts.length === 1 ? parts[0] : and(...parts);
13934
+ }
13935
+ if (c.members) {
13936
+ const disj = or(
13937
+ ...c.members.map((m) => instantiateOnTerm(m, v(paramName), depth))
13938
+ );
13939
+ const own = c.preds.map((p) => substPred2(p, paramName));
13940
+ return own.length === 0 ? disj : and(...own, disj);
13941
+ }
13942
+ if (c.fn) {
13943
+ const own = c.preds.map((p) => substPred2(p, paramName));
13944
+ return own.length === 0 ? pTrue : and(...own);
13945
+ }
13946
+ const preds = c.preds.map((p) => substPred2(p, paramName));
13947
+ if (c.prim && c.preds.length === 0) {
13948
+ return ptypeof(v(paramName), primToTypeof(c.prim));
13949
+ }
13950
+ return preds.length === 0 ? { op: "true" } : preds.length === 1 ? preds[0] : and(...preds);
13951
+ }
13952
+ function instantiateOnTerm(c, t, depth = LAZY_TEMPLATE_DEPTH) {
13953
+ if (c.lazy) {
13954
+ if (depth <= 0) return pTrue;
13955
+ return instantiateOnTerm(derefConstraint(c), t, depth - 1);
13956
+ }
13957
+ const subst = (p) => {
13958
+ switch (p.op) {
13959
+ case "gt":
13960
+ case "ge":
13961
+ case "lt":
13962
+ case "le":
13963
+ case "eq":
13964
+ case "ne": {
13965
+ const a = p.a.op === "var" && p.a.id === SELF ? t : p.a;
13966
+ const b = p.b.op === "var" && p.b.id === SELF ? t : p.b;
13967
+ return { op: p.op, a, b };
13968
+ }
13969
+ case "typeof": {
13970
+ const tt = p.t.op === "var" && p.t.id === SELF ? t : p.t;
13971
+ return { op: "typeof", t: tt, type: p.type };
13972
+ }
13973
+ case "and":
13974
+ return and(...p.args.map(subst));
13975
+ default:
13976
+ return p;
13977
+ }
13978
+ };
13979
+ if (c.fields) {
13980
+ const parts = [];
13981
+ for (const [key, field] of Object.entries(c.fields)) {
13982
+ if (field.optional || field.constraint.isOptional) continue;
13983
+ parts.push(instantiateOnTerm(field.constraint, getTerm(t, key), depth));
13984
+ }
13985
+ if (parts.length === 0) return { op: "true" };
13986
+ return parts.length === 1 ? parts[0] : and(...parts);
13987
+ }
13988
+ if (c.members) {
13989
+ const disj = or(...c.members.map((m) => instantiateOnTerm(m, t, depth)));
13990
+ const own = c.preds.map(subst);
13991
+ return own.length === 0 ? disj : and(...own, disj);
13992
+ }
13993
+ if (c.fn) {
13994
+ const own = c.preds.map(subst);
13995
+ return own.length === 0 ? pTrue : and(...own);
13996
+ }
13997
+ const preds = c.preds.map(subst);
13998
+ if (c.prim && c.preds.length === 0) return ptypeof(t, primToTypeof(c.prim));
13999
+ return preds.length === 0 ? { op: "true" } : preds.length === 1 ? preds[0] : and(...preds);
14000
+ }
14001
+ function constraintToEntryAbs(c, paramName, depth = LAZY_TEMPLATE_DEPTH) {
14002
+ const t = v(paramName);
14003
+ if (c.fields) {
14004
+ const slots = {};
14005
+ for (const [key, field] of Object.entries(c.fields)) {
14006
+ if (field.constraint.lazy && depth <= 0) continue;
14007
+ const fieldTerm = getTerm(t, key);
14008
+ slots[key] = {
14009
+ value: constraintOnTermAbs(field.constraint, fieldTerm, depth),
14010
+ ...field.optional || field.constraint.isOptional ? { optional: true } : {}
14011
+ };
14012
+ }
14013
+ return abs({ k: "obj", slots }, t, void 0, "path");
14014
+ }
14015
+ return constraintOnTermAbs(c, t, depth);
14016
+ }
14017
+ function memberLitValue(m) {
14018
+ const leaves = [];
14019
+ const visit = (p2) => {
14020
+ if (p2.op === "and") {
14021
+ p2.args.forEach(visit);
14022
+ return;
14023
+ }
14024
+ leaves.push(p2);
14025
+ };
14026
+ m.preds.forEach(visit);
14027
+ if (leaves.length !== 1) return { ok: false };
14028
+ const p = leaves[0];
14029
+ if (p.op !== "eq") return { ok: false };
14030
+ if (p.a.op === "var" && p.b.op === "lit") {
14031
+ return { ok: true, v: p.b.value };
14032
+ }
14033
+ if (p.b.op === "var" && p.a.op === "lit") {
14034
+ return { ok: true, v: p.a.value };
14035
+ }
14036
+ return { ok: false };
14037
+ }
14038
+ function samePrimLiteralUnionAbs(members, t) {
14039
+ if (members.length === 0) return void 0;
14040
+ const values = [];
14041
+ let prim;
14042
+ for (const m of members) {
14043
+ const mk = memberLitValue(m);
14044
+ if (!mk.ok) return void 0;
14045
+ const v2 = mk.v;
14046
+ if (v2 === void 0 || v2 === null) return void 0;
14047
+ const mp = m.prim ?? (typeof v2 === "number" ? "number" : typeof v2 === "string" ? "string" : "boolean");
14048
+ if (prim === void 0) prim = mp;
14049
+ else if (prim !== mp) return void 0;
14050
+ values.push(v2);
14051
+ }
14052
+ if (prim === void 0) return void 0;
14053
+ const uniq = [];
14054
+ for (const v2 of values) {
14055
+ if (!uniq.some((u) => Object.is(u, v2))) uniq.push(v2);
14056
+ }
14057
+ const disj = or(
14058
+ ...uniq.map((v2) => eq(t, lit(v2)))
14059
+ );
14060
+ return abs({ k: "prim", type: prim }, t, disj, "path");
14061
+ }
14062
+ function constraintOnTermAbs(c, t, depth) {
14063
+ if (c.lazy) {
14064
+ if (depth <= 0) return abs({ k: "any" }, t, void 0, "path");
14065
+ return constraintOnTermAbs(derefConstraint(c), t, depth - 1);
14066
+ }
14067
+ if (c.fields) {
14068
+ const slots = {};
14069
+ for (const [key, field] of Object.entries(c.fields)) {
14070
+ if (field.constraint.lazy && depth <= 0) continue;
14071
+ slots[key] = {
14072
+ value: constraintOnTermAbs(field.constraint, getTerm(t, key), depth),
14073
+ ...field.optional || field.constraint.isOptional ? { optional: true } : {}
14074
+ };
14075
+ }
14076
+ return abs({ k: "obj", slots }, t, void 0, "path");
14077
+ }
14078
+ if (c.members) {
14079
+ const litUnion = samePrimLiteralUnionAbs(c.members, t);
14080
+ if (litUnion) return litUnion;
14081
+ const joined = c.members.map((m) => constraintOnTermAbs(m, t, depth)).reduce((a, b) => joinAbs(a, b));
14082
+ if (joined.shape.k === "prim" && joined.pred === void 0 && c.members.every((m) => m.prim === joined.shape.type)) {
14083
+ const type = joined.shape.type;
14084
+ return abs({ k: "prim", type }, t, ptypeof(t, primToTypeof(type)), "path");
14085
+ }
14086
+ return joined;
14087
+ }
14088
+ if (c.fn) {
14089
+ const paramNames = Object.keys(c.fn.params);
14090
+ const paramTypes = paramNames.map(
14091
+ (p, i) => constraintOnTermAbs(c.fn.params[p], v(`x${i}`), depth)
14092
+ );
14093
+ const returnType = c.fn.returns ? constraintOnTermAbs(c.fn.returns, v("ret"), depth) : unknown;
14094
+ return abs(
14095
+ { k: "fn", params: paramNames, paramTypes, returnType },
14096
+ t,
14097
+ void 0,
14098
+ "path"
14099
+ );
14100
+ }
14101
+ if (c.element) {
14102
+ const elem = constraintOnTermAbs(c.element, v("x[]"), depth);
14103
+ return abs({ k: "arr", element: elem }, t, void 0, "path");
14104
+ }
14105
+ const pred = instantiateOnTerm(c, t, depth);
14106
+ const predOut = pred.op === "true" ? void 0 : pred;
14107
+ if (c.prim) {
14108
+ return abs({ k: "prim", type: c.prim }, t, predOut, "path");
14109
+ }
14110
+ const allEqNullish = c.preds.length > 0 && c.preds.every(
14111
+ (p) => p.op === "eq" && (p.b.op === "lit" && (p.b.value === null || p.b.value === void 0) || p.a.op === "lit" && (p.a.value === null || p.a.value === void 0))
14112
+ );
14113
+ if (allEqNullish) {
14114
+ let nullish = null;
14115
+ for (const p of c.preds) {
14116
+ if (p.op !== "eq") continue;
14117
+ if (p.b.op === "lit" && (p.b.value === null || p.b.value === void 0)) {
14118
+ nullish = p.b.value;
14119
+ break;
14120
+ }
14121
+ if (p.a.op === "lit" && (p.a.value === null || p.a.value === void 0)) {
14122
+ nullish = p.a.value;
14123
+ break;
14124
+ }
14125
+ }
14126
+ return abs({ k: "unknown" }, lit(nullish), void 0, "path");
14127
+ }
14128
+ if (c.preds.length > 0) {
14129
+ return abs({ k: "prim", type: "number" }, t, predOut, "path");
14130
+ }
14131
+ return abs({ k: "any" }, t, void 0, "path");
14132
+ }
14133
+ function fnConstraintToEntryReqs(c) {
14134
+ if (!c.fn) throw new Error("nudo fnConstraintToEntryReqs(): constraint is not in fn() form");
14135
+ return Object.entries(c.fn.params).map(([param, constraint]) => ({
14136
+ param,
14137
+ constraint
14138
+ }));
14139
+ }
14140
+ function throwConstraintToKinds(c) {
14141
+ if (!c) return void 0;
14142
+ const out = /* @__PURE__ */ new Set();
14143
+ let any2 = false;
14144
+ const seen = /* @__PURE__ */ new Set();
14145
+ const note2 = (s) => {
14146
+ if (s === "*" || s === "any") any2 = true;
14147
+ else if (s) out.add(s);
14148
+ };
14149
+ const walk = (x) => {
14150
+ if (x.lazy) {
14151
+ if (seen.has(x.lazy)) return;
14152
+ seen.add(x.lazy);
14153
+ walk(derefConstraint(x));
14154
+ return;
14155
+ }
14156
+ if (x.members) {
14157
+ for (const m of x.members) walk(m);
14158
+ return;
14159
+ }
14160
+ for (const p of x.preds) {
14161
+ if (p.op !== "eq" && p.op !== "ne") continue;
14162
+ for (const side of [p.a, p.b]) {
14163
+ if (side.op === "lit" && typeof side.value === "string") note2(side.value);
14164
+ }
14165
+ }
14166
+ };
14167
+ walk(c);
14168
+ if (any2) return "*";
14169
+ if (out.size > 0) return [...out];
14170
+ return void 0;
14171
+ }
14172
+
14173
+ // src/algebra/domain-membership.ts
14174
+ function literalMeetsConstraint(lv, c, seen) {
14175
+ if (c.lazy) {
14176
+ const s = seen ?? /* @__PURE__ */ new Set();
14177
+ if (s.has(c.lazy)) return false;
14178
+ s.add(c.lazy);
14179
+ return literalMeetsConstraint(lv, derefConstraint(c), s);
14180
+ }
14181
+ const ext = c;
14182
+ if (c.fields || c.element) return false;
14183
+ if (ext.fn) return false;
14184
+ if (Array.isArray(ext.members) && ext.members.length > 0) {
14185
+ return ext.members.some((m) => literalMeetsConstraint(lv, m, seen));
14186
+ }
14187
+ if (c.prim === void 0) {
14188
+ return c.preds.every((p) => predHolds(lv, p));
14189
+ }
14190
+ if (!primMatches(c.prim, lv)) return false;
14191
+ if (isIntFlag(c) && c.prim === "number" && !(typeof lv === "number" && Number.isInteger(lv))) {
14192
+ return false;
14193
+ }
14194
+ return c.preds.every((p) => predHolds(lv, p));
14195
+ }
14196
+ function primMatches(prim, lv) {
14197
+ switch (prim) {
14198
+ case "number":
14199
+ return typeof lv === "number";
14200
+ case "string":
14201
+ return typeof lv === "string";
14202
+ case "boolean":
14203
+ return typeof lv === "boolean";
14204
+ case "object":
14205
+ return lv === null;
14206
+ case "undefined":
14207
+ return lv === void 0;
14208
+ default:
14209
+ return false;
14210
+ }
14211
+ }
14212
+ function predHolds(lv, p) {
14213
+ switch (p.op) {
14214
+ case "eq": {
14215
+ const litT = isSelfVar(p.a) && p.b.op === "lit" ? p.b : isSelfVar(p.b) && p.a.op === "lit" ? p.a : void 0;
14216
+ if (!litT) return false;
14217
+ return Object.is(lv, litT.value);
14218
+ }
14219
+ case "gt":
14220
+ case "ge":
14221
+ case "lt":
14222
+ case "le":
14223
+ return boundHolds(lv, p);
14224
+ case "typeof":
14225
+ return p.t.op === "var" && p.t.id === SELF && primMatches(p.type, lv);
14226
+ // and 是合取:逐参数按同一规则判定(string().length(n) 的 preds 是
14227
+ // and 包裹的两个长度界,叶子仍是 gt/ge/lt/le,无假阳性风险)
14228
+ case "and":
14229
+ return p.args.every((x) => predHolds(lv, x));
14230
+ // ne / or / not / true / false 等其余形态:保守不满足
14231
+ default:
14232
+ return false;
14233
+ }
14234
+ }
14235
+ function cmpHolds(x, op, n) {
14236
+ switch (op) {
14237
+ case "gt":
14238
+ return x > n;
14239
+ case "ge":
14240
+ return x >= n;
14241
+ case "lt":
14242
+ return x < n;
14243
+ case "le":
14244
+ return x <= n;
14245
+ }
14246
+ }
14247
+ function boundHolds(lv, p) {
14248
+ if (p.b.op !== "lit" || typeof p.b.value !== "number") return false;
14249
+ const n = p.b.value;
14250
+ if (isLengthSelf(p.a)) {
14251
+ return typeof lv === "string" && cmpHolds(lv.length, p.op, n);
14252
+ }
14253
+ if (isSelfVar(p.a)) {
14254
+ return typeof lv === "number" && cmpHolds(lv, p.op, n);
14255
+ }
14256
+ return false;
14257
+ }
14258
+ function isSelfVar(t) {
14259
+ return t.op === "var" && t.id === SELF;
14260
+ }
14261
+ function isLengthSelf(t) {
14262
+ return t.op === "app" && t.fn === "length" && t.args.length === 1 && isSelfVar(t.args[0]);
14263
+ }
14264
+
14265
+ // src/algebra/contract-face.ts
14266
+ var facesByFn = /* @__PURE__ */ new WeakMap();
14267
+ function attachContractFaces(fnObj, faces) {
14268
+ facesByFn.set(fnObj, faces);
14269
+ }
14270
+ function contractFacesOf(fnObj) {
14271
+ if (!fnObj || typeof fnObj !== "object" && typeof fnObj !== "function") {
14272
+ return void 0;
14273
+ }
14274
+ return facesByFn.get(fnObj);
14275
+ }
14276
+ var contractFaceResolverSlot = createScopedSlot(
14277
+ () => null
14278
+ );
14279
+ registerCollectorScopeParticipant(
14280
+ (body) => contractFaceResolverSlot.runScoped(body)
14281
+ );
14282
+ function setContractFaceResolver(resolver) {
14283
+ const prev = contractFaceResolverSlot.get();
14284
+ contractFaceResolverSlot.set(resolver);
14285
+ return prev;
14286
+ }
14287
+ function resolveContractFacesByName(fnName) {
14288
+ const resolver = contractFaceResolverSlot.get();
14289
+ return resolver ? resolver(fnName) : void 0;
14290
+ }
14291
+ function argLacksInformation(a) {
14292
+ if (!a || typeof a !== "object" || !("shape" in a)) return false;
14293
+ const k = a.shape?.k;
14294
+ if (k === "any") return true;
14295
+ if (k === "unknown") return a.term?.op !== "lit";
14296
+ return false;
14297
+ }
14298
+ function adoptCallArgsToFaces(args, faces) {
14299
+ const n = Math.min(args.length, faces.paramFaces.length);
14300
+ let changed = false;
14301
+ const out = args.slice();
14302
+ for (let i = 0; i < n; i++) {
14303
+ const face = faces.paramFaces[i];
14304
+ if (!face || !argLacksInformation(args[i])) continue;
14305
+ out[i] = face;
14306
+ changed = true;
14307
+ }
14308
+ return changed ? out : args;
14309
+ }
14310
+ function litMeetsReturnConstraint(r, c) {
14311
+ if (!c) return false;
14312
+ const lv = litValue(r);
14313
+ if (!lv.ok) return false;
14314
+ const v2 = lv.value;
14315
+ if (typeof v2 !== "number" && typeof v2 !== "string" && typeof v2 !== "boolean" && v2 !== null && v2 !== void 0) {
14316
+ return false;
14317
+ }
14318
+ return literalMeetsConstraint(v2, c);
14319
+ }
14320
+ function presentCallResultFace(r, faces) {
14321
+ const face = faces.returns;
14322
+ if (!face || !r || typeof r !== "object" || !r.shape) return r;
14323
+ if (r.shape.k === "never") return r;
14324
+ if (r.conf === "opaque") return r;
14325
+ if (litMeetsReturnConstraint(r, faces.returnsConstraint)) return r;
14326
+ if (leqAbs(r, face).ok) return r;
14327
+ return face;
14328
+ }
14329
+ function contractFacesFromEffectiveInterface(eff, paramNames) {
14330
+ if (eff.source !== "handwritten") return void 0;
14331
+ const conflictParams = eff.conflict?.params ?? [];
14332
+ const paramFaces = [];
14333
+ let hasFace = false;
14334
+ for (const e of eff.params) {
14335
+ const idx = paramNames.indexOf(e.param);
14336
+ if (idx < 0 || conflictParams.includes(e.param)) continue;
14337
+ paramFaces[idx] = constraintToEntryAbs(e.constraint, e.param);
14338
+ hasFace = true;
14339
+ }
14340
+ let returns;
14341
+ let returnsConstraint;
14342
+ if (eff.returns && !eff.conflict?.returns) {
14343
+ returns = constraintToEntryAbs(eff.returns.constraint, "return");
14344
+ returnsConstraint = eff.returns.constraint;
14345
+ hasFace = true;
14346
+ }
14347
+ return hasFace ? {
14348
+ paramFaces,
14349
+ ...returns !== void 0 ? { returns } : {},
14350
+ ...returnsConstraint !== void 0 ? { returnsConstraint } : {}
14351
+ } : void 0;
14352
+ }
14353
+
13506
14354
  // src/algebra/exec/calls.ts
13507
14355
  var PURE_CALL_MEMO_MAX = 256;
13508
14356
  var pureCallMemo = /* @__PURE__ */ new WeakMap();
@@ -13589,16 +14437,16 @@ var NEVER_EXEC_HOST_FN_NAMES = [
13589
14437
  "requestAnimationFrame",
13590
14438
  "requestIdleCallback"
13591
14439
  ];
13592
- function neverExecHostName(fn) {
13593
- if (typeof fn !== "function") return null;
14440
+ function neverExecHostName(fn2) {
14441
+ if (typeof fn2 !== "function") return null;
13594
14442
  const g = globalThis;
13595
14443
  for (const n of NEVER_EXEC_HOST_FN_NAMES) {
13596
- if (fn === g[n]) return n;
14444
+ if (fn2 === g[n]) return n;
13597
14445
  }
13598
14446
  return null;
13599
14447
  }
13600
- function blockHostSideEffect(fn) {
13601
- const hostName = neverExecHostName(fn);
14448
+ function blockHostSideEffect(fn2) {
14449
+ const hostName = neverExecHostName(fn2);
13602
14450
  if (hostName === null) return null;
13603
14451
  noteHostEffectBlocked(hostName);
13604
14452
  return abs({ k: "unknown" }, void 0, void 0, "opaque");
@@ -13620,8 +14468,8 @@ function getEvalCallCollector() {
13620
14468
  return evalCallCollectorSlot.get();
13621
14469
  }
13622
14470
  var hostGlobalFnIds;
13623
- function isHostGlobalFn(fn) {
13624
- if (typeof fn !== "function") return false;
14471
+ function isHostGlobalFn(fn2) {
14472
+ if (typeof fn2 !== "function") return false;
13625
14473
  if (!hostGlobalFnIds) {
13626
14474
  hostGlobalFnIds = /* @__PURE__ */ new Set();
13627
14475
  const g = globalThis;
@@ -13630,9 +14478,9 @@ function isHostGlobalFn(fn) {
13630
14478
  if (typeof v2 === "function") hostGlobalFnIds.add(v2);
13631
14479
  }
13632
14480
  }
13633
- return hostGlobalFnIds.has(fn);
14481
+ return hostGlobalFnIds.has(fn2);
13634
14482
  }
13635
- function callHostGlobalLiteralOnly(name, fn, args) {
14483
+ function callHostGlobalLiteralOnly(name, fn2, args) {
13636
14484
  const jsArgs = [];
13637
14485
  for (const a of args) {
13638
14486
  if (a && typeof a === "object" && "shape" in a) {
@@ -13653,7 +14501,7 @@ function callHostGlobalLiteralOnly(name, fn, args) {
13653
14501
  }
13654
14502
  }
13655
14503
  try {
13656
- return asAbsVal(fn(...jsArgs));
14504
+ return asAbsVal(fn2(...jsArgs));
13657
14505
  } catch (e) {
13658
14506
  throw new NudoThrow(throwPayloadOf(e));
13659
14507
  }
@@ -13726,12 +14574,12 @@ function getEvalCallBudgetState() {
13726
14574
  function evalTruncatedAbs() {
13727
14575
  return abs({ k: "unknown" }, void 0, void 0, "opaque");
13728
14576
  }
13729
- function evalCallBudgetKey(name, fn, args) {
13730
- const id = fn && typeof fn === "object" ? evalStableId(fn) : "prim";
14577
+ function evalCallBudgetKey(name, fn2, args) {
14578
+ const id = fn2 && typeof fn2 === "object" ? evalStableId(fn2) : "prim";
13731
14579
  return callBudgetKey(name, id, args);
13732
14580
  }
13733
- function evalEnterCall(name, fn, args) {
13734
- const key = evalCallBudgetKey(name, fn, args);
14581
+ function evalEnterCall(name, fn2, args) {
14582
+ const key = evalCallBudgetKey(name, fn2, args);
13735
14583
  if (evalActiveCallKeys.includes(key) || evalCallDepth >= evalCallDepthLimit || evalTotalCalls >= evalTotalCallsLimit) {
13736
14584
  noteAbsTruncation(name);
13737
14585
  return { ok: false };
@@ -13745,13 +14593,19 @@ function evalExitCall() {
13745
14593
  if (evalCallDepth > 0) evalCallDepth--;
13746
14594
  if (evalActiveCallKeys.length > 0) evalActiveCallKeys.pop();
13747
14595
  }
13748
- function $callNamed(name, fn, args, loc, argLocs) {
13749
- const pureName = pureFnNameOf(fn);
13750
- const fnObj = fn && (typeof fn === "object" || typeof fn === "function") ? fn : void 0;
13751
- const pk = pureName && fnObj ? callBudgetKey("pure", "", args) : void 0;
14596
+ function $callNamed(name, fn2, args, loc, argLocs) {
14597
+ const faces = resolveContractFacesByName(name) ?? contractFacesOf(fn2);
14598
+ const fnObj = fn2 && (typeof fn2 === "object" || typeof fn2 === "function") ? fn2 : void 0;
14599
+ if (faces && fnObj) attachContractFaces(fnObj, faces);
14600
+ const execArgs = faces ? adoptCallArgsToFaces(args, faces) : args;
14601
+ const pureName = pureFnNameOf(fn2);
14602
+ const pk = pureName && fnObj ? callBudgetKey("pure", "", execArgs) : void 0;
13752
14603
  if (fnObj && pk !== void 0) {
13753
14604
  const hit = pureCallMemo.get(fnObj)?.get(pk);
13754
- if (hit !== void 0) return routeApplyThrows(hit.abs, hit.throws);
14605
+ if (hit !== void 0) {
14606
+ const routed = routeApplyThrows(hit.abs, hit.throws);
14607
+ return faces ? presentCallResultFace(routed, faces) : routed;
14608
+ }
13755
14609
  }
13756
14610
  let result = unknown;
13757
14611
  let threw = false;
@@ -13767,42 +14621,42 @@ function $callNamed(name, fn, args, loc, argLocs) {
13767
14621
  );
13768
14622
  if (loc) pushCallLoc({ line: loc[0], column: loc[1] });
13769
14623
  try {
13770
- if (typeof fn === "function") {
14624
+ if (typeof fn2 === "function") {
13771
14625
  let g;
13772
- if (GLOBAL_FNS.has(name) && fn === globalThis[name]) {
14626
+ if (GLOBAL_FNS.has(name) && fn2 === globalThis[name]) {
13773
14627
  g = evalGlobalFn(name, args);
13774
14628
  } else {
13775
- const ctorName = hostBuiltinCtorName(fn);
14629
+ const ctorName = hostBuiltinCtorName(fn2);
13776
14630
  if (ctorName !== void 0) {
13777
14631
  g = evalGlobalFn(ctorName, args);
13778
14632
  }
13779
14633
  }
13780
- const blockedHost = g === void 0 ? blockHostSideEffect(fn) : null;
14634
+ const blockedHost = g === void 0 ? blockHostSideEffect(fn2) : null;
13781
14635
  if (g !== void 0) {
13782
14636
  result = g;
13783
14637
  } else if (blockedHost !== null) {
13784
14638
  result = blockedHost;
13785
- } else if (isHostGlobalFn(fn)) {
13786
- result = callHostGlobalLiteralOnly(name, fn, args);
14639
+ } else if (isHostGlobalFn(fn2)) {
14640
+ result = callHostGlobalLiteralOnly(name, fn2, args);
13787
14641
  } else {
13788
- const entered = evalEnterCall(name, fn, args);
14642
+ const entered = evalEnterCall(name, fn2, execArgs);
13789
14643
  if (!entered.ok) {
13790
14644
  result = evalTruncatedAbs();
13791
14645
  } else {
13792
14646
  try {
13793
- result = callAtFunctionBoundary(() => fn(...args));
14647
+ result = callAtFunctionBoundary(() => fn2(...execArgs));
13794
14648
  } finally {
13795
14649
  evalExitCall();
13796
14650
  }
13797
14651
  }
13798
14652
  }
13799
- } else if (fn && typeof fn === "object" && "shape" in fn) {
13800
- const entered = evalEnterCall(name, fn, args);
14653
+ } else if (fn2 && typeof fn2 === "object" && "shape" in fn2) {
14654
+ const entered = evalEnterCall(name, fn2, execArgs);
13801
14655
  if (!entered.ok) {
13802
14656
  result = evalTruncatedAbs();
13803
14657
  } else {
13804
14658
  try {
13805
- result = $call(fn, args);
14659
+ result = $call(fn2, execArgs);
13806
14660
  } finally {
13807
14661
  evalExitCall();
13808
14662
  }
@@ -13836,7 +14690,7 @@ function $callNamed(name, fn, args, loc, argLocs) {
13836
14690
  }
13837
14691
  }
13838
14692
  }
13839
- return result;
14693
+ return faces ? presentCallResultFace(result, faces) : result;
13840
14694
  }
13841
14695
 
13842
14696
  // src/algebra/methods.ts
@@ -14906,8 +15760,8 @@ function $new(cls, args) {
14906
15760
  popCtorFrame();
14907
15761
  }
14908
15762
  }
14909
- const shape = objOf({});
14910
- return abs({ k: "brand", name: clsName, shape }, void 0, void 0, "path");
15763
+ const shape2 = objOf({});
15764
+ return abs({ k: "brand", name: clsName, shape: shape2 }, void 0, void 0, "path");
14911
15765
  }
14912
15766
  const spec = specOf(cls);
14913
15767
  if (!spec) {
@@ -15183,12 +16037,12 @@ function $invokeInner(thisVal, method, args, loc) {
15183
16037
  return ["_rest"];
15184
16038
  };
15185
16039
  if (typeof thisVal === "function") {
15186
- const fn = thisVal;
16040
+ const fn2 = thisVal;
15187
16041
  if (method === "call") {
15188
- return callAtFunctionBoundary(() => fn.apply(args[0], args.slice(1)));
16042
+ return callAtFunctionBoundary(() => fn2.apply(args[0], args.slice(1)));
15189
16043
  }
15190
16044
  if (method === "apply") {
15191
- return callAtFunctionBoundary(() => fn.apply(args[0], expandApplyArgs(args[1])));
16045
+ return callAtFunctionBoundary(() => fn2.apply(args[0], expandApplyArgs(args[1])));
15192
16046
  }
15193
16047
  const boundThis = args[0];
15194
16048
  const bound = args.slice(1);
@@ -15196,7 +16050,7 @@ function $invokeInner(thisVal, method, args, loc) {
15196
16050
  return absFunction(
15197
16051
  boundFnParams(thisVal, bound.length),
15198
16052
  {
15199
- apply: (callArgs) => callAtFunctionBoundary(() => fn.apply(boundThis, [...bound, ...callArgs]))
16053
+ apply: (callArgs) => callAtFunctionBoundary(() => fn2.apply(boundThis, [...bound, ...callArgs]))
15200
16054
  },
15201
16055
  hostFacet !== void 0 ? { ctor: hostFacet } : void 0
15202
16056
  );
@@ -15450,9 +16304,9 @@ function $invokeInner(thisVal, method, args, loc) {
15450
16304
  noteUnknownMemberMissing(thisVal, method, "method", loc);
15451
16305
  return unknown;
15452
16306
  }
15453
- function refineFnReturnType(fn, result) {
15454
- if (!fn || typeof fn !== "object" || !("shape" in fn)) return;
15455
- const s = fn.shape;
16307
+ function refineFnReturnType(fn2, result) {
16308
+ if (!fn2 || typeof fn2 !== "object" || !("shape" in fn2)) return;
16309
+ const s = fn2.shape;
15456
16310
  if (s.k !== "fn") return;
15457
16311
  if (s.returnType === void 0) {
15458
16312
  s.returnType = result;
@@ -15472,8 +16326,8 @@ function memberLikelyHasMethod(m, method) {
15472
16326
  return false;
15473
16327
  }
15474
16328
  function invokeArrMethod(arr, method, args) {
15475
- const shape = arr.shape;
15476
- const holes = shape.k === "tuple" ? arr.shape.holes ?? [] : [];
16329
+ const shape2 = arr.shape;
16330
+ const holes = shape2.k === "tuple" ? arr.shape.holes ?? [] : [];
15477
16331
  const isHole = (i) => holes.includes(i);
15478
16332
  const unknownIdx = () => abs({ k: "prim", type: "number" }, void 0, void 0, "path");
15479
16333
  const callbackTruth = (r) => {
@@ -15484,7 +16338,7 @@ function invokeArrMethod(arr, method, args) {
15484
16338
  if (typeof v2 === "number" && (v2 === 0 || Number.isNaN(v2))) return false;
15485
16339
  return true;
15486
16340
  };
15487
- const callFn = (fn, ...fnArgs) => {
16341
+ const callFn = (fn2, ...fnArgs) => {
15488
16342
  const sumIdx = fnArgs.findIndex(
15489
16343
  (a) => a && typeof a === "object" && "shape" in a && a.shape.k === "sum"
15490
16344
  );
@@ -15493,24 +16347,24 @@ function invokeArrMethod(arr, method, args) {
15493
16347
  let acc;
15494
16348
  for (const m of members) {
15495
16349
  const next = fnArgs.map((a, i) => i === sumIdx ? m : a);
15496
- const r = callFn(fn, ...next);
16350
+ const r = callFn(fn2, ...next);
15497
16351
  acc = acc === void 0 ? r : joinAbs(acc, r);
15498
16352
  }
15499
16353
  return acc ?? unknown;
15500
16354
  }
15501
- if (typeof fn === "function") {
15502
- const r = callAtFunctionBoundary(() => fn(...fnArgs));
16355
+ if (typeof fn2 === "function") {
16356
+ const r = callAtFunctionBoundary(() => fn2(...fnArgs));
15503
16357
  if (r && typeof r === "object" && "shape" in r) return r;
15504
16358
  return unknown;
15505
16359
  }
15506
- const absFn = asAbs(fn);
16360
+ const absFn = asAbs(fn2);
15507
16361
  if (absFn) {
15508
16362
  return applyCallbackAbs(absFn, fnArgs, emptyEnv(), pTrue, defaultLeakBudget);
15509
16363
  }
15510
16364
  return unknown;
15511
16365
  };
15512
- const isRelationOnly = (fn) => {
15513
- const a = asAbs(fn);
16366
+ const isRelationOnly = (fn2) => {
16367
+ const a = asAbs(fn2);
15514
16368
  if (!a) return false;
15515
16369
  const impl = getFnImpl(a);
15516
16370
  if (impl?.body || impl?.apply) return false;
@@ -15518,8 +16372,8 @@ function invokeArrMethod(arr, method, args) {
15518
16372
  };
15519
16373
  if (method === "map") {
15520
16374
  validateCallableArg(args[0], "map callback may not be callable");
15521
- if (shape.k === "tuple") {
15522
- const mapped = shape.elements.map(
16375
+ if (shape2.k === "tuple") {
16376
+ const mapped = shape2.elements.map(
15523
16377
  (el2, i) => isHole(i) ? el2 : callFn(args[0], el2, $lit(i), arr)
15524
16378
  );
15525
16379
  return abs(
@@ -15529,70 +16383,70 @@ function invokeArrMethod(arr, method, args) {
15529
16383
  "path"
15530
16384
  );
15531
16385
  }
15532
- const out = callFn(args[0], shape.element, unknownIdx(), arr);
15533
- const el = mapElementFallback(asAbs(args[0]), shape.element, out);
16386
+ const out = callFn(args[0], shape2.element, unknownIdx(), arr);
16387
+ const el = mapElementFallback(asAbs(args[0]), shape2.element, out);
15534
16388
  const conf = el === out ? confJoin(arr.conf, out.conf) : "partial";
15535
16389
  return abs({ k: "arr", element: el }, void 0, void 0, conf);
15536
16390
  }
15537
16391
  if (method === "reduce") {
15538
16392
  validateCallableArg(args[0], "reduce callback may not be callable");
15539
- const fn = args[0];
16393
+ const fn2 = args[0];
15540
16394
  const noInitial = args.length < 2;
15541
16395
  let acc = args[1] ?? unknown;
15542
- if (noInitial && shape.k === "arr") {
16396
+ if (noInitial && shape2.k === "arr") {
15543
16397
  recordMayThrow({
15544
16398
  kind: "TypeError",
15545
16399
  cause: "reduce of possibly-empty array with no initial value"
15546
16400
  });
15547
16401
  }
15548
- if (isRelationOnly(fn) && shape.k === "arr") {
15549
- const d = instantiateReturn(fn, [acc, shape.element]);
16402
+ if (isRelationOnly(fn2) && shape2.k === "arr") {
16403
+ const d = instantiateReturn(fn2, [acc, shape2.element]);
15550
16404
  return joinAbs(acc, d);
15551
16405
  }
15552
- if (shape.k === "tuple") {
16406
+ if (shape2.k === "tuple") {
15553
16407
  if (noInitial) {
15554
- const firstIdx = shape.elements.findIndex((_, i) => !isHole(i));
16408
+ const firstIdx = shape2.elements.findIndex((_, i) => !isHole(i));
15555
16409
  if (firstIdx === -1) throw new NudoThrow(errorTypeAbs("TypeError"));
15556
- let acc2 = shape.elements[firstIdx];
15557
- for (let i = firstIdx + 1; i < shape.elements.length; i++) {
16410
+ let acc2 = shape2.elements[firstIdx];
16411
+ for (let i = firstIdx + 1; i < shape2.elements.length; i++) {
15558
16412
  if (isHole(i)) continue;
15559
- acc2 = callFn(fn, acc2, shape.elements[i], $lit(i), arr);
16413
+ acc2 = callFn(fn2, acc2, shape2.elements[i], $lit(i), arr);
15560
16414
  }
15561
16415
  return acc2;
15562
16416
  }
15563
- for (let i = 0; i < shape.elements.length; i++) {
16417
+ for (let i = 0; i < shape2.elements.length; i++) {
15564
16418
  if (isHole(i)) continue;
15565
- acc = callFn(fn, acc, shape.elements[i], $lit(i), arr);
16419
+ acc = callFn(fn2, acc, shape2.elements[i], $lit(i), arr);
15566
16420
  }
15567
16421
  return acc;
15568
16422
  }
15569
- return callFn(fn, acc, shape.element, unknownIdx(), arr);
16423
+ return callFn(fn2, acc, shape2.element, unknownIdx(), arr);
15570
16424
  }
15571
16425
  if (method === "reduceRight") {
15572
16426
  validateCallableArg(args[0], "reduceRight callback may not be callable");
15573
- const fn = args[0];
16427
+ const fn2 = args[0];
15574
16428
  const noInitial = args.length < 2;
15575
16429
  let acc = args[1] ?? unknown;
15576
- if (shape.k === "tuple") {
16430
+ if (shape2.k === "tuple") {
15577
16431
  if (noInitial) {
15578
16432
  let lastIdx = -1;
15579
- for (let i = shape.elements.length - 1; i >= 0; i--) {
16433
+ for (let i = shape2.elements.length - 1; i >= 0; i--) {
15580
16434
  if (!isHole(i)) {
15581
16435
  lastIdx = i;
15582
16436
  break;
15583
16437
  }
15584
16438
  }
15585
16439
  if (lastIdx === -1) throw new NudoThrow(errorTypeAbs("TypeError"));
15586
- let acc2 = shape.elements[lastIdx];
16440
+ let acc2 = shape2.elements[lastIdx];
15587
16441
  for (let i = lastIdx - 1; i >= 0; i--) {
15588
16442
  if (isHole(i)) continue;
15589
- acc2 = callFn(fn, acc2, shape.elements[i], $lit(i), arr);
16443
+ acc2 = callFn(fn2, acc2, shape2.elements[i], $lit(i), arr);
15590
16444
  }
15591
16445
  return acc2;
15592
16446
  }
15593
- for (let i = shape.elements.length - 1; i >= 0; i--) {
16447
+ for (let i = shape2.elements.length - 1; i >= 0; i--) {
15594
16448
  if (isHole(i)) continue;
15595
- acc = callFn(fn, acc, shape.elements[i], $lit(i), arr);
16449
+ acc = callFn(fn2, acc, shape2.elements[i], $lit(i), arr);
15596
16450
  }
15597
16451
  return acc;
15598
16452
  }
@@ -15602,14 +16456,14 @@ function invokeArrMethod(arr, method, args) {
15602
16456
  cause: "reduceRight of possibly-empty array with no initial value"
15603
16457
  });
15604
16458
  }
15605
- return callFn(fn, acc, shape.element, unknownIdx(), arr);
16459
+ return callFn(fn2, acc, shape2.element, unknownIdx(), arr);
15606
16460
  }
15607
16461
  if (method === "filter") {
15608
16462
  validateCallableArg(args[0], "filter callback may not be callable");
15609
- if (shape.k === "tuple") {
16463
+ if (shape2.k === "tuple") {
15610
16464
  const kept = [];
15611
16465
  let anyUncertain = false;
15612
- shape.elements.forEach((el2, i) => {
16466
+ shape2.elements.forEach((el2, i) => {
15613
16467
  if (isHole(i)) return;
15614
16468
  const p = callFn(args[0], el2, $lit(i), arr);
15615
16469
  const t = callbackTruth(p);
@@ -15641,33 +16495,33 @@ function invokeArrMethod(arr, method, args) {
15641
16495
  }
15642
16496
  if (method === "flatMap") {
15643
16497
  validateCallableArg(args[0], "flatMap callback may not be callable");
15644
- if (shape.k === "tuple") {
15645
- const mapped = shape.elements.map(
16498
+ if (shape2.k === "tuple") {
16499
+ const mapped = shape2.elements.map(
15646
16500
  (el, i) => isHole(i) ? abs({ k: "tuple", elements: [] }, void 0, void 0, "exact") : callFn(args[0], el, $lit(i), arr)
15647
16501
  );
15648
16502
  return projectFlatMapResult(arr.conf, mapped);
15649
16503
  }
15650
- const out = callFn(args[0], shape.element, unknownIdx(), arr);
16504
+ const out = callFn(args[0], shape2.element, unknownIdx(), arr);
15651
16505
  return projectFlatMapResult(arr.conf, [out]);
15652
16506
  }
15653
16507
  if (method === "forEach") {
15654
16508
  validateCallableArg(args[0], "forEach callback may not be callable");
15655
- if (shape.k === "tuple") {
15656
- shape.elements.forEach((el, i) => {
16509
+ if (shape2.k === "tuple") {
16510
+ shape2.elements.forEach((el, i) => {
15657
16511
  if (!isHole(i)) callFn(args[0], el, $lit(i), arr);
15658
16512
  });
15659
16513
  } else {
15660
- callFn(args[0], shape.element, unknownIdx(), arr);
16514
+ callFn(args[0], shape2.element, unknownIdx(), arr);
15661
16515
  }
15662
16516
  return undefAbs();
15663
16517
  }
15664
16518
  if (method === "some" || method === "every") {
15665
16519
  validateCallableArg(args[0], `${method} callback may not be callable`);
15666
16520
  let undecided = false;
15667
- if (shape.k === "tuple") {
15668
- for (let i = 0; i < shape.elements.length; i++) {
16521
+ if (shape2.k === "tuple") {
16522
+ for (let i = 0; i < shape2.elements.length; i++) {
15669
16523
  if (isHole(i)) continue;
15670
- const t = callbackTruth(callFn(args[0], shape.elements[i], $lit(i), arr));
16524
+ const t = callbackTruth(callFn(args[0], shape2.elements[i], $lit(i), arr));
15671
16525
  if (t === void 0) {
15672
16526
  undecided = true;
15673
16527
  continue;
@@ -15676,7 +16530,7 @@ function invokeArrMethod(arr, method, args) {
15676
16530
  if (method === "every" && !t) return boolLit(false);
15677
16531
  }
15678
16532
  } else {
15679
- const t = callbackTruth(callFn(args[0], shape.element, unknownIdx(), arr));
16533
+ const t = callbackTruth(callFn(args[0], shape2.element, unknownIdx(), arr));
15680
16534
  if (t === void 0) return bool();
15681
16535
  if (method === "some" && t) return boolLit(true);
15682
16536
  if (method === "every" && !t) return boolLit(false);
@@ -15687,21 +16541,21 @@ function invokeArrMethod(arr, method, args) {
15687
16541
  }
15688
16542
  if (method === "find") {
15689
16543
  validateCallableArg(args[0], "find callback may not be callable");
15690
- if (shape.k === "tuple") {
16544
+ if (shape2.k === "tuple") {
15691
16545
  let undecided = false;
15692
- for (let i = 0; i < shape.elements.length; i++) {
15693
- const el2 = shape.elements[i];
16546
+ for (let i = 0; i < shape2.elements.length; i++) {
16547
+ const el2 = shape2.elements[i];
15694
16548
  const t2 = callbackTruth(callFn(args[0], el2, $lit(i), arr));
15695
16549
  if (t2 === true) return el2;
15696
16550
  if (t2 === void 0) undecided = true;
15697
16551
  }
15698
16552
  if (undecided) {
15699
- const joined = shape.elements.reduce((a, b) => joinAbs(a, b));
16553
+ const joined = shape2.elements.reduce((a, b) => joinAbs(a, b));
15700
16554
  return joinAbs(joined, undefAbs());
15701
16555
  }
15702
16556
  return undefAbs();
15703
16557
  }
15704
- const el = shape.element;
16558
+ const el = shape2.element;
15705
16559
  const t = callbackTruth(callFn(args[0], el, unknownIdx(), arr));
15706
16560
  if (t === true) return el;
15707
16561
  if (t === false) return undefAbs();
@@ -15709,17 +16563,17 @@ function invokeArrMethod(arr, method, args) {
15709
16563
  }
15710
16564
  if (method === "findIndex") {
15711
16565
  validateCallableArg(args[0], "findIndex callback may not be callable");
15712
- if (shape.k === "tuple") {
16566
+ if (shape2.k === "tuple") {
15713
16567
  let undecided = false;
15714
- for (let i = 0; i < shape.elements.length; i++) {
15715
- const t2 = callbackTruth(callFn(args[0], shape.elements[i], $lit(i), arr));
16568
+ for (let i = 0; i < shape2.elements.length; i++) {
16569
+ const t2 = callbackTruth(callFn(args[0], shape2.elements[i], $lit(i), arr));
15716
16570
  if (t2 === true) return $lit(i);
15717
16571
  if (t2 === void 0) undecided = true;
15718
16572
  }
15719
16573
  if (undecided) return joinAbs(unknownIdx(), $lit(-1));
15720
16574
  return $lit(-1);
15721
16575
  }
15722
- const t = callbackTruth(callFn(args[0], shape.element, unknownIdx(), arr));
16576
+ const t = callbackTruth(callFn(args[0], shape2.element, unknownIdx(), arr));
15723
16577
  if (t === true) return unknownIdx();
15724
16578
  if (t === false) return $lit(-1);
15725
16579
  return joinAbs(unknownIdx(), $lit(-1));
@@ -15727,28 +16581,28 @@ function invokeArrMethod(arr, method, args) {
15727
16581
  if (method === "findLast" || method === "findLastIndex") {
15728
16582
  validateCallableArg(args[0], `${method} callback may not be callable`);
15729
16583
  const wantIndex = method === "findLastIndex";
15730
- if (shape.k === "tuple") {
16584
+ if (shape2.k === "tuple") {
15731
16585
  let undecided = false;
15732
- for (let i = shape.elements.length - 1; i >= 0; i--) {
15733
- const t2 = callbackTruth(callFn(args[0], shape.elements[i], $lit(i), arr));
15734
- if (t2 === true) return wantIndex ? $lit(i) : shape.elements[i];
16586
+ for (let i = shape2.elements.length - 1; i >= 0; i--) {
16587
+ const t2 = callbackTruth(callFn(args[0], shape2.elements[i], $lit(i), arr));
16588
+ if (t2 === true) return wantIndex ? $lit(i) : shape2.elements[i];
15735
16589
  if (t2 === void 0) undecided = true;
15736
16590
  }
15737
16591
  if (undecided) {
15738
- const joined = shape.elements.length ? shape.elements.reduce((a, b) => joinAbs(a, b)) : unknown;
16592
+ const joined = shape2.elements.length ? shape2.elements.reduce((a, b) => joinAbs(a, b)) : unknown;
15739
16593
  return wantIndex ? joinAbs(unknownIdx(), $lit(-1)) : joinAbs(joined, undefAbs());
15740
16594
  }
15741
16595
  return wantIndex ? $lit(-1) : undefAbs();
15742
16596
  }
15743
- const t = callbackTruth(callFn(args[0], shape.element, unknownIdx(), arr));
16597
+ const t = callbackTruth(callFn(args[0], shape2.element, unknownIdx(), arr));
15744
16598
  if (wantIndex) {
15745
16599
  if (t === true) return unknownIdx();
15746
16600
  if (t === false) return $lit(-1);
15747
16601
  return joinAbs(unknownIdx(), $lit(-1));
15748
16602
  }
15749
- if (t === true) return shape.element;
16603
+ if (t === true) return shape2.element;
15750
16604
  if (t === false) return undefAbs();
15751
- return joinAbs(shape.element, undefAbs());
16605
+ return joinAbs(shape2.element, undefAbs());
15752
16606
  }
15753
16607
  if (method === "join") {
15754
16608
  const folded = arrayJoinWithSep(arr, args[0]);
@@ -15760,11 +16614,11 @@ function invokeArrMethod(arr, method, args) {
15760
16614
  return arrayJoinToString(arr);
15761
16615
  }
15762
16616
  if (method === "keys") {
15763
- if (shape.k === "tuple") {
16617
+ if (shape2.k === "tuple") {
15764
16618
  return abs(
15765
16619
  {
15766
16620
  k: "tuple",
15767
- elements: shape.elements.map((_, i) => numLit(i))
16621
+ elements: shape2.elements.map((_, i) => numLit(i))
15768
16622
  },
15769
16623
  void 0,
15770
16624
  void 0,
@@ -15774,12 +16628,12 @@ function invokeArrMethod(arr, method, args) {
15774
16628
  return abs({ k: "arr", element: unknownIdx() }, void 0, void 0, "partial");
15775
16629
  }
15776
16630
  if (method === "values") {
15777
- if (shape.k === "tuple") {
15778
- const holes2 = shape.holes ?? [];
16631
+ if (shape2.k === "tuple") {
16632
+ const holes2 = shape2.holes ?? [];
15779
16633
  return abs(
15780
16634
  {
15781
16635
  k: "tuple",
15782
- elements: shape.elements.map((el, i) => holes2.includes(i) ? undefAbs() : el)
16636
+ elements: shape2.elements.map((el, i) => holes2.includes(i) ? undefAbs() : el)
15783
16637
  },
15784
16638
  void 0,
15785
16639
  void 0,
@@ -15789,12 +16643,12 @@ function invokeArrMethod(arr, method, args) {
15789
16643
  return arr;
15790
16644
  }
15791
16645
  if (method === "entries") {
15792
- if (shape.k === "tuple") {
15793
- const holes2 = shape.holes ?? [];
16646
+ if (shape2.k === "tuple") {
16647
+ const holes2 = shape2.holes ?? [];
15794
16648
  return abs(
15795
16649
  {
15796
16650
  k: "tuple",
15797
- elements: shape.elements.map(
16651
+ elements: shape2.elements.map(
15798
16652
  (el, i) => abs(
15799
16653
  { k: "tuple", elements: [numLit(i), holes2.includes(i) ? undefAbs() : el] },
15800
16654
  void 0,
@@ -15812,7 +16666,7 @@ function invokeArrMethod(arr, method, args) {
15812
16666
  {
15813
16667
  k: "arr",
15814
16668
  element: abs(
15815
- { k: "tuple", elements: [unknownIdx(), shape.element] },
16669
+ { k: "tuple", elements: [unknownIdx(), shape2.element] },
15816
16670
  void 0,
15817
16671
  void 0,
15818
16672
  "partial"
@@ -15824,16 +16678,16 @@ function invokeArrMethod(arr, method, args) {
15824
16678
  );
15825
16679
  }
15826
16680
  if (method === "fill" && args.length >= 1) {
15827
- return fillTuple(shape, args, arr);
16681
+ return fillTuple(shape2, args, arr);
15828
16682
  }
15829
16683
  if (method === "sort" || method === "toSorted") {
15830
16684
  validateCallableArg(args[0], `${method} comparator may not be callable`, {
15831
16685
  undefinedOk: true
15832
16686
  });
15833
- if (shape.k === "arr") {
15834
- return abs({ k: "arr", element: shape.element }, void 0, void 0, "partial");
16687
+ if (shape2.k === "arr") {
16688
+ return abs({ k: "arr", element: shape2.element }, void 0, void 0, "partial");
15835
16689
  }
15836
- const slots = shape.elements.map((el2, i) => isHole(i) ? undefAbs() : el2);
16690
+ const slots = shape2.elements.map((el2, i) => isHole(i) ? undefAbs() : el2);
15837
16691
  const isUndefLit = (el2) => el2.term?.op === "lit" && el2.term.value === void 0;
15838
16692
  const isDefaultCmp = args[0] === void 0 || !!asAbs(args[0])?.term && asAbs(args[0]).term.op === "lit" && asAbs(args[0]).term.value === void 0;
15839
16693
  if (isDefaultCmp) {
@@ -15862,17 +16716,17 @@ function invokeArrMethod(arr, method, args) {
15862
16716
  }
15863
16717
  }
15864
16718
  }
15865
- const el = shape.elements.length ? shape.elements.reduce((x, y) => joinAbs(x, y)) : unknown;
16719
+ const el = shape2.elements.length ? shape2.elements.reduce((x, y) => joinAbs(x, y)) : unknown;
15866
16720
  return abs({ k: "arr", element: el }, void 0, void 0, confJoin(arr.conf, "path"));
15867
16721
  }
15868
16722
  if (method === "reverse") {
15869
- if (shape.k === "tuple") {
15870
- const len = shape.elements.length;
15871
- const holesR = shape.holes ? shape.holes.map((h) => len - 1 - h) : void 0;
16723
+ if (shape2.k === "tuple") {
16724
+ const len = shape2.elements.length;
16725
+ const holesR = shape2.holes ? shape2.holes.map((h) => len - 1 - h) : void 0;
15872
16726
  return abs(
15873
16727
  {
15874
16728
  k: "tuple",
15875
- elements: [...shape.elements].reverse(),
16729
+ elements: [...shape2.elements].reverse(),
15876
16730
  holes: holesR && holesR.length > 0 ? holesR : void 0
15877
16731
  },
15878
16732
  void 0,
@@ -15880,21 +16734,21 @@ function invokeArrMethod(arr, method, args) {
15880
16734
  confJoin(arr.conf, "path")
15881
16735
  );
15882
16736
  }
15883
- return abs({ k: "arr", element: shape.element }, void 0, void 0, "partial");
16737
+ return abs({ k: "arr", element: shape2.element }, void 0, void 0, "partial");
15884
16738
  }
15885
16739
  if (method === "toReversed") {
15886
- if (shape.k === "tuple") {
16740
+ if (shape2.k === "tuple") {
15887
16741
  return abs(
15888
16742
  {
15889
16743
  k: "tuple",
15890
- elements: [...shape.elements].reverse().map((el, i) => (shape.holes ?? []).includes(shape.elements.length - 1 - i) ? undefAbs() : el)
16744
+ elements: [...shape2.elements].reverse().map((el, i) => (shape2.holes ?? []).includes(shape2.elements.length - 1 - i) ? undefAbs() : el)
15891
16745
  },
15892
16746
  void 0,
15893
16747
  void 0,
15894
16748
  confJoin(arr.conf, "path")
15895
16749
  );
15896
16750
  }
15897
- return abs({ k: "arr", element: shape.element }, void 0, void 0, "partial");
16751
+ return abs({ k: "arr", element: shape2.element }, void 0, void 0, "partial");
15898
16752
  }
15899
16753
  if (method === "flat") {
15900
16754
  validateIndexArg(args[0], "flat depth may not be convertible to a number");
@@ -15922,10 +16776,10 @@ function invokeArrMethod(arr, method, args) {
15922
16776
  }
15923
16777
  return { els: out, degraded };
15924
16778
  };
15925
- if (shape.k === "arr") {
15926
- const es = shape.element.shape;
16779
+ if (shape2.k === "arr") {
16780
+ const es = shape2.element.shape;
15927
16781
  const innerEls = es.k === "tuple" ? es.elements.length ? es.elements.reduce((x, y) => joinAbs(x, y)) : unknown : es.k === "arr" ? es.element : void 0;
15928
- const el = innerEls !== void 0 ? joinAbs(shape.element, innerEls) : shape.element;
16782
+ const el = innerEls !== void 0 ? joinAbs(shape2.element, innerEls) : shape2.element;
15929
16783
  return abs({ k: "arr", element: el }, void 0, void 0, "partial");
15930
16784
  }
15931
16785
  if (depthRaw === null) {
@@ -15933,8 +16787,8 @@ function invokeArrMethod(arr, method, args) {
15933
16787
  kind: "TypeError",
15934
16788
  cause: "flat depth may not be convertible to a number"
15935
16789
  });
15936
- const shallow = rec(shape.elements, holeSet, 0);
15937
- const deep = rec(shape.elements, holeSet, Number.MAX_SAFE_INTEGER);
16790
+ const shallow = rec(shape2.elements, holeSet, 0);
16791
+ const deep = rec(shape2.elements, holeSet, Number.MAX_SAFE_INTEGER);
15938
16792
  if (shallow !== null && deep !== null) {
15939
16793
  const el = [...shallow.els, ...deep.els].reduce((x, y) => joinAbs(x, y));
15940
16794
  return abs({ k: "arr", element: el }, void 0, void 0, "partial");
@@ -15942,9 +16796,9 @@ function invokeArrMethod(arr, method, args) {
15942
16796
  return unknown;
15943
16797
  }
15944
16798
  const depth = depthRaw === void 0 ? 1 : Math.max(depthRaw, 0);
15945
- const r = rec(shape.elements, holeSet, depth);
16799
+ const r = rec(shape2.elements, holeSet, depth);
15946
16800
  if (r === null) {
15947
- const shallow = rec(shape.elements, holeSet, 0);
16801
+ const shallow = rec(shape2.elements, holeSet, 0);
15948
16802
  const el = shallow && shallow.els.length ? shallow.els.reduce((x, y) => joinAbs(x, y)) : unknown;
15949
16803
  return abs({ k: "arr", element: el }, void 0, void 0, "partial");
15950
16804
  }
@@ -15963,22 +16817,22 @@ function invokeArrMethod(arr, method, args) {
15963
16817
  validateIndexArg(args[0], "toSpliced start may not be convertible to a number");
15964
16818
  validateIndexArg(args[1], "toSpliced skipCount may not be convertible to a number");
15965
16819
  const items = args.slice(2);
15966
- if (shape.k === "tuple") {
16820
+ if (shape2.k === "tuple") {
15967
16821
  const st = toIOI(args[0]);
15968
16822
  const dc = args[1] === void 0 ? void 0 : toIOI(args[1]);
15969
16823
  if (st === null || dc === null) {
15970
- const parts2 = [...shape.elements.filter((_, i) => !isHole(i)), ...items];
16824
+ const parts2 = [...shape2.elements.filter((_, i) => !isHole(i)), ...items];
15971
16825
  const el = parts2.length ? parts2.reduce((x, y) => joinAbs(x, y)) : unknown;
15972
16826
  return abs({ k: "arr", element: el }, void 0, void 0, "partial");
15973
16827
  }
15974
- const len = shape.elements.length;
16828
+ const len = shape2.elements.length;
15975
16829
  const a = st === void 0 ? 0 : st < 0 ? Math.max(len + st, 0) : Math.min(st, len);
15976
16830
  const skip = dc === void 0 ? len - a : Math.max(0, Math.min(dc, len - a));
15977
16831
  const solid = (el, i) => isHole(i) ? undefAbs() : el;
15978
16832
  const els = [
15979
- ...shape.elements.slice(0, a).map(solid),
16833
+ ...shape2.elements.slice(0, a).map(solid),
15980
16834
  ...items,
15981
- ...shape.elements.slice(a + skip).map((el, i) => solid(el, a + skip + i))
16835
+ ...shape2.elements.slice(a + skip).map((el, i) => solid(el, a + skip + i))
15982
16836
  ];
15983
16837
  return abs(
15984
16838
  { k: "tuple", elements: els },
@@ -15987,7 +16841,7 @@ function invokeArrMethod(arr, method, args) {
15987
16841
  confJoin(arr.conf, "path")
15988
16842
  );
15989
16843
  }
15990
- const parts = [shape.element, ...items];
16844
+ const parts = [shape2.element, ...items];
15991
16845
  return abs(
15992
16846
  { k: "arr", element: parts.reduce((x, y) => joinAbs(x, y)) },
15993
16847
  void 0,
@@ -15998,21 +16852,21 @@ function invokeArrMethod(arr, method, args) {
15998
16852
  if (method === "with") {
15999
16853
  validateIndexArg(args[0], "with index may not be convertible to a number");
16000
16854
  const v2 = args[1] ?? undefAbs();
16001
- if (shape.k === "tuple") {
16855
+ if (shape2.k === "tuple") {
16002
16856
  const iv = toIOI(args[0]) ?? 0;
16003
16857
  if (iv === null) {
16004
16858
  recordMayThrow({ kind: "RangeError", cause: "with index may be out of range" });
16005
16859
  return abs(
16006
- { k: "tuple", elements: shape.elements.map((el) => joinAbs(el, v2)) },
16860
+ { k: "tuple", elements: shape2.elements.map((el) => joinAbs(el, v2)) },
16007
16861
  void 0,
16008
16862
  void 0,
16009
16863
  "partial"
16010
16864
  );
16011
16865
  }
16012
- const len = shape.elements.length;
16866
+ const len = shape2.elements.length;
16013
16867
  const idx = iv < 0 ? len + iv : iv;
16014
16868
  if (idx < 0 || idx >= len) throw new NudoThrow(errorTypeAbs("RangeError"));
16015
- const els = shape.elements.map(
16869
+ const els = shape2.elements.map(
16016
16870
  (el, i) => i === idx ? v2 : isHole(i) ? undefAbs() : el
16017
16871
  );
16018
16872
  return abs(
@@ -16023,15 +16877,15 @@ function invokeArrMethod(arr, method, args) {
16023
16877
  );
16024
16878
  }
16025
16879
  return abs(
16026
- { k: "arr", element: joinAbs(shape.element, v2) },
16880
+ { k: "arr", element: joinAbs(shape2.element, v2) },
16027
16881
  void 0,
16028
16882
  void 0,
16029
16883
  "partial"
16030
16884
  );
16031
16885
  }
16032
16886
  if (method === "concat") {
16033
- if (shape.k === "tuple") {
16034
- const out = [...shape.elements];
16887
+ if (shape2.k === "tuple") {
16888
+ const out = [...shape2.elements];
16035
16889
  const holesC = new Set(holes);
16036
16890
  let degraded = false;
16037
16891
  for (const a of args) {
@@ -16064,7 +16918,7 @@ function invokeArrMethod(arr, method, args) {
16064
16918
  confJoin(arr.conf, "path")
16065
16919
  );
16066
16920
  }
16067
- const parts = [shape.element, ...args.map((a) => {
16921
+ const parts = [shape2.element, ...args.map((a) => {
16068
16922
  const aa = asAbs(a) ?? unknown;
16069
16923
  return aa.shape.k === "arr" || aa.shape.k === "tuple" ? aa.shape.k === "arr" ? aa.shape.element : aa.shape.elements.length ? aa.shape.elements.reduce((x, y) => joinAbs(x, y)) : unknown : aa;
16070
16924
  })];
@@ -16078,24 +16932,24 @@ function invokeArrMethod(arr, method, args) {
16078
16932
  if (method === "slice") {
16079
16933
  validateIndexArg(args[0], "slice start may not be convertible to a number");
16080
16934
  validateIndexArg(args[1], "slice end may not be convertible to a number");
16081
- if (shape.k === "tuple") {
16935
+ if (shape2.k === "tuple") {
16082
16936
  const st = toIOI(args[0]);
16083
16937
  const en = toIOI(args[1]);
16084
16938
  if (st === null || en === null) {
16085
- const el = shape.elements.length ? shape.elements.reduce((x, y) => joinAbs(x, y)) : unknown;
16939
+ const el = shape2.elements.length ? shape2.elements.reduce((x, y) => joinAbs(x, y)) : unknown;
16086
16940
  return abs({ k: "arr", element: el }, void 0, void 0, "partial");
16087
16941
  }
16088
- const len = shape.elements.length;
16942
+ const len = shape2.elements.length;
16089
16943
  const s = st === void 0 ? 0 : st < 0 ? Math.max(len + st, 0) : Math.min(st, len);
16090
16944
  const e = en === void 0 ? len : en < 0 ? Math.max(len + en, 0) : Math.min(en, len);
16091
16945
  if (e <= s) {
16092
16946
  return abs({ k: "tuple", elements: [] }, void 0, void 0, confJoin(arr.conf, "exact"));
16093
16947
  }
16094
- const holesS = (shape.holes ?? []).filter((h) => h >= s && h < e).map((h) => h - s);
16948
+ const holesS = (shape2.holes ?? []).filter((h) => h >= s && h < e).map((h) => h - s);
16095
16949
  return abs(
16096
16950
  {
16097
16951
  k: "tuple",
16098
- elements: shape.elements.slice(s, e),
16952
+ elements: shape2.elements.slice(s, e),
16099
16953
  holes: holesS.length > 0 ? holesS : void 0
16100
16954
  },
16101
16955
  void 0,
@@ -16103,12 +16957,12 @@ function invokeArrMethod(arr, method, args) {
16103
16957
  confJoin(arr.conf, "path")
16104
16958
  );
16105
16959
  }
16106
- return abs({ k: "arr", element: shape.element }, void 0, void 0, "partial");
16960
+ return abs({ k: "arr", element: shape2.element }, void 0, void 0, "partial");
16107
16961
  }
16108
16962
  if (method === "indexOf" || method === "lastIndexOf") {
16109
16963
  validateIndexArg(args[1], `${method} fromIndex may not be convertible to a number`);
16110
- if (shape.k === "tuple") {
16111
- const els = shape.elements;
16964
+ if (shape2.k === "tuple") {
16965
+ const els = shape2.elements;
16112
16966
  const search = args[0];
16113
16967
  const searchLit = search !== void 0 && search.term?.op === "lit" ? litValue(search) : void 0;
16114
16968
  const hasLitSearch = search !== void 0 && search.term?.op === "lit";
@@ -16153,22 +17007,22 @@ function invokeArrMethod(arr, method, args) {
16153
17007
  return abs({ k: "prim", type: "number" }, void 0, void 0, "path");
16154
17008
  }
16155
17009
  if (method === "pop") {
16156
- if (shape.k === "tuple") {
16157
- return shape.elements.length > 0 ? shape.elements[shape.elements.length - 1] ?? unknown : undefAbs();
17010
+ if (shape2.k === "tuple") {
17011
+ return shape2.elements.length > 0 ? shape2.elements[shape2.elements.length - 1] ?? unknown : undefAbs();
16158
17012
  }
16159
- if (shape.k === "arr") return joinAbs(shape.element, undefAbs());
17013
+ if (shape2.k === "arr") return joinAbs(shape2.element, undefAbs());
16160
17014
  }
16161
17015
  if (method === "shift") {
16162
- if (shape.k === "tuple" && shape.elements.length > 0) {
16163
- return shape.elements[0] ?? unknown;
17016
+ if (shape2.k === "tuple" && shape2.elements.length > 0) {
17017
+ return shape2.elements[0] ?? unknown;
16164
17018
  }
16165
- if (shape.k === "arr") return joinAbs(shape.element, undefAbs());
17019
+ if (shape2.k === "arr") return joinAbs(shape2.element, undefAbs());
16166
17020
  }
16167
17021
  if (method === "at") {
16168
17022
  validateIndexArg(args[0], "at index may not be convertible to a number");
16169
17023
  const iv = toIntegerOrInfinityLit(args[0]);
16170
- if (shape.k === "tuple") {
16171
- const els = shape.elements;
17024
+ if (shape2.k === "tuple") {
17025
+ const els = shape2.elements;
16172
17026
  if (iv === void 0) {
16173
17027
  if (els.length === 0) return undefAbs();
16174
17028
  return joinAbs(els.reduce((a, b) => joinAbs(a, b)), undefAbs());
@@ -16177,7 +17031,7 @@ function invokeArrMethod(arr, method, args) {
16177
17031
  if (idx >= 0 && idx < els.length) return els[idx] ?? unknown;
16178
17032
  return undefAbs();
16179
17033
  }
16180
- if (shape.k === "arr") return joinAbs(shape.element, undefAbs());
17034
+ if (shape2.k === "arr") return joinAbs(shape2.element, undefAbs());
16181
17035
  }
16182
17036
  return void 0;
16183
17037
  }
@@ -16391,11 +17245,11 @@ function $setKey(o, key, value) {
16391
17245
  confJoin("path", value.conf)
16392
17246
  );
16393
17247
  }
16394
- const shape = o.shape;
16395
- const prevIndex = shape.index?.value;
17248
+ const shape2 = o.shape;
17249
+ const prevIndex = shape2.index?.value;
16396
17250
  const indexVal = prevIndex ? joinAbs(prevIndex, val) : val;
16397
- const next = objOf({ ...shape.slots }, {
16398
- index: { key: shape.index?.key ?? unknown, value: indexVal },
17251
+ const next = objOf({ ...shape2.slots }, {
17252
+ index: { key: shape2.index?.key ?? unknown, value: indexVal },
16399
17253
  open: true
16400
17254
  });
16401
17255
  next.conf = confJoin(o.conf, value.conf);
@@ -17403,12 +18257,12 @@ ${js}`;
17403
18257
  }
17404
18258
  const cjsMerge = hasCjsExports ? `(() => { const me = $get(module, "exports"); if (me !== __nudoCjsOrig && me && typeof me === "object" && "shape" in me) { return { default: me }; } const out = {}; if (__nudoCjsOrig && __nudoCjsOrig.shape && __nudoCjsOrig.shape.k === "obj") { for (const k of Object.keys(__nudoCjsOrig.shape.slots)) out[k] = __nudoCjsOrig.shape.slots[k].value; } return out; })()` : "{}";
17405
18259
  const ret = `return { ...__nudoExports, ...${cjsMerge}, ${names.join(", ")} };`;
17406
- const fn = new Function(...argNames, `${js}
18260
+ const fn2 = new Function(...argNames, `${js}
17407
18261
  ${ret}`);
17408
18262
  setEvalBindingSink(bindings);
17409
18263
  beginClassEpoch();
17410
18264
  try {
17411
- const result = fn(...args);
18265
+ const result = fn2(...args);
17412
18266
  runBindings.set(result, bindings);
17413
18267
  return result;
17414
18268
  } finally {
@@ -17500,14 +18354,14 @@ function callTranspiledExportFull(exports, name, args, opts) {
17500
18354
  });
17501
18355
  }
17502
18356
  function callTranspiledExportFullInner(exports, name, args, opts) {
17503
- const fn = Object.hasOwn(exports, name) ? exports[name] : void 0;
17504
- if (typeof fn === "function") {
18357
+ const fn2 = Object.hasOwn(exports, name) ? exports[name] : void 0;
18358
+ if (typeof fn2 === "function") {
17505
18359
  const callArgs = args.map(
17506
18360
  (a) => a && typeof a === "object" && "shape" in a ? $copy(a) : asAbsVal(a)
17507
18361
  );
17508
18362
  return runWithLoopExits(() => {
17509
18363
  try {
17510
- const invoke = () => withNewTargetReset(() => fn(...callArgs));
18364
+ const invoke = () => withNewTargetReset(() => fn2(...callArgs));
17511
18365
  const r = opts?.phi ? withExecPhi(opts.phi, invoke) : invoke();
17512
18366
  drainPromiseMicros();
17513
18367
  if (!isAbsVal(r)) return joinControlExits(unknown);
@@ -17536,11 +18390,11 @@ function callTranspiledExportFullInner(exports, name, args, opts) {
17536
18390
  }
17537
18391
  });
17538
18392
  }
17539
- if (isAbsVal(fn)) {
17540
- if (fn.shape.k === "fn") {
18393
+ if (isAbsVal(fn2)) {
18394
+ if (fn2.shape.k === "fn") {
17541
18395
  return runWithLoopExits(() => {
17542
18396
  try {
17543
- const r = $call(fn, args);
18397
+ const r = $call(fn2, args);
17544
18398
  drainPromiseMicros();
17545
18399
  return joinControlExits(r);
17546
18400
  } catch (e) {
@@ -17560,7 +18414,7 @@ function callTranspiledExportFullInner(exports, name, args, opts) {
17560
18414
  });
17561
18415
  }
17562
18416
  drainPromiseMicros();
17563
- return { result: fn, throws: never };
18417
+ return { result: fn2, throws: never };
17564
18418
  }
17565
18419
  drainPromiseMicros();
17566
18420
  return { result: unknown, throws: never };
@@ -17744,26 +18598,31 @@ function joinThrowsSince2(mark) {
17744
18598
  if (items.length === 1) return items[0];
17745
18599
  return items.reduce((a, b) => joinAbs(a, b));
17746
18600
  }
17747
- function $call(fn, args, thisVal) {
17748
- return withNewTargetReset(() => $callInner(fn, args, thisVal));
18601
+ function $call(fn2, args, thisVal) {
18602
+ return withNewTargetReset(() => $callInner(fn2, args, thisVal));
17749
18603
  }
17750
- function $callInner(fn, args, thisVal) {
17751
- if (fn?.shape?.k === "sum") {
17752
- const results = fn.shape.members.map((m) => $call(m, args, thisVal));
17753
- if (results.every((r) => r.shape.k === "unknown")) return unknown;
18604
+ function $callInner(fn2, args, thisVal) {
18605
+ if (fn2?.shape?.k === "sum") {
18606
+ const results = fn2.shape.members.map((m) => $call(m, args, thisVal));
18607
+ if (results.every((r2) => r2.shape.k === "unknown")) return unknown;
17754
18608
  return results.reduce((a, b) => joinAbs(a, b));
17755
18609
  }
17756
- const pureName = pureFnNameOf(fn);
17757
- const fnObj = fn && typeof fn === "object" ? fn : void 0;
18610
+ const faces = contractFacesOf(fn2);
18611
+ const r = $callDispatch(fn2, faces ? adoptCallArgsToFaces(args, faces) : args, thisVal);
18612
+ return faces ? presentCallResultFace(r, faces) : r;
18613
+ }
18614
+ function $callDispatch(fn2, args, thisVal) {
18615
+ const pureName = pureFnNameOf(fn2);
18616
+ const fnObj = fn2 && typeof fn2 === "object" ? fn2 : void 0;
17758
18617
  const pk = pureName && fnObj ? pureMemoKey(args) : void 0;
17759
18618
  if (fnObj && pk !== void 0) {
17760
18619
  const hit = pureMemo.get(fnObj)?.get(pk);
17761
18620
  if (hit !== void 0) return routeApplyThrows(hit.abs, hit.throws);
17762
18621
  }
17763
- const impl = getFnImpl(fn);
18622
+ const impl = getFnImpl(fn2);
17764
18623
  if (!impl?.body && !impl?.apply) {
17765
- if (impl?.relation || isRelFn(fn)) return instantiateReturn(fn, args);
17766
- const calleeAbs = fn && typeof fn === "object" ? fn : void 0;
18624
+ if (impl?.relation || isRelFn(fn2)) return instantiateReturn(fn2, args);
18625
+ const calleeAbs = fn2 && typeof fn2 === "object" ? fn2 : void 0;
17767
18626
  const calleeK = calleeAbs?.shape?.k;
17768
18627
  if (calleeK === "prim" || calleeAbs !== void 0 && isNullishLitAbs(calleeAbs)) {
17769
18628
  throw new NudoThrow(errorTypeAbs("TypeError"));
@@ -17777,8 +18636,8 @@ function $callInner(fn, args, thisVal) {
17777
18636
  return unknown;
17778
18637
  }
17779
18638
  if (impl?.apply) {
17780
- const key = callBudgetKey("absfn", impl.fingerprint ?? stableCallId(fn), args);
17781
- const label = fn.shape.name ?? "anonymous";
18639
+ const key = callBudgetKey("absfn", impl.fingerprint ?? stableCallId(fn2), args);
18640
+ const label = fn2.shape.name ?? "anonymous";
17782
18641
  if (!enterCall(key, label)) return truncatedAbs();
17783
18642
  try {
17784
18643
  try {
@@ -17804,8 +18663,8 @@ function $callInner(fn, args, thisVal) {
17804
18663
  }
17805
18664
  const compiled = compiledBodyOf(impl);
17806
18665
  if (compiled) {
17807
- const key = callBudgetKey("absbody", impl.fingerprint ?? stableCallId(fn), args);
17808
- const label = fn.shape.name ?? "anonymous";
18666
+ const key = callBudgetKey("absbody", impl.fingerprint ?? stableCallId(fn2), args);
18667
+ const label = fn2.shape.name ?? "anonymous";
17809
18668
  if (!enterCall(key, label)) return truncatedAbs();
17810
18669
  try {
17811
18670
  const throwMark = throwExitsMark();
@@ -18182,9 +19041,9 @@ function evalObjectMethod(name, args) {
18182
19041
  const key = keyR?.ok ? keyR.value : void 0;
18183
19042
  if (typeof key !== "string") return boolPrim();
18184
19043
  if (a0.shape.k === "obj") {
18185
- const shape = a0.shape;
18186
- if (Object.prototype.hasOwnProperty.call(shape.slots, key)) return boolLit(true);
18187
- if (!shape.open && a0.conf === "exact") return boolLit(false);
19044
+ const shape2 = a0.shape;
19045
+ if (Object.prototype.hasOwnProperty.call(shape2.slots, key)) return boolLit(true);
19046
+ if (!shape2.open && a0.conf === "exact") return boolLit(false);
18188
19047
  return boolPrim();
18189
19048
  }
18190
19049
  return boolPrim();
@@ -21404,6 +22263,40 @@ export {
21404
22263
  $removeMemberNullish,
21405
22264
  $narrowTypeOf,
21406
22265
  $nullishTest,
22266
+ SELF,
22267
+ getTerm,
22268
+ lenTerm,
22269
+ isNudoConstraint,
22270
+ isIntFlag,
22271
+ number,
22272
+ string,
22273
+ boolean,
22274
+ any,
22275
+ array,
22276
+ shape,
22277
+ litC,
22278
+ union,
22279
+ nullable,
22280
+ lazy,
22281
+ derefConstraint,
22282
+ constraintAdmitsNullish,
22283
+ fn,
22284
+ andC,
22285
+ partial,
22286
+ pick,
22287
+ omit,
22288
+ CONSTRAINT_BUILDERS,
22289
+ CONSTRAINT_BUILDER_NAMES,
22290
+ CONSTRAINT_EXPR_RE,
22291
+ instantiateConstraint,
22292
+ instantiateOnTerm,
22293
+ constraintToEntryAbs,
22294
+ fnConstraintToEntryReqs,
22295
+ throwConstraintToKinds,
22296
+ literalMeetsConstraint,
22297
+ attachContractFaces,
22298
+ setContractFaceResolver,
22299
+ contractFacesFromEffectiveInterface,
21407
22300
  clearPureCallMemo,
21408
22301
  setEvalAssignCollector,
21409
22302
  $assignRecord,