@geastack/compiler 1.0.48 → 1.0.62

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/README.md +57 -19
  2. package/dist/cli.js +2 -1
  3. package/dist/compiler.d.ts +1 -1
  4. package/dist/compiler.js +13 -6
  5. package/dist/conversion/derive.js +5 -0
  6. package/dist/conversion/native-field-view.d.ts +7 -0
  7. package/dist/conversion/native-field-view.js +50 -0
  8. package/dist/conversion/native-record-products.js +1 -0
  9. package/dist/conversion/native-view-origins.d.ts +1 -1
  10. package/dist/conversion/native-view-origins.js +5 -4
  11. package/dist/conversion/nodes.d.ts +9 -0
  12. package/dist/conversion/nodes.js +18 -0
  13. package/dist/conversion/record-view.d.ts +25 -1
  14. package/dist/conversion/record-view.js +61 -2
  15. package/dist/conversion/structural-plan.js +7 -6
  16. package/dist/ir/borrowed-field-reads.d.ts +30 -0
  17. package/dist/ir/borrowed-field-reads.js +218 -0
  18. package/dist/ir/borrowed-window-cells.d.ts +35 -0
  19. package/dist/ir/borrowed-window-cells.js +117 -0
  20. package/dist/ir/call-dispatch.js +21 -4
  21. package/dist/ir/callable-class-flow.js +269 -43
  22. package/dist/ir/captures.js +18 -1
  23. package/dist/ir/certify.js +14 -1
  24. package/dist/ir/construction-only-fields.d.ts +15 -1
  25. package/dist/ir/construction-only-fields.js +71 -3
  26. package/dist/ir/dead-logical-merge.d.ts +4 -0
  27. package/dist/ir/dead-logical-merge.js +89 -18
  28. package/dist/ir/dense-loops.d.ts +38 -4
  29. package/dist/ir/dense-loops.js +112 -17
  30. package/dist/ir/dense-read-windows.d.ts +42 -0
  31. package/dist/ir/dense-read-windows.js +137 -0
  32. package/dist/ir/facts.d.ts +12 -0
  33. package/dist/ir/facts.js +18 -2
  34. package/dist/ir/field-read-reuse.d.ts +71 -0
  35. package/dist/ir/field-read-reuse.js +430 -0
  36. package/dist/ir/hoist.d.ts +19 -2
  37. package/dist/ir/hoist.js +143 -24
  38. package/dist/ir/lower-narrow.js +19 -1
  39. package/dist/ir/model.d.ts +19 -0
  40. package/dist/ir/native-field-view-domains.d.ts +12 -2
  41. package/dist/ir/native-field-view-domains.js +51 -15
  42. package/dist/ir/native-field-view-facts.js +5 -2
  43. package/dist/ir/native-method-frames.js +15 -2
  44. package/dist/ir/plain-field-read.d.ts +31 -0
  45. package/dist/ir/plain-field-read.js +51 -0
  46. package/dist/ir/program-facts.d.ts +14 -0
  47. package/dist/ir/program-facts.js +85 -2
  48. package/dist/ir/proven-branches.js +8 -1
  49. package/dist/ir/publish-conversion-recipes.js +5 -1
  50. package/dist/ir/short-circuit-threading.d.ts +12 -4
  51. package/dist/ir/short-circuit-threading.js +124 -12
  52. package/dist/ir/stable-cell-reads.d.ts +24 -1
  53. package/dist/ir/stable-cell-reads.js +65 -42
  54. package/dist/ir/write-effects.d.ts +42 -0
  55. package/dist/ir/write-effects.js +208 -0
  56. package/dist/plugins/gea/contract.d.ts +3 -2
  57. package/dist/plugins/gea/contract.js +3 -1
  58. package/dist/plugins/gea/host.d.ts +7 -2
  59. package/dist/plugins/gea/host.js +25 -5
  60. package/dist/project-preparation.d.ts +11 -0
  61. package/dist/project-preparation.js +44 -0
  62. package/dist/projection/classes.d.ts +8 -0
  63. package/dist/projection/classes.js +112 -12
  64. package/dist/projection/dispatch.d.ts +24 -4
  65. package/dist/projection/dispatch.js +71 -2
  66. package/dist/projection/fields.js +2 -2
  67. package/dist/representation/model.d.ts +3 -0
  68. package/dist/representation/model.js +3 -0
  69. package/dist/representation/value-records.js +22 -0
  70. package/dist/semantics/frontend-timing.d.ts +9 -0
  71. package/dist/semantics/frontend-timing.js +43 -2
  72. package/dist/semantics/frontend.js +103 -7
  73. package/dist/semantics/model/operations.d.ts +7 -0
  74. package/dist/semantics/normalize/binding-fixpoint.js +7 -2
  75. package/dist/semantics/normalize/callable-data-write.js +6 -2
  76. package/dist/semantics/normalize/field-bindings.js +151 -111
  77. package/dist/semantics/normalize/flow/callable-reach.js +27 -0
  78. package/dist/semantics/normalize/flow/component-solver.js +23 -5
  79. package/dist/semantics/normalize/flow/source-record-data.js +6 -2
  80. package/dist/semantics/normalize/flow/source-value-session.d.ts +13 -0
  81. package/dist/semantics/normalize/flow/source-value-session.js +207 -65
  82. package/dist/semantics/normalize/global-host-mutations.js +162 -1
  83. package/dist/semantics/normalize/parameter-bindings.js +16 -1
  84. package/dist/semantics/normalize/producers/class-lifecycle.js +2 -1
  85. package/dist/semantics/normalize/producers/erasure.js +13 -8
  86. package/dist/semantics/subclass-member-overlay-transform.d.ts +3 -2
  87. package/dist/semantics/subclass-member-overlay-transform.js +416 -316
  88. package/dist/semantics/typescript-tsgo.d.ts +20 -0
  89. package/dist/semantics/typescript-tsgo.js +832 -0
  90. package/dist/semantics/typescript.d.ts +0 -9
  91. package/dist/semantics/typescript.js +4 -1
  92. package/dist/targets/cpp/borrowed-call-entry.d.ts +9 -0
  93. package/dist/targets/cpp/borrowed-call-entry.js +12 -2
  94. package/dist/targets/cpp/captures.js +4 -0
  95. package/dist/targets/cpp/class-properties/computed-method-value.d.ts +1 -1
  96. package/dist/targets/cpp/class-properties/computed-method-value.js +17 -7
  97. package/dist/targets/cpp/class-properties/emit-class-properties.d.ts +8 -0
  98. package/dist/targets/cpp/class-properties/emit-class-properties.js +62 -2
  99. package/dist/targets/cpp/class-properties/native-method-read.js +12 -1
  100. package/dist/targets/cpp/conversions.js +1 -0
  101. package/dist/targets/cpp/emit-arrays.d.ts +5 -0
  102. package/dist/targets/cpp/emit-arrays.js +60 -10
  103. package/dist/targets/cpp/emit-binding-reference.d.ts +19 -6
  104. package/dist/targets/cpp/emit-binding-reference.js +26 -8
  105. package/dist/targets/cpp/emit-bindings.js +22 -0
  106. package/dist/targets/cpp/emit-callable.js +133 -16
  107. package/dist/targets/cpp/emit-carrier-members.d.ts +6 -0
  108. package/dist/targets/cpp/emit-carrier-members.js +24 -2
  109. package/dist/targets/cpp/emit-context.d.ts +97 -1
  110. package/dist/targets/cpp/emit-context.js +52 -0
  111. package/dist/targets/cpp/emit-equality.js +3 -0
  112. package/dist/targets/cpp/emit-narrowing.js +9 -0
  113. package/dist/targets/cpp/emit-native-field-view.d.ts +24 -0
  114. package/dist/targets/cpp/emit-native-field-view.js +87 -8
  115. package/dist/targets/cpp/emit-properties.js +139 -16
  116. package/dist/targets/cpp/emit-record-view.js +49 -22
  117. package/dist/targets/cpp/emit-return.js +5 -1
  118. package/dist/targets/cpp/emit-tonumber.js +4 -1
  119. package/dist/targets/cpp/emit-union-properties.js +1 -1
  120. package/dist/targets/cpp/emit.d.ts +4 -1
  121. package/dist/targets/cpp/emit.js +148 -6
  122. package/dist/targets/cpp/reactive-dependencies.js +100 -28
  123. package/dist/targets/cpp/translation-unit.js +71 -17
  124. package/dist/targets/cpp/virtual-methods.d.ts +2 -2
  125. package/dist/targets/cpp/virtual-methods.js +11 -3
  126. package/package.json +1 -1
  127. package/src/targets/cpp/runtime/gea_runtime.h +400 -21
@@ -4,6 +4,17 @@ import { classMemberOf } from './fields.js';
4
4
  * Selection happens when the property is read, before a later call supplies
5
5
  * its receiver. A virtual call adapter would select at the wrong time.
6
6
  */
7
+ /** What a run-time lookup finds: an `abstract` declaration installs nothing, so it continues to the base. */
8
+ const runtimeClassMemberOf = (classes, allocation, key) => {
9
+ const walked = new Set();
10
+ let site = classMemberOf(classes, allocation, key);
11
+ while (site?.kind === 'method' && site.method.abstract === true && !walked.has(site.owner)) {
12
+ walked.add(site.owner);
13
+ const base = classes.get(site.owner)?.base ?? null;
14
+ site = base === null ? null : classMemberOf(classes, base, key);
15
+ }
16
+ return site;
17
+ };
7
18
  export const classPrototypeMethodValueArmsOf = (classes, receiver, key) => {
8
19
  const arms = [];
9
20
  for (const [allocation, layout] of classes) {
@@ -13,7 +24,7 @@ export const classPrototypeMethodValueArmsOf = (classes, receiver, key) => {
13
24
  continue;
14
25
  if (layout.nativeBase !== null)
15
26
  return null;
16
- const site = classMemberOf(classes, allocation, key);
27
+ const site = runtimeClassMemberOf(classes, allocation, key);
17
28
  // Absence belongs to the language's undefined result. An accessor is an
18
29
  // invocation, not a method value, and must keep its separate proof path.
19
30
  if (site === null)
@@ -87,6 +98,24 @@ export const classMethodValueArmsOf = (classes, receiver, key) => {
87
98
  return null;
88
99
  return arms.map((arm) => ({ allocation: arm.allocation, method: arm.method, owner: arm.owner }));
89
100
  };
101
+ /** The method-bearing arms of a family whose every other allocation misses
102
+ * `key` on an abstract declaration (`classAbstractMemberMissesAt`). Those
103
+ * allocations read the empty callable, so only these arms publish a method
104
+ * frame; any other absence keeps the family incomplete (`null`).
105
+ */
106
+ export const classPresentMethodArmsOf = (classes, receiver, key) => {
107
+ const arms = classPrototypeMethodValueArmsOf(classes, receiver, key);
108
+ if (arms === null)
109
+ return null;
110
+ const present = [];
111
+ for (const arm of arms) {
112
+ if (arm.method !== null && arm.owner !== null)
113
+ present.push({ allocation: arm.allocation, method: arm.method, owner: arm.owner });
114
+ else if (!classAbstractMemberMissesAt(classes, arm.allocation, key))
115
+ return null;
116
+ }
117
+ return present.length === 0 ? null : present;
118
+ };
90
119
  /** A declared method frame does not supply an executable body. A bodyless
91
120
  * method read needs the existing complete allocation/prototype selection,
92
121
  * including a callable on every normal allocation. One unused override does
@@ -96,8 +125,25 @@ export const classMethodFamilyHasNativeBody = (classes, receiver, key) => {
96
125
  const site = classMemberOf(classes, receiver, key);
97
126
  if (site?.kind !== 'method' || site.method.callable !== null)
98
127
  return true;
99
- return classMethodValueArmsOf(classes, receiver, key) !== null;
128
+ // An instance of the abstract class itself (constructed by reflection) has
129
+ // no such method: calling it is the TypeError the abstract root's dispatch
130
+ // member raises, exactly as calling `undefined` does.
131
+ const arms = classPrototypeMethodValueArmsOf(classes, receiver, key);
132
+ return arms !== null && arms.every((arm) => arm.method !== null || classAbstractMemberMissesAt(classes, arm.allocation, key));
133
+ };
134
+ /** An allocation whose own class declares `key` abstract and inherits no
135
+ * body for it: its lookup misses, so the read is `undefined` and a call of it
136
+ * is JS's TypeError for calling `undefined` -- not an unproved family.
137
+ */
138
+ export const classAbstractMemberMissesAt = (classes, allocation, key) => {
139
+ const declared = classMemberOf(classes, allocation, key);
140
+ return declared?.kind === 'method' && declared.method.abstract === true && runtimeClassMemberOf(classes, allocation, key) === null;
100
141
  };
142
+ /** Whether some allocation a read of `key` on `receiver` may meet misses it on
143
+ * an abstract declaration (`classAbstractMemberMissesAt`): the read is then
144
+ * `undefined` there, which only a carrier with an empty callable can hold.
145
+ */
146
+ export const classMethodReadMayMissAbstractly = (classes, receiver, key) => classPrototypeMethodValueArmsOf(classes, receiver, key)?.some((arm) => arm.method === null && classAbstractMemberMissesAt(classes, arm.allocation, key)) === true;
101
147
  /**
102
148
  * The class-hierarchy topology behind method dispatch: which key belongs to
103
149
  * which override family, and who redeclares what.
@@ -806,3 +852,26 @@ export const virtualDispatchVerdictOf = (classes, abiOf, capturesNothing, conver
806
852
  }
807
853
  return { families, refused, dispatched };
808
854
  };
855
+ /**
856
+ * Whether an instance carried as `declaration` may hold an own `key` that a
857
+ * write through a dynamic receiver installed over a method
858
+ * (`ClassLayout.dynamicMethodShadows`): on its own chain, or on a subclass it
859
+ * may really be. Such a shadow lives in the instance's native expando table,
860
+ * so a call checks that table before it dispatches.
861
+ */
862
+ export const classDynamicMethodShadowOf = (classes, declaration, key) => {
863
+ const seen = new Set();
864
+ for (let current = declaration; current !== null && !seen.has(current);) {
865
+ seen.add(current);
866
+ const layout = classes.get(current);
867
+ if (!layout)
868
+ break;
869
+ if (layout.dynamicMethodShadows?.includes(key))
870
+ return true;
871
+ current = layout.base;
872
+ }
873
+ for (const [candidate, layout] of classes)
874
+ if (layout.dynamicMethodShadows?.includes(key) && extendsClass(classes, candidate, declaration))
875
+ return true;
876
+ return false;
877
+ };
@@ -1,5 +1,5 @@
1
1
  import { walkRepresentation } from '../representation/model.js';
2
- import { classMethodValueArmsOf, methodCopyHeldBy } from './dispatch.js';
2
+ import { classPresentMethodArmsOf, methodCopyHeldBy } from './dispatch.js';
3
3
  import { abiOfCallee } from './callee.js';
4
4
  import { dynamicFieldAbsencePolicy } from '../representation/field-descriptor-policy.js';
5
5
  /** The record layout a shape derives to, or `null` when it carries none. */
@@ -396,7 +396,7 @@ export const nativeClassMethodValueSourcesOf = (classes, declaration, key, proje
396
396
  : site.method.representation === undefined
397
397
  ? null
398
398
  : abiOfCallee(site.method.representation);
399
- const arms = classMethodValueArmsOf(classes, declaration, key);
399
+ const arms = classPresentMethodArmsOf(classes, declaration, key);
400
400
  if (held === null || arms === null)
401
401
  return null;
402
402
  const sources = [];
@@ -997,6 +997,9 @@ export declare const isBoxed: (representation: Representation) => boolean;
997
997
  * produces.
998
998
  */
999
999
  export declare const carriesNoAbsence: (representation: Representation) => boolean;
1000
+ /** An Object carrier whose one falsy state is that undefined lane -- a shared
1001
+ * record reference, which `carriesNoAbsence` refuses for exactly the lane. */
1002
+ export declare const objectCarrierWithOnlyNativeUndefined: (representation: Representation) => boolean;
1000
1003
  /** Native object references reserve an undefined lane for strict unbound method receivers, separate from null. */
1001
1004
  export declare const carriesNativeUndefined: (representation: Representation) => boolean;
1002
1005
  /**
@@ -478,6 +478,9 @@ const alwaysTruthyKinds = new Set([
478
478
  * produces.
479
479
  */
480
480
  export const carriesNoAbsence = (representation) => alwaysTruthyKinds.has(representation.kind) && !carriesNativeUndefined(representation);
481
+ /** An Object carrier whose one falsy state is that undefined lane -- a shared
482
+ * record reference, which `carriesNoAbsence` refuses for exactly the lane. */
483
+ export const objectCarrierWithOnlyNativeUndefined = (representation) => alwaysTruthyKinds.has(representation.kind) && carriesNativeUndefined(representation);
481
484
  /** Native object references reserve an undefined lane for strict unbound method receivers, separate from null. */
482
485
  export const carriesNativeUndefined = (representation) => ((representation.kind === 'class-ref' || representation.kind === 'record' || representation.kind === 'record-with-index') &&
483
486
  representation.ownership === 'shared-refcount') ||
@@ -349,6 +349,28 @@ export const valueRecordTypesOf = (graph) => {
349
349
  return;
350
350
  if (isDynamic(graph, destination))
351
351
  return exposeToDynamic(source);
352
+ // A getter seen through a by-value copy runs once, when the copy is made,
353
+ // and never again: `boxes.push(lazy)` into a `Box[]` of structs would
354
+ // snapshot `lazy.min` where JavaScript calls the getter at every
355
+ // `boxes[i].min`. A destination reading a key some source answers with an
356
+ // accessor needs the live view only a shared carrier has. This holds
357
+ // whether or not the edge joins the two alias classes: a host's own
358
+ // signature (`Array.prototype.push`) does not, and is the usual way in.
359
+ const accessorKeys = new Set();
360
+ for (const core of held) {
361
+ const shape = graph.structuralTypes.get(core)?.shape;
362
+ if (shape?.kind === 'object')
363
+ for (const member of shape.members)
364
+ if (member.accessor !== null && member.key.kind !== 'symbol')
365
+ accessorKeys.add(`${member.key.kind}:${member.key.value}`);
366
+ }
367
+ if (accessorKeys.size > 0)
368
+ for (const core of objectHoldersOf(graph, destination)) {
369
+ const shape = graph.structuralTypes.get(core)?.shape;
370
+ if (shape?.kind === 'object' &&
371
+ shape.members.some((member) => member.key.kind !== 'symbol' && accessorKeys.has(`${member.key.kind}:${member.key.value}`)))
372
+ disqualified.add(core);
373
+ }
352
374
  // Only the object-shaped cores join: an alias through a shared primitive
353
375
  // id would let any comparison against that primitive disqualify both.
354
376
  if (join)
@@ -1,3 +1,12 @@
1
+ /**
2
+ * `GEA_PROGRESS=1` prints a timestamped line as each phase, census round and
3
+ * round step starts and finishes, the moment it happens. `GEA_STAGE_TIMING`
4
+ * and `GEA_FRONTEND_TIMING` report only once a stage ends, so a compile that
5
+ * stays inside one stage for an hour says nothing about where it is.
6
+ */
7
+ export declare const progress: (label: string) => void;
8
+ /** Runs `action` between a start and a finish progress line carrying its duration. */
9
+ export declare const progressed: <T>(label: string, action: () => T) => T;
1
10
  export declare const createFrontendTiming: (scope: string) => {
2
11
  measure: <T>(name: string, action: () => T) => T;
3
12
  mark: (name: string) => void;
@@ -1,5 +1,32 @@
1
1
  import { writeHeapSnapshot } from 'v8';
2
2
  import { join } from 'path';
3
+ /**
4
+ * `GEA_PROGRESS=1` prints a timestamped line as each phase, census round and
5
+ * round step starts and finishes, the moment it happens. `GEA_STAGE_TIMING`
6
+ * and `GEA_FRONTEND_TIMING` report only once a stage ends, so a compile that
7
+ * stays inside one stage for an hour says nothing about where it is.
8
+ */
9
+ export const progress = (label) => {
10
+ if (process.env['GEA_PROGRESS'] !== '1')
11
+ return;
12
+ const heap = (process.memoryUsage().heapUsed / 1073741824).toFixed(2);
13
+ process.stderr.write(`[PROGRESS +${process.uptime().toFixed(1)}s heap ${heap}GB] ${label}\n`);
14
+ };
15
+ /** Runs `action` between a start and a finish progress line carrying its duration. */
16
+ export const progressed = (label, action) => {
17
+ if (process.env['GEA_PROGRESS'] !== '1')
18
+ return action();
19
+ const start = performance.now();
20
+ const cpu = process.cpuUsage();
21
+ progress(`${label} ...`);
22
+ try {
23
+ return action();
24
+ }
25
+ finally {
26
+ const used = process.cpuUsage(cpu);
27
+ progress(`${label} done in ${((performance.now() - start) / 1000).toFixed(1)}s (cpu ${((used.user + used.system) / 1e6).toFixed(1)}s)`);
28
+ }
29
+ };
3
30
  export const createFrontendTiming = (scope) => {
4
31
  const enabled = process.env.GEA_FRONTEND_TIMING === '1';
5
32
  const rows = new Map();
@@ -12,8 +39,21 @@ export const createFrontendTiming = (scope) => {
12
39
  };
13
40
  return {
14
41
  measure: (name, action) => {
15
- if (!enabled)
16
- return action();
42
+ if (!enabled) {
43
+ if (process.env['GEA_PROGRESS'] !== '1')
44
+ return action();
45
+ // Per-file measures (the source transforms) run thousands of times:
46
+ // only a slow call is worth a line.
47
+ const begun = performance.now();
48
+ try {
49
+ return action();
50
+ }
51
+ finally {
52
+ const seconds = (performance.now() - begun) / 1000;
53
+ if (seconds >= 1)
54
+ progress(`${scope}:${name} took ${seconds.toFixed(1)}s`);
55
+ }
56
+ }
17
57
  const start = performance.now();
18
58
  try {
19
59
  return action();
@@ -23,6 +63,7 @@ export const createFrontendTiming = (scope) => {
23
63
  }
24
64
  },
25
65
  mark: (name) => {
66
+ progress(`${scope}:${name} finished`);
26
67
  // The compiler's stage hooks one level finer: `GEA_STAGE_TIMING=gc` prints
27
68
  // what the frontend retains after each phase, and
28
69
  // `GEA_HEAP_SNAPSHOT_AFTER=frontend:<phase>` snapshots it and