@geastack/compiler 1.0.62 → 1.0.64

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/dist/cli-emit.js +14 -5
  2. package/dist/conversion/dictionary-view.js +13 -2
  3. package/dist/conversion/document-record-view.d.ts +0 -1
  4. package/dist/conversion/document-record-view.js +30 -3
  5. package/dist/conversion/impossible-field-read.d.ts +9 -0
  6. package/dist/conversion/impossible-field-read.js +26 -0
  7. package/dist/conversion/nodes.d.ts +12 -0
  8. package/dist/conversion/nodes.js +106 -2
  9. package/dist/conversion/record-view.js +21 -0
  10. package/dist/ir/build.d.ts +5 -2
  11. package/dist/ir/build.js +9 -2
  12. package/dist/ir/callable-class-flow.js +233 -13
  13. package/dist/ir/certify/parallel-region.js +1 -0
  14. package/dist/ir/certify.js +32 -2
  15. package/dist/ir/dense-loops.js +8 -1
  16. package/dist/ir/hoist.js +15 -1
  17. package/dist/ir/host-template-conversions.js +12 -0
  18. package/dist/ir/lower-invocation.js +42 -2
  19. package/dist/ir/lower-property.js +2 -2
  20. package/dist/ir/model.d.ts +18 -6
  21. package/dist/ir/native-callable-data-reads.js +15 -2
  22. package/dist/ir/native-field-view-domains.d.ts +8 -0
  23. package/dist/ir/native-field-view-domains.js +44 -3
  24. package/dist/ir/native-field-view-facts.d.ts +2 -2
  25. package/dist/ir/native-field-view-facts.js +57 -13
  26. package/dist/ir/native-own-assignment.js +20 -2
  27. package/dist/ir/program-conversions.js +38 -7
  28. package/dist/ir/property-read-conversions.js +14 -5
  29. package/dist/ir/publish-native-field-view-facts.js +1 -1
  30. package/dist/ir/queries.js +2 -0
  31. package/dist/ir/read-only-dictionary.js +138 -15
  32. package/dist/ir/reflection-demand.js +7 -1
  33. package/dist/ir/shake.js +26 -6
  34. package/dist/ir/typed-property-access.d.ts +20 -0
  35. package/dist/ir/typed-property-access.js +56 -0
  36. package/dist/projection/bindings.js +14 -19
  37. package/dist/projection/fields.js +7 -1
  38. package/dist/projection/native-object-data.d.ts +8 -1
  39. package/dist/projection/native-object-data.js +16 -4
  40. package/dist/representation/derive.js +67 -1
  41. package/dist/representation/proxy-carriers.js +17 -2
  42. package/dist/representation/publish.js +34 -0
  43. package/dist/semantics/callable-own-data-slots.js +71 -6
  44. package/dist/semantics/model/operations.d.ts +15 -4
  45. package/dist/semantics/native-own-assignment.d.ts +3 -0
  46. package/dist/semantics/normalize/collection-bindings.js +2 -2
  47. package/dist/semantics/normalize/flow/array-element-continuation.d.ts +1 -1
  48. package/dist/semantics/normalize/flow/array-element-continuation.js +32 -9
  49. package/dist/semantics/normalize/flow/callable-reach.d.ts +3 -5
  50. package/dist/semantics/normalize/flow/callable-reach.js +3 -5
  51. package/dist/semantics/normalize/flow/component-solver.d.ts +2 -0
  52. package/dist/semantics/normalize/flow/component-solver.js +32 -6
  53. package/dist/semantics/normalize/flow/computed-key-set.js +53 -1
  54. package/dist/semantics/normalize/flow/source-value-session.js +16 -14
  55. package/dist/semantics/normalize/producers/invocations.js +40 -1
  56. package/dist/semantics/normalize/producers/native-own-assignment.js +12 -4
  57. package/dist/semantics/normalize/reachability.js +18 -8
  58. package/dist/semantics/normalize/structural-mutable-field.d.ts +1 -0
  59. package/dist/semantics/normalize/structural-mutable-field.js +170 -4
  60. package/dist/semantics/normalize/structural-parts.js +6 -1
  61. package/dist/semantics/normalize/structural-self-reference.d.ts +1 -1
  62. package/dist/semantics/normalize/structural-self-reference.js +9 -1
  63. package/dist/semantics/normalize/structural.js +10 -1
  64. package/dist/semantics/program.js +102 -1
  65. package/dist/targets/cpp/class-properties/emit-class-properties.js +9 -0
  66. package/dist/targets/cpp/emit-allocation.js +22 -1
  67. package/dist/targets/cpp/emit-callable.js +3 -3
  68. package/dist/targets/cpp/emit-exceptions.js +6 -0
  69. package/dist/targets/cpp/emit-narrowing.js +24 -2
  70. package/dist/targets/cpp/emit-native-field-view.d.ts +1 -1
  71. package/dist/targets/cpp/emit-native-field-view.js +37 -5
  72. package/dist/targets/cpp/emit-native-own-assignment.js +5 -1
  73. package/dist/targets/cpp/emit-record-view.js +6 -1
  74. package/dist/targets/cpp/emit-tonumber.d.ts +22 -11
  75. package/dist/targets/cpp/emit-tonumber.js +86 -25
  76. package/dist/targets/cpp/emit.js +3 -0
  77. package/dist/targets/cpp/host/emit-host-invoke.js +6 -6
  78. package/dist/targets/cpp/prototype/emit-prototype-array.js +13 -1
  79. package/dist/targets/cpp/records.js +15 -7
  80. package/dist/targets/cpp/recursive-containers.js +5 -1
  81. package/dist/targets/cpp/translation-unit.js +17 -2
  82. package/package.json +4 -2
  83. package/src/targets/cpp/runtime/gea_runtime.h +212 -7
