@geastack/compiler 1.0.43 → 1.0.45

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 (35) hide show
  1. package/dist/cli.js +8 -2
  2. package/dist/ir/callable-class-flow.js +87 -29
  3. package/dist/ir/construction-only-fields.d.ts +1 -1
  4. package/dist/ir/construction-only-fields.js +3 -1
  5. package/dist/ir/lower-operands.js +6 -1
  6. package/dist/ir/native-callable-data-owner.js +13 -1
  7. package/dist/ir/native-callable-data-write.d.ts +0 -4
  8. package/dist/ir/native-callable-data-write.js +9 -0
  9. package/dist/ir/shake.js +21 -0
  10. package/dist/semantics/frontend.js +18 -14
  11. package/dist/semantics/normalize/field-bindings.d.ts +2 -0
  12. package/dist/semantics/normalize/field-bindings.js +669 -13
  13. package/dist/semantics/normalize/flow/component-solver.js +37 -2
  14. package/dist/semantics/normalize/flow/source-value-session.d.ts +3 -0
  15. package/dist/semantics/normalize/flow/source-value-session.js +343 -138
  16. package/dist/semantics/normalize/global-host-mutations.js +14 -6
  17. package/dist/semantics/normalize/implicit-arguments-tuple.d.ts +11 -10
  18. package/dist/semantics/normalize/implicit-arguments-tuple.js +15 -3
  19. package/dist/semantics/normalize/parameter-bindings.js +18 -0
  20. package/dist/semantics/normalize/producers/object-assignment.js +7 -1
  21. package/dist/semantics/normalize/stated-dynamic-value.d.ts +11 -0
  22. package/dist/semantics/normalize/stated-dynamic-value.js +36 -0
  23. package/dist/semantics/normalize/structural-mutable-method.js +88 -2
  24. package/dist/targets/cpp/borrowed-call-entry.d.ts +41 -2
  25. package/dist/targets/cpp/borrowed-call-entry.js +91 -6
  26. package/dist/targets/cpp/emit-callable.js +62 -29
  27. package/dist/targets/cpp/emit.js +106 -10
  28. package/dist/targets/cpp/host/emit-host-object.js +69 -2
  29. package/dist/targets/cpp/records.d.ts +1 -0
  30. package/dist/targets/cpp/records.js +1 -1
  31. package/dist/targets/cpp/translation-unit.js +59 -22
  32. package/dist/targets/cpp/virtual-methods.js +9 -4
  33. package/package.json +1 -1
  34. package/src/targets/cpp/runtime/gea_dynamic_proxy.h +121 -0
  35. package/src/targets/cpp/runtime/gea_runtime.h +218 -28
@@ -482,6 +482,8 @@ const componentEngine = (graph, mode) => {
482
482
  };
483
483
  /** Past this many entries an edge collection becomes a hash table: a lookup is a linear scan below it. */
484
484
  const SMALL_EDGES = 8;
485
+ /** How far ahead of its last edge read `observedState` looks before asking the dependency. */
486
+ const CURSOR_WINDOW = 4;
485
487
  const edgeCount = (edges) => edges === null ? 0 : edges instanceof Map || edges instanceof Set ? edges.size : Array.isArray(edges) ? edges.length : 1;
486
488
  const NO_EDGE_STATES = [];
487
489
  const edgeStates = (edges) => edges === null ? NO_EDGE_STATES : edges instanceof Set || Array.isArray(edges) ? edges : [edges];
@@ -814,11 +816,32 @@ export const dependencyFactSolver = (expand, mode, keysAreStates = false) => {
814
816
  return candidate;
815
817
  return undefined;
816
818
  }
819
+ // A transfer re-reads its edges in the order it first read them, so the
820
+ // running owner's next edge is nearly always the one asked for: checked
821
+ // first, a few places ahead for a read the transfer skipped this time.
822
+ // The test below asks a dependency's dependents, which for a node read
823
+ // from everywhere is a table of hundreds of thousands of states; on a
824
+ // large three.js program it was a tenth of the session's time.
825
+ if (owner === cursorOwner) {
826
+ const end = Math.min(observed.length, readCursor + CURSOR_WINDOW);
827
+ for (let at = readCursor; at < end; at++) {
828
+ const candidate = observed[at];
829
+ if (candidate.solverKey === dependency) {
830
+ readCursor = at + 1;
831
+ return candidate;
832
+ }
833
+ }
834
+ }
817
835
  // An owner is among a dependency's dependents exactly when it observes
818
836
  // it: the two edges are only ever added together (`factsFrom`).
819
837
  const state = existingStateOf(dependency);
820
838
  return state !== undefined && edgeHas(state.dependents, owner) ? state : undefined;
821
839
  };
840
+ // The state whose transfer or seal is running and where its edge reads have
841
+ // reached (`observedState`). Only a hint: every hit is checked against the
842
+ // dependency's key, so a stale cursor costs a miss, never a wrong edge.
843
+ let cursorOwner = null;
844
+ let readCursor = 0;
822
845
  const withObserved = (observed, dependencyState) => {
823
846
  if (observed === null)
824
847
  return dependencyState;
@@ -981,6 +1004,10 @@ export const dependencyFactSolver = (expand, mode, keysAreStates = false) => {
981
1004
  const holding = holders.get(fact);
982
1005
  if (holding === undefined)
983
1006
  return NO_HOLDERS;
1007
+ // A key that is its own state needs no copy: the collection only grows in
1008
+ // `index`, which runs after the transfer asking has returned.
1009
+ if (keysAreStates)
1010
+ return edgeStates(holding);
984
1011
  const found = [];
985
1012
  for (const holder of edgeStates(holding))
986
1013
  found.push(holder.solverKey);
@@ -1046,8 +1073,16 @@ export const dependencyFactSolver = (expand, mode, keysAreStates = false) => {
1046
1073
  const observeFrom = (ownerState, dependency) => factsFrom(ownerState, dependency, false);
1047
1074
  // A state's edge readers, minted per transfer or seal call rather than kept
1048
1075
  // on every state (see `stateOf`).
1049
- const transferOf = (state) => definitionOf(state).transfer((dependency) => readFrom(state, dependency), (dependency) => observeFrom(state, dependency), (fact) => holdersOfFrom(state, fact), state.solverKey);
1050
- const sealOf = (state) => definitionOf(state).seal((dependency) => readFrom(state, dependency), (dependency) => observeFrom(state, dependency), (fact) => holdersOfFrom(state, fact), state.solverKey);
1076
+ const transferOf = (state) => {
1077
+ cursorOwner = state;
1078
+ readCursor = 0;
1079
+ return definitionOf(state).transfer((dependency) => readFrom(state, dependency), (dependency) => observeFrom(state, dependency), (fact) => holdersOfFrom(state, fact), state.solverKey);
1080
+ };
1081
+ const sealOf = (state) => {
1082
+ cursorOwner = state;
1083
+ readCursor = 0;
1084
+ return definitionOf(state).seal((dependency) => readFrom(state, dependency), (dependency) => observeFrom(state, dependency), (fact) => holdersOfFrom(state, fact), state.solverKey);
1085
+ };
1051
1086
  const propagate = () => {
1052
1087
  for (let cursor = 0; cursor < queue.length; cursor++) {
1053
1088
  const state = queue[cursor];
@@ -63,6 +63,9 @@ type QueryShape = {
63
63
  } | {
64
64
  readonly kind: 'unknown-reads';
65
65
  readonly node: ObjectRoot;
66
+ } | {
67
+ readonly kind: 'copy-sites';
68
+ readonly node: ObjectRoot;
66
69
  } | {
67
70
  readonly kind: 'key-reads' | 'key-uses' | 'family-slot';
68
71
  readonly node: ObjectRoot;