jz 0.0.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/narrow.js ADDED
@@ -0,0 +1,928 @@
1
+ /**
2
+ * Signature narrowing — fixpoint analysis that mutates each user func's `sig`
3
+ * based on call-site observations.
4
+ *
5
+ * Reads programFacts.callSites + valueUsed; mutates sig.params/results,
6
+ * func.valResult, and programFacts.paramReps. Pure w.r.t. the AST — only
7
+ * function `sig` records change.
8
+ */
9
+
10
+ import { ctx } from './ctx.js'
11
+ import {
12
+ VAL,
13
+ analyzeBody, analyzeLocals,
14
+ callerParamFactMap, clearStickyNull, ensureParamRep, mergeParamFact,
15
+ exprType, findMutations, hasBareReturn, inferArgArrElemSchema,
16
+ inferArgArrElemValType, inferArgSchema, inferArgType, inferArgTypedCtor,
17
+ invalidateLocalsCache, invalidateValTypesCache, isBlockBody, alwaysReturns,
18
+ narrowReturnArrayElems, observeProgramSlots, returnExprs, staticObjectProps,
19
+ typedElemAux, typedElemCtor, ctorFromElemAux, valTypeOf,
20
+ } from './analyze.js'
21
+
22
+ const PTR_ABI_KINDS = new Set([VAL.OBJECT, VAL.SET, VAL.MAP, VAL.BUFFER])
23
+
24
+ function filterLiveCallSites(callSites, valueUsed) {
25
+ if (!callSites.length) return
26
+
27
+ const live = new Set()
28
+ for (const f of ctx.func.list) {
29
+ if (f.exported || valueUsed.has(f.name)) live.add(f.name)
30
+ }
31
+
32
+ let changed = true
33
+ while (changed) {
34
+ changed = false
35
+ for (const cs of callSites) {
36
+ if (cs.callerFunc === null || live.has(cs.callerFunc.name)) {
37
+ if (!live.has(cs.callee)) { live.add(cs.callee); changed = true }
38
+ }
39
+ }
40
+ }
41
+
42
+ let w = 0
43
+ for (let r = 0; r < callSites.length; r++) {
44
+ const cs = callSites[r]
45
+ if (cs.callerFunc === null || live.has(cs.callerFunc.name)) callSites[w++] = cs
46
+ }
47
+ callSites.length = w
48
+ }
49
+
50
+ function buildCallerCtx() {
51
+ const callerCtx = new Map()
52
+ callerCtx.set(null, { callerLocals: ctx.scope.globalTypes, callerValTypes: ctx.scope.globalValTypes })
53
+ for (const func of ctx.func.list) {
54
+ if (!func.body || func.raw) continue
55
+ const facts = analyzeBody(func.body)
56
+ for (const p of func.sig.params) if (!facts.locals.has(p.name)) facts.locals.set(p.name, p.type)
57
+ callerCtx.set(func, { callerLocals: facts.locals, callerValTypes: facts.valTypes })
58
+ }
59
+ return callerCtx
60
+ }
61
+
62
+ function buildCallerElems(sliceKey) {
63
+ const m = new Map()
64
+ m.set(null, new Map())
65
+ for (const func of ctx.func.list) {
66
+ if (!func.body || func.raw) continue
67
+ m.set(func, analyzeBody(func.body)[sliceKey])
68
+ }
69
+ return m
70
+ }
71
+
72
+ function applyI32ParamSpecialization(paramReps, valueUsed, { skipTyped = false } = {}) {
73
+ for (const func of ctx.func.list) {
74
+ if (func.raw || valueUsed.has(func.name)) continue
75
+ const reps = paramReps.get(func.name)
76
+ if (!reps) continue
77
+ const restIdx = func.rest ? func.sig.params.length - 1 : -1
78
+ for (const [k, r] of reps) {
79
+ if (r.wasm !== 'i32' || k === restIdx) continue
80
+ if (k >= func.sig.params.length) continue
81
+ const p = func.sig.params[k]
82
+ if (p.type === 'i32') continue
83
+ if (func.defaults?.[p.name] != null) continue
84
+ if (skipTyped && r.val === VAL.TYPED) continue
85
+ p.type = 'i32'
86
+ }
87
+ }
88
+ }
89
+
90
+ function validateIntConstParams(paramReps, valueUsed) {
91
+ for (const func of ctx.func.list) {
92
+ if (func.exported || func.raw || valueUsed.has(func.name)) continue
93
+ if (!func.body) continue
94
+ const reps = paramReps.get(func.name)
95
+ if (!reps) continue
96
+ const restIdx = func.rest ? func.sig.params.length - 1 : -1
97
+ let candidates = null
98
+ for (const [k, r] of reps) {
99
+ if (r.intConst == null || k === restIdx) continue
100
+ if (k >= func.sig.params.length) { r.intConst = null; continue }
101
+ const pname = func.sig.params[k].name
102
+ if (func.defaults?.[pname] != null) { r.intConst = null; continue }
103
+ ;(candidates ||= new Map()).set(pname, r)
104
+ }
105
+ if (!candidates) continue
106
+ const mutated = new Set()
107
+ findMutations(func.body, new Set(candidates.keys()), mutated)
108
+ for (const name of mutated) candidates.get(name).intConst = null
109
+ }
110
+ }
111
+
112
+ function applyPointerParamAbi(paramReps, valueUsed) {
113
+ for (const func of ctx.func.list) {
114
+ if (func.exported || func.raw || valueUsed.has(func.name)) continue
115
+ const reps = paramReps.get(func.name)
116
+ if (!reps) continue
117
+ const restIdx = func.rest ? func.sig.params.length - 1 : -1
118
+ for (const [k, r] of reps) {
119
+ if (!PTR_ABI_KINDS.has(r.val)) continue
120
+ if (k === restIdx) continue
121
+ if (k >= func.sig.params.length) continue
122
+ const p = func.sig.params[k]
123
+ if (p.type === 'i32') continue
124
+ if (func.defaults?.[p.name] != null) continue
125
+ p.type = 'i32'
126
+ p.ptrKind = r.val
127
+ }
128
+ }
129
+ }
130
+
131
+ function narrowableFuncs(valueUsed) {
132
+ return ctx.func.list.filter(f =>
133
+ !f.raw && !valueUsed.has(f.name) && f.sig.results.length === 1
134
+ )
135
+ }
136
+
137
+ function refreshCallerValTypes(callerCtx) {
138
+ for (const func of ctx.func.list) {
139
+ if (!func.body || func.raw) continue
140
+ const entry = callerCtx.get(func)
141
+ if (entry) entry.callerValTypes = analyzeBody(func.body).valTypes
142
+ }
143
+ }
144
+
145
+ function buildCallerTypedCtx() {
146
+ const callerTypedCtx = new Map()
147
+ callerTypedCtx.set(null, ctx.scope.globalTypedElem || new Map())
148
+ for (const func of ctx.func.list) {
149
+ if (!func.body || func.raw) continue
150
+ callerTypedCtx.set(func, analyzeBody(func.body).typedElems)
151
+ }
152
+ return callerTypedCtx
153
+ }
154
+
155
+ function applyTypedPointerParamAbi(paramReps, valueUsed) {
156
+ for (const func of ctx.func.list) {
157
+ if (func.exported || func.raw || valueUsed.has(func.name)) continue
158
+ const reps = paramReps.get(func.name)
159
+ if (!reps) continue
160
+ const restIdx = func.rest ? func.sig.params.length - 1 : -1
161
+ for (const [k, r] of reps) {
162
+ const ctor = r.typedCtor
163
+ if (ctor == null) continue
164
+ if (k === restIdx) continue
165
+ if (k >= func.sig.params.length) continue
166
+ const p = func.sig.params[k]
167
+ if (p.type === 'i32') continue
168
+ if (func.defaults?.[p.name] != null) continue
169
+ const aux = typedElemAux(ctor)
170
+ if (aux == null) continue
171
+ p.type = 'i32'
172
+ p.ptrKind = VAL.TYPED
173
+ p.ptrAux = aux
174
+ }
175
+ }
176
+ }
177
+
178
+ function enrichCallerValTypesFromPointerParams(callerCtx) {
179
+ for (const func of ctx.func.list) {
180
+ if (!func.body || func.raw) continue
181
+ const entry = callerCtx.get(func)
182
+ if (!entry) continue
183
+ for (const p of func.sig.params) {
184
+ if (p.ptrKind == null) continue
185
+ if (entry.callerValTypes.has(p.name)) continue
186
+ entry.callerValTypes.set(p.name, p.ptrKind)
187
+ }
188
+ }
189
+ }
190
+
191
+ function refreshCallerLocals(callerCtx) {
192
+ for (const func of ctx.func.list) {
193
+ if (!func.body || func.raw) continue
194
+ invalidateLocalsCache(func.body)
195
+ const fresh = analyzeLocals(func.body)
196
+ for (const p of func.sig.params) if (!fresh.has(p.name)) fresh.set(p.name, p.type)
197
+ callerCtx.get(func).callerLocals = fresh
198
+ }
199
+ }
200
+
201
+ function resetParamWasmFacts(paramReps) {
202
+ for (const m of paramReps.values()) for (const r of m.values()) r.wasm = undefined
203
+ }
204
+
205
+ function createPhaseState() {
206
+ const callerCtx = buildCallerCtx()
207
+ const elemCtx = new Map()
208
+ let callerTypedCtx = null
209
+
210
+ const clearDerived = () => {
211
+ elemCtx.clear()
212
+ callerTypedCtx = null
213
+ }
214
+
215
+ return {
216
+ callerCtx,
217
+
218
+ callerElems(sliceKey) {
219
+ let m = elemCtx.get(sliceKey)
220
+ if (!m) { m = buildCallerElems(sliceKey); elemCtx.set(sliceKey, m) }
221
+ return m
222
+ },
223
+
224
+ callerTyped() {
225
+ callerTypedCtx ||= buildCallerTypedCtx()
226
+ return callerTypedCtx
227
+ },
228
+
229
+ invalidateBodyFacts() {
230
+ for (const func of ctx.func.list) {
231
+ if (func.body && !func.raw) invalidateValTypesCache(func.body)
232
+ }
233
+ clearDerived()
234
+ },
235
+
236
+ refreshValTypes() {
237
+ refreshCallerValTypes(callerCtx)
238
+ clearDerived()
239
+ },
240
+
241
+ refreshLocals() {
242
+ refreshCallerLocals(callerCtx)
243
+ clearDerived()
244
+ },
245
+ }
246
+ }
247
+
248
+ export default function narrowSignatures(programFacts, ast) {
249
+ const { callSites, valueUsed, paramReps, hasSchemaLiterals } = programFacts
250
+
251
+ // Reachability filter: dead callerFuncs (e.g. unused stdlib helpers from bundled
252
+ // modules) shouldn't poison narrowing of live functions. Without this, a never-
253
+ // executed call like `checksumF64 → mix(h, u[i])` would force mix's `x` rep to
254
+ // bimorphic (f64 ∪ i32) and block i32 narrowing of mix's hot caller (runKernel).
255
+ // Live = exported ∪ value-used ∪ transitively reached from those + top-level.
256
+ // Top-level call sites have callerFunc === null and are unconditionally live.
257
+ filterLiveCallSites(callSites, valueUsed)
258
+
259
+ // D: Call-site type propagation — infer param types from how functions are called.
260
+ // Drives off `callSites` collected during the ProgramFacts walk; no AST re-walking.
261
+ // For non-exported internal functions, if all call sites agree on a param's type,
262
+ // seed the param's val rep (ctx.func.repByLocal) during per-function compilation.
263
+ // Also infer i32/f64 WASM type — when all call sites pass i32 for a param, specialize
264
+ // sig.params[k].type to i32 (no default, no rest, not exported, not value-used).
265
+ // Also propagate schema ID — when all call sites pass objects with the same schema,
266
+ // bind the callee's param to that schema so `p.x` becomes a direct slot load.
267
+ // Inference helpers (inferArgType/inferArgSchema/inferArgArr*/inferArgTypedCtor)
268
+ // live in analyze.js — pure AST→fact resolvers shared across fixpoint phases.
269
+ // Per-caller analysis is stable across fixpoint iterations — precompute once.
270
+ // callerCtx[null] (top-level) uses module globals for both locals and valTypes.
271
+ const phase = createPhaseState()
272
+ const { callerCtx } = phase
273
+ const intConstArg = (arg) => {
274
+ let raw = null
275
+ if (typeof arg === 'number') raw = arg
276
+ else if (Array.isArray(arg) && arg[0] == null && typeof arg[1] === 'number') raw = arg[1]
277
+ else if (Array.isArray(arg) && arg[0] === 'u-' && typeof arg[1] === 'number') raw = -arg[1]
278
+ else if (typeof arg === 'string' && ctx.scope.constInts?.has(arg)) raw = ctx.scope.constInts.get(arg)
279
+ return (raw != null && Number.isInteger(raw) && raw >= -2147483648 && raw <= 2147483647) ? raw : null
280
+ }
281
+
282
+ const runCallsiteLattice = (rules) => {
283
+ for (let s = 0; s < callSites.length; s++) {
284
+ const { callee, argList, callerFunc } = callSites[s]
285
+ const func = ctx.func.map.get(callee)
286
+ if (!func || func.exported || valueUsed.has(callee)) continue
287
+ const ctxEntry = callerCtx.get(callerFunc)
288
+ if (!ctxEntry) continue
289
+ const restIdx = func.rest ? func.sig.params.length - 1 : -1
290
+ const paramFacts = new Map()
291
+ const state = {
292
+ callee, callerFunc, argList, func, restIdx,
293
+ callerLocals: ctxEntry.callerLocals,
294
+ callerValTypes: ctxEntry.callerValTypes,
295
+ callerParamFacts(key) {
296
+ if (!paramFacts.has(key)) paramFacts.set(key, callerParamFactMap(paramReps, callerFunc, key))
297
+ return paramFacts.get(key)
298
+ },
299
+ }
300
+ for (let k = 0; k < func.sig.params.length; k++) {
301
+ const r = ensureParamRep(paramReps, callee, k)
302
+ if (k >= argList.length) { for (const rule of rules) rule.missing(r, k, state); continue }
303
+ const arg = argList[k]
304
+ for (const rule of rules) rule.apply(r, arg, k, state)
305
+ }
306
+ }
307
+ }
308
+
309
+ const poison = field => r => { r[field] = null }
310
+ const mergeRule = (field, infer) => ({
311
+ missing: poison(field),
312
+ apply(r, arg, k, state) {
313
+ if (r[field] !== null) mergeParamFact(r, field, infer(arg, k, state))
314
+ },
315
+ })
316
+ const runFixpoint = () => runCallsiteLattice([
317
+ mergeRule('val', (arg, _k, state) => inferArgType(arg, state.callerValTypes)),
318
+ {
319
+ missing: poison('wasm'),
320
+ apply(r, arg, _k, state) {
321
+ if (r.wasm === null) return
322
+ const wt = exprType(arg, state.callerLocals)
323
+ if (r.wasm === undefined) r.wasm = wt
324
+ else if (r.wasm !== wt) r.wasm = null
325
+ },
326
+ },
327
+ mergeRule('schemaId', (arg, _k, state) => inferArgSchema(arg, state.callerParamFacts('schemaId'))),
328
+ {
329
+ missing: poison('intConst'),
330
+ apply(r, arg, k, state) {
331
+ if (k === state.restIdx) r.intConst = null
332
+ else if (r.intConst !== null) mergeParamFact(r, 'intConst', intConstArg(arg))
333
+ },
334
+ },
335
+ ])
336
+ const runArrElemFixpoint = (field, inferFn, elemsCtxMap) => {
337
+ runCallsiteLattice([mergeRule(field, (arg, _k, state) =>
338
+ inferFn(arg, elemsCtxMap.get(state.callerFunc), state.callerParamFacts(field))
339
+ )])
340
+ }
341
+ const runArrFixpoint = () => runArrElemFixpoint('arrayElemSchema', inferArgArrElemSchema, phase.callerElems('arrElemSchemas'))
342
+ const runArrValTypeFixpoint = () => runArrElemFixpoint('arrayElemValType', inferArgArrElemValType, phase.callerElems('arrElemValTypes'))
343
+ runFixpoint()
344
+ runFixpoint()
345
+
346
+ // Apply i32 specialization: for non-value-used funcs with consistent i32 call
347
+ // sites and no defaults/rest at that position, narrow sig.params[k].type.
348
+ // Exports too — boundary wrapper handles the f64→i32 truncation at the JS edge.
349
+ applyI32ParamSpecialization(paramReps, valueUsed)
350
+
351
+ // intConst validation: a param marked with a unanimous integer literal at every call
352
+ // site is only safe to substitute if the body never reassigns it. Clear intConst on any
353
+ // param whose name appears on the LHS of an assignment / `++` / `--`. Skip exported
354
+ // (callable from JS with arbitrary value), value-used (closure callees), raw, defaulted,
355
+ // and rest params — same exclusions as the wasm-narrowing pass above.
356
+ validateIntConstParams(paramReps, valueUsed)
357
+
358
+ // Pointer-ABI specialization: for non-forwarding pointer params consistent across
359
+ // call sites, narrow from NaN-boxed f64 to i32 offset. Eliminates per-call __ptr_offset
360
+ // extraction + f64→i64→i32 reinterpret chains that dominate watr-style compilers.
361
+ // Safety:
362
+ // - exclude ARRAY (forwards on realloc — f64 NaN-box is a stable identity) and
363
+ // STRING (SSO vs heap dual encoding depends on ptr-type bits we'd drop).
364
+ // - exclude CLOSURE/TYPED (aux bits carry schema/element-type, lost with offset).
365
+ // - exclude params with defaults (nullish sentinel needs the f64 NaN space).
366
+ // - exclude rest position (array pack/unpack stays f64).
367
+ applyPointerParamAbi(paramReps, valueUsed)
368
+
369
+ // E: Result-type monomorphization — narrow sig.results[0] to 'i32' when body only
370
+ // produces i32 values. Fixpoint: a call to another narrowed func now contributes i32;
371
+ // iterate until stable so chains of i32-only helpers all narrow together.
372
+ // Safety: skip exported (JS boundary preserves number semantics), value-used (closure
373
+ // trampolines assume f64 result), raw WAT, multi-value. `undefined` return = skip.
374
+ // exprType already consults ctx.func.map for narrowed user-function results
375
+ // (analyze.js exprType `()` branch), plus the Math.imul/Math.clz32/charCodeAt
376
+ // stdlib subset and primitive-op rules. Earlier we had a local shim here that
377
+ // shadowed exprType's stdlib rules with `return 'f64'` for any non-user call;
378
+ // unifying through exprType lets a single rule (math.imul → i32) flow through
379
+ // to mix-style helpers (`(h, x) => Math.imul(h ^ (x|0), C)`) and unblocks the
380
+ // E-phase result narrowing on every call site that consumes them.
381
+ const exprTypeWithCalls = exprType
382
+ // Body-driven: safe for exports — the result type is determined by what the body
383
+ // computes, not by what JS callers might pass. JS-visible f64 ABI is restored at
384
+ // the boundary via a synthesized wrapper (see synthesizeBoundaryWrappers below).
385
+ // Shared pool for E (numeric), E2 (valType) and E3 (ptr) narrowing — same predicate.
386
+ const funcsWithNarrowableResult = narrowableFuncs(valueUsed)
387
+ let changed = true
388
+ while (changed) {
389
+ changed = false
390
+ for (const func of funcsWithNarrowableResult) {
391
+ if (func.sig.results[0] === 'i32') continue
392
+ const body = func.body
393
+ // Bare `return;` produces undef (f64) — narrowing to i32 would lose that.
394
+ if (isBlockBody(body) && hasBareReturn(body)) continue
395
+ const exprs = returnExprs(body)
396
+ if (!exprs.length) continue
397
+ // Skip narrowing when any return-tail is `>>>` (unsigned uint32). Narrowing to i32
398
+ // loses the unsigned interpretation: the wrapper rebox via `f64.convert_i32_s` would
399
+ // sign-flip values with bit 31 set, breaking the canonical `(x >>> 0)` uint32 idiom.
400
+ // A future pass could track sig.unsignedResult and emit `f64.convert_i32_u` instead.
401
+ if (exprs.some(e => Array.isArray(e) && e[0] === '>>>')) continue
402
+ const savedCurrent = ctx.func.current
403
+ ctx.func.current = func.sig
404
+ const locals = isBlockBody(body) ? analyzeLocals(body) : new Map()
405
+ for (const p of func.sig.params) if (!locals.has(p.name)) locals.set(p.name, p.type)
406
+ const allI32 = exprs.every(e => exprTypeWithCalls(e, locals) === 'i32')
407
+ ctx.func.current = savedCurrent
408
+ if (allI32) { func.sig.results = ['i32']; changed = true }
409
+ }
410
+ }
411
+
412
+ // E2: VAL-type result inference — if a function always returns the same VAL kind,
413
+ // record it so callers inherit that type (enables static dispatch on .length, .[],
414
+ // .prop through a call chain). Fixpoint propagates through helper chains.
415
+ // Safety: skip exported (host sees raw f64), value-used (indirect call signature).
416
+ // Shim so calls to already-typed funcs contribute their result type.
417
+ const valTypeOfWithCalls = (expr, localValTypes) => {
418
+ if (expr == null) return null
419
+ if (typeof expr === 'string') return localValTypes?.get(expr) || ctx.scope.globalValTypes?.get(expr) || null
420
+ if (!Array.isArray(expr)) return valTypeOf(expr)
421
+ const [op, ...args] = expr
422
+ if (op === '()' && typeof args[0] === 'string') {
423
+ const f = ctx.func.map.get(args[0])
424
+ if (f?.valResult) return f.valResult
425
+ }
426
+ if (op === '?:') {
427
+ const a = valTypeOfWithCalls(args[1], localValTypes), b = valTypeOfWithCalls(args[2], localValTypes)
428
+ return a && a === b ? a : null
429
+ }
430
+ if (op === '&&' || op === '||') {
431
+ const a = valTypeOfWithCalls(args[0], localValTypes), b = valTypeOfWithCalls(args[1], localValTypes)
432
+ return a && a === b ? a : null
433
+ }
434
+ return valTypeOf(expr)
435
+ }
436
+ // Body-driven valResult inference: same safety analysis as numeric narrowing
437
+ // above — exports OK because boundary wrapper restores f64 ABI for JS callers.
438
+ changed = true
439
+ while (changed) {
440
+ changed = false
441
+ for (const func of funcsWithNarrowableResult) {
442
+ if (func.valResult) continue
443
+ const body = func.body
444
+ const isBlock = isBlockBody(body)
445
+ if (isBlock && hasBareReturn(body)) continue
446
+ const exprs = returnExprs(body)
447
+ if (!exprs.length) continue
448
+ const localValTypes = isBlock ? analyzeBody(body).valTypes : new Map()
449
+ // Params of this function contribute no known VAL type yet (paramReps may help later).
450
+ const vt0 = valTypeOfWithCalls(exprs[0], localValTypes)
451
+ if (!vt0) continue
452
+ const allSame = exprs.every(e => valTypeOfWithCalls(e, localValTypes) === vt0)
453
+ if (allSame) { func.valResult = vt0; changed = true }
454
+ }
455
+ }
456
+
457
+ // Now that E2 set `valResult` on funcs, narrow per-func `arrayElemSchema` for
458
+ // VAL.ARRAY-returning funcs (via push observations + call chains). Then re-run the
459
+ // D-pass arrayElemSchema/val fixpoints so `const rows = initRows()` in main
460
+ // resolves to VAL.ARRAY (lets runKernel pick up r.val=ARRAY) and its arr-elem
461
+ // schema (sets paramReps[runKernel][0].arrayElemSchema=sid).
462
+ // Cache invalidation: analyzeBody.valTypes is body-keyed, and entries cached
463
+ // during the first D pass have stale (null) `valTypeOf(call)` results because
464
+ // valResult was unset back then.
465
+ narrowReturnArrayElems('arrayElemSchema', paramReps, valueUsed)
466
+ narrowReturnArrayElems('arrayElemValType', paramReps, valueUsed)
467
+ phase.invalidateBodyFacts()
468
+ phase.refreshValTypes()
469
+ // Re-observe schema slot val-types now that E2 has set `valResult` on user
470
+ // funcs. First pass runs in collectProgramFacts before valResult is known, so
471
+ // a slot like `cs` in `{ ..., cs }` (where `cs = checksum(out)`) gets observed
472
+ // as null. observeSlot's first-wins-then-clash rule lets a later precise
473
+ // observation upgrade `undefined` → NUMBER without poisoning earlier
474
+ // monomorphic observations.
475
+ if (hasSchemaLiterals) observeProgramSlots(ast)
476
+ // Clear sticky-null on val/schemaId — first 2 passes ran with valResult unset, so
477
+ // call args resolving via `f.valResult` returned null and got stuck. Re-running
478
+ // with refreshed callerValTypes lets these flow.
479
+ clearStickyNull(paramReps, 'val')
480
+ clearStickyNull(paramReps, 'schemaId')
481
+ runFixpoint()
482
+ // Now that .val is refreshed, dedicated arr-elem-schema fixpoint.
483
+ runArrFixpoint()
484
+ runArrFixpoint()
485
+ // Parallel arr-elem-val fixpoint (NUMBER/STRING/…). Twice for transitive closure
486
+ // through helper chains: `init()→main→runKernel`.
487
+ runArrValTypeFixpoint()
488
+ runArrValTypeFixpoint()
489
+ // E3: Result-type pointer narrowing — when valResult is a non-ambiguous pointer kind
490
+ // with constant aux, narrow sig.results[0] from f64 to i32 and tag sig.ptrKind/.ptrAux.
491
+ // Eliminates the f64.reinterpret_i64+i64.or rebox at every return and the
492
+ // i32.wrap_i64+i64.reinterpret_f64 unbox at every callsite that uses the value as a
493
+ // pointer (load .[], .length, .prop slot dispatch).
494
+ // - SET/MAP/BUFFER: aux always 0 — no per-callsite aux preservation needed.
495
+ // - OBJECT: aux is schema-id; narrow only when all return exprs share a constant
496
+ // schema (literal `{a,b,c}`, schemaId-bound param, module-bound var, or call to
497
+ // another OBJECT-narrowed func). Caller picks aux up via callIR.ptrAux → readVar →
498
+ // repByLocal.schemaId, restoring property-slot dispatch through the call boundary.
499
+ // Safety: ARRAY forwards on realloc (no narrowing). STRING dual-encoded SSO/heap.
500
+ // CLOSURE/TYPED also carry meaningful aux — TYPED narrowing is a follow-up. Body must
501
+ // be a guaranteed-return form — fallthrough fallback i32.const 0 would be a valid
502
+ // offset 0 of the narrowed kind, not undefined.
503
+ const PTR_RESULT_KINDS_NOAUX = new Set([VAL.SET, VAL.MAP, VAL.BUFFER])
504
+ // Schema-id inference for a return expression. Returns id (number), or null if unknown
505
+ // / not constant. Mirrors inferArgSchema but extends with calls to already-narrowed
506
+ // OBJECT-result funcs (fixpoint propagation through helper chains).
507
+ const schemaIdOfReturn = (expr, paramSchemasMap) => {
508
+ if (typeof expr === 'string') {
509
+ if (paramSchemasMap?.has(expr)) return paramSchemasMap.get(expr)
510
+ if (ctx.schema.vars.has(expr)) return ctx.schema.vars.get(expr)
511
+ return null
512
+ }
513
+ if (!Array.isArray(expr)) return null
514
+ const [op, ...args] = expr
515
+ if (op === '{}') {
516
+ // Object literal: bail to null on block body, dynamic key, or spread.
517
+ const parsed = staticObjectProps(args)
518
+ return parsed ? ctx.schema.register(parsed.names) : null
519
+ }
520
+ if (op === '()' && typeof args[0] === 'string') {
521
+ const f = ctx.func.map.get(args[0])
522
+ if (f?.valResult === VAL.OBJECT && f.sig.ptrAux != null) return f.sig.ptrAux
523
+ return null
524
+ }
525
+ if (op === '?:') {
526
+ const a = schemaIdOfReturn(args[1], paramSchemasMap)
527
+ const b = schemaIdOfReturn(args[2], paramSchemasMap)
528
+ return a != null && a === b ? a : null
529
+ }
530
+ if (op === '&&' || op === '||') {
531
+ const a = schemaIdOfReturn(args[0], paramSchemasMap)
532
+ const b = schemaIdOfReturn(args[1], paramSchemasMap)
533
+ return a != null && a === b ? a : null
534
+ }
535
+ return null
536
+ }
537
+ // Per-body local elemAux map: scans `let/const x = new TypedArray(...)` decls so
538
+ // a return like `let a = new Float64Array(...); return a` resolves to a constant
539
+ // aux. Result calls + ?: are handled inline in typedAuxOfReturn.
540
+ const localElemAuxMap = (body) => {
541
+ const m = new Map()
542
+ const walk = (n) => {
543
+ if (!Array.isArray(n)) return
544
+ const op = n[0]
545
+ if (op === '=>') return
546
+ if ((op === 'let' || op === 'const') && n.length > 1) {
547
+ for (let i = 1; i < n.length; i++) {
548
+ const a = n[i]
549
+ if (Array.isArray(a) && a[0] === '=' && typeof a[1] === 'string') {
550
+ const aux = typedElemAux(typedElemCtor(a[2]))
551
+ if (aux != null) m.set(a[1], aux)
552
+ }
553
+ }
554
+ }
555
+ for (let i = 1; i < n.length; i++) walk(n[i])
556
+ }
557
+ walk(body)
558
+ return m
559
+ }
560
+ const typedAuxOfReturn = (expr, localElemMap) => {
561
+ if (typeof expr === 'string') return localElemMap?.get(expr) ?? null
562
+ if (!Array.isArray(expr)) return null
563
+ const [op, ...args] = expr
564
+ if (op === '()' && typeof args[0] === 'string') {
565
+ if (args[0].startsWith('new.')) {
566
+ const ctor = typedElemCtor(expr)
567
+ return ctor != null ? typedElemAux(ctor) : null
568
+ }
569
+ const f = ctx.func.map.get(args[0])
570
+ if (f?.valResult === VAL.TYPED && f.sig.ptrAux != null) return f.sig.ptrAux
571
+ return null
572
+ }
573
+ if (op === '?:') {
574
+ const a = typedAuxOfReturn(args[1], localElemMap)
575
+ const b = typedAuxOfReturn(args[2], localElemMap)
576
+ return a != null && a === b ? a : null
577
+ }
578
+ if (op === '&&' || op === '||') {
579
+ const a = typedAuxOfReturn(args[0], localElemMap)
580
+ const b = typedAuxOfReturn(args[1], localElemMap)
581
+ return a != null && a === b ? a : null
582
+ }
583
+ return null
584
+ }
585
+ // Fixpoint: a chain `outer → inner → {a,b}` needs inner to narrow first so outer's
586
+ // call to inner contributes a known schema-id.
587
+ let narrowChanged = true
588
+ while (narrowChanged) {
589
+ narrowChanged = false
590
+ for (const func of funcsWithNarrowableResult) {
591
+ if (!func.valResult) continue
592
+ if (func.sig.results[0] !== 'f64') continue
593
+ const isBlock = isBlockBody(func.body)
594
+ if (isBlock && !alwaysReturns(func.body)) continue
595
+ if (PTR_RESULT_KINDS_NOAUX.has(func.valResult)) {
596
+ func.sig.results = ['i32']
597
+ func.sig.ptrKind = func.valResult
598
+ narrowChanged = true
599
+ continue
600
+ }
601
+ const exprs = returnExprs(func.body)
602
+ if (!exprs.length) continue
603
+ if (func.valResult === VAL.OBJECT) {
604
+ const paramSchemasMap = callerParamFactMap(paramReps, func, 'schemaId')
605
+ const sid0 = schemaIdOfReturn(exprs[0], paramSchemasMap)
606
+ if (sid0 == null) continue
607
+ if (!exprs.every(e => schemaIdOfReturn(e, paramSchemasMap) === sid0)) continue
608
+ func.sig.results = ['i32']
609
+ func.sig.ptrKind = VAL.OBJECT
610
+ func.sig.ptrAux = sid0
611
+ narrowChanged = true
612
+ } else if (func.valResult === VAL.TYPED) {
613
+ const localMap = isBlock ? localElemAuxMap(func.body) : null
614
+ const aux0 = typedAuxOfReturn(exprs[0], localMap)
615
+ if (aux0 == null) continue
616
+ if (!exprs.every(e => typedAuxOfReturn(e, localMap) === aux0)) continue
617
+ func.sig.results = ['i32']
618
+ func.sig.ptrKind = VAL.TYPED
619
+ func.sig.ptrAux = aux0
620
+ narrowChanged = true
621
+ }
622
+ }
623
+ }
624
+
625
+ // F: Cross-call typed-array element ctor propagation. Runs AFTER E3 so that
626
+ // calls to user functions returning a TYPED-narrowed pointer (with constant
627
+ // ptrAux, e.g. mkInput → Float64Array) contribute their element type to the
628
+ // caller's local typedElem map. Result: callees pick up `ctx.types.typedElem`
629
+ // for their own params and `arr[i]` reads emit a direct `f64.load` instead of
630
+ // the runtime `__is_str_key + __typed_idx` dispatch — closes the largest
631
+ // chunk of the JS→wasm gap on f64-heavy hot loops.
632
+ // (Helpers `inferArgTypedCtor`/`ctorFromElemAux` live in analyze.js so the
633
+ // bimorphic-typed specialization pass below can reuse them.)
634
+ // Per-caller typed-elem map, recomputed now that E3 has tagged helper sigs.
635
+ // Cache invalidation: analyzeBody.typedElems reads `ctx.func.map.get(...).sig.ptrKind`
636
+ // for `let x = mkInput(...)` decls; entries cached during the initial walk
637
+ // (before E3 ran) are stale (mkInput's ptrKind was unset then).
638
+ phase.invalidateBodyFacts()
639
+ const callerTypedCtx = phase.callerTyped()
640
+ // Two-pass fixpoint: lets a caller's params, once typed, propagate further to
641
+ // its own callees (e.g. if `outer(buf)` calls `inner(buf)` and we learn `buf`
642
+ // for outer, the second pass picks it up for inner). Reuses runArrElemFixpoint
643
+ // (same shape — field/inferFn/elemsCtxMap parameterization).
644
+ const runTypedFixpoint = () => runArrElemFixpoint('typedCtor', inferArgTypedCtor, callerTypedCtx)
645
+ runTypedFixpoint()
646
+ runTypedFixpoint()
647
+
648
+ // G: TYPED pointer-ABI narrowing — once .typedCtor agrees on a single
649
+ // ctor across all call sites, narrow the param from NaN-boxed f64 to raw
650
+ // i32 offset (with ptrAux carrying the elem-type bits). Eliminates the
651
+ // per-read `i32.wrap_i64 (i64.reinterpret_f64 (local.get $arr))` unbox dance
652
+ // that today dominates hot loops dominated by typed-array indexing.
653
+ // Call sites coerce via emitArgForParam → ptrOffsetIR(arg, VAL.TYPED).
654
+ // Safety: same exclusions as the OBJECT/SET/MAP/BUFFER narrowing above —
655
+ // exported, value-used, raw, defaults, rest position.
656
+ applyTypedPointerParamAbi(paramReps, valueUsed)
657
+
658
+ // H: Post-F/G re-fixpoint — propagates VAL kinds through bimorphic call sites
659
+ // where ptrKind narrowed but ptrAux disagreed (e.g. `sum(f64arr)` and `sum(i32arr)`
660
+ // → both VAL.TYPED, different ctors). Without this, callerValTypes carries no entry
661
+ // for caller's params, so inferArgType returns null and paramReps[callee][k].val is
662
+ // sticky null. With ptrKind enriching callerValTypes, sum's arr gets val=TYPED in
663
+ // its rep, letting array.js skip __is_str_key + __str_idx dispatch on `arr[i]`.
664
+ enrichCallerValTypesFromPointerParams(callerCtx)
665
+ clearStickyNull(paramReps, 'val')
666
+ runFixpoint()
667
+
668
+ // I: Post-E re-narrow of numeric (i32) params. The first numeric narrowing pass
669
+ // ran before E narrowed any result types, so callerLocals saw `let h = mix(...)`
670
+ // as f64 (mix's result was f64 then). After E narrowed mix's result to i32,
671
+ // exprType (which now consults func.sig.results for user calls) sees `h` as i32.
672
+ // Refresh callerLocals + clear sticky-null wasm + re-run fixpoint + re-apply
673
+ // numeric narrowing to propagate i32 through chains of i32-only helpers
674
+ // (callback bench: mix is FNV — params and result all i32-shaped, but inferred
675
+ // only after E phase narrowed mix's result).
676
+ phase.refreshLocals()
677
+ // Reset wasm field unconditionally — first pass populated it from stale callerLocals
678
+ // (where `let h = mix(...)` widened h to f64 because mix's result wasn't narrowed
679
+ // yet). clearStickyNull only resets null; here we need to reset f64-observed too
680
+ // so the refreshed exprType view propagates.
681
+ resetParamWasmFacts(paramReps)
682
+ runFixpoint()
683
+ // Don't steal typed-array params from specializeBimorphicTyped: F phase parks
684
+ // bimorphic typed params at type='f64' with sticky-null typedCtor (two distinct
685
+ // ctors at call sites). Their callers post-F pass them as i32 (pointer ABI),
686
+ // so r.wasm flips to 'i32' here — but narrowing now breaks the clone path
687
+ // that still needs to mint per-ctor sigs with ptrKind=TYPED, ptrAux=ctor-aux.
688
+ applyI32ParamSpecialization(paramReps, valueUsed, { skipTyped: true })
689
+ }
690
+
691
+ /**
692
+ * Phase: bimorphic typed-array param specialization.
693
+ *
694
+ * For each non-exported user function with a typed-array param that F/G-phase
695
+ * left bimorphic (paramReps[name][k].typedCtor === null because two or more call sites
696
+ * disagreed on the elem-ctor — e.g. `sum(f64)` and `sum(i32)`), clone the
697
+ * function once per concrete ctor seen at the call sites, narrow each clone's
698
+ * sig.params[k] to a monomorphic typed pointer ABI (type='i32', ptrKind=TYPED,
699
+ * ptrAux=ctor's aux), and rewrite the call AST nodes to dispatch to the right
700
+ * clone. The original survives as a fallback for any non-static call sites
701
+ * (e.g. inside arrow bodies); treeshake removes it if every site got rewritten.
702
+ *
703
+ * Why this matters: without specialization, `arr[i]` inside `sum` falls into
704
+ * the runtime `__typed_idx` path on every iteration — V8 can't inline a wasm
705
+ * call dominated by a switch on elem type. After specialization, each clone's
706
+ * `arr[i]` lowers to a direct `f64.load` (or `i32.load + f64.convert`) with
707
+ * the elem-ctor known at compile time. On poly bench this is the difference
708
+ * between ~5 ms and matching AS at ~1 ms.
709
+ *
710
+ * Safety mirrors G-phase: skip exported, raw, value-used, defaulted, rest, or
711
+ * already-i32 params. Bounded by MAX_CLONES_PER_FN to guard against polymorphic
712
+ * blow-up (≥5 distinct ctors at one site → no specialization).
713
+ */
714
+ export function specializeBimorphicTyped(programFacts) {
715
+ const { callSites, valueUsed, paramReps } = programFacts
716
+ const MAX_CLONES_PER_FN = 4
717
+
718
+ // Per-callee static-call-site index. Built once; cheap.
719
+ const sitesByCallee = new Map()
720
+ for (const cs of callSites) {
721
+ const list = sitesByCallee.get(cs.callee)
722
+ if (list) list.push(cs); else sitesByCallee.set(cs.callee, [cs])
723
+ }
724
+
725
+ // Per-caller typedElem map (literal `new TypedArray(N)` bindings inside body).
726
+ const callerTypedCtx = new Map()
727
+ callerTypedCtx.set(null, ctx.scope.globalTypedElem || new Map())
728
+ for (const func of ctx.func.list) {
729
+ if (!func.body || func.raw) continue
730
+ callerTypedCtx.set(func, analyzeBody(func.body).typedElems)
731
+ }
732
+ // Per-caller typed-param map: caller's own params that F/G already narrowed
733
+ // (so transitive `sum(arr)` inside a func that took `arr` from above resolves).
734
+ const callerTypedParamsCtx = new Map()
735
+ for (const func of ctx.func.list) {
736
+ const m = callerParamFactMap(paramReps, func, 'typedCtor') || null
737
+ let acc = m
738
+ if (func.sig?.params) for (const p of func.sig.params) {
739
+ if (p.ptrKind === VAL.TYPED && p.ptrAux != null) {
740
+ acc ||= new Map()
741
+ if (!acc.has(p.name)) acc.set(p.name, ctorFromElemAux(p.ptrAux))
742
+ }
743
+ }
744
+ if (acc) callerTypedParamsCtx.set(func, acc)
745
+ }
746
+
747
+ // Snapshot ctx.func.list — we'll be appending clones during the loop.
748
+ const originals = ctx.func.list.slice()
749
+ for (const func of originals) {
750
+ if (func.exported || func.raw || valueUsed.has(func.name)) continue
751
+ if (!func.body) continue
752
+ if (func.rest) continue
753
+ const reps = paramReps.get(func.name)
754
+ if (!reps) continue
755
+ const sites = sitesByCallee.get(func.name)
756
+ if (!sites || sites.length < 2) continue
757
+
758
+ // Find sticky-bimorphic typed-param positions left by F-phase.
759
+ const bimorphic = []
760
+ for (let k = 0; k < func.sig.params.length; k++) {
761
+ const r = reps.get(k)
762
+ if (!r || r.val !== VAL.TYPED || r.typedCtor !== null) continue
763
+ const p = func.sig.params[k]
764
+ if (p.type === 'i32') continue
765
+ if (func.defaults?.[p.name] != null) continue
766
+ bimorphic.push(k)
767
+ }
768
+ if (bimorphic.length === 0) continue
769
+
770
+ // For each site, infer the ctor combination across bimorphic positions.
771
+ // Abort if any site has unknown ctor at any bimorphic position — we can't
772
+ // route that call to a specific clone without it.
773
+ const siteCombos = []
774
+ let abort = false
775
+ for (const site of sites) {
776
+ const callerTypedElems = callerTypedCtx.get(site.callerFunc)
777
+ const callerTypedParams = callerTypedParamsCtx.get(site.callerFunc)
778
+ const combo = []
779
+ for (const k of bimorphic) {
780
+ if (k >= site.argList.length) { abort = true; break }
781
+ const c = inferArgTypedCtor(site.argList[k], callerTypedElems, callerTypedParams)
782
+ if (c == null || typedElemAux(c) == null) { abort = true; break }
783
+ combo.push(c)
784
+ }
785
+ if (abort) break
786
+ siteCombos.push(combo)
787
+ }
788
+ if (abort) continue
789
+
790
+ // Distinct combos seen across call sites.
791
+ const distinct = new Map()
792
+ for (const combo of siteCombos) {
793
+ const key = combo.join('|')
794
+ if (!distinct.has(key)) distinct.set(key, combo)
795
+ }
796
+ if (distinct.size < 2) continue // F-phase already mono — nothing to do
797
+ if (distinct.size > MAX_CLONES_PER_FN) continue // polymorphic blow-up
798
+
799
+ // Build one clone per distinct combo.
800
+ const cloneByKey = new Map()
801
+ for (const [key, combo] of distinct) {
802
+ const suffix = combo.map(c => c.replace(/^new\./, '').replace(/\./g, '_')).join('$')
803
+ let cloneName = `${func.name}$${suffix}`
804
+ let n = 0
805
+ while (ctx.func.names.has(cloneName)) cloneName = `${func.name}$${suffix}$${++n}`
806
+
807
+ const cloneSig = {
808
+ ...func.sig,
809
+ params: func.sig.params.map(p => ({ ...p })),
810
+ results: [...func.sig.results],
811
+ }
812
+ for (let i = 0; i < bimorphic.length; i++) {
813
+ const k = bimorphic[i]
814
+ const aux = typedElemAux(combo[i])
815
+ const p = cloneSig.params[k]
816
+ p.type = 'i32'
817
+ p.ptrKind = VAL.TYPED
818
+ p.ptrAux = aux
819
+ }
820
+ const clone = { ...func, name: cloneName, sig: cloneSig }
821
+ ctx.func.list.push(clone)
822
+ ctx.func.map.set(cloneName, clone)
823
+ ctx.func.names.add(cloneName)
824
+
825
+ // Mirror per-param reps under the clone's name with mono ctors at bimorphic
826
+ // positions. emitFunc's preseed reads typedCtor → seeds typedElem map →
827
+ // `arr[i]` lowers to direct typed load.
828
+ const cloneReps = new Map()
829
+ for (const [k, r] of reps) cloneReps.set(k, { ...r })
830
+ for (let i = 0; i < bimorphic.length; i++) {
831
+ const k = bimorphic[i]
832
+ const r = cloneReps.get(k) || {}
833
+ r.typedCtor = combo[i]
834
+ r.val = VAL.TYPED
835
+ cloneReps.set(k, r)
836
+ }
837
+ paramReps.set(cloneName, cloneReps)
838
+
839
+ cloneByKey.set(key, clone)
840
+ }
841
+
842
+ // Rewrite each site's call AST to point at the matching clone.
843
+ for (let i = 0; i < sites.length; i++) {
844
+ const clone = cloneByKey.get(siteCombos[i].join('|'))
845
+ sites[i].node[1] = clone.name
846
+ }
847
+ }
848
+ }
849
+
850
+ /**
851
+ * Phase: refine ctx.types.anyDynKey using post-narrowSignatures type info.
852
+ */
853
+ const NON_DYN_VTS = new Set([VAL.TYPED, VAL.ARRAY, VAL.STRING, VAL.BUFFER])
854
+ const TYPED_ARRAY_CTOR = /^(Float|Int|Uint|BigInt|BigUint)(8|16|32|64)(Clamped)?Array$/
855
+
856
+ export function refineDynKeys(programFacts) {
857
+ if (!ctx.types.anyDynKey) return
858
+ const { paramReps, valueUsed } = programFacts
859
+ const isLitStr = idx => Array.isArray(idx) && idx[0] === 'str' && typeof idx[1] === 'string'
860
+
861
+ // Per-function type map: param vtypes from paramReps, plus locals
862
+ // we can prove are typed arrays from `let v = new TypedArray(...)`. After
863
+ // prepare, that node is `['()', 'new.Float64Array', ...args]`.
864
+ const buildTypeMap = (funcName, body, params) => {
865
+ const map = new Map()
866
+ if (params) {
867
+ const reps = paramReps.get(funcName)
868
+ if (reps) for (let i = 0; i < params.length; i++) {
869
+ const t = reps.get(i)?.val
870
+ if (t != null) map.set(params[i].name, t)
871
+ }
872
+ }
873
+ const walk = (node) => {
874
+ if (!Array.isArray(node)) return
875
+ const op = node[0]
876
+ if (op === 'let' || op === 'const') {
877
+ for (let i = 1; i < node.length; i++) {
878
+ const d = node[i]
879
+ if (!Array.isArray(d) || d[0] !== '=' || typeof d[1] !== 'string') continue
880
+ const init = d[2]
881
+ let ctor = null
882
+ if (Array.isArray(init) && init[0] === '()' && typeof init[1] === 'string' && init[1].startsWith('new.'))
883
+ ctor = init[1].slice(4)
884
+ if (ctor && TYPED_ARRAY_CTOR.test(ctor)) map.set(d[1], VAL.TYPED)
885
+ else if (typeof init === 'string' && map.has(init)) map.set(d[1], map.get(init))
886
+ }
887
+ }
888
+ if (op === '=>') return // don't cross into nested arrows; they're separate funcs
889
+ for (let i = 1; i < node.length; i++) walk(node[i])
890
+ }
891
+ walk(body)
892
+ return map
893
+ }
894
+
895
+ let real = false
896
+ const visit = (typeMap, node) => {
897
+ if (real || !Array.isArray(node)) return
898
+ const op = node[0]
899
+ if (op === '[]') {
900
+ const idx = node[2]
901
+ if (!isLitStr(idx)) {
902
+ const obj = node[1]
903
+ const vt = typeof obj === 'string' ? typeMap.get(obj) : null
904
+ if (!NON_DYN_VTS.has(vt)) real = true
905
+ }
906
+ } else if (op === 'for-in') real = true
907
+ if (op === '=>') return
908
+ for (let i = 1; i < node.length; i++) visit(typeMap, node[i])
909
+ }
910
+
911
+ // Live: anything reachable from exports/first-class value uses. Skipping
912
+ // dead helpers (unused benchlib imports) keeps their generic params from
913
+ // pretending to be dyn-key access.
914
+ const isLive = f => f.exported || paramReps.has(f.name) || (valueUsed && valueUsed.has(f.name))
915
+
916
+ const topMap = buildTypeMap(null, null, null)
917
+ for (const f of ctx.func.list) {
918
+ if (real) break
919
+ if (!f.body || !isLive(f)) continue
920
+ visit(buildTypeMap(f.name, f.body, f.sig?.params), f.body)
921
+ }
922
+ if (!real && ctx.module.initFacts?.anyDyn && ctx.module.moduleInits) for (const mi of ctx.module.moduleInits) {
923
+ if (real) break
924
+ visit(topMap, mi)
925
+ }
926
+
927
+ if (!real) ctx.types.anyDynKey = false
928
+ }