Skip to main content

RewriteCache

Trait RewriteCache 

Source
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§

Source

fn get(&self, subtree: &T, level: usize) -> CacheResult<T>

Get the cached result

Source

fn insert(&mut self, from: &T, to: Option<T>, level: usize)

Insert the results into the cache. Note: Any powerful side effects such as changing other parts of the tree or replacing the root should NOT be inserted into the cache.

Provided Methods§

Source

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.

Source

fn invalidate_subtree(&self, _node: &T)

Invalidate cached hashes for the given node and all its descendants. Called on replacement subtrees after rule application.

Source

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.

Source

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.

Source

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.

Source

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>>

Source§

fn get(&self, subtree: &T, level: usize) -> CacheResult<T>

Get the cached result
Source§

fn insert(&mut self, from: &T, to: Option<T>, level: usize)

Insert the results into the cache. Note: Any powerful side effects such as changing other parts of the tree or replacing the root should NOT be inserted into the cache.
Source§

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.
Source§

fn invalidate_subtree(&self, node: &T)

Invalidate cached hashes for the given node and all its descendants. Called on replacement subtrees after rule application.
Source§

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.
Source§

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.
Source§

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.
Source§

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.

Implementations on Foreign Types§

Source§

impl<T> RewriteCache<T> for Box<dyn RewriteCache<T>>

Source§

fn get(&self, subtree: &T, level: usize) -> CacheResult<T>

Source§

fn insert(&mut self, from: &T, to: Option<T>, level: usize)

Source§

fn invalidate_node(&self, node: &T)

Source§

fn invalidate_subtree(&self, node: &T)

Source§

fn is_active(&self) -> bool

Source§

fn push_ancestor(&mut self, node: &T)

Source§

fn pop_ancestor(&mut self)

Source§

fn pop_and_map_ancestor(&mut self, new_ancestor: &T, level: usize)

Implementors§

Source§

impl<T> RewriteCache<T> for NoCache

Source§

impl<T, K> RewriteCache<T> for HashMapCache<T, K>
where K: CacheKey<T>, T: Clone,