Delivers the Handshake docs/features/type-definition/README.md filed: an unqualified lexical miss written where a TYPE goes — bus_if bus;, my_cls h;, a cross-file typedef — now carries its bare name to the workspace overlay (last, so imports still win), in both spellings: ExternalCandidate, and InheritedCandidate inside extending classes, whose base and count (7,841, bit-identical) are untouched. The mechanism is a new Target::Type emitted only by bind_data_type's unqualified arm; value-position identifiers, disable labels and redeclarations keep their pre-round Target::Lexical behavior — NotFound stays NotFound, and rename keeps refusing them. That value/type split is the round's story: QA rejected the first cut with a kept repro proving a value-position typo could rename an unrelated same-named module cross-file (write-by-coincidence, pre-round refused), and disproved the work log's exposure claim against the pre-round source. The fix is a four-line behavior delta; QA re-killed the regression from three angles and reproduced every corpus figure to the digit. Result over the 860-file corpus: NotFound 1,418 -> 1,256, 418 clean-file references gained a jump target, none lost one, 141 coincidence-answers deliberately given back. The server's stopgap is deleted whole: type_def.rs::indexed_type, qualifier guard included — all 45 type-definition tests green unchanged, and cross-file interface rename from a type window is newly possible and pinned. Corpus formatter results byte-identical (813/820 both trees). New docs/features/overlay-promotion/README.md; the vlog-semantic and workspace-index tables re-measured (the committed baselines had gone stale several rounds ago; both READMEs now carry the three-state table). Co-Authored-By: Claude Fable 5 <[email protected]>
135 lines
4.5 KiB
Rust
135 lines
4.5 KiB
Rust
//! Smoke test over the real-RTL corpus (`corpus/`, fetched by
|
|
//! `tools/corpus_fetch.sh`): analyze every file, panic nowhere, check that
|
|
//! every recorded span really covers the name it claims, and report an honest
|
|
//! resolution rate. Skipped when the corpus is not checked out.
|
|
|
|
use std::fs;
|
|
use std::path::{Path, PathBuf};
|
|
use vlog_parser::parse_source_tolerant;
|
|
use vlog_semantic::{analyze, Semantics};
|
|
|
|
#[derive(Default)]
|
|
struct Totals {
|
|
files: usize,
|
|
symbols: usize,
|
|
references: usize,
|
|
resolved: usize,
|
|
external: usize,
|
|
/// Uses inside a class that only its `extends` (or an import) could
|
|
/// supply — the honest third bucket class-semantics added.
|
|
inherited: usize,
|
|
/// Names the source scan could not place. Expected to stay at zero — a
|
|
/// nonzero count means a construct whose name this crate cannot locate.
|
|
unplaced: usize,
|
|
}
|
|
|
|
impl Totals {
|
|
fn add(&mut self, sem: &Semantics, src: &str, path: &Path) {
|
|
self.files += 1;
|
|
self.symbols += sem.symbols().len();
|
|
for sym in sem.symbols() {
|
|
self.unplaced +=
|
|
usize::from(!covers(src, sym.name_span, &sym.name, path, "declaration"));
|
|
}
|
|
for r in sem.references() {
|
|
self.unplaced += usize::from(!covers(src, r.name_span, &r.name, path, "use"));
|
|
}
|
|
let (resolved, total) = sem.resolution_counts();
|
|
self.references += total;
|
|
self.resolved += resolved;
|
|
self.external += sem.references().iter().filter(|r| r.is_external_candidate()).count();
|
|
self.inherited += sem.references().iter().filter(|r| r.is_inherited_candidate()).count();
|
|
}
|
|
|
|
fn unresolved(&self) -> usize {
|
|
self.references - self.resolved - self.external - self.inherited
|
|
}
|
|
|
|
fn report(&self, label: &str) {
|
|
let pct = |n: usize| 100.0 * n as f64 / self.references.max(1) as f64;
|
|
println!(
|
|
"{label}: {} files, {} symbols, {} references — {:.1}% resolved in-file, \
|
|
{:.1}% external candidates, {:.1}% inherited candidates, {:.2}% unresolved ({}), \
|
|
{} names unplaced",
|
|
self.files,
|
|
self.symbols,
|
|
self.references,
|
|
pct(self.resolved),
|
|
pct(self.external),
|
|
pct(self.inherited),
|
|
pct(self.unresolved()),
|
|
self.unresolved(),
|
|
self.unplaced,
|
|
);
|
|
}
|
|
}
|
|
|
|
/// True when `span` really is where `name` is written. An empty span is the
|
|
/// scan's "not found" answer and is counted, not asserted away.
|
|
fn covers(src: &str, span: vlog_parser::TextRange, name: &str, path: &Path, what: &str) -> bool {
|
|
if span.is_empty() {
|
|
return false;
|
|
}
|
|
assert_eq!(
|
|
&src[span.as_range()],
|
|
name,
|
|
"{}: the {what} span of {name} covers other bytes",
|
|
path.display()
|
|
);
|
|
true
|
|
}
|
|
|
|
#[test]
|
|
fn every_corpus_file_analyzes_without_panicking() {
|
|
let root = Path::new(env!("CARGO_MANIFEST_DIR")).join("../../corpus");
|
|
if !root.is_dir() {
|
|
eprintln!("corpus/ not checked out — skipping");
|
|
return;
|
|
}
|
|
let mut files = Vec::new();
|
|
collect(&root, &mut files);
|
|
files.sort();
|
|
|
|
let mut all = Totals::default();
|
|
// The same numbers over the files that parse without a single error node,
|
|
// which is the population the LSP's resolution quality is really about.
|
|
let mut clean = Totals::default();
|
|
for path in &files {
|
|
let Ok(src) = fs::read_to_string(path) else {
|
|
continue;
|
|
};
|
|
let (file, diags) = parse_source_tolerant(&src);
|
|
let sem = analyze(&file, &src);
|
|
all.add(&sem, &src, path);
|
|
if diags.is_empty() {
|
|
clean.add(&sem, &src, path);
|
|
}
|
|
}
|
|
|
|
all.report("corpus (every file)");
|
|
clean.report("corpus (files that parse cleanly)");
|
|
|
|
assert!(all.files > 0, "corpus/ exists but holds no Verilog");
|
|
assert_eq!(all.unplaced, 0, "every name must be locatable in the source");
|
|
assert!(
|
|
100 * clean.unresolved() < 3 * clean.references,
|
|
"unresolved rate on cleanly-parsed files regressed: {} of {}",
|
|
clean.unresolved(),
|
|
clean.references
|
|
);
|
|
}
|
|
|
|
fn collect(dir: &Path, out: &mut Vec<PathBuf>) {
|
|
let Ok(entries) = fs::read_dir(dir) else {
|
|
return;
|
|
};
|
|
for entry in entries.flatten() {
|
|
let path = entry.path();
|
|
if path.is_dir() {
|
|
collect(&path, out);
|
|
} else if matches!(path.extension().and_then(|e| e.to_str()), Some("sv" | "v" | "svh")) {
|
|
out.push(path);
|
|
}
|
|
}
|
|
}
|