Skip to content

feat(native): discover declarations, SQL tests and YAML files natively - #999

Merged
kvlonge merged 3 commits into
mainfrom
feat/native-discovery
Oct 7, 2026
Merged

kvlonge merged 3 commits into
mainfrom
feat/native-discovery

Conversation

@kvlonge

@kvlonge kvlonge commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Why

Milestone M2 moves project discovery to Rust behind the compiler engine switch. After model files, discovery time with SQLBUILD_COMPILER_ENGINE=native was spent on the declaration layout, SQL test files and YAML loading. This change makes those native. Output stays byte-identical to the Python engine, and the default engine stays python.

Changes

  • Declaration layout: Rust walks the declaration roots on the pass's shared tree and validates groups, scoped roots and named roles. Python records the facts only for a valid layout; it rescans an invalid one and raises its own error. Declaration files are still parsed in Python.
  • SQL tests and scenarios: Rust selects, reads and splits TEST blocks, parses headers, rejects unsupported keys and cleans bodies (an inspect.cleandoc port). Python keeps block and scenario semantics, including parameter normalisation, so the first error is unchanged.
  • YAML: Rust reads the source, model schema and seed declaration files Python selects, and loads each with the PyYAML-compatible loader in size-bounded batches. Python loads any file the native loader or conversion cannot reproduce (including implicit keys near the 1024-character limit), and re-reads unreadable files for their error. Large integers convert exactly.
  • When native defers, the Python path keeps the discovery fact cache.
  • One native tree per pass, with listings shared with the Python snapshot. The statement header matcher now takes the keyword.

Verification

  • make compiler-differential with native on Python 3.12: 114 projects identical (8 new layout failure cases); dense 3k identical. Dense 3k discovery: ~3.7 s (python) → ~1.5 s (native).
  • Seeded engine-parity tests: 400 layouts, 1000 test/scenario files, 800 source/seed documents. Stage tests through the switch; cleandoc oracle.
  • cargo test --workspace --all-features, clippy/fmt 1.98.0, make check-native-layering, make check-ci, make test.

With the native engine, Rust walks the canonical, global and named
declaration roots on the pass's shared tree, validates the declaration
group, scoped root and named role layout, and returns the macro, enum and
constant file facts and the declaration groups. Python records them only
for a valid layout and rescans an invalid one to raise its own error.
Reading and parsing declaration files stays in Python.
With the native engine, Rust selects, reads and splits SQL test files into
TEST blocks, parses each header and rejects unsupported keys, and cleans
bodies like inspect.cleandoc; scenario files get the same header handling.
Python keeps the block and scenario semantics, including parameter value
normalisation, so the first failure is unchanged.
With the native engine, Rust reads the source, model schema and seed
declaration files Python selects and loads each with the PyYAML-compatible
loader. A file the native loader cannot reproduce is loaded by Python, and
an unreadable file is re-read by Python for its error. Validation of the
loaded documents stays in Python.
@kvlonge
kvlonge enabled auto-merge (squash) October 7, 2026 06:45
@kvlonge
kvlonge merged commit c0b546f into main Oct 7, 2026
34 checks passed
@kvlonge
kvlonge deleted the feat/native-discovery branch October 7, 2026 07:19
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