Count shared command shards once during suffix verification
This commit is contained in:
1 parent
7981493caf
commit
ccb278fceb
3 files changed
+88
-23
No files matched your search
@@ -276,9 +276,9 @@ impl Executor {
|
||||
}
|
||||
let (history, old_history) =
|
||||
Self::collect_event_usage_pair(&self.events, &old.events, collector());
|
||||
let mut live = collector().tracking_aliases();
|
||||
let mut old_live = collector().tracking_aliases();
|
||||
self.state.collect_compared_statistics(&old.state, &mut live, &mut old_live)?;
|
||||
let (live, old_live) = self.state.collect_compared_statistics(
|
||||
&old.state, collector().tracking_aliases(),
|
||||
)?;
|
||||
let mut live = self.collect_live_usage(None, None, live);
|
||||
let old_live = old.collect_live_usage(None, None, old_live);
|
||||
// The splice translates the cumulative counters separately.
|
||||
|
||||
@@ -1192,6 +1192,50 @@ fn cached_macro_fingerprint_preserves_aliases_mutations_and_uncached_hashes() {
|
||||
assert_eq!(state.fingerprint(), uncached);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paired_statistics_keep_aliases_from_changed_to_shared_command_shards() {
|
||||
use super::statistics::Collector;
|
||||
|
||||
let body = Arc::new(Macro {
|
||||
prefix: Vec::new(),
|
||||
parameters: Vec::new(),
|
||||
parameter_chars: Vec::new(),
|
||||
replacement: Vec::new(),
|
||||
long: false,
|
||||
outer: false,
|
||||
protected: false,
|
||||
});
|
||||
let independent = Arc::new(body.as_ref().clone());
|
||||
let first = CommandName::Control("common-definition".into());
|
||||
let second = CommandName::Control("other-common-definition".into());
|
||||
let shard = |name: &CommandName| CommandBindings::shard_index(command_hasher().hash_one(name));
|
||||
let shared_shards = [shard(&first), shard(&second)];
|
||||
let edited = (0..128)
|
||||
.map(|index| CommandName::Control(format!("edited-alias-{index}")))
|
||||
.find(|name| !shared_shards.contains(&shard(name)))
|
||||
.unwrap();
|
||||
|
||||
let mut prior = State::default();
|
||||
prior.define(first, Meaning::Macro(body.clone()), true);
|
||||
prior.define(second, Meaning::Macro(independent.clone()), true);
|
||||
prior.define(edited.clone(), Meaning::Macro(body), true);
|
||||
let mut current = prior.clone();
|
||||
current.define(edited, Meaning::Macro(independent), true);
|
||||
assert_eq!(current, prior);
|
||||
|
||||
let history = Collector::default();
|
||||
let (new_counts, old_counts) = current
|
||||
.collect_compared_statistics(&prior, Collector::default().tracking_aliases())
|
||||
.unwrap();
|
||||
assert_eq!(new_counts.usage, old_counts.usage);
|
||||
assert!(!new_counts.has_equivalent_history(&old_counts, &history, &history));
|
||||
|
||||
let (same, old_counts) = prior
|
||||
.collect_compared_statistics(&prior, Collector::default().tracking_aliases())
|
||||
.unwrap();
|
||||
assert!(same.has_equivalent_history(&old_counts, &history, &history));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn command_snapshots_share_unmodified_shards_and_keep_ordered_identity() {
|
||||
let mut state = State::initex().with_etex();
|
||||
@@ -1718,31 +1762,42 @@ impl State {
|
||||
pub(super) fn collect_compared_statistics(
|
||||
&self,
|
||||
old: &Self,
|
||||
current_usage: &mut super::statistics::Collector,
|
||||
old_usage: &mut super::statistics::Collector,
|
||||
) -> Option<()> {
|
||||
if !current_usage.material_only() {
|
||||
let entries = old.commands.len();
|
||||
current_usage.usage.state.command_entries = entries;
|
||||
old_usage.usage.state.command_entries = entries;
|
||||
// The alias proof needs corresponding visits, so both sides
|
||||
// walk the donor's binding order. Hashing and serialization
|
||||
// still use the independent, sorted command order.
|
||||
for (current, prior) in self.commands.shards.iter().zip(&old.commands.shards) {
|
||||
mut current_usage: super::statistics::Collector,
|
||||
) -> Option<(super::statistics::Collector, super::statistics::Collector)> {
|
||||
let mut old_usage = if current_usage.material_only() {
|
||||
current_usage.clone()
|
||||
} else {
|
||||
let pairs = self.commands.shards.iter().zip(&old.commands.shards);
|
||||
current_usage.usage.state.command_entries = old.commands.len();
|
||||
for (current, prior) in pairs.clone() {
|
||||
if current.entries.len() != prior.entries.len() {
|
||||
return None;
|
||||
}
|
||||
let shared = Arc::ptr_eq(current, prior);
|
||||
for (name, old_meaning) in &prior.entries {
|
||||
let meaning = if shared { old_meaning } else { current.entries.get(name)? };
|
||||
Self::collect_command_statistics(current_usage, name, meaning);
|
||||
Self::collect_command_statistics(old_usage, name, old_meaning);
|
||||
if Arc::ptr_eq(current, prior) {
|
||||
for (name, meaning) in &prior.entries {
|
||||
Self::collect_command_statistics(&mut current_usage, name, meaning);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
self.collect_state_storage(current_usage);
|
||||
old.collect_state_storage(old_usage);
|
||||
Some(())
|
||||
|
||||
// Both alias walks start with the exact same live allocations.
|
||||
// Copy their ordinals before counting the remaining bindings so
|
||||
// a later alias to a shared macro still has the original ordinal.
|
||||
let mut old_usage = current_usage.clone();
|
||||
for (current, prior) in pairs {
|
||||
if !Arc::ptr_eq(current, prior) {
|
||||
for (name, old_meaning) in &prior.entries {
|
||||
let meaning = current.entries.get(name)?;
|
||||
Self::collect_command_statistics(&mut current_usage, name, meaning);
|
||||
Self::collect_command_statistics(&mut old_usage, name, old_meaning);
|
||||
}
|
||||
}
|
||||
}
|
||||
old_usage
|
||||
};
|
||||
self.collect_state_storage(&mut current_usage);
|
||||
old.collect_state_storage(&mut old_usage);
|
||||
Some((current_usage, old_usage))
|
||||
}
|
||||
|
||||
fn collect_command_statistics(
|
||||
|
||||
Reference in new issue
Block a user