macro_rules! thread_local_content_memo {
(
$(#[$meta:meta])*
$STATIC:ident : $K:ty => $V:ty ;
fn $get:ident ;
fn $clear:ident ;
) => { ... };
}Expand description
Declare a thread-local ContentMemo plus a memoized accessor and a clear
fn — the boilerplate that was hand-rolled at every memo site. Real-easy
front: one declaration replaces the thread_local! + get_or_compute
wrapper + clear wrapper trio.
ⓘ
use sui_intern::thread_local_content_memo;
use std::collections::HashSet;
thread_local_content_memo! {
/// referenced idents per (source-id, text-range)
REFERENCED_IDENTS: (u32, rnix::TextRange) => HashSet<smol_str::SmolStr>;
fn referenced_idents_memo; // accessor: (key, || compute) -> Rc<V>
fn clear_referenced_idents; // clear the memo (per top-level eval)
}
// hit-or-compute (byte-neutral: value is a pure fn of the key):
let set = referenced_idents_memo(key, || walk_and_collect(expr));
// reset at the eval boundary:
clear_referenced_idents();