Repository navigation
refactor(lsp): one engine table for the cross-file pass; declared-type rows for more languages - #3040
Merged
Merged
Conversation
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
force-pushed
the
refactor/lsp-engine-table-type-scope-rows
branch
from
November 18, 2026 23:18
3c6d676 to
68d9470
Compare
Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.cdecided per language in five places: which shared registry to build (the same list written three times, in the sequential pass,pipeline.candpipeline_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:scope_sourcecolon_pathsa::Bis one spelling of a qualified name; a leading::gets no answeropen_importsimplicit_externaljava.lang): such a name, unbound otherwise, gets no answer instead of a guessnested_typesIt 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
33f2973a6in the graph-identity check above: 30 of 30 pairs identical.)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_rowspins 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.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).