X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc_trans%2Ftrans%2Fcontext.rs;h=38459c1ec3cb7df05d8db83eddcbfc76906107c8;hb=303892ee156e5c31222b10786e661abb24dcf241;hp=fda8577f99f9c4753d0b527c3c6c702188b08600;hpb=3e9589c0f43af69544b042f50b886005613540f2;p=rust.git diff --git a/src/librustc_trans/trans/context.rs b/src/librustc_trans/trans/context.rs index fda8577f99f..38459c1ec3c 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; @@ -23,6 +24,7 @@ use trans::declare; use trans::glue::DropGlueKind; use trans::monomorphize::MonoId; +use trans::collector::{TransItem, TransItemState}; use trans::type_::{Type, TypeNames}; use middle::subst::Substs; use middle::ty::{self, Ty}; @@ -33,6 +35,7 @@ use std::ffi::CString; use std::cell::{Cell, RefCell}; +use std::marker::PhantomData; use std::ptr; use std::rc::Rc; use syntax::ast; @@ -75,6 +78,8 @@ pub struct SharedCrateContext<'a, 'tcx: 'a> { available_drop_glues: RefCell, String>>, use_dll_storage_attrs: bool, + + translation_items: RefCell, TransItemState>>, } /// The local portion of a `CrateContext`. There is one `LocalCrateContext` @@ -161,8 +166,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> { @@ -228,7 +248,6 @@ fn next(&mut self) -> Option<(CrateContext<'a, 'tcx>, bool)> { } } - unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextRef, ModuleRef) { let llcx = llvm::LLVMContextCreate(); let mod_name = CString::new(mod_name).unwrap(); @@ -337,6 +356,7 @@ pub fn new(crate_name: &str, check_drop_flag_for_sanity: check_drop_flag_for_sanity, available_drop_glues: RefCell::new(FnvHashMap()), use_dll_storage_attrs: use_dll_storage_attrs, + translation_items: RefCell::new(FnvHashMap()), }; for i in 0..local_count { @@ -478,7 +498,9 @@ fn new<'a>(shared: &SharedCrateContext<'a, '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 +774,7 @@ pub fn count_llvm_insn(&self) { 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 } @@ -811,6 +832,24 @@ pub fn use_dll_storage_attrs(&self) -> bool { pub fn mir_map(&self) -> &'b MirMap<'tcx> { self.shared.mir_map } + + pub fn translation_items(&self) -> &RefCell, TransItemState>> { + &self.shared.translation_items + } + + pub fn record_translation_item_as_generated(&self, cgi: TransItem<'tcx>) { + if self.sess().opts.debugging_opts.print_trans_items.is_none() { + return; + } + + let mut codegen_items = self.translation_items().borrow_mut(); + + if codegen_items.contains_key(&cgi) { + codegen_items.insert(cgi, TransItemState::PredictedAndGenerated); + } else { + codegen_items.insert(cgi, TransItemState::NotPredictedButGenerated); + } + } } pub struct TypeOfDepthLock<'a, 'tcx: 'a>(&'a LocalCrateContext<'tcx>);