@geastack/compiler 1.0.44 → 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.
@@ -581,7 +581,22 @@ const ownedOperationKinds = new Set([
581
581
  'return',
582
582
  'super-initialize'
583
583
  ]);
584
- const computeNativeCallableFlow = (bodies, placements, classes, conversions, trace, deriver, programConversions, constructionTopology) => {
584
+ /**
585
+ * The conversion nodes whose field views the solve installs: the ones the
586
+ * bodies cite, the program-level recipes', and everything they reach. This is
587
+ * the only thing the solve reads of `programConversions` (`nativeCallableFlowOf`).
588
+ */
589
+ const flowViewNodesOf = (bodies, conversions, programConversions) => {
590
+ const citedViewNodes = bodies
591
+ .flatMap((body) => nativeFieldViewBodyCitationsOf(body).map((id) => conversions?.nodeById(id)))
592
+ .filter((node) => node !== null && node !== undefined);
593
+ for (const recipe of programConversions ?? [])
594
+ if (conversions?.nodeById(recipe.conversion.id) === recipe.conversion)
595
+ citedViewNodes.push(recipe.conversion);
596
+ return [...recipeClosureOf(citedViewNodes, conversions?.nodeById).values()];
597
+ };
598
+ const computeNativeCallableFlow = (bodies, placements, classes, conversions, trace, deriver, programConversions, constructionTopology) => solveNativeCallableFlow(flowViewNodesOf(bodies, conversions, programConversions), bodies, placements, classes, conversions, trace, deriver, constructionTopology);
599
+ const solveNativeCallableFlow = (viewNodes, bodies, placements, classes, conversions, trace, deriver, constructionTopology) => {
585
600
  const propertyLayoutCache = new Map();
586
601
  const nativePropertyLayoutOf = (representation) => hasNativePropertyLayout(representation, deriver ?? null, classes, new Set(), propertyLayoutCache);
587
602
  const cells = [];
@@ -869,13 +884,6 @@ const computeNativeCallableFlow = (bodies, placements, classes, conversions, tra
869
884
  }
870
885
  return [...found];
871
886
  };
872
- const citedViewNodes = bodies
873
- .flatMap((body) => nativeFieldViewBodyCitationsOf(body).map((id) => conversions?.nodeById(id)))
874
- .filter((node) => node !== null && node !== undefined);
875
- for (const recipe of programConversions ?? [])
876
- if (conversions?.nodeById(recipe.conversion.id) === recipe.conversion)
877
- citedViewNodes.push(recipe.conversion);
878
- const viewNodes = [...recipeClosureOf(citedViewNodes, conversions?.nodeById).values()];
879
887
  const viewShapes = new Set(nativeFieldViewPlansOf(viewNodes).map((plan) => plan.target.shapeId));
880
888
  const viewMethodFields = new Map();
881
889
  for (const node of viewNodes) {
@@ -3727,7 +3735,11 @@ export const nativeCallableFlowOf = (...args) => {
3727
3735
  if (held === undefined)
3728
3736
  rememberedFlows.set(classes, (held = []));
3729
3737
  const entries = held;
3730
- const remember = (flow, replaced) => {
3738
+ // The request's view nodes, built once and only when an answer is solved or a
3739
+ // remembered one differs from it only in its program conversions.
3740
+ let requestViewNodes = null;
3741
+ const viewNodesOfRequest = () => (requestViewNodes ??= flowViewNodesOf(bodies, conversions, programConversions));
3742
+ const remember = (flow, replaced, viewNodes) => {
3731
3743
  if (replaced !== -1)
3732
3744
  entries.splice(replaced, 1);
3733
3745
  const kind = flowKindOf(programConversions, constructionTopology);
@@ -3741,6 +3753,7 @@ export const nativeCallableFlowOf = (...args) => {
3741
3753
  deriver: deriver ?? null,
3742
3754
  programConversions: programConversions ?? null,
3743
3755
  constructionTopology: constructionTopology ?? null,
3756
+ viewNodes,
3744
3757
  flow
3745
3758
  });
3746
3759
  return flow;
@@ -3765,15 +3778,23 @@ export const nativeCallableFlowOf = (...args) => {
3765
3778
  (entry.programConversions === null) !== (programConversions === undefined) ||
3766
3779
  (entry.constructionTopology === null) !== (constructionTopology === undefined))
3767
3780
  continue;
3768
- const pairs = new Map();
3769
- if (!pairSameData(entry.bodies, bodies, pairs) ||
3770
- !pairSameData(entry.programConversions, programConversions ?? null, pairs) ||
3771
- !pairSameData(entry.constructionTopology, constructionTopology ?? null, pairs))
3781
+ let pairs = new Map();
3782
+ if (!pairSameData(entry.bodies, bodies, pairs))
3783
+ continue;
3784
+ // Program conversions reach the answer only through its view nodes
3785
+ // (`flowViewNodesOf`): recipes that differ but cite nodes already in the
3786
+ // closure leave the very same view nodes, and so the same answer.
3787
+ const withConversions = new Map(pairs);
3788
+ if (pairSameData(entry.programConversions, programConversions ?? null, withConversions))
3789
+ pairs = withConversions;
3790
+ else if (!sameNodeSequence(entry.viewNodes, viewNodesOfRequest()))
3791
+ continue;
3792
+ if (!pairSameData(entry.constructionTopology, constructionTopology ?? null, pairs))
3772
3793
  continue;
3773
3794
  const reused = flowOverCopy(entry.flow, pairs);
3774
3795
  if (reused === null)
3775
3796
  continue;
3776
- return remember(reused, index);
3797
+ return remember(reused, index, entry.viewNodes);
3777
3798
  }
3778
3799
  return null;
3779
3800
  })();
@@ -3801,8 +3822,10 @@ export const nativeCallableFlowOf = (...args) => {
3801
3822
  if (flowKindOf(entries[index].programConversions, entries[index].constructionTopology) === kind)
3802
3823
  entries.splice(index, 1);
3803
3824
  }
3804
- const flow = computeNativeCallableFlow(...args);
3805
- return remember(flow, -1);
3825
+ const viewNodes = viewNodesOfRequest();
3826
+ const flow = solveNativeCallableFlow(viewNodes, bodies, placements, classes, conversions, undefined, deriver, constructionTopology);
3827
+ return remember(flow, -1, viewNodes);
3806
3828
  };
