Reduce macro copying during native suffix convergence

This commit is contained in:
gloamxun committed 2026-12-01 22:50:53 +08:00
1 parent 57c05d9635
commit c008c52964
9 files changed
+228 -110

No files matched your search

@@ -1,4 +1,6 @@
use super::super::source_relocation::SourceRelocation;
use super::super::{
source_relocation::SourceRelocation, source_relocation_events::EventRelocation,
};
use super::*;
mod material;
mod relocate;
@@ -171,7 +173,10 @@ impl EntryCheckpoint {
None if self.frontier == prior.frontier => None,
None => return None,
};
if !same_kernel_continuation(current, old, relocation.as_ref()) {
// Comparison and publication visit some of the same original
// allocations. Keep the checked relocations for this donor only.
let mut moved = relocation.as_ref().map(EventRelocation::new);
if !same_kernel_continuation(current, old, moved.as_mut()) {
return None;
}
let offset = StepOffset::new(old.steps, current.steps);
@@ -214,8 +219,11 @@ impl EntryCheckpoint {
reads_event_history: false,
accounts_event_history: completed.accounts_event_history,
};
if let Some((map, sizes)) = relocation.as_ref().zip(entry_sizes) {
relocate::append_suffix(&mut execution, tail, offset, map, sizes, old.sources.len())?;
if let Some((moved, sizes)) = moved.as_mut().zip(entry_sizes) {
relocate::append_suffix(&mut execution, tail, offset, moved, sizes, old.sources.len())?;
if execution.state != completed.state {
execution.outgoing_state = execution.state.fingerprint();
}
} else if offset.is_identity() {
execution.events.extend_from_slice(tail);
} else {
@@ -378,7 +386,7 @@ fn is_idle_continuation(e: &Executor) -> bool {
fn same_kernel_continuation(
current: &Executor,
prior: &Executor,
relocation: Option<&SourceRelocation>,
relocation: Option<&mut EventRelocation<'_>>,
) -> bool {
// Every field belongs to one of these checks. Adding kernel state requires
// an explicit decision here before a later execution may be skipped.
@@ -489,9 +497,10 @@ fn same_kernel_continuation(
{
return false;
}
let map = relocation.as_ref().map(|context| context.map());
let relocated;
let prior = if let Some(map) = relocation {
relocated = match relocate::kernel_continuation(prior, map) {
let prior = if let Some(context) = relocation {
relocated = match relocate::kernel_continuation(prior, context) {
Some(executor) => executor,
None => return false,
};
@@ -522,5 +531,5 @@ fn same_kernel_continuation(
.inputs
.iter()
.zip(&prior.inputs)
.all(|(a, b)| a.same_at_shipout(b, relocation))
.all(|(a, b)| a.same_at_shipout(b, map))
}
@@ -1,26 +1,26 @@
use super::*;
use crate::execution::{
source_relocation_events::EventRelocation, state::source_relocation::relocate_macro,
};
use crate::execution::source_relocation_events::EventRelocation;
pub(super) fn kernel_continuation(prior: &Executor, map: &SourceRelocation) -> Option<Executor> {
pub(super) fn kernel_continuation(
prior: &Executor,
relocation: &mut EventRelocation<'_>,
) -> Option<Executor> {
let mut prior = prior.clone();
let mut relocation = EventRelocation::new(map);
let map = relocation.map();
prior.current = map.relocate_span(prior.current)?;
prior.state = prior.state.relocate_source(&mut relocation)?;
prior.state.relocate_source(relocation)?;
relocate_generated(&mut prior.generated_inputs, map)?;
for conditional in &mut prior.conditionals {
conditional.span = map.relocate_span(conditional.span)?;
}
let mut macros = std::collections::HashMap::new();
for frame in &mut prior.inputs {
match frame {
InputFrame::Tokens { tokens, .. } => match tokens {
InputTokens::One(token) => token.token = relocation.relocate_token(&token.token)?,
InputTokens::One(token) => relocation.relocate_token(&mut token.token)?,
InputTokens::Many(tokens) => {
for token in tokens {
token.token = relocation.relocate_token(&token.token)?;
relocation.relocate_token(&mut token.token)?;
}
}
},
@@ -30,7 +30,7 @@ pub(super) fn kernel_continuation(prior: &Executor, map: &SourceRelocation) -> O
call,
..
} => {
*definition = relocate_macro(definition, &mut relocation, &mut macros)?;
*definition = relocation.relocate_macro(definition)?;
for tokens in arguments {
*tokens = relocation.relocate_tokens(tokens)?;
}
@@ -45,17 +45,17 @@ pub(super) fn kernel_continuation(prior: &Executor, map: &SourceRelocation) -> O
InputFrame::Source { .. } | InputFrame::Boundary => {}
}
}
relocate_tokens(&mut prior.pdf_catalog_tokens, &mut relocation)?;
relocate_tokens(&mut prior.pdf_info_tokens, &mut relocation)?;
relocate_tokens(&mut prior.pdf_catalog_tokens, relocation)?;
relocate_tokens(&mut prior.pdf_info_tokens, relocation)?;
for outline in &mut prior.pdf_outlines {
relocate_tokens(&mut outline.attributes, &mut relocation)?;
relocate_tokens(&mut outline.attributes, relocation)?;
}
if let Some(token) = &mut prior.after_assignment {
*token = relocation.relocate_token(token)?;
relocation.relocate_token(token)?;
}
relocate_vertical(&mut prior.vertical.nodes, &mut relocation)?;
relocate_vertical(&mut prior.split_discards, &mut relocation)?;
relocate_page(&mut prior.native_page, &mut relocation)?;
relocate_vertical(&mut prior.vertical.nodes, relocation)?;
relocate_vertical(&mut prior.split_discards, relocation)?;
relocate_page(&mut prior.native_page, relocation)?;
for value in &mut prior.pending_shipouts {
*value = relocation.relocate_box(value)?;
}
@@ -66,11 +66,11 @@ pub(super) fn append_suffix(
execution: &mut Execution,
tail: &[Event],
offset: StepOffset,
map: &SourceRelocation,
relocation: &mut EventRelocation<'_>,
(previous_bytes, current_bytes): (usize, usize),
source_count: usize,
) -> Option<()> {
let mut relocation = EventRelocation::new(map);
let map = relocation.map();
for event in tail {
if let Event::Statistics(report) = event {
if let StatisticsPhase::Shipout { before, after } = &report.phase {
@@ -90,19 +90,15 @@ pub(super) fn append_suffix(
execution.events.push(relocation.relocate_event(event)?);
}
}
let state = execution.state.relocate_source(&mut relocation)?;
if state != execution.state {
execution.outgoing_state = state.fingerprint();
}
execution.state = state;
relocate_page(&mut execution.native_page, &mut relocation)?;
relocate_vertical(&mut execution.split_discards, &mut relocation)?;
execution.state.relocate_source(relocation)?;
relocate_page(&mut execution.native_page, relocation)?;
relocate_vertical(&mut execution.split_discards, relocation)?;
if let Some(token) = &mut execution.after_assignment {
*token = relocation.relocate_token(token)?;
relocation.relocate_token(token)?;
}
relocate_generated(&mut execution.generated_inputs, map)?;
for image in &mut execution.format_pdf_images {
relocate_tokens(&mut image.attributes, &mut relocation)?;
relocate_tokens(&mut image.attributes, relocation)?;
}
Some(())
}
@@ -132,7 +128,7 @@ fn relocate_page(
fn relocate_tokens(tokens: &mut [Token], relocation: &mut EventRelocation<'_>) -> Option<()> {
for token in tokens {
*token = relocation.relocate_token(token)?;
relocation.relocate_token(token)?;
}
Some(())
}