Skip to main content

with_cache

Function with_cache 

Source
pub fn with_cache<F>(
    cache: &mut DefEqCache,
    lhs: &Expr,
    rhs: &Expr,
    check: F,
) -> bool
where F: FnOnce() -> bool,
Expand description

Memoizing wrapper that checks the cache before invoking the checker.

If (lhs, rhs) is already in cache, returns the cached result immediately. Otherwise, calls check(), stores the result in the cache, and returns it.

This is the primary way to integrate DefEqCache into a definitional equality checker without modifying the checker itself.

§Example

let result = with_cache(&mut cache, &expr_a, &expr_b, || {
    expensive_def_eq_check(&expr_a, &expr_b)
});