Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
145 changes: 121 additions & 24 deletions README.md

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions crates/phantom-fractal-extract/rust-tops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
10 changes: 7 additions & 3 deletions crates/phantom-fractal-extract/src/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
10 changes: 7 additions & 3 deletions crates/phantom-fractal-extract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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,
Expand All @@ -102,6 +104,7 @@ impl ReasonCounts {
Reason::CratePath,
Reason::TypedMethod,
Reason::UniqueMethod,
Reason::UseGlob,
];

/// The count of each reason among `edges`.
Expand Down Expand Up @@ -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,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/phantom-fractal-extract/tests/fixture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}

Expand Down
17 changes: 15 additions & 2 deletions crates/phantom-fractal-extract/tests/graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]),
Expand All @@ -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", ""),
]
);
}
Expand Down Expand Up @@ -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", ""),
]
);
}
Expand Down Expand Up @@ -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()
Expand All @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions crates/phantom-fractal-extract/tests/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
94 changes: 94 additions & 0 deletions crates/phantom-fractal-extract/tests/resolve_dogfood.rs
Original file line number Diff line number Diff line change
@@ -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);
}
6 changes: 4 additions & 2 deletions crates/phantom-fractal-extract/tests/scip_score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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");
Expand Down
8 changes: 8 additions & 0 deletions crates/phantom-fractal-lang-rust/rust-tops.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
5 changes: 3 additions & 2 deletions crates/phantom-fractal-lang-rust/src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -111,7 +112,7 @@ pub fn resolve(input: &ResolveInput) -> (Vec<Edge>, ResolveCounts) {
counts.no_source += 1;
continue;
};
(source, index.place(call, source))
(source, index.place_cured(call, source))
}
};
match placed {
Expand Down Expand Up @@ -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,
Expand Down
17 changes: 16 additions & 1 deletion crates/phantom-fractal-lang-rust/src/resolve/lookup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -318,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,
};
Expand Down Expand Up @@ -682,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<Entity> {
let module = self.canonical(module);
let mut local: Vec<Entity> = self
.children
.get(&(module, name))
Expand All @@ -706,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<Found, Miss> {
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;
Expand Down Expand Up @@ -741,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<Walked, Miss> {
let module = self
Expand Down
Loading
Loading