Remove unused DepTrackingMap
This commit is contained in:
parent
6c2c29c432
commit
9b00e219fe
4 changed files with 3 additions and 156 deletions
|
@ -1,87 +0,0 @@
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
|
||||||
use std::cell::RefCell;
|
|
||||||
use std::hash::Hash;
|
|
||||||
use std::marker::PhantomData;
|
|
||||||
use crate::util::common::MemoizationMap;
|
|
||||||
|
|
||||||
use super::{DepKind, DepNodeIndex, DepGraph};
|
|
||||||
|
|
||||||
/// A DepTrackingMap offers a subset of the `Map` API and ensures that
|
|
||||||
/// we make calls to `read` and `write` as appropriate. We key the
|
|
||||||
/// maps with a unique type for brevity.
|
|
||||||
pub struct DepTrackingMap<M: DepTrackingMapConfig> {
|
|
||||||
phantom: PhantomData<M>,
|
|
||||||
graph: DepGraph,
|
|
||||||
map: FxHashMap<M::Key, (M::Value, DepNodeIndex)>,
|
|
||||||
}
|
|
||||||
|
|
||||||
pub trait DepTrackingMapConfig {
|
|
||||||
type Key: Eq + Hash + Clone;
|
|
||||||
type Value: Clone;
|
|
||||||
fn to_dep_kind() -> DepKind;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<M: DepTrackingMapConfig> DepTrackingMap<M> {
|
|
||||||
pub fn new(graph: DepGraph) -> DepTrackingMap<M> {
|
|
||||||
DepTrackingMap {
|
|
||||||
phantom: PhantomData,
|
|
||||||
graph,
|
|
||||||
map: Default::default(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<M: DepTrackingMapConfig> MemoizationMap for RefCell<DepTrackingMap<M>> {
|
|
||||||
type Key = M::Key;
|
|
||||||
type Value = M::Value;
|
|
||||||
|
|
||||||
/// 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.hir_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)`.
|
|
||||||
fn memoize<OP>(&self, key: M::Key, op: OP) -> M::Value
|
|
||||||
where OP: FnOnce() -> M::Value
|
|
||||||
{
|
|
||||||
let graph;
|
|
||||||
{
|
|
||||||
let this = self.borrow();
|
|
||||||
if let Some(&(ref result, dep_node)) = this.map.get(&key) {
|
|
||||||
this.graph.read_index(dep_node);
|
|
||||||
return result.clone();
|
|
||||||
}
|
|
||||||
graph = this.graph.clone();
|
|
||||||
}
|
|
||||||
|
|
||||||
let (result, dep_node) = graph.with_anon_task(M::to_dep_kind(), op);
|
|
||||||
self.borrow_mut().map.insert(key, (result.clone(), dep_node));
|
|
||||||
graph.read_index(dep_node);
|
|
||||||
result
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,6 +1,5 @@
|
||||||
pub mod debug;
|
pub mod debug;
|
||||||
mod dep_node;
|
mod dep_node;
|
||||||
mod dep_tracking_map;
|
|
||||||
mod graph;
|
mod graph;
|
||||||
mod prev;
|
mod prev;
|
||||||
mod query;
|
mod query;
|
||||||
|
@ -8,7 +7,6 @@ mod safe;
|
||||||
mod serialized;
|
mod serialized;
|
||||||
pub mod cgu_reuse_tracker;
|
pub mod cgu_reuse_tracker;
|
||||||
|
|
||||||
pub use self::dep_tracking_map::{DepTrackingMap, DepTrackingMapConfig};
|
|
||||||
pub use self::dep_node::{DepNode, DepKind, DepConstructor, WorkProductId, RecoverKey, label_strs};
|
pub use self::dep_node::{DepNode, DepKind, DepConstructor, WorkProductId, RecoverKey, label_strs};
|
||||||
pub use self::graph::{DepGraph, WorkProduct, DepNodeIndex, DepNodeColor, TaskDeps, hash_result};
|
pub use self::graph::{DepGraph, WorkProduct, DepNodeIndex, DepNodeColor, TaskDeps, hash_result};
|
||||||
pub use self::graph::WorkProductFileKind;
|
pub use self::graph::WorkProductFileKind;
|
||||||
|
|
|
@ -3,12 +3,10 @@
|
||||||
// seems likely that they should eventually be merged into more
|
// seems likely that they should eventually be merged into more
|
||||||
// general routines.
|
// general routines.
|
||||||
|
|
||||||
use crate::dep_graph::{DepKind, DepTrackingMapConfig};
|
|
||||||
use std::marker::PhantomData;
|
|
||||||
use crate::infer::InferCtxt;
|
use crate::infer::InferCtxt;
|
||||||
use crate::traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext,
|
use crate::traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext,
|
||||||
TraitEngine, Vtable};
|
TraitEngine, Vtable};
|
||||||
use crate::ty::{self, Ty, TyCtxt};
|
use crate::ty::{self, TyCtxt};
|
||||||
use crate::ty::subst::{Subst, SubstsRef};
|
use crate::ty::subst::{Subst, SubstsRef};
|
||||||
use crate::ty::fold::TypeFoldable;
|
use crate::ty::fold::TypeFoldable;
|
||||||
|
|
||||||
|
@ -100,33 +98,8 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Implement DepTrackingMapConfig for `trait_cache`
|
|
||||||
pub struct TraitSelectionCache<'tcx> {
|
|
||||||
data: PhantomData<&'tcx ()>
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> DepTrackingMapConfig for TraitSelectionCache<'tcx> {
|
|
||||||
type Key = (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>);
|
|
||||||
type Value = Vtable<'tcx, ()>;
|
|
||||||
fn to_dep_kind() -> DepKind {
|
|
||||||
DepKind::TraitSelect
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// # Global Cache
|
// # Global Cache
|
||||||
|
|
||||||
pub struct ProjectionCache<'tcx> {
|
|
||||||
data: PhantomData<&'tcx ()>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'tcx> DepTrackingMapConfig for ProjectionCache<'tcx> {
|
|
||||||
type Key = Ty<'tcx>;
|
|
||||||
type Value = Ty<'tcx>;
|
|
||||||
fn to_dep_kind() -> DepKind {
|
|
||||||
DepKind::TraitSelect
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
|
||||||
/// Finishes processes any obligations that remain in the
|
/// Finishes processes any obligations that remain in the
|
||||||
/// fulfillment context, and then returns the result with all type
|
/// fulfillment context, and then returns the result with all type
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
#![allow(non_camel_case_types)]
|
#![allow(non_camel_case_types)]
|
||||||
|
|
||||||
use rustc_data_structures::{fx::FxHashMap, sync::Lock};
|
use rustc_data_structures::sync::Lock;
|
||||||
|
|
||||||
use std::cell::{RefCell, Cell};
|
use std::cell::Cell;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::hash::Hash;
|
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use std::sync::mpsc::{Sender};
|
use std::sync::mpsc::{Sender};
|
||||||
|
@ -279,39 +278,3 @@ pub fn indenter() -> Indenter {
|
||||||
debug!(">>");
|
debug!(">>");
|
||||||
Indenter { _cannot_construct_outside_of_this_module: () }
|
Indenter { _cannot_construct_outside_of_this_module: () }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait MemoizationMap {
|
|
||||||
type Key: Clone;
|
|
||||||
type Value: Clone;
|
|
||||||
|
|
||||||
/// If `key` is present in the map, return the value,
|
|
||||||
/// otherwise invoke `op` and store the value in the map.
|
|
||||||
///
|
|
||||||
/// N.B., 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!
|
|
||||||
fn memoize<OP>(&self, key: Self::Key, op: OP) -> Self::Value
|
|
||||||
where OP: FnOnce() -> Self::Value;
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<K, V> MemoizationMap for RefCell<FxHashMap<K,V>>
|
|
||||||
where K: Hash+Eq+Clone, V: Clone
|
|
||||||
{
|
|
||||||
type Key = K;
|
|
||||||
type Value = V;
|
|
||||||
|
|
||||||
fn memoize<OP>(&self, key: K, op: OP) -> V
|
|
||||||
where OP: FnOnce() -> V
|
|
||||||
{
|
|
||||||
let result = self.borrow().get(&key).cloned();
|
|
||||||
match result {
|
|
||||||
Some(result) => result,
|
|
||||||
None => {
|
|
||||||
let result = op();
|
|
||||||
self.borrow_mut().insert(key, result.clone());
|
|
||||||
result
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue