mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Fix translation item collection for inline and const fns.
This commit is contained in:
parent
a17e72462f
commit
b61ee5180c
@ -324,9 +324,14 @@ fn collect_roots<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
let mut roots = Vec::new();
|
||||
|
||||
{
|
||||
let entry_fn = tcx.sess.entry_fn.borrow().map(|(node_id, _)| {
|
||||
tcx.hir.local_def_id(node_id)
|
||||
});
|
||||
|
||||
let mut visitor = RootCollector {
|
||||
tcx,
|
||||
mode,
|
||||
entry_fn,
|
||||
output: &mut roots,
|
||||
};
|
||||
|
||||
@ -875,6 +880,7 @@ struct RootCollector<'b, 'a: 'b, 'tcx: 'a + 'b> {
|
||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||
mode: TransItemCollectionMode,
|
||||
output: &'b mut Vec<TransItem<'tcx>>,
|
||||
entry_fn: Option<DefId>,
|
||||
}
|
||||
|
||||
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> {
|
||||
let tcx = self.tcx;
|
||||
let def_id = tcx.hir.local_def_id(item.id);
|
||||
|
||||
if (self.mode == TransItemCollectionMode::Eager ||
|
||||
!tcx.is_const_fn(def_id) || tcx.is_exported_symbol(def_id)) &&
|
||||
!item_has_type_parameters(tcx, def_id) {
|
||||
|
||||
if self.is_root(def_id) {
|
||||
debug!("RootCollector: ItemFn({})",
|
||||
def_id_to_string(tcx, def_id));
|
||||
|
||||
@ -957,10 +960,7 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
|
||||
let tcx = self.tcx;
|
||||
let def_id = tcx.hir.local_def_id(ii.id);
|
||||
|
||||
if (self.mode == TransItemCollectionMode::Eager ||
|
||||
!tcx.is_const_fn(def_id) ||
|
||||
tcx.is_exported_symbol(def_id)) &&
|
||||
!item_has_type_parameters(tcx, def_id) {
|
||||
if self.is_root(def_id) {
|
||||
debug!("RootCollector: MethodImplItem({})",
|
||||
def_id_to_string(tcx, def_id));
|
||||
|
||||
@ -973,6 +973,20 @@ impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'b, 'a, 'v> RootCollector<'b, 'a, 'v> {
|
||||
fn is_root(&self, def_id: DefId) -> bool {
|
||||
!item_has_type_parameters(self.tcx, def_id) && match self.mode {
|
||||
TransItemCollectionMode::Eager => {
|
||||
true
|
||||
}
|
||||
TransItemCollectionMode::Lazy => {
|
||||
self.entry_fn == Some(def_id) ||
|
||||
self.tcx.is_exported_symbol(def_id)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn item_has_type_parameters<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
|
||||
let generics = tcx.generics_of(def_id);
|
||||
generics.parent_types as usize + generics.types.len() > 0
|
||||
|
@ -107,11 +107,11 @@ pub fn find_exported_symbols(tcx: TyCtxt) -> NodeSet {
|
||||
node: hir::ImplItemKind::Method(..), .. }) => {
|
||||
let def_id = tcx.hir.local_def_id(id);
|
||||
let generics = tcx.generics_of(def_id);
|
||||
let attributes = tcx.get_attrs(def_id);
|
||||
(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(&attributes)
|
||||
!attr::requests_inline(&tcx.get_attrs(def_id)) &&
|
||||
!tcx.is_const_fn(def_id)
|
||||
}
|
||||
|
||||
_ => false
|
||||
|
Loading…
Reference in New Issue
Block a user