Skip to content

feat(kernel): the native Rust kernel reads a Rust tree with errors itself - #3621

Merged
colbymchenry merged 1 commit into
mainfrom
claude/kernel-error-trees-rust
Dec 4, 2026
Merged

colbymchenry merged 1 commit into
mainfrom
claude/kernel-error-trees-rust

Conversation

@colbymchenry

Copy link
Copy Markdown
Owner

What this does

Rust is the next language whose files with syntax errors the native Rust kernel reads itself. rust moves to policy Ascii: the grammar's scanner asks the platform about characters, so only an all-ASCII file is known to parse to the reference's own tree. Such a file with an error is parsed again as UTF-16 and walked natively; a file with an error and a character outside ASCII still defers. On seven real code bases 2,523 of the 2,589 files with an error (97%) are now read natively.

What the walker needed (the table is in docs/design/kernel-error-trees.md, Rust's section):

  • the reference's parse_error warning for a tree with an error and no symbol;
  • an impl of a zero-width missing type has no receiver (the reference tests the text for truthiness); the walker is split into a function reader and a method reader as the reference is, so a nameless fn in a trait is the reference's <anonymous> method and a nameless one elsewhere has its body walked;
  • a fn written in a body with an empty name is no name;
  • a supertrait bound whose type is a zero-width missing node makes no extends reference (found by the review);
  • JavaScript's trim(), \s and split('::') wherever the reference uses them.

Three differences on clean files, there before this change, are fixed with it: a block written right after a value-reference scope (a file-level let X = { ... };) is part of that scope, as in the reference; a path value ending in a raw identifier with a capital (m::r#Foo); and a U+0085 or U+FEFF in a comment inside a chained call's inner callee. None of the three occurs in any repository compared.

No routing change (Rust was already on the kernel by default), no other walker and no shared helper changed, no wasm changed, scripts/regression/expected.json unchanged.

Review

Written by a coding agent, then read against the reference before this pull request was opened (a second model): the Rust walker against languages/rust.ts and the paths of the generic extractor a Rust node reaches (the ladder of node kinds, functions and methods, the body walker, value references and their scope, static member references, the generic variable fallback), and the lines this change touches in the macro reader. One finding, fixed before this was pushed: a supertrait bound whose type is a zero-width missing node behind a higher-ranked for<...> (trait X: for<'a> m::Y<'a> + for<'b> {}) made an extends reference with an empty name, where the reference, which tests the name for truthiness, makes none. Three such shapes are pinned. The stack's Windows run then found one of this change's own tests failing there: its repair of a fixture's text matched a line end, and a CRLF checkout left the text broken. The repair no longer depends on line ends, and the test now fails by name when a repair matches nothing; the engine was not involved.

The change was then put on main as it stands after #3611 and #3619 by the reviewer (the changelog and the document merged; everything else is the reviewed commit's, byte for byte).

Validation

macOS (Apple silicon), the coding agent's runs (on its own base): cargo test --release 99 passed; the kernel suites 31 files, 870 passed, 1 skipped; regression gate PASS (173 projects, 171 growth cases, expected.json unchanged). Real code in full objects and emission order (ripgrep, tokio, diesel, rust-analyzer, wasm-bindgen, actix-web, and the Rust compiler's parser, macro and async tests): 8,146 files, 2,523 read from a tree with an error, 66 deferred (a character outside ASCII), 0 differences. Damaged (--damage 3, two seeds): 48,882 texts. Scrambled (--scramble 10, two seeds): 162,940 texts. Random-token and hand-built: 62,193 texts, every tree equal to the wasm tree. 0 differences, 0 failures, 0 timeouts. compare-graphs.mjs against the previous build, both parsers: 31 of 31 identical each way, and the seven Rust repositories 7 of 7. Speed (medians of seven interleaved rounds): wasm-bindgen 2,000 ms against 2,859 ms for the reference and 2,830 ms for the previous kernel build; the compiler's tests 318 / 641 / 379 ms; rust-analyzer 1,641 / 3,308 / 1,770 ms; clean repositories unchanged (ripgrep 222 → 223 ms, tokio 696 → 696 ms); broken files of 0.3 / 1.2 / 3.9 MB 84 / 335 / 1,079 ms against 155 / 563 / 1,829 ms.

The reviewer's own build and repositories the runs above did not use (serde, axum, clap, regex, syn, rustfmt: 3,377 files), macOS, on the fixed commit: random-token and hand-built texts (484 of them built from the reading) 100,535 over two seeds, every tree equal to the wasm tree where read; --damage 3, two seeds, 25,953 texts, 8,361 from a tree with an error; --scramble 8, two seeds, 27,854 compares on a tree with an error; 0 differences in all three. Whole-project graphs against the previous build, one repository per language and five of the six above: 31 of 31 identical. The sixth, rustfmt, could not be indexed by either build: its import tests sent the resolver's use lookup into a loop that never ended, which this review run found and #3611 fixed first.

The stack: This change was checked as the first of three changes stacked on main in the order they land (Rust, CFScript and CFQuery, the TypeScript and JavaScript family): each layer on its own tree, and the whole on the head of the stack. The regression gate, the sweeps against the reference, the speeds and, on Windows, the kernel's build and its own tests were measured on the stack as first built. After them its head changed in test files only: the two test corrections the reviews of the Rust change and of the TypeScript and JavaScript change name, and #3619 on main (the query pool's test file, which this stack's full Windows run had shown failing there when run on its own). No source file differs, so those measurements stand; on the commits that land, each layer's own tree was run again on macOS and every suite on the three platforms. On this change's own tree, macOS: the build and the kernel build are clean; cargo test --release 99 passed; the kernel suites 32 files, 876 tests passed. On the head of the stack, macOS: the regression gate (npm run gate) PASS (174 projects, 171 growth cases, expected.json unchanged); the full suite 1,031 files passed and 2 skipped, 13,818 tests passed, 0 failed. Rust against the reference there, full objects in emission order: 30,258 random-token and hand-built texts (the reviewer's 484 among them), every tree equal to the wasm tree where read, 0 differences; kernel-parity.mjs --damage 1 --scramble 4 over axum, regex, serde and syn, 3,522 compares, 2,170 of them on a tree with an error, 0 differences; the same sweep over one repository of each language landed before (Python, Java, Go, C, C++, Objective-C, Pascal, Solidity, Nix, COBOL, Erlang), 0 differences. Speed on macOS, whole folders on the engine's path, the default route against the reference (medians of seven interleaved rounds, node counts equal): serde 268 → 135 ms, regex 1,013 → 559 ms, syn 551 → 280 ms, axum 332 → 171 ms, clap 646 → 406 ms (1.59 to 1.98 times the reference's speed).

