Maintain command source bounds across checkpoint revisions
This commit is contained in:
1 parent
c8f7a0cbe6
commit
65bf302f5f
3 files changed
+70
-21
No files matched your search
@@ -810,20 +810,20 @@ type CommandEntries = HashMap<Arc<CommandName>, Meaning, RandomState>;
|
||||
#[derive(Clone, Debug)]
|
||||
struct CommandShard {
|
||||
entries: CommandEntries,
|
||||
// Bounds may retain ranges of replaced or removed entries. Their only
|
||||
// use is to prove that every surviving token is before an edit.
|
||||
source_bounds: OnceLock<BTreeMap<usize, Option<usize>>>,
|
||||
// Keep conservative bounds as each meaning is installed. Checkpoints
|
||||
// share the bounds along with the entries, so proving a source move does
|
||||
// not have to discover them from every macro body in each donor.
|
||||
// Replacing or removing an entry may retain its bound.
|
||||
source_bounds: BTreeMap<usize, Option<usize>>,
|
||||
}
|
||||
|
||||
impl CommandShard {
|
||||
fn new(entries: CommandEntries) -> Self {
|
||||
Self { entries, source_bounds: OnceLock::new() }
|
||||
fn new(hasher: RandomState) -> Self {
|
||||
Self { entries: CommandEntries::with_hasher(hasher), source_bounds: BTreeMap::new() }
|
||||
}
|
||||
|
||||
fn insert(&mut self, name: Arc<CommandName>, meaning: Meaning) -> Option<Meaning> {
|
||||
if let Some(bounds) = self.source_bounds.get_mut() {
|
||||
source_relocation::include_meaning_bounds(bounds, &meaning);
|
||||
}
|
||||
source_relocation::include_meaning_bounds(&mut self.source_bounds, &meaning);
|
||||
self.entries.insert(name, meaning)
|
||||
}
|
||||
|
||||
@@ -831,9 +831,7 @@ impl CommandShard {
|
||||
let hashbrown::hash_map::Entry::Vacant(entry) = self.entries.entry(name) else {
|
||||
return false;
|
||||
};
|
||||
if let Some(bounds) = self.source_bounds.get_mut() {
|
||||
source_relocation::include_meaning_bounds(bounds, &meaning);
|
||||
}
|
||||
source_relocation::include_meaning_bounds(&mut self.source_bounds, &meaning);
|
||||
entry.insert(meaning);
|
||||
true
|
||||
}
|
||||
@@ -869,7 +867,7 @@ impl Default for CommandBindings {
|
||||
let hasher = command_hasher();
|
||||
Self {
|
||||
shards: std::array::from_fn(|_| {
|
||||
Arc::new(CommandShard::new(CommandEntries::with_hasher(hasher.clone())))
|
||||
Arc::new(CommandShard::new(hasher.clone()))
|
||||
}),
|
||||
revisions: [0; COMMAND_SHARDS],
|
||||
ordered_names: Arc::default(),
|
||||
|
||||
Reference in new issue
Block a user