Share packed box diagnostics across native execution

This commit is contained in:
gloamxun committed 2026-11-28 07:43:44 +08:00
1 parent 526ec9b3b0
commit ca3730338e
13 files changed
+126 -22

No files matched your search

@@ -152,8 +152,16 @@ pub(super) struct Collector {
pub usage: ResourceUsage,
macros: BTreeSet<usize>,
token_lists: BTreeSet<(usize, usize)>,
shared_diagnostic_lists: Option<BTreeSet<usize>>,
}
impl Collector {
pub fn for_capacity() -> Self {
Self {
shared_diagnostic_lists: Some(BTreeSet::new()),
..Self::default()
}
}
pub fn macro_body(&mut self, m: &Arc<Macro>) {
if self.macros.insert(Arc::as_ptr(m) as usize) {
self.usage.unique_macro_bodies += 1;
@@ -187,7 +195,7 @@ impl Collector {
BoxContent::Horizontal(v) => self.text(v, o),
BoxContent::Vertical(v) => self.vertical(v, o),
}
self.diagnostics(&b.diagnostic, o);
self.shared_diagnostics(&b.diagnostic, o);
}
pub fn horizontal_box(&mut self, b: &crate::HorizontalBox, o: Ownership) {
if let Some(b) = &b.native_box {
@@ -298,12 +306,24 @@ impl Collector {
self.text(&b.nodes, Ownership::Active);
self.usage.active_material.ligature_work_items += b.ligature_work_items();
}
pub fn diagnostics(&mut self, nodes: &[super::diagnostics::DiagnosticNode], o: Ownership) {
pub fn shared_diagnostics(
&mut self,
nodes: &Arc<[super::diagnostics::DiagnosticNode]>,
o: Ownership,
) {
if !nodes.is_empty() && self.shared_diagnostic_lists.as_mut()
.is_none_or(|seen| seen.insert(nodes.as_ptr() as usize))
{
self.diagnostics(nodes, o);
}
}
fn diagnostics(&mut self, nodes: &[super::diagnostics::DiagnosticNode], o: Ownership) {
use super::diagnostics::DiagnosticNode as D;
self.material(o).diagnostic_nodes += nodes.len();
for n in nodes {
match n {
D::Box(b) => self.diagnostics(&b.nodes, o),
D::Box(b) => self.shared_diagnostics(&b.nodes, o),
D::Leaders { pattern, .. } => {
self.diagnostics(std::slice::from_ref(pattern.as_ref()), o)
}