@neocompose/cli 0.52.4 → 0.53.0

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/dist/neo.mjs CHANGED
@@ -5012,6 +5012,15 @@ function identPathSegments(expression) {
5012
5012
  if (receiver === null) return null;
5013
5013
  return [...receiver, expression.name];
5014
5014
  }
5015
+ function receiverNarrowings(path, rootEntry, scope) {
5016
+ const facts = [];
5017
+ for (let dot = path.indexOf("."); dot !== -1; dot = path.indexOf(".", dot + 1)) {
5018
+ const prefix = path.slice(0, dot);
5019
+ const type = scope.lookupNarrowedType(prefix, rootEntry);
5020
+ if (type !== null) facts.push([prefix, type]);
5021
+ }
5022
+ return facts;
5023
+ }
5015
5024
  function pathRoot(path) {
5016
5025
  const dot = path.indexOf(".");
5017
5026
  return dot === -1 ? path : path.slice(0, dot);
@@ -7536,7 +7545,15 @@ var init_strict_resolver = __esm({
7536
7545
  if (assignedPath) {
7537
7546
  const rootEntry = scope.lookup(pathRoot(assignedPath));
7538
7547
  if (rootEntry) {
7548
+ const receiverFacts = receiverNarrowings(
7549
+ assignedPath,
7550
+ rootEntry,
7551
+ scope
7552
+ );
7539
7553
  scope.invalidate(rootEntry);
7554
+ for (const [path, type] of receiverFacts) {
7555
+ scope.narrow(path, rootEntry, type);
7556
+ }
7540
7557
  if (statement.op === "=" && !isNullable(value.type)) {
7541
7558
  scope.narrow(assignedPath, rootEntry, {
7542
7559
  ...target.type,
@@ -7627,7 +7644,17 @@ var init_strict_resolver = __esm({
7627
7644
  const assignedPath = canonicalPath(statement.target);
7628
7645
  if (assignedPath) {
7629
7646
  const rootEntry = scope.lookup(pathRoot(assignedPath));
7630
- if (rootEntry) scope.invalidate(rootEntry);
7647
+ if (rootEntry) {
7648
+ const receiverFacts = receiverNarrowings(
7649
+ assignedPath,
7650
+ rootEntry,
7651
+ scope
7652
+ );
7653
+ scope.invalidate(rootEntry);
7654
+ for (const [path, type] of receiverFacts) {
7655
+ scope.narrow(path, rootEntry, type);
7656
+ }
7657
+ }
7631
7658
  }
7632
7659
  const kind = statement.op === "+=" ? "addActionListener" /* AddActionListener */ : "removeActionListener" /* RemoveActionListener */;
7633
7660
  return {
@@ -53539,11 +53566,14 @@ function requiredMembersForConstruction(classId, document, classArguments2) {
53539
53566
  );
53540
53567
  }
53541
53568
  function contextFor(document, env = /* @__PURE__ */ new Map()) {
53542
- return {
53543
- document,
53544
- membersById: new Map(document.members.map((member) => [member.id, member])),
53545
- env
53546
- };
53569
+ const indexed = document.memberById;
53570
+ if (indexed !== void 0) {
53571
+ return { document, memberById: (id2) => indexed(id2) ?? void 0, env };
53572
+ }
53573
+ const membersById = new Map(
53574
+ document.members.map((member) => [member.id, member])
53575
+ );
53576
+ return { document, memberById: (id2) => membersById.get(id2), env };
53547
53577
  }
53548
53578
  function unsettledMembers(classId, context, classArguments2, path) {
53549
53579
  const previousEnv = context.env;
@@ -53561,7 +53591,7 @@ function unsettledMembers(classId, context, classArguments2, path) {
53561
53591
  }
53562
53592
  }
53563
53593
  function constructionMembers(classId, context) {
53564
- const { document, membersById, env } = context;
53594
+ const { document, memberById: memberById2, env } = context;
53565
53595
  if (firstUnboundParamId(env) !== null) return [];
53566
53596
  const result = [];
53567
53597
  for (const entry of mergeStoredInstanceSchema(
@@ -53569,7 +53599,7 @@ function constructionMembers(classId, context) {
53569
53599
  document.classes,
53570
53600
  document.members
53571
53601
  )) {
53572
- const raw = membersById.get(entry.memberId);
53602
+ const raw = memberById2(entry.memberId);
53573
53603
  if (raw === void 0) continue;
53574
53604
  const member = {
53575
53605
  ...raw,
@@ -53632,7 +53662,7 @@ function valueSettlesConstruction(member, body, context, path, storedRow = false
53632
53662
  if (isCollection) {
53633
53663
  if (body.genericBindings != null)
53634
53664
  context.env = envFromStamp(body.genericBindings);
53635
- const entry = context.membersById.get(member.entryMemberId);
53665
+ const entry = context.memberById(member.entryMemberId);
53636
53666
  if (entry === void 0) return false;
53637
53667
  const resolvedEntry = substituteMember(
53638
53668
  entry,
@@ -55060,7 +55090,8 @@ function evaluateLiteralContainer(args) {
55060
55090
  const evaluated = args.initEvaluator(
55061
55091
  args.member,
55062
55092
  body.init,
55063
- args.sourceValueId
55093
+ args.sourceValueId,
55094
+ args.genericEnv
55064
55095
  );
55065
55096
  const literal3 = {
55066
55097
  value: evaluated.value,
@@ -55113,6 +55144,7 @@ function buildDefaultMemberValue(args) {
55113
55144
  if (documentHasInitValueContent(args.document, declaredDefault)) {
55114
55145
  const initializerCreatedValuesStart = args.createdValues.length;
55115
55146
  const evaluated = evaluateLiteralContainer({
55147
+ genericEnv: args.genericEnv,
55116
55148
  body: declaredDefault,
55117
55149
  member,
55118
55150
  initEvaluator: args.initEvaluator
@@ -55134,7 +55166,7 @@ function buildDefaultMemberValue(args) {
55134
55166
  value2.genericBindings = { ...evaluated.genericBindings };
55135
55167
  }
55136
55168
  if (evaluated.provisionalRootId !== void 0) {
55137
- retargetDelegateReceiverValueIds(
55169
+ retargetInitializerRootValueIds(
55138
55170
  [value2, ...args.createdValues.slice(initializerCreatedValuesStart)],
55139
55171
  evaluated.provisionalRootId,
55140
55172
  value2.id
@@ -55436,7 +55468,7 @@ function buildNewValue(projectId, body, timestamp2 = Date.now()) {
55436
55468
  }
55437
55469
  return props;
55438
55470
  }
55439
- function retargetDelegateReceiverValueIds(rows, fromValueId, toValueId) {
55471
+ function retargetInitializerRootValueIds(rows, fromValueId, toValueId) {
55440
55472
  const visited = /* @__PURE__ */ new WeakSet();
55441
55473
  const visit = (value) => {
55442
55474
  if (typeof value !== "object" || value === null) return;
@@ -55453,6 +55485,7 @@ function retargetDelegateReceiverValueIds(rows, fromValueId, toValueId) {
55453
55485
  for (const entry of Object.values(value)) visit(entry);
55454
55486
  };
55455
55487
  for (const row of rows) {
55488
+ if (row.containerId === fromValueId) row.containerId = toValueId;
55456
55489
  if (!isLiteralValueContent(row)) continue;
55457
55490
  visit(row.value);
55458
55491
  visit(row.constructorArgs);
@@ -55582,6 +55615,7 @@ function cloneDefaultValueForMember(args) {
55582
55615
  if (documentHasInitValueContent(args.document, sourceValue)) {
55583
55616
  const initializerCreatedValuesStart = args.createdValues.length;
55584
55617
  const evaluated = evaluateLiteralContainer({
55618
+ genericEnv: args.genericEnv,
55585
55619
  body: sourceValue,
55586
55620
  member,
55587
55621
  initEvaluator: args.initEvaluator,
@@ -55604,7 +55638,7 @@ function cloneDefaultValueForMember(args) {
55604
55638
  evaluatedRow.genericBindings = { ...evaluated.genericBindings };
55605
55639
  }
55606
55640
  if (evaluated.provisionalRootId !== void 0) {
55607
- retargetDelegateReceiverValueIds(
55641
+ retargetInitializerRootValueIds(
55608
55642
  [
55609
55643
  evaluatedRow,
55610
55644
  ...args.createdValues.slice(initializerCreatedValuesStart)
@@ -68040,6 +68074,247 @@ var init_read_class_member = __esm({
68040
68074
  }
68041
68075
  });
68042
68076
 
68077
+ // ../src/runtime/neoscript/unattributable-reads.ts
68078
+ function ownershipChainRead(kind, rowId) {
68079
+ return `${kind}:${rowId}`;
68080
+ }
68081
+ function containerEntriesRead(containerId) {
68082
+ return `${CONTAINER_ENTRIES_PREFIX}${containerId}`;
68083
+ }
68084
+ function classifyUnattributableRead(reason) {
68085
+ for (const prefix of OWNERSHIP_CHAIN_PREFIXES) {
68086
+ if (reason.startsWith(prefix)) {
68087
+ return { scope: "ownership-chain" /* OwnershipChain */ };
68088
+ }
68089
+ }
68090
+ if (reason.startsWith(CONTAINER_ENTRIES_PREFIX)) {
68091
+ return {
68092
+ scope: "container" /* Container */,
68093
+ containerId: reason.slice(CONTAINER_ENTRIES_PREFIX.length)
68094
+ };
68095
+ }
68096
+ return { scope: "corpus" /* Corpus */ };
68097
+ }
68098
+ var OWNERSHIP_CHAIN_PREFIXES, CONTAINER_ENTRIES_PREFIX, OWNERSHIP_CHAIN_READ;
68099
+ var init_unattributable_reads = __esm({
68100
+ "../src/runtime/neoscript/unattributable-reads.ts"() {
68101
+ "use strict";
68102
+ OWNERSHIP_CHAIN_PREFIXES = [
68103
+ "generic-parent-resolution:",
68104
+ "member-owner-resolution:",
68105
+ "owned-value-parents:",
68106
+ "declaration-owner-resolution:"
68107
+ ];
68108
+ CONTAINER_ENTRIES_PREFIX = "container-entries:";
68109
+ OWNERSHIP_CHAIN_READ = ownershipChainRead(
68110
+ "member-owner-resolution",
68111
+ "*"
68112
+ );
68113
+ }
68114
+ });
68115
+
68116
+ // ../src/runtime/neoscript/cell-pattern.ts
68117
+ function integer2(value, name, minimum = -2147483648) {
68118
+ if (typeof value !== "number" || !Number.isInteger(value)) {
68119
+ throw new TypeError(`${name} must be an integer.`);
68120
+ }
68121
+ if (value < minimum) {
68122
+ throw new RangeError(`${name} must be at least ${minimum}.`);
68123
+ }
68124
+ if (value > 2147483647) {
68125
+ throw new RangeError(`${name} exceeds the supported integer range.`);
68126
+ }
68127
+ return value === 0 ? 0 : value;
68128
+ }
68129
+ function vector(value, name) {
68130
+ if (!isVector2IntValue(value)) {
68131
+ throw new TypeError(`${name} must be a Vector2Int.`);
68132
+ }
68133
+ return { x: integer2(value.x, `${name}.x`), y: integer2(value.y, `${name}.y`) };
68134
+ }
68135
+ function exclusion(value) {
68136
+ if (!Array.isArray(value) || value.length !== 1) {
68137
+ throw new TypeError(
68138
+ "excluding must select one NeoCellPatternExcluding option."
68139
+ );
68140
+ }
68141
+ if (value[0] === NEO_CELL_PATTERN_EXCLUDING_OPTION_IDS.None) return "none";
68142
+ if (value[0] === NEO_CELL_PATTERN_EXCLUDING_OPTION_IDS.Center)
68143
+ return "center";
68144
+ throw new RangeError("excluding is not a NeoCellPatternExcluding option.");
68145
+ }
68146
+ function reserve(ctx, count) {
68147
+ if (!Number.isSafeInteger(count) || count < 0) {
68148
+ throw new RangeError("Cell pattern contains too many offsets.");
68149
+ }
68150
+ ctx.reserveEntries(count);
68151
+ }
68152
+ function appendShell(result, radius, minX, maxX, minY, maxY) {
68153
+ if (radius === 0) {
68154
+ if (minX <= 0 && maxX >= 0 && minY <= 0 && maxY >= 0)
68155
+ result.push({ x: 0, y: 0 });
68156
+ return;
68157
+ }
68158
+ const firstY = Math.max(minY, -radius) || 0;
68159
+ const lastY = Math.min(maxY, radius);
68160
+ if (firstY > lastY) return;
68161
+ if (-radius >= minX && -radius <= maxX) {
68162
+ for (let y = firstY; y <= lastY; y++) result.push({ x: -radius, y });
68163
+ }
68164
+ const bottom = -radius >= minY && -radius <= maxY;
68165
+ const top = radius !== 0 && radius >= minY && radius <= maxY;
68166
+ if (bottom || top) {
68167
+ const firstX = Math.max(minX, -radius + 1) || 0;
68168
+ const lastX = Math.min(maxX, radius - 1);
68169
+ for (let x = firstX; x <= lastX; x++) {
68170
+ if (bottom) result.push({ x, y: -radius });
68171
+ if (top) result.push({ x, y: radius });
68172
+ }
68173
+ }
68174
+ if (radius !== 0 && radius >= minX && radius <= maxX) {
68175
+ for (let y = firstY; y <= lastY; y++) result.push({ x: radius, y });
68176
+ }
68177
+ }
68178
+ function rectangle(ctx, minX, maxX, minY, maxY, excluding) {
68179
+ const count = (maxX - minX + 1) * (maxY - minY + 1);
68180
+ reserve(ctx, count - (excluding === "center" ? 1 : 0));
68181
+ const offsets = [];
68182
+ const radius = Math.max(-minX, maxX, -minY, maxY);
68183
+ for (let shell = excluding === "center" ? 1 : 0; shell <= radius; shell++) {
68184
+ appendShell(offsets, shell, minX, maxX, minY, maxY);
68185
+ }
68186
+ return offsets;
68187
+ }
68188
+ function translated(offsets, origin, ctx) {
68189
+ reserve(ctx, offsets.length);
68190
+ return offsets.map((offset) => ({
68191
+ x: integer2(offset.x + origin.x, "Translated cell.x"),
68192
+ y: integer2(offset.y + origin.y, "Translated cell.y")
68193
+ }));
68194
+ }
68195
+ function isCenter(offset) {
68196
+ return offset.x === 0 && offset.y === 0;
68197
+ }
68198
+ function evaluateCellPatternNative(memberId, receiver, args, ctx) {
68199
+ if (!NEO_CELL_PATTERN_PURE_NATIVE_MEMBER_IDS.has(memberId)) {
68200
+ return { handled: false };
68201
+ }
68202
+ const pattern = (offsets2) => ({
68203
+ handled: true,
68204
+ value: ctx.constructPattern(offsets2)
68205
+ });
68206
+ switch (memberId) {
68207
+ case NEO_CELL_PATTERN_MEMBER_IDS.Box: {
68208
+ const x = integer2(args[0], "Box radiusX", 0);
68209
+ const y = args[1] === null ? x : integer2(args[1], "Box radiusY", 0);
68210
+ return pattern(rectangle(ctx, -x, x, -y, y, exclusion(args[2])));
68211
+ }
68212
+ case NEO_CELL_PATTERN_MEMBER_IDS.Cross: {
68213
+ const x = integer2(args[0], "Cross radiusX", 0);
68214
+ const y = args[1] === null ? x : integer2(args[1], "Cross radiusY", 0);
68215
+ const excluding = exclusion(args[2]);
68216
+ reserve(ctx, 2 * (x + y) + (excluding === "none" ? 1 : 0));
68217
+ const offsets2 = excluding === "none" ? [{ x: 0, y: 0 }] : [];
68218
+ for (let distance = 1; distance <= Math.max(x, y); distance++) {
68219
+ if (distance <= x)
68220
+ offsets2.push({ x: -distance, y: 0 }, { x: distance, y: 0 });
68221
+ if (distance <= y)
68222
+ offsets2.push({ x: 0, y: -distance }, { x: 0, y: distance });
68223
+ }
68224
+ return pattern(offsets2);
68225
+ }
68226
+ case NEO_CELL_PATTERN_MEMBER_IDS.Ring: {
68227
+ const radius = integer2(args[0], "Ring radius", 0);
68228
+ reserve(ctx, radius === 0 ? 1 : 8 * radius);
68229
+ const offsets2 = [];
68230
+ appendShell(offsets2, radius, -radius, radius, -radius, radius);
68231
+ return pattern(offsets2);
68232
+ }
68233
+ case NEO_CELL_PATTERN_MEMBER_IDS.Rect: {
68234
+ const size = vector(args[0], "Rect size");
68235
+ integer2(size.x, "Rect size.x", 1);
68236
+ integer2(size.y, "Rect size.y", 1);
68237
+ return pattern(rectangle(ctx, 0, size.x - 1, 0, size.y - 1, "none"));
68238
+ }
68239
+ case NEO_CELL_PATTERN_MEMBER_IDS.Line: {
68240
+ const direction = vector(args[0], "Line direction");
68241
+ if (isCenter(direction))
68242
+ throw new RangeError("Line direction must be non-zero.");
68243
+ const length = integer2(args[1], "Line length", 0);
68244
+ const excluding = exclusion(args[2]);
68245
+ reserve(ctx, length + (excluding === "none" ? 1 : 0));
68246
+ integer2(direction.x * length, "Line endpoint.x");
68247
+ integer2(direction.y * length, "Line endpoint.y");
68248
+ const offsets2 = excluding === "none" ? [{ x: 0, y: 0 }] : [];
68249
+ for (let step = 1; step <= length; step++) {
68250
+ offsets2.push({ x: direction.x * step, y: direction.y * step });
68251
+ }
68252
+ return pattern(offsets2);
68253
+ }
68254
+ }
68255
+ const offsets = ctx.readPattern(receiver);
68256
+ ctx.visitEntries(offsets.length);
68257
+ switch (memberId) {
68258
+ case NEO_CELL_PATTERN_MEMBER_IDS.Contains: {
68259
+ const offset = vector(args[0], "Contains offset");
68260
+ return {
68261
+ handled: true,
68262
+ value: offsets.some(
68263
+ (cell) => cell.x === offset.x && cell.y === offset.y
68264
+ )
68265
+ };
68266
+ }
68267
+ case NEO_CELL_PATTERN_MEMBER_IDS.Cells:
68268
+ return {
68269
+ handled: true,
68270
+ value: translated(offsets, vector(args[0], "Cells origin"), ctx)
68271
+ };
68272
+ case NEO_CELL_PATTERN_MEMBER_IDS.WithCenter:
68273
+ if (offsets.some(isCenter)) return { handled: true, value: receiver };
68274
+ reserve(ctx, offsets.length + 1);
68275
+ return pattern([{ x: 0, y: 0 }, ...offsets]);
68276
+ case NEO_CELL_PATTERN_MEMBER_IDS.WithoutCenter: {
68277
+ let count = 0;
68278
+ for (const offset of offsets) if (!isCenter(offset)) count++;
68279
+ if (count === offsets.length) return { handled: true, value: receiver };
68280
+ reserve(ctx, count);
68281
+ return pattern(offsets.filter((offset) => !isCenter(offset)));
68282
+ }
68283
+ case NEO_CELL_PATTERN_MEMBER_IDS.Translate: {
68284
+ const offset = vector(args[0], "Translate offset");
68285
+ if (isCenter(offset)) return { handled: true, value: receiver };
68286
+ return pattern(translated(offsets, offset, ctx));
68287
+ }
68288
+ case NEO_CELL_PATTERN_MEMBER_IDS.Union: {
68289
+ const other = ctx.readPattern(args[0]);
68290
+ ctx.visitEntries(other.length);
68291
+ const seen = /* @__PURE__ */ new Set();
68292
+ const result = [];
68293
+ for (const source of [offsets, other]) {
68294
+ for (const offset of source) {
68295
+ const key = `${offset.x},${offset.y}`;
68296
+ if (seen.has(key)) continue;
68297
+ reserve(ctx, 1);
68298
+ seen.add(key);
68299
+ result.push(offset);
68300
+ }
68301
+ }
68302
+ return pattern(result);
68303
+ }
68304
+ default:
68305
+ throw new Error(
68306
+ `Cell pattern native member '${memberId}' has no implementation.`
68307
+ );
68308
+ }
68309
+ }
68310
+ var init_cell_pattern2 = __esm({
68311
+ "../src/runtime/neoscript/cell-pattern.ts"() {
68312
+ "use strict";
68313
+ init_src();
68314
+ init_member_kinds();
68315
+ }
68316
+ });
68317
+
68043
68318
  // ../src/models/project/project-types.ts
68044
68319
  function isProject(value) {
68045
68320
  const v = value;
@@ -68823,588 +69098,6 @@ var init_project2 = __esm({
68823
69098
  }
68824
69099
  });
68825
69100
 
68826
- // ../src/models/members/stored-value-placement-index.ts
68827
- function buildStoredValuePlacementIndex(args) {
68828
- return createStoredValuePlacementTraversal(args)();
68829
- }
68830
- function createStoredValuePlacementTraversal(args, trackReferences = false) {
68831
- const membersById = /* @__PURE__ */ new Map();
68832
- for (const member of args.members) membersById.set(member.id, member);
68833
- const valuesById = args.indexedRows?.valuesById ?? new Map(args.values.map((row) => [row.id, row]));
68834
- const unorderedEntriesByContainerId = /* @__PURE__ */ new Map();
68835
- for (const value of args.indexedRows === void 0 ? args.values : []) {
68836
- if (typeof value.containerId !== "string") continue;
68837
- const entries = unorderedEntriesByContainerId.get(value.containerId);
68838
- if (entries === void 0) {
68839
- unorderedEntriesByContainerId.set(value.containerId, [value]);
68840
- } else {
68841
- entries.push(value);
68842
- }
68843
- }
68844
- for (const entries of unorderedEntriesByContainerId.values()) {
68845
- entries.sort((left, right) => left.id.localeCompare(right.id));
68846
- }
68847
- const constructorsById = new Map(
68848
- args.constructors.map((constructor2) => [constructor2.id, constructor2])
68849
- );
68850
- const resolveConstructorSettlement = createConstructorSettlementResolver({
68851
- classes: args.classes,
68852
- constructors: args.constructors,
68853
- members: args.members
68854
- });
68855
- const resolvedMemberById = /* @__PURE__ */ new Map();
68856
- const resolvedMember = (member) => {
68857
- const cached = resolvedMemberById.get(member.id);
68858
- if (cached !== void 0) return cached;
68859
- const resolved = resolveMember2(member, args.members);
68860
- resolvedMemberById.set(member.id, resolved);
68861
- return resolved;
68862
- };
68863
- const storedSchemaByClassId = /* @__PURE__ */ new Map();
68864
- const storedSchema = (classId) => {
68865
- const cached = storedSchemaByClassId.get(classId);
68866
- if (cached !== void 0) return cached;
68867
- const schema = mergeStoredInstanceSchema(
68868
- classId,
68869
- args.classes,
68870
- args.members
68871
- );
68872
- storedSchemaByClassId.set(classId, schema);
68873
- return schema;
68874
- };
68875
- return (roots) => {
68876
- const queue = [...roots ?? []];
68877
- if (roots === void 0) {
68878
- for (const root of projectRootMembersInDisplayOrder(args.project)) {
68879
- const member = membersById.get(root.memberId);
68880
- if (member === void 0 || typeof member.valueId !== "string")
68881
- continue;
68882
- queue.push({
68883
- memberId: member.id,
68884
- parentValueId: null,
68885
- source: {
68886
- kind: "root",
68887
- label: root.root.label,
68888
- sourcePath: `root.${root.root.key}`
68889
- },
68890
- valueId: member.valueId
68891
- });
68892
- }
68893
- for (const member of args.members) {
68894
- if (!isStaticMember(member) || memberAccessOf(member) !== 0 /* Public */)
68895
- continue;
68896
- const valueId = args.resolveStaticValueId(member.id);
68897
- if (valueId === null) continue;
68898
- const placement = findSchemaPlacement(member.id, args.classes);
68899
- if (placement === null) continue;
68900
- queue.push({
68901
- memberId: member.id,
68902
- parentValueId: null,
68903
- source: {
68904
- kind: "static",
68905
- label: placement.schemaKey,
68906
- ownerClassName: placement.ownerClass.name,
68907
- sourcePath: `static:${member.id}`
68908
- },
68909
- valueId
68910
- });
68911
- }
68912
- }
68913
- const placementByValueId = /* @__PURE__ */ new Map();
68914
- const mutablePlacementsByClassId = /* @__PURE__ */ new Map();
68915
- const mutablePlacementsByMemberId = /* @__PURE__ */ new Map();
68916
- const mutablePlacementsByKind = /* @__PURE__ */ new Map();
68917
- for (let cursor = 0; cursor < queue.length; cursor += 1) {
68918
- const item = queue[cursor];
68919
- if (item === void 0 || placementByValueId.has(item.valueId)) continue;
68920
- const authoredValue = valuesById.get(item.valueId);
68921
- const storedMember = membersById.get(item.memberId);
68922
- if (authoredValue === void 0 || storedMember === void 0) continue;
68923
- const value = args.resolveValue === void 0 ? authoredValue : args.resolveValue(authoredValue);
68924
- if (value === null) continue;
68925
- const placement = item;
68926
- placementByValueId.set(value.id, placement);
68927
- appendPlacement(mutablePlacementsByMemberId, storedMember.id, placement);
68928
- const member = resolvedMember(storedMember);
68929
- appendPlacement(mutablePlacementsByKind, member.kind, placement);
68930
- if (isMemberClassBase(member)) {
68931
- const classId = value.classId ?? member.classId;
68932
- appendPlacement(mutablePlacementsByClassId, classId, placement);
68933
- if (!isLiteralValueContent(value) || !isStringRecord4(value.value)) {
68934
- continue;
68935
- }
68936
- const settledChildrenBySchemaKey = /* @__PURE__ */ new Map();
68937
- const constructor2 = typeof value.instanceConstructorId === "string" ? constructorsById.get(value.instanceConstructorId) : void 0;
68938
- if (constructor2 !== void 0 && constructor2.classId === classId && value.constructorArgs != null) {
68939
- for (const [
68940
- index,
68941
- parameter4
68942
- ] of constructor2.argumentTypes.entries()) {
68943
- const settled = resolveConstructorSettlement(
68944
- classId,
68945
- parameter4.name,
68946
- constructor2.id
68947
- );
68948
- if (settled === null || Object.hasOwn(value.value, settled.schemaKey)) {
68949
- continue;
68950
- }
68951
- const childValueId = value.constructorArgs[constructorActionParameterId(constructor2, index)];
68952
- if (typeof childValueId === "string") {
68953
- settledChildrenBySchemaKey.set(settled.schemaKey, childValueId);
68954
- }
68955
- }
68956
- }
68957
- for (const entry of storedSchema(classId)) {
68958
- const childMember = membersById.get(entry.memberId);
68959
- const childValueId = value.value[entry.schemaKey] ?? settledChildrenBySchemaKey.get(entry.schemaKey);
68960
- if (childMember === void 0 || typeof childValueId !== "string") {
68961
- continue;
68962
- }
68963
- if (memberAccessOf(childMember) !== 0 /* Public */) continue;
68964
- queue.push({
68965
- memberId: childMember.id,
68966
- parentValueId: value.id,
68967
- source: { kind: "classField", schemaKey: entry.schemaKey },
68968
- valueId: childValueId
68969
- });
68970
- }
68971
- continue;
68972
- }
68973
- if (!isMemberListBase(member) && !isMemberDictionaryBase(member)) {
68974
- continue;
68975
- }
68976
- const entryMember = membersById.get(member.entryMemberId);
68977
- if (entryMember === void 0) continue;
68978
- if (isMemberDictionaryBase(member)) {
68979
- if (!isStringRecord4(value.value)) continue;
68980
- for (const [key, childValueId] of Object.entries(value.value)) {
68981
- queue.push({
68982
- memberId: entryMember.id,
68983
- parentValueId: value.id,
68984
- source: {
68985
- kind: "collectionEntry",
68986
- containerMemberId: storedMember.id,
68987
- entry: { kind: "dict", key, valueId: childValueId }
68988
- },
68989
- valueId: childValueId
68990
- });
68991
- }
68992
- continue;
68993
- }
68994
- const entries = listKindOf(member) === 1 /* Unordered */ ? args.indexedRows === void 0 ? unorderedEntriesByContainerId.get(value.id) ?? [] : args.indexedRows.unorderedListEntryIds(value.id).flatMap((id2) => {
68995
- const row = valuesById.get(id2);
68996
- return row === void 0 ? [] : [row];
68997
- }) : Array.isArray(value.value) ? value.value.flatMap((childValueId) => {
68998
- if (typeof childValueId !== "string") return [];
68999
- const childValue = valuesById.get(childValueId);
69000
- return childValue === void 0 ? [] : [childValue];
69001
- }) : [];
69002
- for (const [index, childValue] of entries.entries()) {
69003
- queue.push({
69004
- memberId: entryMember.id,
69005
- parentValueId: value.id,
69006
- source: {
69007
- kind: "collectionEntry",
69008
- containerMemberId: storedMember.id,
69009
- entry: { kind: "list", index, valueId: childValue.id }
69010
- },
69011
- valueId: childValue.id
69012
- });
69013
- }
69014
- }
69015
- const referencesByParentId = /* @__PURE__ */ new Map();
69016
- if (trackReferences) {
69017
- for (const id2 of placementByValueId.keys())
69018
- referencesByParentId.set(id2, /* @__PURE__ */ new Set());
69019
- for (const item of queue) {
69020
- if (item.parentValueId !== null)
69021
- referencesByParentId.get(item.parentValueId)?.add(item.valueId);
69022
- }
69023
- }
69024
- return {
69025
- referencesByParentId,
69026
- placementByValueId,
69027
- placementsByClassId: mutablePlacementsByClassId,
69028
- placementsByKind: mutablePlacementsByKind,
69029
- placementsByMemberId: mutablePlacementsByMemberId
69030
- };
69031
- };
69032
- }
69033
- function createStoredValuePlacementBatch(args) {
69034
- const traverse = createStoredValuePlacementTraversal(args, true);
69035
- const initial = traverse();
69036
- const placementByValueId = new Map(initial.placementByValueId);
69037
- const childrenByParentId = /* @__PURE__ */ new Map();
69038
- const referencingParentsById = /* @__PURE__ */ new Map();
69039
- const referencesByParentId = /* @__PURE__ */ new Map();
69040
- const declaredRootIds = new Set(
69041
- args.members.flatMap(
69042
- (member) => typeof member.valueId === "string" ? [member.valueId] : []
69043
- )
69044
- );
69045
- const indexPlacement = (placement) => {
69046
- if (placement.parentValueId === null) return;
69047
- const children = childrenByParentId.get(placement.parentValueId) ?? /* @__PURE__ */ new Set();
69048
- children.add(placement.valueId);
69049
- childrenByParentId.set(placement.parentValueId, children);
69050
- };
69051
- for (const placement of placementByValueId.values())
69052
- indexPlacement(placement);
69053
- const indexReferences2 = (parentId, references) => {
69054
- for (const id2 of referencesByParentId.get(parentId) ?? []) {
69055
- const parents = referencingParentsById.get(id2);
69056
- parents?.delete(parentId);
69057
- if (parents?.size === 0) referencingParentsById.delete(id2);
69058
- }
69059
- referencesByParentId.set(parentId, new Set(references));
69060
- for (const id2 of references) {
69061
- const parents = referencingParentsById.get(id2) ?? /* @__PURE__ */ new Set();
69062
- parents.add(parentId);
69063
- referencingParentsById.set(id2, parents);
69064
- }
69065
- };
69066
- for (const [parentId, references] of initial.referencesByParentId)
69067
- indexReferences2(parentId, references);
69068
- const rebuild = () => {
69069
- const rebuilt = traverse();
69070
- placementByValueId.clear();
69071
- childrenByParentId.clear();
69072
- referencesByParentId.clear();
69073
- referencingParentsById.clear();
69074
- for (const placement of rebuilt.placementByValueId.values()) {
69075
- placementByValueId.set(placement.valueId, placement);
69076
- indexPlacement(placement);
69077
- }
69078
- for (const [parentId, references] of rebuilt.referencesByParentId)
69079
- indexReferences2(parentId, references);
69080
- };
69081
- return {
69082
- placementByValueId,
69083
- /** Call after the external row/membership indexes have received these replacements. */
69084
- refresh(rows, previousRows) {
69085
- const affected = /* @__PURE__ */ new Set();
69086
- const consider = (id2) => {
69087
- if (typeof id2 === "string" && placementByValueId.has(id2))
69088
- affected.add(id2);
69089
- };
69090
- let needsRootRebuild = false;
69091
- for (const row of rows) {
69092
- consider(row.id);
69093
- if (!placementByValueId.has(row.id)) {
69094
- for (const parentId of referencingParentsById.get(row.id) ?? [])
69095
- consider(parentId);
69096
- }
69097
- if (!placementByValueId.has(row.id) && declaredRootIds.has(row.id))
69098
- needsRootRebuild = true;
69099
- }
69100
- const previousById = new Map(
69101
- previousRows.flatMap(
69102
- (row) => row === void 0 ? [] : [[row.id, row]]
69103
- )
69104
- );
69105
- for (const row of rows) {
69106
- const previous = previousById.get(row.id);
69107
- if (previous?.containerId === row.containerId) continue;
69108
- consider(previous?.containerId);
69109
- consider(row.containerId);
69110
- }
69111
- if (needsRootRebuild) {
69112
- rebuild();
69113
- return;
69114
- }
69115
- const hasAffectedAncestor = /* @__PURE__ */ new Map();
69116
- const rootSeeds = [];
69117
- for (const id2 of affected) {
69118
- const placement = placementByValueId.get(id2);
69119
- let parent = placement.parentValueId;
69120
- const path = [];
69121
- let found = false;
69122
- while (parent !== null) {
69123
- if (affected.has(parent)) {
69124
- found = true;
69125
- break;
69126
- }
69127
- const cached = hasAffectedAncestor.get(parent);
69128
- if (cached !== void 0) {
69129
- found = cached;
69130
- break;
69131
- }
69132
- path.push(parent);
69133
- parent = placementByValueId.get(parent)?.parentValueId ?? null;
69134
- }
69135
- for (const ancestor of path) hasAffectedAncestor.set(ancestor, found);
69136
- if (!found) rootSeeds.push(placement);
69137
- }
69138
- const removed = /* @__PURE__ */ new Set();
69139
- const queue = rootSeeds.map((root) => root.valueId);
69140
- for (let index = 0; index < queue.length; index += 1) {
69141
- const id2 = queue[index];
69142
- if (removed.has(id2)) continue;
69143
- removed.add(id2);
69144
- for (const child of childrenByParentId.get(id2) ?? []) queue.push(child);
69145
- }
69146
- for (const id2 of removed) {
69147
- const oldParent = placementByValueId.get(id2)?.parentValueId;
69148
- for (const parentId of referencingParentsById.get(id2) ?? []) {
69149
- if (!removed.has(parentId) && parentId !== oldParent && placementByValueId.has(parentId)) {
69150
- rebuild();
69151
- return;
69152
- }
69153
- }
69154
- }
69155
- for (const id2 of removed) {
69156
- const parent = placementByValueId.get(id2)?.parentValueId;
69157
- if (typeof parent === "string")
69158
- childrenByParentId.get(parent)?.delete(id2);
69159
- childrenByParentId.delete(id2);
69160
- placementByValueId.delete(id2);
69161
- }
69162
- const next = traverse(rootSeeds);
69163
- for (const [id2, placement] of next.placementByValueId) {
69164
- const existing = placementByValueId.get(id2);
69165
- if (existing !== void 0 && existing.parentValueId !== placement.parentValueId) {
69166
- rebuild();
69167
- return;
69168
- }
69169
- }
69170
- for (const id2 of removed) indexReferences2(id2, /* @__PURE__ */ new Set());
69171
- for (const [parentId, references] of next.referencesByParentId)
69172
- indexReferences2(parentId, references);
69173
- for (const placement of next.placementByValueId.values()) {
69174
- placementByValueId.set(placement.valueId, placement);
69175
- indexPlacement(placement);
69176
- }
69177
- }
69178
- };
69179
- }
69180
- function appendPlacement(index, key, placement) {
69181
- const placements = index.get(key);
69182
- if (placements === void 0) {
69183
- index.set(key, [placement]);
69184
- } else {
69185
- placements.push(placement);
69186
- }
69187
- }
69188
- function isStringRecord4(value) {
69189
- if (typeof value !== "object" || value === null || Array.isArray(value)) {
69190
- return false;
69191
- }
69192
- return Object.values(value).every((item) => typeof item === "string");
69193
- }
69194
- var init_stored_value_placement_index = __esm({
69195
- "../src/models/members/stored-value-placement-index.ts"() {
69196
- "use strict";
69197
- init_inheritance();
69198
- init_constructor_parameter_settlement();
69199
- init_constructors2();
69200
- init_project2();
69201
- init_member_kinds();
69202
- init_members();
69203
- }
69204
- });
69205
-
69206
- // ../src/runtime/neoscript/cell-pattern.ts
69207
- function integer2(value, name, minimum = -2147483648) {
69208
- if (typeof value !== "number" || !Number.isInteger(value)) {
69209
- throw new TypeError(`${name} must be an integer.`);
69210
- }
69211
- if (value < minimum) {
69212
- throw new RangeError(`${name} must be at least ${minimum}.`);
69213
- }
69214
- if (value > 2147483647) {
69215
- throw new RangeError(`${name} exceeds the supported integer range.`);
69216
- }
69217
- return value === 0 ? 0 : value;
69218
- }
69219
- function vector(value, name) {
69220
- if (!isVector2IntValue(value)) {
69221
- throw new TypeError(`${name} must be a Vector2Int.`);
69222
- }
69223
- return { x: integer2(value.x, `${name}.x`), y: integer2(value.y, `${name}.y`) };
69224
- }
69225
- function exclusion(value) {
69226
- if (!Array.isArray(value) || value.length !== 1) {
69227
- throw new TypeError(
69228
- "excluding must select one NeoCellPatternExcluding option."
69229
- );
69230
- }
69231
- if (value[0] === NEO_CELL_PATTERN_EXCLUDING_OPTION_IDS.None) return "none";
69232
- if (value[0] === NEO_CELL_PATTERN_EXCLUDING_OPTION_IDS.Center)
69233
- return "center";
69234
- throw new RangeError("excluding is not a NeoCellPatternExcluding option.");
69235
- }
69236
- function reserve(ctx, count) {
69237
- if (!Number.isSafeInteger(count) || count < 0) {
69238
- throw new RangeError("Cell pattern contains too many offsets.");
69239
- }
69240
- ctx.reserveEntries(count);
69241
- }
69242
- function appendShell(result, radius, minX, maxX, minY, maxY) {
69243
- if (radius === 0) {
69244
- if (minX <= 0 && maxX >= 0 && minY <= 0 && maxY >= 0)
69245
- result.push({ x: 0, y: 0 });
69246
- return;
69247
- }
69248
- const firstY = Math.max(minY, -radius) || 0;
69249
- const lastY = Math.min(maxY, radius);
69250
- if (firstY > lastY) return;
69251
- if (-radius >= minX && -radius <= maxX) {
69252
- for (let y = firstY; y <= lastY; y++) result.push({ x: -radius, y });
69253
- }
69254
- const bottom = -radius >= minY && -radius <= maxY;
69255
- const top = radius !== 0 && radius >= minY && radius <= maxY;
69256
- if (bottom || top) {
69257
- const firstX = Math.max(minX, -radius + 1) || 0;
69258
- const lastX = Math.min(maxX, radius - 1);
69259
- for (let x = firstX; x <= lastX; x++) {
69260
- if (bottom) result.push({ x, y: -radius });
69261
- if (top) result.push({ x, y: radius });
69262
- }
69263
- }
69264
- if (radius !== 0 && radius >= minX && radius <= maxX) {
69265
- for (let y = firstY; y <= lastY; y++) result.push({ x: radius, y });
69266
- }
69267
- }
69268
- function rectangle(ctx, minX, maxX, minY, maxY, excluding) {
69269
- const count = (maxX - minX + 1) * (maxY - minY + 1);
69270
- reserve(ctx, count - (excluding === "center" ? 1 : 0));
69271
- const offsets = [];
69272
- const radius = Math.max(-minX, maxX, -minY, maxY);
69273
- for (let shell = excluding === "center" ? 1 : 0; shell <= radius; shell++) {
69274
- appendShell(offsets, shell, minX, maxX, minY, maxY);
69275
- }
69276
- return offsets;
69277
- }
69278
- function translated(offsets, origin, ctx) {
69279
- reserve(ctx, offsets.length);
69280
- return offsets.map((offset) => ({
69281
- x: integer2(offset.x + origin.x, "Translated cell.x"),
69282
- y: integer2(offset.y + origin.y, "Translated cell.y")
69283
- }));
69284
- }
69285
- function isCenter(offset) {
69286
- return offset.x === 0 && offset.y === 0;
69287
- }
69288
- function evaluateCellPatternNative(memberId, receiver, args, ctx) {
69289
- if (!NEO_CELL_PATTERN_PURE_NATIVE_MEMBER_IDS.has(memberId)) {
69290
- return { handled: false };
69291
- }
69292
- const pattern = (offsets2) => ({
69293
- handled: true,
69294
- value: ctx.constructPattern(offsets2)
69295
- });
69296
- switch (memberId) {
69297
- case NEO_CELL_PATTERN_MEMBER_IDS.Box: {
69298
- const x = integer2(args[0], "Box radiusX", 0);
69299
- const y = args[1] === null ? x : integer2(args[1], "Box radiusY", 0);
69300
- return pattern(rectangle(ctx, -x, x, -y, y, exclusion(args[2])));
69301
- }
69302
- case NEO_CELL_PATTERN_MEMBER_IDS.Cross: {
69303
- const x = integer2(args[0], "Cross radiusX", 0);
69304
- const y = args[1] === null ? x : integer2(args[1], "Cross radiusY", 0);
69305
- const excluding = exclusion(args[2]);
69306
- reserve(ctx, 2 * (x + y) + (excluding === "none" ? 1 : 0));
69307
- const offsets2 = excluding === "none" ? [{ x: 0, y: 0 }] : [];
69308
- for (let distance = 1; distance <= Math.max(x, y); distance++) {
69309
- if (distance <= x)
69310
- offsets2.push({ x: -distance, y: 0 }, { x: distance, y: 0 });
69311
- if (distance <= y)
69312
- offsets2.push({ x: 0, y: -distance }, { x: 0, y: distance });
69313
- }
69314
- return pattern(offsets2);
69315
- }
69316
- case NEO_CELL_PATTERN_MEMBER_IDS.Ring: {
69317
- const radius = integer2(args[0], "Ring radius", 0);
69318
- reserve(ctx, radius === 0 ? 1 : 8 * radius);
69319
- const offsets2 = [];
69320
- appendShell(offsets2, radius, -radius, radius, -radius, radius);
69321
- return pattern(offsets2);
69322
- }
69323
- case NEO_CELL_PATTERN_MEMBER_IDS.Rect: {
69324
- const size = vector(args[0], "Rect size");
69325
- integer2(size.x, "Rect size.x", 1);
69326
- integer2(size.y, "Rect size.y", 1);
69327
- return pattern(rectangle(ctx, 0, size.x - 1, 0, size.y - 1, "none"));
69328
- }
69329
- case NEO_CELL_PATTERN_MEMBER_IDS.Line: {
69330
- const direction = vector(args[0], "Line direction");
69331
- if (isCenter(direction))
69332
- throw new RangeError("Line direction must be non-zero.");
69333
- const length = integer2(args[1], "Line length", 0);
69334
- const excluding = exclusion(args[2]);
69335
- reserve(ctx, length + (excluding === "none" ? 1 : 0));
69336
- integer2(direction.x * length, "Line endpoint.x");
69337
- integer2(direction.y * length, "Line endpoint.y");
69338
- const offsets2 = excluding === "none" ? [{ x: 0, y: 0 }] : [];
69339
- for (let step = 1; step <= length; step++) {
69340
- offsets2.push({ x: direction.x * step, y: direction.y * step });
69341
- }
69342
- return pattern(offsets2);
69343
- }
69344
- }
69345
- const offsets = ctx.readPattern(receiver);
69346
- ctx.visitEntries(offsets.length);
69347
- switch (memberId) {
69348
- case NEO_CELL_PATTERN_MEMBER_IDS.Contains: {
69349
- const offset = vector(args[0], "Contains offset");
69350
- return {
69351
- handled: true,
69352
- value: offsets.some(
69353
- (cell) => cell.x === offset.x && cell.y === offset.y
69354
- )
69355
- };
69356
- }
69357
- case NEO_CELL_PATTERN_MEMBER_IDS.Cells:
69358
- return {
69359
- handled: true,
69360
- value: translated(offsets, vector(args[0], "Cells origin"), ctx)
69361
- };
69362
- case NEO_CELL_PATTERN_MEMBER_IDS.WithCenter:
69363
- if (offsets.some(isCenter)) return { handled: true, value: receiver };
69364
- reserve(ctx, offsets.length + 1);
69365
- return pattern([{ x: 0, y: 0 }, ...offsets]);
69366
- case NEO_CELL_PATTERN_MEMBER_IDS.WithoutCenter: {
69367
- let count = 0;
69368
- for (const offset of offsets) if (!isCenter(offset)) count++;
69369
- if (count === offsets.length) return { handled: true, value: receiver };
69370
- reserve(ctx, count);
69371
- return pattern(offsets.filter((offset) => !isCenter(offset)));
69372
- }
69373
- case NEO_CELL_PATTERN_MEMBER_IDS.Translate: {
69374
- const offset = vector(args[0], "Translate offset");
69375
- if (isCenter(offset)) return { handled: true, value: receiver };
69376
- return pattern(translated(offsets, offset, ctx));
69377
- }
69378
- case NEO_CELL_PATTERN_MEMBER_IDS.Union: {
69379
- const other = ctx.readPattern(args[0]);
69380
- ctx.visitEntries(other.length);
69381
- const seen = /* @__PURE__ */ new Set();
69382
- const result = [];
69383
- for (const source of [offsets, other]) {
69384
- for (const offset of source) {
69385
- const key = `${offset.x},${offset.y}`;
69386
- if (seen.has(key)) continue;
69387
- reserve(ctx, 1);
69388
- seen.add(key);
69389
- result.push(offset);
69390
- }
69391
- }
69392
- return pattern(result);
69393
- }
69394
- default:
69395
- throw new Error(
69396
- `Cell pattern native member '${memberId}' has no implementation.`
69397
- );
69398
- }
69399
- }
69400
- var init_cell_pattern2 = __esm({
69401
- "../src/runtime/neoscript/cell-pattern.ts"() {
69402
- "use strict";
69403
- init_src();
69404
- init_member_kinds();
69405
- }
69406
- });
69407
-
69408
69101
  // ../src/models/classes/world-layer-link-target.ts
69409
69102
  function validateWorldLayerLinkClassTargets(args) {
69410
69103
  const relationResolver = createEffectiveClassRelationResolver(args);
@@ -69596,6 +69289,7 @@ var init_initializer_context = __esm({
69596
69289
  "../src/runtime/neoscript/initializer-context.ts"() {
69597
69290
  "use strict";
69598
69291
  init_collections();
69292
+ init_unattributable_reads();
69599
69293
  init_world_grid_query_reads();
69600
69294
  InitializerReadSet = class {
69601
69295
  valueIds = /* @__PURE__ */ new Set();
@@ -69606,9 +69300,28 @@ var init_initializer_context = __esm({
69606
69300
  worldQueries = new WorldGridQueryReadSet();
69607
69301
  hasValuePlacementRead = false;
69608
69302
  hasUnattributableValueRead = false;
69609
- recordUnattributableValueRead = (_reason) => {
69610
- void _reason;
69303
+ /**
69304
+ * The unattributable reads by scope, for a fork of the same document to
69305
+ * re-attribute; see {@link classifyUnattributableRead}. Ownership-chain
69306
+ * reads collapse to one flag: their inputs are already in `valueIds`.
69307
+ */
69308
+ hasOwnershipChainRead = false;
69309
+ containerEntryReadIds = /* @__PURE__ */ new Set();
69310
+ corpusReadReasons = /* @__PURE__ */ new Set();
69311
+ recordUnattributableValueRead = (reason) => {
69611
69312
  this.hasUnattributableValueRead = true;
69313
+ const read = classifyUnattributableRead(reason);
69314
+ switch (read.scope) {
69315
+ case "ownership-chain" /* OwnershipChain */:
69316
+ this.hasOwnershipChainRead = true;
69317
+ return;
69318
+ case "container" /* Container */:
69319
+ this.containerEntryReadIds.add(read.containerId);
69320
+ return;
69321
+ case "corpus" /* Corpus */:
69322
+ this.corpusReadReasons.add(reason);
69323
+ return;
69324
+ }
69612
69325
  };
69613
69326
  recordValuePlacementRead = () => {
69614
69327
  this.hasValuePlacementRead = true;
@@ -70524,10 +70237,10 @@ function evaluatorOwnershipCachesForBase(base) {
70524
70237
  evaluatorOwnershipCachesByBase.set(base, created);
70525
70238
  return created;
70526
70239
  }
70527
- function createEvaluatorBaseIndexBuild(members, values, valueById) {
70528
- const indexes2 = {
70240
+ function blankEvaluatorIndexes(memberByValueId) {
70241
+ return {
70529
70242
  rowByValueReference: /* @__PURE__ */ new WeakMap(),
70530
- memberByValueId: /* @__PURE__ */ new Map(),
70243
+ memberByValueId,
70531
70244
  parentLinksByChildId: /* @__PURE__ */ new Map(),
70532
70245
  indexedRowIds: /* @__PURE__ */ new Set(),
70533
70246
  indexedOverlayValues: /* @__PURE__ */ new Map(),
@@ -70544,6 +70257,9 @@ function createEvaluatorBaseIndexBuild(members, values, valueById) {
70544
70257
  constructorOwnershipDirtyValueIds: /* @__PURE__ */ new Set(),
70545
70258
  memberByRowId: /* @__PURE__ */ new Map()
70546
70259
  };
70260
+ }
70261
+ function createEvaluatorBaseIndexBuild(members, values, valueById) {
70262
+ const indexes2 = blankEvaluatorIndexes(/* @__PURE__ */ new Map());
70547
70263
  const membersByValueId = /* @__PURE__ */ new Map();
70548
70264
  for (const member of members) {
70549
70265
  if (typeof member.valueId === "string") {
@@ -70636,6 +70352,114 @@ function createEvaluatorLookupsBuild(members, storedValues, options = {}) {
70636
70352
  }
70637
70353
  };
70638
70354
  }
70355
+ function layerEvaluatorLookups(base, overlay) {
70356
+ const baseIndexes = base.evaluatorIndexes;
70357
+ if (baseIndexes === void 0) {
70358
+ throw new Error(
70359
+ "Layered evaluator lookups require a base with value graph indexes."
70360
+ );
70361
+ }
70362
+ const baseConstructorIndexes = base.constructorInitializerIndexes;
70363
+ if (baseConstructorIndexes === void 0) {
70364
+ throw new Error(
70365
+ "Layered evaluator lookups require a base with constructor initializer indexes."
70366
+ );
70367
+ }
70368
+ const masked = (id2) => overlay.rows.has(id2) || overlay.hiddenIds.has(id2);
70369
+ const local = blankEvaluatorIndexes(baseIndexes.memberByValueId);
70370
+ const localUnorderedMembership = /* @__PURE__ */ new Map();
70371
+ for (const row of overlay.rows.values()) {
70372
+ indexEvaluatorRow(local, row);
70373
+ if (typeof row.containerId !== "string") continue;
70374
+ const bucket = localUnorderedMembership.get(row.containerId) ?? [];
70375
+ bucket.push(row.id);
70376
+ localUnorderedMembership.set(row.containerId, bucket);
70377
+ }
70378
+ const parentLinks = /* @__PURE__ */ new Map();
70379
+ const parentLinksFor = (childId) => {
70380
+ const cached = parentLinks.get(childId);
70381
+ if (cached !== void 0) return cached;
70382
+ const inherited = (baseIndexes.parentLinksByChildId.get(childId) ?? []).filter((link) => !masked(link.parentId));
70383
+ const own = local.parentLinksByChildId.get(childId) ?? [];
70384
+ const merged = inherited.length === 0 ? own : [...inherited, ...own];
70385
+ parentLinks.set(childId, merged);
70386
+ return merged.length === 0 ? void 0 : merged;
70387
+ };
70388
+ const unorderedMembership = /* @__PURE__ */ new Map();
70389
+ const unorderedListEntryIds2 = (containerId) => {
70390
+ const cached = unorderedMembership.get(containerId);
70391
+ if (cached !== void 0) return cached;
70392
+ const own = localUnorderedMembership.get(containerId) ?? [];
70393
+ const inherited = overlay.rows.has(containerId) ? [] : (base.unorderedListEntryIds?.(containerId) ?? []).filter(
70394
+ (id2) => !masked(id2)
70395
+ );
70396
+ const merged = [...inherited, ...own].sort();
70397
+ unorderedMembership.set(containerId, merged);
70398
+ return merged;
70399
+ };
70400
+ const evaluatorIndexes2 = {
70401
+ rows: overlay.values,
70402
+ valueById: overlay.valuesById,
70403
+ rowByValueReference: {
70404
+ get: (value) => {
70405
+ const own = local.rowByValueReference.get(value);
70406
+ if (own !== void 0) return own;
70407
+ const inherited = baseIndexes.rowByValueReference.get(value);
70408
+ return inherited === void 0 || masked(inherited.id) ? void 0 : inherited;
70409
+ }
70410
+ },
70411
+ memberByValueId: baseIndexes.memberByValueId,
70412
+ membersByValueId: baseIndexes.membersByValueId,
70413
+ parentLinksByChildId: { get: parentLinksFor },
70414
+ indexedRowIds: {
70415
+ has: (id2) => local.indexedRowIds.has(id2) || !masked(id2) && baseIndexes.indexedRowIds.has(id2)
70416
+ },
70417
+ rowsBySourceValueId: {
70418
+ get: (sourceValueId) => {
70419
+ const inherited = (baseIndexes.rowsBySourceValueId.get(sourceValueId) ?? []).filter((row) => !masked(row.id));
70420
+ const own = local.rowsBySourceValueId.get(sourceValueId) ?? [];
70421
+ if (inherited.length === 0 && own.length === 0) return void 0;
70422
+ return inherited.length === 0 ? own : [...inherited, ...own];
70423
+ }
70424
+ }
70425
+ };
70426
+ const scopeByValueId = /* @__PURE__ */ new Map();
70427
+ const scopeFor = (row) => {
70428
+ const shadowed = baseConstructorIndexes.initializerScopeMemberIdsByValueId.get(row.id);
70429
+ if (shadowed !== void 0) return shadowed;
70430
+ const visited = /* @__PURE__ */ new Set();
70431
+ let currentId = row.id;
70432
+ while (!visited.has(currentId)) {
70433
+ visited.add(currentId);
70434
+ const link = parentLinksFor(currentId)?.[0];
70435
+ if (link === void 0) break;
70436
+ currentId = link.parentId;
70437
+ }
70438
+ return baseIndexes.memberByValueId.get(currentId)?.id;
70439
+ };
70440
+ for (const row of overlay.rows.values()) {
70441
+ if (!isInitValueContent(row)) continue;
70442
+ const scope = scopeFor(row);
70443
+ if (scope !== void 0) scopeByValueId.set(row.id, scope);
70444
+ }
70445
+ const constructorInitializerIndexes2 = {
70446
+ initializerScopeMemberIds: baseConstructorIndexes.initializerScopeMemberIds,
70447
+ initializerScopeMemberIdsByValueId: {
70448
+ get: (id2) => overlay.rows.has(id2) ? scopeByValueId.get(id2) : overlay.hiddenIds.has(id2) ? void 0 : baseConstructorIndexes.initializerScopeMemberIdsByValueId.get(id2)
70449
+ },
70450
+ schemaIndex: baseConstructorIndexes.schemaIndex
70451
+ };
70452
+ return {
70453
+ memberById: (id2) => base.memberById(id2),
70454
+ valueById: (id2) => overlay.rows.get(id2) ?? (overlay.hiddenIds.has(id2) ? null : base.valueById(id2)),
70455
+ hasStoredValueId: (id2) => overlay.rows.has(id2) || !overlay.hiddenIds.has(id2) && (base.hasStoredValueId?.(id2) ?? false),
70456
+ unorderedListEntryIds: unorderedListEntryIds2,
70457
+ virtualInstanceRowsForValue: () => [],
70458
+ rowForValueReference: (value) => evaluatorIndexes2.rowByValueReference.get(value) ?? null,
70459
+ evaluatorIndexes: evaluatorIndexes2,
70460
+ constructorInitializerIndexes: constructorInitializerIndexes2
70461
+ };
70462
+ }
70639
70463
  function evaluatorIndexes(ctx) {
70640
70464
  const overlayRevision = ctx.__valueOverlay instanceof LazyValueOverlay ? ctx.__valueOverlay.revision : void 0;
70641
70465
  if (ctx.__indexes !== void 0 && ctx.__indexes.overlayRevision === overlayRevision) {
@@ -71334,6 +71158,29 @@ function evaluateNSGetterWithEffects(getter, ctx, argumentValues = [], options =
71334
71158
  if (getter.typeInfo.type === 20 /* Decimal */ && typeof result.value === "number") {
71335
71159
  result.value = coerceDecimalOperand(result.value, "return");
71336
71160
  }
71161
+ const initializerResult = options.initializerResult;
71162
+ if (initializerResult !== void 0 && result.value !== null && (isMemberListBase(initializerResult.member) || isMemberDictionaryBase(initializerResult.member)) && findKnownRowIdByValueReference(result.value, runtimeCtx) === null) {
71163
+ const createdValues = createdSessionValuesSince(runtimeCtx, creationCheckpoint);
71164
+ const declarations = /* @__PURE__ */ new Map();
71165
+ const root = materializeConstructorArgumentValue({
71166
+ member: initializerResult.member,
71167
+ value: result.value,
71168
+ genericEnv: initializerResult.genericEnv ?? /* @__PURE__ */ new Map(),
71169
+ ctx: runtimeCtx,
71170
+ createdValues,
71171
+ createdById: new Map(createdValues.map((row) => [row.id, row])),
71172
+ storageKeyDeclarations: declarations,
71173
+ collectionEntriesAreReferences: false
71174
+ });
71175
+ declarations.delete(root.id);
71176
+ publishConstructedRows({
71177
+ root,
71178
+ createdValues,
71179
+ storageKeyDeclarations: declarations,
71180
+ ctx: runtimeCtx
71181
+ });
71182
+ result.value = root.value;
71183
+ }
71337
71184
  if (options.exportInitializerValues) {
71338
71185
  const created = createdSessionValuesSince(
71339
71186
  runtimeCtx,
@@ -71585,6 +71432,7 @@ function ownedConstructorArgumentValues(row, ctx, readRow) {
71585
71432
  }
71586
71433
  const owned = [];
71587
71434
  const collect = (value, rawTypeInfo, parameterId) => {
71435
+ if (!genericParametersConcretelyBound(rawTypeInfo, genericEnv)) return;
71588
71436
  let typeInfo = rawTypeInfo;
71589
71437
  try {
71590
71438
  typeInfo = substituteRuntimeTypeInfo(
@@ -71743,9 +71591,7 @@ function finalizeConstructorAllocations(ctx, returnValue, ownsInvocationState, r
71743
71591
  }
71744
71592
  }
71745
71593
  }
71746
- ctx.onUnattributableValueRead?.(
71747
- `constructor-argument-list:${argumentId}`
71748
- );
71594
+ ctx.onUnattributableValueRead?.(containerEntriesRead(argumentId));
71749
71595
  for (const childId of containerEntryIds(argumentId)) {
71750
71596
  scanCreationDataRow({
71751
71597
  id: childId,
@@ -71808,7 +71654,7 @@ function finalizeConstructorAllocations(ctx, returnValue, ownsInvocationState, r
71808
71654
  if (member !== null && isMemberListBase(member)) {
71809
71655
  const entryMember = evalMemberById(ctx.vm, member.entryMemberId);
71810
71656
  if (listKindOf(member) === 1 /* Unordered */) {
71811
- ctx.onUnattributableValueRead?.(`constructed-unordered-list:${row.id}`);
71657
+ ctx.onUnattributableValueRead?.(containerEntriesRead(row.id));
71812
71658
  for (const childId of containerEntryIds(row.id)) {
71813
71659
  scanOwnedRow(childId, entryMember);
71814
71660
  }
@@ -74296,7 +74142,9 @@ function runtimeGenericEnvForValueRow(row, ctx, visited, readRow) {
74296
74142
  }
74297
74143
  function runtimeParentGenericEnv(row, ctx, visited, readRow) {
74298
74144
  const result = /* @__PURE__ */ new Map();
74299
- ctx.onUnattributableValueRead?.(`generic-parent-resolution:${row.id}`);
74145
+ ctx.onUnattributableValueRead?.(
74146
+ ownershipChainRead("generic-parent-resolution", row.id)
74147
+ );
74300
74148
  for (const link of evaluatorParentLinks(evaluatorIndexes(ctx), row.id)) {
74301
74149
  const parent = readRow === void 0 ? evalValueById(
74302
74150
  ctx,
@@ -74324,6 +74172,24 @@ function overlayConcreteGenericEntries(target, source) {
74324
74172
  }
74325
74173
  }
74326
74174
  }
74175
+ function genericParametersConcretelyBound(typeInfo, env) {
74176
+ if (typeInfo.type === 21 /* Generic */) {
74177
+ return env.get(typeInfo.genericParamId)?.kind === "member";
74178
+ }
74179
+ if (typeInfo.type === 6 /* List */ || typeInfo.type === 5 /* Dictionary */ || typeInfo.type === 9 /* Lookup */) {
74180
+ return genericParametersConcretelyBound(typeInfo.entryTypeInfo, env);
74181
+ }
74182
+ if (typeInfo.type === 25 /* NSDelegate */) {
74183
+ return genericParametersConcretelyBound(typeInfo.returnTypeInfo, env) && typeInfo.argumentTypes.every(
74184
+ (argument2) => genericParametersConcretelyBound(argument2, env)
74185
+ );
74186
+ }
74187
+ if (typeInfo.type !== 7 /* Class */) return true;
74188
+ for (const argument2 of Object.values(typeInfo.typeArguments ?? {})) {
74189
+ if (!genericParametersConcretelyBound(argument2, env)) return false;
74190
+ }
74191
+ return true;
74192
+ }
74327
74193
  function substituteRuntimeTypeInfo(typeInfo, env, ctx) {
74328
74194
  if (typeInfo.type === 21 /* Generic */) {
74329
74195
  const binding = env.get(typeInfo.genericParamId);
@@ -74997,17 +74863,19 @@ function readDeclarationDefault(member, ctx) {
74997
74863
  projectId: ctx.vm.project.id,
74998
74864
  member,
74999
74865
  createdValues: created,
75000
- initEvaluator: (child, init, sourceValueId) => withConstructionGenericSlots(
74866
+ initEvaluator: (child, init, sourceValueId, genericEnv = /* @__PURE__ */ new Map()) => withConstructionGenericSlots(
75001
74867
  child,
75002
74868
  ctx,
75003
- /* @__PURE__ */ new Map(),
74869
+ genericEnv,
75004
74870
  () => evaluateInitializerInContext(
75005
74871
  init,
75006
74872
  child,
75007
74873
  ctx,
75008
74874
  created,
75009
74875
  [],
75010
- sourceValueId
74876
+ sourceValueId,
74877
+ void 0,
74878
+ genericEnv
75011
74879
  )
75012
74880
  )
75013
74881
  });
@@ -75279,7 +75147,9 @@ function resolveMemberForValueRow(row, ctx, visited) {
75279
75147
  if (syntheticMemberId !== null) {
75280
75148
  return evalMemberById(ctx.vm, syntheticMemberId);
75281
75149
  }
75282
- ctx.onUnattributableValueRead?.(`member-owner-resolution:${row.id}`);
75150
+ ctx.onUnattributableValueRead?.(
75151
+ ownershipChainRead("member-owner-resolution", row.id)
75152
+ );
75283
75153
  for (const link of evaluatorParentLinks(indexes2, row.id)) {
75284
75154
  const parent = evalValueById(
75285
75155
  ctx,
@@ -76692,7 +76562,8 @@ function validateClassConstructorDescriptor(info, ctx, requireEveryRequiredField
76692
76562
  members: ctx.vm.members,
76693
76563
  constructors: ctx.vm.constructors ?? [],
76694
76564
  values: ctx.vm.values,
76695
- valueById: ctx.vm.databaseVM?.valueById
76565
+ valueById: ctx.vm.databaseVM?.valueById,
76566
+ memberById: evaluatorDefaultValueDocument(ctx).memberById
76696
76567
  };
76697
76568
  const classArguments2 = slotArguments ?? resolveConstructionTypeArguments(
76698
76569
  info.schemaClassInfo.typeArguments,
@@ -77796,7 +77667,7 @@ function constructionInitEvaluator(ctx, createdValues, argumentScopes, construct
77796
77667
  }
77797
77668
  return null;
77798
77669
  };
77799
- return (member, init, sourceValueId) => {
77670
+ return (member, init, sourceValueId, genericEnv = instanceEnv) => {
77800
77671
  const memberId = Reflect.get(member, "id");
77801
77672
  const effectiveMemberId = typeof memberId === "string" ? memberId : null;
77802
77673
  const scopeMemberId = indexes2.initializerScopeMemberIds.get(init) ?? (typeof sourceValueId !== "string" ? void 0 : indexes2.initializerScopeMemberIdsByValueId.get(sourceValueId)) ?? effectiveMemberId;
@@ -77811,7 +77682,7 @@ function constructionInitEvaluator(ctx, createdValues, argumentScopes, construct
77811
77682
  return withConstructionGenericSlots(
77812
77683
  member,
77813
77684
  ctx,
77814
- instanceEnv,
77685
+ genericEnv,
77815
77686
  () => evaluateInitializerInContext(
77816
77687
  init,
77817
77688
  member,
@@ -77819,7 +77690,8 @@ function constructionInitEvaluator(ctx, createdValues, argumentScopes, construct
77819
77690
  createdValues,
77820
77691
  argumentValues,
77821
77692
  sourceValueId ?? null,
77822
- scopeMemberId
77693
+ scopeMemberId,
77694
+ genericEnv
77823
77695
  )
77824
77696
  );
77825
77697
  };
@@ -77956,7 +77828,7 @@ function runtimeValueReferencesVariable(value, variableId, visited = /* @__PURE_
77956
77828
  (child) => runtimeValueReferencesVariable(child, variableId, visited)
77957
77829
  );
77958
77830
  }
77959
- function evaluateInitializerInContext(init, member, ctx, createdValues, argumentValues = [], sourceValueId = null, compileMemberId) {
77831
+ function evaluateInitializerInContext(init, member, ctx, createdValues, argumentValues = [], sourceValueId = null, compileMemberId, genericEnv = /* @__PURE__ */ new Map()) {
77960
77832
  ctx.__constructedArgumentsByValue ??= /* @__PURE__ */ new WeakMap();
77961
77833
  const compiled = ensureInitializerCompiled({
77962
77834
  init,
@@ -77972,7 +77844,8 @@ function evaluateInitializerInContext(init, member, ctx, createdValues, argument
77972
77844
  result = evaluateNSGetterWithEffects(
77973
77845
  compiled,
77974
77846
  initializerCtx,
77975
- argumentValues
77847
+ argumentValues,
77848
+ { initializerResult: { member, genericEnv } }
77976
77849
  );
77977
77850
  } finally {
77978
77851
  closeFrame();
@@ -79279,7 +79152,9 @@ function currentOwnedValueAttachments(valueId, ctx) {
79279
79152
  });
79280
79153
  }
79281
79154
  }
79282
- ctx.onUnattributableValueRead?.(`owned-value-parents:${valueId}`);
79155
+ ctx.onUnattributableValueRead?.(
79156
+ ownershipChainRead("owned-value-parents", valueId)
79157
+ );
79283
79158
  const parentIds = new Set(
79284
79159
  evaluatorParentLinks(indexes2, valueId).map((link) => link.parentId)
79285
79160
  );
@@ -79561,9 +79436,7 @@ function cloneConstructorArgumentGraph(args) {
79561
79436
  if (listKindOf(member) === 1 /* Unordered */) {
79562
79437
  clone.value = [];
79563
79438
  const entryEnv2 = envFromStamp(clone.genericBindings);
79564
- args.ctx.onUnattributableValueRead?.(
79565
- `constructor-import-list:${source.id}`
79566
- );
79439
+ args.ctx.onUnattributableValueRead?.(containerEntriesRead(source.id));
79567
79440
  const entries = evaluatorValues(args.ctx).filter((row) => row.containerId === source.id).sort((left, right) => left.id.localeCompare(right.id));
79568
79441
  for (const entry of entries) {
79569
79442
  cloneRow2(entry, entryMember, entryEnv2, clone.id);
@@ -79620,6 +79493,9 @@ function cloneConstructorLiteralValue(value) {
79620
79493
  }
79621
79494
  function materializeConstructorArgumentValue(args) {
79622
79495
  const trackedValueId = findKnownRowIdByValueReference(args.value, args.ctx);
79496
+ if (args.value === null && !isRequiredMember2(args.member) && (isMemberListBase(args.member) || isMemberDictionaryBase(args.member))) {
79497
+ return registerConstructorArgumentRow(args, null);
79498
+ }
79623
79499
  if (isMemberClassBase(args.member)) {
79624
79500
  if (args.value === null || args.value === void 0) {
79625
79501
  if (isRequiredMember2(args.member)) {
@@ -79697,7 +79573,7 @@ function materializeConstructorArgumentValue(args) {
79697
79573
  let sourceEntries = args.value;
79698
79574
  if (listKindOf(args.member) === 1 /* Unordered */ && trackedValueId !== null) {
79699
79575
  args.ctx.onUnattributableValueRead?.(
79700
- `constructor-argument-list:${trackedValueId}`
79576
+ containerEntriesRead(trackedValueId)
79701
79577
  );
79702
79578
  const rows = [];
79703
79579
  for (const entry of evaluatorValues(args.ctx)) {
@@ -79955,7 +79831,8 @@ function cloneClassValueGraph(receiver, expectedClassId, ctx) {
79955
79831
  initializerCreatedValues,
79956
79832
  argumentValues,
79957
79833
  sourceRow.id,
79958
- compileMemberId
79834
+ compileMemberId,
79835
+ isMemberListBase(sourceMember) || isMemberDictionaryBase(sourceMember) ? runtimeGenericEnvForValueRow(sourceRow, ctx, /* @__PURE__ */ new Set()) : void 0
79959
79836
  );
79960
79837
  if (evaluated.existingValueRow !== void 0) {
79961
79838
  const adoptedClone = cloneRow2(
@@ -79990,7 +79867,7 @@ function cloneClassValueGraph(receiver, expectedClassId, ctx) {
79990
79867
  Reflect.deleteProperty(clone, "containerId");
79991
79868
  }
79992
79869
  if (evaluated.provisionalRootId !== void 0) {
79993
- retargetDelegateReceiverValueIds(
79870
+ retargetInitializerRootValueIds(
79994
79871
  [clone, ...initializerCreatedValues],
79995
79872
  evaluated.provisionalRootId,
79996
79873
  clone.id
@@ -80091,9 +79968,7 @@ function cloneClassValueGraph(receiver, expectedClassId, ctx) {
80091
79968
  entryTypeInfo
80092
79969
  ).id;
80093
79970
  });
80094
- ctx.onUnattributableValueRead?.(
80095
- `class-clone-unordered-list:${sourceRow.id}`
80096
- );
79971
+ ctx.onUnattributableValueRead?.(containerEntriesRead(sourceRow.id));
80097
79972
  for (const child of evaluatorValues(ctx)) {
80098
79973
  if (child.containerId !== sourceRow.id) continue;
80099
79974
  cloneRow2(child, entryMember, id2, entryTypeInfo);
@@ -80342,6 +80217,7 @@ var DELEGATE_LEXICAL_THIS, DELEGATE_LEXICAL_ROOT, NonCatchableNSGetterRuntimeErr
80342
80217
  var init_evaluateNSGetter = __esm({
80343
80218
  "../src/runtime/neoscript/evaluateNSGetter.ts"() {
80344
80219
  "use strict";
80220
+ init_unattributable_reads();
80345
80221
  init_value_row_owner_members();
80346
80222
  init_src();
80347
80223
  init_cell_pattern2();
@@ -80555,6 +80431,7 @@ function evaluateInitializerMaterialization(args) {
80555
80431
  const createdValues = [];
80556
80432
  const storageKeyDeclarations = /* @__PURE__ */ new Map();
80557
80433
  const evaluated = args.evaluateInitializer({
80434
+ genericEnv: args.genericEnv,
80558
80435
  init: args.init,
80559
80436
  member: args.member,
80560
80437
  document: args.document,
@@ -80603,6 +80480,7 @@ function materializeInitializerValue(args) {
80603
80480
  ...args.storedConstructionReplay === true ? { storedConstructionReplay: true } : {},
80604
80481
  ...args.constructionBaselineReplay === true ? { constructionBaselineReplay: true } : {},
80605
80482
  ...args.argumentValues === void 0 ? {} : { argumentValues: args.argumentValues },
80483
+ genericEnv: envFromStamp(args.row.genericBindings),
80606
80484
  sourceValueId: args.row.id,
80607
80485
  readTracking: args.readTracking,
80608
80486
  saveStaticBindings: args.saveStaticBindings,
@@ -80631,7 +80509,7 @@ function materializeInitializerValue(args) {
80631
80509
  };
80632
80510
  const allCreated = [root, ...createdValues];
80633
80511
  if (evaluated.provisionalRootId !== void 0) {
80634
- retargetDelegateReceiverValueIds(
80512
+ retargetInitializerRootValueIds(
80635
80513
  allCreated,
80636
80514
  evaluated.provisionalRootId,
80637
80515
  root.id
@@ -80653,7 +80531,7 @@ function materializeMemberDefaultValue(args) {
80653
80531
  const createdValues = [];
80654
80532
  const storageKeyDeclarations = /* @__PURE__ */ new Map();
80655
80533
  args.readTracking?.recordUnattributableValueRead(
80656
- `declaration-owner-resolution:${args.envelope.id}`
80534
+ ownershipChainRead("declaration-owner-resolution", args.envelope.id)
80657
80535
  );
80658
80536
  const declarationArguments = (member, init, sourceValueId) => {
80659
80537
  const { valuesById, rootOwners } = declarationInitializerContext(
@@ -80694,7 +80572,9 @@ function materializeMemberDefaultValue(args) {
80694
80572
  ...args.genericEnv === void 0 ? {} : { genericEnv: args.genericEnv },
80695
80573
  // A declaration default may itself be init-backed one level down (P43 §2),
80696
80574
  // and those nested initializers must evaluate against the same document.
80697
- initEvaluator: (member, init, sourceValueId) => args.evaluateInitializer({
80575
+ initEvaluator: (member, init, sourceValueId, genericEnv) => args.evaluateInitializer({
80576
+ genericEnv,
80577
+ storageKeyDeclarations,
80698
80578
  init,
80699
80579
  member,
80700
80580
  document: args.document,
@@ -80719,7 +80599,7 @@ function materializeMemberDefaultValue(args) {
80719
80599
  ...built.genericBindings == null ? {} : { genericBindings: { ...built.genericBindings } }
80720
80600
  };
80721
80601
  const allCreated = [root, ...interior];
80722
- retargetDelegateReceiverValueIds(allCreated, built.id, root.id);
80602
+ retargetInitializerRootValueIds(allCreated, built.id, root.id);
80723
80603
  finalizeMaterializedRoot({
80724
80604
  root,
80725
80605
  allCreated,
@@ -80733,9 +80613,11 @@ var declarationInitializerContextByDocument;
80733
80613
  var init_initializer_materialization = __esm({
80734
80614
  "../src/runtime/initializer-materialization.ts"() {
80735
80615
  "use strict";
80616
+ init_unattributable_reads();
80736
80617
  init_deep_clone_plain_data();
80737
80618
  init_members();
80738
80619
  init_inheritance();
80620
+ init_generics();
80739
80621
  init_evaluateNSGetter();
80740
80622
  init_initializer_context();
80741
80623
  init_value_row_owner_members();
@@ -80744,6 +80626,386 @@ var init_initializer_materialization = __esm({
80744
80626
  }
80745
80627
  });
80746
80628
 
80629
+ // ../src/models/members/stored-value-placement-index.ts
80630
+ function buildStoredValuePlacementIndex(args) {
80631
+ return createStoredValuePlacementTraversal(args)();
80632
+ }
80633
+ function createStoredValuePlacementTraversal(args, trackReferences = false) {
80634
+ const membersById = /* @__PURE__ */ new Map();
80635
+ for (const member of args.members) membersById.set(member.id, member);
80636
+ const valuesById = args.indexedRows?.valuesById ?? new Map(args.values.map((row) => [row.id, row]));
80637
+ const unorderedEntriesByContainerId = /* @__PURE__ */ new Map();
80638
+ for (const value of args.indexedRows === void 0 ? args.values : []) {
80639
+ if (typeof value.containerId !== "string") continue;
80640
+ const entries = unorderedEntriesByContainerId.get(value.containerId);
80641
+ if (entries === void 0) {
80642
+ unorderedEntriesByContainerId.set(value.containerId, [value]);
80643
+ } else {
80644
+ entries.push(value);
80645
+ }
80646
+ }
80647
+ for (const entries of unorderedEntriesByContainerId.values()) {
80648
+ entries.sort((left, right) => left.id.localeCompare(right.id));
80649
+ }
80650
+ const constructorsById = new Map(
80651
+ args.constructors.map((constructor2) => [constructor2.id, constructor2])
80652
+ );
80653
+ const resolveConstructorSettlement = createConstructorSettlementResolver({
80654
+ classes: args.classes,
80655
+ constructors: args.constructors,
80656
+ members: args.members
80657
+ });
80658
+ const resolvedMemberById = /* @__PURE__ */ new Map();
80659
+ const resolvedMember = (member) => {
80660
+ const cached = resolvedMemberById.get(member.id);
80661
+ if (cached !== void 0) return cached;
80662
+ const resolved = resolveMember2(member, args.members);
80663
+ resolvedMemberById.set(member.id, resolved);
80664
+ return resolved;
80665
+ };
80666
+ const storedSchemaByClassId = /* @__PURE__ */ new Map();
80667
+ const storedSchema = (classId) => {
80668
+ const cached = storedSchemaByClassId.get(classId);
80669
+ if (cached !== void 0) return cached;
80670
+ const schema = mergeStoredInstanceSchema(
80671
+ classId,
80672
+ args.classes,
80673
+ args.members
80674
+ );
80675
+ storedSchemaByClassId.set(classId, schema);
80676
+ return schema;
80677
+ };
80678
+ return (roots) => {
80679
+ const queue = [...roots ?? []];
80680
+ if (roots === void 0) {
80681
+ for (const root of projectRootMembersInDisplayOrder(args.project)) {
80682
+ const member = membersById.get(root.memberId);
80683
+ if (member === void 0 || typeof member.valueId !== "string")
80684
+ continue;
80685
+ queue.push({
80686
+ memberId: member.id,
80687
+ parentValueId: null,
80688
+ source: {
80689
+ kind: "root",
80690
+ label: root.root.label,
80691
+ sourcePath: `root.${root.root.key}`
80692
+ },
80693
+ valueId: member.valueId
80694
+ });
80695
+ }
80696
+ for (const member of args.members) {
80697
+ if (!isStaticMember(member) || memberAccessOf(member) !== 0 /* Public */)
80698
+ continue;
80699
+ const valueId = args.resolveStaticValueId(member.id);
80700
+ if (valueId === null) continue;
80701
+ const placement = findSchemaPlacement(member.id, args.classes);
80702
+ if (placement === null) continue;
80703
+ queue.push({
80704
+ memberId: member.id,
80705
+ parentValueId: null,
80706
+ source: {
80707
+ kind: "static",
80708
+ label: placement.schemaKey,
80709
+ ownerClassName: placement.ownerClass.name,
80710
+ sourcePath: `static:${member.id}`
80711
+ },
80712
+ valueId
80713
+ });
80714
+ }
80715
+ }
80716
+ const placementByValueId = /* @__PURE__ */ new Map();
80717
+ const mutablePlacementsByClassId = /* @__PURE__ */ new Map();
80718
+ const mutablePlacementsByMemberId = /* @__PURE__ */ new Map();
80719
+ const mutablePlacementsByKind = /* @__PURE__ */ new Map();
80720
+ for (let cursor = 0; cursor < queue.length; cursor += 1) {
80721
+ const item = queue[cursor];
80722
+ if (item === void 0 || placementByValueId.has(item.valueId)) continue;
80723
+ const authoredValue = valuesById.get(item.valueId);
80724
+ const storedMember = membersById.get(item.memberId);
80725
+ if (authoredValue === void 0 || storedMember === void 0) continue;
80726
+ const value = args.resolveValue === void 0 ? authoredValue : args.resolveValue(authoredValue);
80727
+ if (value === null) continue;
80728
+ const placement = item;
80729
+ placementByValueId.set(value.id, placement);
80730
+ appendPlacement(mutablePlacementsByMemberId, storedMember.id, placement);
80731
+ const member = resolvedMember(storedMember);
80732
+ appendPlacement(mutablePlacementsByKind, member.kind, placement);
80733
+ if (isMemberClassBase(member)) {
80734
+ const classId = value.classId ?? member.classId;
80735
+ appendPlacement(mutablePlacementsByClassId, classId, placement);
80736
+ if (!isLiteralValueContent(value) || !isStringRecord4(value.value)) {
80737
+ continue;
80738
+ }
80739
+ const settledChildrenBySchemaKey = /* @__PURE__ */ new Map();
80740
+ const constructor2 = typeof value.instanceConstructorId === "string" ? constructorsById.get(value.instanceConstructorId) : void 0;
80741
+ if (constructor2 !== void 0 && constructor2.classId === classId && value.constructorArgs != null) {
80742
+ for (const [
80743
+ index,
80744
+ parameter4
80745
+ ] of constructor2.argumentTypes.entries()) {
80746
+ const settled = resolveConstructorSettlement(
80747
+ classId,
80748
+ parameter4.name,
80749
+ constructor2.id
80750
+ );
80751
+ if (settled === null || Object.hasOwn(value.value, settled.schemaKey)) {
80752
+ continue;
80753
+ }
80754
+ const childValueId = value.constructorArgs[constructorActionParameterId(constructor2, index)];
80755
+ if (typeof childValueId === "string") {
80756
+ settledChildrenBySchemaKey.set(settled.schemaKey, childValueId);
80757
+ }
80758
+ }
80759
+ }
80760
+ for (const entry of storedSchema(classId)) {
80761
+ const childMember = membersById.get(entry.memberId);
80762
+ const childValueId = value.value[entry.schemaKey] ?? settledChildrenBySchemaKey.get(entry.schemaKey);
80763
+ if (childMember === void 0 || typeof childValueId !== "string") {
80764
+ continue;
80765
+ }
80766
+ if (memberAccessOf(childMember) !== 0 /* Public */) continue;
80767
+ queue.push({
80768
+ memberId: childMember.id,
80769
+ parentValueId: value.id,
80770
+ source: { kind: "classField", schemaKey: entry.schemaKey },
80771
+ valueId: childValueId
80772
+ });
80773
+ }
80774
+ continue;
80775
+ }
80776
+ if (!isMemberListBase(member) && !isMemberDictionaryBase(member)) {
80777
+ continue;
80778
+ }
80779
+ const entryMember = membersById.get(member.entryMemberId);
80780
+ if (entryMember === void 0) continue;
80781
+ if (isMemberDictionaryBase(member)) {
80782
+ if (!isStringRecord4(value.value)) continue;
80783
+ for (const [key, childValueId] of Object.entries(value.value)) {
80784
+ queue.push({
80785
+ memberId: entryMember.id,
80786
+ parentValueId: value.id,
80787
+ source: {
80788
+ kind: "collectionEntry",
80789
+ containerMemberId: storedMember.id,
80790
+ entry: { kind: "dict", key, valueId: childValueId }
80791
+ },
80792
+ valueId: childValueId
80793
+ });
80794
+ }
80795
+ continue;
80796
+ }
80797
+ const entries = listKindOf(member) === 1 /* Unordered */ ? args.indexedRows === void 0 ? unorderedEntriesByContainerId.get(value.id) ?? [] : args.indexedRows.unorderedListEntryIds(value.id).flatMap((id2) => {
80798
+ const row = valuesById.get(id2);
80799
+ return row === void 0 ? [] : [row];
80800
+ }) : Array.isArray(value.value) ? value.value.flatMap((childValueId) => {
80801
+ if (typeof childValueId !== "string") return [];
80802
+ const childValue = valuesById.get(childValueId);
80803
+ return childValue === void 0 ? [] : [childValue];
80804
+ }) : [];
80805
+ for (const [index, childValue] of entries.entries()) {
80806
+ queue.push({
80807
+ memberId: entryMember.id,
80808
+ parentValueId: value.id,
80809
+ source: {
80810
+ kind: "collectionEntry",
80811
+ containerMemberId: storedMember.id,
80812
+ entry: { kind: "list", index, valueId: childValue.id }
80813
+ },
80814
+ valueId: childValue.id
80815
+ });
80816
+ }
80817
+ }
80818
+ const referencesByParentId = /* @__PURE__ */ new Map();
80819
+ if (trackReferences) {
80820
+ for (const id2 of placementByValueId.keys())
80821
+ referencesByParentId.set(id2, /* @__PURE__ */ new Set());
80822
+ for (const item of queue) {
80823
+ if (item.parentValueId !== null)
80824
+ referencesByParentId.get(item.parentValueId)?.add(item.valueId);
80825
+ }
80826
+ }
80827
+ return {
80828
+ referencesByParentId,
80829
+ placementByValueId,
80830
+ placementsByClassId: mutablePlacementsByClassId,
80831
+ placementsByKind: mutablePlacementsByKind,
80832
+ placementsByMemberId: mutablePlacementsByMemberId
80833
+ };
80834
+ };
80835
+ }
80836
+ function createStoredValuePlacementBatch(args) {
80837
+ const traverse = createStoredValuePlacementTraversal(args, true);
80838
+ const initial = traverse();
80839
+ const placementByValueId = new Map(initial.placementByValueId);
80840
+ const childrenByParentId = /* @__PURE__ */ new Map();
80841
+ const referencingParentsById = /* @__PURE__ */ new Map();
80842
+ const referencesByParentId = /* @__PURE__ */ new Map();
80843
+ const declaredRootIds = new Set(
80844
+ args.members.flatMap(
80845
+ (member) => typeof member.valueId === "string" ? [member.valueId] : []
80846
+ )
80847
+ );
80848
+ const indexPlacement = (placement) => {
80849
+ if (placement.parentValueId === null) return;
80850
+ const children = childrenByParentId.get(placement.parentValueId) ?? /* @__PURE__ */ new Set();
80851
+ children.add(placement.valueId);
80852
+ childrenByParentId.set(placement.parentValueId, children);
80853
+ };
80854
+ for (const placement of placementByValueId.values())
80855
+ indexPlacement(placement);
80856
+ const indexReferences2 = (parentId, references) => {
80857
+ for (const id2 of referencesByParentId.get(parentId) ?? []) {
80858
+ const parents = referencingParentsById.get(id2);
80859
+ parents?.delete(parentId);
80860
+ if (parents?.size === 0) referencingParentsById.delete(id2);
80861
+ }
80862
+ referencesByParentId.set(parentId, new Set(references));
80863
+ for (const id2 of references) {
80864
+ const parents = referencingParentsById.get(id2) ?? /* @__PURE__ */ new Set();
80865
+ parents.add(parentId);
80866
+ referencingParentsById.set(id2, parents);
80867
+ }
80868
+ };
80869
+ for (const [parentId, references] of initial.referencesByParentId)
80870
+ indexReferences2(parentId, references);
80871
+ const rebuild = () => {
80872
+ const rebuilt = traverse();
80873
+ placementByValueId.clear();
80874
+ childrenByParentId.clear();
80875
+ referencesByParentId.clear();
80876
+ referencingParentsById.clear();
80877
+ for (const placement of rebuilt.placementByValueId.values()) {
80878
+ placementByValueId.set(placement.valueId, placement);
80879
+ indexPlacement(placement);
80880
+ }
80881
+ for (const [parentId, references] of rebuilt.referencesByParentId)
80882
+ indexReferences2(parentId, references);
80883
+ };
80884
+ return {
80885
+ placementByValueId,
80886
+ /** Call after the external row/membership indexes have received these replacements. */
80887
+ refresh(rows, previousRows) {
80888
+ const affected = /* @__PURE__ */ new Set();
80889
+ const consider = (id2) => {
80890
+ if (typeof id2 === "string" && placementByValueId.has(id2))
80891
+ affected.add(id2);
80892
+ };
80893
+ let needsRootRebuild = false;
80894
+ for (const row of rows) {
80895
+ consider(row.id);
80896
+ if (!placementByValueId.has(row.id)) {
80897
+ for (const parentId of referencingParentsById.get(row.id) ?? [])
80898
+ consider(parentId);
80899
+ }
80900
+ if (!placementByValueId.has(row.id) && declaredRootIds.has(row.id))
80901
+ needsRootRebuild = true;
80902
+ }
80903
+ const previousById = new Map(
80904
+ previousRows.flatMap(
80905
+ (row) => row === void 0 ? [] : [[row.id, row]]
80906
+ )
80907
+ );
80908
+ for (const row of rows) {
80909
+ const previous = previousById.get(row.id);
80910
+ if (previous?.containerId === row.containerId) continue;
80911
+ consider(previous?.containerId);
80912
+ consider(row.containerId);
80913
+ }
80914
+ if (needsRootRebuild) {
80915
+ rebuild();
80916
+ return;
80917
+ }
80918
+ const hasAffectedAncestor = /* @__PURE__ */ new Map();
80919
+ const rootSeeds = [];
80920
+ for (const id2 of affected) {
80921
+ const placement = placementByValueId.get(id2);
80922
+ let parent = placement.parentValueId;
80923
+ const path = [];
80924
+ let found = false;
80925
+ while (parent !== null) {
80926
+ if (affected.has(parent)) {
80927
+ found = true;
80928
+ break;
80929
+ }
80930
+ const cached = hasAffectedAncestor.get(parent);
80931
+ if (cached !== void 0) {
80932
+ found = cached;
80933
+ break;
80934
+ }
80935
+ path.push(parent);
80936
+ parent = placementByValueId.get(parent)?.parentValueId ?? null;
80937
+ }
80938
+ for (const ancestor of path) hasAffectedAncestor.set(ancestor, found);
80939
+ if (!found) rootSeeds.push(placement);
80940
+ }
80941
+ const removed = /* @__PURE__ */ new Set();
80942
+ const queue = rootSeeds.map((root) => root.valueId);
80943
+ for (let index = 0; index < queue.length; index += 1) {
80944
+ const id2 = queue[index];
80945
+ if (removed.has(id2)) continue;
80946
+ removed.add(id2);
80947
+ for (const child of childrenByParentId.get(id2) ?? []) queue.push(child);
80948
+ }
80949
+ for (const id2 of removed) {
80950
+ const oldParent = placementByValueId.get(id2)?.parentValueId;
80951
+ for (const parentId of referencingParentsById.get(id2) ?? []) {
80952
+ if (!removed.has(parentId) && parentId !== oldParent && placementByValueId.has(parentId)) {
80953
+ rebuild();
80954
+ return;
80955
+ }
80956
+ }
80957
+ }
80958
+ for (const id2 of removed) {
80959
+ const parent = placementByValueId.get(id2)?.parentValueId;
80960
+ if (typeof parent === "string")
80961
+ childrenByParentId.get(parent)?.delete(id2);
80962
+ childrenByParentId.delete(id2);
80963
+ placementByValueId.delete(id2);
80964
+ }
80965
+ const next = traverse(rootSeeds);
80966
+ for (const [id2, placement] of next.placementByValueId) {
80967
+ const existing = placementByValueId.get(id2);
80968
+ if (existing !== void 0 && existing.parentValueId !== placement.parentValueId) {
80969
+ rebuild();
80970
+ return;
80971
+ }
80972
+ }
80973
+ for (const id2 of removed) indexReferences2(id2, /* @__PURE__ */ new Set());
80974
+ for (const [parentId, references] of next.referencesByParentId)
80975
+ indexReferences2(parentId, references);
80976
+ for (const placement of next.placementByValueId.values()) {
80977
+ placementByValueId.set(placement.valueId, placement);
80978
+ indexPlacement(placement);
80979
+ }
80980
+ }
80981
+ };
80982
+ }
80983
+ function appendPlacement(index, key, placement) {
80984
+ const placements = index.get(key);
80985
+ if (placements === void 0) {
80986
+ index.set(key, [placement]);
80987
+ } else {
80988
+ placements.push(placement);
80989
+ }
80990
+ }
80991
+ function isStringRecord4(value) {
80992
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
80993
+ return false;
80994
+ }
80995
+ return Object.values(value).every((item) => typeof item === "string");
80996
+ }
80997
+ var init_stored_value_placement_index = __esm({
80998
+ "../src/models/members/stored-value-placement-index.ts"() {
80999
+ "use strict";
81000
+ init_inheritance();
81001
+ init_constructor_parameter_settlement();
81002
+ init_constructors2();
81003
+ init_project2();
81004
+ init_member_kinds();
81005
+ init_members();
81006
+ }
81007
+ });
81008
+
80747
81009
  // ../src/runtime/virtual-instance-graph.ts
80748
81010
  function buildVirtualInstanceMaterializedIndex(args) {
80749
81011
  const rowsById = new Map(
@@ -80867,8 +81129,14 @@ function expandStoredInstance(args) {
80867
81129
  for (const read of readTracking.worldQueries) {
80868
81130
  recorder?.recordWorldQueryRead?.(read);
80869
81131
  }
80870
- if (readTracking.hasUnattributableValueRead) {
80871
- recorder?.recordGlobalRead("initializer-runtime");
81132
+ if (readTracking.hasOwnershipChainRead) {
81133
+ recorder?.recordGlobalRead(OWNERSHIP_CHAIN_READ);
81134
+ }
81135
+ for (const containerId of readTracking.containerEntryReadIds) {
81136
+ recorder?.recordGlobalRead(containerEntriesRead(containerId));
81137
+ }
81138
+ for (const reason of readTracking.corpusReadReasons) {
81139
+ recorder?.recordGlobalRead(reason);
80872
81140
  }
80873
81141
  }
80874
81142
  };
@@ -83171,9 +83439,66 @@ function createHeadlessVirtualInstanceResolver(args) {
83171
83439
  const failedRootIds = /* @__PURE__ */ new Set();
83172
83440
  const expandedRowById = /* @__PURE__ */ new Map();
83173
83441
  const expandedRowByRecord = /* @__PURE__ */ new WeakMap();
83442
+ const readsByRootId = /* @__PURE__ */ new Map();
83443
+ const activeReads = [];
83444
+ const sharedByReceiverId = /* @__PURE__ */ new Map();
83445
+ const mergeReads = (reads) => {
83446
+ for (const active of activeReads) {
83447
+ if (active === reads) continue;
83448
+ for (const id2 of reads.valueIds) active.valueIds.add(id2);
83449
+ for (const id2 of reads.containerIds) active.containerIds.add(id2);
83450
+ if (reads.global) active.global = true;
83451
+ }
83452
+ };
83453
+ const recorder = {
83454
+ recordValueRead: (id2) => {
83455
+ for (const active of activeReads) active.valueIds.add(id2);
83456
+ args.readRecorder?.recordValueRead(id2);
83457
+ },
83458
+ recordLocalizedTextRead: (id2) => args.readRecorder?.recordLocalizedTextRead(id2),
83459
+ recordVariantRead: (id2) => args.readRecorder?.recordVariantRead(id2),
83460
+ recordStaticMemberRead: (id2) => args.readRecorder?.recordStaticMemberRead(id2),
83461
+ recordContainerMembershipRead: (id2) => {
83462
+ for (const active of activeReads) active.containerIds.add(id2);
83463
+ args.readRecorder?.recordContainerMembershipRead(id2);
83464
+ },
83465
+ recordWorldQueryRead: (read) => {
83466
+ for (const active of activeReads) active.global = true;
83467
+ args.readRecorder?.recordWorldQueryRead?.(read);
83468
+ },
83469
+ recordValuePlacementRead: () => args.readRecorder?.recordValuePlacementRead(),
83470
+ recordGlobalRead: (reason) => {
83471
+ const read = classifyUnattributableRead(reason);
83472
+ if (read.scope === "container" /* Container */) {
83473
+ for (const active of activeReads)
83474
+ active.containerIds.add(read.containerId);
83475
+ } else if (read.scope === "corpus" /* Corpus */) {
83476
+ for (const active of activeReads) active.global = true;
83477
+ }
83478
+ args.readRecorder?.recordGlobalRead(reason);
83479
+ }
83480
+ };
83481
+ const remember = (graph, rows) => {
83482
+ graphRowsByRootId.set(graph.instanceRootId, rows);
83483
+ for (const [id2, row] of graph.rowsById) {
83484
+ expandedRowById.set(id2, row);
83485
+ graphByValueId.set(id2, graph);
83486
+ if (typeof row.value === "object" && row.value !== null) {
83487
+ expandedRowByRecord.set(row.value, row);
83488
+ }
83489
+ }
83490
+ for (const id2 of graph.locationsById.keys()) {
83491
+ graphByValueId.set(id2, graph);
83492
+ }
83493
+ graphByValueId.set(graph.instanceRootId, graph);
83494
+ };
83174
83495
  const expandRoot = (rootId, declaredMember) => {
83175
83496
  const cached = graphRowsByRootId.get(rootId);
83176
- if (cached !== void 0) return cached;
83497
+ if (cached !== void 0) {
83498
+ const reads2 = readsByRootId.get(rootId);
83499
+ if (reads2 !== void 0) mergeReads(reads2);
83500
+ return cached;
83501
+ }
83177
83502
  if (failedRootIds.has(rootId)) return emptyRows;
83178
83503
  const instanceRoot = rawById.get(rootId);
83179
83504
  if (instanceRoot === void 0 || declaredMember === void 0) {
@@ -83189,6 +83514,12 @@ function createHeadlessVirtualInstanceResolver(args) {
83189
83514
  failedRootIds.add(rootId);
83190
83515
  return emptyRows;
83191
83516
  }
83517
+ const reads = {
83518
+ valueIds: /* @__PURE__ */ new Set(),
83519
+ containerIds: /* @__PURE__ */ new Set(),
83520
+ global: false
83521
+ };
83522
+ activeReads.push(reads);
83192
83523
  try {
83193
83524
  const resolverDocument = resolverDocumentOnce();
83194
83525
  materializedIndex ??= buildVirtualInstanceMaterializedIndex({
@@ -83201,33 +83532,52 @@ function createHeadlessVirtualInstanceResolver(args) {
83201
83532
  instanceRoot,
83202
83533
  rootMember: member,
83203
83534
  materializedIndex,
83204
- readRecorder: args.readRecorder
83535
+ readRecorder: recorder
83205
83536
  });
83206
83537
  const rows = [...graph.rowsById.values()];
83207
- graphRowsByRootId.set(rootId, rows);
83208
- for (const [id2, row] of graph.rowsById) {
83209
- expandedRowById.set(id2, row);
83210
- graphByValueId.set(id2, graph);
83211
- if (typeof row.value === "object" && row.value !== null) {
83212
- expandedRowByRecord.set(row.value, row);
83213
- }
83214
- }
83215
- for (const id2 of graph.locationsById.keys()) {
83216
- graphByValueId.set(id2, graph);
83217
- }
83218
- graphByValueId.set(rootId, graph);
83538
+ readsByRootId.set(rootId, reads);
83539
+ remember(graph, rows);
83219
83540
  return rows;
83220
83541
  } catch {
83221
83542
  failedRootIds.add(rootId);
83222
83543
  return emptyRows;
83223
- }
83544
+ } finally {
83545
+ activeReads.pop();
83546
+ mergeReads(reads);
83547
+ }
83548
+ };
83549
+ const adoptSharedExpansion = (receiverValueId) => {
83550
+ const share = args.shareFrom;
83551
+ if (share === void 0 || share.masked(receiverValueId)) return null;
83552
+ const adopted = sharedByReceiverId.get(receiverValueId);
83553
+ if (adopted !== void 0) {
83554
+ mergeReads(adopted.reads);
83555
+ return adopted.rows;
83556
+ }
83557
+ const shared = share.resolver.shareExpansion(
83558
+ receiverValueId,
83559
+ share.masked,
83560
+ share.containerChanged
83561
+ );
83562
+ if (shared === null) return null;
83563
+ for (const id2 of shared.reads.valueIds) recorder.recordValueRead(id2);
83564
+ for (const id2 of shared.reads.containerIds)
83565
+ recorder.recordContainerMembershipRead(id2);
83566
+ if (graphRowsByRootId.get(shared.graph.instanceRootId) === void 0) {
83567
+ readsByRootId.set(shared.graph.instanceRootId, shared.reads);
83568
+ remember(shared.graph, shared.rows);
83569
+ }
83570
+ sharedByReceiverId.set(receiverValueId, shared);
83571
+ return shared.rows;
83224
83572
  };
83225
83573
  const virtualInstanceRowsForValue = (receiverValueId) => {
83226
- args.readRecorder?.recordValuePlacementRead();
83227
- args.readRecorder?.recordValueRead(receiverValueId);
83574
+ const adopted = adoptSharedExpansion(receiverValueId);
83575
+ if (adopted !== null) return adopted;
83576
+ recorder.recordValuePlacementRead();
83577
+ recorder.recordValueRead(receiverValueId);
83228
83578
  let placement = placements().get(receiverValueId) ?? null;
83229
83579
  while (placement !== null) {
83230
- args.readRecorder?.recordValueRead(placement.valueId);
83580
+ recorder.recordValueRead(placement.valueId);
83231
83581
  const raw = rawById.get(placement.valueId);
83232
83582
  if (raw !== void 0 && isLiteralValueContent(raw) && isStoredClassResolutionRoot(raw)) {
83233
83583
  return expandRoot(
@@ -83257,6 +83607,33 @@ function createHeadlessVirtualInstanceResolver(args) {
83257
83607
  if (known !== void 0) return known;
83258
83608
  virtualInstanceRowsForValue(valueId);
83259
83609
  return graphByValueId.get(valueId) ?? null;
83610
+ },
83611
+ shareExpansion: (receiverValueId, masked, containerChanged) => {
83612
+ const reads = {
83613
+ valueIds: /* @__PURE__ */ new Set(),
83614
+ containerIds: /* @__PURE__ */ new Set(),
83615
+ global: false
83616
+ };
83617
+ activeReads.push(reads);
83618
+ let rows;
83619
+ try {
83620
+ rows = virtualInstanceRowsForValue(receiverValueId);
83621
+ } finally {
83622
+ activeReads.pop();
83623
+ mergeReads(reads);
83624
+ }
83625
+ const first = rows[0];
83626
+ if (first === void 0 || reads.global) return null;
83627
+ for (const id2 of reads.valueIds) if (masked(id2)) return null;
83628
+ for (const id2 of reads.containerIds)
83629
+ if (containerChanged(id2)) return null;
83630
+ const graph = graphByValueId.get(first.id);
83631
+ if (graph === void 0) {
83632
+ throw new Error(
83633
+ `Virtual expansion for receiver "${receiverValueId}" has rows but no graph.`
83634
+ );
83635
+ }
83636
+ return { graph, rows, reads };
83260
83637
  }
83261
83638
  };
83262
83639
  }
@@ -83294,6 +83671,7 @@ var init_virtual_instance_graph = __esm({
83294
83671
  init_initializer_context();
83295
83672
  init_src();
83296
83673
  init_initializer_materialization();
83674
+ init_unattributable_reads();
83297
83675
  KEPT_ROW_SAMPLE_LIMIT = 12;
83298
83676
  CORPUS_SCANNING_MEMBER_KINDS = /* @__PURE__ */ new Set([
83299
83677
  9 /* Lookup */,
@@ -83314,6 +83692,20 @@ var init_virtual_instance_graph = __esm({
83314
83692
  });
83315
83693
 
83316
83694
  // ../src/runtime/neoscript/evaluateInitializer.ts
83695
+ function sharedHeadlessResolver(overlay) {
83696
+ const base = overlay.base;
83697
+ if (base.databaseVM !== void 0) return void 0;
83698
+ initializerEvaluatorLookups(base);
83699
+ const resolver = headlessResolversByLookupKey.get(
83700
+ initializerEvaluatorCacheKey(base)
83701
+ );
83702
+ if (resolver === void 0) return void 0;
83703
+ return {
83704
+ resolver,
83705
+ masked: (id2) => overlay.rows.has(id2) || overlay.hiddenIds.has(id2),
83706
+ containerChanged: (id2) => overlay.changedContainerIds.has(id2)
83707
+ };
83708
+ }
83317
83709
  function initializerEvaluatorLookups(document, readTracking) {
83318
83710
  const trackedHeadless = readTracking !== void 0 && document.databaseVM === void 0;
83319
83711
  const indexKey = initializerEvaluatorCacheKey(document);
@@ -83378,10 +83770,12 @@ function initializerEvaluatorLookups(document, readTracking) {
83378
83770
  indexKey,
83379
83771
  revision
83380
83772
  );
83773
+ const shareFrom = document.databaseVM === void 0 && document.evaluatorOverlay !== void 0 ? sharedHeadlessResolver(document.evaluatorOverlay) : void 0;
83381
83774
  const headlessVirtualResolver = document.databaseVM === void 0 ? createHeadlessVirtualInstanceResolver({
83382
83775
  evaluateInitializer: evaluateMemberInitializer,
83383
83776
  document,
83384
83777
  resolverLookups: () => lookups,
83778
+ ...shareFrom === void 0 ? {} : { shareFrom },
83385
83779
  ...readTracking === void 0 ? {} : { readRecorder: virtualReadRecorder(readTracking) }
83386
83780
  }) : null;
83387
83781
  const lookups = {
@@ -83451,6 +83845,8 @@ function initializerEvaluatorLookups(document, readTracking) {
83451
83845
  revision,
83452
83846
  lookups
83453
83847
  });
83848
+ if (headlessVirtualResolver !== null)
83849
+ headlessResolversByLookupKey.set(lookupKey, headlessVirtualResolver);
83454
83850
  }
83455
83851
  return lookups;
83456
83852
  }
@@ -83459,10 +83855,18 @@ function indexedInitializerEvaluatorLookups(document, key, revision) {
83459
83855
  if (cached !== void 0 && (revision === void 0 ? cached.members === document.members && cached.values === document.values : cached.revision === revision)) {
83460
83856
  return cached.lookups;
83461
83857
  }
83462
- const lookups = makeEvaluatorLookups(document.members, document.values, {
83858
+ const overlay = document.evaluatorOverlay;
83859
+ const lookups = overlay === void 0 ? makeEvaluatorLookups(document.members, document.values, {
83463
83860
  includeValueGraphIndexes: true,
83464
83861
  constructorInitializerDocument: document
83465
- });
83862
+ }) : layerEvaluatorLookups(
83863
+ indexedInitializerEvaluatorLookups(
83864
+ overlay.base,
83865
+ initializerEvaluatorCacheKey(overlay.base),
83866
+ initializerEvaluatorCacheRevision(overlay.base)
83867
+ ),
83868
+ overlay
83869
+ );
83466
83870
  indexedEvaluatorLookupsByDocument.set(key, {
83467
83871
  members: document.members,
83468
83872
  values: document.values,
@@ -83772,7 +84176,10 @@ function evaluateMemberInitializer(args) {
83772
84176
  compiled,
83773
84177
  ctx,
83774
84178
  args.argumentValues ?? [],
83775
- { exportInitializerValues: true }
84179
+ {
84180
+ exportInitializerValues: true,
84181
+ initializerResult: { member: args.member, genericEnv: args.genericEnv }
84182
+ }
83776
84183
  );
83777
84184
  const created = result.createdSessionValues ?? [];
83778
84185
  if (isMemberLookupBase(args.member)) {
@@ -83812,7 +84219,7 @@ function evaluateMemberInitializer(args) {
83812
84219
  }
83813
84220
  };
83814
84221
  }
83815
- var evaluatorLookupsByDocument, indexedEvaluatorLookupsByDocument;
84222
+ var evaluatorLookupsByDocument, headlessResolversByLookupKey, indexedEvaluatorLookupsByDocument;
83816
84223
  var init_evaluateInitializer = __esm({
83817
84224
  "../src/runtime/neoscript/evaluateInitializer.ts"() {
83818
84225
  "use strict";
@@ -83825,32 +84232,39 @@ var init_evaluateInitializer = __esm({
83825
84232
  init_virtual_instance_graph();
83826
84233
  init_initializer_context();
83827
84234
  evaluatorLookupsByDocument = /* @__PURE__ */ new WeakMap();
84235
+ headlessResolversByLookupKey = /* @__PURE__ */ new WeakMap();
83828
84236
  indexedEvaluatorLookupsByDocument = /* @__PURE__ */ new WeakMap();
83829
84237
  }
83830
84238
  });
83831
84239
 
83832
- // ../src/runtime/materialize-values.ts
83833
- function materializeInitializerValue2(args) {
83834
- return materializeInitializerValue({
83835
- ...args,
83836
- evaluateInitializer: evaluateMemberInitializer
84240
+ // ../src/runtime/effective-value-reader.ts
84241
+ function rootReadScope(document) {
84242
+ const cached = rootReadScopes.get(document);
84243
+ if (cached !== void 0 && cached.members === document.members && cached.values === document.values && cached.variants === document.variants) {
84244
+ return cached.scope;
84245
+ }
84246
+ const scope = withVariantOwnershipRoots(
84247
+ expandPackedDocumentValues(document),
84248
+ document.variants ?? []
84249
+ );
84250
+ const created = scope.document === document ? scope : {
84251
+ ...scope,
84252
+ document: { ...scope.document, evaluatorCache: void 0 }
84253
+ };
84254
+ rootReadScopes.set(document, {
84255
+ members: document.members,
84256
+ values: document.values,
84257
+ variants: document.variants,
84258
+ scope: created
83837
84259
  });
84260
+ return created;
83838
84261
  }
83839
- function materializeMemberDefaultValue2(args) {
83840
- return materializeMemberDefaultValue({
83841
- ...args,
83842
- evaluateInitializer: evaluateMemberInitializer
83843
- });
84262
+ function genericEnvironmentKey2(env) {
84263
+ if (env === void 0 || env.size === 0) return "";
84264
+ return canonicalJsonStringify(
84265
+ [...env].sort(([left], [right]) => left.localeCompare(right))
84266
+ );
83844
84267
  }
83845
- var init_materialize_values = __esm({
83846
- "../src/runtime/materialize-values.ts"() {
83847
- "use strict";
83848
- init_evaluateInitializer();
83849
- init_initializer_materialization();
83850
- }
83851
- });
83852
-
83853
- // ../src/runtime/effective-value-reader.ts
83854
84268
  function createTypedValueNormalizer(reader, document, childrenByContainerId, parameterTypesForRow, memberById2, memberTypeInfo, genericEnvironmentForRow, rowIdentities) {
83855
84269
  const visiting = /* @__PURE__ */ new Set();
83856
84270
  const completed = /* @__PURE__ */ new Map();
@@ -84092,7 +84506,7 @@ function isStringRecord5(value) {
84092
84506
  function isAggregateTypeInfo2(type) {
84093
84507
  return type.type === 7 /* Class */ || type.type === 22 /* Interface */ || type.type === 6 /* List */ || type.type === 5 /* Dictionary */;
84094
84508
  }
84095
- var EffectiveValueReader;
84509
+ var rootReadScopes, EffectiveValueReader;
84096
84510
  var init_effective_value_reader = __esm({
84097
84511
  "../src/runtime/effective-value-reader.ts"() {
84098
84512
  "use strict";
@@ -84106,9 +84520,10 @@ var init_effective_value_reader = __esm({
84106
84520
  init_members();
84107
84521
  init_packed_value_encoding();
84108
84522
  init_read_class_member();
84109
- init_materialize_values();
84523
+ init_initializer_materialization();
84110
84524
  init_evaluateInitializer();
84111
84525
  init_virtual_instance_graph();
84526
+ rootReadScopes = /* @__PURE__ */ new WeakMap();
84112
84527
  EffectiveValueReader = class _EffectiveValueReader {
84113
84528
  constructor(document, overrides = /* @__PURE__ */ new Map(), context = {}, base) {
84114
84529
  this.document = document;
@@ -84120,18 +84535,12 @@ var init_effective_value_reader = __esm({
84120
84535
  "Effective value reads require a complete document snapshot; use initializerEvaluationSnapshot() for a live database."
84121
84536
  );
84122
84537
  }
84538
+ this.root = base?.root ?? this;
84123
84539
  if (base === void 0) {
84124
- const expanded = expandPackedDocumentValues(document);
84125
- const scope = withVariantOwnershipRoots(
84126
- expanded,
84127
- document.variants ?? []
84128
- );
84540
+ const scope = rootReadScope(document);
84129
84541
  this.document = scope.document;
84130
84542
  for (const [id2, member] of scope.rootMembersByValueId)
84131
84543
  this.placements.set(id2, member);
84132
- } else {
84133
- for (const [id2, member] of base.placements)
84134
- this.placements.set(id2, member);
84135
84544
  }
84136
84545
  if (overrides.size > 0) {
84137
84546
  const rows = [...overrides.values()];
@@ -84148,15 +84557,22 @@ var init_effective_value_reader = __esm({
84148
84557
  overrides;
84149
84558
  context;
84150
84559
  base;
84560
+ root;
84151
84561
  schemas = /* @__PURE__ */ new Map();
84152
84562
  placements = /* @__PURE__ */ new Map();
84153
84563
  effectiveRows = /* @__PURE__ */ new Map();
84154
- defaultRows = /* @__PURE__ */ new WeakMap();
84564
+ /** Declaration defaults by member identity and closed generic environment. */
84565
+ defaultRows = /* @__PURE__ */ new Map();
84566
+ /** Initializer-free declaration defaults, shared by every fork (root only). */
84567
+ sharedDefaultRows = /* @__PURE__ */ new Map();
84568
+ /** Every row a shared declaration default minted, readable from every fork. */
84569
+ declarationRows = /* @__PURE__ */ new Map();
84155
84570
  effectiveChildren = /* @__PURE__ */ new Map();
84156
84571
  resolvedRoots = /* @__PURE__ */ new Set();
84157
84572
  normalizer;
84158
84573
  identityNormalizers = /* @__PURE__ */ new WeakMap();
84159
84574
  resolvedDocument;
84575
+ indexedDocument;
84160
84576
  materializedIndex;
84161
84577
  graphCache;
84162
84578
  createNormalizer(rowIdentities) {
@@ -84164,33 +84580,87 @@ var init_effective_value_reader = __esm({
84164
84580
  this,
84165
84581
  this.document,
84166
84582
  { get: (id2) => this.children(id2) },
84167
- (row) => this.graph.constructorParameterTypes(row, this.placements.get(row.id)),
84583
+ (row) => this.graph.constructorParameterTypes(row, this.placementFor(row.id)),
84168
84584
  (id2) => this.graph.memberForId(id2),
84169
84585
  (member, env) => this.graph.typeInfoForMember(member, env),
84170
- (row) => this.graph.genericEnvironmentForRow(row, this.placements.get(row.id)),
84586
+ (row) => this.graph.genericEnvironmentForRow(row, this.placementFor(row.id)),
84171
84587
  rowIdentities
84172
84588
  );
84173
84589
  }
84590
+ /** The base document with this context's override rows spliced in. */
84174
84591
  get readDocument() {
84175
84592
  if (this.resolvedDocument !== void 0) return this.resolvedDocument;
84593
+ const baseDocument = this.base?.readDocument ?? this.document;
84176
84594
  if (this.overrides.size === 0)
84177
- return this.resolvedDocument = this.document;
84595
+ return this.resolvedDocument = baseDocument;
84178
84596
  const values = [];
84179
- for (const row of this.document.values) {
84180
- if (this.overrides.has(row.id)) continue;
84181
- if (row.containerId && this.overrides.has(row.containerId)) continue;
84597
+ const valuesById = /* @__PURE__ */ new Map();
84598
+ const hiddenIds = /* @__PURE__ */ new Set();
84599
+ const changedContainerIds = new Set(this.overrides.keys());
84600
+ for (const row of baseDocument.values) {
84601
+ if (this.overrides.has(row.id)) {
84602
+ if (row.containerId) changedContainerIds.add(row.containerId);
84603
+ continue;
84604
+ }
84605
+ if (row.containerId && this.overrides.has(row.containerId)) {
84606
+ hiddenIds.add(row.id);
84607
+ continue;
84608
+ }
84609
+ values.push(row);
84610
+ valuesById.set(row.id, row);
84611
+ }
84612
+ for (const row of this.overrides.values()) {
84613
+ if (row.containerId) changedContainerIds.add(row.containerId);
84182
84614
  values.push(row);
84615
+ valuesById.set(row.id, row);
84183
84616
  }
84184
- for (const row of this.overrides.values()) values.push(row);
84185
84617
  this.resolvedDocument = {
84186
- ...this.document,
84618
+ ...baseDocument,
84187
84619
  databaseVM: void 0,
84188
- valueById: void 0,
84189
84620
  evaluatorCache: void 0,
84190
- values
84621
+ evaluatorOverlay: {
84622
+ base: baseDocument,
84623
+ rows: this.overrides,
84624
+ hiddenIds,
84625
+ changedContainerIds,
84626
+ values,
84627
+ valuesById
84628
+ },
84629
+ values,
84630
+ valueById: (id2) => valuesById.get(id2) ?? null
84191
84631
  };
84192
84632
  return this.resolvedDocument;
84193
84633
  }
84634
+ /**
84635
+ * The root's read document with id indexes and the shared schema cache, so
84636
+ * declaration-default materialization never scans the document for a row,
84637
+ * a member, or a class schema.
84638
+ */
84639
+ get declarationDocument() {
84640
+ if (this.indexedDocument !== void 0) return this.indexedDocument;
84641
+ const document = this.readDocument;
84642
+ this.indexedDocument = {
84643
+ ...document,
84644
+ // Same rows as the read document: share its evaluator indexes.
84645
+ evaluatorCache: document.evaluatorCache ?? {
84646
+ key: document,
84647
+ revision: void 0
84648
+ },
84649
+ valueById: document.valueById ?? ((id2) => this.graph.valuesById.get(id2) ?? null),
84650
+ memberById: document.memberById ?? ((id2) => this.memberForId(id2)),
84651
+ storedInstanceSchema: (classId) => this.schema(classId)
84652
+ };
84653
+ return this.indexedDocument;
84654
+ }
84655
+ membersById;
84656
+ memberForId(memberId) {
84657
+ if (this.membersById === void 0) {
84658
+ this.membersById = /* @__PURE__ */ new Map();
84659
+ for (const member of this.document.members)
84660
+ this.membersById.set(member.id, member);
84661
+ }
84662
+ return this.membersById.get(memberId) ?? null;
84663
+ }
84194
84664
  get graph() {
84195
84665
  return this.base?.graph ?? (this.graphCache ??= new MaterializedValueGraphContext(
84196
84666
  this.document,
@@ -84198,8 +84668,25 @@ var init_effective_value_reader = __esm({
84198
84668
  this.placements
84199
84669
  ));
84200
84670
  }
84671
+ schema(classId) {
84672
+ const cached = this.root.schemas.get(classId);
84673
+ if (cached !== void 0) return cached;
84674
+ const schema = mergeStoredInstanceSchema(
84675
+ classId,
84676
+ this.document.classes,
84677
+ this.document.members
84678
+ );
84679
+ this.root.schemas.set(classId, schema);
84680
+ return schema;
84681
+ }
84201
84682
  rawRow(id2) {
84202
- return this.overrides.get(id2) ?? this.base?.rawRow(id2) ?? this.graph.valuesById.get(id2);
84683
+ const override = this.overrides.get(id2);
84684
+ if (override !== void 0) return override;
84685
+ if (this.base !== void 0) return this.base.rawRow(id2);
84686
+ return this.declarationRows.get(id2) ?? this.graph.valuesById.get(id2);
84687
+ }
84688
+ placementFor(valueId) {
84689
+ return this.placements.get(valueId) ?? this.base?.placementFor(valueId);
84203
84690
  }
84204
84691
  overrideChildren;
84205
84692
  rememberRows(rows) {
@@ -84252,21 +84739,13 @@ var init_effective_value_reader = __esm({
84252
84739
  return row;
84253
84740
  if (this.resolvedRoots.has(valueId)) return row;
84254
84741
  if (this.mode(valueId) === "partial") return row;
84255
- let schema = this.schemas.get(classId);
84256
- if (schema === void 0) {
84257
- schema = mergeStoredInstanceSchema(
84258
- classId,
84259
- this.document.classes,
84260
- this.document.members
84261
- );
84262
- this.schemas.set(classId, schema);
84263
- }
84742
+ const schema = this.schema(classId);
84264
84743
  if (schema.every(
84265
84744
  (entry) => Object.prototype.hasOwnProperty.call(row.value, entry.schemaKey)
84266
84745
  ))
84267
84746
  return row;
84268
84747
  this.resolvedRoots.add(valueId);
84269
- const member = this.placements.get(valueId) ?? this.graph.ownerForValue(valueId) ?? {
84748
+ const member = this.placementFor(valueId) ?? this.graph.ownerForValue(valueId) ?? {
84270
84749
  name: "Value",
84271
84750
  kind: 7 /* Class */,
84272
84751
  classId,
@@ -84318,26 +84797,52 @@ var init_effective_value_reader = __esm({
84318
84797
  return rows;
84319
84798
  }
84320
84799
  memberForValue(valueId) {
84321
- return this.placements.get(valueId) ?? this.graph.ownerForValue(valueId);
84800
+ return this.placementFor(valueId) ?? this.graph.ownerForValue(valueId);
84322
84801
  }
84323
84802
  mode(valueId) {
84324
84803
  return getField(this.memberForValue(valueId), "payload") === 1 /* Partial */ ? "partial" : "runtime";
84325
84804
  }
84805
+ /**
84806
+ * The declared default graph for a member position.
84807
+ *
84808
+ * A default that evaluated no initializer is a clone of declaration rows,
84809
+ * which no replay overrides, so the root reader keeps it for every fork. A
84810
+ * default that ran an initializer read this context's document and stays
84811
+ * with this context.
84812
+ */
84326
84813
  declarationRow(member, genericEnv) {
84327
- const cached = this.defaultRows.get(member)?.get(genericEnv);
84814
+ const memberId = getField(member, "id");
84815
+ const memberKey = typeof memberId === "string" ? memberId : member;
84816
+ const envKey = genericEnvironmentKey2(genericEnv);
84817
+ const shared = this.root.sharedDefaultRows.get(memberKey)?.get(envKey);
84818
+ if (shared !== void 0) return shared;
84819
+ const cached = this.defaultRows.get(memberKey)?.get(envKey);
84328
84820
  if (cached !== void 0) return cached;
84329
- const result = materializeMemberDefaultValue2({
84821
+ let evaluatedInitializer = false;
84822
+ const result = materializeMemberDefaultValue({
84330
84823
  ...this.context,
84331
- document: this.readDocument,
84824
+ evaluateInitializer: (args) => {
84825
+ evaluatedInitializer = true;
84826
+ return evaluateMemberInitializer(args);
84827
+ },
84828
+ document: this.declarationDocument,
84332
84829
  member,
84333
84830
  genericEnv,
84334
84831
  envelope: buildNewValue(this.document.project.id, { value: null }),
84335
84832
  declarationRoot: true
84336
84833
  });
84337
- this.rememberRows([result.root, ...result.createdValues]);
84338
- const contexts = this.defaultRows.get(member) ?? /* @__PURE__ */ new Map();
84339
- contexts.set(genericEnv, result.root);
84340
- this.defaultRows.set(member, contexts);
84834
+ const rows = [result.root, ...result.createdValues];
84835
+ const owner = evaluatedInitializer ? this : this.root;
84836
+ owner.rememberRows(rows);
84837
+ const cache = evaluatedInitializer ? owner.defaultRows : owner.sharedDefaultRows;
84838
+ if (!evaluatedInitializer)
84839
+ for (const row of rows) owner.declarationRows.set(row.id, row);
84840
+ let contexts = cache.get(memberKey);
84841
+ if (contexts === void 0) {
84842
+ contexts = /* @__PURE__ */ new Map();
84843
+ cache.set(memberKey, contexts);
84844
+ }
84845
+ contexts.set(envKey, result.root);
84341
84846
  return result.root;
84342
84847
  }
84343
84848
  normalizeConstructorArguments(args, root, placement) {
@@ -84360,12 +84865,7 @@ var init_effective_value_reader = __esm({
84360
84865
  return normalizer.normalizeTypedRow(valueId, typeInfo, placement, env);
84361
84866
  }
84362
84867
  withRowOverrides(rows) {
84363
- return new _EffectiveValueReader(
84364
- this.readDocument,
84365
- rows,
84366
- this.context,
84367
- this
84368
- );
84868
+ return new _EffectiveValueReader(this.document, rows, this.context, this);
84369
84869
  }
84370
84870
  };
84371
84871
  }
@@ -84870,6 +85370,21 @@ var init_init_source = __esm({
84870
85370
  }
84871
85371
  });
84872
85372
 
85373
+ // ../src/runtime/materialize-values.ts
85374
+ function materializeInitializerValue2(args) {
85375
+ return materializeInitializerValue({
85376
+ ...args,
85377
+ evaluateInitializer: evaluateMemberInitializer
85378
+ });
85379
+ }
85380
+ var init_materialize_values = __esm({
85381
+ "../src/runtime/materialize-values.ts"() {
85382
+ "use strict";
85383
+ init_evaluateInitializer();
85384
+ init_initializer_materialization();
85385
+ }
85386
+ });
85387
+
84873
85388
  // ../src/database/project-read-base.ts
84874
85389
  import { ConvexError } from "convex/values";
84875
85390
  function readProjectReadBase(value) {
@@ -88884,16 +89399,26 @@ function collectStructuralDependencyRecords(document, currentDocument, changedCl
88884
89399
  return records2;
88885
89400
  }
88886
89401
  function classPlacementsForMember(memberId, document) {
88887
- const placements = /* @__PURE__ */ new Set();
88888
- for (const schemaClass2 of document.classes) {
88889
- const surface = mergeSchemas(
88890
- resolveInheritanceChain(schemaClass2.id, document.classes)
88891
- );
88892
- if (surface.some((entry) => entry.memberId === memberId)) {
88893
- placements.add(schemaClass2.id);
89402
+ let index = classPlacementIndexes.get(document.classes);
89403
+ if (index === void 0) {
89404
+ const built = /* @__PURE__ */ new Map();
89405
+ for (const schemaClass2 of document.classes) {
89406
+ const surface = mergeSchemas(
89407
+ resolveInheritanceChain(schemaClass2.id, document.classes)
89408
+ );
89409
+ for (const entry of surface) {
89410
+ let owners = built.get(entry.memberId);
89411
+ if (owners === void 0) {
89412
+ owners = /* @__PURE__ */ new Set();
89413
+ built.set(entry.memberId, owners);
89414
+ }
89415
+ owners.add(schemaClass2.id);
89416
+ }
88894
89417
  }
89418
+ index = built;
89419
+ classPlacementIndexes.set(document.classes, index);
88895
89420
  }
88896
- return placements;
89421
+ return index.get(memberId) ?? NO_PLACEMENTS;
88897
89422
  }
88898
89423
  function explicitTargetIds(changes) {
88899
89424
  const result = {
@@ -89149,7 +89674,7 @@ function withoutFields(value, ignored) {
89149
89674
  Object.entries(value).filter(([field]) => !ignored.has(field))
89150
89675
  );
89151
89676
  }
89152
- var NON_CONTRACT_MEMBER_FIELDS, NS_PROPERTY_BODY_FIELDS, NS_FUNCTION_BODY_FIELDS;
89677
+ var NON_CONTRACT_MEMBER_FIELDS, NS_PROPERTY_BODY_FIELDS, NS_FUNCTION_BODY_FIELDS, NO_PLACEMENTS, classPlacementIndexes;
89153
89678
  var init_neo_script_recompile_scope = __esm({
89154
89679
  "../src/database/neo-script-recompile-scope.ts"() {
89155
89680
  "use strict";
@@ -89190,6 +89715,8 @@ var init_neo_script_recompile_scope = __esm({
89190
89715
  "bodyMode",
89191
89716
  "uiAction"
89192
89717
  ]);
89718
+ NO_PLACEMENTS = /* @__PURE__ */ new Set();
89719
+ classPlacementIndexes = /* @__PURE__ */ new WeakMap();
89193
89720
  }
89194
89721
  });
89195
89722
 
@@ -96782,11 +97309,8 @@ function materializePreparedInstanceInitializers(args) {
96782
97309
  compiledDocument,
96783
97310
  compiledDocument.variants ?? []
96784
97311
  );
96785
- let currentGraph = null;
96786
- const requireCurrentGraph = () => currentGraph ??= createVariantMaterializedValueGraphContext(
96787
- materializationScope.document,
96788
- materializationScope.document.variants ?? []
96789
- );
97312
+ let currentReader = null;
97313
+ const requireCurrentReader = () => currentReader ??= new EffectiveValueReader(materializationScope.document);
96790
97314
  const owners = resolveSemanticOwnerMembersForValues(
96791
97315
  materializationScope.document,
96792
97316
  new Set(sites.keys()),
@@ -96827,8 +97351,7 @@ function materializePreparedInstanceInitializers(args) {
96827
97351
  // scope that compiled and evaluated this initializer. Stored replay
96828
97352
  // closes its generic slot from the same ephemeral member id, so its
96829
97353
  // expansion must read that scoped document too.
96830
- currentDocument: materializationScope.document,
96831
- currentGraph: requireCurrentGraph(),
97354
+ currentReader: requireCurrentReader(),
96832
97355
  currentRoot: existingRoot,
96833
97356
  rootMember: member,
96834
97357
  replayRoot: materialized.root,
@@ -96923,8 +97446,7 @@ function replayedCreationDataMatches(args) {
96923
97446
  if (replayArgs !== void 0 && replayArgs !== null) {
96924
97447
  const currentArgs = args.currentRoot.constructorArgs;
96925
97448
  if (currentArgs === void 0 || currentArgs === null || !constructorArgumentsSemanticallyEqual({
96926
- currentDocument: args.currentDocument,
96927
- currentGraph: args.currentGraph,
97449
+ currentReader: args.currentReader,
96928
97450
  currentRoot: args.currentRoot,
96929
97451
  rootMember: args.rootMember,
96930
97452
  current: currentArgs,
@@ -97088,7 +97610,7 @@ function reconcileInitializerMaterializationTransport(args) {
97088
97610
  }
97089
97611
  }
97090
97612
  function constructorArgumentsSemanticallyEqual(args) {
97091
- const current = new EffectiveValueReader(args.currentDocument);
97613
+ const current = args.currentReader;
97092
97614
  const replayRows = /* @__PURE__ */ new Map([
97093
97615
  [args.replayRoot.id, args.replayRoot]
97094
97616
  ]);
@@ -98651,7 +99173,8 @@ function materializeAuthoredSeedRow(args) {
98651
99173
  const literalArgs = { ...args, row: args.row };
98652
99174
  const rowCarriesCompleteConstructionRecipe = carriesCompleteConstructionRecipe(args.row);
98653
99175
  const belongsToSparseConstruction = args.sparseConstructionRoot || rowCarriesCompleteConstructionRecipe;
98654
- if (isMemberClassBase(resolvedStoredMember) && args.row.value !== null && !belongsToSparseConstruction) {
99176
+ const rowIsStored = args.replaceExistingIds.has(args.row.id);
99177
+ if (isMemberClassBase(resolvedStoredMember) && args.row.value !== null && !belongsToSparseConstruction && !rowIsStored) {
98655
99178
  return materializeLegacyAuthoredClassSeedRow({
98656
99179
  args: literalArgs,
98657
99180
  member: resolvedStoredMember
@@ -98983,7 +99506,8 @@ function isStringValueRecord(value) {
98983
99506
  return value !== null && typeof value === "object" && !Array.isArray(value) && Object.values(value).every((entry) => typeof entry === "string");
98984
99507
  }
98985
99508
  function commitInitEvaluator(document, createdValues) {
98986
- return (member, init, sourceValueId) => evaluateMemberInitializer({
99509
+ return (member, init, sourceValueId, genericEnv) => evaluateMemberInitializer({
99510
+ genericEnv,
98987
99511
  init,
98988
99512
  member,
98989
99513
  document,
@@ -99002,10 +99526,19 @@ function assertConstructedGraphReferencesResolve(args) {
99002
99526
  const valueIds = new Set(args.document.values.map((value) => value.id));
99003
99527
  for (const site of sites) {
99004
99528
  if ((site.init.compiled?.parameters.length ?? 2) > 2) continue;
99529
+ if (site.sourceValueId === void 0 && [
99530
+ ...referencedGenericParams(
99531
+ resolveMember2(site.member, args.document.members),
99532
+ args.document.members
99533
+ )
99534
+ ].some((paramId) => site.genericEnv.get(paramId)?.kind !== "member"))
99535
+ continue;
99005
99536
  const createdValues = [];
99006
99537
  const produced = evaluateMemberInitializer({
99007
99538
  init: site.init,
99008
99539
  member: site.member,
99540
+ genericEnv: site.genericEnv,
99541
+ sourceValueId: site.sourceValueId,
99009
99542
  document: args.document,
99010
99543
  createdValues
99011
99544
  });
@@ -99037,6 +99570,10 @@ function collectTouchedInitializerSites(args) {
99037
99570
  if (!isInitValueContent(member.defaultValue)) continue;
99038
99571
  if (!changedConstructor && !changedMemberIds.has(member.id)) continue;
99039
99572
  sites.push({
99573
+ genericEnv: resolveDeclaringClassGenericEnv(
99574
+ member.id,
99575
+ args.document.classes
99576
+ ),
99040
99577
  label: `Member "${member.name}" (${member.id})`,
99041
99578
  member,
99042
99579
  init: member.defaultValue.init
@@ -99064,6 +99601,8 @@ function collectTouchedInitializerSites(args) {
99064
99601
  );
99065
99602
  }
99066
99603
  sites.push({
99604
+ genericEnv: envFromStamp(row.genericBindings),
99605
+ sourceValueId: row.id,
99067
99606
  label: `Value "${row.id}"`,
99068
99607
  member,
99069
99608
  init: row.init
@@ -99080,11 +99619,19 @@ function assertProducedGraphLookupsResolve(args) {
99080
99619
  projectId: args.document.project.id,
99081
99620
  value: args.produced.value,
99082
99621
  classId: args.produced.classId,
99622
+ ...args.produced.genericBindings === void 0 ? {} : { genericBindings: { ...args.produced.genericBindings } },
99083
99623
  ...args.produced.constructorArgs === void 0 ? {} : { constructorArgs: args.produced.constructorArgs },
99084
99624
  ...args.produced.instanceConstructorId === void 0 ? {} : { instanceConstructorId: args.produced.instanceConstructorId },
99085
99625
  createdAt: 0,
99086
99626
  updatedAt: 0
99087
99627
  };
99628
+ if (args.produced.provisionalRootId !== void 0) {
99629
+ retargetInitializerRootValueIds(
99630
+ graphValues,
99631
+ args.produced.provisionalRootId,
99632
+ rootRow.id
99633
+ );
99634
+ }
99088
99635
  const ownerByValueId = resolveSemanticOwnerMembersForValues(
99089
99636
  { ...args.document, values: [...graphValues, rootRow] },
99090
99637
  new Set(args.createdValues.map((value) => value.id)),
@@ -99209,6 +99756,22 @@ function prepareServerOwnedValueInitializerBodies(args) {
99209
99756
  const currentValueById = new Map(
99210
99757
  args.document.values.map((value) => [value.id, value])
99211
99758
  );
99759
+ const compilationProjects = /* @__PURE__ */ new WeakMap();
99760
+ const compilationProjectFor = (document) => {
99761
+ const cached = compilationProjects.get(document);
99762
+ if (cached !== void 0) return cached;
99763
+ const compilationProject = cachedServerCompilationProject({
99764
+ project: document.project,
99765
+ projectFiles: document.projectFiles,
99766
+ members: document.members,
99767
+ classes: document.classes,
99768
+ enums: document.enums,
99769
+ interfaces: document.interfaces,
99770
+ constructors: document.constructors ?? []
99771
+ });
99772
+ compilationProjects.set(document, compilationProject);
99773
+ return compilationProject;
99774
+ };
99212
99775
  const compileOne = (document, row, documentValuesById) => {
99213
99776
  const member = ownerByValueId.get(row.id);
99214
99777
  if (member === void 0) {
@@ -99230,6 +99793,7 @@ function prepareServerOwnedValueInitializerBodies(args) {
99230
99793
  enums: document.enums,
99231
99794
  interfaces: document.interfaces,
99232
99795
  constructors: document.constructors ?? [],
99796
+ compilationProject: compilationProjectFor(document),
99233
99797
  member,
99234
99798
  valueRow: row,
99235
99799
  valueId: row.id,
@@ -99413,21 +99977,29 @@ function compileInlineDelegateConstructorArguments(args) {
99413
99977
  env,
99414
99978
  document.members
99415
99979
  );
99416
- compiled[argumentKey] = compileDelegateClosureValue(argument2.code, {
99417
- project: document.project,
99418
- projectFiles: document.projectFiles,
99419
- members: document.members,
99420
- classes: document.classes,
99421
- enums: document.enums,
99422
- interfaces: document.interfaces,
99423
- constructors: document.constructors ?? [],
99424
- variants: document.variants ?? [],
99425
- variantFolders: document.variantFolders ?? [],
99426
- thisClass,
99427
- returnTypeInfo: substituted.returnTypeInfo,
99428
- argumentTypes: substituted.argumentTypes,
99429
- name: `${settledMember.name} argument`
99430
- });
99980
+ try {
99981
+ compiled[argumentKey] = compileDelegateClosureValue(argument2.code, {
99982
+ project: document.project,
99983
+ projectFiles: document.projectFiles,
99984
+ members: document.members,
99985
+ classes: document.classes,
99986
+ enums: document.enums,
99987
+ interfaces: document.interfaces,
99988
+ constructors: document.constructors ?? [],
99989
+ variants: document.variants ?? [],
99990
+ variantFolders: document.variantFolders ?? [],
99991
+ thisClass,
99992
+ returnTypeInfo: substituted.returnTypeInfo,
99993
+ argumentTypes: substituted.argumentTypes,
99994
+ name: `${settledMember.name} argument`
99995
+ });
99996
+ } catch (error) {
99997
+ const detail = error instanceof Error ? error.message : String(error);
99998
+ throw new Error(
99999
+ `Value "${row.id}" (class "${schemaClass2.name}", root owner "${rootOwner?.name ?? "unknown"}") has a NeoDelegate closure for constructor parameter "${parameter4.name}" that does not compile: ${detail}`,
100000
+ { cause: error }
100001
+ );
100002
+ }
99431
100003
  }
99432
100004
  return compiled;
99433
100005
  }
@@ -99470,8 +100042,9 @@ function prepareServerOwnedDelegateValueBodies(args) {
99470
100042
  const compileOne = (document, row) => {
99471
100043
  const member = ownerByValueId.get(row.id);
99472
100044
  if (!isMemberDelegateBase(member)) {
100045
+ const placement = typeof row.containerId === "string" ? `container "${row.containerId}"` : `map key "${row.mapKey ?? "none"}"`;
99473
100046
  throw new Error(
99474
- `Value "${row.id}" carries a NeoDelegate closure but no NeoDelegate member in this project version stores it.`
100047
+ `Value "${row.id}" (${placement}, owner ${member === void 0 ? "unresolved" : `"${member.name}" of kind ${member.kind}`}) carries a NeoDelegate closure but no NeoDelegate member in this project version stores it: ${row.value.code.slice(0, 120)}`
99475
100048
  );
99476
100049
  }
99477
100050
  const rootOwner = rootOwnerByValueId.get(row.id);
@@ -117805,9 +118378,24 @@ function prepareServerPreparationChanges(args) {
117805
118378
  };
117806
118379
  const prepareFull = (discardedScopedAttempt) => {
117807
118380
  if (discardedScopedAttempt) args.resetReplayIds?.();
117808
- return prepareServerOwnedSchemaCommit(preparationArgs);
118381
+ const finish = startPerformanceSpan("server-preparation-full");
118382
+ try {
118383
+ return prepareServerOwnedSchemaCommit(preparationArgs);
118384
+ } finally {
118385
+ finish();
118386
+ }
118387
+ };
118388
+ const validate2 = (prepared) => {
118389
+ const finish = startPerformanceSpan("server-preparation-validate");
118390
+ try {
118391
+ assertProjectVersionWholeGraphWritesValid({
118392
+ document,
118393
+ changes: prepared
118394
+ });
118395
+ } finally {
118396
+ finish();
118397
+ }
117809
118398
  };
117810
- const validate2 = (prepared) => assertProjectVersionWholeGraphWritesValid({ document, changes: prepared });
117811
118399
  if (args.forceRecompile === true) {
117812
118400
  const prepared = prepareFull(false);
117813
118401
  validate2(prepared);
@@ -117865,9 +118453,15 @@ function prepareServerPreparationChanges(args) {
117865
118453
  document: scopedDocument,
117866
118454
  contentHashHeads: scopedHeads
117867
118455
  });
118456
+ let lastPass = null;
117868
118457
  for (; ; ) {
118458
+ const finishPass = startPerformanceSpan("server-preparation-pass", {
118459
+ pass: lastPass === null ? COMMIT_PREPARATION_PASS_ORDER[0] : nextCommitPreparationPass(lastPass) ?? "final"
118460
+ });
117869
118461
  const step = passes.next();
118462
+ finishPass();
117870
118463
  if (step.done) return step.value;
118464
+ lastPass = step.value.pass;
117871
118465
  const topUpRequest = planCommitPreparationInitialScope({
117872
118466
  pass: nextCommitPreparationPass(step.value.pass) ?? step.value.pass,
117873
118467
  document: scopedDocument,
@@ -118145,6 +118739,7 @@ var init_server_preparation_preflight = __esm({
118145
118739
  init_project_world_placement_bindings();
118146
118740
  init_build_default_member_value();
118147
118741
  init_packed_value_encoding();
118742
+ init_performance();
118148
118743
  init_projection();
118149
118744
  init_trusted_commit_verification();
118150
118745
  ServerPreparationPreflightError = class extends Error {
@@ -118561,7 +119156,31 @@ function compilePulledMemberInitializerBodyV4(document, memberId, compilationPro
118561
119156
  ...compilationProject === void 0 ? {} : { compilationProject }
118562
119157
  });
118563
119158
  }
119159
+ function samePulledRecords(left, right) {
119160
+ if (left === right) return true;
119161
+ if (left.size !== right.size) return false;
119162
+ for (const [key, record6] of left) {
119163
+ const other = right.get(key);
119164
+ if (other === void 0) return false;
119165
+ if (other === record6) continue;
119166
+ if (other.recordKind !== record6.recordKind || other.recordId !== record6.recordId || other.contentHash !== record6.contentHash || other.deleted !== record6.deleted || other.data !== record6.data) {
119167
+ return false;
119168
+ }
119169
+ }
119170
+ return true;
119171
+ }
118564
119172
  function readPulledProjectDocumentV4(records2) {
119173
+ for (const recent of recentPulledDocuments) {
119174
+ if (samePulledRecords(recent.records, records2)) return recent.document;
119175
+ }
119176
+ const document = readPulledProjectDocumentUncachedV4(records2);
119177
+ recentPulledDocuments.unshift({ records: records2, document });
119178
+ if (recentPulledDocuments.length > RECENT_PULLED_DOCUMENT_LIMIT) {
119179
+ recentPulledDocuments.pop();
119180
+ }
119181
+ return document;
119182
+ }
119183
+ function readPulledProjectDocumentUncachedV4(records2) {
118565
119184
  const raw = structuredClone(
118566
119185
  pulledProjectDocumentRaw(
118567
119186
  replayWorkspace(completeProspectiveRecordCreateEnvelopes(records2))
@@ -118674,7 +119293,7 @@ function replayWorkspace(records2) {
118674
119293
  state: { records: stateRecords }
118675
119294
  };
118676
119295
  }
118677
- var pulledBodyCompileSites, pulledInitializerCompilerStates, pulledMemberCompilationIndexes, pulledValueInitializerCompilationSites;
119296
+ var pulledBodyCompileSites, pulledInitializerCompilerStates, pulledMemberCompilationIndexes, pulledValueInitializerCompilationSites, recentPulledDocuments, RECENT_PULLED_DOCUMENT_LIMIT;
118678
119297
  var init_initializer_replay = __esm({
118679
119298
  "src/project-source/initializer-replay.ts"() {
118680
119299
  "use strict";
@@ -118693,6 +119312,8 @@ var init_initializer_replay = __esm({
118693
119312
  pulledInitializerCompilerStates = /* @__PURE__ */ new WeakMap();
118694
119313
  pulledMemberCompilationIndexes = /* @__PURE__ */ new WeakMap();
118695
119314
  pulledValueInitializerCompilationSites = /* @__PURE__ */ new WeakMap();
119315
+ recentPulledDocuments = [];
119316
+ RECENT_PULLED_DOCUMENT_LIMIT = 4;
118696
119317
  }
118697
119318
  });
118698
119319
 
@@ -129527,6 +130148,10 @@ function readProjectVersionTransactionStatus(value, transactionId) {
129527
130148
  value.preparationPhase ?? null,
129528
130149
  `Project transaction "${transactionId}" preparationPhase`
129529
130150
  ),
130151
+ preparationStep: readNullableString(
130152
+ value.preparationStep ?? null,
130153
+ `Project transaction "${transactionId}" preparationStep`
130154
+ ),
129530
130155
  preparationCompletedCount: readNullableCount(
129531
130156
  value.preparationCompletedCount ?? null,
129532
130157
  `Project transaction "${transactionId}" preparationCompletedCount`
@@ -129634,6 +130259,25 @@ function createPushProgressReporter(json) {
129634
130259
  }
129635
130260
  };
129636
130261
  }
130262
+ function isPreparationPass(name) {
130263
+ return Object.hasOwn(PREPARATION_PASS_LABELS, name);
130264
+ }
130265
+ function preparationStepLabel(step) {
130266
+ if (step.startsWith("pass:")) {
130267
+ const pass = step.slice("pass:".length);
130268
+ return isPreparationPass(pass) ? PREPARATION_PASS_LABELS[pass] : step;
130269
+ }
130270
+ switch (step) {
130271
+ case "document-read":
130272
+ return "reading records";
130273
+ case "validate":
130274
+ return "validating the graph";
130275
+ case "plan":
130276
+ return "planning writes";
130277
+ default:
130278
+ return step;
130279
+ }
130280
+ }
129637
130281
  function projectTransactionProgressLabel(event) {
129638
130282
  if (event.type === "push-progress") {
129639
130283
  return `Uploading files\u2026 ${event.completedFiles.toLocaleString("en-US")}/${event.totalFiles.toLocaleString("en-US")} (${formatByteProgress(event.completedBytes)}/${formatByteProgress(event.totalBytes)})`;
@@ -129647,7 +130291,8 @@ function projectTransactionProgressLabel(event) {
129647
130291
  return "Verifying uploaded files on server\u2026";
129648
130292
  }
129649
130293
  if (event.preparationPhase === "compile") {
129650
- return "Compiling affected NeoScript on server\u2026";
130294
+ const step = event.preparationStep ?? null;
130295
+ return step === null ? "Compiling affected NeoScript on server\u2026" : `Compiling affected NeoScript on server\u2026 ${preparationStepLabel(step)}`;
129651
130296
  }
129652
130297
  if (typeof event.preparationCompletedCount === "number" && typeof event.preparationTotalCount === "number" && typeof event.preparationUnit === "string") {
129653
130298
  const remaining = Math.max(
@@ -129690,6 +130335,7 @@ function progressEventFromAccepted(accepted) {
129690
130335
  errorCode: null,
129691
130336
  errorMessage: null,
129692
130337
  preparationPhase: null,
130338
+ preparationStep: null,
129693
130339
  preparationCompletedCount: null,
129694
130340
  preparationTotalCount: null,
129695
130341
  preparationUnit: null
@@ -129708,6 +130354,7 @@ function progressEventFromStatus(status) {
129708
130354
  errorCode: status.errorCode,
129709
130355
  errorMessage: status.errorMessage,
129710
130356
  preparationPhase: status.preparationPhase,
130357
+ preparationStep: status.preparationStep,
129711
130358
  preparationCompletedCount: status.preparationCompletedCount,
129712
130359
  preparationTotalCount: status.preparationTotalCount,
129713
130360
  preparationUnit: status.preparationUnit
@@ -132445,7 +133092,7 @@ function compileMigrationAction(context, migrationData, locator) {
132445
133092
  locator
132446
133093
  );
132447
133094
  }
132448
- var compileNSVoidBody2, compileNSFunction2, compileNSGetter2, compileNSSetter2, createNeoScriptCompilationProject2, ProjectTransactionInterruptedError, ProjectTransactionFailedError, LocalCandidateArtifactError, SERVER_MINTED_PUSH_RECORD_KINDS;
133095
+ var compileNSVoidBody2, compileNSFunction2, compileNSGetter2, compileNSSetter2, createNeoScriptCompilationProject2, ProjectTransactionInterruptedError, ProjectTransactionFailedError, PREPARATION_PASS_LABELS, LocalCandidateArtifactError, SERVER_MINTED_PUSH_RECORD_KINDS;
132449
133096
  var init_push = __esm({
132450
133097
  "src/commands/push.ts"() {
132451
133098
  "use strict";
@@ -132520,6 +133167,14 @@ var init_push = __esm({
132520
133167
  }
132521
133168
  status;
132522
133169
  };
133170
+ PREPARATION_PASS_LABELS = {
133171
+ "neo-script-recompile-targets": "selecting recompile targets",
133172
+ "authored-value-seeds": "seeding authored values",
133173
+ "variant-child-override-binding-members": "binding variant overrides",
133174
+ "prepared-instance-initializers": "materializing initializers",
133175
+ "delegate-value-bodies": "compiling delegate bodies",
133176
+ "variant-constructor-args": "checking variant constructor arguments"
133177
+ };
132523
133178
  LocalCandidateArtifactError = class extends Error {
132524
133179
  constructor(cause) {
132525
133180
  super(cause instanceof Error ? cause.message : String(cause));
@@ -133225,7 +133880,7 @@ import {
133225
133880
  rmSync as rmSync6,
133226
133881
  writeFileSync as writeFileSync9
133227
133882
  } from "node:fs";
133228
- import { dirname as dirname9, join as join12, relative as relative7, sep as sep7 } from "node:path";
133883
+ import { dirname as dirname8, join as join12, relative as relative7, sep as sep7 } from "node:path";
133229
133884
  function prepareWorkspaceResetV4(workspace, document, options = {}) {
133230
133885
  const emissionRecords = options.regenerateSourceNames ? regenerateDialogueSourceNamesV4(document.records) : document.records;
133231
133886
  const layoutWorkspace = workspaceForSourceLayoutV4(workspace, document);
@@ -133265,7 +133920,7 @@ function resetWorkspaceToProjectSourcesV4(workspace, document, options = {}) {
133265
133920
  }
133266
133921
  for (const file of emitted.files) {
133267
133922
  const absolute = resolveSourcePath(file.path);
133268
- mkdirSync9(dirname9(absolute), { recursive: true });
133923
+ mkdirSync9(dirname8(absolute), { recursive: true });
133269
133924
  if (existsSync10(absolute) && readFileSync14(absolute, "utf8") === file.content) {
133270
133925
  continue;
133271
133926
  }
@@ -133693,7 +134348,7 @@ import {
133693
134348
  existsSync as existsSync12,
133694
134349
  readFileSync as readFileSync15
133695
134350
  } from "node:fs";
133696
- import { dirname as dirname10 } from "node:path";
134351
+ import { dirname as dirname9 } from "node:path";
133697
134352
  async function runPull(workspace, options, progress = spinner("Checking local workspace\u2026")) {
133698
134353
  if (options.reset) {
133699
134354
  await runResetPull(workspace, progress);
@@ -134178,7 +134833,7 @@ async function finishFormat4Pull(args) {
134178
134833
  if (content === void 0) continue;
134179
134834
  const marked = conflictPaths.has(path) && detectConflictMarkers(content) !== null;
134180
134835
  if (marked) markedPaths.add(path);
134181
- mkdirSync10(dirname10(absolute), { recursive: true });
134836
+ mkdirSync10(dirname9(absolute), { recursive: true });
134182
134837
  if (existing !== null && !marked && !rewritePaths.has(path)) continue;
134183
134838
  if (existing !== content) {
134184
134839
  writeFileSync10(absolute, content, "utf8");
@@ -137722,7 +138377,7 @@ var init_registry2 = __esm({
137722
138377
  "schema-contract/registry.mjs"() {
137723
138378
  "use strict";
137724
138379
  PROJECT_SCHEMA_CONTRACT = Object.freeze({
137725
- cliVersion: "0.52.4",
138380
+ cliVersion: "0.53.0",
137726
138381
  projectFileUploadBatchSize: 32,
137727
138382
  documentRecords: {
137728
138383
  member: {
@@ -139159,7 +139814,7 @@ import {
139159
139814
  } from "node:fs";
139160
139815
  import {
139161
139816
  basename as basename3,
139162
- dirname as dirname11,
139817
+ dirname as dirname10,
139163
139818
  isAbsolute as isAbsolute3,
139164
139819
  join as join15,
139165
139820
  relative as relative8,
@@ -139451,7 +140106,7 @@ function cachedTestCandidate(workspace, inputFingerprint) {
139451
140106
  }
139452
140107
  if (typeof parsed.documentSha256 !== "string") return null;
139453
140108
  const documentJson = readFileSync18(
139454
- join15(dirname11(candidatePath), "document.json"),
140109
+ join15(dirname10(candidatePath), "document.json"),
139455
140110
  "utf8"
139456
140111
  );
139457
140112
  if (createHash11("sha256").update(documentJson).digest("hex") !== parsed.documentSha256) {
@@ -139472,7 +140127,7 @@ function cacheTestCandidate(workspace, inputFingerprint, candidate) {
139472
140127
  const documentJson = JSON.stringify(candidate.document);
139473
140128
  const documentSha256 = createHash11("sha256").update(documentJson).digest("hex");
139474
140129
  const candidatePath = testCandidateCachePath(workspace, inputFingerprint);
139475
- atomicWrite(join15(dirname11(candidatePath), "document.json"), documentJson);
140130
+ atomicWrite(join15(dirname10(candidatePath), "document.json"), documentJson);
139476
140131
  atomicWrite(
139477
140132
  candidatePath,
139478
140133
  JSON.stringify({
@@ -140316,7 +140971,7 @@ async function executeRegisteredSpec(registered, document, selected, timeoutMs,
140316
140971
  return { tests: results, failures: fileFailures, testDurationMs };
140317
140972
  }
140318
140973
  function atomicWrite(path, content) {
140319
- mkdirSync12(dirname11(path), { recursive: true });
140974
+ mkdirSync12(dirname10(path), { recursive: true });
140320
140975
  const temporary = `${path}.tmp-${String(process.pid)}-${randomUUID6()}`;
140321
140976
  writeFileSync12(temporary, content, "utf8");
140322
140977
  renameSync7(temporary, path);
@@ -144857,7 +145512,7 @@ import {
144857
145512
  unlinkSync,
144858
145513
  writeFileSync as writeFileSync14
144859
145514
  } from "node:fs";
144860
- import { dirname as dirname12, join as join18 } from "node:path";
145515
+ import { dirname as dirname11, join as join18 } from "node:path";
144861
145516
  function validatePath(path) {
144862
145517
  if (!/^Generated\/[a-zA-Z0-9_%./-]+\.g\.cs$/.test(path))
144863
145518
  throw new Error(`Invalid generated file path: ${path}`);
@@ -144980,7 +145635,7 @@ function writeUnityGeneratedFiles(directory, projectId, files) {
144980
145635
  if (content === null) {
144981
145636
  if (existsSync17(path)) unlinkSync(path);
144982
145637
  } else {
144983
- mkdirSync14(dirname12(path), { recursive: true });
145638
+ mkdirSync14(dirname11(path), { recursive: true });
144984
145639
  writeFileSync14(path, content);
144985
145640
  }
144986
145641
  };
@@ -145595,7 +146250,7 @@ There is no --keep-current: preserving current semantic state defines flatten.
145595
146250
  async function main() {
145596
146251
  const args = parseArgs(process.argv.slice(2));
145597
146252
  if (args.command === "--version") {
145598
- console.log("0.52.4");
146253
+ console.log("0.53.0");
145599
146254
  return;
145600
146255
  }
145601
146256
  if (args.command === null || args.command === "help" || args.command === "--help" || args.command === "-h") {