@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.
- package/README.md +57 -19
- package/dist/cli.js +2 -1
- package/dist/compiler.js +8 -2
- 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.js +17 -4
- 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
|
@@ -607,8 +607,11 @@ export const strictEqualityText = (operator, left, right, convert) => {
|
|
|
607
607
|
nested.push(`(${unionText}.is<${nestedIndex}>() && (${unionText}.get<${nestedIndex}>() == ${other.text}))`);
|
|
608
608
|
continue;
|
|
609
609
|
}
|
|
610
|
+
// A `dynamic` arm (a `{}` member of the sum) may hold any object,
|
|
611
|
+
// this class instance or callable included: its box's own tag answers.
|
|
610
612
|
if (arm.value.kind !== 'tagged-union' &&
|
|
611
613
|
arm.value.kind !== 'optional' &&
|
|
614
|
+
arm.value.kind !== 'dynamic' &&
|
|
612
615
|
!(arm.value.kind === 'class-ref' && other.representation.kind === 'class-ref') &&
|
|
613
616
|
!(callableIdentityCarrier(arm.value) && callableIdentityCarrier(other.representation)))
|
|
614
617
|
continue;
|
|
@@ -5300,6 +5300,15 @@ const renderedRecipeText = (ctx, node, text) => {
|
|
|
5300
5300
|
node.capability.materializer.id === ASSERTED_CLASS_DOWNCAST_MATERIALIZER &&
|
|
5301
5301
|
node.target.kind === 'class-ref')
|
|
5302
5302
|
return `gea::host::assertedDowncastClassRef<${cppClassName(node.target.declaration)}>(${text})`;
|
|
5303
|
+
// The same check over a present payload (`nodes.ts`'s `checkedClassFieldReadFor`).
|
|
5304
|
+
if (node.capability.kind === 'static' &&
|
|
5305
|
+
node.capability.materializer.id === ASSERTED_CLASS_DOWNCAST_MATERIALIZER &&
|
|
5306
|
+
node.target.kind === 'optional' &&
|
|
5307
|
+
node.target.payload.kind === 'class-ref') {
|
|
5308
|
+
const optionalType = cppTypeOf(node.target);
|
|
5309
|
+
return (`[](const auto& gea_present) -> ${optionalType} { return gea_present.has_value() ? ${optionalType}(` +
|
|
5310
|
+
`gea::host::assertedDowncastClassRef<${cppClassName(node.target.payload.declaration)}>(*gea_present)) : ${optionalType}(); }(${text})`);
|
|
5311
|
+
}
|
|
5303
5312
|
// The census's caught-value handoff (`nodes.ts`'s `caughtHandoffFor`).
|
|
5304
5313
|
if (node.capability.kind === 'static' &&
|
|
5305
5314
|
node.capability.materializer.id === CAUGHT_HANDOFF_MATERIALIZER &&
|
|
@@ -12,6 +12,30 @@ export declare const nativeFieldViewReadForText: (ctx: EmitContext, receiver: Ir
|
|
|
12
12
|
readonly accessor?: true;
|
|
13
13
|
readonly absentReadsUndefined?: true;
|
|
14
14
|
} | null, keyOperand?: IrOperand) => string;
|
|
15
|
+
/**
|
|
16
|
+
* A field-view read whose one use is the receiver of the next member read
|
|
17
|
+
* (`gull.pos.x` on a view-target record): spelled as a reference instead of a
|
|
18
|
+
* copied handle, so the plain allocation's answer costs no retain and no
|
|
19
|
+
* release. A live view's answer is held by `gea_field_slot`, a temporary of
|
|
20
|
+
* the caller's full expression, so the reference outlives the member load
|
|
21
|
+
* that consumes it (`readLiveFieldBorrowed`). Only the exact shape the plain
|
|
22
|
+
* read answers with its own member: a plain shared receiver, a declared,
|
|
23
|
+
* always-present, getter-free field already carried as the result; anything
|
|
24
|
+
* else keeps `nativeFieldViewReadText`.
|
|
25
|
+
*/
|
|
26
|
+
export declare const nativeFieldViewBorrowedReadText: (ctx: EmitContext, operation: GetOperation, ordinaryReadOf: (carrier: Representation, key: string) => {
|
|
27
|
+
readonly source: Representation;
|
|
28
|
+
readonly text: string;
|
|
29
|
+
readonly accessor?: true;
|
|
30
|
+
readonly absentReadsUndefined?: true;
|
|
31
|
+
} | null,
|
|
32
|
+
/**
|
|
33
|
+
* A frame slot a live view's answer is moved into, so the reference outlives
|
|
34
|
+
* the expression (`EmitContext.fieldPointerValues`). Without one the slot is
|
|
35
|
+
* a temporary of the full expression, which only a consumer in that same
|
|
36
|
+
* expression may read through.
|
|
37
|
+
*/
|
|
38
|
+
slot?: string) => string | null;
|
|
15
39
|
export declare const nativeFieldViewReadText: (ctx: EmitContext, operation: GetOperation, ordinaryReadOf: (carrier: Representation, key: string) => {
|
|
16
40
|
readonly source: Representation;
|
|
17
41
|
readonly text: string;
|
|
@@ -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, unitFunctionName } from './types.js';
|
|
6
|
+
import { cppTypeOf, cppStringLiteral, cppRecordFieldAttributesName, cppRecordFieldKeyIsSymbol, cppRecordFieldPresenceName, 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';
|
|
@@ -71,6 +71,19 @@ export const nativeFieldViewOperandContext = (ctx, operation) => {
|
|
|
71
71
|
}
|
|
72
72
|
return { ...ctx, valueNames, deferredTexts, pendingPacks };
|
|
73
73
|
};
|
|
74
|
+
/**
|
|
75
|
+
* Whether `key` is an optional, non-accessor field of a plain record's own
|
|
76
|
+
* layout (the record itself, or the shared allocation of one): a member whose
|
|
77
|
+
* presence bit says whether it holds the property. A class is left out -- its
|
|
78
|
+
* own accessors may shadow an inherited slot -- as is a host record, whose
|
|
79
|
+
* fields a host layout owns.
|
|
80
|
+
*/
|
|
81
|
+
const optionalRecordMember = (ctx, carrier, key) => {
|
|
82
|
+
const layout = carrier.kind === 'native-record-ref' && carrier.native === null ? ctx.deriver.layoutOf(carrier.shapeId) : carrier;
|
|
83
|
+
return (layout.kind === 'record' &&
|
|
84
|
+
!layout.accessors.some((accessor) => accessor.key === key) &&
|
|
85
|
+
layout.fields.some((field) => field.key === key && !field.required));
|
|
86
|
+
};
|
|
74
87
|
export const nativeFieldViewReadForText = (ctx, receiver, target, receipt, ordinaryReadOf, keyOperand) => {
|
|
75
88
|
const result = cppTypeOf(target);
|
|
76
89
|
const { adapter, accepted } = fieldViewRoutesText(ctx, receipt, result);
|
|
@@ -112,6 +125,15 @@ export const nativeFieldViewReadForText = (ctx, receiver, target, receipt, ordin
|
|
|
112
125
|
const plain = ordinary && actual && (actual.source.kind === 'optional' || actual.absentReadsUndefined === true)
|
|
113
126
|
? `return ${renderedLeaf(ctx, ordinary.conversion, concrete)};`
|
|
114
127
|
: 'gea::host::throwRuntimeError("TypeError", "a native view receiver has no admitted plain allocation");';
|
|
128
|
+
// An optional declared member of a plain record that is present holds
|
|
129
|
+
// its own value: the own-field protocol would find that same member by
|
|
130
|
+
// comparing the key against every field name. Only an absent key (an
|
|
131
|
+
// original allocation's answer, or undefined) needs the protocol.
|
|
132
|
+
// three's uniform `needsUpdate` is one, read for every uniform every
|
|
133
|
+
// frame.
|
|
134
|
+
const presentMember = ordinary && actual && actual.accessor !== true && memberAnswer === null && optionalRecordMember(ctx, carrier, key)
|
|
135
|
+
? `if (gea_field_receiver->${cppRecordFieldPresenceName(key)}) return ${renderedLeaf(ctx, ordinary.conversion, concrete)}; `
|
|
136
|
+
: '';
|
|
115
137
|
const property = `${viewKeyText(key)}`;
|
|
116
138
|
const native = `std::optional<${result}> gea_plain_answer; auto gea_plain_adapter = ${adapter}; ` +
|
|
117
139
|
`struct PlainRead { std::optional<${result}>* answer; decltype(gea_plain_adapter)* adapter; }; ` +
|
|
@@ -131,7 +153,7 @@ export const nativeFieldViewReadForText = (ctx, receiver, target, receipt, ordin
|
|
|
131
153
|
`if (!gea_field_receiver->gea_ownFieldPresent(${property}, gea_plain_present) || gea_plain_present) ` +
|
|
132
154
|
'gea::host::throwRuntimeError("TypeError", "a native allocation read has no certified carrier route"); ';
|
|
133
155
|
return (`return gea::record::readLiveField<${result}>(gea_field_receiver, ${liveKeyText(key)}, ` +
|
|
134
|
-
`${adapter}, ${accepted}, [&]() -> ${result} { ${getterAnswer ?? `${native}${plain}`} });`);
|
|
156
|
+
`${adapter}, ${accepted}, [&]() -> ${result} { ${getterAnswer ?? `${presentMember}${native}${plain}`} });`);
|
|
135
157
|
}, dynamicRead(key), nativeDataRead(key));
|
|
136
158
|
// The receiver is the statement-lambda's ARGUMENT, not a local bound inside
|
|
137
159
|
// it: a withheld receiver can be `(*presentOrThrow(<element read>))`, a
|
|
@@ -178,6 +200,51 @@ export const nativeFieldViewReadForText = (ctx, receiver, target, receipt, ordin
|
|
|
178
200
|
`const gea::PropertyKey gea_field_key = ${propertyKeyText(bound, keyOperand, 'a computed native field-view read')}; ` +
|
|
179
201
|
`${selected} ${otherKey} })(${operandText(ctx, receiver)})`);
|
|
180
202
|
};
|
|
203
|
+
/**
|
|
204
|
+
* A field-view read whose one use is the receiver of the next member read
|
|
205
|
+
* (`gull.pos.x` on a view-target record): spelled as a reference instead of a
|
|
206
|
+
* copied handle, so the plain allocation's answer costs no retain and no
|
|
207
|
+
* release. A live view's answer is held by `gea_field_slot`, a temporary of
|
|
208
|
+
* the caller's full expression, so the reference outlives the member load
|
|
209
|
+
* that consumes it (`readLiveFieldBorrowed`). Only the exact shape the plain
|
|
210
|
+
* read answers with its own member: a plain shared receiver, a declared,
|
|
211
|
+
* always-present, getter-free field already carried as the result; anything
|
|
212
|
+
* else keeps `nativeFieldViewReadText`.
|
|
213
|
+
*/
|
|
214
|
+
export const nativeFieldViewBorrowedReadText = (ctx, operation, ordinaryReadOf,
|
|
215
|
+
/**
|
|
216
|
+
* A frame slot a live view's answer is moved into, so the reference outlives
|
|
217
|
+
* the expression (`EmitContext.fieldPointerValues`). Without one the slot is
|
|
218
|
+
* a temporary of the full expression, which only a consumer in that same
|
|
219
|
+
* expression may read through.
|
|
220
|
+
*/
|
|
221
|
+
slot) => {
|
|
222
|
+
const receipt = operation.nativeFieldViewRead;
|
|
223
|
+
if (receipt === undefined || receipt.keyDomain !== undefined || receipt.originalAbsent === true)
|
|
224
|
+
return null;
|
|
225
|
+
const carrier = operation.receiver.representation;
|
|
226
|
+
if ((carrier.kind !== 'record' && carrier.kind !== 'class-ref' && carrier.kind !== 'native-record-ref') ||
|
|
227
|
+
carrier.ownership !== 'shared-refcount')
|
|
228
|
+
return null;
|
|
229
|
+
const target = operation.result.representation;
|
|
230
|
+
if ((target.kind !== 'record' && target.kind !== 'class-ref' && target.kind !== 'native-record-ref') ||
|
|
231
|
+
target.ownership !== 'shared-refcount')
|
|
232
|
+
return null;
|
|
233
|
+
const actual = ordinaryReadOf(carrier, receipt.key);
|
|
234
|
+
if (actual === null || actual.accessor === true || actual.source.kind === 'optional' || actual.absentReadsUndefined === true)
|
|
235
|
+
return null;
|
|
236
|
+
const ordinary = receipt.sources.find((entry) => representationKey(entry.source) === representationKey(actual.source));
|
|
237
|
+
const result = cppTypeOf(target);
|
|
238
|
+
if (ordinary === undefined || cppTypeOf(actual.source) !== result)
|
|
239
|
+
return null;
|
|
240
|
+
const concrete = `static_cast<const ${result}&>(${actual.text})`;
|
|
241
|
+
if (renderedLeaf(ctx, ordinary.conversion, concrete) !== concrete)
|
|
242
|
+
return null;
|
|
243
|
+
const { adapter, accepted } = fieldViewRoutesText(ctx, receipt, result);
|
|
244
|
+
return (`([&](const auto& gea_field_receiver, ${result}${slot === undefined ? '&&' : '&'} gea_field_slot) -> const ${result}& { ` +
|
|
245
|
+
`return gea::record::readLiveFieldBorrowed<${result}>(gea_field_receiver, ${liveKeyText(receipt.key)}, ${adapter}, ${accepted}, ` +
|
|
246
|
+
`gea_field_slot, [&]() -> const ${result}& { return ${concrete}; }); })(${operandText(ctx, operation.receiver)}, ${slot ?? `${result}()`})`);
|
|
247
|
+
};
|
|
181
248
|
export const nativeFieldViewReadText = (ctx, operation, ordinaryReadOf) => operation.nativeFieldViewRead === undefined
|
|
182
249
|
? null
|
|
183
250
|
: nativeFieldViewReadForText(ctx, operation.receiver, operation.result.representation, operation.nativeFieldViewRead, ordinaryReadOf, operation.key);
|
|
@@ -205,6 +272,8 @@ ordinaryStore) => {
|
|
|
205
272
|
// a dynamic writer may store a view into, such as three's uniform
|
|
206
273
|
// `{ value }` -- otherwise sends every plain store of the type, every
|
|
207
274
|
// frame, through `gea_writeOwnFieldNative`.
|
|
275
|
+
// An optional member takes the same store while it is present and writable;
|
|
276
|
+
// creating it, or refusing a read-only one, stays with the protocol.
|
|
208
277
|
const memberStore = (carrier, key) => {
|
|
209
278
|
// The receiver as `withFieldReceiver` binds it: presence and borrowing
|
|
210
279
|
// peeled, never a union arm (an arm's member store is that arm's own).
|
|
@@ -212,12 +281,17 @@ ordinaryStore) => {
|
|
|
212
281
|
while (held.kind === 'optional' || held.kind === 'borrowed-ref')
|
|
213
282
|
held = held.kind === 'optional' ? held.payload : held.referent;
|
|
214
283
|
if (ordinaryStore === undefined || representationKey(carrier) !== representationKey(held))
|
|
215
|
-
return
|
|
284
|
+
return null;
|
|
216
285
|
if (carrier.kind !== 'record' && carrier.kind !== 'native-record-ref')
|
|
217
|
-
return
|
|
286
|
+
return null;
|
|
218
287
|
if (carrier.kind === 'record' && carrier.accessors.some((accessor) => accessor.key === key))
|
|
219
|
-
return
|
|
220
|
-
|
|
288
|
+
return null;
|
|
289
|
+
const field = (staticOwnFieldsOf(ctx.deriver, carrier) ?? []).find((entry) => entry.key === key);
|
|
290
|
+
if (field === undefined)
|
|
291
|
+
return null;
|
|
292
|
+
if (field.required)
|
|
293
|
+
return 'required';
|
|
294
|
+
return optionalRecordMember(ctx, carrier, key) ? 'optional' : null;
|
|
221
295
|
};
|
|
222
296
|
const forKey = (key) => withFieldReceiver(operation.receiver.representation, 'gea_field_input', (carrier) => {
|
|
223
297
|
// A forwarded key no source behind a view declares is created on that
|
|
@@ -227,7 +301,8 @@ ordinaryStore) => {
|
|
|
227
301
|
return (`return gea::record::writeLiveOpenField<${nativeFieldPolicyType(receipt.open.carrier)}>(gea_field_receiver, ${viewKeyText(key)}, ` +
|
|
228
302
|
`gea_field_value, ${adapter}, ${openMaterializer(receipt.open)}, [&](const gea::NativeFieldWrite& gea_open_write) -> bool { ` +
|
|
229
303
|
`return gea_field_receiver->gea_writeOwnFieldNative(${viewKeyText(key)}, gea_open_write, gea::nativeIsExtensible(gea_field_receiver)); });`);
|
|
230
|
-
|
|
304
|
+
const member = receipt.keyDomain === undefined ? memberStore(carrier, key) : null;
|
|
305
|
+
if (member === 'required')
|
|
231
306
|
return (`return gea::record::writeLiveField(gea_field_receiver, ${liveKeyText(key)}, ` +
|
|
232
307
|
`gea_field_value, ${adapter}, [&]() -> bool { ` +
|
|
233
308
|
`${ordinaryStore(bound, { value: operation.receiver.value, representation: carrier }).join(' ')} return true; });`);
|
|
@@ -237,8 +312,12 @@ ordinaryStore) => {
|
|
|
237
312
|
'return (*static_cast<const decltype(gea_plain_adapter)*>(slot))(type, policy, answer); }; ' +
|
|
238
313
|
`return gea_field_receiver->gea_writeOwnFieldNative(${viewKeyText(key)}, ` +
|
|
239
314
|
'gea_plain_write, gea::nativeIsExtensible(gea_field_receiver));';
|
|
315
|
+
const presentStore = member === 'optional'
|
|
316
|
+
? `if (gea_field_receiver->${cppRecordFieldPresenceName(key)} && gea_field_receiver->${cppRecordFieldAttributesName(key)}.writable) { ` +
|
|
317
|
+
`${ordinaryStore(bound, { value: operation.receiver.value, representation: carrier }).join(' ')} return true; } `
|
|
318
|
+
: '';
|
|
240
319
|
return (`return gea::record::writeLiveField(gea_field_receiver, ${liveKeyText(key)}, ` +
|
|
241
|
-
`gea_field_value, ${adapter}, [&]() -> bool { ${plain} });`);
|
|
320
|
+
`gea_field_value, ${adapter}, [&]() -> bool { ${presentStore}${plain} });`);
|
|
242
321
|
});
|
|
243
322
|
// A fresh record's out-of-layout-order store states the order its literal
|
|
244
323
|
// created its keys in (`ir/facts.ts`'s `outOfOrderFreshStores`), exactly as
|
|
@@ -2,11 +2,11 @@ import { errorConstructorGetText, errorConstructorMemberText } from './emit-erro
|
|
|
2
2
|
import { dictionaryKeyDomainOf, isOpenDocument, ownershipOf, representationKey } from '../../representation/model.js';
|
|
3
3
|
import { carrierDifference, shortCarrierText } from '../../representation/difference.js';
|
|
4
4
|
import { nativeFieldOwnerReadText } from './emit-field-owner.js';
|
|
5
|
-
import { nativeFieldViewOperandContext, nativeFieldViewReadText, nativeFieldViewWriteText } from './emit-native-field-view.js';
|
|
5
|
+
import { nativeFieldViewBorrowedReadText, nativeFieldViewOperandContext, nativeFieldViewReadText, nativeFieldViewWriteText } from './emit-native-field-view.js';
|
|
6
6
|
import { nativeObjectDataGetText, nativeObjectDataSetText } from './emit-native-object-data.js';
|
|
7
7
|
import { nativeDocumentEntryText } from './emit-native-document-entry.js';
|
|
8
8
|
import { nativeCallableOptionalDataReadText } from './emit-native-callable-data.js';
|
|
9
|
-
import { cppDenseFlagName, cppDensePointerName, createCppEmitBlockedError, defineValue, defineValueAlias, nameOfValue, operandText, prototypeMethodReceiverText, unwrapPresentValue, isIntegerKeyValue, isIntegerStorageValue, storedEnvironmentText } from './emit-context.js';
|
|
9
|
+
import { cppDenseExtentName, cppDenseFlagName, cppDensePointerName, createCppEmitBlockedError, defineFieldPointer, defineValue, defineValueAlias, nameOfValue, operandText, prototypeMethodReceiverText, unwrapPresentValue, isIntegerKeyValue, isIntegerStorageValue, storageTypeOf, storedEnvironmentText } from './emit-context.js';
|
|
10
10
|
import { declaredHostMethodRead, emitNativeHostStore, nativeHostMemberText } from './host/emit-host-properties.js';
|
|
11
11
|
import { hostResultText } from './host/emit-host-arity.js';
|
|
12
12
|
import { classFamilyOverridesOf, classMemberOf, dispatchesStatically, fieldDeclaringStructOf, lazyArrowFieldGetPlanOf, lazyMaterializedFieldText, structNameOfReceiver, isConstructorViewShape } from './class-layout.js';
|
|
@@ -70,7 +70,7 @@ export const staticKeyTextOf = (ctx, key, contextDescription) => {
|
|
|
70
70
|
throw createCppEmitBlockedError(`runtime-helper:computation:to-property-key:${contextDescription}`, `${contextDescription} has a key that was not produced by a "constant" operation in this body; this emitter has no dynamic-key path`);
|
|
71
71
|
};
|
|
72
72
|
import { dateMemberText } from './prototype/emit-prototype-date.js';
|
|
73
|
-
import { arrayAccessText, presentElementText, keyedCollectionMemberText, iteratorMemberText, canonicalIndexLiteral, dictionaryPrototypeMemberRead, memberAccessOperator, positionalRecordArityText, promiseMemberText, keyedTableKeyText, emitRecordIndexSidecarStore, recordIndexSidecarReadText, reactiveRevisionText, scalarMemberText, stringMemberText, symbolMemberText, typedArrayAccessText, integerTypedArrayElements } from './emit-carrier-members.js';
|
|
73
|
+
import { arrayAccessText, presentElementText, keyedCollectionMemberText, iteratorMemberText, canonicalIndexLiteral, dictionaryPrototypeMemberRead, memberAccessOperator, positionalRecordArityText, promiseMemberText, keyedTableKeyText, emitRecordIndexSidecarStore, recordIndexSidecarReadText, reactiveRevisionText, scalarMemberText, stringMemberText, symbolMemberText, typedArrayAccessText, integerTypedArrayElements, declareDenseWindow } from './emit-carrier-members.js';
|
|
74
74
|
import { arrayBufferAccessText, dataViewAccessText, nativeBufferMethodValueText, sharedArrayBufferAccessText } from './emit-buffers.js';
|
|
75
75
|
import { functionSourceReadClaimOf } from './function-source-reads.js';
|
|
76
76
|
import { deferredCallableBuiltinReadClaimOf, recordWithIndexFieldClaimOf } from './property-read-claims.js';
|
|
@@ -163,7 +163,7 @@ const dictionaryReadText = (ctx, operation) => {
|
|
|
163
163
|
// (`Dictionary::hintedPosition`): the static lives in a lambda unique to the
|
|
164
164
|
// site, so each read site remembers where it last found its key.
|
|
165
165
|
const hinted = operation.receiver.representation.key === 'string' && ctx.staticKeyTexts.get(operation.key.value) !== undefined;
|
|
166
|
-
const withHint = (text) => `([&]() -> decltype(auto) { static constinit std::atomic<std::
|
|
166
|
+
const withHint = (text) => `([&]() -> decltype(auto) { static constinit std::atomic<std::uint64_t> gea_key_hint{0}; return ${text}; }())`;
|
|
167
167
|
const raw = hinted
|
|
168
168
|
? withHint(`gea::dictionary::readHinted(${table.table}, ${table.key}, gea_key_hint)`)
|
|
169
169
|
: `${table.member}read(${table.key})`;
|
|
@@ -418,11 +418,19 @@ const denseCellText = (ctx, operation) => {
|
|
|
418
418
|
const key = ctx.denseIndices.get(operation.key.value) ?? operandText(ctx, operation.key);
|
|
419
419
|
const flag = cppDenseFlagName(access.flag);
|
|
420
420
|
const integral = ctx.denseIndices.has(operation.key.value) || ctx.integerValues.has(operation.key.value);
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
421
|
+
// A checked window's index is not bounded by the loop: it is compared with
|
|
422
|
+
// the view's length the preheader took, unsigned so a negative one fails too.
|
|
423
|
+
// A Number index is asked whether it is a whole one as well.
|
|
424
|
+
const checked = ctx.denseArrays.find((array) => array.ordinal === access.array)?.checked === true;
|
|
425
|
+
const guarded = checked
|
|
426
|
+
? integral
|
|
427
|
+
? `${flag} && static_cast<std::size_t>(${key}) < ${cppDenseExtentName(access.array)}`
|
|
428
|
+
: `${flag} && gea::denseCheckedIndex(${key}, ${cppDenseExtentName(access.array)})`
|
|
429
|
+
: !access.signed
|
|
430
|
+
? flag
|
|
431
|
+
: integral
|
|
432
|
+
? `${flag} && (${key}) >= 0`
|
|
433
|
+
: `${flag} && (${key}) >= 0 && static_cast<double>(static_cast<long long>(${key})) == (${key})`;
|
|
426
434
|
return {
|
|
427
435
|
pointer: cppDensePointerName(access.array),
|
|
428
436
|
index: `static_cast<std::size_t>(${key})`,
|
|
@@ -477,11 +485,30 @@ const denseElementText = (ctx, operation) => {
|
|
|
477
485
|
(fast ?? dense.text) === dense.text) {
|
|
478
486
|
const slot = `gea_dense_read_${ctx.declarations.length}`;
|
|
479
487
|
ctx.declarations.push({ name: slot, type: `std::optional<${cppTypeOf(element)}>` });
|
|
488
|
+
ctx.denseCellReads.add(operation.result.id);
|
|
480
489
|
return `(${dense.flag} ? ${dense.text} : std::as_const(${slot}.emplace(${general})))`;
|
|
481
490
|
}
|
|
482
491
|
return `(${dense.flag} ? ${fast ?? dense.text} : ${general})`;
|
|
483
492
|
};
|
|
484
493
|
export const emitGet = (ctx, lines, operation) => {
|
|
494
|
+
emitGetRendering(ctx, lines, operation);
|
|
495
|
+
// A field pointer a pointer merge takes whose read rendered as a value of its
|
|
496
|
+
// own: the copy goes to a frame slot whose address the merge takes. Any
|
|
497
|
+
// other read that could not borrow keeps its value as it was.
|
|
498
|
+
if (ctx.fieldPointerMergeInputs.has(operation.result.id) && !ctx.fieldPointerTexts.has(operation.result.id)) {
|
|
499
|
+
const value = ctx.valueNames.get(operation.result.id);
|
|
500
|
+
if (value === undefined)
|
|
501
|
+
throw new Error(`field pointer ${operation.result.id} rendered no value`);
|
|
502
|
+
const slot = `gea_field_slot_${ctx.declarations.length}`;
|
|
503
|
+
ctx.declarations.push({
|
|
504
|
+
name: slot,
|
|
505
|
+
type: `std::optional<${storageTypeOf(ctx, operation.result.id, operation.result.representation)}>`
|
|
506
|
+
});
|
|
507
|
+
lines.push(`${slot}.emplace(${value});`);
|
|
508
|
+
ctx.fieldPointerTexts.set(operation.result.id, `&*${slot}`);
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
const emitGetRendering = (ctx, lines, operation) => {
|
|
485
512
|
const objectData = nativeObjectDataGetText(ctx, operation);
|
|
486
513
|
if (objectData !== null) {
|
|
487
514
|
lines.push(`${defineValue(ctx, operation.result)} = ${objectData};`);
|
|
@@ -516,8 +543,8 @@ export const emitGet = (ctx, lines, operation) => {
|
|
|
516
543
|
lines.push(`${defineValue(ctx, operation.result)} = ${rendered};`);
|
|
517
544
|
return;
|
|
518
545
|
}
|
|
519
|
-
if (operation.nativeFieldViewRead) {
|
|
520
|
-
const
|
|
546
|
+
if (operation.nativeFieldViewRead && !plainAllocationMemberRead(ctx, operation)) {
|
|
547
|
+
const ordinaryReadOf = (carrier, key) => {
|
|
521
548
|
// A class arm answering the key from a getter has no own field to
|
|
522
549
|
// read natively: the plain allocation's answer is the getter's body
|
|
523
550
|
// (`parent?.options` over `A | B | ...`, each a getter).
|
|
@@ -541,6 +568,9 @@ export const emitGet = (ctx, lines, operation) => {
|
|
|
541
568
|
read = `static_cast<${cppTypeOf(source.value)}>(${read})`;
|
|
542
569
|
if (source.required)
|
|
543
570
|
return { source: source.value, text: read };
|
|
571
|
+
if (representationKey(carrier) === representationKey(operation.receiver.representation) &&
|
|
572
|
+
allocationKeepsField(ctx, operation.receiver, key))
|
|
573
|
+
return { source: source.value, text: read };
|
|
544
574
|
// An absent own key reads undefined. A union spells it as its undefined
|
|
545
575
|
// arm and a Value or a reference as its own; their default does not.
|
|
546
576
|
const undefinedText = cppUndefinedIn(source.value);
|
|
@@ -552,7 +582,20 @@ export const emitGet = (ctx, lines, operation) => {
|
|
|
552
582
|
text: `(gea_field_receiver->${cppRecordFieldPresenceName(key)} ? ${read} : ${absent})`,
|
|
553
583
|
...(undefinedText === null ? {} : { absentReadsUndefined: true })
|
|
554
584
|
};
|
|
555
|
-
}
|
|
585
|
+
};
|
|
586
|
+
// A field pointer names the view's answer in a slot of the frame, or the
|
|
587
|
+
// plain allocation's own member.
|
|
588
|
+
if (ctx.fieldPointerValues.has(operation.result.id)) {
|
|
589
|
+
const slot = `gea_field_slot_${ctx.declarations.length}`;
|
|
590
|
+
const borrowed = nativeFieldViewBorrowedReadText(ctx, operation, ordinaryReadOf, slot);
|
|
591
|
+
if (borrowed !== null) {
|
|
592
|
+
ctx.declarations.push({ name: slot, type: cppTypeOf(operation.result.representation) });
|
|
593
|
+
lines.push(`${defineFieldPointer(ctx, operation.result)} = &${borrowed};`);
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
const rendered = (ctx.borrowedFieldReads.has(operation.result.id) ? nativeFieldViewBorrowedReadText(ctx, operation, ordinaryReadOf) : null) ??
|
|
598
|
+
nativeFieldViewReadText(ctx, operation, ordinaryReadOf);
|
|
556
599
|
if (rendered === null)
|
|
557
600
|
throw new Error('a published field-view read lost its receipt');
|
|
558
601
|
lines.push(`${defineValue(ctx, operation.result)} = ${rendered};`);
|
|
@@ -1028,6 +1071,11 @@ export const emitGet = (ctx, lines, operation) => {
|
|
|
1028
1071
|
return;
|
|
1029
1072
|
}
|
|
1030
1073
|
const read = accessorShadowedFieldReadText(ctx, operation, fieldName) ?? fixedFieldReadText(ctx, operation, fieldName);
|
|
1074
|
+
// A field pointer names the member itself, when the read is the bare load.
|
|
1075
|
+
if (ctx.fieldPointerValues.has(operation.result.id) && read === plainFieldReadText(ctx, operation, fieldName)) {
|
|
1076
|
+
lines.push(`${defineFieldPointer(ctx, operation.result)} = &(${read});`);
|
|
1077
|
+
return;
|
|
1078
|
+
}
|
|
1031
1079
|
// A construction-only field of this body's own receiver holds one value
|
|
1032
1080
|
// from the read to every use (`ctx.stableFieldReads`), so the read names
|
|
1033
1081
|
// the member. Only the plain member load qualifies: a presence test or a
|
|
@@ -1179,6 +1227,53 @@ const fieldReadText = (ctx, representation, fieldName, prefix) => {
|
|
|
1179
1227
|
const fields = recordFieldsForTailLookup(ctx, representation);
|
|
1180
1228
|
return fields === null ? `${prefix}${cppRecordFieldName(fieldName)}` : tailAwareFieldReadText(fields, fieldName, prefix);
|
|
1181
1229
|
};
|
|
1230
|
+
/**
|
|
1231
|
+
* A field-view read whose receiver is a cell's one plain allocation
|
|
1232
|
+
* (`EmitContext.plainAllocationValues`) and whose key is a declared member
|
|
1233
|
+
* carried as the read's own result: the view protocol would only ever take its
|
|
1234
|
+
* plain branch, which is this member (an absent optional one reads undefined,
|
|
1235
|
+
* as its presence test says), so the read is the member's ordinary load --
|
|
1236
|
+
* and, across a window nothing stores it in, an alias of it.
|
|
1237
|
+
*/
|
|
1238
|
+
const plainAllocationMemberRead = (ctx, operation) => {
|
|
1239
|
+
const receipt = operation.nativeFieldViewRead;
|
|
1240
|
+
const carrier = operation.receiver.representation;
|
|
1241
|
+
if (receipt === undefined || receipt.keyDomain !== undefined || receipt.originalAbsent === true)
|
|
1242
|
+
return false;
|
|
1243
|
+
if (!ctx.plainAllocationValues.has(operation.receiver.value))
|
|
1244
|
+
return false;
|
|
1245
|
+
const accessors = carrier.kind === 'record'
|
|
1246
|
+
? carrier.accessors
|
|
1247
|
+
: carrier.kind === 'native-record-ref' && carrier.native === null
|
|
1248
|
+
? recordAccessorsOfShape(ctx.deriver, carrier.shapeId)
|
|
1249
|
+
: null;
|
|
1250
|
+
if (accessors === null || accessors.some((accessor) => accessor.key === receipt.key))
|
|
1251
|
+
return false;
|
|
1252
|
+
const source = declaredRecordFieldOf(ctx.deriver, carrier, receipt.key, ctx.classes);
|
|
1253
|
+
return source !== null && representationKey(source.value) === representationKey(operation.result.representation);
|
|
1254
|
+
};
|
|
1255
|
+
/**
|
|
1256
|
+
* A field-view store into a cell's one plain allocation, of a declared member:
|
|
1257
|
+
* the view protocol's plain branch is the ordinary member store
|
|
1258
|
+
* (`emitFieldStoreLines`, which keeps its own writability guard), so that is
|
|
1259
|
+
* the whole store.
|
|
1260
|
+
*/
|
|
1261
|
+
const plainAllocationMemberWrite = (ctx, operation) => {
|
|
1262
|
+
const receipt = operation.nativeFieldViewWrite;
|
|
1263
|
+
const carrier = operation.receiver.representation;
|
|
1264
|
+
if (receipt === undefined || receipt.keyDomain !== undefined || receipt.openKeys === true)
|
|
1265
|
+
return false;
|
|
1266
|
+
if (!ctx.plainAllocationValues.has(operation.receiver.value))
|
|
1267
|
+
return false;
|
|
1268
|
+
const accessors = carrier.kind === 'record'
|
|
1269
|
+
? carrier.accessors
|
|
1270
|
+
: carrier.kind === 'native-record-ref' && carrier.native === null
|
|
1271
|
+
? recordAccessorsOfShape(ctx.deriver, carrier.shapeId)
|
|
1272
|
+
: null;
|
|
1273
|
+
if (accessors === null || accessors.some((accessor) => accessor.key === receipt.key))
|
|
1274
|
+
return false;
|
|
1275
|
+
return declaredRecordFieldOf(ctx.deriver, carrier, receipt.key, ctx.classes) !== null;
|
|
1276
|
+
};
|
|
1182
1277
|
/** `receiver->field` with nothing around it: the rendering a stable field read may alias. */
|
|
1183
1278
|
const plainFieldReadText = (ctx, operation, fieldName) => {
|
|
1184
1279
|
const receiver = constructorViewReceiverText(ctx, operation.receiver, fieldName, operandText(ctx, operation.receiver));
|
|
@@ -1315,8 +1410,22 @@ const fixedFieldPresenceText = (ctx, receiver, fieldName) => {
|
|
|
1315
1410
|
// leave unset.
|
|
1316
1411
|
if (field.required && ctx.fixedFieldStateConstant)
|
|
1317
1412
|
return null;
|
|
1413
|
+
if (allocationKeepsField(ctx, receiver, fieldName))
|
|
1414
|
+
return null;
|
|
1318
1415
|
return `${constructorViewReceiverText(ctx, receiver, fieldName, operandText(ctx, receiver))}${memberAccessOperator(representation.ownership)}${cppRecordFieldPresenceName(fieldName)}`;
|
|
1319
1416
|
};
|
|
1417
|
+
/**
|
|
1418
|
+
* Whether `receiver` holds a cell's one allocation (`ctx.allocationFieldKeys`)
|
|
1419
|
+
* that defined `fieldName`, a key nothing in the program can delete from its
|
|
1420
|
+
* carrier (`fixedFieldState`): the allocation raised the field's presence bit
|
|
1421
|
+
* and nothing lowers it, so the field is present for the object's whole life
|
|
1422
|
+
* however few family members declare it required. A Gull-only field of an
|
|
1423
|
+
* interface family is optional in the family's one layout because a Hound
|
|
1424
|
+
* never has it, yet the gull's own methods read it through `gull`, the cell
|
|
1425
|
+
* holding the literal that wrote it.
|
|
1426
|
+
*/
|
|
1427
|
+
const allocationKeepsField = (ctx, receiver, fieldName) => ctx.allocationFieldKeys.get(receiver.value)?.has(fieldName) === true &&
|
|
1428
|
+
ctx.nativeIntegrityRestricted.fixedFieldState(receiver.representation, fieldName);
|
|
1320
1429
|
/** A native slot is read through the exact conversion lowering certified. */
|
|
1321
1430
|
const narrowedFieldReadText = (ctx, operation, fieldName, storage, presence = null,
|
|
1322
1431
|
/**
|
|
@@ -1497,7 +1606,7 @@ export const emitFieldStore = (ctx, lines, operation, label) => {
|
|
|
1497
1606
|
defineValueAlias(ctx, operation.result, operandText(ctx, operation.receiver));
|
|
1498
1607
|
return;
|
|
1499
1608
|
}
|
|
1500
|
-
if (operation.kind === 'set' && operation.nativeFieldViewWrite) {
|
|
1609
|
+
if (operation.kind === 'set' && operation.nativeFieldViewWrite && !plainAllocationMemberWrite(ctx, operation)) {
|
|
1501
1610
|
let viewContext = ctx;
|
|
1502
1611
|
if (operation.result) {
|
|
1503
1612
|
lines.push(`${defineValue(ctx, operation.result)} = ${operandText(ctx, operation.receiver)};`);
|
|
@@ -1774,7 +1883,20 @@ const emitFieldStoreLines = (ctx, lines, operation, label) => {
|
|
|
1774
1883
|
throw createCppEmitBlockedError(`conversion:${representationKey(operation.value.representation)}->${representationKey(operation.receiver.representation.element)}`, `cannot convert an Array element from "${representationKey(operation.value.representation)}" to ` +
|
|
1775
1884
|
`"${representationKey(operation.receiver.representation.element)}"`);
|
|
1776
1885
|
}
|
|
1777
|
-
|
|
1886
|
+
// A store of a run of constant-index accesses (`ir/dense-read-windows.ts`):
|
|
1887
|
+
// while the run's window holds -- dense, in range, writable -- the store
|
|
1888
|
+
// is the cell's own assignment.
|
|
1889
|
+
const window = operation.kind === 'set' ? ctx.denseWriteWindows.get(operation) : undefined;
|
|
1890
|
+
if (window === undefined)
|
|
1891
|
+
lines.push(`${arrayReceiver}->setElementAtIndex(${index}, ${storedValue});`);
|
|
1892
|
+
else {
|
|
1893
|
+
const name = `gea_read_window_${window.ordinal}`;
|
|
1894
|
+
declareDenseWindow(ctx, name, operation.receiver.representation);
|
|
1895
|
+
const cells = window.initialize
|
|
1896
|
+
? `(${name}.cells = gea::denseWindowCellsMutable(${arrayReceiver}, ${window.last}))`
|
|
1897
|
+
: `${name}.cells`;
|
|
1898
|
+
lines.push(`if (${cells}) ${name}.cells[${index}].value = ${storedValue}; else ${arrayReceiver}->setElementAtIndex(${index}, ${storedValue});`);
|
|
1899
|
+
}
|
|
1778
1900
|
finishArrayStore();
|
|
1779
1901
|
return;
|
|
1780
1902
|
}
|
|
@@ -2081,8 +2203,9 @@ const emitFieldStoreLines = (ctx, lines, operation, label) => {
|
|
|
2081
2203
|
// the field (`nativeIntegrityRestricted.fixedFieldState`), though the bit
|
|
2082
2204
|
// itself stays an instance member there that allocation set to `true`.
|
|
2083
2205
|
const fieldStatePinned = field &&
|
|
2084
|
-
field.required &&
|
|
2085
|
-
|
|
2206
|
+
((field.required &&
|
|
2207
|
+
(ctx.fixedFieldStateConstant || ctx.nativeIntegrityRestricted.fixedFieldState(operation.receiver.representation, fieldName))) ||
|
|
2208
|
+
allocationKeepsField(ctx, operation.receiver, fieldName));
|
|
2086
2209
|
if (field && !fieldStatePinned)
|
|
2087
2210
|
stores.push(`${receiverText}${accessor}${cppRecordFieldPresenceName(fieldName)} = true;`);
|
|
2088
2211
|
// A fresh record's keys are known statically, so only a store the IR
|
|
@@ -310,6 +310,26 @@ const recordViewText = (ctx, plan, text) => {
|
|
|
310
310
|
return (`([&]() -> ${targetType} { const auto& ${source} = ${text}; ` +
|
|
311
311
|
`return ${source}${arrow}${cppRecordFieldName('done')} ? ${returned} : ${yielded}; }())`);
|
|
312
312
|
}
|
|
313
|
+
case 'present-field': {
|
|
314
|
+
const source = 'gea_present_field';
|
|
315
|
+
const targetType = cppTypeOf(plan.target);
|
|
316
|
+
const home = (planned) => {
|
|
317
|
+
const arm = plan.target.arms[planned.index];
|
|
318
|
+
if (arm === undefined)
|
|
319
|
+
return null;
|
|
320
|
+
const built = planned.payload === null
|
|
321
|
+
? alignedValueText(ctx, 'emit-record-view.ts:present-field', plan.source, arm.value, source)
|
|
322
|
+
: recordViewText(ctx, planned.payload, source);
|
|
323
|
+
return built === null ? null : `${targetType}::ofArm<${planned.index}>(${built})`;
|
|
324
|
+
};
|
|
325
|
+
const present = home(plan.presentHome);
|
|
326
|
+
const absent = home(plan.absentHome);
|
|
327
|
+
if (present === null || absent === null)
|
|
328
|
+
return null;
|
|
329
|
+
const arrow = plan.source.ownership !== 'shared-refcount' ? '.' : '->';
|
|
330
|
+
return (`([&]() -> ${targetType} { const auto& ${source} = ${text}; ` +
|
|
331
|
+
`return ${source}${arrow}${cppRecordFieldName(plan.key)}.has_value() ? ${present} : ${absent}; }())`);
|
|
332
|
+
}
|
|
313
333
|
case 'fields':
|
|
314
334
|
return recordFieldsViewText(ctx, plan, text);
|
|
315
335
|
}
|
|
@@ -397,6 +417,24 @@ expandoAbsent = false) => {
|
|
|
397
417
|
// `recastedRecordText`). Left alone a bit keeps its declared default.
|
|
398
418
|
const presences = [];
|
|
399
419
|
const structName = cppRecordStructName(target.shapeId);
|
|
420
|
+
// Inside braces [dcl.init.list]/7 forbids the narrowing every other
|
|
421
|
+
// position allows: a field the integer census holds in a `long long`
|
|
422
|
+
// (`{ kind, type }` with `kind: 1 | 2`) is a hard error written into a
|
|
423
|
+
// `double` member of the layout it is viewed as, though both carriers say
|
|
424
|
+
// `scalar(number)`. `static_cast` spells the same conversion explicitly --
|
|
425
|
+
// `emit-narrowing.ts`'s `recastFieldText` answers the identical rule this
|
|
426
|
+
// way -- and is a no-op where the two already agree. The cast names the
|
|
427
|
+
// member's OWN declared type, `decltype(Struct::member)`, because the
|
|
428
|
+
// census's answer lives in the struct declaration `records.ts` emitted
|
|
429
|
+
// and nowhere this emitter can ask: the representation says `double` for
|
|
430
|
+
// both sides, and casting to that spelling is the same narrowing error
|
|
431
|
+
// in the other direction whenever the TARGET member is the narrowed one
|
|
432
|
+
// (a `Leaf { value: number }` read through a `Branch | Leaf` arm).
|
|
433
|
+
// A getter's answer obeys the same rule: its body's return is narrowed by the
|
|
434
|
+
// same census, so `get min() { return 5 }` hands back a `long long`.
|
|
435
|
+
const memberCast = (field, from, converted) => field.value.kind === 'scalar' && field.value.domain !== 'bigint' && from.kind === 'scalar'
|
|
436
|
+
? `static_cast<decltype(${structName}::${cppRecordFieldName(field.key)})>(${converted})`
|
|
437
|
+
: converted;
|
|
400
438
|
// An authenticated source allocation is a traced edge of the new view's
|
|
401
439
|
// own allocation. Value-record copies have no source handle to retain.
|
|
402
440
|
const allocate = (argumentsText) => source.ownership === 'shared-refcount'
|
|
@@ -457,7 +495,7 @@ expandoAbsent = false) => {
|
|
|
457
495
|
if (got === null)
|
|
458
496
|
return null;
|
|
459
497
|
orderSensitive = true;
|
|
460
|
-
reads.push(got);
|
|
498
|
+
reads.push(memberCast(field, read.value, got));
|
|
461
499
|
if (!field.required)
|
|
462
500
|
presences.push([field.key, 'true']);
|
|
463
501
|
continue;
|
|
@@ -470,7 +508,7 @@ expandoAbsent = false) => {
|
|
|
470
508
|
const converted = structuralLeafText(ctx, read.value, field.value, got);
|
|
471
509
|
if (converted === null)
|
|
472
510
|
return null;
|
|
473
|
-
reads.push(converted);
|
|
511
|
+
reads.push(memberCast(field, read.value, converted));
|
|
474
512
|
orderSensitive = true;
|
|
475
513
|
if (!field.required)
|
|
476
514
|
presences.push([field.key, 'true']);
|
|
@@ -538,23 +576,7 @@ expandoAbsent = false) => {
|
|
|
538
576
|
if (read.kind === 'view' && ['gea_sidecar', 'gea_vget_', 'gea_body_fn_decl_'].some((mark) => converted.includes(mark))) {
|
|
539
577
|
orderSensitive = true;
|
|
540
578
|
}
|
|
541
|
-
|
|
542
|
-
// position allows: a field the integer census holds in a `long long`
|
|
543
|
-
// (`{ kind, type }` with `kind: 1 | 2`) is a hard error written into a
|
|
544
|
-
// `double` member of the layout it is viewed as, though both carriers say
|
|
545
|
-
// `scalar(number)`. `static_cast` spells the same conversion explicitly --
|
|
546
|
-
// `emit-narrowing.ts`'s `recastFieldText` answers the identical rule this
|
|
547
|
-
// way -- and is a no-op where the two already agree. The cast names the
|
|
548
|
-
// member's OWN declared type, `decltype(Struct::member)`, because the
|
|
549
|
-
// census's answer lives in the struct declaration `records.ts` emitted
|
|
550
|
-
// and nowhere this emitter can ask: the representation says `double` for
|
|
551
|
-
// both sides, and casting to that spelling is the same narrowing error
|
|
552
|
-
// in the other direction whenever the TARGET member is the narrowed one
|
|
553
|
-
// (a `Leaf { value: number }` read through a `Branch | Leaf` arm).
|
|
554
|
-
const arithmetic = field.value.kind === 'scalar' && field.value.domain !== 'bigint';
|
|
555
|
-
reads.push(arithmetic && held.value.kind === 'scalar'
|
|
556
|
-
? `static_cast<decltype(${structName}::${cppRecordFieldName(field.key)})>(${converted})`
|
|
557
|
-
: converted);
|
|
579
|
+
reads.push(memberCast(field, held.value, converted));
|
|
558
580
|
if (!field.required) {
|
|
559
581
|
presences.push([field.key, held.required ? 'true' : `${text}${arrow}${cppRecordFieldPresenceName(field.key)}`]);
|
|
560
582
|
}
|
|
@@ -631,6 +653,11 @@ const liveRecordFieldsText = (ctx, plan, live, text) => {
|
|
|
631
653
|
const actual = 'gea_live_source';
|
|
632
654
|
const environment = (key, body, half) => ctx.captures.of(body).kind === 'ok' ? [storedEnvironmentText(body, `${actual}->${cppRecordAccessorEnvironmentName(key, half)}`)] : [];
|
|
633
655
|
const accesses = [];
|
|
656
|
+
// A getter's body is narrowed by the integer census, so `get min() { return
|
|
657
|
+
// 5 }` answers a `long long` where the route accepts a `double`; the route's
|
|
658
|
+
// `assign` deduces the stored type from its argument and refuses the
|
|
659
|
+
// mismatch, so the answer is converted to the route's own carrier first.
|
|
660
|
+
const getterAnswer = (carrier, call) => carrier.kind === 'scalar' && carrier.domain !== 'bigint' ? `static_cast<${cppTypeOf(carrier)}>(${call})` : call;
|
|
634
661
|
for (const { field, read } of plan.fields) {
|
|
635
662
|
const route = live.fields.find((entry) => entry.key === field.key);
|
|
636
663
|
if (!route)
|
|
@@ -674,7 +701,7 @@ const liveRecordFieldsText = (ctx, plan, live, text) => {
|
|
|
674
701
|
}
|
|
675
702
|
}
|
|
676
703
|
else if (read.kind === 'record-accessor') {
|
|
677
|
-
got = `${cppBodyName(read.getter)}(${[...environment(field.key, read.getter, 'getter'), actual].join(', ')})
|
|
704
|
+
got = getterAnswer(route.read, `${cppBodyName(read.getter)}(${[...environment(field.key, read.getter, 'getter'), actual].join(', ')})`);
|
|
678
705
|
if (read.setter !== null && route.write !== null)
|
|
679
706
|
write = {
|
|
680
707
|
value: route.write,
|
|
@@ -695,9 +722,9 @@ const liveRecordFieldsText = (ctx, plan, live, text) => {
|
|
|
695
722
|
const dispatch = ctx.virtualDispatch?.get(virtualDispatchKey(source.declaration, field.key, 'get'));
|
|
696
723
|
if (dispatch && representationKey(dispatch.result) !== representationKey(route.read))
|
|
697
724
|
return null;
|
|
698
|
-
got = dispatch
|
|
725
|
+
got = getterAnswer(route.read, dispatch
|
|
699
726
|
? `${actual}->${cppVirtualMemberName(field.key, 'get')}()`
|
|
700
|
-
: `${cppBodyName(getter)}(${[...environment(field.key, getter, 'getter'), actual].join(', ')})
|
|
727
|
+
: `${cppBodyName(getter)}(${[...environment(field.key, getter, 'getter'), actual].join(', ')})`);
|
|
701
728
|
if (route.write !== null && member.accessor.setter !== null) {
|
|
702
729
|
const setter = member.accessor.setter;
|
|
703
730
|
const dispatch = ctx.virtualDispatch?.get(virtualDispatchKey(source.declaration, field.key, 'set'));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { representationKey } from '../../representation/model.js';
|
|
2
2
|
import { settlesOverPayloadOrPromise } from '../../projection/slots.js';
|
|
3
|
-
import { operandText, createCppEmitBlockedError } from './emit-context.js';
|
|
3
|
+
import { operandText, createCppEmitBlockedError, cppReceiverName } from './emit-context.js';
|
|
4
4
|
import { cppTypeOf, cppUndefinedIn } from './types.js';
|
|
5
5
|
import { alignedValueText, dynamicPromiseAdoptionText, recipeText } from './emit-narrowing.js';
|
|
6
6
|
import { structuralRecordViewText } from './emit-record-view.js';
|
|
@@ -209,6 +209,10 @@ export const emitReturn = (ctx, lines, terminator) => {
|
|
|
209
209
|
lines.push(completion === null ? 'co_return;' : `co_return ${returnedCellText(ctx, completion.text)};`);
|
|
210
210
|
return;
|
|
211
211
|
}
|
|
212
|
+
if (ctx.returnsOwnReceiver && terminator.value) {
|
|
213
|
+
lines.push(`return ${cppReceiverName};`);
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
212
216
|
if (!terminator.value) {
|
|
213
217
|
// `Promise<void>` is a real class type, not the literal `void` -- a
|
|
214
218
|
// bare `return;` inside a function whose ABI result is
|