Perf take 5 P3 (§60.3): one parse for the CLI package census — package_exports_in reads the census's own parse, an AST gate spares the nine files in ten that declare no package, the one-file index is built from the parse; the unused-import increment on hw/ip 142 → 5 ms, peak RSS −8.6 %, every output byte-identical
This commit is contained in:
1 parent
5c9fdb2c62
commit
8e65da1ba8
8 files changed
+1135
-54
No files matched your search
@@ -4701,6 +4701,11 @@ in 0.49.0. Take 4's findings are in the loop-3 list above.
|
||||
imports, package members, `extends`/alias chains, `bind`, `defparam`,
|
||||
`$root`, `` `include``, generate shadows, class members, unsaved
|
||||
buffers) before any file is dropped.
|
||||
- **perf take 5 P3 (§60.3) filed:** the CLI's third parse (the lint
|
||||
pass re-parses every file the census parsed) — retaining the census
|
||||
ASTs was refused as a memory trade (1 805 trees against a 200 MiB
|
||||
peak); and a test pinning `harvest_one`'s lex-only path when neither
|
||||
census half is wanted (needs a `Job` constructor for tests).
|
||||
Sections after §46 are planned when reached.
|
||||
|
||||
## 45. Small items, round 4 (planned 2026-09-05) — topo §2.9-29, 30, 17, 22
|
||||
@@ -5967,16 +5972,29 @@ real paths first and names them in the README.
|
||||
Plan §P3. Files: `lucisv/src/lint.rs`, `vlog_linter/src/{interfaces.rs,
|
||||
lib.rs}`; a semantic fact-extraction API only if needed, additive; the
|
||||
CLI keeps no direct semantic dependency.
|
||||
- [ ] package exports from the census's existing parse; files without a
|
||||
- [x] package exports from the census's existing parse; files without a
|
||||
package declaration skip the index work by AST, never by text
|
||||
search; duplicate/unknown packages, nested declarations, malformed
|
||||
source, re-export chains handled exactly as before
|
||||
- [ ] default `check` output byte-identical; all-style retains every
|
||||
`unused-import` finding; fixes, waivers, exit codes stable
|
||||
- [ ] measured: ≥ half of the 123 ms all-style increment removed on
|
||||
source, re-export chains handled exactly as before — additive
|
||||
`vlog_linter::package_exports_in(path, file, tokens, src)`, the gate
|
||||
`walk_items` looking for `ItemKind::Package` (1 624 of `hw/ip`'s
|
||||
1 805 files never build an index), the index itself built from the
|
||||
census's own parse through `FileFacts::from_analysis`; **no
|
||||
`vlog_semantic` change was needed**. Pinned by a 15-fixture equality
|
||||
test against the pre-P3 `WorkspaceIndex::build` body, kept verbatim
|
||||
- [x] default `check` output byte-identical; all-style retains every
|
||||
`unused-import` finding; fixes, waivers, exit codes stable — all
|
||||
five corpus cells' stdout `diff` clean against the reference
|
||||
binary's (`hw/ip` 445 / 7 751 / 7 734, `hw/vendor` 1 666, `hw/dv`
|
||||
1 158), plus six new end-to-end CLI tests
|
||||
- [x] measured: ≥ half of the 123 ms all-style increment removed on
|
||||
`hw/ip`, default time and peak RSS not materially worse; the
|
||||
paired three-configuration experiment; tracker filled
|
||||
- [ ] QA: full findings/fixes/waivers diffed, not counts; RSS re-taken
|
||||
paired three-configuration experiment; tracker filled — the paired
|
||||
increment **141.7 → 5.0 ms (96 % removed)**, all-style
|
||||
**0.6333 → 0.4817 s (−23.9 %)**, default unchanged (all three
|
||||
binaries median 0.420 s), all-style peak RSS **219.1 → 202.0 MiB**.
|
||||
Experiment `P3-2026-09-07`
|
||||
- [x] QA: full findings/fixes/waivers diffed, not counts; RSS re-taken
|
||||
|
||||
### 60.4 P4 — startup and memory, only after P1–P3
|
||||
|
||||
|
||||
+46
-32
@@ -78,6 +78,44 @@ pub struct Census {
|
||||
packages: HashMap<String, Option<Vec<String>>>,
|
||||
}
|
||||
|
||||
/// What one file contributes to a [`Census`]: its words, the units it
|
||||
/// declares, and the packages it exports from.
|
||||
type PerFile = (
|
||||
Vec<String>,
|
||||
Vec<(String, Option<vlog_linter::ModuleInterface>)>,
|
||||
Vec<(String, Option<Vec<String>>)>,
|
||||
);
|
||||
|
||||
/// One file's three contributions, off **one** parse.
|
||||
///
|
||||
/// The word census wants the tokens, the interface table wants the tree and
|
||||
/// the package table wants both — so a run that asks for either table lexes
|
||||
/// and parses the file exactly once and all three read that. A run that asks
|
||||
/// for neither never parses at all: `harvest_text` lexes and stops, which is
|
||||
/// what the word census alone needs.
|
||||
///
|
||||
/// A file that cannot be read contributes nothing, and so does one that does
|
||||
/// not lex (`harvest_text` and a `ParsedSource` with no tokens agree on that).
|
||||
/// The file's own check is what reports the error.
|
||||
fn harvest_one(job: &Job, interfaces: bool, packages: bool) -> PerFile {
|
||||
let Ok(src) = std::fs::read_to_string(&job.path) else {
|
||||
return (Vec::new(), Vec::new(), Vec::new());
|
||||
};
|
||||
if !interfaces && !packages {
|
||||
return (words::harvest_text(&src), Vec::new(), Vec::new());
|
||||
}
|
||||
let parsed = ParsedSource::parse(&src);
|
||||
let declared = match interfaces {
|
||||
true => vlog_linter::module_interfaces(parsed.file()),
|
||||
false => Vec::new(),
|
||||
};
|
||||
let exports = match packages {
|
||||
true => vlog_linter::package_exports_in(&job.path, parsed.file(), parsed.tokens(), &src),
|
||||
false => Vec::new(),
|
||||
};
|
||||
(words::harvest(parsed.tokens()), declared, exports)
|
||||
}
|
||||
|
||||
impl Census {
|
||||
/// The census of every file in the run, harvested in parallel.
|
||||
///
|
||||
@@ -86,39 +124,15 @@ impl Census {
|
||||
/// file's own check reports the error.
|
||||
///
|
||||
/// `interfaces` says whether the run also needs each unit's ports and
|
||||
/// parameters (`unknown-port`, `unknown-parameter`). It costs a **parse**
|
||||
/// of every file on top of the lex the word census already pays for, so
|
||||
/// it is built only when some enabled rule asks — measured on opentitan
|
||||
/// `hw/` in `docs/features/linter-expansion-1/README.md`.
|
||||
/// parameters (`unknown-port`, `unknown-parameter`), and `packages`
|
||||
/// whether it needs each package's exported names (`unused-import`).
|
||||
/// Either costs a **parse** of every file on top of the lex the word
|
||||
/// census already pays for, so each is built only when some enabled rule
|
||||
/// asks — measured on opentitan `hw/` in
|
||||
/// `docs/features/linter-expansion-1/README.md`.
|
||||
fn of(jobs: &[Job], interfaces: bool, packages: bool) -> Census {
|
||||
type PerFile = (
|
||||
Vec<String>,
|
||||
Vec<(String, Option<vlog_linter::ModuleInterface>)>,
|
||||
Vec<(String, Option<Vec<String>>)>,
|
||||
);
|
||||
let per_file: Vec<PerFile> = jobs
|
||||
.par_iter()
|
||||
.map(|job| {
|
||||
let Ok(src) = std::fs::read_to_string(&job.path) else {
|
||||
return (Vec::new(), Vec::new(), Vec::new());
|
||||
};
|
||||
let exports = match packages {
|
||||
true => vlog_linter::package_exports(&job.path, &src),
|
||||
false => Vec::new(),
|
||||
};
|
||||
if !interfaces {
|
||||
return (words::harvest_text(&src), Vec::new(), exports);
|
||||
}
|
||||
// One lex for both halves: the parse is what the interface
|
||||
// table needs, and its tokens are the word census's.
|
||||
let parsed = ParsedSource::parse(&src);
|
||||
(
|
||||
words::harvest(parsed.tokens()),
|
||||
vlog_linter::module_interfaces(parsed.file()),
|
||||
exports,
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
let per_file: Vec<PerFile> =
|
||||
jobs.par_iter().map(|job| harvest_one(job, interfaces, packages)).collect();
|
||||
|
||||
let mut files: HashMap<String, u32> = HashMap::new();
|
||||
let mut units: HashMap<String, Option<vlog_linter::ModuleInterface>> = HashMap::new();
|
||||
|
||||
@@ -2294,3 +2294,132 @@ fn a_dangling_source_link_named_on_the_command_line_is_still_an_error() {
|
||||
assert_eq!(code(&out), 2, "{}", stderr(&out));
|
||||
assert!(stderr(&out).contains("no such file or directory"), "{}", stderr(&out));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// The package half of the census and `unused-import` (perf5-p3, 2026-09-07)
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
/// A package with two exported names, and the two importers the rule has to
|
||||
/// tell apart.
|
||||
const PKG: &str = "package p_pkg;\n localparam int A = 1;\n localparam int B = 2;\nendpackage\n";
|
||||
const USES_PKG: &str = "module uses_pkg;\n import p_pkg::*;\n localparam int C = A;\nendmodule\n";
|
||||
const IGNORES_PKG: &str =
|
||||
"module ignores_pkg;\n import p_pkg::*;\n localparam int C = 1;\nendmodule\n";
|
||||
|
||||
/// The style selection the rule lives in — `unused-import` is `Severity::Style`
|
||||
/// and so is off in a default `check`.
|
||||
const ALL_STYLE: [&str; 2] = ["--select", "error,warning,style"];
|
||||
|
||||
/// The headline: over a project, an import nothing in its file uses is
|
||||
/// reported, and one the file does use is not — and it is the *package
|
||||
/// census* that makes the difference, because the rule can only judge an
|
||||
/// import whose package the run can answer for.
|
||||
#[test]
|
||||
fn an_unused_package_import_is_reported_over_a_project() {
|
||||
let dir = TempDir::new("pkg-census");
|
||||
dir.write("p_pkg.sv", PKG);
|
||||
dir.write("uses_pkg.sv", USES_PKG);
|
||||
dir.write("ignores_pkg.sv", IGNORES_PKG);
|
||||
let out = run(&["check", &dir.root(), ALL_STYLE[0], ALL_STYLE[1]]);
|
||||
let text = stdout(&out);
|
||||
assert!(text.contains("unused-import"), "{text}");
|
||||
assert!(text.contains("ignores_pkg.sv"), "{text}");
|
||||
assert!(
|
||||
!text.lines().any(|line| line.contains("uses_pkg.sv") && line.contains("unused-import")),
|
||||
"the file that reads `A` keeps its import: {text}"
|
||||
);
|
||||
assert_eq!(code(&out), 1);
|
||||
}
|
||||
|
||||
/// `unused-import` is a style rule, so a default `check` neither reports it
|
||||
/// nor is changed by the presence of a package in the run.
|
||||
#[test]
|
||||
fn a_default_check_says_nothing_about_imports() {
|
||||
let dir = TempDir::new("pkg-default");
|
||||
dir.write("p_pkg.sv", PKG);
|
||||
dir.write("uses_pkg.sv", USES_PKG);
|
||||
dir.write("ignores_pkg.sv", IGNORES_PKG);
|
||||
let out = run(&["check", &dir.root()]);
|
||||
assert!(!stdout(&out).contains("unused-import"), "{}", stdout(&out));
|
||||
}
|
||||
|
||||
/// A package the run does not contain is a package the run cannot answer
|
||||
/// for, and the rule is silent about every import of it. This is the
|
||||
/// conservative direction the whole feature is built around: an accusation
|
||||
/// needs a known export list.
|
||||
#[test]
|
||||
fn an_import_of_a_package_outside_the_run_is_not_reported() {
|
||||
let dir = TempDir::new("pkg-unknown");
|
||||
dir.write("p_pkg.sv", PKG);
|
||||
dir.write("uses_pkg.sv", USES_PKG);
|
||||
dir.write(
|
||||
"stranger.sv",
|
||||
"module stranger;\n import elsewhere_pkg::*;\n localparam int C = 1;\nendmodule\n",
|
||||
);
|
||||
let text = stdout(&run(&["check", &dir.root(), ALL_STYLE[0], ALL_STYLE[1]]));
|
||||
assert!(!text.contains("elsewhere_pkg"), "an unknown package is unknowable: {text}");
|
||||
}
|
||||
|
||||
/// A package that re-exports from another one answers `None`: only a whole
|
||||
/// project index settles what a re-export chain lets through, and the CLI's
|
||||
/// one-file census will not guess. Every import of it goes quiet.
|
||||
#[test]
|
||||
fn an_import_of_a_re_exporting_package_is_not_reported() {
|
||||
let dir = TempDir::new("pkg-reexport");
|
||||
dir.write("p_pkg.sv", PKG);
|
||||
dir.write(
|
||||
"r_pkg.sv",
|
||||
"package r_pkg;\n import p_pkg::*;\n export p_pkg::*;\n localparam int D = 1;\n\
|
||||
endpackage\n",
|
||||
);
|
||||
dir.write(
|
||||
"ignores_r.sv",
|
||||
"module ignores_r;\n import r_pkg::*;\n localparam int C = 1;\nendmodule\n",
|
||||
);
|
||||
let text = stdout(&run(&["check", &dir.root(), ALL_STYLE[0], ALL_STYLE[1]]));
|
||||
assert!(!text.contains("r_pkg"), "a re-export chain is unknowable: {text}");
|
||||
}
|
||||
|
||||
/// Two files declaring one package name is a name the run cannot answer for,
|
||||
/// whatever the two say — `Census::of`'s merge turns the second contribution
|
||||
/// into `None`, and the rule goes quiet about it.
|
||||
#[test]
|
||||
fn an_import_of_a_package_two_files_declare_is_not_reported() {
|
||||
let dir = TempDir::new("pkg-duplicate");
|
||||
dir.write("p_pkg.sv", PKG);
|
||||
dir.write("p_pkg_copy.sv", "package p_pkg;\n localparam int Z = 9;\nendpackage\n");
|
||||
dir.write("ignores_pkg.sv", IGNORES_PKG);
|
||||
let text = stdout(&run(&["check", &dir.root(), ALL_STYLE[0], ALL_STYLE[1]]));
|
||||
assert!(!text.contains("unused-import"), "a duplicate package is unknowable: {text}");
|
||||
}
|
||||
|
||||
/// The gate is a claim about *cost*, not about answers, so the answers get
|
||||
/// their own end-to-end pin: a run whose only package file is surrounded by
|
||||
/// files holding the word `package` in strings and comments reports exactly
|
||||
/// what a run without those files reports.
|
||||
#[test]
|
||||
fn text_that_merely_says_package_changes_no_finding() {
|
||||
let bare = TempDir::new("pkg-bare");
|
||||
bare.write("p_pkg.sv", PKG);
|
||||
bare.write("ignores_pkg.sv", IGNORES_PKG);
|
||||
let plain = stdout(&run(&["check", &bare.root(), ALL_STYLE[0], ALL_STYLE[1]]));
|
||||
|
||||
let noisy = TempDir::new("pkg-noisy");
|
||||
noisy.write("p_pkg.sv", PKG);
|
||||
noisy.write("ignores_pkg.sv", IGNORES_PKG);
|
||||
noisy.write(
|
||||
"talker.sv",
|
||||
"// package q_pkg; endpackage\n\
|
||||
module talker;\n initial $display(\"package q_pkg; endpackage\");\nendmodule\n",
|
||||
);
|
||||
let with_noise = stdout(&run(&["check", &noisy.root(), ALL_STYLE[0], ALL_STYLE[1]]));
|
||||
for finding in plain.lines().filter(|line| line.contains("unused-import")) {
|
||||
let tail = finding.rsplit('/').next().unwrap_or(finding);
|
||||
assert!(with_noise.contains(tail), "{tail} lost: {with_noise}");
|
||||
}
|
||||
assert_eq!(
|
||||
plain.matches("unused-import").count(),
|
||||
with_noise.matches("unused-import").count(),
|
||||
"{plain}\n---\n{with_noise}"
|
||||
);
|
||||
}
|
||||
@@ -14,14 +14,29 @@
|
||||
use std::path::Path;
|
||||
|
||||
use vlog_parser::ast::{ItemKind, ListElem, Module, ParamPort, PortList, SourceFile};
|
||||
use vlog_semantic::{SymbolKind, WorkspaceIndex};
|
||||
use vlog_parser::defines::collect_defines;
|
||||
use vlog_parser::token::Token;
|
||||
use vlog_parser::LineIndex;
|
||||
use vlog_semantic::{analyze, FileFacts, IndexBuilder, SymbolKind, WorkspaceIndex};
|
||||
|
||||
use crate::context::ModuleInterface;
|
||||
use crate::visit::walk_items;
|
||||
use crate::ParsedSource;
|
||||
|
||||
/// Every package one file declares, with the names it exports — `None` for a
|
||||
/// package this file alone cannot answer for.
|
||||
///
|
||||
/// The text-taking form, for a caller that has not parsed: exactly one
|
||||
/// [`ParsedSource::parse`] followed by [`package_exports_in`], so the two can
|
||||
/// only ever give the same answer.
|
||||
pub fn package_exports(path: &Path, src: &str) -> Vec<(String, Option<Vec<String>>)> {
|
||||
let parsed = ParsedSource::parse(src);
|
||||
package_exports_in(path, parsed.file(), parsed.tokens(), src)
|
||||
}
|
||||
|
||||
/// [`package_exports`] over a parse the caller **already has** — `file` and
|
||||
/// `tokens` from one [`ParsedSource::parse`] of `src`.
|
||||
///
|
||||
/// The CLI's half of [`crate::MentionOracle::package_exports`], on the same
|
||||
/// terms [`module_interfaces`] is the CLI's half of `module_interface`: the
|
||||
/// language server reads the answer off its workspace index, and a run with
|
||||
@@ -31,8 +46,25 @@ use crate::visit::walk_items;
|
||||
/// A package writing `export q::*;` answers `None`: which names that lets
|
||||
/// through is a question only a whole-project index can settle, and a short
|
||||
/// list is what would turn a used import into an accusation.
|
||||
pub fn package_exports(path: &Path, src: &str) -> Vec<(String, Option<Vec<String>>)> {
|
||||
let index = WorkspaceIndex::build([(path.to_path_buf(), src)]);
|
||||
///
|
||||
/// Two things make this cheap enough for the CLI to run over a whole project
|
||||
/// (take 5 §P3, `docs/features/perf5-p3/README.md`). The index is built from
|
||||
/// the caller's parse rather than from the text, so the file is lexed and
|
||||
/// parsed once for this and for the interface census together; and a file
|
||||
/// whose tree holds **no package item** never reaches the index at all — nine
|
||||
/// files in ten on opentitan `hw/ip`. The gate reads the AST, never the text:
|
||||
/// a `package` inside a string or a comment is not a declaration, and a file
|
||||
/// that says nothing about packages must cost nothing.
|
||||
pub fn package_exports_in(
|
||||
path: &Path,
|
||||
file: &SourceFile,
|
||||
tokens: &[Token],
|
||||
src: &str,
|
||||
) -> Vec<(String, Option<Vec<String>>)> {
|
||||
if !declares_a_package(file) {
|
||||
return Vec::new();
|
||||
}
|
||||
let index = one_file_index(path, file, tokens, src);
|
||||
index
|
||||
.units_of(SymbolKind::Package)
|
||||
.map(|(name, _)| name.to_string())
|
||||
@@ -48,6 +80,52 @@ pub fn package_exports(path: &Path, src: &str) -> Vec<(String, Option<Vec<String
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Whether this tree holds a `package` item anywhere, which is the gate on
|
||||
/// building an index for the file at all.
|
||||
///
|
||||
/// Deliberately a **superset** of "declares a package unit": `walk_items`
|
||||
/// descends into every container, while only a package item bound in the file
|
||||
/// scope becomes a unit the index records. Answering `true` too often costs
|
||||
/// an index; answering `false` too often would lose a package, so the walk
|
||||
/// errs the one way it may.
|
||||
///
|
||||
/// A **fragment** parse — a file that is the bare middle of something, so its
|
||||
/// items list is empty and its content hangs off `SourceFile::fragment` —
|
||||
/// `walk_items` does not descend into, and is never gated out. No fragment
|
||||
/// shape can hold a package (they are statements, enum members and cover
|
||||
/// items, and a file opening with `package` is never re-read as one), but the
|
||||
/// gate does not rest on that.
|
||||
fn declares_a_package(file: &SourceFile) -> bool {
|
||||
if file.fragment.is_some() {
|
||||
return true;
|
||||
}
|
||||
let mut found = false;
|
||||
walk_items(file, &mut |item| {
|
||||
found |= matches!(item.kind, ItemKind::Package { .. });
|
||||
});
|
||||
found
|
||||
}
|
||||
|
||||
/// The one-file index [`WorkspaceIndex::build`] would make of this file,
|
||||
/// built from the caller's parse instead of from its text.
|
||||
///
|
||||
/// `build` is `IndexBuilder::add_file` + `finish`, and `add_file` is
|
||||
/// `add_facts(FileFacts::of(path, src))`. `FileFacts::of` parses, analyses and
|
||||
/// reads the record off; [`FileFacts::from_analysis`] is that same read-off
|
||||
/// with the parse handed in. So this is `build` with the lex and the parse it
|
||||
/// would have done deleted — pinned by the equality test below, not by the
|
||||
/// reading of two functions.
|
||||
fn one_file_index(path: &Path, file: &SourceFile, tokens: &[Token], src: &str) -> WorkspaceIndex {
|
||||
let defines = collect_defines(tokens);
|
||||
let sem = analyze(file, src);
|
||||
let lines = LineIndex::new(src);
|
||||
let facts =
|
||||
FileFacts::from_analysis(path.to_path_buf(), file, &defines, &sem, src, &lines, tokens);
|
||||
let mut builder = IndexBuilder::new();
|
||||
builder.add_facts(facts);
|
||||
builder.finish()
|
||||
}
|
||||
|
||||
/// Every module, interface and program the file declares, with what it
|
||||
/// exposes. `None` for a unit whose header cannot be read whole.
|
||||
///
|
||||
@@ -213,3 +291,196 @@ mod tests {
|
||||
assert_eq!(found.iter().map(|(name, _)| name.as_str()).collect::<Vec<_>>(), vec!["a", "b"]);
|
||||
}
|
||||
}
|
||||
|
||||
/// The package half: every fixture answers what a one-file `WorkspaceIndex`
|
||||
/// built from the file's **text** answers, and a file with no package item
|
||||
/// never builds one (take 5 §P3).
|
||||
#[cfg(test)]
|
||||
mod package_tests {
|
||||
use super::*;
|
||||
|
||||
/// The construction §P3 replaced, kept here as the thing to be equal to:
|
||||
/// a one-file index built from the text, queried exactly as
|
||||
/// [`package_exports_in`] queries the index it builds from a parse.
|
||||
fn from_text(path: &Path, src: &str) -> Vec<(String, Option<Vec<String>>)> {
|
||||
let index = WorkspaceIndex::build([(path.to_path_buf(), src)]);
|
||||
index
|
||||
.units_of(SymbolKind::Package)
|
||||
.map(|(name, _)| name.to_string())
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
.map(|name| {
|
||||
let answer = index.reexported_packages(&name).is_empty().then(|| {
|
||||
index.members_of(&name).map(|(member, _)| member.to_string()).collect()
|
||||
});
|
||||
(name, answer)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Every shape the census can meet, named so a failure says which.
|
||||
///
|
||||
/// The list is the §P3 brief's: no package, one, two, a wildcard export,
|
||||
/// a named re-export, a package behind a directive, a package after a
|
||||
/// module, text that does not lex, a parse error inside a package body, a
|
||||
/// class in a package, the word `package` in a string and in a comment,
|
||||
/// and one name declared twice in the same file.
|
||||
fn fixtures() -> Vec<(&'static str, &'static str)> {
|
||||
vec![
|
||||
("no package", "module m ();\n wire a;\nendmodule\n"),
|
||||
(
|
||||
"one package",
|
||||
"package p;\n localparam int A = 1;\n typedef logic [1:0] t;\n\
|
||||
endpackage\n",
|
||||
),
|
||||
(
|
||||
"two packages",
|
||||
"package p;\n localparam int A = 1;\nendpackage\n\
|
||||
package q;\n localparam int B = 2;\nendpackage\n",
|
||||
),
|
||||
(
|
||||
"a wildcard export of itself",
|
||||
"package p;\n localparam int A = 1;\n export *::*;\nendpackage\n",
|
||||
),
|
||||
(
|
||||
"a wildcard export of another package",
|
||||
"package p;\n import q::*;\n localparam int A = 1;\n export q::*;\n\
|
||||
endpackage\n",
|
||||
),
|
||||
(
|
||||
"a named re-export",
|
||||
"package p;\n import q::x;\n localparam int A = 1;\n export q::x;\n\
|
||||
endpackage\n",
|
||||
),
|
||||
(
|
||||
"a package behind a directive",
|
||||
"`ifdef USE_PKG\npackage p;\n localparam int A = 1;\nendpackage\n`endif\n",
|
||||
),
|
||||
(
|
||||
"a package after a module",
|
||||
"module m ();\nendmodule\npackage p;\n localparam int A = 1;\nendpackage\n",
|
||||
),
|
||||
("text that does not lex", "module m;\n wire a = \"unterminated\nendmodule\n"),
|
||||
(
|
||||
"a parse error inside the package",
|
||||
"package p;\n localparam int A = 1;\n @@@ ;\n localparam int B = 2;\n\
|
||||
endpackage\n",
|
||||
),
|
||||
(
|
||||
"a class in a package",
|
||||
"package p;\n class c;\n int field;\n endclass\n\
|
||||
endpackage\n",
|
||||
),
|
||||
(
|
||||
"the word package in a string",
|
||||
"module m ();\n initial $display(\"package p; endpackage\");\nendmodule\n",
|
||||
),
|
||||
(
|
||||
"the word package in a comment",
|
||||
"// package p; endpackage\nmodule m ();\nendmodule\n",
|
||||
),
|
||||
(
|
||||
"one name declared twice",
|
||||
"package p;\n localparam int A = 1;\nendpackage\n\
|
||||
package p;\n localparam int B = 2;\nendpackage\n",
|
||||
),
|
||||
("an empty file", ""),
|
||||
]
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn every_fixture_answers_what_a_text_built_index_answers() {
|
||||
for (name, src) in fixtures() {
|
||||
let path = Path::new("/w/f.sv");
|
||||
assert_eq!(package_exports(path, src), from_text(path, src), "{name}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_parsed_form_and_the_text_form_agree() {
|
||||
for (name, src) in fixtures() {
|
||||
let path = Path::new("/w/f.sv");
|
||||
let parsed = ParsedSource::parse(src);
|
||||
assert_eq!(
|
||||
package_exports_in(path, parsed.file(), parsed.tokens(), src),
|
||||
package_exports(path, src),
|
||||
"{name}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// The gate is the whole saving, so it is asserted directly rather than
|
||||
/// inferred from an equal answer: exactly the fixtures that write a
|
||||
/// `package` item reach the index.
|
||||
#[test]
|
||||
fn only_a_package_item_opens_the_gate() {
|
||||
let gated_out = [
|
||||
"no package",
|
||||
"text that does not lex",
|
||||
"the word package in a string",
|
||||
"the word package in a comment",
|
||||
"an empty file",
|
||||
];
|
||||
for (name, src) in fixtures() {
|
||||
let opens = declares_a_package(ParsedSource::parse(src).file());
|
||||
assert_eq!(opens, !gated_out.contains(&name), "{name}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A file that does not lex really is one, or the fixture above tests
|
||||
/// nothing about the lex-error path.
|
||||
#[test]
|
||||
fn the_unlexable_fixture_does_not_lex() {
|
||||
let src = fixtures()
|
||||
.into_iter()
|
||||
.find(|(name, _)| *name == "text that does not lex")
|
||||
.map(|(_, src)| src)
|
||||
.unwrap_or_default();
|
||||
assert!(ParsedSource::parse(src).lex_error().is_some(), "{src:?}");
|
||||
}
|
||||
|
||||
/// The answers themselves, not only their equality to the old
|
||||
/// construction: a file with no package says nothing, a plain package is
|
||||
/// a list, and a re-export is unknowable.
|
||||
#[test]
|
||||
fn the_answers_are_the_conservative_ones() {
|
||||
let path = Path::new("/w/f.sv");
|
||||
assert!(package_exports(path, "module m ();\nendmodule\n").is_empty());
|
||||
|
||||
let plain = package_exports(path, "package p;\n localparam int A = 1;\nendpackage\n");
|
||||
assert_eq!(plain.len(), 1);
|
||||
assert_eq!(plain[0].0, "p");
|
||||
assert_eq!(plain[0].1.as_deref(), Some(["A".to_string()].as_slice()));
|
||||
|
||||
let wildcard = package_exports(
|
||||
path,
|
||||
"package p;\n localparam int A = 1;\n export q::*;\nendpackage\n",
|
||||
);
|
||||
assert_eq!(wildcard, vec![("p".to_string(), None)], "a re-export is unknowable");
|
||||
}
|
||||
|
||||
/// One name declared twice **in one file** — the `` `ifdef``-copied
|
||||
/// package — answers with the *first* declaration's members, not with
|
||||
/// `None`. That is what the one-file index has always said and this lane
|
||||
/// changes nothing about it; the `None` the CLI's census produces is the
|
||||
/// *cross-file* rule, applied by `Census::of`'s merge when two files each
|
||||
/// contribute an entry for one name.
|
||||
///
|
||||
/// Pinned here so a later change to either construction has to notice it.
|
||||
#[test]
|
||||
fn a_name_declared_twice_in_one_file_answers_with_the_first() {
|
||||
let path = Path::new("/w/f.sv");
|
||||
let first = package_exports(
|
||||
path,
|
||||
"package p;\n localparam int A = 1;\nendpackage\n\
|
||||
package p;\n localparam int B = 2;\nendpackage\n",
|
||||
);
|
||||
assert_eq!(first, vec![("p".to_string(), Some(vec!["A".to_string()]))]);
|
||||
let swapped = package_exports(
|
||||
path,
|
||||
"package p;\n localparam int B = 2;\nendpackage\n\
|
||||
package p;\n localparam int A = 1;\nendpackage\n",
|
||||
);
|
||||
assert_eq!(swapped, vec![("p".to_string(), Some(vec!["B".to_string()]))]);
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ mod waiver_file;
|
||||
use std::path::PathBuf;
|
||||
|
||||
pub use context::{LintContext, MentionOracle, ModuleInterface, ParsedSource};
|
||||
pub use interfaces::{module_interfaces, package_exports};
|
||||
pub use interfaces::{module_interfaces, package_exports, package_exports_in};
|
||||
pub use options::{OptionDefault, OptionKind, OptionSpec, OptionValue, RuleOptions};
|
||||
pub use registry::{
|
||||
all_rules, default_rules, rule_by_name, rules_named, select_rules, workspace_rules, Rule,
|
||||
|
||||
@@ -0,0 +1,458 @@
|
||||
# perf5-p3 — one parse for the CLI package census
|
||||
|
||||
## Goal
|
||||
|
||||
`lucisv check` builds a project census before the first rule runs. When
|
||||
`unused-import` is enabled the census asked `vlog_linter::package_exports`
|
||||
for **every** file in the run, and that function built a one-file
|
||||
`WorkspaceIndex` — a lex, a parse, a full analysis and a fact read-off —
|
||||
even for a file that declares no package at all. The census had already
|
||||
parsed the same text a line earlier for the interface table, so every file
|
||||
paid for two whole-file parses and one analysis it almost never needed.
|
||||
Performance take 5 §P3 measured the price: the rule turns a 0.450 s
|
||||
all-style run on opentitan `hw/ip` into a 0.587 s one, **+137 ms (23.3 %)**,
|
||||
and peak RSS 177 → 217 MiB.
|
||||
|
||||
This feature removes the duplication. The census parses each file once and
|
||||
derives both halves from that parse, and the package half opens with an
|
||||
**AST gate**: a file whose tree holds no `package` item contributes nothing
|
||||
and no index is built for it. On `hw/ip` that is 1 624 of 1 805 files.
|
||||
|
||||
## Assumptions
|
||||
|
||||
- `ParsedSource::parse` and `vlog_semantic`'s `parse_and_collect` produce
|
||||
the *same* tree for the same text: both are `tokenize` + `parse_tolerant`
|
||||
on the lex-ok path and `parse_source_tolerant` on the lex-error path. The
|
||||
equality tests in `interfaces.rs` are what hold this true rather than the
|
||||
reading of two functions.
|
||||
- `collect_defines(&[])` equals `DefineTable::default()` (it is `Vec::new()`
|
||||
either way), and `words::harvest(&[])` / `harvest_raw(&[])` are empty — so
|
||||
the lex-error path of `FileFacts::from_analysis` gives the record
|
||||
`FileFacts::of` gives.
|
||||
- Only `bind_item`'s `ItemKind::Package` arm ever declares a
|
||||
`SymbolKind::Package`, so a tree with no `Package` item cannot produce a
|
||||
file-scope package unit. The gate additionally never fires on a
|
||||
**fragment** parse, which `walk_items` does not descend into.
|
||||
- `words::harvest_text(src)` equals `words::harvest(ParsedSource::parse(src)
|
||||
.tokens())`: `harvest_text` is `tokenize` + `harvest`, empty on a lex
|
||||
error, and a `ParsedSource` whose text did not lex holds no tokens.
|
||||
- A rayon worker in `lucisv` has `PARSE_STACK_SIZE` of stack
|
||||
(`main.rs::pool`), which is what lets the census analyse on it. This
|
||||
feature removes a parse from that thread and adds none.
|
||||
|
||||
## Handshakes
|
||||
|
||||
### Consumed
|
||||
|
||||
- `vlog_semantic::{analyze, FileFacts::from_analysis, IndexBuilder::{new,
|
||||
add_facts, finish}, WorkspaceIndex::{units_of, members_of,
|
||||
reexported_packages}}` — the one-file index, now built from a parse the
|
||||
caller already has instead of from text. **No semantic change was needed:**
|
||||
`FileFacts::from_analysis` (added by perf5-p2 for the refactoring scope)
|
||||
already accepts exactly `(path, tree, defines, sem, src, lines, tokens)`,
|
||||
and `IndexBuilder::add_facts` + `finish` is what `WorkspaceIndex::build`
|
||||
itself does. `crates/vlog_semantic/` is untouched by this lane.
|
||||
- `vlog_parser::defines::collect_defines`, `vlog_parser::token::Token`,
|
||||
`vlog_parser::LineIndex` — the three inputs `from_analysis` wants that a
|
||||
`ParsedSource` does not already carry.
|
||||
|
||||
### Promised
|
||||
|
||||
- `vlog_linter::package_exports_in(path, file, tokens, src)` — new, additive.
|
||||
Every package the parsed file declares, with the names it exports, `None`
|
||||
for one this file alone cannot answer for. **Byte-identical to
|
||||
`package_exports(path, src)` on the same text**, which is now a wrapper
|
||||
(parse, then `_in`) and stays the API for a caller holding only text.
|
||||
- `MentionOracle::package_exports`' answers are unchanged: the same
|
||||
duplicate-package `None`, the same `export q::*` `None`, the same
|
||||
conservative silence for an unknown package.
|
||||
|
||||
### Requested of the lead (not done by this lane — `docs/topo.md` is not ours)
|
||||
|
||||
1. `lucisv ──▶ vlog_linter`: add `package_exports_in` beside `ParsedSource`
|
||||
— the CLI census hands the linter its own parse for the package half, as
|
||||
it already does for the interface half (`module_interfaces`).
|
||||
2. `vlog_linter ──▶ vlog_semantic`: the edge now also reads
|
||||
`FileFacts::from_analysis` + `IndexBuilder::{add_facts, finish}` to build
|
||||
the one-file package index from a parse the linter already has.
|
||||
`WorkspaceIndex::build` is still what the equality test compares against,
|
||||
so the two constructions are pinned equal.
|
||||
|
||||
## Status / TODO
|
||||
|
||||
- [x] package exports from the census's existing parse; AST gate, never a
|
||||
textual `contains("package")`
|
||||
- [x] every-fixture equality test against the old `WorkspaceIndex::build`
|
||||
construction (15 fixtures, plus a gate-answer test and the duplicate pin)
|
||||
- [x] CLI regression: default `check` byte-identical, all-style keeps every
|
||||
`unused-import` finding — six new end-to-end tests, and the corpus run's
|
||||
five stdout captures `diff` clean
|
||||
- [x] paired three-configuration measurement on `hw/ip`, tracker filled
|
||||
- [x] `cargo fmt` / guarded `clippy --all-targets` / guarded
|
||||
`test --workspace` (4 250 → 4 262, 0 failed)
|
||||
- [ ] QA
|
||||
- [ ] lead: the two `docs/topo.md` edges requested above
|
||||
|
||||
## Work log
|
||||
|
||||
### 2026-09-07 — dev
|
||||
|
||||
**The change, file by file.**
|
||||
|
||||
- `crates/vlog_linter/src/interfaces.rs`. New public
|
||||
`package_exports_in(path: &Path, file: &SourceFile, tokens: &[Token], src:
|
||||
&str) -> Vec<(String, Option<Vec<String>>)>` — the same three index queries
|
||||
as before (`units_of(Package)`, `reexported_packages`, `members_of`) over an
|
||||
index built two new ways. `package_exports(path, src)` is now
|
||||
`ParsedSource::parse` + `package_exports_in`, so a text-only caller is
|
||||
unaffected and the two forms cannot disagree. Two private helpers:
|
||||
`declares_a_package(file)` — the gate, `walk_items` looking for
|
||||
`ItemKind::Package`, deliberately a *superset* of "declares a package unit"
|
||||
(the walk descends into every container while only a file-scope binding
|
||||
becomes a unit), and never firing on a fragment parse; and
|
||||
`one_file_index(path, file, tokens, src)` —
|
||||
`collect_defines` + `analyze` + `LineIndex::new` +
|
||||
`FileFacts::from_analysis` + `IndexBuilder::{add_facts, finish}`, which is
|
||||
`WorkspaceIndex::build` with the lex and the parse deleted.
|
||||
- `crates/vlog_linter/src/lib.rs`. One line: `package_exports_in` joins the
|
||||
`interfaces` re-export.
|
||||
- `crates/lucisv/src/lint.rs`. `Census::of`'s rayon closure became a free
|
||||
`harvest_one(job, interfaces, packages) -> PerFile` (the `PerFile` alias
|
||||
moved to module scope with it), so `of` is a `par_iter` line plus the merge
|
||||
and both stay inside the size rule. `harvest_one` parses **once** when
|
||||
either half is wanted and feeds the word census, the interface table and the
|
||||
package table from that one parse; when neither is wanted it still only
|
||||
lexes, via `words::harvest_text`. Production lines (non-blank, non-comment, before `mod tests`): 495 → **494** — the census work moved rather than grew, well under
|
||||
the 600 mark.
|
||||
- `crates/lucisv/tests/cli.rs`. Six end-to-end tests (see below).
|
||||
|
||||
**Why no `vlog_semantic` change.** The plan allowed an additive
|
||||
`FileFacts::from_parsed`. It was not needed: §P2b already added
|
||||
`FileFacts::from_analysis(path, tree, defines, sem, src, lines, tokens)` for
|
||||
the refactoring scope, and that is exactly the second half of `FileFacts::of`.
|
||||
`crates/vlog_semantic/` is byte-unchanged by this lane.
|
||||
|
||||
**The gate, and why it is safe.** `SymbolKind::Package` is created in exactly
|
||||
one place, `bind/item.rs`'s `ItemKind::Package` arm, and only a binding in the
|
||||
*file* scope becomes an indexed unit. So a tree holding no `Package` item
|
||||
anywhere cannot yield a package unit, and returning empty for it is not an
|
||||
approximation. Erring the other way (opening the gate too often) costs an
|
||||
index and nothing else, which is why the fragment case is let through rather
|
||||
than reasoned about.
|
||||
|
||||
**Tests.** `interfaces::package_tests` keeps the **pre-P3 body verbatim** as a
|
||||
`from_text` reference and asserts the new code equal to it over 15 fixtures:
|
||||
no package; one; two; `export *::*`; `export q::*`; a named re-export; a
|
||||
package behind an `` `ifdef``; a package after a module; text that does not
|
||||
lex; a parse error inside a package body; a class in a package; the word
|
||||
`package` in a string; the same in a comment; one name declared twice; an
|
||||
empty file. Three further tests pin what equality cannot see —
|
||||
`only_a_package_item_opens_the_gate` checks the gate's answer fixture by
|
||||
fixture (a gate that always opened would fail it),
|
||||
`the_unlexable_fixture_does_not_lex` stops that fixture going stale, and
|
||||
`a_name_declared_twice_in_one_file_answers_with_the_first` pins a pre-existing
|
||||
answer worth knowing: **within one file** a duplicate package name reports the
|
||||
*first* declaration's members, not `None`. The `None` is the cross-file rule
|
||||
and belongs to `Census::of`'s merge. That behaviour is unchanged by this lane
|
||||
and is not a finding against it, but QA should know it is there.
|
||||
|
||||
The six CLI tests drive the real binary: an unused import reported and a used
|
||||
one not; a default `check` silent about imports; an import of a package
|
||||
outside the run silent; an import of a re-exporting package silent; an import
|
||||
of a package two files declare silent; and a run whose extra files write
|
||||
`package` only inside a string and a comment producing the identical finding
|
||||
set. There were **no** CLI-level `unused-import` tests before this lane.
|
||||
|
||||
**Measurement** (full record: `docs/perf/take5-tracking.md`, experiment
|
||||
`P3-2026-09-07`; raw data `~/.cache/lucisv-perf/take5-p3/`). The owner's
|
||||
paired method — alternating binary order, `/usr/bin/time -l`, every child
|
||||
under `tools/guard.sh -m 8 -t 1800`, opentitan read-only and its
|
||||
`git status --porcelain` asserted after every single invocation.
|
||||
|
||||
| `hw/ip` cell | reference 0.50.0 | trunk rebuilt here | candidate |
|
||||
|---|---:|---:|---:|
|
||||
| default `check` | 0.4183 s (median 0.420) | 0.4450 (0.420) | **0.4233 (0.420)** |
|
||||
| `--select error,warning,style` | 0.6333 | 0.6333 | **0.4817** |
|
||||
| the same, `--ignore unused-import` | 0.4750 | 0.4917 | **0.4767** |
|
||||
| the rule's paired increment | 158.3 ms | 141.7 ms | **5.0 ms** |
|
||||
| all-style peak RSS (max of 6) | 220.9 MiB | 219.1 | **202.0** |
|
||||
|
||||
**96 % of the increment is gone** against the same-toolchain control, where
|
||||
the target was half. All-style falls **−23.9 %**; `hw/vendor` −22.2 % and
|
||||
`hw/dv` −18.5 % in a separate eight-trial pass. Every cell's stdout is
|
||||
**byte-identical** to the reference's, diffed as files: `hw/ip` default 445
|
||||
findings, all-style 7 751 (17 of them `unused-import`), minus rule 7 734;
|
||||
`hw/vendor` 1 666; `hw/dv` 1 158.
|
||||
|
||||
Two notes on honesty. First, the machine was loaded (one-minute load 3.6–9.9
|
||||
against the §P0 baseline's 2.9–4.6), so absolute seconds here are higher than
|
||||
the tracker's REF cells for *both* binaries; only the paired difference is
|
||||
quoted. Second, the first eight-trial pass showed default `check` +4 % on the
|
||||
candidate, which no code path explains (a default run never asks for the
|
||||
package half). A **third binary** — the same trunk source rebuilt here — was
|
||||
added as a control and settled it: the trunk rebuild is +6.4 % on default
|
||||
against the cached reference while the candidate is +1.2 %, and all three
|
||||
medians are 0.420 s. The default cell is unchanged.
|
||||
|
||||
**What remains.** The 5.0 ms left is the `unused-import` rule body's own
|
||||
`import_usage` plus the 181 surviving one-file index builds (now analysis and
|
||||
record only). The next measurable CLI duplicate is the **third parse** — the
|
||||
lint pass parses each of the 1 805 files again after the census has. Retaining
|
||||
the census's ASTs would remove it and would hold 1 805 trees of a 39 MB corpus
|
||||
alive at once against a 202 MiB peak; the plan told this stage to measure peak
|
||||
RSS before making that trade, and it is not made here.
|
||||
|
||||
## QA log
|
||||
|
||||
### 2026-09-07 — QA
|
||||
|
||||
**Verdict: PASS.** All gates green, the AST gate independently attacked (9
|
||||
fixtures beyond the dev's 15) and sabotage-tested, lint-silence parity
|
||||
diffed full-output on a fixture tree the dev did not build, all five corpus
|
||||
cells re-run and re-hashed to the exact quoted hashes, the timing claim
|
||||
reproduced within the noise this machine allows, and traceability numbers
|
||||
re-derived independently. No corruption/idempotency/comment risk: this
|
||||
lane touches only census bookkeeping, never emitted text.
|
||||
|
||||
**Setup.** Worked in a fresh clone at
|
||||
`/private/tmp/.../scratchpad/qa-p3/clone` (branched from `5c9fdb2`, `git
|
||||
apply` of `git diff -- crates/ TODO.md` from the working tree — applied
|
||||
clean) plus an unmodified sibling clone `clone-head` at the same `5c9fdb2`
|
||||
for a true pre-P3 baseline. Every cargo/lucisv invocation below went
|
||||
through `tools/guard.sh -m 8 -t 1800`; zero guard kills anywhere in this
|
||||
pass. `git -C /Users/guoliangchen/repo/opentitan status --porcelain` was
|
||||
checked before this session and after every corpus/timing invocation —
|
||||
always exactly the three pre-existing files (`hw/ip/aes/dv/tb/tb.sv`,
|
||||
`hw/top_darjeeling/ip/ast/rtl/ast.sv`, `hw/top_earlgrey/ip/ast/rtl/ast.sv`).
|
||||
Machine load was elevated for part of this session (a 1-minute sample of
|
||||
59 was observed mid-session, decaying to ~5 by the timing re-take;
|
||||
unrelated system processes, not a runaway — checked with `top`, nothing
|
||||
of mine was consuming it) — noted per instruction, and the timing section
|
||||
below reads only the paired difference for that reason.
|
||||
|
||||
**1. Gates.**
|
||||
- `cargo fmt --all -- --check` on the clone: clean (exit 0).
|
||||
- `cargo clippy --all-targets` on the clone: clean, zero warnings (exit 0).
|
||||
`grep -n "#\[allow" crates/lucisv/src/lint.rs
|
||||
crates/vlog_linter/src/interfaces.rs`: no hits — no new `#[allow]`.
|
||||
- `cargo test --workspace --release` on the clone (candidate, P3 applied):
|
||||
**4262 passed, 0 failed** (summed across every binary's `test result:`
|
||||
line). Same command on `clone-head` (5c9fdb2, no P3): **4250 passed, 0
|
||||
failed**. Difference is exactly **+12**, matching the dev's own count of
|
||||
new tests (6 `package_tests`/gate tests + 6 CLI tests); nothing existing
|
||||
was lost.
|
||||
- `cargo tree -p lucisv -e normal` on the clone: lists `lucisv_core`,
|
||||
`rayon`, `vlog_formatter`, `vlog_linter`, `vlog_parser` — `vlog_semantic`
|
||||
appears only nested under `vlog_linter`, never as a direct dependency of
|
||||
`lucisv`. Topology claim confirmed.
|
||||
- Production line count, non-blank/non-comment before `mod tests`:
|
||||
`crates/lucisv/src/lint.rs` **494** — confirmed by the same `awk`+`grep -c`
|
||||
method the dev used. Well under the 600 mark.
|
||||
- Binary provenance: rebuilding `5c9fdb2` unmodified in `clone-head`
|
||||
produced sha256 `81bb40a28802e713…` — an **exact match** to the dev's own
|
||||
recorded "trunk-rebuild" control binary. Rebuilding the clone with the
|
||||
P3 diff applied produced sha256 `2c16b321cb2d1083…` — an exact match to
|
||||
the dev's recorded candidate hash, and to `target/release/lucisv` in the
|
||||
main tree (no rebuild was needed there; used as-is for corpus/timing
|
||||
runs below).
|
||||
|
||||
**2. THE AST GATE.** Read `declares_a_package` and `walk_items`
|
||||
(`crates/vlog_linter/src/visit.rs`): the gate is a `matches!(item.kind,
|
||||
ItemKind::Package { .. })` predicate over an AST walk that descends into
|
||||
modules, classes, packages, and every generate-region/if/for/case shape —
|
||||
never a text search. Macros are confirmed **not expanded** by this parser
|
||||
(`ItemKind::MacroItem(MacroCall)` holds the call, not a substituted body —
|
||||
`vlog_parser/src/ast/mod.rs:360`), so a `` `define P package p; endpackage
|
||||
`` followed by `` `P `` cannot manufacture a real `Package` item under
|
||||
either the old or the new construction — confirmed by test, not assumed.
|
||||
|
||||
Nine fixtures beyond the dev's 15, appended as `qa_attack_tests` in the
|
||||
clone's `interfaces.rs` (not shipped; QA-only clone code) and run with
|
||||
`cargo test -p vlog_linter -- interfaces:: --nocapture`: **all 9 pass**,
|
||||
each asserting `package_exports(new) == from_text(old)` (old = the
|
||||
dev's verbatim pre-P3 `WorkspaceIndex::build` construction, duplicated
|
||||
into the QA module since it is private to `package_tests`):
|
||||
(a) package word only in a macro body never invoked, in a string
|
||||
spanning a line continuation, in a block comment, and in an invoked
|
||||
(but not expanded) macro — all agree, all empty;
|
||||
(d) `Package p; ... endpackage` (capital P) — not a keyword, agrees;
|
||||
(e) `program`/`interface`/`class`/`module` all named `package_x` — none
|
||||
is a package, agrees;
|
||||
(c) a parse error (`@@@`) before the first member inside the package
|
||||
body — agrees;
|
||||
(f) an empty package body — agrees, and is `Some(vec![])` not `None`;
|
||||
(g) a package followed by an unterminated second one — agrees;
|
||||
(h) CRLF line endings — agrees;
|
||||
(i) UTF-8 BOM prefix — agrees.
|
||||
|
||||
**Sabotage.** Edited the clone's `declares_a_package` to
|
||||
`{ let _ = file; false }` (gate always closed) and reran `cargo test -p
|
||||
vlog_linter -- interfaces::`: **9 of the dev's+QA's package tests fail**,
|
||||
including the dev's own `every_fixture_answers_what_a_text_built_index_
|
||||
answers`, `only_a_package_item_opens_the_gate`, and
|
||||
`a_name_declared_twice_in_one_file_answers_with_the_first`, plus 6 of the
|
||||
QA attack fixtures. The equality oracle catches a broken gate exactly as
|
||||
intended. `interfaces.rs` was restored byte-for-byte afterward (diffed
|
||||
against the pre-sabotage copy: clean) and the full suite re-run clean (23
|
||||
passed under `interfaces::`, 0 failed).
|
||||
|
||||
**(b) duplicate-in-one-file pin.** Independently re-derived, not just
|
||||
trusted: constructing `package p; A=1; endpackage package p; B=2;
|
||||
endpackage` by hand and calling `package_exports` gives `Some(["A"])` —
|
||||
the first declaration's members, not `None`. This matches the dev's
|
||||
documented pre-existing answer exactly; it is the one-file index's
|
||||
behavior (unchanged by this lane) and the CLI's cross-file `None` comes
|
||||
from `Census::of`'s merge, confirmed separately below.
|
||||
|
||||
**`from_text` verbatim check.** `git show 5c9fdb2:crates/vlog_linter/src/
|
||||
interfaces.rs` has no `package_tests` module (P3 added it), so the
|
||||
"verbatim" claim was checked against the actual pre-P3 production body
|
||||
instead: the current `package_tests::from_text` is character-for-character
|
||||
the same construction `package_exports` used to be at `5c9fdb2` (`let
|
||||
index = WorkspaceIndex::build(...)`, same two-step `units_of` +
|
||||
`reexported_packages`/`members_of` query) — confirmed by diffing the two
|
||||
snippets by hand.
|
||||
|
||||
**3. LINT SILENCE PARITY.** Built a fixture tree the dev did not have
|
||||
(`scratchpad/qa-p3/fixtree`, 16 files) covering every shape the task
|
||||
named: a used import, an unused import, an import of an unknown package,
|
||||
an import of a package declared twice across files, an `a_pkg → b_pkg`
|
||||
re-export chain used through `b_pkg`, a second independent re-export
|
||||
chain (`c_pkg → d_pkg`) used through a wildcard, a package behind an
|
||||
`` `ifdef`` (never defined — the census still sees the package item,
|
||||
matching the dev's own "package behind a directive" fixture's finding:
|
||||
lucisv does not evaluate conditionals structurally), and a waiver file
|
||||
waiving `unused-import`.
|
||||
|
||||
Ran `clone-head/target/release/lucisv` (pre-P3, sha `81bb40a2…`) and the
|
||||
candidate (`target/release/lucisv`, sha `2c16b321…`) over this tree:
|
||||
- `check --select error,warning,style`: stdout **byte-identical**, exit 1
|
||||
both. 2 `unused-import` findings (`unused_import.sv`, `ifdef_import.sv`);
|
||||
the re-export/unknown/duplicate-package imports and the used imports are
|
||||
silent on both binaries, as expected.
|
||||
- `check` (default): stdout byte-identical, exit 1 both (package-filename
|
||||
and endif-comment findings only — `unused-import` is style-only, off by
|
||||
default on both).
|
||||
- `check --select error,warning,style --fix` on two copies of the tree:
|
||||
stdout identical once the two temp-dir paths are normalized out; **the
|
||||
fixed files themselves are byte-identical** (`diff -r` clean) — this
|
||||
answers the "does `unused-import` have a fix, and does `--fix` diff
|
||||
clean" question: yes, it deletes the whole `import` line
|
||||
(`Applicability::Safe`), and both binaries produce the same edit.
|
||||
- A waiver file (`waive --rule=unused-import
|
||||
--location=unused_import.sv`): both binaries silence the waived finding
|
||||
and exit 0, stdout identical (empty).
|
||||
|
||||
**4. CORPUS.** Re-ran all five cells independently (not reusing the dev's
|
||||
saved captures) with `~/.cache/lucisv-baselines/lucisv-0.50.0` as
|
||||
reference and `target/release/lucisv` as candidate (sha confirmed matching
|
||||
the tracker beforehand, no rebuild). Captured stdout only (`2>/dev/null`
|
||||
— the `found N violations` summary is on stderr,
|
||||
`crates/lucisv/src/lint.rs:753`, which the first attempt without
|
||||
redirection discipline conflated; corrected before drawing conclusions).
|
||||
Every cell: reference and candidate stdout **byte-identical**, exit codes
|
||||
equal (1, 1, 1, 2, 1 — `hw/vendor` is 2 for both, a pre-existing format
|
||||
failure unrelated to this lane), and the hashes match the tracker's quoted
|
||||
values exactly:
|
||||
|
||||
| Cell | sha256 | Lines | Matches tracker |
|
||||
|---|---|---:|---|
|
||||
| `hw/ip` default | `c2444712e23e…` | 445 | yes |
|
||||
| `hw/ip` all-style | `97201de03bca…` | 7751 (17 `unused-import`) | yes |
|
||||
| `hw/ip` minus rule | `58780c3e81b8…` | 7734 | yes |
|
||||
| `hw/vendor` all-style | `1ce51659c4ab…` | 1666 | yes |
|
||||
| `hw/dv` all-style | `d7913e5f5846…` | 1158 | yes |
|
||||
|
||||
`git status --porcelain` on opentitan checked and unchanged after every
|
||||
one of these ten invocations.
|
||||
|
||||
**5. TIMING.** Re-took `hw/ip` all-style / minus-rule, 3 trials alternating
|
||||
binary order, `/usr/bin/time -l`, both binaries as in §4, every child under
|
||||
`tools/guard.sh`. **Machine load was elevated** (1-minute sample 4.76–5.11
|
||||
at run time, still carrying a 5-minute average around 22–23 from earlier
|
||||
work this session), so — per instruction — only the paired
|
||||
(all-style − minus-rule) increment is read, not absolute seconds:
|
||||
|
||||
| | trial 1 | trial 2 | trial 3 | median |
|
||||
|---|---:|---:|---:|---:|
|
||||
| reference increment | +150 ms | +140 ms | +160 ms | **+150 ms** |
|
||||
| candidate increment | −30 ms | +30 ms | −20 ms | **−20 ms (noise floor)** |
|
||||
|
||||
The reference's increment lands inside the dev's own reported range
|
||||
(141.7–158.3 ms across the dev's three binaries). The candidate's
|
||||
increment is indistinguishable from zero at `/usr/bin/time`'s ~10 ms
|
||||
rounding — fully consistent with the dev's claimed 5.0 ms residual, and
|
||||
independently confirms **well over 50 %** of the increment is gone (the
|
||||
target). Peak RSS, maximum of 3 trials: reference **211.0 MiB**, candidate
|
||||
**196.2 MiB** — not worse, matching the dev's direction (219–221 → ~196–
|
||||
202 MiB across both passes). `git status --porcelain` on opentitan
|
||||
unchanged after all 12 timed invocations.
|
||||
|
||||
**6. Traceability.** All hashes and counts in the tracker's P3 cells and
|
||||
experiment `P3-2026-09-07` were checked against
|
||||
`~/.cache/lucisv-perf/take5-p3/` and reproduce: `binaries.sha256` matches
|
||||
the two rebuilt QA binaries exactly; the five `stdout-*` capture files'
|
||||
sha256 match the hashes quoted in the README/tracker; `p3-threeway.jsonl`
|
||||
and `p3-results.jsonl` exist and are non-empty. Package-file counts
|
||||
re-derived with a plain `grep -lE '^[[:space:]]*package[[:space:]]+'`
|
||||
over each tree's `.sv`/`.svh` files (a different method than whatever the
|
||||
dev used, deliberately): `hw/ip` **181/1805**, `hw/vendor` **24/285**,
|
||||
`hw/dv` **40/365** — all three exact matches.
|
||||
|
||||
**7. `harvest_one` lex-only path.** Read the function
|
||||
(`crates/lucisv/src/lint.rs:100-108`): the `if !interfaces && !packages`
|
||||
branch returns `words::harvest_text(&src)` before any call to
|
||||
`ParsedSource::parse`, so the neither-wanted path is lex-only by
|
||||
construction — not something that could regress silently without a
|
||||
diff touching this exact `if`. **Finding (non-blocking):** there is no
|
||||
test in `lint.rs`'s own `mod tests` pinning this contract, and adding one
|
||||
is not a one-liner — `Job` has no test constructor and its `config:
|
||||
vlog_formatter::Config` field has no `Default` impl, so a pinning test
|
||||
needs a small `Job`-building test helper first. Left as a finding rather
|
||||
than fixed in the main tree per the QA policy on non-trivial fixes;
|
||||
suggested for a future small addition (a `Job`-builder test helper plus
|
||||
one assertion that `harvest_one(job, false, false)` returns empty
|
||||
`declared`/`exports` and equals `words::harvest_text`).
|
||||
|
||||
**Topology edges for the lead** (from the feature README's Handshakes,
|
||||
independently confirmed correct by the `cargo tree` check in §1 and the
|
||||
code reading in §2): apply both — `lucisv ──▶ vlog_linter` gains
|
||||
`package_exports_in`, and `vlog_linter ──▶ vlog_semantic` gains
|
||||
`FileFacts::from_analysis` + `IndexBuilder::{add_facts, finish}` as a read
|
||||
the CLI package half now depends on.
|
||||
|
||||
**Nothing else was touched.** No production files were edited in the main
|
||||
tree; the sabotage and QA attack fixtures live only in the scratch clone
|
||||
(`/private/tmp/.../scratchpad/qa-p3/clone`), which is left in place as
|
||||
QA evidence rather than deleted.
|
||||
|
||||
## Review
|
||||
|
||||
**2026-09-07 (lead).** Accepted. Read `package_exports_in`,
|
||||
`declares_a_package`, `one_file_index`, `harvest_one`, the equality test's
|
||||
verbatim pre-P3 reference, the six CLI tests, the tracker's P3 entry and
|
||||
both logs; QA's parity over a fixture tree (`check`, all-style, `--fix`
|
||||
outputs and fixed files, a waiver) against a HEAD build and its byte-diff
|
||||
of the five corpus cells are the acceptance.
|
||||
|
||||
- The plan's own shape, delivered as written: one parse in the census,
|
||||
the package half read off it, the AST gate (never text) sparing the
|
||||
nine files in ten that declare no package, the one-file index assembled
|
||||
from the caller's parse through §P2's `FileFacts::from_analysis` — no
|
||||
new semantic API, the CLI still without a direct semantic dependency.
|
||||
- 96 % of the rule's increment removed (142 → 5 ms on `hw/ip`, RSS down
|
||||
8.6 %) with every output byte-identical; the target was half.
|
||||
- The third parse (the lint pass's own) stays, deliberately: retaining
|
||||
1 805 trees against a 200 MiB peak is the memory-for-time trade the
|
||||
plan says to refuse without a recorded case. Filed as a number, not
|
||||
taken.
|
||||
- QA's non-blocking finding — no test pins `harvest_one`'s lex-only path
|
||||
when neither half is wanted — noted; the code reads correctly and a
|
||||
test needs a `Job` constructor the module does not have. Loop-3 list.
|
||||
- The "duplicate package within one file reports the first declaration's
|
||||
members" answer is pre-existing and now pinned, which is better than
|
||||
before.
|
||||
|
||||
Docs applied at merge: topo edges `lucisv ──▶ vlog_linter`
|
||||
(`package_exports_in`) and `vlog_linter ──▶ vlog_semantic`
|
||||
(`FileFacts::from_analysis` + `IndexBuilder`).
|
||||
+200
-9
@@ -1,6 +1,6 @@
|
||||
# Performance implementation tracker — take 5
|
||||
|
||||
**Status: baseline measured; P0 done; P1a–P1c and P2a–P2c implemented, measured and merged; topology handshake 33 closed and P2d measured; P2d's `warnings` dedupe implemented and measured (2026-09-07; the second §P2 lane's QA pending). P2d ships no narrowing — the census below says why — and the ≥×2 rename target is **met at 2.01×** by the dedupe instead.** The implementation agent owns the blank candidate columns and experiment entries below. Read [the causes and detailed plan](../performance_take5.md) before selecting work. Baseline provenance and raw rows are in [take5-baseline](take5-baseline/README.md).
|
||||
**Status: baseline measured; P0 done; P1a–P1c and P2a–P2c implemented, measured and merged; topology handshake 33 closed and P2d measured; P2d's `warnings` dedupe implemented and measured (2026-09-07; the second §P2 lane's QA pending). P2d ships no narrowing — the census below says why — and the ≥×2 rename target is **met at 2.01×** by the dedupe instead. P3 implemented and measured 2026-09-07 (dev; QA pending): the CLI package census shares the interface census's parse and gates on the AST, and **96 % of the `unused-import` all-style increment is gone** (141.7 → 5.0 ms paired against a same-toolchain trunk build; all-style `hw/ip` 0.633 → 0.482 s, −23.9 %), with every stdout byte-identical.** The implementation agent owns the blank candidate columns and experiment entries below. Read [the causes and detailed plan](../performance_take5.md) before selecting work. Baseline provenance and raw rows are in [take5-baseline](take5-baseline/README.md).
|
||||
|
||||
Do not overwrite the baseline, silently replace a workload, omit refusals, or report a proposed target as an achieved result. Use `not measured`, `blocked`, or `not applicable` rather than zero. Update this file after each measured stage, including rejected changes.
|
||||
|
||||
@@ -41,7 +41,7 @@ The order follows the plan. Later stages are conditional on the preceding measur
|
||||
| H33 | Topology handshake 33 — the transitive hierarchical user `module_sources` could not see | P2c | dev (Opus); release `da2aa9433e11…`; committed 2026-09-07 | Done | `docs/features/perf5-p2/README.md`; experiment `H33-2026-09-07` below. A **fifth rung**, opt-in and asked for by inline-module alone: every file whose token census (`files_mentioning`, i.e. `FileFacts::words`) writes the dissolved instance's name. That census is exactly what `no_hierarchy` can refuse from, so the selected set now answers that refusal **as `sources()` would** — pinned by a six-shape whole-workspace equivalence test. Costs **+1.2 ms** at the measured site (8 files added); the four rungs, and therefore extract and every port action, are unchanged in answer and in cost |
|
||||
| P2d | Exact-name postings; source-set narrowing only with whole-scope proof | Reprofile P2c; topology 33 for shared module selector | dev (Opus); same release; committed 2026-09-07 → QA PASS → lead; committed 2026-09-07 | Done — no narrowing (proof negative); handshake 33 closed; warnings dedupe; tail rename 2.01× | Same README; experiment `P2d-2026-09-07` below. The census says **133 of the tail rename's 238 selected files (56 %, 58 % of the bytes, ~130 ms) write neither name down** — all of them on the container rungs. They are not droppable: they are what `fold_path` hops through for a multi-level hierarchical tail and what `base_chain` climbs, so dropping them turns a resolved tail `StillUnresolved` (a **missed edit**, §49's own feature) and, where a reference has two paths, lets it fall through onto the target (an **extra edit**). Exact-name postings not implemented: selection is **13.6 ms of 420 (3.2 %)**, below the plan's own materiality gate. The target-scoped selector — fan out from the one declaration the cursor resolves to — is filed with its full shape list as a lane of its own |
|
||||
| P2d-W | The `warnings` stage stops repeating itself: one lex and one `LineIndex` per file per call | P2d's finding | dev (Opus); release `18ef6d60c548…`; 2026-09-07 | Done | Same README; experiment `P2d-warnings-2026-09-07` below. The pure dedupe §P2d filed: `FileScan` memoizes `tokenize` and `LineIndex::new` per file, the five scans share it, and their sentences are concatenated in the order the five loops emitted them. The `warnings` stage **82.2 → 51.4 ms** on the tail rename, **22.9 → 8.3** on `aes`, **848.5 → 437.9** on the `clk_i` fallback. Tail rename **387.9 ms = 2.01× the §P0 REF — the ≥2× target is met.** The second dedupe P2d proposed (gate `macro_argument_sites` on `files_naming_in_macros`) is **not taken and the reason is in the code**: `macro_words` skips double-quoted runs, so `` `uvm_info("state_q", …) `` is a site the scan reports and the census cannot see. Warning **lists** compared as lists across 13 renames, old binary vs new: identical, order included |
|
||||
| P3 | Reuse CLI census parse for package exports/interfaces | P0; coordinate semantic ownership | — | Not started | — |
|
||||
| P3 | Reuse CLI census parse for package exports/interfaces | P0; coordinate semantic ownership | dev (Opus); release CLI sha256 `2c16b321cb2d…`; 2026-09-07 → QA PASS → lead; committed 2026-09-07 | Done — 96 % of the increment removed, outputs byte-identical | `docs/features/perf5-p3/README.md`; experiment `P3-2026-09-07` below. Additive `vlog_linter::package_exports_in(path, file, tokens, src)`: the census parses each file **once** and both halves read that parse, and a file whose tree holds no `package` item never builds an index — **1 624 of `hw/ip`'s 1 805 files** (181 declare a package). No `vlog_semantic` change was needed; `FileFacts::from_analysis` + `IndexBuilder::add_facts` already existed. All-style `hw/ip` **0.6333 → 0.4817 s (−23.9 %)**, the rule's paired increment **141.7 → 5.0 ms**, default `check` unchanged (medians identical), all-style peak RSS **219.1 → 202.0 MiB**. Every cell's stdout **byte-identical** to the reference's, `hw/vendor` and `hw/dv` included |
|
||||
| P4a | Attribute scan/prelude/table-build/cache/RSS cost | P0 | — | Not started | — |
|
||||
| P4b | Implement the dominant measured startup/memory fix | P4a; serialize with state/index changes | — | Not started | — |
|
||||
| P5 | Parser or cancellable snapshot work only if a new measured case justifies it | Reprofile P1–P4 | — | Deferred | — |
|
||||
@@ -113,10 +113,11 @@ REF and part of each delta is §P1b's.
|
||||
| Diagnostics publication (`diagnostics`) | 158.02 / 155.95–157.62 ms | Preserve debounce/burst coalescing | **REF** 156.72 / 152.74–160.55 ms | +1.6% | Agrees |
|
||||
| Unblocked definition (`nav`) | 0.365 / 0.048–0.084 ms; 1 location | Transport-sensitive regression control | **REF** 0.528 / 0.145–0.206 ms; 1 location | +132% but **sub-millisecond: not read** | Not read, per the round's own rule |
|
||||
| Transport floor (`baseline`) | 0.240 / 0.066–0.070 ms | Record contemporaneous noise | **REF** 0.207 / 0.061–0.102 ms; `status: error` with `expected_status: error` (an unknown method, rejected without work) | +10.6% but **sub-millisecond: not read** | Not read; the row's rejection is now explicit |
|
||||
| CLI default, hw/ip | 0.59 / 0.40–0.40 s; 445 findings | First trial outlier; compare paired repeats | **REF** 0.39 / 0.38–0.39 s; 445 findings; stdout sha256 **identical to baseline** | −3.0% on repeats (baseline's first trial excluded as the owner flagged) | Agrees on repeats; outcome byte-identical |
|
||||
| CLI all-style, hw/ip | 0.58 / 0.56–0.58 s; mean 0.573 s; 7751 findings | Retain all findings | **REF** 0.58 / 0.59–0.59 s; mean **0.587 s**; 7751 findings; stdout sha256 identical | +2.4% on means | Agrees; reference for P3 |
|
||||
| CLI all-style minus unused-import, attribution only | 0.44 / 0.44–0.47 s; mean 0.450 s; 7734 findings | Save ≥half of 123 ms increment with rule enabled | **REF** 0.46 / 0.43–0.46 s; mean **0.450 s**; 7734 findings; stdout sha256 identical | 0.0% on means; the increment reproduces at **137 ms (23.3% of all-style)** against the baseline's 123 ms (21.5%) | Agrees; P3's target is ≥half of the increment measured on its own reference |
|
||||
| CLI all-style peak RSS | 208.4 MiB max of 3 | No material memory increase | **REF** 217.0 MiB max of 3 | +4.1% | Agrees |
|
||||
| CLI default, hw/ip | 0.59 / 0.40–0.40 s; 445 findings | First trial outlier; compare paired repeats | **REF** 0.39 / 0.38–0.39 s; 445 findings; stdout sha256 **identical to baseline** — **P3** mean **0.4233 s**, median **0.420**, n=6 against the reference's 0.4183 / **0.420** and a same-toolchain trunk build's 0.4450 / **0.420**; 445 findings; stdout sha256 `c2444712e23e…` on all three binaries | −3.0% on repeats (baseline's first trial excluded as the owner flagged); **P3 0.0% on medians, +1.2% on means** — the trunk control's mean is *higher* than either, so the mean spread is the machine, not the change | Agrees on repeats; outcome byte-identical. P3: default time unchanged, as the code path predicts (a default `check` never asks for the package half) |
|
||||
| CLI all-style, hw/ip | 0.58 / 0.56–0.58 s; mean 0.573 s; 7751 findings | Retain all findings | **REF** 0.58 / 0.59–0.59 s; mean **0.587 s**; 7751 findings; stdout sha256 identical — **P3** mean **0.4817 s** (median 0.480, range 0.47–0.49, n=6) against the same-day reference's 0.6333 and the trunk control's 0.6333; **7751 findings**, stdout sha256 `97201de03bca…` **byte-identical** to the reference's | +2.4% on means; **P3 −23.9% on the same-day paired means** (−17.9% on the §P0 REF's 0.587, which was taken at a lower machine load) | Agrees; reference for P3. **P3 target ≤ ~0.52 s met at 0.482** |
|
||||
| CLI all-style minus unused-import, attribution only | 0.44 / 0.44–0.47 s; mean 0.450 s; 7734 findings | Save ≥half of 123 ms increment with rule enabled | **REF** 0.46 / 0.43–0.46 s; mean **0.450 s**; 7734 findings; stdout sha256 identical — **P3** mean **0.4767 s** against the reference's 0.4750 and the trunk control's 0.4917 (n=6 each); 7734 findings, stdout sha256 `58780c3e81b8…` identical | 0.0% on means; the increment reproduces at **137 ms (23.3% of all-style)** against the baseline's 123 ms (21.5%). **P3: the control is flat (+0.4% on the reference, −3.1% on the trunk build), so the whole all-style saving is the rule's own path — the paired increment falls 141.7 → 5.0 ms, 96% removed** | Agrees; P3's target is ≥half of the increment measured on its own reference — **met, and then some** |
|
||||
| CLI all-style peak RSS | 208.4 MiB max of 3 | No material memory increase | **REF** 217.0 MiB max of 3 — **P3** max of 6 **202.0 MiB**, against the reference's 220.9 and the trunk control's 219.1 on the same runs (`/usr/bin/time -l` maximum resident set size) | +4.1%; **P3 −8.6% on the same-day reference maximum** | Agrees. P3 removes memory rather than trading for speed: the one-file index is built for 181 files instead of 1 805 |
|
||||
| CLI all-style, `hw/vendor` and `hw/dv` (**new**, P3) | not measured | Show the saving is not an `hw/ip` artefact | **P3** `hw/vendor` (285 files, 24 declare a package) 0.1125 → **0.0875 s**; `hw/dv` (365 files, 40 packages) 0.0813 → **0.0663 s**; eight alternating trials each, stdout sha256 `1ce51659c4ab…` and `d7913e5f5846…` **identical** to the reference's | **−22.2%** and **−18.5%** on means | New row; no REF exists — P0 measured `hw/ip` only. The two smaller trees move by the same fraction, which is what a per-file cost predicts |
|
||||
| Format check independently cold, hw/ip | 0.67 / 0.59–0.68 s | 0 cache hits; unchanged outcomes | **REF** 0.67 / 0.61–0.70 s; **0 cache hits in all three tries**; 1772 would reformat, 30 unchanged, 4 failed; stdout sha256 identical | +2.0% on means | Agrees, and cold is now provably cold |
|
||||
| Format check warm, hw/ip | 0.69 / 0.61–0.63 s | 30 hits; unchanged outcomes | **REF** 0.67 / 0.65–0.66 s; **30 hits in all three tries**; same outcomes; stdout sha256 identical | +2.6% on means | Agrees |
|
||||
|
||||
@@ -132,8 +133,8 @@ REF and part of each delta is §P1b's.
|
||||
| Tail rename index / parse / analysis / resolution / verification stage times | Not measured | Not measured — P2a | **Measured, §P2a** (ms / whole-file parses): selection 13.4/0, `Scope::build` 228.5/**238**, `locate` 0.5/1, occurrence walk 116.3/**134**, token identity 4.3/0, before-prints 14.0/0, `rebuilt_index` 228.4/**238**, after-prints 71.5/**106**, warnings 83.6/0 — **717 parses**, 73 % of the request. **§P2c**: 13.4 / 225.1 / 0.0 / 12.1 / 4.5 / 14.0 / **37.2** / **7.9** / 83.3 — **240 parses = K + E** |
|
||||
| Ordinary rename selected bytes / stages | Edited 9; other counts unmeasured | Edited 9 confirmed (14 edits, fingerprint `fa7e31c78382…`); stages unmeasured — P2a | **Measured, §P2a: 13 files / 400 051 bytes** (request 1, declaration 4, reference 8), watched 12 / 398 160 bytes, edited 9; 51 parses; index 23.4, occurrence walk 19.2, verify 63.3 (rebuild 22.4, after 20.3), warnings 23.4 ms. **§P2c: 22 parses = K + E**, verify 46.8 (rebuild 23.4, after 2.9) |
|
||||
| Ambiguous-use all-sources fallback frequency | Not measured | Not measured — P2a | **Measured, §P2a.** Of the eight renames the `renametrace` phase walks, **four** take the whole scope: a common port name (`clk_i`, whose declarations carry ambiguous references), a duplicate module name (`rstmgr_por`, declared in four files), a new name a great many external uses spell, and a cursor on no symbol at all (which `rename.rs` answers with `ws.sources()` outright, without consulting the ladder). Each costs a **3 976-file / 35.8 MB** `Scope::build`, ~1 840 ms, before anything else happens |
|
||||
| Per-file parses for CLI census and lint | Multiple paths confirmed; runtime counts unmeasured | Not measured — P3 | — |
|
||||
| CLI package-census vs unused-import body time | Combined 123 ms wall increment; stages unseparated | Increment reproduced on the same binary at **137 ms, 23.3% of all-style** (means 0.587 vs 0.450 s, three trials, alternating order, stdout hashes identical to baseline). Stages still unseparated — P3 | — |
|
||||
| Per-file parses for CLI census and lint | Multiple paths confirmed; runtime counts unmeasured | Not measured — P3 | **Counted by construction, §P3.** Before: an all-style run over `hw/ip` did 1 805 `ParsedSource::parse` (the interface census) + 1 805 `WorkspaceIndex::build` (each a lex + parse + analyse + record) + 1 805 lint parses = **5 415 whole-file parses**. After: 1 805 census parses + **181** analyses (no parse — the record is read off the census's own tree, and only for the files whose AST holds a `package` item) + 1 805 lint parses = **3 610 parses + 181 analyses**. The third parse, the lint pass's own, is untouched and is the remaining duplicate |
|
||||
| CLI package-census vs unused-import body time | Combined 123 ms wall increment; stages unseparated | Increment reproduced on the same binary at **137 ms, 23.3% of all-style** (means 0.587 vs 0.450 s, three trials, alternating order, stdout hashes identical to baseline). Stages still unseparated — P3 | **Separated, §P3.** The increment is **141.7 ms** on a same-toolchain trunk build and **5.0 ms** on the candidate: the census's per-file index build was **136.7 ms of it, 96%**, and the rule body plus the surviving 181-file census is the remaining **5.0 ms (1.0% of all-style)**. Measured as the paired difference `all-style − (all-style with --ignore unused-import)` on each binary, six alternating trials |
|
||||
| Startup discovery / hash / decode / merge / candidates / includes / compact | Only combined scan time measured | Still only combined — P4a. P0 adds the scan's *other* half: first useful answer, cold **84.42–85.87 ms** vs warm **206.12–218.72 ms**, and the settle of those same perturbed sessions (cold 2855–2877, warm 1340–1358 ms) | — |
|
||||
| Peak server RSS during startup and refactoring | Idle RSS only; peak unmeasured | **Startup peak measured** (`peak_rss_kib`, `ps -o rss=` at 50 ms across the scan): cold 526.7 / 530.2 / 535.2 MiB, warm 575.0 / 572.5 / 575.6 MiB — equal to idle to the KiB in all six sessions, i.e. no transient above idle. Refactoring peak still unmeasured — P2a | **Measured, §P2a, and re-measured at §P2b/§P2c** (MiB, `ps -o rss=` at 50 ms across each rename): tail 590 → 610 → 593; `aes` 582 → 577 → 585; unique internal 570 → 579 → 579; **`clk_i` fallback 1 864 → 1 840 → 1 830**; conflict 647 → 639 → 641; `cipher_alert → clk_i` **1 809 → 1 695 → 1 590**; `rstmgr_por` fallback 922 → 901 → 927; no-symbol 914 → 905 → 918. **No row's peak rose by more than 20 MiB and the two heaviest fell** — retention is bounded to the files the request was going to analyse anyway |
|
||||
| First useful response during scan; open buffers 1 / 10 / 100 | Not measured in this round | **First useful response measured** (above), each session a fresh process, kept in separate sessions from the settled rows so the settled series stays comparable. Open buffers 1 / 10 / 100 not measured — P4a | — |
|
||||
@@ -153,7 +154,7 @@ this stage; each says so rather than being left ambiguous.
|
||||
| Refactor whole-scope parity | Exact edits, warnings, refusal sentences; old/new common names, unresolved and ambiguous uses | **P0 supplies the instrument**: `fingerprint` (sha256 over sorted edits + created paths + warnings) and `edits`/`files`/`created` on every edit-bearing row, plus refusal sentences captured verbatim in `message`. First reference values recorded (tail rename, `aes` rename, extraction). **P2: matched on every row of every stage.** All thirteen edit-bearing rows of `renametrace`, `tailrename`, `rename`, `refactor` and `execute` carry byte-identical fingerprints at §P2a, §P2b and §P2c and equal to the §P0 REF's — `b39defb21265…`, `fa7e31c78382…`, `5f53e977da59…`, `31aadc134628…`, `4b534a16bca7…`, `8f3a26dd147b…`, `0ee027e37d07…`, `090e92e7736e…` — and the three refusal rows carry the same sentences and the same empty-edit fingerprint `96f32d4243b1…`. The common-name, unresolved-new-name and ambiguous-use cases the gate names are the `renametrace` phase's own rows. **Second lane (H33/P2d): matched again on every row** — the four `renametrace` edit fingerprints, the shared refusal `96f32d4243b1…` on all three refusal rows, the extract capture `090e92e7736e…` and the three `refactor` resolves, all byte-identical; and inline-module gains a **whole-workspace equivalence test in the suite** (`the_selected_set_answers_the_inline_exactly_as_the_whole_workspace_does`), which is this gate asserted in code rather than only on the corpus |
|
||||
| Topology handshake 33 | Transitive `wrap.u_S.x` refusal coverage before sharing/narrowing module sources | **CLOSED 2026-09-07 (second lane).** `module_sources` gains an opt-in **fifth rung** (`module_select::hierarchical_users`, `Workspace::module_sources_reaching`), asked for by `inline_module::execute` alone: every file whose token census (`WorkspaceIndex::files_mentioning`, i.e. `FileFacts::words`) writes the dissolved instance's name down. `words::harvest` records every `Ident` token **and** the words inside macro/directive/attribute raw text, so every file `no_hierarchy` can refuse over is in it — the selected set now answers that refusal exactly as `sources()` does, asserted by `the_selected_set_answers_the_inline_exactly_as_the_whole_workspace_does` on six shapes. Sixteen tests (twelve through the real dispatch): two and three wrapper levels, the level the four rungs already saw, a `bind` from a file that instantiates nothing (**the fixture that discarded the transitive-instantiator walk the topology row names — the walk cannot reach it**), a generated path, a macro-hidden path (pinned *not* refused, with the reason), a package/interface/class name, duplicate modules, an unsaved buffer, a clean ladder, and the four-rung answer asserted unchanged as a list. Cost **+1.2 ms** at `aes_wrap.sv` 66:2 (8 files added); worst instance spelling in the corpus selects 79 of 3 975 files (2 %), on a command, never on a keystroke. Extract and the port actions ask for `Reach::none()` and are unchanged in answer and cost. Historical: **not applicable at P2a–P2c**: `module_sources`, `offer_sources`, `imports::sources` and `rename_sources`' six rungs are untouched, and **no source set was narrowed or shared** — the ladder's only change is that the set it fills now records which rung filled it. Handshake 33 remains §P2d's prerequisite. Not applicable at P0 — no selector shared or narrowed. **Still not applicable at P1**: the four `*_in` selectors take the same decisions over the same tree, and **no source set was narrowed or shared** — `module_sources` / `offer_sources` / `imports::sources` are untouched. Handshake 33 stays P2's prerequisite |
|
||||
| Refactor verification | Token identity, semantic identity, parse-diagnostic preservation, comments/attributes, span remapping | **P2: the checks are untouched; their inputs changed.** `Print`, `print`, `Shifts`, `Excluded`, `watched_files`, `tokens_match`, `first_difference`, the `ledger` and the parse-diagnostic comparison are the same code and the same comparisons; what moved is where a `Semantics` and an after-index come from (`check/after.rs`, new). Every existing attack still refuses — `check::tests`' eight `tokens_match` pairs, `check/ledger.rs`'s, `removing_an_import_a_reference_needs_is_rejected`, the `rename/tests.rs` refusals — and **three new attack pairs aimed at the reuse** were added and pass: a stale retained analysis (`a_rename_whose_edit_rebinds_a_name_in_the_edited_file_is_refused`), an after-index that forgot an unedited file (`a_rename_that_would_make_a_third_files_use_ambiguous_is_refused`), and shifted file ids (`a_print_names_paths_so_shifted_file_ids_cannot_change_it`). Not applicable at P0 — the engine's verifiers are untouched. **Unchanged at P1**: nothing below the four gates moved; `extract_module`, `inline_module`, `organize_imports`, `port_actions` and `check::verify` are the same code, and `vlog_refactor`'s own suites are green. **P1c: still unchanged where it matters.** `check::verify_splice`, `check::verify` and `ports::confirm` are untouched, and every resolve/execute path still runs them — the three resolve rows measured above carry fingerprints byte-identical to the REF's. The *offer* predicates deliberately do not run them; that is the only widening, it is confined to a menu, it was already the lazy offer's stated contract, and the every-offset parity suites find **zero** cursors on their fixtures where it changes the answer |
|
||||
| CLI output | Compare full findings/fixes/waivers/exit codes, not just counts; disabled-rule run stays attribution-only | **Passed.** stdout sha256 of all five configurations byte-identical to the baseline's; exit codes 1 (lint findings) / 2 (four pre-existing format failures) as before; the `--ignore unused-import` run is recorded as attribution only |
|
||||
| CLI output | Compare full findings/fixes/waivers/exit codes, not just counts; disabled-rule run stays attribution-only | **Passed.** stdout sha256 of all five configurations byte-identical to the baseline's; exit codes 1 (lint findings) / 2 (four pre-existing format failures) as before; the `--ignore unused-import` run is recorded as attribution only. **P3: passed again, this time against a changed binary** — the candidate's stdout is byte-identical to the reference's on all five cells (`hw/ip` default 445, all-style 7 751 including 17 `unused-import`, minus rule 7 734; `hw/vendor` 1 666; `hw/dv` 1 158), `diff`ed as files. Exit codes unchanged. The `--ignore unused-import` run stays the attribution control and is never quoted as the optimization |
|
||||
| Index parity | Fresh/incremental/absorbed fingerprints, unsaved wins, coherent partial publication, scope/filelist/rootless behavior | **P2c pins the absorbed-against-fresh equality where the verifier now stands on it**: `an_absorbed_after_index_is_the_index_a_rebuild_would_give` compares fingerprint, file list **and** a query-level print (`units`, `references_to`, `instantiations_of`, `hierarchical_declarations`, `workspace_symbols`) on nine cases including a file gaining and losing a declaration, an edit that changes what another file resolves to, a re-export chain, an edited package and a file that stops lexing; `absorbing_an_edited_file_keeps_every_file_id` pins id stability; `an_index_from_analyzed_facts_is_the_index_a_build_gives` pins the §P2b assembly. Not applicable at P0. Store size unchanged at 44.34 MiB and the scan's own `$/progress` end messages recorded per cell (`124 → 3976 files indexed, 3975 from cache, 3 skipped` warm) |
|
||||
| Persistence | Corrupt/truncated/old-format stores rebuild safely; interrupted writes; content hash retained | Not applicable at P0 |
|
||||
| Resources | Guard outcomes, idle and peak memory, allocated/actual store size, stack-size requirement | **P2: zero guard kills** across nineteen timed phases and every `cargo` gate; largest resident set **1 864 MiB** (23 % of the 8 GiB limit), on the §P2a all-sources fallback — and §P2b/§P2c *lowered* it. Peak RSS re-measured per rename at all three stages (the row above); no row rose by more than 20 MiB. The one new retention is a request-local `HashMap<usize, Semantics>` bounded to the files whose text spells one of the two names, which are the files the request analyses anyway. No new parsing thread, so the 16 MiB stack contract is untouched. **Passed.** Every run under `tools/guard.sh -m 8 -t 1800`; **zero kills**; largest resident set 575.6 MiB (7% of the limit). Idle *and* peak RSS now recorded in their own KiB fields; store 44.34 MiB. **P1: zero guard kills** across ten timed runs and every `cargo` gate. Memory not re-measured (P4a's phase); the only new retention is one `Vec<Region>` per open buffer that ever needed a fence answer. No new parsing thread, so the 16 MiB stack contract is untouched |
|
||||
@@ -1290,6 +1291,196 @@ this stage; each says so rather than being left ambiguous.
|
||||
- **QA result and lead review link:** QA pending (the second §P2 lane's QA
|
||||
covers handshake 33, §P2d and this follow-up).
|
||||
|
||||
## Experiment record — P3-2026-09-07 (stage P3)
|
||||
|
||||
- **Experiment ID / stage / date / owner:** `P3-2026-09-07` / P3, one parse for
|
||||
the CLI package census / 2026-09-07, America/Chicago / dev agent (Opus).
|
||||
- **Hypothesis and exact expected work reduction:** `Census::of` called
|
||||
`vlog_linter::package_exports(path, src)` for **every** file whenever
|
||||
`unused-import` was enabled, and that function built a one-file
|
||||
`WorkspaceIndex` — a lex, a parse, an analysis and a record read-off — even
|
||||
for a file declaring no package. The census had already parsed the same text
|
||||
a line earlier for the interface table. Two removals were expected: share the
|
||||
parse, and gate the index on the AST. On `hw/ip` **181 of 1 805 files**
|
||||
declare a package, so the gate alone should remove ~90 % of the index work.
|
||||
Target: at least half of the 137 ms all-style increment, default time and
|
||||
peak RSS not materially worse.
|
||||
- **Reference commit, candidate commit or diff hash, binary hashes:** reference
|
||||
= trunk `5c9fdb2` (the §P2d lane's commit); reference binary = the tracker's
|
||||
own `~/.cache/lucisv-baselines/lucisv-0.50.0`, sha256
|
||||
`894054128495b764bb966e7b923e08267e57aea83fdc611fad4b4ed7a66b51e3`.
|
||||
**A third binary was added as a control**: the same trunk source rebuilt on
|
||||
this machine with this toolchain, sha256
|
||||
`81bb40a28802e713233519c0e390f518c6cc32f31f535332ba4b7c3295c5deff` (the four
|
||||
edited files were replaced with `git show HEAD:<path>` output, built, then
|
||||
restored from copies — no git state was changed). Candidate = the working
|
||||
tree, release sha256
|
||||
`2c16b321cb2d10835129c809af1acb8c6cb680bb7fa56cf9b4b2b9c25c220215`, built
|
||||
twice from the restored sources to the same hash. The control exists because
|
||||
the first eight-trial pass showed default `check` +4 % on the candidate with
|
||||
**no code path behind it**; it separates a build/machine difference from a
|
||||
source one, and it answered: the trunk rebuild is +6.4 % on default against
|
||||
the cached reference while the candidate is +1.2 %, and all three medians are
|
||||
0.420 s.
|
||||
- **Files changed / API contracts amended / topology references:**
|
||||
`crates/vlog_linter/src/interfaces.rs` (new `package_exports_in(path: &Path,
|
||||
file: &SourceFile, tokens: &[Token], src: &str)`, the private
|
||||
`declares_a_package` gate and `one_file_index`; `package_exports(path, src)`
|
||||
is now a two-line wrapper), `crates/vlog_linter/src/lib.rs` (one re-export),
|
||||
`crates/lucisv/src/lint.rs` (`Census::of`'s closure lifted to a free
|
||||
`harvest_one`, which parses once and feeds both halves),
|
||||
`crates/lucisv/tests/cli.rs` (+6 tests). **`crates/vlog_semantic/` is
|
||||
untouched:** `FileFacts::from_analysis` (added by §P2b) and
|
||||
`IndexBuilder::{add_facts, finish}` were already exactly what was needed, so
|
||||
the additive semantic API the plan allowed was not required. Topology: two
|
||||
edges need amending by the lead — `lucisv ──▶ vlog_linter` (add
|
||||
`package_exports_in` beside `ParsedSource`) and `vlog_linter ──▶
|
||||
vlog_semantic` (the edge now also reads `FileFacts::from_analysis` +
|
||||
`IndexBuilder`). Requested in `docs/features/perf5-p3/README.md`; `topo.md`
|
||||
was not edited by this lane. `cargo tree -p lucisv -e normal` still lists
|
||||
`lucisv_core`, `rayon`, `vlog_formatter`, `vlog_linter`, `vlog_parser` and
|
||||
**not** `vlog_semantic` — the CLI keeps no direct semantic dependency.
|
||||
- **Workload, corpus/input hashes, open files, cursor/range, rules, client
|
||||
capabilities:** opentitan `00981352642fb65ef2b6c47143a0f6bb31fd4a97` with the
|
||||
same three pre-existing modified files, verified `git status --porcelain`
|
||||
before the run and after every phase. Three configurations on
|
||||
`hw/ip` (1 805 `.sv`/`.svh`): default `check`; `check --select
|
||||
error,warning,style`; the same with `--ignore unused-import` (attribution
|
||||
control). Plus all-style on `hw/vendor` (285 files) and `hw/dv` (365).
|
||||
Package-declaring files, `grep -lE '^[[:space:]]*package[[:space:]]+'`:
|
||||
`hw/ip` **181**, `hw/vendor` **24**, `hw/dv` **40**. Default worker count.
|
||||
- **Machine, compiler/profile, threads, load before/after, competing activity:**
|
||||
M1 Max, macOS 27.0, release profile, workspace LTO. **Load was high and rising
|
||||
for the first pass — 5.77 to 9.92 one-minute — and 3.63 to 5.83 for the
|
||||
three-way control pass**, against the §P0 baseline's 2.92–4.59. The competing
|
||||
load was ordinary desktop work (WindowServer, browsers), no build and no
|
||||
benchmark; nothing was killed. This is why the headline is quoted as the
|
||||
**paired** difference against a binary measured in the same alternating pass,
|
||||
and why absolute seconds here are higher than §P0's REF cells across the
|
||||
board — the reference binary is 8 % slower here than it was there.
|
||||
No `cargo` command ran during any timed pass.
|
||||
- **Commands, cache reset/prime steps, trial ordering and fresh-session count:**
|
||||
every child `tools/guard.sh -m 8 -t 1800 -- /usr/bin/time -l <binary> <args>
|
||||
<tree>`, the owner's paired-CLI method from
|
||||
[take5-baseline](take5-baseline/README.md) with the binary order **alternating
|
||||
between trials**. Three passes: `probe.py` (2 binaries × 5 cells × 8 trials),
|
||||
`default-only.py` (default `check` alone, 12 alternating pairs, to settle the
|
||||
ambiguous default cell), `threeway.py` (3 binaries × 3 cells × 6 trials).
|
||||
The lint cache is not involved (`check` does not use the format cache); no
|
||||
cache reset step applies.
|
||||
- **Raw evidence path, explicit units, full sample arrays:**
|
||||
`~/.cache/lucisv-perf/take5-p3/` — `probe.py`, `default-only.py`,
|
||||
`threeway.py`, `p3-results.jsonl`, `p3-default-focus.jsonl`,
|
||||
`p3-threeway.jsonl`, the ten saved stdout captures and `binaries.sha256`.
|
||||
Units: `wall_s` seconds, `peak_rss_bytes` bytes (`/usr/bin/time -l`'s
|
||||
maximum resident set size). Three-way pass, wall seconds in trial order:
|
||||
|
||||
| Cell | `ref-0.50.0` | `trunk-rebuild` | `cand-p3` |
|
||||
|---|---|---|---|
|
||||
| default | `[0.40, 0.40, 0.42, 0.43, 0.42, 0.44]` | `[0.59, 0.40, 0.42, 0.44, 0.40, 0.42]` | `[0.42, 0.43, 0.42, 0.41, 0.41, 0.45]` |
|
||||
| all-style | `[0.60, 0.65, 0.63, 0.60, 0.64, 0.68]` | `[0.61, 0.64, 0.61, 0.64, 0.62, 0.68]` | `[0.47, 0.49, 0.49, 0.48, 0.48, 0.48]` |
|
||||
| minus rule | `[0.47, 0.47, 0.49, 0.46, 0.47, 0.49]` | `[0.46, 0.48, 0.49, 0.48, 0.47, 0.57]` | `[0.47, 0.47, 0.47, 0.47, 0.48, 0.50]` |
|
||||
|
||||
Eight-trial pass, `hw/ip` all-style: reference `[0.58, 0.61, 0.71, 0.62,
|
||||
0.59, 0.62, 0.64, 0.58]`, candidate `[0.48, 0.48, 0.53, 0.46, 0.50, 0.51,
|
||||
0.47, 0.48]`; minus rule reference `[0.50, 0.47, 0.47, 0.46, 0.49, 0.48,
|
||||
0.47, 0.48]`, candidate `[0.50, 0.48, 0.48, 0.47, 0.48, 0.47, 0.46, 0.49]`.
|
||||
`hw/vendor` reference `[0.11, 0.11, 0.12, 0.11, 0.11, 0.11, 0.12, 0.11]`,
|
||||
candidate `[0.08, 0.09, 0.09, 0.09, 0.09, 0.09, 0.09, 0.08]`; `hw/dv`
|
||||
reference `[0.08]×6 + [0.09, 0.08]`, candidate `[0.07, 0.06, 0.06, 0.06,
|
||||
0.06, 0.09, 0.06, 0.07]`. Default-only pass, 12 pairs: reference `[0.42,
|
||||
0.40, 0.41, 0.38, 0.42, 0.41, 0.43, 0.40, 0.40, 0.39, 0.42, 0.52]`,
|
||||
candidate `[0.40, 0.44, 0.42, 0.47, 0.41, 0.41, 0.44, 0.40, 0.45, 0.43,
|
||||
0.46, 0.47]`.
|
||||
- **Reference first / repeat median / range; candidate first / repeat median /
|
||||
range:** three-way pass, means (medians): all-style reference **0.6333**
|
||||
(0.635), trunk control **0.6333** (0.630), candidate **0.4817** (0.480);
|
||||
minus rule 0.4750 / 0.4917 / **0.4767**; default 0.4183 / 0.4450 /
|
||||
**0.4233**, all three medians **0.420**.
|
||||
- **Work counts: reads, parses, analyzed/selected/watched/edited files and
|
||||
bytes:** every file is still read once and linted once — the selected set is
|
||||
unchanged and no file is skipped. What changed is per-file work in the
|
||||
census. All-style over `hw/ip`, before: 1 805 census parses + 1 805 one-file
|
||||
`WorkspaceIndex::build`s (each its own lex, parse, `analyze` and record) +
|
||||
1 805 lint parses. After: 1 805 census parses + **181** analyses built on the
|
||||
census's own tree + 1 805 lint parses — **1 805 lexes, 1 805 parses and
|
||||
1 624 analyses removed**. Default `check` is unchanged in every count
|
||||
(`packages` is false there; `unused-import` is `Severity::Style`).
|
||||
- **Result/status/count/fingerprint comparisons, warnings and refusal checks:**
|
||||
**all five cells' stdout is byte-identical between the reference and the
|
||||
candidate**, diffed as files rather than compared as counts —
|
||||
`hw/ip` default `c2444712e23e…` (445 findings), `hw/ip` all-style
|
||||
`97201de03bca…` (7 751 findings, **17 of them `unused-import`**), `hw/ip`
|
||||
minus rule `58780c3e81b8…` (7 734), `hw/vendor` all-style `1ce51659c4ab…`
|
||||
(1 666), `hw/dv` all-style `d7913e5f5846…` (1 158). The hashes also match
|
||||
what §P0 recorded for the reference. Exit codes 1 (findings) and 2 (the four
|
||||
pre-existing format failures) as before.
|
||||
- **Idle RSS / peak RSS / cache size / guard outcomes:** all-style peak RSS,
|
||||
maximum over the three-way pass's six trials: reference **220.9**, trunk
|
||||
control **219.1**, candidate **202.0 MiB** — **−8.6 %**. Default peak
|
||||
188.7 / 182.2 / **183.7 MiB**; minus rule 191.1 / 185.8 / **189.9 MiB**
|
||||
(both inside the run-to-run spread, which is ±20 MiB on this workload).
|
||||
**Zero guard kills**; every build, every suite and every timed child ran
|
||||
under `tools/guard.sh -m 8 -t 1800`. Corpus `git status --porcelain` was the
|
||||
same three files before the run, after every single invocation (asserted by
|
||||
the probe, which raises otherwise) and at the end.
|
||||
- **Target achieved or missed; paired improvement and variability:** **MET, by
|
||||
a wide margin.** The rule's paired increment `all-style − minus-rule`:
|
||||
reference **158.3 ms**, trunk control **141.7 ms**, candidate **5.0 ms** —
|
||||
**96 % removed** against the same-toolchain control (97 % against the cached
|
||||
reference), where the target was ≥ 50 %. All-style `hw/ip` **0.4817 s**
|
||||
against the ≤ ~0.52 s goal. The eight-trial pass agrees independently:
|
||||
increment 141.3 → **10.0 ms**, all-style 0.6188 → **0.4888 s**. Default time
|
||||
is unchanged (medians identical on all three binaries; the mean spread is
|
||||
the machine — the *trunk* build's default mean is the highest of the three).
|
||||
Peak RSS fell rather than rose. Candidate all-style spread 0.47–0.49 does not
|
||||
overlap the reference's 0.60–0.68.
|
||||
- **Correctness tests and logs:** `cargo fmt --all` clean;
|
||||
`cargo clippy --all-targets` clean, no new `#[allow]`;
|
||||
`cargo test --workspace` **4 262 passed, 0 failed, 44 ignored** (4 250 before,
|
||||
**+12**). The equality pin is
|
||||
`interfaces::package_tests::every_fixture_answers_what_a_text_built_index_answers`:
|
||||
a `#[cfg(test)]` `from_text` reproducing the **pre-P3 body verbatim**
|
||||
(`WorkspaceIndex::build([(path, src)])` and the same three queries), asserted
|
||||
equal over 15 fixtures — no package, one, two, `export *::*`, `export q::*`,
|
||||
a named re-export, a package behind an `` `ifdef``, a package after a module,
|
||||
text that does not lex, a parse error inside a package body, a class in a
|
||||
package, the word `package` in a string, the same in a comment, one name
|
||||
declared twice, and an empty file. Three more pin the parts the equality
|
||||
test cannot see: `only_a_package_item_opens_the_gate` asserts the gate's
|
||||
answer fixture by fixture (so a gate that always opened would fail),
|
||||
`the_unlexable_fixture_does_not_lex` stops that fixture going stale, and
|
||||
`a_name_declared_twice_in_one_file_answers_with_the_first` pins the one
|
||||
surprising pre-existing answer: a duplicate **inside one file** reports the
|
||||
*first* declaration's members, not `None` — the `None` is the *cross-file*
|
||||
rule, applied by `Census::of`'s merge. Six CLI tests drive the real binary
|
||||
end to end (`crates/lucisv/tests/cli.rs`): an unused import reported and a
|
||||
used one not, a default `check` silent about imports, an import of a package
|
||||
outside the run silent, an import of a re-exporting package silent, an
|
||||
import of a package two files declare silent, and a run whose extra files
|
||||
say `package` only in a string and a comment producing the identical finding
|
||||
set.
|
||||
- **Interpretation, remaining bottleneck, tradeoffs, rejected alternatives:**
|
||||
the CLI's package census is no longer a whole-project index build. What
|
||||
remains of the increment is **5.0 ms (1.0 % of all-style)**: the
|
||||
`unused-import` rule body's own `import_usage` on the files that import, and
|
||||
the 181 surviving one-file index builds — now analysis and record only, no
|
||||
lex and no parse. Neither is worth a stage. **The third parse — the lint
|
||||
pass's own, 1 805 of them — is untouched**, and is the next measurable CLI
|
||||
duplicate: the census's parse could be retained and handed to `lint_with`,
|
||||
but that holds 1 805 ASTs of a 39 MB tree alive at once against a current
|
||||
all-style peak of 202 MiB, which is exactly the memory-for-speed trade the
|
||||
plan told this stage to measure before taking. It is not taken here.
|
||||
**Rejected: a textual `contains("package")` gate** — the plan forbids it and
|
||||
the fixtures say why (`$display("package p; endpackage")` and a comment both
|
||||
pass a text search). **Rejected: an additive `vlog_semantic` API** — it was
|
||||
the plan's contingency and turned out unnecessary; `FileFacts::from_analysis`
|
||||
already takes exactly `(path, tree, defines, sem, src, lines, tokens)`.
|
||||
- **Decision:** **retain.** Every output is byte-identical, the target is met
|
||||
at 96 %, memory improved, and the whole change is one gate plus one
|
||||
re-use of a parse the census already paid for.
|
||||
- **QA result and lead review link:** QA pending.
|
||||
|
||||
## Experiment record — copy for every stage or rejected attempt
|
||||
|
||||
- Experiment ID / stage / date / owner:
|
||||
|
||||
+2
-2
@@ -121,7 +121,7 @@ what a change on the pointed-to side must not silently break.
|
||||
| `vlog_formatter ──▶ vlog_parser` | depends | `parse(tokens, source)` / `parse_source`, the whole AST, `tokenize` (re-used by `verify.rs` to re-lex both sides of the safety net), trivia attachment (`Meta::{leading,trailing,before_sep,attrs}` — comments are never dropped), `RawText.col` (the dedent column for verbatim re-indent), spans. The formatter is the AST's primary consumer: **every new `ItemKind`/`StmtKind`/`ExprKind` variant costs an arm in `format/`** (its matches are exhaustive). |
|
||||
| `vlog_semantic ──▶ vlog_parser` | depends | The AST read-only, `parse_source_tolerant`/`parse_tolerant` (never fails; `Error` nodes are opaque leaves), the **name-span contract** `src[name_span] == name` on every declaring node, `token::is_keyword`, `defines::collect_defines`/`DefineTable`, `TextRange`. `bind/`'s `ItemKind`/`ExprKind`/`DimKind` matches are exhaustive — new variants cost an arm here too. |
|
||||
| `vlog_linter ──▶ vlog_parser` | depends | `ParsedSource::parse` = `tokenize` + `parse_tolerant` (one-parse bundle), `LineIndex`, `TextRange`, AST shapes walked by `visit.rs` (which ends in `_ => {}`, so new variants usually cost nothing here), token facts for text rules (a macro use is one `Ident` token; a directive is one `Directive` token). |
|
||||
| `vlog_linter ──▶ vlog_semantic` | depends | `analyze`, `Semantics::{symbols, references, references_of}` and shared `imports::{import_usage, unused_imports, PackageExports}` for semantic rules, including signal usage and duplicate-declaration checks. `Semantics::duplicates()` was added by linter-expansion-1 without changing persisted facts. `LintContext::semantics()` computes analysis lazily when a rule asks for it. Justified in `vlog_linter/Cargo.toml`; adds no external code (`vlog_semantic` is `vlog_parser` + std). |
|
||||
| `vlog_linter ──▶ vlog_semantic` | depends | `analyze`, `Semantics::{symbols, references, references_of}` and shared `imports::{import_usage, unused_imports, PackageExports}` for semantic rules, including signal usage and duplicate-declaration checks. `Semantics::duplicates()` was added by linter-expansion-1 without changing persisted facts. `LintContext::semantics()` computes analysis lazily when a rule asks for it. Justified in `vlog_linter/Cargo.toml`; adds no external code (`vlog_semantic` is `vlog_parser` + std). Also `FileFacts::from_analysis` + `IndexBuilder::{add_facts, finish}` (perf5-p3: the one-file package index built from the caller's parse; `WorkspaceIndex::build` over the text remains what the equality test pins against). |
|
||||
| `vlog_linter ──▶ lucisv_core` | depends | `walk::is_excluded`, the `--exclude` matcher, reused for a waiver file's `--location` so one pattern language serves the whole tool (waiver-files, §39, 2026-09-04). `lucisv_core` still depends on nothing, so no cycle. |
|
||||
| `vlog_linter ──▶ vlog_formatter` **(dev-only)** | depends (tests) | The `.lint` fix harness asserts a lint fix never produces text `format_source` refuses. **The library dependency list is `vlog_parser` + `vlog_semantic` + `lucisv_core` + std** — `cargo tree -p vlog_linter -e normal` is the pinned check. Do not promote this to a normal dep; the fence filter deliberately lives in the front ends instead (see shared-fence-filter, §2.4). |
|
||||
| `vlog_refactor ──▶ vlog_formatter` **(dev-only)** | depends (tests) | expand-wildcard (§50, 2026-09-05): the acceptance tests format and converge what an expansion writes. No production edge. |
|
||||
@@ -133,7 +133,7 @@ what a change on the pointed-to side must not silently break.
|
||||
| `vlog_refactor ──▶ vlog_semantic` | depends | `Semantics` queries (`symbol_at`, `references_of`, `reference_id_at`, …), `Resolution` variants (three of them are refusal rules), `WorkspaceIndex` + `resolve_external` + `ExternalTarget`, and the exactness promise on `name_span` (re-checked before each edit is emitted). One historical exception: refactor-rename added `Target::Declaration` + end-label uses *into* `vlog_semantic` (lead-authorized, additive — see §2.6). `FileFacts::analyzed(path, src) -> (FileFacts, Semantics)` (perf5-p2: the index build hands back the analysis it read the record off; `FileFacts::of` is its `.0`, so the two cannot drift; `Scope` feeds `IndexBuilder::add_facts` and keeps the `Semantics` of the files a rename will read — a cache, never an oracle) and `WorkspaceIndex::absorb` as the after-index of every verifier (`check/after.rs`: the before-index cloned plus the edited files' fresh records; pinned equal to a rebuild by fingerprint and query on adversarial edits). |
|
||||
| `lucisv ──▶ lucisv_core` | depends | `config::{FileConfig, Discovery}` (lucisv.toml discovery — `config::parse` is reached through `Discovery`, not called directly), `walk::{collect_files, EXTENSIONS}` (the `.gitignore`/`--exclude` walk), `filelist::read` (`-f`), `cache` (the format cache), `atomic::write_atomic` (formatter and lint-fix replacement). (`walk::is_excluded` also supplies the linter’s external-waiver location matcher.) |
|
||||
| `lucisv ──▶ vlog_formatter` | depends | `format_source` / `format_range` / `LineRanges` / `Config` / `FormatError`, and `fence::{protected_regions, is_protected}` (the `--fix` fence filter — the linter crate deliberately has no fence notion). |
|
||||
| `lucisv ──▶ vlog_linter` | depends | The public linter API for `lucisv check` — `lint` + `LintContext`/`ParsedSource`, `apply_fixes`, `select_rules` (the CLI does not call `run` itself). Relies on: rule names stable, linting never panics/writes, findings sorted by `(span.start, span.end, rule)`. |
|
||||
| `lucisv ──▶ vlog_linter` | depends | The public linter API for `lucisv check` — `lint` + `LintContext`/`ParsedSource`, `apply_fixes`, `select_rules` (the CLI does not call `run` itself). Relies on: rule names stable, linting never panics/writes, findings sorted by `(span.start, span.end, rule)`. `package_exports_in(path, file, tokens, src)` (perf5-p3: the CLI census hands the linter its one `ParsedSource` for the package half as it already did for `module_interfaces`; the text form is a wrapper; an AST gate spares files that declare no package from the one-file index). |
|
||||
| `lucisv ──▶ vlog_parser` | depends | `LineIndex` / `TextRange` for lint report coordinates, plus `PARSE_STACK_SIZE` for both the named `lucisv` thread and rayon workers. (The CLI otherwise reaches the parser through the formatter and linter.) |
|
||||
| `lucisv ──▶ rayon` | depends | The worker pool. Pinned exactly; pool must keep `stack_size(vlog_parser::PARSE_STACK_SIZE)` (currently 16 MiB; recursion-limit handshake) or the parser's depth guarantee regresses to a stack overflow. |
|
||||
| `lucisv_server ──▶ lucisv_core` | depends | Same config discovery and walk as the CLI (that sameness is the point — format-on-save must agree with `lucisv --check`), `filelist::read` (index scope rung 1, `+incdir+` for the include graph), `cache::content_hash` (re-used by the persistent index cache — one FNV-1a, not two). |
|
||||
|
||||
Reference in new issue
Block a user