Skip to content

Commit ed46fd2

Browse files
committed
Merge origin/main into perf/unify-build-features
2 parents 5754573 + 58e5ce8 commit ed46fd2

662 files changed

Lines changed: 8681 additions & 6019 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Cargo.lock‎

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ members = [
88
"crates/sqlbuild-cache",
99
"crates/sqlbuild-sqltext",
1010
"crates/sqlbuild-config",
11+
"crates/sqlbuild-host",
1112
"crates/sqlbuild-recall",
1213
"crates/sqlbuild-discovery",
1314
"crates/sqlbuild-scopes",
@@ -35,6 +36,7 @@ order = [
3536
"sqlbuild-cache",
3637
"sqlbuild-sqltext",
3738
"sqlbuild-config",
39+
"sqlbuild-host",
3840
"sqlbuild-recall",
3941
"sqlbuild-model-config",
4042
"sqlbuild-discovery",
@@ -119,6 +121,7 @@ sqlbuild-config = { path = "crates/sqlbuild-config" }
119121
sqlbuild-core = { path = "crates/sqlbuild-core" }
120122
sqlbuild-cursor = { path = "crates/sqlbuild-cursor" }
121123
sqlbuild-discovery = { path = "crates/sqlbuild-discovery" }
124+
sqlbuild-host = { path = "crates/sqlbuild-host" }
122125
sqlbuild-render = { path = "crates/sqlbuild-render" }
123126
sqlbuild-refactor = { path = "crates/sqlbuild-refactor" }
124127
sqlbuild-rules = { path = "crates/sqlbuild-rules" }

‎crates/README.md‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ that can be tested and benchmarked with `cargo test` alone.
1414
| `sqlbuild-cache` | The shared native store every native cache uses (one atomically replaced, checksummed file per cache kind, keyed by content digests) and the one fingerprinting scheme for cache keys: the content digest and the project file fingerprint. |
1515
| `sqlbuild-sqltext` | Lexical SQL text without polyglot: comment, quote and parenthesis scanning, the rules quote policy, model header tokenization and matching, static variable substitution, static reference extraction, and the general reference scan with table-function call arguments under each adapter's lexical rules. |
1616
| `sqlbuild-config` | Configuration file reading without Python: TOML, YAML 1.2 with the core schema and merge keys, and typed project and local config readers for the fields discovery needs. It also writes the workspace files `sqb playground` and `sqb skills` create from packaged templates and skills. Errors carry their kind and position; YAML outside the supported subset is an `Unsupported` error. |
17+
| `sqlbuild-host` | The contract of the permanent Python edges as plain Rust: the catalogue of `sqlbuild._native_host` entries and the trait that resolves them, the per-thread compile timing collector with its process clock, the compile diagnostic sink, and the executor result types the Python result dataclasses and enums mirror. `sqlbuild-python` implements the traits. |
1718
| `sqlbuild-discovery` | Native project discovery and the only implementation of the model, SQL test, scenario, source and schema file collections and the declaration layout: the shared directory walk with Python's glob and sort semantics, file reading with Python's newline handling and read errors, and parsing of authored files with Python's exact discovery messages. Results are plain data the Python discovery facade materialises. |
1819
| `sqlbuild-scopes` | Declaration scopes, visibility, relationship grants, placement, report queries and the offline scope cache, including dialect-aware SQL-test and scenario scans. |
1920
| `sqlbuild-model-config` | MODEL configuration, columns and audits, template expansion over caller values, and dynamic-column name patterns using Rust regex syntax. |
@@ -32,8 +33,8 @@ Dependencies point one way, from the top of this graph to the bottom:
3233
```text
3334
sqlbuild-python
3435
-> sqlbuild-refactor -> sqlbuild-rules -> sqlbuild-analysis -> sqlbuild-attachments
35-
-> sqlbuild-model-config -> sqlbuild-scopes -> sqlbuild-render -> sqlbuild-discovery -> sqlbuild-config
36-
-> sqlbuild-sqltext -> sqlbuild-cache -> sqlbuild-pysource -> sqlbuild-state -> sqlbuild-cursor -> sqlbuild-core
36+
-> sqlbuild-model-config -> sqlbuild-scopes -> sqlbuild-render -> sqlbuild-discovery -> sqlbuild-host
37+
-> sqlbuild-config -> sqlbuild-sqltext -> sqlbuild-cache -> sqlbuild-pysource -> sqlbuild-state -> sqlbuild-cursor -> sqlbuild-core
3738
sqlbuild-cli -> sqlbuild-cache, sqlbuild-core, sqlbuild-build-features
3839
```
3940

@@ -59,6 +60,14 @@ version other than its manifest's, because the version is part of the build iden
5960
`fensu check` applies the Rust structure rules inside each crate: other crates use items through
6061
`main/` entry points, `models.rs`, `types.rs` and `constants.rs`, not through `_helpers/`.
6162

63+
Inside `sqlbuild-python`, the custom rule XSB075 orders the `bindings/_helpers` modules in layers
64+
that follow the planned crate split: shared Python plumbing (`infra`), then the glue of the lower
65+
crates (`front`), the compiled project (`project`), planning and compilation as siblings (`plan`,
66+
`compile`), command output (`output`), command handlers (`commands`) and registration
67+
(`registry`). A module may import only from lower layers; `plan` and `compile` may not import each
68+
other. `module_layers` in `fensu.toml` assigns every helper module a layer. `pending_budgets` is
69+
empty: every import points down, and a new upward import fails the check.
70+
6271
## Python module paths
6372

6473
`sqlbuild-python` and `sqlbuild-cli` import Python by module path strings. The repository test

‎crates/sqlbuild-host/Cargo.toml‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
[package]
2+
name = "sqlbuild-host"
3+
version.workspace = true
4+
description = "The contract of the permanent Python edges: host entries and traits, compile timings, diagnostics and executor results."
5+
edition.workspace = true
6+
license.workspace = true
7+
publish.workspace = true
8+
rust-version.workspace = true
9+
10+
[dependencies]
11+
sqlbuild-core.workspace = true
12+
13+
[lints]
14+
workspace = true
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! The thread's active collector slot.
2+
3+
use std::cell::RefCell;
4+
5+
use crate::compile_context::types::CompileTimingsHandle;
6+
7+
thread_local! {
8+
static ACTIVE: RefCell<Option<CompileTimingsHandle>> = const { RefCell::new(None) };
9+
}
10+
11+
/// Make `collector` the thread's active collector; return the one it replaces.
12+
pub(crate) fn replace_active(
13+
collector: Option<CompileTimingsHandle>,
14+
) -> Option<CompileTimingsHandle> {
15+
ACTIVE.with(|active| active.replace(collector))
16+
}
17+
18+
/// The thread's active collector, if a compile is collecting.
19+
pub(crate) fn active() -> Option<CompileTimingsHandle> {
20+
ACTIVE.with(|active| active.borrow().clone())
21+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub(crate) mod active;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//! Add elapsed time to one compile phase.
2+
3+
use crate::compile_context::_helpers::active::active;
4+
5+
/// Add elapsed nanoseconds to a phase when a collector is active.
6+
pub fn add_compile_timing(phase: &str, elapsed_ns: u64) {
7+
if let Some(collector) = active() {
8+
*collector
9+
.borrow_mut()
10+
.elapsed_ns
11+
.entry(phase.to_owned())
12+
.or_default() += elapsed_ns;
13+
}
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//! Collect the timings one compile records on this thread.
2+
3+
use std::rc::Rc;
4+
5+
use crate::compile_context::_helpers::active::replace_active;
6+
use crate::compile_context::types::CompileTimingsHandle;
7+
8+
/// Run `body` with a fresh collector active on this thread, restoring the previous one after.
9+
pub fn collect_compile_timings<T, E>(
10+
body: impl FnOnce(&CompileTimingsHandle) -> Result<T, E>,
11+
) -> Result<T, E> {
12+
let collector: CompileTimingsHandle = Rc::default();
13+
let previous: Option<CompileTimingsHandle> = replace_active(Some(Rc::clone(&collector)));
14+
let result: Result<T, E> = body(&collector);
15+
let _ = replace_active(previous);
16+
result
17+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pub mod add_compile_timing;
2+
pub mod collect_compile_timings;
3+
pub mod record_compile_cpu_timing;
4+
pub mod record_compile_metric;
5+
pub mod record_compile_timing;
6+
pub mod timing_milliseconds;
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Record the process CPU time of one compile phase.
2+
3+
use crate::compile_context::_helpers::active::active;
4+
use crate::compile_context::main::add_compile_timing::add_compile_timing;
5+
use crate::compile_context::types::ProcessClock;
6+
7+
/// Record the process CPU time `body` spans, including its worker threads, under `phase`.
8+
pub fn record_compile_cpu_timing<C: ProcessClock, T>(
9+
clock: &C,
10+
phase: &str,
11+
body: impl FnOnce() -> Result<T, C::Error>,
12+
) -> Result<T, C::Error> {
13+
if active().is_none() {
14+
return body();
15+
}
16+
let started: u64 = clock.process_time_ns()?;
17+
let result: Result<T, C::Error> = body();
18+
let ended: u64 = clock.process_time_ns()?;
19+
add_compile_timing(phase, ended.saturating_sub(started));
20+
result
21+
}

0 commit comments

Comments
 (0)