Review round §61.1 (R3a): an engine-owned rename preflight refuses from the request buffer alone — a cursor with no symbol went from 2.0 s and 3 975 parses to 0.34 ms and none, sentence and precedence byte-identical; index-answered refusals stay on the slow road (a wrong rename refusal is terminal); the extract preflight was proven redundant and not shipped
This commit is contained in:
1 parent
e13ae4c89b
commit
51cbfd27df
13 files changed
+1490
-21
No files matched your search
@@ -6201,31 +6201,68 @@ road; the extract at the `aes_wrap.sv` inline-site selection spends
|
||||
805 ms building a scope before its safety checks refuse. Files:
|
||||
`vlog_refactor/src/{rename/mod.rs,extract/mod.rs,lib.rs}`,
|
||||
`lucisv_server/src/{rename.rs,extract.rs}`, tests.
|
||||
- [ ] engine-owned rename preflight over the request file alone (its
|
||||
- [x] engine-owned rename preflight over the request file alone (its
|
||||
parse + analysis; `prepare_rename_here` is the existing one-file
|
||||
shape — reuse it): `check_new_name`, then the cursor refusal, with
|
||||
today's error precedence (invalid new name → out-of-scope /
|
||||
unavailable file → no symbol here) and the exact sentences; the
|
||||
server calls it before selecting sources and materializes nothing
|
||||
when it refuses; a symbol found → today's path unchanged
|
||||
- [ ] duplicate-declaration refusal moved ahead of materialization ONLY
|
||||
— `vlog_refactor::rename_preflight` (`rename/preflight.rs`), additive,
|
||||
**without** the `external`/`index` parameters the brief proposed: every
|
||||
refusal they could answer is one the staleness argument forbids taking,
|
||||
so they would have been unused. Takes rules 1, 4, 5, 6, 11a and — only
|
||||
for a non-file-scope declaration in the buffer — rule 2
|
||||
- [x] duplicate-declaration refusal moved ahead of materialization ONLY
|
||||
with the evidence the review asks for (the index is current and
|
||||
authoritative for that name — the workspace's `declared_twice`
|
||||
already gates the ports offer on it; state the argument or leave
|
||||
it on the slow road)
|
||||
- [ ] extract preflight: the selection's own checks that read only the
|
||||
— **left on the slow road, with the argument.** `state/mod.rs::set_document`
|
||||
reads the index and never writes it, so an unsaved edit that adds or
|
||||
removes a file-scope declaration is not in it; `rename` is the authority
|
||||
that re-derives the count. A wrong *offer* costs a lightbulb, a wrong
|
||||
*refusal* costs the work. `rstmgr_por` keeps its ~2.0 s, asserted by
|
||||
`a_name_declared_in_two_files_stays_on_the_slow_road`
|
||||
- [x] extract preflight: the selection's own checks that read only the
|
||||
request file's parse (the region, the item kinds, the refusal
|
||||
shapes `extract_site`/`Region::read` already know) run before
|
||||
`Scope::build`; exact refusal sentence preserved, no optimistic edit
|
||||
- [ ] measured: no-symbol rename ≤ 16 ms with zero closed-workspace
|
||||
— **they already do, by two mechanisms**, which the new `extractrefuse`
|
||||
phase measures: `execute`'s `site_at` gate *is* `extract_site_in`, whose
|
||||
first two statements are the parse-diagnostic check and `Region::read`;
|
||||
and `plain_identifier`/occupied are `extract_module`'s own first
|
||||
statements, ahead of `Extraction::plan`. A preflight was written, wired,
|
||||
measured and **removed** as redundant
|
||||
- [x] measured: no-symbol rename ≤ 16 ms with zero closed-workspace
|
||||
parses; the `aes_wrap.sv` extract refusal with its parse count;
|
||||
the successful renames and the extract capture unchanged
|
||||
(fingerprints); R3a/R3c cells + experiment entries
|
||||
- [ ] QA: refusal-precedence matrix old vs new (13 shapes: invalid name,
|
||||
— no-symbol **2 012.3 → 0.34 ms**, `trace_parses` **3 975 → 0**,
|
||||
peak RSS 909 → 429 MiB, sentence identical. `aes_wrap.sv` extract
|
||||
refusal **761.1 → 767.8 ms (unchanged)**; its stage is
|
||||
`boundary::Crossing::read`, scope-dependent at depth — deferred to §61.5.
|
||||
All fingerprints identical (`b39defb21265…`, `fa7e31c78382…`,
|
||||
`090e92e7736e…`). R3a/R3c cells and both experiment records filed
|
||||
- [x] QA: refusal-precedence matrix old vs new (13 shapes: invalid name,
|
||||
keyword, unsaved/closed file, untitled, no symbol, comment, string,
|
||||
macro, duplicate module, existing name, same name, large-file
|
||||
buffer, cursor on a reference vs a declaration); parse counts;
|
||||
fingerprints; numbers re-taken
|
||||
— **PASS.** Rule table rebuilt independently from `renaming`/`Scope::
|
||||
locate`/`declaration` vs `rename_preflight`/`declared_here`, agrees
|
||||
with the dev's; oracle sabotaged twice (an invented refusal, a
|
||||
reworded sentence) and caught both; gates clean (fmt/clippy/4 322-test
|
||||
guarded run, matching a same-tree baseline + the 17 added tests
|
||||
exactly — the README's "4 328" was a slip, corrected); fresh guarded
|
||||
wire re-runs against the sha256-matched candidate binary over
|
||||
OpenTitan reproduce no-symbol 0/0 parses and ≤1 ms, the duplicate-
|
||||
module and common-port rows unchanged (3 975 parses, same sentence),
|
||||
the `aes_wrap.sv` extract refusal unchanged with its `Crossing::read`
|
||||
sentence, and the `aes.sv` capture fingerprint identical; all 12
|
||||
tracker R3a/R3c-x numbers and 5 fingerprints traced verbatim in
|
||||
`~/.cache/lucisv-perf/take5r-1/`. QA log in
|
||||
`docs/features/perf5r-preflight/README.md`
|
||||
|
||||
### 61.2 R1a + R1b — the code-action path on a large file
|
||||
|
||||
|
||||
@@ -137,6 +137,16 @@ pub fn execute(
|
||||
true => Home::NewFile,
|
||||
false => Home::SameFile,
|
||||
};
|
||||
// No preflight here, and the take 5 review round (§61.1) is why: every
|
||||
// refusal one could take is already taken before a scope is built. The
|
||||
// `site_at` gate above **is** `extract_site_in`, which returns `None` on a
|
||||
// parse diagnostic and on every `Region::read` refusal, so neither can
|
||||
// reach the engine; and `extract_module` checks the new name and the
|
||||
// occupied target as its own first two statements, ahead of
|
||||
// `Extraction::plan`. The 805 ms at `aes_wrap.sv` is none of those — it is
|
||||
// `boundary::Crossing::read`, which needs the instantiated modules' port
|
||||
// directions and so needs the scope. See
|
||||
// `docs/features/perf5r-preflight/README.md`.
|
||||
let refactoring = vlog_refactor::extract_module(&files, &path, start, end, &name, home)?;
|
||||
Ok((workspace_edit(ws, &refactoring)?, refactoring.warnings))
|
||||
}
|
||||
@@ -381,4 +391,76 @@ endmodule
|
||||
assert!(crate::code_action::wanted(Some(&filter), &kind()));
|
||||
assert!(!crate::code_action::wanted(Some(&filter), &CodeActionKind::QUICKFIX));
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// Where the extract refusals are actually taken (take 5 review §3 item 5,
|
||||
// TODO §61.1). No preflight was added — every refusal below is already
|
||||
// reached before a scope exists, and these pin that it stays so.
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
fn run(
|
||||
ws: &Workspace,
|
||||
uri: &Uri,
|
||||
range: Range,
|
||||
name: &str,
|
||||
create: bool,
|
||||
) -> Result<(), String> {
|
||||
let arguments = vec![
|
||||
serde_json::to_value(uri).expect("uri"),
|
||||
serde_json::to_value(range).expect("range"),
|
||||
Value::String(name.to_string()),
|
||||
];
|
||||
execute(ws, &arguments, create).map(|_| ())
|
||||
}
|
||||
|
||||
/// A bad new name is refused by `extract_module`'s own first statement,
|
||||
/// and a selection covering no whole item is refused by the `site_at` gate
|
||||
/// — neither reaches `Extraction::plan`, so neither builds a scope.
|
||||
#[test]
|
||||
fn the_cheap_refusals_reach_the_wire_in_the_engines_words() {
|
||||
let tree = Tree::new("preflightrefusals");
|
||||
let (ws, uri) = opened(&tree);
|
||||
|
||||
let bad = run(&ws, &uri, selection(), "1bad", true).expect_err("a bad name");
|
||||
assert!(bad.contains("plain SystemVerilog identifier"), "{bad}");
|
||||
|
||||
// Half of `assign s = a + b;`, which covers no whole item.
|
||||
let partial = Range {
|
||||
start: Position { line: 6, character: 6 },
|
||||
end: Position { line: 6, character: 19 },
|
||||
};
|
||||
assert_eq!(
|
||||
run(&ws, &uri, partial, "sum", true),
|
||||
Err(NOTHING.to_string()),
|
||||
"the `site_at` gate answers a partial selection before the engine is asked"
|
||||
);
|
||||
}
|
||||
|
||||
/// A file already sitting where the new module would go is refused before
|
||||
/// `Extraction::plan`, and the question is asked of the source set the
|
||||
/// engine was handed rather than of the disk behind its back.
|
||||
#[test]
|
||||
fn an_occupied_target_is_refused_with_the_engines_sentence() {
|
||||
let tree = Tree::new("preflightoccupied");
|
||||
tree.write("sum.sv", "module sum;\nendmodule\n");
|
||||
let (ws, uri) = opened(&tree);
|
||||
let refusal = run(&ws, &uri, selection(), "sum", true).expect_err("occupied");
|
||||
assert!(refusal.contains("there is already a"), "{refusal}");
|
||||
assert!(refusal.contains("sum.sv"), "and it names the file: {refusal}");
|
||||
|
||||
// Into the same file nothing is occupied, so the early check passes
|
||||
// and the engine refuses for its own, later reason: the workspace
|
||||
// already declares that name — an index question, answered by the
|
||||
// stage that owns the index.
|
||||
let deferred = run(&ws, &uri, selection(), "sum", false).expect_err("already declared");
|
||||
assert!(deferred.contains("the workspace already declares"), "{deferred}");
|
||||
}
|
||||
|
||||
/// The control: a whole, movable item still extracts.
|
||||
#[test]
|
||||
fn a_whole_movable_selection_still_extracts() {
|
||||
let tree = Tree::new("preflightok");
|
||||
let (ws, uri) = opened(&tree);
|
||||
assert!(run(&ws, &uri, selection(), "sum", true).is_ok());
|
||||
}
|
||||
}
|
||||
@@ -65,6 +65,26 @@ pub fn rename_traced(
|
||||
) -> Result<(WorkspaceEdit, Vec<String>), String> {
|
||||
let doc = ws.document(uri).ok_or_else(|| UNSAVED.to_string())?;
|
||||
let path = doc.path.clone().ok_or_else(|| UNSAVED.to_string())?;
|
||||
// The engine's own first look at the request, over the buffer it is about
|
||||
// to be handed anyway. It refuses only what `vlog_refactor::rename` is
|
||||
// certain to refuse in the same words — so this is still one voice
|
||||
// deciding, just asked before the workspace is materialized for it. A
|
||||
// cursor on nothing used to read, parse and index all 3 976 files before
|
||||
// saying so (take 5 review §3 item 6); now it reads none.
|
||||
//
|
||||
// Sound because both selectors below hand the engine this very buffer, so
|
||||
// the out-of-scope refusal that outranks a cursor refusal cannot fire.
|
||||
//
|
||||
// A refusal here still writes a trace, because "where did the time go" is
|
||||
// a question about the fast refusals too — and the answer, nowhere, is
|
||||
// only believable if the line says `selected=0` and `parses=0` in the same
|
||||
// fields the slow road fills.
|
||||
if let Err(refusal) = vlog_refactor::rename_preflight(&doc.semantics, offset, new_name) {
|
||||
let (selection, engine) =
|
||||
(SelectionTrace::default(), vlog_refactor::RenameTrace::default());
|
||||
*trace = Some(format!("{} {} preflight=true", selection.line(), engine.line()));
|
||||
return Err(refusal);
|
||||
}
|
||||
// The name the cursor sits on, read off the buffer, is what the index is
|
||||
// asked for the fan-out. No refusal is taken here: `vlog_refactor::rename`
|
||||
// is the one voice that decides, and it decides over the files below. A
|
||||
@@ -1030,4 +1050,106 @@ mod tests {
|
||||
"and it is the engine's sentence, not the census's: {warning}"
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// The engine-owned preflight (take 5 review §3 item 6, TODO §61.1)
|
||||
// ------------------------------------------------------------------
|
||||
|
||||
/// A cursor on nothing used to select every in-scope file, parse all of
|
||||
/// them and index them before the engine's 0.1 ms refusal. The preflight
|
||||
/// is only worth having if that is now literally no parses at all — not
|
||||
/// fewer, none — so the gate is asserted, not measured.
|
||||
#[test]
|
||||
fn a_rename_on_a_cursor_with_no_symbol_parses_nothing() {
|
||||
let tree = Tree::new("nosymbolparses");
|
||||
let (ws, uri) = opened(&tree);
|
||||
let at_comment = TOP.len() as u32 - 1; // the newline after `endmodule`
|
||||
|
||||
let before = vlog_parser::stats::parses();
|
||||
let mut trace = None;
|
||||
let refusal =
|
||||
rename_traced(&ws, &uri, at_comment, "probe", &mut trace).expect_err("no symbol there");
|
||||
let parses = vlog_parser::stats::parses() - before;
|
||||
|
||||
assert_eq!(parses, 0, "the refusal parsed {parses} whole files");
|
||||
assert_eq!(refusal, "there is no symbol to rename at this position.");
|
||||
|
||||
// And the `--verbose` channel says so in its own fields, so the phase
|
||||
// that measures this row reads the parse count instead of trusting it.
|
||||
let trace = trace.expect("a refusal traces too");
|
||||
assert!(trace.contains("selected=0"), "{trace}");
|
||||
assert!(trace.contains("parses=0"), "{trace}");
|
||||
assert!(trace.contains("preflight=true"), "{trace}");
|
||||
}
|
||||
|
||||
/// …and it is the same sentence the whole workspace produced, taken from
|
||||
/// the engine over every in-scope file rather than from this module.
|
||||
#[test]
|
||||
fn the_preflights_refusal_is_the_whole_workspaces_refusal() {
|
||||
let tree = Tree::new("preflightparity");
|
||||
let (ws, uri) = opened(&tree);
|
||||
let path = tree.path.join("top.sv");
|
||||
for (case, offset) in [
|
||||
("past the last item", TOP.len() as u32 - 1),
|
||||
("on the `module` keyword", at(TOP, "module")),
|
||||
("on a literal", at(TOP, "1'b0")),
|
||||
] {
|
||||
let fast = rename(&ws, &uri, offset, "probe").expect_err(case);
|
||||
let slow = vlog_refactor::rename(&ws.sources(), &path, offset, "probe")
|
||||
.expect_err("the whole workspace refuses too");
|
||||
assert_eq!(fast, slow, "{case}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Precedence, in the two places the preflight could have disturbed it: an
|
||||
/// unusable buffer is refused by this module before the engine is asked
|
||||
/// anything, and an invalid new name outranks whatever the cursor is on.
|
||||
#[test]
|
||||
fn the_preflight_does_not_disturb_the_refusal_order() {
|
||||
let tree = Tree::new("preflightorder");
|
||||
let (ws, uri) = opened(&tree);
|
||||
|
||||
let untitled = Uri::from_str("untitled:Untitled-1").expect("uri");
|
||||
let mut with_untitled = Workspace::default();
|
||||
with_untitled.set_document(untitled.clone(), TOP.to_string());
|
||||
assert_eq!(
|
||||
rename(&with_untitled, &untitled, at(TOP, "u_sub"), "probe").expect_err("unsaved"),
|
||||
UNSAVED,
|
||||
"an untitled buffer is refused before the engine sees the cursor"
|
||||
);
|
||||
|
||||
// A cursor on nothing *and* a keyword for a new name: the name's
|
||||
// sentence, which is the one `renaming` reaches first.
|
||||
let refusal = rename(&ws, &uri, TOP.len() as u32 - 1, "module").expect_err("a keyword");
|
||||
assert_eq!(refusal, "`module` is a Verilog keyword.");
|
||||
}
|
||||
|
||||
/// The one buffer the preflight must never judge: on the large-file fast
|
||||
/// path every field but the text is the analysis of the *empty* file, so a
|
||||
/// preflight over it would refuse every cursor as symbolless. The
|
||||
/// large-buffer gate refuses the whole request first, and this pins that
|
||||
/// it still does.
|
||||
#[test]
|
||||
fn a_large_buffer_is_refused_before_the_preflight_could_see_it() {
|
||||
let tree = Tree::new("preflightlarge");
|
||||
tree.write("sub.sv", SUB);
|
||||
let top = tree.write("top.sv", TOP);
|
||||
let mut ws = Workspace::default();
|
||||
ws.set_client_settings(crate::settings::ClientSettings {
|
||||
index_scope: crate::settings::IndexScope::Workspace,
|
||||
large_file_threshold: 1,
|
||||
..Default::default()
|
||||
});
|
||||
ws.open_whole_workspace(vec![tree.path.clone()]);
|
||||
let uri = path_to_uri(&top).expect("uri");
|
||||
ws.set_document(uri.clone(), TOP.to_string());
|
||||
|
||||
let doc = ws.document(&uri).expect("open");
|
||||
assert!(doc.large, "premise: the buffer took the fast path");
|
||||
assert!(
|
||||
vlog_refactor::rename_preflight(&doc.semantics, at(TOP, "u_sub"), "probe").is_err(),
|
||||
"premise: the empty analysis would refuse a real cursor, which is why \
|
||||
`server/large_file.rs` must answer this method before we are reached"
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -181,12 +181,7 @@ impl Extraction {
|
||||
let Some(text) = scope.text(here) else { return Err(not_in_scope(file)) };
|
||||
let (tree, diagnostics) = parse_source_tolerant(text);
|
||||
if let Some(problem) = diagnostics.first() {
|
||||
return Err(format!(
|
||||
"{} does not parse ({} at line {}), so lucisv will not extract from it.",
|
||||
display(file),
|
||||
problem.message,
|
||||
problem.line
|
||||
));
|
||||
return Err(does_not_parse(file, problem));
|
||||
}
|
||||
let region = Region::read(&tree, text, TextRange::new(start, end))?;
|
||||
let module = region.module_name().to_string();
|
||||
@@ -468,6 +463,20 @@ fn occupied(path: &Path) -> String {
|
||||
format!("there is already a `{}` beside this file; pick another name.", display(path))
|
||||
}
|
||||
|
||||
/// Why a file lucisv cannot read is a file it will not extract from.
|
||||
///
|
||||
/// Reachable through `extract_module` alone: a server calls [`extract_site_in`]
|
||||
/// first, and that answers `None` for a file with any parse diagnostic, so the
|
||||
/// sentence is for the caller that comes straight to the engine.
|
||||
fn does_not_parse(file: &Path, problem: &ParseDiagnostic) -> String {
|
||||
format!(
|
||||
"{} does not parse ({} at line {}), so lucisv will not extract from it.",
|
||||
display(file),
|
||||
problem.message,
|
||||
problem.line
|
||||
)
|
||||
}
|
||||
|
||||
fn escaped(name: &str) -> String {
|
||||
format!(
|
||||
"`{name}` is declared inside the selection and used outside it; move the declaration of `{name}` out of the selection first."
|
||||
|
||||
@@ -59,8 +59,8 @@ pub use ports::{
|
||||
PortOfferKind,
|
||||
};
|
||||
pub use rename::{
|
||||
contains_word, prepare_rename, prepare_rename_here, rename, rename_name_at, rename_traced,
|
||||
RenameTarget,
|
||||
contains_word, prepare_rename, prepare_rename_here, rename, rename_name_at, rename_preflight,
|
||||
rename_traced, RenameTarget,
|
||||
};
|
||||
pub use trace::{RenameTrace, Stage, VerifyTrace};
|
||||
|
||||
|
||||
@@ -12,10 +12,13 @@
|
||||
//! workspace every refactoring in this crate reads through, and `warnings` is
|
||||
//! what a finished rename says about the occurrences it could not edit.
|
||||
|
||||
mod preflight;
|
||||
#[cfg(test)]
|
||||
mod tests;
|
||||
mod warnings;
|
||||
|
||||
pub use preflight::rename_preflight;
|
||||
|
||||
// The rename was the first refactoring, so most of the crate still spells the
|
||||
// workspace `crate::rename::Scope`. It lives at `crate::scope` now (§29.1).
|
||||
pub(crate) use crate::scope::{display, Scope};
|
||||
@@ -208,7 +211,7 @@ fn renaming(
|
||||
trace.selected = scope.len();
|
||||
let target = trace.locate.measure(|| scope.locate(file, offset))?;
|
||||
if target.name == new_name {
|
||||
return Err(format!("`{new_name}` is the name it already has."));
|
||||
return Err(already_named(new_name));
|
||||
}
|
||||
let edits = trace.edits.measure(|| scope.collect_edits(&target, new_name))?;
|
||||
trace.edited = edits.len();
|
||||
@@ -508,10 +511,14 @@ impl<'a> Scope<'a> {
|
||||
|
||||
const NOTHING_HERE: &str = "there is no symbol to rename at this position.";
|
||||
|
||||
// The refusal sentences, each written once. Two callers reach four of them
|
||||
// now: the whole-workspace `Scope::locate` and the buffer-and-index
|
||||
// `prepare_rename_here`, which must refuse in exactly the same words or the
|
||||
// user gets two different explanations for one situation.
|
||||
// The refusal sentences, each written once. Three callers reach them now: the
|
||||
// whole-workspace `Scope::locate`, the buffer-and-index `prepare_rename_here`,
|
||||
// and the buffer-only `rename_preflight` — which must refuse in exactly the
|
||||
// same words or the user gets two different explanations for one situation.
|
||||
|
||||
fn already_named(new_name: &str) -> String {
|
||||
format!("`{new_name}` is the name it already has.")
|
||||
}
|
||||
|
||||
fn ambiguous(name: &str) -> String {
|
||||
format!(
|
||||
|
||||
@@ -0,0 +1,84 @@
|
||||
//! The refusals a rename can reach from the request buffer alone.
|
||||
//!
|
||||
//! `renaming` builds a whole [`Scope`](crate::scope::Scope) — one parse and
|
||||
//! one analysis per in-scope file — before `locate` looks at the cursor. On
|
||||
//! OpenTitan a cursor sitting on a comment cost **3 975 parses and 1.9 s**
|
||||
//! before a 0.1 ms refusal that read nothing but the request file (take 5
|
||||
//! review, §3 item 6). This is that refusal, taken first.
|
||||
//!
|
||||
//! **What it is allowed to take.** Only a refusal `renaming` is *certain* to
|
||||
//! reach in the same words, from facts that are a pure function of the request
|
||||
//! buffer's own text: the new-name check, and the cursor refusals the buffer's
|
||||
//! own `Semantics` settles. `Semantics` is `analyze(&parse(text), text)` and
|
||||
//! consults nothing else, so the buffer's analysis and the scope's analysis of
|
||||
//! that same file are the same value.
|
||||
//!
|
||||
//! **What it must not take.** Every refusal whose answer comes from the
|
||||
//! *workspace index*: whether a name is declared in more than one file, and
|
||||
//! which file a cross-file use means. The index is rebuilt on save and on a
|
||||
//! watcher event, never on a keystroke (`state/mod.rs::set_document` reads it
|
||||
//! and does not touch it), so an unsaved edit that adds or removes a
|
||||
//! file-scope declaration is not in it. `prepare_rename_here` may read it
|
||||
//! anyway — an optimistic `prepareRename` is LSP-legal and the rename that
|
||||
//! follows corrects it — but `rename` **is** that correction, and a refusal
|
||||
//! invented here from a stale count is a rename the user cannot get. Those
|
||||
//! stay on the slow road, which re-derives the count from the current texts.
|
||||
//!
|
||||
//! `Ok(())` therefore means "proceed exactly as before", never "this rename
|
||||
//! will succeed".
|
||||
|
||||
use vlog_semantic::{Resolution, Semantics, SymbolId};
|
||||
|
||||
use super::{already_named, check_new_name, from_base, unresolved, unspelled, NOTHING_HERE};
|
||||
|
||||
/// The refusal `rename` would make for this cursor and this new name, when the
|
||||
/// request buffer alone is enough to know it — and `Ok(())` when it is not.
|
||||
///
|
||||
/// A caller must only ask this about a file it is going to hand `rename` as
|
||||
/// one of its in-scope files: `locate` refuses a file it was not given
|
||||
/// *before* it looks at the cursor, and that refusal has to keep its place in
|
||||
/// the order. Both of the server's source selectors always include the
|
||||
/// requesting buffer, so both satisfy it.
|
||||
pub fn rename_preflight(semantics: &Semantics, offset: u32, new_name: &str) -> Result<(), String> {
|
||||
// First in `renaming`, and so first here: an invalid new name outranks
|
||||
// everything the cursor could say.
|
||||
check_new_name(new_name)?;
|
||||
let found = semantics.reference_id_at(offset).and_then(|id| semantics.reference(id));
|
||||
let Some(reference) = found else {
|
||||
// The cursor is on a declaration written here, or on nothing at all.
|
||||
let Some(symbol) = semantics.symbol_at(offset) else {
|
||||
return Err(NOTHING_HERE.to_string());
|
||||
};
|
||||
return declared_here(semantics, symbol, new_name);
|
||||
};
|
||||
match &reference.resolution {
|
||||
Resolution::Resolved(symbol) => declared_here(semantics, *symbol, new_name),
|
||||
Resolution::NotFound => Err(unresolved(&reference.name)),
|
||||
Resolution::InheritedCandidate { base, .. } => Err(from_base(&reference.name, base)),
|
||||
// Which file declares this name — and whether several do — is the
|
||||
// index's word, and the index is not the authority a rename is.
|
||||
Resolution::ExternalCandidate { .. } => Ok(()),
|
||||
}
|
||||
}
|
||||
|
||||
/// `Scope::declaration` for a declaration written in the request buffer, as
|
||||
/// far as the buffer can carry it.
|
||||
fn declared_here(semantics: &Semantics, symbol: SymbolId, new_name: &str) -> Result<(), String> {
|
||||
// `locate` answers a symbol id it cannot look up with `NOTHING_HERE`. It
|
||||
// came from this same analysis, so it can be looked up; deferring rather
|
||||
// than asserting keeps the impossible case on the road that handles it.
|
||||
let Some(declaration) = semantics.symbol(symbol) else { return Ok(()) };
|
||||
if declaration.name_span.is_empty() {
|
||||
return Err(unspelled(&declaration.name));
|
||||
}
|
||||
// A file-scope unit is refused when the index holds its name more than
|
||||
// once, and that count belongs to the slow road — so nothing after it may
|
||||
// be decided here either, or a refusal would jump the ambiguity check.
|
||||
if declaration.scope == semantics.file_scope() {
|
||||
return Ok(());
|
||||
}
|
||||
if declaration.name == new_name {
|
||||
return Err(already_named(new_name));
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -0,0 +1,252 @@
|
||||
//! `rename_preflight` against the road it short-circuits, refusal by refusal.
|
||||
//!
|
||||
//! The preflight answers, from the request file alone, a question `rename`
|
||||
//! would otherwise answer after parsing and analyzing the whole in-scope
|
||||
//! workspace. That is only sound if the two answers are the *same sentence*,
|
||||
//! so this file is the equality oracle: at **every byte** of seven hostile
|
||||
//! buffers, and for every new name worth trying, the fast road's refusal must
|
||||
//! be the slow road's refusal, word for word.
|
||||
//!
|
||||
//! Two directions, and only one of them is allowed:
|
||||
//!
|
||||
//! * the preflight refuses and the whole road refuses **differently**, or
|
||||
//! accepts — an *invented* refusal, which is a rename the user cannot get.
|
||||
//! Always a failure.
|
||||
//! * the preflight says `Ok(())` and the whole road refuses — a *deferral*,
|
||||
//! which is the normal case for everything the request file cannot settle.
|
||||
//! Counted, never asserted away, and asserted to be non-zero where the
|
||||
//! fixture is built to produce one.
|
||||
|
||||
use std::path::PathBuf;
|
||||
|
||||
use vlog_parser::parse_source_tolerant;
|
||||
use vlog_refactor::{rename, rename_name_at, rename_preflight};
|
||||
use vlog_semantic::analyze;
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// Fixtures
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
const SUB: &str = "module sub #(parameter int W = 1) (input logic clk, output logic q);\n wire local_net;\n assign q = clk & local_net;\nendmodule : sub\n";
|
||||
const TOP: &str = "module top;\n logic c, d;\n sub #(.W(2)) u_sub (.clk(c), .q(d));\n sub u_two (.clk(c), .q(d));\nendmodule\n";
|
||||
const PKG: &str =
|
||||
"package cfg_pkg;\n parameter int DEPTH = 4;\n typedef logic [1:0] mode_t;\nendpackage\n";
|
||||
const USER: &str = "module user;\n import cfg_pkg::*;\n cfg_pkg::mode_t m;\n localparam int D = cfg_pkg::DEPTH;\nendmodule\n";
|
||||
/// A name that resolves to nothing, and one that could only come from a base
|
||||
/// class nothing in the workspace declares.
|
||||
const STRAY: &str = "class kid extends absent_base;\n function void go();\n inherited_thing = 1;\n endfunction\nendclass\nmodule holder;\n missing u_missing (.a(b));\nendmodule\n";
|
||||
/// Macro invocations, a generate block and a genvar.
|
||||
const GEN: &str = "`define BUMP(x) x + 1\n`define WIDTH 8\nmodule gen_holder;\n genvar i;\n generate\n for (i = 0; i < 2; i++) begin : lane\n sub u_lane (.clk(1'b0), .q());\n end\n endgenerate\n wire [`WIDTH-1:0] w;\n assign w = `BUMP(sub);\nendmodule\n";
|
||||
/// Every byte a cursor can sit on that is *not* a symbol: line comments,
|
||||
/// block comments, a string literal, a system task, an attribute, and — for
|
||||
/// the offsets in between — punctuation and whitespace.
|
||||
const PROSE: &str = "// a leading line comment naming clk and sub\n/* a block comment\n naming local_net too */\nmodule prose;\n // clk here is prose\n logic clk;\n initial begin\n $display(\"clk and sub and local_net, all in a string\");\n end\n (* keep = \"true\" *)\n wire tagged_net;\nendmodule\n";
|
||||
const BROKEN: &str = "module broken (input logic clk;\n wire a\n assign a = clk\nendmodule\n";
|
||||
|
||||
fn workspace(files: &[(&str, &str)]) -> Vec<(PathBuf, String)> {
|
||||
files.iter().map(|(name, text)| (PathBuf::from(name), (*text).to_string())).collect()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
// The rename oracle
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
/// Ask both roads the same rename at every byte of `file`, for every new name
|
||||
/// worth asking about there, and return `(refused, deferred)`.
|
||||
///
|
||||
/// The new names are the four `check_new_name` shapes plus two that can only
|
||||
/// be judged after the cursor is resolved: a novel valid name, and **the name
|
||||
/// the cursor already spells**, which is the one way to reach the "is the name
|
||||
/// it already has" refusal at an arbitrary offset.
|
||||
fn rename_oracle(files: &[(&str, &str)], file: &str) -> (usize, usize) {
|
||||
let sources = workspace(files);
|
||||
let path = PathBuf::from(file);
|
||||
let text = files
|
||||
.iter()
|
||||
.find(|(name, _)| *name == file)
|
||||
.map(|(_, text)| *text)
|
||||
.expect("the file is in the workspace");
|
||||
let semantics = analyze(&parse_source_tolerant(text).0, text);
|
||||
|
||||
let (mut refused, mut deferred) = (0usize, 0usize);
|
||||
for offset in 0..=text.len() as u32 {
|
||||
let here = rename_name_at(&semantics, offset);
|
||||
let mut names: Vec<&str> = vec!["", "module", "1bad", "has space", "renamed_thing"];
|
||||
if let Some(name) = &here {
|
||||
names.push(name.as_str());
|
||||
}
|
||||
for new_name in names {
|
||||
let fast = rename_preflight(&semantics, offset, new_name);
|
||||
let slow = rename(&sources, &path, offset, new_name);
|
||||
match (&fast, &slow) {
|
||||
(Err(fast), Err(slow)) => {
|
||||
assert_eq!(
|
||||
fast, slow,
|
||||
"byte {offset} of {file} renamed to {new_name:?}: \
|
||||
the preflight and the workspace refuse in different words"
|
||||
);
|
||||
refused += 1;
|
||||
}
|
||||
(Err(fast), Ok(_)) => panic!(
|
||||
"byte {offset} of {file} renamed to {new_name:?}: the preflight \
|
||||
invented the refusal {fast:?} for a rename the workspace performs"
|
||||
),
|
||||
// The preflight stood aside. Whatever the workspace then says
|
||||
// is today's answer, unchanged — which is the whole contract.
|
||||
(Ok(()), Err(_)) => deferred += 1,
|
||||
(Ok(()), Ok(_)) => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
(refused, deferred)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_preflight_refuses_a_rename_exactly_as_the_workspace_does() {
|
||||
let files = [("sub.sv", SUB), ("top.sv", TOP)];
|
||||
let (refused, _) = rename_oracle(&files, "top.sv");
|
||||
assert!(refused > 0, "the sweep must actually reach the preflight's refusals");
|
||||
rename_oracle(&files, "sub.sv");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_cursor_on_prose_is_refused_from_the_buffer_alone() {
|
||||
// Comments, a string literal, a system task and an attribute: the whole
|
||||
// "there is no symbol to rename at this position" family, which is the
|
||||
// 2,192 ms refusal this preflight exists for.
|
||||
let files = [("prose.sv", PROSE), ("sub.sv", SUB), ("top.sv", TOP)];
|
||||
let (refused, _) = rename_oracle(&files, "prose.sv");
|
||||
assert!(refused > 0);
|
||||
|
||||
// And named exactly, so a reworded refusal cannot hide inside the sweep.
|
||||
let sources = workspace(&files);
|
||||
let path = PathBuf::from("prose.sv");
|
||||
let semantics = analyze(&parse_source_tolerant(PROSE).0, PROSE);
|
||||
for (what, at) in [
|
||||
("a line comment", PROSE.find("a leading line").expect("the comment")),
|
||||
("a block comment", PROSE.find("naming local_net").expect("the comment")),
|
||||
("a string literal", PROSE.find("all in a string").expect("the string")),
|
||||
] {
|
||||
let at = at as u32;
|
||||
let fast = rename_preflight(&semantics, at, "renamed_thing").expect_err(what);
|
||||
assert_eq!(fast, "there is no symbol to rename at this position.", "{what}");
|
||||
assert_eq!(fast, rename(&sources, &path, at, "renamed_thing").expect_err(what), "{what}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unresolved_and_an_inherited_reference_keep_their_own_sentences() {
|
||||
let files = [("stray.sv", STRAY), ("sub.sv", SUB)];
|
||||
rename_oracle(&files, "stray.sv");
|
||||
|
||||
// Which byte carries which refusal is the binder's business, so the
|
||||
// fixture is swept for the two sentences rather than told where they are —
|
||||
// and both must be found, or the fixture has stopped exercising them.
|
||||
let sources = workspace(&files);
|
||||
let path = PathBuf::from("stray.sv");
|
||||
let semantics = analyze(&parse_source_tolerant(STRAY).0, STRAY);
|
||||
let (mut unresolved, mut inherited) = (0usize, 0usize);
|
||||
for at in 0..=STRAY.len() as u32 {
|
||||
let Err(fast) = rename_preflight(&semantics, at, "renamed_thing") else { continue };
|
||||
if fast.contains("is not resolved to any declaration") {
|
||||
unresolved += 1;
|
||||
} else if fast.contains("could only come from the base class") {
|
||||
inherited += 1;
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
let slow = rename(&sources, &path, at, "renamed_thing").expect_err("the same refusal");
|
||||
assert_eq!(fast, slow, "at byte {at} of stray.sv");
|
||||
}
|
||||
assert!(unresolved > 0, "the fixture no longer holds a reference that resolves to nothing");
|
||||
assert!(inherited > 0, "the fixture no longer holds an inherited candidate");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_macro_invocation_and_a_generate_block_keep_parity() {
|
||||
rename_oracle(&[("gen.sv", GEN), ("sub.sv", SUB)], "gen.sv");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_buffer_that_does_not_parse_keeps_parity() {
|
||||
rename_oracle(&[("broken.sv", BROKEN), ("sub.sv", SUB)], "broken.sv");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_package_and_its_qualified_users_keep_parity() {
|
||||
let files = [("pkg.sv", PKG), ("user.sv", USER)];
|
||||
rename_oracle(&files, "user.sv");
|
||||
rename_oracle(&files, "pkg.sv");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_name_declared_in_two_files_stays_on_the_slow_road() {
|
||||
// Two modules called `sub`. The ambiguity is the *index's* answer, and the
|
||||
// index is rebuilt on save, never on a keystroke — so the preflight must
|
||||
// not take this refusal, and the sweep must show it deferring instead.
|
||||
let files = [("a.sv", SUB), ("b.sv", SUB), ("top.sv", TOP)];
|
||||
let (_, deferred) = rename_oracle(&files, "top.sv");
|
||||
assert!(deferred > 0, "the ambiguous declaration must reach the workspace to be refused");
|
||||
|
||||
let sources = workspace(&files);
|
||||
let path = PathBuf::from("top.sv");
|
||||
let semantics = analyze(&parse_source_tolerant(TOP).0, TOP);
|
||||
let at = TOP.find("sub #").expect("the instantiation") as u32;
|
||||
assert!(
|
||||
rename_preflight(&semantics, at, "renamed_thing").is_ok(),
|
||||
"the preflight must stand aside for a name the index answers ambiguously"
|
||||
);
|
||||
assert!(rename(&sources, &path, at, "renamed_thing").is_err(), "and the workspace refuses it");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn renaming_a_symbol_to_the_name_it_already_has_is_refused_from_the_buffer() {
|
||||
let files = [("sub.sv", SUB), ("top.sv", TOP)];
|
||||
let sources = workspace(&files);
|
||||
let path = PathBuf::from("sub.sv");
|
||||
let semantics = analyze(&parse_source_tolerant(SUB).0, SUB);
|
||||
// `local_net` is a declaration inside the module — not at file scope, so
|
||||
// no index question stands between the cursor and this refusal.
|
||||
let at = SUB.find("local_net").expect("the declaration") as u32;
|
||||
let fast = rename_preflight(&semantics, at, "local_net").expect_err("the same name");
|
||||
assert_eq!(fast, "`local_net` is the name it already has.");
|
||||
assert_eq!(fast, rename(&sources, &path, at, "local_net").expect_err("the same name"));
|
||||
|
||||
// A file-scope unit's same-name refusal is the index's to reach, because
|
||||
// the ambiguity check comes first.
|
||||
let at = SUB.find("sub").expect("the module name") as u32;
|
||||
assert!(rename_preflight(&semantics, at, "sub").is_ok(), "deferred, not taken");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_invalid_new_name_outranks_every_cursor_refusal() {
|
||||
// Precedence: `renaming` checks the new name before it builds a scope and
|
||||
// before it looks at the cursor, so a bad name on a cursor that sits on
|
||||
// nothing must produce the *name's* sentence, not the cursor's.
|
||||
let files = [("prose.sv", PROSE), ("sub.sv", SUB)];
|
||||
let sources = workspace(&files);
|
||||
let path = PathBuf::from("prose.sv");
|
||||
let semantics = analyze(&parse_source_tolerant(PROSE).0, PROSE);
|
||||
let at = PROSE.find("a leading line").expect("the comment") as u32;
|
||||
for (name, expected) in [
|
||||
("", "a new name cannot be empty."),
|
||||
("module", "`module` is a Verilog keyword."),
|
||||
("1bad", "`1bad` is not a valid Verilog identifier."),
|
||||
] {
|
||||
let fast = rename_preflight(&semantics, at, name).expect_err(name);
|
||||
assert_eq!(fast, expected, "{name}");
|
||||
assert_eq!(fast, rename(&sources, &path, at, name).expect_err(name), "{name}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_preflight_reads_only_the_buffer_it_was_given() {
|
||||
// The proof behind the gate: resolving a cursor that sits on nothing costs
|
||||
// no whole-file parse at all, however large the workspace around it.
|
||||
let semantics = analyze(&parse_source_tolerant(PROSE).0, PROSE);
|
||||
let at = PROSE.find("a leading line").expect("the comment") as u32;
|
||||
let before = vlog_parser::stats::parses();
|
||||
let refusal = rename_preflight(&semantics, at, "renamed_thing").expect_err("no symbol");
|
||||
assert_eq!(vlog_parser::stats::parses() - before, 0, "the preflight parsed something");
|
||||
assert_eq!(refusal, "there is no symbol to rename at this position.");
|
||||
}
|
||||
@@ -0,0 +1,609 @@
|
||||
# perf5r-preflight — engine-owned refusal preflights
|
||||
|
||||
Take 5 **review** round (`docs/performance_take5_review.md` §3 items 5–6),
|
||||
TODO §61.1, tracker rows **R3a** and the refused-extraction half of **R3c**.
|
||||
Baseline is 0.51.0.
|
||||
|
||||
## Goal
|
||||
|
||||
Two refactorings refuse a request only after materializing and analyzing a
|
||||
workspace they never needed. A `textDocument/rename` on a cursor that sits on
|
||||
no symbol reads all **3 976** in-scope files, performs **3 975 whole-file
|
||||
parses** and spends **1.9 s** building a scope, so that `locate` can refuse in
|
||||
**0.1 ms** from the request buffer's own analysis — 2 192 ms on the wire for a
|
||||
sentence the buffer could have said immediately. An extraction at the review's
|
||||
`aes_wrap.sv` inline site spends **805 ms** building a scope before the checks
|
||||
that refuse it.
|
||||
|
||||
For the rename this lane adds one **additive** function to `vlog_refactor`,
|
||||
`rename_preflight`, which takes — from the request file alone and in the slow
|
||||
road's own order — the refusals the slow road is *certain* to reach in the same
|
||||
words. The server calls it before it selects or analyzes anything, and
|
||||
materializes nothing when it refuses. **Result: 2 012 → 0.3 ms, 3 975 → 0
|
||||
parses.**
|
||||
|
||||
For the extraction the answer is a measured **negative**, and no code shipped.
|
||||
An extract preflight was written, wired and measured, and then removed: every
|
||||
refusal it could take is *already* taken before a scope is built, by two
|
||||
mechanisms that were both already there. The 805 ms refusal is none of them.
|
||||
The evidence is below; this is the review's "instrument first, then decide"
|
||||
answered honestly rather than with code that changes nothing.
|
||||
|
||||
The refusals stay the engine's. That is the review's own condition ("put any
|
||||
cheap preflight in the refactor engine so the server does not become a second
|
||||
authority on what is safe") and it is also the only way the sentences can be
|
||||
guaranteed identical: each one is a single function in `rename/mod.rs` that
|
||||
both roads call.
|
||||
|
||||
**What must not move:** the sentences, their order, the successful edits and
|
||||
their fingerprints, and the warnings. A faster refusal that refuses something
|
||||
else is a failure, and so is a refusal invented for a rename the workspace
|
||||
would have performed.
|
||||
|
||||
## Assumptions
|
||||
|
||||
- **A buffer's `Semantics` is a pure function of its text.** `analyze(&tree,
|
||||
text)` consults no index and no other file, and both roads reach it the same
|
||||
way: the server's `Document::new` calls `analyze` directly, and the scope's
|
||||
`FileFacts::analyzed` calls it through `analyzed_facts`. So the request
|
||||
file's analysis inside a `Scope` and the open buffer's analysis are the same
|
||||
value, and every refusal read off one is the refusal that would be read off
|
||||
the other. *Not enforced by a type* — asserted at every byte of seven
|
||||
fixtures by the oracle below.
|
||||
- **The request file is always among the files the caller hands the engine.**
|
||||
`Scope::locate` refuses a file it was not given *before* it looks at the
|
||||
cursor, so a preflight that jumped that check would reorder the refusals.
|
||||
Both rename selectors put every open buffer in the set. Stated as a
|
||||
precondition in the preflight's doc comment and pinned by
|
||||
`the_preflights_refusal_is_the_whole_workspaces_refusal`.
|
||||
- **A large-file buffer never reaches the rename preflight.** On the fast path
|
||||
every field but the text is the analysis of the *empty* file, so a preflight
|
||||
over it would refuse every cursor as symbolless. `server/large_file.rs`
|
||||
answers `textDocument/rename` with `TOO_LARGE` before this module is
|
||||
reached; `a_large_buffer_is_refused_before_the_preflight_could_see_it` pins
|
||||
both halves of that — the gate, and the fact that the preflight would
|
||||
otherwise be wrong, so the test fails loudly if the gate is ever moved.
|
||||
- **The workspace index is not current with respect to unsaved edits.** See
|
||||
the duplicate-declaration decision below; this is the load-bearing
|
||||
assumption of the whole lane, and it is the reason two refusals stayed on the
|
||||
slow road.
|
||||
|
||||
## Handshakes
|
||||
|
||||
**Consumed.**
|
||||
|
||||
- `vlog_semantic::Semantics` — `reference_id_at`, `reference`, `symbol_at`,
|
||||
`symbol`, `file_scope`, and `Resolution`'s four variants. The preflight reads
|
||||
exactly the fields `Scope::locate` reads, and nothing else.
|
||||
- `crate::state::Document`'s `semantics` — read, never written.
|
||||
|
||||
**Promised.**
|
||||
|
||||
- `vlog_refactor::rename_preflight(semantics, offset, new_name) -> Result<(),
|
||||
String>`. **Additive**: no existing signature changed, no existing behaviour
|
||||
changed, and `Ok(())` means "proceed exactly as before" — never "this rename
|
||||
will succeed". It is the only new public item in the crate; the extraction
|
||||
gained none.
|
||||
- Every refusal the preflight makes is byte-identical to the one `rename` makes
|
||||
for the same request. This is the contract; the oracle is its proof.
|
||||
- The `--verbose` `timing: rename trace` line is still written for a rename
|
||||
the preflight refuses, with `selected=0`, `parses=0` and a new
|
||||
`preflight=true` field. `tools/perf/phases_p2.py` reads that line by regex
|
||||
and flattens every `key=value` into a row field, so the new field arrives as
|
||||
`preflight` with no harness change.
|
||||
|
||||
**Requested of others: none.** No file outside this lane's list was touched.
|
||||
|
||||
**Amended for `docs/topo.md` (lead to apply).** §1.2's request-selector parity
|
||||
gains a third participant. Today it reads that `prepare_rename_here` must
|
||||
produce the same answer or refusal text as whole-scope `prepare_rename`. It
|
||||
should now also record that `rename_preflight` must produce the same *refusal*
|
||||
text as whole-scope `rename` — a one-directional obligation, since the
|
||||
preflight may always stand aside — and that the two cheap paths are
|
||||
deliberately **not** the same set: `prepare_rename_here` reads the index and
|
||||
`rename_preflight` does not. The reason is in "the duplicate-declaration
|
||||
decision" below.
|
||||
|
||||
## The duplicate-declaration decision — evidence, and the answer
|
||||
|
||||
TODO §61.1 asks whether the ambiguous-declaration refusal (`rstmgr_por`,
|
||||
2 200 ms) may move ahead of materialization "ONLY with the evidence the review
|
||||
asks for: the index is current and authoritative for that name".
|
||||
|
||||
**It is not, and the refusal stays on the slow road.** The evidence:
|
||||
|
||||
1. `state/mod.rs::set_document` (line 695) — the handler for every `didOpen`
|
||||
and `didChange` — *reads* `self.index` to build the new `Document`'s
|
||||
external overlay and never writes it. The index is written only by
|
||||
`absorb`, at scan publication and on the `didSave` rebuild. So an unsaved
|
||||
buffer that adds or removes a file-scope declaration of a name is a buffer
|
||||
whose `index.units(name).len()` is stale, in both directions.
|
||||
2. `docs/features/refactor-rename/README.md` already states this exact
|
||||
divergence ("The one divergence, stated exactly") for
|
||||
`prepare_rename_here`, and resolves it by naming the authority: *"`rename`
|
||||
re-derives the count from the current texts and is the authority."*
|
||||
3. So the two callers are not symmetric, and the asymmetry is the whole point.
|
||||
An optimistic `prepareRename` that is wrong is LSP-legal and self-correcting
|
||||
— the rename that follows delivers the real answer. A `rename` that is wrong
|
||||
is terminal: the user is told a name is declared twice, and there is no
|
||||
later road to say otherwise. Moving this refusal forward would trade a
|
||||
correct 2 200 ms answer for a possibly-wrong 15 ms one.
|
||||
4. The ports offer's `declared_twice` (`ports.rs:338`) does trust the index,
|
||||
and that is consistent rather than contradictory: a wrong *offer* costs a
|
||||
lightbulb that should or should not have appeared, and the command behind it
|
||||
still asks the engine. A wrong *refusal* costs the work itself.
|
||||
|
||||
The same argument disposes of the two cross-file cursor refusals — a use whose
|
||||
declaration the index answers ambiguously, and one it cannot answer at all
|
||||
(`ExternalTarget::Ambiguous` / `StillUnresolved`). Both are the index's word,
|
||||
so `rename_preflight` stands aside for every `Resolution::ExternalCandidate`
|
||||
and for every declaration at file scope.
|
||||
`a_name_declared_in_two_files_stays_on_the_slow_road` asserts the deferral
|
||||
rather than merely permitting it, so a later round cannot quietly take it.
|
||||
|
||||
The cost of the decision is stated plainly: **`rstmgr_por` keeps its 2 200 ms**,
|
||||
and so does `cipher_alert → clk_i` at 2 884 ms, whose "meaning would change"
|
||||
refusal is `check::verify`'s and needs the edit computed over the real scope.
|
||||
|
||||
## What the preflight takes, and what it leaves
|
||||
|
||||
### `rename_preflight` — `crates/vlog_refactor/src/rename/preflight.rs`
|
||||
|
||||
In `renaming`'s order. Rule numbers are
|
||||
`docs/features/refactor-rename/README.md`'s refusal list.
|
||||
|
||||
| Rule | Refusal | Taken? | Why |
|
||||
|---|---|---|---|
|
||||
| 1 | new name empty / not an identifier / a keyword | **taken** | `check_new_name` is a pure function of the new name, and is `renaming`'s own first statement |
|
||||
| 3 | *"… is not one of the files lucisv indexes …"* | n/a | unreachable: both selectors contain the request buffer (precondition above) |
|
||||
| 4 | *"there is no symbol to rename at this position."* | **taken** | `reference_id_at` and `symbol_at` on the buffer — the 2 192 ms row |
|
||||
| 5 | *"… is not resolved to any declaration …"* | **taken** | `Resolution::NotFound` is single-file resolution |
|
||||
| 6 | *"… could only come from the base class `B` …"* | **taken** | `Resolution::InheritedCandidate`, same |
|
||||
| 7 | *"… is declared outside the files lucisv indexes …"* | deferred | the index's word |
|
||||
| 8 | *"… is declared in more than one indexed file …"* (from a use) | deferred | the index's word |
|
||||
| 9 | the same sentence, from a file-scope declaration | deferred | the index's word — the decision above |
|
||||
| 11a | *"lucisv cannot find where `x` is spelled …"*, declaration in this buffer | **taken** | empty `name_span`, read here |
|
||||
| 11b | the same, declaration elsewhere | deferred | needs that file's text |
|
||||
| 2 | *"`x` is the name it already has."* | **taken, narrowly** | only for a declaration in this buffer that is **not** at file scope, where nothing stands between the cursor and this check. At file scope rule 9 comes first, so it is deferred |
|
||||
| 10, 12, 13 | ambiguous use onto this declaration, capture, token drift | deferred | all need the edit computed over the scope |
|
||||
|
||||
Note rule 2's narrowing: taking it unconditionally would let a same-name
|
||||
refusal jump ahead of rule 9's ambiguity check and change which sentence the
|
||||
user sees.
|
||||
`renaming_a_symbol_to_the_name_it_already_has_is_refused_from_the_buffer`
|
||||
pins both halves — taken for a net, deferred for a module.
|
||||
### The extraction — a preflight was written, measured, and removed
|
||||
|
||||
The same preflight was built for `extract_module`: `plain_identifier`, the
|
||||
occupied-target check, the request file's parse-diagnostic refusal, and every
|
||||
refusal `Region::read` knows, stopping before `declared_once`. It was wired
|
||||
into `extract::execute` ahead of `Scope::build`, measured, and then **deleted**,
|
||||
because every one of those refusals is already reached before a scope exists:
|
||||
|
||||
1. **`site_at` is `extract_site_in`.** `execute` calls it as its own gate,
|
||||
before `module_sources` and before the engine. Its first two statements are
|
||||
`if !diagnostics.is_empty() { return None }` and
|
||||
`Region::read(tree, text, …).ok()?`. So a buffer that does not parse and
|
||||
every selection-shape refusal are answered by the server with `NOTHING`, and
|
||||
**cannot reach `Extraction::plan` at all** — the preflight's parse check and
|
||||
its `Region::read` were provably dead on the only caller.
|
||||
2. **`plain_identifier` and the occupied check are already `extract_module`'s
|
||||
first two statements**, ahead of `Extraction::plan` and therefore ahead of
|
||||
`Scope::build`. Moving them earlier moves nothing.
|
||||
|
||||
Measured, at the 805 ms site itself (`extractrefuse`, both cases below):
|
||||
|
||||
| Row | 0.51.0 | with preflight | Where it is refused |
|
||||
|---|---:|---:|---|
|
||||
| new name is not an identifier | 9.3 ms | 9.8 ms | `extract_module`'s first statement, in **both** |
|
||||
| selection covers no whole item | 0.22 ms | 0.13 ms | the server's `site_at` gate, in **both** |
|
||||
|
||||
Both sub-noise, both refused pre-scope in the reference already. The preflight
|
||||
bought nothing, so it is not in the tree: shipping it would have been ~130
|
||||
lines of engine code, a new public API and a second copy of two checks, in
|
||||
exchange for zero measured work. `crates/lucisv_server/src/extract.rs` carries
|
||||
a comment at the point where it would have gone, saying why there is nothing
|
||||
there — so the next round does not rediscover this.
|
||||
|
||||
What **did** stay from the exercise: `extract::does_not_parse`, the refusal
|
||||
sentence lifted out of `Extraction::plan` into the block where
|
||||
`extract/mod.rs` keeps its other refusal sentences (`occupied`,
|
||||
`not_in_scope`, `escaped`), and three server tests that pin where each cheap
|
||||
extract refusal is actually taken.
|
||||
|
||||
## What the `aes_wrap.sv` 805 ms refusal turned out to be
|
||||
|
||||
Identified from the review's own evidence without a run
|
||||
(`docs/perf/take5-review-20260908/results.jsonl`, the `inline-module: lucisv:
|
||||
extract selection into module…` row), then confirmed by the paired rerun. Its
|
||||
message is:
|
||||
|
||||
> the selection drives `h2d_intg`, and something outside it passes the same
|
||||
> name to a task or function, which may drive it too; lucisv will not make it
|
||||
> an output over that.
|
||||
|
||||
That sentence is `extract/boundary.rs:196`, inside `Crossing::read` — the
|
||||
**last** stage of `plan` before rendering. `Crossing::read` needs `flow`, and
|
||||
`flow::read(&scope, …)` walks the module's items *through the scope*, because
|
||||
giving an instance-port connection its direction means reading the instantiated
|
||||
module's own file. So the refusal is **scope-dependent at depth**, not
|
||||
region-local, and no bounded preflight reaches it.
|
||||
|
||||
Measured unchanged, as predicted: **761.1 → 767.8 ms** (+0.9%, within the
|
||||
session's noise), identical sentence.
|
||||
|
||||
What a future round could take is named instead, since the review asked for it:
|
||||
the directions `flow` wants are port facts the workspace index already holds,
|
||||
so the lever is not a preflight but the scope-reuse work already filed as
|
||||
§61.5 (R3b/R3c). Recorded as a finding and **not attempted here** — the
|
||||
review's instruction was to instrument first and "do not implement beyond the
|
||||
region-local checks without the evidence", and the evidence says the
|
||||
region-local checks were already free.
|
||||
## Status / TODO
|
||||
|
||||
- [x] `rename_preflight`, additive, engine-owned, in `renaming`'s order
|
||||
- [x] the server calls it before selecting sources; nothing materializes on a
|
||||
refusal; the sentence goes back unchanged
|
||||
- [x] the duplicate-declaration question answered **with evidence** — deferred,
|
||||
argument recorded above
|
||||
- [x] extract: the region-local checks confirmed to run before `Scope::build`
|
||||
**already**, by `site_at` and by `extract_module`'s own prefix; a
|
||||
preflight was written, measured and removed as redundant
|
||||
- [x] the equality oracle: every byte of seven fixtures × six new names
|
||||
- [x] the parse-count proof: a no-symbol rename performs **zero** whole-file
|
||||
parses, asserted in a test and read off the wire trace
|
||||
- [x] the `aes_wrap.sv` refusal identified, its stage named, measured unchanged
|
||||
- [x] measured against 0.51.0; R3a and R3c cells filled
|
||||
|
||||
## Measurements — 0.51.0 vs candidate
|
||||
|
||||
Paired, `~/.cache/lucisv-perf/take5r-1/`. Repeat medians (`ms[1:]`), three
|
||||
repeats after a first. Reference and candidate order alternated between
|
||||
phases; load 1.7–4.8 throughout, inside the review's own 2.82–6.00 band.
|
||||
|
||||
| Phase / row | 0.51.0 | candidate | Δ | parses | peak RSS |
|
||||
|---|---:|---:|---:|---|---|
|
||||
| renametrace **no symbol** | 2 012.3 ms | **0.3 ms** | **−100.0%** | **3 975 → 0** | 909 → 429 MiB |
|
||||
| renametrace duplicate module `rstmgr_por` | 2 012.6 | 2 032.0 | +1.0% | 3 975 → 3 975 | 910 → 914 MiB |
|
||||
| renametrace common port `clk_i` | 3 242.4 | 3 252.7 | +0.3% | 3 977 → 3 977 | 1 827 → 1 826 MiB |
|
||||
| renametrace `cipher_alert → clk_i` | 2 626.4 | 2 730.1 | +3.9% | unchanged | 1 609 → 1 610 MiB |
|
||||
| renametrace conflict `state_q → state_d` | 305.9 | 319.3 | +4.4% | unchanged | 530 → 539 MiB |
|
||||
| renametrace tail `state_q` | 367.3 | 365.0 | −0.6% | unchanged | 611 → 659 MiB |
|
||||
| renametrace ordinary `aes` | 84.9 | 85.2 | +0.4% | unchanged | 454 → 455 MiB |
|
||||
| renametrace unique internal `cipher_alert` | 15.5 | 17.2 | +11.0% | unchanged | 434 → 433 MiB |
|
||||
| tailrename | 376.3 | 377.4 | +0.3% | — | — |
|
||||
| rename `aes → aes_renamed` | 87.6 | 88.1 | +0.6% | — | — |
|
||||
| rename prepareRename | 0.11 | 0.17 | sub-ms, not read | — | — |
|
||||
| execute extract capture (`aes.sv`) | 143.5 | 143.3 | −0.1% | — | — |
|
||||
| execute **extract refusal** (`aes_wrap.sv`) | 761.1 | 767.8 | +0.9% | — | — |
|
||||
| execute inline refusal | 5.79 | 5.85 | +1.0% | — | — |
|
||||
| refactor extract offer | 0.81 | 0.80 | −1.2% | — | — |
|
||||
| extractrefuse bad name | 9.3 | 9.8 | already pre-scope | — | — |
|
||||
| extractrefuse partial selection | 0.22 | 0.13 | refused by `site_at` in both | — | — |
|
||||
|
||||
**Gates.** R3a's gate — *"≤16 ms; zero closed-workspace parses; exact
|
||||
refusal/precedence"* — is **met on all three counts**: 0.3 ms (53× inside the
|
||||
bound), `trace_parses` 0 and `trace_selected` 0 read off the wire, and the
|
||||
refusal string byte-identical. The duplicate-module refusal was **not** shipped
|
||||
and its row is unchanged, as the decision above requires. The extract refusal's
|
||||
before/after is reported with its stage named and is **unchanged**, which is
|
||||
the honest reading of R3c's extract half.
|
||||
|
||||
**Parity.** Every fingerprint identical: tail `b39defb21265…`, `aes`
|
||||
`fa7e31c78382…`, `clk_i` `31aadc134628…`, `cipher_alert` `5f53e977da59…`,
|
||||
extraction `090e92e7736e…`. Every refusal message identical (checked
|
||||
programmatically, not by eye). Corpus `git status --porcelain` = the same three
|
||||
pre-existing files after every one of the 12 phase invocations. **No guard
|
||||
kill.**
|
||||
|
||||
**Variability.** The +3.9% and +4.4% rows are single-session medians on a
|
||||
desktop machine and are within the band the review itself declines to read;
|
||||
+11.0% is on a 15.5 ms row (1.7 ms). None is a claimed movement, and none is
|
||||
adjusted.
|
||||
|
||||
## Work log
|
||||
|
||||
**2026-09-08 — dev (Opus).**
|
||||
|
||||
- Read the code before designing. Three findings changed the plan the brief
|
||||
proposed:
|
||||
1. **The brief's premise that `set_document` updates the index is wrong** —
|
||||
it reads the index and does not touch it (`state/mod.rs:695`). That
|
||||
inverted the duplicate-declaration answer from "probably yes" to a
|
||||
documented no, argued above.
|
||||
2. **`new_name == module` is not the last region-local check in `plan`** —
|
||||
`declared_once` and `undeclared` precede it. It could not go in a
|
||||
preflight without reordering two refusals.
|
||||
3. **The `aes_wrap.sv` refusal is `Crossing::read`'s**, four stages past
|
||||
anything a region-local preflight can reach. Identified from the review's
|
||||
preserved `results.jsonl` message rather than by a run, which cost nothing
|
||||
and settled the design before any code was written.
|
||||
- **Signature deviation, rename.** The brief proposed `rename_preflight(semantics,
|
||||
external, index, offset, new_name)`. Shipped without `external` and `index`:
|
||||
every refusal those two could answer is one the staleness argument forbids
|
||||
taking, so both parameters would have been unused — and carrying them would
|
||||
have implied the preflight consults the index, which is exactly the thing it
|
||||
must not do. `prepare_rename_here` keeps them, because an optimistic
|
||||
`prepareRename` is allowed to.
|
||||
- **The extract preflight was built, then removed.** It was written to the
|
||||
brief (taking `files` rather than a server-computed `occupied` bool, so the
|
||||
occupied question stayed the engine's), wired into `execute` ahead of
|
||||
`Scope::build`, and covered by eight oracle tests. Measuring it is what
|
||||
killed it: `tools/perf/phases_r3.py` was added to time the refusals it takes
|
||||
at the 805 ms site, and both came back unchanged — because `site_at` **is**
|
||||
`extract_site_in`, whose first two statements are the parse-diagnostic check
|
||||
and `Region::read`, and because `plain_identifier` and the occupied check
|
||||
were already `extract_module`'s own first statements. Removed rather than
|
||||
shipped: ~130 lines of engine code and a new public API for zero measured
|
||||
work is exactly the abstraction CLAUDE.md says to stop building. The reason
|
||||
is now a comment at the call site so it is not rediscovered.
|
||||
- **A refusal now traces too.** `rename_traced` writes its `timing:` line on
|
||||
the preflight path with `selected=0 parses=0 preflight=true`, so the
|
||||
measurement reads the parse count off the wire instead of trusting it. No
|
||||
change to `rename_trace.rs` was needed — `SelectionTrace` already derives
|
||||
`Default`, and `whole_scope` was the wrong shape (it sets `fallback=true`,
|
||||
which would have been a lie).
|
||||
- One incidental tidy kept: `extract::does_not_parse`, the parse refusal's
|
||||
sentence moved out of `Extraction::plan` into the block where
|
||||
`extract/mod.rs` already keeps `occupied`, `not_in_scope` and `escaped`.
|
||||
Behaviour identical; it is the only surviving trace of the removed preflight
|
||||
in that file.
|
||||
- Tests: `crates/vlog_refactor/tests/preflight_oracle.rs` (10), 4 added in
|
||||
`lucisv_server/src/rename.rs`, 3 in `lucisv_server/src/extract.rs` (kept
|
||||
after the removal — they pin *where* each cheap extract refusal is taken,
|
||||
which is the finding). The oracle counts deferrals rather than asserting them
|
||||
away, and a fixture that stops producing the shape it was written for fails
|
||||
loudly: `an_unresolved_and_an_inherited_reference_keep_their_own_sentences`
|
||||
sweeps for its two sentences instead of being told their offsets, because
|
||||
the first draft guessed an offset and was wrong.
|
||||
- Harness: `tools/perf/phases_r3.py` (new, phase `extractrefuse`) and one
|
||||
import line in `tools/perf/bench.py`. It is kept even though its answer was
|
||||
negative — the two rows are what make "the extract refusals are already
|
||||
pre-scope" a measurement rather than a claim.
|
||||
- File sizes after the change: `rename/mod.rs` 549, `rename/preflight.rs` 84,
|
||||
`extract/mod.rs` 535 — all under 600. The rename preflight went in a module
|
||||
of its own because `rename/mod.rs` was already within 60 lines of the mark.
|
||||
- Gates: `cargo fmt` clean; guarded `cargo clippy --all-targets` clean with no
|
||||
new `#[allow]`; guarded `cargo test --workspace` **4 322 passed, 0 failed**,
|
||||
exit 0, no guard kill. Zero tests removed (`git diff` shows no deleted
|
||||
`#[test]` in a tracked file), 17 added. (Corrected from "4 328" by QA —
|
||||
see QA log: a clean guarded run on this exact tree counts 4 322, matching
|
||||
a same-tree baseline of 4 305 plus the 17 added exactly.)
|
||||
|
||||
## QA log
|
||||
|
||||
**2026-09-08 — QA (Sonnet).** Verdict: **PASS.** Method: read `renaming` /
|
||||
`Scope::locate` / `Scope::declaration` / `Scope::declaration_across_files`
|
||||
(`rename/mod.rs`) side by side with `rename_preflight` / `declared_here`
|
||||
(`rename/preflight.rs`) and built the rule table below independently before
|
||||
reading the dev's own table, then attacked the oracle with sabotage in a
|
||||
throwaway clone, ran the gates guarded on the main tree, and re-ran the real
|
||||
`lucisv-server` over the wire (fresh sessions, my own storage dir, no reuse of
|
||||
the dev's cached results except for cross-referencing) against OpenTitan and
|
||||
read the wire traces.
|
||||
|
||||
**1. Gates, guarded, main tree.**
|
||||
`cargo fmt --all -- --check`: clean. `cargo clippy --all-targets`: clean, zero
|
||||
new `#[allow]` (`git diff HEAD | grep '#\[allow'` finds none in changed code).
|
||||
`cargo test --workspace` (guarded, `tools/guard.sh -m 8 -t 1800`): **4 322
|
||||
passed, 0 failed**, no guard kill. Cross-checked against a clone of `e13ae4c`
|
||||
with *no* diff applied, same guard, same machine window: **4 305 passed, 0
|
||||
failed**. 4 322 − 4 305 = **17**, matching the diff's added-test count exactly
|
||||
(`git diff HEAD | grep -c '^+.*#\[test\]'` → 7 in tracked files, plus the 10 in
|
||||
the new `preflight_oracle.rs` = 17; `git diff HEAD | grep -c '^-.*#\[test\]'` →
|
||||
0). **Nothing lost, nothing invented.** Found and fixed a documentation slip:
|
||||
the work log's "4 328 passed" does not reproduce on this tree in either of two
|
||||
independent guarded runs (main tree and a fresh clone); corrected above to
|
||||
4 322 with the arithmetic that supports it. Production line counts of
|
||||
changed/new files (non-blank, non-line-comment): `rename/mod.rs` 400 (551
|
||||
total), `rename/preflight.rs` 31 (84 total), `extract/mod.rs` 396 (539 total)
|
||||
— all comfortably under the 600-line mark by either counting convention; the
|
||||
dev's own 549/84/535 use the total-lines-minus-tests convention CLAUDE.md's
|
||||
own history entries use, and agree.
|
||||
|
||||
**2. The precedence contract — rule table, built independently.**
|
||||
|
||||
Read top to bottom: `renaming` calls `check_new_name` (rule 1) before
|
||||
`Scope::build_keeping` (the whole-workspace materialization this lane exists
|
||||
to skip), then `scope.locate` (rules 3–9, 11), then — *after* `locate`
|
||||
returns `Ok` — the same-name check (rule 2), then `collect_edits`/`verify`
|
||||
(rules 10, 12, 13). `Scope::declaration` (reached from both a same-file symbol
|
||||
and a cross-file `declaration_across_files`) checks `name_span.is_empty()`
|
||||
(rule 11) **before** `at_file_scope && index.units(name).len() > 1` (rule 9)
|
||||
— that specific order is the whole reason rule 2's preflight narrowing is
|
||||
sound only for non-file-scope declarations.
|
||||
|
||||
| Rule | Refusal | Preflight takes it? | Can preflight's answer differ from `renaming`'s for the same request? |
|
||||
|---|---|---|---|
|
||||
| 1 | invalid new name | yes (`check_new_name`, byte-identical shared fn) | no — same function, same first statement in both roads |
|
||||
| 3 | file not in scope | n/a, unreachable (precondition: request buffer always in both selectors' file sets) | no |
|
||||
| 4 | no symbol here | yes (`reference_id_at`/`symbol_at` on the buffer) | no — same `Semantics`, pure fn of buffer text |
|
||||
| 5 | unresolved reference | yes (`Resolution::NotFound`) | no — single-file resolution, same `Semantics` |
|
||||
| 6 | inherited-candidate reference | yes (`Resolution::InheritedCandidate`) | no — resolved entirely within the buffer's own analysis regardless of which file the base class lives in |
|
||||
| 7, 8 | external candidate: unresolved / ambiguous (from a use) | deferred (`Ok(())` for every `ExternalCandidate`) | n/a — never taken, so never differs |
|
||||
| 9 | file-scope declaration, ambiguous in index | deferred (`declared_here` returns `Ok(())` when `scope == file_scope`, **before** the same-name check) | n/a |
|
||||
| 11a | empty `name_span`, declaration in this buffer | yes, and correctly checked **before** the file-scope test, exactly matching `Scope::declaration`'s order — so it is taken even for a file-scope declaration | no |
|
||||
| 11b | empty `name_span`, declaration elsewhere | deferred (preflight never resolves cross-file) | n/a |
|
||||
| 2 | same name as new name | yes, **only** when `scope != file_scope` (checked after 11a, after the file-scope deferral) | no for the cases it takes; for a file-scope same-name it correctly stands aside so rule 9 keeps precedence on the slow road |
|
||||
| 10, 12, 13 | ambiguous-onto/capture/token drift | deferred (need computed edits) | n/a |
|
||||
|
||||
This matches `docs/features/perf5r-preflight/README.md`'s own table exactly,
|
||||
built before I read it. The one place a bug could hide — rule 11a's precedence
|
||||
over rule 9 for a file-scope declaration — is real and correctly ordered in
|
||||
both `declared_here` and `Scope::declaration`; confirmed by reading, not
|
||||
assumed.
|
||||
|
||||
**3. Wire matrix, a–j.** Both a hostile-fixture sweep (the oracle, byte-by-byte)
|
||||
and real OpenTitan sessions over the wire (fresh `lucisv-server` process, my
|
||||
own `--storage`, none of the dev's cached results reused for this half):
|
||||
|
||||
| Case | Verified how | Old vs new |
|
||||
|---|---|---|
|
||||
| (a) invalid name (`1abc`,`wire`,`a b`,empty) at no-symbol cursor | `an_invalid_new_name_outranks_every_cursor_refusal` (oracle) + `the_preflight_does_not_disturb_the_refusal_order` (server) | identical — name's sentence wins, rule 1 before rule 4 |
|
||||
| (b) comment/string/whitespace/macro-arg/`` `define``/keyword cursor | oracle's `PROSE`/`GEN` fixtures swept at every byte; `the_preflights_refusal_is_the_whole_workspaces_refusal` pins the `module` keyword explicitly | identical, `NOTHING_HERE` in both roads |
|
||||
| (c) unresolved reference | `an_unresolved_and_an_inherited_reference_keep_their_own_sentences`, swept for the sentence rather than told an offset | identical |
|
||||
| (d) inherited-candidate via `extends` (base in another file) | same test/fixture (`STRAY`); confirmed by reading that `Resolution::InheritedCandidate` is settled entirely inside the request buffer's own analysis regardless of which file the base lives in — the resolution *type* itself already encodes "unresolved candidate", not "resolved to a symbol in file X" | identical |
|
||||
| (e) same-name at non-file-scope (local net) vs file-scope (module) | `renaming_a_symbol_to_the_name_it_already_has_is_refused_from_the_buffer` — pins **both** halves directly | net: taken, identical sentence. module: **deferred**, confirmed `rename_preflight(...).is_ok()`, and the slow road's answer is the unchanged `already_named()` string (only the sentence's *construction* was refactored into a shared fn, not its text or its position after `locate`) |
|
||||
| (f) duplicate module (`rstmgr_por`) | `a_name_declared_in_two_files_stays_on_the_slow_road` + live re-run: real server, real OpenTitan — refused with *"`rstmgr_por` is declared in more than one indexed file; lucisv will not guess which declaration this rename means."*, `trace_parses_index=3975` (unchanged), no `preflight` field | identical, unchanged parse count |
|
||||
| (g) unsaved (`untitled:`) buffer | `the_preflight_does_not_disturb_the_refusal_order`; and by reading `rename_traced`'s own source — the `UNSAVED` checks (`ws.document`, then `doc.path`) run and can early-return **before** the preflight call is reached | identical, unchanged order |
|
||||
| (h) large-file buffer | read `server/dispatch.rs:83` (`large_file_answer` runs first, unconditionally, ahead of the method dispatch that would call `rename_traced`) and `server/large_file.rs:80` (`Rename::METHOD => Err(... TOO_LARGE ...)`) — the preflight is provably never reached; `a_large_buffer_is_refused_before_the_preflight_could_see_it` pins that the preflight *would* have been wrong if it were reached, which is exactly why the gate must stay in front of it | unaffected by this diff; still TOO_LARGE before either road runs |
|
||||
| (i) reference to a symbol declared in another file | `Resolution::ExternalCandidate => Ok(())` read directly; live re-run's `ordinary: aes -> aes_renamed` row (an `aes` instantiation reference) completed the whole-scope path normally, fingerprint `fa7e31c78382…` unchanged | `Ok` from preflight, whole-scope path runs, unchanged |
|
||||
| (j) empty `name_span` in this buffer (rule 11a) | read `declared_here`'s first check, ahead of the file-scope test; oracle sweeps `SUB`/`TOP`/`GEN` at every byte, which would surface an unspelled-declaration mismatch if one existed in the fixtures — none constructed with a literally empty span beyond what the parser already produces on malformed input, covered indirectly by `a_buffer_that_does_not_parse_keeps_parity` | code-path identical to `Scope::declaration`'s own check; no divergence found |
|
||||
|
||||
Every case in the wire re-run returned the **same sentence text** as the
|
||||
tracker's own evidence (`~/.cache/lucisv-perf/take5r-1/results.jsonl`), which
|
||||
I cross-checked field by field (see §5).
|
||||
|
||||
**4. Oracle sabotage.** In a throwaway clone
|
||||
(`.../scratchpad/qa-61-1/sabotage-clone`, cloned from `e13ae4c` with the
|
||||
working-tree diff applied via `git apply` + copying the four untracked new
|
||||
files — diffed byte-identical against the real tree before use):
|
||||
|
||||
- **Sabotage 1** — made the `Resolution::Resolved` arm of `rename_preflight`
|
||||
return `Err(NOTHING_HERE.to_string())` unconditionally instead of calling
|
||||
`declared_here` (an invented refusal for a resolved reference). Result:
|
||||
`cargo test -p vlog_refactor --test preflight_oracle` — **3 of 10 tests
|
||||
fail**, each panicking with *"the preflight invented the refusal ... for a
|
||||
rename the workspace performs"*, exactly the failure mode the oracle's own
|
||||
doc comment promises.
|
||||
- **Sabotage 2** — changed only the *wording* of the same-name refusal inside
|
||||
`declared_here` (`` `{new_name}` already is the name it has.`` instead of
|
||||
the shared `already_named()`'s `` `{new_name}` is the name it already
|
||||
has.``), leaving the slow road's sentence untouched. Result: **8 of 10
|
||||
tests fail** with *"the preflight and the workspace refuse in different
|
||||
words"* and the two strings printed side by side.
|
||||
|
||||
Both sabotages caught decisively, restored, and the clone diffed clean against
|
||||
the real preflight.rs afterward. This is real evidence the oracle does what
|
||||
its doc comment claims, not an assumption from reading it.
|
||||
|
||||
**5. Parse count and traceability.** `a_rename_on_a_cursor_with_no_symbol_
|
||||
parses_nothing` reads `vlog_parser::stats::parses()` before/after and asserts
|
||||
the **difference** is `0` — not a hard-coded literal — and separately asserts
|
||||
the `--verbose` trace line contains `selected=0`, `parses=0`, `preflight=true`
|
||||
by substring, so a regression that made the count right but the trace wrong
|
||||
would still fail. My own fresh wire re-run (guarded, real server, real
|
||||
OpenTitan, fresh session, `--tries 1`) reproduces this independent of the
|
||||
dev's logged run: no-symbol **0.248 ms**, `parses=0`, `selected=0`,
|
||||
`preflight=true`, sentence *"there is no symbol to rename at this
|
||||
position."*; `rstmgr_por` (duplicate module) **2 120–2 153 ms**,
|
||||
`parses_index=3975`, `selected=3976` — unchanged; `clk_i` (common port)
|
||||
**~3.4 s**, `parses_index=3975`, `fallback=true` — unchanged. All twelve
|
||||
numbers named in the tracker's R3a/R3c-x records (no-symbol 2 012.3→0.34,
|
||||
duplicate-module 2 012.6→2 032.0, common-port 3 242.4→3 252.7, tail
|
||||
367.3→365.0, plus the five fingerprints) were located verbatim in
|
||||
`~/.cache/lucisv-perf/take5r-1/results.jsonl`/`results2.jsonl` by field
|
||||
(`row`, `server`, `ms`, `fingerprint`, `trace_parses`, `trace_selected`) —
|
||||
traceability item 8 satisfied.
|
||||
|
||||
**6. The extract decision.** Read `lucisv_server/src/extract.rs::execute`:
|
||||
`site_at` is called and, for a non-large buffer, **is**
|
||||
`vlog_refactor::extract_site_in`, whose first two statements are the
|
||||
parse-diagnostic check (`if !diagnostics.is_empty() { return None }`) and
|
||||
`Region::read(...).ok()?` — confirmed at
|
||||
`crates/vlog_refactor/src/extract/mod.rs:99-103`, called *before*
|
||||
`ws.module_sources` (workspace materialization). Read `extract_module`
|
||||
(same file, line 131): `plain_identifier(new_name)?` is its first statement
|
||||
and the occupied-target check is its second, both ahead of
|
||||
`Extraction::plan` → `Scope::build`. Live re-run of the `extractrefuse` phase:
|
||||
bad-name refusal **12.7 ms**, partial-selection refusal **0.05 ms** — both
|
||||
already pre-scope in the reference too, consistent with "no work to remove."
|
||||
Live re-run of `execute`'s `aes_wrap.sv` inline-site row: refused at
|
||||
**757.6 ms** with the sentence *"the selection drives `h2d_intg`, and
|
||||
something outside it passes the same name to a task or function ... lucisv
|
||||
will not make it an output over that."* — matches `boundary.rs`'s `direction`
|
||||
function (the sentence text found at that exact location), which needs
|
||||
`sides: flow::Sides` from `flow::read(&scope, ...)`, confirming the refusal is
|
||||
genuinely scope-dependent and unreachable from a region-local preflight. `aes.sv`
|
||||
extract-capture fingerprint from the live re-run's `execute` output matched
|
||||
`090e92e7736e…` (the `090e92e7736e0a5a93557d75befa65a5bea0c2f44494d71dc67e3f8d70d05835`
|
||||
row in the JSONL). No sabotage was needed here since no production code
|
||||
shipped from this half — verified the claim by reading the removed-preflight's
|
||||
would-be call sites instead, which is what the task asked for.
|
||||
|
||||
**7. Trace-line / RequestFailed check.** Read `server/dispatch.rs`'s
|
||||
`Rename::METHOD` arm: `trace` is always populated by `rename_traced` (both
|
||||
roads), but `self.timing(...)` — the only place a `preflight=true` line
|
||||
reaches any output — fires only under `if let (true, Some(line)) =
|
||||
(self.verbose, trace)`. Every `Err` outcome, preflight or slow-road, becomes
|
||||
`Failure::Request(message)` → `lsp_server::ErrorCode::RequestFailed` with text
|
||||
`"lucisv: {message}"` (`dispatch.rs:598-599`) — never a result value. Matches
|
||||
the task's item 6 exactly.
|
||||
|
||||
**8. Re-measured cells.** Fresh, guarded, real-server sessions on this exact
|
||||
candidate binary (sha256 `5f815542ac16854acb77f545805378324e0025eaaf48662f28bcc8ae8b6ebdb9`,
|
||||
matching the tracker's own recorded candidate hash — **no rebuild needed**,
|
||||
confirmed identical before use) against OpenTitan, `--tries 1` (a lighter
|
||||
re-measurement than the dev's 3-repeat sessions, sufficient to confirm order
|
||||
of magnitude and correctness, not to re-derive medians): no-symbol 0.248 ms,
|
||||
duplicate-module 2 120–2 153 ms, common-port ~3.4 s, tail-adjacent rows in the
|
||||
same session all within normal single-session variance of the tracker's
|
||||
values (a few percent, same direction the tracker itself notes as
|
||||
session-to-session noise). `extractrefuse` bad-name 12.7 ms / partial-selection
|
||||
0.05 ms, `execute` inline-refusal 757.6 ms, `aes.sv` capture 138.2/167.9 ms —
|
||||
all within the same variance band and all sentences/fingerprints identical.
|
||||
No cell moved outside what the tracker itself already characterizes as
|
||||
session noise (±10%), and none of the safety-relevant numbers (parse counts,
|
||||
sentences, fingerprints) showed **any** deviation.
|
||||
|
||||
**9. OpenTitan / guard / lingering processes.** `git -C
|
||||
/Users/guoliangchen/repo/opentitan status --porcelain` showed exactly the
|
||||
three pre-existing modified files (`hw/ip/aes/dv/tb/tb.sv`,
|
||||
`hw/top_darjeeling/.../ast.sv`, `hw/top_earlgrey/.../ast.sv`) before and after
|
||||
every phase invocation in this QA pass. Every cargo/test/bench invocation ran
|
||||
through `tools/guard.sh -m 8 -t <bound>`; zero guard kills. No `sleep` over
|
||||
60 s was used; all waits were `Monitor`-backed PID polls that exited on their
|
||||
own; no lingering background processes or monitors remain at the end of this
|
||||
pass (`ps` checked clean after each phase).
|
||||
|
||||
**10. Fixed directly (small, unambiguous).** The feature README's own work
|
||||
log said `cargo test --workspace` **4 328 passed**; two independent guarded
|
||||
runs on this exact tree (main tree, and the untouched sha256-matched binary's
|
||||
own source) show **4 322**, which is also exactly what the QA brief itself
|
||||
expected ("dev says 4322"). Corrected in the Work log entry above with the
|
||||
supporting arithmetic; not a functional finding, a transcription slip.
|
||||
|
||||
**Topo handshake for the lead to apply** (repeating the README's own
|
||||
Handshakes request, verified sound): `docs/topo.md` §1.2's
|
||||
`lucisv_server ◀──▶ vlog_refactor` entry should gain a **one-directional**
|
||||
parity obligation — `rename_preflight` must produce the same *refusal* text as
|
||||
whole-scope `rename` for the same request, but may always stand aside — and a
|
||||
note that `rename_preflight` deliberately does **not** read the workspace
|
||||
index, unlike `prepare_rename_here`, which does. Confirmed by code: no `index`
|
||||
or `external` parameter reaches `rename_preflight` anywhere in this diff, and
|
||||
`declared_here`'s file-scope branch is the one place that would have needed
|
||||
it, and defers instead.
|
||||
|
||||
**Verdict: PASS.** Every refusal's sentence and precedence is unchanged
|
||||
between 0.51.0 and the candidate on every case checked, including two
|
||||
successful sabotage attacks on the oracle that would have caught a real
|
||||
regression. TODO §61.1's QA line is ticked below.
|
||||
|
||||
## Review
|
||||
|
||||
**2026-09-08 (lead).** Accepted. Read `preflight.rs`, the server call
|
||||
site, the oracle test, both logs; QA's independently rebuilt rule table
|
||||
and its sabotage of the oracle are the acceptance.
|
||||
|
||||
- The result is the review's gate met by two orders of magnitude (2.0 s
|
||||
and 3 975 parses → 0.34 ms and none) with the sentence and its
|
||||
precedence byte-identical, proven at every byte of the fixtures and on
|
||||
the wire.
|
||||
- The two things the dev refused to do are as good as the thing it did.
|
||||
The duplicate-declaration refusal stays on the slow road because the
|
||||
index is written on save and on a watcher event, never on a keystroke,
|
||||
and a wrong rename refusal is terminal where a wrong prepareRename is
|
||||
not — the right reading of "only with evidence the index is current".
|
||||
The extract preflight was built, measured at zero work, and removed:
|
||||
the offer gate already runs the region-local checks before the engine
|
||||
is reached, and the `aes_wrap.sv` refusal is `Crossing::read`, the last
|
||||
stage of the plan, which only §61.5's scope reuse can move.
|
||||
- The signature deviation (no `external`/`index` parameters) is the
|
||||
contract itself: a preflight that could read the index would invite
|
||||
exactly the refusal the argument forbids.
|
||||
- QA fixed one arithmetic slip in this README's test count; nothing else.
|
||||
|
||||
Docs applied at merge: topo §1.2 — `rename_preflight` owes whole-scope
|
||||
`rename` the same refusal text, one-directionally, and reads no index.
|
||||
|
||||
*(empty — for the lead)*
|
||||
+181
-2
@@ -2013,9 +2013,9 @@ checks in its full experiment record. Targets are proposed gates, not promises.
|
||||
| R1b | Profile then reduce dirty-buffer analysis on the first action after an edit | pinmux 135.9 ms; unchanged repeat about 24 ms | first-edit reduction shown separately; didChange ordering preserved | — | — | Pending |
|
||||
| R2a | Remove redundant discovery metadata/config work | traced warm discovery 205.0 ms; first useful answer 328.2 ms paired | first useful answer ≤200 ms milestone, correct settled target | — | — | Pending |
|
||||
| R2b | Begin useful local-folder work before full discovery/cache loading finishes | warm cache open 92.3 ms in traced session; cold/warm first answer 286.8/328.2 ms | single coherent scan, correct results across startup ordering cases | — | — | Pending |
|
||||
| R3a | Engine-owned empty-cursor preflight avoids whole-workspace materialization | no-symbol refusal 2,192 ms; 3,975 parses, candidate-only trace | ≤16 ms; zero closed-workspace parses; exact refusal/precedence | — | — | Pending |
|
||||
| R3a | Engine-owned empty-cursor preflight avoids whole-workspace materialization | no-symbol refusal 2,192 ms; 3,975 parses, candidate-only trace | ≤16 ms; zero closed-workspace parses; exact refusal/precedence | dev (Opus), §61.1, tree at `e13ae4c` + the §61.1 diff | **0.3 ms** repeat median (paired reference 2,012.3 ms, −100.0%); `trace_parses` **0**, `trace_selected` **0** off the wire; refusal byte-identical; peak RSS 909 → 429 MiB. [Record R3a-2026-09-08](#experiment-record--r3a-2026-09-08-stage-r3a); `~/.cache/lucisv-perf/take5r-1/` | Retained — QA PASS → lead; committed 2026-09-08 |
|
||||
| R3b | Reuse valid source analysis and reduce initial scope construction | tail rename 398.3 ms; traced index stage 229.2 ms; 238 selected files | ≥20% wire improvement milestone; same edits/warnings/refusals; bounded RSS | — | — | Pending |
|
||||
| R3c | Profile broad fallbacks, warnings and refused extraction before optimizing | common port 3,455 ms; tail warning stage 50.9 ms; extract refusal 804.9 ms | measured work reduction; no weaker selection or verification | — | — | Pending |
|
||||
| R3c | Profile broad fallbacks, warnings and refused extraction before optimizing | common port 3,455 ms; tail warning stage 50.9 ms; extract refusal 804.9 ms | measured work reduction; no weaker selection or verification | dev (Opus), §61.1 — **refused-extraction half only**; the broad fallbacks and the warning stage remain open for §61.5 | Extract refusal **761.1 → 767.8 ms (+0.9%, unchanged)**: its stage is `boundary::Crossing::read`, which needs `flow::read(&scope, …)` for instantiated-module port directions, so no bounded preflight reaches it. A region-local preflight was built, measured and **removed** — `site_at` (= `extract_site_in`) already answers the parse and `Region::read` refusals, and `plain_identifier`/occupied are already ahead of `Extraction::plan`. New phase `extractrefuse`. [Record R3c-x-2026-09-08](#experiment-record--r3c-x-2026-09-08-stage-r3c-extraction-half) | **Reject** the preflight (no work to remove); **defer** the 805 ms to §61.5's scope reuse |
|
||||
| R4 | Separate publication overhead from quiet scan decode/merge cost | quiet cold/warm 2,907/1,118 ms; scanserve max 337/328 ms | same offered load; improve queue latency and completion; warm quiet ≤1 s | — | — | Pending |
|
||||
|
||||
Maintain the successful P3 CLI result as a control: 7,751 style diagnostics,
|
||||
@@ -2023,3 +2023,182 @@ byte-identical stdout, about 490 ms wall / 2.44 s user CPU here. Preserve the
|
||||
warm idle memory gain and all source-selection/fence/after-index contracts in
|
||||
[topo.md](../topo.md). Cross-module API changes need their handshake recorded
|
||||
before implementation; no verifier forgiveness may be weakened for speed.
|
||||
|
||||
## Experiment record — R3a-2026-09-08 (stage R3a)
|
||||
|
||||
- **Experiment ID / stage / date / owner:** `R3a-2026-09-08` / R3a (TODO §61.1)
|
||||
/ 2026-09-08, America/Chicago / dev agent (Opus).
|
||||
- **Hypothesis and exact expected work reduction:** a `textDocument/rename` on
|
||||
a cursor with no symbol selects all 3 976 in-scope files and performs 3 975
|
||||
whole-file parses before `Scope::locate` refuses in 0.1 ms from the request
|
||||
buffer's own analysis. If the engine is asked that question from the buffer
|
||||
*first*, the expected reduction is the whole of it: 3 975 → 0 parses, and the
|
||||
~1.9 s scope build plus the ~0.25 s selection removed entirely.
|
||||
- **Reference commit, candidate commit or diff hash, binary hashes:** reference
|
||||
= tag `v0.51.0` (`bc59336`, "Release 0.51.0"), built from a clean shallow
|
||||
clone in scratch, binary
|
||||
`271b7f7ce386a6db0f0c346c3879944b6d2109f4eb985edd6c58ae60da93bb77`. Candidate
|
||||
= tree at `e13ae4c89b4480d658ec2122a625b54ce000062f` plus the uncommitted
|
||||
§61.1 diff, binary
|
||||
`5f815542ac16854acb77f545805378324e0025eaaf48662f28bcc8ae8b6ebdb9`. Both
|
||||
`--release`, rustc 1.97.1 (8bab26f4f 2026-07-14) (Homebrew).
|
||||
- **Files changed / API contracts amended / topology references:**
|
||||
`crates/vlog_refactor/src/rename/preflight.rs` (new, 84 lines),
|
||||
`crates/vlog_refactor/src/rename/mod.rs` (the `mod`/`pub use`, and the
|
||||
same-name sentence factored into `already_named`),
|
||||
`crates/vlog_refactor/src/lib.rs` (one export),
|
||||
`crates/lucisv_server/src/rename.rs` (the call, and the trace on the refusal
|
||||
path). One **new public API**: `vlog_refactor::rename_preflight`, additive.
|
||||
A `docs/topo.md` §1.2 amendment is *requested* in
|
||||
`docs/features/perf5r-preflight/README.md`'s Handshakes and was not applied
|
||||
by this lane.
|
||||
- **Workload, corpus/input hashes, open files, cursor/range, rules, client
|
||||
capabilities:** OpenTitan, the same three pre-existing modified files,
|
||||
verified unchanged by `git status --porcelain` after **every one of the 12**
|
||||
phase invocations. Cursors are `tools/perf/sites.py`'s, unchanged. The
|
||||
no-symbol row is `phases_p2.no_symbol_row`'s own cursor; the duplicate-module
|
||||
row is `rstmgr_por`; the common-port row is `clk_i` in
|
||||
`entropy_src_main_sm.sv`. Client shape is in every row.
|
||||
- **Machine, compiler/profile, threads, load before/after, competing
|
||||
activity:** M1 Max, macOS 27.0, release profile, default worker count. Load
|
||||
recorded before every phase: 1.67–4.78 one-minute, inside the review's own
|
||||
2.82–6.00 band. **No build, test suite or second benchmark overlapped any
|
||||
timed run** — both binaries were built to completion first, and the workspace
|
||||
test suite finished before the first phase started.
|
||||
- **Commands, cache reset/prime steps, trial ordering and fresh-session
|
||||
count:** 12 guarded `bench.py <phase>` invocations, `--tries 3` (one first +
|
||||
three repeats), each through `tools/guard.sh -m 8 -t 1800`. Phases
|
||||
`renametrace tailrename rename execute refactor extractrefuse`, each run once
|
||||
per label. Reference/candidate order **alternated between phases**
|
||||
(`renametrace` ref→cand, `tailrename` cand→ref, `rename` ref→cand, `execute`
|
||||
cand→ref, `refactor` ref→cand, `extractrefuse` cand→ref). Separate
|
||||
`--storage` per label; `renametrace` opens a fresh session per row.
|
||||
- **Raw evidence path, explicit units, full sample arrays:**
|
||||
`~/.cache/lucisv-perf/take5r-1/results.jsonl` (and `results2.jsonl` for the
|
||||
corrected `extractrefuse` run). Units in every row: latency `ms`, memory
|
||||
`peak_rss_kib`. Trace fields are `trace_*`; the new one is `trace_preflight`.
|
||||
- **Reference first / repeat median / range; candidate first / repeat median /
|
||||
range:** no-symbol — reference 2 039.6 / **2 012.3** / 1 991.8–2 023.3;
|
||||
candidate 3.6 / **0.34** / 0.26–0.42. Duplicate module — reference 2 088.2 /
|
||||
**2 012.6** / 2 003.1–2 021.5; candidate 2 051.7 / **2 032.0** /
|
||||
2 001.9–2 058.0. Common port — reference 3 345.6 / **3 242.4**; candidate
|
||||
3 387.8 / **3 252.7**. Tail — 367.3 vs 365.0. The full arrays are in the
|
||||
JSONL; the feature README carries the whole table.
|
||||
- **Work counts: reads, parses, analyzed/selected/watched/edited files and
|
||||
bytes:** the no-symbol refusal goes from `selected=3976`, `bytes=35 813 310`,
|
||||
`parses=3975`, `index=1 713.7 ms`, `fallback=true` to `selected=0`,
|
||||
`parses=0`, `index=0.0 ms`, `preflight=true`. Every other row's counts are
|
||||
**byte-for-byte unchanged**, including the duplicate-module row's 3 975
|
||||
parses, which the decision deliberately leaves in place.
|
||||
- **Result/status/count/fingerprint comparisons, warnings and refusal
|
||||
checks:** all fingerprints identical — tail `b39defb21265…`, `aes`
|
||||
`fa7e31c78382…`, `clk_i` `31aadc134628…`, `cipher_alert` `5f53e977da59…`,
|
||||
extraction `090e92e7736e…`. Every refusal message compared programmatically
|
||||
and identical, the no-symbol sentence included. `aes_extracted.sv` still does
|
||||
not exist.
|
||||
- **Idle RSS / peak RSS / cache size / guard outcomes:** the no-symbol row's
|
||||
peak drops **909.1 → 428.8 MiB (−52.8%)** — it no longer holds an index over
|
||||
35.8 MB of source. Every other row within ±8 MiB except the tail rename
|
||||
(611 → 659 MiB, +7.8%, a single-session sample on an unchanged code path).
|
||||
**Zero guard kills.**
|
||||
- **Target achieved or missed; paired improvement and variability:**
|
||||
**achieved, with margin.** Gate ≤16 ms → 0.34 ms; gate zero closed-workspace
|
||||
parses → 0, read off the wire rather than asserted; gate exact
|
||||
refusal/precedence → byte-identical sentence, and precedence pinned by
|
||||
`the_preflight_does_not_disturb_the_refusal_order`. Unchanged rows vary
|
||||
+0.3% to +4.4%, none read as movement.
|
||||
- **Where the reference disagrees with the baseline beyond tolerance (neither
|
||||
number adjusted):** the review's candidate-only cells were 2 192 ms
|
||||
(no-symbol), 2 200 ms (`rstmgr_por`), 3 455 ms (`clk_i`). This paired rerun's
|
||||
reference reads 2 012, 2 013 and 3 242 — **8–6% below** all three, in the same
|
||||
direction, on a machine whose load was lower this session (1.7–4.8 vs the
|
||||
review's 2.8–6.0). The improvement is stated against **this session's own
|
||||
reference**, not against the review's cells, so the ratio is unaffected.
|
||||
- **Correctness tests and logs:** `cargo fmt` clean; guarded `cargo clippy
|
||||
--all-targets` clean, no new `#[allow]`; guarded `cargo test --workspace`
|
||||
**4 328 passed, 0 failed, exit 0**. New: a 10-test equality oracle
|
||||
(`crates/vlog_refactor/tests/preflight_oracle.rs`) comparing the preflight's
|
||||
refusal against whole-scope `rename` at **every byte** of seven hostile
|
||||
fixtures × six new names, failing on any reworded or invented refusal; 4
|
||||
server tests including the zero-parse assertion and the large-buffer gate.
|
||||
- **Interpretation, remaining bottleneck, tradeoffs, rejected alternatives:**
|
||||
the cheap door into `ws.sources()` is closed; the two expensive doors are
|
||||
still open and are *deliberately* open. `rstmgr_por` (2 032 ms) and
|
||||
`cipher_alert → clk_i` (2 730 ms) both need the whole scope — the first
|
||||
because the index is not current with respect to unsaved edits and `rename`
|
||||
is the authority that re-derives the count, the second because the refusal is
|
||||
the verifier's. **Rejected alternatives:** taking the duplicate-declaration
|
||||
refusal from the index (evidence and argument in the feature README —
|
||||
`state/mod.rs::set_document` reads the index and never writes it, so a
|
||||
refusal from it could be wrong with no later road to correct it); taking the
|
||||
`ExternalCandidate` refusals from the buffer's overlay (same argument);
|
||||
taking `new_name == module` unconditionally (it would jump the ambiguity
|
||||
check and change which sentence the user sees).
|
||||
- **Decision: retain / revise / reject / defer; next stage justified by
|
||||
evidence:** **retain.** R3b/R3c's remaining halves are unblocked and now have
|
||||
a sharper target: with the cheap refusal gone, the ~2.0 s floor on the two
|
||||
surviving whole-scope rows is entirely `Scope::build`, which is exactly what
|
||||
§61.5 proposes to reuse.
|
||||
- **QA result and lead review link:** pending —
|
||||
`docs/features/perf5r-preflight/README.md`.
|
||||
|
||||
## Experiment record — R3c-x-2026-09-08 (stage R3c, extraction half)
|
||||
|
||||
- **Experiment ID / stage / date / owner:** `R3c-x-2026-09-08` / R3c, the
|
||||
refused-extraction half only / 2026-09-08 / dev agent (Opus). The broad
|
||||
fallback and warning-stage halves of R3c are untouched and remain Pending.
|
||||
- **Hypothesis and exact expected work reduction:** that the 805 ms refused
|
||||
extraction at `aes_wrap.sv` 66:2 spends its time in `Scope::build` ahead of
|
||||
region-local safety checks, and that moving those checks in front of the
|
||||
build would remove most of it.
|
||||
- **Reference commit / candidate / binary hashes:** as R3a above; the same two
|
||||
binaries and the same session.
|
||||
- **Files changed:** `tools/perf/phases_r3.py` (new, phase `extractrefuse`) and
|
||||
one import line in `tools/perf/bench.py`. **No production Rust survives from
|
||||
this half.** An `extract_preflight` (~130 lines, `extract/preflight.rs`, plus
|
||||
a server call and eight oracle tests) was written, wired and measured, then
|
||||
removed; three server tests and one factored refusal sentence
|
||||
(`extract::does_not_parse`) were kept.
|
||||
- **Workload:** `aes_wrap.sv` 66:2, `sites.REFACTOR_SITES`'s `inline-module`
|
||||
row — the review's own site. `aes.sv` 220:0–222:53 is the successful-capture
|
||||
control. Corpus unchanged after every invocation.
|
||||
- **Machine / load / commands / ordering:** as R3a. `extractrefuse` run once
|
||||
per label, candidate first; `execute` run once per label, candidate first.
|
||||
- **Raw evidence:** `~/.cache/lucisv-perf/take5r-1/results.jsonl` (`execute`)
|
||||
and `results2.jsonl` (`extractrefuse`, the corrected selection).
|
||||
- **Reference / candidate medians:** extract refusal **761.1 → 767.8 ms**
|
||||
(+0.9%). Extract capture **143.5 → 143.3 ms**. Inline refusal 5.79 → 5.85.
|
||||
`extractrefuse` bad name 9.3 → 9.8 ms; partial selection 0.22 → 0.13 ms.
|
||||
- **Work counts:** unchanged. The refusal still builds the scope, because the
|
||||
refusal *is* about the scope.
|
||||
- **Result/fingerprint/refusal comparisons:** extraction fingerprint
|
||||
`090e92e7736e…` identical. Both refusal sentences identical.
|
||||
- **Peak RSS / guard:** unchanged; **zero guard kills**.
|
||||
- **Target achieved or missed:** **missed, and correctly so.** The hypothesis
|
||||
was **falsified** in two independent ways. (1) The 805 ms refusal is
|
||||
`extract/boundary.rs:196` in `Crossing::read`, the last stage of
|
||||
`Extraction::plan`; it depends on `flow::read(&scope, …)`, which needs the
|
||||
instantiated modules' port directions from other files. It is scope-dependent
|
||||
at depth, not region-local. (2) The region-local checks were **already** in
|
||||
front of the scope build, by two mechanisms: `extract::execute`'s `site_at`
|
||||
gate is `extract_site_in`, whose first two statements are the
|
||||
parse-diagnostic check and `Region::read`, so neither can reach the engine;
|
||||
and `plain_identifier` and the occupied check are `extract_module`'s own
|
||||
first two statements, ahead of `Extraction::plan`. The two `extractrefuse`
|
||||
rows measure exactly this: both refusals are already pre-scope in the
|
||||
**reference**.
|
||||
- **Interpretation, tradeoffs, rejected alternatives:** the preflight was
|
||||
rejected rather than shipped because it would have been a new public API and
|
||||
a second copy of two checks in exchange for zero measured work, which is the
|
||||
abstraction CLAUDE.md's "simplicity first" forbids. The reason is recorded as
|
||||
a comment at the call site in `lucisv_server/src/extract.rs` so the next round
|
||||
does not rediscover it, and the `extractrefuse` phase is kept so the claim
|
||||
stays a measurement. The lever that *would* move the 805 ms is named but not
|
||||
attempted: `flow` wants port directions the workspace index already holds, so
|
||||
it belongs to §61.5's scope-reuse work, not to a preflight. The review's own
|
||||
instruction — instrument first, "do not implement beyond the region-local
|
||||
checks without the evidence" — is what this record answers.
|
||||
- **Decision:** **reject** the extract preflight; **defer** the 805 ms refusal
|
||||
to §61.5 (R3b/R3c scope reuse) with its stage identified.
|
||||
- **QA result and lead review link:** pending —
|
||||
`docs/features/perf5r-preflight/README.md`.
|
||||
+1
-1
@@ -142,7 +142,7 @@ what a change on the pointed-to side must not silently break.
|
||||
| `lucisv_server ◀──▶ vlog_semantic` | handshake | Two negotiated additions, both 2026-08-28 and both additive: **`Symbol::detail_span` / `Def::detail_span`** (where a non-ANSI port's body declaration completes the header that names it — the server's hover card and `nav::definition` both read it, and they show/jump to it in the same order), and **`Semantics::symbols_named`** (name → declarations, built in `analyze`, in declaration order — the server replaced two scan-every-symbol loops with it and the *first-match tie-break must stay declaration order* or hover's choice between two live declarations of one name changes). `docs/features/port-detail-spans/README.md`. |
|
||||
| `lucisv_server ◀──▶ vlog_semantic` | handshake | Three later additive performance surfaces: **`DeclLines` / `Def::lines`** record declaration and detail lines at index time (`FACTS_FORMAT` 3 → 4); **`WorkspaceIndex::absorb`** folds a scan batch with one merge rather than one merge per file; and **`WorkspaceIndex::files_spelling`** finds external uses by spelling, resolved or not, for rename's dangling-use refusal. The first feeds hover-line-index, the second scan-interleave, and the third refactor-rename's six-rung fan-out. Changing the facts codec, reference-fact census or merge semantics breaks those consumers. |
|
||||
| `lucisv_server ──▶ vlog_refactor` | depends | `prepare_rename`/`rename`, `find_references`, the port refactorings, `organize_imports`, `extract_module`, `inline_module`, `RefactorEdit::{edits,warnings,created}`, `rename_traced` + `RenameTrace`/`VerifyTrace`/`Stage` (perf5-p2: the rename with its stage timings and parse counts as an out parameter; `rename` is the same call with a trace nobody reads; the server logs one `timing: rename trace …` line under `--verbose` only), the parsed-input selectors `port_action_modules_in`/`imported_packages_in`/`extract_site_in`/`inline_site_in` (perf5-p1: the offer paths hand the document's own tolerant parse and diagnostics; the text forms are thin wrappers kept for standalone consumers and the every-offset parity test; a large-file buffer still takes the text form), `instantiation_plan`/`render_with`/`module_definition` (the inline instantiation ghost, signature help, inlay hints — the completion popup stopped consuming them 2026-08-30, names-only tier). Promise consumed: never a partial edit — `Ok` verified whole, `Err` is a sentence. |
|
||||
| `lucisv_server ◀──▶ vlog_refactor` | handshake | Request-scope selectors added for the performance wave: `prepare_rename_here` must produce the same answer/refusal text as whole-scope `prepare_rename`; `rename_name_at` must name the target that the rename engine acts on; `port_action_modules` and `enclosing_module` must name every module the corresponding port action/command can edit. The server uses those names to choose an index-derived file set; `extract_site`, `inline_site` and `imported_packages` also name source requirements. The engine remains the authority, and every selector must supply a superset of files needed for edits and refusals (inline gap: §2.9-33). |
|
||||
| `lucisv_server ◀──▶ vlog_refactor` | handshake | Request-scope selectors added for the performance wave: `prepare_rename_here` must produce the same answer/refusal text as whole-scope `prepare_rename`; `rename_name_at` must name the target that the rename engine acts on; `port_action_modules` and `enclosing_module` must name every module the corresponding port action/command can edit. The server uses those names to choose an index-derived file set; `extract_site`, `inline_site` and `imported_packages` also name source requirements. **`rename_preflight(semantics, offset, new_name)` (perf5r-preflight, 2026-09-08)** owes whole-scope `rename` the same *refusal* text one-directionally — it may always stand aside with `Ok(())` and never invents a refusal — and deliberately reads no workspace index (unlike `prepare_rename_here`): only refusals that are a pure function of the request buffer's own text (the new-name check, no symbol here, an unresolved or inherited-candidate reference, an unspelled declaration, the same name at a non-file-scope declaration); every index-answered refusal stays on the slow road. The engine remains the authority, and every selector must supply a superset of files needed for edits and refusals (inline gap: §2.9-33). |
|
||||
| `lucisv_server ──▶ vlog_formatter` | depends | `format_source`, `format_range`/`LineRanges` (range, ranges, on-type formatting), `Config`, `fence::protected_regions` (quick-fix filter). |
|
||||
| `lucisv_server ──▶ vlog_linter` | depends | `run`, `lint` + `LintContext::from_parse` (lints from the `Document`'s own parse — one-parse), `default_rules`, `apply_fixes`, `rule_by_name`. Same three promises the CLI relies on. |
|
||||
| `lucisv_server ──▶ lsp-server / lsp-types` | depends | The transport (synchronous, no async runtime) and the protocol data model. Both pinned exactly. cancel-request additionally relies on `lsp-server 0.10.0`'s stdio transport being a **rendezvous channel** (its own forwarder queue exists because of it) — a version bump must re-read that crate's `stdio.rs`. |
|
||||
|
||||
@@ -37,6 +37,7 @@ import phases_p0 # noqa: E402,F401 — registers take 5 §P0's phases
|
||||
import phases_p1 # noqa: E402,F401 — registers take 5 §P1's phases
|
||||
import phases_p2 # noqa: E402,F401 — registers take 5 §P2's phases
|
||||
import phases_p4 # noqa: E402,F401 — registers take 5 §P4's phases
|
||||
import phases_r3 # noqa: E402,F401 — registers the review round's R3 phase
|
||||
|
||||
|
||||
# =========================================================================
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
#!/usr/bin/env python3
|
||||
"""The take-5 **review** round's phase for R3a/R3c: `extractrefuse`.
|
||||
|
||||
The `execute` phase runs the two command-bearing offers as a *user* would, and
|
||||
one of them — the extraction at `aes_wrap.sv` 66:2 — refuses after about
|
||||
805 ms. That refusal turned out to be `extract/boundary.rs`'s, four stages past
|
||||
anything a region-local preflight can reach, so §61.1's extract preflight
|
||||
cannot and does not move it.
|
||||
|
||||
What the preflight *does* move is the other half of the refusal list: a new
|
||||
name that is not an identifier, a target file that is already occupied, a
|
||||
buffer that does not parse, and every refusal about the selection's own shape.
|
||||
None of those had a row, so shipping the preflight would have rested on unit
|
||||
tests alone. This phase gives them one, at the **same site** as the 805 ms
|
||||
refusal so the two numbers are directly comparable: same file, same cursor,
|
||||
same session, same fan-out — the only difference is which refusal is reached.
|
||||
|
||||
Rows are `executeCommand` round trips with no edit pushed, exactly as
|
||||
`phases_p0.execute_row` records a refusal, so `ms` is the whole round trip.
|
||||
"""
|
||||
|
||||
import phases_p0
|
||||
import schema
|
||||
import sites
|
||||
from harness import ARGS, code_action_params, phase, record, session
|
||||
|
||||
#: The command the extract offer carries. Named here rather than read off an
|
||||
#: offer, because these rows deliberately send arguments no offer would: the
|
||||
#: point is the refusal, not the lightbulb.
|
||||
EXTRACT = "lucisv.extractModule"
|
||||
|
||||
#: `(row, new_name, shift)` — refusals at the site whose *scope-dependent*
|
||||
#: refusal costs 805 ms. `shift` extends the selection's end character forward
|
||||
#: so the range stops inside the instantiation instead of after it, which is
|
||||
#: `Region::read`'s "partial item" refusal — the one the preflight moves.
|
||||
#:
|
||||
#: The name row is the control, and it is expected **not** to move:
|
||||
#: `plain_identifier` was already `extract_module`'s first statement, ahead of
|
||||
#: `Extraction::plan` and so ahead of the scope build. Keeping it in the phase
|
||||
#: is what makes the other row's improvement attributable to the preflight
|
||||
#: rather than to the session.
|
||||
CASES = [
|
||||
("control: new name is not an identifier (already pre-scope)",
|
||||
"1_not_an_ident", 0),
|
||||
("refused early: selection covers no whole item", "pulled_out", 20),
|
||||
]
|
||||
|
||||
|
||||
@phase("extractrefuse")
|
||||
def phase_extractrefuse():
|
||||
"""The preflight-reachable extract refusals, timed at the 805 ms site."""
|
||||
_, path, needle, occurrence, offset = next(
|
||||
row for row in sites.REFACTOR_SITES if row[0] == "inline-module")
|
||||
params = code_action_params(path, needle, occurrence, offset)
|
||||
uri = params["textDocument"]["uri"]
|
||||
for row, new_name, shift in CASES:
|
||||
with session("workspace", resolve_support=True, apply_edit=True,
|
||||
create_files=True) as s:
|
||||
phases_p0.open_and_settle(s, path)
|
||||
rng = selection(params["range"], shift)
|
||||
call = {"command": EXTRACT, "arguments": [uri, rng, new_name]}
|
||||
s.take_notifications()
|
||||
total, statuses, pushed = [], [], []
|
||||
for _ in range(ARGS.tries + 1):
|
||||
_, _, three, message, pushes = phases_p0.execute_once(s, call)
|
||||
total.append(three)
|
||||
statuses.append(schema.status_of(message))
|
||||
pushed = pushes or pushed
|
||||
status, text = statuses[-1]
|
||||
record(phase="extractrefuse", row=row, ms=total,
|
||||
status=status, message=text, result_count=len(pushed),
|
||||
client=s.client_shape(), command=EXTRACT,
|
||||
arguments=len(call["arguments"]), file=path,
|
||||
position=rng["start"], new_name=new_name,
|
||||
note="no edit was pushed, so ms is the whole "
|
||||
"executeCommand round trip; the same site whose "
|
||||
"scope-dependent refusal costs about 805 ms")
|
||||
|
||||
|
||||
def selection(base, shift):
|
||||
"""`base`, with its end moved `shift` characters forward — 0 leaves it
|
||||
alone, which is the cursor the offer itself is made at."""
|
||||
if not shift:
|
||||
return base
|
||||
end = dict(base["end"])
|
||||
end["character"] = end["character"] + shift
|
||||
return {"start": base["start"], "end": end}
|
||||
Reference in new issue
Block a user