Windows 11 (ARM64, MSVC), the head of the stack, with the host quiet: the kernel builds; cargo test --release 99 passed; the kernel suites 31 files, 966 tests passed; the error-tree test file and the languages' own test files 87 files, 1,194 tests passed. Rust against the reference in emission order: axum, regex, serde and syn with damage, 3,462 texts, 1,032 from a tree with an error, and 30,258 random-token and hand-built texts; 0 differences. kernel-parity.mjs --damage 1 --scramble 4 with one seed gives macOS's counts line for line on all four repositories. Speed there, the default route against the reference (medians of three passes, arms in turn, twice): serde 316 → 159 ms, regex 1,221 → 617 ms, syn 718 → 340 ms, axum 419 → 198 ms (1.98 to 2.12 times). The full suite: 1,028 files passed and 5 skipped, 13,719 tests passed, 0 failed; query-pool.test.ts on its own, three runs, 51 of 51 tests each.

Linux (Docker, arm64, node:22-bookworm), the head of the stack: the kernel builds; cargo test --release 99 passed; the kernel suites 31 files, 966 tests passed; the error-tree and function-pointer test files 452 tests passed. kernel-parity.mjs --damage 1 --scramble 4 with one seed gives macOS's counts line for line on axum, regex, serde and syn, and on the 23 repositories of the languages landed before; 0 differences. The full suite: 1,031 files passed and 2 skipped, 13,808 tests passed, 0 failed. Speed was not measured on Linux.

🤖 Generated with Claude Code

…self

`rust` moves from policy Defer to Ascii in tree::policy_for: tree-sitter-rust's
scanner asks the platform about characters, so an all-ASCII Rust file whose
tree has an error is parsed again as UTF-16, the reference's own tree, and
walked natively; a file with an error and a character outside ASCII still
defers with the ordinary defer: message.

