Skip to content

feat(native): extract model references natively behind the preview engine - #1008

Merged
kvlonge merged 3 commits into
mainfrom
feat/native-table-function-refs
Oct 7, 2026
Merged

kvlonge merged 3 commits into
mainfrom
feat/native-table-function-refs

Conversation

@kvlonge

@kvlonge kvlonge commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Why

The native reference fast path gives up on any __table_fn( call and on dialect-specific text, so those SQL strings run the slow Python scanner. Table functions need the call-argument count and the exact Python errors, which the fast path never produced.

Changes

  • sqlbuild-sqltext gains the general reference scan: every reference kind including __table_fn with its call-argument count, under each adapter's lexical rules (# and // comments, nested comments, backslash, escape, raw and triple-quoted strings), with Python's exact error messages. A non-ASCII character that decides the outcome, or an unknown line-comment prefix, defers to Python.
  • New preview-tier stage reference_extraction: only native-preview uses it. python and native are unchanged.
  • A native error stands only when the Python scanner raises the same message, which is re-raised from Python. Any disagreement raises NativeStageMismatchError instead of silently falling back.
  • Native scanners share SqlLexicalSyntax.native_mapping and one binding input type.
  • The failure corpus gains nine reference cases, and a harness test compares a project with table functions and hidden references.

Verification

  • Parity tests: crafted cases and 3,000 seeded strings for each of 7 lexical syntaxes match Python exactly (about 2% deferred). Time-limited worst-case shapes are covered.
  • make compiler-differential with captures and coverage (153 identical), make compiler-differential-shipped (147 identical), tests/e2e/scripts/compiler_differential, and dense 3k (2/2) all pass.
  • A large real project is byte-identical with stage captures. Its reference-phase CPU on a cold compile drops by about 70%, and dense 3k drops by about 50%. Edit compiles are unchanged because the reference cache serves them.
  • cargo test, clippy, fmt, make check-native-layering, make check-ci and make test pass.

@kvlonge
kvlonge enabled auto-merge (squash) October 7, 2026 16:19
…call arguments

Port Python's general reference extraction to sqlbuild-sqltext: every
reference kind including __table_fn with its call-argument count, under
each adapter's lexical rules, with Python's exact error messages for
argument counts, empty arguments, malformed names and unclosed text.
A non-ASCII character that decides the outcome, or an unsupported line
comment prefix, defers the text to Python.
…gine

Register reference extraction as a preview-tier native stage. Under
native-preview every SQL text goes through the native scan, for every
adapter's lexical rules; a deferral runs the Python scanner. A native
error stands only when Python raises the same message, which is
re-raised from Python; otherwise the compile fails with a
NativeStageMismatchError instead of silently falling back. The python
and native engines are unchanged.

The lexical-syntax mapping for native scanners is shared through
SqlLexicalSyntax.native_mapping and one binding input type.
The failure corpus gains reference cases: wrong argument counts, an empty
argument, an expression name, unclosed calls, and table functions without
an argument list, with a single-quoted name or with an empty call
argument. A harness test compares a project with table functions and
references hidden in comments, strings and dollar quotes under both
engines.
@kvlonge
kvlonge force-pushed the feat/native-table-function-refs branch from 68b9609 to 6a28f13 Compare October 7, 2026 19:14
@kvlonge
kvlonge merged commit 3fb32ee into main Oct 7, 2026
37 checks passed
@kvlonge
kvlonge deleted the feat/native-table-function-refs branch October 7, 2026 19:41
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