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