Skip to content

Commit 2708946

Browse files
committed
pass full InstanceDef to run_passes
1 parent cd21696 commit 2708946

File tree

12 files changed

+60
-55
lines changed

12 files changed

+60
-55
lines changed

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2428,7 +2428,7 @@ pub struct TypeckMir;
24282428

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

24342434
// When NLL is enabled, the borrow checker runs the typeck

src/librustc_mir/shim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ fn make_shim<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
116116
};
117117
debug!("make_shim({:?}) = untransformed {:?}", instance, result);
118118

119-
run_passes(tcx, &mut result, instance.def_id(), MirPhase::Const, &[
119+
run_passes(tcx, &mut result, instance, MirPhase::Const, &[
120120
&add_moves_for_packed_drops::AddMovesForPackedDrops,
121121
&no_landing_pads::NoLandingPads,
122122
&remove_noop_landing_pads::RemoveNoopLandingPads,

src/librustc_mir/transform/add_moves_for_packed_drops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl MirPass for AddMovesForPackedDrops {
4646
mir: &mut Mir<'tcx>)
4747
{
4848
debug!("add_moves_for_packed_drops({:?} @ {:?})", src, mir.span);
49-
add_moves_for_packed_drops(tcx, mir, src.def_id);
49+
add_moves_for_packed_drops(tcx, mir, src.def_id());
5050
}
5151
}
5252

src/librustc_mir/transform/const_prop.rs

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -30,31 +30,31 @@ pub struct ConstProp;
3030
impl MirPass for ConstProp {
3131
fn run_pass<'a, 'tcx>(&self,
3232
tcx: TyCtxt<'a, 'tcx, 'tcx>,
33-
source: MirSource,
33+
source: MirSource<'tcx>,
3434
mir: &mut Mir<'tcx>) {
3535
// will be evaluated by miri and produce its errors there
3636
if source.promoted.is_some() {
3737
return;
3838
}
3939

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

4444
let is_fn_like = FnLikeNode::from_node(tcx.hir().get(node_id)).is_some();
45-
let is_assoc_const = match tcx.describe_def(source.def_id) {
45+
let is_assoc_const = match tcx.describe_def(source.def_id()) {
4646
Some(Def::AssociatedConst(_)) => true,
4747
_ => false,
4848
};
4949

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

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

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

66-
trace!("ConstProp done for {:?}", source.def_id);
66+
trace!("ConstProp done for {:?}", source.def_id());
6767
}
6868
}
6969

@@ -74,7 +74,7 @@ struct ConstPropagator<'a, 'mir, 'tcx:'a+'mir> {
7474
ecx: EvalContext<'a, 'mir, 'tcx, CompileTimeInterpreter<'a, 'mir, 'tcx>>,
7575
mir: &'mir Mir<'tcx>,
7676
tcx: TyCtxt<'a, 'tcx, 'tcx>,
77-
source: MirSource,
77+
source: MirSource<'tcx>,
7878
places: IndexVec<Local, Option<Const<'tcx>>>,
7979
can_const_prop: IndexVec<Local, bool>,
8080
param_env: ParamEnv<'tcx>,
@@ -107,10 +107,10 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
107107
fn new(
108108
mir: &'mir Mir<'tcx>,
109109
tcx: TyCtxt<'a, 'tcx, 'tcx>,
110-
source: MirSource,
110+
source: MirSource<'tcx>,
111111
) -> ConstPropagator<'a, 'mir, 'tcx> {
112-
let param_env = tcx.param_env(source.def_id);
113-
let ecx = mk_eval_cx(tcx, tcx.def_span(source.def_id), param_env);
112+
let param_env = tcx.param_env(source.def_id());
113+
let ecx = mk_eval_cx(tcx, tcx.def_span(source.def_id()), param_env);
114114
ConstPropagator {
115115
ecx,
116116
mir,
@@ -284,13 +284,13 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
284284
_ => None,
285285
},
286286
Place::Promoted(ref promoted) => {
287-
let generics = self.tcx.generics_of(self.source.def_id);
287+
let generics = self.tcx.generics_of(self.source.def_id());
288288
if generics.requires_monomorphization(self.tcx) {
289289
// FIXME: can't handle code with generics
290290
return None;
291291
}
292-
let substs = Substs::identity_for_item(self.tcx, self.source.def_id);
293-
let instance = Instance::new(self.source.def_id, substs);
292+
let substs = Substs::identity_for_item(self.tcx, self.source.def_id());
293+
let instance = Instance::new(self.source.def_id(), substs);
294294
let cid = GlobalId {
295295
instance,
296296
promoted: Some(promoted.0),
@@ -358,10 +358,10 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
358358
)))
359359
}
360360
Rvalue::UnaryOp(op, ref arg) => {
361-
let def_id = if self.tcx.is_closure(self.source.def_id) {
362-
self.tcx.closure_base_def_id(self.source.def_id)
361+
let def_id = if self.tcx.is_closure(self.source.def_id()) {
362+
self.tcx.closure_base_def_id(self.source.def_id())
363363
} else {
364-
self.source.def_id
364+
self.source.def_id()
365365
};
366366
let generics = self.tcx.generics_of(def_id);
367367
if generics.requires_monomorphization(self.tcx) {
@@ -398,10 +398,10 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
398398
Rvalue::BinaryOp(op, ref left, ref right) => {
399399
trace!("rvalue binop {:?} for {:?} and {:?}", op, left, right);
400400
let right = self.eval_operand(right, source_info)?;
401-
let def_id = if self.tcx.is_closure(self.source.def_id) {
402-
self.tcx.closure_base_def_id(self.source.def_id)
401+
let def_id = if self.tcx.is_closure(self.source.def_id()) {
402+
self.tcx.closure_base_def_id(self.source.def_id())
403403
} else {
404-
self.source.def_id
404+
self.source.def_id()
405405
};
406406
let generics = self.tcx.generics_of(def_id);
407407
if generics.requires_monomorphization(self.tcx) {
@@ -608,7 +608,7 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
608608
let node_id = self
609609
.tcx
610610
.hir()
611-
.as_local_node_id(self.source.def_id)
611+
.as_local_node_id(self.source.def_id())
612612
.expect("some part of a failing const eval must be local");
613613
use rustc::mir::interpret::EvalErrorKind::*;
614614
let msg = match msg {

src/librustc_mir/transform/elaborate_drops.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ impl MirPass for ElaborateDrops {
2828
{
2929
debug!("elaborate_drops({:?} @ {:?})", src, mir.span);
3030

31-
let id = tcx.hir().as_local_node_id(src.def_id).unwrap();
32-
let param_env = tcx.param_env(src.def_id).with_reveal_all();
31+
let id = tcx.hir().as_local_node_id(src.def_id()).unwrap();
32+
let param_env = tcx.param_env(src.def_id()).with_reveal_all();
3333
let move_data = match MoveData::gather_moves(mir, tcx) {
3434
Ok(move_data) => move_data,
3535
Err((move_data, _move_errors)) => {

src/librustc_mir/transform/generator.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ fn locals_live_across_suspend_points(
383383
FxHashMap<BasicBlock, liveness::LiveVarSet<Local>>,
384384
) {
385385
let dead_unwinds = BitSet::new_empty(mir.basic_blocks().len());
386-
let node_id = tcx.hir().as_local_node_id(source.def_id).unwrap();
386+
let node_id = tcx.hir().as_local_node_id(source.def_id()).unwrap();
387387

388388
// Calculate when MIR locals have live storage. This gives us an upper bound of their
389389
// lifetimes.
@@ -880,7 +880,7 @@ impl MirPass for StateTransform {
880880

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

883-
let def_id = source.def_id;
883+
let def_id = source.def_id();
884884

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

src/librustc_mir/transform/inline.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ struct CallSite<'tcx> {
4040
impl MirPass for Inline {
4141
fn run_pass<'a, 'tcx>(&self,
4242
tcx: TyCtxt<'a, 'tcx, 'tcx>,
43-
source: MirSource,
43+
source: MirSource<'tcx>,
4444
mir: &mut Mir<'tcx>) {
4545
if tcx.sess.opts.debugging_opts.mir_opt_level >= 2 {
4646
Inliner { tcx, source }.run_pass(mir);
@@ -50,7 +50,7 @@ impl MirPass for Inline {
5050

5151
struct Inliner<'a, 'tcx: 'a> {
5252
tcx: TyCtxt<'a, 'tcx, 'tcx>,
53-
source: MirSource,
53+
source: MirSource<'tcx>,
5454
}
5555

5656
impl<'a, 'tcx> Inliner<'a, 'tcx> {
@@ -69,10 +69,10 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
6969

7070
let mut callsites = VecDeque::new();
7171

72-
let param_env = self.tcx.param_env(self.source.def_id);
72+
let param_env = self.tcx.param_env(self.source.def_id());
7373

7474
// Only do inlining into fn bodies.
75-
let id = self.tcx.hir().as_local_node_id(self.source.def_id).unwrap();
75+
let id = self.tcx.hir().as_local_node_id(self.source.def_id()).unwrap();
7676
if self.tcx.hir().body_owner_kind(id).is_fn_or_closure() && self.source.promoted.is_none() {
7777
for (bb, bb_data) in caller_mir.basic_blocks().iter_enumerated() {
7878
if let Some(callsite) = self.get_valid_function_call(bb,
@@ -274,7 +274,7 @@ impl<'a, 'tcx> Inliner<'a, 'tcx> {
274274

275275
// FIXME: Give a bonus to functions with only a single caller
276276

277-
let param_env = tcx.param_env(self.source.def_id);
277+
let param_env = tcx.param_env(self.source.def_id());
278278

279279
let mut first_block = true;
280280
let mut cost = 0;

src/librustc_mir/transform/mod.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use crate::borrow_check::nll::type_check;
22
use crate::build;
33
use rustc::hir::def_id::{CrateNum, DefId, LOCAL_CRATE};
44
use rustc::mir::{Mir, MirPhase, Promoted};
5-
use rustc::ty::TyCtxt;
5+
use rustc::ty::{TyCtxt, InstanceDef};
66
use rustc::ty::query::Providers;
77
use rustc::ty::steal::Steal;
88
use rustc::hir;
@@ -104,20 +104,25 @@ fn mir_built<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Stea
104104

105105
/// Where a specific Mir comes from.
106106
#[derive(Debug, Copy, Clone)]
107-
pub struct MirSource {
108-
pub def_id: DefId,
107+
pub struct MirSource<'tcx> {
108+
pub instance: InstanceDef<'tcx>,
109109

110110
/// If `Some`, this is a promoted rvalue within the parent function.
111111
pub promoted: Option<Promoted>,
112112
}
113113

114-
impl MirSource {
114+
impl<'tcx> MirSource<'tcx> {
115115
pub fn item(def_id: DefId) -> Self {
116116
MirSource {
117-
def_id,
117+
instance: InstanceDef::Item(def_id),
118118
promoted: None
119119
}
120120
}
121+
122+
#[inline]
123+
pub fn def_id(&self) -> DefId {
124+
self.instance.def_id()
125+
}
121126
}
122127

123128
/// Generates a default name for the pass based on the name of the
@@ -141,14 +146,14 @@ pub trait MirPass {
141146

142147
fn run_pass<'a, 'tcx>(&self,
143148
tcx: TyCtxt<'a, 'tcx, 'tcx>,
144-
source: MirSource,
149+
source: MirSource<'tcx>,
145150
mir: &mut Mir<'tcx>);
146151
}
147152

148153
pub fn run_passes(
149154
tcx: TyCtxt<'a, 'tcx, 'tcx>,
150155
mir: &mut Mir<'tcx>,
151-
def_id: DefId,
156+
instance: InstanceDef<'tcx>,
152157
mir_phase: MirPhase,
153158
passes: &[&dyn MirPass],
154159
) {
@@ -160,7 +165,7 @@ pub fn run_passes(
160165
}
161166

162167
let source = MirSource {
163-
def_id,
168+
instance,
164169
promoted,
165170
};
166171
let mut index = 0;
@@ -198,7 +203,7 @@ fn mir_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx Stea
198203
let _ = tcx.unsafety_check_result(def_id);
199204

200205
let mut mir = tcx.mir_built(def_id).steal();
201-
run_passes(tcx, &mut mir, def_id, MirPhase::Const, &[
206+
run_passes(tcx, &mut mir, InstanceDef::Item(def_id), MirPhase::Const, &[
202207
// What we need to do constant evaluation.
203208
&simplify::SimplifyCfg::new("initial"),
204209
&type_check::TypeckMir,
@@ -217,7 +222,7 @@ fn mir_validated<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
217222
}
218223

219224
let mut mir = tcx.mir_const(def_id).steal();
220-
run_passes(tcx, &mut mir, def_id, MirPhase::Validated, &[
225+
run_passes(tcx, &mut mir, InstanceDef::Item(def_id), MirPhase::Validated, &[
221226
// What we need to run borrowck etc.
222227
&qualify_consts::QualifyAndPromoteConstants,
223228
&simplify::SimplifyCfg::new("qualify-consts"),
@@ -235,7 +240,7 @@ fn optimized_mir<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> &'tcx
235240
}
236241

237242
let mut mir = tcx.mir_validated(def_id).steal();
238-
run_passes(tcx, &mut mir, def_id, MirPhase::Optimized, &[
243+
run_passes(tcx, &mut mir, InstanceDef::Item(def_id), MirPhase::Optimized, &[
239244
// Remove all things not needed by analysis
240245
&no_landing_pads::NoLandingPads,
241246
&simplify_branches::SimplifyBranches::new("initial"),

src/librustc_mir/transform/qualify_consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ impl MirPass for QualifyAndPromoteConstants {
11711171
return;
11721172
}
11731173

1174-
let def_id = src.def_id;
1174+
let def_id = src.def_id();
11751175
let id = tcx.hir().as_local_node_id(def_id).unwrap();
11761176
let mut const_promoted_temps = None;
11771177
let mode = match tcx.hir().body_owner_kind(id) {

src/librustc_mir/transform/rustc_peek.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct SanityCheck;
2525
impl MirPass for SanityCheck {
2626
fn run_pass<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
2727
src: MirSource, mir: &mut Mir<'tcx>) {
28-
let def_id = src.def_id;
28+
let def_id = src.def_id();
2929
let id = tcx.hir().as_local_node_id(def_id).unwrap();
3030
if !tcx.has_attr(def_id, "rustc_mir") {
3131
debug!("skipping rustc_peek::SanityCheck on {}", tcx.item_path_str(def_id));

0 commit comments

Comments
 (0)