From e546fea0a187dfeeddb7a3a17486aabd686c0555 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Mon, 30 Oct 2017 18:49:56 +0100 Subject: [PATCH] Don't duplicate logic of when an Instance requests to be inlined. --- src/librustc_trans_utils/common.rs | 3 ++- src/librustc_trans_utils/lib.rs | 9 +++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/librustc_trans_utils/common.rs b/src/librustc_trans_utils/common.rs index ec9c5b1119b..47968afd70d 100644 --- a/src/librustc_trans_utils/common.rs +++ b/src/librustc_trans_utils/common.rs @@ -51,7 +51,8 @@ pub fn requests_inline<'a, 'tcx>( // available to normal end-users. return true } - attr::requests_inline(&instance.def.attrs(tcx)[..]) + attr::requests_inline(&instance.def.attrs(tcx)[..]) || + tcx.is_const_fn(instance.def.def_id()) } pub fn is_inline_instance<'a, 'tcx>( diff --git a/src/librustc_trans_utils/lib.rs b/src/librustc_trans_utils/lib.rs index c460752d75e..d6f8707b874 100644 --- a/src/librustc_trans_utils/lib.rs +++ b/src/librustc_trans_utils/lib.rs @@ -40,14 +40,12 @@ extern crate rustc_data_structures; extern crate syntax; extern crate syntax_pos; -use rustc::ty::TyCtxt; +use rustc::ty::{TyCtxt, Instance}; use rustc::hir; use rustc::hir::def_id::LOCAL_CRATE; use rustc::hir::map as hir_map; use rustc::util::nodemap::NodeSet; -use syntax::attr; - pub mod common; pub mod link; pub mod collector; @@ -77,7 +75,7 @@ pub fn check_for_rustc_errors_attr(tcx: TyCtxt) { /// /// This list is later used by linkers to determine the set of symbols needed to /// be exposed from a dynamic library and it's also encoded into the metadata. -pub fn find_exported_symbols(tcx: TyCtxt) -> NodeSet { +pub fn find_exported_symbols<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> NodeSet { tcx.reachable_set(LOCAL_CRATE).0.iter().cloned().filter(|&id| { // Next, we want to ignore some FFI functions that are not exposed from // this crate. Reachable FFI functions can be lumped into two @@ -110,8 +108,7 @@ pub fn find_exported_symbols(tcx: TyCtxt) -> NodeSet { (generics.parent_types == 0 && generics.types.is_empty()) && // Functions marked with #[inline] are only ever translated // with "internal" linkage and are never exported. - !attr::requests_inline(&tcx.get_attrs(def_id)) && - !tcx.is_const_fn(def_id) + !common::requests_inline(tcx, &Instance::mono(tcx, def_id)) } _ => false