Skip to content
Merged

B4.4 #825

Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 18 additions & 6 deletions src/v3/compiler/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,20 @@
// so the compiler's own pipeline authority lives in the bootstrap Dag with
// the intended stage-body shape.
//
// `EXTDEPS_BOOTSTRAP_FIXTURES` is a narrow, bounded extension of that
// boundary: only extdeps authorities whose content is pure structural
// **data** (target-primitive declarations consumed symbolically by the
// **B4.4 extdeps-bootstrap fixture set.** The structural carrier
// `extdeps_bootstrap_fixture_authority` in
// `src/v3/std/extdeps_bootstrap_fixtures.dag` is the substrate authority for
// *which* extdeps files participate. The PB-1-e regen host filters
// `build.rs`-emitted `EXTDEPS_FILES` through [`EXTDEPS_BOOTSTRAP_PATH_KEYS`]
// (must stay in lockstep with that declaration's `virtual_path` fields).
// Only extdeps authorities whose content is pure structural **data**
// (target-primitive declarations consumed symbolically by the
// target-grounding engine as `Declaration`-shaped values; see
// `dsl/extdeps/languages/rust/primitives.dag`) are loaded. Arrow/realization
// files (`rust/emit.dag`, `rust/types.dag`, etc.) are deliberately excluded
// — their bodies stay per-target emitter-side, not in the bootstrap Dag.
// Coverage is currently `rust/primitives.dag` only (T-Ground-Engine pilot
// unblock, Director-dispatched); expansion to python/go primitives is a
// file-system extension once those targets reach the same pilot stage.
// Expansion adds a field to the carrier + a key in `EXTDEPS_BOOTSTRAP_PATH_KEYS`
// once python/go primitives reach the same pilot stage.
//
// **Type-structure-only load (Path 2 scoping).** The top-level
// `rust_pilot_primitives: List<RustPrimitive> = [...]` data declaration
Expand Down Expand Up @@ -81,6 +85,14 @@ use crate::pipeline_authority::{ordered_pipeline_stages, PIPELINE_AUTHORITY_FILE
#[cfg_attr(not(feature = "bootstrap-regen-fresh"), allow(dead_code))]
const PIPELINE_REALIZATION_META: &str = "CompilerHostRealization";

/// Virtual paths selecting extdeps `.dag` sources for PB-1-e bootstrap regen.
///
/// **Lockstep:** each entry must match a `virtual_path` on
/// `extdeps_bootstrap_fixture_authority` in `src/v3/std/extdeps_bootstrap_fixtures.dag`.
/// `Dag::extdeps_bootstrap_fixture_virtual_paths` is compared to this slice when the
/// committed bootstrap snapshots initialize (`dag.rs` LazyLock).
pub const EXTDEPS_BOOTSTRAP_PATH_KEYS: &[&str] = &["dsl/extdeps/languages/rust/primitives.dag"];

/// v3-only inhabitance for kernel `Bool` (Class 5 / Lane 1e-2b Path A).
///
/// `dsl/std/types.dag` must stay free of `inhabits` so v2 can parse every
Expand Down
2,591 changes: 1,297 additions & 1,294 deletions src/v3/compiler/src/bootstrap_generated.rs

Large diffs are not rendered by default.

2,425 changes: 1,214 additions & 1,211 deletions src/v3/compiler/src/bootstrap_generated_without_parse_surface.rs

Large diffs are not rendered by default.

33 changes: 23 additions & 10 deletions src/v3/compiler/src/bootstrap_regen_fresh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ const FLOAT_DAG: &str = include_str!("../../../../dsl/std/float.dag");
const STRING_TYPE_DAG: &str = include_str!("../../../../dsl/std/string_type.dag");
const TYPES_DAG: &str = include_str!("../../../../dsl/std/types.dag");

const EXTDEPS_RUST_PRIMITIVES_DAG: &str =
include_str!("../../../../dsl/extdeps/languages/rust/primitives.dag");

const EXTDEPS_BOOTSTRAP_FIXTURES: &[(&str, &str)] = &[(
"dsl/extdeps/languages/rust/primitives.dag",
EXTDEPS_RUST_PRIMITIVES_DAG,
)];

// Same `OUT_DIR` fixture arrays `build.rs` emits for staged/spec/compiler sources;
// Same `OUT_DIR` fixture arrays `build.rs` emits for staged/spec/compiler/extdeps sources;
// this module is their only remaining fresh-parse consumer.
include!(concat!(env!("OUT_DIR"), "/v3_staged_files.rs"));
include!(concat!(env!("OUT_DIR"), "/v3_specs.rs"));
include!(concat!(env!("OUT_DIR"), "/v3_compiler_files.rs"));
include!(concat!(env!("OUT_DIR"), "/v3_extdeps_files.rs"));

fn extdeps_bootstrap_fixtures() -> impl Iterator<Item = (&'static str, &'static str)> {
EXTDEPS_FILES
.iter()
.copied()
.filter(|(path, _)| crate::bootstrap::EXTDEPS_BOOTSTRAP_PATH_KEYS.contains(path))
}

// Single authority for staged-vs-`dsl/` name collision resolution during regen.
// The committed `bootstrap_generated.rs` snapshot was baked with this policy; any
Expand Down Expand Up @@ -89,16 +89,29 @@ fn load_runtime_bootstrap_authorities(
.iter()
.copied()
.filter(|(path, _)| !excluded_compiler_paths.contains(path));
assert_extdeps_bootstrap_keys_resolve_against_extdeps_files();
let fixtures: Vec<(&str, &str)> = staged_iter
.chain(V3_SPECS.iter().copied())
.chain(compiler_iter)
.chain(EXTDEPS_BOOTSTRAP_FIXTURES.iter().copied())
.chain(extdeps_bootstrap_fixtures())
.collect();
load_fixtures(dag, &fixtures);
crate::bootstrap::materialize_pipeline_realizations(dag);
dag.populate_primitive_cache();
}

fn assert_extdeps_bootstrap_keys_resolve_against_extdeps_files() {
let missing: Vec<&str> = crate::bootstrap::EXTDEPS_BOOTSTRAP_PATH_KEYS
.iter()
.copied()
.filter(|key| !EXTDEPS_FILES.iter().any(|(path, _)| *path == *key))
.collect();
assert!(
missing.is_empty(),
"EXTDEPS_BOOTSTRAP_PATH_KEYS must each appear in EXTDEPS_FILES (from build.rs): {missing:?}"
);
}

fn std_fixtures() -> &'static [(&'static str, &'static str)] {
&[
("dsl/std/logic.dag", LOGIC_DAG),
Expand Down
65 changes: 63 additions & 2 deletions src/v3/compiler/src/dag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
use std::collections::{HashMap, HashSet};
use std::sync::LazyLock;

use crate::bootstrap::EXTDEPS_BOOTSTRAP_PATH_KEYS;
use crate::diagnostics::{Diagnostic, DiagnosticTable, SourceSpan};
use crate::types::TypeShape;

Expand Down Expand Up @@ -2157,6 +2158,7 @@ pub struct Dag {

static BOOTSTRAPPED_DAG: LazyLock<Dag> = LazyLock::new(|| {
let mut dag = bootstrap_generated::bootstrapped_fixture_dag();
assert_extdeps_bootstrap_fixture_paths_match_regen_keys(&dag);
dag.populate_primitive_cache();
dag
});
Expand All @@ -2173,6 +2175,7 @@ static BOOTSTRAPPED_STD_FIXTURE_DAG: LazyLock<Dag> = LazyLock::new(|| {
static BOOTSTRAPPED_DAG_WITHOUT_PARSE_SURFACE_FIXTURE: LazyLock<Dag> = LazyLock::new(|| {
let mut dag =
bootstrap_generated_without_parse_surface::bootstrapped_fixture_without_parse_surface_dag();
assert_extdeps_bootstrap_fixture_paths_match_regen_keys(&dag);
dag.populate_primitive_cache();
dag
});
Expand Down Expand Up @@ -2823,8 +2826,9 @@ impl Dag {
}

/// Typed accessor for the `rust_pilot_primitives` data declaration
/// from `dsl/extdeps/languages/rust/primitives.dag` (loaded via
/// `EXTDEPS_BOOTSTRAP_FIXTURES` in `bootstrap.rs`). Returns the
/// from `dsl/extdeps/languages/rust/primitives.dag` (path authorized by
/// B4.4 `extdeps_bootstrap_fixture_authority` and the regen host's
/// `EXTDEPS_BOOTSTRAP_PATH_KEYS` filter over `EXTDEPS_FILES`). Returns the
/// top-level `List<RustPrimitive>` declaration whose *type* the
/// target-grounding engine walks structurally (`RustPrimitive =
/// IntegerPrimitive | NonIntegerPrimitive {target_name, algebra,
Expand All @@ -2850,6 +2854,27 @@ impl Dag {
self.declaration_by_name("rust_pilot_primitives")
}

/// Virtual paths from the B4.4 extdeps-bootstrap fixture carrier
/// (`extdeps_bootstrap_fixture_authority` in
/// `src/v3/std/extdeps_bootstrap_fixtures.dag`), in the order fields
/// appear on the lowered `ValueBody::Structural` body.
///
/// Used to keep the regen host's `EXTDEPS_BOOTSTRAP_PATH_KEYS` filter
/// aligned with the substrate declaration (compared in this module's bootstrap
/// `LazyLock` initializers).
pub fn extdeps_bootstrap_fixture_virtual_paths(&self) -> Option<Vec<String>> {
let decl = self.declaration_by_name("extdeps_bootstrap_fixture_authority")?;
let body = decl.value_body.as_ref()?;
let ValueBody::Structural { fields } = body else {
return None;
};
let mut out = Vec::with_capacity(fields.len());
for (_slot, fv) in fields {
out.push(extdeps_fixture_entry_virtual_path(fv)?);
}
(!out.is_empty()).then_some(out)
}

/// DB-10 (3a.2): read the compile-time value body attached to a
/// declaration. Returns `None` for declarations without a
/// value body (type aliases, bare type declarations, function
Expand Down Expand Up @@ -3375,6 +3400,42 @@ impl Default for Dag {
}
}

/// PB-1-e B4.4: the substrate `extdeps_bootstrap_fixture_authority` carrier and
/// [`EXTDEPS_BOOTSTRAP_PATH_KEYS`](crate::bootstrap::EXTDEPS_BOOTSTRAP_PATH_KEYS)
/// must list the same virtual paths in the same order — the const is the regen
/// filter; the `.dag` declaration is runtime authority.
fn assert_extdeps_bootstrap_fixture_paths_match_regen_keys(dag: &Dag) {
let Some(paths) = dag.extdeps_bootstrap_fixture_virtual_paths() else {
panic!(
"bootstrap snapshot must include `extdeps_bootstrap_fixture_authority` with a \
structural body (regenerate via `regen_bootstrap` after editing \
`src/v3/std/extdeps_bootstrap_fixtures.dag`)"
);
};
if paths.len() != EXTDEPS_BOOTSTRAP_PATH_KEYS.len()
|| paths
.iter()
.zip(EXTDEPS_BOOTSTRAP_PATH_KEYS.iter())
.any(|(a, b)| a != *b)
{
panic!(
"`EXTDEPS_BOOTSTRAP_PATH_KEYS` must match `extdeps_bootstrap_fixture_authority` \
virtual_path fields in order.\n substrate: {paths:?}\n regen keys: {EXTDEPS_BOOTSTRAP_PATH_KEYS:?}"
);
}
}

fn extdeps_fixture_entry_virtual_path(fv: &FieldValue) -> Option<String> {
let FieldValue::Record(fields) = fv else {
return None;
};
let (_, vp) = fields.iter().find(|(l, _)| l == "virtual_path")?;
match vp {
FieldValue::Literal(LiteralBits::String(s)) => Some(s.clone()),
_ => None,
}
}

fn binding_reference_field(fields: &[(String, FieldValue)], label: &str) -> Option<DeclarationId> {
fields.iter().find_map(|(field_label, value)| {
if field_label != label {
Expand Down
2 changes: 2 additions & 0 deletions src/v3/compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,8 @@ pub mod lens_structural_resolution {

mod bootstrap;

pub use bootstrap::EXTDEPS_BOOTSTRAP_PATH_KEYS;

#[cfg(feature = "bootstrap-regen-fresh")]
mod bootstrap_regen_fresh;

Expand Down
30 changes: 30 additions & 0 deletions src/v3/std/extdeps_bootstrap_fixtures.dag
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module v3.std.extdeps_bootstrap_fixtures

// B4.4 — Structural extdeps-bootstrap fixture-set carrier.
//
// Single substrate authority for *which* `dsl/extdeps/**/*.dag` files are
// loaded into the PB-1-e bootstrap Dag as structural primitive data (Path 2
// pilot). Arrow/realization authorities stay emitter-side; this set is the
// bounded exception documented in `bootstrap.rs`.
//
// The regen host (`bootstrap_regen_fresh`) filters `EXTDEPS_FILES` (emitted by
// `build.rs`) through the `virtual_path` strings recorded here. At runtime the
// committed bootstrap snapshot load compares those paths to
// `EXTDEPS_BOOTSTRAP_PATH_KEYS` in `bootstrap.rs` (see `dag.rs`).

// One extdeps file authorized for bootstrap loading.
type ExtdepsBootstrapFixture {
virtual_path: String
}

// Named product of every pilot fixture row (extend with new fields when adding
// targets; cost of change stays this file + the parallel `const` filter).
type ExtdepsBootstrapFixtureSet {
rust_pilot_primitives: ExtdepsBootstrapFixture
}

data extdeps_bootstrap_fixture_authority: ExtdepsBootstrapFixtureSet = {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BLOCKING: This substrate authority does not flow into the committed Dag::new() snapshots, so Dag::extdeps_bootstrap_fixture_virtual_paths() cannot see it and the Rust const remains the effective authority (facts-flow-forward / single authority).

rust_pilot_primitives: {
virtual_path: "dsl/extdeps/languages/rust/primitives.dag"
}
}
Loading