Track frequent command tracing reads without hashing

This commit is contained in:
gloamxun committed 2026-12-02 16:51:34 +08:00
1 parent 23b77548d2
commit fd87b6aa42
4 files changed
+38 -10

No files matched your search

@@ -1,5 +1,5 @@
//! Deduplicate execution reads before producing the ordered public evidence.
use super::Dependency;
use super::{Dependency, Parameter};
use std::{
cmp::Ordering,
collections::{BTreeSet, HashMap},
@@ -83,6 +83,7 @@ impl Eq for DependencyEvidence {}
#[derive(Clone)]
pub(super) struct DependencyReads {
pub(super) current_epoch: u32,
tracing_commands: u32,
byte_catcodes: [u32; 256],
other: HashMap<Dependency, u32>,
}
@@ -91,6 +92,7 @@ impl Default for DependencyReads {
fn default() -> Self {
Self {
current_epoch: INITIAL_EPOCH,
tracing_commands: 0,
byte_catcodes: [0; 256],
other: HashMap::new(),
}
@@ -100,6 +102,7 @@ impl Default for DependencyReads {
impl PartialEq for DependencyReads {
fn eq(&self, other: &Self) -> bool {
self.other.len() == other.other.len()
&& (self.tracing_commands == 0) == (other.tracing_commands == 0)
&& self
.byte_catcodes
.iter()
@@ -133,12 +136,17 @@ impl DependencyReads {
}
pub(super) fn insert(&mut self, dependency: Dependency) {
if let Dependency::CatCode(character) = dependency {
self.catcode(character);
} else {
match dependency {
Dependency::CatCode(character) => self.catcode(character),
// The executor checks tracing for every executable token.
Dependency::Parameter(Parameter::Tracingcommands) => {
self.tracing_commands = self.current_epoch;
}
dependency => {
self.other.insert(dependency, self.current_epoch);
}
}
}
pub(super) fn observed_statistics(&self) -> bool {
self.other.contains_key(&Dependency::ResourceStatistics)
@@ -146,6 +154,7 @@ impl DependencyReads {
pub(super) fn is_subset(&self, other: &Self) -> bool {
self.other.len() <= other.other.len()
&& (self.tracing_commands == 0 || other.tracing_commands != 0)
&& self
.byte_catcodes
.iter()
@@ -157,6 +166,9 @@ impl DependencyReads {
/// Extend a completed execution with observations made only in the new prefix.
/// The caller has already checked that the prefix keeps all old observations.
pub(super) fn extend_ordered_delta(&self, prior: &Self, into: &mut BTreeSet<Dependency>) {
if self.tracing_commands != 0 && prior.tracing_commands == 0 {
into.insert(Dependency::Parameter(Parameter::Tracingcommands));
}
for (index, (&seen, &old)) in self
.byte_catcodes
.iter()
@@ -181,9 +193,8 @@ impl DependencyReads {
self.other
.iter()
.map(|(key, &epoch)| (key.clone(), epoch))
.chain(byte_catcode_observations(
self.byte_catcodes.iter().copied(),
))
.chain(byte_catcode_observations(self.byte_catcodes.iter().copied()))
.chain(tracing_command_observation(self.tracing_commands))
}
pub(super) fn into_evidence(
@@ -195,6 +206,7 @@ impl DependencyReads {
.other
.into_iter()
.chain(byte_catcode_observations(self.byte_catcodes.into_iter()))
.chain(tracing_command_observation(self.tracing_commands))
.chain(meanings);
if !has_captures {
return (
@@ -231,6 +243,10 @@ fn byte_catcode_observations(
})
}
fn tracing_command_observation(epoch: u32) -> Option<(Dependency, u32)> {
(epoch != 0).then_some((Dependency::Parameter(Parameter::Tracingcommands), epoch))
}
impl Extend<Dependency> for DependencyReads {
fn extend<T: IntoIterator<Item = Dependency>>(&mut self, dependencies: T) {
for dependency in dependencies {
@@ -248,6 +264,11 @@ mod tests {
let mut prior = DependencyReads::default();
prior.extend([Dependency::CatCode('A'), Dependency::EndLineChar]);
let mut current = prior.clone();
current.insert(Dependency::Parameter(Parameter::Tracingcommands));
assert!(prior.is_subset(&current));
assert!(!current.is_subset(&prior));
assert!(current != prior);
current.extend([
Dependency::CatCode('ÿ'),
Dependency::CatCode('文'),
@@ -271,6 +292,7 @@ mod tests {
reads.extend([
Dependency::CatCode('A'),
Dependency::CatCode('文'),
Dependency::Parameter(Parameter::Tracingcommands),
Dependency::EndLineChar,
Dependency::EscapeChar,
]);
@@ -280,9 +302,14 @@ mod tests {
reads.extend([
Dependency::CatCode('A'),
Dependency::CatCode('文'),
Dependency::Parameter(Parameter::Tracingcommands),
Dependency::EndLineChar,
]);
assert!(reads == original);
assert!(reads.observations().any(|(dependency, epoch)| {
dependency == Dependency::Parameter(Parameter::Tracingcommands)
&& epoch == boundary_epoch + 1
}));
let (ordered, evidence) = reads.into_evidence(std::iter::empty());
let repeated: BTreeSet<_> = ordered
.into_iter()
@@ -294,6 +321,7 @@ mod tests {
BTreeSet::from([
Dependency::CatCode('A'),
Dependency::CatCode('文'),
Dependency::Parameter(Parameter::Tracingcommands),
Dependency::EndLineChar,
])
);
+1 -1
View File
@@ -3237,7 +3237,7 @@ dependencies = [
[[package]]
name = "texrra-desktop"
version = "0.1.6"
version = "0.1.7"
dependencies = [
"serde_json",
"tauri",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "texrra-desktop"
version = "0.1.6"
version = "0.1.7"
edition = "2024"
rust-version = "1.92"
license = "MIT OR Apache-2.0"
+1 -1
View File
@@ -1,7 +1,7 @@
{
"$schema": "https://schema.tauri.app/config/2",
"productName": "Texrra",
"version": "0.1.6",
"version": "0.1.7",
"identifier": "org.texrra.desktop",
"build": {
"frontendDist": "../startup"