Trait rustc::util::common::MemoizationMap [] [src]

pub trait MemoizationMap {
    type Key: Clone;
    type Value: Clone;
    fn memoize<OP>(&self, key: Self::Key, op: OP) -> Self::Value
    where
        OP: FnOnce() -> Self::Value
; }
🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

Associated Types

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

Required Methods

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

If key is present in the map, return the value, otherwise invoke op and store the value in the map.

NB: if the receiver is a DepTrackingMap, special care is needed in the op to ensure that the correct edges are added into the dep graph. See the DepTrackingMap impl for more details!

Implementations on Foreign Types

impl<M: DepTrackingMapConfig> MemoizationMap for RefCell<DepTrackingMap<M>>
[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

Memoizes an entry in the dep-tracking-map. If the entry is not already present, then op will be executed to compute its value. The resulting dependency graph looks like this:

[op] -> Map(key) -> CurrentTask

Here, [op] represents whatever nodes op reads in the course of execution; Map(key) represents the node for this map; and CurrentTask represents the current task when memoize is invoked.

**Important:* when op is invoked, the current task will be switched to Map(key). Therefore, if op makes use of any HIR nodes or shared state accessed through its closure environment, it must explicitly register a read of that state. As an example, see type_of_item in collect, which looks something like this:

fn type_of_item(..., item: &hir::Item) -> Ty<'tcx> {
    let item_def_id = ccx.tcx.hir.local_def_id(it.id);
    ccx.tcx.item_types.memoized(item_def_id, || {
        ccx.tcx.dep_graph.read(DepNode::Hir(item_def_id)); // (*)
        compute_type_of_item(ccx, item)
    });
}

The key is the line marked (*): the closure implicitly accesses the body of the item item, so we register a read from Hir(item_def_id).

impl<K, V, S> MemoizationMap for RefCell<HashMap<K, V, S>> where
    K: Hash + Eq + Clone,
    V: Clone,
    S: BuildHasher
[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

[src]

🔬 This is a nightly-only experimental API. (rustc_private)

this crate is being loaded from the sysroot, an unstable location; did you mean to load this crate from crates.io via Cargo.toml instead?

Implementors