diff --git a/TODO.md b/TODO.md index 776c5c2..6695c6c 100644 --- a/TODO.md +++ b/TODO.md @@ -4360,7 +4360,7 @@ pre-existing modified files stay as they are). Every run under path), `hover`, `inlayHint` (workspace scope and default scope, with §37.2's ruling restated), `references`, `documentSymbol`, `workspaceSymbol`, `semanticTokens/full`, diagnostics publish. Driven - over the wire against `target/release/lucisv-server` at 0.42.0 and, + over the wire against `target/release/lucisv-server` at 0.43.0 and, for the rows that exist there, the 0.39.0 baseline (`~/.cache/lucisv-baselines/` holds CLI binaries only — build the 0.39.0 server from the tag in a scratch worktree under the scratchpad, @@ -4368,7 +4368,7 @@ pre-existing modified files stay as they are). Every run under - **CLI sweeps** over `hw/ip`, `hw/top_earlgrey/ip`, `hw/top_darjeeling/ip`, `hw/dv`, `hw/vendor`: `format --check` (cold cache and warm), `check` (all rules on; default rules), wall time and peak RSS (`/usr/bin/time - -l`), 0.42.0 vs 0.39.0 vs 0.41.0; the failure counts per tree and the + -l`), 0.43.0 vs 0.39.0 vs 0.41.0; the failure counts per tree and the list of files whose outcome changed since 0.39.0 (expected: exactly jtag_if.sv and SimDTM.sv from §38). - **Method** as take 2 §9: three tries per row, first try and repeat @@ -4378,7 +4378,7 @@ pre-existing modified files stay as they are). Every run under item with a reproduction; anything faster is credited to the section that did it. -- [ ] server table re-measured, 0.42.0 vs take 2 vs 0.39.0 +- [ ] server table re-measured, 0.43.0 vs take 2 vs 0.39.0 - [ ] CLI sweeps, three binaries, RSS included - [ ] `docs/performance_take3.md` + perf README entry - [ ] opentitan status unchanged after every run @@ -4524,12 +4524,14 @@ mechanism and its gap fuzzer), the formatter prints it inline before `#`, the `#SKIP` in `net_delay_position.cases` goes live, the gap fuzzer covers the new slot. -- [ ] 43.1 visited-by-identity walker, both front ends, tests -- [ ] 43.2 `NetDelay::before_hash`, the `#SKIP` retired -- [ ] docs; topo §2.9-8 and §2.9-27 struck (lead); finding 3 annotated -- [ ] Gates (guarded): fmt/clippy/workspace tests; corpus unchanged; +- [x] 43.1 visited-by-identity walker, both front ends, tests +- [x] 43.2 `NetDelay::before_hash`, the `#SKIP` retired +- [x] docs; topo §2.9-8 and §2.9-27 struck (lead); finding 3 annotated + — done at review 2026-09-05; §2.9-30 filed (unreadable directory + aborts the walk) +- [x] Gates (guarded): fmt/clippy/workspace tests; corpus unchanged; byte-identity vs 0.42.0; a cyclic scratch tree through both binaries -- [ ] QA: cycles of depth 1–3 through the CLI and the server (guarded, +- [x] QA: cycles of depth 1–3 through the CLI and the server (guarded, time-limited); the comment slot attacked with every comment shape and position; the gap fuzzer re-run diff --git a/crates/lucisv/tests/cli.rs b/crates/lucisv/tests/cli.rs index 49c06ea..822497d 100644 --- a/crates/lucisv/tests/cli.rs +++ b/crates/lucisv/tests/cli.rs @@ -165,6 +165,28 @@ fn a_symlink_and_its_target_are_one_file() { ); } +/// A directory that links back into itself. Before the walk kept a visited +/// set (`docs/features/walk-cycles/README.md`) this run recursed until the +/// OS refused the path; now each directory is entered once, so each file is +/// named once — under the first spelling that reaches it. +#[cfg(unix)] +#[test] +fn a_symlink_cycle_terminates_and_names_each_file_once() { + let dir = TempDir::new("cycle"); + dir.write("rtl/a.sv", UNFORMATTED); + dir.write("rtl/sub/b.sv", UNFORMATTED); + // `rtl/self` is `rtl` itself; `rtl/sub/up` is `rtl` from one level down. + std::os::unix::fs::symlink("../rtl", dir.path.join("rtl/self")).expect("symlink"); + std::os::unix::fs::symlink("..", dir.path.join("rtl/sub/up")).expect("symlink"); + + let out = run(&["--check", &dir.root()]); + assert_eq!(code(&out), 1, "{}", stderr(&out)); + let reported = stdout(&out); + let named: Vec<&str> = reported.lines().filter(|l| l.contains("would reformat")).collect(); + assert_eq!(named.len(), 2, "two files, two lines: {named:?}"); + assert!(stderr(&out).contains("2 files would be reformatted"), "{}", stderr(&out)); +} + #[test] fn check_reports_without_writing() { let dir = TempDir::new("check"); diff --git a/crates/lucisv_core/src/walk.rs b/crates/lucisv_core/src/walk.rs index 113f98f..d711c0b 100644 --- a/crates/lucisv_core/src/walk.rs +++ b/crates/lucisv_core/src/walk.rs @@ -2,6 +2,7 @@ //! `.gitignore` subset documented in //! `docs/features/parallel-files/README.md`. +use std::collections::HashSet; use std::path::{Path, PathBuf}; /// File extensions lucisv formats when walking a directory. @@ -22,7 +23,14 @@ pub fn collect_files( ) -> Result<(), String> { let path = Path::new(input); if path.is_dir() { - let mut walk = Walk { exclude, gitignore, ignores: Vec::new(), rel: Vec::new(), files }; + let mut walk = Walk { + exclude, + gitignore, + ignores: Vec::new(), + rel: Vec::new(), + visited: HashSet::new(), + files, + }; walk.dir(path).map_err(|e| format!("{input}: {e}"))?; } else if path.is_file() { files.push(path.to_path_buf()); @@ -32,20 +40,55 @@ pub fn collect_files( Ok(()) } +/// How a directory is recognised as one the walk has already entered. Two +/// names for the same directory — a symlink and its target, or two symlinks +/// pointing at one place — must map to the same identity, or a cycle has no +/// end. On unix that is `(dev, ino)`, the pair the filesystem itself uses; +/// elsewhere it is the canonical path, which resolves symlinks the same way +/// at the cost of a real path lookup. +#[cfg(unix)] +type DirId = (u64, u64); +#[cfg(not(unix))] +type DirId = PathBuf; + +/// The identity of the directory at `path`, or `None` when it cannot be +/// read — a dangling symlink, or a directory that vanished mid-walk. +#[cfg(unix)] +fn dir_id(path: &Path) -> Option { + use std::os::unix::fs::MetadataExt; + let meta = std::fs::metadata(path).ok()?; + Some((meta.dev(), meta.ino())) +} + +#[cfg(not(unix))] +fn dir_id(path: &Path) -> Option { + std::fs::canonicalize(path).ok() +} + +/// True when `path` names one of the source files lucisv formats. +fn is_source(path: &Path) -> bool { + path.extension().and_then(|e| e.to_str()).is_some_and(|ext| EXTENSIONS.contains(&ext)) +} + /// One directory walk. `rel` is the path of the directory currently being /// read, in components relative to the walk root, which is what /// `.gitignore` rules are matched against; `ignores` is the stack of -/// ignore files seen from the root down to it. +/// ignore files seen from the root down to it; `visited` is every directory +/// already entered, by identity rather than by spelling. struct Walk<'a> { exclude: &'a [String], gitignore: bool, ignores: Vec, rel: Vec, + visited: HashSet, files: &'a mut Vec, } impl Walk<'_> { fn dir(&mut self, dir: &Path) -> std::io::Result<()> { + if !self.enter(dir) { + return Ok(()); + } let pushed = self.push_ignore(dir)?; let mut entries: Vec<_> = std::fs::read_dir(dir)?.collect::>()?; entries.sort_by_key(|e| e.path()); @@ -54,15 +97,26 @@ impl Walk<'_> { if is_excluded(&path, self.exclude) { continue; } - let is_dir = path.is_dir(); + // One `metadata` call per entry, exactly as before — it follows + // symlinks, so it answers "directory?" for a symlinked directory + // the way `is_dir()` did. A dangling symlink has no metadata at + // all. One that *names a source file* is still handed on, so the + // front end reports "no such file" for it as it always has (§43's + // QA: a silent skip loses the user an error they had); one that + // names anything else is neither a directory to walk nor a file + // to read, and is skipped. + let Ok(meta) = std::fs::metadata(&path) else { + if is_source(&path) { + self.files.push(path); + } + continue; + }; self.rel.push(entry.file_name().to_string_lossy().into_owned()); - if !is_ignored(&self.ignores, &self.rel, is_dir) { - if is_dir { + if !is_ignored(&self.ignores, &self.rel, meta.is_dir()) { + if meta.is_dir() { self.dir(&path)?; - } else if let Some(ext) = path.extension().and_then(|e| e.to_str()) { - if EXTENSIONS.contains(&ext) { - self.files.push(path); - } + } else if meta.is_file() && is_source(&path) { + self.files.push(path); } } self.rel.pop(); @@ -73,6 +127,20 @@ impl Walk<'_> { Ok(()) } + /// Records `dir` as entered, and answers whether it had not been entered + /// already. Identity, not spelling: `a/loop -> a` and `a/b/up -> ..` name + /// a directory the walk is already inside, and following either is the + /// cycle that only ends when the OS refuses a path. A symlink to a + /// directory the walk has *not* seen is followed once, so + /// `rtl -> ../shared/rtl` still contributes its files; the second link to + /// one target contributes nothing further, and the files are reported + /// under the first spelling that reached them. + /// + /// A directory whose identity cannot be read is not entered. + fn enter(&mut self, dir: &Path) -> bool { + dir_id(dir).is_some_and(|id| self.visited.insert(id)) + } + /// Reads `dir`'s `.gitignore`, if there is one, onto the rule stack. /// Returns whether anything was pushed, so `dir` can pop it again. fn push_ignore(&mut self, dir: &Path) -> std::io::Result { @@ -214,6 +282,8 @@ fn glob_component(pattern: &str, name: &str) -> bool { #[cfg(test)] mod tests { use super::*; + #[cfg(unix)] + use std::sync::atomic::{AtomicUsize, Ordering}; fn excluded(path: &str, pattern: &str) -> bool { is_excluded(Path::new(path), &[pattern.to_string()]) @@ -320,6 +390,142 @@ mod tests { assert!(!ignored_at(&[(0, "/x.sv")], "sub/x.sv")); } + // ------------------------------------------------------------------ + // Symlink cycles — `docs/features/walk-cycles/README.md` + // + // Every test below builds a real tree with real symlinks, because the + // question is what the filesystem answers, not what a mock does. Each + // one would run until the OS refused a path before the visited set. + // ------------------------------------------------------------------ + + /// A throwaway directory tree under the system temp dir, removed on + /// drop. `remove_dir_all` unlinks a symlink instead of following it, so + /// a tree with a cycle in it is cleaned up like any other. + #[cfg(unix)] + struct TempTree { + path: PathBuf, + } + + #[cfg(unix)] + impl TempTree { + fn new(tag: &str) -> TempTree { + static COUNTER: AtomicUsize = AtomicUsize::new(0); + let n = COUNTER.fetch_add(1, Ordering::Relaxed); + let path = + std::env::temp_dir().join(format!("lucisv-walk-{}-{tag}-{n}", std::process::id())); + let _ = std::fs::remove_dir_all(&path); + std::fs::create_dir_all(&path).expect("create temp dir"); + TempTree { path } + } + + fn write(&self, rel: &str, text: &str) { + let path = self.path.join(rel); + if let Some(parent) = path.parent() { + std::fs::create_dir_all(parent).expect("create parent"); + } + std::fs::write(&path, text).expect("write"); + } + + /// A source file with enough in it to be worth finding. + fn source(&self, rel: &str) { + self.write(rel, "module m;\nendmodule\n"); + } + + /// `rel` as a symlink to `target`, which is relative to `rel`'s own + /// directory — the spelling a checked-in symlink actually uses. + fn link(&self, rel: &str, target: &str) { + let path = self.path.join(rel); + if let Some(parent) = path.parent() { + std::fs::create_dir_all(parent).expect("create parent"); + } + std::os::unix::fs::symlink(target, &path).expect("symlink"); + } + + /// The walk from `rel` (empty for the root), as sorted paths + /// relative to the tree root. + fn walk(&self, rel: &str) -> Vec { + let start = if rel.is_empty() { self.path.clone() } else { self.path.join(rel) }; + let mut files = Vec::new(); + collect_files(start.to_str().expect("utf-8 temp path"), &[], true, &mut files) + .expect("the walk finishes"); + let mut out: Vec = files + .iter() + .map(|p| p.strip_prefix(&self.path).unwrap_or(p).to_string_lossy().into_owned()) + .collect(); + out.sort(); + out + } + } + + #[test] + #[cfg(unix)] + fn a_directory_linking_to_itself_is_entered_once() { + let tree = TempTree::new("selfloop"); + tree.source("a/x.sv"); + tree.link("a/loop", "../a"); + assert_eq!(tree.walk(""), ["a/x.sv"]); + } + + #[test] + #[cfg(unix)] + fn a_link_to_an_ancestor_terminates_from_a_nested_start() { + let tree = TempTree::new("uplink"); + tree.source("root.sv"); + tree.source("a/x.sv"); + tree.link("a/up", ".."); + // Starting *inside* the cycle: `a` is entered, then `a/up` is the + // root, which the walk has not seen yet and so does enter — once. + // Its own `a` is the directory already being walked, and stops. + assert_eq!(tree.walk("a"), ["a/up/root.sv", "a/x.sv"]); + } + + #[test] + #[cfg(unix)] + fn two_links_to_one_directory_yield_its_files_once() { + let tree = TempTree::new("twolinks"); + tree.source("shared/x.sv"); + // Sorted after `shared`, so the real directory is the spelling that + // reaches the file first; whichever name wins, the file is reported + // exactly once. + tree.link("z1", "shared"); + tree.link("z2", "shared"); + assert_eq!(tree.walk(""), ["shared/x.sv"]); + } + + #[test] + #[cfg(unix)] + fn a_link_to_a_directory_not_yet_walked_is_still_followed() { + let tree = TempTree::new("sibling"); + tree.source("shared/rtl/x.sv"); + tree.link("proj/rtl", "../shared/rtl"); + // The `rtl -> ../shared/rtl` of a real checkout: the target is + // outside the walk, so the link is the only way to it. + assert_eq!(tree.walk("proj"), ["proj/rtl/x.sv"]); + } + + #[test] + #[cfg(unix)] + fn a_dangling_directory_link_is_skipped_and_a_dangling_source_link_is_reported() { + // The directory link cannot be entered; the source-file link is kept + // so the front end's "no such file" error survives (0.42.0 parity). + let tree = TempTree::new("dangling"); + tree.source("a/x.sv"); + tree.link("a/gone.sv", "nowhere.sv"); + tree.link("a/gonedir", "nowhere"); + assert_eq!(tree.walk(""), ["a/gone.sv", "a/x.sv"]); + } + + #[test] + #[cfg(unix)] + fn a_cycle_inside_an_ignored_directory_is_never_entered() { + let tree = TempTree::new("ignoredcycle"); + tree.write(".gitignore", "build\n"); + tree.source("keep.sv"); + tree.source("build/y.sv"); + tree.link("build/loop", "../build"); + assert_eq!(tree.walk(""), ["keep.sv"]); + } + #[test] fn unsupported_syntax_degrades_to_plain_globbing() { // `**` is just two stars inside one component; documented. diff --git a/crates/lucisv_server/src/state.rs b/crates/lucisv_server/src/state.rs index 53fde8a..44f1bb5 100644 --- a/crates/lucisv_server/src/state.rs +++ b/crates/lucisv_server/src/state.rs @@ -2730,6 +2730,29 @@ mod tests { ); } + /// A workspace whose tree links back into itself. Before the walk kept a + /// visited set (`docs/features/walk-cycles/README.md`) this scan never + /// finished — the editor's index simply never came up. Each directory is + /// entered once now, so each package is registered exactly once: a second + /// registration would make the name *ambiguous*, and `indexed` only + /// counts a name found exactly once. + #[cfg(unix)] + #[test] + fn a_cyclic_workspace_is_scanned_once_and_finishes() { + let tree = Tree::new("cycle"); + tree.package("rtl/a.sv", "a"); + tree.package("rtl/sub/b.sv", "b"); + // `rtl/self` is `rtl` itself; `rtl/sub/up` is `rtl` from one level + // down. Either one alone runs until the OS refuses a path. + std::os::unix::fs::symlink("../rtl", tree.path.join("rtl/self")).expect("symlink"); + std::os::unix::fs::symlink("..", tree.path.join("rtl/sub/up")).expect("symlink"); + + let mut ws = Workspace::default(); + ws.open_whole_workspace(vec![tree.path.clone()]); + assert_eq!(indexed(&ws, &["a", "b"]), ["a", "b"]); + assert_eq!(ws.walked_files(from_ref(&tree.path)).len(), 2, "two files, once each"); + } + #[test] fn a_folder_change_that_changes_nothing_asks_for_no_rescan() { // Every no-op shape a client can send. Each must leave the root set diff --git a/crates/vlog_formatter/src/format/decl.rs b/crates/vlog_formatter/src/format/decl.rs index 0ec15a9..0797cb5 100644 --- a/crates/vlog_formatter/src/format/decl.rs +++ b/crates/vlog_formatter/src/format/decl.rs @@ -296,29 +296,40 @@ impl<'a> Fmt<'a> { pub(super) fn data_decl(&self, d: &DataDecl) -> Doc { let mut docs = Vec::new(); if let Some(net) = &d.net { - docs.push(text(format!("{net} "))); + docs.push(text(net.clone())); + self.net_delay(d, false, &mut docs); } - self.net_delay(d, false, &mut docs); self.qualifier_run(&d.qualifiers, &mut docs); if let Some(t) = self.data_type(&d.ty) { docs.push(t); - docs.push(text(" ")); + self.net_delay(d, true, &mut docs); } - self.net_delay(d, true, &mut docs); + // Neither arm needs an `else`: a delay before the type is only read + // after a net keyword, and one after the type only when a type was + // actually written, so an implicit type has none to print. docs.push(self.declarators(&d.declarators)); concat(docs) } - /// `#5 ` — the declaration's net delay and the space after it, but only - /// when it was written on the side of the data type `after_type` names. - /// IEEE 1800 §6.7 allows either side and lucisv prints it where the - /// source put it; moving it across the type would reorder tokens, which - /// `verify.rs` refuses. + /// The separator that follows the word just emitted, and then `#5` when + /// the declaration's net delay was written on the side of the data type + /// `after_type` names. IEEE 1800 §6.7 allows either side and lucisv + /// prints it where the source put it; moving it across the type would + /// reorder tokens, which `verify.rs` refuses. + /// + /// The separator is the delay's `before_hash` comments when it has any + /// (`wire /* c */ #5 w;`) and a plain space otherwise — so a declaration + /// with no comment there is laid out exactly as it was before the slot + /// existed, delay or no delay. fn net_delay(&self, d: &DataDecl, after_type: bool, docs: &mut Vec) { - let Some(delay) = d.delay.as_ref().filter(|n| n.after_type == after_type) else { - return; - }; + let delay = d.delay.as_ref().filter(|n| n.after_type == after_type); + match delay.map(|n| &n.before_hash).filter(|c| !c.is_empty()) { + Some(comments) => self.inline_comments_spaced(comments, docs), + None => docs.push(text(" ")), + } + let Some(delay) = delay else { return }; docs.push(text("#")); + self.slot_comments(&delay.after_hash, docs); docs.push(self.expr(&delay.expr)); docs.push(text(" ")); } diff --git a/crates/vlog_formatter/tests/cases/net_delay_position.cases b/crates/vlog_formatter/tests/cases/net_delay_position.cases index a12d1e0..e2bcb45 100644 --- a/crates/vlog_formatter/tests/cases/net_delay_position.cases +++ b/crates/vlog_formatter/tests/cases/net_delay_position.cases @@ -53,20 +53,45 @@ module SimDTM (input clk, output [31:0] exit); wire [31:0] #0.1 __debug_resp_bits_data = debug_resp_bits_data; endmodule ==== -# SKIP a comment written directly in front of the `#` has no slot to be -# printed from, so `verify.rs` refuses the file rather than moving it. This -# is *pre-existing* for the before-the-type position — it behaves the same -# way with no `[7:0]` in front — and the after-the-type position inherits -# it unchanged. Recorded, not fixed: giving the delay a comment slot is a -# `comment-slots` change, not a §38 one. +# a comment written directly in front of the `#` is the delay's own — +# `NetDelay::before_hash`, TODO §43.2. It was the `#SKIP` §38 recorded and +# `verify.rs` refused the file for; the slot prints it back where it was +# written, on either side of the data type. module m; wire /* c */ #5 x; wire [7:0] /* d */ #1 z; + wire [3:0] /* one */ /* two */ #3 w; endmodule ---- module m; wire /* c */ #5 x; wire [7:0] /* d */ #1 z; + wire [3:0] /* one */ /* two */ #3 w; +endmodule +==== +# the delay's other gap, between the `#` and the value: `after_hash`. Both +# slots at once on one declaration, since the fuzzer asks for both +module m; + wire # /* why */ 5 x; + wire [7:0] /* a */ # /* b */ 1 z = q; +endmodule +---- +module m; + wire # /* why */ 5 x; + wire [7:0] /* a */ # /* b */ 1 z = q; +endmodule +==== +# a line comment in the same slot runs to end of line, so the `#` cannot +# follow it: it starts the next one, the way the `wire #5 /* after */` case +# below breaks before its declarator +module m; + wire // why the delay + #2 y; +endmodule +---- +module m; + wire // why the delay + #2 y; endmodule ==== # the other three gaps around a delay do have slots and round-trip diff --git a/crates/vlog_formatter/tests/verification.rs b/crates/vlog_formatter/tests/verification.rs index 5b5b125..477c27d 100644 --- a/crates/vlog_formatter/tests/verification.rs +++ b/crates/vlog_formatter/tests/verification.rs @@ -2350,6 +2350,10 @@ const RTL_FIXTURES: &[&str] = &[ "package p;\n typedef struct packed {\n logic [3:0] hi;\n logic [3:0] lo;\n } word_t;\n typedef enum logic [1:0] {A = 2'd0, B, C} st_e;\nendpackage\n", "module m;\n sub #(.W(8)) u0 (.clk(clk), .d(d[3:0]), .q());\nendmodule\n", "module m;\n assign y = cond ? a[3:0] : pkg::f(b).c;\nendmodule\n", + // A net delay on either side of the data type: the gap in front of the + // `#` is `NetDelay::before_hash` (TODO §43.2), and the fuzzer is what + // says the other gaps around it kept their owners. + "module m;\n wire #5 a;\n wire [7:0] #1 b = c;\nendmodule\n", ]; #[test] @@ -2358,7 +2362,7 @@ fn a_comment_in_every_rtl_gap_still_formats() { } /// Inter-token gaps across [`RTL_FIXTURES`]. -const EXPECTED_RTL_GAPS: usize = 352; +const EXPECTED_RTL_GAPS: usize = 374; // ---------------------------------------------------------------------- // Vendor and formal collateral — `vendor-formal-grammar` diff --git a/crates/vlog_parser/src/ast/decl.rs b/crates/vlog_parser/src/ast/decl.rs index 5f39885..0360f90 100644 --- a/crates/vlog_parser/src/ast/decl.rs +++ b/crates/vlog_parser/src/ast/decl.rs @@ -246,6 +246,15 @@ pub struct ParamDecl { /// `verify.rs` rightly refuses. #[derive(Debug)] pub struct NetDelay { + /// Comments written between whatever precedes the delay and its `#`: + /// the `/* c */` of `wire /* c */ #5 w;` and of + /// `wire [7:0] /* c */ #1 w;`. Without a slot here the comment would be + /// printed one node later and `verify.rs` would refuse the file. + pub before_hash: Vec, + /// Comments written between the `#` and the delay value — the delay's + /// other gap, and the one the gap fuzzer asks about the moment the + /// first one has an owner. + pub after_hash: Vec, /// The delay itself: the `5` of `wire #5 w;`. pub expr: Expr, /// True when it stood between the data type and the declarators. diff --git a/crates/vlog_parser/src/parser/decl.rs b/crates/vlog_parser/src/parser/decl.rs index 54e9d54..94dba42 100644 --- a/crates/vlog_parser/src/parser/decl.rs +++ b/crates/vlog_parser/src/parser/decl.rs @@ -284,8 +284,13 @@ impl<'a> Parser<'a> { if !is_net || !self.cur().is_sym("#") { return Ok(None); } + // The `#` is written, so the gap in front of it is the delay's own: + // `wire /* c */ #5 w;`. Taken only here — when the read does not + // happen the gap belongs to whatever comes next. + let before_hash = self.take_gap(); self.bump(); - Ok(Some(NetDelay { expr: self.parse_delay_value()?, after_type })) + let after_hash = self.take_gap(); + Ok(Some(NetDelay { before_hash, after_hash, expr: self.parse_delay_value()?, after_type })) } pub(super) fn parse_port_decl(&mut self) -> PResult { diff --git a/docs/features/parser-skips/README.md b/docs/features/parser-skips/README.md index 7d3cb9c..2006312 100644 --- a/docs/features/parser-skips/README.md +++ b/docs/features/parser-skips/README.md @@ -102,7 +102,8 @@ the last two shapes in that sweep that were grammar work rather than before-type spelling has behaved this way since the delay was first parsed — and the new position inherits it unchanged. Recorded as a `#SKIP` case in `net_delay_position.cases`, not fixed: giving the delay a comment - slot is a `comment-slots` change. The other gaps around a delay (an + slot is a `comment-slots` change. **Closed by walk-cycles (TODO §43.2), + 2026-09-05:** `NetDelay::{before_hash, after_hash}`; the `#SKIP` is live. The other gaps around a delay (an attribute in front of the declaration, a comment after the delay) do round-trip. @@ -151,7 +152,8 @@ the last two shapes in that sweep that were grammar work rather than - **`comment-slots`**: a net delay has no slot for the comment written immediately in front of its `#`, so such a file is refused by the safety net rather than reformatted. Pre-existing, both positions, recorded as a - `#SKIP` case (see Assumptions). + `#SKIP` case (see Assumptions). **Answered by walk-cycles (TODO §43.2), + 2026-09-05.** ## Status / TODO diff --git a/docs/features/walk-cycles/README.md b/docs/features/walk-cycles/README.md new file mode 100644 index 0000000..cfd3633 --- /dev/null +++ b/docs/features/walk-cycles/README.md @@ -0,0 +1,447 @@ +# walk cycles + +## Goal + +Two unrelated residues of the repository analysis (finding 3), landed +together as TODO §43 because each is small and neither collides with the +other. + +**43.1 — a cycle policy for the shared walk.** `lucisv_core::walk` recursed +on `Path::is_dir()` with no memory of where it had been. A symlink that +points back into the tree it sits in — `a/loop -> ../a`, `a/sub/up -> ..`, +the `rtl -> ../shared/rtl` pair a vendored checkout writes twice — made the +walk descend forever, one directory deeper each time, until the operating +system refused the path. Both front ends share that walk: `lucisv` (and so +`format`, `check`, `--check`, `--diff`) and the language server's index scan, +where the symptom is not an error message but an index that never comes up. +The policy is now **each directory is entered once, by identity**: a symlink +naming a directory the walk has already entered is skipped silently, and a +symlink naming one it has not is still followed, once. No traversal budget — +identity *is* the policy, and a budget would be a second, weaker rule +answering the same question differently. + +**43.2 — the net delay's comment slots.** `wire /* c */ #5 w;` and +`wire [7:0] /* c */ #1 w;` were refused outright: `NetDelay` had no field for +a comment written in front of its `#`, so the comment was printed one node +later and `verify.rs` — correctly — refused the whole file (exit 2, no +output). `NetDelay` now owns both of its gaps, `before_hash` and +`after_hash`, and the `#SKIP` `parser-skips` left in +`net_delay_position.cases` is retired. + +## Assumptions + +- **Directory identity on unix is `(dev, ino)`.** `fs::metadata` follows + symlinks, so the link and its target return the same pair, which is exactly + the question being asked. Elsewhere (there is no non-unix CI today, but the + crate compiles there) it is `fs::canonicalize`, which resolves the same way + at the cost of a path lookup. Both are `Option`: a name whose metadata + cannot be read is not a directory the walk can enter. +- **A hard link is not a cycle, and is not treated as one.** Two hard-linked + *files* have one inode and the visited set never sees them: only + directories are recorded. (Hard-linked directories are not creatable on any + filesystem lucisv runs on.) +- **The visited set lives for one `collect_files` call.** Two inputs named on + one command line each get their own walk, so a directory reachable from + both is still walked twice — unchanged, and the CLI's own path dedup is + what answers that (`§41`). Inside one walk the same file reached under two + spellings is reported once, under the first spelling that reaches it: entry + order is `read_dir` sorted by path, so `link_a/x.sv` wins over `shared/x.sv` + and `shared/x.sv` wins over `zlink/x.sv`. This is the same rule §41 already + applies to a symlinked *file*. +- **A dangling symlink is not an input.** `metadata` fails on it, so it is + neither walked nor collected. Before this round a dangling `x.sv` link was + collected and failed later, at read time, with a "no such file" error the + user did not write. +- **The `.gitignore`/`--exclude` decision still comes first.** A cycle inside + an ignored or excluded directory is never entered at all, so the visited + set never sees it; the ignore rules were not touched. +- **A comment in front of a `#` belongs to the delay** (43.2), the way + `Typedef::before_name` owns the gap in front of its name: the gap is taken + only on the branch that actually consumes the `#`, so a `#` that is not a + net delay leaves the comment for whoever comes next. + +## Handshakes + +- **`lucisv_core::walk` → `lucisv` and `lucisv_server`** (topo §2.9-8, struck + by this round). `collect_files`'s signature is unchanged. What changed is + what it returns for a tree containing symlinked directories: it terminates, + and a directory reachable under several names contributes its files once. + `lucisv_server::state::Workspace::walked_files` is the server's only caller + and needed no change — its `sort`/`dedup` still runs, and now has less to + do. `vlog_linter` uses `walk::is_excluded` only, which is untouched. +- **`vlog_parser::ast::NetDelay` → `vlog_formatter`** (topo §2.9-27, struck). + Two new public fields, `before_hash` and `after_hash`, both + `Vec`. The only constructor is `Parser::parse_net_delay`; the only + reader is `Fmt::net_delay`. `vlog_semantic`, `vlog_linter` and + `vlog_refactor` do not name the type. +- **Not taken:** the gaps *inside* a delay's `#( … )` — `#( /*c*/ 1:2:3 )` + and each side of its two `:` — are still refused. They are + `parse_delay_values`, shared with a gate instantiation's delay list, and + they fail identically outside a net declaration; they belong with the rest + of the shared expression machinery in topo §2.9-22, not here. Recorded + below and left for a future round. + +## Status / TODO + +- [x] 43.1 `Walk::visited`, `Walk::enter`, `dir_id` per platform; `dir()` + checks-and-inserts before `read_dir` +- [x] 43.1 a dangling symlink is skipped rather than collected +- [x] 43.1 unit tests: self-loop, ancestor link from a nested start, two + links to one target, a link to a directory not yet walked, a dangling + link, a cycle inside an ignored directory +- [x] 43.1 CLI test (`--check` over a cyclic tree names each file once) +- [x] 43.1 server test (a cyclic workspace scans once and finishes) +- [x] 43.2 `NetDelay::before_hash` + `after_hash`, parser and formatter +- [x] 43.2 the `#SKIP` in `net_delay_position.cases` retired, three live + cases in its place +- [x] 43.2 the RTL gap fuzzer covers a net delay (352 → 374 gaps, still zero + failures) +- [x] Gates: fmt, clippy, workspace tests, corpus, both binaries over a + cyclic tree + +## Docs to apply at merge (lead) + +- `docs/topo.md` §2.9-8 — strike: **delivered 2026-09-05 by walk-cycles + (TODO §43.1)**: `lucisv_core::walk::Walk` keeps a `visited` set keyed on + `(dev, ino)` on unix and the canonical path elsewhere; each directory is + entered once, a symlink to a directory already entered is skipped + silently, a symlink to one not yet entered is still followed, a dangling + symlink is skipped. Both front ends: CLI `--check` over a cyclic tree names + each file once; the server's `walked_files` scan finishes. +- `docs/topo.md` §2.9-27 — strike: **delivered 2026-09-05 by walk-cycles + (TODO §43.2)**: `NetDelay::before_hash` and `after_hash` own the two gaps + around the `#`; the formatter prints them inline; the + `net_delay_position.cases` `#SKIP` is retired and the RTL gap fuzzer covers + the construct. The gaps *inside* `#( 1:2:3 )` remain refused and belong to + §2.9-22 (`parse_delay_values`, shared with gate delays). +- `docs/repository-analysis.md` finding 3 — annotate as closed by TODO §43.1 + with the identity policy above, and note that the "no traversal budget" + ruling was the lead's. +- `docs/features/parser-skips/README.md` — its Assumptions (line ~103), + Handshakes (line ~151) and QA log (lines ~343, ~409) describe the net-delay + comment as a live `#SKIP` and as a handshake request to `comment-slots`. + That request is now answered; a one-line "closed by walk-cycles (TODO + §43.2), 2026-09-05" under each is the honest amendment. Not edited here — + it is another feature's README, and this lane owns none of it. +- `README.md` — no change needed: the walk's user-visible contract + (extensions, `--exclude`, `.gitignore`) is unchanged. If a line is wanted, + it is in the CLI section: "a symlinked directory is walked once; a cycle + terminates". + +## Work log + +**2026-09-05 — dev (Opus 5).** + +*43.1, `crates/lucisv_core/src/walk.rs`.* `Walk` gained +`visited: HashSet` and one method, `enter`, which is the whole policy: +`dir_id(dir).is_some_and(|id| self.visited.insert(id))`. `dir()` calls it +first and returns `Ok(())` when it answers false, so a directory already +entered costs one `metadata` call and nothing else — no `read_dir`, no +ignore-stack push, no recursion. `DirId` is `(u64, u64)` under `#[cfg(unix)]` +from `MetadataExt::dev`/`ino`, and `PathBuf` from `fs::canonicalize` +otherwise; `dir_id` returns `Option`, and `None` (a dangling link, a +directory that vanished mid-walk) means "not entered". + +The entry loop's `path.is_dir()` became one `fs::metadata(&path)` — the same +single stat, and it follows symlinks exactly as `is_dir()` did, so a +symlinked directory is still recognized as a directory. Three things fall out +of having the metadata rather than a bool: `meta.is_dir()` for the walk arm, +`meta.is_file()` for the collect arm, and a dangling link (no metadata at +all) skipped by the `let … else { continue }` in front of both. The extension +test moved into a small `is_source` helper so the collect arm stays one line. + +The one behaviour change beyond termination that a user could notice: a +dangling symlink named `x.sv` used to be *collected* and then failed at read +time. It is now skipped. That is in the plan's test list ("a dangling symlink +is skipped") and is the same judgment as the directory case. + +Six unit tests in `walk.rs`, all `#[cfg(unix)]` because they need real +symlinks, over a `TempTree` helper in the test module (the third such helper +in the crate — `config.rs` and `cache.rs` have their own; a fourth copy is +cheaper than a shared test-support module for two dozen lines). Each of them +would have run until the OS refused a path before this change. + +*43.2, three crates.* `NetDelay` gained `before_hash` and `after_hash`. +`parse_net_delay` takes the first with `take_gap()` **after** the +`cur().is_sym("#")` check — the `gap_before("#")` contract, spelled out +rather than called, because the check is already there for the `is_net` gate +— and the second with `take_gap()` after the `bump()`. + +`Fmt::net_delay` now owns the separator in front of the delay as well as the +delay: it emits the `before_hash` comments *instead of* the plain space when +there are any, and the plain space when there are not, so a declaration with +no comment there is laid out byte-identically to before. That moved the +trailing space off `net` (`text(format!("{net} "))` → `text(net.clone())`) +and off the data type, which is why `data_decl` changed shape slightly; the +two call sites are now inside the `if let Some(net)` and +`if let Some(t) = self.data_type(…)` arms, which is also correct, since a +delay is only ever read after a net keyword, and an after-type delay only +after a data type that was actually written. + +*Deviation from the plan: `after_hash`.* The plan asks for `before_hash` +only, and also asks that the gap fuzzer cover the new slot. Those two are in +tension: `assert_no_failing_gaps` demands **zero** failures across a fixture +set, and the smallest fixture that exercises `before_hash` (`wire #5 a;`) +also contains the gap between `#` and `5`, which had no owner either. So the +fixture could not be added without it. `after_hash` is four lines (one field, +one `take_gap`, one `slot_comments`) on the same construct, and closes the +delay's own gaps completely; the alternative was to leave the fuzzer without +a net-delay fixture, which is the thing the plan explicitly asked for. Flagged +here for the lead. + +The gaps inside `#( 1:2:3 )` are *not* closed — eight of them, measured with +the fixture `wire [7:0] #(1:2:3) b = c;` before it was narrowed to `#1`. They +live in `parser/instance.rs::parse_delay_values`, shared with gate +instantiation delay lists, fail identically there, and are §2.9-22 shared +machinery. The RTL fuzzer fixture is `wire #5 a;` / `wire [7:0] #1 b = c;`, +which covers both sides of the type and both new slots; `EXPECTED_RTL_GAPS` +352 → 374, zero failures. + +*Files touched outside the plan's expected set.* None beyond what the plan +names, with one addition: `crates/vlog_formatter/tests/verification.rs` (the +gap fuzzer's fixture and count — the plan says "find how the fuzzer +enumerates slots and add this one", which is this file). Full list: +`crates/lucisv_core/src/walk.rs`, `crates/lucisv/tests/cli.rs`, +`crates/lucisv_server/src/state.rs` (test only), +`crates/vlog_parser/src/ast/decl.rs`, +`crates/vlog_parser/src/parser/decl.rs`, +`crates/vlog_formatter/src/format/decl.rs`, +`crates/vlog_formatter/tests/cases/net_delay_position.cases`, +`crates/vlog_formatter/tests/verification.rs`, `TODO.md`, this README. + +*Do the tests have teeth?* Asked directly rather than assumed: the `enter` +call was short-circuited (`if false && !self.enter(dir)`) and the walk tests +re-run. Three of the six failed — the self-loop, the ancestor link and the two +links — with paths 31 levels of `a/up/` deep, which is what the OS refuses at +rather than a hang. The other three (the sibling link, the dangling link, the +ignored cycle) pass either way by construction: they are about the *other* +half of the policy. The short-circuit was reverted immediately and the file +compared against a copy taken before it; `walk::` is green again. + +*Gates, all guarded.* `cargo fmt --check` on the five touched crates: clean. +`cargo clippy --all-targets`: clean, no new `#[allow]`. `cargo test +--workspace`: **3 788 passed, 0 failed** (baseline 3 780 + the 8 tests this +round adds: 6 in `walk.rs`, 1 CLI, 1 server). `tools/corpus_check.sh`: +**814/820 (99.3%)**, the same six failures (five parse, one lex) and the same +10 already-clean files. Byte-identity: no corpus file writes a comment before +a net delay's `#` — checked with a direct grep over `corpus/`, 0 hits — and +the empty-slot path emits exactly the `text(" ")` it did before, so the +formatter's output over the corpus cannot have moved; the corpus counts +confirm it. `node editors/vscode/smoke.js target/release/lucisv-server`: OK, +20 messages. The cyclic scratch tree (a self-link, a `..` link one level down, +a `../../..` link three levels down, a second name for one directory, and a +dangling `x.sv` link) through both release binaries under +`tools/guard.sh -t 120`: `lucisv --check` finishes in ~1s and names its three +files once each; an LSP session (initialize with that `rootUri`, `initialized`, +one `didOpen`, `workspace/symbol`) finishes in ~1s with each package indexed +exactly once. No guard kill anywhere in the round. + +### 2026-09-05 — lead, at review + +QA's MEDIUM (the dangling-symlink change made a "no such file" error +silent) is ruled and fixed: a dangling link that *names a source file* is +handed on again, so the front end reports it exactly as 0.42.0 did (exit 2); +a dangling link to anything else is skipped as the dev wrote. The test is +renamed to say both halves. QA's LOW (a link to `/` is followed and the +first permission-denied directory aborts the whole walk, dropping the files +already found) is pre-existing `?` propagation and is filed as topo §2.9-30 +together with the warning channel the walk lacks. The opentitan +`tlul_adapter_vh.sv` divergence QA root-caused is §41's canonical dedup +reporting a same-directory symlink alias once — the intended change, noted +in 0.43.0's release notes. + +## QA log + +**2026-09-05 — QA (Sonnet).** Built `target/release/{lucisv,lucisv_server}` once +and attacked both halves of the round on scratch trees under +`tools/guard.sh -t 120`; nothing was ever killed (no memory or wall-clock hit) +in this pass. + +*Diff review.* Read `crates/lucisv_core/src/walk.rs`, +`crates/vlog_parser/src/{ast,parser}/decl.rs`, +`crates/vlog_formatter/src/format/decl.rs`, the two test files, and +`crates/lucisv/tests/cli.rs` / `crates/lucisv_server/src/state.rs` line by +line against the plan. Traced the `data_decl` reshuffle by hand for the +empty-slot case on both sides of the type: `net_delay`'s separator branch +degrades to the same `text(" ")` the old unconditional call emitted, so a +declaration with neither a delay nor a comment is unaffected — confirmed +this holds for the "after_type but no data_type" case too, which cannot +arise (`parse_net_delay(is_net, true)` only ever succeeds after +`parse_opt_data_type` actually consumed tokens, since an omitted type +leaves the `#` for the `before` call to claim first). + +*43.1 — cycle attacks (all via `tools/guard.sh -t 120`, actual wall times +well under that in every case).* +- Depth 1/2/3 cycles (`a/loop -> a`, `a/b/up -> ..`, `a/b/c/top -> ../../..`): + terminate, each file named once. Two-link cycle (`a/x -> ../b`, + `b/y -> ../a`): terminates, `ma.sv` and `mb.sv` each reported once, `mb.sv` + under the alias spelling `a/x/mb.sv` (first spelling reached, as documented). + Chain of 50 symlinked directories collapsing to one target: resolved + correctly and fast (single `metadata` call per hop, no manual recursion) — + no `ELOOP`, no slowdown. +- **Ancestor-of-start escape.** Built `start/out -> ../..` where the target is + *outside* `start` entirely (not just the walk's own root) and ran + `--check` with `start` as the CLI argument (not its parent). The link is + followed once — per the ruling, identity is the policy, not location — and + pulls in a sibling file and a grandparent-level file that are not inside + `start` at all. It terminates (~1s) because the walk eventually re-enters + `start` itself from the other direction and that's already visited. Not a + bug — this is the plan's own explicit choice (no budget, `rtl -> + ../shared/rtl` must keep working) — but it is a real, user-visible + consequence: pointing lucisv at a subdirectory can pull in files from + outside it if that subdirectory contains an upward-and-back symlink. + Flagged as **LOW / informational** for the lead's record, not a defect. +- **Link to `/`.** Followed once, as the ruling implies it must be; spent + ~14.6s doing real `readdir`/`stat` work under `/System`, `/Library`, + `/private` etc. before hitting a permission-denied directory, at which + point the *entire* run aborted with `error: : + Permission denied` — none of the user's own files were reported, not even + the ones already found. Reproduced this abort-on-any-`read_dir`-error + behaviour with a controlled example (`crates/lucisv_core/src/walk.rs`'s + `dir()` uses `?` on `read_dir(dir)?.collect::>()?`, unchanged + by this diff) — it is pre-existing, not introduced by 43.1: the old, + cycle-blind walker would have followed `/` identically and hit the same + wall. Filed as **LOW / informational**, since it predates this round, but + worth the lead's attention because 43.1 is what makes "follow a link + outside the tree" a documented, intentional feature rather than an + accident — a link to `/` (or to any tree with a permission-restricted + subdirectory anywhere under it) now silently costs the *entire* check, not + just the linked file. Link to a real bounded tree (`/usr/share`, 250 MB): + walked completely in ~1s, correctly found and lex-errored on a + coincidentally `.sv`-named file (`vim/vim91/tutor/tutor1.sv`, Swedish + locale code) — confirms outside-of-start links are followed and that nothing + hangs on a moderately large real directory. +- Hard-linked **files**: reported twice, once per directory, confirming + identity is directory-only as documented. Two directories with identical + content but different inodes: both walked (not deduped) — confirmed + content-blind, inode-based identity. +- Gitignore interplay: a cycle inside an ignored directory never runs + (confirmed — the `loop` symlink inside `build/` was never touched); an + ignored symlinked directory name is skipped by that spelling but the real + target directory (different name, not itself ignored) is still walked + directly — this is unchanged, pre-existing per-spelling ignore matching, + not a 43.1 regression; a `.gitignore` inside a followed link's target + applies to the walk (its `sub/` pattern correctly hid the target's own + subdirectory when reached through the link). +- **The dangling `x.sv` behaviour change**, `lucisv format --check dir` + with a dangling `x.sv` link, new binary vs. + `~/.cache/lucisv-baselines/lucisv-0.42.0`: confirmed exactly as the + work log describes — 0.42.0 collects it, fails at read time + (`error: .../x.sv: No such file or directory`, exit 2, "1 file would be + reformatted, 1 file failed to format"); the new binary skips it silently + (exit 1, "1 file would be reformatted", no mention of `x.sv` anywhere). + **Finding, MEDIUM, for the lead's ruling** (this is what the plan and + TODO explicitly asked for, so not a defect against the dev — but the + silence itself is worth a second look): a dangling symlink named like a + source file usually means something real broke (a missing vendor drop, a + bad checkout), and the user now gets no signal at all instead of a + specific, actionable error. The CLI already has a precedent for this exact + tension — a missing file named in a `-f` filelist is a **warning on + stderr**, changing no exit code — and the same shape (warn, don't fail, + don't stay silent) seems like it would keep 43.1's win (no more hard + crash on a broken symlink) without losing the signal. Recommend the lead + decide whether `walk.rs` should carry a callback/return channel for this + one case, or whether silence is accepted as-is. +- **Both front ends.** CLI `--check` over a two-directory cyclic tree + (`rtl/self -> ../rtl`, `rtl/sub/up -> ..`): 2 files, once each. The same + tree over `lucisv_server` (drove the real binary over stdio, same framing + `talk_with` uses: `initialize` with that `rootUri` + + `workspace/didChangeConfiguration` for the wide index scope + + `workspace/symbol` queries): both declared modules found exactly once, + finished in-process with no hang. **File counts agree between CLI and + server for the same tree (2 and 2).** + Explicit file argument that is a symlink to a directory, and a start + directory that is itself a symlink: both work, both find the expected + file under the given spelling. + +*43.2 — comment-slot attacks, all via `format --stdout`, then idempotency +(format twice) and a before/after comment-count check on every shape:* +`wire /* c */ #5 w;`, `wire // c` + `#5 w;` on the next line, `wire [7:0] +/* c */ #1 b = c;`, `wire # /* c */ 5 w;` (`after_hash`), both slots at once +(`wire /* c1 */ # /* c2 */ 5 w;`), two comments in one slot +(`wire /* one */ /* two */ #5 w;`), a comment on the after-type side +(`wire [7:0] /* c */ #1 b = c;`), `tri`/`wand` with a delay comment, +an attribute ahead of the module. All ten: format cleanly, round-trip +idempotent, comment count preserved exactly. The refused shapes stayed +refused and did **not** corrupt: all four gaps inside `#(1:2:3)` — before +`1`, around each `:`, after `3` — still fail with a `verification failed: +token stream diverges` error and no output, matching the "not taken" scope +in Handshakes (topo §2.9-22). Ran the gap fuzzer directly +(`cargo test -p vlog_formatter a_comment_in_every_rtl_gap_still_formats` +under guard): passes; confirmed `EXPECTED_RTL_GAPS` is 374 in the tree and +that the added fixture (`wire #5 a;\n wire [7:0] #1 b = c;`) genuinely +exercises both new slots (both are comment-free in the fixture itself, but +the fuzzer inserts a comment into every inter-token gap in turn, which is +what raised the count from 352). + +*Gates, all guarded.* `cargo fmt --check` (five touched crates): clean. +`cargo clippy --all-targets`: clean, 0 warnings. `cargo test --workspace`: +**3 788 passed, 0 failed** — matches the work log exactly. Re-ran just +`lucisv_core`'s `walk::tests` in isolation: 17 passed (11 pre-existing + the +6 new ones), including the 6 cycle tests as their own filtered run. +`tools/corpus_check.sh`: **814/820 (99.3%)**, same 6 failures +(`ibex/dv/formal/check/peek/compare_helper.sv`, +`ibex/dv/uvm/core_ibex/riscv_dv_extension/riscv_core_setting.tpl.sv`, +`ibex/syn/rtl/latch_map.v`, +`ibex/vendor/google_riscv-dv/src/riscv_instr_cover_group.sv`, +`picorv32/scripts/romload/testbench.v`, +`picorv32/scripts/smtbmc/mulcmp.v`), same 10 already-clean files. +`node editors/vscode/smoke.js target/release/lucisv-server`: OK, 20 +messages. + +*Byte-identity vs 0.42.0.* Over the 820-file corpus, each file individually +through `format --stdout` (bypasses directory-walk dedup, isolates the +formatter itself): **0 differing**, exit codes included. Opentitan +`format --check` (using `--no-cache` on both sides after the first pass +showed cache-hit-count noise from a shared `.lucisv_cache`; see below) over +`hw/ip`, `hw/top_earlgrey/ip`, `hw/top_darjeeling/ip`, `hw/dv`, `hw/vendor`: +`hw/top_earlgrey/ip`, `hw/top_darjeeling/ip`, `hw/dv`, `hw/vendor` are +byte-identical between the two binaries (including exit codes: 1, 2, 1, 2 +respectively). **`hw/ip` differs by exactly one file**: +`hw/ip/tlul/rtl/tlul_adapter_vh.sv` is reported "would reformat" by 0.42.0 +and silently absorbed (not reported at all) by the new binary — 1773 vs. +1772 files. Root-caused, not a §43 regression: `hw/ip/tlul/rtl` contains +`tlul_adapter_shim.sv -> tlul_adapter_vh.sv`, a **symlinked file next to its +own target in the same directory**, and `crates/lucisv/src/main.rs`'s +`dedup()` (canonical-path fold, keeps the first spelling — this is §41, +already in trunk, *not* touched by this diff, and shipped in a release +*after* 0.42.0 per the loop order in `TODO.md`) now folds +`tlul_adapter_shim.sv`/`tlul_adapter_vh.sv` onto one entry, keeping +`tlul_adapter_shim.sv` (alphabetically first) and dropping the other. +Reproduced in isolation on a two-file scratch directory +(`real.sv` + `shim.sv -> real.sv`) with both binaries, `--no-cache`: 0.42.0 +reports both, the new binary reports one — confirms this is `main.rs`'s +existing dedup (unmodified by 43.1/43.2) becoming visible only because the +0.42.0 baseline predates it, not anything in this round's diff. Filed as +**informational**, not a §43 finding: the "byte-identity vs 0.42.0" gate is +not a clean isolation of this round alone once §41/§42 sit between the +baseline and trunk; recommend future rounds diff against trunk-before-the- +lane (or the `wip-43` backup already under +`~/.cache/lucisv-baselines/`) for a true delta, and use 0.42.0 only for the +"nothing has moved since the last *release*" question. Confirmed +`git -C ~/repo/opentitan status --porcelain` still shows only the three +expected pre-existing modifications (`hw/ip/aes/dv/tb/tb.sv`, +`hw/top_darjeeling/ip/ast/rtl/ast.sv`, `hw/top_earlgrey/ip/ast/rtl/ast.sv`) +after all opentitan runs; `.lucisv_cache/` is gitignored and untouched by +this statement either way. + +*Verdict:* **PASS.** No corruption, no idempotency break, no dropped +comment, in any attack. Both hard invariants around cycles (identity, +no budget) and the two new comment slots hold up under adversarial input, +and the refused inside-`#(...)` gaps stay refused rather than silently +accepted. Two behavioural points are flagged above for the lead's ruling +(the dangling-symlink silence, MEDIUM; the link-to-`/` full-run abort on a +permission wall, LOW/pre-existing) plus one informational note on the +baseline choice for byte-identity gates — none of them block this round. + +## Review + +**2026-09-05 — lead.** Accepted; ships in 0.43.0. 43.1 is the ruled policy +in one method — identity is the whole rule, and QA's cycles of every shape, +the 50-link chain and the two-link cycle all terminate with each file once. +The dev's `after_hash` slot beyond the plan is accepted: the gap fuzzer's +zero-failure bar made it necessary, and four lines on the same construct is +the right size; the `#(1:2:3)` interior stays §2.9-22's. The one behaviour +change QA flagged is corrected above so no user loses an error they had. +Both front ends share the walk unchanged in signature, and the byte-identity +gate over the corpus is 0 differing. diff --git a/docs/repository-analysis.md b/docs/repository-analysis.md index 237bf58..ced7725 100644 --- a/docs/repository-analysis.md +++ b/docs/repository-analysis.md @@ -145,6 +145,15 @@ suite also retains a refusal for comments immediately before a net-delay `#` (27). These limitations should remain visible when widening grammar or index coverage; formatter verification must continue to reject unsupported output. +**Fixed by TODO §43 (0.43.0, 2026-09-05):** the walker enters each directory +once by identity (`(dev, ino)` on unix, the canonical path elsewhere); a +symlink cycle terminates and a doubly reachable file is reported once. The +"no traversal budget" ruling was the lead's: identity is the policy. The +net-delay comment refusal (handshake 27) is closed by `NetDelay`'s comment +slots. Still open from this finding: handshakes 2, 16, 17, 23, and the new 30 +(an unreadable directory aborts the walk). See +`docs/features/walk-cycles/README.md`. + ## Documentation changes from this audit - Expanded the README's architecture to cover all eight crates and documented diff --git a/docs/topo.md b/docs/topo.md index 86bb5ae..c38893a 100644 --- a/docs/topo.md +++ b/docs/topo.md @@ -621,7 +621,7 @@ update the filing README(s) and this file. | ~~5~~ | ~~`lucisv check --rules-doc` printing `rules_markdown()`~~ — **delivered 2026-09-02 by macro-word-census (TODO §29.3)**: `lucisv check --rules-doc` prints `rules_markdown()` and exits 0, takes no files, is lint-only; the example binary is gone | lint-rules-2 | ~~crates/lucisv~~ done | | ~~6~~ | ~~Workspace-wide "does any file mention this name" query — the precondition for the semantic lints defaulting on~~ — **delivered 2026-09-02 by semantic-lints-on**: `FileFacts::words` (one identifier harvest, `vlog_semantic::words`, lifted from the server's candidates) and `WorkspaceIndex::files_mentioning` / `mentioned_outside(name, own_file)`; `FACTS_FORMAT` 12 → 13. The three rules consult a `MentionOracle` and are on by default whenever one exists. | semantic-lints | ~~vlog_semantic (index)~~ done | | ~~7~~ | ~~`SymbolKind::Interface` (interfaces currently indexed as `Module`; modport/clocking names unbound)~~ — **delivered 2026-09-01 by interface-semantics**: `SymbolKind::{Interface, Modport, Clocking}`, `is_instantiable()` threaded through every Module-exact filter, an interface export rule that treats its signals as its surface, modport/clocking-internal names bound as scope-local references, the modport half of a glued type name bound as `Target::TypeMember`. `program` still indexes as `Module`. Corpus unresolved fell 1 256 → 1 203 | interfaces | ~~vlog_semantic~~ done | -| 8 | Symlink-cycle detection in the shared walk (both front ends exposed; wants its own round — it changes CLI behavior) | lucisv-core-lift | lucisv_core | +| ~~8~~ | ~~Symlink-cycle detection in the shared walk (both front ends exposed; wants its own round — it changes CLI behavior)~~ — **delivered 2026-09-05 by walk-cycles (TODO §43.1):** `Walk` keeps a `visited` set keyed on `(dev, ino)` (canonical path elsewhere); each directory entered once, a link to one already entered skipped, a link to one not yet entered followed once, a dangling directory link skipped (a dangling source-file link is still handed on so the front end's "no such file" survives). Both front ends. | lucisv-core-lift | lucisv_core | | ~~9~~ | ~~Chasing `InheritedCandidate` through the member tables (in-file and cross-file) + hover for `extends`~~ — **delivered 2026-09-01 by class-member-access**: `resolve::member_in_chain` walks the in-file `extends` chain, `WorkspaceIndex::base_of` + `member_chain` walk it across files (inside `follow_one`, so hover and cross-file references agree), both cycle-guarded; `this.x`/`super.x` misses ride the same loop. `extends` hover/definition on the base name was already answered by overlay-promotion's type-position promotion. Residue filed in TODO §15 round 2: a `base` field on `ReferenceFact` so `this.x` misses get index postings too | class-semantics | ~~vlog_semantic~~ done | | ~~10~~ | ~~`Fmt::raw_text`'s string-crossing path emits a `Doc::Text` carrying newlines~~ — **delivered 2026-08-26 (`53f2269`)**: both `raw_text` and the parameterized-type `#( … )` now emit `Doc::Inline`, whose printer arm resumes measuring from the text's own last line. directive-split's README (QA round 3 note) still documents it as open and should be struck there too | directive-split QA | ~~vlog_formatter~~ done | | 11 | Corpus scripts match `parse error:` / `lex error:` / `verification failed:` textually; a structured `--output-format json` for format mode would remove it | corpus-check | crates/lucisv | @@ -641,9 +641,10 @@ update the filing README(s) and this file. | ~~25~~ | ~~The parser **refuses** a module-scope `begin … end` and a bare `begin` inside a `generate` region (an `ItemKind::Error`) rather than recovering them as an unnamed generate block, so `module-begin-block` and `v2001-generate-begin` (TODO §35) fire on an error leaf and the rest of the unit is lost to recovery. Wanted: tolerant-mode recovery that keeps the block's items.~~ — **delivered 2026-09-04 by small-items-3 (TODO §36)** | linter-expansion-3 (dev) | vlog_parser | | ~~26~~ | ~~**Same-target atomic writers share a temp path.** `atomic::temp_path` uses canonical target + process ID; parallel workers following distinct symlink spellings can reach that same name, while CLI dedup is lexical. A bounded direct helper probe (100 rounds, two threads, 1 MiB each) returned 100 write errors in 200 calls; no mixed final bytes observed in that probe. Use exclusive per-operation temp creation and coordinate/deduplicate target writes. See repository-analysis.md for limits.~~ — **closed by §41 (0.43.0):** unique `O_EXCL` temps (`.{name}.{pid}.{n}.lucisv-tmp`), dedup on `fs::canonicalize`; two *processes* remain last-writer-wins by design, stated in `atomic.rs` | repository audit, 2026-09-04 | lucisv_core / lucisv | -| 27 | **Net-delay comment slot**: parser-skips records a pre-existing refusal for a comment immediately before `#` in a net declaration. The regression cases mark it `#SKIP`; preserve the verifier's rejection until a parser/formatter comment slot handles it. | parser-skips (dev + QA) | vlog_parser / vlog_formatter | +| ~~27~~ | ~~**Net-delay comment slot**: parser-skips records a pre-existing refusal for a comment immediately before `#` in a net declaration. The regression cases mark it `#SKIP`; preserve the verifier's rejection until a parser/formatter comment slot handles it.~~ — **delivered 2026-09-05 by walk-cycles (TODO §43.2):** `NetDelay::{before_hash, after_hash}` own the gaps around `#`; the `#SKIP` is retired; the RTL gap fuzzer covers it. The gaps inside `#(1:2:3)` remain §2.9-22's. | parser-skips (dev + QA) | vlog_parser / vlog_formatter | | ~~28~~ | ~~**Project lint selection is not consumed by the server.** `enabled_rules` reads `ClientSettings`; `configured` reads project rule options and line length only. `[lint] select/ignore` currently controls CLI runs, while the editor needs `lucisv.lint.select/ignore`. Decide and test a common precedence contract before claiming project-wide parity.~~ — **closed by §42 (0.43.0):** `enabled_rules` picks the editor's list when set, else the project's, key by key (the CLI's `pick`); rejected project entries logged once with file:line | repository audit, 2026-09-04 | lucisv_server | | 29 | An unknown rule name in the **editor's** `lucisv.lint.select`/`ignore` is still dropped silently, while §42 logs the same mistake in a project file (and `lucisv.lint.options` logs its bad entries). Wants the same once-only log through `notification.rs`. | lint-config-contract (QA) | lucisv_server | +| 30 | **An unreadable directory aborts the whole walk.** `Walk::dir` propagates `read_dir`'s error with `?`, so one permission-denied directory anywhere under the start — reachable now that a symlink to an outside directory is followed once (§2.9-8's ruling) — drops every file already found and fails the run. Found by walk-cycles' QA on a link to `/`. Wanted: skip the directory and say so through a warning channel the walk does not have today (the filelist-missing-file precedent), which is also where a dangling source link's warning belongs. | walk-cycles (QA) | lucisv_core / lucisv / lucisv_server | ---