What the walker (rustlang.rs) needed, read function by function against
languages/rust.ts, languages/rust-macro-calls.ts (token by token) and every
path of tree-sitter.ts, function-ref.ts and tree-sitter-helpers.ts a Rust node
reaches:
- the reference's parse warning for a tree with an error and no symbol;
- an impl of a zero-width MISSING type: getReceiverType gives '', which is
  falsy, so no receiver; the walker is now split into extract_function and
  extract_method as the reference has them (a nameless fn in a trait is the
  reference's `<anonymous>` method, a nameless one elsewhere walks its body);
- a fn written in a body with an empty name is no name: walked as any node;
- a supertrait bound whose type is a zero-width MISSING node (a plain or a
  higher-ranked bound, `trait T: for<'a> {}`) makes no `extends` reference:
  the reference's `if (typeName && posNode)` (found by the review);
- clean trees, differing before this change: a file-level `let X = { ... };`
  (the value-reference scope takes in its identifier's next named sibling
  block, as Go's and Java's walkers already do); a path value ending in a raw
  identifier with a capital, `m::r#Foo` (`/^(?:r#)?[a-z_]/` holds for it); a
  U+0085 or U+FEFF in a comment inside a chained call's inner callee
  (JavaScript's `\s`);
- JavaScript's trim(), `\s` and split('::') at every site the reference uses
  them; the reference's fallbacks the grammar never takes (an assignment
  without `left`, an enum variant without `name`, a direct `async` child,
  `nil_literal`, `enum_member` class-like, no `union:` value-target scope).
Shapes left deferring: a Rust file with a parse error and a character outside
ASCII (policy). No other walker and no shared helper changed.

Gates (macOS, Apple silicon):
- build, kernel build clean; cargo test --release 99 passed; the kernel
  suites 31 files, 870 passed, 1 skipped; clippy on rustlang.rs reports four
  lints in lines this change does not touch (there on the base too).
- Real code, full objects in emission order: ripgrep 105 files (0 read from
  an error tree), tokio 816 (0), diesel 984 (4), rust-analyzer 1,518 (267, 15
  deferred), wasm-bindgen 2,462 (1,577, 18 deferred), actix-web 329 (0), the
  compiler's tests/ui parser, macros and async-await 1,932 (675, 33
  deferred): 0 differences, 0 kernel failures; 2,523 of the 2,589 files with
  an error (97%) are now read natively. kernel-parity.mjs also reports one
  clean file of the compiler's tests (an expression nested 1,800 calls deep)
  on which the reference's JavaScript stack overflows: the same on the base.
- Damaged: --damage 3, seeds 101 and 202, 48,882 texts, 28,731 read from an
  error tree, 6,470 deferred by policy; scrambled: --scramble 10, seeds 303
  and 404, 162,940 texts, 90,975 read from an error tree; 0 differences, 0
  failures, 0 timeouts, but damaged copies of the file above (3 texts) on
  which the reference's stack overflows. Hand-built and random-token texts
  (lang-adversarial with a Rust profile), 62,193 over two seeds: every tree
  equal to the wasm tree, 0 differences. Crash check 7,893 cases (Rust, Go and
  C++ files as Rust), 0 crashes, 0 other errors.
- Neutral: compare-graphs against the base build, one repository per kernel
  language, four CFML repositories and the test fixtures: 31 of 31 identical
  with the kernel and with CODEGRAPH_KERNEL=0; the seven Rust repositories
  with the kernel: 7 of 7 identical; the every-language sweep: the same
  counts and deferrals per language as the base build.
- Speed (medians of seven interleaved rounds, a shared machine): wasm-bindgen
  2,000 ms against the reference's 2,859 and the base kernel arm's 2,830; the
  compiler's tests 318 / 641 / 379 ms; rust-analyzer 1,641 / 3,308 / 1,770
  ms; clean path ripgrep 221.8 -> 222.7 ms, tokio 696.2 -> 695.7 ms; broken
  large files at 0.3 / 1.2 / 3.9 MB 84 / 335 / 1,079 ms (functions), 74 /
  294 / 960 (methods), 89 / 356 / 1,146 (one match ending in an error)
  against the reference's 155 / 563 / 1,829, 145 / 526 / 1,700 and 135 / 525
  / 1,730: linear in the size.
- Regression gate (npm run gate): PASS, 173 projects, 171 growth cases,
  expected.json unchanged.

