class-semantics: classes are first-class in vlog_semantic -- class
scopes and symbols, member/method/prototype binding, this.x
(nearest-class-only), super.x, cls::x with lexical unit heads,
out-of-body cls::method bound into the class's scope with the extern
prototype as the definition (rule 10), and the honest
InheritedCandidate{base, paths} shape: a member miss in an extending
class records what the unknown base might supply (import paths
included) and is never chased, not even in-file -- the future
inheritance round's worklist, measured at 1303 candidates. Unit-name
misses stay ExternalCandidate (QA-found, lead-ruled: bases supply
members, not package names; +170 recovered navigations, pinned).
Workspace index gains classes as units (246) and their members
(11399). scan.rs migrated to parser name-spans: 26 call sites down
to the 2 documented consumers. 114044 spans, 0 unplaced, 0 panics;
UVM code now has hover/definition/references/outline.
lexer-cleanup: the three filed gaps -- @(* ) lexes via a
starts_attribute backoff (an attribute cannot begin with `)`; real
attributes pinned, no misfire on legal expressions), a leading BOM
is accepted as a named losslessness exception (mid-file BOM errors
clearly; 20k-case position fuzz clean), and non-ASCII lex errors now
decode the full character AND surface through vfmt check's error
slot (exit 2, matching format, text-rule findings still reported --
the silent-pass hole closed). The macro space-before-paren item is
parked with a QA-hardened analysis: the reading depends on a
definition vfmt cannot see, any fixed answer is provably wrong for
one population, and today's behavior fails safe.
827 workspace tests. Dev: 2 Fable agents; QA: 2 Opus agents; reviews
in docs/features/{class-semantics,lexer-cleanup}/README.md.
Co-Authored-By: Claude Fable 5 <[email protected]>
134 lines
4.5 KiB
Rust
134 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, {:.1}% unresolved, \
|
|
{} names unplaced",
|
|
self.files,
|
|
self.symbols,
|
|
self.references,
|
|
pct(self.resolved),
|
|
pct(self.external),
|
|
pct(self.inherited),
|
|
pct(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);
|
|
}
|
|
}
|
|
}
|