@geastack/compiler 1.0.49 → 1.0.62

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.
Files changed (125) hide show
  1. package/README.md +57 -19
  2. package/dist/cli.js +2 -1
  3. package/dist/compiler.js +8 -2
  4. package/dist/conversion/derive.js +5 -0
  5. package/dist/conversion/native-field-view.d.ts +7 -0
  6. package/dist/conversion/native-field-view.js +50 -0
  7. package/dist/conversion/native-record-products.js +1 -0
  8. package/dist/conversion/native-view-origins.d.ts +1 -1
  9. package/dist/conversion/native-view-origins.js +5 -4
  10. package/dist/conversion/nodes.d.ts +9 -0
  11. package/dist/conversion/nodes.js +18 -0
  12. package/dist/conversion/record-view.d.ts +25 -1
  13. package/dist/conversion/record-view.js +61 -2
  14. package/dist/conversion/structural-plan.js +7 -6
  15. package/dist/ir/borrowed-field-reads.d.ts +30 -0
  16. package/dist/ir/borrowed-field-reads.js +218 -0
  17. package/dist/ir/borrowed-window-cells.d.ts +35 -0
  18. package/dist/ir/borrowed-window-cells.js +117 -0
  19. package/dist/ir/call-dispatch.js +21 -4
  20. package/dist/ir/callable-class-flow.js +269 -43
  21. package/dist/ir/captures.js +18 -1
  22. package/dist/ir/certify.js +14 -1
  23. package/dist/ir/construction-only-fields.d.ts +15 -1
  24. package/dist/ir/construction-only-fields.js +71 -3
  25. package/dist/ir/dead-logical-merge.d.ts +4 -0
  26. package/dist/ir/dead-logical-merge.js +89 -18
  27. package/dist/ir/dense-loops.d.ts +38 -4
  28. package/dist/ir/dense-loops.js +112 -17
  29. package/dist/ir/dense-read-windows.d.ts +42 -0
  30. package/dist/ir/dense-read-windows.js +137 -0
  31. package/dist/ir/facts.d.ts +12 -0
  32. package/dist/ir/facts.js +18 -2
  33. package/dist/ir/field-read-reuse.d.ts +71 -0
  34. package/dist/ir/field-read-reuse.js +430 -0
  35. package/dist/ir/hoist.d.ts +19 -2
  36. package/dist/ir/hoist.js +143 -24
  37. package/dist/ir/lower-narrow.js +19 -1
  38. package/dist/ir/model.d.ts +19 -0
  39. package/dist/ir/native-field-view-domains.d.ts +12 -2
  40. package/dist/ir/native-field-view-domains.js +51 -15
  41. package/dist/ir/native-field-view-facts.js +5 -2
  42. package/dist/ir/native-method-frames.js +15 -2
  43. package/dist/ir/plain-field-read.d.ts +31 -0
  44. package/dist/ir/plain-field-read.js +51 -0
  45. package/dist/ir/program-facts.d.ts +14 -0
  46. package/dist/ir/program-facts.js +85 -2
  47. package/dist/ir/proven-branches.js +8 -1
  48. package/dist/ir/publish-conversion-recipes.js +5 -1
  49. package/dist/ir/short-circuit-threading.d.ts +12 -4
  50. package/dist/ir/short-circuit-threading.js +124 -12
  51. package/dist/ir/stable-cell-reads.d.ts +24 -1
  52. package/dist/ir/stable-cell-reads.js +65 -42
  53. package/dist/ir/write-effects.d.ts +42 -0
  54. package/dist/ir/write-effects.js +208 -0
  55. package/dist/plugins/gea/contract.d.ts +3 -2
  56. package/dist/plugins/gea/contract.js +3 -1
  57. package/dist/plugins/gea/host.d.ts +7 -2
  58. package/dist/plugins/gea/host.js +25 -5
  59. package/dist/project-preparation.d.ts +11 -0
  60. package/dist/project-preparation.js +44 -0
  61. package/dist/projection/classes.d.ts +8 -0
  62. package/dist/projection/classes.js +112 -12
  63. package/dist/projection/dispatch.d.ts +24 -4
  64. package/dist/projection/dispatch.js +71 -2
  65. package/dist/projection/fields.js +2 -2
  66. package/dist/representation/model.d.ts +3 -0
  67. package/dist/representation/model.js +3 -0
  68. package/dist/representation/value-records.js +22 -0
  69. package/dist/semantics/frontend-timing.d.ts +9 -0
  70. package/dist/semantics/frontend-timing.js +43 -2
  71. package/dist/semantics/frontend.js +103 -7
  72. package/dist/semantics/model/operations.d.ts +7 -0
  73. package/dist/semantics/normalize/binding-fixpoint.js +7 -2
  74. package/dist/semantics/normalize/callable-data-write.js +6 -2
  75. package/dist/semantics/normalize/field-bindings.js +151 -111
  76. package/dist/semantics/normalize/flow/callable-reach.js +27 -0
  77. package/dist/semantics/normalize/flow/component-solver.js +23 -5
  78. package/dist/semantics/normalize/flow/source-record-data.js +6 -2
  79. package/dist/semantics/normalize/flow/source-value-session.d.ts +13 -0
  80. package/dist/semantics/normalize/flow/source-value-session.js +207 -65
  81. package/dist/semantics/normalize/global-host-mutations.js +162 -1
  82. package/dist/semantics/normalize/parameter-bindings.js +16 -1
  83. package/dist/semantics/normalize/producers/class-lifecycle.js +2 -1
  84. package/dist/semantics/normalize/producers/erasure.js +13 -8
  85. package/dist/semantics/subclass-member-overlay-transform.js +17 -4
  86. package/dist/semantics/typescript-tsgo.d.ts +20 -0
  87. package/dist/semantics/typescript-tsgo.js +832 -0
  88. package/dist/semantics/typescript.d.ts +0 -9
  89. package/dist/semantics/typescript.js +4 -1
  90. package/dist/targets/cpp/borrowed-call-entry.d.ts +9 -0
  91. package/dist/targets/cpp/borrowed-call-entry.js +12 -2
  92. package/dist/targets/cpp/captures.js +4 -0
  93. package/dist/targets/cpp/class-properties/computed-method-value.d.ts +1 -1
  94. package/dist/targets/cpp/class-properties/computed-method-value.js +17 -7
  95. package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +8 -0
  96. package/dist/targets/cpp/class-properties/emit-class-properties.js +62 -2
  97. package/dist/targets/cpp/class-properties/native-method-read.js +12 -1
  98. package/dist/targets/cpp/conversions.js +1 -0
  99. package/dist/targets/cpp/emit-arrays.d.ts +5 -0
  100. package/dist/targets/cpp/emit-arrays.js +60 -10
  101. package/dist/targets/cpp/emit-binding-reference.d.ts +19 -6
  102. package/dist/targets/cpp/emit-binding-reference.js +26 -8
  103. package/dist/targets/cpp/emit-bindings.js +22 -0
  104. package/dist/targets/cpp/emit-callable.js +133 -16
  105. package/dist/targets/cpp/emit-carrier-members.d.ts +6 -0
  106. package/dist/targets/cpp/emit-carrier-members.js +24 -2
  107. package/dist/targets/cpp/emit-context.d.ts +97 -1
  108. package/dist/targets/cpp/emit-context.js +52 -0
  109. package/dist/targets/cpp/emit-equality.js +3 -0
  110. package/dist/targets/cpp/emit-narrowing.js +9 -0
  111. package/dist/targets/cpp/emit-native-field-view.d.ts +24 -0
  112. package/dist/targets/cpp/emit-native-field-view.js +87 -8
  113. package/dist/targets/cpp/emit-properties.js +139 -16
  114. package/dist/targets/cpp/emit-record-view.js +49 -22
  115. package/dist/targets/cpp/emit-return.js +5 -1
  116. package/dist/targets/cpp/emit-tonumber.js +4 -1
  117. package/dist/targets/cpp/emit-union-properties.js +1 -1
  118. package/dist/targets/cpp/emit.d.ts +4 -1
  119. package/dist/targets/cpp/emit.js +148 -6
  120. package/dist/targets/cpp/reactive-dependencies.js +100 -28
  121. package/dist/targets/cpp/translation-unit.js +71 -17
  122. package/dist/targets/cpp/virtual-methods.d.ts +2 -2
  123. package/dist/targets/cpp/virtual-methods.js +11 -3
  124. package/package.json +1 -1
  125. package/src/targets/cpp/runtime/gea_runtime.h +400 -21
