From 1fe158adc303a3bca91c05352d6abfa7f38aa3e3 Mon Sep 17 00:00:00 2001 From: VirtualMachinist <252028890+VirtualMachinist@users.noreply.github.com> Date: Sat, 14 Nov 2026 15:41:35 -0800 Subject: [PATCH 01/11] Place a bare name that only one glob of a workspace module supplies A call or macro-argument path that the base tiers leave unresolved, whose first segment no local item, non-glob use or shadowing binding of its module binds, now looks up that name in each workspace module a glob use of the module reaches. When exactly one item is found across them, the call walks from that module by the existing tiers, with the new reason use-glob at 0.85. Two candidates or none give no edge, and a call the base tiers place keeps its edge. The extractor version goes to 12. The store and the command-line reason tables gain use-glob. The resolve fixture gains its two glob calls as use-glob edges, and the scorer case for the glob bucket keeps its miss with a second globbed module. Co-Authored-By: Claude Opus 5.5 --- crates/phantom-fractal-extract/src/lib.rs | 10 +- .../tests/fixture/mod.rs | 1 + .../phantom-fractal-extract/tests/resolve.rs | 5 +- .../tests/scip_score.rs | 6 +- .../phantom-fractal-lang-rust/src/resolve.rs | 5 +- .../src/resolve/lookup.rs | 2 + .../src/resolve/lookup/cures.rs | 106 ++++++++++ .../tests/glob_cure.rs | 196 ++++++++++++++++++ .../tests/resolve.rs | 22 +- crates/phantom-fractal-lang/src/resolve.rs | 5 + crates/phantom-fractal-store/src/graph.rs | 2 + crates/phantom-fractal/src/ops/index.rs | 3 + crates/phantom-fractal/tests/doctor.rs | 2 +- crates/phantom-fractal/tests/fresh.rs | 8 +- crates/phantom-fractal/tests/version.rs | 2 +- fixtures/resolve/EXPECTED.md | 19 +- 16 files changed, 366 insertions(+), 28 deletions(-) create mode 100644 crates/phantom-fractal-lang-rust/src/resolve/lookup/cures.rs create mode 100644 crates/phantom-fractal-lang-rust/tests/glob_cure.rs diff --git a/crates/phantom-fractal-extract/src/lib.rs b/crates/phantom-fractal-extract/src/lib.rs index f91678f..18e8fd0 100644 --- a/crates/phantom-fractal-extract/src/lib.rs +++ b/crates/phantom-fractal-extract/src/lib.rs @@ -44,8 +44,9 @@ pub use walk::{Candidate, MAX_FILE_BYTES, SkipReason, Skipped, Walk, is_secret, /// and the `typed-method` edges; version 9 adds `test` targets and their /// module trees; version 10 places `macro_arg` refs, with their receivers, /// hints and shadowing; version 11 adds the return, path-call and -/// same-file field hints. -pub const EXTRACTOR_VERSION: u32 = 11; +/// same-file field hints; version 12 adds the `use-glob` edges and the +/// parse budget. +pub const EXTRACTOR_VERSION: u32 = 12; /// What one [`index`] pass did, by repo-relative path, in walk order. #[derive(Debug, Clone, Default, PartialEq, Eq)] @@ -88,11 +89,12 @@ pub struct ReasonCounts { pub crate_path: u64, pub typed_method: u64, pub unique_method: u64, + pub use_glob: u64, } impl ReasonCounts { /// Every reason in declaration order. - pub const REASONS: [Reason; 9] = [ + pub const REASONS: [Reason; 10] = [ Reason::PathExact, Reason::Local, Reason::UseAlias, @@ -102,6 +104,7 @@ impl ReasonCounts { Reason::CratePath, Reason::TypedMethod, Reason::UniqueMethod, + Reason::UseGlob, ]; /// The count of each reason among `edges`. @@ -130,6 +133,7 @@ impl ReasonCounts { Reason::CratePath => &mut self.crate_path, Reason::TypedMethod => &mut self.typed_method, Reason::UniqueMethod => &mut self.unique_method, + Reason::UseGlob => &mut self.use_glob, } } } diff --git a/crates/phantom-fractal-extract/tests/fixture/mod.rs b/crates/phantom-fractal-extract/tests/fixture/mod.rs index 2b1be8b..c1b989d 100644 --- a/crates/phantom-fractal-extract/tests/fixture/mod.rs +++ b/crates/phantom-fractal-extract/tests/fixture/mod.rs @@ -74,6 +74,7 @@ pub fn reason_text(reason: Reason) -> (&'static str, f64) { Reason::CratePath => ("crate-path", 0.95), Reason::TypedMethod => ("typed-method", 0.8), Reason::UniqueMethod => ("unique-method", 0.5), + Reason::UseGlob => ("use-glob", 0.85), } } diff --git a/crates/phantom-fractal-extract/tests/resolve.rs b/crates/phantom-fractal-extract/tests/resolve.rs index 0aacdce..90c4d70 100644 --- a/crates/phantom-fractal-extract/tests/resolve.rs +++ b/crates/phantom-fractal-extract/tests/resolve.rs @@ -94,10 +94,11 @@ fn a_deleted_file_loses_its_rows_and_edges() { let edges = stored_edges(&s.store); assert!(!edges.iter().any(|edge| edge.contains("sink")), "{edges:?}"); let graph = graph(&report); - assert_eq!(graph.counts.edges, 21); + // The two `use-glob` edges of SPEC-w13 G2a stay: neither is in the file. + assert_eq!(graph.counts.edges, 23); assert_eq!(graph.modules, 10); // `deep::sink()` in `util::helper` now names a module with no file. - assert_eq!(graph.counts.unresolved, 9); + assert_eq!(graph.counts.unresolved, 7); } #[test] diff --git a/crates/phantom-fractal-extract/tests/scip_score.rs b/crates/phantom-fractal-extract/tests/scip_score.rs index 1a19792..f3d5eb3 100644 --- a/crates/phantom-fractal-extract/tests/scip_score.rs +++ b/crates/phantom-fractal-extract/tests/scip_score.rs @@ -589,13 +589,14 @@ fn an_uncovered_edge_reads_its_graded_precision_beside_the_full_one() { } /// The glob and re-export buckets on a real index pass (W13 G0a): a -/// bare call in the scope of a file-module glob leaves `unresolved +/// bare call in the scope of two file-module globs that both supply its +/// name, so the glob cure of G2a leaves it unplaced, leaves `unresolved /// path call` for `glob import in scope`, a call through a /// crate-root re-export leaves it for `re-exported path`, and the /// split map says what each took and from where. #[test] fn the_w13_buckets_hold_their_extracted_cases() { - let lib_source = "mod helper;\nmod user;\npub use helper::Gadget;\nuse helper::*;\n\npub fn caller() {\n reach();\n}\n"; + let lib_source = "mod helper;\nmod spare;\nmod user;\npub use helper::Gadget;\nuse helper::*;\nuse spare::*;\n\npub fn caller() {\n reach();\n}\n"; let helper_source = "pub fn reach() {}\npub struct Gadget;\nimpl Default for Gadget {\n fn default() -> Gadget {\n Gadget\n }\n}\n"; let user_source = "use crate::Gadget;\n\npub fn call() {\n Gadget::default();\n}\n"; let temp = Temp::new("w13"); @@ -604,6 +605,7 @@ fn the_w13_buckets_hold_their_extracted_cases() { std::fs::write(repo.join("Cargo.toml"), "[package]\nname = \"w13\"\n").expect("manifest"); std::fs::write(repo.join("src/lib.rs"), lib_source).expect("lib"); std::fs::write(repo.join("src/helper.rs"), helper_source).expect("helper"); + std::fs::write(repo.join("src/spare.rs"), "pub fn reach() {}\n").expect("spare"); std::fs::write(repo.join("src/user.rs"), user_source).expect("user"); let mut store = Store::open(&temp.db()).expect("open store"); index(&repo, &mut store, &RustLanguage::new().expect("grammar")).expect("index"); diff --git a/crates/phantom-fractal-lang-rust/src/resolve.rs b/crates/phantom-fractal-lang-rust/src/resolve.rs index 56a9afc..5fa0c6e 100644 --- a/crates/phantom-fractal-lang-rust/src/resolve.rs +++ b/crates/phantom-fractal-lang-rust/src/resolve.rs @@ -52,6 +52,7 @@ pub fn confidence(reason: Reason) -> f64 { Reason::PathExact => 1.0, Reason::Local | Reason::UseAlias | Reason::CratePath => 0.95, Reason::Assoc | Reason::SelfMethod | Reason::SelfAssoc => 0.9, + Reason::UseGlob => 0.85, Reason::TypedMethod => 0.8, Reason::UniqueMethod => 0.5, } @@ -111,7 +112,7 @@ pub fn resolve(input: &ResolveInput) -> (Vec, ResolveCounts) { counts.no_source += 1; continue; }; - (source, index.place(call, source)) + (source, index.place_cured(call, source)) } }; match placed { @@ -162,7 +163,7 @@ fn placed_after_base(call: &CallRef, hint: &str) -> bool { /// any other method name by [`place_method`]. fn place_macro_arg(index: &Index, call: &CallRef, source: Id) -> Placed { match call.receiver.as_deref() { - None => index.place(call, source), + None => index.place_cured(call, source), Some("self") => match segments(&call.text).and_then(|segs| segs.last().cloned()) { Some(name) => index.place_self(source, &name, Reason::SelfMethod), None => Placed::Unresolved, diff --git a/crates/phantom-fractal-lang-rust/src/resolve/lookup.rs b/crates/phantom-fractal-lang-rust/src/resolve/lookup.rs index 3af9617..de3b323 100644 --- a/crates/phantom-fractal-lang-rust/src/resolve/lookup.rs +++ b/crates/phantom-fractal-lang-rust/src/resolve/lookup.rs @@ -17,6 +17,8 @@ use phantom_fractal_lang::{ }; use super::segments; + +mod cures; use super::signature::{first_segment, generic_parameters, ok_type, return_type}; use crate::STD_METHOD_NAMES; diff --git a/crates/phantom-fractal-lang-rust/src/resolve/lookup/cures.rs b/crates/phantom-fractal-lang-rust/src/resolve/lookup/cures.rs new file mode 100644 index 0000000..d01d8f6 --- /dev/null +++ b/crates/phantom-fractal-lang-rust/src/resolve/lookup/cures.rs @@ -0,0 +1,106 @@ +//! The dogfood cures (SPEC-w13 G2a, D9). Each is tried only for a call +//! the base tiers leave unresolved, so no base edge moves. +//! +//! **(b) A glob import.** The call's first segment is a bare name that +//! nothing in the call's module binds: no item or child module declared +//! there, no non-glob `use` and no shadowing binding. The module's +//! `use p::*` uses whose path walks to a workspace module, by the existing +//! tiers, are the globbed modules. When exactly one item of that name is +//! found across them, as each module's own lookup finds it, the call walks +//! from that module by the existing tiers. The edge's reason is +//! `use-glob`. Two candidates, or none, give no edge. + +use phantom_fractal_lang::{CallRef, Id, Reason}; + +use super::{Entity, Index, Placed, segments}; + +impl Index<'_> { + /// A `Call`, or a path in a macro's tokens, by the base tiers and, + /// when they leave it unresolved, by the cures. + pub(crate) fn place_cured(&self, call: &CallRef, source: Id) -> Placed { + match self.place(call, source) { + Placed::Unresolved => self.place_glob(call).unwrap_or(Placed::Unresolved), + placed => placed, + } + } + + /// Cure (b): the call walked from the one globbed module that gives its + /// first segment. + fn place_glob(&self, call: &CallRef) -> Option { + if call.shadowed { + return None; + } + let module = self.place_of(&call.file, &call.scope)?; + let segs = segments(&call.text)?; + let home = self.glob_home(module, segs.first()?)?; + let walked = self.walk(home, &segs, 0, true).ok()?; + let functions: Vec = walked + .entities + .iter() + .filter_map(|entity| self.function(*entity)) + .collect(); + let [target] = functions[..] else { + return None; + }; + Some(Placed::Edge(target, Reason::UseGlob)) + } + + /// The globbed module of `module` that gives `name`, when nothing in + /// `module` binds `name` and exactly one item of that name is found + /// across its globbed modules. + fn glob_home(&self, module: Id, name: &str) -> Option { + if !self.declared(module, name).is_empty() || self.bound_by_use(module, name) { + return None; + } + let mut found: Vec<(Entity, Id)> = Vec::new(); + for globbed in self.globbed(module) { + for entity in self.given(globbed, name) { + if !found.iter().any(|(seen, _)| *seen == entity) { + found.push((entity, globbed)); + } + } + } + let [(_, home)] = found[..] else { + return None; + }; + Some(home) + } + + /// What `name` names in the globbed module `globbed`, as its own + /// lookup finds it one `use` level down; none when only a glob there + /// could supply it. + fn given(&self, globbed: Id, name: &str) -> Vec { + self.lookup(globbed, name, 1) + .map(|found| found.entities) + .unwrap_or_default() + } + + /// True when a non-glob `use` in `module` binds `name`. + fn bound_by_use(&self, module: Id, name: &str) -> bool { + self.uses.get(&module).is_some_and(|bindings| { + bindings + .iter() + .any(|binding| !binding.glob && super::bound_name(binding) == Some(name)) + }) + } + + /// The workspace modules the glob uses of `module` reach, each once, in + /// `use` order. + fn globbed(&self, module: Id) -> Vec { + let mut out: Vec = Vec::new(); + for binding in self.uses.get(&module).into_iter().flatten() { + let reached = binding + .glob + .then(|| self.use_entities(binding, 1).ok()) + .flatten(); + for entity in reached.into_iter().flat_map(|walked| walked.entities) { + if let Entity::Module(globbed) = entity + && !out.contains(&globbed) + { + out.push(globbed); + } + } + } + out + } +} diff --git a/crates/phantom-fractal-lang-rust/tests/glob_cure.rs b/crates/phantom-fractal-lang-rust/tests/glob_cure.rs new file mode 100644 index 0000000..20e70f2 --- /dev/null +++ b/crates/phantom-fractal-lang-rust/tests/glob_cure.rs @@ -0,0 +1,196 @@ +//! Cure (b), a glob import (SPEC-w13 G2a, D9). +//! +//! A bare first segment that nothing in the call's module binds, no item, +//! child module, non-glob `use` or shadowing binding, resolves through the +//! module's `use p::*` uses of workspace modules when exactly one item of +//! that name is found across them. The edge's reason is `use-glob`, at +//! 0.85. A call the base tiers place keeps its edge. + +mod support; + +use phantom_fractal_lang::{Id, Reason, RefKind, SymbolKind}; +use phantom_fractal_lang_rust::{confidence, links}; +use support::{Input, edge}; + +const LIB: &str = "src/lib.rs"; + +/// A crate whose root declares `mod tests` with `use super::*`, and a +/// function `check` inside it. +fn tests_module() -> (Input, Id) { + let mut i = Input::new(); + i.module(1, "tests", LIB, "tests"); + i.uses(LIB, "tests", "super", None, true); + let check = i.symbol(SymbolKind::Function, "check", LIB, "tests"); + (i, check) +} + +/// A call `text` from `from` in the `tests` scope of `src/lib.rs`. +fn call_in_tests(i: &mut Input, from: Id, text: &str) -> Id { + i.call_in(Some(from), LIB, "tests", text, RefKind::Call) +} + +#[test] +fn use_glob_has_its_store_text_and_confidence() { + assert_eq!(Reason::UseGlob.as_str(), "use-glob"); + assert_eq!(confidence(Reason::UseGlob), 0.85); +} + +#[test] +fn a_bare_name_only_a_glob_supplies_resolves_by_use_glob() { + let (mut i, check) = tests_module(); + let helper = i.function("helper"); + let call = call_in_tests(&mut i, check, "helper"); + let through = call_in_tests(&mut i, check, "super::helper"); + let (edges, counts) = i.resolve(); + assert_eq!( + edges, + [ + edge(call, check, helper, Reason::UseGlob), + edge(through, check, helper, Reason::PathExact), + ] + ); + assert_eq!((counts.edges, counts.unresolved), (2, 0)); +} + +#[test] +fn a_type_a_glob_supplies_reaches_its_inherent_method() { + let (mut i, check) = tests_module(); + i.symbol(SymbolKind::Struct, "Gadget", LIB, ""); + let new = i.method("Gadget", None, "new"); + // A trait method is not inherent: no edge, as for a local type. + i.method("Gadget", Some("Default"), "default"); + let call = call_in_tests(&mut i, check, "Gadget::new"); + call_in_tests(&mut i, check, "Gadget::default"); + let (edges, counts) = i.resolve(); + assert_eq!(edges, [edge(call, check, new, Reason::UseGlob)]); + assert_eq!(counts.unresolved, 1); +} + +#[test] +fn two_candidates_across_the_globbed_modules_give_no_edge() { + let mut i = Input::new(); + i.module(1, "a", LIB, "a"); + i.module(1, "b", LIB, "b"); + i.symbol(SymbolKind::Function, "twin", LIB, "a"); + i.symbol(SymbolKind::Function, "twin", LIB, "b"); + i.uses(LIB, "", "a", None, true); + i.uses(LIB, "", "b", None, true); + let caller = i.function("caller"); + i.call(caller, "twin"); + let (edges, counts) = i.resolve(); + assert!(edges.is_empty(), "{edges:?}"); + assert_eq!(counts.unresolved, 1); +} + +#[test] +fn one_item_reached_by_two_globs_is_one_candidate() { + let mut i = Input::new(); + let a = i.module(1, "a", LIB, "a"); + let only = i.symbol(SymbolKind::Function, "only", LIB, "a"); + i.uses(LIB, "", "a", None, true); + i.uses(LIB, "", "crate::a", None, true); + let caller = i.function("caller"); + let call = i.call(caller, "only"); + let (edges, _) = i.resolve(); + assert_eq!(edges, [edge(call, caller, only, Reason::UseGlob)]); + let _ = a; +} + +#[test] +fn a_shadowing_binding_or_an_explicit_import_keeps_the_call_unresolved() { + let (mut i, check) = tests_module(); + i.function("helper"); + i.function("other"); + // `let helper = ..` in `check`. + let shadowed = call_in_tests(&mut i, check, "helper"); + i.input + .refs + .iter_mut() + .find(|call| call.id == shadowed) + .expect("ref") + .shadowed = true; + // `use crate::gone as other;` binds `other` to nothing. + i.uses(LIB, "tests", "crate::gone", Some("other"), false); + call_in_tests(&mut i, check, "other"); + let (edges, counts) = i.resolve(); + assert!(edges.is_empty(), "{edges:?}"); + assert_eq!(counts.unresolved, 2); +} + +#[test] +fn a_local_item_is_placed_by_the_base_tier_and_keeps_its_reason() { + let (mut i, check) = tests_module(); + i.function("helper"); + let local = i.symbol(SymbolKind::Function, "helper", LIB, "tests"); + let call = call_in_tests(&mut i, check, "helper"); + assert_eq!(i.resolve().0, [edge(call, check, local, Reason::Local)]); +} + +#[test] +fn a_glob_of_no_workspace_module_supplies_nothing() { + let mut i = Input::new(); + i.symbol(SymbolKind::Enum, "Shape", LIB, ""); + // `use std::io::*;`, `use Shape::*;` and a glob of a missing module. + i.uses(LIB, "", "std::io", None, true); + i.uses(LIB, "", "Shape", None, true); + i.uses(LIB, "", "crate::gone", None, true); + let caller = i.function("caller"); + i.call(caller, "read"); + let (edges, counts) = i.resolve(); + assert!(edges.is_empty(), "{edges:?}"); + assert_eq!(counts.unresolved, 1); +} + +#[test] +fn a_re_export_of_the_globbed_module_counts_and_its_own_glob_does_not() { + let mut i = Input::new(); + i.module(1, "prelude", LIB, "prelude"); + i.module(1, "model", LIB, "model"); + i.module(1, "deep", LIB, "deep"); + let thing = i.symbol(SymbolKind::Function, "thing", LIB, "model"); + i.symbol(SymbolKind::Function, "far", LIB, "deep"); + // `mod prelude { pub use crate::model::thing; pub use crate::deep::*; }` + i.uses(LIB, "prelude", "crate::model::thing", None, false); + i.uses(LIB, "prelude", "crate::deep", None, true); + i.uses(LIB, "", "prelude", None, true); + let caller = i.function("caller"); + let call = i.call(caller, "thing"); + i.call(caller, "far"); + let (edges, counts) = i.resolve(); + assert_eq!(edges, [edge(call, caller, thing, Reason::UseGlob)]); + assert_eq!(counts.unresolved, 1); +} + +#[test] +fn a_glob_of_a_parent_module_does_not_reach_its_child_modules() { + let mut i = Input::new(); + i.module(1, "util", LIB, "util"); + i.module(1, "inner", LIB, "inner"); + i.symbol(SymbolKind::Function, "helper", LIB, "util"); + i.uses(LIB, "", "util", None, true); + // `inner` has no glob of its own. + let inner_fn = i.symbol(SymbolKind::Function, "run", LIB, "inner"); + i.call_in(Some(inner_fn), LIB, "inner", "helper", RefKind::Call); + let (edges, counts) = i.resolve(); + assert!(edges.is_empty(), "{edges:?}"); + // Nothing in `inner` binds `helper` and it has no glob: external. + assert_eq!((counts.unresolved, counts.external), (0, 1)); +} + +#[test] +fn a_path_in_a_macro_s_tokens_resolves_by_the_same_cure() { + let (mut i, check) = tests_module(); + let helper = i.function("helper"); + let arg = i.call_in(Some(check), LIB, "tests", "helper", RefKind::MacroArg); + let (edges, counts) = i.resolve(); + assert_eq!(edges, [edge(arg, check, helper, Reason::UseGlob)]); + assert_eq!(counts.edges, 1); +} + +#[test] +fn the_cure_adds_no_link() { + let (mut i, check) = tests_module(); + i.function("helper"); + call_in_tests(&mut i, check, "helper"); + assert!(links(&i.input).is_empty()); +} diff --git a/crates/phantom-fractal-lang-rust/tests/resolve.rs b/crates/phantom-fractal-lang-rust/tests/resolve.rs index 97f2027..53bed5c 100644 --- a/crates/phantom-fractal-lang-rust/tests/resolve.rs +++ b/crates/phantom-fractal-lang-rust/tests/resolve.rs @@ -288,13 +288,15 @@ fn a_shadowed_call_gives_no_edge() { } #[test] -fn a_name_only_a_glob_supplies_gives_no_edge() { +fn a_name_only_a_glob_supplies_resolves_by_use_glob() { + // SPEC-w4 left it unresolved; SPEC-w13 G2a cure (b) places it. The + // cases of the cure are in `tests/glob_cure.rs`. let mut i = Input::new(); - let tests = i.module(1, "tests", "src/lib.rs", "tests"); - i.function("helper"); + i.module(1, "tests", "src/lib.rs", "tests"); + let helper = i.function("helper"); i.uses("src/lib.rs", "tests", "super", None, true); let check = i.symbol(SymbolKind::Function, "check", "src/lib.rs", "tests"); - i.call_in(Some(check), "src/lib.rs", "tests", "helper", RefKind::Call); + let bare = i.call_in(Some(check), "src/lib.rs", "tests", "helper", RefKind::Call); let through = i.call_in( Some(check), "src/lib.rs", @@ -303,10 +305,14 @@ fn a_name_only_a_glob_supplies_gives_no_edge() { RefKind::Call, ); let (edges, counts) = i.resolve(); - assert_eq!(edges.len(), 1); - assert_eq!(edges[0].ref_id, through); - assert_eq!(counts.unresolved, 1); - let _ = tests; + assert_eq!( + edges, + [ + edge(bare, check, helper, Reason::UseGlob), + edge(through, check, helper, Reason::PathExact), + ] + ); + assert_eq!(counts.unresolved, 0); } #[test] diff --git a/crates/phantom-fractal-lang/src/resolve.rs b/crates/phantom-fractal-lang/src/resolve.rs index bae0897..f5a1f5e 100644 --- a/crates/phantom-fractal-lang/src/resolve.rs +++ b/crates/phantom-fractal-lang/src/resolve.rs @@ -201,6 +201,10 @@ pub enum Reason { /// `x.m()` with no placed hint, to the one workspace method named `m` /// (SPEC-w10 G3a). UniqueMethod, + /// A bare first segment that only a `use p::*` of a workspace module + /// supplies, with exactly one item of that name across the globbed + /// modules (SPEC-w13 G2a). + UseGlob, } impl Reason { @@ -216,6 +220,7 @@ impl Reason { Self::CratePath => "crate-path", Self::TypedMethod => "typed-method", Self::UniqueMethod => "unique-method", + Self::UseGlob => "use-glob", } } } diff --git a/crates/phantom-fractal-store/src/graph.rs b/crates/phantom-fractal-store/src/graph.rs index 51ca2e0..ccf7ba0 100644 --- a/crates/phantom-fractal-store/src/graph.rs +++ b/crates/phantom-fractal-store/src/graph.rs @@ -112,6 +112,7 @@ pub(crate) fn reason_from_text(reason: &str) -> Result { "crate-path" => Ok(Reason::CratePath), "typed-method" => Ok(Reason::TypedMethod), "unique-method" => Ok(Reason::UniqueMethod), + "use-glob" => Ok(Reason::UseGlob), other => Err(StoreError::UnknownReason(other.to_owned())), } } @@ -127,6 +128,7 @@ pub(crate) fn reason_to_text(reason: Reason) -> &'static str { Reason::CratePath => "crate-path", Reason::TypedMethod => "typed-method", Reason::UniqueMethod => "unique-method", + Reason::UseGlob => "use-glob", } } diff --git a/crates/phantom-fractal/src/ops/index.rs b/crates/phantom-fractal/src/ops/index.rs index ec4d6d7..a6e49a3 100644 --- a/crates/phantom-fractal/src/ops/index.rs +++ b/crates/phantom-fractal/src/ops/index.rs @@ -96,6 +96,8 @@ struct EdgesByReason { typed_method: u64, #[serde(rename = "unique-method")] unique_method: u64, + #[serde(rename = "use-glob")] + use_glob: u64, } impl From for EdgesByReason { @@ -110,6 +112,7 @@ impl From for EdgesByReason { crate_path: counts.crate_path, typed_method: counts.typed_method, unique_method: counts.unique_method, + use_glob: counts.use_glob, } } } diff --git a/crates/phantom-fractal/tests/doctor.rs b/crates/phantom-fractal/tests/doctor.rs index 5b1ef1f..f6fe150 100644 --- a/crates/phantom-fractal/tests/doctor.rs +++ b/crates/phantom-fractal/tests/doctor.rs @@ -198,7 +198,7 @@ fn a_new_install_with_no_data_directory_is_ok() { check(&data, "network")["detail"], "none: Phantom has no network code" ); - assert_eq!(check(&data, "extractor")["detail"], "11"); + assert_eq!(check(&data, "extractor")["detail"], "12"); let grammar = check(&data, "grammar")["detail"].as_str().expect("grammar"); assert!(grammar.starts_with("tree-sitter-rust 0."), "{grammar}"); // An extra argument is usage. diff --git a/crates/phantom-fractal/tests/fresh.rs b/crates/phantom-fractal/tests/fresh.rs index 730bd72..b507d26 100644 --- a/crates/phantom-fractal/tests/fresh.rs +++ b/crates/phantom-fractal/tests/fresh.rs @@ -380,7 +380,7 @@ fn status_has_the_spec_keys_and_no_path() { ); assert_eq!( data["versions"], - json!({ "schema": 3, "extractor": 11, "envelope": 1 }) + json!({ "schema": 3, "extractor": 12, "envelope": 1 }) ); assert_eq!( data["epochs"], @@ -615,10 +615,10 @@ fn status_flags_an_index_from_another_extractor_version() { .filter(|check| check["name"] == "extractor" || check["name"] == "databases") .collect::>() }; - status(false, 11); + status(false, 12); let fresh = doctor(); let extractor = fresh.iter().find(|check| check["name"] == "extractor"); - assert_eq!(extractor.expect("extractor")["detail"], "11", "git {git}"); + assert_eq!(extractor.expect("extractor")["detail"], "12", "git {git}"); for stamp in [7, 8, 9, 10] { world.store().set_extractor_version(stamp).expect("stamp"); let db = world.db(); @@ -633,7 +633,7 @@ fn status_flags_an_index_from_another_extractor_version() { assert_eq!(doctor(), fresh, "git {git} stamp {stamp}"); assert_eq!(world.db(), db, "git {git} stamp {stamp}: a read wrote"); world.index(); - status(false, 11); + status(false, 12); } } } diff --git a/crates/phantom-fractal/tests/version.rs b/crates/phantom-fractal/tests/version.rs index 2f6f52f..1b7dd23 100644 --- a/crates/phantom-fractal/tests/version.rs +++ b/crates/phantom-fractal/tests/version.rs @@ -147,7 +147,7 @@ fn the_line_is_the_spec_envelope() { phantom_fractal_proto::SCHEMA_VERSION, ); assert_eq!(line, want); - assert_eq!(env["data"]["extractor_version"], 11, "{env}"); + assert_eq!(env["data"]["extractor_version"], 12, "{env}"); assert_eq!(env["data"]["store_schema"], 3, "{env}"); assert_eq!(env["schema"], 1, "{env}"); } diff --git a/fixtures/resolve/EXPECTED.md b/fixtures/resolve/EXPECTED.md index 28a784d..1f23023 100644 --- a/fixtures/resolve/EXPECTED.md +++ b/fixtures/resolve/EXPECTED.md @@ -3,13 +3,14 @@ title: Expected edges — resolve fixture type: fixture status: ground-truth created: "2026-10-26" -updated: "2026-10-27" +updated: "2026-11-14" owner: fullstack spec: "[[foundry/phantom/specs/SPEC-w3]]" cross_refs: - "[[foundry/phantom/checklists/CHECKLIST-w3]]" - "[[foundry/phantom/rubrics/RUBRIC-w3]]" - "[[foundry/phantom/specs/SPEC-w4]]" + - "[[foundry/phantom/specs/SPEC-w13]]" tags: - phantom - fixture @@ -42,6 +43,8 @@ same module has the same owner and name. The targets are `lib` (`src/lib.rs`), ` - `lib:crate::entry -> lib:crate::Counter::new@47 assoc` - `lib:crate::entry -> lib:crate::Counter::bump unique-method` - `lib:crate::tests::check -> lib:crate::local_fn path-exact` +- `lib:crate::entry -> lib:crate::shapes::area use-glob` +- `lib:crate::tests::check -> lib:crate::local_fn use-glob` - `lib:crate::util::helper -> lib:crate::util::deep::sink local` - `lib:crate::util::helper -> lib:crate::local_fn path-exact` - `lib:crate::util::deep::sink -> lib:crate::shapes::area path-exact` @@ -77,19 +80,25 @@ edges from `Guest::greet` or the module-level `inner`. The two `#[cfg]` |---|---|---| | `Counter::tally()` | `entry` | Only a trait impl has `tally`; `assoc` needs an inherent method. | | `std::mem::drop(1)` | `entry` | External: `std`. | -| `area()` | `entry` | Only the glob `use shapes::*` supplies `area`. | | `twin()` | `entry` | Two `#[cfg]` functions: two candidates. | | `shadow(2)` | `entry` | Shadowed by `let shadow`. | | `escaped::nothing()` | `entry` | `#[path = "../../outside.rs"]` leaves the root, so `escaped` has no module. | | `println!` | `entry` | A macro. | | `start_value()` | `static START` | Outside any function. | -| `local_fn()` | `tests::check` | Only the glob `use super::*` supplies it. | | `outside_crate::entry()` | `main` | A crate outside the workspace: external. | | `found()` | `src/orphan.rs` | No target reaches the file. | | `target()` | trait default `Greet::greet` | No source: a trait default body has no symbol. | | `target()` | nested `outer::inner` | No source: a nested fn has no symbol. | | `inner()` | `tricky::outer` | Shadowed by the nested `fn inner`. | +## Change for SPEC-w13 G2a + +Cure (b) places a bare name that only a glob of a workspace module supplies, with exactly one item of that name across the globbed modules, by `use-glob` at 0.85. Two calls the W4 rule left unresolved now get an edge, and the source comments `none: only the glob ...` predate it: +- `area()` in `entry`: `use shapes::*` globs `crate::shapes`, which declares one `area`; +- `local_fn()` in `tests::check`: `use super::*` globs the crate root, which declares one `local_fn`. + +So `edges` goes from 23 to 25 and `unresolved` from 8 to 6. No other line changes. + ## Change for SPEC-w4 G2c `src/main.rs:7` used to call `resolve_fixture::entry()`, this package's own lib by @@ -100,8 +109,8 @@ counts above are unchanged. ## Counts -- edges: 23 -- unresolved: 8 +- edges: 25 +- unresolved: 6 - external: 2 - no_source: 3 - method_calls: 0 From 4789a788c5c0452b746dd1d7aeb2b8ccd9b6a7bc Mon Sep 17 00:00:00 2001 From: VirtualMachinist <252028890+VirtualMachinist@users.noreply.github.com> Date: Sat, 14 Nov 2026 15:57:26 -0800 Subject: [PATCH 02/11] Put a module file that several roots declare in scope from each A non-inline mod declaration naming a file another root already reached now gives that later claimant a module row of its own on the file. The file keeps one row in files and in symbols, its first module, and its own declarations are read once, from its first claimant. The resolver answers a lookup in any module row from the first module of its file and scope, so the file items resolve from every claiming root by the existing tiers and reasons. The store picks a file module, for files, symbols and the resolver input, as its first module row. The command-line tests that pin the reason table and the resolve fixture counts follow the use-glob edges, and the resolve-tests fixture gains the call its second test root makes into the shared file. Co-Authored-By: Claude Opus 5.5 --- crates/phantom-fractal-extract/src/graph.rs | 10 ++++++--- crates/phantom-fractal-extract/tests/graph.rs | 17 ++++++++++++-- .../src/resolve/lookup.rs | 13 +++++++++++ crates/phantom-fractal-store/src/graph.rs | 8 +++++-- crates/phantom-fractal/tests/calls.rs | 14 ++++++++++-- crates/phantom-fractal/tests/commands.rs | 7 +++--- crates/phantom-fractal/tests/fresh.rs | 3 ++- fixtures/resolve-tests/EXPECTED.md | 22 ++++++++++++++----- 8 files changed, 75 insertions(+), 19 deletions(-) diff --git a/crates/phantom-fractal-extract/src/graph.rs b/crates/phantom-fractal-extract/src/graph.rs index 70a91b7..8f43103 100644 --- a/crates/phantom-fractal-extract/src/graph.rs +++ b/crates/phantom-fractal-extract/src/graph.rs @@ -283,13 +283,17 @@ impl<'a> Tree<'a> { let Some(child) = self.child_file(file, mod_rs, decl) else { continue; }; - if !self.claimed.insert(child.path.as_str()) { - continue; - } let id = self.push(target, Some(parent), path, &child.path, String::new()); if decl.cfg_test { self.cfg_test.insert(id); } + // A file another `mod` already reached keeps the module row of + // that later claimant, so its items are in scope from each + // root, and its own declarations are read once, from its first + // claimant (SPEC-w13 G2a, D9 (a)). + if !self.claimed.insert(child.path.as_str()) { + continue; + } // A `#[path]` file declares its children beside itself, as a // `mod.rs` does. let child_mod_rs = decl.path.is_some() || file_name(&child.path) == "mod.rs"; diff --git a/crates/phantom-fractal-extract/tests/graph.rs b/crates/phantom-fractal-extract/tests/graph.rs index c778a9c..b1e9d39 100644 --- a/crates/phantom-fractal-extract/tests/graph.rs +++ b/crates/phantom-fractal-extract/tests/graph.rs @@ -265,8 +265,11 @@ fn a_path_inside_an_inline_module_is_relative_to_its_directory() { assert_eq!(graph.modules[3].file, "src/a/inner/z.rs"); } +/// A file two roots declare keeps its first module, and the later +/// claimant gets a module row of its own on the same file (SPEC-w13 G2a, +/// D9 (a)). #[test] -fn a_file_reached_twice_keeps_its_first_module() { +fn a_file_reached_twice_gets_a_module_row_from_each_claimant() { let files = [ file("src/lib.rs", vec![decl("shared", "", false, None)]), file("src/main.rs", vec![decl("shared", "", false, None)]), @@ -279,6 +282,7 @@ fn a_file_reached_twice_keeps_its_first_module() { row("src/lib.rs", "crate", "src/lib.rs", ""), row("src/lib.rs", "crate::shared", "src/shared.rs", ""), row("src/main.rs", "crate", "src/main.rs", ""), + row("src/main.rs", "crate::shared", "src/shared.rs", ""), ] ); } @@ -368,6 +372,7 @@ fn test_targets_follow_every_lib_and_bin_so_those_keep_their_files() { row("b/src/lib.rs", "crate", "b/src/lib.rs", ""), row("b/src/lib.rs", "crate::x", "b/src/x.rs", ""), row("a/tests/t.rs", "crate", "a/tests/t.rs", ""), + row("a/tests/t.rs", "crate::x", "b/src/x.rs", ""), ] ); } @@ -400,9 +405,16 @@ fn a_test_root_looks_beside_itself_and_every_module_of_it_is_a_test_module() { "" ), row("tests/suite/main.rs", "crate", "tests/suite/main.rs", ""), + row( + "tests/suite/main.rs", + "crate::common", + "tests/common/mod.rs", + "" + ), ] ); - // `common` keeps its first module, under `plain`. + // `common` keeps its first module, under `plain`, which alone reads + // its `mod util`; `suite` gets a row of its own on the same file. let tests: Vec<&str> = graph .test_modules .iter() @@ -415,6 +427,7 @@ fn a_test_root_looks_beside_itself_and_every_module_of_it_is_a_test_module() { "tests/common/mod.rs", "tests/common/util.rs", "tests/suite/main.rs", + "tests/common/mod.rs", ] ); assert!(graph.orphans.is_empty(), "{:?}", graph.orphans); diff --git a/crates/phantom-fractal-lang-rust/src/resolve/lookup.rs b/crates/phantom-fractal-lang-rust/src/resolve/lookup.rs index de3b323..28eb071 100644 --- a/crates/phantom-fractal-lang-rust/src/resolve/lookup.rs +++ b/crates/phantom-fractal-lang-rust/src/resolve/lookup.rs @@ -684,6 +684,7 @@ impl<'a> Index<'a> { /// The child modules and items named `name` declared in `module`. A /// module item that has its own module row counts once, as the row. fn declared(&self, module: Id, name: &str) -> Vec { + let module = self.canonical(module); let mut local: Vec = self .children .get(&(module, name)) @@ -708,6 +709,7 @@ impl<'a> Index<'a> { /// them; with no such binding, unresolved when a glob could supply the /// name, else external. fn through_uses(&self, module: Id, name: &str, depth: u32) -> Result { + let module = self.canonical(module); let bindings = self.uses.get(&module).map_or(&[][..], Vec::as_slice); let mut found = Vec::new(); let mut crossed = false; @@ -743,6 +745,17 @@ impl<'a> Index<'a> { }) } + /// The first module row of `module`'s file and scope, where that + /// file's items and `use` bindings are kept: `module` itself, or for a + /// later claimant of a file several roots declare, the first claimant + /// (SPEC-w13 G2a, D9 (a)). + fn canonical(&self, module: Id) -> Id { + self.modules + .get(&module) + .and_then(|row| self.place_of(&row.file, &row.scope)) + .unwrap_or(module) + } + /// What a `use` path names, in any namespace. fn use_entities(&self, binding: &UseBinding, depth: u32) -> Result { let module = self diff --git a/crates/phantom-fractal-store/src/graph.rs b/crates/phantom-fractal-store/src/graph.rs index ccf7ba0..08f9253 100644 --- a/crates/phantom-fractal-store/src/graph.rs +++ b/crates/phantom-fractal-store/src/graph.rs @@ -257,6 +257,7 @@ impl crate::Store { "UPDATE files SET module_id = ( SELECT m.id FROM modules m WHERE m.file_id = files.id AND m.scope = '' + ORDER BY m.id LIMIT 1 )", [], )?; @@ -264,6 +265,7 @@ impl crate::Store { "UPDATE symbols SET module_id = ( SELECT m.id FROM modules m WHERE m.file_id = symbols.file_id AND m.scope = symbols.scope + ORDER BY m.id LIMIT 1 )", [], )?; @@ -359,7 +361,8 @@ impl crate::Store { { let mut statement = self.conn.prepare( "SELECT r.text, r.alias, r.glob, r.scope, f.path, - (SELECT m.id FROM modules m WHERE m.file_id = f.id AND m.scope = ''), + (SELECT m.id FROM modules m WHERE m.file_id = f.id AND m.scope = '' + ORDER BY m.id LIMIT 1), r.id FROM refs r JOIN files f ON f.id = r.file_id WHERE r.kind = 'use' ORDER BY r.id", @@ -384,7 +387,8 @@ impl crate::Store { { let mut statement = self.conn.prepare( "SELECT r.id, r.from_symbol, - (SELECT m.id FROM modules m WHERE m.file_id = r.file_id AND m.scope = ''), + (SELECT m.id FROM modules m WHERE m.file_id = r.file_id AND m.scope = '' + ORDER BY m.id LIMIT 1), r.scope, f.path, r.kind, r.text, r.receiver_hint, r.receiver, r.shadowed FROM refs r JOIN files f ON f.id = r.file_id WHERE r.kind IN ('call', 'method_call', 'macro', 'macro_arg') ORDER BY r.id", diff --git a/crates/phantom-fractal/tests/calls.rs b/crates/phantom-fractal/tests/calls.rs index 5f70771..9ce9da5 100644 --- a/crates/phantom-fractal/tests/calls.rs +++ b/crates/phantom-fractal/tests/calls.rs @@ -177,6 +177,7 @@ fn confidence(reason: &str) -> f64 { "assoc" | "self-method" | "self-assoc" => 0.9, "typed-method" => 0.8, "unique-method" => 0.5, + "use-glob" => 0.85, other => panic!("unknown reason {other}"), } } @@ -248,6 +249,7 @@ fn callers_and_callees_return_the_expected_sets() { ("crate::entry", "path-exact"), ("crate::entry", "local"), ("crate::tests::check", "path-exact"), + ("crate::tests::check", "use-glob"), ("crate::util::helper", "path-exact"), ("crate::placed::from_path", "path-exact"), ], @@ -313,10 +315,18 @@ fn callers_and_callees_return_the_expected_sets() { ("crate::placed::from_path", "local"), ("crate::Counter::new", "assoc"), ("crate::Counter::bump", "unique-method"), + ("crate::shapes::area", "use-glob"), ], - 7, + 6, + ), + ( + "tests::check", + &[ + ("crate::local_fn", "path-exact"), + ("crate::local_fn", "use-glob"), + ], + 0, ), - ("tests::check", &[("crate::local_fn", "path-exact")], 1), ( "util::helper", &[ diff --git a/crates/phantom-fractal/tests/commands.rs b/crates/phantom-fractal/tests/commands.rs index f19c3a7..27fc99c 100644 --- a/crates/phantom-fractal/tests/commands.rs +++ b/crates/phantom-fractal/tests/commands.rs @@ -25,7 +25,7 @@ const RESOLVE_SELF_FIXTURE: &str = const WORKSPACE_FIXTURE: &str = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures/workspace"); /// The keys of `edges_by_reason`: every reason `callers` and `callees` print. -const REASONS: [&str; 9] = [ +const REASONS: [&str; 10] = [ "path-exact", "local", "use-alias", @@ -35,6 +35,7 @@ const REASONS: [&str; 9] = [ "crate-path", "typed-method", "unique-method", + "use-glob", ]; /// The graph counts `index` adds, in `fixtures/resolve/EXPECTED.md` order. @@ -267,7 +268,7 @@ fn index_json_holds_no_absolute_path() { } } -/// `data.edges_by_reason`, after checking it has exactly the nine +/// `data.edges_by_reason`, after checking it has exactly the ten /// [`REASONS`] keys, each a count. fn reason_counts(env: &Value) -> BTreeMap<&str, u64> { let object = env["data"]["edges_by_reason"] @@ -346,7 +347,7 @@ fn index_reports_the_edges_by_reason_of_each_fixture() { /// database bytes as they were. #[test] fn index_reports_the_graph_counts_on_every_pass() { - let expected = [23, 8, 2, 3, 0, 1, 11, 1]; + let expected = [25, 6, 2, 3, 0, 1, 11, 1]; let fixture = Fixture::of(RESOLVE_FIXTURE); let (code, first) = fixture.index(BINS[1]); assert_eq!(code, Some(0), "{first}"); diff --git a/crates/phantom-fractal/tests/fresh.rs b/crates/phantom-fractal/tests/fresh.rs index b507d26..437b25e 100644 --- a/crates/phantom-fractal/tests/fresh.rs +++ b/crates/phantom-fractal/tests/fresh.rs @@ -575,7 +575,8 @@ fn index_lists_typed_method_after_crate_path() { "self-assoc", "crate-path", "typed-method", - "unique-method" + "unique-method", + "use-glob" ], "{line}" ); diff --git a/fixtures/resolve-tests/EXPECTED.md b/fixtures/resolve-tests/EXPECTED.md index 323af79..bb1822d 100644 --- a/fixtures/resolve-tests/EXPECTED.md +++ b/fixtures/resolve-tests/EXPECTED.md @@ -3,12 +3,13 @@ title: Expected edges — resolve-tests fixture type: fixture status: ground-truth created: "2026-10-31" -updated: "2026-10-31" +updated: "2026-11-14" owner: fullstack spec: "[[foundry/phantom/specs/SPEC-w11]]" cross_refs: - "[[foundry/phantom/checklists/CHECKLIST-w11]]" - "[[foundry/phantom/rubrics/RUBRIC-w11]]" + - "[[foundry/phantom/specs/SPEC-w13]]" tags: - phantom - fixture @@ -54,7 +55,7 @@ A symbol is written `/:::`, with the impl ow | `a_typed_method_call` | `Counter::new()` | as above | `crate-path` | | `a_typed_method_call` | `counter.bump()` | `let mut counter = Counter::new()` gives `ctor:Counter::new`; placing it needs the test module's `use app::Counter` | `typed-method` | | `suite_case` | `app::add(3, 4)` | the second test target calls the lib too | `crate-path` | -| `suite_case` | `common::fresh()` | `suite` has no `common` module | none (unresolved) | +| `suite_case` | `common::fresh()` | `suite` declares `common` too, so it has its own module row on `tests/common/mod.rs` (SPEC-w13 G2a, D9 (a)) | `local` | | `app` lib `checked` | `probe::check(value)` | a lib ignores dev entries | none (external) | | `app` bin `main` | `app::add(1, 2)` | a bin may call its own lib, as before | `crate-path` | | `app` bin `main` | `probe::check(total)` | a bin ignores dev entries | none (external) | @@ -73,16 +74,25 @@ A symbol is written `/:::`, with the impl ow - `app/test-plain:crate::through_a_use_alias -> app/lib:crate::add crate-path` - `app/test-plain:crate::through_a_use_alias -> app/test-plain:crate::common::fresh use-alias` - `app/test-suite:crate::suite_case -> app/lib:crate::add crate-path` +- `app/test-suite:crate::suite_case -> app/test-plain:crate::common::fresh local` + +## Change for SPEC-w13 G2a + +Cure (a) of D9 puts a file that several roots declare in scope from each of them. `tests/common/mod.rs` is declared by `plain.rs` and by `suite/main.rs`. It keeps its first module and its symbols under `plain`, as before, and `suite` gets a module row of its own on that file. So: +- `common::fresh()` in `suite_case` resolves by `local` to the one `common::fresh` symbol; +- `edges` goes from 11 to 12, `unresolved` from 3 to 2, and `modules` from 6 to 7. + +No other line changes. ## Counts -- edges: 11 -- unresolved: 3 +- edges: 12 +- unresolved: 2 - external: 2 - no_source: 0 - method_calls: 0 - macros: 0 -- modules: 6 +- modules: 7 - orphans: 2 -`unresolved` is `common::fresh()` in `suite_case` and the `app::add` calls of the two orphans. `external` is `probe::check` from the lib and from the bin. +`unresolved` is the `app::add` calls of the two orphans. `external` is `probe::check` from the lib and from the bin. From b3a13eaf1737663ad19acc15b8b212cd3cead5be Mon Sep 17 00:00:00 2001 From: VirtualMachinist <252028890+VirtualMachinist@users.noreply.github.com> Date: Sat, 14 Nov 2026 16:00:45 -0800 Subject: [PATCH 03/11] Add the resolve-dogfood fixture and the shared-module tests The fixture covers a shared test helper from two test roots, a glob with one candidate, two candidates left unresolved, a local item that wins over the glob, a call the base tiers already place, a two-hop re-export the base tiers follow and a re-export cycle they refuse. The resolver tests cover a shared module file reached from each claiming root by a path, a use and a glob, and the store test checks that the shared file keeps one file row, one symbol row and its first module. Co-Authored-By: Claude Opus 5.5 --- .../tests/resolve_dogfood.rs | 94 ++++++++++++++ .../tests/shared_module.rs | 119 ++++++++++++++++++ fixtures/resolve-dogfood/Cargo.toml | 4 + fixtures/resolve-dogfood/EXPECTED.md | 70 +++++++++++ fixtures/resolve-dogfood/src/alt.rs | 1 + fixtures/resolve-dogfood/src/cycle.rs | 5 + fixtures/resolve-dogfood/src/lib.rs | 24 ++++ fixtures/resolve-dogfood/src/mid.rs | 1 + fixtures/resolve-dogfood/src/model.rs | 17 +++ fixtures/resolve-dogfood/src/prelude.rs | 1 + fixtures/resolve-dogfood/tests/common/mod.rs | 3 + fixtures/resolve-dogfood/tests/first.rs | 6 + fixtures/resolve-dogfood/tests/second.rs | 9 ++ 13 files changed, 354 insertions(+) create mode 100644 crates/phantom-fractal-extract/tests/resolve_dogfood.rs create mode 100644 crates/phantom-fractal-lang-rust/tests/shared_module.rs create mode 100644 fixtures/resolve-dogfood/Cargo.toml create mode 100644 fixtures/resolve-dogfood/EXPECTED.md create mode 100644 fixtures/resolve-dogfood/src/alt.rs create mode 100644 fixtures/resolve-dogfood/src/cycle.rs create mode 100644 fixtures/resolve-dogfood/src/lib.rs create mode 100644 fixtures/resolve-dogfood/src/mid.rs create mode 100644 fixtures/resolve-dogfood/src/model.rs create mode 100644 fixtures/resolve-dogfood/src/prelude.rs create mode 100644 fixtures/resolve-dogfood/tests/common/mod.rs create mode 100644 fixtures/resolve-dogfood/tests/first.rs create mode 100644 fixtures/resolve-dogfood/tests/second.rs diff --git a/crates/phantom-fractal-extract/tests/resolve_dogfood.rs b/crates/phantom-fractal-extract/tests/resolve_dogfood.rs new file mode 100644 index 0000000..818ba04 --- /dev/null +++ b/crates/phantom-fractal-extract/tests/resolve_dogfood.rs @@ -0,0 +1,94 @@ +//! The index pass over `fixtures/resolve-dogfood`, checked against its +//! `EXPECTED.md` (SPEC-w13 G2a): the D9 cures and the cases they leave. + +mod common; +mod fixture; + +use fixture::{assert_matches_expected, db_digest, graph, run, setup, stored_edges}; + +const FIXTURE: &str = concat!( + env!("CARGO_MANIFEST_DIR"), + "/../../fixtures/resolve-dogfood" +); +const EXPECTED: &str = include_str!("../../../fixtures/resolve-dogfood/EXPECTED.md"); + +#[test] +fn fixture_edges_and_counts_match_expected_exactly() { + let mut s = setup(FIXTURE); + let report = run(&mut s); + assert_matches_expected(&s.store, &graph(&report), EXPECTED); +} + +#[test] +fn a_second_pass_writes_nothing() { + let mut s = setup(FIXTURE); + run(&mut s); + let edges = stored_edges(&s.store); + let before = db_digest(&s); + let report = run(&mut s); + assert!(report.written.is_empty(), "{:?}", report.written); + assert_eq!(report.graph, None); + assert_eq!(stored_edges(&s.store), edges); + assert_eq!(db_digest(&s), before); +} + +/// The store keeps one file row and one symbol row for the shared file, +/// and every read that picks a file's module takes its first module row: +/// the module of its symbols, of the `use` and call rows of the file, and +/// the module a name query reports (SPEC-w13 G2a, D9 (a), R13). +#[test] +fn the_shared_file_keeps_one_row_each_and_its_first_module() { + let mut s = setup(FIXTURE); + run(&mut s); + let input = s.store.resolve_input().expect("resolve input"); + let rows: Vec<&phantom_fractal_lang::Module> = input + .modules + .iter() + .filter(|module| module.file == "tests/common/mod.rs") + .collect(); + assert_eq!(rows.len(), 2, "{rows:?}"); + let (first, later) = (rows[0], rows[1]); + assert!(first.id < later.id); + let targets: Vec<&str> = [first, later] + .iter() + .map(|module| { + input + .targets + .iter() + .find(|target| target.id == module.target) + .map_or("", |target| target.root.as_str()) + }) + .collect(); + assert_eq!(targets, ["tests/first.rs", "tests/second.rs"]); + let shared: Vec<&phantom_fractal_lang::Symbol> = input + .symbols + .iter() + .filter(|symbol| symbol.file == "tests/common/mod.rs") + .collect(); + assert_eq!(shared.len(), 1, "{shared:?}"); + assert_eq!(shared[0].module, Some(first.id)); + let second_root = input + .modules + .iter() + .find(|module| module.file == "tests/second.rs" && module.parent.is_none()) + .expect("second root"); + let glob = input + .uses + .iter() + .find(|binding| binding.file == "tests/second.rs" && binding.glob) + .expect("the glob"); + assert_eq!(glob.module, Some(second_root.id)); + let found = s + .store + .symbols_matching("common::fixture_data") + .expect("query"); + assert_eq!(found.len(), 1, "{found:?}"); + assert_eq!(found[0].module_path, "crate::common"); + assert_eq!(found[0].file, "tests/common/mod.rs"); + let files = s.store.file_paths().expect("paths"); + let at = files + .iter() + .filter(|path| path.as_str() == "tests/common/mod.rs") + .count(); + assert_eq!(at, 1); +} diff --git a/crates/phantom-fractal-lang-rust/tests/shared_module.rs b/crates/phantom-fractal-lang-rust/tests/shared_module.rs new file mode 100644 index 0000000..7bb951b --- /dev/null +++ b/crates/phantom-fractal-lang-rust/tests/shared_module.rs @@ -0,0 +1,119 @@ +//! Cure (a), a module file that several roots declare (SPEC-w13 G2a, D9). +//! +//! Each later claimant of the file has a module row of its own on it, +//! while the file's items and `use` bindings sit with its first module. +//! A lookup in any of those rows answers from the first, so the file's +//! items resolve from every claiming root by the existing tiers and +//! reasons. + +mod support; + +use phantom_fractal_lang::{Id, Reason, RefKind, SymbolKind, TargetKind}; +use support::{Input, edge}; + +const COMMON: &str = "tests/common/mod.rs"; + +/// Two test targets, `a` and `b`, each declaring `mod common;` on one +/// file whose items are `fresh` and `start`: the first module row of the +/// file is `a`'s. +struct Shared { + i: Input, + a: Id, + b: Id, + fresh: Id, +} + +fn shared() -> Shared { + let mut i = Input::new(); + let a = i.target("pkg", TargetKind::Test, "tests/a.rs"); + let b = i.target("pkg", TargetKind::Test, "tests/b.rs"); + i.module(a, "common", COMMON, ""); + i.module(b, "common", COMMON, ""); + let fresh = i.symbol(SymbolKind::Function, "fresh", COMMON, ""); + i.symbol(SymbolKind::Function, "start", COMMON, ""); + Shared { i, a, b, fresh } +} + +/// A function `name` at the root of the test target rooted at `root`. +fn test_fn(i: &mut Input, root: &str, name: &str) -> Id { + i.symbol(SymbolKind::Function, name, root, "") +} + +#[test] +fn each_claiming_root_reaches_the_file_items_by_the_existing_tiers() { + let mut s = shared(); + let in_a = test_fn(&mut s.i, "tests/a.rs", "in_a"); + let in_b = test_fn(&mut s.i, "tests/b.rs", "in_b"); + let first = s.i.call_from(in_a, "tests/a.rs", "common::fresh"); + let later = s.i.call_from(in_b, "tests/b.rs", "common::fresh"); + let by_path = s.i.call_from(in_b, "tests/b.rs", "crate::common::fresh"); + let (edges, counts) = s.i.resolve(); + assert_eq!( + edges, + [ + edge(first, in_a, s.fresh, Reason::Local), + edge(later, in_b, s.fresh, Reason::Local), + edge(by_path, in_b, s.fresh, Reason::PathExact), + ] + ); + assert_eq!(counts.unresolved, 0); + let _ = (s.a, s.b); +} + +#[test] +fn a_later_claimant_reaches_the_file_items_through_a_use_and_a_glob() { + let mut s = shared(); + s.i.uses("tests/b.rs", "", "common::fresh", None, false); + let in_b = test_fn(&mut s.i, "tests/b.rs", "in_b"); + let alias = s.i.call_from(in_b, "tests/b.rs", "fresh"); + let mut g = shared(); + g.i.uses("tests/b.rs", "", "common", None, true); + let in_g = test_fn(&mut g.i, "tests/b.rs", "in_b"); + let glob = g.i.call_from(in_g, "tests/b.rs", "fresh"); + assert_eq!( + s.i.resolve().0, + [edge(alias, in_b, s.fresh, Reason::UseAlias)] + ); + assert_eq!( + g.i.resolve().0, + [edge(glob, in_g, g.fresh, Reason::UseGlob)] + ); +} + +#[test] +fn a_call_inside_the_shared_file_resolves_from_its_first_module() { + let mut s = shared(); + let start = + s.i.input + .symbols + .iter() + .find(|symbol| symbol.name == "start") + .map(|symbol| symbol.id) + .expect("start"); + let call = + s.i.call_in(Some(s.fresh), COMMON, "", "start", RefKind::Call); + // `super` from the file's first module is `a`'s root. + let root_fn = test_fn(&mut s.i, "tests/a.rs", "helper"); + let up = + s.i.call_in(Some(s.fresh), COMMON, "", "super::helper", RefKind::Call); + assert_eq!( + s.i.resolve().0, + [ + edge(call, s.fresh, start, Reason::Local), + edge(up, s.fresh, root_fn, Reason::PathExact), + ] + ); +} + +#[test] +fn a_root_that_does_not_declare_the_file_does_not_reach_it() { + let mut s = shared(); + let c = s.i.target("pkg", TargetKind::Test, "tests/c.rs"); + let in_c = test_fn(&mut s.i, "tests/c.rs", "in_c"); + s.i.call_from(in_c, "tests/c.rs", "common::fresh"); + let (edges, counts) = s.i.resolve(); + assert!(edges.is_empty(), "{edges:?}"); + // Nothing in `c` binds `common`, and it has no glob: external. + assert_eq!((counts.unresolved, counts.external), (0, 1)); + let _ = c; +} diff --git a/fixtures/resolve-dogfood/Cargo.toml b/fixtures/resolve-dogfood/Cargo.toml new file mode 100644 index 0000000..125823a --- /dev/null +++ b/fixtures/resolve-dogfood/Cargo.toml @@ -0,0 +1,4 @@ +[package] +name = "dogfood" +version = "0.1.0" +edition = "2024" diff --git a/fixtures/resolve-dogfood/EXPECTED.md b/fixtures/resolve-dogfood/EXPECTED.md new file mode 100644 index 0000000..438a325 --- /dev/null +++ b/fixtures/resolve-dogfood/EXPECTED.md @@ -0,0 +1,70 @@ +--- +title: Expected edges — resolve-dogfood fixture +type: fixture +status: ground-truth +created: "2026-11-14" +updated: "2026-11-14" +owner: fullstack +spec: "[[foundry/phantom/specs/SPEC-w13]]" +cross_refs: + - "[[foundry/phantom/checklists/CHECKLIST-w13]]" + - "[[foundry/phantom/rubrics/RUBRIC-w13]]" + - "[[foundry/phantom/goals/GOAL-w13-fence]]" + - "[[foundry/phantom/w13]]" +tags: + - phantom + - fixture + - w13 +--- + +# Expected edges — `fixtures/resolve-dogfood` + +Ground truth for [[foundry/phantom/specs/SPEC-w13]] G2a: the D9 cures, and the cases they leave alone. The test `crates/phantom-fractal-extract/tests/resolve_dogfood.rs` indexes a copy of this package. It asserts three things exactly: the stored edge set equals the **Edges** list, every **Counts** line matches, and the per-reason counts equal the reasons in **Edges**. + +There is one package, `dogfood`, with three targets: +- `lib`, rooted at `src/lib.rs`; +- `test-first`, rooted at `tests/first.rs`; +- `test-second`, rooted at `tests/second.rs`. + +Both test roots declare `mod common;` on `tests/common/mod.rs`. A symbol is written `:::`, with the impl owner before a method's name. Each line is `caller -> callee reason`. + +## Cases + +| Cure | Call | In | Why | Edge | +|---|---|---|---|---| +| (a) | `common::fixture_data()` | `first_case` | the first claimant of `tests/common/mod.rs` | `local` | +| (a) | `common::fixture_data()` | `second_case` | `second` declares `common` too, so it has its own module row on the file, whose items sit with the first | `local` | +| (a) and (b) | `fixture_data()` | `second_case` | `use common::*` globs the later claimant's row, which gives the one `fixture_data` | `use-glob` | +| (b) | `build()` | `entry` | only the glob `use model::*` supplies `build`, and `model` declares one | `use-glob` | +| (b) | `twin()` | `entry` | `model` and `alt` both declare `twin`: two candidates | none (unresolved) | +| (b) | `local_wins()` | `entry` | the crate root declares `local_wins` itself, so the base tier places it and the glob is never tried | `local` to `crate::local_wins` | +| base | `model::build()` | `entry` | a call the base tiers place keeps its edge | `local` | +| (c), skipped | `prelude::Gadget::new()` | `entry` | two `pub use` hops, from `prelude` to `mid` to `model`, which the base tiers already follow | `local` to `model::Gadget::new` | +| (c), skipped | `cycle::looped()` | `entry` | `cycle` re-exports `inner::looped`, which re-exports `super::looped`: a cycle, refused at the depth limit | none (unresolved) | + +Cure (c) is skipped by ruling R12, and the reasons are in [[foundry/phantom/evidence/w13/G2-fullstack]]. Its two shapes stay here because the base tiers already decide them. + +## Edges + +- `lib:crate::entry -> lib:crate::local_wins local` +- `lib:crate::entry -> lib:crate::model::Gadget::new local` +- `lib:crate::entry -> lib:crate::model::build local` +- `lib:crate::entry -> lib:crate::model::build use-glob` +- `test-first:crate::first_case -> test-first:crate::common::fixture_data local` +- `test-second:crate::second_case -> test-first:crate::common::fixture_data local` +- `test-second:crate::second_case -> test-first:crate::common::fixture_data use-glob` + +## Counts + +- edges: 7 +- unresolved: 2 +- external: 0 +- no_source: 0 +- method_calls: 0 +- macros: 0 +- modules: 11 +- orphans: 0 + +`unresolved` is `twin()` and `cycle::looped()`. + +`modules` counts three groups of rows. `lib` has seven: `crate`, `alt`, `cycle`, `cycle::inner`, `mid`, `model` and `prelude`. `test-first` has `crate` and `common`. `test-second` has `crate` and its own `common` row on the shared file. diff --git a/fixtures/resolve-dogfood/src/alt.rs b/fixtures/resolve-dogfood/src/alt.rs new file mode 100644 index 0000000..1872aec --- /dev/null +++ b/fixtures/resolve-dogfood/src/alt.rs @@ -0,0 +1 @@ +pub fn twin() {} diff --git a/fixtures/resolve-dogfood/src/cycle.rs b/fixtures/resolve-dogfood/src/cycle.rs new file mode 100644 index 0000000..6047863 --- /dev/null +++ b/fixtures/resolve-dogfood/src/cycle.rs @@ -0,0 +1,5 @@ +pub use self::inner::looped; + +pub mod inner { + pub use super::looped; +} diff --git a/fixtures/resolve-dogfood/src/lib.rs b/fixtures/resolve-dogfood/src/lib.rs new file mode 100644 index 0000000..5df4ca9 --- /dev/null +++ b/fixtures/resolve-dogfood/src/lib.rs @@ -0,0 +1,24 @@ +//! The dogfood cures of SPEC-w13 G2a (D9). + +mod alt; +mod cycle; +mod mid; +mod model; +pub mod prelude; + +use alt::*; +use model::*; + +pub fn local_wins() -> u32 { + 0 +} + +pub fn entry() -> u32 { + let one = build(); // (b) one candidate: only `model` declares `build` + twin(); // (b) two candidates: `model` and `alt` both declare `twin` + local_wins(); // (b) shadowed: a local item beats the glob + model::build(); // already placed by the base tiers: keeps `local` + prelude::Gadget::new(); // (c) two hops: prelude, then mid, then model + cycle::looped(); // (c) a cycle of re-exports: refused + one +} diff --git a/fixtures/resolve-dogfood/src/mid.rs b/fixtures/resolve-dogfood/src/mid.rs new file mode 100644 index 0000000..6efcf5c --- /dev/null +++ b/fixtures/resolve-dogfood/src/mid.rs @@ -0,0 +1 @@ +pub use crate::model::Gadget; diff --git a/fixtures/resolve-dogfood/src/model.rs b/fixtures/resolve-dogfood/src/model.rs new file mode 100644 index 0000000..875bbcf --- /dev/null +++ b/fixtures/resolve-dogfood/src/model.rs @@ -0,0 +1,17 @@ +pub fn build() -> u32 { + 1 +} + +pub fn twin() {} + +pub fn local_wins() -> u32 { + 2 +} + +pub struct Gadget; + +impl Gadget { + pub fn new() -> Gadget { + Gadget + } +} diff --git a/fixtures/resolve-dogfood/src/prelude.rs b/fixtures/resolve-dogfood/src/prelude.rs new file mode 100644 index 0000000..8d51d95 --- /dev/null +++ b/fixtures/resolve-dogfood/src/prelude.rs @@ -0,0 +1 @@ +pub use crate::mid::Gadget; diff --git a/fixtures/resolve-dogfood/tests/common/mod.rs b/fixtures/resolve-dogfood/tests/common/mod.rs new file mode 100644 index 0000000..ef67afc --- /dev/null +++ b/fixtures/resolve-dogfood/tests/common/mod.rs @@ -0,0 +1,3 @@ +pub fn fixture_data() -> u32 { + 3 +} diff --git a/fixtures/resolve-dogfood/tests/first.rs b/fixtures/resolve-dogfood/tests/first.rs new file mode 100644 index 0000000..6f06abe --- /dev/null +++ b/fixtures/resolve-dogfood/tests/first.rs @@ -0,0 +1,6 @@ +mod common; + +#[test] +fn first_case() { + common::fixture_data(); // (a) the first claimant +} diff --git a/fixtures/resolve-dogfood/tests/second.rs b/fixtures/resolve-dogfood/tests/second.rs new file mode 100644 index 0000000..c574ec0 --- /dev/null +++ b/fixtures/resolve-dogfood/tests/second.rs @@ -0,0 +1,9 @@ +mod common; + +use common::*; + +#[test] +fn second_case() { + common::fixture_data(); // (a) a later claimant + fixture_data(); // (a) and (b): the glob of the later claimant's row +} From d437f1dfb84a9c1c44dc553a280d19af2565fd49 Mon Sep 17 00:00:00 2001 From: VirtualMachinist <252028890+VirtualMachinist@users.noreply.github.com> Date: Sat, 14 Nov 2026 17:20:53 -0800 Subject: [PATCH 04/11] Keep the import links a later claimant row of a shared file would move An import whose path now ends at a later claimant module row of a shared file names what it named before that row existed: the one mod item of that name in the parent module. So every existing link keeps its endpoints, and only links the shared file newly makes reachable are added. Co-Authored-By: Claude Opus 5.5 --- .../src/resolve/lookup.rs | 2 +- .../src/resolve/lookup/cures.rs | 22 ++++++++++++-- .../tests/shared_module.rs | 29 ++++++++++++++++++- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/crates/phantom-fractal-lang-rust/src/resolve/lookup.rs b/crates/phantom-fractal-lang-rust/src/resolve/lookup.rs index 28eb071..7dc4874 100644 --- a/crates/phantom-fractal-lang-rust/src/resolve/lookup.rs +++ b/crates/phantom-fractal-lang-rust/src/resolve/lookup.rs @@ -320,7 +320,7 @@ impl<'a> Index<'a> { // A call reaches a binding one level down from its own lookup. let walked = self.use_entities(binding, 1).ok()?; let target = match walked.entities[..] { - [Entity::Module(id)] => Node::Module(id), + [Entity::Module(id)] => self.link_node(id), [Entity::Symbol(id)] => Node::Symbol(id), _ => return None, }; diff --git a/crates/phantom-fractal-lang-rust/src/resolve/lookup/cures.rs b/crates/phantom-fractal-lang-rust/src/resolve/lookup/cures.rs index d01d8f6..defc811 100644 --- a/crates/phantom-fractal-lang-rust/src/resolve/lookup/cures.rs +++ b/crates/phantom-fractal-lang-rust/src/resolve/lookup/cures.rs @@ -10,11 +10,29 @@ //! from that module by the existing tiers. The edge's reason is //! `use-glob`. Two candidates, or none, give no edge. -use phantom_fractal_lang::{CallRef, Id, Reason}; +use phantom_fractal_lang::{CallRef, Id, Node, Reason, SymbolKind}; -use super::{Entity, Index, Placed, segments}; +use super::{Entity, Index, Placed, last_segment, segments}; impl Index<'_> { + /// What an `import` link to module row `id` names. A later claimant's + /// row of a shared file, which cure (a) adds, names what the link named + /// before it was there: the one `mod` item of that name in the parent + /// module. So no existing link moves (D10). + pub(crate) fn link_node(&self, id: Id) -> Node { + if self.canonical(id) == id { + return Node::Module(id); + } + let item = self.modules.get(&id).and_then(|row| { + let items = self.items.get(&(row.parent?, last_segment(&row.path)))?; + let [one] = items[..] else { + return None; + }; + (self.kind(one) == Some(SymbolKind::Module)).then_some(one) + }); + item.map_or(Node::Module(id), Node::Symbol) + } + /// A `Call`, or a path in a macro's tokens, by the base tiers and, /// when they leave it unresolved, by the cures. pub(crate) fn place_cured(&self, call: &CallRef, source: Id) -> Placed { diff --git a/crates/phantom-fractal-lang-rust/tests/shared_module.rs b/crates/phantom-fractal-lang-rust/tests/shared_module.rs index 7bb951b..8e3781e 100644 --- a/crates/phantom-fractal-lang-rust/tests/shared_module.rs +++ b/crates/phantom-fractal-lang-rust/tests/shared_module.rs @@ -8,7 +8,8 @@ mod support; -use phantom_fractal_lang::{Id, Reason, RefKind, SymbolKind, TargetKind}; +use phantom_fractal_lang::{Id, LinkKind, Node, Reason, RefKind, SymbolKind, TargetKind}; +use phantom_fractal_lang_rust::links; use support::{Input, edge}; const COMMON: &str = "tests/common/mod.rs"; @@ -117,3 +118,29 @@ fn a_root_that_does_not_declare_the_file_does_not_reach_it() { assert_eq!((counts.unresolved, counts.external), (0, 1)); let _ = c; } + +#[test] +fn an_import_of_the_shared_module_keeps_the_link_it_had() { + let mut s = shared(); + // Each root declares `mod common;`, an item of kind module. + s.i.symbol(SymbolKind::Module, "common", "tests/a.rs", ""); + let item_b = s.i.symbol(SymbolKind::Module, "common", "tests/b.rs", ""); + s.i.uses("tests/a.rs", "", "crate::common", None, false); + s.i.uses("tests/b.rs", "", "crate::common", None, false); + let first_row = + s.i.input + .modules + .iter() + .find(|module| module.file == COMMON) + .map(|module| module.id) + .expect("first row"); + let targets: Vec = links(&s.i.input) + .into_iter() + .filter(|link| link.kind == LinkKind::Import) + .map(|link| link.target) + .collect(); + // The first claimant's link names its module row; the later claimant's + // names its `mod common` item, as before its row existed. + assert_eq!(targets, [Node::Module(first_row), Node::Symbol(item_b)]); + let _ = (s.a, s.b); +} From 3ef1c8269790d3a4149e49c8f611c624a9d0a6ee Mon Sep 17 00:00:00 2001 From: VirtualMachinist <252028890+VirtualMachinist@users.noreply.github.com> Date: Sat, 14 Nov 2026 17:48:48 -0800 Subject: [PATCH 05/11] Name the one-function step of the glob cure and list its dispatch growth The glob cure picks the one function its walk names through a named helper, and a test keeps a use of another name from blocking it. The lang, lang-rust and extract instances list the Reason dispatch matches that the use-glob reason grows by one arm as CRAP exemptions, each with its reason and an expiry. Co-Authored-By: Claude Opus 5.5 --- crates/phantom-fractal-extract/rust-tops.yaml | 8 ++++++++ crates/phantom-fractal-lang-rust/rust-tops.yaml | 8 ++++++++ .../src/resolve/lookup/cures.rs | 11 ++++++++--- crates/phantom-fractal-lang-rust/tests/glob_cure.rs | 11 +++++++++++ crates/phantom-fractal-lang/rust-tops.yaml | 8 ++++++++ 5 files changed, 43 insertions(+), 3 deletions(-) diff --git a/crates/phantom-fractal-extract/rust-tops.yaml b/crates/phantom-fractal-extract/rust-tops.yaml index 8d69df6..2bb6405 100644 --- a/crates/phantom-fractal-extract/rust-tops.yaml +++ b/crates/phantom-fractal-extract/rust-tops.yaml @@ -140,3 +140,11 @@ agent: - fmt - clippy - nextest + +exemptions: + - path: src/lib.rs + symbol: ReasonCounts::slot + layer: crap + reason: exhaustive dispatch match over Reason with no guards, each arm one value; the use-glob reason of SPEC-w13 G2a adds one arm, and R4(4) forbids a split made for CRAP alone + owner: phantom-fractal-extract + expires: "2027-02-14" diff --git a/crates/phantom-fractal-lang-rust/rust-tops.yaml b/crates/phantom-fractal-lang-rust/rust-tops.yaml index 6392a82..c032875 100644 --- a/crates/phantom-fractal-lang-rust/rust-tops.yaml +++ b/crates/phantom-fractal-lang-rust/rust-tops.yaml @@ -140,3 +140,11 @@ agent: - fmt - clippy - nextest + +exemptions: + - path: src/resolve.rs + symbol: confidence + layer: crap + reason: exhaustive dispatch match over Reason with no guards, each arm one value; the use-glob reason of SPEC-w13 G2a adds one arm, and R4(4) forbids a split made for CRAP alone + owner: phantom-fractal-lang-rust + expires: "2027-02-14" diff --git a/crates/phantom-fractal-lang-rust/src/resolve/lookup/cures.rs b/crates/phantom-fractal-lang-rust/src/resolve/lookup/cures.rs index defc811..6e36c4e 100644 --- a/crates/phantom-fractal-lang-rust/src/resolve/lookup/cures.rs +++ b/crates/phantom-fractal-lang-rust/src/resolve/lookup/cures.rs @@ -52,15 +52,20 @@ impl Index<'_> { let segs = segments(&call.text)?; let home = self.glob_home(module, segs.first()?)?; let walked = self.walk(home, &segs, 0, true).ok()?; - let functions: Vec = walked - .entities + let target = self.one_function(&walked.entities)?; + Some(Placed::Edge(target, Reason::UseGlob)) + } + + /// The one function or method `entities` name, if exactly one. + fn one_function(&self, entities: &[Entity]) -> Option { + let functions: Vec = entities .iter() .filter_map(|entity| self.function(*entity)) .collect(); let [target] = functions[..] else { return None; }; - Some(Placed::Edge(target, Reason::UseGlob)) + Some(target) } /// The globbed module of `module` that gives `name`, when nothing in diff --git a/crates/phantom-fractal-lang-rust/tests/glob_cure.rs b/crates/phantom-fractal-lang-rust/tests/glob_cure.rs index 20e70f2..bfbfd5d 100644 --- a/crates/phantom-fractal-lang-rust/tests/glob_cure.rs +++ b/crates/phantom-fractal-lang-rust/tests/glob_cure.rs @@ -194,3 +194,14 @@ fn the_cure_adds_no_link() { call_in_tests(&mut i, check, "helper"); assert!(links(&i.input).is_empty()); } + +#[test] +fn a_use_of_another_name_leaves_the_glob_free_to_supply_this_one() { + let (mut i, check) = tests_module(); + let helper = i.function("helper"); + i.function("other"); + // `use super::other;` binds `other`, not `helper`. + i.uses(LIB, "tests", "super::other", None, false); + let call = call_in_tests(&mut i, check, "helper"); + assert_eq!(i.resolve().0, [edge(call, check, helper, Reason::UseGlob)]); +} diff --git a/crates/phantom-fractal-lang/rust-tops.yaml b/crates/phantom-fractal-lang/rust-tops.yaml index 1c90e17..ead7bcf 100644 --- a/crates/phantom-fractal-lang/rust-tops.yaml +++ b/crates/phantom-fractal-lang/rust-tops.yaml @@ -141,3 +141,11 @@ agent: - fmt - clippy - nextest + +exemptions: + - path: src/resolve.rs + symbol: Reason::as_str + layer: crap + reason: exhaustive dispatch match over Reason with no guards, each arm one value; the use-glob reason of SPEC-w13 G2a adds one arm, and R4(4) forbids a split made for CRAP alone + owner: phantom-fractal-lang + expires: "2027-02-14" From da8b06b7b99846460458dfa4f7d8f6a17e6ce4fc Mon Sep 17 00:00:00 2001 From: VirtualMachinist <252028890+VirtualMachinist@users.noreply.github.com> Date: Sat, 14 Nov 2026 17:49:36 -0800 Subject: [PATCH 06/11] List the store reason matches that use-glob grows as CRAP exemptions Co-Authored-By: Claude Opus 5.5 --- crates/phantom-fractal-store/rust-tops.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/crates/phantom-fractal-store/rust-tops.yaml b/crates/phantom-fractal-store/rust-tops.yaml index 04e4981..6552894 100644 --- a/crates/phantom-fractal-store/rust-tops.yaml +++ b/crates/phantom-fractal-store/rust-tops.yaml @@ -140,3 +140,17 @@ agent: - fmt - clippy - nextest + +exemptions: + - path: src/graph.rs + symbol: reason_from_text + layer: crap + reason: exhaustive dispatch match over the reason texts with no guards, each arm one value; the use-glob reason of SPEC-w13 G2a adds one arm, and R4(4) forbids a split made for CRAP alone + owner: phantom-fractal-store + expires: "2027-02-14" + - path: src/graph.rs + symbol: reason_to_text + layer: crap + reason: exhaustive dispatch match over Reason with no guards, each arm one value; the use-glob reason of SPEC-w13 G2a adds one arm, and R4(4) forbids a split made for CRAP alone + owner: phantom-fractal-store + expires: "2027-02-14" From 913080796d602d1c6642049d0eeafb147f6a2736 Mon Sep 17 00:00:00 2001 From: VirtualMachinist <252028890+VirtualMachinist@users.noreply.github.com> Date: Sat, 14 Nov 2026 18:05:44 -0800 Subject: [PATCH 07/11] Name the walk from the globbed module in the glob cure Co-Authored-By: Claude Opus 5.5 --- .../src/resolve/lookup/cures.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/crates/phantom-fractal-lang-rust/src/resolve/lookup/cures.rs b/crates/phantom-fractal-lang-rust/src/resolve/lookup/cures.rs index 6e36c4e..8dd2e53 100644 --- a/crates/phantom-fractal-lang-rust/src/resolve/lookup/cures.rs +++ b/crates/phantom-fractal-lang-rust/src/resolve/lookup/cures.rs @@ -42,18 +42,24 @@ impl Index<'_> { } } - /// Cure (b): the call walked from the one globbed module that gives its - /// first segment. + /// Cure (b): the one function the call names, walked from the one + /// globbed module that gives its first segment. fn place_glob(&self, call: &CallRef) -> Option { if call.shadowed { return None; } + let entities = self.glob_walk(call)?; + let target = self.one_function(&entities)?; + Some(Placed::Edge(target, Reason::UseGlob)) + } + + /// What the call's path names when walked by the existing tiers from + /// the one globbed module that gives its first segment. + fn glob_walk(&self, call: &CallRef) -> Option> { let module = self.place_of(&call.file, &call.scope)?; let segs = segments(&call.text)?; let home = self.glob_home(module, segs.first()?)?; - let walked = self.walk(home, &segs, 0, true).ok()?; - let target = self.one_function(&walked.entities)?; - Some(Placed::Edge(target, Reason::UseGlob)) + Some(self.walk(home, &segs, 0, true).ok()?.entities) } /// The one function or method `entities` name, if exactly one. From 688bc8b1a13e2c8454fc308277563218bfd262de Mon Sep 17 00:00:00 2001 From: VirtualMachinist <252028890+VirtualMachinist@users.noreply.github.com> Date: Sat, 14 Nov 2026 18:54:22 -0800 Subject: [PATCH 08/11] Refuse a random-bytes fuzz input that is not UTF-8 before any parse The indexer refuses a file that is not UTF-8 before it parses it, and the random-bytes family now does the same: such an input is counted under refused_not_utf8 and never reaches the extractor, instead of going in lossily decoded. The token soup and mutation families are unchanged, and the full run still asserts no panic and 250 ms per input and lists every slow case by number. Co-Authored-By: Claude Opus 5.5 --- .../phantom-fractal-lang-rust/tests/fuzz.rs | 35 ++++++++++++++----- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/crates/phantom-fractal-lang-rust/tests/fuzz.rs b/crates/phantom-fractal-lang-rust/tests/fuzz.rs index a7d591c..06b66fc 100644 --- a/crates/phantom-fractal-lang-rust/tests/fuzz.rs +++ b/crates/phantom-fractal-lang-rust/tests/fuzz.rs @@ -8,9 +8,11 @@ //! | 1 | a Rust token soup, up to 64 KiB | //! | 2 | byte mutations of one real file, from every `fixtures/**/*.rs` and then every `.rs` under `PHANTOM_FUZZ_CORPUS` | //! -//! Each input is `src/lib.rs` of a one-file lib crate. The extractor takes -//! text, and the indexer skips a file that is not UTF-8, so the bytes go in -//! lossily decoded. The test extracts the file, builds the resolve input +//! Each input is `src/lib.rs` of a one-file lib crate. The indexer refuses +//! a file that is not UTF-8 before any parse, and a random-bytes input does +//! the same: it is counted as `refused_not_utf8` and never parsed (A5). A +//! token soup is always UTF-8, and a mutation goes in lossily decoded. The +//! test extracts the file, builds the resolve input //! the store builds from that extract, and resolves it. Each input must //! return without a panic within 250 ms of wall time. //! @@ -492,6 +494,8 @@ struct Summary { cases: u64, per_family: [u64; 3], input_bytes: u64, + /// Random-bytes inputs that are not UTF-8, refused before any parse. + refused_not_utf8: u64, refused: u64, placed: u64, slowest: (Duration, u64), @@ -510,6 +514,7 @@ impl Summary { *total += count; } self.input_bytes += other.input_bytes; + self.refused_not_utf8 += other.refused_not_utf8; self.refused += other.refused; self.placed += other.placed; self.slowest = self.slowest.max(other.slowest); @@ -539,7 +544,7 @@ impl Summary { let mut line = format!( "{{\"first\":{first},\"cases\":{},\"bytes\":{},\"soup\":{},\"mutation\":{},\ \"fixture_files\":{},\"corpus_files\":{},\"corpus_digest\":\"{:016x}\",\ - \"input_bytes\":{},\"refused\":{},\"placed\":{},\"panics\":{},\ + \"input_bytes\":{},\"refused_not_utf8\":{},\"refused\":{},\"placed\":{},\"panics\":{},\ \"over_250_ms\":{},\"max_ms\":{:.3},\"slowest_case\":{}}}", self.cases, self.per_family[0], @@ -549,6 +554,7 @@ impl Summary { corpus.files.len() - corpus.fixture_files, corpus.digest, self.input_bytes, + self.refused_not_utf8, self.refused, self.placed, self.panics.len(), @@ -574,14 +580,16 @@ impl Summary { fn run_cases(first: u64, end: u64, step: u64, corpus: &Corpus) -> Summary { let language = RustLanguage::new().expect("the query compiles"); let mut summary = Summary::default(); - let mut number = first; - while number < end { + for number in (first..end).step_by(step as usize) { let family = FAMILIES[(number % 3) as usize]; let bytes = input(number, corpus); - let source = String::from_utf8_lossy(&bytes); summary.cases += 1; summary.per_family[(number % 3) as usize] += 1; summary.input_bytes += bytes.len() as u64; + let Some(source) = source_of(number, &bytes) else { + summary.refused_not_utf8 += 1; + continue; + }; match catch_unwind(AssertUnwindSafe(|| run(&language, &source))) { Err(_) => summary.panics.push(format!("case {number} ({family})")), Ok(outcome) => { @@ -600,11 +608,22 @@ fn run_cases(first: u64, end: u64, step: u64, corpus: &Corpus) -> Summary { } } } - number += step; } summary } +/// The text case `number` feeds the extractor: none for a random-bytes +/// input that is not UTF-8, which the indexer refuses before any parse +/// (A5); a mutation lossily decoded. +fn source_of(number: u64, bytes: &[u8]) -> Option> { + if number.is_multiple_of(3) { + return std::str::from_utf8(bytes) + .ok() + .map(std::borrow::Cow::Borrowed); + } + Some(String::from_utf8_lossy(bytes)) +} + /// One CI shard: no case may panic. Its times are printed, not asserted, /// because a debug build of the C parser cannot meet a release bound /// (ruling R3); the full run on the build box asserts them. From 55712dd02b64b1865c5cf8f5126d1ec1fc179551 Mon Sep 17 00:00:00 2001 From: VirtualMachinist <252028890+VirtualMachinist@users.noreply.github.com> Date: Sat, 14 Nov 2026 19:02:39 -0800 Subject: [PATCH 09/11] Describe glob imports and shared module files, and refuse stamp-11 indexes status and doctor treat an index from extractor version 11 as they did the earlier stamps: stale in status, refused by reads, the same doctor checks. The README's Resolution gains the use-glob row and sections on glob imports, shared module files and re-exported paths, which the path rows already follow except through a glob re-export. A new Quality section gives the contract run's figures on three trees: precision for each reason and recall against rust-analyzer, the per-crate quality gate, the fuzz and map property runs with the accepted tree-sitter error-recovery miss, the network-less run and the timings. The extractor version reads 12 throughout. Co-Authored-By: Claude Opus 5.5 --- README.md | 140 +++++++++++++++++++++----- crates/phantom-fractal/tests/fresh.rs | 8 +- 2 files changed, 121 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index 02af7cb..58f48fe 100644 --- a/README.md +++ b/README.md @@ -109,13 +109,14 @@ That output is cut to one hit. ### Resolution -A call inside a function is a candidate when it is a path call, such as `f()`, `a::f()`, `Type::new()`, or `Self::new()`, a method call on `self`, such as `self.m()`, a method call whose receiver has a [type hint](#type-hints), such as `x.m()`, `self.f.m()`, or `f().m()`, or, by its name alone, a method call on any other receiver. A single-segment name that the function binds with `let`, a parameter, a closure parameter, or a pattern is shadowed and not resolved. A call gets an edge only when exactly one symbol fits. Otherwise it gets no edge and is counted instead. +A call inside a function is a candidate when it is a path call, such as `f()`, `a::f()`, `Type::new()`, or `Self::new()`, a method call on `self`, such as `self.m()`, a method call whose receiver has a [type hint](#type-hints), such as `x.m()`, `self.f.m()`, or `f().m()`, or, by its name alone, a method call on any other receiver. A path whose first segment only a [glob import](#glob-imports) supplies is a candidate too. A single-segment name that the function binds with `let`, a parameter, a closure parameter, or a pattern is shadowed and not resolved. A call gets an edge only when exactly one symbol fits. Otherwise it gets no edge and is counted instead. | Reason | Confidence | When | |---|---|---| | `path-exact` | 1.0 | The path starts with `crate`, `self`, or `super` and walks to one item or method in the same target. | | `local` | 0.95 | The first segment is an item or child module declared in the call's module, and the rest walks to one item or method. | | `use-alias` | 0.95 | The first segment is bound by a `use` that is not a glob, or by its `as` alias, in the call's module. The `use` path resolves by the rows above, and the rest walks to one item or method. | +| `use-glob` | 0.85 | The first segment is supplied only by a glob import: see [Glob imports](#glob-imports). The path then walks from the one globbed module that declares it, by the rows above, to one item or method. | | `assoc` | 0.9 | `Type::name`, where `Type` resolves by the rows above to one struct, enum, or trait, and exactly one inherent method of that type is named `name`. | | `self-method` | 0.9 | `self.m()` in a method of an `impl` block. The impl's self type resolves by the path rows (`path-exact`, `local`, `use-alias`, and `crate-path`) to one struct or enum, so `impl Show for core_lib::Thing` counts. Exactly one method named `m` belongs to an impl of that type, inherent or trait, across the whole index, not only in the caller's target: a method of that name for the same type in another target means no edge. | | `self-assoc` | 0.9 | `Self::m()`, exactly two segments, in a method of an `impl` block, by the same rule as `self-method`: the self type resolves by the path rows, `crate-path` included, and the method is the only candidate across the whole index. | @@ -162,12 +163,26 @@ For `crate-path`, the crate name is the package name with `-` turned to `_`. Pac A's `[dev-dependencies]` is read in the same two forms, and those entries count for A's test targets only. A lib or a bin ignores them. -**Test targets.** Each `tests/NAME.rs` directly under a package's directory, and each `tests/DIR/main.rs`, is a `test` target named `NAME` or `DIR`. Its root finds `mod x;` beside itself, as any crate root does, so `mod common;` reaches `tests/common.rs` or `tests/common/mod.rs`, and a file reached from two test roots keeps the first one's module. A test target calls by the same rows as a lib or a bin, and may also call its own package's lib and every workspace lib its package names in `[dependencies]` or `[dev-dependencies]`. Every module of a test target is a test module. `benches/` and `examples/` files have no target and stay orphans, and a lib's `#[cfg(test)]` modules do not gain its dev-dependencies. +**Test targets.** Each `tests/NAME.rs` directly under a package's directory, and each `tests/DIR/main.rs`, is a `test` target named `NAME` or `DIR`. Its root finds `mod x;` beside itself, as any crate root does, so `mod common;` reaches `tests/common.rs` or `tests/common/mod.rs`. A file reached from two test roots is read once and is in scope from both, as [Shared module files](#shared-module-files) describes. A test target calls by the same rows as a lib or a bin, and may also call its own package's lib and every workspace lib its package names in `[dependencies]` or `[dev-dependencies]`. Every module of a test target is a test module. `benches/` and `examples/` files have no target and stay orphans, and a lib's `#[cfg(test)]` modules do not gain its dev-dependencies. Any other form gives no dependency: a `[dependencies.B]` or `[dev-dependencies.B]` table, a version-only line, an inline table split over lines, or the forms under [Never resolved](#never-resolved). A lib that calls its own crate by name gets no edge. `index` rebuilds the crate graph and its edges when a `.rs` file is written or removed, when the index was written by another extractor version, or when the workspace fingerprint changes. The fingerprint is a blake3 hash, stored in the database, over every walked `Cargo.toml` (its path and its bytes, or that the read skipped it or found it not UTF-8) and over every `.rs` file the pass skipped or found not UTF-8 (its path and which of the two). So a `Cargo.toml`-only edit rebuilds, even one that changes only whitespace, and so does a `.rs` file that starts or stops being skipped. A pass where none of these changed writes nothing. +#### Glob imports + +A path such as `f()` or `Type::new()` whose first segment the call's module does not declare as an item or child module, and does not bind with a `use` that is not a glob, may be supplied by a glob, `use p::*`. Only a glob whose `p` resolves by the path rows to a workspace module counts: a glob of an external crate, of an enum, or of a missing module is skipped. A name the function binds is shadowed and never tried. + +In each counted module, the first segment is looked up as the module itself declares or re-exports it with `pub use`; a nested glob inside that module is not followed. When exactly one item is found across all of them, the call walks from that module by the rows above and gets `use-glob` at 0.85. Two or more items give no edge, and so does one that the walk does not take to a single function or method. A glob is tried only for a call the rows above leave without an edge, so it never moves an edge they place, and a glob in a parent module does not reach its child modules. A path inside a macro invocation's tokens takes the same rule. + +#### Shared module files + +A file that several targets declare with `mod`, such as `tests/common/mod.rs`, which each `tests/*.rs` declares with `mod common;`, is in scope from every target that declares it. It keeps one file row and one row per item, under the first target the walk reaches, and its items take that target's qualified names. Each later target that declares it gets its own module on the same file, so a call from any of them reaches the file's items by the rows above, with their usual reasons and confidences, and a `use common::*` in a later target globs that target's module. + +#### Re-exported paths + +The path rows already follow a `pub use` chain from module to module, to the defining item, up to 8 hops, and refuse a cycle. One shape is left: a chain through a glob re-export, `pub use p::*`, which no row follows. It is not resolved. On the measured trees, almost every unplaced call through a type path is a trait-impl method, such as `Budget::default` or `NodeId::from`, not a re-export, so following that shape would add almost nothing. Trait-impl methods are under [Never resolved](#never-resolved). + #### Calls inside macros A call-shaped name in a macro invocation's tokens, such as `f(x)` in `assert!(f(x))` or `.m()` in `vec![a.m()]`, nested macros included, is placed by its shape with the rows above. The macro is never expanded, and nothing in its tokens is parsed as an expression. @@ -181,29 +196,14 @@ Each edge keeps the reason and confidence of its row. A call-shaped name that no #### Measured -On Phantom's own tree at commit `986c55d`, against a SCIP index from rust-analyzer 1.95.0. These are the contract run's figures, from the commit that added [placed receivers](#placed-receivers), and the review run's figures replace them. An edge is corroborated when rust-analyzer has the same caller and callee. The covered figures, a secondary that is not graded, count only edges whose caller and callee both sit in files the SCIP index carries. The last row counts only edges placed from inside a macro's tokens. - -| Measure | Edges | Corroborated | Precision | Covered edges | Covered precision | -|---|---|---|---|---|---| -| `typed-method` | 1265 | 1225 | 0.9684 | 1225 | 1.0000 | -| `unique-method` | 653 | 648 | 0.9923 | 650 | 0.9969 | -| Confidence 0.85 and up | 3983 | 3892 | 0.9772 | 3892 | 1.0000 | -| Confidence 0.5 and up | 5901 | 5765 | 0.9770 | 5767 | 0.9997 | -| From inside a macro | 1027 | 1024 | 0.9971 | — | — | - -Recall is the share of rust-analyzer's distinct caller and callee pairs that Phantom has as an edge. The graded figure is document-scoped: a reference takes the callee defined in its own document when its symbol has a definition there. The unscoped figure lets a symbol defined in several documents count a pair for each, as the earlier scorer did, and is kept for comparison. - -| Recall | Pairs | Hits | Ratio | -|---|---|---|---| -| Document-scoped (graded) | 5345 | 3899 | 0.7295 | -| Unscoped (the earlier comparison) | 7753 | 3899 | 0.5029 | +[Quality](#quality) gives the precision of each reason and the recall on three trees, against rust-analyzer. ### Never resolved - **Receivers:** a method call on a receiver other than `self` with no [type hint](#type-hints), such as `a.b().m()`, `(*self).m()`, or an unhinted `x.m()`, is placed only by `unique-method`, so it stays unresolved when two or more workspace methods share its name or the name is on `STD_METHOD_NAMES`. A call whose hint and name rule both place nothing stays unresolved. No receiver is typed by a field of a struct declared in another file, a field of a field, a method chain such as `x.f().m()` or `f().g().m()`, or a closure or iterator element. -- **Dispatch:** a method that only a trait's provided default supplies, `::f`, blanket impls, and dispatch on `dyn` or a generic. +- **Dispatch:** a trait-impl method called through a type path, such as `Budget::default()` or `NodeId::from(…)`, a method that only a trait's provided default supplies, `::f`, blanket impls, and dispatch on `dyn` or a generic. - **Crates:** `std`, `core`, `alloc`, registry and git crates, renamed dependencies (`package = "…"`), `[target.…].dependencies` and `[target.…].dev-dependencies`, `[build-dependencies]`, `[dev-dependencies]` from a lib or a bin, a lib's `#[cfg(test)]` modules included, `extern crate … as …`, and `[lib] path`, `[[bin]] path`, and `[[test]] path`. The targets are `src/lib.rs`, `src/main.rs`, `src/bin/*.rs`, `tests/*.rs`, and `tests/*/main.rs`; `benches/` and `examples/` have none. -- **Other edges:** edges for paths that are not calls, for types, and for struct literals, and names that only a glob import such as `use a::*` supplies. +- **Other edges:** edges for paths that are not calls, for types, and for struct literals. A name that two or more globbed modules supply, one that only a nested glob or a glob of an external crate or an enum supplies, and a path through a glob re-export. - **Macros:** the calls a macro's expansion makes, calls written in a `macro_rules!` body, and a call-shaped name inside a macro invocation that [Calls inside macros](#calls-inside-macros) does not place. That last kind is stored as a fact for [`macro_boundary`](#completeness), never as an edge. ### Nothing runs @@ -549,7 +549,7 @@ An index describes the tree as it was at the last `index`. Every success envelop On the history in [`cochange`](#cochange), after `fract index .` and one line added to `src/b.rs`, `fract status` prints: ``` -{"ok":true,"data":{"key":"repo-a4236502","name":"repo","head":"beb28036163f91ba4918d2acf7d2a294c73d10f8","index_head":"beb28036163f91ba4918d2acf7d2a294c73d10f8","stale":true,"changes":{"added":0,"modified":1,"removed":0},"fingerprint_changed":false,"extractor_changed":false,"counts":{"files":8,"symbols":15,"edges":2},"versions":{"schema":3,"extractor":11,"envelope":1},"epochs":{"graph":1,"rank":1},"cochange":{"head":"beb28036163f91ba4918d2acf7d2a294c73d10f8","commits_seen":23,"skipped_bulk":0,"pairs":4,"window":{"days":365,"max_commits":5000}},"lock":"free"},"meta":{"stale":true,"head":"beb28036163f91ba4918d2acf7d2a294c73d10f8","index_head":"beb28036163f91ba4918d2acf7d2a294c73d10f8","rank_epoch":1},"error":null,"schema":1} +{"ok":true,"data":{"key":"repo-a4236502","name":"repo","head":"beb28036163f91ba4918d2acf7d2a294c73d10f8","index_head":"beb28036163f91ba4918d2acf7d2a294c73d10f8","stale":true,"changes":{"added":0,"modified":1,"removed":0},"fingerprint_changed":false,"extractor_changed":false,"counts":{"files":8,"symbols":15,"edges":2},"versions":{"schema":3,"extractor":12,"envelope":1},"epochs":{"graph":1,"rank":1},"cochange":{"head":"beb28036163f91ba4918d2acf7d2a294c73d10f8","commits_seen":23,"skipped_bulk":0,"pairs":4,"window":{"days":365,"max_commits":5000}},"lock":"free"},"meta":{"stale":true,"head":"beb28036163f91ba4918d2acf7d2a294c73d10f8","index_head":"beb28036163f91ba4918d2acf7d2a294c73d10f8","rank_epoch":1},"error":null,"schema":1} ``` The key's hash comes from the tree's canonical path, so it differs on another machine. `fract find fb` still answers from the index, with the same `meta`. @@ -629,7 +629,7 @@ Each index is a directory under the data directory's `repos/`, named `-","extractor_version":11,"store_schema":3},"error":null,"schema":1} +{"ok":true,"data":{"name":"phantom-fractal","version":"0.0.0","git_sha":"<40 lowercase hex, or null>","extractor_version":12,"store_schema":3},"error":null,"schema":1} ``` `phantom-fractal --json version`, `phantom-fractal version --json`, and `fract version` print the same line. `data` holds these fields, in this order: @@ -810,7 +810,7 @@ The answers are heuristic. Only resolved calls, trait impls, and imports are edg | `name` | `phantom-fractal`, under `fract` too | | `version` | the CLI crate's version, `0.0.0` | | `git_sha` | the commit the binary was built from, as 40 lowercase hex characters, or `null` when unknown | -| `extractor_version` | the extractor version the binary writes, 11 | +| `extractor_version` | the extractor version the binary writes, 12 | | `store_schema` | the store schema version the binary writes, 3 | `git_sha` is fixed at build time. `PHANTOM_FRACTAL_GIT_SHA`, when it holds 40 hex characters, sets it, for packagers. Otherwise it is the output of `git rev-parse HEAD` in the CLI crate's directory. With no git, no `.git` (as in a crates.io tarball), or a refused repository, it is `null`, and the build still succeeds. @@ -821,6 +821,98 @@ The envelope keys come in the order `ok`, `data`, `error`, `schema`. `version` r `--version` and `-V` still print the plain line `phantom-fractal 0.0.0`. +## Quality + +These are the contract run's figures, from commit `688bc8b`, the commit that added [glob imports](#glob-imports) and [shared module files](#shared-module-files), with the gate, fuzz, map, network and timing rows from the runs named beside them. The review run's figures replace them. + +### Against rust-analyzer + +Three trees: Phantom's own tree at `61236dc`, [lapis-lattice](https://github.com/Hedronite/lapis-lattice) at `42aa3b8`, and [facet](https://github.com/Hedronite/facet) at `acf4286`. Each is compared with a SCIP index from rust-analyzer 1.95.0, default features, over the workspace members that `cargo metadata --no-deps` lists. A document outside every member counts for neither side. + +- **Recall** is the share of rust-analyzer's distinct caller and callee pairs that Phantom has as an edge, document-scoped: a reference takes the callee defined in its own document when its symbol has a definition there. +- **Precision** is the share of Phantom's edges that rust-analyzer corroborates with the same caller and callee, over covered edges: both ends sit in documents the SCIP index carries. Each figure is followed by its edge count in brackets. +- **The last row** counts only edges placed from inside a macro's tokens. + +| Measure | Phantom | lapis-lattice | facet | +|---|---|---|---| +| Recall | 0.8898 (4756 of 5345) | 0.8319 (3499 of 4206) | 0.8048 (4577 of 5687) | +| Confidence 0.85 and up | 1.0000 (4540) | 0.9957 (4377) | 0.9984 (4481) | +| Confidence 0.5 and up | 0.9997 (7155) | 0.9858 (4987) | 0.9917 (6487) | +| `path-exact` | 1.0000 (183) | 0.9918 (366) | 1.0000 (108) | +| `local` | 1.0000 (6966) | 0.9957 (6339) | 1.0000 (6015) | +| `use-alias` | 1.0000 (2490) | 1.0000 (1680) | 1.0000 (1416) | +| `use-glob` | 1.0000 (189) | 0.9903 (2484) | 1.0000 (2514) | +| `crate-path` | 1.0000 (957) | 1.0000 (294) | 1.0000 (789) | +| `assoc` | 1.0000 (2244) | 0.9889 (270) | 0.9854 (1443) | +| `self-method` | 1.0000 (546) | 1.0000 (1578) | 1.0000 (972) | +| `self-assoc` | 1.0000 (45) | 1.0000 (120) | 1.0000 (186) | +| `typed-method` | 1.0000 (3930) | 1.0000 (410) | 0.9966 (1788) | +| `unique-method` | 0.9969 (1300) | 0.8716 (810) | 0.9604 (2224) | +| From inside a macro | 1.0000 (1258) | 0.9969 (961) | 0.9990 (996) | + +**Scope on lapis-lattice.** Its `vendor/` packages are not workspace members, so their 6323 edges are out of scope. 911 of its edges sit in code that rust-analyzer's default features leave out, and they are uncovered. + +### The quality gate + +Each crate runs `cargo-tops gate` from its own directory, with cargo-tops 0.2.0 from an isolated install. [RUST-TOPS.md](RUST-TOPS.md) gives each crate's thresholds and how to run the gate. + +0.2.0 applies no coverage or CRAP threshold. So each crate's figures are read from the cargo-llvm-cov summary, cargo-crap's report and cargo-mutants' outcomes, and compared with its `rust-tops.yaml`. cargo-tops 0.4.0, with protocol 1.2.0, is merged upstream and not yet run here. + +Measured at the commit before glob imports (`a03a762`, the store crate at `f90a1b4`), with mutation on the diff from `61236dc`: + +| Crate | Line | Region | Files under 90% | Mutants caught of viable | +|---|---|---|---|---| +| `phantom-fractal` | 95.94% | 94.06% | 0 | 73 of 73 | +| `phantom-fractal-proto` | 100.00% | 97.05% | 0 | no mutant | +| `phantom-fractal-lang` | 100.00% | 100.00% | 0 | no mutant | +| `phantom-fractal-lang-rust` | 98.58% | 96.91% | 0 | 3 of 3 | +| `phantom-fractal-extract` | 97.55% | 95.07% | 0 | no mutant | +| `phantom-fractal-analyze` | 98.23% | 96.02% | 0 | no mutant | +| `phantom-fractal-store` | 97.82% | 90.29% | 0 | 130 of 130 | +| `phantom-fractal-git` | 97.59% | 95.95% | 0 | no mutant | + +- **CRAP.** Every function added or changed since `61236dc` is at or under 6, and no existing function rose. +- **Exemptions.** The five reason-dispatch matches that the `use-glob` arm lengthened are exemptions in their crates' `rust-tops.yaml`. +- **The glob and shared-file changes.** Mutation on their own diff caught 40 of the 40 viable mutants, and coverage met every bar. +- **"No mutant"** means the diff changed no production line in that crate. + +### Fuzz and the map property + +Both are std-only harnesses, driven by a seeded generator, so every case replays by its number. + +**Map property, 10000 cases** (at `209889b`). Random graphs of up to 500 symbols, with budgets from 0 to 20000: +- 0 maps over their budget; +- every second run byte-identical; +- no line removed by a larger budget. + +**Fuzz, 500000 cases.** Random bytes up to 64 KiB, a Rust token soup, and byte mutations of every fixture and of both dogfood trees, through extraction and resolution. + +- **Panics.** 0, in every family. +- **The 250 ms bound.** At `209889b`, 7178 inputs took longer. Since then: + - **Invalid UTF-8.** A random input that is not valid UTF-8 is now refused before any parse, as `index` refuses such a file. That covers 1345 of the slow random inputs. + - **The resolver.** The four slowest mutation inputs now replay in 2.3 to 4.2 ms, since the resolver memoizes its lookups. + - **A recorded, accepted miss: tree-sitter's error recovery on unstructured text.** 2222 random ASCII inputs with control characters took up to 3375 ms, and 608 random printable inputs up to 2816 ms. Every one ends, without a panic. The time is spent inside tree-sitter's error recovery, which its progress callback cannot see or stop, so no budget can cut it short. + + The review run measures all 500000 again. + +### No network + +In a container with `--network none`, with every tree mounted read-only and a trace of `socket` and `connect`: +- `fract index`, `status`, `rank`, `map`, `find`, `callers`, `impact` and an MCP session opened 0 IPv4 or IPv6 sockets on all three trees, and left every tree unchanged (at `209889b`). +- The test suite's only such sockets were name lookups by the `git` processes that test fixtures spawn, when git looked up the host's name to make an identity. Every test that spawns `git` now gives it an explicit identity and no outside config. The review run measures the suite again. + +### Timings + +Medians of 5 runs, in milliseconds, from the release `fract` (at `209889b`): + +| Tree | Cold `index` | `index` after a one-line edit | `find` | `callers` | `impact` | `map` at 2000 | +|---|---|---|---|---|---|---| +| Phantom | 997.0 | 601.4 | 33.1 | 111.4 | 241.2 | 13.4 | +| lapis-lattice | 3253.5 | 2215.7 | 158.9 | 494.5 | 509.8 | 17.6 | +| facet | 1166.5 | 640.9 | 24.8 | 103.2 | 104.4 | 10.9 | + +The edit is made in a copy of the tree under a temp directory, never in the tree itself. `crates/phantom-fractal/tests/timings.rs` runs these on any tree named by `PHANTOM_TIMING_ROOT`. + ## Other `--version` prints `phantom-fractal 0.0.0`. `--help` lists the sixteen commands with a usage line, and so does a run with no command. `find` matches names only. There is no other command. diff --git a/crates/phantom-fractal/tests/fresh.rs b/crates/phantom-fractal/tests/fresh.rs index 437b25e..a1b9d3c 100644 --- a/crates/phantom-fractal/tests/fresh.rs +++ b/crates/phantom-fractal/tests/fresh.rs @@ -588,8 +588,10 @@ fn index_lists_typed_method_after_crate_path() { /// targets, is refused by reads with the old `no_index`, and `doctor` /// reports it as it did a stamp-7 one (SPEC-w11 G1c). So is a stamp-9 /// index, from the version before calls inside macro arguments resolved -/// (SPEC-w12 G1c), and a stamp-10 one, from the version before receivers -/// were placed by return types and same-file fields (SPEC-w12 G2c). +/// (SPEC-w12 G1c), a stamp-10 one, from the version before receivers were +/// placed by return types and same-file fields (SPEC-w12 G2c), and a +/// stamp-11 one, from the version before shared module files and glob +/// imports resolved (SPEC-w13 G2c). #[test] fn status_flags_an_index_from_another_extractor_version() { for git in [false, true] { @@ -620,7 +622,7 @@ fn status_flags_an_index_from_another_extractor_version() { let fresh = doctor(); let extractor = fresh.iter().find(|check| check["name"] == "extractor"); assert_eq!(extractor.expect("extractor")["detail"], "12", "git {git}"); - for stamp in [7, 8, 9, 10] { + for stamp in [7, 8, 9, 10, 11] { world.store().set_extractor_version(stamp).expect("stamp"); let db = world.db(); status(true, stamp); From c3185a0542c9cc699f8f52c8b6cf606b637c29cc Mon Sep 17 00:00:00 2001 From: VirtualMachinist <252028890+VirtualMachinist@users.noreply.github.com> Date: Sat, 14 Nov 2026 19:46:04 -0800 Subject: [PATCH 10/11] Give the two max_tokens budget sweeps 60 s under the ci profile every_budgeted_reply_is_the_fewest_drops_that_fit and impact_diff_fits_in_its_own_order are CPU-bound and run past the ci profile's 20 s kill on a slow or shared box, such as a network-less container, while native runs are fast. A ci override gives exactly those two a 10 s period with terminate-after 6. Nothing else changes. Co-Authored-By: Claude Opus 5.5 --- .config/nextest.toml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.config/nextest.toml b/.config/nextest.toml index 38dd358..1f029c4 100644 --- a/.config/nextest.toml +++ b/.config/nextest.toml @@ -32,3 +32,9 @@ slow-timeout = { period = "30s", terminate-after = 2 } [[profile.ci.overrides]] filter = 'binary(watch) & test(=a_burst_of_twenty_saves_inside_the_debounce_is_one_batch)' retries = 2 + +# Two CPU-bound budget sweeps that run past the ci profile's 20 s on a +# slow or shared box, such as a network-less container: give them 60 s. +[[profile.ci.overrides]] +filter = 'binary(max_tokens) & (test(=every_budgeted_reply_is_the_fewest_drops_that_fit) | test(=impact_diff_fits_in_its_own_order))' +slow-timeout = { period = "10s", terminate-after = 6 } From 9517b124964ecfcc03dc13ae36ebe67dff8bb764 Mon Sep 17 00:00:00 2001 From: VirtualMachinist <252028890+VirtualMachinist@users.noreply.github.com> Date: Sat, 14 Nov 2026 20:52:47 -0800 Subject: [PATCH 11/11] Give the review run's figures in Quality, and the agent comparison The Quality section now carries the review run's figures at c3185a0: recall and both bands, which equal the contract run's, the per-reason precision it measured, the gate on all eight crates, the 500000-case fuzz run with its accepted tree-sitter error-recovery miss, the map property, the network-less run and the timings. A new Agents part gives the 48-run comparison of two agent harnesses with and without fract mcp. Neither read fewer files with Phantom at an equal or better score, so the goal is not met; it is recorded as a miss accepted by the project's owner, and agent uptake is the next work. Co-Authored-By: Claude Opus 5.5 --- README.md | 79 +++++++++++++++++++++++++++++-------------------------- 1 file changed, 42 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 58f48fe..166905d 100644 --- a/README.md +++ b/README.md @@ -823,14 +823,14 @@ The envelope keys come in the order `ok`, `data`, `error`, `schema`. `version` r ## Quality -These are the contract run's figures, from commit `688bc8b`, the commit that added [glob imports](#glob-imports) and [shared module files](#shared-module-files), with the gate, fuzz, map, network and timing rows from the runs named beside them. The review run's figures replace them. +These figures come from the review run at commit `c3185a0`, the commit that added [glob imports](#glob-imports) and [shared module files](#shared-module-files). Its scorer, map and fuzz rows ran at `688bc8b`, whose product code is the same. ### Against rust-analyzer Three trees: Phantom's own tree at `61236dc`, [lapis-lattice](https://github.com/Hedronite/lapis-lattice) at `42aa3b8`, and [facet](https://github.com/Hedronite/facet) at `acf4286`. Each is compared with a SCIP index from rust-analyzer 1.95.0, default features, over the workspace members that `cargo metadata --no-deps` lists. A document outside every member counts for neither side. - **Recall** is the share of rust-analyzer's distinct caller and callee pairs that Phantom has as an edge, document-scoped: a reference takes the callee defined in its own document when its symbol has a definition there. -- **Precision** is the share of Phantom's edges that rust-analyzer corroborates with the same caller and callee, over covered edges: both ends sit in documents the SCIP index carries. Each figure is followed by its edge count in brackets. +- **Precision** is the share of Phantom's distinct edges that rust-analyzer corroborates with the same caller and callee, over covered edges: both ends sit in documents the SCIP index carries. Each figure is followed by its covered-edge count in brackets. - **The last row** counts only edges placed from inside a macro's tokens. | Measure | Phantom | lapis-lattice | facet | @@ -838,81 +838,86 @@ Three trees: Phantom's own tree at `61236dc`, [lapis-lattice](https://github.com | Recall | 0.8898 (4756 of 5345) | 0.8319 (3499 of 4206) | 0.8048 (4577 of 5687) | | Confidence 0.85 and up | 1.0000 (4540) | 0.9957 (4377) | 0.9984 (4481) | | Confidence 0.5 and up | 0.9997 (7155) | 0.9858 (4987) | 0.9917 (6487) | -| `path-exact` | 1.0000 (183) | 0.9918 (366) | 1.0000 (108) | -| `local` | 1.0000 (6966) | 0.9957 (6339) | 1.0000 (6015) | -| `use-alias` | 1.0000 (2490) | 1.0000 (1680) | 1.0000 (1416) | -| `use-glob` | 1.0000 (189) | 0.9903 (2484) | 1.0000 (2514) | -| `crate-path` | 1.0000 (957) | 1.0000 (294) | 1.0000 (789) | -| `assoc` | 1.0000 (2244) | 0.9889 (270) | 0.9854 (1443) | -| `self-method` | 1.0000 (546) | 1.0000 (1578) | 1.0000 (972) | -| `self-assoc` | 1.0000 (45) | 1.0000 (120) | 1.0000 (186) | -| `typed-method` | 1.0000 (3930) | 1.0000 (410) | 0.9966 (1788) | -| `unique-method` | 0.9969 (1300) | 0.8716 (810) | 0.9604 (2224) | +| `typed-method` | 1.0000 (1965) | 1.0000 (205) | 1.0000 (891) | +| `unique-method` | 0.9969 (650) | 0.9051 (390) | 0.9561 (1117) | +| `use-glob` | 1.0000 (63) | 0.9927 (826) | 1.0000 (838) | | From inside a macro | 1.0000 (1258) | 0.9969 (961) | 0.9990 (996) | -**Scope on lapis-lattice.** Its `vendor/` packages are not workspace members, so their 6323 edges are out of scope. 911 of its edges sit in code that rust-analyzer's default features leave out, and they are uncovered. +- **The other reasons.** The contract run gives `path-exact`, `local`, `use-alias`, `crate-path`, `assoc`, `self-method` and `self-assoc` at 0.98 or better on every tree. It counted edges by another convention, so its counts are not shown. +- **Scope on lapis-lattice.** Its `vendor/` packages are not workspace members, so their edges are out of scope. 911 of its edges sit in code that rust-analyzer's default features leave out, and they are uncovered. ### The quality gate -Each crate runs `cargo-tops gate` from its own directory, with cargo-tops 0.2.0 from an isolated install. [RUST-TOPS.md](RUST-TOPS.md) gives each crate's thresholds and how to run the gate. +Each crate runs `cargo-tops gate` from its own directory, with cargo-tops 0.2.0 from an isolated install. [RUST-TOPS.md](RUST-TOPS.md) gives each crate's thresholds and how to run the gate. All eight crates exit 0. 0.2.0 applies no coverage or CRAP threshold. So each crate's figures are read from the cargo-llvm-cov summary, cargo-crap's report and cargo-mutants' outcomes, and compared with its `rust-tops.yaml`. cargo-tops 0.4.0, with protocol 1.2.0, is merged upstream and not yet run here. -Measured at the commit before glob imports (`a03a762`, the store crate at `f90a1b4`), with mutation on the diff from `61236dc`: +Mutation runs on the diff since `209889b`, the commit that added the measurement harnesses: | Crate | Line | Region | Files under 90% | Mutants caught of viable | |---|---|---|---|---| | `phantom-fractal` | 95.94% | 94.06% | 0 | 73 of 73 | | `phantom-fractal-proto` | 100.00% | 97.05% | 0 | no mutant | -| `phantom-fractal-lang` | 100.00% | 100.00% | 0 | no mutant | -| `phantom-fractal-lang-rust` | 98.58% | 96.91% | 0 | 3 of 3 | -| `phantom-fractal-extract` | 97.55% | 95.07% | 0 | no mutant | +| `phantom-fractal-lang` | 100.00% | 100.00% | 0 | 2 of 2 | +| `phantom-fractal-lang-rust` | 98.51% | 96.89% | 0 | 32 of 32 | +| `phantom-fractal-extract` | 97.55% | 95.08% | 0 | 4 of 4 | | `phantom-fractal-analyze` | 98.23% | 96.02% | 0 | no mutant | -| `phantom-fractal-store` | 97.82% | 90.29% | 0 | 130 of 130 | +| `phantom-fractal-store` | 97.83% | 90.29% | 0 | 132 of 132 | | `phantom-fractal-git` | 97.59% | 95.95% | 0 | no mutant | -- **CRAP.** Every function added or changed since `61236dc` is at or under 6, and no existing function rose. -- **Exemptions.** The five reason-dispatch matches that the `use-glob` arm lengthened are exemptions in their crates' `rust-tops.yaml`. -- **The glob and shared-file changes.** Mutation on their own diff caught 40 of the 40 viable mutants, and coverage met every bar. +- **CRAP.** No function rose above its value at `61236dc`, and no function added since is over 6, except the five reason-dispatch matches that the `use-glob` arm lengthened. Those are exhaustive, one arm per variant, and are exemptions in their crates' `rust-tops.yaml`. - **"No mutant"** means the diff changed no production line in that crate. ### Fuzz and the map property Both are std-only harnesses, driven by a seeded generator, so every case replays by its number. -**Map property, 10000 cases** (at `209889b`). Random graphs of up to 500 symbols, with budgets from 0 to 20000: +**Map property, 10000 cases.** Random graphs of up to 500 symbols, with budgets from 0 to 20000: - 0 maps over their budget; - every second run byte-identical; - no line removed by a larger budget. -**Fuzz, 500000 cases.** Random bytes up to 64 KiB, a Rust token soup, and byte mutations of every fixture and of both dogfood trees, through extraction and resolution. +**Fuzz, 500000 cases.** 166667 random byte strings up to 64 KiB, 166667 Rust token soups, and 166666 byte mutations of every fixture and of both dogfood trees, through extraction and resolution. -- **Panics.** 0, in every family. -- **The 250 ms bound.** At `209889b`, 7178 inputs took longer. Since then: - - **Invalid UTF-8.** A random input that is not valid UTF-8 is now refused before any parse, as `index` refuses such a file. That covers 1345 of the slow random inputs. - - **The resolver.** The four slowest mutation inputs now replay in 2.3 to 4.2 ms, since the resolver memoizes its lookups. - - **A recorded, accepted miss: tree-sitter's error recovery on unstructured text.** 2222 random ASCII inputs with control characters took up to 3375 ms, and 608 random printable inputs up to 2816 ms. Every one ends, without a panic. The time is spent inside tree-sitter's error recovery, which its progress callback cannot see or stop, so no budget can cut it short. - - The review run measures all 500000 again. +- **Panics.** 0. +- **Invalid UTF-8.** 55715 random byte strings are not valid UTF-8 and are refused before any parse, as `index` refuses such a file. +- **The token soups and the mutations.** All within 250 ms. The slowest soup took 32 ms, and the slowest mutation 153.9 ms. +- **The 250 ms bound: a recorded miss, accepted by the project's owner.** 3894 random byte strings, all valid UTF-8, took longer, up to 4149 ms. Every one ends, without a panic. The time is spent inside tree-sitter's error recovery on text that is not code, which its progress callback cannot see or stop, so no budget can cut it short. ### No network In a container with `--network none`, with every tree mounted read-only and a trace of `socket` and `connect`: -- `fract index`, `status`, `rank`, `map`, `find`, `callers`, `impact` and an MCP session opened 0 IPv4 or IPv6 sockets on all three trees, and left every tree unchanged (at `209889b`). -- The test suite's only such sockets were name lookups by the `git` processes that test fixtures spawn, when git looked up the host's name to make an identity. Every test that spawns `git` now gives it an explicit identity and no outside config. The review run measures the suite again. +- the test suite, 996 of 996 passing, opened 0 IPv4 or IPv6 sockets; +- `fract index`, `status`, `rank`, `map`, `find`, `callers`, `impact` and an MCP session opened 0 on all three trees; +- every tree was left unchanged. ### Timings -Medians of 5 runs, in milliseconds, from the release `fract` (at `209889b`): +Medians of 5 runs, in milliseconds, from the release `fract`: | Tree | Cold `index` | `index` after a one-line edit | `find` | `callers` | `impact` | `map` at 2000 | |---|---|---|---|---|---|---| -| Phantom | 997.0 | 601.4 | 33.1 | 111.4 | 241.2 | 13.4 | -| lapis-lattice | 3253.5 | 2215.7 | 158.9 | 494.5 | 509.8 | 17.6 | -| facet | 1166.5 | 640.9 | 24.8 | 103.2 | 104.4 | 10.9 | +| Phantom | 975.7 | 604.4 | 31.0 | 106.3 | 250.9 | 11.4 | +| lapis-lattice | 3076.9 | 2162.2 | 154.5 | 471.6 | 482.1 | 17.3 | +| facet | 1062.8 | 633.6 | 24.0 | 104.3 | 104.6 | 10.5 | The edit is made in a copy of the tree under a temp directory, never in the tree itself. `crates/phantom-fractal/tests/timings.rs` runs these on any tree named by `PHANTOM_TIMING_ROOT`. +### Agents + +**The setup.** 48 runs: 12 sealed tasks on lapis-lattice and facet, asking where a symbol is, what a change reaches, and what changes with a file. Two agent harnesses ran each task with and without `fract mcp` as a tool server, each run in a fresh copy of the tree. The answers were scored blind, 0 to 2 per task. + +| Harness | Phantom | File reads | Searches | Answer score (of 24) | +|---|---|---|---|---| +| Claude Code | with | 5 | 27 | 23 | +| Claude Code | without | 3 | 50 | 23 | +| omp | with | 16 | 46 | 22 | +| omp | without | 16 | 43 | 23 | + +**The goal: not met.** It was fewer file reads with Phantom and an answer score at least as high, for each harness. Neither harness met it. With Phantom, Claude Code read more files at an equal score, and omp read as many at a lower score. This is a recorded miss, accepted by the project's owner. + +The server was available in every run with Phantom, and the agents called it in 7 of those 24. Getting agents to use it well is the next work. + ## Other `--version` prints `phantom-fractal 0.0.0`. `--help` lists the sixteen commands with a usage line, and so does a run with no command. `find` matches names only. There is no other command.