Simplify and speed up GDSII diffs
Summarize added and removed cells, group references, and keep replacement pairs together at text display limits. Trim hierarchy labels and summarize long unmatched paths. Stream JSON object evidence and reduce parsing and comparison allocations. Parse large revisions concurrently and adaptively reuse matching cell bodies when most of the layout is shared.
This commit is contained in:
parent
15e8a3b7b5
commit
8efeb04aab
1 changed files with 1137 additions and 261 deletions
|
|
@ -1,6 +1,6 @@
|
|||
use super::*;
|
||||
use pheon::review::{
|
||||
Diagnostic, Outcome, Side,
|
||||
Diagnostic, Outcome, RevisionPair, Side,
|
||||
report::{ReportInputs, ReportOptions, failure_report},
|
||||
selection::{DisplayFilter, Scope},
|
||||
};
|
||||
|
|
@ -27,6 +27,78 @@ fn unknown(geometry: Vec<u8>) -> Vec<u8> {
|
|||
layout(&[("CHIP", vec![object])])
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn adaptive_pair_rebases_diagnostics_and_keeps_metadata_and_graph_state() {
|
||||
let mut stable = vec![square(); 512];
|
||||
stable.extend([
|
||||
reference("leaf", 0, 2),
|
||||
label((900, 7), LAYER_SENTINEL),
|
||||
label((900, 7), "1:0:WG"),
|
||||
label((900, 8), "PHEON_LAYER_NAMES_V2"),
|
||||
]);
|
||||
let mut unsupported = square();
|
||||
unsupported.truncate(unsupported.len() - 4);
|
||||
record(&mut unsupported, 0x7f02, &[0, 42]);
|
||||
record(&mut unsupported, RTAG_ENDEL, &[]);
|
||||
let old = layout(&[
|
||||
("leaf", vec![]),
|
||||
("changed", vec![square()]),
|
||||
("stable", stable.clone()),
|
||||
("unsupported", vec![unsupported.clone()]),
|
||||
]);
|
||||
let mut new = layout(&[
|
||||
("unsupported", vec![unsupported]),
|
||||
("stable", stable),
|
||||
("changed", vec![triangle()]),
|
||||
]);
|
||||
let stable_offset = Document::parse(&new).unwrap().cells["stable"].offset;
|
||||
new[stable_offset + 4..stable_offset + 6].copy_from_slice(&2026_u16.to_be_bytes());
|
||||
|
||||
let full = Comparison::between(
|
||||
&Document::parse(&old).unwrap(),
|
||||
&Document::parse(&new).unwrap(),
|
||||
);
|
||||
let adaptive = RevisionPair::parse(&old, &new).unwrap().compare();
|
||||
let options = ReportOptions {
|
||||
hierarchy: true,
|
||||
..ReportOptions::default()
|
||||
};
|
||||
let actual = adaptive.json_report(&inputs(), &options);
|
||||
assert_eq!(actual, full.json_report(&inputs(), &options));
|
||||
assert_eq!(actual["layer_legend"][0]["name"], "WG");
|
||||
assert_eq!(actual["status"], "incomplete");
|
||||
assert!(
|
||||
actual["diagnostics"]
|
||||
.as_array()
|
||||
.unwrap()
|
||||
.iter()
|
||||
.any(|issue| { issue["code"] == "unresolved_reference" && issue["side"] == "new" })
|
||||
);
|
||||
let text = RevisionPair::parse(&old, &new).unwrap().compare_text();
|
||||
assert_eq!(
|
||||
text.render_text(100, &DisplayFilter::default(), true),
|
||||
full.text(100)
|
||||
);
|
||||
assert_eq!(text.hierarchy(false, 8), full.hierarchy(false, 8));
|
||||
assert_eq!(text.hierarchy(true, 8), full.hierarchy(true, 8));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn adaptive_pair_prioritizes_old_structure_errors_over_new_frame_errors() {
|
||||
let mut old = layout(&[("CHIP", vec![square()])]);
|
||||
let name_offset = Document::parse(&old)
|
||||
.unwrap()
|
||||
.records
|
||||
.iter()
|
||||
.find(|r| r.tag == RTAG_LIBNAME)
|
||||
.unwrap()
|
||||
.offset;
|
||||
old[name_offset + 2] = 0x7f;
|
||||
let error = RevisionPair::parse(&old, b"bad").unwrap_err();
|
||||
assert_eq!(error.side, Some(Side::Old));
|
||||
assert!(error.message.contains("LIBNAME and UNITS"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn comparison_reports_survive_dropped_documents_and_overwritten_inputs() {
|
||||
let comparison = {
|
||||
|
|
@ -75,7 +147,11 @@ fn comparison_reports_survive_dropped_documents_and_overwritten_inputs() {
|
|||
assert_eq!(limited["hierarchy"], actual["hierarchy"]);
|
||||
assert_eq!(limited["summary"], actual["summary"]);
|
||||
assert_eq!(limited["exit_code"], 1);
|
||||
assert!(comparison.text(0).contains("Showing 0 of 2 object changes"));
|
||||
assert!(
|
||||
comparison
|
||||
.text(0)
|
||||
.contains("Omitted · 2 object changes over the limit")
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -323,6 +399,33 @@ fn json_is_unbounded_by_default_and_explicit_filters_do_not_change_totals() {
|
|||
assert_eq!(filtered["cell_changes"][0]["added"], json!([]));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn streamed_report_keeps_object_ids_and_replacements_across_layer_filter_gaps() {
|
||||
let a = layout(&[("CHIP", vec![square(), label((2, 0), "old")])]);
|
||||
let b = layout(&[("CHIP", vec![triangle(), label((2, 0), "new")])]);
|
||||
let diff = Comparison::between(&Document::parse(&a).unwrap(), &Document::parse(&b).unwrap());
|
||||
let options = ReportOptions {
|
||||
filter: DisplayFilter {
|
||||
cell: None,
|
||||
layer: Some((2, 0)),
|
||||
},
|
||||
max_objects: Some(2),
|
||||
..Default::default()
|
||||
};
|
||||
let mut bytes = Vec::new();
|
||||
diff.write_json_report(&mut bytes, &inputs(), &options)
|
||||
.unwrap();
|
||||
let actual: Value = serde_json::from_slice(&bytes).unwrap();
|
||||
assert_eq!(actual, diff.json_report(&inputs(), &options));
|
||||
assert_eq!(actual["report_selection"]["filtered_objects"], "2");
|
||||
let cell = &actual["cell_changes"][0];
|
||||
assert_eq!(cell["added"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(cell["removed"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(cell["replacements"].as_array().unwrap().len(), 1);
|
||||
assert_eq!(cell["replacements"][0]["removed"], "c0:old:1");
|
||||
assert_eq!(cell["replacements"][0]["added"], "c0:new:1");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn typed_evidence_preserves_defaults_properties_bytes_and_real_encodings() {
|
||||
let mut a = reference("leaf", 0, 1);
|
||||
|
|
@ -710,6 +813,22 @@ fn cli_emits_json_for_success_input_errors_scope_errors_and_argument_errors() {
|
|||
let full = command(&["--hierarchy", "graph"]);
|
||||
assert_eq!(full["result"], "different");
|
||||
assert!(full["hierarchy"].is_object());
|
||||
let large = |mut bytes: Vec<u8>| {
|
||||
bytes.resize(3 * 1024 * 1024, 0);
|
||||
bytes
|
||||
};
|
||||
let mut large_old = large(shared(square()));
|
||||
let mut large_new = large(shared(triangle()));
|
||||
fs::write(&a, &large_old).unwrap();
|
||||
fs::write(&b, &large_new).unwrap();
|
||||
assert_eq!(command(&["--hierarchy", "graph"]), full);
|
||||
*large_old.last_mut().unwrap() = 1;
|
||||
*large_new.last_mut().unwrap() = 1;
|
||||
fs::write(&a, &large_old).unwrap();
|
||||
fs::write(&b, &large_new).unwrap();
|
||||
assert_eq!(command(&[])["diagnostics"][0]["side"], "old");
|
||||
fs::write(&a, shared(square())).unwrap();
|
||||
fs::write(&b, shared(triangle())).unwrap();
|
||||
let limited = command(&["--max-changes", "0"]);
|
||||
assert_eq!(limited["summary"], full["summary"]);
|
||||
assert_eq!(limited["report_selection"]["emitted_objects"], "0");
|
||||
|
|
|
|||
Loading…
Reference in a new issue