Review (a second model, before this was pushed): the Rust walker against
languages/rust.ts and the paths of the generic extractor a Rust node reaches
(the ladder of node kinds, functions and methods, the body walker, value
references and their scope, static member references, the generic variable
fallback), and the lines this change touches in the macro reader. One finding,
fixed before this was pushed: a supertrait bound whose type is a zero-width
missing node behind a higher-ranked for<...> (trait X: for<'a> m::Y<'a> +
for<'b> {}) made an extends reference with an empty name, where the reference,
which tests the name for truthiness, makes none. Three such shapes are pinned.
The stack's Windows run then found one of this change's own tests failing
there: its repair of a fixture's text matched a line end, and a CRLF checkout
left the text broken. The repair no longer depends on line ends, and the test
now fails by name when a repair matches nothing; the engine was not involved.

The reviewer's own build and repositories the runs above did not use (serde,
axum, clap, regex, syn, rustfmt: 3,377 files), macOS, on the fixed commit:
random-token and hand-built texts (484 of them built from the reading) 100,535
over two seeds, every tree equal to the wasm tree where read; --damage 3, two
seeds, 25,953 texts, 8,361 from a tree with an error; --scramble 8, two seeds,
27,854 compares on a tree with an error; 0 differences in all three.
Whole-project graphs against the previous build, one repository per language
and five of the six above: 31 of 31 identical. The sixth, rustfmt, could not
be indexed by either build: its import tests sent the resolver's use lookup
into a loop that never ended, which this review run found and #3611 fixed
first.

The change was then put on main as it stands after #3611 and #3619 by the
reviewer (the changelog and the document merged; everything else is the
reviewed commit's, byte for byte).

This change was checked as the first of three changes stacked on main in the
order they land (Rust, CFScript and CFQuery, the TypeScript and JavaScript
family): each layer on its own tree, and the whole on the head of the stack.
The regression gate, the sweeps against the reference, the speeds and, on
Windows, the kernel's build and its own tests were measured on the stack as
first built. After them its head changed in test files only: the two test
corrections the reviews of the Rust change and of the TypeScript and
JavaScript change name, and #3619 on main (the query pool's test file, which
this stack's full Windows run had shown failing there when run on its own). No
source file differs, so those measurements stand; on the commits that land,
each layer's own tree was run again on macOS and every suite on the three
platforms. On this change's own tree, macOS: the build and the kernel build
are clean; cargo test --release 99 passed; the kernel suites 32 files, 876
tests passed. On the head of the stack, macOS: the regression gate (npm run
gate) PASS (174 projects, 171 growth cases, expected.json unchanged); the full
suite 1,031 files passed and 2 skipped, 13,818 tests passed, 0 failed. Rust
against the reference there, full objects in emission order: 30,258
random-token and hand-built texts (the reviewer's 484 among them), every tree
equal to the wasm tree where read, 0 differences; kernel-parity.mjs --damage 1
--scramble 4 over axum, regex, serde and syn, 3,522 compares, 2,170 of them on
a tree with an error, 0 differences; the same sweep over one repository of
each language landed before (Python, Java, Go, C, C++, Objective-C, Pascal,
Solidity, Nix, COBOL, Erlang), 0 differences.

Speed on macOS, whole folders on the engine's path, the default route against
the reference (medians of seven interleaved rounds, node counts equal): serde
268 -> 135 ms, regex 1,013 -> 559 ms, syn 551 -> 280 ms, axum 332 -> 171 ms,
clap 646 -> 406 ms (1.59 to 1.98 times the reference's speed).

Windows 11 (ARM64, MSVC), the head of the stack, with the host quiet: the
kernel builds; cargo test --release 99 passed; the kernel suites 31 files, 966
tests passed; the error-tree test file and the languages' own test files 87
files, 1,194 tests passed. Rust against the reference in emission order: axum,
regex, serde and syn with damage, 3,462 texts, 1,032 from a tree with an
error, and 30,258 random-token and hand-built texts; 0 differences.
kernel-parity.mjs --damage 1 --scramble 4 with one seed gives macOS's counts
line for line on all four repositories. Speed there, the default route against
the reference (medians of three passes, arms in turn, twice): serde 316 -> 159
ms, regex 1,221 -> 617 ms, syn 718 -> 340 ms, axum 419 -> 198 ms (1.98 to 2.12
times). The full suite: 1,028 files passed and 5 skipped, 13,719 tests passed,
0 failed; query-pool.test.ts on its own, three runs, 51 of 51 tests each.

Linux (Docker, arm64, node:22-bookworm), the head of the stack: the kernel
builds; cargo test --release 99 passed; the kernel suites 31 files, 966 tests
passed; the error-tree and function-pointer test files 452 tests passed.
kernel-parity.mjs --damage 1 --scramble 4 with one seed gives macOS's counts
line for line on axum, regex, serde and syn, and on the 23 repositories of the
languages landed before; 0 differences. The full suite: 1,031 files passed and
2 skipped, 13,808 tests passed, 0 failed. Speed was not measured on Linux.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@colbymchenry
colbymchenry merged commit 63616db into main Dec 4, 2026
@colbymchenry
colbymchenry deleted the claude/kernel-error-trees-rust branch December 4, 2026 02:11
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