Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make -Zdump-mir dump shims #58103

Merged
merged 9 commits into from
Feb 10, 2019
7 changes: 5 additions & 2 deletions src/librustc/hir/map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,16 +371,19 @@ impl<'hir> Map<'hir> {
let def_id = self.local_def_id(variant.node.data.id());
Some(Def::Variant(def_id))
}
Node::Field(_) |
Node::StructCtor(variant) => {
let def_id = self.local_def_id(variant.id());
Some(Def::StructCtor(def_id, def::CtorKind::from_hir(variant)))
}
Node::AnonConst(_) |
Node::Field(_) |
Node::Expr(_) |
Node::Stmt(_) |
Node::PathSegment(_) |
Node::Ty(_) |
Node::TraitRef(_) |
Node::Pat(_) |
Node::Binding(_) |
Node::StructCtor(_) |
Node::Lifetime(_) |
Node::Visibility(_) |
Node::Block(_) |
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/borrow_check/nll/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ pub(in crate::borrow_check) fn compute_regions<'cx, 'gcx, 'tcx>(

fn dump_mir_results<'a, 'gcx, 'tcx>(
infcx: &InferCtxt<'a, 'gcx, 'tcx>,
source: MirSource,
source: MirSource<'tcx>,
mir: &Mir<'tcx>,
regioncx: &RegionInferenceContext<'_>,
closure_region_requirements: &Option<ClosureRegionRequirements<'_>>,
Expand Down
9 changes: 7 additions & 2 deletions src/librustc_mir/borrow_check/nll/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2427,8 +2427,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
pub struct TypeckMir;

