Skip to content

refactor(lsp): one engine table for the cross-file pass; declared-type rows for more languages - #3040

Merged
DeusData merged 3 commits into
mainfrom
refactor/lsp-engine-table-type-scope-rows
Nov 19, 2026
Merged

DeusData merged 3 commits into
mainfrom
refactor/lsp-engine-table-type-scope-rows

Conversation

@DeusData

Copy link
Copy Markdown
Owner

What changes

Two commits. Neither changes a graph: every node, edge and property is the same before and after.

1. One table of engines in the cross-file pass. pass_lsp_cross.c decided per language in five places: which shared registry to build (the same list written three times, in the sequential pass, pipeline.c and pipeline_incremental.c), which registry a language reads, whether a language has a cross-file walk at all, how to walk one file against a registry, and how to walk one file over a definition list. They are now one static table, pxc_engines[], with one row per type-aware engine: Go, Python, C/C++/CUDA, C#, TypeScript/JavaScript/TSX, Java, PHP, Kotlin and Rust.

A row names the languages it serves, the shared registry it builds once over all definitions, its walk of one file against that registry, its walk of one file over a definition list, and a flag for each special case that exists today (Rust's registry is built on first use and its definition list is never filtered by module; Go and Python read declared-type identities). Each engine keeps its present calls exactly, in a pair of small wrappers beside the table. An engine is added by adding a row; a special case becomes a flag in the row, never a branch in the dispatch.

2. The declared-type step can describe more languages. #3034 resolves each declared type once, in the scope of the file that wrote it, for Go and Python. The other engines' languages need more than "own module, then the import map", so the per-language row of that step (type_scope.c) gains the fields they will use. No language is switched on here:

Field What it describes
scope_source where a bare name is looked up: the module and its imports (today's path), an include closure the caller supplies, or the namespaces enclosing the definition, innermost first
colon_paths a::B is one spelling of a qualified name; a leading :: gets no answer
open_imports on-demand imports: a name left unbound by the module and the named imports is looked up in each open package and answered only when exactly one has it
implicit_external a predicate for names the language binds without an import (such as java.lang): such a name, unbound otherwise, gets no answer instead of a guess
nested_types a bare name written inside a type is first that type's member, then each enclosing type's, before the module

It also adds one table per calling file (each local name the file's named imports bind, with the type it resolves to in that file) and replaces the two per-language folds of fields into their owner type (struct fields for Go and C, annotated fields for Python) with one fold driven by the engine row.

Go's and Python's rows state the values they had implicitly, and nothing reads the new fields or the calling-file table yet. The first user is the Java engine, in a following pull request.

Why

Nine engines each qualify a declared type name in their own way; #3034 moved two of them, Go and Python, onto one shared step. This pull request is the place where the other seven attach: one row in each of the two tables, instead of a new branch in each of those places.

How "no graph change" was checked

  • Graph identity, per commit. Nodes with properties and every edge type with properties, compared on 14 pinned open-source repositories (one or two per engine) and a Perl fixture, on both resolver routes (one worker = the sequential pass; default workers = the parallel resolver): 30 of 30 pairs identical. The base binary compared with itself gives 30 of 30 as well, so a difference would have been this change's.
  • All repositories. Scored on 86 pinned open-source repositories against compiler-resolved call sites (SCIP indexes): the same pairs found and the same judged edges on every one; the edge-by-edge view lists no repository as changed. (Measured on these two commits on top of feat(lsp): resolve declared types in the scope that wrote them (Go, Python) #3034's head. The rebase onto its merge commit is conflict-free, and the rebased binary was compared again with main 33f2973a6 in the graph-identity check above: 30 of 30 pairs identical.)
  • Stored engine surfaces. The per-file rows the engines persist are byte-identical, row for row, on seven repositories (1,460 files on helm, 1,262 on cli).
  • Incremental against full. Four one-file edits (Go, Java, TypeScript, Python), covering the per-file walk of a small closure, the shared registries of a large closure, and a declined repair: the reindexed graph and the fresh full graph each equal the base's.
  • Suites. 34 suites under ASan, 4,853 tests passed; after the rebase onto main the affected suites again (type_scope, parallel, pipeline, incremental, index_format and the engine suites), 2,008 passed.

Cost

Worker pass times, medians of 8 alternating runs: on helm with one worker the cross-file pass takes 282 ms before, 286 ms after the first commit and 291 ms after the second, with overlapping ranges; with default workers and on flask the times are the same to within 1 ms. Memory: the table is static; one pointer array per run grows from 7 to 16 entries; nothing is added per definition or per call. The Python field fold no longer keeps 16 bytes per field and per definition in the collector's arena.

One visible change

The profile log line lsp_cross_prepare.builders (six fixed name and time pairs) becomes one line per engine with a shared registry: lsp_cross_prepare.builder engine=<name> elapsed_ms=<n>. Nothing in the repository reads it.

Tests

  • type_scope_engine_table_rows pins the engine table: the thirteen languages that had a cross-file walk and no other, the registries built eagerly and their order, the rows shared by the C family and by the TypeScript family, and declared-type identities wanted exactly where the declared-type table has a row.
  • One test per new field, each with the flag-off case and a negative partner in the same test: type_scope_open_imports_one_answer_or_none, type_scope_implicit_external_scope_gets_none, type_scope_nested_types_innermost_first, type_scope_include_closure_source, type_scope_lexical_nesting_source, type_scope_colon_paths.
  • type_scope_calling_file_imports, type_scope_calling_file_scope_per_engine, type_scope_field_fold_rows.
  • type_scope_nested_and_open_work_grow_linearly: counted work doubles when the input doubles (x2.00 to x2.05).
  • tests/test_parallel.c: the resolve harness builds the C# and C registries through the table (the C line, added by fix(extract): read a CRLF line splice in C-family strings as LF does (#1546) #2983, wrote the struct field the table replaces).

The cross-file pass decided per language in five places: which shared
registry to build (three copies of the same six calls, in the sequential
driver, pipeline.c and pipeline_incremental.c), which registry a language
reads (an inline switch), whether a language has a cross-file walk (a
switch), how to walk one file against a registry (a switch in the
dispatch, with Rust's lazy registry and TypeScript's own def filter as
special paths of its fallback) and how to walk one file over a def list
(a switch in cbm_pxc_run_one_with_php_bindings, plus cbm_pxc_run_one_ts).

They are now one static table, one row per engine (Go, Python, the C
family, C#, the TypeScript family, Java, PHP, Kotlin, Rust): the
languages it serves, its shared-registry builder, whether that registry
is lazy (Rust) and read without an overlay, its walk against a registry,
its per-file walk, whether its defs skip the module filter (Rust), and
whether it reads declared-type identities (Go, Python). Each engine's two
walk wrappers keep its present calls exactly. CBMCrossLspRegistries is one
slot per row; the three drivers build through the table. An engine plugs
in by adding its row; the dispatch no longer names a language.

Behaviour is unchanged: on one development repository per engine
language (Go, Python, TypeScript/JavaScript/TSX, Rust, Ruby, Java, C#,
PHP, Kotlin, C, C++) and a Perl fixture, the graph of the base and of this
change are identical (nodes, edges and properties) with one worker and
with the default worker count. The per-engine log line
lsp_cross_prepare.builder replaces the fixed six-pair
lsp_cross_prepare.builders line.

Test: type_scope_engine_table_rows pins the rows: the thirteen languages
that had a walk and no other, the shared registries built eagerly (go
python c cs ts java, in that order), the shared rows of the C and
TypeScript families, and identities wanted exactly where the declared-type
step has a row.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
Everything the remaining engine slices need from the shared step lands
at once, so each of them appends rows and touches no shared code:

Type-scope rows state every field. New ones, unused by the Go and Python
rows (their graphs are unchanged):
- scope_source: MODULE_IMPORTS (the own module, then the import map; Go,
  Python), INCLUDE_CLOSURE (a caller-supplied visible() answers a name:
  C and C++ once the include closure exists) or LEXICAL_NESTING (the
  namespaces of the file enclosing the definition, innermost first: Ruby
  constants).
- colon_paths: `a::B` is one spelling whose QN joins with `.`; a leading
  `::` gets no identity.
- open_imports: import-map entries under the key "*" name open packages;
  a name nothing else binds is the one type of that name across them, or
  none.
- implicit_external: a predicate for the language's implicit external
  scope (java.lang and the like); a name it declares gets no identity.
- nested_types: a bare name written inside a type is first that type's
  member type, then each enclosing type's, before the module; member
  types of supertypes are not seen (a possible answer, not a proven one).

The calling file's own table, cbm_type_scope_file_imports: each local its
named imports bind, with the verified type identity, from the same scope
the collector attaches with. A walk reaches it through
cbm_pxc_file_scope(f->ctx, ...); every driver now hands the walks the
pipeline context in CBMCrossLspRegistries.ctx (behaviour unchanged: a
struct with no registry built is read like none).

One row-driven field fold (pxc_fold_fields) replaces
pxc_fold_struct_fields and pxc_fold_py_field_types. The engine row says
where fields come from ("Field" definitions with raw types: Go, C, C++;
annotations resolved to project QNs: Python), the owner label, that only
the last owner of a QN takes them (Python) and which of the row's
languages fold (C and C++, not CUDA: kept as before). One hash of the
owners, one pass over the fields, one chain per owner.

Tests: each new field through the public step API with a hand-made row,
each with its negative partner; the calling-file table (Python, Go, open
key, a star import); cbm_pxc_file_scope per engine; counted work of the
nested and open lookups at two sizes; the fold's rows (Go and C fold in
declaration order, CUDA none). Go and Python graphs are identical to
before on their development repositories, as are C and C++.

Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
@DeusData
DeusData force-pushed the refactor/lsp-engine-table-type-scope-rows branch from 3c6d676 to 68d9470 Compare November 18, 2026 23:18
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
@DeusData
DeusData merged commit 3a8f82b into main Nov 19, 2026
26 of 27 checks passed
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