3829
+ const sameNodeSequence = (left, right) => left === right || (left.length === right.length && left.every((node, index) => node === right[index]));
3807
3830
  /** Compatibility view of the same execution/escape census; no second analysis policy. */
3808
3831
  export const closedClassFieldCallablesOf = (...args) => nativeCallableFlowOf(...args).callables;
@@ -89,7 +89,7 @@ export declare const stableReceiversOf: (body: IrBody, receivers: ReadonlySet<Ir
89
89
  */
90
90
  export declare const stableFieldReadsOf: (body: IrBody, receivers: ReadonlySet<IrValueId>, fields: ConstructionOnlyFields, integrity: {
91
91
  readonly restricts: (representation: Representation) => boolean;
92
- }, dying: ReadonlySet<IrValueId>) => ReadonlySet<IrValueId>;
92
+ }, dying: Pick<ReadonlySet<IrValueId>, "has">) => ReadonlySet<IrValueId>;
93
93
  /**
94
94
  * Cells that may name the stable field read they are initialized with,
95
95
  * instead of holding a counted copy of it.
@@ -385,7 +385,9 @@ export const stableFieldReadsAndCellsOf = (body, receivers, fields, integrity, d
385
385
  written.set(operation.value.value, operation.declaration);
386
386
  }
387
387
  const intoCell = (value) => written.has(value) && uses.get(value) === 1;
388
- const candidates = stableFieldReadsOf(body, receivers, fields, integrity, new Set([...dying].filter((value) => !intoCell(value))));
388
+ // Asked of this body's values only, so the program's whole dying set is
389
+ // filtered as it is asked, not copied for every body rendered.
390
+ const candidates = stableFieldReadsOf(body, receivers, fields, integrity, { has: (value) => dying.has(value) && !intoCell(value) });
389
391
  const cells = stableFieldCellsOf(body, candidates, admits);
390
392
  const all = new Set(reads);
391
393
  for (const value of candidates) {
@@ -752,4 +752,16 @@ const createOwnerAuthority = (input, observedOperations) => {
752
752
  }
753
753
  };
754
754
  };
755
- export const nativeCallableDataOwnerAuthorityOf = (input) => createOwnerAuthority(input);
755
+ /**
756
+ * One authority per input object: the slot discovery, its optional reads and
757
+ * the write census each asked for one over the same input within a single
758
+ * publication or certification, and each built the program-wide tables again.
759
+ * The authority is a function of the input alone, which nothing mutates.
760
+ */
761
+ const ownerAuthorities = new WeakMap();
762
+ export const nativeCallableDataOwnerAuthorityOf = (input) => {
763
+ let authority = ownerAuthorities.get(input);
764
+ if (authority === undefined)
765
+ ownerAuthorities.set(input, (authority = createOwnerAuthority(input)));
766
+ return authority;
767
+ };
@@ -50,9 +50,5 @@ export interface NativeCallableDataWriteInput {
50
50
  readonly callableFlow: NativeCallableFlow;
51
51
  readonly nativeCallableData: NativeCallableDataPlan;
52
52
  }
53
- /** Actual evaluated operands, rather than a signature or source key spelling,
54
- * authenticate a native write. The ordinary descriptor engine retains setter,
55
- * inherited writable, extensibility and strict-assignment effects.
56
- */
57
53
  export declare const nativeCallableDataWritesOf: (input: NativeCallableDataWriteInput) => ReadonlyMap<IrOperation, NativeCallableDataWrite>;
58
54
  export declare const nativeCallableDataWriteMatches: (expected: NativeCallableDataWrite | undefined, actual: NativeCallableDataWrite | undefined) => boolean;
@@ -20,7 +20,16 @@ const supportedPayload = (value, callable = false) => value.kind === 'optional'
20
20
  * authenticate a native write. The ordinary descriptor engine retains setter,
21
21
  * inherited writable, extensibility and strict-assignment effects.
22
22
  */
23
+ // One census per input object (`nativeCallableDataOwnerAuthorityOf`): slot
24
+ // discovery's optional reads and its publication each asked for it again.
25
+ const writeCensuses = new WeakMap();
23
26
  export const nativeCallableDataWritesOf = (input) => {
27
+ let census = writeCensuses.get(input);
28
+ if (census === undefined)
29
+ writeCensuses.set(input, (census = nativeCallableDataWritesUncached(input)));
30
+ return census;
31
+ };
32
+ const nativeCallableDataWritesUncached = (input) => {
24
33
  const owners = nativeCallableDataOwnerAuthorityOf(input);
25
34
  const definitions = new Map();
26
35
  const operations = [];
@@ -123,6 +123,8 @@ export interface FieldBindingCensus {
123
123
  readonly statedTypeAt: (node: ts.Node) => ts.Type | null;
124
124
  /** How many field symbols this census bound, for measurement. */
125
125
  readonly boundCount: number;
126
+ /** How many unstated fields this census widened to `any` because a write stores a value nothing types -- see `widenDynamicallyWrittenFields`. */
127
+ readonly widenedCount: number;
126
128
  /**
127
129
  * Every field symbol this census could not bind, one `CensusRefusal` each --
128
130
  * the owner is what makes this a list something downstream can act on,