@@ -0,0 +1,218 @@
1
+ import { controlFlowGraphOf } from './dominance.js';
2
+ import { fieldReadFactsOf } from './field-read-reuse.js';
3
+ import { allOperationsOf } from './model.js';
4
+ import { operandsOfIrOperation } from './queries.js';
5
+ /**
6
+ * Field reads, and the merges of them `reuseFieldReads` built, that may name
7
+ * the field they read instead of holding a counted copy of it.
8
+ *
9
+ * A slab test reads `box.min` and `box.max` once per axis; the reuse pass
10
+ * turned six reads into two and carries each across the axis branches through
11
+ * a phi. Each kept read still copied the handle -- a retain and a release per
12
+ * box, per field -- because the value lives across statements, and the phi
13
+ * copied again. The field holds that value for as long as nothing can store
14
+ * the key, rewrite the receiver's cell, or run program code: exactly the
15
+ * availability `field-read-reuse.ts` already tracks. So a read, or a phi of
16
+ * such reads, may be a pointer to the field when, at every use, the read is
17
+ * still available under that same value and the use itself forgets nothing
18
+ * of it.
19
+ *
20
+ * A use that is a phi this admits is checked on its edge, at the end of the
21
+ * predecessor. Any other use reads through the pointer where it stands; a
22
+ * merge this does not admit copies at its edge. A member every use cannot
23
+ * vouch for leaves, and so does every phi that merges it, until nothing moves.
24
+ *
25
+ * Only reads through a binding cell (`admitsCell`): the cell keeps the
26
+ * receiver alive until something writes it, and a write of the cell forgets
27
+ * the read. A receiver that is itself an SSA value may render as an alias of
28
+ * another field that a store of a different key can release. `borrowable`
29
+ * is the target's answer to which reads it renders as a load at all.
30
+ */
31
+ export const borrowedFieldReadsOf = (body, codeFree, admitsCell, borrowable, inlined) => {
32
+ if (body.tryRegions.length > 0 || (body.iteratorCloseRegions?.length ?? 0) > 0)
33
+ return new Set();
34
+ for (const block of body.blocks.values())
35
+ for (const operation of block.operations)
36
+ if (operation.kind === 'await' || operation.kind === 'yield')
37
+ return new Set();
38
+ const facts = fieldReadFactsOf(body, codeFree);
39
+ const cellOf = new Map();
40
+ for (const block of body.blocks.values())
41
+ for (const operation of block.operations)
42
+ if (operation.kind === 'binding-read')
43
+ cellOf.set(operation.result.id, operation.declaration);
44
+ // A read with one use renders inline at it, a load with no copy, and so does
45
+ // one the target re-renders at each use (`inlined`); only a read held across
46
+ // statements, or carried by a merge, has a copy to save.
47
+ const uses = new Map();
48
+ const mergeInputs = new Set();
49
+ for (const block of body.blocks.values())
50
+ for (const operation of allOperationsOf(block)) {
51
+ if (operation.kind === 'phi')
52
+ for (const incoming of operation.incoming)
53
+ mergeInputs.add(incoming.value.value);
54
+ for (const operand of operandsOfIrOperation(operation))
55
+ uses.set(operand.value, (uses.get(operand.value) ?? 0) + 1);
56
+ }
57
+ const members = new Set();
58
+ for (const [operation] of facts.candidates) {
59
+ if (((uses.get(operation.result.id) ?? 0) < 2 || inlined(operation.result.id)) && !mergeInputs.has(operation.result.id))
60
+ continue;
61
+ const cell = cellOf.get(operation.receiver.value);
62
+ if (cell === undefined || !admitsCell(cell) || facts.pinned.has(operation.result.id))
63
+ continue;
64
+ if (operation.result.representation.kind === 'scalar' || !borrowable(operation))
65
+ continue;
66
+ members.add(operation.result.id);
67
+ }
68
+ if (members.size === 0)
69
+ return members;
70
+ const phis = [];
71
+ for (const block of body.blocks.values())
72
+ for (const operation of block.operations)
73
+ if (operation.kind === 'phi')
74
+ phis.push(operation);
75
+ const closePhis = () => {
76
+ for (let growing = true; growing;) {
77
+ growing = false;
78
+ for (const phi of phis)
79
+ if (!members.has(phi.result.id) && phi.incoming.every((incoming) => members.has(incoming.value.value))) {
80
+ members.add(phi.result.id);
81
+ growing = true;
82
+ }
83
+ }
84
+ };
85
+ closePhis();
86
+ const graph = controlFlowGraphOf(body);
87
+ const predecessorsOf = (block) => [...new Set(graph.predecessors.get(block) ?? [])];
88
+ const transferOne = (current, operation) => {
89
+ if (operation.kind === 'get') {
90
+ const candidate = facts.candidates.get(operation);
91
+ if (candidate !== undefined) {
92
+ const receiver = facts.receiverOf(operation.receiver.value);
93
+ const id = facts.factId(receiver, candidate.key, candidate.shape);
94
+ if (!current.has(id))
95
+ current.set(id, { receiver, key: candidate.key, value: operation.result.id });
96
+ return;
97
+ }
98
+ }
99
+ const kill = facts.killOf(operation);
100
+ if (kill === null)
101
+ return;
102
+ for (const [id, fact] of current)
103
+ if (facts.forgets(kill, fact))
104
+ current.delete(id);
105
+ };
106
+ const holds = (current, value) => [...current.values()].find((fact) => fact.value === value);
107
+ const exits = new Map();
108
+ const entries = new Map();
109
+ // A join whose predecessors hold different reads holds a phi of them, when
110
+ // the block has one: the reuse pass built exactly those. The phi is matched
111
+ // by its incoming values, not by the reads' fact ids: a read's published
112
+ // facts (its recipes) differ per site once they are certified, so two reads
113
+ // the reuse pass merged no longer share an id here.
114
+ const merge = (blockId) => {
115
+ const predecessors = predecessorsOf(blockId);
116
+ if (blockId === body.entry || predecessors.length === 0)
117
+ return new Map();
118
+ const reached = predecessors.flatMap((predecessor) => {
119
+ const exit = exits.get(predecessor);
120
+ return exit === undefined ? [] : [{ predecessor, exit }];
121
+ });
122
+ const [first, ...rest] = reached;
123
+ if (first === undefined)
124
+ return null;
125
+ const blockPhis = (body.blocks.get(blockId)?.operations ?? []).filter((operation) => operation.kind === 'phi');
126
+ const merged = new Map();
127
+ for (const [id, fact] of first.exit)
128
+ if (rest.every(({ exit }) => exit.get(id)?.value === fact.value))
129
+ merged.set(id, fact);
130
+ for (const phi of blockPhis) {
131
+ const held = reached.map(({ predecessor, exit }) => {
132
+ const incoming = phi.incoming.find((candidate) => candidate.block === predecessor);
133
+ return incoming === undefined ? undefined : holds(exit, incoming.value.value);
134
+ });
135
+ const [one, ...others] = held;
136
+ if (one === undefined || others.some((other) => other === undefined || other.receiver !== one.receiver || other.key !== one.key))
137
+ continue;
138
+ merged.set(`phi:${phi.result.id}`, { receiver: one.receiver, key: one.key, value: phi.result.id });
139
+ }
140
+ return merged;
141
+ };
142
+ const same = (left, right) => left.size === right.size && [...left].every(([id, fact]) => right.get(id)?.value === fact.value);
143
+ let settled = false;
144
+ for (let round = 0; round < 64 && !settled; round++) {
145
+ settled = true;
146
+ for (const blockId of body.blockOrder) {
147
+ const block = body.blocks.get(blockId);
148
+ if (block === undefined)
149
+ continue;
150
+ const incoming = merge(blockId);
151
+ if (incoming === null)
152
+ continue;
153
+ entries.set(blockId, new Map(incoming));
154
+ for (const operation of block.operations)
155
+ transferOne(incoming, operation);
156
+ const previous = exits.get(blockId);
157
+ if (previous === undefined || !same(previous, incoming)) {
158
+ exits.set(blockId, incoming);
159
+ settled = false;
160
+ }
161
+ }
162
+ }
163
+ if (!settled)
164
+ return new Set();
165
+ // Every use of a member, and whether it can vouch for it.
166
+ const vouched = () => {
167
+ for (const blockId of body.blockOrder) {
168
+ const block = body.blocks.get(blockId);
169
+ const entry = entries.get(blockId);
170
+ if (block === undefined)
171
+ continue;
172
+ const current = new Map(entry ?? []);
173
+ for (const operation of block.operations) {
174
+ if (operation.kind === 'phi') {
175
+ // On its edge: the predecessor's exit must still hold the incoming read.
176
+ for (const incoming of operation.incoming) {
177
+ if (!members.has(incoming.value.value))
178
+ continue;
179
+ if (holds(exits.get(incoming.block) ?? new Map(), incoming.value.value) === undefined)
180
+ return incoming.value.value;
181
+ }
182
+ continue;
183
+ }
184
+ for (const operand of operandsOfIrOperation(operation)) {
185
+ if (!members.has(operand.value))
186
+ continue;
187
+ if (entry === undefined)
188
+ return operand.value;
189
+ const fact = holds(current, operand.value);
190
+ if (fact === undefined)
191
+ return operand.value;
192
+ // Code the use runs would see the field through the pointer: a getter
193
+ // handed the read as its receiver, a call handed it as an argument.
194
+ if (facts.forgets(facts.killOf(operation), fact))
195
+ return operand.value;
196
+ }
197
+ transferOne(current, operation);
198
+ }
199
+ for (const operand of operandsOfIrOperation(block.terminator))
200
+ if (members.has(operand.value) && (entry === undefined || holds(current, operand.value) === undefined))
201
+ return operand.value;
202
+ }
203
+ return null;
204
+ };
205
+ for (let failed = vouched(); failed !== null; failed = vouched()) {
206
+ members.delete(failed);
207
+ // A phi that merges a value no longer borrowed copies at its edges.
208
+ for (let shrinking = true; shrinking;) {
209
+ shrinking = false;
210
+ for (const phi of phis)
211
+ if (members.has(phi.result.id) && phi.incoming.some((incoming) => !members.has(incoming.value.value))) {
212
+ members.delete(phi.result.id);
213
+ shrinking = true;
214
+ }
215
+ }
216
+ }
217
+ return members;
218
+ };
@@ -0,0 +1,35 @@
1
+ import type { DeclarationId, IrValueId } from '../identity/ids.js';
2
+ import { type IrBlockId, type IrBody } from './model.js';
3
+ /**
4
+ * Cells that may hold the address of the dense window cell they are written
5
+ * from, instead of a counted copy of the element.
6
+ *
7
+ * `const box = boxes[i]` in a loop over a dense window stores the element into
8
+ * `box`'s cell, and for a counted element that store is a retain and a release
9
+ * on every turn: a collision world's raycast and groundHeight paid one per box,
10
+ * the largest piece of a game's enemy update. The window's cell already holds
11
+ * the element, and keeps holding it for as long as nothing changes the array.
12
+ *
13
+ * So the cell may name the array's cell when:
14
+ *
15
+ * - the body writes it exactly once, with a window read (`windowReads`, the
16
+ * reads the target renders as the cell itself) that has no other use;
17
+ * - the innermost loop around that write changes no array storage
18
+ * (`mutatesArrayStorage`, `ir/hoist.ts`'s authority): no element store
19
+ * can replace the element and release it, and no push or call can move the
20
+ * storage the address points into;
21
+ * - every read of the cell is inside that loop and comes after the write,
22
+ * dominating it and earlier in `blockOrder` as `stableFieldCellsOf` asks.
23
+ * Both in one loop, a read always sees this turn's write: a turn that
24
+ * reaches the read without passing the write would give a path from entry
25
+ * that skips it, and the write would not dominate. A read after the loop
26
+ * could see storage a later push moved;
27
+ * - nothing else names the cell (`admits`: a closure or another frame reads
28
+ * it with code this body does not render), and each read wants the
29
+ * written carrier.
30
+ *
31
+ * A body with exception or iterator-close regions keeps its cells: the
32
+ * dominator tree does not carry those edges. A suspending body keeps them too:
33
+ * other code runs while it is suspended.
34
+ */
35
+ export declare const borrowedWindowCellsOf: (body: IrBody, windowReads: ReadonlySet<IrValueId>, mutatesArrayStorage: (blocks: ReadonlySet<IrBlockId>) => boolean, admits: (declaration: DeclarationId) => boolean) => ReadonlySet<DeclarationId>;
@@ -0,0 +1,117 @@
1
+ import { representationKey } from '../representation/model.js';
2
+ import { controlFlowGraphOf, dominatorTreeOf, naturalLoopsOf } from './dominance.js';
3
+ import { allOperationsOf } from './model.js';
4
+ import { operandsOfIrOperation, resultOfIrOperation } from './queries.js';
5
+ /**
6
+ * Cells that may hold the address of the dense window cell they are written
7
+ * from, instead of a counted copy of the element.
8
+ *
9
+ * `const box = boxes[i]` in a loop over a dense window stores the element into
10
+ * `box`'s cell, and for a counted element that store is a retain and a release
11
+ * on every turn: a collision world's raycast and groundHeight paid one per box,
12
+ * the largest piece of a game's enemy update. The window's cell already holds
13
+ * the element, and keeps holding it for as long as nothing changes the array.
14
+ *
15
+ * So the cell may name the array's cell when:
16
+ *
17
+ * - the body writes it exactly once, with a window read (`windowReads`, the
18
+ * reads the target renders as the cell itself) that has no other use;
19
+ * - the innermost loop around that write changes no array storage
20
+ * (`mutatesArrayStorage`, `ir/hoist.ts`'s authority): no element store
21
+ * can replace the element and release it, and no push or call can move the
22
+ * storage the address points into;
23
+ * - every read of the cell is inside that loop and comes after the write,
24
+ * dominating it and earlier in `blockOrder` as `stableFieldCellsOf` asks.
25
+ * Both in one loop, a read always sees this turn's write: a turn that
26
+ * reaches the read without passing the write would give a path from entry
27
+ * that skips it, and the write would not dominate. A read after the loop
28
+ * could see storage a later push moved;
29
+ * - nothing else names the cell (`admits`: a closure or another frame reads
30
+ * it with code this body does not render), and each read wants the
31
+ * written carrier.
32
+ *
33
+ * A body with exception or iterator-close regions keeps its cells: the
34
+ * dominator tree does not carry those edges. A suspending body keeps them too:
35
+ * other code runs while it is suspended.
36
+ */
37
+ export const borrowedWindowCellsOf = (body, windowReads, mutatesArrayStorage, admits) => {
38
+ if (windowReads.size === 0 || body.tryRegions.length > 0 || (body.iteratorCloseRegions?.length ?? 0) > 0)
39
+ return new Set();
40
+ const writes = new Map();
41
+ const reads = new Map();
42
+ const refused = new Set();
43
+ const uses = new Map();
44
+ const definedIn = new Map();
45
+ for (const [block, contents] of body.blocks) {
46
+ for (const [index, operation] of allOperationsOf(contents).entries()) {
47
+ if (operation.kind === 'await' || operation.kind === 'yield')
48
+ return new Set();
49
+ for (const operand of operandsOfIrOperation(operation))
50
+ uses.set(operand.value, (uses.get(operand.value) ?? 0) + 1);
51
+ const result = resultOfIrOperation(operation);
52
+ if (result !== null)
53
+ definedIn.set(result.id, block);
54
+ if (operation.kind === 'binding-write') {
55
+ const sites = writes.get(operation.declaration) ?? [];
56
+ sites.push({ block, index, value: operation.value.value, key: representationKey(operation.value.representation) });
57
+ writes.set(operation.declaration, sites);
58
+ }
59
+ else if (operation.kind === 'binding-read') {
60
+ const sites = reads.get(operation.declaration) ?? [];
61
+ sites.push({ block, index, key: representationKey(operation.result.representation) });
62
+ reads.set(operation.declaration, sites);
63
+ }
64
+ else if ('declaration' in operation && typeof operation.declaration === 'string') {
65
+ refused.add(operation.declaration);
66
+ }
67
+ }
68
+ }
69
+ const dominance = dominatorTreeOf(body);
70
+ // Every back edge to one header is one loop here: a `continue` in a `while`
71
+ // gives a header two latches, and each natural loop alone misses the blocks
72
+ // only the other path runs in the same turn.
73
+ const loopBlocks = new Map();
74
+ for (const loop of naturalLoopsOf(controlFlowGraphOf(body), dominance)) {
75
+ const blocks = loopBlocks.get(loop.header) ?? new Set();
76
+ for (const block of loop.blocks)
77
+ blocks.add(block);
78
+ loopBlocks.set(loop.header, blocks);
79
+ }
80
+ const innermostLoopOf = (block) => {
81
+ let found = null;
82
+ for (const blocks of loopBlocks.values())
83
+ if (blocks.has(block) && (found === null || blocks.size < found.size))
84
+ found = blocks;
85
+ return found;
86
+ };
87
+ const neutral = new Map();
88
+ const order = new Map(body.blockOrder.map((block, position) => [block, position]));
89
+ const cells = new Set();
90
+ for (const [declaration, sites] of writes) {
91
+ const write = sites[0];
92
+ if (sites.length !== 1 || write === undefined || refused.has(declaration))
93
+ continue;
94
+ if (!windowReads.has(write.value) || uses.get(write.value) !== 1 || !admits(declaration))
95
+ continue;
96
+ const loop = innermostLoopOf(write.block);
97
+ const readBlock = definedIn.get(write.value);
98
+ if (loop === null || readBlock === undefined || !loop.has(readBlock))
99
+ continue;
100
+ const unchanged = neutral.get(loop) ?? !mutatesArrayStorage(loop);
101
+ neutral.set(loop, unchanged);
102
+ if (!unchanged)
103
+ continue;
104
+ const writeOrder = order.get(write.block);
105
+ if (writeOrder === undefined)
106
+ continue;
107
+ const after = (read) => {
108
+ if (read.block === write.block)
109
+ return write.index < read.index;
110
+ const readOrder = order.get(read.block);
111
+ return readOrder !== undefined && writeOrder < readOrder && dominance.dominates(write.block, read.block);
112
+ };
113
+ if ((reads.get(declaration) ?? []).every((read) => loop.has(read.block) && after(read) && read.key === write.key))
114
+ cells.add(declaration);
115
+ }
116
+ return cells;
117
+ };
@@ -3,7 +3,7 @@ import { closedClassFieldCallablesOf } from './callable-class-flow.js';
3
3
  import { closedStaticCallablesOf } from './static-callables.js';