package/dist/cli-emit.js CHANGED
@@ -26,6 +26,7 @@ const parseEmitArguments = (argv) => {
26
26
  let entry = null;
27
27
  let stage = 'hybrid';
28
28
  let projectFileName = null;
29
+ let noProject = false;
29
30
  let dynamicFallback = false;
30
31
  let closedScriptScope = false;
31
32
  let isolateSymbols = false;
@@ -85,6 +86,9 @@ const parseEmitArguments = (argv) => {
85
86
  translationUnits = value;
86
87
  index += 1;
87
88
  }
89
+ else if (argument === '--no-project') {
90
+ noProject = true;
91
+ }
88
92
  else if (argument === '--project') {
89
93
  projectFileName = argv[index + 1] ?? null;
90
94
  index += 1;
@@ -118,6 +122,10 @@ const parseEmitArguments = (argv) => {
118
122
  positional.push(argument);
119
123
  }
120
124
  }
125
+ // Two answers to the one question discovery would otherwise guess at; either
126
+ // winning silently compiles a program the caller did not ask for.
127
+ if (noProject && projectFileName !== null)
128
+ return 'compile: --project and --no-project cannot both be given';
121
129
  const input = positional[0];
122
130
  if (input === undefined)
123
131
  return 'compile: no input file';
@@ -135,6 +143,7 @@ const parseEmitArguments = (argv) => {
135
143
  plugins,
136
144
  pluginOptions,
137
145
  projectFileName,
146
+ noProject,
138
147
  isolateSymbols,
139
148
  realmStorage,
140
149
  debugSource,
@@ -192,10 +201,10 @@ export const runEmit = async (argv, moduleGraph = false) => {
192
201
  // generated type hints), so the honest reading is that it has no project,
193
202
  // and its types come from JSDoc.
194
203
  const bundled = /\.[cm]?js$/.test(input);
195
- // A named project wins over discovery, and over the bundle rule above: a
196
- // caller that states which project an input belongs to has answered the
197
- // question this command would otherwise guess at.
198
- const projectFileName = parsed.projectFileName ?? (bundled ? null : findProjectFile(dirname(input)));
204
+ // A named project -- or a stated absence of one -- wins over discovery, and
205
+ // over the bundle rule above: a caller that states which project an input
206
+ // belongs to has answered the question this command would otherwise guess at.
207
+ const projectFileName = parsed.noProject ? null : (parsed.projectFileName ?? (bundled ? null : findProjectFile(dirname(input))));
199
208
  const result = compile({
200
209
  rootFileNames: [input],
201
210
  projectFileName,
@@ -230,7 +239,7 @@ const runModuleGraph = (parsed, plugins) => {
230
239
  const graph = readModuleGraph(parsed.input, parsed.stage, parsed.entry);
231
240
  const result = compile({
232
241
  rootFileNames: [graph.entry],
233
- projectFileName: parsed.projectFileName ?? findProjectFile(dirname(graph.entry)),
242
+ projectFileName: parsed.noProject ? null : (parsed.projectFileName ?? findProjectFile(dirname(graph.entry))),
234
243
  javaScriptSources: true,
235
244
  dynamicFallback: parsed.dynamicFallback,
236
245
  plugins,
@@ -19,8 +19,19 @@ const preservesReadValue = (capability) => {
19
19
  return true;
20
20
  case 'atom':
21
21
  case 'static':
22
- if (capability.materializer.dictionaryRead !== undefined)
23
- return preservesReadValue(capability.materializer.dictionaryRead.conversion.capability);
22
+ if (capability.materializer.dictionaryRead !== undefined) {
23
+ const read = capability.materializer.dictionaryRead;
24
+ // An exact payload or class read (`checkedPayloadEntry`,
25
+ // `checkedClassEntry`) hands back the entry's own object or throws;
26
+ // it never runs the ordinary conversion, which for a Promise adopts a
27
+ // foreign thenable into a fresh promise.
28
+ if (read.kind === 'dynamic-payload' || read.kind === 'dynamic-class' || read.kind === 'dynamic-absence')
29
+ return true;
30
+ // A present entry is read by `present`, not by the ordinary pair.
31
+ if (read.kind === 'dynamic-optional')
32
+ return preservesReadValue(read.present.capability);
33
+ return preservesReadValue(read.conversion.capability);
34
+ }
24
35
  if (capability.materializer.documentRecordView !== undefined)
25
36
  return capability.materializer.nativeFieldViewProtocol === 'live';
26
37
  if (capability.materializer.nativeArrayView !== undefined)
@@ -81,7 +81,6 @@ export declare const dynamicRecordLoadNeedsPlan: (value: Representation, layouts
81
81
  export declare const nativeDocumentEntryValueIsNative: (value: Representation) => boolean;
82
82
  /** A fixed native field view delegates future reads and writes to the original declared-any entries. */
83
83
  export declare const documentRecordViewPlanOf: (source: Representation, target: Representation, layouts: RecordLayoutPolicy, accepted: AcceptedConversion, readAccepted: AcceptedConversion, resolve?: ConversionNodeResolver, store?: NativeEntryStoreOptions) => DocumentRecordViewPlan | null;
84
- /** Wrappers retain every live source arm and cite their own exact absence conversions. */
85
84
  export declare const composedDocumentRecordViewPlanOf: (source: Representation, target: Representation, layouts: RecordLayoutPolicy, accepted: AcceptedConversion, readAccepted: AcceptedConversion, resolve?: ConversionNodeResolver, store?: NativeEntryStoreOptions) => ComposedDocumentRecordViewPlan | null;
86
85
  /** Every normal object path of this exact converter installs Document entry callbacks.
87
86
  * An ordinary native arm cannot acquire that protocol from a sibling view.
@@ -148,13 +148,33 @@ export const documentRecordViewPlanOf = (source, target, layouts, accepted, read
148
148
  };
149
149
  };
150
150
  /** Wrappers retain every live source arm and cite their own exact absence conversions. */
151
+ /**
152
+ * The zero-field record the bare `object` keyword lowers to
153
+ * (`structural.ts`): it has no layout to read a field from, and every own
154
+ * property lives in its dynamic sidecar, so it is viewed as the open Document
155
+ * it is before a typed record reads it -- `throw new
156
+ * MongoWriteConcernError(writeConcernError as any)` hands an `object | null`
157
+ * local to a typed result interface.
158
+ */
159
+ const documentTakesTableArm = (from, arm, accepted, resolve) => {
160
+ if (arm.kind !== 'dictionary' || arm.key !== from.key || arm.value.kind === 'undefined')
161
+ return false;
162
+ const conversion = accepted(from, arm);
163
+ return conversion !== null && recipeIsMaterializableWithoutPriorSourceGuard(conversion, resolve);
164
+ };
165
+ const fieldlessObject = (value) => value.kind === 'record' && value.fields.length === 0 && value.accessors.length === 0 && value.ownership === 'shared-refcount';
166
+ const containsFieldlessObject = (value) => fieldlessObject(value) ||
167
+ (value.kind === 'optional' && containsFieldlessObject(value.payload)) ||
168
+ (value.kind === 'tagged-union' && value.arms.some((arm) => containsFieldlessObject(arm.value)));
151
169
  export const composedDocumentRecordViewPlanOf = (source, target, layouts, accepted, readAccepted, resolve, store) => {
152
- if (!containsOpenDocument(source) && (source.kind !== 'dynamic' || source.reason === 'untyped-callable'))
170
+ if (!containsOpenDocument(source) &&
171
+ (source.kind !== 'dynamic' || source.reason === 'untyped-callable') &&
172
+ !containsFieldlessObject(source))
153
173
  return null;
154
174
  const fields = [];
155
175
  const dependencies = new Map();
156
176
  const build = (from, into) => {
157
- if (from.kind === 'dynamic') {
177
+ if (from.kind === 'dynamic' || (fieldlessObject(from) && into.kind !== 'optional' && !fieldlessObject(into))) {
158
178
  if (into.kind === 'optional') {
159
179
  const present = build(from, into.payload);
160
180
  const absent = accepted({ kind: into.absence }, into);
@@ -169,7 +189,7 @@ export const composedDocumentRecordViewPlanOf = (source, target, layouts, accept
169
189
  kind: 'dictionary',
170
190
  key: 'string',
171
191
  ownership: 'shared-refcount',
172
- value: from
192
+ value: from.kind === 'dynamic' ? from : { kind: 'dynamic', reason: 'declared-any-never-narrowed' }
173
193
  };
174
194
  const conversion = accepted(from, document);
175
195
  if (!conversion || !recipeIsMaterializableWithoutPriorSourceGuard(conversion, resolve))
@@ -197,6 +217,13 @@ export const composedDocumentRecordViewPlanOf = (source, target, layouts, accept
197
217
  return payload === null ? null : { kind: 'wrap', target: into, payload };
198
218
  }
199
219
  if (into.kind === 'tagged-union' && containsOpenDocument(from)) {
220
+ // A Document is a string-keyed table, and a union arm that is one takes
221
+ // it as a table: the record arms are fixed-key readings of the same
222
+ // object the program never asked for. `formatSort(doc)` over `Sort`
223
+ // otherwise viewed the Document as the `[string, SortDirection]` tuple
224
+ // arm, whose `t[1]` then had no receipt.
225
+ if (from.kind === 'dictionary' && into.arms.some((arm) => documentTakesTableArm(from, arm.value, accepted, resolve)))
226
+ return null;
200
227
  const candidates = into.arms.flatMap((arm, index) => {
201
228
  const view = documentRecordViewPlanOf(from, arm.value, layouts, accepted, readAccepted, resolve, store);
202
229
  return view === null ? [] : [{ index, view }];
@@ -1,5 +1,6 @@
1
1
  import type { Representation } from '../representation/model.js';
2
2
  export declare const IMPOSSIBLE_FIELD_READ = "native:impossible-field-read";
3
+ export declare const ABSENT_ONLY_FIELD_READ = "native:absent-only-field-read";
3
4
  /**
4
5
  * A declared native slot cannot contain a value of this narrowed carrier.
5
6
  * This is a property-read context, never permission to convert the pair at
@@ -7,3 +8,11 @@ export declare const IMPOSSIBLE_FIELD_READ = "native:impossible-field-read";
7
8
  * than reading the slot through an incompatible layout.
8
9
  */
9
10
  export declare const impossibleFieldReadOf: (source: Representation, target: Representation) => boolean;
11
+ /**
12
+ * One route of a live view's field read whose present payload can never be
13
+ * the target's (a TLS `session` held as bytes, read through a view as a
14
+ * client session object). Its only legal outcome is the shared absence; a
15
+ * present value takes the impossible read's checked failure. Anything that
16
+ * could convert keeps its ordinary conversion -- this answers only `never`.
17
+ */
18
+ export declare const absentOnlyFieldReadOf: (source: Representation, target: Representation) => boolean;
@@ -1,4 +1,5 @@
1
1
  export const IMPOSSIBLE_FIELD_READ = 'native:impossible-field-read';
2
+ export const ABSENT_ONLY_FIELD_READ = 'native:absent-only-field-read';
2
3
  const objectKinds = new Set([
3
4
  'record',
4
5
  'record-with-index',
@@ -14,6 +15,7 @@ const objectKinds = new Set([
14
15
  'data-view',
15
16
  'proxy-object'
16
17
  ]);
18
+ const bufferKinds = new Set(['typed-array', 'array-buffer', 'shared-array-buffer', 'data-view']);
17
19
  /**
18
20
  * A declared native slot cannot contain a value of this narrowed carrier.
19
21
  * This is a property-read context, never permission to convert the pair at
@@ -23,6 +25,30 @@ const objectKinds = new Set([
23
25
  export const impossibleFieldReadOf = (source, target) => {
24
26
  if ((source.kind === 'string' || source.kind === 'scalar') && objectKinds.has(target.kind))
25
27
  return true;
28
+ // A byte container is an integer-indexed exotic object, never an Array
29
+ // exotic one: a slot holding one cannot hold the Array a narrowed read
30
+ // names (a `{ value: chunk }` iterator result reached through a dead
31
+ // union arm of a Map entry step, whose own checked view would throw too).
32
+ if (bufferKinds.has(source.kind) && target.kind === 'array-object')
33
+ return true;
26
34
  const record = source.kind === 'record' || source.kind === 'record-with-index' || (source.kind === 'native-record-ref' && source.native === null);
27
35
  return record && (target.kind === 'typed-array' || target.kind === 'array-buffer' || target.kind === 'data-view');
28
36
  };
37
+ /**
38
+ * No value of a byte container's carrier is an instance of a compiled class
39
+ * whose instance is no native object: the class's struct derives from no
40
+ * buffer, so no common subtype exists (a class extending a collection, error
41
+ * or promise names that base in `nativeBase` and stays out).
42
+ */
43
+ const disjointPayloadOf = (source, target) => impossibleFieldReadOf(source, target) || (bufferKinds.has(source.kind) && target.kind === 'class-ref' && target.nativeBase === undefined);
44
+ /**
45
+ * One route of a live view's field read whose present payload can never be
46
+ * the target's (a TLS `session` held as bytes, read through a view as a
47
+ * client session object). Its only legal outcome is the shared absence; a
48
+ * present value takes the impossible read's checked failure. Anything that
49
+ * could convert keeps its ordinary conversion -- this answers only `never`.
50
+ */
51
+ export const absentOnlyFieldReadOf = (source, target) => source.kind === 'optional' &&
52
+ target.kind === 'optional' &&
53
+ source.absence === target.absence &&
54
+ disjointPayloadOf(source.payload, target.payload);
@@ -175,6 +175,16 @@ export interface ConversionCensus {
175
175
  * other pair.
176
176
  */
177
177
  readonly nullishOptionalFor: (source: Representation, target: Representation) => ConversionNode | null;
178
+ /**
179
+ * An optional value read where the checker has already proved it present,
180
+ * into a carrier with no absent state: `options[name]` after
181
+ * `options[name] != null`, a narrowing TypeScript keeps on the keyed read
182
+ * itself. The present payload takes its own conversion; an absent one is a
183
+ * `TypeError`, since the program's type says it cannot be there. `null` when
184
+ * the target can hold the absence (then the ordinary conversion answers) or
185
+ * the payload has no materializable route.
186
+ */
187
+ readonly presentPayloadFor: (source: Representation, target: Representation) => ConversionNode | null;
178
188
  /** The node a `convert` instruction names, from whichever table minted it; `null` for an id no census minted. */
179
189
  readonly nodeById: (id: ConversionNodeId) => ConversionNode | null;
180
190
  /** Every node minted through `nodeFor` that the eager graph did not already hold. */
@@ -193,6 +203,8 @@ export declare const FAMILY_MEMBER_VIEW_MATERIALIZER = "view:family-member-recor
193
203
  export declare const IMPOSSIBLE_INDEX_READ = "native:impossible-index-read";
194
204
  /** The materializer id every nullish-optional node carries; the printer dispatches its recipe on it. */
195
205
  export declare const NULLISH_OPTIONAL_MATERIALIZER = "view:nullish-optional";
206
+ /** The materializer id every present-payload node carries; the printer dispatches its recipe on it. */
207
+ export declare const PRESENT_PAYLOAD_MATERIALIZER = "view:present-payload";
196
208
  /** The materializer id every asserted-class-downcast node carries; the printer dispatches its recipe on it. */
197
209
  export declare const ASSERTED_CLASS_DOWNCAST_MATERIALIZER = "gea::host::assertedDowncastClassRef";
198
210
  /** The materializer id every caught-handoff node carries; the printer dispatches its recipe on it. */
@@ -3,7 +3,7 @@ import { transfersNativeStorage, validateCapability } from './algebra.js';
3
3
  import { recipeClosureOf, recipeIsMaterializableWithoutPriorSourceGuard } from './recipe-closure.js';
4
4
  import { createConversionDerivationContext, deriveConversionCapability } from './derive.js';
5
5
  import { narrowingCapabilityFor } from './build.js';
6
- import { impossibleFieldReadOf, IMPOSSIBLE_FIELD_READ } from './impossible-field-read.js';
6
+ import { absentOnlyFieldReadOf, impossibleFieldReadOf, ABSENT_ONLY_FIELD_READ, IMPOSSIBLE_FIELD_READ } from './impossible-field-read.js';
7
7
  import { nativeUnboundMethodContractOf, NATIVE_UNBOUND_METHOD_MATERIALIZER } from './native-method.js';
8
8
  import { nativeBufferUnboundMethodContractOf } from './native-buffer-method.js';
9
9
  import { siblingClassArgumentOf, SIBLING_CLASS_ARGUMENT } from './sibling-class.js';
@@ -189,10 +189,39 @@ export const createConversionNodes = (input) => {
189
189
  return { kind: 'static', materializer: structural };
190
190
  if (recipe)
191
191
  return { kind: 'static', materializer: recipe };
192
+ // The optional's payload has its own route, but no recipe takes both steps
193
+ // at once: a `let` read before any write carries its absence on every read
194
+ // (`unassigned-binding-cells.ts`), so `if (result) add(result)` hands
195
+ // `T | undefined` to a `Document` parameter. That is the same checked
196
+ // unwrap an `optional(T) -> T` load is, followed by the payload's own
197
+ // conversion; the absent case is the load's `TypeError`.
198
+ const present = checkedPresentPayloadOf(source, target);
199
+ if (present)
200
+ return present;
192
201
  const foreign = foreignReceiverOf(source, target);
193
202
  const missing = `no runtime conversion is installed from ${sourceKey} to ${targetKey}`;
194
203
  return { kind: 'never', reason: foreign === null ? missing : `${missing}: ${foreign}` };
195
204
  };
205
+ const checkedPresentPayloadOf = (source, target) => {
206
+ if (source.kind !== 'optional' || target.kind === 'optional' || target.kind === 'dynamic')
207
+ return null;
208
+ if (target.kind === 'tagged-union' && target.arms.some((arm) => arm.value.kind === source.absence))
209
+ return null;
210
+ const payload = nodeFor(source.payload, target);
211
+ if (!recipeIsMaterializableWithoutPriorSourceGuard(payload, nodeById))
212
+ return null;
213
+ return {
214
+ kind: 'static',
215
+ materializer: {
216
+ id: PRESENT_PAYLOAD_MATERIALIZER,
217
+ domain: 'static:present-payload',
218
+ allocates: 'materializer' in payload.capability && payload.capability.materializer.allocates,
219
+ requiresSourceGuard: true,
220
+ executesSourceGuard: true,
221
+ dependencies: [payload]
222
+ }
223
+ };
224
+ };
196
225
  const nodeFor = (source, target) => {
197
226
  const sourceKey = representationKey(source);
198
227
  const targetKey = representationKey(target);
@@ -502,6 +531,38 @@ export const createConversionNodes = (input) => {
502
531
  // certifying a read whose every present value is a run-time TypeError.
503
532
  return null;
504
533
  }
534
+ // A union read out of an entry selects its arm by the wrapper's own
535
+ // classifiers, and then reads that arm exactly as a field of that carrier
536
+ // alone is read out of a Document: by the entry's own object, checked
537
+ // (`gea::dictionary::checkedPayloadEntry`), never a rebuilt one. The
538
+ // ordinary wrapper's Promise arm adopts a foreign thenable into a fresh
539
+ // promise -- right for an `any` value, but a Document view's read must
540
+ // hand back the entry it holds (a family layout's `metadata?: Document |
541
+ // Promise<ClientMetadata>` read through a `Db`'s filtered options).
542
+ if (source.kind === 'dynamic' &&
543
+ target.kind === 'tagged-union' &&
544
+ ordinary.capability.kind === 'static' &&
545
+ ordinary.capability.materializer.dynamicWrapper?.kind === 'union') {
546
+ const plan = ordinary.capability.materializer.dynamicWrapper;
547
+ let changed = false;
548
+ const arms = plan.arms.map((arm) => {
549
+ const value = plan.target.arms[arm.index]?.value;
550
+ const read = value === undefined ? null : dictionaryReadFor(source, value);
551
+ if (read === null ||
552
+ read === arm.conversion ||
553
+ !('materializer' in read.capability) ||
554
+ !read.capability.materializer.dictionaryRead)
555
+ return arm;
556
+ changed = true;
557
+ return { ...arm, conversion: read };
558
+ });
559
+ if (changed)
560
+ return contextualNode(source, target, 'dictionary-entry-read', {
561
+ ...ordinary.capability.materializer,
562
+ dynamicWrapper: { ...plan, arms },
563
+ dependencies: arms.map((arm) => arm.conversion)
564
+ });
565
+ }
505
566
  if (source.kind === 'dynamic' && target.kind === 'optional') {
506
567
  const present = dictionaryReadFor(source, target.payload);
507
568
  const absent = nodeFor({ kind: target.absence }, target);
@@ -526,7 +587,16 @@ export const createConversionNodes = (input) => {
526
587
  if (method)
527
588
  return method;
528
589
  const ordinary = nodeFor(source, target);
529
- if (ordinary.capability.kind !== 'never' || !impossibleFieldReadOf(source, target))
590
+ if (ordinary.capability.kind !== 'never')
591
+ return ordinary;
592
+ if (absentOnlyFieldReadOf(source, target))
593
+ return contextualNode(source, target, 'absent-only-field-read', {
594
+ id: ABSENT_ONLY_FIELD_READ,
595
+ domain: 'static:absent-only-field-read',
596
+ allocates: false,
597
+ nativeFieldProtocol: 'unused'
598
+ });
599
+ if (!impossibleFieldReadOf(source, target))
530
600
  return ordinary;
531
601
  return contextualNode(source, target, 'field-read', {
532
602
  id: IMPOSSIBLE_FIELD_READ,
@@ -983,6 +1053,36 @@ export const createConversionNodes = (input) => {
983
1053
  nullishOptionals.set(id, node);
984
1054
  return node;
985
1055
  };
1056
+ const presentPayloads = new Map();
1057
+ const presentPayloadFor = (source, target) => {
1058
+ if (source.kind !== 'optional' || target.kind === 'optional' || target.kind === 'dynamic')
1059
+ return null;
1060
+ if (target.kind === 'tagged-union' && target.arms.some((arm) => arm.value.kind === source.absence))
1061
+ return null;
1062
+ const id = `${representationKey(source)}->${representationKey(target)}#present-payload`;
1063
+ const remembered = presentPayloads.get(id);
1064
+ if (remembered !== undefined)
1065
+ return remembered;
1066
+ const payload = nodeFor(source.payload, target);
1067
+ if (!recipeIsMaterializableWithoutPriorSourceGuard(payload, nodeById))
1068
+ return null;
1069
+ const node = {
1070
+ id,
1071
+ source,
1072
+ target,
1073
+ capability: {
1074
+ kind: 'static',
1075
+ materializer: {
1076
+ id: PRESENT_PAYLOAD_MATERIALIZER,
1077
+ domain: 'static:present-payload',
1078
+ allocates: 'materializer' in payload.capability && payload.capability.materializer.allocates,
1079
+ dependencies: [payload]
1080
+ }
1081
+ }
1082
+ };
1083
+ presentPayloads.set(id, node);
1084
+ return node;
1085
+ };
986
1086
  const nodeById = (id) => minted.get(id) ??
987
1087
  provisional.get(id)?.node ??
988
1088
  contextual.get(id) ??
@@ -997,6 +1097,7 @@ export const createConversionNodes = (input) => {
997
1097
  caughtHandoffs.get(id) ??
998
1098
  assertedClassDowncasts.get(id) ??
999
1099
  nullishOptionals.get(id) ??
1100
+ presentPayloads.get(id) ??
1000
1101
  null;
1001
1102
  return {
1002
1103
  nativeObjectSampleFor,
@@ -1021,6 +1122,7 @@ export const createConversionNodes = (input) => {
1021
1122
  caughtHandoffFor,
1022
1123
  assertedClassDowncastFor,
1023
1124
  nullishOptionalFor,
1125
+ presentPayloadFor,
1024
1126
  nodeById,
1025
1127
  minted
1026
1128
  };
@@ -1030,6 +1132,8 @@ export const FAMILY_MEMBER_VIEW_MATERIALIZER = 'view:family-member-record';
1030
1132
  export const IMPOSSIBLE_INDEX_READ = 'native:impossible-index-read';
1031
1133
  /** The materializer id every nullish-optional node carries; the printer dispatches its recipe on it. */
1032
1134
  export const NULLISH_OPTIONAL_MATERIALIZER = 'view:nullish-optional';
1135
+ /** The materializer id every present-payload node carries; the printer dispatches its recipe on it. */
1136
+ export const PRESENT_PAYLOAD_MATERIALIZER = 'view:present-payload';
1033
1137
  /** The materializer id every asserted-class-downcast node carries; the printer dispatches its recipe on it. */
1034
1138
  export const ASSERTED_CLASS_DOWNCAST_MATERIALIZER = 'gea::host::assertedDowncastClassRef';
1035
1139
  /** The materializer id every caught-handoff node carries; the printer dispatches its recipe on it. */
@@ -386,6 +386,25 @@ const widensFieldIntoDynamic = (layouts, source, arm) => {
386
386
  return field !== undefined && isDynamic(field.value) && !isDynamic(held.value);
387
387
  });
388
388
  };
389
+ /**
390
+ * A table whose every entry is `undefined` (`Record<string, never>`, the
391
+ * "fetch these credentials for me" marker) is no home for a record holding a
392
+ * required present field: reaching it reads that field as `undefined`, the
393
+ * chain's discard. `{ ...providers, azure }` storing an `AccessToken` into
394
+ * `{ accessToken: string } | Record<string, never> | ...` tied the empty
395
+ * table with the token's real arm and refused the pair.
396
+ */
397
+ const emptyTableArmCannotHold = (layouts, source, arm) => {
398
+ if (arm.kind !== 'dictionary' || arm.value.kind !== 'undefined')
399
+ return false;
400
+ const sourceFields = source.kind === 'record' || source.kind === 'record-with-index'
401
+ ? source.fields
402
+ : source.kind === 'native-record-ref'
403
+ ? layouts.forShape(source.shapeId)
404
+ : null;
405
+ const absent = (value) => value.kind === 'undefined' || value.kind === 'void' || (value.kind === 'optional' && value.absence === 'undefined');
406
+ return sourceFields !== null && sourceFields.some((field) => field.required && !absent(field.value));
407
+ };
389
408
  export const structuralRecordViewPlan = (layouts, source, target, convertible, members) => {
390
409
  if (standInRefuses(source, target))
391
410
  return null;
@@ -414,6 +433,8 @@ export const structuralRecordViewPlan = (layouts, source, target, convertible, m
414
433
  // `callback(error)` into `(err?: Error | null)` passed `undefined`.
415
434
  if (arm.value.kind === 'undefined' || arm.value.kind === 'null' || arm.value.kind === 'void')
416
435
  continue;
436
+ if (emptyTableArmCannotHold(layouts, source, arm.value))
437
+ continue;
417
438
  if (convertible(source, arm.value, 'sum-home')) {
418
439
  homes.push({ index, payload: null });
419
440
  continue;
@@ -5,7 +5,7 @@ import type { ConstantLiteral } from '../semantics/model/operands.js';
5
5
  import type { SemanticTargetProof } from '../semantics/model/operations.js';
6
6
  import type { HostMethodBinding } from '../semantics/host-methods.js';
7
7
  import type { UnboxedMethodAssumption } from '../projection/method-value-escapes.js';
8
- import type { TypedComputedReadRecipe, TypedComputedWriteRecipe } from './typed-property-access.js';
8
+ import type { CorrelatedSourceField, TypedComputedReadRecipe, TypedComputedWriteRecipe } from './typed-property-access.js';
9
9
  import type { CallOperation, ComputeOperation, ConversionUseId, ElementOperation, GetIteratorOperation, IrArrayElement, IrBlockId, IrBody, IrNonTerminatorOperation, IrOperand, IrPhiIncoming, IrPropertyAttributes, IrRecordFieldInit, IrSwitchCase, IrTemplateCookedSegment, IrTryRegion, IrIteratorCloseRegion } from './model.js';
10
10
  import type { ConversionCensus } from '../conversion/nodes.js';
11
11
  export interface IrBodyBuilder {
@@ -29,7 +29,9 @@ export interface IrBodyBuilder {
29
29
  /** See `SetOperation.provenKeyTexts`. */
30
30
  provenKeyTexts?: readonly string[],
31
31
  /** See SetOperation.ordinaryFunctionDataWrite. */
32
- ordinaryFunctionDataWrite?: true, ordinaryObjectDataWriteAbsent?: true) => IrValueId | null;
32
+ ordinaryFunctionDataWrite?: true, ordinaryObjectDataWriteAbsent?: true,
33
+ /** See `SetOperation.correlatedSourceFields`. */
34
+ correlatedSourceFields?: readonly CorrelatedSourceField[]) => IrValueId | null;
33
35
  readonly delete: (block: IrBlockId, lineage: SemanticResultId, receiver: IrOperand, key: IrOperand, strict: boolean, representation: Representation | null) => IrValueId | null;
34
36
  readonly hasProperty: (block: IrBlockId, lineage: SemanticResultId, receiver: IrOperand, key: IrOperand, representation: Representation, ordinaryObjectPrototypeKeyAbsent?: true) => IrValueId;
35
37
  readonly ownPropertyKeys: (block: IrBlockId, lineage: SemanticResultId, receiver: IrOperand, representation: Representation) => IrValueId;
@@ -48,6 +50,7 @@ export interface IrBodyBuilder {
48
50
  } | {
49
51
  readonly absentPackage: string;
50
52
  }, builtinModule: string | null, representation: Representation) => IrValueId;
53
+ readonly moduleNamespace: (block: IrBlockId, lineage: SemanticResultId, target: RegionId, fresh: IrOperand) => IrValueId;
51
54
  readonly commonJsBinding: (block: IrBlockId, lineage: SemanticResultId, global: 'require' | 'exports' | 'module', owner: RegionId, representation: Representation) => IrValueId;
52
55
  readonly commonJsBindingSet: (block: IrBlockId, lineage: SemanticResultId, global: 'require' | 'exports' | 'module', owner: RegionId, value: IrOperand) => void;
53
56
  readonly superInitialize: (block: IrBlockId, lineage: SemanticResultId, args: readonly IrOperand[]) => void;
package/dist/ir/build.js CHANGED
@@ -137,7 +137,7 @@ export const createIrBodyBuilder = (owner, sourceOwner, abi, constructAbi = null
137
137
  });
138
138
  return result.id;
139
139
  };
140
- const set = (block, lineage, receiver, key, value, strict, representation, typedComputedWrite, provenKeyTexts, ordinaryFunctionDataWrite, ordinaryObjectDataWriteAbsent) => {
140
+ const set = (block, lineage, receiver, key, value, strict, representation, typedComputedWrite, provenKeyTexts, ordinaryFunctionDataWrite, ordinaryObjectDataWriteAbsent, correlatedSourceFields) => {
141
141
  const result = mintOptionalResult(representation);
142
142
  append(block, {
143
143
  kind: 'set',
@@ -152,7 +152,8 @@ export const createIrBodyBuilder = (owner, sourceOwner, abi, constructAbi = null
152
152
  ...(ordinaryFunctionDataWrite === undefined ? {} : { ordinaryFunctionDataWrite }),
153
153
  ...(ordinaryObjectDataWriteAbsent === undefined || !mayCarryOrdinaryObject(receiver.representation)
154
154
  ? {}
155
- : { ordinaryObjectDataWriteAbsent })
155
+ : { ordinaryObjectDataWriteAbsent }),
156
+ ...(correlatedSourceFields === undefined ? {} : { correlatedSourceFields })
156
157
  });
157
158
  return result?.id ?? null;
158
159
  };
@@ -233,6 +234,11 @@ export const createIrBodyBuilder = (owner, sourceOwner, abi, constructAbi = null
233
234
  });
234
235
  return result?.id ?? null;
235
236
  };
237
+ const moduleNamespace = (block, lineage, target, fresh) => {
238
+ const result = mintResult(fresh.representation);
239
+ append(block, { kind: 'module-namespace', lineage, target, fresh, result });
240
+ return result.id;
241
+ };
236
242
  const commonJsRequire = (block, lineage, owner, target, builtinModule, representation) => {
237
243
  const result = mintResult(representation);
238
244
  append(block, {
@@ -570,6 +576,7 @@ export const createIrBodyBuilder = (owner, sourceOwner, abi, constructAbi = null
570
576
  spreadCopy,
571
577
  call,
572
578
  commonJsRequire,
579
+ moduleNamespace,
573
580
  commonJsBinding,
574
581
  commonJsBindingSet,
575
582
  superInitialize,