use std::path::PathBuf;
use std::sync::Arc;
use std::time::Instant;
use mir_analyzer::{discover_files, AnalysisSession, Name, PhpVersion};
fn main() {
let fixture = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("benches/fixtures/laravel");
if !fixture.join("vendor").exists() || !fixture.join("src").exists() {
eprintln!(
"Laravel fixture not found at {}; run `bash {}/benches/download-fixtures.sh`",
fixture.display(),
env!("CARGO_MANIFEST_DIR")
);
std::process::exit(2);
}
let psr4 = Arc::new(
mir_analyzer::composer::Psr4Map::from_composer(&fixture)
.expect("failed to load composer.json"),
);
let session = AnalysisSession::new(PhpVersion::LATEST).with_psr4(psr4);
session.ensure_all_stubs();
let project_files = discover_files(&fixture.join("src"));
eprintln!("loaded {} project files", project_files.len());
let workspace: Vec<(Arc<str>, Arc<str>)> = project_files
.iter()
.enumerate()
.filter_map(|(i, p)| {
let src = std::fs::read_to_string(p).ok()?;
let doctored = format!(
"{src}\nif (false) {{ \\App\\ForcedUnresolvedByBench_{i}::neverCalled(); }}\n"
);
Some((
Arc::<str>::from(p.to_string_lossy().as_ref()),
Arc::<str>::from(doctored),
))
})
.collect();
session.set_workspace_files(workspace);
let project_paths: Vec<Arc<str>> = project_files
.iter()
.map(|p| Arc::<str>::from(p.to_string_lossy().as_ref()))
.collect();
let t0 = Instant::now();
session
.indexed_references_to(&Name::method("", ""), &project_paths, false, &|| false)
.expect("not cancelled");
eprintln!(
"initial full-commit pass: {:.3}s",
t0.elapsed().as_secs_f64()
);
session.ingest_file(
Arc::from("src/BenchLater.php"),
Arc::from("<?php\nnamespace Illuminate\\Support;\nclass BenchLater {}\n"),
);
let target = Name::method("Illuminate\\Support\\Distinctive", "staticThing");
let t1 = Instant::now();
let refs = session
.indexed_references_to(&target, &project_paths, false, &|| false)
.expect("not cancelled");
eprintln!(
"post-growth distinctive-static query: {:.3}s, {} references found",
t1.elapsed().as_secs_f64(),
refs.len()
);
}