impl MirPass for TypeckMir {
fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, src: MirSource, mir: &mut Mir<'tcx>) {
let def_id = src.def_id;
fn run_pass<'a, 'tcx>(
&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
src: MirSource<'tcx>,
mir: &mut Mir<'tcx>,
) {
let def_id = src.def_id();
debug!("run_pass: {:?}", def_id);

// When NLL is enabled, the borrow checker runs the typeck
Expand Down
21 changes: 13 additions & 8 deletions src/librustc_mir/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ use syntax_pos::Span;
use std::fmt;
use std::iter;

use crate::transform::{add_moves_for_packed_drops, add_call_guards};
use crate::transform::{remove_noop_landing_pads, no_landing_pads, simplify};
use crate::transform::{
add_moves_for_packed_drops, add_call_guards,
remove_noop_landing_pads, no_landing_pads, simplify, run_passes
};
use crate::util::elaborate_drops::{self, DropElaborator, DropStyle, DropFlagMode};
use crate::util::patch::MirPatch;

Expand Down Expand Up @@ -113,12 +115,15 @@ fn make_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
};
debug!("make_shim({:?}) = untransformed {:?}", instance, result);
add_moves_for_packed_drops::add_moves_for_packed_drops(
tcx, &mut result, instance.def_id());
no_landing_pads::no_landing_pads(tcx, &mut result);
remove_noop_landing_pads::remove_noop_landing_pads(tcx, &mut result);
simplify::simplify_cfg(&mut result);
add_call_guards::CriticalCallEdges.add_call_guards(&mut result);

run_passes(tcx, &mut result, instance, MirPhase::Const, &[
&add_moves_for_packed_drops::AddMovesForPackedDrops,
&no_landing_pads::NoLandingPads,
&remove_noop_landing_pads::RemoveNoopLandingPads,
&simplify::SimplifyCfg::new("make_shim"),
&add_call_guards::CriticalCallEdges,
]);

debug!("make_shim({:?}) = {:?}", instance, result);

tcx.alloc_mir(result)
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/add_call_guards.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub use self::AddCallGuards::*;
impl MirPass for AddCallGuards {
fn run_pass<'a, 'tcx>(&self,
_tcx: TyCtxt<'a, 'tcx, 'tcx>,
_src: MirSource,
_src: MirSource<'tcx>,
mir: &mut Mir<'tcx>) {
self.add_call_guards(mir);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/add_moves_for_packed_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ pub struct AddMovesForPackedDrops;
impl MirPass for AddMovesForPackedDrops {
fn run_pass<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
src: MirSource,
src: MirSource<'tcx>,
mir: &mut Mir<'tcx>)
{
debug!("add_moves_for_packed_drops({:?} @ {:?})", src, mir.span);
add_moves_for_packed_drops(tcx, mir, src.def_id);
add_moves_for_packed_drops(tcx, mir, src.def_id());
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/add_retag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ fn may_have_reference<'a, 'gcx, 'tcx>(ty: Ty<'tcx>, tcx: TyCtxt<'a, 'gcx, 'tcx>)
impl MirPass for AddRetag {
fn run_pass<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
_src: MirSource,
_src: MirSource<'tcx>,
mir: &mut Mir<'tcx>)
{
if !tcx.sess.opts.debugging_opts.mir_emit_retag {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/cleanup_post_borrowck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub struct DeleteAscribeUserType;
impl MirPass for CleanAscribeUserType {
fn run_pass<'a, 'tcx>(&self,
_tcx: TyCtxt<'a, 'tcx, 'tcx>,
_source: MirSource,
_source: MirSource<'tcx>,
mir: &mut Mir<'tcx>) {
let mut delete = DeleteAscribeUserType;
delete.visit_mir(mir);
Expand Down Expand Up @@ -69,7 +69,7 @@ pub struct DeleteFakeBorrows {
impl MirPass for CleanFakeReadsAndBorrows {
fn run_pass<'a, 'tcx>(&self,
_tcx: TyCtxt<'a, 'tcx, 'tcx>,
_source: MirSource,
_source: MirSource<'tcx>,
mir: &mut Mir<'tcx>) {
let mut delete_reads = DeleteAndRecordFakeReads::default();
delete_reads.visit_mir(mir);
Expand Down
40 changes: 20 additions & 20 deletions src/librustc_mir/transform/const_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,31 +30,31 @@ pub struct ConstProp;
impl MirPass for ConstProp {
fn run_pass<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
source: MirSource,
source: MirSource<'tcx>,
mir: &mut Mir<'tcx>) {
// will be evaluated by miri and produce its errors there
if source.promoted.is_some() {
return;
}

use rustc::hir::map::blocks::FnLikeNode;
let node_id = tcx.hir().as_local_node_id(source.def_id)
let node_id = tcx.hir().as_local_node_id(source.def_id())
.expect("Non-local call to local provider is_const_fn");

let is_fn_like = FnLikeNode::from_node(tcx.hir().get(node_id)).is_some();
let is_assoc_const = match tcx.describe_def(source.def_id) {
let is_assoc_const = match tcx.describe_def(source.def_id()) {
Some(Def::AssociatedConst(_)) => true,
_ => false,
};

// Only run const prop on functions, methods, closures and associated constants
if !is_fn_like && !is_assoc_const {
// skip anon_const/statics/consts because they'll be evaluated by miri anyway
trace!("ConstProp skipped for {:?}", source.def_id);
trace!("ConstProp skipped for {:?}", source.def_id());
return
}

trace!("ConstProp starting for {:?}", source.def_id);
trace!("ConstProp starting for {:?}", source.def_id());

// FIXME(oli-obk, eddyb) Optimize locals (or even local paths) to hold
// constants, instead of just checking for const-folding succeeding.
Expand All @@ -63,7 +63,7 @@ impl MirPass for ConstProp {
let mut optimization_finder = ConstPropagator::new(mir, tcx, source);
optimization_finder.visit_mir(mir);

trace!("ConstProp done for {:?}", source.def_id);
trace!("ConstProp done for {:?}", source.def_id());
}
}

Expand All @@ -74,7 +74,7 @@ struct ConstPropagator<'a, 'mir, 'tcx:'a+'mir> {
ecx: EvalContext<'a, 'mir, 'tcx, CompileTimeInterpreter<'a, 'mir, 'tcx>>,
mir: &'mir Mir<'tcx>,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
source: MirSource,
source: MirSource<'tcx>,
places: IndexVec<Local, Option<Const<'tcx>>>,
can_const_prop: IndexVec<Local, bool>,
param_env: ParamEnv<'tcx>,
Expand Down Expand Up @@ -107,10 +107,10 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
fn new(
mir: &'mir Mir<'tcx>,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
source: MirSource,
source: MirSource<'tcx>,
) -> ConstPropagator<'a, 'mir, 'tcx> {
let param_env = tcx.param_env(source.def_id);
let ecx = mk_eval_cx(tcx, tcx.def_span(source.def_id), param_env);
let param_env = tcx.param_env(source.def_id());
let ecx = mk_eval_cx(tcx, tcx.def_span(source.def_id()), param_env);
ConstPropagator {
ecx,
mir,
Expand Down Expand Up @@ -284,13 +284,13 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
_ => None,
},
Place::Promoted(ref promoted) => {
let generics = self.tcx.generics_of(self.source.def_id);
let generics = self.tcx.generics_of(self.source.def_id());
if generics.requires_monomorphization(self.tcx) {
// FIXME: can't handle code with generics
return None;
}
let substs = Substs::identity_for_item(self.tcx, self.source.def_id);
let instance = Instance::new(self.source.def_id, substs);
let substs = Substs::identity_for_item(self.tcx, self.source.def_id());
let instance = Instance::new(self.source.def_id(), substs);
let cid = GlobalId {
instance,
promoted: Some(promoted.0),
Expand Down Expand Up @@ -358,10 +358,10 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
)))
}
Rvalue::UnaryOp(op, ref arg) => {
let def_id = if self.tcx.is_closure(self.source.def_id) {
self.tcx.closure_base_def_id(self.source.def_id)
let def_id = if self.tcx.is_closure(self.source.def_id()) {
self.tcx.closure_base_def_id(self.source.def_id())
} else {
self.source.def_id
self.source.def_id()
};
let generics = self.tcx.generics_of(def_id);
if generics.requires_monomorphization(self.tcx) {
Expand Down Expand Up @@ -398,10 +398,10 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
Rvalue::BinaryOp(op, ref left, ref right) => {
trace!("rvalue binop {:?} for {:?} and {:?}", op, left, right);
let right = self.eval_operand(right, source_info)?;
let def_id = if self.tcx.is_closure(self.source.def_id) {
self.tcx.closure_base_def_id(self.source.def_id)
let def_id = if self.tcx.is_closure(self.source.def_id()) {
self.tcx.closure_base_def_id(self.source.def_id())
} else {
self.source.def_id
self.source.def_id()
};
let generics = self.tcx.generics_of(def_id);
if generics.requires_monomorphization(self.tcx) {
Expand Down Expand Up @@ -608,7 +608,7 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
let node_id = self
.tcx
.hir()
.as_local_node_id(self.source.def_id)
.as_local_node_id(self.source.def_id())
.expect("some part of a failing const eval must be local");
use rustc::mir::interpret::EvalErrorKind::*;
let msg = match msg {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/copy_prop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct CopyPropagation;
impl MirPass for CopyPropagation {
fn run_pass<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
_source: MirSource,
_source: MirSource<'tcx>,
mir: &mut Mir<'tcx>) {
// We only run when the MIR optimization level is > 1.
// This avoids a slow pass, and messing up debug info.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/deaggregator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ pub struct Deaggregator;
impl MirPass for Deaggregator {
fn run_pass<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
_source: MirSource,
_source: MirSource<'tcx>,
mir: &mut Mir<'tcx>) {
let (basic_blocks, local_decls) = mir.basic_blocks_and_local_decls_mut();
let local_decls = &*local_decls;
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_mir/transform/dump_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl MirPass for Marker {

fn run_pass<'a, 'tcx>(&self,
_tcx: TyCtxt<'a, 'tcx, 'tcx>,
_source: MirSource,
_source: MirSource<'tcx>,
_mir: &mut Mir<'tcx>)
{
}
Expand All @@ -41,7 +41,7 @@ impl fmt::Display for Disambiguator {
pub fn on_mir_pass<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
pass_num: &dyn fmt::Display,
pass_name: &str,
source: MirSource,
source: MirSource<'tcx>,
mir: &Mir<'tcx>,
is_after: bool) {
if mir_util::dump_enabled(tcx, pass_name, source) {
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_mir/transform/elaborate_drops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ pub struct ElaborateDrops;
impl MirPass for ElaborateDrops {
fn run_pass<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
src: MirSource,
src: MirSource<'tcx>,
mir: &mut Mir<'tcx>)
{
debug!("elaborate_drops({:?} @ {:?})", src, mir.span);

let id = tcx.hir().as_local_node_id(src.def_id).unwrap();
let param_env = tcx.param_env(src.def_id).with_reveal_all();
let id = tcx.hir().as_local_node_id(src.def_id()).unwrap();
let param_env = tcx.param_env(src.def_id()).with_reveal_all();
let move_data = match MoveData::gather_moves(mir, tcx) {
Ok(move_data) => move_data,
Err((move_data, _move_errors)) => {
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/transform/erase_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub struct EraseRegions;
impl MirPass for EraseRegions {
fn run_pass<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
_: MirSource,
_: MirSource<'tcx>,
mir: &mut Mir<'tcx>) {
EraseRegionsVisitor::new(tcx).visit_mir(mir);
}
Expand Down
14 changes: 7 additions & 7 deletions src/librustc_mir/transform/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -376,14 +376,14 @@ impl<'tcx> Visitor<'tcx> for StorageIgnored {
fn locals_live_across_suspend_points(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
mir: &Mir<'tcx>,
source: MirSource,
source: MirSource<'tcx>,
movable: bool,
) -> (
liveness::LiveVarSet<Local>,
FxHashMap<BasicBlock, liveness::LiveVarSet<Local>>,
) {
let dead_unwinds = BitSet::new_empty(mir.basic_blocks().len());
let node_id = tcx.hir().as_local_node_id(source.def_id).unwrap();
let node_id = tcx.hir().as_local_node_id(source.def_id()).unwrap();

// Calculate when MIR locals have live storage. This gives us an upper bound of their
// lifetimes.
Expand Down Expand Up @@ -484,7 +484,7 @@ fn locals_live_across_suspend_points(
}

fn compute_layout<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
source: MirSource,
source: MirSource<'tcx>,
upvars: Vec<Ty<'tcx>>,
interior: Ty<'tcx>,
movable: bool,
Expand Down Expand Up @@ -635,7 +635,7 @@ fn create_generator_drop_shim<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
transform: &TransformVisitor<'a, 'tcx>,
def_id: DefId,
source: MirSource,
source: MirSource<'tcx>,
gen_ty: Ty<'tcx>,
mir: &Mir<'tcx>,
drop_clean: BasicBlock) -> Mir<'tcx> {
Expand Down Expand Up @@ -758,7 +758,7 @@ fn create_generator_resume_function<'a, 'tcx>(
tcx: TyCtxt<'a, 'tcx, 'tcx>,
transform: TransformVisitor<'a, 'tcx>,
def_id: DefId,
source: MirSource,
source: MirSource<'tcx>,
mir: &mut Mir<'tcx>) {
// Poison the generator when it unwinds
for block in mir.basic_blocks_mut() {
Expand Down Expand Up @@ -869,7 +869,7 @@ fn create_cases<'a, 'tcx, F>(mir: &mut Mir<'tcx>,
impl MirPass for StateTransform {
fn run_pass<'a, 'tcx>(&self,
tcx: TyCtxt<'a, 'tcx, 'tcx>,
source: MirSource,
source: MirSource<'tcx>,
mir: &mut Mir<'tcx>) {
let yield_ty = if let Some(yield_ty) = mir.yield_ty {
yield_ty
Expand All @@ -880,7 +880,7 @@ impl MirPass for StateTransform {

assert!(mir.generator_drop.is_none());

let def_id = source.def_id;
let def_id = source.def_id();

// The first argument is the generator type passed by value
let gen_ty = mir.local_decls.raw[1].ty;
Expand Down
Loading