Make Pheon structural review results self-contained

Capture revision metadata, cell presence and attributes, and structured
diagnostics in owned comparison results. Derive outcomes and render text,
JSON, and hierarchy reports without retaining source documents. Keep derived
descriptions and graph analysis in their renderers.

Use pheon-structural-v1 and PHEON_LAYER_NAMES_V1 consistently, expose helpers
through their defining modules, and remove obsolete re-exports. Update user
guides and report fixtures without changing schema version 1.

Cover dropped inputs, diagnostic ordering, absent and empty cells, offset
independence, and CLI failures. All 92 Rust tests pass in debug and release;
report and hierarchy goldens retain their behavior.
This commit is contained in:
Jan Petykiewicz 2026-11-16 20:45:06 -08:00
commit df62677f5c
6 changed files with 870 additions and 504 deletions

View file

@ -1,11 +1,12 @@
use pheon::review::report::{ReportInputs, ReportOptions, failure_report};
use pheon::review::{
Comparison, DisplayFilter, Document, Scope, dump_records, hierarchy, parse_layer,
parse_layer_name, write_layer_names,
Comparison, Diagnostic, Document, Outcome, Side, dump_records,
names::{parse_layer, parse_layer_name, write_layer_names},
selection::{DisplayFilter, Scope},
};
use std::{
collections::BTreeMap,
ffi::OsString,
ffi::{OsStr, OsString},
fs,
io::{self, Write},
path::PathBuf,
@ -18,7 +19,7 @@ const HELP: &str = "Usage:
pheon hierarchy FILE [--format ascii|mermaid] [--depth N] [--top NAME]\n pheon git-diff [OPTIONS] -- PATH OLD OLD_OID OLD_MODE NEW NEW_OID NEW_MODE
pheon name-layers INPUT OUTPUT --cell NAME --carrier L/T --name L:T:NAME ...
Object profile: ignore timestamps and element order, normalize polygon start/winding,
Structural comparison: ignore timestamps and element order, normalize polygon start/winding,
preserve duplicates, compare all retained fields exactly. No geometric XOR or tolerance.
Exit status: 0 equal/success, 1 different, 2 invalid/unsupported/incomplete.
";
@ -93,40 +94,68 @@ fn json_stdout(report: &serde_json::Value) -> Result<(), String> {
output.write_all(b"\n").map_err(|e| e.to_string())
}
fn prepare_comparison(
old_path: Option<&OsStr>,
new_path: Option<&OsStr>,
scope: &Scope,
) -> Result<Comparison, Diagnostic> {
let read = |path: Option<&OsStr>, side| {
path.map(|path| {
fs::read(path).map_err(|error| {
Diagnostic::new("io_error", format!("{path:?}: {error}"), Some(side))
})
})
.transpose()
};
let old_bytes = read(old_path, Side::Old)?;
let new_bytes = read(new_path, Side::New)?;
let old = old_bytes
.as_deref()
.map(Document::parse)
.transpose()
.map_err(|message| Diagnostic::new("invalid_input", message, Some(Side::Old)))?;
let new = new_bytes
.as_deref()
.map(Document::parse)
.transpose()
.map_err(|message| Diagnostic::new("invalid_input", message, Some(Side::New)))?;
let (old, new) = match (old, new) {
(Some(old), Some(new)) => (old, new),
(None, Some(new)) => (new.empty_like(), new),
(Some(old), None) => {
let new = old.empty_like();
(old, new)
}
(None, None) => {
return Err(Diagnostic::new(
"invalid_input",
"both Git revisions are absent",
None,
));
}
};
scope
.validate_pair(&old, &new)
.map_err(|message| Diagnostic::new("invalid_scope", message, None))?;
let old = old
.selected(scope, true)
.map_err(|message| Diagnostic::new("invalid_scope", message, Some(Side::Old)))?;
let new = new
.selected(scope, true)
.map_err(|message| Diagnostic::new("invalid_scope", message, Some(Side::New)))?;
Ok(Comparison::between(&old, &new))
}
fn json_diff(paths: &[OsString], scope: &Scope, options: &ReportOptions) -> Result<u8, String> {
let inputs = ReportInputs {
old: Some(PathBuf::from(&paths[0])),
new: Some(PathBuf::from(&paths[1])),
};
let comparison = || {
let read = |index, side| {
fs::read(&paths[index])
.map_err(|e| ("io_error", format!("{:?}: {e}", paths[index]), Some(side)))
};
let old_bytes = read(0, "old")?;
let new_bytes = read(1, "new")?;
let old = Document::parse(&old_bytes).map_err(|e| ("invalid_input", e, Some("old")))?;
let new = Document::parse(&new_bytes).map_err(|e| ("invalid_input", e, Some("new")))?;
scope
.validate_pair(&old, &new)
.map_err(|e| ("invalid_scope", e, None))?;
let old = old
.selected(scope, true)
.map_err(|e| ("invalid_scope", e, Some("old")))?;
let new = new
.selected(scope, true)
.map_err(|e| ("invalid_scope", e, Some("new")))?;
let diff = Comparison::between(&old, &new);
Ok::<_, (&str, String, Option<&str>)>((
diff.json_report(&old, &new, &inputs, options),
diff.exit_code(),
))
};
let (report, status) = match comparison() {
Ok(result) => result,
Err((code, message, side)) => (
failure_report(&inputs, scope, options, code, &message, side),
2,
let (report, outcome) = match prepare_comparison(Some(&paths[0]), Some(&paths[1]), scope) {
Ok(diff) => (diff.json_report(&inputs, options), diff.outcome()),
Err(error) => (
failure_report(&inputs, scope, options, &error),
Outcome::Failed,
),
};
if let Err(error) = json_stdout(&report) {
@ -134,7 +163,7 @@ fn json_diff(paths: &[OsString], scope: &Scope, options: &ReportOptions) -> Resu
eprintln!("pheon: {error}");
return Ok(2);
}
Ok(status)
Ok(outcome.exit_code())
}
fn run(args: &[OsString]) -> Result<u8, String> {
@ -252,40 +281,25 @@ fn run(args: &[OsString]) -> Result<u8, String> {
let output = if command == "dump" {
doc.canonical_dump()
} else {
hierarchy(&doc, &doc, None, format == "mermaid", depth)
doc.hierarchy(format == "mermaid", depth)
};
stdout(&output)?;
if command == "hierarchy" {
for issue in &doc.issues {
eprintln!("INCOMPLETE: {issue}");
for diagnostic in &doc.diagnostics {
eprintln!("INCOMPLETE: {}", diagnostic.message);
}
}
return Ok(if doc.issues.is_empty() { 0 } else { 2 });
return Ok(if doc.diagnostics.is_empty() { 0 } else { 2 });
}
let git = command == "git-diff";
let old_missing = git && (paths[3] == "000000" || paths[3] == ".");
let new_missing = git && (paths[6] == "000000" || paths[6] == ".");
if old_missing && new_missing {
return Err("both Git revisions are absent".to_string());
}
let old_bytes = if old_missing {
None
} else {
Some(read(&paths[if git { 1 } else { 0 }])?)
};
let new_bytes = if new_missing {
None
} else {
Some(read(&paths[if git { 4 } else { 1 }])?)
};
let old = old_bytes.as_ref().map(|b| Document::parse(b)).transpose()?;
let new = new_bytes.as_ref().map(|b| Document::parse(b)).transpose()?;
let old = old.unwrap_or_else(|| new.as_ref().unwrap().empty_like());
let new = new.unwrap_or_else(|| old.empty_like());
scope.validate_pair(&old, &new)?;
let old = old.selected(&scope, true)?;
let new = new.selected(&scope, true)?;
let diff = Comparison::between(&old, &new);
let diff = prepare_comparison(
(!old_missing).then_some(paths[if git { 1 } else { 0 }].as_os_str()),
(!new_missing).then_some(paths[if git { 4 } else { 1 }].as_os_str()),
&scope,
)
.map_err(|error| error.message)?;
let mut output = String::new();
if git {
if paths.len() == 9 {
@ -307,13 +321,7 @@ fn run(args: &[OsString]) -> Result<u8, String> {
if format == "mermaid" {
output.push_str("```mermaid\n");
}
output.push_str(&hierarchy(
&old,
&new,
Some(&diff),
format == "mermaid",
depth,
));
output.push_str(&diff.hierarchy(format == "mermaid", depth));
if format == "mermaid" {
output.push_str("```\n");
}
@ -321,10 +329,10 @@ fn run(args: &[OsString]) -> Result<u8, String> {
stdout(&output)?;
// Git's external driver expects successful rendering for either equality
// or differences. Actual comparison/input failures remain nonzero.
Ok(if git && diff.exit_code() == 1 {
Ok(if git && diff.outcome().exit_code() == 1 {
0
} else {
diff.exit_code()
diff.outcome().exit_code()
})
}
@ -363,9 +371,7 @@ fn main() -> ExitCode {
&ReportInputs::default(),
&Scope::default(),
&ReportOptions::default(),
"command_error",
&message,
None,
&Diagnostic::new("command_error", message, None),
);
if let Err(error) = json_stdout(&report) {
eprintln!("pheon: {error}");

View file

@ -5,22 +5,39 @@ use crate::{basic::decode_real8, record::RecordHeader, records::*};
use std::{
borrow::Cow,
collections::{BTreeMap, BTreeSet},
fmt::Write,
fmt::{self, Write},
};
mod names;
pub use names::{parse_layer, parse_layer_name, write_layer_names};
mod selection;
pub use selection::{DisplayFilter, Scope};
mod changes;
pub use changes::Replacement;
pub mod changes;
pub mod names;
pub mod report;
pub mod selection;
/// A comparison limitation with source context independent of its wording.
use changes::Replacement;
use selection::{DisplayFilter, Scope};
/// Input revision associated with a diagnostic.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Side {
Old,
New,
}
impl fmt::Display for Side {
fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result {
out.write_str(match self {
Self::Old => "old",
Self::New => "new",
})
}
}
/// A review error or comparison limitation, with structured source context.
#[derive(Clone, Debug)]
pub struct Diagnostic {
pub code: &'static str,
pub message: String,
pub side: Option<Side>,
pub offset: Option<usize>,
pub cell: Option<String>,
pub layer: Option<Layer>,
@ -28,20 +45,79 @@ pub struct Diagnostic {
}
impl Diagnostic {
fn at(code: &'static str, offset: usize, message: String) -> Self {
pub fn new(code: &'static str, message: impl Into<String>, side: Option<Side>) -> Self {
Self {
code,
message: error(offset, message),
offset: Some(offset),
message: message.into(),
side,
offset: None,
cell: None,
layer: None,
target: None,
}
}
fn at(code: &'static str, offset: usize, message: String) -> Self {
Self {
offset: Some(offset),
..Self::new(code, error(offset, message), None)
}
}
}
pub const PROFILE: &str = "klamath-object-v2";
pub const LAYER_SENTINEL: &str = "KLAMATH_LAYER_NAMES_V1";
impl fmt::Display for Diagnostic {
fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(side) = self.side {
write!(out, "{side}: ")?;
}
out.write_str(&self.message)
}
}
/// The five meaningful combinations of completeness and comparison result.
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum Outcome {
Equal,
Different,
Incomplete { different: bool },
Failed,
}
impl Outcome {
pub fn status(self) -> &'static str {
match self {
Self::Equal | Self::Different => "complete",
Self::Incomplete { .. } => "incomplete",
Self::Failed => "failed",
}
}
pub fn result(self) -> &'static str {
match self {
Self::Equal => "equal",
Self::Different | Self::Incomplete { different: true } => "different",
Self::Incomplete { different: false } | Self::Failed => "unknown",
}
}
pub fn exit_code(self) -> u8 {
match self {
Self::Equal => 0,
Self::Different => 1,
_ => 2,
}
}
pub fn is_equal(self) -> bool {
self == Self::Equal
}
pub fn is_complete(self) -> bool {
matches!(self, Self::Equal | Self::Different)
}
}
pub const PROFILE: &str = "pheon-structural-v1";
pub type Layer = (u16, u16);
pub type Bounds = [i32; 4];
@ -81,16 +157,35 @@ impl Object<'_> {
.find(|(t, _)| *t == tag)
.map(|(_, v)| v.as_ref())
}
}
pub fn description(&self) -> String {
let mut out = kind_name(self.kind).to_string();
for (tag, value) in &self.key.fields {
write!(out, " {}={}", tag_name(*tag), format_data(*tag, value)).unwrap();
}
for (attribute, value) in &self.key.properties {
write!(out, " property[{attribute}]={}", quoted(value)).unwrap();
}
out
fn format_object<'a>(
out: &mut fmt::Formatter<'_>,
kind: u16,
fields: impl IntoIterator<Item = (u16, &'a [u8])>,
properties: impl IntoIterator<Item = (u16, &'a [u8])>,
) -> fmt::Result {
out.write_str(kind_name(kind))?;
for (tag, value) in fields {
write!(out, " {}={}", tag_name(tag), format_data(tag, value))?;
}
for (attribute, value) in properties {
write!(out, " property[{attribute}]={}", quoted(value))?;
}
Ok(())
}
impl fmt::Display for Object<'_> {
fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result {
format_object(
out,
self.kind,
self.key
.fields
.iter()
.map(|(tag, data)| (*tag, data.as_ref())),
self.key.properties.iter().copied(),
)
}
}
@ -110,7 +205,6 @@ pub struct Document<'a> {
pub cells: BTreeMap<String, Cell<'a>>,
pub layer_names: BTreeMap<Layer, String>,
/// Unsupported features or invalid reference graphs prevent an equality claim.
pub issues: Vec<String>,
pub diagnostics: Vec<Diagnostic>,
header: Vec<(u16, &'a [u8])>,
global_issues: Vec<Diagnostic>,
@ -452,7 +546,6 @@ impl<'a> Document<'a> {
records,
cells: BTreeMap::new(),
layer_names: BTreeMap::new(),
issues: Vec::new(),
diagnostics: Vec::new(),
header: Vec::new(),
global_issues: Vec::new(),
@ -594,64 +687,10 @@ impl<'a> Document<'a> {
doc.header.sort();
doc.read_metadata()?;
doc.known_cells = doc.cells.keys().cloned().collect();
doc.refresh_issues();
doc.refresh_diagnostics();
Ok(doc)
}
fn read_metadata(&mut self) -> Result<(), String> {
for (cell_name, cell) in &mut self.cells {
for object in cell.objects.iter().filter(|o| o.kind == RTAG_TEXT) {
let text = object.field(RTAG_STRING).unwrap();
if text.starts_with(b"KLAMATH_LAYER_NAMES_") && text != LAYER_SENTINEL.as_bytes() {
// Layer names apply across the library. An unknown version
// may describe layers used outside this carrier or cell, so
// geometry scope selection cannot establish its relevance.
let mut diagnostic = Diagnostic::at(
"unsupported_metadata_version",
object.offset,
"unsupported layer-name metadata version".to_string(),
);
diagnostic.cell = Some(cell_name.clone());
diagnostic.layer = object.layer;
diagnostic.message = format!("cell {cell_name:?}: {}", diagnostic.message);
self.global_issues.push(diagnostic);
}
}
let carriers: BTreeSet<_> = cell
.objects
.iter()
.filter(|o| {
o.kind == RTAG_TEXT && o.field(RTAG_STRING) == Some(LAYER_SENTINEL.as_bytes())
})
.filter_map(|o| o.layer)
.collect();
for object in &mut cell.objects {
if object.kind != RTAG_TEXT || !object.layer.is_some_and(|l| carriers.contains(&l))
{
continue;
}
let text = decoded_string(object.field(RTAG_STRING).unwrap(), object.offset)?;
if text != LAYER_SENTINEL {
let ((layer, dtype), name) =
parse_layer_name(&text).map_err(|message| error(object.offset, message))?;
if self
.layer_names
.get(&(layer, dtype))
.is_some_and(|old| old != &name)
{
return Err(error(
object.offset,
format!("conflicting names for {layer}/{dtype}"),
));
}
self.layer_names.insert((layer, dtype), name.to_string());
}
object.metadata = true;
}
}
Ok(())
}
fn check_graph(&mut self) {
let mut unresolved = BTreeMap::new();
for (parent, cell) in &self.cells {
@ -666,6 +705,7 @@ impl<'a> Document<'a> {
for ((parent, target), offset) in unresolved {
self.diagnostics.push(Diagnostic {
code: "unresolved_reference",
side: None,
message: format!("cell {parent:?}: unresolved reference {target:?}"),
offset: Some(offset),
cell: Some(parent.clone()),
@ -686,6 +726,7 @@ impl<'a> Document<'a> {
Some(1) => {
self.diagnostics.push(Diagnostic {
code: "hierarchy_cycle",
side: None,
message: format!("cyclic hierarchy involving {name:?}"),
offset: self.cells.get(name).map(|c| c.offset),
cell: Some(name.to_string()),
@ -722,6 +763,11 @@ impl<'a> Document<'a> {
edges
}
pub fn hierarchy(&self, mermaid: bool, max_depth: usize) -> String {
let revision = Revision::from_document(self);
render_hierarchy(&revision, &revision, None, mermaid, max_depth)
}
pub fn canonical_dump(&self) -> String {
let mut out = format!(
"profile {PROFILE}\n{}\ncoordinates: integer database units; bounds: coordinate envelopes\n",
@ -739,11 +785,11 @@ impl<'a> Document<'a> {
writeln!(out, " {}={}", tag_name(*tag), format_data(*tag, data)).unwrap();
}
for object in cell.objects.iter().filter(|o| !o.metadata) {
writeln!(out, " {}", object.description()).unwrap();
writeln!(out, " {object}").unwrap();
}
}
for issue in &self.issues {
writeln!(out, "INCOMPLETE: {issue}").unwrap();
for diagnostic in &self.diagnostics {
writeln!(out, "INCOMPLETE: {}", diagnostic.message).unwrap();
}
out
}
@ -811,11 +857,25 @@ pub struct ObjectChange {
pub origin: Option<[i32; 2]>,
pub width: Option<i32>,
pub counts: Option<[u16; 2]>,
pub description: String,
pub fields: Vec<FieldValue>,
pub properties: Vec<(u16, Vec<u8>)>,
}
impl fmt::Display for ObjectChange {
fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result {
format_object(
out,
self.kind,
self.fields
.iter()
.map(|field| (field.tag, field.data.as_slice())),
self.properties
.iter()
.map(|(attribute, data)| (*attribute, data.as_slice())),
)
}
}
impl From<&Object<'_>> for ObjectChange {
fn from(object: &Object<'_>) -> Self {
Self {
@ -842,7 +902,6 @@ impl From<&Object<'_>> for ObjectChange {
[1, 1]
}
}),
description: object.description(),
fields: owned_fields(
object
.key
@ -860,19 +919,39 @@ impl From<&Object<'_>> for ObjectChange {
}
}
/// An existing cell's source location and retained attributes.
#[derive(Debug)]
pub struct CellRevision {
pub offset: usize,
pub attributes: Vec<FieldValue>,
}
impl From<&Cell<'_>> for CellRevision {
fn from(cell: &Cell<'_>) -> Self {
Self {
offset: cell.offset,
attributes: owned_fields(cell.attributes.iter().copied()),
}
}
}
#[derive(Debug)]
pub struct CellChange {
pub name: String,
pub old_offset: Option<usize>,
pub new_offset: Option<usize>,
pub attributes_changed: bool,
pub old_attributes: Vec<FieldValue>,
pub new_attributes: Vec<FieldValue>,
pub old: Option<CellRevision>,
pub new: Option<CellRevision>,
pub removed: Vec<ObjectChange>,
pub added: Vec<ObjectChange>,
pub replacements: Vec<Replacement>,
}
impl CellChange {
pub fn attributes_changed(&self) -> bool {
self.old.as_ref().map(|cell| &cell.attributes)
!= self.new.as_ref().map(|cell| &cell.attributes)
}
}
#[derive(Debug)]
pub struct LayerNameChange {
pub layer: Layer,
@ -880,59 +959,117 @@ pub struct LayerNameChange {
pub new: Option<String>,
}
/// Library presence or exact record payloads, formatted only when rendered.
#[derive(Debug)]
pub struct LibraryFieldChange {
pub field: String,
pub tag: Option<u16>,
pub old_fields: Vec<FieldValue>,
pub new_fields: Vec<FieldValue>,
pub old: Vec<String>,
pub new: Vec<String>,
pub enum LibraryChange {
Presence {
old: bool,
new: bool,
},
Record {
tag: u16,
old: Vec<Vec<u8>>,
new: Vec<Vec<u8>>,
},
}
impl fmt::Display for LibraryChange {
fn fmt(&self, out: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Presence { old, new } => {
let label = |present| if present { "present" } else { "absent" };
write!(out, "presence: {:?} -> {:?}", [label(*old)], [label(*new)])
}
Self::Record { tag, old, new } => {
write!(out, "{}: ", tag_name(*tag))?;
out.debug_list()
.entries(old.iter().map(|data| format_data(*tag, data)))
.finish()?;
out.write_str(" -> ")?;
out.debug_list()
.entries(new.iter().map(|data| format_data(*tag, data)))
.finish()
}
}
}
}
/// Owned revision metadata and reference counts captured before documents are dropped.
#[derive(Debug)]
pub struct Revision {
pub scope: Scope,
pub present: bool,
pub units: Option<Vec<u8>>,
cells: BTreeSet<String>,
known_cells: BTreeSet<String>,
edges: BTreeMap<(String, String), u64>,
}
impl Revision {
fn from_document(doc: &Document<'_>) -> Self {
Self {
scope: doc.scope.clone(),
present: doc.present,
units: doc
.header
.iter()
.find(|(tag, _)| *tag == RTAG_UNITS && doc.present)
.map(|(_, data)| data.to_vec()),
cells: doc.cells.keys().cloned().collect(),
known_cells: doc.known_cells.clone(),
edges: doc.edges(),
}
}
}
#[derive(Debug)]
pub struct Comparison {
pub scope: Scope,
pub old: Revision,
pub new: Revision,
/// Unchanged names are displayed once when objects on that layer change.
pub layer_legend: BTreeMap<Layer, String>,
pub library_fields: Vec<LibraryFieldChange>,
pub library_changes: Vec<LibraryChange>,
pub layer_names: Vec<LayerNameChange>,
pub cells: Vec<CellChange>,
pub issues: Vec<String>,
pub diagnostics: Vec<Diagnostic>,
}
impl Comparison {
pub fn between(old: &Document<'_>, new: &Document<'_>) -> Self {
let mut result = Self {
scope: old.scope.clone(),
old: Revision::from_document(old),
new: Revision::from_document(new),
layer_legend: old
.layer_names
.iter()
.filter(|(pair, name)| new.layer_names.get(pair) == Some(*name))
.map(|(pair, name)| (*pair, name.clone()))
.collect(),
library_fields: Vec::new(),
library_changes: Vec::new(),
layer_names: Vec::new(),
cells: Vec::new(),
issues: Vec::new(),
diagnostics: Vec::new(),
};
if old.scope != new.scope {
result.issues.push("comparison scopes differ".to_string());
}
if old.present != new.present {
result.library_fields.push(LibraryFieldChange {
field: "presence".to_string(),
tag: None,
old_fields: Vec::new(),
new_fields: Vec::new(),
old: vec![if old.present { "present" } else { "absent" }.to_string()],
new: vec![if new.present { "present" } else { "absent" }.to_string()],
result.library_changes.push(LibraryChange::Presence {
old: old.present,
new: new.present,
});
}
for (side, doc) in [("old", old), ("new", new)] {
for (side, doc) in [(Side::Old, old), (Side::New, new)] {
result
.issues
.extend(doc.issues.iter().map(|i| format!("{side}: {i}")));
.diagnostics
.extend(doc.diagnostics.iter().cloned().map(|mut diagnostic| {
diagnostic.side = Some(side);
diagnostic
}));
}
if old.scope != new.scope {
result.diagnostics.push(Diagnostic::new(
"scope_mismatch",
"comparison scopes differ",
None,
));
}
let header_tags: BTreeSet<_> = old
.header
@ -954,13 +1091,10 @@ impl Comparison {
.map(|(_, value)| *value)
.collect();
if a != b {
result.library_fields.push(LibraryFieldChange {
field: tag_name(tag),
tag: Some(tag),
old_fields: owned_fields(a.iter().map(|data| (tag, *data))),
new_fields: owned_fields(b.iter().map(|data| (tag, *data))),
old: a.iter().map(|data| format_data(tag, data)).collect(),
new: b.iter().map(|data| format_data(tag, data)).collect(),
result.library_changes.push(LibraryChange::Record {
tag,
old: a.into_iter().map(<[u8]>::to_vec).collect(),
new: b.into_iter().map(<[u8]>::to_vec).collect(),
});
}
}
@ -985,15 +1119,8 @@ impl Comparison {
let b = new.cells.get(name);
let mut change = CellChange {
name: name.clone(),
old_offset: a.map(|c| c.offset),
new_offset: b.map(|c| c.offset),
attributes_changed: a.map(|c| &c.attributes) != b.map(|c| &c.attributes),
old_attributes: owned_fields(
a.into_iter().flat_map(|c| c.attributes.iter().copied()),
),
new_attributes: owned_fields(
b.into_iter().flat_map(|c| c.attributes.iter().copied()),
),
old: a.map(CellRevision::from),
new: b.map(CellRevision::from),
removed: Vec::new(),
added: Vec::new(),
replacements: Vec::new(),
@ -1030,11 +1157,7 @@ impl Comparison {
}
}
}
if change.old_offset.is_none()
|| change.new_offset.is_none()
|| change.attributes_changed
|| !change.removed.is_empty()
|| !change.added.is_empty()
if change.attributes_changed() || !change.removed.is_empty() || !change.added.is_empty()
{
change.replacements = changes::replacements(&change.removed, &change.added);
result.cells.push(change);
@ -1043,21 +1166,21 @@ impl Comparison {
result
}
pub fn is_equal(&self) -> bool {
self.issues.is_empty()
&& self.library_fields.is_empty()
&& self.layer_names.is_empty()
&& self.cells.is_empty()
pub fn outcome(&self) -> Outcome {
let different = !self.library_changes.is_empty()
|| !self.layer_names.is_empty()
|| !self.cells.is_empty();
if !self.diagnostics.is_empty() {
Outcome::Incomplete { different }
} else if different {
Outcome::Different
} else {
Outcome::Equal
}
}
pub fn exit_code(&self) -> u8 {
if !self.issues.is_empty() {
2
} else if self.is_equal() {
0
} else {
1
}
pub fn hierarchy(&self, mermaid: bool, max_depth: usize) -> String {
render_hierarchy(&self.old, &self.new, Some(&self.cells), mermaid, max_depth)
}
/// Limit presentation only: the complete comparison has already been made.
@ -1066,19 +1189,22 @@ impl Comparison {
}
pub fn text_filtered(&self, max_objects: usize, show: &DisplayFilter) -> String {
let mut out = format!("profile {PROFILE}\n{}\n", self.scope.description());
let mut out = format!("profile {PROFILE}\n{}\n", self.old.scope.description());
if show.cell.is_some() || show.layer.is_some() {
writeln!(out, "display-only filter cell={:?} layer={:?}; status, totals and hierarchy are unfiltered", show.cell, show.layer).unwrap();
}
for change in &self.library_fields {
writeln!(
out,
"library {}: {:?} -> {:?}",
change.field, change.old, change.new
)
.unwrap();
for change in &self.library_changes {
writeln!(out, "library {change}").unwrap();
}
if self.library_fields.iter().any(|c| c.field == "UNITS") {
if self.library_changes.iter().any(|change| {
matches!(
change,
LibraryChange::Record {
tag: RTAG_UNITS,
..
}
)
}) {
out.push_str("UNITS changed; coordinates remain in each file's database units\n");
}
for change in &self.layer_names {
@ -1116,9 +1242,9 @@ impl Comparison {
out,
"cell {:?} old@{:?} new@{:?}{}",
cell.name,
cell.old_offset,
cell.new_offset,
if cell.attributes_changed {
cell.old.as_ref().map(|revision| revision.offset),
cell.new.as_ref().map(|revision| revision.offset),
if cell.attributes_changed() {
" [cell/header changed]"
} else {
""
@ -1135,19 +1261,9 @@ impl Comparison {
.layer
.is_none_or(|layer| a.layer == Some(layer) && b.layer == Some(layer))
{
writeln!(out, " ~ {}", replacement.explanation).unwrap();
writeln!(
out,
" - @{} bbox={:?} {}",
a.offset, a.bounds, a.description
)
.unwrap();
writeln!(
out,
" + @{} bbox={:?} {}",
b.offset, b.bounds, b.description
)
.unwrap();
writeln!(out, " ~ {}", changes::explain(a, b)).unwrap();
writeln!(out, " - @{} bbox={:?} {}", a.offset, a.bounds, a).unwrap();
writeln!(out, " + @{} bbox={:?} {}", b.offset, b.bounds, b).unwrap();
paired_old.insert(replacement.removed);
paired_new.insert(replacement.added);
shown += 2;
@ -1168,7 +1284,7 @@ impl Comparison {
writeln!(
out,
" {sign} @{} bbox={:?} {}",
object.offset, object.bounds, object.description
object.offset, object.bounds, object
)
.unwrap();
shown += 1;
@ -1183,55 +1299,93 @@ impl Comparison {
self.layer_names.len()
)
.unwrap();
for issue in &self.issues {
writeln!(out, "INCOMPLETE: {issue}").unwrap();
// General comparison errors precede revision-specific errors in text.
for diagnostic in self
.diagnostics
.iter()
.filter(|d| d.side.is_none())
.chain(self.diagnostics.iter().filter(|d| d.side.is_some()))
{
writeln!(out, "INCOMPLETE: {diagnostic}").unwrap();
}
if self.is_equal() {
if self.outcome().is_equal() {
out.push_str("equal under this profile\n");
}
out
}
}
/// Graph facts shared by text, Mermaid, and JSON renderers.
struct HierarchyAnalysis<'a> {
old_edges: &'a BTreeMap<(String, String), u64>,
new_edges: &'a BTreeMap<(String, String), u64>,
edges: BTreeSet<(String, String)>,
direct: BTreeSet<String>,
affected: BTreeSet<String>,
changed_refs: BTreeSet<(String, String)>,
}
impl<'a> HierarchyAnalysis<'a> {
fn between(old: &'a Revision, new: &'a Revision, changes: Option<&[CellChange]>) -> Self {
let old_edges = &old.edges;
let new_edges = &new.edges;
let edges: BTreeSet<_> = old_edges.keys().chain(new_edges.keys()).cloned().collect();
let direct: BTreeSet<_> = changes
.into_iter()
.flatten()
.map(|cell| cell.name.clone())
.collect();
let changed_refs: BTreeSet<_> = changes
.into_iter()
.flatten()
.flat_map(|c| {
c.removed
.iter()
.chain(&c.added)
.filter_map(|o| o.target.as_ref().map(|t| (c.name.clone(), t.clone())))
})
.collect();
let mut parents = BTreeMap::<&str, Vec<&str>>::new();
for (parent, child) in &edges {
parents.entry(child).or_default().push(parent);
}
let mut affected = direct.clone();
let mut pending: Vec<_> = direct.iter().cloned().collect();
while let Some(child) = pending.pop() {
for parent in parents.get(child.as_str()).into_iter().flatten() {
if affected.insert((*parent).to_string()) {
pending.push((*parent).to_string());
}
}
}
Self {
old_edges,
new_edges,
edges,
direct,
affected,
changed_refs,
}
}
}
/// The graph joins both revisions, retaining removed branches and old callers.
pub fn hierarchy(
old: &Document<'_>,
new: &Document<'_>,
diff: Option<&Comparison>,
fn render_hierarchy(
old: &Revision,
new: &Revision,
changes: Option<&[CellChange]>,
mermaid: bool,
max_depth: usize,
) -> String {
let old_edges = old.edges();
let new_edges = new.edges();
let edges: BTreeSet<_> = old_edges.keys().chain(new_edges.keys()).cloned().collect();
let direct: BTreeSet<_> = diff
.into_iter()
.flat_map(|d| d.cells.iter().map(|c| c.name.clone()))
.collect();
let changed_refs: BTreeSet<_> = diff
.into_iter()
.flat_map(|d| &d.cells)
.flat_map(|c| {
c.removed
.iter()
.chain(&c.added)
.filter_map(|o| o.target.as_ref().map(|t| (c.name.clone(), t.clone())))
})
.collect();
let mut parents = BTreeMap::<&str, Vec<&str>>::new();
for (parent, child) in &edges {
parents.entry(child).or_default().push(parent);
}
let mut affected = direct.clone();
let mut pending: Vec<_> = direct.iter().cloned().collect();
while let Some(child) = pending.pop() {
for parent in parents.get(child.as_str()).into_iter().flatten() {
if affected.insert((*parent).to_string()) {
pending.push((*parent).to_string());
}
}
}
let visible: BTreeSet<_> = if diff.is_some() {
let HierarchyAnalysis {
old_edges,
new_edges,
edges,
direct,
affected,
changed_refs,
} = HierarchyAnalysis::between(old, new, changes);
let visible: BTreeSet<_> = if changes.is_some() {
affected
.iter()
.cloned()
@ -1239,8 +1393,8 @@ pub fn hierarchy(
.collect()
} else {
old.cells
.keys()
.chain(new.cells.keys())
.iter()
.chain(new.cells.iter())
.cloned()
.chain(edges.iter().map(|(_, t)| t.clone()))
.collect()
@ -1292,7 +1446,7 @@ pub fn hierarchy(
rows.push((name.clone(), 0, None, false, true));
}
let status = |name: &String| {
if !old.cells.contains_key(name) && !new.cells.contains_key(name) {
if !old.cells.contains(name) && !new.cells.contains(name) {
if old.known_cells.contains(name) || new.known_cells.contains(name) {
" [outside scope]"
} else {
@ -1302,7 +1456,7 @@ pub fn hierarchy(
" [cell changed]"
} else if affected.contains(name) {
" [affected]"
} else if diff.is_some() {
} else if changes.is_some() {
" [cell unchanged]"
} else {
""

View file

@ -1,10 +1,11 @@
//! Unique replacement matches that explain removed and added objects.
use super::*;
#[derive(Debug)]
pub struct Replacement {
pub removed: usize,
pub added: usize,
pub explanation: String,
/// Explanation matching is never object identity or geometric equivalence.
pub match_rule: &'static str,
}
@ -56,7 +57,6 @@ pub(super) fn replacements(old: &[ObjectChange], new: &[ObjectChange]) -> Vec<Re
result.push(Replacement {
removed: i,
added: j,
explanation: explain(&old[i], &new[j]),
match_rule: if old[i].target.is_some() {
"unique_kind_target"
} else if bounds {
@ -74,7 +74,7 @@ pub(super) fn replacements(old: &[ObjectChange], new: &[ObjectChange]) -> Vec<Re
result
}
fn explain(old: &ObjectChange, new: &ObjectChange) -> String {
pub(super) fn explain(old: &ObjectChange, new: &ObjectChange) -> String {
let mut parts = vec![format!(
"{} modified{}",
kind_name(old.kind),

View file

@ -1,5 +1,66 @@
//! Embedded layer names: parsing, recognition, and record-preserving updates.
use super::*;
const LAYER_PREFIX: &[u8] = b"PHEON_LAYER_NAMES_";
pub const LAYER_SENTINEL: &str = "PHEON_LAYER_NAMES_V1";
impl Document<'_> {
pub(super) fn read_metadata(&mut self) -> Result<(), String> {
for (cell_name, cell) in &mut self.cells {
for object in cell.objects.iter().filter(|o| o.kind == RTAG_TEXT) {
let text = object.field(RTAG_STRING).unwrap();
if text.starts_with(LAYER_PREFIX) && text != LAYER_SENTINEL.as_bytes() {
// Layer names apply across the library. An unknown version
// may describe layers used outside this carrier or cell, so
// geometry scope selection cannot establish its relevance.
let mut diagnostic = Diagnostic::at(
"unsupported_metadata_version",
object.offset,
"unsupported layer-name metadata version".to_string(),
);
diagnostic.cell = Some(cell_name.clone());
diagnostic.layer = object.layer;
diagnostic.message = format!("cell {cell_name:?}: {}", diagnostic.message);
self.global_issues.push(diagnostic);
}
}
let carriers: BTreeSet<_> = cell
.objects
.iter()
.filter(|o| {
o.kind == RTAG_TEXT && o.field(RTAG_STRING) == Some(LAYER_SENTINEL.as_bytes())
})
.filter_map(|o| o.layer)
.collect();
for object in &mut cell.objects {
if object.kind != RTAG_TEXT || !object.layer.is_some_and(|l| carriers.contains(&l))
{
continue;
}
let text = decoded_string(object.field(RTAG_STRING).unwrap(), object.offset)?;
if text != LAYER_SENTINEL {
let ((layer, dtype), name) =
parse_layer_name(&text).map_err(|message| error(object.offset, message))?;
if self
.layer_names
.get(&(layer, dtype))
.is_some_and(|old| old != &name)
{
return Err(error(
object.offset,
format!("conflicting names for {layer}/{dtype}"),
));
}
self.layer_names.insert((layer, dtype), name.to_string());
}
object.metadata = true;
}
}
Ok(())
}
}
pub fn parse_layer(value: &str) -> Result<Layer, String> {
let (a, b) = value
.split_once('/')

View file

@ -27,32 +27,37 @@ fn scope(value: &Scope) -> Value {
json!({"top": value.top, "cell": value.cell, "layer": value.layer.map(layer)})
}
fn input(path: Option<&Path>, doc: Option<&Document<'_>>) -> Value {
let units = doc
.filter(|d| d.present)
.and_then(|d| d.header.iter().find(|(tag, _)| *tag == RTAG_UNITS))
.map(|(tag, data)| field(*tag, data));
fn input(path: Option<&Path>, revision: Option<&Revision>) -> Value {
let units = revision
.and_then(|r| r.units.as_deref())
.map(|data| field(RTAG_UNITS, data));
json!({
"path": path.and_then(Path::to_str),
"path_encoded_hex": path.filter(|p| p.to_str().is_none())
.map(|p| hex(p.as_os_str().as_encoded_bytes())),
"present": doc.map(|d| d.present),
"present": revision.map(|r| r.present),
"units": units
})
}
fn envelope(inputs: &ReportInputs, selection: &Scope, options: &ReportOptions) -> Value {
fn envelope(
inputs: &ReportInputs,
selection: &Scope,
options: &ReportOptions,
outcome: Outcome,
revisions: Option<(&Revision, &Revision)>,
) -> Value {
json!({
"schema_version": SCHEMA_VERSION,
"kind": "diff",
"producer": {"name": "pheon", "version": env!("CARGO_PKG_VERSION")},
"comparison_profile": PROFILE,
"inputs": {"old": input(inputs.old.as_deref(), None), "new": input(inputs.new.as_deref(), None)},
"inputs": {"old": input(inputs.old.as_deref(), revisions.map(|r| r.0)), "new": input(inputs.new.as_deref(), revisions.map(|r| r.1))},
"scope": scope(selection),
"coordinates": {"unit": "database_unit", "frame": "cell_local", "bounds": "coordinate_envelope"},
"status": "failed",
"result": "unknown",
"exit_code": 2,
"status": outcome.status(),
"result": outcome.result(),
"exit_code": outcome.exit_code(),
"summary": null,
"report_selection": {
"cell": options.filter.cell,
@ -74,18 +79,22 @@ pub fn failure_report(
inputs: &ReportInputs,
selection: &Scope,
options: &ReportOptions,
code: &str,
message: &str,
side: Option<&str>,
error: &Diagnostic,
) -> Value {
let mut report = envelope(inputs, selection, options);
report["diagnostics"] = json!([{
"code": code, "severity": "error", "message": message,
"side": side, "byte_offset": null, "cell": null, "layer": null, "target": null
}]);
let mut report = envelope(inputs, selection, options, Outcome::Failed, None);
report["diagnostics"] = json!([diagnostic(error)]);
report
}
fn diagnostic(value: &Diagnostic) -> Value {
json!({
"code": value.code, "severity": "error", "message": value.message,
"side": value.side.map(|side| side.to_string()),
"byte_offset": value.offset.map(|offset| offset.to_string()),
"cell": value.cell, "layer": value.layer.map(layer), "target": value.target
})
}
fn field(tag: u16, data: &[u8]) -> Value {
let (encoding, value) = if tag == RTAG_XY && data.len().is_multiple_of(8) {
("xy", json!(points(data)))
@ -195,40 +204,24 @@ fn field_changes(old: &ObjectChange, new: &ObjectChange) -> Vec<Value> {
}
impl Comparison {
/// Render evidence from the same documents used to construct this comparison.
/// Render the captured comparison evidence without retaining its source documents.
/// IDs are local to this report, not persistent object identities.
pub fn json_report(
&self,
old: &Document<'_>,
new: &Document<'_>,
inputs: &ReportInputs,
options: &ReportOptions,
) -> Value {
let mut report = envelope(inputs, &self.scope, options);
report["inputs"] = json!({"old": input(inputs.old.as_deref(), Some(old)), "new": input(inputs.new.as_deref(), Some(new))});
let different = !self.cells.is_empty()
|| !self.library_fields.is_empty()
|| !self.layer_names.is_empty();
report["status"] = json!(if self.issues.is_empty() {
"complete"
} else {
"incomplete"
});
report["result"] = json!(if different {
"different"
} else if self.is_equal() {
"equal"
} else {
"unknown"
});
report["exit_code"] = json!(self.exit_code());
pub fn json_report(&self, inputs: &ReportInputs, options: &ReportOptions) -> Value {
let outcome = self.outcome();
let mut report = envelope(
inputs,
&self.old.scope,
options,
outcome,
Some((&self.old, &self.new)),
);
report["summary"] = json!({
"counts": if self.issues.is_empty() { "exact" } else { "observed" },
"counts": if outcome.is_complete() { "exact" } else { "observed" },
"changed_cells": self.cells.len().to_string(),
"removed_objects": self.cells.iter().map(|c| c.removed.len()).sum::<usize>().to_string(),
"added_objects": self.cells.iter().map(|c| c.added.len()).sum::<usize>().to_string(),
"layer_name_changes": self.layer_names.len().to_string(),
"library_field_changes": self.library_fields.len().to_string()
"library_field_changes": self.library_changes.len().to_string()
});
report["layer_legend"] = json!(
self.layer_legend
@ -244,11 +237,17 @@ impl Comparison {
}))
.collect::<Vec<_>>()
);
report["library_changes"] = json!(self.library_fields.iter().map(|c| {
if c.tag.is_none() {
json!({"field": "presence", "tag": null, "before": old.present, "after": new.present})
} else {
json!({"field": c.field, "tag": c.tag, "before": fields(&c.old_fields), "after": fields(&c.new_fields)})
report["library_changes"] = json!(self.library_changes.iter().map(|change| {
match change {
LibraryChange::Presence { old, new } => {
json!({"field": "presence", "tag": null, "before": old, "after": new})
}
LibraryChange::Record { tag, old, new } => {
let values = |data: &[Vec<u8>]| {
data.iter().map(|bytes| field(*tag, bytes)).collect::<Vec<_>>()
};
json!({"field": tag_name(*tag), "tag": tag, "before": values(old), "after": values(new)})
}
}
}).collect::<Vec<_>>());
let (mut emitted, mut filtered_objects, mut limited, mut filtered_cells) =
@ -293,16 +292,16 @@ impl Comparison {
let b = format!("c{cell_index}:new:{}", r.added);
(shown.contains(&a) && shown.contains(&b)).then(|| json!({
"removed": a, "added": b, "match_rule": r.match_rule,
"explanation": r.explanation,
"explanation": changes::explain(&cell.removed[r.removed], &cell.added[r.added]),
"field_changes": field_changes(&cell.removed[r.removed], &cell.added[r.added]),
"properties_changed": cell.removed[r.removed].properties != cell.added[r.added].properties
}))
}).collect();
cells.push(json!({
"name": cell.name,
"before": cell.old_offset.map(|offset| json!({"byte_offset": offset.to_string(), "attributes": fields(&cell.old_attributes)})),
"after": cell.new_offset.map(|offset| json!({"byte_offset": offset.to_string(), "attributes": fields(&cell.new_attributes)})),
"attributes_changed": cell.attributes_changed,
"before": cell.old.as_ref().map(|revision| json!({"byte_offset": revision.offset.to_string(), "attributes": fields(&revision.attributes)})),
"after": cell.new.as_ref().map(|revision| json!({"byte_offset": revision.offset.to_string(), "attributes": fields(&revision.attributes)})),
"attributes_changed": cell.attributes_changed(),
"removed": removed, "added": added, "replacements": replacements
}));
}
@ -317,37 +316,29 @@ impl Comparison {
] {
report["report_selection"][key] = json!(count.to_string());
}
let mut diagnostics: Vec<_> = [("old", old), ("new", new)]
.into_iter()
.flat_map(|(side, doc)| {
doc.diagnostics.iter().map(move |d| {
json!({
"code": d.code, "severity": "error", "message": d.message, "side": side,
"byte_offset": d.offset.map(|n| n.to_string()), "cell": d.cell,
"layer": d.layer.map(layer), "target": d.target
})
})
})
.collect();
if old.scope != new.scope {
diagnostics.push(json!({"code": "scope_mismatch", "severity": "error", "message": "comparison scopes differ", "side": null, "byte_offset": null, "cell": null, "layer": null, "target": null}));
}
report["diagnostics"] = json!(diagnostics);
report["diagnostics"] = json!(self.diagnostics.iter().map(diagnostic).collect::<Vec<_>>());
if options.hierarchy {
report["hierarchy"] = graph(old, new, self);
report["hierarchy"] = graph(self);
}
report
}
}
fn graph(old: &Document<'_>, new: &Document<'_>, diff: &Comparison) -> Value {
let a = old.edges();
let b = new.edges();
let edges: BTreeSet<_> = a.keys().chain(b.keys()).cloned().collect();
fn graph(diff: &Comparison) -> Value {
let old = &diff.old;
let new = &diff.new;
let HierarchyAnalysis {
old_edges,
new_edges,
edges,
direct,
affected,
changed_refs,
} = HierarchyAnalysis::between(old, new, Some(&diff.cells));
let names: BTreeSet<_> = old
.cells
.keys()
.chain(new.cells.keys())
.iter()
.chain(new.cells.iter())
.cloned()
.chain(
edges
@ -355,34 +346,10 @@ fn graph(old: &Document<'_>, new: &Document<'_>, diff: &Comparison) -> Value {
.flat_map(|(parent, child)| [parent.clone(), child.clone()]),
)
.collect();
let direct: BTreeSet<_> = diff.cells.iter().map(|c| c.name.clone()).collect();
let mut affected = direct.clone();
let mut parents = BTreeMap::<&str, Vec<&str>>::new();
for (parent, child) in &edges {
parents.entry(child).or_default().push(parent);
}
let mut pending: Vec<_> = direct.iter().cloned().collect();
while let Some(child) = pending.pop() {
for parent in parents.get(child.as_str()).into_iter().flatten() {
if affected.insert((*parent).to_string()) {
pending.push((*parent).to_string());
}
}
}
let changed_refs: BTreeSet<_> = diff
.cells
.iter()
.flat_map(|c| {
c.removed
.iter()
.chain(&c.added)
.filter_map(|o| o.target.as_ref().map(|t| (c.name.clone(), t.clone())))
})
.collect();
let a_targets: BTreeSet<_> = a.keys().map(|(_, t)| t.as_str()).collect();
let b_targets: BTreeSet<_> = b.keys().map(|(_, t)| t.as_str()).collect();
let state = |doc: &Document<'_>, targets: &BTreeSet<&str>, name: &String| {
if doc.cells.contains_key(name) {
let old_targets: BTreeSet<_> = old_edges.keys().map(|(_, t)| t.as_str()).collect();
let new_targets: BTreeSet<_> = new_edges.keys().map(|(_, t)| t.as_str()).collect();
let state = |doc: &Revision, targets: &BTreeSet<&str>, name: &String| {
if doc.cells.contains(name) {
"included"
} else if doc.known_cells.contains(name) {
"outside_scope"
@ -394,13 +361,13 @@ fn graph(old: &Document<'_>, new: &Document<'_>, diff: &Comparison) -> Value {
};
json!({
"nodes": names.iter().map(|name| json!({
"cell": name, "before": state(old, &a_targets, name), "after": state(new, &b_targets, name),
"cell": name, "before": state(old, &old_targets, name), "after": state(new, &new_targets, name),
"change": if direct.contains(name) { "direct" } else if affected.contains(name) { "affected" } else { "unchanged" }
})).collect::<Vec<_>>(),
"edges": edges.iter().map(|edge| json!({
"parent": edge.0, "target": edge.1,
"before_count": a.get(edge).copied().unwrap_or(0).to_string(),
"after_count": b.get(edge).copied().unwrap_or(0).to_string(),
"before_count": old_edges.get(edge).copied().unwrap_or(0).to_string(),
"after_count": new_edges.get(edge).copied().unwrap_or(0).to_string(),
"reference_changed": changed_refs.contains(edge)
})).collect::<Vec<_>>()
})

View file

@ -1,3 +1,5 @@
//! Comparison scope and display-only filters.
use super::*;
#[derive(Clone, Debug, Default, Eq, PartialEq)]
@ -64,7 +66,6 @@ impl<'a> Document<'a> {
records: Vec::new(),
cells: BTreeMap::new(),
layer_names: BTreeMap::new(),
issues: Vec::new(),
diagnostics: Vec::new(),
header: self.header.clone(),
global_issues: Vec::new(),
@ -86,7 +87,7 @@ impl<'a> Document<'a> {
found
}
pub(super) fn refresh_issues(&mut self) {
pub(super) fn refresh_diagnostics(&mut self) {
self.diagnostics = self.global_issues.clone();
for (name, cell) in &self.cells {
for issue in &cell.issues {
@ -106,7 +107,6 @@ impl<'a> Document<'a> {
}
}
self.check_graph();
self.issues = self.diagnostics.iter().map(|d| d.message.clone()).collect();
}
/// Project a parsed document. Missing selectors are allowed only for one
@ -227,7 +227,7 @@ impl<'a> Document<'a> {
self.layer_names.retain(|pair, _| layers.contains(pair));
}
self.scope = scope.clone();
self.refresh_issues();
self.refresh_diagnostics();
Ok(self)
}
}