Skip to content

fix(lsp): bound repeated resolver work without truncating large files - #2522

Open
DeusData wants to merge 4 commits into
mainfrom
fix/issue-1527-resolver-cost-v2
Open

DeusData wants to merge 4 commits into
mainfrom
fix/issue-1527-resolver-cost-v2

Conversation

@DeusData

@DeusData DeusData commented Oct 3, 2026 •

Copy link
Copy Markdown
Owner

Large Python and C/C++ files can lose later resolved calls when the per-file expression budget is exhausted. This ports the first resolver-cost change from #1527: cursor-based walks, scope and registry indexes, and C expression memoization reduce repeated work so that content-dependent budget can be removed.

Memo allocation/capacity failure and reaching the existing evaluator-depth bound now stop the walk and report distinct incomplete-file errors. Failed walks preserve prior completed output; Python also restores synthetic-call counts and prior dedup-row metadata using a fixed-size snapshot. Failure propagates through raw, preprocessed (C), fallback, prebuilt, batch, and sequential/parallel pipeline paths. Parallel workers pass errors to the coordinator.

Scope-index recovery sizes from all existing bindings, preventing a full-table loop after earlier allocation failure. Python class-name collection fails closed when a name cannot be copied. Deterministic work-count coverage runs in the normal Python suite, including PR jobs that skip performance suites; timing remains diagnostic. Existing #1277 field-array copy-on-write and both pipeline regressions are preserved.

The depth contract intentionally changes: reaching the unchanged bound reports an incomplete refinement instead of silently continuing with unknown types. That prevents repeated uncached receiver work after removal of the old work budget; no replacement work cap is introduced.

Base: main. Depends on #2498; this branch includes that prerequisite. Later resolver-stack patches are not included. Refs #1527.

Parallel resolver error slots use matching tracked allocation and cleanup. The existing raw-allocation allowances are unchanged.

Validation: source review, changed-range formatting, exact 21-file scope, git diff --check, and byte-for-byte preservation of seven #1277 functions passed. Local builds, runtime tests, revert proofs, local CI, and performance measurements were explicitly waived and remain UNRUN. No current performance result or universal complexity bound is claimed.

@DeusData

DeusData commented Oct 3, 2026

Copy link
Copy Markdown
Owner Author

Checkpoint and handover (2026-10-03 UTC)

Published head: dcdcbc7cd12a8464460799f60e02aa24ed5c5868. The remote head was verified.

The resolver-cost fix for #1527 spans 21 files and adds 21 tests, all unrun locally. The latest allocator correction uses checked sizing and tracked allocation/free for the parallel error array; the allocation baseline is unchanged. Memo/scope failure propagation was reviewed. This is the prerequisite for #2525 and the subsequent Python stack.

Hosted snapshot at 2026-10-03 21:54:17 UTC: 3 queued. Confirm the required checks on this exact head before treating it as ready.

No additional local build, test, lint, sanitizer, benchmark or CI runs were performed at this checkpoint, as requested. Earlier executed evidence remains historical; prepared tests and the newer source-reviewed changes must still be validated by the hosted gate.

The campaign is paused at the maintainer’s request. Local monitoring has stopped; hosted jobs remain running. No merge was performed. Thanks for reviewing this change.

Memoize C expression evaluation, index repeated scope and registry queries,
and report incomplete walks explicitly on memo or depth failure.

Refs #1527

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Use tracked zeroed storage for the parallel LSP failure array and
release it with the matching memory class after worker joins.
Keep existing raw-allocation allowances unchanged.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
…ds the cross walk

The cross-stage memo and depth failure cases defined S and called s.m()
in the same file. The per-file LSP already resolves that call, and the
parallel driver skips the cross-file LSP walk for a file whose call sites
are all resolved, so the CBM_TEST_*_FAIL_STAGE=cross seam never fired on
the parallel path and the four parallel cases saw no file error.

Move S into a second file (memo_def.cpp / memo_def.py, imported from
Python), so run() holds a call only the cross walk can resolve. The
assertions are unchanged.

With the corrected fixture all 17 issue-1527 pipeline cases pass in 3 of
3 runs; removing the parallel failure capture in pass_parallel.c turns
exactly the four parallel cross cases RED again.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
The depth guard of the C/C++ and Python expression evaluators
(C_EVAL_DEPTH_LIMIT, PY_LSP_MAX_EVAL_DEPTH = 256) now reports a sticky
per-file failure that stops the walk and drops every LSP resolution of the
file. Both evaluators recursed once per chain link, so a 300-term sum or a
C++ fluent chain of ~130 calls counted as 256 levels of nesting: one long
expression cost its whole file every LSP call edge. A chain's length is not
nesting, and the guard must not decide graph content for it.

c_eval_expr_type and py_eval_expr_type now first walk down the chain
operands below the node (the operand the evaluator evaluates first and
derives the link's type from), then evaluate them innermost first at the
caller's depth, keeping pending links on a small arena-owned stack in the
context that nested evaluations share. When a link is evaluated, its chain
operand is already memoized, so the evaluator's own recursive call into it
is a memo hit one frame deep. Every node is still evaluated by the
unchanged inner evaluator, evaluation does not mutate scope within one
outermost call, and only operands the recursion itself evaluates are
pre-evaluated, so the types are exactly the recursive ones.

No longer counted as depth (any length):
- C/C++: binary operators other than == != < > <= >= && || (those yield
  bool without evaluating an operand), member access (. and ->), calls on
  a non-name callee, subscripts, conditional consequences, parentheses,
  comma lists.
- Python: binary operators, attribute access, calls on obj.m(...), f()()
  and (expr)(), subscripts, the else branch of a conditional, parentheses.

Still counted, unchanged guard and reporting (genuine nesting):
- C/C++: call arguments used for template argument deduction,
  std::move/std::forward operands, unary, pointer and update operands,
  assignment left sides, lambda return expressions, co_await, fold and
  _Generic operands.
- Python: tuple/list/set elements, dictionary keys and values, the true
  branch of a conditional, await operands, next()/iter()/assert_type()
  arguments, called lambdas.

Proof:
- New c_lsp and py_lsp tests build chains of 300, 2,000 and 20,000 terms
  (a binary + chain and a .a() receiver chain) next to an unrelated s.m().
  On the previous evaluator, and with this change reverted, all four fail
  at 300 terms: the depth error is recorded and the file resolves 0 calls
  (C++ per-file; Python per-file and through the cross-file dispatch).
  With it, every size records no error, resolves run -> S.m, and the
  chain's result type resolves x.done() / the final .done().
- Real input, isolated cache, before and after:
  redis 4f20cb48 (C): 36,876 CALLS, 10,699 LSP-resolved;
  django fb113765 (Python): 60,123 CALLS, 25,153 LSP-resolved.
  Identical CALLS edge sets on both (0 lost, 0 gained, 0 strategy
  changes), 0 files with an LSP error before and after, wall time
  unchanged (redis 5.5 s, django 9.1-10.2 s both ways).

Refs #1527

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
@DeusData
DeusData force-pushed the fix/issue-1527-resolver-cost-v2 branch from dcdcbc7 to 1c391bd Compare October 4, 2026 18:28

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant