Skip to content

Commit b61ee51

Browse files
Fix translation item collection for inline and const fns.
1 parent a17e724 commit b61ee51

File tree

2 files changed

+24
-10
lines changed

2 files changed

+24
-10
lines changed

src/librustc_trans_utils/collector.rs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,14 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
324324
let mut roots = Vec::new();
325325

326326
{
327+
let entry_fn = tcx.sess.entry_fn.borrow().map(|(node_id, _)| {
328+
tcx.hir.local_def_id(node_id)
329+
});
330+
327331
let mut visitor = RootCollector {
328332
tcx,
329333
mode,
334+
entry_fn,
330335
output: &mut roots,
331336
};
332337

@@ -875,6 +880,7 @@ struct RootCollector<'b, 'a: 'b, 'tcx: 'a + 'b> {
875880
tcx: TyCtxt<'a, 'tcx, 'tcx>,
876881
mode: TransItemCollectionMode,
877882
output: &'b mut Vec<TransItem<'tcx>>,
883+
entry_fn: Option<DefId>,
878884
}
879885

880886
impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
@@ -932,10 +938,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
932938
let tcx = self.tcx;
933939
let def_id = tcx.hir.local_def_id(item.id);
934940

935-
if (self.mode == TransItemCollectionMode::Eager ||
936-
!tcx.is_const_fn(def_id) || tcx.is_exported_symbol(def_id)) &&
937-
!item_has_type_parameters(tcx, def_id) {
938-
941+
if self.is_root(def_id) {
939942
debug!("RootCollector: ItemFn({})",
940943
def_id_to_string(tcx, def_id));
941944

@@ -957,10 +960,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
957960
let tcx = self.tcx;
958961
let def_id = tcx.hir.local_def_id(ii.id);
959962

960-
if (self.mode == TransItemCollectionMode::Eager ||
961-
!tcx.is_const_fn(def_id) ||
962-
tcx.is_exported_symbol(def_id)) &&
963-
!item_has_type_parameters(tcx, def_id) {
963+
if self.is_root(def_id) {
964964
debug!("RootCollector: MethodImplItem({})",
965965
def_id_to_string(tcx, def_id));
966966

@@ -973,6 +973,20 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
973973
}
974974
}
975975

976+
impl<'b, 'a, 'v> RootCollector<'b, 'a, 'v> {
977+
fn is_root(&self, def_id: DefId) -> bool {
978+
!item_has_type_parameters(self.tcx, def_id) && match self.mode {
979+
TransItemCollectionMode::Eager => {
980+
true
981+
}
982+
TransItemCollectionMode::Lazy => {
983+
self.entry_fn == Some(def_id) ||
984+
self.tcx.is_exported_symbol(def_id)
985+
}
986+
}
987+
}
988+
}
989+
976990
fn item_has_type_parameters<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
977991
let generics = tcx.generics_of(def_id);
978992
generics.parent_types as usize + generics.types.len() > 0

src/librustc_trans_utils/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,11 @@ pub fn find_exported_symbols(tcx: TyCtxt) -> NodeSet {
107107
node: hir::ImplItemKind::Method(..), .. }) => {
108108
let def_id = tcx.hir.local_def_id(id);
109109
let generics = tcx.generics_of(def_id);
110-
let attributes = tcx.get_attrs(def_id);
111110
(generics.parent_types == 0 && generics.types.is_empty()) &&
112111
// Functions marked with #[inline] are only ever translated
113112
// with "internal" linkage and are never exported.
114-
!attr::requests_inline(&attributes)
113+
!attr::requests_inline(&tcx.get_attrs(def_id)) &&
114+
!tcx.is_const_fn(def_id)
115115
}
116116

117117
_ => false

0 commit comments

Comments
 (0)