mirror of https://github.com/rust-lang/rust.git
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 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 {
|
let mut visitor = RootCollector {
|
||||||
tcx,
|
tcx,
|
||||||
mode,
|
mode,
|
||||||
|
entry_fn,
|
||||||
output: &mut roots,
|
output: &mut roots,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -875,6 +880,7 @@ struct RootCollector<'b, 'a: 'b, 'tcx: 'a + 'b> {
|
||||||
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
tcx: TyCtxt<'a, 'tcx, 'tcx>,
|
||||||
mode: TransItemCollectionMode,
|
mode: TransItemCollectionMode,
|
||||||
output: &'b mut Vec<TransItem<'tcx>>,
|
output: &'b mut Vec<TransItem<'tcx>>,
|
||||||
|
entry_fn: Option<DefId>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'b, 'a, 'v> ItemLikeVisitor<'v> for RootCollector<'b, 'a, 'v> {
|
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 tcx = self.tcx;
|
||||||
let def_id = tcx.hir.local_def_id(item.id);
|
let def_id = tcx.hir.local_def_id(item.id);
|
||||||
|
|
||||||
if (self.mode == TransItemCollectionMode::Eager ||
|
if self.is_root(def_id) {
|
||||||
!tcx.is_const_fn(def_id) || tcx.is_exported_symbol(def_id)) &&
|
|
||||||
!item_has_type_parameters(tcx, def_id) {
|
|
||||||
|
|
||||||
debug!("RootCollector: ItemFn({})",
|
debug!("RootCollector: ItemFn({})",
|
||||||
def_id_to_string(tcx, def_id));
|
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 tcx = self.tcx;
|
||||||
let def_id = tcx.hir.local_def_id(ii.id);
|
let def_id = tcx.hir.local_def_id(ii.id);
|
||||||
|
|
||||||
if (self.mode == TransItemCollectionMode::Eager ||
|
if self.is_root(def_id) {
|
||||||
!tcx.is_const_fn(def_id) ||
|
|
||||||
tcx.is_exported_symbol(def_id)) &&
|
|
||||||
!item_has_type_parameters(tcx, def_id) {
|
|
||||||
debug!("RootCollector: MethodImplItem({})",
|
debug!("RootCollector: MethodImplItem({})",
|
||||||
def_id_to_string(tcx, def_id));
|
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 {
|
fn item_has_type_parameters<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> bool {
|
||||||
let generics = tcx.generics_of(def_id);
|
let generics = tcx.generics_of(def_id);
|
||||||
generics.parent_types as usize + generics.types.len() > 0
|
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(..), .. }) => {
|
node: hir::ImplItemKind::Method(..), .. }) => {
|
||||||
let def_id = tcx.hir.local_def_id(id);
|
let def_id = tcx.hir.local_def_id(id);
|
||||||
let generics = tcx.generics_of(def_id);
|
let generics = tcx.generics_of(def_id);
|
||||||
let attributes = tcx.get_attrs(def_id);
|
|
||||||
(generics.parent_types == 0 && generics.types.is_empty()) &&
|
(generics.parent_types == 0 && generics.types.is_empty()) &&
|
||||||
// Functions marked with #[inline] are only ever translated
|
// Functions marked with #[inline] are only ever translated
|
||||||
// with "internal" linkage and are never exported.
|
// 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
|
_ => false
|
||||||
|
|
Loading…
Reference in New Issue