//! Some things are not yet fully implemented in the current version of this
//! module.
//!
-//! ### Initializers of Constants and Statics
-//! Since no MIR is constructed yet for initializer expressions of constants and
-//! statics we cannot inspect these properly.
-//!
//! ### Const Fns
//! Ideally, no mono item should be generated for const fns unless there
//! is a call to them that cannot be evaluated at compile time. At the moment
use rustc::hir::{self, CodegenFnAttrFlags};
use rustc::hir::itemlikevisit::ItemLikeVisitor;
-use rustc::hir::Node;
use rustc::hir::def_id::DefId;
use rustc::mir::interpret::{AllocId, ConstValue};
use rustc::middle::lang_items::{ExchangeMallocFnLangItem, StartFnLangItem};
{
let entry_fn = tcx.sess.entry_fn.borrow().map(|(node_id, _, _)| {
- tcx.hir.local_def_id(node_id)
+ tcx.hir().local_def_id(node_id)
});
debug!("collect_roots: entry_fn = {:?}", entry_fn);
output: &mut roots,
};
- tcx.hir.krate().visit_all_item_likes(&mut visitor);
+ tcx.hir().krate().visit_all_item_likes(&mut visitor);
visitor.push_extra_entry_roots();
}
if recursion_depth > *tcx.sess.recursion_limit.get() {
let error = format!("reached the recursion limit while instantiating `{}`",
instance);
- if let Some(node_id) = tcx.hir.as_local_node_id(def_id) {
- tcx.sess.span_fatal(tcx.hir.span(node_id), &error);
+ if let Some(node_id) = tcx.hir().as_local_node_id(def_id) {
+ tcx.sess.span_fatal(tcx.hir().span(node_id), &error);
} else {
tcx.sess.fatal(&error);
}
let instance_name = instance.to_string();
let msg = format!("reached the type-length limit while instantiating `{:.64}...`",
instance_name);
- let mut diag = if let Some(node_id) = tcx.hir.as_local_node_id(instance.def_id()) {
- tcx.sess.struct_span_fatal(tcx.hir.span(node_id), &msg)
+ let mut diag = if let Some(node_id) = tcx.hir().as_local_node_id(instance.def_id()) {
+ tcx.sess.struct_span_fatal(tcx.hir().span(node_id), &msg)
} else {
tcx.sess.struct_fatal(&msg)
};
ty::InstanceDef::CloneShim(..) => return true
};
- return match tcx.hir.get_if_local(def_id) {
- Some(Node::ForeignItem(..)) => {
- false // foreign items are linked against, not codegened.
- }
- Some(_) => true,
- None => {
- if tcx.is_reachable_non_generic(def_id) ||
- tcx.is_foreign_item(def_id) ||
- is_available_upstream_generic(tcx, def_id, instance.substs)
- {
- // We can link to the item in question, no instance needed
- // in this crate
- false
- } else {
- if !tcx.is_mir_available(def_id) {
- bug!("Cannot create local mono-item for {:?}", def_id)
- }
- true
- }
- }
- };
+ if tcx.is_foreign_item(def_id) {
+ // We can always link to foreign items
+ return false;
+ }
+
+ if def_id.is_local() {
+ // local items cannot be referred to locally without monomorphizing them locally
+ return true;
+ }
+
+ if tcx.is_reachable_non_generic(def_id) ||
+ is_available_upstream_generic(tcx, def_id, instance.substs) {
+ // We can link to the item in question, no instance needed
+ // in this crate
+ return false;
+ }
+
+ if !tcx.is_mir_available(def_id) {
+ bug!("Cannot create local mono-item for {:?}", def_id)
+ }
+ return true;
fn is_available_upstream_generic<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
def_id: DefId,
/// Again, we want this `find_vtable_types_for_unsizing()` to provide the pair
/// `(SomeStruct, SomeTrait)`.
///
-/// Finally, there is also the case of custom unsizing coercions, e.g. for
+/// Finally, there is also the case of custom unsizing coercions, e.g., for
/// smart pointers such as `Rc` and `Arc`.
fn find_vtable_types_for_unsizing<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
source_ty: Ty<'tcx>,
hir::ItemKind::Union(_, ref generics) => {
if generics.params.is_empty() {
if self.mode == MonoItemCollectionMode::Eager {
- let def_id = self.tcx.hir.local_def_id(item.id);
+ let def_id = self.tcx.hir().local_def_id(item.id);
debug!("RootCollector: ADT drop-glue for {}",
def_id_to_string(self.tcx, def_id));
hir::ItemKind::GlobalAsm(..) => {
debug!("RootCollector: ItemKind::GlobalAsm({})",
def_id_to_string(self.tcx,
- self.tcx.hir.local_def_id(item.id)));
+ self.tcx.hir().local_def_id(item.id)));
self.output.push(MonoItem::GlobalAsm(item.id));
}
hir::ItemKind::Static(..) => {
- let def_id = self.tcx.hir.local_def_id(item.id);
+ let def_id = self.tcx.hir().local_def_id(item.id);
debug!("RootCollector: ItemKind::Static({})",
def_id_to_string(self.tcx, def_id));
self.output.push(MonoItem::Static(def_id));
// actually used somewhere. Just declaring them is insufficient.
// but even just declaring them must collect the items they refer to
- let def_id = self.tcx.hir.local_def_id(item.id);
+ let def_id = self.tcx.hir().local_def_id(item.id);
let instance = Instance::mono(self.tcx, def_id);
let cid = GlobalId {
}
}
hir::ItemKind::Fn(..) => {
- let def_id = self.tcx.hir.local_def_id(item.id);
+ let def_id = self.tcx.hir().local_def_id(item.id);
self.push_if_root(def_id);
}
}
fn visit_impl_item(&mut self, ii: &'v hir::ImplItem) {
match ii.node {
hir::ImplItemKind::Method(hir::MethodSig { .. }, _) => {
- let def_id = self.tcx.hir.local_def_id(ii.id);
+ let def_id = self.tcx.hir().local_def_id(ii.id);
self.push_if_root(def_id);
}
_ => { /* Nothing to do here */ }
}
}
- let impl_def_id = tcx.hir.local_def_id(item.id);
+ let impl_def_id = tcx.hir().local_def_id(item.id);
debug!("create_mono_items_for_default_impls(item={})",
def_id_to_string(tcx, impl_def_id));