From b279c5b068517c034c6b1a8b1aa78a7271fa223b Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 21 Jan 2016 08:33:58 -0500 Subject: [PATCH] Add dependency tracking to trait cache in translation context --- src/librustc_trans/trans/context.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/librustc_trans/trans/context.rs b/src/librustc_trans/trans/context.rs index d4d2f01f774..7301afa46fc 100644 --- a/src/librustc_trans/trans/context.rs +++ b/src/librustc_trans/trans/context.rs @@ -10,6 +10,7 @@ use llvm; use llvm::{ContextRef, ModuleRef, ValueRef, BuilderRef}; +use rustc::dep_graph::{DepNode, DepTrackingMap, DepTrackingMapConfig}; use middle::cstore::LinkMeta; use middle::def::ExportMap; use middle::def_id::DefId; @@ -33,6 +34,7 @@ use util::nodemap::{NodeMap, NodeSet, DefIdMap, FnvHashMap, FnvHashSet}; use std::ffi::CString; use std::cell::{Cell, RefCell}; +use std::marker::PhantomData; use std::ptr; use std::rc::Rc; use syntax::ast; @@ -161,8 +163,23 @@ pub struct LocalCrateContext<'tcx> { /// Depth of the current type-of computation - used to bail out type_of_depth: Cell, - trait_cache: RefCell, - traits::Vtable<'tcx, ()>>>, + trait_cache: RefCell>>, +} + +// Implement DepTrackingMapConfig for `trait_cache` +pub struct TraitSelectionCache<'tcx> { + data: PhantomData<&'tcx ()> +} + +impl<'tcx> DepTrackingMapConfig for TraitSelectionCache<'tcx> { + type Key = ty::PolyTraitRef<'tcx>; + type Value = traits::Vtable<'tcx, ()>; + fn to_dep_node(key: &ty::PolyTraitRef<'tcx>) -> DepNode { + ty::tls::with(|tcx| { + let lifted_key = tcx.lift(key).unwrap(); + lifted_key.to_poly_trait_predicate().dep_node() + }) + } } pub struct CrateContext<'a, 'tcx: 'a> { @@ -478,7 +495,9 @@ impl<'tcx> LocalCrateContext<'tcx> { intrinsics: RefCell::new(FnvHashMap()), n_llvm_insns: Cell::new(0), type_of_depth: Cell::new(0), - trait_cache: RefCell::new(FnvHashMap()), + trait_cache: RefCell::new(DepTrackingMap::new(shared.tcx + .dep_graph + .clone())), }; local_ccx.int_type = Type::int(&local_ccx.dummy_ccx(shared)); @@ -752,8 +771,7 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { self.local.n_llvm_insns.set(self.local.n_llvm_insns.get() + 1); } - pub fn trait_cache(&self) -> &RefCell, - traits::Vtable<'tcx, ()>>> { + pub fn trait_cache(&self) -> &RefCell>> { &self.local.trait_cache }