@geastack/compiler 1.0.48 → 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.
- package/README.md +57 -19
- package/dist/cli.js +2 -1
- package/dist/compiler.d.ts +1 -1
- package/dist/compiler.js +13 -6
- package/dist/conversion/derive.js +5 -0
- package/dist/conversion/native-field-view.d.ts +7 -0
- package/dist/conversion/native-field-view.js +50 -0
- package/dist/conversion/native-record-products.js +1 -0
- package/dist/conversion/native-view-origins.d.ts +1 -1
- package/dist/conversion/native-view-origins.js +5 -4
- package/dist/conversion/nodes.d.ts +9 -0
- package/dist/conversion/nodes.js +18 -0
- package/dist/conversion/record-view.d.ts +25 -1
- package/dist/conversion/record-view.js +61 -2
- package/dist/conversion/structural-plan.js +7 -6
- package/dist/ir/borrowed-field-reads.d.ts +30 -0
- package/dist/ir/borrowed-field-reads.js +218 -0
- package/dist/ir/borrowed-window-cells.d.ts +35 -0
- package/dist/ir/borrowed-window-cells.js +117 -0
- package/dist/ir/call-dispatch.js +21 -4
- package/dist/ir/callable-class-flow.js +269 -43
- package/dist/ir/captures.js +18 -1
- package/dist/ir/certify.js +14 -1
- package/dist/ir/construction-only-fields.d.ts +15 -1
- package/dist/ir/construction-only-fields.js +71 -3
- package/dist/ir/dead-logical-merge.d.ts +4 -0
- package/dist/ir/dead-logical-merge.js +89 -18
- package/dist/ir/dense-loops.d.ts +38 -4
- package/dist/ir/dense-loops.js +112 -17
- package/dist/ir/dense-read-windows.d.ts +42 -0
- package/dist/ir/dense-read-windows.js +137 -0
- package/dist/ir/facts.d.ts +12 -0
- package/dist/ir/facts.js +18 -2
- package/dist/ir/field-read-reuse.d.ts +71 -0
- package/dist/ir/field-read-reuse.js +430 -0
- package/dist/ir/hoist.d.ts +19 -2
- package/dist/ir/hoist.js +143 -24
- package/dist/ir/lower-narrow.js +19 -1
- package/dist/ir/model.d.ts +19 -0
- package/dist/ir/native-field-view-domains.d.ts +12 -2
- package/dist/ir/native-field-view-domains.js +51 -15
- package/dist/ir/native-field-view-facts.js +5 -2
- package/dist/ir/native-method-frames.js +15 -2
- package/dist/ir/plain-field-read.d.ts +31 -0
- package/dist/ir/plain-field-read.js +51 -0
- package/dist/ir/program-facts.d.ts +14 -0
- package/dist/ir/program-facts.js +85 -2
- package/dist/ir/proven-branches.js +8 -1
- package/dist/ir/publish-conversion-recipes.js +5 -1
- package/dist/ir/short-circuit-threading.d.ts +12 -4
- package/dist/ir/short-circuit-threading.js +124 -12
- package/dist/ir/stable-cell-reads.d.ts +24 -1
- package/dist/ir/stable-cell-reads.js +65 -42
- package/dist/ir/write-effects.d.ts +42 -0
- package/dist/ir/write-effects.js +208 -0
- package/dist/plugins/gea/contract.d.ts +3 -2
- package/dist/plugins/gea/contract.js +3 -1
- package/dist/plugins/gea/host.d.ts +7 -2
- package/dist/plugins/gea/host.js +25 -5
- package/dist/project-preparation.d.ts +11 -0
- package/dist/project-preparation.js +44 -0
- package/dist/projection/classes.d.ts +8 -0
- package/dist/projection/classes.js +112 -12
- package/dist/projection/dispatch.d.ts +24 -4
- package/dist/projection/dispatch.js +71 -2
- package/dist/projection/fields.js +2 -2
- package/dist/representation/model.d.ts +3 -0
- package/dist/representation/model.js +3 -0
- package/dist/representation/value-records.js +22 -0
- package/dist/semantics/frontend-timing.d.ts +9 -0
- package/dist/semantics/frontend-timing.js +43 -2
- package/dist/semantics/frontend.js +103 -7
- package/dist/semantics/model/operations.d.ts +7 -0
- package/dist/semantics/normalize/binding-fixpoint.js +7 -2
- package/dist/semantics/normalize/callable-data-write.js +6 -2
- package/dist/semantics/normalize/field-bindings.js +151 -111
- package/dist/semantics/normalize/flow/callable-reach.js +27 -0
- package/dist/semantics/normalize/flow/component-solver.js +23 -5
- package/dist/semantics/normalize/flow/source-record-data.js +6 -2
- package/dist/semantics/normalize/flow/source-value-session.d.ts +13 -0
- package/dist/semantics/normalize/flow/source-value-session.js +207 -65
- package/dist/semantics/normalize/global-host-mutations.js +162 -1
- package/dist/semantics/normalize/parameter-bindings.js +16 -1
- package/dist/semantics/normalize/producers/class-lifecycle.js +2 -1
- package/dist/semantics/normalize/producers/erasure.js +13 -8
- package/dist/semantics/subclass-member-overlay-transform.d.ts +3 -2
- package/dist/semantics/subclass-member-overlay-transform.js +416 -316
- package/dist/semantics/typescript-tsgo.d.ts +20 -0
- package/dist/semantics/typescript-tsgo.js +832 -0
- package/dist/semantics/typescript.d.ts +0 -9
- package/dist/semantics/typescript.js +4 -1
- package/dist/targets/cpp/borrowed-call-entry.d.ts +9 -0
- package/dist/targets/cpp/borrowed-call-entry.js +12 -2
- package/dist/targets/cpp/captures.js +4 -0
- package/dist/targets/cpp/class-properties/computed-method-value.d.ts +1 -1
- package/dist/targets/cpp/class-properties/computed-method-value.js +17 -7
- package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +8 -0
- package/dist/targets/cpp/class-properties/emit-class-properties.js +62 -2
- package/dist/targets/cpp/class-properties/native-method-read.js +12 -1
- package/dist/targets/cpp/conversions.js +1 -0
- package/dist/targets/cpp/emit-arrays.d.ts +5 -0
- package/dist/targets/cpp/emit-arrays.js +60 -10
- package/dist/targets/cpp/emit-binding-reference.d.ts +19 -6
- package/dist/targets/cpp/emit-binding-reference.js +26 -8
- package/dist/targets/cpp/emit-bindings.js +22 -0
- package/dist/targets/cpp/emit-callable.js +133 -16
- package/dist/targets/cpp/emit-carrier-members.d.ts +6 -0
- package/dist/targets/cpp/emit-carrier-members.js +24 -2
- package/dist/targets/cpp/emit-context.d.ts +97 -1
- package/dist/targets/cpp/emit-context.js +52 -0
- package/dist/targets/cpp/emit-equality.js +3 -0
- package/dist/targets/cpp/emit-narrowing.js +9 -0
- package/dist/targets/cpp/emit-native-field-view.d.ts +24 -0
- package/dist/targets/cpp/emit-native-field-view.js +87 -8
- package/dist/targets/cpp/emit-properties.js +139 -16
- package/dist/targets/cpp/emit-record-view.js +49 -22
- package/dist/targets/cpp/emit-return.js +5 -1
- package/dist/targets/cpp/emit-tonumber.js +4 -1
- package/dist/targets/cpp/emit-union-properties.js +1 -1
- package/dist/targets/cpp/emit.d.ts +4 -1
- package/dist/targets/cpp/emit.js +148 -6
- package/dist/targets/cpp/reactive-dependencies.js +100 -28
- package/dist/targets/cpp/translation-unit.js +71 -17
- package/dist/targets/cpp/virtual-methods.d.ts +2 -2
- package/dist/targets/cpp/virtual-methods.js +11 -3
- package/package.json +1 -1
- package/src/targets/cpp/runtime/gea_runtime.h +400 -21
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
import { operandsOfIrOperation } from './queries.js';
|
|
2
|
+
const primitiveKinds = new Set(['scalar', 'string', 'null', 'undefined', 'symbol', 'record-literal']);
|
|
3
|
+
const primitive = (value) => {
|
|
4
|
+
if (value.kind === 'optional')
|
|
5
|
+
return primitive(value.payload);
|
|
6
|
+
if (value.kind === 'tagged-union')
|
|
7
|
+
return value.arms.every((arm) => primitive(arm.value));
|
|
8
|
+
return primitiveKinds.has(value.kind);
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Runs of constant-index accesses of one array with nothing between them that
|
|
12
|
+
* can change the array's storage.
|
|
13
|
+
*
|
|
14
|
+
* A matrix multiply reads sixteen elements of each operand in a row
|
|
15
|
+
* (`const a11 = ae[0], a12 = ae[4], ...`) and stores sixteen into its own,
|
|
16
|
+
* and every access checked the array's live source, descriptors, integrity,
|
|
17
|
+
* bounds, holes and undefined marks again: the check's cold path is a call,
|
|
18
|
+
* after which the backend must reload every field it tested, so it re-tested
|
|
19
|
+
* them all for the next access. Loops already take a dense window once
|
|
20
|
+
* (`dense-loops.ts`); a run in straight-line code takes it at its first access,
|
|
21
|
+
* sized for its highest index, and the rest use the cells.
|
|
22
|
+
*
|
|
23
|
+
* A run is one block's accesses of one receiver -- one SSA value, or one cell
|
|
24
|
+
* that nothing writes in between -- with only operations that run no program
|
|
25
|
+
* code and store nothing between them: constants, cell reads and writes,
|
|
26
|
+
* primitive arithmetic and conversions, tests, and further element reads. A
|
|
27
|
+
* store into a run's array keeps that run open and ends every other: the other
|
|
28
|
+
* array may be the same object, and a store whose window failed takes the
|
|
29
|
+
* plain path, which may grow and so move the cells. Anything else ends every
|
|
30
|
+
* open run, since a call may resize, reshape or replace any array.
|
|
31
|
+
*/
|
|
32
|
+
export const straightLineArrayWindowsOf = (body, excluded, firstOrdinal = 0) => {
|
|
33
|
+
const reads = new Map();
|
|
34
|
+
const writes = new Map();
|
|
35
|
+
if (body.tryRegions.length > 0 || (body.iteratorCloseRegions?.length ?? 0) > 0 || body.generator || body.async)
|
|
36
|
+
return { reads, writes };
|
|
37
|
+
const indices = new Map();
|
|
38
|
+
const cells = new Map();
|
|
39
|
+
for (const block of body.blocks.values())
|
|
40
|
+
for (const operation of block.operations) {
|
|
41
|
+
// A canonical array index, however the key was spelled: `m[0]` and `m['0']` name one element.
|
|
42
|
+
if (operation.kind === 'constant' &&
|
|
43
|
+
(operation.literal === 'number' || operation.literal === 'string') &&
|
|
44
|
+
/^(0|[1-9]\d{0,8})$/.test(operation.text))
|
|
45
|
+
indices.set(operation.result.id, Number(operation.text));
|
|
46
|
+
if (operation.kind === 'binding-read')
|
|
47
|
+
cells.set(operation.result.id, operation.declaration);
|
|
48
|
+
}
|
|
49
|
+
let ordinal = firstOrdinal;
|
|
50
|
+
const identityOf = (value) => {
|
|
51
|
+
const cell = cells.get(value);
|
|
52
|
+
return cell === undefined ? `value:${value}` : `cell:${cell}`;
|
|
53
|
+
};
|
|
54
|
+
const safe = (operation) => {
|
|
55
|
+
switch (operation.kind) {
|
|
56
|
+
case 'constant':
|
|
57
|
+
case 'binding-read':
|
|
58
|
+
case 'test':
|
|
59
|
+
return true;
|
|
60
|
+
case 'compute':
|
|
61
|
+
return operandsOfIrOperation(operation).every((operand) => primitive(operand.representation));
|
|
62
|
+
case 'convert':
|
|
63
|
+
return primitive(operation.source.representation) && primitive(operation.result.representation);
|
|
64
|
+
default:
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const finish = (run) => {
|
|
69
|
+
if (run.members.length < 2)
|
|
70
|
+
return;
|
|
71
|
+
const last = Math.max(...run.members.map((member) => member.index));
|
|
72
|
+
run.members.forEach((member, position) => {
|
|
73
|
+
const window = { ordinal, initialize: position === 0, last, mutable: run.writes };
|
|
74
|
+
if ('read' in member)
|
|
75
|
+
reads.set(member.read, window);
|
|
76
|
+
else
|
|
77
|
+
writes.set(member.write, window);
|
|
78
|
+
});
|
|
79
|
+
ordinal++;
|
|
80
|
+
};
|
|
81
|
+
for (const blockId of body.blockOrder) {
|
|
82
|
+
const block = body.blocks.get(blockId);
|
|
83
|
+
if (!block)
|
|
84
|
+
continue;
|
|
85
|
+
const open = new Map();
|
|
86
|
+
const closeAll = (except) => {
|
|
87
|
+
for (const [identity, run] of open) {
|
|
88
|
+
if (identity === except)
|
|
89
|
+
continue;
|
|
90
|
+
finish(run);
|
|
91
|
+
open.delete(identity);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
const runOf = (identity) => {
|
|
95
|
+
const known = open.get(identity);
|
|
96
|
+
if (known !== undefined)
|
|
97
|
+
return known;
|
|
98
|
+
const run = { members: [], writes: false };
|
|
99
|
+
open.set(identity, run);
|
|
100
|
+
return run;
|
|
101
|
+
};
|
|
102
|
+
for (const operation of block.operations) {
|
|
103
|
+
if (operation.kind === 'get' && operation.receiver.representation.kind === 'array-object' && !excluded.has(operation.result.id)) {
|
|
104
|
+
const index = indices.get(operation.key.value);
|
|
105
|
+
if (index !== undefined) {
|
|
106
|
+
runOf(identityOf(operation.receiver.value)).members.push({ read: operation.result.id, index });
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (operation.kind === 'set' && operation.receiver.representation.kind === 'array-object') {
|
|
111
|
+
const index = indices.get(operation.key.value);
|
|
112
|
+
if (index !== undefined) {
|
|
113
|
+
const identity = identityOf(operation.receiver.value);
|
|
114
|
+
closeAll(identity);
|
|
115
|
+
const run = runOf(identity);
|
|
116
|
+
run.members.push({ write: operation, index });
|
|
117
|
+
run.writes = true;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (operation.kind === 'binding-write') {
|
|
122
|
+
// A write of the receiver's own cell names a different array from here on.
|
|
123
|
+
const identity = `cell:${operation.declaration}`;
|
|
124
|
+
const run = open.get(identity);
|
|
125
|
+
if (run !== undefined) {
|
|
126
|
+
finish(run);
|
|
127
|
+
open.delete(identity);
|
|
128
|
+
}
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
if (!safe(operation))
|
|
132
|
+
closeAll();
|
|
133
|
+
}
|
|
134
|
+
closeAll();
|
|
135
|
+
}
|
|
136
|
+
return { reads, writes };
|
|
137
|
+
};
|
package/dist/ir/facts.d.ts
CHANGED
|
@@ -9,6 +9,8 @@ import { type DeclaredIntegerWidth, type IntegerStorageFacts } from './integers.
|
|
|
9
9
|
import { type CallOperation, type ComputeOperation, type GetOperation, type IrBody, type IrOperand, type IrOperation } from './model.js';
|
|
10
10
|
import { type NumericIntrinsic } from './numeric-intrinsics.js';
|
|
11
11
|
import { type SharedStringLayout } from './string-layout-reuse.js';
|
|
12
|
+
import { type DenseReadWindow } from './dense-read-windows.js';
|
|
13
|
+
import type { SetOperation } from './model.js';
|
|
12
14
|
import { type TypeQueryComparison } from './type-query-results.js';
|
|
13
15
|
export interface IrBodyCensus {
|
|
14
16
|
/** Protocol cursors that never escape their `get-iterator`, so the printer may hold them by value. */
|
|
@@ -48,6 +50,10 @@ export interface IrBodyCensus {
|
|
|
48
50
|
readonly hoists: HoistPlan;
|
|
49
51
|
readonly hoistedResults: ReadonlySet<IrValueId>;
|
|
50
52
|
readonly sharedStringLayouts: ReadonlyMap<IrValueId, SharedStringLayout>;
|
|
53
|
+
/** Constant-index element reads that share one dense window -- see `ir/dense-read-windows.ts`. */
|
|
54
|
+
readonly denseReadWindows: ReadonlyMap<IrValueId, DenseReadWindow>;
|
|
55
|
+
/** The stores of those runs, keyed by operation since a store has no result. */
|
|
56
|
+
readonly denseWriteWindows: ReadonlyMap<SetOperation, DenseReadWindow>;
|
|
51
57
|
readonly reusedStringLengths: ReadonlyMap<IrValueId, IrOperand>;
|
|
52
58
|
}
|
|
53
59
|
/**
|
|
@@ -97,6 +103,12 @@ export interface IrBodyCensusPolicy {
|
|
|
97
103
|
readonly formalStorage: (settled: IrBodyCensusBeforeHoists) => ReadonlySet<DeclarationId>;
|
|
98
104
|
/** Whether this body reads the declaration through its own by-value copy, which no call it makes can change. */
|
|
99
105
|
readonly copiedCapture: (declaration: DeclarationId) => boolean;
|
|
106
|
+
/** Whether it reads a box written exactly once (`IrBodyFacts.settledBoxes`), which code the loop calls may still write. */
|
|
107
|
+
readonly settledCapture?: (declaration: DeclarationId) => boolean;
|
|
108
|
+
/** Whether this store writes a data field and runs nothing: no setter, no view routine, no reactive cell. */
|
|
109
|
+
readonly codeFreeStore?: (operation: SetOperation) => boolean;
|
|
110
|
+
/** Whether this property read runs none of the program's code (`ir/plain-field-read.ts`'s `codeFreeGetOf`); absent, only native data and host methods do. */
|
|
111
|
+
readonly codeFreeGet?: (operation: GetOperation) => boolean;
|
|
100
112
|
}
|
|
101
113
|
/** What is known when `formalStorage` runs: everything except the hoists and the two censuses that read them. */
|
|
102
114
|
export type IrBodyCensusBeforeHoists = Pick<IrBodyCensus, 'localIterators' | 'deferrable' | 'callArgumentOnly' | 'forwardedBindings' | 'dead' | 'unread' | 'booleanConstants' | 'typeQueryValues' | 'typeQueryBindings' | 'typeQueryComparisons' | 'integerValues' | 'integerBindings' | 'float32' | 'remainderForms' | 'roundingArithmetic' | 'integerDivisions' | 'nonZeroDivisors' | 'declaredWidths' | 'exactNumericConversions' | 'declaredIntegerCells' | 'numericCalls' | 'numericCallOnly'>;
|
package/dist/ir/facts.js
CHANGED
|
@@ -8,6 +8,7 @@ import { allOperationsOf } from './model.js';
|
|
|
8
8
|
import { numericIntrinsicsOf } from './numeric-intrinsics.js';
|
|
9
9
|
import { operandsOfIrOperation, resultOfIrOperation } from './queries.js';
|
|
10
10
|
import { sharedStringLayoutsOf, straightLineStringLayoutsOf } from './string-layout-reuse.js';
|
|
11
|
+
import { straightLineArrayWindowsOf } from './dense-read-windows.js';
|
|
11
12
|
import { stableStringReceiversOf, stringLengthReuseOf } from './string-length-reuse.js';
|
|
12
13
|
import { typeQueryResultsOf } from './type-query-results.js';
|
|
13
14
|
/**
|
|
@@ -116,7 +117,7 @@ export const irBodyCensusOf = (body, policy) => {
|
|
|
116
117
|
};
|
|
117
118
|
const stableFormals = policy.formalStorage(settled);
|
|
118
119
|
const loopInvariantValues = loopInvariantValuesOf(body);
|
|
119
|
-
const hoists = loopInvariantHoistsOf(body, policy.integerStorage.cellConstants, policy.copiedCapture);
|
|
120
|
+
const hoists = loopInvariantHoistsOf(body, policy.integerStorage.cellConstants, policy.copiedCapture, policy.settledCapture, policy.codeFreeStore, policy.codeFreeGet);
|
|
120
121
|
const hoistedStringLayouts = sharedStringLayoutsOf(body, hoists, dead);
|
|
121
122
|
const stringReceivers = stableStringReceiversOf(body, stableFormals, policy.stringQueryCell);
|
|
122
123
|
const straightLineStringLayouts = straightLineStringLayoutsOf(body, stringReceivers, new Set([...dead, ...hoists.relocated]), Math.max(-1, ...[...hoistedStringLayouts.values()].map((layout) => layout.ordinal)) + 1);
|
|
@@ -132,6 +133,12 @@ export const irBodyCensusOf = (body, policy) => {
|
|
|
132
133
|
// by every later member from there, so none of them may render at its use.
|
|
133
134
|
for (const value of straightLineStringLayouts.keys())
|
|
134
135
|
deferrable.delete(value);
|
|
136
|
+
// Likewise a window: its first read takes it, so every member renders in order.
|
|
137
|
+
const denseWindows = straightLineArrayWindowsOf(body, new Set([...dead, ...hoists.relocated]));
|
|
138
|
+
const denseReadWindows = denseWindows.reads;
|
|
139
|
+
const denseWriteWindows = denseWindows.writes;
|
|
140
|
+
for (const value of denseReadWindows.keys())
|
|
141
|
+
deferrable.delete(value);
|
|
135
142
|
const reusedStringLengths = stringLengthReuseOf(body, stringReceivers, new Set([...dead, ...hoists.relocated, ...straightLineStringLayouts.keys()]));
|
|
136
143
|
// A reused result must be stored at its dominating definition, even if its
|
|
137
144
|
// original single consumer would otherwise defer that computation.
|
|
@@ -145,7 +152,16 @@ export const irBodyCensusOf = (body, policy) => {
|
|
|
145
152
|
if ((!deferrable.has(forwarded.value.value) && forwarded.stepped !== true) || !deferrable.has(forwarded.read))
|
|
146
153
|
forwardedBindings.delete(declaration);
|
|
147
154
|
}
|
|
148
|
-
return {
|
|
155
|
+
return {
|
|
156
|
+
...settled,
|
|
157
|
+
loopInvariantValues,
|
|
158
|
+
hoists,
|
|
159
|
+
hoistedResults,
|
|
160
|
+
sharedStringLayouts,
|
|
161
|
+
denseReadWindows,
|
|
162
|
+
denseWriteWindows,
|
|
163
|
+
reusedStringLengths
|
|
164
|
+
};
|
|
149
165
|
};
|
|
150
166
|
const primitiveOperand = (operand) => {
|
|
151
167
|
const carrier = operand.representation.kind === 'optional' ? operand.representation.payload : operand.representation;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { type DeclarationId, type IrValueId, type PhysicalBodyId } from '../identity/ids.js';
|
|
2
|
+
import type { ClassLayout } from '../projection/classes.js';
|
|
3
|
+
import type { RepresentationDeriver } from '../representation/derive.js';
|
|
4
|
+
import { type Representation } from '../representation/model.js';
|
|
5
|
+
import type { GetOperation, IrBody, IrNonTerminatorOperation } from './model.js';
|
|
6
|
+
/**
|
|
7
|
+
* Reuse a field read that an earlier read of the same field already answered.
|
|
8
|
+
*
|
|
9
|
+
* A slab test over `boxes` reads `box.min` and `box.max` once per axis, six
|
|
10
|
+
* reads of two fields with nothing between them that can store either. V8
|
|
11
|
+
* eliminates the repeated loads; clang cannot, because each one is a call
|
|
12
|
+
* through a live-view check that hands back a retained handle, and the retain
|
|
13
|
+
* and release around it are calls too. Here the reads are the same IR
|
|
14
|
+
* operation on the same receiver, and this pass can see that nothing between
|
|
15
|
+
* them stores the key or runs code, so the later read takes the earlier
|
|
16
|
+
* read's value.
|
|
17
|
+
*
|
|
18
|
+
* Forward availability over the body's control flow, intersected at joins:
|
|
19
|
+
* a read is available at an operation when every path from the entry passes
|
|
20
|
+
* through it and nothing on the path after it may change what it read. Being
|
|
21
|
+
* available on every path is what makes the earlier read dominate the later
|
|
22
|
+
* one, so the rewrite never uses a value its definition does not reach.
|
|
23
|
+
*
|
|
24
|
+
* The receiver is named by the SSA value or, for a binding read, by the cell:
|
|
25
|
+
* `box.min.x` and `box.max.x` read `box` twice, and both reads see the cell's
|
|
26
|
+
* one value until something writes it. A read qualifies only when it loads a
|
|
27
|
+
* data field no getter can answer, on any class or record that carries the
|
|
28
|
+
* key, so reusing it runs nothing less than the original did. Anything that
|
|
29
|
+
* can run the program's code -- a call, a coercion, an accessor -- forgets
|
|
30
|
+
* every read; a store forgets the reads of its key, on every receiver, since
|
|
31
|
+
* two names can be one object. A body with a try region is left alone: its
|
|
32
|
+
* exceptional edges are not in the graph this walks.
|
|
33
|
+
*/
|
|
34
|
+
export declare const reuseFieldReads: (bodies: ReadonlyMap<PhysicalBodyId, IrBody>, classes: ReadonlyMap<DeclarationId, ClassLayout>, deriver: RepresentationDeriver) => ReadonlyMap<PhysicalBodyId, IrBody>;
|
|
35
|
+
/** Whether reading `key` off a value carried as `receiver` loads a data field no getter of the program can answer. */
|
|
36
|
+
export type CodeFreeFieldRead = (receiver: Representation, key: string) => boolean;
|
|
37
|
+
/**
|
|
38
|
+
* The one answer to which field reads this pass, and the borrowed reads that
|
|
39
|
+
* lean on the same proof (`borrowed-field-reads.ts`), may treat as a load.
|
|
40
|
+
*/
|
|
41
|
+
export declare const codeFreeFieldReadOf: (bodies: Iterable<IrBody>, classes: ReadonlyMap<DeclarationId, ClassLayout>, deriver: RepresentationDeriver) => CodeFreeFieldRead;
|
|
42
|
+
/** What an operation forgets: every read, the reads of one key, the reads through one cell, or nothing. */
|
|
43
|
+
export type FieldReadKill = {
|
|
44
|
+
readonly kind: 'all';
|
|
45
|
+
} | {
|
|
46
|
+
readonly kind: 'key';
|
|
47
|
+
readonly key: string;
|
|
48
|
+
} | {
|
|
49
|
+
readonly kind: 'cell';
|
|
50
|
+
readonly cell: DeclarationId;
|
|
51
|
+
} | null;
|
|
52
|
+
/**
|
|
53
|
+
* The facts this pass tracks over one body: which reads are candidates, the
|
|
54
|
+
* receiver each one names (a cell for a binding read, else the SSA value), and
|
|
55
|
+
* what every other operation forgets.
|
|
56
|
+
*/
|
|
57
|
+
export interface FieldReadFacts {
|
|
58
|
+
readonly candidates: ReadonlyMap<GetOperation, {
|
|
59
|
+
readonly key: string;
|
|
60
|
+
readonly shape: string;
|
|
61
|
+
}>;
|
|
62
|
+
readonly pinned: ReadonlySet<IrValueId>;
|
|
63
|
+
readonly receiverOf: (value: IrValueId) => string;
|
|
64
|
+
readonly killOf: (operation: IrNonTerminatorOperation) => FieldReadKill;
|
|
65
|
+
readonly forgets: (kill: FieldReadKill, fact: {
|
|
66
|
+
readonly receiver: string;
|
|
67
|
+
readonly key: string;
|
|
68
|
+
}) => boolean;
|
|
69
|
+
readonly factId: (receiver: string, key: string, shape: string) => string;
|
|
70
|
+
}
|
|
71
|
+
export declare const fieldReadFactsOf: (body: IrBody, codeFree: CodeFreeFieldRead) => FieldReadFacts;
|