metrale_circuit/hardware/
sources.rs

1// SPDX-License-Identifier: MIT OR Apache-2.0
2
3//! 2026-09-30: What the caller resolves from the kernel tree for one class: the modules a target
4//! of the class compiles (after inheritance, shadows and `[modules]` renames), every file the
5//! resolution stages, and the kernels its MODEL.tomls declare absent. The pure planner reads
6//! nothing else about the sources.
7//!
8//! Owner: metrale-circuit (hardware).
9//! Invariants:
10//! - The caller resolves with the same layout the kernels build uses (metrale-closure), so
11//!   "compiled" here is what the build compiles; the crate never walks a directory itself.
12//! - A class with no target for the model resolves its common layer only (`target = None`),
13//!   and the report says so: its model-specific kernels are absent, not assumed.
14
15use std::collections::{BTreeMap, BTreeSet};
16
17use crate::venn::repo::Repo;
18
19/// 2026-09-30: One compiled module.
20#[derive(Debug, Clone, PartialEq, Eq)]
21pub struct Module {
22    /// 2026-09-30: Repo-relative source path.
23    pub path: String,
24    /// 2026-09-30: Source text.
25    pub text: String,
26}
27
28/// 2026-09-30: The kernel sources of one class for one model target.
29#[derive(Debug, Clone, Default, PartialEq, Eq)]
30pub struct ClassSources {
31    /// 2026-09-30: Class.
32    pub class: String,
33    /// 2026-09-30: `class/model/quant` resolved, or `None` when the class has no target for the
34    /// model and only its common layer was resolved.
35    pub target: Option<String>,
36    /// 2026-09-30: Module name (source stem after renames) to its source.
37    pub modules: BTreeMap<String, Module>,
38    /// 2026-09-30: Every repo-relative file the resolution compiles or stages (headers too).
39    pub files: BTreeSet<String>,
40    /// 2026-09-30: `[expected_absent.<module>]` entries: module to (function to reason).
41    pub expected_absent: BTreeMap<String, BTreeMap<String, String>>,
42}
43
44/// 2026-09-30: A repository that can also resolve a class's kernel sources.
45pub trait KernelTree: Repo {
46    /// 2026-09-30: The sources `class` compiles for `model`/`quant`, or its common layer when it
47    /// has no such target.
48    fn class_sources(&self, class: &str, model: &str, quant: &str) -> Result<ClassSources, String>;
49
50    /// 2026-09-30: The kernel model directory that serves the checkpoint whose `config.json`
51    /// is `config_json`, named by `refs`: the engine's own resolution (its config parse, which
52    /// may rewrite `model_type`, then MODEL.toml `[[model_types]]` and `match_names`), or
53    /// `None` when no target claims it.
54    fn kernel_target(&self, config_json: &str, refs: &[&str]) -> Result<Option<String>, String>;
55
56    /// 2026-09-30: This tree as a plain [`Repo`].
57    fn as_repo(&self) -> &dyn Repo;
58}