Repository navigation
Commit 8bc5325
authored
feat(native): batch and cache macro calls behind the preview engine (#1013)
* feat(native): add a render crate that scans, splices and memoizes macro calls
The sqlbuild-render crate ports the Python macro call scanner byte for
byte (quotes, comments, dollar quotes, the identifier/whitespace quirks,
Python Unicode classes), splices rendered calls with code-point spans,
and holds the in-compile memo of recorded calls and their events.
Anything the scanner cannot reproduce exactly defers to Python.
* feat(native): expose macro call scanning, splicing and the memo to Python
A macro_bridge module in the PyO3 crate registers scan_macro_call_sites
and splice_macro_calls (run with the GIL released) and the MacroCallMemo
class, whose recorded events cross as plain (tag, text, text) rows.
* feat(native): batch macro calls through a native render bridge
With the native engine, the compile-input render runs every
expand_sql_macros_result call through the macro bridge: Rust scans the
top-level call sites, Python resolves their call class and executes
memo misses in order with the existing _evaluate_macro_call, recorded
calls replay their ordered events (macro uses, declaration reads,
generated-reference candidates, typed argument references) for each
consumer, and Rust splices the results. Relation placeholders render
exactly as in the serial path. Any native render failure re-runs the
Python stage, which raises the exact error; a re-run that succeeds is
reported as a divergence. The Python engine is unchanged.
* feat(native): add a shared native store and carry macro calls in it
The sqlbuild-cache crate is the one store and fingerprinting scheme for
native caches: a content digest, a project file fingerprint that skips
the folders project reuse skips, and one checksummed, atomically
replaced file per cache kind whose entries are immutable and dropped
after 64 saves unused. A damaged, foreign or older file opens empty.
The macro call memo can attach a store: calls of a persistent class are
looked up by a digest of their class text and call text, and recorded
results are stored. The Python extension exposes the digest, the
project fingerprint and the memo's store methods.
* feat(native): cache macro call results across compiles
The native macro bridge now loads stored call results when the compile
cache is enabled and saves the results it used or recorded after the
render stage succeeds. A stored result is valid only in the same
environment: native build, interpreter, import search path, SQLBUILD_*
and SQB_* variables, and the content of every project file except model
SQL files; loaded module files are stamped and rechecked before use.
Each call is keyed by its text, the name, file, declaration identity
and source of every macro in the call, the relations passed so far, and
for context macros the whole context by value (vars, target, adapter,
visible constants and enums). Values without stable text make the call
uncached.
An edit-sequence e2e test compiles each edit with the store and with
--no-cache, with and without project reuse, and a broken store key
must make it fail. The compiler differential compiles every authored
and generated project a second time with a warm store.
* feat(native): run the macro bridge and call store only in the preview tier
The macro bridge and the macro call store are registered as preview-tier
native stages, so the default native engine and the Python engine never
batch macro calls or open the store. The bindings move under the grouped
bindings layout (render and cache domains). An e2e test compiles twice
under each engine and checks macro executions and store files; the
edit sequence also changes an @@env value passed to a macro.
* fix(native): scan nested macro calls in one pass without recursion
Collecting the names of nested macro calls recursed once per nesting
level and rescanned the arguments at each level, so deep nesting was
quadratic and very deep nesting overflowed the native stack. One pass
with an explicit stack now covers any depth in linear time.
* docs: state that macros must be deterministic
Compile reuse, the per-compile macro call memo and the macro call cache
all reuse a macro's result for the same call and context. Document the
contract, which inputs are compared, and that environment variables read
directly are compared only for SQLBUILD_ and SQB_ names.
* fix(native): trust stored macro calls only for code identified by content
Module stamps were read when the store was saved, so a module imported
before its file changed could be stored under the new file's stamps and
replayed by later processes; unreadable modules (zip members, moved
files) were skipped, and timestamps can be preserved or coarse.
Only the first compile of a process now uses and saves the store, so
code loaded by earlier compiles can no longer differ from disk. Loaded
modules outside the interpreter and SQLBuild are identified by a BLAKE3
digest of their backing file, at attach, after recorded calls and at
save; a module whose code cannot be read from a plain file disables the
store for that compile. Installed compiled extensions are covered by
their distributions' RECORD files, and the project fingerprint must be
unchanged between attach and save. The process start time is no longer
read, so the store also works without /proc.
* test(native): replay macro-returned reference call errors for every consumer
* refactor(native): raise the shared native stage mismatch error from the macro bridge1 parent b5a2453 commit 8bc5325
115 files changed
Lines changed: 7027 additions & 151 deletions
File tree
- crates
- sqlbuild-cache
- src
- digest
- _helpers
- main
- tests
- store
- _helpers
- main
- tests
- sqlbuild-python
- src/bindings
- _helpers
- cache
- render
- main
- sqlbuild-render
- src
- macro_calls
- _helpers
- main
- tests
- scripts/compiler_differential
- _helpers
- corpus
- running
- src/sqlbuild
- .agents/skills/sqlbuild/references/docs
- cli
- concepts
- compiler
- compile
- _helpers
- macro_bridge
- render
- classes
- main
- frontier
- _helpers
- macro_bridge
- _helpers
- classes
- main
- tests
- e2e
- scripts/compiler_differential
- src/sqlbuild/cli/commands/main/compile
- integration/src/sqlbuild/compiler/compile
- unit/src/sqlbuild/compiler
- frontier
- macro_bridge
- _helpers
- classes
- main
- website/src/content/docs/docs
- cli
- concepts
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| 10 | + | |
9 | 11 | | |
10 | 12 | | |
11 | 13 | | |
| |||
18 | 20 | | |
19 | 21 | | |
20 | 22 | | |
| 23 | + | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
24 | 27 | | |
25 | 28 | | |
| 29 | + | |
26 | 30 | | |
27 | 31 | | |
28 | 32 | | |
| |||
61 | 65 | | |
62 | 66 | | |
63 | 67 | | |
| 68 | + | |
64 | 69 | | |
65 | 70 | | |
66 | 71 | | |
| |||
70 | 75 | | |
71 | 76 | | |
72 | 77 | | |
| 78 | + | |
73 | 79 | | |
74 | 80 | | |
75 | 81 | | |
| 82 | + | |
76 | 83 | | |
77 | 84 | | |
78 | 85 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
| 10 | + | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
15 | 17 | | |
16 | 18 | | |
17 | 19 | | |
| |||
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
25 | | - | |
26 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
0 commit comments