Skip to content

Commit 678d377

Browse files
Address some nits in trans-collector and partitioner.
1 parent c93e62b commit 678d377

File tree

3 files changed

+33
-44
lines changed

3 files changed

+33
-44
lines changed

src/librustc_trans/base.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,9 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
13011301

13021302
let (items, inlining_map) =
13031303
time(time_passes, "translation item collection", || {
1304-
collector::collect_crate_translation_items(&scx, collection_mode)
1304+
collector::collect_crate_translation_items(&scx,
1305+
exported_symbols,
1306+
collection_mode)
13051307
});
13061308

13071309
assert_symbols_are_distinct(scx.tcx(), items.iter());

src/librustc_trans/collector.rs

+29-41
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ use rustc::util::nodemap::{FxHashSet, FxHashMap, DefIdMap};
209209
use trans_item::{TransItem, DefPathBasedNames, InstantiationMode};
210210

211211
use rustc_data_structures::bitvec::BitVector;
212+
use back::symbol_export::ExportedSymbols;
212213

213214
#[derive(PartialEq, Eq, Hash, Clone, Copy, Debug)]
214215
pub enum TransItemCollectionMode {
@@ -293,13 +294,14 @@ impl<'tcx> InliningMap<'tcx> {
293294
}
294295

295296
pub fn collect_crate_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
297+
exported_symbols: &ExportedSymbols,
296298
mode: TransItemCollectionMode)
297299
-> (FxHashSet<TransItem<'tcx>>,
298300
InliningMap<'tcx>) {
299301
// We are not tracking dependencies of this pass as it has to be re-executed
300302
// every time no matter what.
301303
scx.tcx().dep_graph.with_ignore(|| {
302-
let roots = collect_roots(scx, mode);
304+
let roots = collect_roots(scx, exported_symbols, mode);
303305

304306
debug!("Building translation item graph, beginning at roots");
305307
let mut visited = FxHashSet();
@@ -321,6 +323,7 @@ pub fn collect_crate_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a, 't
321323
// Find all non-generic items by walking the HIR. These items serve as roots to
322324
// start monomorphizing from.
323325
fn collect_roots<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
326+
exported_symbols: &ExportedSymbols,
324327
mode: TransItemCollectionMode)
325328
-> Vec<TransItem<'tcx>> {
326329
debug!("Collecting roots");
@@ -330,6 +333,7 @@ fn collect_roots<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
330333
let mut visitor = RootCollector {
331334
scx: scx,
332335
mode: mode,
336+
exported_symbols,
333337
output: &mut roots,
334338
};
335339

@@ -853,6 +857,7 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(scx: &SharedCrateContext<'a,
853857

854858
struct RootCollector<'b, 'a: 'b, 'tcx: 'a + 'b> {
855859
scx: &'b SharedCrateContext<'a, 'tcx>,
860+
exported_symbols: &'b ExportedSymbols,
856861
mode: TransItemCollectionMode,
857862
output: &'b mut Vec<TransItem<'tcx>>,
858863
}
@@ -908,20 +913,19 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
908913
// const items only generate translation items if they are
909914
// actually used somewhere. Just declaring them is insufficient.
910915
}
911-
hir::ItemFn(_, _, constness, _, ref generics, _) => {
912-
let is_const = match constness {
913-
hir::Constness::Const => true,
914-
hir::Constness::NotConst => false,
915-
};
916+
hir::ItemFn(..) => {
917+
let tcx = self.scx.tcx();
918+
let def_id = tcx.hir.local_def_id(item.id);
916919

917-
if !generics.is_type_parameterized() &&
918-
(!is_const || self.mode == TransItemCollectionMode::Eager) {
919-
let def_id = self.scx.tcx().hir.local_def_id(item.id);
920+
if (self.mode == TransItemCollectionMode::Eager ||
921+
!tcx.is_const_fn(def_id) ||
922+
self.exported_symbols.local_exports().contains(&item.id)) &&
923+
!item_has_type_parameters(tcx, def_id) {
920924

921925
debug!("RootCollector: ItemFn({})",
922-
def_id_to_string(self.scx.tcx(), def_id));
926+
def_id_to_string(tcx, def_id));
923927

924-
let instance = Instance::mono(self.scx.tcx(), def_id);
928+
let instance = Instance::mono(tcx, def_id);
925929
self.output.push(TransItem::Fn(instance));
926930
}
927931
}
@@ -935,39 +939,18 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
935939

936940
fn visit_impl_item(&mut self, ii: &'v hir::ImplItem) {
937941
match ii.node {
938-
hir::ImplItemKind::Method(hir::MethodSig {
939-
constness,
940-
ref generics,
941-
..
942-
}, _) => {
943-
let hir_map = &self.scx.tcx().hir;
944-
let parent_node_id = hir_map.get_parent_node(ii.id);
945-
let is_impl_generic = || match hir_map.expect_item(parent_node_id) {
946-
&hir::Item {
947-
node: hir::ItemImpl(_, _, _, ref generics, ..),
948-
..
949-
} => {
950-
generics.is_type_parameterized()
951-
}
952-
_ => {
953-
bug!()
954-
}
955-
};
956-
957-
let is_const = match constness {
958-
hir::Constness::Const => true,
959-
hir::Constness::NotConst => false,
960-
};
961-
962-
if (!is_const || self.mode == TransItemCollectionMode::Eager) &&
963-
!generics.is_type_parameterized() &&
964-
!is_impl_generic() {
965-
let def_id = self.scx.tcx().hir.local_def_id(ii.id);
942+
hir::ImplItemKind::Method(hir::MethodSig { .. }, _) => {
943+
let tcx = self.scx.tcx();
944+
let def_id = tcx.hir.local_def_id(ii.id);
966945

946+
if (self.mode == TransItemCollectionMode::Eager ||
947+
!tcx.is_const_fn(def_id) ||
948+
self.exported_symbols.local_exports().contains(&ii.id)) &&
949+
!item_has_type_parameters(tcx, def_id) {
967950
debug!("RootCollector: MethodImplItem({})",
968-
def_id_to_string(self.scx.tcx(), def_id));
951+
def_id_to_string(tcx, def_id));
969952

970-
let instance = Instance::mono(self.scx.tcx(), def_id);
953+
let instance = Instance::mono(tcx, def_id);
971954
self.output.push(TransItem::Fn(instance));
972955
}
973956
}
@@ -976,6 +959,11 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
976959
}
977960
}
978961

962+
fn item_has_type_parameters<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
963+
let generics = tcx.generics_of(def_id);
964+
generics.parent_types as usize + generics.types.len() > 0
965+
}
966+
979967
fn create_trans_items_for_default_impls<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
980968
item: &'tcx hir::Item,
981969
output: &mut Vec<TransItem<'tcx>>) {

src/librustc_trans/partitioning.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,6 @@ fn internalize_symbols<'a, 'tcx>(_tcx: TyCtxt<'a, 'tcx, 'tcx>,
576576
cgu_name: cgu.name.clone()
577577
};
578578

579-
'item:
580579
for (accessee, &mut (ref mut linkage, _)) in &mut cgu.items {
581580
if !partitioning.internalization_candidates.contains(accessee) {
582581
// This item is no candidate for internalizing, so skip it.
@@ -594,7 +593,7 @@ fn internalize_symbols<'a, 'tcx>(_tcx: TyCtxt<'a, 'tcx, 'tcx>,
594593
.any(|placement| *placement != home_cgu) {
595594
// Found an accessor from another CGU, so skip to the next
596595
// item without marking this one as internal.
597-
continue 'item;
596+
continue
598597
}
599598
}
600599

0 commit comments

Comments
 (0)