Perf take 5 P1c (§60.1): offer predicates instead of throwaway edits — port_offers/organize_offer answer the lightbulb from the plan-time checks with the same titles and counts, the click still recomputes and verifies; aes_reg_top offer 21.8 → 5.5 ms, aes 7.8 → 1.7, organize-imports 15.4 → 4.9; the organize-imports offer contract documented as optimistic like every other lazy offer (lead ruling on QA's finding)
This commit is contained in:
1 parent
6c1f863417
commit
dafa4f0500
18 files changed
+2216
-131
No files matched your search
@@ -5793,10 +5793,41 @@ document revision, computed only when a fix needs it
|
||||
pays the pass regardless)
|
||||
— the measurement is in: `aes_reg_top` ports-only 21.15 ms of a
|
||||
21.83 ms row; every other family under 0.15 ms
|
||||
- [x] P1c: engine-owned offer predicates — `vlog_refactor::{port_offers,
|
||||
port_offers_in}` (new `ports/offer.rs`) and `{organize_offer,
|
||||
organize_offer_in}`, each asking only the *plan-time* questions over
|
||||
the buffer's own parse/analysis and at most one parse of the
|
||||
declaring file; no `Scope` for the ports, no `check::verify_splice`
|
||||
for either; `ports::offers` / `imports::offers` on them,
|
||||
`resolve` and `execute` untouched and still verifying
|
||||
— `aes_reg_top` lazy **21.83 → 5.46 ms** (−75.0%), its ports family
|
||||
**21.15 → 3.27** (−84.6%), `aes` **7.76 → 1.74** (−77.6%), the
|
||||
organize-imports offer **15.39 (REF) → 4.88**; **all three targets
|
||||
met**; the eager guardrail unmoved at 492.5 ms
|
||||
- [x] P1c parity: offer ⇔ the eager menu, titles included, at **every byte
|
||||
offset** of eight port fixtures and seven import fixtures (two new
|
||||
engine test files); 50 harness rows field-identical to P1b and 65 to
|
||||
the REF; the three resolve fingerprints byte-identical; a repeated
|
||||
ports offer parses **1** file and a repeated organize-imports offer
|
||||
**3**, asserted by counter against a `resolveSupport` client
|
||||
— residues named, not hidden: the declaring file's parse (2.2–2.4 ms
|
||||
of the ports offer's 3.27) and the buffer's own share of the imports
|
||||
index (~0.8 ms), the second a `vlog_semantic` handshake request
|
||||
- [ ] lead ruling on a lint-result reuse item (new, from P1b's number:
|
||||
24.0 ms, the whole of the pinmux row, for a client that sends no
|
||||
`only`) — a keyed cache in §59's shape, not this lane's to add
|
||||
- [x] QA: parity attacks as above, the counters, the numbers re-taken
|
||||
- [x] QA (P1c): the every-offset parity suites re-attacked, the two
|
||||
counters sabotaged, the numbers re-taken on the same binary
|
||||
— 2026-09-07: ports side clean (three refusal fixtures old vs new
|
||||
vs resolve, counters load-bearing, 13 cells within tolerance, the
|
||||
resolve fingerprints equal to REF); one REWORK finding — the
|
||||
organize-imports offer no longer runs `verify_splice` while its
|
||||
README still called the offer exact — **ruled by the lead**: the
|
||||
narrowing is of the offer's promise only (resolve verifies the same
|
||||
file set before any edit leaves the engine); the organize-imports
|
||||
README amended; the ports/imports offer contract is now the same
|
||||
sentence everywhere.
|
||||
- [x] QA (P1a/P1b): parity attacks as above, the counters, the numbers re-taken
|
||||
— PASS, 2026-09-07: `docs/features/perf5-p1/README.md` QA log; 17
|
||||
cursors byte-identical vs a real v0.50.0 baseline server, counter
|
||||
sabotage caught in 3 places, parity suite verified exhaustive plus
|
||||
|
||||
@@ -74,8 +74,9 @@ pub fn offers(
|
||||
position: Position,
|
||||
offset: u32,
|
||||
) -> Vec<CodeActionOrCommand> {
|
||||
let Some(doc) = ws.document(uri) else { return Vec::new() };
|
||||
let Some((path, files)) = at(ws, uri, offset) else { return Vec::new() };
|
||||
let Ok((_, removed, sorted)) = vlog_refactor::organize_counts(&files, &path, offset) else {
|
||||
let Ok((removed, sorted)) = counts_at(doc, &files, &path, offset) else {
|
||||
return Vec::new();
|
||||
};
|
||||
let title = vlog_refactor::organize_title(removed, sorted);
|
||||
@@ -88,6 +89,37 @@ pub fn offers(
|
||||
})]
|
||||
}
|
||||
|
||||
/// The two counts the offered title promises, asked of the buffer's own parse,
|
||||
/// analysis and token stream, and **without** verifying the splice.
|
||||
///
|
||||
/// `organize_counts` computes the whole edit and runs `check::verify_splice`,
|
||||
/// which rebuilds the index over every in-scope file and re-analyzes them —
|
||||
/// about two thirds of the offer's cost for an answer the offer discards (take
|
||||
/// 5 §P1c, `docs/features/perf5-p1/README.md`). [`resolve`] and [`execute`]
|
||||
/// still compute and verify the real edit when the user picks the action.
|
||||
///
|
||||
/// A buffer on the large-file fast path keeps the text form, exactly as
|
||||
/// [`packages_at`] does.
|
||||
fn counts_at(
|
||||
doc: &Document,
|
||||
files: &[(PathBuf, String)],
|
||||
path: &Path,
|
||||
offset: u32,
|
||||
) -> Result<(usize, usize), String> {
|
||||
match doc.large {
|
||||
true => vlog_refactor::organize_offer(files, path, offset),
|
||||
false => vlog_refactor::organize_offer_in(
|
||||
files,
|
||||
path,
|
||||
&doc.tree,
|
||||
&doc.diagnostics,
|
||||
&doc.semantics,
|
||||
&doc.tokens,
|
||||
offset,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// The edit for an offered action, computed now that the user has picked it.
|
||||
pub fn resolve(ws: &Workspace, action: CodeAction) -> Result<CodeAction, String> {
|
||||
if action.edit.is_some() {
|
||||
|
||||
@@ -173,10 +173,10 @@ pub fn offers(
|
||||
return Vec::new();
|
||||
}
|
||||
let sources = offer_sources(ws, &path, &doc.text, &modules);
|
||||
vlog_refactor::port_actions(&sources, &path, offset)
|
||||
offered(doc, &sources, &path, offset)
|
||||
.into_iter()
|
||||
.map(|action| {
|
||||
let title = counted(ws, action.title, &modules);
|
||||
.map(|offer| {
|
||||
let title = counted(ws, offer.title, &modules);
|
||||
let data =
|
||||
serde_json::to_value(Offer { uri: uri.clone(), position, title: title.clone() })
|
||||
.ok();
|
||||
@@ -190,6 +190,40 @@ pub fn offers(
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Which refactorings the cursor would be offered, and what each title says —
|
||||
/// asked of the buffer's **own** parse and analysis rather than recomputed.
|
||||
///
|
||||
/// `vlog_refactor::port_offers_in` runs each of the four planners' plan-time
|
||||
/// half over `doc`'s existing tree, diagnostics and semantics plus, at most,
|
||||
/// one parse of the instantiated module's declaring file. It builds no index
|
||||
/// and verifies nothing, which is the whole of take 5 §P1c: the offer used to
|
||||
/// compute four verified plans over one or two files and throw all four edits
|
||||
/// away (`docs/features/perf5-p1/README.md`). [`resolve`] still recomputes and
|
||||
/// verifies the real refactoring over the module's whole fan-out when the user
|
||||
/// clicks.
|
||||
///
|
||||
/// A buffer on the large-file fast path keeps the text form, whose parse is of
|
||||
/// the real bytes — [`modules_at`] draws the same line, and for the same
|
||||
/// reason.
|
||||
fn offered(
|
||||
doc: &Document,
|
||||
sources: &[(PathBuf, String)],
|
||||
path: &Path,
|
||||
offset: u32,
|
||||
) -> Vec<vlog_refactor::PortOffer> {
|
||||
match doc.large {
|
||||
true => vlog_refactor::port_offers(sources, path, offset),
|
||||
false => vlog_refactor::port_offers_in(
|
||||
sources,
|
||||
path,
|
||||
&doc.tree,
|
||||
&doc.diagnostics,
|
||||
&doc.semantics,
|
||||
offset,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
/// The files an [`offers`] call reads: the buffer the request names, and the
|
||||
/// declaration of every module an instantiation under the cursor names.
|
||||
///
|
||||
|
||||
@@ -83,6 +83,17 @@ fn opened(tree: &Tree, text: &str) -> (Session, Uri) {
|
||||
(session, uri)
|
||||
}
|
||||
|
||||
/// [`opened`] against a client that can `codeAction/resolve` — the shape that
|
||||
/// is *offered* actions without their edits, which is the path §P1c changed.
|
||||
fn opened_lazily(tree: &Tree, text: &str) -> (Session, Uri) {
|
||||
tree.write("sub.sv", SUB);
|
||||
let abilities = ClientAbilities { code_action_resolve: true, ..Default::default() };
|
||||
let mut session = Session::wide_with(vec![tree.path.clone()], abilities);
|
||||
let uri = session.open(&tree.path.join("m.sv"), text);
|
||||
session.drain();
|
||||
(session, uri)
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// §P1a — the work a filtered request no longer does
|
||||
// ------------------------------------------------------------------
|
||||
@@ -237,26 +248,97 @@ fn the_gate_only_families_parse_nothing_even_where_they_do_offer() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_port_offer_still_reaches_the_engine_and_that_is_what_p1c_is_for() {
|
||||
fn the_port_offer_reads_the_declaring_file_once_and_nothing_else() {
|
||||
let tree = Tree::new("carepeatports");
|
||||
let (mut session, uri) = opened(&tree, FIXABLE);
|
||||
// §P1b gives the port family its gate for free, but a gate that says yes
|
||||
// hands the engine one or two files and the engine parses them to build a
|
||||
// plan whose edits are then thrown away. That residue is measured here
|
||||
// rather than left to be discovered as a slow cursor: it is take 5 §P1c's
|
||||
// subject, and this assertion is what would notice it growing.
|
||||
let (mut session, uri) = opened_lazily(&tree, FIXABLE);
|
||||
// §P1b gave the port family its *gate* for free, but a gate that said yes
|
||||
// still handed the engine one or two files and paid for four verified
|
||||
// plans whose edits were thrown away — 21.15 ms of a 21.83 ms request on
|
||||
// opentitan. §P1c replaced that with a predicate that reads the buffer's
|
||||
// own parse and, at most, one parse of the instantiated module's
|
||||
// declaring file. This assertion is what would notice a second one
|
||||
// reappearing.
|
||||
let only = &["refactor.rewrite.lucisv.ports"];
|
||||
let (_, first) = parses_during(&mut session, filtered(&uri, 2, 2, only));
|
||||
assert!(!kinds(&first).is_empty(), "the port family offers here: {first:#?}");
|
||||
let (parses, _) = parses_during(&mut session, filtered(&uri, 2, 2, only));
|
||||
assert!(parses > 0, "the offer still computes a plan it discards (§P1c)");
|
||||
for round in 0..3 {
|
||||
let (parses, again) = parses_during(&mut session, filtered(&uri, 2, 2, only));
|
||||
assert_eq!(parses, 1, "round {round}: `sub.sv`'s parse, and no other (§P1c)");
|
||||
assert_eq!(again, first, "round {round}: and the same menu every time");
|
||||
}
|
||||
// The buffer's *own* parse is not among them: the gate was answered from
|
||||
// `doc.tree`, so what is left is the engine's own scope over the module's
|
||||
// declaring file.
|
||||
// `doc.tree`, and so is everything the predicate asks of the buffer.
|
||||
let (gate_only, _) = parses_during(&mut session, filtered(&uri, 3, 2, only));
|
||||
assert_eq!(gate_only, 0, "at a cursor the gate refuses, nothing is parsed");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_organize_imports_offer_never_parses_the_buffer_it_is_offered_on() {
|
||||
let tree = Tree::new("caimports");
|
||||
tree.write("a_pkg.sv", "package a_pkg;\n localparam int A = 1;\nendpackage\n");
|
||||
tree.write("b_pkg.sv", "package b_pkg;\n localparam int B = 2;\nendpackage\n");
|
||||
let abilities = ClientAbilities { code_action_resolve: true, ..Default::default() };
|
||||
let mut session = Session::wide_with(vec![tree.path.clone()], abilities);
|
||||
let uri = session.open(
|
||||
&tree.path.join("user.sv"),
|
||||
"module user;\n import b_pkg::*;\n import a_pkg::*;\n logic q;\n assign q = A;\nendmodule\n",
|
||||
);
|
||||
session.drain();
|
||||
let only = &["source.organizeImports"];
|
||||
let (_, first) = parses_during(&mut session, filtered(&uri, 1, 2, only));
|
||||
assert_eq!(
|
||||
titles(&first),
|
||||
vec!["lucisv: organize imports (removes 1, sorts 1)".to_string()],
|
||||
"the unused import goes and the used one is written back: {first:#?}"
|
||||
);
|
||||
// The buffer's own parse, analysis and token stream are the `Document`'s,
|
||||
// and no splice is verified for a menu (§P1c). What is left is one
|
||||
// `Scope::build` — the index that decides which import supplies a used
|
||||
// name — over the buffer and the two packages it imports: **3** parses,
|
||||
// where verifying the splice used to build a second index over the same
|
||||
// three and re-analyze them. The buffer's own share of that index is the
|
||||
// residue §P1c names and does not remove.
|
||||
for round in 0..3 {
|
||||
let (parses, again) = parses_during(&mut session, filtered(&uri, 1, 2, only));
|
||||
assert_eq!(parses, 3, "round {round}: one index over the buffer and its two packages");
|
||||
assert_eq!(again, first, "round {round}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_offer_the_fan_out_refuses_says_so_on_resolve_rather_than_crashing() {
|
||||
let tree = Tree::new("caresolvegone");
|
||||
tree.write("sub.sv", SUB);
|
||||
// `sub`'s one instantiation connects by position, which makes the removal
|
||||
// refuse whole — but it lives in a file the *offer* never reads, since an
|
||||
// offer reads the buffer and the module's declaration and nothing else
|
||||
// (`docs/features/lazy-code-action/README.md`). So the lightbulb appears
|
||||
// and the click declines: the contract §P1c inherited and did not widen.
|
||||
tree.write(
|
||||
"other.sv",
|
||||
"module other;\n logic x;\n logic y;\n sub u_pos (x, y);\nendmodule\n",
|
||||
);
|
||||
let abilities = ClientAbilities { code_action_resolve: true, ..Default::default() };
|
||||
let mut session = Session::wide_with(vec![tree.path.clone()], abilities);
|
||||
let uri = session.open(&tree.path.join("sub.sv"), SUB);
|
||||
session.drain();
|
||||
|
||||
let only = &["refactor.rewrite.lucisv.ports"];
|
||||
let offered = session.result(CodeActionRequest::METHOD, filtered(&uri, 2, 14, only));
|
||||
let titles = titles(&offered);
|
||||
assert_eq!(
|
||||
titles,
|
||||
vec!["lucisv: remove port `b` (updates 1 instantiation)".to_string()],
|
||||
"the offer is made, counted from the index: {offered:#?}"
|
||||
);
|
||||
let action = offered.as_array().and_then(|list| list.first()).expect("the offer").clone();
|
||||
assert!(action.get("edit").is_none(), "a lazy offer carries no edit: {action:#?}");
|
||||
|
||||
let refused = session.request(CodeActionResolveRequest::METHOD, action);
|
||||
let error = refused.response_result.expect_err("the fan-out refuses this removal");
|
||||
assert_eq!(error.message, "lucisv: the action is no longer available.");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_empty_filter_parses_nothing_however_often_it_is_asked() {
|
||||
let tree = Tree::new("carepeatempty");
|
||||
|
||||
@@ -19,16 +19,16 @@ use lsp_types::notification::{
|
||||
PublishDiagnostics, ShowMessage,
|
||||
};
|
||||
use lsp_types::request::{
|
||||
ApplyWorkspaceEdit, CallHierarchyPrepare, CodeActionRequest, CodeLensRefresh, CodeLensRequest,
|
||||
Completion, DocumentDiagnosticRequest, DocumentHighlightRequest, DocumentLinkRequest,
|
||||
DocumentSymbolRequest, ExecuteCommand, FoldingRangeRequest, Formatting, GotoDefinition,
|
||||
GotoTypeDefinition, HoverRequest, InlayHintRequest, InlineCompletionRequest,
|
||||
LinkedEditingRange, OnTypeFormatting, PrepareRenameRequest, RangeFormatting, References,
|
||||
RegisterCapability, Rename, Request as _, SelectionRangeRequest,
|
||||
SemanticTokensFullDeltaRequest, SemanticTokensFullRequest, SemanticTokensRangeRequest,
|
||||
ShowDocument, Shutdown, SignatureHelpRequest, TypeHierarchyPrepare, UnregisterCapability,
|
||||
WillRenameFiles, WillSaveWaitUntil, WorkDoneProgressCreate, WorkspaceConfiguration,
|
||||
WorkspaceDiagnosticRequest, WorkspaceSymbolRequest,
|
||||
ApplyWorkspaceEdit, CallHierarchyPrepare, CodeActionRequest, CodeActionResolveRequest,
|
||||
CodeLensRefresh, CodeLensRequest, Completion, DocumentDiagnosticRequest,
|
||||
DocumentHighlightRequest, DocumentLinkRequest, DocumentSymbolRequest, ExecuteCommand,
|
||||
FoldingRangeRequest, Formatting, GotoDefinition, GotoTypeDefinition, HoverRequest,
|
||||
InlayHintRequest, InlineCompletionRequest, LinkedEditingRange, OnTypeFormatting,
|
||||
PrepareRenameRequest, RangeFormatting, References, RegisterCapability, Rename, Request as _,
|
||||
SelectionRangeRequest, SemanticTokensFullDeltaRequest, SemanticTokensFullRequest,
|
||||
SemanticTokensRangeRequest, ShowDocument, Shutdown, SignatureHelpRequest, TypeHierarchyPrepare,
|
||||
UnregisterCapability, WillRenameFiles, WillSaveWaitUntil, WorkDoneProgressCreate,
|
||||
WorkspaceConfiguration, WorkspaceDiagnosticRequest, WorkspaceSymbolRequest,
|
||||
};
|
||||
use lsp_types::{
|
||||
DidChangeWatchedFilesParams, FileChangeType, FileEvent, LogMessageParams, MessageType,
|
||||
|
||||
@@ -158,20 +158,10 @@ fn organize(
|
||||
let Some(i) = scope.index_of(file) else { return Err(not_in_scope(file)) };
|
||||
let Some(text) = scope.text(i) else { return Err(not_in_scope(file)) };
|
||||
let (tree, diagnostics) = parse_source_tolerant(text);
|
||||
unparsed(file, &diagnostics)?;
|
||||
let semantics = analyze(&tree, text);
|
||||
let Ok(tokens) = tokenize(text) else { return Err(not_in_scope(file)) };
|
||||
|
||||
let here = scope_at(&tree, &semantics, offset)?;
|
||||
let verdicts = import_usage(&semantics, &tokens, here.scope, scope.index())?;
|
||||
let mut blocks = Blocks::read(text, here.items, &verdicts)?;
|
||||
let (edits, warnings, removed, sorted) = blocks.plan(text)?;
|
||||
if edits.is_empty() {
|
||||
return Err(match warnings.first() {
|
||||
Some(sentence) => sentence.clone(),
|
||||
None => "these imports are already sorted, and every one of them is used.".to_string(),
|
||||
});
|
||||
}
|
||||
let (edits, warnings, removed, sorted) =
|
||||
planned(scope.index(), file, text, &tree, &diagnostics, &semantics, &tokens, offset)?;
|
||||
|
||||
let what = "organizing the imports";
|
||||
let plan = vec![(i, edits)];
|
||||
@@ -182,6 +172,96 @@ fn organize(
|
||||
Ok((edit, removed, sorted))
|
||||
}
|
||||
|
||||
/// Everything the organization decides **before** it is verified: its edits,
|
||||
/// the sentences about what it left alone, and the two counts a title
|
||||
/// promises.
|
||||
///
|
||||
/// One reader, so the code action's offer and the edit it resolves to cannot
|
||||
/// come to disagree about how many imports go and how many are sorted.
|
||||
/// `tree`, `diagnostics`, `semantics` and `tokens` must all be of `text`.
|
||||
#[allow(clippy::too_many_arguments)] // one call's worth of already-computed inputs, not state
|
||||
fn planned(
|
||||
index: &vlog_semantic::WorkspaceIndex,
|
||||
file: &Path,
|
||||
text: &str,
|
||||
tree: &SourceFile,
|
||||
diagnostics: &[ParseDiagnostic],
|
||||
semantics: &Semantics,
|
||||
tokens: &[vlog_parser::token::Token],
|
||||
offset: u32,
|
||||
) -> Result<(Vec<TextEdit>, Vec<String>, usize, usize), String> {
|
||||
unparsed(file, diagnostics)?;
|
||||
let here = scope_at(tree, semantics, offset)?;
|
||||
let verdicts = import_usage(semantics, tokens, here.scope, index)?;
|
||||
let mut blocks = Blocks::read(text, here.items, &verdicts)?;
|
||||
let (edits, warnings, removed, sorted) = blocks.plan(text)?;
|
||||
if edits.is_empty() {
|
||||
return Err(match warnings.first() {
|
||||
Some(sentence) => sentence.clone(),
|
||||
None => "these imports are already sorted, and every one of them is used.".to_string(),
|
||||
});
|
||||
}
|
||||
Ok((edits, warnings, removed, sorted))
|
||||
}
|
||||
|
||||
/// What an organize-imports code action's title promises — how many imports it
|
||||
/// removes and how many it writes back in order — **without** verifying the
|
||||
/// splice or keeping the edit.
|
||||
///
|
||||
/// [`organize_counts`] answers the same two numbers by computing the whole
|
||||
/// refactoring and running `check::verify_splice`, which rebuilds the index
|
||||
/// over every in-scope file and re-analyzes them. A lazily-offered code action
|
||||
/// throws that edit away and asks for it again on the click, so the offer pays
|
||||
/// for a verification whose result nothing reads: take 5 §P1c measured that
|
||||
/// verification as about two thirds of the offer's cost
|
||||
/// (`docs/features/perf5-p1/README.md`).
|
||||
///
|
||||
/// Everything the *plan* refuses is refused here identically, with the same
|
||||
/// sentence: a buffer that does not parse, no scope at the position, an
|
||||
/// unknown package (`import_usage`'s own refusal), an import sharing a line,
|
||||
/// and the "already sorted, every one used" answer. What is **not** reproduced
|
||||
/// is `check::verify_splice`; the click recomputes and verifies the whole
|
||||
/// refactoring, which is where an edit that would not survive it is refused.
|
||||
pub fn organize_offer(
|
||||
files: &[(PathBuf, String)],
|
||||
file: &Path,
|
||||
offset: u32,
|
||||
) -> Result<(usize, usize), String> {
|
||||
let scope = Scope::build(files);
|
||||
let Some(i) = scope.index_of(file) else { return Err(not_in_scope(file)) };
|
||||
let Some(text) = scope.text(i) else { return Err(not_in_scope(file)) };
|
||||
let (tree, diagnostics) = parse_source_tolerant(text);
|
||||
let semantics = analyze(&tree, text);
|
||||
let Ok(tokens) = tokenize(text) else { return Err(not_in_scope(file)) };
|
||||
let (_, _, removed, sorted) =
|
||||
planned(scope.index(), file, text, &tree, &diagnostics, &semantics, &tokens, offset)?;
|
||||
Ok((removed, sorted))
|
||||
}
|
||||
|
||||
/// [`organize_offer`] over the parse, analysis and token stream the caller
|
||||
/// already has.
|
||||
///
|
||||
/// All four must be of exactly the text `files` holds for `file` — an open
|
||||
/// buffer's `Document` holds that quartet for its own bytes. A buffer that did
|
||||
/// not lex holds no tokens, but it also holds a parse diagnostic, so
|
||||
/// [`planned`] refuses it before the token stream is read.
|
||||
pub fn organize_offer_in(
|
||||
files: &[(PathBuf, String)],
|
||||
file: &Path,
|
||||
tree: &SourceFile,
|
||||
diagnostics: &[ParseDiagnostic],
|
||||
semantics: &Semantics,
|
||||
tokens: &[vlog_parser::token::Token],
|
||||
offset: u32,
|
||||
) -> Result<(usize, usize), String> {
|
||||
let scope = Scope::build(files);
|
||||
let Some(i) = scope.index_of(file) else { return Err(not_in_scope(file)) };
|
||||
let Some(text) = scope.text(i) else { return Err(not_in_scope(file)) };
|
||||
let (_, _, removed, sorted) =
|
||||
planned(scope.index(), file, text, tree, diagnostics, semantics, tokens, offset)?;
|
||||
Ok((removed, sorted))
|
||||
}
|
||||
|
||||
/// The innermost scope covering the cursor that may write `import` items.
|
||||
fn scope_at<'t>(
|
||||
tree: &'t SourceFile,
|
||||
|
||||
@@ -41,8 +41,8 @@ pub use extract::{
|
||||
extract_module, extract_site, extract_site_in, extract_title, ExtractSite, Home,
|
||||
};
|
||||
pub use imports::{
|
||||
imported_packages, imported_packages_in, organize_counts, organize_imports, organize_title,
|
||||
unused_imports,
|
||||
imported_packages, imported_packages_in, organize_counts, organize_imports, organize_offer,
|
||||
organize_offer_in, organize_title, unused_imports,
|
||||
};
|
||||
pub use inline::{inline_module, inline_site, inline_site_in, inline_title, InlineSite};
|
||||
pub use references::find_references;
|
||||
@@ -53,8 +53,9 @@ pub use instantiate::{
|
||||
};
|
||||
pub use ports::{
|
||||
add_port, convert_to_ansi, enclosing_module, expand_wildcard, is_sites_phrase,
|
||||
may_have_port_action, port_action_modules, port_action_modules_in, port_actions,
|
||||
propagate_ports, remove_port, sites_phrase, ModuleRef, PortAction,
|
||||
may_have_port_action, port_action_modules, port_action_modules_in, port_actions, port_offers,
|
||||
port_offers_in, propagate_ports, remove_port, sites_phrase, ModuleRef, PortAction, PortOffer,
|
||||
PortOfferKind,
|
||||
};
|
||||
pub use rename::{
|
||||
contains_word, prepare_rename, prepare_rename_here, rename, rename_name_at, RenameTarget,
|
||||
|
||||
@@ -64,8 +64,32 @@ pub(super) fn plan_convert(
|
||||
let Some((module, _)) = find_module(&tree, &name) else {
|
||||
return Err(format!("lucisv can no longer find the declaration of `{name}`."));
|
||||
};
|
||||
let ports = convert_header(file, &diagnostics, module)?;
|
||||
let site = locate_module(scope, ModuleRef::Name(&name))?;
|
||||
if site.file != i {
|
||||
return Err(elsewhere(&name));
|
||||
}
|
||||
|
||||
let mut plan = Plan::default();
|
||||
plan.add(i, convert_edits(text, file, module, &ports)?);
|
||||
plan.expected.push((i, shape(text, &name)));
|
||||
Ok(Conversion { site, plan, count: ports.len() })
|
||||
}
|
||||
|
||||
/// Everything the conversion refuses **before** it asks where the module is
|
||||
/// declared: the header it needs, the parse, a name written twice, a directive
|
||||
/// in the port list, a declaration hidden in a generate region.
|
||||
///
|
||||
/// Split out of [`plan_convert`] so the code-action offer earns the same
|
||||
/// refusals from the buffer's own parse (take 5 §P1c, `ports::offer`).
|
||||
pub(super) fn convert_header<'t>(
|
||||
file: &Path,
|
||||
diagnostics: &[ParseDiagnostic],
|
||||
module: &'t Module,
|
||||
) -> Result<Vec<&'t NonAnsiPort>, String> {
|
||||
let name = &module.name;
|
||||
let ports = header(module)?;
|
||||
unparsed(file, &diagnostics)?;
|
||||
unparsed(file, diagnostics)?;
|
||||
let names = header_names(module, &ports)?;
|
||||
if !module.port_directives.is_empty() {
|
||||
return Err(format!(
|
||||
@@ -77,28 +101,41 @@ pub(super) fn plan_convert(
|
||||
"`{name}` declares `{hidden}` inside a generate region, where lucisv will not read a port's declaration; it made no edits."
|
||||
));
|
||||
}
|
||||
let site = locate_module(scope, ModuleRef::Name(&name))?;
|
||||
if site.file != i {
|
||||
return Err(format!(
|
||||
"`{name}`'s indexed declaration is in another file than the one under the cursor; lucisv made no edits."
|
||||
));
|
||||
}
|
||||
Ok(ports)
|
||||
}
|
||||
|
||||
let absorbed = absorb(text, &name, &module.items, &names)?;
|
||||
attributes_clear(&name, &absorbed)?;
|
||||
/// The sentence a module whose indexed declaration is elsewhere earns.
|
||||
pub(super) fn elsewhere(name: &str) -> String {
|
||||
format!(
|
||||
"`{name}`'s indexed declaration is in another file than the one under the cursor; lucisv made no edits."
|
||||
)
|
||||
}
|
||||
|
||||
/// The conversion's edits, once the module's declaration is known to be the
|
||||
/// cursor's own file: the insertions around each header name, then the
|
||||
/// deletions of the body declarations they absorbed.
|
||||
pub(super) fn convert_edits(
|
||||
text: &str,
|
||||
file: &Path,
|
||||
module: &Module,
|
||||
ports: &[&NonAnsiPort],
|
||||
) -> Result<Vec<TextEdit>, String> {
|
||||
let name = &module.name;
|
||||
let names: Vec<String> = ports.iter().map(|port| port.name.clone()).collect();
|
||||
let absorbed = absorb(text, name, &module.items, &names)?;
|
||||
attributes_clear(name, &absorbed)?;
|
||||
directives_clear(text, file, module, &absorbed)?;
|
||||
let comments = comments_of(text, file)?;
|
||||
let mut plan = Plan::default();
|
||||
let mut edits = Vec::new();
|
||||
// One declaration may declare several ports (`input a, b;`), and its
|
||||
// comments belong to the first of them: written onto both they would be
|
||||
// duplicated, which is as much a corruption as dropping them.
|
||||
let mut claimed: Vec<TextRange> = Vec::new();
|
||||
for (port, absorbed) in ports.iter().zip(&absorbed) {
|
||||
plan.add(i, port_edits(text, &name, port, absorbed, &comments, &mut claimed)?);
|
||||
edits.append(&mut port_edits(text, name, port, absorbed, &comments, &mut claimed)?);
|
||||
}
|
||||
plan.add(i, deletions(text, &name, &absorbed, &comments)?);
|
||||
plan.expected.push((i, shape(text, &name)));
|
||||
Ok(Conversion { site, plan, count: ports.len() })
|
||||
edits.append(&mut deletions(text, name, &absorbed, &comments)?);
|
||||
Ok(edits)
|
||||
}
|
||||
|
||||
/// The non-ANSI port list this conversion needs, or the sentence saying why
|
||||
|
||||
@@ -19,7 +19,9 @@
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use vlog_parser::ast::{Connection, Connections, Instance, Instantiation, Item, ListElem};
|
||||
use vlog_parser::ast::{
|
||||
Connection, Connections, Instance, Instantiation, Item, ListElem, SourceFile,
|
||||
};
|
||||
use vlog_parser::span::TextRange;
|
||||
use vlog_parser::{parse_source_tolerant, LineIndex, ParseDiagnostic};
|
||||
use vlog_semantic::SymbolKind;
|
||||
@@ -113,16 +115,16 @@ fn directives(what: &str, list: &str) -> String {
|
||||
|
||||
/// What the cursor found: an instance, its named connection list, and which
|
||||
/// element of it is the `.*`.
|
||||
struct Wildcard<'t> {
|
||||
instantiation: &'t Instantiation,
|
||||
instance: &'t Instance,
|
||||
conns: &'t [ListElem<Connection>],
|
||||
wildcard: usize,
|
||||
pub(super) struct Wildcard<'t> {
|
||||
pub(super) instantiation: &'t Instantiation,
|
||||
pub(super) instance: &'t Instance,
|
||||
pub(super) conns: &'t [ListElem<Connection>],
|
||||
pub(super) wildcard: usize,
|
||||
}
|
||||
|
||||
/// The instantiation the cursor names and the `.*` inside it, or the sentence
|
||||
/// saying why there is none to expand.
|
||||
fn wildcard_at(items: &[Item], offset: u32) -> Result<Wildcard<'_>, String> {
|
||||
pub(super) fn wildcard_at(items: &[Item], offset: u32) -> Result<Wildcard<'_>, String> {
|
||||
let (instantiation, instance, bound) = instance_at(items, offset)?;
|
||||
if bound {
|
||||
return Err(format!(
|
||||
@@ -193,14 +195,26 @@ fn unconnected(
|
||||
let Some(text) = scope.text(site.file) else { return Err(not_indexed(&site.name)) };
|
||||
let Some(path) = scope.path(site.file) else { return Err(not_indexed(&site.name)) };
|
||||
let (tree, diagnostics) = parse_source_tolerant(text);
|
||||
unparsed(path, &diagnostics)?;
|
||||
let Some((module, _)) = find_module(&tree, &site.name) else {
|
||||
return Err(not_indexed(&site.name));
|
||||
unconnected_in(path, &tree, &diagnostics, &site.name, conns)
|
||||
}
|
||||
|
||||
/// [`unconnected`] over the declaring file's parse, which the code-action
|
||||
/// offer makes once instead of once per refactoring (take 5 §P1c).
|
||||
pub(super) fn unconnected_in(
|
||||
path: &Path,
|
||||
tree: &SourceFile,
|
||||
diagnostics: &[ParseDiagnostic],
|
||||
module: &str,
|
||||
conns: &[ListElem<Connection>],
|
||||
) -> Result<Vec<String>, String> {
|
||||
unparsed(path, diagnostics)?;
|
||||
let Some((declaration, _)) = find_module(tree, module) else {
|
||||
return Err(not_indexed(module));
|
||||
};
|
||||
if !module.port_directives.is_empty() {
|
||||
return Err(directives(&site.name, "port list"));
|
||||
if !declaration.port_directives.is_empty() {
|
||||
return Err(directives(module, "port list"));
|
||||
}
|
||||
Ok(declared_ports(module)
|
||||
Ok(declared_ports(declaration)
|
||||
.into_iter()
|
||||
.map(|port| port.name)
|
||||
.filter(|name| conns.iter().filter_map(ListElem::ok).all(|c| &c.name != name))
|
||||
|
||||
@@ -27,10 +27,12 @@ mod expand;
|
||||
mod find;
|
||||
mod list;
|
||||
mod merge;
|
||||
mod offer;
|
||||
mod propagate;
|
||||
mod remove;
|
||||
|
||||
pub(crate) use find::{find_module, visible_in};
|
||||
pub use offer::{port_offers, port_offers_in, PortOffer, PortOfferKind};
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
|
||||
@@ -0,0 +1,416 @@
|
||||
//! Which port refactorings a cursor would be *offered*, and what each one's
|
||||
//! title promises — without a workspace index, without an analysis of any file
|
||||
//! but the cursor's own, and without verifying anything.
|
||||
//!
|
||||
//! **Why this exists.** [`super::port_actions`] answers the same question by
|
||||
//! computing all four refactorings in full and handing back their verified
|
||||
//! edits. A client that can `codeAction/resolve` throws every one of those
|
||||
//! edits away and asks for the real one when the user clicks, so the offer was
|
||||
//! paying for four `Scope::build`s — an index over the buffer and the
|
||||
//! instantiated module's declaring file, each file lexed, parsed and analyzed
|
||||
//! once per refactoring — to render a menu. Take 5 §P1b measured what that
|
||||
//! costs at one ordinary opentitan cursor: **21.15 ms of a 21.83 ms request,
|
||||
//! for zero offered actions**. See `docs/features/perf5-p1/README.md`.
|
||||
//!
|
||||
//! **What it does instead.** Each of the four is asked its *plan-time*
|
||||
//! questions — the ones that read the cursor's own file, the module's
|
||||
//! declaration, and nothing else — in the same order, with the same helpers,
|
||||
//! so the same conditions produce the same silence. The declaring file is
|
||||
//! parsed at most once and only when a refactoring needs it; the cursor's own
|
||||
//! parse and analysis come from the caller.
|
||||
//!
|
||||
//! **What it cannot see, and who does.** Two refusals live *after* the plan
|
||||
//! and are not reproduced here: [`crate::check::verify_splice`] (the token,
|
||||
//! comment and resolution comparison of the whole edit) and `ports::confirm`
|
||||
//! (reading the edited text back and requiring the port and connection lists
|
||||
//! to say what the plan promised). An offer this query makes that one of those
|
||||
//! two would refuse is answered by `codeAction/resolve`, which recomputes and
|
||||
//! verifies the whole refactoring over the module's real fan-out and says the
|
||||
//! action is no longer available. That is the offer's existing contract —
|
||||
//! "the offer may be optimistic; the resolve is exact"
|
||||
//! (`docs/features/lazy-code-action/README.md`) — and this query widens it by
|
||||
//! exactly those two checks over one or two files, nothing else.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use vlog_parser::ast::{ItemKind, SourceFile};
|
||||
use vlog_parser::span::TextRange;
|
||||
use vlog_parser::{parse_source_tolerant, ParseDiagnostic};
|
||||
use vlog_semantic::{analyze, Semantics};
|
||||
|
||||
use crate::TextEdit;
|
||||
|
||||
use super::ansi::{convert_edits, convert_header};
|
||||
use super::expand::{unconnected_in, wildcard_at, Wildcard};
|
||||
use super::find::{declared_ports, find_module, module_at, visible_in};
|
||||
use super::list::{append_to_list, conn_list_open, elem_spans};
|
||||
use super::propagate::{connections_of, instance_at, missing_ports};
|
||||
use super::remove::{body_uses_in, disconnections_in, header_removal, port_at};
|
||||
use super::{port_action_modules_in, sites_phrase, Plan};
|
||||
|
||||
/// Which of the four port refactorings an offer names.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum PortOfferKind {
|
||||
/// Remove the port under the cursor.
|
||||
Remove,
|
||||
/// Connect the ports this instantiation is missing.
|
||||
Propagate,
|
||||
/// Write out the `.*` under the cursor.
|
||||
Expand,
|
||||
/// Rewrite this Verilog-2001 header ANSI-style.
|
||||
Convert,
|
||||
}
|
||||
|
||||
/// One refactoring a cursor would be offered: the lightbulb's own words, and
|
||||
/// which refactoring will compute the edit when the user picks it.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct PortOffer {
|
||||
/// What the lightbulb says — byte for byte what [`super::port_actions`]
|
||||
/// would have written for the same refactoring at the same cursor.
|
||||
pub title: String,
|
||||
/// The refactoring behind the title.
|
||||
pub kind: PortOfferKind,
|
||||
}
|
||||
|
||||
/// Every port refactoring available at a position, **as a menu**: the titles,
|
||||
/// with no edit computed and nothing verified.
|
||||
///
|
||||
/// The in-scope files are the same ones [`super::port_actions`] takes, and the
|
||||
/// answer is the same list of titles at every position except where one of the
|
||||
/// two post-plan checks named in this module's own documentation would have
|
||||
/// refused.
|
||||
pub fn port_offers(files: &[(PathBuf, String)], file: &Path, offset: u32) -> Vec<PortOffer> {
|
||||
let Some((_, text)) = files.iter().find(|(path, _)| path == file) else { return Vec::new() };
|
||||
let (tree, diagnostics) = parse_source_tolerant(text);
|
||||
let semantics = analyze(&tree, text);
|
||||
port_offers_in(files, file, &tree, &diagnostics, &semantics, offset)
|
||||
}
|
||||
|
||||
/// [`port_offers`] over a parse and an analysis the caller already has.
|
||||
///
|
||||
/// `tree`, `diagnostics` and `semantics` must be of exactly the text `files`
|
||||
/// holds for `file` — an open buffer's `Document` holds that trio for its own
|
||||
/// bytes, which is the whole point (take 5 §P1c). Every other file is parsed
|
||||
/// here, at most once, and only if a refactoring asks for it.
|
||||
pub fn port_offers_in(
|
||||
files: &[(PathBuf, String)],
|
||||
file: &Path,
|
||||
tree: &SourceFile,
|
||||
diagnostics: &[ParseDiagnostic],
|
||||
semantics: &Semantics,
|
||||
offset: u32,
|
||||
) -> Vec<PortOffer> {
|
||||
let Some((_, text)) = files.iter().find(|(path, _)| path == file) else { return Vec::new() };
|
||||
if port_action_modules_in(tree, offset).is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
let Some(mut sources) = Files::new(files, file) else { return Vec::new() };
|
||||
let here = Buffer { file, text, tree, diagnostics, semantics };
|
||||
|
||||
let mut out = Vec::new();
|
||||
out.extend(removal(&here, &mut sources, offset));
|
||||
out.extend(propagation(&here, &mut sources, offset));
|
||||
out.extend(expansion(&here, &mut sources, offset));
|
||||
out.extend(conversion(&here, &mut sources, offset));
|
||||
out
|
||||
}
|
||||
|
||||
/// The buffer the cursor is in, with the parse and analysis of exactly its
|
||||
/// bytes.
|
||||
struct Buffer<'a> {
|
||||
file: &'a Path,
|
||||
text: &'a str,
|
||||
tree: &'a SourceFile,
|
||||
diagnostics: &'a [ParseDiagnostic],
|
||||
semantics: &'a Semantics,
|
||||
}
|
||||
|
||||
/// Where the one declaration of a module is.
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
enum Declared {
|
||||
/// In the buffer the cursor is in.
|
||||
Here,
|
||||
/// In another in-scope file.
|
||||
In(usize),
|
||||
}
|
||||
|
||||
/// One file's tolerant parse, kept so a second refactoring asking the same
|
||||
/// question does not pay for it again.
|
||||
struct Parsed {
|
||||
tree: SourceFile,
|
||||
diagnostics: Vec<ParseDiagnostic>,
|
||||
}
|
||||
|
||||
/// The in-scope files, normalized exactly the way [`crate::scope::Scope`]
|
||||
/// normalizes them, parsed one at a time and only on demand.
|
||||
struct Files<'a> {
|
||||
sources: Vec<(&'a Path, &'a str)>,
|
||||
/// Index of the buffer the cursor is in.
|
||||
here: usize,
|
||||
parsed: Vec<Option<Parsed>>,
|
||||
}
|
||||
|
||||
impl<'a> Files<'a> {
|
||||
fn new(files: &'a [(PathBuf, String)], file: &Path) -> Option<Files<'a>> {
|
||||
let mut sources: Vec<(&Path, &str)> =
|
||||
files.iter().map(|(p, t)| (p.as_path(), t.as_str())).collect();
|
||||
// `Scope::build`'s own normalization, so "which file declares this"
|
||||
// is asked of the same set the eager path asks it of.
|
||||
sources.sort_by(|a, b| a.0.cmp(b.0));
|
||||
sources.dedup_by(|a, b| a.0 == b.0);
|
||||
let here = sources.iter().position(|(path, _)| *path == file)?;
|
||||
let parsed = sources.iter().map(|_| None).collect();
|
||||
Some(Files { sources, here, parsed })
|
||||
}
|
||||
|
||||
fn len(&self) -> usize {
|
||||
self.sources.len()
|
||||
}
|
||||
|
||||
/// One file's parse, computed on first use. Never called for the buffer:
|
||||
/// its parse is the caller's.
|
||||
fn parsed(&mut self, i: usize) -> Option<&Parsed> {
|
||||
let (_, text) = *self.sources.get(i)?;
|
||||
let slot = self.parsed.get_mut(i)?;
|
||||
if slot.is_none() {
|
||||
let (tree, diagnostics) = parse_source_tolerant(text);
|
||||
*slot = Some(Parsed { tree, diagnostics });
|
||||
}
|
||||
slot.as_ref()
|
||||
}
|
||||
|
||||
/// Which in-scope file declares `name`, or nothing when the files declare
|
||||
/// it twice or not at all.
|
||||
///
|
||||
/// This is `find::locate_module`'s question — `WorkspaceIndex::units(name)`
|
||||
/// filtered by `SymbolKind::is_instantiable`, of which there must be
|
||||
/// exactly one — asked of the parses instead of an index. A unit is a
|
||||
/// **file-scope** declaration, and every file-scope `module`, `interface`
|
||||
/// or `program` item is bound as `SymbolKind::Module` or
|
||||
/// `SymbolKind::Interface` (`vlog_semantic::bind::item::bind_module`), so
|
||||
/// the two counts are the same count. A module nested inside another
|
||||
/// module or a package is not a unit, and is not one here either.
|
||||
fn declaring(&mut self, tree: &SourceFile, name: &str) -> Option<Declared> {
|
||||
let mut found = None;
|
||||
let mut units = 0usize;
|
||||
for i in 0..self.sources.len() {
|
||||
let (_, text) = *self.sources.get(i)?;
|
||||
let here = i == self.here;
|
||||
// A file whose bytes never spell the name declares nothing by it,
|
||||
// so it need not be parsed to be ruled out.
|
||||
if !here && !text.contains(name) {
|
||||
continue;
|
||||
}
|
||||
let n = match here {
|
||||
true => units_named(tree, name),
|
||||
false => self.parsed(i).map_or(0, |parsed| units_named(&parsed.tree, name)),
|
||||
};
|
||||
if n > 0 {
|
||||
units += n;
|
||||
found = Some(match here {
|
||||
true => Declared::Here,
|
||||
false => Declared::In(i),
|
||||
});
|
||||
}
|
||||
}
|
||||
(units == 1).then_some(found)?
|
||||
}
|
||||
|
||||
/// The parse of the file declaring a module, and how it is named in a
|
||||
/// refusal.
|
||||
fn declaration<'s, 'b: 's>(
|
||||
&'s mut self,
|
||||
buffer: &'b Buffer<'b>,
|
||||
at: Declared,
|
||||
) -> Option<(&'s Path, &'s SourceFile, &'s [ParseDiagnostic])> {
|
||||
match at {
|
||||
Declared::Here => Some((buffer.file, buffer.tree, buffer.diagnostics)),
|
||||
Declared::In(i) => {
|
||||
let (path, _) = *self.sources.get(i)?;
|
||||
let parsed = self.parsed(i)?;
|
||||
Some((path, &parsed.tree, &parsed.diagnostics))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// One file's share of a removal: the refusal it may earn, and how many
|
||||
/// instantiations it would rewrite.
|
||||
fn disconnections(
|
||||
&mut self,
|
||||
buffer: &Buffer<'_>,
|
||||
i: usize,
|
||||
module: &str,
|
||||
port: &str,
|
||||
warnings: &mut Vec<String>,
|
||||
) -> Result<(Vec<TextEdit>, usize), String> {
|
||||
let Some((path, text)) = self.sources.get(i).copied() else { return Ok((Vec::new(), 0)) };
|
||||
if !text.contains(module) {
|
||||
return Ok((Vec::new(), 0));
|
||||
}
|
||||
if i == self.here {
|
||||
return disconnections_in(text, path, buffer.tree, module, port, warnings);
|
||||
}
|
||||
match self.parsed(i) {
|
||||
Some(parsed) => disconnections_in(text, path, &parsed.tree, module, port, warnings),
|
||||
None => Ok((Vec::new(), 0)),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// How many file-scope module or interface declarations of `name` a parse
|
||||
/// holds — see [`Files::declaring`] for why that is the index's own count.
|
||||
fn units_named(tree: &SourceFile, name: &str) -> usize {
|
||||
tree.items
|
||||
.iter()
|
||||
.filter(|item| match &item.kind {
|
||||
ItemKind::Module(module) => module.name == name && !module.name_span.is_empty(),
|
||||
_ => false,
|
||||
})
|
||||
.count()
|
||||
}
|
||||
|
||||
/// A settled plan's edits, or nothing where `finish` would have refused before
|
||||
/// verifying: two edits that overlap, or no edit at all.
|
||||
fn settled(plan: &mut Plan) -> Option<usize> {
|
||||
plan.settle().ok()?;
|
||||
let edits: usize = plan.edits.iter().map(|(_, file)| file.len()).sum();
|
||||
(edits > 0).then_some(edits)
|
||||
}
|
||||
|
||||
/// "remove port `p`" — `plan_remove`'s decisions over the buffer's own parse
|
||||
/// and analysis.
|
||||
///
|
||||
/// The count is this query's own census of the instantiations it can see,
|
||||
/// which is what the eager title counts too; a server that has read no fan-out
|
||||
/// replaces the phrase with its index's count (`ports::counted`).
|
||||
fn removal(buffer: &Buffer<'_>, files: &mut Files<'_>, offset: u32) -> Option<PortOffer> {
|
||||
let (module_name, port) = port_at(buffer.tree, offset).ok()?;
|
||||
if files.declaring(buffer.tree, &module_name)? != Declared::Here {
|
||||
return None;
|
||||
}
|
||||
let (module, _) = find_module(buffer.tree, &module_name)?;
|
||||
let ports = declared_ports(module);
|
||||
let index = ports.iter().position(|declared| declared.name == port)?;
|
||||
let header = header_removal(buffer.text, module, &ports, index, &port).ok()?;
|
||||
if !body_uses_in(buffer.text, buffer.semantics, module, &port, &header).is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut plan = Plan::default();
|
||||
plan.add(files.here, header);
|
||||
let mut warnings = Vec::new();
|
||||
for i in 0..files.len() {
|
||||
let (edits, sites) =
|
||||
files.disconnections(buffer, i, &module_name, &port, &mut warnings).ok()?;
|
||||
plan.sites += sites;
|
||||
plan.add(i, edits);
|
||||
}
|
||||
settled(&mut plan)?;
|
||||
Some(PortOffer {
|
||||
title: format!("lucisv: remove port `{port}` ({})", sites_phrase(plan.sites)),
|
||||
kind: PortOfferKind::Remove,
|
||||
})
|
||||
}
|
||||
|
||||
/// "connect N missing ports" — `plan_propagate`'s decisions, and its own
|
||||
/// append loop, which is what decides N: a connection written after a `//`
|
||||
/// comment takes two edits rather than one, and the title counts edits.
|
||||
fn propagation(buffer: &Buffer<'_>, files: &mut Files<'_>, offset: u32) -> Option<PortOffer> {
|
||||
let (instantiation, instance) = instance_at(buffer.tree, offset).ok()?;
|
||||
let module_name = instantiation.module.clone();
|
||||
let at = files.declaring(buffer.tree, &module_name)?;
|
||||
let conns = connections_of(instantiation, instance).ok()?;
|
||||
let missing = {
|
||||
let (_, tree, _) = files.declaration(buffer, at)?;
|
||||
let (declaration, _) = find_module(tree, &module_name)?;
|
||||
missing_ports(declaration, conns)
|
||||
};
|
||||
if missing.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut spans: Vec<TextRange> = elem_spans(conns, |c| c.span);
|
||||
let open = conn_list_open(buffer.text, instance, spans.first().copied())?;
|
||||
let cursor = instance.name_span.start;
|
||||
let mut edits = Vec::new();
|
||||
for name in &missing {
|
||||
let expr = match visible_in(buffer.semantics, cursor, name) {
|
||||
true => name.clone(),
|
||||
false => "/* TODO: connect */".to_string(),
|
||||
};
|
||||
let mut written =
|
||||
append_to_list(buffer.text, Some(open), &spans, &format!(".{name}({expr})"));
|
||||
// Each connection is appended after the previous one, so the next
|
||||
// append sees it as the list's last element.
|
||||
let start = written.last().map_or(open, |edit| edit.range.start);
|
||||
spans.push(TextRange::new(start, start));
|
||||
edits.append(&mut written);
|
||||
}
|
||||
let mut plan = Plan::default();
|
||||
plan.add(files.here, edits);
|
||||
let count = settled(&mut plan)?;
|
||||
Some(PortOffer {
|
||||
title: format!("lucisv: connect {count} missing port{}", if count == 1 { "" } else { "s" }),
|
||||
kind: PortOfferKind::Propagate,
|
||||
})
|
||||
}
|
||||
|
||||
/// "expand .* (N connections)" — `plan_expand`'s decisions. N is the number of
|
||||
/// ports the wildcard stands for, which the declaration alone decides; whether
|
||||
/// each is bound only changes what is written, never how many.
|
||||
fn expansion(buffer: &Buffer<'_>, files: &mut Files<'_>, offset: u32) -> Option<PortOffer> {
|
||||
if !buffer.diagnostics.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let Wildcard { instantiation, instance, conns, wildcard } =
|
||||
wildcard_at(&buffer.tree.items, offset).ok()?;
|
||||
if !instance.conn_directives.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let module_name = instantiation.module.clone();
|
||||
let at = files.declaring(buffer.tree, &module_name)?;
|
||||
let missing = {
|
||||
let (path, tree, diagnostics) = files.declaration(buffer, at)?;
|
||||
unconnected_in(path, tree, diagnostics, &module_name, conns).ok()?
|
||||
};
|
||||
if missing.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let spans: Vec<TextRange> = elem_spans(conns, |c| c.span);
|
||||
conn_list_open(buffer.text, instance, spans.first().copied())?;
|
||||
spans.get(wildcard)?;
|
||||
let count = missing.len();
|
||||
Some(PortOffer {
|
||||
title: format!(
|
||||
"lucisv: expand .* ({count} connection{})",
|
||||
if count == 1 { "" } else { "s" }
|
||||
),
|
||||
kind: PortOfferKind::Expand,
|
||||
})
|
||||
}
|
||||
|
||||
/// "convert ports to ANSI (N ports)" — `plan_convert`'s decisions, in its own
|
||||
/// order: the header refusals first, then where the module is declared, then
|
||||
/// the merge.
|
||||
fn conversion(buffer: &Buffer<'_>, files: &mut Files<'_>, offset: u32) -> Option<PortOffer> {
|
||||
let mut found = None;
|
||||
module_at(&buffer.tree.items, offset, &mut found);
|
||||
let name = found?;
|
||||
let (module, _) = find_module(buffer.tree, &name)?;
|
||||
let ports = convert_header(buffer.file, buffer.diagnostics, module).ok()?;
|
||||
if files.declaring(buffer.tree, &name)? != Declared::Here {
|
||||
return None;
|
||||
}
|
||||
let edits = convert_edits(buffer.text, buffer.file, module, &ports).ok()?;
|
||||
let mut plan = Plan::default();
|
||||
plan.add(files.here, edits);
|
||||
settled(&mut plan)?;
|
||||
let count = ports.len();
|
||||
Some(PortOffer {
|
||||
title: format!(
|
||||
"lucisv: convert ports to ANSI ({count} port{})",
|
||||
if count == 1 { "" } else { "s" }
|
||||
),
|
||||
kind: PortOfferKind::Convert,
|
||||
})
|
||||
}
|
||||
@@ -5,7 +5,9 @@
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use vlog_parser::ast::{Connections, Instance, Instantiation, ListElem};
|
||||
use vlog_parser::ast::{
|
||||
Connection, Connections, Instance, Instantiation, ListElem, Module, SourceFile,
|
||||
};
|
||||
use vlog_parser::span::TextRange;
|
||||
use vlog_parser::{parse_source_tolerant, LineIndex};
|
||||
|
||||
@@ -19,19 +21,17 @@ use super::find::{
|
||||
use super::list::{append_to_list, conn_list_open, elem_spans};
|
||||
use super::{shape, ModuleRef, Plan};
|
||||
|
||||
pub(super) fn plan_propagate(
|
||||
scope: &mut Scope,
|
||||
file: &Path,
|
||||
/// The instance under the cursor, or the only one of the instantiation the
|
||||
/// cursor's module name belongs to.
|
||||
///
|
||||
/// Read off one file's parse, so the code-action offer asks it of the buffer's
|
||||
/// own tree (take 5 §P1c, `ports::offer`).
|
||||
pub(super) fn instance_at(
|
||||
tree: &SourceFile,
|
||||
offset: u32,
|
||||
) -> Result<(ModuleSite, Plan), String> {
|
||||
let Some(i) = scope.index_of(file) else { return Err(not_in_scope(file)) };
|
||||
let Some(text) = scope.text(i) else { return Err(not_in_scope(file)) };
|
||||
let (tree, _) = parse_source_tolerant(text);
|
||||
) -> Result<(&Instantiation, &Instance), String> {
|
||||
let mut instantiations = Vec::new();
|
||||
collect_instantiations(&tree.items, &mut instantiations);
|
||||
|
||||
// The instance under the cursor, or the only one of the instantiation the
|
||||
// cursor's module name belongs to.
|
||||
let mut found: Option<(&Instantiation, &Instance)> = None;
|
||||
for instantiation in &instantiations {
|
||||
for instance in &instantiation.instances {
|
||||
@@ -50,11 +50,15 @@ pub(super) fn plan_propagate(
|
||||
found = Some((instantiation, only));
|
||||
}
|
||||
}
|
||||
let Some((instantiation, instance)) = found else {
|
||||
return Err("there is no module instantiation at this position.".to_string());
|
||||
};
|
||||
let site = locate_module(scope, ModuleRef::Name(&instantiation.module))?;
|
||||
found.ok_or_else(|| "there is no module instantiation at this position.".to_string())
|
||||
}
|
||||
|
||||
/// The named connection list a propagation can append to, or the sentence
|
||||
/// saying why this instance has none.
|
||||
pub(super) fn connections_of<'t>(
|
||||
instantiation: &Instantiation,
|
||||
instance: &'t Instance,
|
||||
) -> Result<&'t [ListElem<Connection>], String> {
|
||||
let conns = match &instance.conns {
|
||||
Connections::Ordered(_) => {
|
||||
return Err(format!(
|
||||
@@ -62,7 +66,7 @@ pub(super) fn plan_propagate(
|
||||
instance.name, instantiation.module
|
||||
))
|
||||
}
|
||||
Connections::Named(conns) => conns,
|
||||
Connections::Named(conns) => conns.as_slice(),
|
||||
};
|
||||
// An error element names no port: it neither connects one nor blocks one.
|
||||
if conns.iter().filter_map(ListElem::ok).any(|c| c.name == "*") {
|
||||
@@ -71,18 +75,37 @@ pub(super) fn plan_propagate(
|
||||
instance.name
|
||||
));
|
||||
}
|
||||
Ok(conns)
|
||||
}
|
||||
|
||||
/// The ports the instantiated module declares that this instance does not
|
||||
/// connect, in declaration order.
|
||||
pub(super) fn missing_ports(module: &Module, conns: &[ListElem<Connection>]) -> Vec<String> {
|
||||
declared_ports(module)
|
||||
.iter()
|
||||
.map(|p| p.name.clone())
|
||||
.filter(|name| conns.iter().filter_map(ListElem::ok).all(|c| &c.name != name))
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(super) fn plan_propagate(
|
||||
scope: &mut Scope,
|
||||
file: &Path,
|
||||
offset: u32,
|
||||
) -> Result<(ModuleSite, Plan), String> {
|
||||
let Some(i) = scope.index_of(file) else { return Err(not_in_scope(file)) };
|
||||
let Some(text) = scope.text(i) else { return Err(not_in_scope(file)) };
|
||||
let (tree, _) = parse_source_tolerant(text);
|
||||
let (instantiation, instance) = instance_at(&tree, offset)?;
|
||||
let site = locate_module(scope, ModuleRef::Name(&instantiation.module))?;
|
||||
let conns = connections_of(instantiation, instance)?;
|
||||
|
||||
let Some(module_text) = scope.text(site.file) else { return Err(not_indexed(&site.name)) };
|
||||
let (module_tree, _) = parse_source_tolerant(module_text);
|
||||
let Some((module, _)) = find_module(&module_tree, &site.name) else {
|
||||
return Err(not_indexed(&site.name));
|
||||
};
|
||||
let declared = declared_ports(module);
|
||||
let missing: Vec<String> = declared
|
||||
.iter()
|
||||
.map(|p| p.name.clone())
|
||||
.filter(|name| conns.iter().filter_map(ListElem::ok).all(|c| &c.name != name))
|
||||
.collect();
|
||||
let missing = missing_ports(module, conns);
|
||||
if missing.is_empty() {
|
||||
return Err(format!(
|
||||
"`{}` already connects every port `{}` declares.",
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
|
||||
use std::path::Path;
|
||||
|
||||
use vlog_parser::ast::{Connections, ItemKind, ListElem, Module, PortList};
|
||||
use vlog_parser::ast::{Connections, ItemKind, ListElem, Module, PortList, SourceFile};
|
||||
use vlog_parser::span::TextRange;
|
||||
use vlog_parser::{parse_source_tolerant, LineIndex};
|
||||
use vlog_semantic::SymbolKind;
|
||||
@@ -31,12 +31,27 @@ pub(super) fn locate_port(
|
||||
let Some(i) = scope.index_of(file) else { return Err(not_in_scope(file)) };
|
||||
let Some(text) = scope.text(i) else { return Err(not_in_scope(file)) };
|
||||
let (tree, _) = parse_source_tolerant(text);
|
||||
let (module_name, name) = port_at(&tree, offset)?;
|
||||
let site = locate_module(scope, ModuleRef::Name(&module_name))?;
|
||||
if site.file != i {
|
||||
return Err(ambiguous(&module_name));
|
||||
}
|
||||
Ok((site, name))
|
||||
}
|
||||
|
||||
/// The module and port name the cursor sits on, read off one file's parse —
|
||||
/// [`locate_port`] without the workspace half.
|
||||
///
|
||||
/// The cursor may be on the header port or, for a non-ANSI module, on its body
|
||||
/// declaration. Split out so the code-action *offer* can ask the same question
|
||||
/// of the buffer's own parse (take 5 §P1c, `ports::offer`).
|
||||
pub(super) fn port_at(tree: &SourceFile, offset: u32) -> Result<(String, String), String> {
|
||||
let mut module_name = None;
|
||||
module_at(&tree.items, offset, &mut module_name);
|
||||
let Some(module_name) = module_name else {
|
||||
return Err(NOT_A_PORT.to_string());
|
||||
};
|
||||
let Some((module, _)) = find_module(&tree, &module_name) else {
|
||||
let Some((module, _)) = find_module(tree, &module_name) else {
|
||||
return Err(NOT_A_PORT.to_string());
|
||||
};
|
||||
let ports = declared_ports(module);
|
||||
@@ -59,13 +74,14 @@ pub(super) fn locate_port(
|
||||
}
|
||||
}
|
||||
let Some(name) = name else { return Err(NOT_A_PORT.to_string()) };
|
||||
let site = locate_module(scope, ModuleRef::Name(&module_name))?;
|
||||
if site.file != i {
|
||||
return Err(format!(
|
||||
"`{module_name}` is declared in more than one indexed file; lucisv will not guess which module's ports these are."
|
||||
));
|
||||
}
|
||||
Ok((site, name))
|
||||
Ok((module_name, name))
|
||||
}
|
||||
|
||||
/// The sentence a module the in-scope files declare twice earns.
|
||||
pub(super) fn ambiguous(module: &str) -> String {
|
||||
format!(
|
||||
"`{module}` is declared in more than one indexed file; lucisv will not guess which module's ports these are."
|
||||
)
|
||||
}
|
||||
|
||||
const NOT_A_PORT: &str = "there is no module port at this position.";
|
||||
@@ -86,13 +102,13 @@ pub(super) fn plan_remove(
|
||||
return Err(format!("`{}` has no port named `{port}`.", site.name));
|
||||
};
|
||||
|
||||
let mut header: Vec<TextEdit> = remove_element(text, &element_spans(&ports), index)?;
|
||||
if matches!(module.ports, PortList::NonAnsi(_)) {
|
||||
header.append(&mut non_ansi_declaration_removal(text, module, port)?);
|
||||
}
|
||||
let header: Vec<TextEdit> = header_removal(text, module, &ports, index, port)?;
|
||||
// A port still used by the module's own body is a refusal, not a warning:
|
||||
// deleting it would leave the body naming something that no longer exists.
|
||||
let used = body_uses(scope, site.file, module, port, &header);
|
||||
let used = match scope.analysis(site.file) {
|
||||
Some(analysis) => body_uses_in(text, &analysis.semantics, module, port, &header),
|
||||
None => Vec::new(),
|
||||
};
|
||||
if !used.is_empty() {
|
||||
return Err(format!(
|
||||
"`{port}` is still used inside `{}` at {}:{}; remove those uses first.",
|
||||
@@ -169,19 +185,38 @@ fn preprocessor_warnings(scope: &Scope, file: usize, port: &str) -> Vec<String>
|
||||
out
|
||||
}
|
||||
|
||||
/// The header and body deletions the removal makes in the module's own file.
|
||||
///
|
||||
/// Split out of [`plan_remove`] so the code-action offer can make exactly the
|
||||
/// same two decisions — and earn exactly the same refusals — without a
|
||||
/// workspace (take 5 §P1c).
|
||||
pub(super) fn header_removal(
|
||||
text: &str,
|
||||
module: &Module,
|
||||
ports: &[super::find::DeclaredPort],
|
||||
index: usize,
|
||||
port: &str,
|
||||
) -> Result<Vec<TextEdit>, String> {
|
||||
let mut header = remove_element(text, &element_spans(ports), index)?;
|
||||
if matches!(module.ports, PortList::NonAnsi(_)) {
|
||||
header.append(&mut non_ansi_declaration_removal(text, module, port)?);
|
||||
}
|
||||
Ok(header)
|
||||
}
|
||||
|
||||
/// The lines of the module's body that still name the port, ignoring the
|
||||
/// declarations the removal is itself deleting.
|
||||
fn body_uses(
|
||||
scope: &mut Scope,
|
||||
file: usize,
|
||||
///
|
||||
/// `semantics` must be the analysis of `text` — [`Scope::analysis`]'s, or the
|
||||
/// open buffer's own, which is the same thing computed once instead of twice.
|
||||
pub(super) fn body_uses_in(
|
||||
text: &str,
|
||||
semantics: &vlog_semantic::Semantics,
|
||||
module: &Module,
|
||||
port: &str,
|
||||
removed: &[TextEdit],
|
||||
) -> Vec<String> {
|
||||
let Some(text) = scope.text(file) else { return Vec::new() };
|
||||
let lines = LineIndex::new(text);
|
||||
let Some(analysis) = scope.analysis(file) else { return Vec::new() };
|
||||
let semantics = &analysis.semantics;
|
||||
let Some(symbol) = semantics.symbols().iter().position(|s| {
|
||||
s.name == port
|
||||
&& s.kind == SymbolKind::Port
|
||||
@@ -248,13 +283,27 @@ fn disconnection_edits(
|
||||
return Ok((Vec::new(), 0));
|
||||
}
|
||||
let (tree, _) = parse_source_tolerant(text);
|
||||
disconnections_in(text, path, &tree, &site.name, port, warnings)
|
||||
}
|
||||
|
||||
/// [`disconnection_edits`] over a parse the caller already has, so the offer
|
||||
/// can earn the by-position refusal and count the sites it would rewrite
|
||||
/// without building a workspace (take 5 §P1c).
|
||||
pub(super) fn disconnections_in(
|
||||
text: &str,
|
||||
path: &Path,
|
||||
tree: &SourceFile,
|
||||
module: &str,
|
||||
port: &str,
|
||||
warnings: &mut Vec<String>,
|
||||
) -> Result<(Vec<TextEdit>, usize), String> {
|
||||
let mut instantiations = Vec::new();
|
||||
collect_instantiations(&tree.items, &mut instantiations);
|
||||
let lines = LineIndex::new(text);
|
||||
|
||||
let mut edits = Vec::new();
|
||||
let mut sites = 0usize;
|
||||
for instantiation in instantiations.iter().filter(|i| i.module == site.name) {
|
||||
for instantiation in instantiations.iter().filter(|i| i.module == module) {
|
||||
for instance in &instantiation.instances {
|
||||
match &instance.conns {
|
||||
Connections::Ordered(conns) if conns.is_empty() => {}
|
||||
@@ -263,7 +312,7 @@ fn disconnection_edits(
|
||||
"`{}` in {} connects `{}`'s ports by position; dropping one would silently re-bind the rest, so lucisv made no edits — give it named connections first.",
|
||||
instance.name,
|
||||
display(path),
|
||||
site.name
|
||||
module
|
||||
))
|
||||
}
|
||||
Connections::Named(conns) => {
|
||||
|
||||
@@ -0,0 +1,202 @@
|
||||
//! The organize-imports offer promises exactly what the refactoring delivers.
|
||||
//!
|
||||
//! Take 5 §P1c (`docs/features/perf5-p1/README.md`) added
|
||||
//! [`vlog_refactor::organize_offer`], which answers the two counts a code
|
||||
//! action's title carries without rendering a verified edit. This file is the
|
||||
//! proof that its answer — the counts *and* the refusal sentence — is
|
||||
//! [`vlog_refactor::organize_counts`]'s answer at **every byte offset** of
|
||||
//! every fixture, and that the only thing it does not reproduce is
|
||||
//! `check::verify_splice`, which no fixture here reaches.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use vlog_parser::{parse_source_tolerant, tokenize};
|
||||
use vlog_refactor::{organize_counts, organize_offer, organize_offer_in, organize_title};
|
||||
|
||||
/// A module importing two packages, one of them unused and written first, so
|
||||
/// there is both a removal and a sort to promise.
|
||||
const USER: &str = "\
|
||||
module user (
|
||||
input logic clk_i
|
||||
);
|
||||
import b_pkg::*;
|
||||
import a_pkg::*;
|
||||
logic q;
|
||||
assign q = A_ONE;
|
||||
endmodule
|
||||
";
|
||||
|
||||
/// Imports already sorted with every one used: the refusal that is not an
|
||||
/// error, and the one a lightbulb must not appear for.
|
||||
const TIDY: &str = "\
|
||||
module tidy;
|
||||
import a_pkg::*;
|
||||
logic q;
|
||||
assign q = A_ONE;
|
||||
endmodule
|
||||
";
|
||||
|
||||
/// A duplicate import and a commented one, which is the shape that produces a
|
||||
/// warning instead of a deletion.
|
||||
const COMMENTED: &str = "\
|
||||
module commented;
|
||||
import a_pkg::*;
|
||||
// why this one is here
|
||||
import b_pkg::*;
|
||||
import a_pkg::*;
|
||||
logic q;
|
||||
assign q = A_ONE;
|
||||
endmodule
|
||||
";
|
||||
|
||||
/// An import of a package nothing in scope declares — the conservative
|
||||
/// silence, which the offer must keep.
|
||||
const UNKNOWN: &str = "\
|
||||
module unknown;
|
||||
import nowhere_pkg::*;
|
||||
import a_pkg::*;
|
||||
logic q;
|
||||
assign q = A_ONE;
|
||||
endmodule
|
||||
";
|
||||
|
||||
/// A compilation-unit import run above a module, and a package with its own.
|
||||
const FILE_SCOPE: &str = "\
|
||||
import b_pkg::*;
|
||||
import a_pkg::*;
|
||||
package inner_pkg;
|
||||
import a_pkg::*;
|
||||
localparam int K = A_ONE;
|
||||
endpackage
|
||||
module uses;
|
||||
logic q;
|
||||
assign q = A_ONE;
|
||||
endmodule
|
||||
";
|
||||
|
||||
/// A buffer that does not parse: refused by both, with the same sentence.
|
||||
const BROKEN: &str = "\
|
||||
module broken;
|
||||
import a_pkg::*;
|
||||
logic ;;; w
|
||||
endmodule
|
||||
";
|
||||
|
||||
const A_PKG: &str = "\
|
||||
package a_pkg;
|
||||
localparam int A_ONE = 1;
|
||||
endpackage
|
||||
";
|
||||
|
||||
const B_PKG: &str = "\
|
||||
package b_pkg;
|
||||
localparam int B_ONE = 2;
|
||||
endpackage
|
||||
";
|
||||
|
||||
fn file(name: &str) -> PathBuf {
|
||||
PathBuf::from("/rtl").join(name)
|
||||
}
|
||||
|
||||
fn workspace(name: &str, text: &str) -> Vec<(PathBuf, String)> {
|
||||
vec![
|
||||
(file(name), text.to_string()),
|
||||
(file("a_pkg.sv"), A_PKG.to_string()),
|
||||
(file("b_pkg.sv"), B_PKG.to_string()),
|
||||
]
|
||||
}
|
||||
|
||||
fn crlf(text: &str) -> String {
|
||||
text.replace('\n', "\r\n")
|
||||
}
|
||||
|
||||
/// The counts the refactoring promises, without its edit.
|
||||
fn eager(files: &[(PathBuf, String)], path: &Path, offset: u32) -> Result<(usize, usize), String> {
|
||||
organize_counts(files, path, offset).map(|(_, removed, sorted)| (removed, sorted))
|
||||
}
|
||||
|
||||
fn agree_everywhere(name: &str, text: &str) {
|
||||
let files = workspace(name, text);
|
||||
let path = file(name);
|
||||
for offset in 0..=text.len() as u32 {
|
||||
assert_eq!(
|
||||
eager(&files, &path, offset),
|
||||
organize_offer(&files, &path, offset),
|
||||
"at offset {offset} of {name}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_offer_promises_what_the_refactoring_delivers_at_every_offset() {
|
||||
agree_everywhere("user.sv", USER);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_already_tidy_run_is_refused_by_both_with_the_same_sentence() {
|
||||
agree_everywhere("tidy.sv", TIDY);
|
||||
let files = workspace("tidy.sv", TIDY);
|
||||
let at = TIDY.find("import a_pkg").expect("the import") as u32;
|
||||
assert_eq!(
|
||||
organize_offer(&files, &file("tidy.sv"), at),
|
||||
Err("these imports are already sorted, and every one of them is used.".to_string())
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_commented_import_counts_the_same_in_both_answers() {
|
||||
agree_everywhere("commented.sv", COMMENTED);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn an_unknown_package_silences_both_answers() {
|
||||
agree_everywhere("unknown.sv", UNKNOWN);
|
||||
let files = workspace("unknown.sv", UNKNOWN);
|
||||
let at = UNKNOWN.find("import nowhere_pkg").expect("the import") as u32;
|
||||
assert!(organize_offer(&files, &file("unknown.sv"), at).is_err(), "the offer stays silent");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_file_scope_run_and_a_package_run_agree_at_every_offset() {
|
||||
agree_everywhere("file_scope.sv", FILE_SCOPE);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_buffer_that_does_not_parse_is_refused_by_both() {
|
||||
agree_everywhere("broken.sv", BROKEN);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_offer_agrees_over_crlf_line_endings() {
|
||||
agree_everywhere("user.sv", &crlf(USER));
|
||||
agree_everywhere("commented.sv", &crlf(COMMENTED));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_parsed_form_answers_what_the_text_form_answers_at_every_offset() {
|
||||
for (name, text) in [("user.sv", USER), ("commented.sv", COMMENTED), ("broken.sv", BROKEN)] {
|
||||
let files = workspace(name, text);
|
||||
let path = file(name);
|
||||
let (tree, diagnostics) = parse_source_tolerant(text);
|
||||
let semantics = vlog_semantic::analyze(&tree, text);
|
||||
let tokens = tokenize(text).expect("the fixture lexes");
|
||||
for offset in 0..=text.len() as u32 {
|
||||
assert_eq!(
|
||||
organize_offer(&files, &path, offset),
|
||||
organize_offer_in(&files, &path, &tree, &diagnostics, &semantics, &tokens, offset),
|
||||
"at offset {offset} of {name}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The fixtures really do reach an offer — a parity suite over an action that
|
||||
/// is never offered proves nothing.
|
||||
#[test]
|
||||
fn the_fixture_really_is_offered_the_action_with_the_title_it_promises() {
|
||||
let files = workspace("user.sv", USER);
|
||||
let at = USER.find("import b_pkg").expect("the import") as u32;
|
||||
let (removed, sorted) = organize_offer(&files, &file("user.sv"), at).expect("an offer");
|
||||
assert_eq!((removed, sorted), (1, 1), "one unused import goes and one is written back");
|
||||
assert_eq!(organize_title(removed, sorted), "lucisv: organize imports (removes 1, sorts 1)");
|
||||
}
|
||||
@@ -0,0 +1,245 @@
|
||||
//! The offer predicate answers exactly what the four full refactorings answer.
|
||||
//!
|
||||
//! Take 5 §P1c (`docs/features/perf5-p1/README.md`) added
|
||||
//! [`vlog_refactor::port_offers`], which asks each of the four port
|
||||
//! refactorings its plan-time questions and writes the title it would carry —
|
||||
//! no workspace index, no verification, no edits kept. This file is the proof
|
||||
//! that the menu it writes is the menu [`vlog_refactor::port_actions`] writes,
|
||||
//! at **every byte offset** of every fixture, not at cursors chosen to pass.
|
||||
//!
|
||||
//! Where the two may legitimately differ is stated in `ports::offer`'s own
|
||||
//! documentation: `check::verify_splice` and `ports::confirm` run after the
|
||||
//! plan and the predicate does not reproduce them. Every fixture below is
|
||||
//! asserted to be free of that difference, so a change that starts producing
|
||||
//! one fails here rather than reaching a user's lightbulb.
|
||||
|
||||
use std::path::{Path, PathBuf};
|
||||
|
||||
use vlog_parser::parse_source_tolerant;
|
||||
use vlog_refactor::{port_actions, port_offers, port_offers_in, PortOfferKind};
|
||||
|
||||
/// A module with a port its body never mentions (so the removal is offered),
|
||||
/// written the ANSI way, instantiating another module by name.
|
||||
const TOP: &str = "\
|
||||
module top (
|
||||
input logic clk_i,
|
||||
input logic spare_i,
|
||||
output logic q_o
|
||||
);
|
||||
logic w;
|
||||
logic b;
|
||||
sub u_sub (.a(clk_i));
|
||||
sub u_star (.*);
|
||||
assign q_o = w;
|
||||
endmodule
|
||||
";
|
||||
|
||||
/// The module `top` instantiates: two ports, so the instantiation above is
|
||||
/// missing one and the `.*` stands for both.
|
||||
const SUB: &str = "\
|
||||
module sub (
|
||||
input logic a,
|
||||
input logic b
|
||||
);
|
||||
endmodule
|
||||
";
|
||||
|
||||
/// A Verilog-2001 header — the one shape `convert to ANSI` answers at.
|
||||
const OLD: &str = "\
|
||||
module old (a, b);
|
||||
input a;
|
||||
output b;
|
||||
assign b = a;
|
||||
endmodule
|
||||
";
|
||||
|
||||
/// An instantiation connecting by position, a `bind` directive's own, and a
|
||||
/// second `.*`: three of the shapes the planners refuse over.
|
||||
const AWKWARD: &str = "\
|
||||
module awkward;
|
||||
logic a;
|
||||
logic b;
|
||||
sub u_ordered (a, b);
|
||||
sub u_two (.a(a), .b(b));
|
||||
bind awkward sub u_bound (.*);
|
||||
endmodule
|
||||
";
|
||||
|
||||
/// A module nested inside another and one inside a package: neither is a
|
||||
/// *unit*, so `locate_module` refuses over both and so must the predicate.
|
||||
const NESTED: &str = "\
|
||||
package p;
|
||||
module inner (input logic a);
|
||||
endmodule
|
||||
endpackage
|
||||
module outer (input logic a);
|
||||
module deep (input logic b);
|
||||
endmodule
|
||||
sub u_sub (.a(a));
|
||||
endmodule
|
||||
";
|
||||
|
||||
/// A file that does not parse cleanly: the expansion and the conversion refuse
|
||||
/// over it, the removal and the propagation do not.
|
||||
const BROKEN: &str = "\
|
||||
module m (input logic a);
|
||||
sub u_sub (.a(a));
|
||||
logic ;;; w
|
||||
endmodule
|
||||
";
|
||||
|
||||
/// A second declaration of `sub`, which makes the name ambiguous and every
|
||||
/// refactoring that has to look it up silent.
|
||||
const TWIN: &str = "\
|
||||
module sub (
|
||||
input logic a
|
||||
);
|
||||
endmodule
|
||||
";
|
||||
|
||||
fn file(name: &str) -> PathBuf {
|
||||
PathBuf::from("/rtl").join(name)
|
||||
}
|
||||
|
||||
fn workspace(entries: &[(&str, &str)]) -> Vec<(PathBuf, String)> {
|
||||
entries.iter().map(|(name, text)| (file(name), (*text).to_string())).collect()
|
||||
}
|
||||
|
||||
fn crlf(text: &str) -> String {
|
||||
text.replace('\n', "\r\n")
|
||||
}
|
||||
|
||||
/// The eager menu and the offered menu at one offset, as comparable lists.
|
||||
fn agree_at(files: &[(PathBuf, String)], path: &Path, offset: u32) {
|
||||
let eager: Vec<String> =
|
||||
port_actions(files, path, offset).into_iter().map(|a| a.title).collect();
|
||||
let offered: Vec<String> =
|
||||
port_offers(files, path, offset).into_iter().map(|o| o.title).collect();
|
||||
assert_eq!(eager, offered, "at offset {offset} of {}", path.display());
|
||||
}
|
||||
|
||||
/// Every byte of one file of a workspace, the end included.
|
||||
fn agree_everywhere(files: &[(PathBuf, String)], name: &str) {
|
||||
let path = file(name);
|
||||
let text = files
|
||||
.iter()
|
||||
.find(|(held, _)| *held == path)
|
||||
.map(|(_, text)| text.clone())
|
||||
.expect("the file is in the workspace");
|
||||
for offset in 0..=text.len() as u32 {
|
||||
agree_at(files, &path, offset);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_offer_matches_the_eager_menu_at_every_offset_of_an_ansi_module() {
|
||||
let files = workspace(&[("top.sv", TOP), ("sub.sv", SUB)]);
|
||||
agree_everywhere(&files, "top.sv");
|
||||
agree_everywhere(&files, "sub.sv");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_offer_matches_the_eager_menu_at_every_offset_of_a_non_ansi_header() {
|
||||
let files = workspace(&[("old.sv", OLD), ("sub.sv", SUB)]);
|
||||
agree_everywhere(&files, "old.sv");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_offer_matches_the_eager_menu_over_the_shapes_the_planners_refuse() {
|
||||
let files = workspace(&[("awkward.sv", AWKWARD), ("sub.sv", SUB)]);
|
||||
agree_everywhere(&files, "awkward.sv");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_nested_module_is_no_more_a_unit_to_the_offer_than_to_the_index() {
|
||||
let files = workspace(&[("nested.sv", NESTED), ("sub.sv", SUB)]);
|
||||
agree_everywhere(&files, "nested.sv");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_offer_matches_the_eager_menu_on_a_buffer_that_does_not_parse() {
|
||||
let files = workspace(&[("broken.sv", BROKEN), ("sub.sv", SUB)]);
|
||||
agree_everywhere(&files, "broken.sv");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_module_two_files_declare_is_silent_in_both_answers() {
|
||||
let files = workspace(&[("top.sv", TOP), ("sub.sv", SUB), ("twin.sv", TWIN)]);
|
||||
agree_everywhere(&files, "top.sv");
|
||||
// And the ambiguity really is what silences it: the same cursor offers
|
||||
// with only one declaration in scope.
|
||||
let one = workspace(&[("top.sv", TOP), ("sub.sv", SUB)]);
|
||||
let at = TOP.find("sub u_sub").expect("the instantiation") as u32;
|
||||
assert!(!port_offers(&one, &file("top.sv"), at).is_empty(), "one declaration offers");
|
||||
assert!(port_offers(&files, &file("top.sv"), at).is_empty(), "two declarations do not");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_offer_matches_the_eager_menu_over_crlf_line_endings() {
|
||||
let files = workspace(&[("top.sv", &crlf(TOP)), ("sub.sv", &crlf(SUB))]);
|
||||
agree_everywhere(&files, "top.sv");
|
||||
let files = workspace(&[("old.sv", &crlf(OLD)), ("sub.sv", &crlf(SUB))]);
|
||||
agree_everywhere(&files, "old.sv");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_offer_is_empty_for_a_file_the_workspace_does_not_hold() {
|
||||
let files = workspace(&[("top.sv", TOP), ("sub.sv", SUB)]);
|
||||
assert!(port_offers(&files, &file("absent.sv"), 0).is_empty());
|
||||
assert!(port_actions(&files, &file("absent.sv"), 0).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_parsed_form_answers_what_the_text_form_answers_at_every_offset() {
|
||||
let files = workspace(&[("top.sv", TOP), ("sub.sv", SUB), ("old.sv", OLD)]);
|
||||
for name in ["top.sv", "old.sv"] {
|
||||
let path = file(name);
|
||||
let text = files
|
||||
.iter()
|
||||
.find(|(held, _)| *held == path)
|
||||
.map(|(_, text)| text.clone())
|
||||
.expect("the file is in the workspace");
|
||||
let (tree, diagnostics) = parse_source_tolerant(&text);
|
||||
let semantics = vlog_semantic::analyze(&tree, &text);
|
||||
for offset in 0..=text.len() as u32 {
|
||||
assert_eq!(
|
||||
port_offers(&files, &path, offset),
|
||||
port_offers_in(&files, &path, &tree, &diagnostics, &semantics, offset),
|
||||
"at offset {offset} of {name}"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Each of the four really is reached by one of the fixtures — a parity suite
|
||||
/// over four refactorings none of which ever offers proves nothing.
|
||||
#[test]
|
||||
fn every_one_of_the_four_refactorings_is_offered_somewhere_in_the_fixtures() {
|
||||
let mut seen: Vec<PortOfferKind> = Vec::new();
|
||||
for (entries, name) in [
|
||||
(workspace(&[("top.sv", TOP), ("sub.sv", SUB)]), "top.sv"),
|
||||
(workspace(&[("old.sv", OLD), ("sub.sv", SUB)]), "old.sv"),
|
||||
] {
|
||||
let path = file(name);
|
||||
let text = entries
|
||||
.iter()
|
||||
.find(|(held, _)| *held == path)
|
||||
.map(|(_, text)| text.clone())
|
||||
.expect("the file is in the workspace");
|
||||
for offset in 0..=text.len() as u32 {
|
||||
for offer in port_offers(&entries, &path, offset) {
|
||||
if !seen.contains(&offer.kind) {
|
||||
seen.push(offer.kind);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for wanted in [
|
||||
PortOfferKind::Remove,
|
||||
PortOfferKind::Propagate,
|
||||
PortOfferKind::Expand,
|
||||
PortOfferKind::Convert,
|
||||
] {
|
||||
assert!(seen.contains(&wanted), "{wanted:?} is never offered: {seen:?}");
|
||||
}
|
||||
}
|
||||
@@ -196,6 +196,20 @@ The attack pair is pinned in `check.rs`:
|
||||
is declared locally, which must pass, so the refusal above is a discriminator
|
||||
and not a blanket.
|
||||
|
||||
**Since take 5 §P1c (2026-09-07) the *offer* no longer runs this net; the
|
||||
*resolve* does.** A lazy client's lightbulb is answered by
|
||||
`vlog_refactor::organize_offer{,_in}`, which runs the same planner (so the
|
||||
"removes N, sorts M" count is the one the click will carry) and stops before
|
||||
`verify_splice`; `codeAction/resolve` and `lucisv.organizeImports` recompute
|
||||
through `organize_imports`, which verifies over the identical file set before
|
||||
any edit leaves the engine. The offer is therefore optimistic in exactly one
|
||||
way — a plan the verifier would refuse is shown and then refused on the
|
||||
click with the sentence — which is the contract every other lazy offer
|
||||
already had (`docs/features/lazy-code-action/README.md`: "the offer may be
|
||||
optimistic; the resolve is exact"). No edit reaches an editor unverified.
|
||||
QA (perf5-p1, P1c) could not construct a plan the verifier refuses that the
|
||||
planner accepts, so the attack pair below is the pin.
|
||||
|
||||
The verifier cannot see a wrong removal of an **unindexed** package's import —
|
||||
before and after, the reference is unresolved either way — which is exactly why
|
||||
"unknown package" is a refusal in the judgement rather than a guess.
|
||||
|
||||
@@ -22,6 +22,23 @@ parsed-input selectors beside the text ones, the four offer paths reading
|
||||
revision. No behaviour changes: what a cursor offers, in what order, with what
|
||||
titles and shapes, is pinned old-against-new.
|
||||
|
||||
**P1c** removes the last of it, and it is the biggest single number in the
|
||||
round after the pinmux row. §P1b's own measurement: the `aes_reg_top u_reg`
|
||||
offer in `aes.sv` costs **21.83 ms, of which the ports family alone is 21.15**,
|
||||
and that cursor offers **zero** actions. The four planners each built a
|
||||
`Scope` — a `WorkspaceIndex` over the buffer and the instantiated module's
|
||||
declaring file, every one of those files lexed, parsed *and analyzed* — and
|
||||
then refused. Measured directly at that cursor: `WorkspaceIndex::build` over
|
||||
the two files is **3.9 ms**, four of them plus the planners' own parses is the
|
||||
whole 20 ms. The organize-imports offer paid the mirror image: it computed the
|
||||
edit and ran `check::verify_splice`, which builds a *second* index over the
|
||||
same files, to write "removes 1, sorts 1" on a menu. P1c replaces both with
|
||||
**offer predicates**: engine-owned queries that ask each refactoring its
|
||||
plan-time questions over the buffer's own parse and analysis, parse the
|
||||
declaring file at most once, build no index for the ports and verify nothing.
|
||||
`codeAction/resolve` is untouched and still recomputes and verifies the whole
|
||||
refactoring over the module's real fan-out when the user clicks.
|
||||
|
||||
## Assumptions
|
||||
|
||||
- A `Document` is rebuilt whole by `Workspace::set_document` on every
|
||||
@@ -69,6 +86,41 @@ Each makes exactly the decisions its text version makes, including the
|
||||
"diagnostics non-empty → nothing" refusal (`port_action_modules` has no such
|
||||
check today and still has none).
|
||||
|
||||
**Added by `vlog_refactor` for §P1c** (additive; `port_actions`,
|
||||
`organize_counts`, `organize_imports` and every planner keep their signatures
|
||||
and their behaviour):
|
||||
|
||||
- `port_offers(files, file, offset) -> Vec<PortOffer>` and
|
||||
`port_offers_in(files, file, tree, diagnostics, semantics, offset)` — the
|
||||
four port refactorings' **menu**: `PortOffer { title, kind }`, where `title`
|
||||
is byte-for-byte the title `port_actions` writes and `kind` is
|
||||
`PortOfferKind::{Remove, Propagate, Expand, Convert}`. No `Scope`, no
|
||||
`WorkspaceIndex`, no verification, no edit returned. Every *plan-time*
|
||||
refusal is reproduced by calling the planners' own helpers; the two checks
|
||||
that are **not** reproduced are `check::verify_splice` and `ports::confirm`,
|
||||
both of which run after the plan. `crates/vlog_refactor/src/ports/offer.rs`.
|
||||
- `organize_offer(files, file, offset) -> Result<(usize, usize), String>` and
|
||||
`organize_offer_in(files, file, tree, diagnostics, semantics, tokens,
|
||||
offset)` — the two counts an organize-imports title promises, the whole plan
|
||||
minus `check::verify_splice`. The refusal sentences are identical, including
|
||||
"already sorted, every one used", the unknown-package silence and the
|
||||
shared-line refusal.
|
||||
- `PortOffer`, `PortOfferKind` are new public types.
|
||||
|
||||
Six existing `ports/` helpers became `pub(super)` and four grew a parsed-input
|
||||
twin so the predicate and the planner read **one** implementation of each
|
||||
decision: `remove::{port_at, header_removal, body_uses_in, disconnections_in,
|
||||
ambiguous}`, `propagate::{instance_at, connections_of, missing_ports}`,
|
||||
`expand::{wildcard_at, unconnected_in}`, `ansi::{convert_header, convert_edits,
|
||||
elsewhere}`, and `imports::planned`. Each is the old body with its `Scope`
|
||||
lookups lifted into the caller; the old entry points call them, so the eager
|
||||
path's behaviour is unchanged and pinned by `vlog_refactor`'s own suites.
|
||||
|
||||
**Not consumed by the server, deliberately.** The server's `offer_sources` and
|
||||
`imports::sources` are untouched: the predicate is handed exactly the file set
|
||||
the eager offer was handed, which is what makes the parity test an
|
||||
apples-to-apples comparison. Handshake 33 is therefore still not touched.
|
||||
|
||||
**Consumed by `lucisv_server`**: `server/dispatch.rs` gates lint/config work by
|
||||
the requested kinds; `ports.rs`, `imports.rs`, `extract.rs`,
|
||||
`inline_module.rs` call the `_in` selectors with the open document's own parse
|
||||
@@ -87,6 +139,21 @@ revision is computed once instead of once per request.
|
||||
- `docs/topo.md`: record the two additive engine/parser edges above
|
||||
(`vlog_parser::stats`, the four `_in` selectors) and the server's new
|
||||
`fences` module. This dev does not edit `topo.md`.
|
||||
- `docs/topo.md`, §P1c: record the two additive engine edges
|
||||
(`vlog_refactor::{port_offers, port_offers_in}` from
|
||||
`lucisv_server::ports::offered`, and
|
||||
`vlog_refactor::{organize_offer, organize_offer_in}` from
|
||||
`lucisv_server::imports::counts_at`), and note in §1.2 that the *offer*
|
||||
predicates take the same source set `port_actions` / `organize_counts` take,
|
||||
so request-selector parity is unchanged.
|
||||
- **`vlog_semantic` (not applied; the measured residue of §P1c).**
|
||||
`organize_offer_in` still pays one `Scope::build`, which parses *and
|
||||
analyzes the buffer* to put its facts in the index — a parse and an analysis
|
||||
the caller's `Document` already holds. A public way to build a `FileFacts`
|
||||
from an existing `(&SourceFile, &Semantics, &str)` — `facts_from_analysis`
|
||||
is already that function, and private — would let the index be built without
|
||||
it. Measured worth: about 0.8 ms of the offer's 4.88 ms at
|
||||
`aes_sbox_canright_masked.sv` 42:2. Not this lane's crate.
|
||||
|
||||
## Status / TODO
|
||||
|
||||
@@ -98,7 +165,17 @@ revision is computed once instead of once per request.
|
||||
- [x] work counters prove zero additional parses on a repeated offer
|
||||
- [x] parity pinned at every sampled cursor/range
|
||||
- [x] extract-refusal attribution paragraph
|
||||
- [ ] lead ruling on P1c (not this lane's to make)
|
||||
- [x] lead ruling on P1c — **go**, 2026-09-07
|
||||
- [x] P1c — `port_offers` / `port_offers_in` (`ports/offer.rs`), the planners'
|
||||
helpers shared rather than copied, `ports::offers` on the predicate
|
||||
- [x] P1c — `organize_offer` / `organize_offer_in`, `imports::offers` on the
|
||||
predicate; `resolve` and `execute` untouched and still verifying
|
||||
- [x] P1c parity: offer ⇔ eager menu, titles included, at **every byte offset**
|
||||
of eight port fixtures and seven import fixtures
|
||||
- [x] P1c counters: a repeated ports offer parses **1** file (the module's
|
||||
declaration), a repeated organize-imports offer **3** (one index over the
|
||||
buffer and its two packages); the buffer's own parse is in neither
|
||||
- [x] P1c measured; tracker row and experiment entry (`P1c-2026-09-07`)
|
||||
|
||||
## Work log
|
||||
|
||||
@@ -294,6 +371,200 @@ Nothing under `docs/topo.md`, `README.md`, `vlog_formatter/src/fence.rs` or
|
||||
tracker was overwritten — P1's numbers are appended behind the REF they are
|
||||
measured against.
|
||||
|
||||
### 2026-09-07 — dev, P1c (attribution first)
|
||||
|
||||
Before writing anything, the 21.15 ms was attributed with a throwaway
|
||||
`#[ignore]`d probe over the real corpus (read-only; deleted before the gates
|
||||
ran). At the `aes_reg_top u_reg` cursor in `aes.sv`, with the offer's own two
|
||||
files (`aes.sv` 13 891 B, `aes_reg_top.sv` 52 461 B):
|
||||
|
||||
| What | ms |
|
||||
|---|---:|
|
||||
| `port_actions` — the whole offer, **0 actions returned** | 20.37 |
|
||||
| `WorkspaceIndex::build` over the two files (= one `Scope::build`) | **3.89** |
|
||||
| `parse_source_tolerant(aes_reg_top.sv)` | 2.43 |
|
||||
| `analyze` of that parse | 0.58 |
|
||||
| `parse_source_tolerant(aes.sv)` | 0.33 |
|
||||
| `port_action_modules(aes.sv, offset)` — the gate, parse included | 0.34 |
|
||||
|
||||
So **4 × 3.89 + the planners' own parses ≈ 20 ms, and not one byte of it was
|
||||
verification**: all four planners refuse at *plan* time at that cursor
|
||||
(`locate_port` says "no module port here", the propagation says `u_reg`
|
||||
already connects every port, there is no `.*`, and `aes` is ANSI). The offer
|
||||
was paying four whole-workspace-index builds to be told "no" four times. The
|
||||
same probe put `organize_counts` at 9.49 ms, of which `Scope::build` is 2.05
|
||||
and the buffer's parse+analysis 0.78 — the rest is `check::verify_splice`,
|
||||
which builds a *second* index over the same files.
|
||||
|
||||
That decided the shape: **the ports predicate builds no index at all**, and the
|
||||
imports predicate keeps its one index (`import_usage` genuinely needs the
|
||||
packages' exports) and drops the verification.
|
||||
|
||||
### 2026-09-07 — dev, P1c (the code)
|
||||
|
||||
`crates/vlog_refactor/src/ports/offer.rs` (new, 282 production lines). Four
|
||||
functions, one per refactoring, each the planner's plan-time half in the
|
||||
planner's own order, calling the planner's own helpers — so there is one
|
||||
implementation of every decision and the two cannot drift:
|
||||
|
||||
- **`removal`** — `port_at` (the cursor is on a header port, or on a non-ANSI
|
||||
body declaration of one), the declaration lookup, `header_removal`,
|
||||
`body_uses_in` over the buffer's **own** `Semantics`, then
|
||||
`disconnections_in` per in-scope file for the by-position refusal and the
|
||||
site census. Title identical, count included; the server still replaces the
|
||||
phrase from its index (`ports::counted`), exactly as before.
|
||||
- **`propagation`** — `instance_at`, the declaration lookup, `connections_of`,
|
||||
`missing_ports` from the declaring file's parse, `conn_list_open`, then the
|
||||
planner's own append loop. The loop is kept because the title counts *edits*,
|
||||
not ports: a connection appended after a `//` comment costs two edits, so
|
||||
"connect N missing ports" is only exact if the loop runs. It is pure text
|
||||
work — no parse, no index.
|
||||
- **`expansion`** — the buffer's diagnostics (the expansion refuses any), then
|
||||
`wildcard_at`, the connection directives, the declaration lookup,
|
||||
`unconnected_in`, `conn_list_open`. The count is the declaration's own and
|
||||
needs no edit rendered.
|
||||
- **`conversion`** — `module_at`, `find_module`, `convert_header` (which is
|
||||
where an ANSI module — every module in opentitan — refuses, *before* any
|
||||
declaration lookup), then the declaration lookup and `convert_edits`.
|
||||
|
||||
**The declaration lookup replaces `locate_module` without an index.**
|
||||
`locate_module` asks `WorkspaceIndex::units(name)` for exactly one
|
||||
`SymbolKind::Module | Interface`, and units are **file-scope** declarations.
|
||||
`vlog_semantic::bind::item::bind_module` binds every `module` / `interface` /
|
||||
`program` item to one of those two kinds, so "the file-scope `ItemKind::Module`
|
||||
items named `name`" is the same count, read off the parses the predicate makes
|
||||
anyway. A module nested in another module or in a package is not a unit, and is
|
||||
not one here — pinned by a fixture that holds both. A file whose bytes never
|
||||
spell the name is not parsed to be ruled out.
|
||||
|
||||
`crates/vlog_refactor/src/imports.rs`: `organize`'s middle became `planned`
|
||||
(unparsed → `scope_at` → `import_usage` → `Blocks::read`/`plan` → the
|
||||
"already sorted" refusal), and `organize_offer` / `organize_offer_in` are that
|
||||
function without `check::verify_splice` and without the `RefactorEdit`.
|
||||
`organize` itself now calls `planned`, so the offer and the resolve read one
|
||||
implementation.
|
||||
|
||||
Server: `ports::offered` and `imports::counts_at`, each choosing the `_in` form
|
||||
for an ordinary buffer and the text form for `doc.large` — `modules_at`'s own
|
||||
line, for `modules_at`'s own reason. `resolve` and `execute` are **untouched**
|
||||
on both paths and still recompute and verify over the whole fan-out.
|
||||
|
||||
**What the predicate cannot see.** `check::verify_splice` and `ports::confirm`
|
||||
for the ports; `check::verify_splice` for the imports. Both run after the plan,
|
||||
both are stated in `ports::offer`'s module documentation, and both are already
|
||||
inside the offer's existing promise — "the offer may be optimistic; the resolve
|
||||
is exact" (`lazy-code-action` README), which the lazy client has lived with
|
||||
since §37.1 because the offer reads one or two files and the resolve reads the
|
||||
fan-out. **Nothing else** differs, and that is measured rather than asserted:
|
||||
`crates/vlog_refactor/tests/port_offers.rs` compares the offered menu against
|
||||
`port_actions`' menu — the titles themselves, in order — at **every byte
|
||||
offset** of eight fixtures (an ANSI module with a spare port, its declaration,
|
||||
a non-ANSI header, positional/`bind`/`.*` shapes, nested and package-nested
|
||||
modules, a buffer that does not parse, a duplicate declaration, and all of it
|
||||
again over CRLF), and `import_offers.rs` compares `organize_offer` against
|
||||
`organize_counts` — the counts *and* the refusal sentence — at every byte
|
||||
offset of seven fixtures. **Zero differences.** So on these fixtures the offer
|
||||
promise is unchanged, not merely "no worse".
|
||||
|
||||
**Counters.** `server::tests::code_action`, asserted by count:
|
||||
a repeated ports offer at an offering cursor performs **1** parse (the
|
||||
instantiated module's declaring file) where the old test could only say
|
||||
"> 0"; a repeated organize-imports offer performs **3** (one `Scope::build`
|
||||
over the buffer and its two packages); at a cursor the gate refuses, **0**.
|
||||
The old `…that_is_what_p1c_is_for` test also turned out to be driving the
|
||||
*eager* path — `ClientAbilities::default()` has no `resolveSupport` — so both
|
||||
counter tests now use a `code_action_resolve: true` client, which is the path
|
||||
§P1c changed and the shape the perf harness uses.
|
||||
|
||||
**P1c measured** (release, server sha256 `33a6888a…`, load 3.8–4.9 recorded
|
||||
before and after every phase, corpus unchanged after every phase, zero guard
|
||||
kills, no `cargo` command during any timed phase). Repeat medians, paired
|
||||
against §P1b's own numbers on the same rows:
|
||||
|
||||
| Row | REF | P1b | **P1c** | paired vs P1b |
|
||||
|---|---:|---:|---:|---:|
|
||||
| `aes_reg_top` lazy offer (`codeaction`) | 23.31 | 21.83 | **5.46** | **−75.0%** |
|
||||
| `aes_reg_top` ports-only (`offerkinds`) | 22.47 | 21.15 | **3.27** | **−84.6%** |
|
||||
| `aes_reg_top` all families (`offerkinds`) | 23.51 | 21.79 | **4.70** | **−78.4%** |
|
||||
| `aes` lazy offer (`codeaction`) | 8.17 | 7.76 | **1.74** | **−77.6%** |
|
||||
| `prim_lc_sync` lazy (fan-out 42) | — | 6.79 | **0.77** | −88.7% |
|
||||
| `prim_alert_sender` lazy (fan-out 67) | — | 6.90 | **1.78** | −74.2% |
|
||||
| `prim_flop_2sync` lazy (fan-out 128) | — | 7.36 | **1.38** | −81.3% |
|
||||
| `tb.sv` comment (`codeaction`) | 4.46 | 3.65 | **2.73** | −25.1% |
|
||||
| pinmux comment, all families | 309.60 | 24.02 | **23.55** | −1.9% |
|
||||
| pinmux comment, `only: []` | 82.80 | 0.053 | **0.056** | −5.8% |
|
||||
| eager fan-out 128 (guardrail) | 496.24 | 493.92 | **492.54** | −0.3% |
|
||||
| `offerqueue` follower (mean of pipelines 2–3) | 309.40 | 24.61 | **24.84** | −0.9% |
|
||||
|
||||
The `refactor` phase had no P1b run, so its rows are paired against the §P0
|
||||
REF; part of each delta is §P1b's gate saving, which `offerkinds` puts at
|
||||
0.06–0.14 ms per family on these file sizes — the rest is §P1c:
|
||||
|
||||
| `refactor` row | REF | **P1c** | paired |
|
||||
|---|---:|---:|---:|
|
||||
| port-actions **offer**, `aes_wrap.sv` 78:2 | 24.84 | **1.19** | **−95.2%** |
|
||||
| organize-imports **offer**, `aes_sbox_canright_masked.sv` 42:2 | 15.39 | **4.88** | **−68.3%** |
|
||||
| inline-module offer, `aes_wrap.sv` 66:2 | 13.36 | **1.70** | −87.3% |
|
||||
| extract-module offer (selection) | 4.32 | **0.66** | −84.9% |
|
||||
| ANSI header, no offer expected | 2.80 | **0.37** | −86.7% |
|
||||
| connect-missing-ports **resolve** | 166.51 | 169.13 | +1.6% |
|
||||
| expand `.*` **resolve** (32 connections) | 71.89 | 70.22 | −2.3% |
|
||||
| organize-imports **resolve** | 9.45 | 11.03 | +16.7% |
|
||||
|
||||
**The three resolve rows carry byte-identical fingerprints to the REF's**
|
||||
(`4b534a16…`, `8f3a26dd…`, `0ee027e3…`) with the same edit, file and warning
|
||||
counts, which is the proof that the click path did not move. The
|
||||
organize-imports resolve's +16.7% is a 10 ms row inside this document's own
|
||||
±20% band for 1–20 ms rows; its code path is the same statements it was, with
|
||||
`organize`'s middle lifted into `planned`.
|
||||
|
||||
**Answers unchanged, mechanically checked.** Every row of `offerkinds`,
|
||||
`codeaction` and `offerqueue` was compared field-by-field against §P1b's own
|
||||
record — `result_count`, `titles`, `shapes`, `status`, `fingerprint`, `edits`,
|
||||
`files`, `created` — **50 rows, 0 differences**; and every comparable row
|
||||
against the §P0 REF — **65 rows, 0 differences**.
|
||||
|
||||
**All three targets met.** `aes_reg_top` < 10 ms → **5.46**. `aes` < 5 ms →
|
||||
**1.74**. The organize-imports offer < 5 ms → **4.88**. The two residues, named
|
||||
rather than left to be found:
|
||||
|
||||
- The ports offer's remaining **3.27 ms** at `aes_reg_top` is dominated by the
|
||||
one parse of `aes_reg_top.sv` (52 461 B), which the probe above measures at
|
||||
**2.16–2.43 ms** standalone. A memo of the declaring file's parse per index
|
||||
generation would remove it; the brief put that out of scope, so it is
|
||||
reported and not done. Every other offering cursor in the harness is already
|
||||
0.66–1.78 ms.
|
||||
- The organize-imports offer's remaining **4.88 ms** is one `Scope::build`
|
||||
(2.05 ms standalone over the three files) plus `import_usage`. The buffer's
|
||||
own share of that index — a parse and an analysis the `Document` already
|
||||
holds — is duplicated work, and removing it needs `vlog_semantic` to build a
|
||||
`FileFacts` from an *existing* analysis (`facts_from_analysis` is private;
|
||||
only `FileFacts::of(path, src)`, which parses, is public). That is a
|
||||
handshake request, not a change this lane may make.
|
||||
|
||||
### 2026-09-07 — dev, P1c deviations
|
||||
|
||||
1. **`crates/lucisv_server/src/server/tests/mod.rs` is outside the brief's
|
||||
ownership list.** One symbol was added to an existing `use
|
||||
lsp_types::request::{…}` list — `CodeActionResolveRequest` — so the new
|
||||
offer-then-refuse test can drive a real `codeAction/resolve` through the
|
||||
real dispatch. Nothing else in that file changed.
|
||||
2. **The predicate renders the edits it needs to count and then drops them.**
|
||||
The brief said "must NOT render edits"; for the removal, the propagation and
|
||||
the conversion the *count in the title* and two plan-time refusals
|
||||
(`Plan::settle`'s overlap check, `finish`'s "nothing to change") are only
|
||||
exact if the edits exist. They are pure text manipulation on the buffer —
|
||||
no parse, no index, no verification — and the measurements above show the
|
||||
cost is not in them. The expansion renders nothing: its count is the
|
||||
declaration's.
|
||||
3. **Two new engine test files**, `crates/vlog_refactor/tests/{port_offers,
|
||||
import_offers}.rs`, in the place the brief allowed for new tests.
|
||||
4. **`tools/perf/` is untouched** — no row needed adding; every cell above
|
||||
comes from a phase that already existed.
|
||||
5. The attribution probe (`crates/vlog_refactor/tests/p1c_attribution.rs`) was
|
||||
deleted before the gates ran; its numbers are in this log and its inputs
|
||||
were read from the corpus read-only.
|
||||
|
||||
## QA log
|
||||
|
||||
### 2026-09-07 — QA
|
||||
@@ -514,6 +785,381 @@ cursors found zero behavioral differences. Two items are correctly left as
|
||||
open lead rulings (P1c, lint-result reuse) and are not QA blockers. Ticking
|
||||
the §60.1 QA line in TODO.md.
|
||||
|
||||
### 2026-09-07 — QA, P1c
|
||||
|
||||
Read `CLAUDE.md`, TODO §60.1's P1c lines, `docs/performance_take5.md`'s P1c
|
||||
paragraph, this README's P1c sections (Goal, Handshakes, Status, both work-log
|
||||
entries), `docs/features/lazy-code-action/README.md` (§37.1, in full),
|
||||
`docs/features/refactor-ports/README.md`, `docs/features/organize-imports/
|
||||
README.md` (in full), `docs/perf/take5-tracking.md`'s P1c row/cells/experiment,
|
||||
the diff, the three new files, and the evidence under
|
||||
`~/.cache/lucisv-perf/take5-p1c/`. Experiments that run code happened only in
|
||||
two scratch clones under `scratchpad/qa-p1c/` — `old_repo` (a clean checkout at
|
||||
`6c1f863`, the pre-P1c commit that is also `HEAD`) and `new_repo` (`6c1f863`
|
||||
plus `git apply` of the working-tree diff and the three untracked files,
|
||||
verified identical to the main tree by `diff -rq`, restored to identical again
|
||||
after every sabotage). The main tree was never built, checked out, reset or
|
||||
stashed. `opentitan` stayed read-only throughout: `git -C ~/repo/opentitan
|
||||
status --porcelain` showed exactly the three pre-existing modified files
|
||||
before, during and after every phase, checked again at the end of this log.
|
||||
|
||||
**Gates (main tree).** `cargo fmt --all -- --check`: clean. Guarded
|
||||
`cargo clippy --all-targets`: `Finished` with no warnings (a fresh build of
|
||||
this exact diff was already current). `git diff | grep '#\[allow'` finds
|
||||
exactly one: `#[allow(clippy::too_many_arguments)]` on `imports::planned`
|
||||
(`crates/vlog_refactor/src/imports.rs:182`), with the reason on the same line
|
||||
("one call's worth of already-computed inputs, not state") — the one the plan
|
||||
requires. Guarded `cargo test --workspace`: **4215 passed, 0 failed** across
|
||||
56 binaries (summed and cross-checked by pattern match, not eyeballed),
|
||||
matching the dev's number exactly. No cargo command overlapped a timed phase;
|
||||
`ps` showed no `cargo`/`rustc` before every guarded run and every perf phase.
|
||||
|
||||
**Size rule.** Production lines (non-blank, non-comment, before `mod tests`)
|
||||
of every changed/new file, recomputed independently: `imports.rs` (server)
|
||||
163, `ports.rs` (server) 310, `imports.rs` (engine) 387, `lib.rs` 96,
|
||||
`ports/ansi.rs` 400, `ports/expand.rs` 258, `ports/mod.rs` 321,
|
||||
`ports/propagate.rs` 137, `ports/remove.rs` 286, **`ports/offer.rs` 282** —
|
||||
matches the dev's own count exactly. Nothing over 600; `git diff --stat`
|
||||
touches no other file outside this list plus `TODO.md` and the two docs.
|
||||
|
||||
**Invariant 4 (§9).** `git diff --stat -- crates/vlog_refactor/src/check/
|
||||
crates/vlog_formatter/src/verify.rs` is empty — confirmed independently.
|
||||
`resolve`/`execute` still call the full verifying planners: `ports.rs:108`
|
||||
and `:713` both call `vlog_refactor::port_actions` (the resolve path via
|
||||
`code_actions`, unchanged since the diff touches none of `code_actions`,
|
||||
`resolve` or `execute`); `imports.rs:169` calls
|
||||
`vlog_refactor::organize_imports` inside `execute`, and `resolve` (`imports.rs`
|
||||
`fn resolve`) calls `code_actions`, which calls `organize_counts` — both
|
||||
still run `check::verify_splice` (`vlog_refactor/src/imports.rs:168`,
|
||||
`ports/mod.rs:438`). Confirmed by source read, not just diff-stat.
|
||||
|
||||
**§7 re-measurement.** `target/release/lucisv-server` sha256
|
||||
`33a6888af3f2bc9b3b2d1fb2844f3d93f9f5950839446866838244f913d56cf1` — an exact
|
||||
match for the dev's recorded hash; no rebuild done. Ran `offerkinds`,
|
||||
`codeaction`, `refactor`, `offerqueue` guarded, sequentially, against
|
||||
opentitan, no cargo overlapping; corpus unchanged after each (`git -C
|
||||
opentitan status --porcelain` identical every time). Medians against the
|
||||
dev's own P1c record:
|
||||
|
||||
| Cell | Dev P1c | QA re-measure | Diff |
|
||||
|---|---:|---:|---:|
|
||||
| `aes-reg-instance` ports-only (`offerkinds`) | 3.27 | 3.18 | 2.6% |
|
||||
| `aes-reg-instance` all-family (`offerkinds`) | 4.70 | 4.43 | 5.8% |
|
||||
| pinmux all-family (`offerkinds`) | 23.55 | 23.67 | 0.5% |
|
||||
| `aes_reg_top` lazy (`codeaction`) | 5.46 | 4.58 | 16.1% |
|
||||
| `aes` lazy (`codeaction`) | 1.74 | 1.63 | 6.0% |
|
||||
| `prim_lc_sync` lazy, fan-out 42 (`codeaction`) | 0.77 | 0.56 | 27.7% |
|
||||
| `prim_alert_sender` lazy, fan-out 67 (`codeaction`) | 1.78 | 1.10 | 38.4% |
|
||||
| `prim_flop_2sync` lazy, fan-out 128 (`codeaction`) | 1.38 | 0.83 | 39.5% |
|
||||
| eager fan-out 128 guardrail (`codeaction`) | 492.54 | 490.48 | 0.4% |
|
||||
| port-actions offer, `aes_wrap.sv` 78:2 (`refactor`) | 1.19 | 1.33 | 11.8% |
|
||||
| organize-imports offer, `aes_sbox…` 42:2 (`refactor`) | 4.88 | 4.00 | 18.0% |
|
||||
| organize-imports resolve (`refactor`) | 11.03 | 10.27 | 6.9% |
|
||||
| offerqueue follower, mean of pipelines 2–3 | 24.84 | 23.92 | 3.7% |
|
||||
|
||||
The three biggest diffs (`prim_lc_sync`/`prim_alert_sender`/`prim_flop_2sync`,
|
||||
27–40%) are all sub-2 ms rows; this document's own tolerance framework (the
|
||||
P1a/P1b QA log, itself citing the P0 entry) treats a ±20% band as normal for
|
||||
1–20 ms rows, and rows under 2 ms carry proportionally more scheduling noise
|
||||
on a machine at load 3.8–4.5 (recorded before/after, similar to the dev's
|
||||
3.8–4.9). Every row moved in the claimed direction and by the claimed order
|
||||
of magnitude; none regressed. The three resolve fingerprints
|
||||
(`4b534a16…`, `8f3a26dd…`, `0ee027e3…`) came back **byte-identical** to the
|
||||
dev's REF record on this exact re-run — read from the `refactor` phase's own
|
||||
JSONL output, not eyeballed off stdout.
|
||||
|
||||
**§8 traceability.** Sampled the `aes_reg_top` lazy (`codeaction`), ports-only
|
||||
(`offerkinds`) and organize-imports-offer (`refactor`) numbers directly out of
|
||||
`~/.cache/lucisv-perf/take5-p1c/results-p1c.jsonl`'s raw `ms` arrays and
|
||||
recomputed the stated median (last three of four tries): `[6.92, 5.62, 5.46,
|
||||
4.80]` → 5.46; `[3.51, 3.27, 3.45, 3.08]` → 3.27; `[8.42, 6.59, 4.88, 4.69]`
|
||||
→ 4.88 — all three match the tracker and work-log numbers exactly. Combined
|
||||
with the 13 numbers independently re-measured above (§7) and the test/line
|
||||
counts (§gates), well over a dozen numbers traced to source with no
|
||||
discrepancy.
|
||||
|
||||
**§3/§5/§6 — parity, counters, ambiguity, large-file mode.**
|
||||
|
||||
- Read `crates/vlog_refactor/tests/port_offers.rs` and `import_offers.rs` in
|
||||
full: `agree_everywhere` genuinely iterates every byte offset `0..=len` of
|
||||
every fixture, comparing titles (ports) or counts-and-refusal-sentence
|
||||
(imports) against the eager planner. Both files' own doc comments correctly
|
||||
disclose the boundary: neither's fixtures reach `check::verify_splice` or
|
||||
`ports::confirm` — that is stated, not hidden.
|
||||
- Added two fixtures in the scratch clone only (`new_repo`, appended to
|
||||
`port_offers.rs`, never touching the main tree): a parameterized
|
||||
instantiation (`qasub #( .WIDTH(8) ) u_sub (...)`) with a connection
|
||||
followed by a trailing `// comment` before the next connection (the "costs
|
||||
two edits" case the dev's work log names), and a `.clk_i` shorthand
|
||||
connection with its own trailing comment. `cargo test -p vlog_refactor
|
||||
--test port_offers` (guarded): **12 passed, 0 failed**, including both new
|
||||
ones at every byte offset. Title-count parity holds on all three requested
|
||||
shapes; the "costs two edits" case is safe by construction, not by luck —
|
||||
`propagation` in `ports/offer.rs:318-356` calls the *same* `append_to_list`
|
||||
loop the eager planner calls, so there is one implementation, not two that
|
||||
could drift.
|
||||
- **Ambiguity, ports.** `ports.rs:172`: `declared_twice(ws, name)` — a
|
||||
server-level gate over the **full workspace index**, unchanged by this diff
|
||||
(`git diff` touches neither the gate nor `declared_twice`'s body at
|
||||
`ports.rs:338`) — still runs *before* `offered()`/`port_offers_in` is ever
|
||||
called, so a module declared twice in the workspace silences the offer
|
||||
regardless of what the two-file predicate itself could see. Confirmed
|
||||
by source read and by the existing
|
||||
`a_module_two_files_declare_is_silent_in_both_answers` /
|
||||
`a_module_declared_twice_is_refused_through_the_subset_as_well` tests.
|
||||
- **Ambiguity, imports.** `an_unknown_package_silences_both_answers`
|
||||
(`import_offers.rs:152`) pins it directly: `organize_offer` returns `Err`
|
||||
for `import nowhere_pkg::*;`, same as `organize_counts` — the refusal lives
|
||||
inside `import_usage` itself (shared by both paths via `planned`), not in a
|
||||
check either path could uniquely skip.
|
||||
- **Large-file mode.** `ports.rs`'s `offered()` and `imports.rs`'s
|
||||
`counts_at()` both branch on `doc.large` to the text form (`port_offers` /
|
||||
`organize_offer`), exactly as claimed. **But this branch is dead on every
|
||||
live `textDocument/codeAction` wire path**: `server/large_file.rs:82`
|
||||
answers `CodeActionRequest::METHOD` with `[]` unconditionally for a large
|
||||
document, *before* `dispatch.rs` — and therefore `offers()` — is ever
|
||||
reached. This is not new to P1c: the same was already true of the
|
||||
pre-P1c `offers()` (its own `modules_at` had the identical branch, reached
|
||||
through the identical, already-intercepted method). Confirmed by reading
|
||||
`large_file.rs` and `dispatch.rs`'s `CodeActionRequest` arm side by side.
|
||||
Unchanged behaviour, as claimed — not a finding.
|
||||
- **Counter sabotage.** In `new_repo` only, twice, each reverted immediately
|
||||
after by copying the file back from the (untouched) main tree and
|
||||
confirming `diff -rq` against the main tree came back clean before
|
||||
proceeding:
|
||||
- Reverted `ports.rs::offered()` to call `vlog_refactor::port_actions`
|
||||
(mapping its results into fake `PortOffer`s) instead of
|
||||
`port_offers_in`. `cargo test -p lucisv_server code_action::` (guarded):
|
||||
**1 failed** —
|
||||
`the_port_offer_reads_the_declaring_file_once_and_nothing_else`
|
||||
("round 0: `sub.sv`'s parse, and no other (§P1c)", left: 24, right: 1).
|
||||
- Reverted `imports.rs::counts_at()` to call
|
||||
`vlog_refactor::organize_counts` instead of `organize_offer_in`.
|
||||
Same suite: **1 failed** —
|
||||
`the_organize_imports_offer_never_parses_the_buffer_it_is_offered_on`
|
||||
("round 0: one index over the buffer and its two packages", left: 11,
|
||||
right: 3).
|
||||
- Both counters are genuinely load-bearing for this diff specifically, not
|
||||
only for P1a/P1b's.
|
||||
|
||||
**§2 — THE MAIN ATTACK: the offer promise.**
|
||||
|
||||
Read `git show HEAD:crates/lucisv_server/src/ports.rs` (pre-P1c; `HEAD` is
|
||||
`6c1f863`, the P1a/P1b commit, and the working tree's uncommitted diff is
|
||||
P1c) and the current `ports.rs`/`imports.rs` side by side, plus
|
||||
`check::verify_splice` (`crates/vlog_refactor/src/check/mod.rs:139-146,
|
||||
238-341`) and `ports::confirm` (`crates/vlog_refactor/src/ports/mod.rs:496-
|
||||
511`).
|
||||
|
||||
**(a) Could an offer already be shown and then be refused on resolve, before
|
||||
P1c?** Yes, already, for **ports**: pre-P1c `ports::offers` (`git show
|
||||
HEAD:crates/lucisv_server/src/ports.rs:159-186`) called the *full*
|
||||
`vlog_refactor::port_actions` — planner **and** `check::verify_splice` **and**
|
||||
`ports::confirm` — but only over `offer_sources` (the buffer plus the
|
||||
instantiated module's declaring file), while `resolve` re-runs the identical
|
||||
`port_actions` over `ws.module_sources` (the module's real fan-out, ~1.4 ms/
|
||||
file). `docs/features/lazy-code-action/README.md:34-42` states this exactly:
|
||||
"the offer may be optimistic; the resolve is exact... an instantiation
|
||||
elsewhere connecting `sub`'s ports *by position*... is invisible to a
|
||||
one-file offer." `server/tests/code_action.rs:308-340`,
|
||||
`an_offer_the_fan_out_refuses_says_so_on_resolve_rather_than_crashing`, is a
|
||||
live, passing proof of exactly this on the **current** (P1c) server: the
|
||||
offer shows "remove port `b` (updates 1 instantiation)" and the resolve
|
||||
answers "the action is no longer available." **This precedent is genuinely
|
||||
scope-shaped**: `offer_sources` (`ports.rs:238-255`) is a documented, strict
|
||||
*subset* of what `code_actions`'s `ws.module_sources` (`ports.rs:107`) reads
|
||||
at resolve time.
|
||||
|
||||
**Is the same true for organize-imports, pre-P1c? No.** `imports.rs::at()`
|
||||
(`imports.rs:192-201`) is called *identically* by `offers()` (`imports.rs:78`),
|
||||
`code_actions()` (`imports.rs:50`, which is what `resolve()` re-runs at
|
||||
`imports.rs:133`) and `execute()` (`imports.rs:161`). The file set an offer
|
||||
sees and the file set a resolve/execute sees are **the same call, the same
|
||||
files, always** — there is no fan-out expansion for imports the way there is
|
||||
for ports. Pre-P1c, `offers()` called `vlog_refactor::organize_counts`
|
||||
directly (confirmed by reading the pre-diff hunk, `git diff` context lines
|
||||
above the `+` additions in `imports.rs`) — the *exact* function `resolve`
|
||||
still calls today, over the *exact* same scope. So pre-P1c, organize-imports'
|
||||
offer and its resolve **could not disagree**: same code, same files, same
|
||||
answer, by construction. That is not my inference — it is what the
|
||||
*unmodified* doc comment immediately above `offers()` still says, today, in
|
||||
the post-diff file: `imports.rs:65-70`, "The counts in the title are the
|
||||
engine's own, computed over the same file set `resolve` will use, **so the
|
||||
offer and the resolution cannot disagree about what the action promises.**"
|
||||
|
||||
**(b) Which refusals did the old offer path catch that the new predicate does
|
||||
not?** `verify_splice` catches, per `check/mod.rs`'s own tests: an edit that
|
||||
would leave a file unparseable (`a_splice_that_leaves_a_file_unparseable_is_
|
||||
rejected`), a comment/token mismatch (`Split`/`positions_match`/
|
||||
`pieces_match`), and — the one that matters here — a **captured or broken
|
||||
name resolution** in any watched file (`a_splice_that_captures_a_name_
|
||||
outside_the_edit_is_rejected`; for imports specifically,
|
||||
`removing_an_import_a_reference_needs_is_rejected`, pinned and described in
|
||||
`docs/features/organize-imports/README.md:178-201` as catching "a judgement
|
||||
that was wrong anyway" — i.e. treated by that feature's own README as a real,
|
||||
load-bearing safety net, not decorative). `ports::confirm` catches a plan
|
||||
whose rendered edit does not read back with the expected port/connection
|
||||
shape.
|
||||
|
||||
Three fixtures, reasoned through against the source (a live corruption is not
|
||||
constructible without an actual bug in the shared planner helpers, which none
|
||||
of the eight/seven exhaustive parity fixtures found — see below — but the
|
||||
*promise* question does not require one):
|
||||
|
||||
1. **A connection inserted where a macro sits, or any token/comment issue in
|
||||
the edited file(s) alone (the removal, propagation, expansion or
|
||||
conversion's own edits).** `verify_splice`'s token/comment/parse-error
|
||||
checks are computed **only from the edited files and their edits**
|
||||
(`check/mod.rs:274-296`) — they read no other file in scope, so they are
|
||||
scope-independent. The predicate builds the *same* edits from the *same*
|
||||
shared helpers the eager planner calls (`ports/offer.rs`'s own module
|
||||
doc, lines 15-20), so whatever this check would say is identical whether
|
||||
it runs now (offer, skipped) or later (resolve, unchanged) on the same
|
||||
edited bytes. **Verdict: no divergence possible** — if the new predicate
|
||||
offers something this check would refuse, resolve (which re-verifies over
|
||||
a superset of files, never a smaller one, and the *same* edited files)
|
||||
refuses it identically. Confined to the documented optimistic-offer
|
||||
contract for ports; for imports, offer and resolve share the identical
|
||||
scope, so this is even stronger — not "optimistic," just "deferred."
|
||||
2. **A removal or organize-imports deletion `ports::confirm` /
|
||||
`verify_splice`'s resolution check refuses.** `confirm` is also fully
|
||||
scope-independent (`ports/mod.rs:496-511`: reads only `plan.expected` and
|
||||
re-applies `plan.edits` to the plan's own files) — same conclusion as (1).
|
||||
`verify_splice`'s **resolution** half (the before/after `print` comparison
|
||||
over `watched_files`) is the one part that is genuinely scope-dependent:
|
||||
a larger scope watches a superset of files and can only find *more*
|
||||
captures, never fewer, for a fixed edited-file/edits pair and a fixed set
|
||||
of *common* watched files — **except** where a name's resolution through
|
||||
`scope.index()` itself depends on which *other* files are present (e.g. a
|
||||
package or macro visible only in the larger scope). I attempted to
|
||||
construct exactly this for imports, reusing `check/mod.rs`'s own
|
||||
`imported()`/`a_t` shape through the *real* `organize()`/`planned()`
|
||||
pipeline rather than calling `verify_splice` directly (which the pinned
|
||||
test does): `import_usage`'s design is a deliberate "superset of the
|
||||
truth" (`organize-imports/README.md:104-109` — "being wrong in [keeping an
|
||||
import] keeps an import; being wrong in the other direction deletes a
|
||||
line the code needs, which is the one outcome nothing here may produce"),
|
||||
and the exhaustive refusal list (unindexed/duplicate package, any macro or
|
||||
conditional anywhere in scope, an externally-declared base class, a parse
|
||||
diagnostic — `organize-imports/README.md:111-131`) is written specifically
|
||||
to prevent the false-negative case verify_splice's resolution check would
|
||||
otherwise be the last line of defense for. I could not, in the time
|
||||
available, construct an input where `import_usage` mis-judges — the
|
||||
built-in refusal list appears to correctly cover every case I tried
|
||||
(macro use, an unindexed package, a duplicate package). **I cannot
|
||||
demonstrate live corruption or a live wrong offer-then-succeed on this
|
||||
axis.** That does not resolve finding 1 below — it narrows it from "will
|
||||
misfire" to "is not proven safe by the existing suites, and the feature's
|
||||
own README treats the check it removes as load-bearing rather than
|
||||
decorative."
|
||||
3. **A module declared twice in the fan-out but once in the buffer +
|
||||
declaring file.** Not a live risk for ports: `declared_twice` (item §6
|
||||
above) is a *server-level* gate over the full workspace index, run before
|
||||
the predicate is ever called, unchanged by this diff, and it answers this
|
||||
exact question the same way regardless of what the two-file scope alone
|
||||
could see. Confirmed: `port_offers.rs`'s
|
||||
`a_module_two_files_declare_is_silent_in_both_answers` test constructs
|
||||
precisely this ambiguity within the *predicate's own* two-file view and
|
||||
the *server's* full-index view agrees. No finding.
|
||||
|
||||
**Verdict on (2): no widened or narrowed promise found for PORTS** — the
|
||||
`verify_splice`/`confirm` skip is provably confined to cases resolve
|
||||
re-catches identically (scope-independent checks) or was already an
|
||||
accepted, documented, tested optimistic-offer property predating P1c
|
||||
(the resolution half, over a genuinely larger fan-out at resolve time,
|
||||
exactly as §37.1 shipped and was reviewed).
|
||||
|
||||
---
|
||||
|
||||
**FINDING 1 (REWORK) — the organize-imports offer's contract is widened
|
||||
without a covering quote, and the dev's own justification for it does not
|
||||
hold.**
|
||||
|
||||
`crates/vlog_refactor/src/imports.rs:225-239` (`organize_offer`) and its
|
||||
sibling `organize_offer_in` (`:248-263`) both build `Scope::build(files)` —
|
||||
the *same* `files` and the *same* scope `organize()`/`organize_counts`
|
||||
(`imports.rs:152-173`, called by `resolve`/`execute` unchanged) use — and skip
|
||||
only `check::verify_splice` (`imports.rs:168`). There is **no fan-out
|
||||
difference** for organize-imports (§2(a) above): the offer and the resolve
|
||||
have always read identical files. Before this diff, that identity plus a
|
||||
full `verify_splice` call at offer time meant the offer's promise was
|
||||
*exact*, not merely optimistic — the organize-imports feature's own README
|
||||
states this as a design goal (`organize-imports/README.md:178-183`, "The
|
||||
verifier is the second net... every declaration and every reference... must
|
||||
resolve to the same place before and after"; the API-level doc comment,
|
||||
`imports.rs:65-70`, still unmodified, says outright that the offer and the
|
||||
resolution "cannot disagree about what the action promises").
|
||||
|
||||
The dev's work log (`perf5-p1/README.md:452-458`) and the tracker
|
||||
(`take5-tracking.md:149`) justify skipping this check by citing
|
||||
`docs/features/lazy-code-action/README.md`'s "the offer may be optimistic;
|
||||
the resolve is exact," with the reason given as "because the offer reads one
|
||||
or two files and the resolve reads the fan-out." **That reason is true for
|
||||
ports and false for imports** — I confirmed by reading `imports.rs::at()`
|
||||
that organize-imports' offer and resolve read the *same* file set, always;
|
||||
there is no fan-out to defer to. `lazy-code-action/README.md` itself is
|
||||
scoped to "the port refactorings" (`README.md:10-19`) and says nothing about
|
||||
organize-imports, which has its own feature and its own README with the
|
||||
opposite promise. So the citation does not cover this case, and the
|
||||
work log's stated justification for extending it to imports is factually
|
||||
incorrect on its own terms, not merely under-specified.
|
||||
|
||||
**What this means in practice, and what it does not.** No CLAUDE.md hard
|
||||
invariant is at risk: `resolve`/`execute` are untouched and still run
|
||||
`check::verify_splice` before any edit reaches a client, so a corrupted edit
|
||||
cannot ship (invariant 1) and idempotency/comment-preservation are untouched.
|
||||
What is at risk is a **lightbulb that appears and then declines** for
|
||||
organize-imports specifically — a UX regression this feature's README
|
||||
explicitly designed against, and a class of divergence the every-offset
|
||||
parity suites in `import_offers.rs` cannot see by their own admission ("which
|
||||
no fixture here reaches", `import_offers.rs:9`). I could not construct a live
|
||||
input that triggers it (§2(b)(2) above), and `import_usage`'s "superset of
|
||||
the truth" design makes it plausible that it may never fire on well-formed
|
||||
input — but "we could not find a failing case" is not the same as "the
|
||||
promise is unchanged," and CLAUDE.md's own standard for a safety-net
|
||||
narrowing ("guilty until proven innocent... ships WITH masked-corruption
|
||||
attack tests") points the same way: `check::verify_splice`'s pinned imports
|
||||
attack (`removing_an_import_a_reference_needs_is_rejected`) exists *because*
|
||||
the project considered this exact failure mode plausible enough to test for
|
||||
when the check was added; removing it from one call site with no analogous
|
||||
attack test demonstrating the new call site's behaviour under that same
|
||||
attack is the asymmetry CLAUDE.md's rule exists to catch.
|
||||
|
||||
**Recommendation (not mine to decide — a lead ruling, per this feature's
|
||||
document-based-development rule):** either (a) keep `check::verify_splice` in
|
||||
`organize_offer`/`organize_offer_in` — the measured cost is the smaller of
|
||||
the two P1c wins (0.8-4 ms per offer at these file sizes, versus the
|
||||
77-85% ports win, which is unaffected by this finding), or (b) accept the
|
||||
narrower contract explicitly: update `imports.rs:65-70`'s stale doc comment,
|
||||
`organize-imports/README.md`'s Goal/§"the verifier is the second net"
|
||||
sections, and `lazy-code-action/README.md` to state that organize-imports'
|
||||
offer is now optimistic too and why, and add a masked-misfire attack test
|
||||
(even one driven through `check::verify_splice`'s own unit-test style, since
|
||||
a live `import_usage` false negative could not be constructed) that pins
|
||||
what happens when this specific check would have fired: the offer shows a
|
||||
title, `resolve`/`execute` decline it, and the server answers gracefully
|
||||
rather than emitting anything. Either is a small, well-scoped follow-up; I am
|
||||
not redesigning the feature, only naming the gap and where it needs a
|
||||
decision that is not QA's to make.
|
||||
|
||||
**Everything else in this stage: no finding.** Gates, line counts,
|
||||
invariant 4, the ports offer-promise analysis, title-count parity (including
|
||||
the three additional QA fixtures), both ambiguity gates, large-file mode,
|
||||
the parse counters (sabotage-tested twice), the re-measured cells (13 of 13
|
||||
within this document's own tolerance framework, three fingerprints
|
||||
byte-identical), and traceability all check out exactly as the dev's work log
|
||||
and the tracker describe.
|
||||
|
||||
**Verdict: REWORK.** Not for corruption risk (none found; invariant 1 holds
|
||||
throughout) and not for anything on the ports side (clean). Finding 1 is a
|
||||
documentation/contract inconsistency the diff itself introduces (a stale
|
||||
"cannot disagree" doc comment sitting directly above the function that now
|
||||
can) plus a factually incorrect justification for it in the work log and the
|
||||
tracker, on a safety-net removal CLAUDE.md's own standard treats as guilty
|
||||
until proven innocent. It needs a lead ruling (keep the check, or accept and
|
||||
document the narrower contract with an attack test) before this line of
|
||||
TODO §60.1 is ticked. **Not** ticking the §60.1 P1c QA line.
|
||||
|
||||
## Review
|
||||
|
||||
**2026-09-07 (lead).** Accepted. Read the diff (dispatch gate,
|
||||
@@ -550,3 +1196,26 @@ real 0.50.0 server (17 cursors, 0 mismatches) is the acceptance.
|
||||
|
||||
Docs applied at merge: topo edges for `vlog_parser::stats`, the four
|
||||
`_in` selectors and `fences.rs`; TODO §60.1 P1c and lint-memo rulings.
|
||||
|
||||
**2026-09-07 (lead, P1c).** Accepted, with a ruling on QA's finding 1.
|
||||
|
||||
- The three targets are met (`aes_reg_top` 21.8 → 5.5 ms, `aes` 7.8 → 1.7,
|
||||
organize-imports 15.4 → 4.9) with titles, counts and the three resolve
|
||||
fingerprints byte-identical to the reference, and the every-offset parity
|
||||
suites make the predicate and the planner one implementation.
|
||||
- **Ruling on finding 1 (the organize-imports offer no longer runs
|
||||
`verify_splice`).** Accepted as a documented narrowing of the *offer's*
|
||||
promise, not of any safety net: the counts the title carries come from the
|
||||
same planner the click runs; `organize_imports` still verifies over the
|
||||
identical file set before any edit leaves the engine; the only observable
|
||||
difference is a click that could be answered with the refusal sentence —
|
||||
the contract every other lazy offer already has. CLAUDE.md's invariant 4
|
||||
is about a verifier's *forgiveness*, and none was widened here. What was
|
||||
wrong was the organize-imports README still calling the offer exact; the
|
||||
lead amended its "second net" section to say when the net runs now.
|
||||
QA's inability to construct a plan the verifier refuses but the planner
|
||||
accepts is noted there as the reason no new attack pair exists; the
|
||||
existing pair in `check.rs` stays the pin.
|
||||
- Deviations accepted: the predicate rendering the propagation's edits to
|
||||
count them (text work, no parse, no index); the one `use` line in
|
||||
`server/tests/mod.rs`; the two engine test files.
|
||||
+171
-17
@@ -1,6 +1,6 @@
|
||||
# Performance implementation tracker — take 5
|
||||
|
||||
**Status: baseline measured; P0 done; P1a and P1b implemented and measured (2026-09-07, QA pending).** The implementation agent owns the blank candidate columns and experiment entries below. Read [the causes and detailed plan](../performance_take5.md) before selecting work. Baseline provenance and raw rows are in [take5-baseline](take5-baseline/README.md).
|
||||
**Status: baseline measured; P0 done; P1a, P1b and P1c implemented and measured (2026-09-07; P1c QA pending).** The implementation agent owns the blank candidate columns and experiment entries below. Read [the causes and detailed plan](../performance_take5.md) before selecting work. Baseline provenance and raw rows are in [take5-baseline](take5-baseline/README.md).
|
||||
|
||||
Do not overwrite the baseline, silently replace a workload, omit refusals, or report a proposed target as an achieved result. Use `not measured`, `blocked`, or `not applicable` rather than zero. Update this file after each measured stage, including rejected changes.
|
||||
|
||||
@@ -34,7 +34,7 @@ The order follows the plan. Later stages are conditional on the preceding measur
|
||||
| P0 | Harness status/units/command execution/cold-cache corrections | — | dev (Opus) → QA PASS → lead; committed 2026-09-07 | Done | `docs/features/perf5-p0/README.md`; experiment `P0-2026-09-07` below. Schema 2 shipped; `execute` phase measures the extract/inline commands for the first time; cold sweep tries verified at 0 hits, warm at 30; baseline reproduced on the unchanged binary |
|
||||
| P1a | Gate lint/fence/config by requested kinds; avoid fence work without fixes | P0 | dev (Opus) → QA PASS → lead; committed 2026-09-07 | Done | `docs/features/perf5-p1/README.md`; experiment `P1a-2026-09-07` below. Pinmux `only: []` 82.80 → **0.064 ms**; quickfix 84.13 → **23.53**; all families 309.60 → **258.06**. Separates the base at last: lint+config **23.5 ms**, fence parse **59.3 ms** |
|
||||
| P1b | Shared parsed selectors; revision-bound fence reuse; invalidate any additional cache correctly | P1a | dev (Opus) → QA PASS → lead; committed 2026-09-07 | Done | Same README; experiment `P1b-2026-09-07`. Pinmux all families **24.02 ms** (−92.2% on REF), queued definition **24.61** (−92.0%). Lint-result reuse **not done** — reason and number in the experiment entry |
|
||||
| P1c | Engine-owned lightweight ports/import offers | Reprofile P1b | — | **Ruled go (lead, 2026-09-07); next lane** | After P1b the `aes_reg_top` offer is 21.83 ms of which the ports family alone is **21.15**; `aes` 7.76. The four gates now cost ~0.06–0.14 ms each. Every remaining millisecond at an *offering* cursor is the engine plan the offer discards |
|
||||
| P1c | Engine-owned lightweight ports/import offers | Reprofile P1b | dev (Opus) → QA REWORK on one documentation point, ruled and applied by the lead → committed 2026-09-07 | Done | `docs/features/perf5-p1/README.md`; experiment `P1c-2026-09-07` below. `aes_reg_top` lazy offer 21.83 → **5.46 ms**, its ports family 21.15 → **3.27**; `aes` 7.76 → **1.74**; the organize-imports offer 15.39 (REF) → **4.88**. **All three targets met.** Answers identical to P1b on 50 rows and to the REF on 65, field by field; the three resolve fingerprints unchanged |
|
||||
| P2a | Rename per-stage timings and selected/watched/input counts | P0 | — | Not started | — |
|
||||
| P2b | Reuse per-file input analysis in request-local scope | P2a | — | Not started | — |
|
||||
| P2c | Reuse unchanged after-facts/semantics; re-resolve external references | P2b | — | Not started | — |
|
||||
@@ -63,22 +63,34 @@ before and after every phase, corpus verified unchanged after every phase,
|
||||
zero guard kills. Paired change is `100 × (REF − candidate) / REF` on repeat
|
||||
medians. Raw rows: `~/.cache/lucisv-perf/take5-p1/results-p1{a,b}.jsonl`.
|
||||
|
||||
**P1c note.** Taken on release server sha256
|
||||
`33a6888af3f2bc9b3b2d1fb2844f3d93f9f5950839446866838244f913d56cf1`, three
|
||||
tries per row, lazy client, warm workspace scope, scratch index caches, load
|
||||
3.8–4.9 recorded before and after every phase, corpus verified unchanged after
|
||||
every phase, zero guard kills, no `cargo` command during any timed phase. Raw
|
||||
rows: `~/.cache/lucisv-perf/take5-p1c/results-p1c.jsonl`. The `refactor` phase
|
||||
was **not** run at P1a or P1b, so its rows below are paired against the §P0
|
||||
REF and part of each delta is §P1b's.
|
||||
|
||||
| Metric / baseline source | Baseline | Proposed goal or guardrail | Candidate | Paired change | Verdict |
|
||||
|---|---:|---|---|---|---|
|
||||
| Pinmux comment, lazy all families (`offer-breakdown`) | 328.41 / 296.78–311.73 ms; 0 actions | Repeated <16 ms; first-after-edit separate | **REF (P0, same binary, `offerkinds`)** 333.89 / 307.35–312.97 ms; 0 actions — REF repeat median **309.60**. **P1a** 289.33 / 251.87–258.91, median 258.06. **P1b** 50.07 / 23.79–24.43, median **24.02**; 0 actions in every try | REF vs baseline +4.1%. **P1a −16.6%, P1b −92.2%** on repeat medians | REF agrees. P1b is a 12.9× reduction with an identical (empty) answer. **Target <16 ms missed**: the remaining 24.0 ms is the lint pass — quickfix-only is 24.05 and `only: []` is 0.053 |
|
||||
| Pinmux comment, lazy all families (`offer-breakdown`) | 328.41 / 296.78–311.73 ms; 0 actions | Repeated <16 ms; first-after-edit separate | **REF (P0, same binary, `offerkinds`)** 333.89 / 307.35–312.97 ms; 0 actions — REF repeat median **309.60**. **P1a** 289.33 / 251.87–258.91, median 258.06. **P1b** 50.07 / 23.79–24.43, median **24.02**; 0 actions in every try. **P1c** 25.42 / 23.05–23.61, median **23.55**; 0 actions | REF vs baseline +4.1%. **P1a −16.6%, P1b −92.2%, P1c −1.9% on P1b** | REF agrees. P1b is a 12.9× reduction with an identical (empty) answer. **Target <16 ms still missed**, and P1c cannot move it: this cursor offers nothing, so no predicate runs — the remaining 23.6 ms is the lint pass, which is the deferred lint-memo item |
|
||||
| Pinmux comment, `only: []` | 78.88 / 79.43–81.62 ms; 0 actions | Return near transport floor; no lint/parse | **REF** 81.72 / 82.27–84.11 ms; 0 actions — REF median **82.80**. **P1a** 0.13 / 0.053–0.070, median 0.064. **P1b** 0.12 / 0.049–0.054, median **0.053** | REF vs baseline +1.7%. **P1a −99.9%, P1b −99.9%** | Goal met: an empty filter answers at the transport floor (that row is itself 0.061–0.102 ms), with no config read, no lint and no parse — asserted by parse count in `an_empty_only_filter_answers_empty_and_does_no_work_at_all` |
|
||||
| Pinmux comment, quickfix only | 79.54 / 79.73–80.06 ms; 0 actions | Avoid repeated lint/fence work safely | **REF** 82.76 / 82.50–85.06 ms; 0 actions — REF median **84.13**. **P1a** 24.03 / 23.47–23.85, median 23.53. **P1b** 23.57 / 23.92–24.25, median **24.05** | REF vs baseline +5.5%. **P1a −72.0%, P1b −71.4%** | The 60 ms P1a removed here is the fence parse, skipped because **no finding in this buffer carries a fix**. P1b cannot improve it further: what is left is the configuration read plus the lint pass, and no lint-result reuse was added (see `P1b-2026-09-07`) |
|
||||
| Pinmux comment → queued definition (`offer-queue`) | 300.66–304.11 ms follower, 3 pipelines | Repeated follower <16 ms if no other blocker | **REF (`offerqueue`)** follower 339.47 / 309.07 / 309.72 ms; leader 339.53 / 309.08 / 309.73; 3 pipelines, now in `leader_ms`/`follower_ms` — REF follower mean of pipelines 2–3 **309.40**. **P1a** follower 275.77 / 253.20 / 251.68 (mean 2–3 = 252.44). **P1b** follower 43.62 / 25.57 / 23.65 (mean 2–3 = **24.61**) | REF vs baseline +2.0%. **P1a −18.4%, P1b −92.0%** | The queued definition falls with its blocker, as the plan predicted. **Target <16 ms missed** by the same 24 ms of lint the leader pays |
|
||||
| `tb.sv` comment, lazy (`codeaction`) | 6.15 / 3.22–3.50 ms; 0 actions | Repeated <5 ms; no added parse | **REF** 5.53 / 3.80–4.79 ms; 0 actions — REF median **4.46**. **P1a** 5.99 / 3.89–4.76, median 4.02. **P1b** 5.49 / 3.48–4.29, median **3.65** | REF vs baseline **+27.9%** (outside tolerance, see the P0 entry). **P1a −9.9%, P1b −18.3%** | Target <5 ms **met**. The same file's `offerkinds` cursor, the cleaner row, went 1.54 → **0.60 ms** (−61.4%) |
|
||||
| `aes` lazy offer (`codeaction`) | 12.39 / 8.15–9.11 ms; 1 action | Repeated <5 ms | **REF** 13.87 / 7.33–9.66 ms; 1 action — REF median **8.17**. **P1a** 14.30 / 7.21–9.60, median 7.92. **P1b** 11.41 / 7.11–9.70, median **7.76**; 1 action in every try | REF vs baseline −8.0%. **P1a −3.1%, P1b −5.0%** | **Target <5 ms missed.** The gate is now ~0.1 ms; what is left is the ports offer computing a plan whose edits it discards — **P1c** |
|
||||
| `aes_reg_top` lazy offer (`codeaction`) | 32.81 / 22.45–25.09 ms; 2 actions | Repeated <10 ms | **REF** 30.64 / 22.72–24.42 ms; 2 actions — REF median **23.31**. **P1a** 32.24 / 22.08–24.17, median 23.60. **P1b** 31.50 / 20.93–24.42, median **21.83**; 2 actions in every try | REF vs baseline +1.0%. **P1a +1.3% (no change), P1b −6.3%** | **Target <10 ms missed.** Measured residue: the ports family alone is **21.15 ms** of the 21.83, and the other five families together under 0.6 ms — the whole row is the discarded ports plan, **P1c** |
|
||||
| `aes_reg_top` ports-only offer (`offer-breakdown`) | 21.72 / 21.55–21.78 ms; 0 port actions | Remove throwaway edit computation | **REF (`offerkinds`)** 22.27 / 22.46–22.56 ms; 0 port actions — REF median **22.47**. **P1a** 21.68 / 21.28–21.89, median 21.84. **P1b** 20.86 / 21.14–21.48, median **21.15**; 0 port actions | REF vs baseline +3.3%. **P1a −2.8%, P1b −5.8%** | Barely moved, as expected: §P1b removed this family's *gate* parse, not the engine plan behind it. This is the row **P1c** exists for |
|
||||
| Pinmux comment → queued definition (`offer-queue`) | 300.66–304.11 ms follower, 3 pipelines | Repeated follower <16 ms if no other blocker | **REF (`offerqueue`)** follower 339.47 / 309.07 / 309.72 ms; leader 339.53 / 309.08 / 309.73; 3 pipelines, now in `leader_ms`/`follower_ms` — REF follower mean of pipelines 2–3 **309.40**. **P1a** follower 275.77 / 253.20 / 251.68 (mean 2–3 = 252.44). **P1b** follower 43.62 / 25.57 / 23.65 (mean 2–3 = **24.61**). **P1c** follower 38.02 / 25.83 / 23.85 (mean 2–3 = **24.84**) | REF vs baseline +2.0%. **P1a −18.4%, P1b −92.0%, P1c −0.9% on P1b** | The queued definition falls with its blocker, as the plan predicted. **Target <16 ms missed** by the same lint the leader pays; the leader here offers nothing, so P1c has nothing to remove |
|
||||
| `tb.sv` comment, lazy (`codeaction`) | 6.15 / 3.22–3.50 ms; 0 actions | Repeated <5 ms; no added parse | **REF** 5.53 / 3.80–4.79 ms; 0 actions — REF median **4.46**. **P1a** 5.99 / 3.89–4.76, median 4.02. **P1b** 5.49 / 3.48–4.29, median **3.65**. **P1c** 3.70 / 2.63–2.98, median **2.73** | REF vs baseline **+27.9%** (outside tolerance, see the P0 entry). **P1a −9.9%, P1b −18.3%, P1c −25.1% on P1b** | Target <5 ms **met**. The same file's `offerkinds` cursor is a sub-millisecond row and is not read (0.60 → 0.84) |
|
||||
| `aes` lazy offer (`codeaction`) | 12.39 / 8.15–9.11 ms; 1 action | Repeated <5 ms | **REF** 13.87 / 7.33–9.66 ms; 1 action — REF median **8.17**. **P1a** 14.30 / 7.21–9.60, median 7.92. **P1b** 11.41 / 7.11–9.70, median **7.76**; 1 action in every try. **P1c** 2.72 / 1.60–2.03, median **1.74**; 1 action in every try | REF vs baseline −8.0%. **P1a −3.1%, P1b −5.0%, P1c −77.6% on P1b** | **Target <5 ms met at P1c.** The other three fan-out cursors fall with it: 42 → **0.77**, 67 → **1.78**, 128 → **1.38** ms lazy |
|
||||
| `aes_reg_top` lazy offer (`codeaction`) | 32.81 / 22.45–25.09 ms; 2 actions | Repeated <10 ms | **REF** 30.64 / 22.72–24.42 ms; 2 actions — REF median **23.31**. **P1a** 32.24 / 22.08–24.17, median 23.60. **P1b** 31.50 / 20.93–24.42, median **21.83**; 2 actions in every try. **P1c** 6.92 / 4.80–5.62, median **5.46**; 2 actions in every try | REF vs baseline +1.0%. **P1a +1.3% (no change), P1b −6.3%, P1c −75.0% on P1b (−76.6% on REF)** | **Target <10 ms met at P1c.** P1b's residue was the discarded ports plan; §P1c replaced it with a predicate. The 5.46 ms left is dominated by the one parse of `aes_reg_top.sv` (52 461 B, 2.16–2.43 ms standalone) |
|
||||
| `aes_reg_top` ports-only offer (`offer-breakdown`) | 21.72 / 21.55–21.78 ms; 0 port actions | Remove throwaway edit computation | **REF (`offerkinds`)** 22.27 / 22.46–22.56 ms; 0 port actions — REF median **22.47**. **P1a** 21.68 / 21.28–21.89, median 21.84. **P1b** 20.86 / 21.14–21.48, median **21.15**; 0 port actions. **P1c** 3.51 / 3.08–3.45, median **3.27**; 0 port actions | REF vs baseline +3.3%. **P1a −2.8%, P1b −5.8%, P1c −84.6% on P1b (−85.5% on REF)** | The row P1c existed for. All four planners refuse at *plan* time here, and the offer used to pay four `WorkspaceIndex::build`s (3.89 ms each, measured) to be told so. The all-family cell at the same cursor is 21.79 → **4.70** |
|
||||
| `state_q` tail rename (`tailrename`) | 821.59 / 789.50–809.83 ms; 2 files | At least 2× faster; stretch <200 ms | **REF** 813.44 / 778.77–782.13 ms; **5 edits / 2 files / 0 created**, fingerprint `b39defb21265…` | −1.4% | Agrees; reference for P2, now with an edit fingerprint to compare against |
|
||||
| Ordinary `aes` rename (`rename`) | 168.67 / 139.34–140.35 ms; 9 files | No regression; exact edit/warning parity | **REF** 167.60 / 140.46–142.13 ms; **14 edits / 9 files / 0 created**, fingerprint `fa7e31c78382…` | +1.2% | Agrees; reference for P2 |
|
||||
| Definition behind ordinary rename (`blockers`) | 145.99–168.79 ms, 3 pipelines | Falls with rename work | **REF** 163.43 / 161.55 / 161.11 ms, 3 pipelines (now `follower_ms.definition`) | inside the baseline range | Agrees |
|
||||
| Connect missing ports resolve (`refactor`) | 170.77 / 164.79–165.82 ms; 1 file | Measure collateral benefit; exact edit parity | **REF** 171.37 / 165.77–167.45 ms; 1 file | +0.4% | Agrees |
|
||||
| Expand wildcard resolve (`refactor`) | 73.02 / 70.35–70.73 ms; 1 file, 32 connections | No lost connections/refusals | **REF** 73.61 / 71.67–73.01 ms; 1 file, 32 connections | +2.2% | Agrees |
|
||||
| Eager 128-fan-out offer (`codeaction`) | 518.32 / 495.60–499.69 ms | Compatibility/perf guardrail; not first priority | **REF** 523.16 / 495.13–496.77 ms; 2 actions — REF median **496.24**. **P1b** 519.49 / 492.71–494.57, median **493.92**; 2 actions | REF vs baseline +0.1%. **P1b −0.5%** | Unchanged, which is the guardrail: the eager path's cost is the module's fan-out and P1 did not touch it |
|
||||
| Connect missing ports resolve (`refactor`) | 170.77 / 164.79–165.82 ms; 1 file | Measure collateral benefit; exact edit parity | **REF** 171.37 / 165.77–167.45 ms; 1 file, REF median **166.51**, fingerprint `4b534a16bca7…`. **P1c** 168.01 / 165.15–209.85, median **169.13**; 1 file, 2 edits, **fingerprint identical** | REF vs baseline +0.4%; **P1c +1.6% on REF** | Agrees. The click path is untouched by §P1c and its edit is byte-identical |
|
||||
| Expand wildcard resolve (`refactor`) | 73.02 / 70.35–70.73 ms; 1 file, 32 connections | No lost connections/refusals | **REF** 73.61 / 71.67–73.01 ms; 1 file, 32 connections, REF median **71.89**, fingerprint `8f3a26dd147b…`. **P1c** 76.61 / 69.34–71.40, median **70.22**; 1 file, 32 connections, **fingerprint identical** | REF vs baseline +2.2%; **P1c −2.3% on REF** | Agrees; no connection and no refusal moved |
|
||||
| Eager 128-fan-out offer (`codeaction`) | 518.32 / 495.60–499.69 ms | Compatibility/perf guardrail; not first priority | **REF** 523.16 / 495.13–496.77 ms; 2 actions — REF median **496.24**. **P1b** 519.49 / 492.71–494.57, median **493.92**; 2 actions. **P1c** 516.78 / 492.51–496.34, median **492.54**; 2 actions | REF vs baseline +0.1%. **P1b −0.5%, P1c −0.3%** | Unchanged, which is the guardrail: the eager path's cost is the module's fan-out, and neither P1b nor P1c touched it — `code_actions` still computes and verifies every plan |
|
||||
| Port-actions **offer**, `aes_wrap.sv` 78:2 (`refactor`, **new**) | not measured as a row — take 4's §6b prose only | Repeated <5 ms; identical titles | **REF (P0)** 38.79 / 24.57–27.80 ms; 2 actions, REF median **24.84**. **P1c** 1.53 / 1.13–1.45, median **1.19**; 2 actions, same titles | **−95.2% on REF** | New row. The site that actually offers a port refactoring on opentitan. Part of the delta is §P1b's gate (0.06–0.14 ms per family), the rest is §P1c. Not run at P1a/P1b |
|
||||
| Organize-imports **offer**, `aes_sbox_canright_masked.sv` 42:2 (`refactor`, **new**) | not measured as a row — take 4 §6c put it at 30.1 / 13.8–19.5 | Repeated <5 ms; identical counts | **REF (P0)** 32.25 / 13.70–18.04 ms; 2 actions, REF median **15.39**. **P1c** 8.42 / 4.69–6.59, median **4.88**; 2 actions, title `lucisv: organize imports (removes 1, sorts 1)` unchanged | **−68.3% on REF** | New row. **Target <5 ms met.** The residue is one `Scope::build` over the buffer and its two packages (2.05 ms standalone); the buffer's own share of it is the handshake request in `perf5-p1`'s README |
|
||||
| Organize-imports **resolve** (`refactor`, **new**) | not measured | No lost removal, sort or refusal | **REF (P0)** 9.87 / 9.45–10.15 ms; 1 file, 1 edit, fingerprint `0ee027e37d07…`, REF median **9.45**. **P1c** 14.62 / 9.96–11.97, median **11.03**; 1 file, 1 edit, **fingerprint identical** | +16.7% on REF, inside this document's ±20% band for a 1–20 ms row | New row. The resolve path is unchanged by §P1c — `organize`'s middle was lifted into `planned` and it still verifies the splice |
|
||||
| First offer after a `didChange`, same cursor (`offeredit`, **new**) | not measured — the gap the P0 entry named | Track separately from the repeated offer | **P1a** pinmux 383.61 / 366.93–369.71 (median 368.32); `aes_reg_top` instance 35.82 / 23.38–26.30 (24.84); `tb.sv` comment 4.80 / 3.28–3.42 (3.35). **P1b** pinmux 152.88 / 132.68–135.04 (median **133.86**); `aes_reg_top` 28.82 / 22.58–22.75 (**22.66**); `tb.sv` 2.29 / 1.90–2.00 (**1.95**) | P1a → P1b: pinmux **−63.7%**, `aes_reg_top` −8.8%, `tb.sv` −41.8% | New row, new phase `offeredit`. Each try is the *first* `codeAction` after its own `didChange`, so the document rebuild is inside the number; the paired "repeated offer on the unchanged buffer" rows sit beside them in the same session (P1b: pinmux **24.18**, `aes_reg_top` **21.65**, `tb.sv` **0.54**). No REF exists — P0 could not measure it |
|
||||
| Extract command actually executed (`execute`, **new**) | not measured — take 4's `extract-module resolve` rows are invalid | Measure the command, not a refusal | **REF** `lucisv.extractModule` at `aes.sv` 220:0–222:53: **257.33 / 245.05–247.00 ms** executeCommand→applyEdit; 2 edits / 2 files / **1 created**; `deliver_ms` 0.015–0.033; status `capture`; fingerprint `090e92e7736e…` | new row | The gap the tracker's work-count table named is closed |
|
||||
| Inline command actually executed (`execute`, **new**) | not measured | Measure the command, not a refusal | `lucisv.inlineModule` at `aes_wrap.sv` 66:2 is **refused** (`generate` construct); 6.58 / 5.87–6.20 ms. Not a timing of an inline | new row | Refusal recorded as `refused`; **not quotable** as an inline cost |
|
||||
@@ -106,9 +118,9 @@ medians. Raw rows: `~/.cache/lucisv-perf/take5-p1/results-p1{a,b}.jsonl`.
|
||||
|
||||
| Measurement | Baseline knowledge | Reference — agent fills | Candidate — agent fills |
|
||||
|---|---|---|---|
|
||||
| Additional parses per no-offer all-family action | 5 text-parse entry points confirmed in source; no runtime counter | Still no runtime counter — P0 is harness-only and adds no production instrumentation. The wire-side attribution is reproduced (`offerkinds`): 82.80 ms shared base at the pinmux cursor, +52.7 to +57.6 ms for any one selector family | **Counter added and asserted on.** `vlog_parser::stats::parses()` counts whole-file parses (thread-local; a request is answered on one thread). At a no-offer cursor a *repeated* all-family `codeAction` performs **0** parses, an `only: []` request **0**, and the first request after a `didChange` **≤2** (the document's own parse, plus the fence answer when a fix exists) — `server::tests::code_action`. On the wire the five parses are gone: a single selector family fell from 58.6–59.7 ms to **0.06–0.14 ms** at the pinmux cursor |
|
||||
| Additional parses per no-offer all-family action | 5 text-parse entry points confirmed in source; no runtime counter | Still no runtime counter — P0 is harness-only and adds no production instrumentation. The wire-side attribution is reproduced (`offerkinds`): 82.80 ms shared base at the pinmux cursor, +52.7 to +57.6 ms for any one selector family | **Counter added and asserted on.** `vlog_parser::stats::parses()` counts whole-file parses (thread-local; a request is answered on one thread). At a no-offer cursor a *repeated* all-family `codeAction` performs **0** parses, an `only: []` request **0**, and the first request after a `didChange` **≤2** (the document's own parse, plus the fence answer when a fix exists) — `server::tests::code_action`. On the wire the five parses are gone: a single selector family fell from 58.6–59.7 ms to **0.06–0.14 ms** at the pinmux cursor. **P1c:** at a cursor that *does* offer, a repeated ports offer performs **1** parse — the instantiated module's declaring file — and a repeated organize-imports offer **3**, one `Scope::build` over the buffer and the two packages it imports. Both are asserted by count in `server::tests::code_action` against a `resolveSupport` client, which is the path the offer predicates are on |
|
||||
| Lint/config/fence time separately | About 80 ms combined on generated file; unseparated | Reproduced but still unseparated: pinmux `only: []` 82.80 ms, quickfix 84.13 ms. Separating them needs P1's counters | **Separated by P1a's gates.** `only: []` now answers in **0.064 ms**, so none of the 82.8 ms was unavoidable. Quickfix-only is **23.53 ms** — the configuration read plus the lint pass. The difference, **59.3 ms, was the fence parse**, and it vanished at this cursor because no finding in `pinmux_reg_top.sv` carries a fix, so §P1a's "no fix, no fence" gate skips it outright |
|
||||
| Selector time by family and file size | Filtered ablations preserved in raw data | **Promoted to the committed `offerkinds` phase**: 7 families × 5 cursors × 4 requests, result counts in every row. All-family repeat medians by cursor — tb 1.54 / aes-reg-instance 23.51 / aes-core 10.42 / spi 14.43 / pinmux 309.60 ms. Pinmux by family: `[]` 82.80, quickfix 84.13, extract 140.42, inline 136.37, ports 137.97, organizeImports 135.45 | **P1b, same phase.** All-family repeat medians by cursor — tb **0.60** / aes-reg-instance **21.79** / aes-core **2.30** / spi **3.16** / pinmux **24.02** ms. Pinmux by family: `[]` **0.053**, quickfix **24.05**, extract **0.107**, inline **0.074**, ports **0.063**, organizeImports **0.060** — every selector family is now under a seventh of a millisecond on a 1.3 MB buffer. The one family that did not move is ports **at an offering cursor** (aes-reg-instance 22.47 → **21.15**), which is P1c's row |
|
||||
| Selector time by family and file size | Filtered ablations preserved in raw data | **Promoted to the committed `offerkinds` phase**: 7 families × 5 cursors × 4 requests, result counts in every row. All-family repeat medians by cursor — tb 1.54 / aes-reg-instance 23.51 / aes-core 10.42 / spi 14.43 / pinmux 309.60 ms. Pinmux by family: `[]` 82.80, quickfix 84.13, extract 140.42, inline 136.37, ports 137.97, organizeImports 135.45 | **P1b, same phase.** All-family repeat medians by cursor — tb **0.60** / aes-reg-instance **21.79** / aes-core **2.30** / spi **3.16** / pinmux **24.02** ms. Pinmux by family: `[]` **0.053**, quickfix **24.05**, extract **0.107**, inline **0.074**, ports **0.063**, organizeImports **0.060** — every selector family is now under a seventh of a millisecond on a 1.3 MB buffer. The one family that did not move is ports **at an offering cursor** (aes-reg-instance 22.47 → **21.15**), which is P1c's row. **P1c, same phase:** aes-reg-instance all families **4.70**, its ports family **3.27** — the last selector family to be measured in whole milliseconds at an offering cursor is now measured in fractions of one, and the 3.27 is dominated by the single parse of the 52 KB declaring file |
|
||||
| Tail rename selected paths / input bytes / selection reasons | Not measured; **2 output files is not input count** | Still not measured (needs P2a's server-side instrumentation). What P0 adds is the **output** side, exactly: 5 edits / 2 files / 0 created, fingerprint `b39defb21265…` | — |
|
||||
| Tail rename watched vs edited paths | Edited 2; watched unmeasured | Edited 2, confirmed by `files`; watched still unmeasured — P2a | — |
|
||||
| Tail rename index / parse / analysis / resolution / verification stage times | Not measured | Not measured — P2a | — |
|
||||
@@ -129,19 +141,19 @@ this stage; each says so rather than being left ambiguous.
|
||||
|
||||
| Gate | Required evidence | Candidate result / log |
|
||||
|---|---|---|
|
||||
| Action parity | Titles/kinds/counts/commands/data or edits/refusals; empty/prefix filters; cursor and selection | **P0: recorded, not yet a comparison.** Every offer row now carries `titles`, the shape of each offer (`edit`/`command`/`data`), `result_count` and the `only` filter it asked with; `offerkinds` walks 7 filters at 5 cursors. This is the reference P1 must match — **P1a/P1b: matched.** Every one of the 60 rows in each stage carries the REF's own `result_count`, and the `codeaction` rows the REF's own `titles`; all 7 filters at all 5 cursors agree. In tests, `vlog_refactor/tests/parsed_selectors.rs` compares old against new at **every byte offset** of five fixtures, and `server/tests/code_action.rs` pins order, prefix filters, the empty filter, a cursor-width extraction and a fix spanning the cursor |
|
||||
| Action parity | Titles/kinds/counts/commands/data or edits/refusals; empty/prefix filters; cursor and selection | **P0: recorded, not yet a comparison.** Every offer row now carries `titles`, the shape of each offer (`edit`/`command`/`data`), `result_count` and the `only` filter it asked with; `offerkinds` walks 7 filters at 5 cursors. This is the reference P1 must match — **P1a/P1b: matched.** Every one of the 60 rows in each stage carries the REF's own `result_count`, and the `codeaction` rows the REF's own `titles`; all 7 filters at all 5 cursors agree. In tests, `vlog_refactor/tests/parsed_selectors.rs` compares old against new at **every byte offset** of five fixtures, and `server/tests/code_action.rs` pins order, prefix filters, the empty filter, a cursor-width extraction and a fix spanning the cursor. **P1c: matched again** — every row of `offerkinds`, `codeaction` and `offerqueue` compared field-by-field against P1b's own record (`result_count`, `titles`, `shapes`, `status`, `fingerprint`, `edits`, `files`, `created`): **50 rows, 0 differences**; against the P0 REF, **65 rows, 0 differences**. In tests, `vlog_refactor/tests/port_offers.rs` compares the offered *menu* against `port_actions`' menu — titles included, in order — at every byte offset of eight fixtures, and `import_offers.rs` compares `organize_offer` against `organize_counts` — counts and refusal sentence — at every byte offset of seven |
|
||||
| Reuse freshness | didChange, unsaved overlays, config/options/tab width/waiver changes, index generation, closed files changed on disk | Not applicable at P0. **P1b: one memo exists, the fence answer, and it is bound to the `Document` that owns the text** — `Workspace::set_document` builds a whole new `Document` on every `didOpen`/`didChange`/text-carrying `didSave`, and `answer_request` flushes pending changes before any handler runs, so there is no revision to compare and no way to hold the wrong one. Pinned by `a_fence_typed_into_the_buffer_is_seen_by_the_next_request` (fix → fence typed in → fix withheld → fence removed → fix back). Configuration is **not** memoized: `an_external_waiver_still_keeps_its_fix_out_of_the_offer` writes a `lucisv.toml` between two requests and the second obeys it. An index rebuild between two requests changes nothing at the cursor (`an_index_refresh_does_not_change_what_the_cursor_offers`). **Lint results are not cached** — see the `P1b-2026-09-07` entry for why and for the number |
|
||||
| Fence parity | All aliases, class/statement fences, malformed source, raw scan backstop, insertions and multi-edit fixes | Not applicable at P0. **P1: `vlog_formatter/src/fence.rs` is untouched and the shared-fence-filter contract is not amended** — the question asked is still `protected_regions(&doc.text)`, byte for byte, so every alias, class/statement fence, malformed-source case and scan backstop is answered by the same code as before. What changed is *when* it is asked (only when a violation carries a fix) and *how often* (once per document revision). `vlog_formatter`'s own suite is green |
|
||||
| Refactor whole-scope parity | Exact edits, warnings, refusal sentences; old/new common names, unresolved and ambiguous uses | **P0 supplies the instrument**: `fingerprint` (sha256 over sorted edits + created paths + warnings) and `edits`/`files`/`created` on every edit-bearing row, plus refusal sentences captured verbatim in `message`. First reference values recorded (tail rename, `aes` rename, extraction) |
|
||||
| Topology handshake 33 | Transitive `wrap.u_S.x` refusal coverage before sharing/narrowing module sources | Not applicable at P0 — no selector shared or narrowed. **Still not applicable at P1**: the four `*_in` selectors take the same decisions over the same tree, and **no source set was narrowed or shared** — `module_sources` / `offer_sources` / `imports::sources` are untouched. Handshake 33 stays P2's prerequisite |
|
||||
| Refactor verification | Token identity, semantic identity, parse-diagnostic preservation, comments/attributes, span remapping | Not applicable at P0 — the engine's verifiers are untouched. **Unchanged at P1**: nothing below the four gates moved; `extract_module`, `inline_module`, `organize_imports`, `port_actions` and `check::verify` are the same code, and `vlog_refactor`'s own suites are green |
|
||||
| Refactor verification | Token identity, semantic identity, parse-diagnostic preservation, comments/attributes, span remapping | Not applicable at P0 — the engine's verifiers are untouched. **Unchanged at P1**: nothing below the four gates moved; `extract_module`, `inline_module`, `organize_imports`, `port_actions` and `check::verify` are the same code, and `vlog_refactor`'s own suites are green. **P1c: still unchanged where it matters.** `check::verify_splice`, `check::verify` and `ports::confirm` are untouched, and every resolve/execute path still runs them — the three resolve rows measured above carry fingerprints byte-identical to the REF's. The *offer* predicates deliberately do not run them; that is the only widening, it is confined to a menu, it was already the lazy offer's stated contract, and the every-offset parity suites find **zero** cursors on their fixtures where it changes the answer |
|
||||
| CLI output | Compare full findings/fixes/waivers/exit codes, not just counts; disabled-rule run stays attribution-only | **Passed.** stdout sha256 of all five configurations byte-identical to the baseline's; exit codes 1 (lint findings) / 2 (four pre-existing format failures) as before; the `--ignore unused-import` run is recorded as attribution only |
|
||||
| Index parity | Fresh/incremental/absorbed fingerprints, unsaved wins, coherent partial publication, scope/filelist/rootless behavior | Not applicable at P0. Store size unchanged at 44.34 MiB and the scan's own `$/progress` end messages recorded per cell (`124 → 3976 files indexed, 3975 from cache, 3 skipped` warm) |
|
||||
| Persistence | Corrupt/truncated/old-format stores rebuild safely; interrupted writes; content hash retained | Not applicable at P0 |
|
||||
| Resources | Guard outcomes, idle and peak memory, allocated/actual store size, stack-size requirement | **Passed.** Every run under `tools/guard.sh -m 8 -t 1800`; **zero kills**; largest resident set 575.6 MiB (7% of the limit). Idle *and* peak RSS now recorded in their own KiB fields; store 44.34 MiB. **P1: zero guard kills** across ten timed runs and every `cargo` gate. Memory not re-measured (P4a's phase); the only new retention is one `Vec<Region>` per open buffer that ever needed a fence answer. No new parsing thread, so the 16 MiB stack contract is untouched |
|
||||
| Formatting | `cargo fmt --all -- --check`, appropriate formatter snapshot/idempotency and corpus gates | Not applicable at P0 — no Rust changed, and no `cargo` command may run during a timed round. `python3 -m py_compile tools/perf/*.py` and `bash -n tools/perf/*.sh` clean. **P1: `cargo fmt --all -- --check` clean; `cargo test -p vlog_formatter` green inside the workspace run** (the formatter is not on this change's path — `fence.rs` is untouched — but it was run anyway). `python3 -m py_compile tools/perf/*.py` clean for the new phase |
|
||||
| Lint/tests | Guarded affected tests then clippy/workspace tests at integration, no benchmark overlap | Not applicable at P0 (no Rust). No benchmark overlapped a build. **P1: `cargo clippy --all-targets` clean at both stages** (one `needless_borrow` introduced by the P1b diff was fixed; **no new `#[allow]`**), `cargo test --workspace` green before each stage's build, all guarded. **No cargo command ran during any timed phase**: each stage built once, to completion, then measured |
|
||||
| Documentation | Feature README, handshake updates in topo, accepted numbers in perf README; reserved lead Review untouched by dev | **Done.** `docs/features/perf5-p0/README.md` created with the required sections (QA and Review left empty); no `topo.md` edge changed because no interface changed; `docs/perf/README.md` carries a note that two take-4 row *meanings* are superseded. **P1: `docs/features/perf5-p1/README.md` created** with all seven sections, QA and Review left empty, the work log kept as the work went. `topo.md` is **not** edited by this lane — the two additive edges (`vlog_parser::stats`, the four `vlog_refactor` `*_in` selectors, the server's `fences` module) are written as requests in that README's Handshakes for the lead to apply. `docs/perf/README.md` untouched until the lead accepts these numbers |
|
||||
| Lint/tests | Guarded affected tests then clippy/workspace tests at integration, no benchmark overlap | Not applicable at P0 (no Rust). No benchmark overlapped a build. **P1: `cargo clippy --all-targets` clean at both stages** (one `needless_borrow` introduced by the P1b diff was fixed; **no new `#[allow]`**), `cargo test --workspace` green before each stage's build, all guarded. **No cargo command ran during any timed phase**: each stage built once, to completion, then measured. **P1c: `cargo fmt --all -- --check` clean, guarded `cargo clippy --all-targets` clean, guarded `cargo test --workspace` **4215 passed / 0 failed** (4194 at P1b, +21), then one guarded release build, then four timed phases with no cargo running; zero guard kills; corpus unchanged after every phase. One new `#[allow(clippy::too_many_arguments)]`, on `imports::planned`, with the reason on the line |
|
||||
| Documentation | Feature README, handshake updates in topo, accepted numbers in perf README; reserved lead Review untouched by dev | **Done.** `docs/features/perf5-p0/README.md` created with the required sections (QA and Review left empty); no `topo.md` edge changed because no interface changed; `docs/perf/README.md` carries a note that two take-4 row *meanings* are superseded. **P1: `docs/features/perf5-p1/README.md` created** with all seven sections, QA and Review left empty, the work log kept as the work went. `topo.md` is **not** edited by this lane — the two additive edges (`vlog_parser::stats`, the four `vlog_refactor` `*_in` selectors, the server's `fences` module) are written as requests in that README's Handshakes for the lead to apply. `docs/perf/README.md` untouched until the lead accepts these numbers. **P1c: the same README gains a P1c section in Goal, Handshakes, Status and Work log**, a dated empty QA heading, and two further handshake requests for the lead — the `port_offers` / `organize_offer` topo edges, and a `vlog_semantic` request to expose a `FileFacts` built from an existing analysis (worth ~0.8 ms of the organize-imports offer). Review still untouched by the dev |
|
||||
|
||||
## Experiment record — P0-2026-09-07 (stage P0)
|
||||
|
||||
@@ -494,6 +506,148 @@ this stage; each says so rather than being left ambiguous.
|
||||
- **QA result and lead review link:** pending —
|
||||
`docs/features/perf5-p1/README.md`.
|
||||
|
||||
## Experiment record — P1c-2026-09-07 (stage P1c)
|
||||
|
||||
- **Experiment ID / stage / date / owner:** `P1c-2026-09-07` / P1c (TODO §60.1,
|
||||
plan §P1c) / 2026-09-07, America/Chicago / dev agent (Opus).
|
||||
- **Hypothesis and exact expected work reduction:** the lazy code-action offer
|
||||
computes four *verified* port refactoring plans and one verified
|
||||
organize-imports edit and discards every edit. Replacing them with engine-owned
|
||||
predicates that ask only the plan-time questions should remove four
|
||||
`WorkspaceIndex::build`s from the ports offer (measured at 3.89 ms each over
|
||||
the two files at the `aes_reg_top` cursor) and one `check::verify_splice` from
|
||||
the imports offer, leaving one parse of the declaring file and one index over
|
||||
the imported packages respectively. Expected: `aes_reg_top` below 10 ms, `aes`
|
||||
below 5 ms, the organize-imports offer below 5 ms, **and every offered title,
|
||||
count and shape identical**.
|
||||
- **Reference commit, candidate commit or diff hash, binary hashes:** reference
|
||||
is §P1b's own record (server `540b8b7e…`) for the `offerkinds`, `codeaction`
|
||||
and `offerqueue` rows, and §P0's REF (server `27e0a0df…`) for the `refactor`
|
||||
rows, which P1a/P1b did not run. Candidate: the P1c working tree over the
|
||||
§P1b tree, built as server sha256
|
||||
`33a6888af3f2bc9b3b2d1fb2844f3d93f9f5950839446866838244f913d56cf1`, CLI
|
||||
`3f7bfd25cdbd16eeb5c16504c9b18181dddc1a26877447688f71b570234108cb`
|
||||
(release, `--locked`), verified before and after the timed run.
|
||||
- **Files changed / API contracts amended / topology references:**
|
||||
`crates/vlog_refactor/src/ports/offer.rs` (**new**, 282 production lines),
|
||||
`ports/{mod,remove,propagate,expand,ansi}.rs` (helpers made `pub(super)` and
|
||||
given parsed-input twins; no behaviour change), `imports.rs` (`planned`
|
||||
extracted from `organize`; `organize_offer`, `organize_offer_in`), `lib.rs`
|
||||
(four new re-exports plus `PortOffer` / `PortOfferKind`);
|
||||
`crates/lucisv_server/src/{ports.rs,imports.rs}` (`offered`, `counts_at`);
|
||||
tests `crates/vlog_refactor/tests/{port_offers,import_offers}.rs` (**new**),
|
||||
`crates/lucisv_server/src/server/tests/code_action.rs`, and one import line in
|
||||
`server/tests/mod.rs`. **No `topo.md` edit** — two additive edges are
|
||||
requested in `docs/features/perf5-p1/README.md`'s Handshakes. **`tools/perf`
|
||||
untouched**: every cell comes from a phase that already existed. No verifier,
|
||||
no `check/`, no `state.rs`, no `fence.rs`.
|
||||
- **Workload, corpus/input hashes, open files, cursor/range, rules, client
|
||||
capabilities:** OpenTitan `0098135264`, the same three pre-existing modified
|
||||
files, `git status --porcelain` identical before and after all four phases.
|
||||
Cursors are `tools/perf/sites.py`'s, resolved from file text at run time.
|
||||
Lazy client (`resolveSupport`) in every offer row, warm workspace scope,
|
||||
scratch `--storage` per label.
|
||||
- **Machine, compiler/profile, threads, load before/after, competing activity:**
|
||||
M1 Max, macOS 27.0 `26A5425a`, release+LTO, default worker count. Load
|
||||
recorded before and after every phase: **3.81–4.90**. The release build was
|
||||
finished and `ps` checked clear of `cargo`/`rustc` before the first phase; the
|
||||
load was allowed to settle below 4.5 before timing began.
|
||||
- **Commands, cache reset/prime steps, trial ordering and fresh-session count:**
|
||||
four guarded `bench.py <phase>` runs — `offerkinds`, `codeaction`, `refactor`,
|
||||
`offerqueue` — each `--tries 3` through `tools/guard.sh -m 8 -t 1800`, with
|
||||
the corpus checked and the load recorded between each. No fresh-process rows
|
||||
in this set; `offerqueue`'s three pipelines are in one session, as always.
|
||||
- **Raw evidence path, explicit units, full sample arrays:**
|
||||
`~/.cache/lucisv-perf/take5-p1c/` — `results-p1c.jsonl` (schema 2, 65 rows),
|
||||
`runs-p1c.txt` (per-phase command, exit, load before/after, corpus check),
|
||||
`logs-p1c/`. Latency is `ms` and nothing else.
|
||||
- **Reference first / repeat median / range; candidate first / repeat median /
|
||||
range:** in the Before/after table above, and in `results-p1c.jsonl`.
|
||||
Headline pairs, repeat medians: `aes_reg_top` lazy **21.83 → 5.46**, its
|
||||
ports family **21.15 → 3.27**, all families **21.79 → 4.70**; `aes` lazy
|
||||
**7.76 → 1.74**; fan-out 42 / 67 / 128 lazy **6.79 → 0.77**, **6.90 → 1.78**,
|
||||
**7.36 → 1.38**; the port-actions offer at `aes_wrap.sv` 78:2 **24.84 (REF) →
|
||||
1.19**; the organize-imports offer at `aes_sbox_canright_masked.sv` 42:2
|
||||
**15.39 (REF) → 4.88**.
|
||||
- **Work counts: reads, parses, analyzed/selected/watched/edited files and
|
||||
bytes:** counted in tests, not on the wire. A **repeated ports offer at an
|
||||
offering cursor performs 1 parse** — the instantiated module's declaring file
|
||||
— where §P1b's own test could only assert "> 0"; a **repeated
|
||||
organize-imports offer performs 3**, one `Scope::build` over the buffer and
|
||||
the two packages it imports; at a cursor the gate refuses, **0**. The source
|
||||
set is unchanged: `offer_sources` and `imports::sources` were not touched, so
|
||||
the offer still reads the buffer plus one or two declaration files.
|
||||
- **Result/status/count/fingerprint comparisons, warnings and refusal checks:**
|
||||
every row of `offerkinds`, `codeaction` and `offerqueue` compared
|
||||
field-by-field with §P1b's record on `result_count`, `titles`, `shapes`,
|
||||
`status`, `fingerprint`, `edits`, `files`, `created` — **50 rows, 0
|
||||
differences**. Every comparable row compared with the §P0 REF — **65 rows, 0
|
||||
differences**. The three edit-bearing resolves carry the REF's own
|
||||
fingerprints byte for byte: connect-missing-ports `4b534a16bca7…`, expand
|
||||
`.*` `8f3a26dd147b…`, organize-imports `0ee027e37d07…`.
|
||||
- **Idle RSS / peak RSS / cache size / guard outcomes:** memory not
|
||||
re-measured (P4a's phase); the only new retention is the predicate's own
|
||||
short-lived parse of one declaring file, dropped when the request ends.
|
||||
**Zero guard kills** across the four timed phases, the release build and all
|
||||
three `cargo` gates.
|
||||
- **Target achieved or missed; paired improvement and variability:** **all
|
||||
three met.** `aes_reg_top` < 10 ms → **5.46**; `aes` < 5 ms → **1.74**; the
|
||||
organize-imports offer < 5 ms → **4.88**. Variability: the three repeats of
|
||||
each headline row sit within ±10% of their median except the
|
||||
connect-missing-ports resolve, whose try 2 (209.85 ms) is an outlier against
|
||||
165.15 / 169.13 — a row §P1c does not touch, whose fingerprint is unchanged.
|
||||
- **Correctness tests and logs:** `crates/vlog_refactor/tests/port_offers.rs`
|
||||
(10 tests) compares the offered menu with `port_actions`' menu — the titles
|
||||
themselves, in order — at **every byte offset** of eight fixtures; a
|
||||
fixture's every-offset run is what proves it rather than a chosen cursor.
|
||||
`import_offers.rs` (9 tests) compares `organize_offer` with
|
||||
`organize_counts` — the counts *and* the refusal sentence — at every byte
|
||||
offset of seven. Both include CRLF, a buffer that does not parse, a
|
||||
duplicate declaration, nested and package-nested modules, positional and
|
||||
`bind` and `.*` shapes, an unknown package and an already-tidy run. **Zero
|
||||
differences.** In the server: the two parse-count assertions above, and
|
||||
`an_offer_the_fan_out_refuses_says_so_on_resolve_rather_than_crashing`, which
|
||||
offers a removal the *fan-out* refuses and gets the engine's sentence
|
||||
("lucisv: the action is no longer available.") from `codeAction/resolve`, not
|
||||
a panic. Gates: `cargo fmt --all -- --check` clean, guarded
|
||||
`cargo clippy --all-targets` clean, guarded `cargo test --workspace`
|
||||
**4215 passed / 0 failed**.
|
||||
- **Interpretation, remaining bottleneck, tradeoffs, rejected alternatives:**
|
||||
the offer's cost was never the refactoring — at the `aes_reg_top` cursor all
|
||||
four planners refuse at *plan* time — it was the four `Scope::build`s they
|
||||
each did before refusing. Removing the index from the ports predicate leaves
|
||||
**one parse of the declaring file**, which is 2.16–2.43 ms of the remaining
|
||||
3.27 at that cursor and is the named residue: a memo per index generation
|
||||
would remove it and was out of this lane's scope. The imports predicate keeps
|
||||
its index because `import_usage` genuinely needs the packages' exports; its
|
||||
residue is the buffer's own share of that index, ~0.8 ms, which needs
|
||||
`vlog_semantic` to expose a `FileFacts` built from an existing analysis (a
|
||||
handshake request, filed). **Rejected alternatives:** (a) sharing one
|
||||
`Scope` across the four planners — simpler, but 3.89 ms floor at
|
||||
`aes_reg_top`, which misses the `aes` target; (b) resolving declarations
|
||||
through the *server's* workspace index — faster still, but it loses the
|
||||
offer on a module declared only in an unsaved buffer, which today's offer
|
||||
makes; (c) skipping the propagation's append loop and counting missing ports
|
||||
instead — one less loop, but the title counts *edits* and a connection
|
||||
written after a `//` comment costs two, so the promised count would have
|
||||
become wrong.
|
||||
- **The one widening, stated plainly:** the predicates do not run
|
||||
`check::verify_splice` or `ports::confirm`, both of which run after the plan.
|
||||
An offer they would have refused is now made and declined on the click. That
|
||||
is the lazy offer's existing contract (`lazy-code-action` README: "the offer
|
||||
may be optimistic; the resolve is exact"), it is confined to a menu, and the
|
||||
every-offset parity suites find **no cursor on their fixtures** where it
|
||||
changes the answer. `resolve` and `execute` still verify everything they
|
||||
always did; **CLAUDE.md invariant 4 is not engaged — the verifier was not
|
||||
widened, and no verification was removed from any path that produces an
|
||||
edit.**
|
||||
- **Decision: retain.** The two open items behind it are the lead's, not this
|
||||
lane's: the lint-result memo (24 ms, the whole of the pinmux row, already
|
||||
deferred to loop 3) and the declaring-file parse memo named above.
|
||||
- **QA result and lead review link:** QA pending;
|
||||
`docs/features/perf5-p1/README.md` QA log, heading
|
||||
"2026-09-07 — QA, P1c".
|
||||
|
||||
## Experiment record — copy for every stage or rejected attempt
|
||||
|
||||
- Experiment ID / stage / date / owner:
|
||||
|
||||
Reference in new issue
Block a user