parseman 0.55.0 → 0.55.1

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.
@@ -6858,19 +6858,11 @@ var Encoder = class {
6858
6858
  nonCommittingChoiceSites = /* @__PURE__ */ new Set();
6859
6859
  failureRollbackCleanSites = /* @__PURE__ */ new Set();
6860
6860
  /**
6861
- * `hasSideWriter` memo for `failureNeedsRollback`, shared across every call
6862
- * for the lifetime of this `Encoder`. A cached entry is written only when
6863
- * `complete` is true, which means the answer is a path-independent fact
6864
- * about that combinator node — it does not depend on which root's traversal
6865
- * asked, only on the node's own reachable subgraph. Scoping the memo per call
6866
- * (as a local inside `failureNeedsRollback`) was correct but discarded that
6867
- * fact after every arm, so a grammar with many ordered-choice arms / optional
6868
- * / attempt sites re-walked the SAME shared rule graph from scratch for each
6869
- * site — O(sites × graph size) instead of O(graph size). Measured on the
6870
- * scss-parser grammar (composed CSS-base superset, the deepest/largest of the
6871
- * four grammars): 47-50s for one `compileRuleMap` with the per-call memo,
6872
- * versus the whole macro transform completing in under a second once this
6873
- * memo is hoisted here.
6861
+ * `reachesSideWriter`'s answers, shared by every `failureNeedsRollback` call
6862
+ * for the lifetime of this `Encoder`. Every entry is exact — it depends only on
6863
+ * the node's own reachable subgraph, never on which root's walk asked — so each
6864
+ * combinator is walked once per encode however many choice arms, optionals and
6865
+ * attempt sites reach it.
6874
6866
  */
6875
6867
  sideWriterMemo = /* @__PURE__ */ new Map();
6876
6868
  labels = void 0;
@@ -7303,63 +7295,96 @@ var Encoder = class {
7303
7295
  * writer census covers the side sinks that proof deliberately does not model:
7304
7296
  * fields, recovered errors, and interpreted scanners. Strict assemblies do
7305
7297
  * not run repeat recovery, but these rows can still publish through a caller's
7306
- * context. Cycles are safe to stop: revisiting the same combinator cannot
7307
- * discover a writer the first traversal did not already reach.
7298
+ * context.
7308
7299
  */
7309
7300
  failureNeedsRollback(p, autoNot) {
7310
7301
  const refName = p._ruleName;
7311
7302
  const winner = refName === void 0 ? void 0 : this.winners?.[refName];
7312
7303
  const root = winner !== void 0 && !winnerWrapsReference2(winner, p) ? winner : p;
7313
- const sideWriterMemo = this.sideWriterMemo;
7314
- const seen = /* @__PURE__ */ new Set();
7315
- const hasSideWriter = (current) => {
7316
- const cached = sideWriterMemo.get(current);
7317
- if (cached !== void 0) return { found: cached, complete: true };
7318
- if (seen.has(current)) return { found: false, complete: false };
7319
- seen.add(current);
7320
- const def = current._def;
7321
- let result;
7322
- switch (def.tag) {
7323
- case "field":
7324
- case "expect":
7325
- case "recover":
7326
- case "scanTo":
7327
- case "unknown":
7328
- result = { found: true, complete: true };
7329
- break;
7330
- case "lazy": {
7331
- const name = current._ruleName;
7332
- const resolvedWinner = name === void 0 ? void 0 : this.winners?.[name];
7333
- if (resolvedWinner !== void 0 && !winnerWrapsReference2(resolvedWinner, current)) {
7334
- result = hasSideWriter(resolvedWinner);
7335
- break;
7336
- }
7337
- try {
7338
- result = hasSideWriter(def.thunk());
7339
- } catch {
7340
- result = { found: true, complete: true };
7304
+ return mayLeavePartialCapture(root, /* @__PURE__ */ new Set(), true) || this.reachesSideWriter(root) || (autoNot?.length ?? 0) > 0 && capturesLeaf(root);
7305
+ }
7306
+ /**
7307
+ * Whether a field, recovered error, interpreted scanner or unresolvable shape
7308
+ * is reachable from `root` — the writer census of `failureNeedsRollback`.
7309
+ *
7310
+ * Reachability over a cyclic graph, decided with Tarjan's strongly connected
7311
+ * components so that every node the walk enters leaves with its exact answer
7312
+ * memoized: the members of one component reach each other, so they share one
7313
+ * answer, settled when the walk returns to the component's first node. A DFS
7314
+ * that instead cuts a cycle at its own ancestor path learns nothing it can
7315
+ * keep about a node whose walk hit the cut, and re-walks that node along
7316
+ * every path that reaches it — exponential over recursive value rules (linking
7317
+ * jess's SCSS grammar cost ~290G instructions). This walk enters each node
7318
+ * once per `Encoder`.
7319
+ */
7320
+ reachesSideWriter(root) {
7321
+ const memo = this.sideWriterMemo;
7322
+ const known = memo.get(root);
7323
+ if (known !== void 0) return known;
7324
+ const order = /* @__PURE__ */ new Map();
7325
+ const low = [];
7326
+ const found = [];
7327
+ const stack = [];
7328
+ const visit = (node2) => {
7329
+ const at = low.length;
7330
+ order.set(node2, at);
7331
+ low.push(at);
7332
+ found.push(false);
7333
+ stack.push(node2);
7334
+ const next = this.sideWriterSuccessors(node2);
7335
+ if (next === true) found[at] = true;
7336
+ else {
7337
+ for (const child of next) {
7338
+ const hit = memo.get(child);
7339
+ if (hit !== void 0) {
7340
+ if (hit) found[at] = true;
7341
+ continue;
7341
7342
  }
7342
- break;
7343
- }
7344
- default: {
7345
- let complete = true;
7346
- result = { found: false, complete: true };
7347
- for (const child of childrenOf2(def)) {
7348
- const childResult = hasSideWriter(child);
7349
- if (childResult.found) {
7350
- result = { found: true, complete: true };
7351
- break;
7352
- }
7353
- complete &&= childResult.complete;
7343
+ const seen = order.get(child);
7344
+ if (seen !== void 0) {
7345
+ if (seen < low[at]) low[at] = seen;
7346
+ continue;
7354
7347
  }
7355
- if (!result.found) result = { found: false, complete };
7348
+ const k = visit(child);
7349
+ if (low[k] < low[at]) low[at] = low[k];
7350
+ if (found[k]) found[at] = true;
7356
7351
  }
7357
7352
  }
7358
- seen.delete(current);
7359
- if (result.found || result.complete) sideWriterMemo.set(current, result.found);
7360
- return result;
7353
+ if (low[at] === at) {
7354
+ const answer = found[at];
7355
+ let member;
7356
+ do {
7357
+ member = stack.pop();
7358
+ memo.set(member, answer);
7359
+ } while (member !== node2);
7360
+ }
7361
+ return at;
7361
7362
  };
7362
- return mayLeavePartialCapture(root, /* @__PURE__ */ new Set(), true) || hasSideWriter(root).found || (autoNot?.length ?? 0) > 0 && capturesLeaf(root);
7363
+ return found[visit(root)];
7364
+ }
7365
+ /** The census's edges out of `node`, or `true` when `node` is itself a writer. */
7366
+ sideWriterSuccessors(node2) {
7367
+ const def = node2._def;
7368
+ switch (def.tag) {
7369
+ case "field":
7370
+ case "expect":
7371
+ case "recover":
7372
+ case "scanTo":
7373
+ case "unknown":
7374
+ return true;
7375
+ case "lazy": {
7376
+ const name = node2._ruleName;
7377
+ const winner = name === void 0 ? void 0 : this.winners?.[name];
7378
+ if (winner !== void 0 && !winnerWrapsReference2(winner, node2)) return [winner];
7379
+ try {
7380
+ return [def.thunk()];
7381
+ } catch {
7382
+ return true;
7383
+ }
7384
+ }
7385
+ default:
7386
+ return childrenOf2(def);
7387
+ }
7363
7388
  }
7364
7389
  /** A first set becomes a char class string, or −1 for `any`. */
7365
7390
  charClass(fs3) {
@@ -17327,7 +17352,7 @@ function fieldOptionsSrc(def) {
17327
17352
  }
17328
17353
 
17329
17354
  // src/version.ts
17330
- var PARSEMAN_VERSION = "0.55.0";
17355
+ var PARSEMAN_VERSION = "0.55.1";
17331
17356
 
17332
17357
  // src/compiler/compile-linkable-table.ts
17333
17358
  function isLocal(rule) {