Skip to content

feat(native): parse declaration files natively behind the preview engine - #1014

Merged
kvlonge merged 4 commits into
mainfrom
feat/native-declaration-parsers
Oct 7, 2026
Merged

kvlonge merged 4 commits into
mainfrom
feat/native-declaration-parsers

Conversation

@kvlonge

@kvlonge kvlonge commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Why

Model, source, test and scenario files already have native discovery. The remaining declaration inputs still went through the Python parsers, so later Rust stages had no native view of enums, constants, schemas, audits, hooks, SQL functions, seeds and macros.

Changes

  • sqlbuild-discovery lists, reads and parses enum, constant, model schema, audit, SQL hook, SQL function, seed and macro files in Python's discovery order, in parallel. Files whose outcome depends on Python-only semantics are deferred, such as a non-ASCII bare word or a file name that is not UTF-8.
  • New NativeDiscoverySession (PyO3). It reads each collection and the declaration layout once per pass and retains them for later native stages. It is attached to DiscoveredProjectInputs with compare=False. None means readers use the Python objects. The session is dropped before render-reuse pickling, from stage captures, and from inputs that Rule fixes edit.
  • New preview-tier stage DECLARATION_FILES. Python still builds the records, normalises constant values and parses schema columns. A file that native rejects or defers is re-parsed by Python, and a differing outcome raises NativeStageMismatchError.
  • Fix for all engines, including the default: discovery failure messages no longer rewrite authored text. Before this, a NUL in a header key such as descri\0ption corrupted the error. Only listed path names are escaped now.

Verification

  • Integration parity tests per kind: seeded generators, crafted and tolerant projects, undecodable names, mismatch, session retention, render reuse, NUL header keys under every engine, and Rule-fix session dropping.
  • Rust unit tests cover the parsers and the single layout walk.
  • make compiler-differential (163/163 identical), make compiler-differential-shipped (157/157), dense 3k and tests/e2e/scripts/compiler_differential.
  • make test, make check-ci, and cargo test --workspace --all-features, clippy and fmt.

Add native listing, reading and parsing for enum, constant, model schema, audit, SQL hook, SQL function, seed and macro files, in Python's discovery order, with a deferred outcome for inputs only Python can judge and a session that retains each collection and its layout for later stages.
…ehind the preview engine

Add the preview-tier DECLARATION_FILES stage. Each declaration collection is read once per pass through a retained native discovery session; Python builds the records, normalises constant values and parses schema columns, and re-runs its own parser for any file native rejects or defers, raising NativeStageMismatchError when the outcomes differ. Default engines are unchanged.
Discovery decoded raw-name markers across whole failure messages, so a NUL authored in a header key (for example a model's descri\0ption) was rewritten under every engine. Layout failures now show each listed path as it is displayed when the message is built, and the binding passes message text through untouched.
Document that a missing session means readers use the Python objects, and drop the session from the inputs each Rule fix pass lints.
@kvlonge
kvlonge enabled auto-merge (squash) October 7, 2026 21:13
@kvlonge
kvlonge merged commit 2cb1514 into main Oct 7, 2026
37 checks passed
@kvlonge
kvlonge deleted the feat/native-declaration-parsers branch October 7, 2026 22:06
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