pub trait RewriteCache<T> {
// Required methods
fn get(&self, subtree: &T, level: usize) -> CacheResult<T>;
fn insert(&mut self, from: &T, to: Option<T>, level: usize);
// Provided methods
fn invalidate_node(&self, _node: &T) { ... }
fn invalidate_subtree(&self, _node: &T) { ... }
fn is_active(&self) -> bool { ... }
fn push_ancestor(&mut self, _node: &T) { ... }
fn pop_ancestor(&mut self) { ... }
fn pop_and_map_ancestor(&mut self, _new_ancestor: &T, _level: usize) { ... }
}Expand description
Caching for Treemorph.
Outward facing API is simple. Given a tree and the rule application level, check the cache before attempting rule checks.
If successful, insert it into the cache. The next time we see the exact same subtree, we can immediately obtain the result without redoing all the hard work of recomputing.
Required Methods§
Sourcefn get(&self, subtree: &T, level: usize) -> CacheResult<T>
fn get(&self, subtree: &T, level: usize) -> CacheResult<T>
Get the cached result
Provided Methods§
Sourcefn invalidate_node(&self, _node: &T)
fn invalidate_node(&self, _node: &T)
Invalidate any internally cached hash for the given node. This is called on ancestors when a subtree is replaced. The default implementation is a no-op for caches that don’t use node-level hash caching.
Sourcefn invalidate_subtree(&self, _node: &T)
fn invalidate_subtree(&self, _node: &T)
Invalidate cached hashes for the given node and all its descendants. Called on replacement subtrees after rule application.
Sourcefn is_active(&self) -> bool
fn is_active(&self) -> bool
Returns false if this cache never stores anything (e.g. NoCache).
The engine uses this to skip clones that would only feed into a no-op insert.
Sourcefn push_ancestor(&mut self, _node: &T)
fn push_ancestor(&mut self, _node: &T)
Record the hash of an ancestor node before descending into a child.
Called by the zipper on every successful go_down.
Sourcefn pop_ancestor(&mut self)
fn pop_ancestor(&mut self)
Discard the top ancestor hash after ascending back to a parent.
Called by the zipper on every go_up during normal traversal.
Sourcefn pop_and_map_ancestor(&mut self, _new_ancestor: &T, _level: usize)
fn pop_and_map_ancestor(&mut self, _new_ancestor: &T, _level: usize)
Pop the top ancestor hash and insert a mapping from the old ancestor
to the new (rebuilt) ancestor at the given level.
Called by mark_dirty_to_root as it walks up after a replacement.
Trait Implementations§
Source§impl<T> RewriteCache<T> for Box<dyn RewriteCache<T>>
impl<T> RewriteCache<T> for Box<dyn RewriteCache<T>>
Source§fn insert(&mut self, from: &T, to: Option<T>, level: usize)
fn insert(&mut self, from: &T, to: Option<T>, level: usize)
Source§fn invalidate_node(&self, node: &T)
fn invalidate_node(&self, node: &T)
Source§fn invalidate_subtree(&self, node: &T)
fn invalidate_subtree(&self, node: &T)
Source§fn is_active(&self) -> bool
fn is_active(&self) -> bool
false if this cache never stores anything (e.g. NoCache).
The engine uses this to skip clones that would only feed into a no-op insert.Source§fn push_ancestor(&mut self, node: &T)
fn push_ancestor(&mut self, node: &T)
go_down.Source§fn pop_ancestor(&mut self)
fn pop_ancestor(&mut self)
go_up during normal traversal.Source§fn pop_and_map_ancestor(&mut self, new_ancestor: &T, level: usize)
fn pop_and_map_ancestor(&mut self, new_ancestor: &T, level: usize)
mark_dirty_to_root as it walks up after a replacement.