From ac80d4117562aa070717fb2ebbbc069be712d906 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 16 Jun 2016 18:56:14 -0400 Subject: [PATCH] trans: Remove tracking of translation item state. The data tracked here was meant to compare the output of the translation item collector to the set of translation items found by the on-demand translator. --- src/librustc_trans/base.rs | 9 +-- src/librustc_trans/collector.rs | 109 ----------------------------- src/librustc_trans/consts.rs | 6 -- src/librustc_trans/context.rs | 25 ++----- src/librustc_trans/glue.rs | 6 -- src/librustc_trans/monomorphize.rs | 2 +- 6 files changed, 8 insertions(+), 149 deletions(-) diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index bcca008c5e9e..c080d1f06d00 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -58,7 +58,7 @@ use callee::{Callee, CallArgs, ArgExprs, ArgVals}; use cleanup::{self, CleanupMethods, DropHint}; use closure; use common::{Block, C_bool, C_bytes_in_context, C_i32, C_int, C_uint, C_integral}; -use collector::{self, TransItemState, TransItemCollectionMode}; +use collector::{self, TransItemCollectionMode}; use common::{C_null, C_struct_in_context, C_u64, C_u8, C_undef}; use common::{CrateContext, DropFlagHintsMap, Field, FunctionContext}; use common::{Result, NodeIdAndSpan, VariantInfo}; @@ -1830,10 +1830,6 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, closure_env: closure::ClosureEnv) { ccx.stats().n_closures.set(ccx.stats().n_closures.get() + 1); - if collector::collecting_debug_information(ccx.shared()) { - ccx.record_translation_item_as_generated(TransItem::Fn(instance)); - } - let _icx = push_ctxt("trans_closure"); if !ccx.sess().no_landing_pads() { attributes::emit_uwtable(llfndecl, true); @@ -2661,7 +2657,6 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } } - collector::print_collection_results(&shared_ccx); symbol_names_test::report_symbol_names(&shared_ccx); { @@ -2881,7 +2876,7 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a let mut ccx_map = scx.translation_items().borrow_mut(); for trans_item in items.iter().cloned() { - ccx_map.insert(trans_item, TransItemState::PredictedButNotGenerated); + ccx_map.insert(trans_item); } } diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index f37c117cb0f5..ba2cd2ba6999 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -1271,112 +1271,3 @@ fn visit_mir_and_promoted<'tcx, V: MirVisitor<'tcx>>(mut visitor: V, mir: &mir:: visitor.visit_mir(promoted); } } - -#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum TransItemState { - PredictedAndGenerated, - PredictedButNotGenerated, - NotPredictedButGenerated, -} - -pub fn collecting_debug_information(scx: &SharedCrateContext) -> bool { - return cfg!(debug_assertions) && - scx.sess().opts.debugging_opts.print_trans_items.is_some(); -} - -pub fn print_collection_results<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>) { - use std::hash::{Hash, SipHasher, Hasher}; - - if !collecting_debug_information(scx) { - return; - } - - fn hash(t: &T) -> u64 { - let mut s = SipHasher::new(); - t.hash(&mut s); - s.finish() - } - - let trans_items = scx.translation_items().borrow(); - - { - // Check for duplicate item keys - let mut item_keys = FnvHashMap(); - - for (item, item_state) in trans_items.iter() { - let k = item.to_string(scx.tcx()); - - if item_keys.contains_key(&k) { - let prev: (TransItem, TransItemState) = item_keys[&k]; - debug!("DUPLICATE KEY: {}", k); - debug!(" (1) {:?}, {:?}, hash: {}, raw: {}", - prev.0, - prev.1, - hash(&prev.0), - prev.0.to_raw_string()); - - debug!(" (2) {:?}, {:?}, hash: {}, raw: {}", - *item, - *item_state, - hash(item), - item.to_raw_string()); - } else { - item_keys.insert(k, (*item, *item_state)); - } - } - } - - let mut predicted_but_not_generated = FnvHashSet(); - let mut not_predicted_but_generated = FnvHashSet(); - let mut predicted = FnvHashSet(); - let mut generated = FnvHashSet(); - - for (item, item_state) in trans_items.iter() { - let item_key = item.to_string(scx.tcx()); - - match *item_state { - TransItemState::PredictedAndGenerated => { - predicted.insert(item_key.clone()); - generated.insert(item_key); - } - TransItemState::PredictedButNotGenerated => { - predicted_but_not_generated.insert(item_key.clone()); - predicted.insert(item_key); - } - TransItemState::NotPredictedButGenerated => { - not_predicted_but_generated.insert(item_key.clone()); - generated.insert(item_key); - } - } - } - - debug!("Total number of translation items predicted: {}", predicted.len()); - debug!("Total number of translation items generated: {}", generated.len()); - debug!("Total number of translation items predicted but not generated: {}", - predicted_but_not_generated.len()); - debug!("Total number of translation items not predicted but generated: {}", - not_predicted_but_generated.len()); - - if generated.len() > 0 { - debug!("Failed to predict {}% of translation items", - (100 * not_predicted_but_generated.len()) / generated.len()); - } - if generated.len() > 0 { - debug!("Predict {}% too many translation items", - (100 * predicted_but_not_generated.len()) / generated.len()); - } - - debug!(""); - debug!("Not predicted but generated:"); - debug!("============================"); - for item in not_predicted_but_generated { - debug!(" - {}", item); - } - - debug!(""); - debug!("Predicted but not generated:"); - debug!("============================"); - for item in predicted_but_not_generated { - debug!(" - {}", item); - } -} diff --git a/src/librustc_trans/consts.rs b/src/librustc_trans/consts.rs index 3f18c61fbd26..5732fded362f 100644 --- a/src/librustc_trans/consts.rs +++ b/src/librustc_trans/consts.rs @@ -21,7 +21,6 @@ use rustc::hir::map as hir_map; use {abi, adt, closure, debuginfo, expr, machine}; use base::{self, push_ctxt}; use callee::Callee; -use collector; use trans_item::TransItem; use common::{type_is_sized, C_nil, const_get_elt}; use common::{CrateContext, C_integral, C_floating, C_bool, C_str_slice, C_bytes, val_ty}; @@ -1140,11 +1139,6 @@ pub fn trans_static(ccx: &CrateContext, id: ast::NodeId, attrs: &[ast::Attribute]) -> Result { - - if collector::collecting_debug_information(ccx.shared()) { - ccx.record_translation_item_as_generated(TransItem::Static(id)); - } - unsafe { let _icx = push_ctxt("trans_static"); let def_id = ccx.tcx().map.local_def_id(id); diff --git a/src/librustc_trans/context.rs b/src/librustc_trans/context.rs index 8f700e2fe389..b8d231db40a2 100644 --- a/src/librustc_trans/context.rs +++ b/src/librustc_trans/context.rs @@ -28,7 +28,6 @@ use mir::CachedMir; use monomorphize::Instance; use partitioning::CodegenUnit; -use collector::TransItemState; use trans_item::TransItem; use type_::{Type, TypeNames}; use rustc::ty::subst::{Substs, VecPerParamSpace}; @@ -37,7 +36,7 @@ use session::config::NoDebugInfo; use session::Session; use symbol_map::SymbolMap; use util::sha2::Sha256; -use util::nodemap::{NodeMap, NodeSet, DefIdMap, FnvHashMap}; +use util::nodemap::{NodeMap, NodeSet, DefIdMap, FnvHashMap, FnvHashSet}; use std::ffi::{CStr, CString}; use std::cell::{Cell, RefCell}; @@ -85,7 +84,7 @@ pub struct SharedCrateContext<'a, 'tcx: 'a> { use_dll_storage_attrs: bool, - translation_items: RefCell, TransItemState>>, + translation_items: RefCell>>, trait_cache: RefCell>>, } @@ -419,7 +418,7 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> { check_overflow: check_overflow, check_drop_flag_for_sanity: check_drop_flag_for_sanity, use_dll_storage_attrs: use_dll_storage_attrs, - translation_items: RefCell::new(FnvHashMap()), + translation_items: RefCell::new(FnvHashSet()), trait_cache: RefCell::new(DepTrackingMap::new(tcx.dep_graph.clone())), } } @@ -482,7 +481,7 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> { } } - pub fn translation_items(&self) -> &RefCell, TransItemState>> { + pub fn translation_items(&self) -> &RefCell>> { &self.translation_items } @@ -902,24 +901,10 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> { &*self.local().symbol_map } - pub fn translation_items(&self) -> &RefCell, TransItemState>> { + pub fn translation_items(&self) -> &RefCell>> { &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); - } - } - /// Given the def-id of some item that has no type parameters, make /// a suitable "empty substs" for it. pub fn empty_substs_for_def_id(&self, item_def_id: DefId) -> &'tcx Substs<'tcx> { diff --git a/src/librustc_trans/glue.rs b/src/librustc_trans/glue.rs index 468192d7f114..87a1d5844337 100644 --- a/src/librustc_trans/glue.rs +++ b/src/librustc_trans/glue.rs @@ -27,7 +27,6 @@ use build::*; use callee::{Callee, ArgVals}; use cleanup; use cleanup::CleanupMethods; -use collector; use common::*; use debuginfo::DebugLoc; use expr; @@ -482,11 +481,6 @@ pub fn size_and_align_of_dst<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>, fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, g: DropGlueKind<'tcx>) -> Block<'blk, 'tcx> { - if collector::collecting_debug_information(bcx.ccx().shared()) { - bcx.ccx() - .record_translation_item_as_generated(TransItem::DropGlue(g)); - } - let t = g.ty(); let skip_dtor = match g { DropGlueKind::Ty(_) => false, DropGlueKind::TyContents(_) => true }; diff --git a/src/librustc_trans/monomorphize.rs b/src/librustc_trans/monomorphize.rs index 71aacfdfe58a..a97e3e5a78db 100644 --- a/src/librustc_trans/monomorphize.rs +++ b/src/librustc_trans/monomorphize.rs @@ -123,7 +123,7 @@ pub fn monomorphic_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, }) => { let trans_item = TransItem::Fn(instance); - if ccx.shared().translation_items().borrow().contains_key(&trans_item) { + if ccx.shared().translation_items().borrow().contains(&trans_item) { attributes::from_fn_attrs(ccx, attrs, lldecl); llvm::SetLinkage(lldecl, llvm::ExternalLinkage); } else {