4
4
  import { explicitObjectConstructEntryOf } from './construct-entry.js';
5
5
  import { closedCallFrameOf, publishOmittedArgumentConversions } from './call-entry.js';
6
- import { classFamilyOverridesOf, extendsClass, virtualDispatchFor } from '../projection/dispatch.js';
6
+ import { classDynamicMethodShadowOf, classFamilyOverridesOf, extendsClass, virtualDispatchFor } from '../projection/dispatch.js';
7
7
  import { classMemberOf, classMethodOverrideOf, classPrototypeMethodMutableOf, declaredRecordFieldOf } from '../projection/fields.js';
8
8
  import { abiKey, representationKey, walkRepresentation } from '../representation/model.js';
9
9
  import { abiOfCallee } from '../projection/callee.js';
@@ -1099,11 +1099,27 @@ const rewriteBody = (body, classes, abiOf, capturesNothing, verdict, callableBin
1099
1099
  if (operation.kind !== 'call')
1100
1100
  return operation;
1101
1101
  const { target, closedCallee, ownShadowGuard } = resolveCall(operation, body, producers, classes, abiOf, capturesNothing, verdict, callableBindings, callableMembers);
1102
+ const guardProducer = producers.get(operation.callee.value);
1103
+ const guardReceiver = guardProducer?.kind === 'get' ? guardProducer.receiver : undefined;
1104
+ const guardKey = guardProducer?.kind === 'get' &&
1105
+ guardReceiver?.representation.kind === 'class-ref' &&
1106
+ operation.receiver?.value === guardReceiver.value
1107
+ ? constantStringKeyOf(guardProducer.key.value, producers)
1108
+ : null;
1109
+ const expandoShadowGuard = guardKey !== null &&
1110
+ guardReceiver?.representation.kind === 'class-ref' &&
1111
+ classDynamicMethodShadowOf(classes, guardReceiver.representation.declaration, guardKey)
1112
+ ? { key: guardKey }
1113
+ : undefined;
1102
1114
  if (target.kind === 'unresolved' && closedCallee === undefined) {
1103
- if (ownShadowGuard === undefined)
1115
+ if (ownShadowGuard === undefined && expandoShadowGuard === undefined)
1104
1116
  return operation;
1105
1117
  blockChanged = true;
1106
- return { ...operation, ownShadowGuard };
1118
+ return {
1119
+ ...operation,
1120
+ ...(ownShadowGuard === undefined ? {} : { ownShadowGuard }),
1121
+ ...(expandoShadowGuard === undefined ? {} : { expandoShadowGuard })
1122
+ };
1107
1123
  }
1108
1124
  // A closed static body whose ABI has no receiver cannot observe the
1109
1125
  // constructor used for method syntax. Keep its evaluation in preceding
@@ -1124,7 +1140,8 @@ const rewriteBody = (body, classes, abiOf, capturesNothing, verdict, callableBin
1124
1140
  ...received,
1125
1141
  ...(closedFrame === undefined ? {} : { closedFrame }),
1126
1142
  ...(target.kind === 'unresolved' ? {} : { target }),
1127
- ...(closedCallee === undefined ? {} : { closedCallee })
1143
+ ...(closedCallee === undefined ? {} : { closedCallee }),
1144
+ ...(expandoShadowGuard === undefined ? {} : { expandoShadowGuard })
1128
1145
  };
1129
1146
  });
1130
1147
  if (blockChanged) {