Files
lucisv/crates/vlog_refactor/tests/rename_bind.rs
T

720 lines
25 KiB
Rust

//! A `bind` directive's own occurrences of a renamed name (TODO §63.1).
//!
//! `bind aes aes_reseed_if u_x (.entropy_masking_req(entropy_masking_req));`
//! writes the target module's internal net down in a file that instantiates
//! nothing in the chain. IEEE 1800 §23.11 evaluates such a connection in the
//! **target's** scope, so the name is a use of `aes`'s net and a rename must
//! edit it — or say out loud that it could not. Silence is a wrong answer: the
//! design no longer elaborates after the rename.
//!
//! Every test here is one of the shapes §63.1 lists, driven through the public
//! `rename` over a little in-memory workspace: the bare-name connection, the
//! positional one, the two-level hierarchical tail, a `: u_x` instance-list
//! target, a hierarchical target path, a `bind` inside a generate block, and
//! the one the engine must *not* resolve — a target module the workspace does
//! not hold, which is warned about and never edited.
use std::path::{Path, PathBuf};
use vlog_refactor::{rename, rename_traced, rename_traced_with, RefactorEdit, RenameTrace};
/// A workspace of `(file name, text)` pairs, rooted at a fake directory.
fn workspace(files: &[(&str, &str)]) -> Vec<(PathBuf, String)> {
files.iter().map(|(name, text)| (PathBuf::from("/rtl").join(name), text.to_string())).collect()
}
fn path(name: &str) -> PathBuf {
PathBuf::from("/rtl").join(name)
}
/// The offset of the first whole-word `name` at or after `prefix`.
fn at(text: &str, prefix: &str, name: &str) -> u32 {
let from = match prefix.is_empty() {
true => 0,
false => {
text.find(prefix).unwrap_or_else(|| panic!("`{prefix}` is not in the text"))
+ prefix.len()
}
};
let is_word = |b: Option<&u8>| b.is_some_and(|b| b.is_ascii_alphanumeric() || *b == b'_');
let bytes = text.as_bytes();
let mut search = from;
while let Some(hit) = text.get(search..).and_then(|s| s.find(name)) {
let start = search + hit;
let end = start + name.len();
if !is_word(start.checked_sub(1).and_then(|i| bytes.get(i))) && !is_word(bytes.get(end)) {
return start as u32;
}
search = start + 1;
}
panic!("`{name}` does not occur after `{prefix}`");
}
/// Apply a refactoring's edits for one file.
fn apply(text: &str, edit: &RefactorEdit, file: &Path) -> String {
let mut out = String::new();
let mut cursor = 0usize;
for e in edit.edits_for(file) {
out.push_str(&text[cursor..e.range.start as usize]);
out.push_str(&e.new_text);
cursor = e.range.end as usize;
}
out.push_str(&text[cursor..]);
out
}
// ----------------------------------------------------------------------
// the little AES the fixtures bind into
// ----------------------------------------------------------------------
/// The target module: it declares the net every fixture renames, and it
/// instantiates the core the two-level tail walks through.
const AES: &str = "\
module aes (input logic clk_i, output logic idle_o);
logic entropy_masking_req;
aes_core u_aes_core (.clk_i(clk_i));
assign idle_o = entropy_masking_req;
endmodule : aes
";
const AES_CORE: &str = "\
module aes_core (input logic clk_i);
aes_prng_clearing u_aes_prng_clearing (.clk_i(clk_i));
endmodule : aes_core
";
const AES_PRNG: &str = "\
module aes_prng_clearing (input logic clk_i);
logic seed_en;
assign seed_en = clk_i;
endmodule : aes_prng_clearing
";
/// The checker a `bind` binds in. Its ports are deliberately spelled like the
/// names being renamed, so a fixture also proves the `.port` half is left
/// alone: it names *this* module's port, not the target's net.
const RESEED_IF: &str = "\
module aes_reseed_if (input logic entropy_masking_req, input logic seed_en);
endmodule : aes_reseed_if
";
/// The RTL half of every fixture's workspace.
fn rtl(bind_file: &str) -> Vec<(PathBuf, String)> {
workspace(&[
("aes.sv", AES),
("aes_core.sv", AES_CORE),
("aes_prng_clearing.sv", AES_PRNG),
("aes_reseed_if.sv", RESEED_IF),
("aes_bind.sv", bind_file),
])
}
/// Rename `name` (declared in `decl_file`, at the first whole-word occurrence
/// after `prefix`) to `new_name`, and return the bind file's new text together
/// with the rename's warnings.
fn rename_with_bind(
bind_file: &str,
decl_file: &str,
prefix: &str,
name: &str,
new_name: &str,
) -> (String, Vec<String>) {
let files = rtl(bind_file);
let text = files
.iter()
.find(|(p, _)| *p == path(decl_file))
.map(|(_, t)| t.clone())
.expect("the declaring file is in the workspace");
let edit = rename(&files, &path(decl_file), at(&text, prefix, name), new_name)
.unwrap_or_else(|e| panic!("the rename was refused: {e}"));
(apply(bind_file, &edit, &path("aes_bind.sv")), edit.warnings.clone())
}
// ----------------------------------------------------------------------
// the shapes that must be edited
// ----------------------------------------------------------------------
#[test]
fn a_bare_name_in_a_bind_connection_is_renamed() {
let bind = "\
module aes_bind;
bind aes aes_reseed_if u_aes_reseed_if (
.entropy_masking_req(entropy_masking_req)
);
endmodule
";
let (after, warnings) =
rename_with_bind(bind, "aes.sv", "logic", "entropy_masking_req", "masking_req");
assert_eq!(
after,
"\
module aes_bind;
bind aes aes_reseed_if u_aes_reseed_if (
.entropy_masking_req(masking_req)
);
endmodule
",
"the expression half names the target's net; the `.port` half names the checker's port"
);
assert!(warnings.is_empty(), "nothing was left unaccounted for: {warnings:?}");
}
#[test]
fn a_positional_connection_in_a_bind_is_renamed() {
let bind = "\
module aes_bind;
bind aes aes_reseed_if u_aes_reseed_if (entropy_masking_req, 1'b0);
endmodule
";
let (after, _) =
rename_with_bind(bind, "aes.sv", "logic", "entropy_masking_req", "masking_req");
assert_eq!(
after,
"\
module aes_bind;
bind aes aes_reseed_if u_aes_reseed_if (masking_req, 1'b0);
endmodule
"
);
}
#[test]
fn a_two_level_hierarchical_tail_in_a_bind_is_renamed() {
let bind = "\
module aes_bind;
bind aes aes_reseed_if u_aes_reseed_if (
.seed_en(u_aes_core.u_aes_prng_clearing.seed_en)
);
endmodule
";
let (after, warnings) =
rename_with_bind(bind, "aes_prng_clearing.sv", "logic", "seed_en", "reseed_en");
assert_eq!(
after,
"\
module aes_bind;
bind aes aes_reseed_if u_aes_reseed_if (
.seed_en(u_aes_core.u_aes_prng_clearing.reseed_en)
);
endmodule
",
"the tail is rooted at the bind target and walks two instances to the declaration"
);
assert!(warnings.is_empty(), "nothing was left unaccounted for: {warnings:?}");
}
#[test]
fn an_instance_list_target_still_names_the_target_module_scope() {
let bind = "\
module aes_bind;
bind aes : u_aes aes_reseed_if u_aes_reseed_if (
.entropy_masking_req(entropy_masking_req)
);
endmodule
";
let (after, _) =
rename_with_bind(bind, "aes.sv", "logic", "entropy_masking_req", "masking_req");
assert!(
after.contains(".entropy_masking_req(masking_req)"),
"`bind aes : u_aes` still binds into `aes`'s scope: {after}"
);
}
#[test]
fn a_bind_inside_a_generate_block_is_renamed() {
let bind = "\
module aes_bind;
if (1) begin : gen_prng_bind
bind aes aes_reseed_if u_aes_reseed_if (
.entropy_masking_req(entropy_masking_req)
);
end
endmodule
";
let (after, _) =
rename_with_bind(bind, "aes.sv", "logic", "entropy_masking_req", "masking_req");
assert!(
after.contains(".entropy_masking_req(masking_req)"),
"a generate block changes where the directive is written, not what it binds into: {after}"
);
}
#[test]
fn a_hierarchical_target_path_is_followed_through_the_instance_it_names() {
let tb = "\
module tb;
aes u_aes (.clk_i(1'b0), .idle_o());
endmodule : tb
";
let bind = "\
module aes_bind;
bind tb.u_aes aes_reseed_if u_aes_reseed_if (
.entropy_masking_req(entropy_masking_req)
);
endmodule
";
let mut files = rtl(bind);
files.push((path("tb.sv"), tb.to_string()));
let edit =
rename(&files, &path("aes.sv"), at(AES, "logic", "entropy_masking_req"), "masking_req")
.expect("renames");
assert_eq!(
apply(bind, &edit, &path("aes_bind.sv")),
"\
module aes_bind;
bind tb.u_aes aes_reseed_if u_aes_reseed_if (
.entropy_masking_req(masking_req)
);
endmodule
",
"`tb.u_aes` is one instance hop the index can take, so the connection resolves"
);
}
// ----------------------------------------------------------------------
// the shape the engine must not resolve
// ----------------------------------------------------------------------
#[test]
fn a_bind_into_a_module_the_workspace_does_not_hold_is_warned_about_never_edited() {
let bind = "\
module aes_bind;
bind aes_shadow aes_reseed_if u_aes_reseed_if (
.entropy_masking_req(entropy_masking_req)
);
endmodule
";
let (after, warnings) =
rename_with_bind(bind, "aes.sv", "logic", "entropy_masking_req", "masking_req");
assert_eq!(after, bind, "nothing in the bind file was edited");
assert!(
warnings.iter().any(|w| w.contains("aes_bind.sv")
&& w.contains("aes_shadow::entropy_masking_req")
&& w.contains("could not be resolved")),
"the miss is said out loud, with the file and the unit that was searched: {warnings:?}"
);
}
// ----------------------------------------------------------------------
// the edited bind file is an ordinary file to everything downstream
// ----------------------------------------------------------------------
// A regression guard rather than a flipped fixture: the collision is an
// ordinary same-file one (`aes.sv` already declares `masking_req`), so
// `check::verify` refused it before the bind file was understood at all
// (it passes at 2675131 unmodified — QA §63.1, finding 1). What it pins is
// that the refusal survives the bind file joining the edited set.
#[test]
fn a_new_name_the_bind_target_already_declares_is_refused() {
let aes = "\
module aes (input logic clk_i, output logic idle_o);
logic entropy_masking_req;
logic masking_req;
assign idle_o = entropy_masking_req & masking_req;
endmodule : aes
";
let bind = "\
module aes_bind;
bind aes aes_reseed_if u_aes_reseed_if (
.entropy_masking_req(entropy_masking_req)
);
endmodule
";
let files =
workspace(&[("aes.sv", aes), ("aes_reseed_if.sv", RESEED_IF), ("aes_bind.sv", bind)]);
let refusal =
rename(&files, &path("aes.sv"), at(aes, "logic", "entropy_masking_req"), "masking_req")
.expect_err("the new name is already taken in the scope the bind reaches into");
assert!(refusal.contains("masking_req"), "the refusal names the collision: {refusal}");
}
#[test]
fn renaming_a_bind_connection_back_restores_the_file_byte_for_byte() {
let bind = "\
module aes_bind;
bind aes aes_reseed_if u_aes_reseed_if (
.entropy_masking_req(entropy_masking_req),
.seed_en (u_aes_core.u_aes_prng_clearing.seed_en)
);
endmodule
";
let (once, _) = rename_with_bind(bind, "aes.sv", "logic", "entropy_masking_req", "masking_req");
assert_ne!(once, bind, "the first rename moved the bind file");
// The same workspace with both edits applied, renamed back: the engine
// resolves the new spelling exactly as it resolved the old one, so the
// bind file returns to the text it started with.
let aes_after = AES.replace("entropy_masking_req", "masking_req");
let files = workspace(&[
("aes.sv", &aes_after),
("aes_core.sv", AES_CORE),
("aes_prng_clearing.sv", AES_PRNG),
("aes_reseed_if.sv", RESEED_IF),
("aes_bind.sv", &once),
]);
let back = rename(
&files,
&path("aes.sv"),
at(&aes_after, "logic", "masking_req"),
"entropy_masking_req",
)
.expect("renames back");
assert_eq!(apply(&once, &back, &path("aes_bind.sv")), bind);
}
// ----------------------------------------------------------------------
// QA attack fixtures (TODO §63.1, task 3): shapes not in the dev's seven
// plus two, each aimed at a specific way the fix could be half right.
// ----------------------------------------------------------------------
#[test]
fn a_bind_connections_bare_name_naming_the_targets_port_is_still_renamed() {
// `in_bind_target`'s widened surface is `Connection` records first, then
// `Hierarchical`-only ones (`workspace/hierarchy.rs::member`) — so a port
// (which was already reachable through the narrow surface) must still
// resolve exactly as it did before this lane, through the same fallback
// that answers a net. `clk_i` is `aes`'s own port, connected bare in the
// `bind`; the `.port` half names the checker's unrelated port of the same
// name and must stay put.
let bind = "\
module aes_bind;
bind aes aes_reseed_if u_aes_reseed_if (
.entropy_masking_req(clk_i)
);
endmodule
";
let (after, warnings) = rename_with_bind(bind, "aes.sv", "input logic", "clk_i", "clk_ix");
assert_eq!(
after,
"\
module aes_bind;
bind aes aes_reseed_if u_aes_reseed_if (
.entropy_masking_req(clk_ix)
);
endmodule
",
"the expression half names `aes`'s port; the `.port` half is the checker's own, untouched"
);
assert!(warnings.is_empty(), "nothing was left unaccounted for: {warnings:?}");
}
#[test]
fn a_bind_connection_resolves_in_the_target_not_a_same_named_decoy_in_the_writing_scope() {
// The writing module — normally empty — now declares its own
// `entropy_masking_req`, spelling the same name `aes` does. If the
// connection ever fell back to the scope the directive is *written* in
// (finding 2's bug, for a bare name rather than a hierarchical tail),
// this decoy is exactly what it would capture instead of `aes`'s net.
let bind = "\
module aes_bind;
logic entropy_masking_req;
bind aes aes_reseed_if u_aes_reseed_if (
.entropy_masking_req(entropy_masking_req)
);
endmodule
";
let (after, warnings) =
rename_with_bind(bind, "aes.sv", "logic", "entropy_masking_req", "masking_req");
assert_eq!(
after,
"\
module aes_bind;
logic entropy_masking_req;
bind aes aes_reseed_if u_aes_reseed_if (
.entropy_masking_req(masking_req)
);
endmodule
",
"the connection is `aes`'s net, never `aes_bind`'s own decoy of the same name, \
which must still read `entropy_masking_req` after the rename"
);
assert!(warnings.is_empty(), "nothing was left unaccounted for: {warnings:?}");
}
#[test]
fn a_new_name_the_two_level_tails_terminal_scope_already_declares_is_refused() {
// The bare-name path's collision refusal
// (`a_new_name_the_bind_target_already_declares_is_refused`) exercises
// only `in_bind_target`. This is the same shape one link further down the
// spine — the tail rooted at the bind target and walked through
// `bind_member`/`member_at`/`descend` — so a collision at the *end* of a
// two-level tail must refuse exactly as readily, with no gap specific to
// the new code path.
let aes_prng = "\
module aes_prng_clearing (input logic clk_i);
logic seed_en;
logic reseed_en;
assign seed_en = clk_i;
endmodule : aes_prng_clearing
";
let bind = "\
module aes_bind;
bind aes aes_reseed_if u_aes_reseed_if (
.seed_en(u_aes_core.u_aes_prng_clearing.seed_en)
);
endmodule
";
let files = workspace(&[
("aes.sv", AES),
("aes_core.sv", AES_CORE),
("aes_prng_clearing.sv", aes_prng),
("aes_reseed_if.sv", RESEED_IF),
("aes_bind.sv", bind),
]);
let refusal = rename(
&files,
&path("aes_prng_clearing.sv"),
at(aes_prng, "logic", "seed_en"),
"reseed_en",
)
.expect_err("`reseed_en` already exists in the tail's terminal scope");
assert!(refusal.contains("reseed_en"), "the refusal names the collision: {refusal}");
}
#[test]
fn an_escaped_identifier_bind_target_is_still_resolved() {
// `\aes.escaped ` is one identifier (an escaped identifier ends at
// whitespace, IEEE 1800 §5.6.2), spelling a name a plain identifier
// cannot. `bind_target_path` joins `b.target`'s segments verbatim, so
// this is a one-segment path exactly like `bind aes …` — the escaping is
// the parser's problem, not the resolver's.
let aes_escaped = "\
module \\aes.escaped (input logic clk_i, output logic idle_o);
logic entropy_masking_req;
assign idle_o = entropy_masking_req;
endmodule
";
let bind = "\
module aes_bind;
bind \\aes.escaped aes_reseed_if u_aes_reseed_if (
.entropy_masking_req(entropy_masking_req)
);
endmodule
";
let files = workspace(&[
("aes.sv", aes_escaped),
("aes_reseed_if.sv", RESEED_IF),
("aes_bind.sv", bind),
]);
let edit = rename(
&files,
&path("aes.sv"),
at(aes_escaped, "logic", "entropy_masking_req"),
"masking_req",
)
.unwrap_or_else(|e| panic!("the rename was refused: {e}"));
let after = apply(bind, &edit, &path("aes_bind.sv"));
assert_eq!(
after,
"\
module aes_bind;
bind \\aes.escaped aes_reseed_if u_aes_reseed_if (
.entropy_masking_req(masking_req)
);
endmodule
",
"the escaped target's connection still resolves and is edited: {edit:?}"
);
}
#[test]
fn a_bind_with_no_connections_naming_the_renamed_signal_is_untouched() {
// An empty connection list plus a `defparam` — a shape with nothing for
// any connection-surface rung to walk. Nothing here spells the renamed
// name, so the file must come back byte for byte and warn about nothing.
let bind = "\
module aes_bind;
bind aes aes_reseed_if u_aes_reseed_if ();
defparam u_aes_reseed_if.SOME_PARAM = 1;
endmodule
";
let (after, warnings) =
rename_with_bind(bind, "aes.sv", "logic", "entropy_masking_req", "masking_req");
assert_eq!(after, bind, "no connection in this bind file spells the renamed name");
assert!(warnings.is_empty(), "nothing was left unaccounted for: {warnings:?}");
}
#[test]
fn a_bind_target_reached_through_a_generate_block_is_warned_about_never_guessed() {
// `bind tb.gen[0].u_aes …`: the middle hop is a generate block, which the
// index has no record of at all (an indexed segment "keeps only its
// name", per `bind_target_path`'s doc comment) — so the path is one the
// index cannot walk, and the contract is a warning, never a silent miss
// and never a guess at which `u_aes` is meant.
let tb = "\
module tb;
if (1) begin : gen
aes u_aes (.clk_i(1'b0), .idle_o());
end
endmodule : tb
";
let bind = "\
module aes_bind;
bind tb.gen[0].u_aes aes_reseed_if u_aes_reseed_if (
.entropy_masking_req(entropy_masking_req)
);
endmodule
";
let mut files = rtl(bind);
files.push((path("tb.sv"), tb.to_string()));
let edit =
rename(&files, &path("aes.sv"), at(AES, "logic", "entropy_masking_req"), "masking_req")
.expect("the rename over the rest of the design still succeeds");
assert_eq!(
apply(bind, &edit, &path("aes_bind.sv")),
bind,
"a path through a generate block is never guessed at: {edit:?}"
);
assert!(
edit.warnings
.iter()
.any(|w| w.contains("aes_bind.sv") && w.contains("could not be resolved")),
"the miss is said out loud rather than silently dropped: {:?}",
edit.warnings
);
}
// ----------------------------------------------------------------------
// the real tree (TODO §63.1, the three QA renames)
// ----------------------------------------------------------------------
/// §61.5's QA renames, run against a real checkout: `WidthPRDSBox` (a package
/// parameter used bare through `module aes_sbox import aes_pkg::*;`),
/// `entropy_masking_req` (the bare-name `bind` connection this lane is about)
/// and `seed_en` (the two-level tail in the same `bind` file). Each is asked
/// three ways — with no index records, with every record, and with every
/// second one — and the three must answer identically; the two `bind` ones
/// must edit `aes_bind.sv`.
///
/// `#[ignore]`d, and skipped unless `LUCISV_BIND_ROOT` names a tree (it is
/// **read** and never written). Run it with
/// `LUCISV_BIND_ROOT=$HOME/repo/opentitan tools/guard.sh -m 8 -t 1800 -- \
/// cargo test -p vlog_refactor --test rename_bind -- --ignored --nocapture`.
#[test]
#[ignore]
fn the_three_qa_renames_agree_across_reuse_modes_and_edit_the_bind_file() {
let Ok(root) = std::env::var("LUCISV_BIND_ROOT") else {
eprintln!("LUCISV_BIND_ROOT unset — skipping");
return;
};
let root = PathBuf::from(root);
if !root.is_dir() {
eprintln!("{} is not a directory — skipping", root.display());
return;
}
let mut files = Vec::new();
collect(&root, &mut files);
files.sort();
let sources: Vec<(PathBuf, String)> =
files.iter().filter_map(|p| Some((p.clone(), std::fs::read_to_string(p).ok()?))).collect();
assert!(!sources.is_empty(), "the tree holds no Verilog");
println!("{} files read from {}", sources.len(), root.display());
// (file, the text the cursor is placed after, the name, the new name,
// whether `aes_bind.sv` must be among the edited files)
let cases: [(&str, &str, &str, &str, bool); 3] = [
(
"aes_pkg.sv",
"parameter int unsigned WidthPRDSBox",
"WidthPRDSBox",
"WidthPRDSBoxX",
false,
),
("aes.sv", "entropy_clearing_req, ", "entropy_masking_req", "masking_req_x", true),
("aes_prng_clearing.sv", "logic seed_en", "seed_en", "seed_en_x", true),
];
for (file, prefix, name, new_name, bind_edited) in cases {
let Some((path, text)) =
sources.iter().find(|(p, _)| p.file_name().is_some_and(|n| n == file))
else {
eprintln!("{file} not in this tree — skipping that case");
continue;
};
let offset = at(text, prefix, name);
let mut plain = RenameTrace::default();
let none = rename_traced(&sources, path, offset, new_name, &mut plain);
let all = Records::of(&sources, false);
let mut every = RenameTrace::default();
let full = rename_traced_with(&sources, path, offset, new_name, &all, &mut every);
let half = Records::of(&sources, true);
let mut mixed = RenameTrace::default();
let some = rename_traced_with(&sources, path, offset, new_name, &half, &mut mixed);
let shape = |r: &Result<vlog_refactor::RefactorEdit, String>| match r {
Ok(edit) => Ok((edit.edits.clone(), edit.warnings.clone())),
Err(e) => Err(e.clone()),
};
assert_eq!(shape(&none), shape(&full), "{name}: every record changed the answer");
assert_eq!(shape(&none), shape(&some), "{name}: half the records changed the answer");
let edit = none.unwrap_or_else(|e| panic!("{name} was refused: {e}"));
let touched: Vec<String> = edit
.edits
.iter()
.filter_map(|(p, _)| p.file_name().map(|n| n.to_string_lossy().into_owned()))
.collect();
println!(
"{name} -> {new_name}: {} files, {} edits, {} warnings; parses {} / {} / {}",
edit.edits.len(),
edit.edits.iter().map(|(_, e)| e.len()).sum::<usize>(),
edit.warnings.len(),
plain.parses,
every.parses,
mixed.parses
);
for (p, edits) in &edit.edits {
println!(" {} x{}", p.display(), edits.len());
}
for w in &edit.warnings {
println!(" warn: {w}");
}
assert_eq!(
touched.iter().any(|n| n == "aes_bind.sv"),
bind_edited,
"{name}: aes_bind.sv among {touched:?}"
);
}
}
fn collect(dir: &Path, out: &mut Vec<PathBuf>) {
let Ok(entries) = std::fs::read_dir(dir) else { return };
for entry in entries.flatten() {
let path = entry.path();
if path.is_dir() {
collect(&path, out);
} else if matches!(path.extension().and_then(|e| e.to_str()), Some("sv" | "svh")) {
out.push(path);
}
}
}
/// Every source's index record, or every second one — the mixture a real
/// rename gets from a partly warm store.
struct Records {
known: Vec<(PathBuf, String, vlog_semantic::FileFacts)>,
}
impl Records {
fn of(sources: &[(PathBuf, String)], half: bool) -> Records {
let known = sources
.iter()
.enumerate()
.filter(|(i, _)| !half || i % 2 == 0)
.map(|(_, (path, text))| {
(path.clone(), text.clone(), vlog_semantic::FileFacts::of(path.clone(), text))
})
.collect();
Records { known }
}
}
impl vlog_refactor::KnownFacts for Records {
fn facts_for(&self, path: &Path, text: &str) -> Option<vlog_semantic::FileFacts> {
self.known
.iter()
.find(|(held, bytes, _)| held == path && bytes == text)
.map(|(_, _, facts)| facts.clone())
}
}