use rustc::mir::interpret::{AllocId, ConstValue};
use rustc::middle::lang_items::{ExchangeMallocFnLangItem, StartFnLangItem};
use rustc::ty::subst::{InternalSubsts, SubstsRef};
-use rustc::ty::{self, TypeFoldable, Ty, TyCtxt, GenericParamDefKind};
+use rustc::ty::{self, TypeFoldable, Ty, TyCtxt, GenericParamDefKind, Instance};
+use rustc::ty::print::obsolete::DefPathBasedNames;
use rustc::ty::adjustment::{CustomCoerceUnsized, PointerCast};
use rustc::session::config::EntryFnType;
-use rustc::mir::{self, Location, Place, PlaceBase, Promoted, Static, StaticKind};
+use rustc::mir::{self, Location, PlaceBase, Promoted, Static, StaticKind};
use rustc::mir::visit::Visitor as MirVisitor;
-use rustc::mir::mono::MonoItem;
-use rustc::mir::interpret::{Scalar, GlobalId, AllocKind, ErrorHandled};
+use rustc::mir::mono::{MonoItem, InstantiationMode};
+use rustc::mir::interpret::{Scalar, GlobalId, GlobalAlloc, ErrorHandled};
-use crate::monomorphize::{self, Instance};
+use crate::monomorphize;
use rustc::util::nodemap::{FxHashSet, FxHashMap, DefIdMap};
use rustc::util::common::time;
-use crate::monomorphize::item::{MonoItemExt, DefPathBasedNames, InstantiationMode};
-
use rustc_data_structures::bit_set::GrowableBitSet;
use rustc_data_structures::sync::{MTRef, MTLock, ParallelIterator, par_iter};
struct MirNeighborCollector<'a, 'tcx: 'a> {
tcx: TyCtxt<'a, 'tcx, 'tcx>,
- mir: &'a mir::Body<'tcx>,
+ body: &'a mir::Body<'tcx>,
output: &'a mut Vec<MonoItem<'tcx>>,
param_substs: SubstsRef<'tcx>,
}
ty::ParamEnv::reveal_all(),
&target_ty,
);
- let source_ty = operand.ty(self.mir, self.tcx);
+ let source_ty = operand.ty(self.body, self.tcx);
let source_ty = self.tcx.subst_and_normalize_erasing_regions(
self.param_substs,
ty::ParamEnv::reveal_all(),
mir::Rvalue::Cast(
mir::CastKind::Pointer(PointerCast::ReifyFnPointer), ref operand, _
) => {
- let fn_ty = operand.ty(self.mir, self.tcx);
+ let fn_ty = operand.ty(self.body, self.tcx);
let fn_ty = self.tcx.subst_and_normalize_erasing_regions(
self.param_substs,
ty::ParamEnv::reveal_all(),
mir::Rvalue::Cast(
mir::CastKind::Pointer(PointerCast::ClosureFnPointer(_)), ref operand, _
) => {
- let source_ty = operand.ty(self.mir, self.tcx);
+ let source_ty = operand.ty(self.body, self.tcx);
let source_ty = self.tcx.subst_and_normalize_erasing_regions(
self.param_substs,
ty::ParamEnv::reveal_all(),
);
match source_ty.sty {
ty::Closure(def_id, substs) => {
- let instance = monomorphize::resolve_closure(
+ let instance = Instance::resolve_closure(
self.tcx, def_id, substs, ty::ClosureKind::FnOnce);
if should_monomorphize_locally(self.tcx, &instance) {
self.output.push(create_fn_mono_item(instance));
let tcx = self.tcx;
match *kind {
mir::TerminatorKind::Call { ref func, .. } => {
- let callee_ty = func.ty(self.mir, tcx);
+ let callee_ty = func.ty(self.body, tcx);
let callee_ty = tcx.subst_and_normalize_erasing_regions(
self.param_substs,
ty::ParamEnv::reveal_all(),
}
mir::TerminatorKind::Drop { ref location, .. } |
mir::TerminatorKind::DropAndReplace { ref location, .. } => {
- let ty = location.ty(self.mir, self.tcx).ty;
+ let ty = location.ty(self.body, self.tcx).ty;
let ty = tcx.subst_and_normalize_erasing_regions(
self.param_substs,
ty::ParamEnv::reveal_all(),
self.super_terminator_kind(kind, location);
}
- fn visit_place(&mut self,
- place: &mir::Place<'tcx>,
- context: mir::visit::PlaceContext,
- location: Location) {
- match place {
- Place::Base(
- PlaceBase::Static(box Static{ kind:StaticKind::Static(def_id), .. })
- ) => {
+ fn visit_place_base(&mut self,
+ place_base: &mir::PlaceBase<'tcx>,
+ _context: mir::visit::PlaceContext,
+ location: Location) {
+ match place_base {
+ PlaceBase::Static(box Static { kind: StaticKind::Static(def_id), .. }) => {
debug!("visiting static {:?} @ {:?}", def_id, location);
let tcx = self.tcx;
self.output.push(MonoItem::Static(*def_id));
}
}
- _ => {}
+ PlaceBase::Static(box Static { kind: StaticKind::Promoted(_), .. }) => {
+ // FIXME: should we handle promoteds here instead of eagerly in collect_neighbours?
+ }
+ PlaceBase::Local(_) => {
+ // Locals have no relevance for collector
+ }
}
-
- self.super_place(place, context, location);
}
}
is_direct_call: bool,
output: &mut Vec<MonoItem<'tcx>>)
{
- let instance = monomorphize::resolve_drop_in_place(tcx, ty);
+ let instance = Instance::resolve_drop_in_place(tcx, ty);
visit_instance_use(tcx, instance, is_direct_call, output);
}
) {
let alloc_kind = tcx.alloc_map.lock().get(alloc_id);
match alloc_kind {
- Some(AllocKind::Static(did)) => {
- let instance = Instance::mono(tcx, did);
+ Some(GlobalAlloc::Static(def_id)) => {
+ let instance = Instance::mono(tcx, def_id);
if should_monomorphize_locally(tcx, &instance) {
- trace!("collecting static {:?}", did);
- output.push(MonoItem::Static(did));
+ trace!("collecting static {:?}", def_id);
+ output.push(MonoItem::Static(def_id));
}
}
- Some(AllocKind::Memory(alloc)) => {
+ Some(GlobalAlloc::Memory(alloc)) => {
trace!("collecting {:?} with {:#?}", alloc_id, alloc);
for &((), inner) in alloc.relocations.values() {
collect_miri(tcx, inner, output);
}
},
- Some(AllocKind::Function(fn_instance)) => {
+ Some(GlobalAlloc::Function(fn_instance)) => {
if should_monomorphize_locally(tcx, &fn_instance) {
trace!("collecting {:?} with {:#?}", alloc_id, fn_instance);
output.push(create_fn_mono_item(fn_instance));
instance: Instance<'tcx>,
output: &mut Vec<MonoItem<'tcx>>)
{
- let mir = tcx.instance_mir(instance.def);
+ let body = tcx.instance_mir(instance.def);
MirNeighborCollector {
tcx,
- mir: &mir,
+ body: &body,
output,
param_substs: instance.substs,
- }.visit_body(&mir);
+ }.visit_body(&body);
let param_env = ty::ParamEnv::reveal_all();
- for i in 0..mir.promoted.len() {
+ for i in 0..body.promoted.len() {
use rustc_data_structures::indexed_vec::Idx;
let i = Promoted::new(i);
let cid = GlobalId {
Ok(val) => collect_const(tcx, val, instance.substs, output),
Err(ErrorHandled::Reported) => {},
Err(ErrorHandled::TooGeneric) => span_bug!(
- mir.promoted[i].span, "collection encountered polymorphic constant",
+ body.promoted[i].span, "collection encountered polymorphic constant",
),
}
}
collect_miri(tcx, id, output);
}
}
- ConstValue::Unevaluated(did, substs) => {
+ ConstValue::Unevaluated(def_id, substs) => {
let param_env = ty::ParamEnv::reveal_all();
let substs = tcx.subst_and_normalize_erasing_regions(
param_substs,
);
let instance = ty::Instance::resolve(tcx,
param_env,
- did,
+ def_id,
substs).unwrap();
let cid = GlobalId {
Ok(val) => collect_const(tcx, val, param_substs, output),
Err(ErrorHandled::Reported) => {},
Err(ErrorHandled::TooGeneric) => span_bug!(
- tcx.def_span(did), "collection encountered polymorphic constant",
+ tcx.def_span(def_id), "collection encountered polymorphic constant",
),
}
}