diff --git a/crates/texrra-tex-core/src/execution/engine.rs b/crates/texrra-tex-core/src/execution/engine.rs index 25b5b4e..4b8222c 100644 --- a/crates/texrra-tex-core/src/execution/engine.rs +++ b/crates/texrra-tex-core/src/execution/engine.rs @@ -1113,6 +1113,15 @@ impl Executor { if self.expansion_depth >= scan_stack::limit(self.limits.input_depth) { return self.fail("native expansion nesting limit exceeded"); } + // Literal and frozen tokens cannot recurse. Keep the logical + // depth check above and reserve stack growth for command expansion. + if input.frozen { + return Ok(Some((input, None))); + } + if let TokenKind::Character(character, category) = input.token.kind { + let meaning = Meaning::Character(TokenKind::Character(character, category)); + return Ok(Some((input, Some(meaning)))); + } self.expansion_depth += 1; let result = scan_stack::enter(|| { self.expand_with_pending_tokens(input, files, definition_context) diff --git a/crates/texrra-tex-core/src/execution/engine/continuation.rs b/crates/texrra-tex-core/src/execution/engine/continuation.rs index ea8e784..42344ce 100644 --- a/crates/texrra-tex-core/src/execution/engine/continuation.rs +++ b/crates/texrra-tex-core/src/execution/engine/continuation.rs @@ -440,23 +440,33 @@ impl EntryCheckpoint { let tail = completed.events.get(old.events.len()..)?; let retained_history = if completed.accounts_event_history { measure(timings.as_deref_mut().map(|timings| &mut timings.retained_accounting), || { - if current.events.len() == old.events.len() - && current.equivalent_accounting_history_with_source_resize(old, resize) - { - return Some(None); + let exact_history = || { + (current.events.len() == old.events.len() + && current.equivalent_accounting_history_with_source_resize(old, resize)) + .then_some(None) + }; + let adjusted_history = || { + // Shipout reports also contribute to later diagnostic + // counters. Only translate the final report here. + let has_final_report = matches!(tail.last(), + Some(Event::Statistics(report)) if matches!(report.phase, StatisticsPhase::End { .. }) + ); + if !no_suffix_recount || !has_final_report + || tail[..tail.len() - 1].iter().any(|event| matches!(event, Event::Statistics(_))) + { + return None; + } + let history = current.retained_history_offset(old, resize)?; + Some((!history.is_identity()).then_some(history)) + }; + if source_id != self.entry { + // An exhausted child splice publishes results without + // carrying later checkpoints. Try the final report proof + // first to avoid recounting the same retained allocations. + adjusted_history().or_else(exact_history) + } else { + exact_history().or_else(adjusted_history) } - // Shipout reports also contribute to later diagnostic - // counters. Only translate the final report here. - let has_final_report = matches!(tail.last(), - Some(Event::Statistics(report)) if matches!(report.phase, StatisticsPhase::End { .. }) - ); - if !no_suffix_recount || !has_final_report - || tail[..tail.len() - 1].iter().any(|event| matches!(event, Event::Statistics(_))) - { - return None; - } - let history = current.retained_history_offset(old, resize)?; - Some((!history.is_identity()).then_some(history)) })? } else { None