@geastack/compiler 1.0.31 → 1.0.33
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/dist/compiler.js +21 -22
- package/dist/ir/dynamic-protocol.d.ts +20 -0
- package/dist/ir/dynamic-protocol.js +88 -0
- package/dist/ir/lower.js +13 -2
- package/dist/ir/model.d.ts +2 -0
- package/dist/representation/any-null-record-members.d.ts +41 -0
- package/dist/representation/any-null-record-members.js +115 -0
- package/dist/representation/unassigned-binding-cells.d.ts +4 -3
- package/dist/representation/unassigned-binding-cells.js +13 -1
- package/dist/semantics/any-null-member-declarations.d.ts +32 -0
- package/dist/semantics/any-null-member-declarations.js +90 -0
- package/dist/semantics/normalize/fresh-array-result.d.ts +32 -0
- package/dist/semantics/normalize/fresh-array-result.js +125 -0
- package/dist/targets/cpp/emit-narrowing.js +17 -0
- package/dist/targets/cpp/emit-native-field-view.js +23 -13
- package/dist/targets/cpp/emit.js +33 -8
- package/dist/targets/cpp/records.d.ts +2 -0
- package/dist/targets/cpp/records.js +6 -3
- package/dist/targets/cpp/translation-unit.js +38 -1
- package/package.json +1 -1
- package/src/targets/cpp/runtime/gea_document_view.h +988 -0
- package/src/targets/cpp/runtime/gea_runtime.h +354 -212
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { inheritedImplementationOf } from './merged-declaration.js';
|
|
3
|
+
/**
|
|
4
|
+
* The method body a member call runs when it returns an array NO OTHER
|
|
5
|
+
* REFERENCE holds: every `return` hands back an array literal, or a local
|
|
6
|
+
* initialized with one that the body only fills, indexes and measures.
|
|
7
|
+
*
|
|
8
|
+
* This is the one fact that makes converting an `array-object` between two
|
|
9
|
+
* element carriers sound. A conversion between them has to allocate, and for
|
|
10
|
+
* a mutable array a second array loses every write through the other alias
|
|
11
|
+
* (`array-object-call-argument-aliasing`). A call result proven fresh has no
|
|
12
|
+
* other alias: the callee dropped its own reference when it returned, so the
|
|
13
|
+
* converted array is the only one the program can ever observe, and a
|
|
14
|
+
* one-time element-wise copy at the call is indistinguishable from the
|
|
15
|
+
* callee having built it at the caller's element type.
|
|
16
|
+
*
|
|
17
|
+
* An `async` body qualifies the same way: its promise settles with the
|
|
18
|
+
* array its `return` names, and that array is still held by nothing else.
|
|
19
|
+
* mongodb's `AbstractCursor.toArray` is the shape this exists for -- it
|
|
20
|
+
* builds `const array: TSchema[] = []`, pushes every document and returns it,
|
|
21
|
+
* while the cursor class is folded onto its `any` copy (`specialization.ts`'s
|
|
22
|
+
* reinterpreted classes), so the body hands back `any[]` where the caller's
|
|
23
|
+
* view declares `CollectionInfo[]`.
|
|
24
|
+
*
|
|
25
|
+
* Deliberately syntactic and small. Any use of the local outside the listed
|
|
26
|
+
* forms -- passing it as an argument, storing it, capturing it in a closure,
|
|
27
|
+
* a method whose result aliases it (`reverse`, `sort`), iteration protocol
|
|
28
|
+
* hooks -- refuses, and a refusal only keeps the conversion refused. The key
|
|
29
|
+
* is returned alongside so lowering can confirm the call it runs really
|
|
30
|
+
* reaches this body: an override in the receiver's family, or a prototype
|
|
31
|
+
* write, would run a different body the proof never saw.
|
|
32
|
+
*/
|
|
33
|
+
export const freshArrayResultBodyOf = (checker, node) => {
|
|
34
|
+
if (ts.isOptionalChain(node))
|
|
35
|
+
return null;
|
|
36
|
+
const callee = skipParentheses(node.expression);
|
|
37
|
+
if (!ts.isPropertyAccessExpression(callee) || !ts.isIdentifier(callee.name))
|
|
38
|
+
return null;
|
|
39
|
+
const member = checker.getSymbolAtLocation(callee.name);
|
|
40
|
+
if (!member)
|
|
41
|
+
return null;
|
|
42
|
+
const implementation = inheritedImplementationOf(checker, member) ?? member;
|
|
43
|
+
const bodies = (implementation.declarations ?? []).filter((declaration) => ts.isMethodDeclaration(declaration) && declaration.body !== undefined && ts.isClassLike(declaration.parent));
|
|
44
|
+
const body = bodies.length === 1 ? bodies[0] : null;
|
|
45
|
+
if (!body || body.asteriskToken !== undefined)
|
|
46
|
+
return null;
|
|
47
|
+
return returnsFreshArray(checker, body) ? body : null;
|
|
48
|
+
};
|
|
49
|
+
const returnsFreshArray = (checker, body) => {
|
|
50
|
+
const returns = [];
|
|
51
|
+
let bare = false;
|
|
52
|
+
const collect = (node) => {
|
|
53
|
+
if (ts.isFunctionLike(node) || ts.isClassLike(node))
|
|
54
|
+
return;
|
|
55
|
+
if (ts.isReturnStatement(node)) {
|
|
56
|
+
if (node.expression)
|
|
57
|
+
returns.push(skipParentheses(node.expression));
|
|
58
|
+
else
|
|
59
|
+
bare = true;
|
|
60
|
+
}
|
|
61
|
+
ts.forEachChild(node, collect);
|
|
62
|
+
};
|
|
63
|
+
ts.forEachChild(body.body, collect);
|
|
64
|
+
if (bare || returns.length === 0)
|
|
65
|
+
return false;
|
|
66
|
+
return returns.every((expression) => ts.isArrayLiteralExpression(expression) || freshLocal(checker, body, expression));
|
|
67
|
+
};
|
|
68
|
+
const freshLocal = (checker, body, expression) => {
|
|
69
|
+
if (!ts.isIdentifier(expression))
|
|
70
|
+
return false;
|
|
71
|
+
const symbol = checker.getSymbolAtLocation(expression);
|
|
72
|
+
const declaration = symbol?.declarations?.length === 1 ? symbol.declarations[0] : undefined;
|
|
73
|
+
if (!symbol || !declaration || !ts.isVariableDeclaration(declaration) || !ts.isIdentifier(declaration.name))
|
|
74
|
+
return false;
|
|
75
|
+
if (!declaration.initializer || !ts.isArrayLiteralExpression(skipParentheses(declaration.initializer)))
|
|
76
|
+
return false;
|
|
77
|
+
const list = declaration.parent;
|
|
78
|
+
if (!ts.isVariableDeclarationList(list) || (list.flags & ts.NodeFlags.Const) === 0)
|
|
79
|
+
return false;
|
|
80
|
+
if (enclosingFunction(declaration) !== body)
|
|
81
|
+
return false;
|
|
82
|
+
let admitted = true;
|
|
83
|
+
const visit = (node) => {
|
|
84
|
+
if (!admitted)
|
|
85
|
+
return;
|
|
86
|
+
if (ts.isIdentifier(node) && node !== declaration.name && checker.getSymbolAtLocation(node) === symbol) {
|
|
87
|
+
admitted = enclosingFunction(node) === body && nonEscapingUse(node);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
ts.forEachChild(node, visit);
|
|
91
|
+
};
|
|
92
|
+
ts.forEachChild(body.body, visit);
|
|
93
|
+
return admitted;
|
|
94
|
+
};
|
|
95
|
+
/** A use that reads, fills or measures the array and hands no reference to it anywhere. */
|
|
96
|
+
const nonEscapingUse = (use) => {
|
|
97
|
+
const parent = use.parent;
|
|
98
|
+
if (ts.isReturnStatement(parent))
|
|
99
|
+
return true;
|
|
100
|
+
if (ts.isParenthesizedExpression(parent))
|
|
101
|
+
return false;
|
|
102
|
+
if (ts.isPropertyAccessExpression(parent) && parent.expression === use && ts.isIdentifier(parent.name)) {
|
|
103
|
+
const name = parent.name.text;
|
|
104
|
+
if (name === 'length')
|
|
105
|
+
return !isAssignmentTarget(parent);
|
|
106
|
+
const call = parent.parent;
|
|
107
|
+
return (name === 'push' || name === 'unshift') && ts.isCallExpression(call) && call.expression === parent;
|
|
108
|
+
}
|
|
109
|
+
if (ts.isElementAccessExpression(parent) && parent.expression === use)
|
|
110
|
+
return true;
|
|
111
|
+
return false;
|
|
112
|
+
};
|
|
113
|
+
const isAssignmentTarget = (node) => ts.isBinaryExpression(node.parent) &&
|
|
114
|
+
node.parent.left === node &&
|
|
115
|
+
node.parent.operatorToken.kind >= ts.SyntaxKind.FirstAssignment &&
|
|
116
|
+
node.parent.operatorToken.kind <= ts.SyntaxKind.LastAssignment;
|
|
117
|
+
const enclosingFunction = (node) => {
|
|
118
|
+
let current = node.parent;
|
|
119
|
+
while (current && !ts.isFunctionLike(current))
|
|
120
|
+
current = current.parent;
|
|
121
|
+
return current;
|
|
122
|
+
};
|
|
123
|
+
const skipParentheses = (node) => ts.isParenthesizedExpression(node) || ts.isAsExpression(node) || ts.isNonNullExpression(node) || ts.isSatisfiesExpression(node)
|
|
124
|
+
? skipParentheses(node.expression)
|
|
125
|
+
: node;
|
|
@@ -4931,7 +4931,24 @@ export const recipeText = (ctx, node, text) => {
|
|
|
4931
4931
|
throw createCppEmitBlockedError(`conversion:${node.id}`, 'the conversion dispatcher requires the exact certified recipe');
|
|
4932
4932
|
return evaluatedOnceText(text, (operand) => renderedRecipeText(ctx, node, operand));
|
|
4933
4933
|
};
|
|
4934
|
+
/**
|
|
4935
|
+
* A union read out of a box depends on its plan alone, so a unit defines it
|
|
4936
|
+
* once and every site calls it by name (`unitFunctionName`). Spelled inline it
|
|
4937
|
+
* was re-emitted at every read: one `Headers`-or-record union in hono tests
|
|
4938
|
+
* some seventy required keys, ~46 KB of machine code per copy.
|
|
4939
|
+
*/
|
|
4934
4940
|
const dynamicWrapperText = (ctx, plan, node, text) => {
|
|
4941
|
+
if (plan.kind !== 'union')
|
|
4942
|
+
return dynamicWrapperTextAt(ctx, plan, node, text);
|
|
4943
|
+
const formal = 'gea_dynamic_source';
|
|
4944
|
+
const body = dynamicWrapperTextAt(ctx, plan, node, formal);
|
|
4945
|
+
if (body === null)
|
|
4946
|
+
return null;
|
|
4947
|
+
const signature = (name) => `${cppTypeOf(plan.target)} ${name}(const gea::Value& ${formal})`;
|
|
4948
|
+
const named = unitFunctionName('gea_dynamic_union', signature, `return ${body};`);
|
|
4949
|
+
return named === null ? dynamicWrapperTextAt(ctx, plan, node, text) : `${named}(${text})`;
|
|
4950
|
+
};
|
|
4951
|
+
const dynamicWrapperTextAt = (ctx, plan, node, text) => {
|
|
4935
4952
|
if (!dynamicWrapperPlanMatches(plan, node.source, node.target, ctx.conversions.nodeById))
|
|
4936
4953
|
return null;
|
|
4937
4954
|
const targetType = cppTypeOf(plan.target);
|
|
@@ -3,7 +3,7 @@ import { createCppEmitBlockedError, operandText } from './emit-context.js';
|
|
|
3
3
|
import { recipeText } from './emit-narrowing.js';
|
|
4
4
|
import { nativeFieldPolicyType, staticKeyOrderText } from './records.js';
|
|
5
5
|
import { tracksKeyOrder } from './key-order-tracking.js';
|
|
6
|
-
import { cppTypeOf, cppStringLiteral, cppRecordFieldKeyIsSymbol, fieldPropertyKeyText } from './types.js';
|
|
6
|
+
import { cppTypeOf, cppStringLiteral, cppRecordFieldKeyIsSymbol, fieldPropertyKeyText, unitFunctionName } from './types.js';
|
|
7
7
|
import { propertyKeyText } from './emit-dynamic-properties.js';
|
|
8
8
|
import { nativeDataPropertyText } from './emit-buffers.js';
|
|
9
9
|
import { nativeDataPropertyOf } from '../../representation/native-data-properties.js';
|
|
@@ -63,15 +63,7 @@ export const nativeFieldViewOperandContext = (ctx, operation) => {
|
|
|
63
63
|
};
|
|
64
64
|
export const nativeFieldViewReadForText = (ctx, receiver, target, receipt, ordinaryReadOf, keyOperand) => {
|
|
65
65
|
const result = cppTypeOf(target);
|
|
66
|
-
const
|
|
67
|
-
const from = cppTypeOf(source);
|
|
68
|
-
const converted = renderedLeaf(ctx, conversion, `(*static_cast<const ${from}*>(gea_native))`);
|
|
69
|
-
return `if (${routeTokenOf(source)}) { static_cast<std::optional<${result}>*>(gea_out)->emplace(${converted}); return true; }`;
|
|
70
|
-
});
|
|
71
|
-
const accepts = receipt.sources.map(({ source }) => `(${routeTokenOf(source)})`).join(' || ') || 'false';
|
|
72
|
-
const adapter = '[&](void* gea_out, const void* gea_type, const void* gea_policy, const void* gea_native) -> bool { ' +
|
|
73
|
-
`${arms.join(' ')} return false; }`;
|
|
74
|
-
const accepted = `+[](const void* gea_type, const void* gea_policy) -> bool { return ${accepts}; }`;
|
|
66
|
+
const { adapter, accepted } = fieldViewRoutesText(ctx, receipt, result);
|
|
75
67
|
const dynamicRead = (key) => (carrier, text) => {
|
|
76
68
|
const route = receipt.sources.find((entry) => representationKey(entry.source) === representationKey(carrier));
|
|
77
69
|
return route === undefined
|
|
@@ -224,12 +216,30 @@ export const nativeFieldViewWriteText = (ctx, operation) => {
|
|
|
224
216
|
*/
|
|
225
217
|
export const nativeHeldFieldViewReadText = (ctx, receipt, target, receiver, plain) => {
|
|
226
218
|
const result = cppTypeOf(target);
|
|
219
|
+
const { adapter, accepted } = fieldViewRoutesText(ctx, receipt, result);
|
|
220
|
+
return `gea::record::readLiveField<${result}>(${receiver}, ${viewKeyText(receipt.key)}, ${adapter}, ${accepted}, [&]() -> ${result} { return ${plain}; })`;
|
|
221
|
+
};
|
|
222
|
+
/**
|
|
223
|
+
* The adapter a live view's certified routes answer through, and the policy
|
|
224
|
+
* check naming them. Both depend on the receipt's routes and result carrier
|
|
225
|
+
* alone, so a unit defines each once (`unitFunctionName`): spelled inline they
|
|
226
|
+
* were re-emitted for every read, every receiver arm and both the live and the
|
|
227
|
+
* plain path of each.
|
|
228
|
+
*/
|
|
229
|
+
const fieldViewRoutesText = (ctx, receipt, result) => {
|
|
227
230
|
const arms = receipt.sources.map(({ source, conversion }) => {
|
|
228
231
|
const converted = renderedLeaf(ctx, conversion, `(*static_cast<const ${cppTypeOf(source)}*>(gea_native))`);
|
|
229
232
|
return `if (${routeTokenOf(source)}) { static_cast<std::optional<${result}>*>(gea_out)->emplace(${converted}); return true; }`;
|
|
230
233
|
});
|
|
231
234
|
const accepts = receipt.sources.map(({ source }) => `(${routeTokenOf(source)})`).join(' || ') || 'false';
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
+
const adapterParameters = '(void* gea_out, const void* gea_type, const void* gea_policy, const void* gea_native)';
|
|
236
|
+
const adapterBody = `${arms.join(' ')} return false;`;
|
|
237
|
+
const acceptedParameters = '(const void* gea_type, const void* gea_policy)';
|
|
238
|
+
const acceptedBody = `return ${accepts};`;
|
|
239
|
+
return {
|
|
240
|
+
adapter: unitFunctionName('gea_field_view_adapter', (name) => `bool ${name}${adapterParameters}`, adapterBody) ??
|
|
241
|
+
`[&]${adapterParameters} -> bool { ${adapterBody} }`,
|
|
242
|
+
accepted: unitFunctionName('gea_field_view_accepts', (name) => `bool ${name}${acceptedParameters}`, acceptedBody) ??
|
|
243
|
+
`+[]${acceptedParameters} -> bool { ${acceptedBody} }`
|
|
244
|
+
};
|
|
235
245
|
};
|
package/dist/targets/cpp/emit.js
CHANGED
|
@@ -1961,7 +1961,9 @@ const threadedFlowOf = (ctx, body, labels, hoists, mergeWrites) => {
|
|
|
1961
1961
|
const result = resultOfIrOperation(operation);
|
|
1962
1962
|
return result !== null && ctx.deadValues.has(result.id);
|
|
1963
1963
|
};
|
|
1964
|
-
const
|
|
1964
|
+
const lifetimeBlocks = new Set(body.bindingLifetimeOrigins?.values());
|
|
1965
|
+
const rendersNothing = (block) => !lifetimeBlocks.has(block.id) &&
|
|
1966
|
+
block.operations.every(rendersNothingAtOrigin) &&
|
|
1965
1967
|
(mergeWrites.get(block.id) ?? []).length === 0 &&
|
|
1966
1968
|
// A relocated operation renders here, in its destination block. Counting
|
|
1967
1969
|
// it as absent a second time lets the flow thread this block away and
|
|
@@ -2054,7 +2056,7 @@ const threadedFlowOf = (ctx, body, labels, hoists, mergeWrites) => {
|
|
|
2054
2056
|
* written in the same order, flat, with every declaration at the top -- the
|
|
2055
2057
|
* layout that needs no graph at all.
|
|
2056
2058
|
*/
|
|
2057
|
-
const nestedBlocksOf = (plan, rendered, labels, successors, declarations, rootText, facts, internalLabels = new Map(), restricted = new Map()) => {
|
|
2059
|
+
const nestedBlocksOf = (plan, rendered, labels, successors, declarations, rootText, facts, internalLabels = new Map(), restricted = new Map(), lifetimeOrigins = new Map()) => {
|
|
2058
2060
|
const flat = () => ({
|
|
2059
2061
|
top: declarations,
|
|
2060
2062
|
artifacts: plan.order.flatMap((id) => {
|
|
@@ -2075,7 +2077,7 @@ const nestedBlocksOf = (plan, rendered, labels, successors, declarations, rootTe
|
|
|
2075
2077
|
]);
|
|
2076
2078
|
if (gotoTargetsOf(block.artifact.text).some((target) => !allowed.has(target)))
|
|
2077
2079
|
return flat();
|
|
2078
|
-
mentions.set(id, identifiersOf(block.artifact.text));
|
|
2080
|
+
mentions.set(id, new Set([...identifiersOf(block.artifact.text), ...[...lifetimeOrigins].filter(([, origin]) => origin === id).map(([name]) => name)]));
|
|
2079
2081
|
}
|
|
2080
2082
|
const scopes = declarationScopesOf(plan, declarations, mentions, rootText);
|
|
2081
2083
|
const top = [];
|
|
@@ -2258,7 +2260,7 @@ const isBareIdentifier = (text) => {
|
|
|
2258
2260
|
* handler renders its blocks bare, and an outer jump into one of them cannot
|
|
2259
2261
|
* be re-nested), or when some chunk is unreachable along the spelled jumps.
|
|
2260
2262
|
*/
|
|
2261
|
-
const regionScopedBlocksOf = (entry, chunkIds, chunks, labels, declarations, rootText, facts) => {
|
|
2263
|
+
const regionScopedBlocksOf = (entry, chunkIds, chunks, labels, declarations, rootText, facts, lifetimeOrigins = new Map()) => {
|
|
2262
2264
|
if (chunkIds.length !== chunks.length)
|
|
2263
2265
|
return null;
|
|
2264
2266
|
const allLabels = new Set(labels.values());
|
|
@@ -2315,7 +2317,17 @@ const regionScopedBlocksOf = (entry, chunkIds, chunks, labels, declarations, roo
|
|
|
2315
2317
|
const rendered = new Map();
|
|
2316
2318
|
for (const [id, artifact] of texts)
|
|
2317
2319
|
rendered.set(id, { label: targeted.has(id) ? requireBlockLabel(labels, id) : null, artifact });
|
|
2318
|
-
|
|
2320
|
+
const chunkOrigins = new Map();
|
|
2321
|
+
const atRoot = [];
|
|
2322
|
+
for (const [name, origin] of lifetimeOrigins) {
|
|
2323
|
+
const label = labels.get(origin);
|
|
2324
|
+
const chunk = label === undefined ? undefined : (internalOf.get(label) ?? nodeOfLabel.get(label));
|
|
2325
|
+
if (chunk === undefined)
|
|
2326
|
+
atRoot.push(name);
|
|
2327
|
+
else
|
|
2328
|
+
chunkOrigins.set(name, chunk);
|
|
2329
|
+
}
|
|
2330
|
+
return nestedBlocksOf(plan, rendered, labels, successors, declarations, [rootText, ...atRoot].join('\n'), facts, internal, new Map(), chunkOrigins);
|
|
2319
2331
|
};
|
|
2320
2332
|
/** One `blockN` label per block, in `blockOrder`, so a forward jump (a loop back-edge included) always resolves before any block renders. */
|
|
2321
2333
|
const blockLabelsOf = (order) => {
|
|
@@ -3082,13 +3094,26 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
3082
3094
|
// scope of a variable whose declaration initializes it.
|
|
3083
3095
|
const declarationFacts = { kind: 'materialized', representation: { kind: 'void' }, owner, lineage: null };
|
|
3084
3096
|
let topDeclarations = ctx.declarations;
|
|
3097
|
+
const lifetimeOrigins = new Map();
|
|
3098
|
+
const atEntry = [];
|
|
3099
|
+
for (const [declaration, origin] of body.bindingLifetimeOrigins ?? []) {
|
|
3100
|
+
const name = ctx.bindingNames.get(declaration);
|
|
3101
|
+
if (name === undefined)
|
|
3102
|
+
continue;
|
|
3103
|
+
const rendered = flow.rendered.find((id) => id === origin || labels.get(id) === labels.get(origin));
|
|
3104
|
+
if (origin === body.entry || rendered === undefined || rendered === body.entry)
|
|
3105
|
+
atEntry.push(name);
|
|
3106
|
+
else
|
|
3107
|
+
lifetimeOrigins.set(name, rendered);
|
|
3108
|
+
}
|
|
3109
|
+
const lifetimeRootText = [...entryPrologue, ...atEntry].join('\n');
|
|
3085
3110
|
if (plan !== null && flow.successors !== null) {
|
|
3086
|
-
const nested = nestedBlocksOf(plan, renderedBlocks, labels, flow.successors, ctx.declarations,
|
|
3111
|
+
const nested = nestedBlocksOf(plan, renderedBlocks, labels, flow.successors, ctx.declarations, lifetimeRootText, declarationFacts, new Map(), restrictedParametersOf(ctx), lifetimeOrigins);
|
|
3087
3112
|
topDeclarations = nested.top;
|
|
3088
3113
|
blocks.push(...nested.artifacts);
|
|
3089
3114
|
}
|
|
3090
3115
|
else if (!isSingleBlock && flow.successors === null) {
|
|
3091
|
-
const nested = regionScopedBlocksOf(body.entry, chunkIds, blocks, labels, ctx.declarations,
|
|
3116
|
+
const nested = regionScopedBlocksOf(body.entry, chunkIds, blocks, labels, ctx.declarations, lifetimeRootText, declarationFacts, lifetimeOrigins);
|
|
3092
3117
|
if (nested !== null) {
|
|
3093
3118
|
topDeclarations = nested.top;
|
|
3094
3119
|
blocks.splice(0, blocks.length, ...nested.artifacts);
|
|
@@ -3096,7 +3121,7 @@ virtualDispatch = new Map(), narrowedStorage = { reads: new Map(), integral: new
|
|
|
3096
3121
|
}
|
|
3097
3122
|
else if (isSingleBlock && blocks.length === 1) {
|
|
3098
3123
|
const only = blocks[0];
|
|
3099
|
-
const segmented = segmentScopedBodyOf(only.text, ctx.declarations,
|
|
3124
|
+
const segmented = segmentScopedBodyOf(only.text, ctx.declarations, lifetimeRootText);
|
|
3100
3125
|
if (segmented !== null) {
|
|
3101
3126
|
topDeclarations = segmented.top;
|
|
3102
3127
|
blocks.splice(0, 1, { text: segmented.text, facts: only.facts });
|
|
@@ -485,6 +485,8 @@ conversionSite?: ConversionSite) => {
|
|
|
485
485
|
* static in rather than a member the struct does not have.
|
|
486
486
|
*/
|
|
487
487
|
readonly staticMethodStateClasses: ReadonlySet<DeclarationId>;
|
|
488
|
+
/** Every program struct this pass declares. */
|
|
489
|
+
readonly structNames: ReadonlySet<string>;
|
|
488
490
|
/** Authenticated program-class ancestry; the translation unit owns namespace placement. */
|
|
489
491
|
/** `nativeBase` marks a runtime-owned base spelled fully qualified, outside the program's namespace. */
|
|
490
492
|
readonly runtimeClassBases: readonly {
|
|
@@ -3518,7 +3518,8 @@ conversionSite) => {
|
|
|
3518
3518
|
})),
|
|
3519
3519
|
revisionFields: new Map(),
|
|
3520
3520
|
celledFields: new Map(),
|
|
3521
|
-
staticMethodStateClasses: new Set()
|
|
3521
|
+
staticMethodStateClasses: new Set(),
|
|
3522
|
+
structNames: new Set()
|
|
3522
3523
|
};
|
|
3523
3524
|
}
|
|
3524
3525
|
const structNames = [...requiredStructs].sort();
|
|
@@ -3686,7 +3687,8 @@ conversionSite) => {
|
|
|
3686
3687
|
refused,
|
|
3687
3688
|
revisionFields: new Map(),
|
|
3688
3689
|
celledFields: new Map(),
|
|
3689
|
-
staticMethodStateClasses: new Set()
|
|
3690
|
+
staticMethodStateClasses: new Set(),
|
|
3691
|
+
structNames: new Set()
|
|
3690
3692
|
};
|
|
3691
3693
|
// `Value` can only project a genuinely dynamic class back to a nominal
|
|
3692
3694
|
// carrier when the allocation itself states an authenticated ancestry. The
|
|
@@ -3745,7 +3747,8 @@ conversionSite) => {
|
|
|
3745
3747
|
refused: [],
|
|
3746
3748
|
revisionFields,
|
|
3747
3749
|
celledFields,
|
|
3748
|
-
staticMethodStateClasses
|
|
3750
|
+
staticMethodStateClasses,
|
|
3751
|
+
structNames: requiredStructs
|
|
3749
3752
|
};
|
|
3750
3753
|
};
|
|
3751
3754
|
/**
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { asyncResultConventionsOf } from '../../ir/async-result-conventions.js';
|
|
2
2
|
import { prototypePropertyDeclarationsOf } from '../../ir/program-conversions.js';
|
|
3
|
+
import { dynamicProtocolOmissionsOf } from '../../ir/dynamic-protocol.js';
|
|
3
4
|
import { createNativeDebugSource } from './native-debug-source.js';
|
|
4
5
|
import { publishRealmStorage } from './realm-storage.js';
|
|
5
6
|
import { nativeSelectionHelpers } from './native-selection-helpers.js';
|
|
@@ -2141,16 +2142,52 @@ const renderTranslationUnitSession = (input) => {
|
|
|
2141
2142
|
// conversion builds and every body signature a record view's bound method
|
|
2142
2143
|
// or getter calls. They are `inline` where several units include the header
|
|
2143
2144
|
// that holds them.
|
|
2145
|
+
// The published omissions (`ir/dynamic-protocol.ts`), spelled as the
|
|
2146
|
+
// runtime's `gea::detail::dynamicProtocolOmitted` specializations. Only a
|
|
2147
|
+
// type whose program structs this unit declares can be named, and several
|
|
2148
|
+
// carriers can share one spelling, so the list is the set of distinct ones.
|
|
2149
|
+
const dynamicProtocolOmissions = dynamicProtocolOmissionsOf(input.classes, input.reflection, emissionRepresentations);
|
|
2150
|
+
const dynamicProtocolOmittedTypes = () => {
|
|
2151
|
+
if (dynamicProtocolOmissions === null)
|
|
2152
|
+
return [];
|
|
2153
|
+
const declared = (representation) => [...walkRepresentation(representation)].every((inner) => inner.kind === 'class-ref'
|
|
2154
|
+
? structs.structNames.has(cppClassName(inner.declaration))
|
|
2155
|
+
: inner.kind === 'record' || inner.kind === 'record-with-index' || (inner.kind === 'native-record-ref' && inner.native === null)
|
|
2156
|
+
? structs.structNames.has(cppRecordStructName(inner.shapeId))
|
|
2157
|
+
: true);
|
|
2158
|
+
const types = new Set();
|
|
2159
|
+
for (const declaration of dynamicProtocolOmissions.classes)
|
|
2160
|
+
if (structs.structNames.has(cppClassName(declaration)))
|
|
2161
|
+
types.add(cppClassName(declaration));
|
|
2162
|
+
for (const shape of dynamicProtocolOmissions.records)
|
|
2163
|
+
if (structs.structNames.has(cppRecordStructName(shape)))
|
|
2164
|
+
types.add(cppRecordStructName(shape));
|
|
2165
|
+
for (const array of dynamicProtocolOmissions.arrays)
|
|
2166
|
+
if (declared(array))
|
|
2167
|
+
types.add(cppTypeOf(array, 'owned'));
|
|
2168
|
+
return [...types].sort();
|
|
2169
|
+
};
|
|
2144
2170
|
const unionAliasMarker = '// gea-union-aliases';
|
|
2145
2171
|
const unitFunctionMarker = '// gea-unit-functions';
|
|
2146
2172
|
const unitFunctionLinkage = perFile ? 'inline ' : '[[maybe_unused]] static ';
|
|
2147
2173
|
const spliceUnionAliases = (source) => {
|
|
2148
2174
|
const { aliases, functions } = endUnionAliasing();
|
|
2149
2175
|
const forwards = [...recursiveContainers, ...structs.declarations, ...jsonStructs.declarations].filter((declaration) => declaration.startsWith('struct ') && declaration.endsWith(';') && !declaration.includes('{'));
|
|
2176
|
+
// Spelled after the alias session ends, so each is its full type.
|
|
2177
|
+
const omitted = dynamicProtocolOmittedTypes();
|
|
2150
2178
|
const block = [
|
|
2151
2179
|
...forwards,
|
|
2152
2180
|
...aliases.map(({ name, spelling }) => `using ${name} = ${spelling};`),
|
|
2153
|
-
...functions.map(({ signature }) => `${unitFunctionLinkage}${signature};`)
|
|
2181
|
+
...functions.map(({ signature }) => `${unitFunctionLinkage}${signature};`),
|
|
2182
|
+
...(omitted.length === 0
|
|
2183
|
+
? []
|
|
2184
|
+
: [
|
|
2185
|
+
...(isolate ? [namespaceClose] : []),
|
|
2186
|
+
'namespace gea::detail {',
|
|
2187
|
+
...omitted.map((type) => `template <> inline constexpr bool dynamicProtocolOmitted<${type}> = true;`),
|
|
2188
|
+
'} // namespace gea::detail',
|
|
2189
|
+
...(isolate ? [namespaceOpen] : [])
|
|
2190
|
+
])
|
|
2154
2191
|
].join('\n');
|
|
2155
2192
|
const definitions = functions.map(({ signature, body }) => `${unitFunctionLinkage}${signature} { ${body} }`).join('\n');
|
|
2156
2193
|
return spliceRendered(spliceRendered(source, unionAliasMarker, block), unitFunctionMarker, definitions);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@geastack/compiler",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.33",
|
|
4
4
|
"description": "The geastack TypeScript-to-C++ compiler: one semantic spine, no source-shaped authority, no boxing of statically typed values.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"repository": {
|