Skip to content

Commit 956e2f8

Browse files
committed
add some instrumentation
1 parent a561ea7 commit 956e2f8

File tree

3 files changed

+189
-134
lines changed

3 files changed

+189
-134
lines changed

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

+77-63
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,18 @@ use borrow_check::nll::renumber;
2121
use borrow_check::nll::universal_regions::UniversalRegions;
2222
use rustc::hir::def_id::DefId;
2323
use rustc::infer::InferOk;
24-
use rustc::ty::Ty;
25-
use rustc::ty::subst::Subst;
26-
use rustc::mir::*;
2724
use rustc::mir::visit::TyContext;
25+
use rustc::mir::*;
2826
use rustc::traits::PredicateObligations;
27+
use rustc::ty::subst::Subst;
28+
use rustc::ty::Ty;
2929

3030
use rustc_data_structures::indexed_vec::Idx;
3131

3232
use super::{Locations, TypeChecker};
3333

3434
impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
35+
#[inline(never)]
3536
pub(super) fn equate_inputs_and_outputs(
3637
&mut self,
3738
mir: &Mir<'tcx>,
@@ -56,8 +57,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
5657
}
5758

5859
assert!(
59-
mir.yield_ty.is_some() && universal_regions.yield_ty.is_some() ||
60-
mir.yield_ty.is_none() && universal_regions.yield_ty.is_none()
60+
mir.yield_ty.is_some() && universal_regions.yield_ty.is_some()
61+
|| mir.yield_ty.is_none() && universal_regions.yield_ty.is_none()
6162
);
6263
if let Some(mir_yield_ty) = mir.yield_ty {
6364
let ur_yield_ty = universal_regions.yield_ty.unwrap();
@@ -76,57 +77,66 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
7677
output_ty
7778
);
7879
let mir_output_ty = mir.local_decls[RETURN_PLACE].ty;
79-
let anon_type_map = self.fully_perform_op(Locations::All, |cx| {
80-
let mut obligations = ObligationAccumulator::default();
81-
82-
let (output_ty, anon_type_map) = obligations.add(infcx.instantiate_anon_types(
83-
mir_def_id,
84-
cx.body_id,
85-
cx.param_env,
86-
&output_ty,
87-
));
88-
debug!(
89-
"equate_inputs_and_outputs: instantiated output_ty={:?}",
90-
output_ty
91-
);
92-
debug!(
93-
"equate_inputs_and_outputs: anon_type_map={:#?}",
94-
anon_type_map
95-
);
96-
97-
debug!(
98-
"equate_inputs_and_outputs: mir_output_ty={:?}",
99-
mir_output_ty
100-
);
101-
obligations.add(infcx
102-
.at(&cx.misc(cx.last_span), cx.param_env)
103-
.eq(output_ty, mir_output_ty)?);
104-
105-
for (&anon_def_id, anon_decl) in &anon_type_map {
106-
let anon_defn_ty = tcx.type_of(anon_def_id);
107-
let anon_defn_ty = anon_defn_ty.subst(tcx, anon_decl.substs);
108-
let anon_defn_ty = renumber::renumber_regions(
109-
cx.infcx,
110-
TyContext::Location(Location::START),
111-
&anon_defn_ty,
112-
);
113-
debug!(
114-
"equate_inputs_and_outputs: concrete_ty={:?}",
115-
anon_decl.concrete_ty
116-
);
117-
debug!("equate_inputs_and_outputs: anon_defn_ty={:?}", anon_defn_ty);
118-
obligations.add(infcx
119-
.at(&cx.misc(cx.last_span), cx.param_env)
120-
.eq(anon_decl.concrete_ty, anon_defn_ty)?);
121-
}
122-
123-
debug!("equate_inputs_and_outputs: equated");
124-
125-
Ok(InferOk {
126-
value: Some(anon_type_map),
127-
obligations: obligations.into_vec(),
128-
})
129-
}).unwrap_or_else(|terr| {
80+
let anon_type_map =
81+
self.fully_perform_op(
82+
Locations::All,
83+
|| format!("input_output"),
84+
|cx| {
85+
let mut obligations = ObligationAccumulator::default();
86+
87+
let (output_ty, anon_type_map) = obligations.add(infcx.instantiate_anon_types(
88+
mir_def_id,
89+
cx.body_id,
90+
cx.param_env,
91+
&output_ty,
92+
));
93+
debug!(
94+
"equate_inputs_and_outputs: instantiated output_ty={:?}",
95+
output_ty
96+
);
97+
debug!(
98+
"equate_inputs_and_outputs: anon_type_map={:#?}",
99+
anon_type_map
100+
);
101+
102+
debug!(
103+
"equate_inputs_and_outputs: mir_output_ty={:?}",
104+
mir_output_ty
105+
);
106+
obligations.add(
107+
infcx
108+
.at(&cx.misc(cx.last_span), cx.param_env)
109+
.eq(output_ty, mir_output_ty)?,
110+
);
111+
112+
for (&anon_def_id, anon_decl) in &anon_type_map {
113+
let anon_defn_ty = tcx.type_of(anon_def_id);
114+
let anon_defn_ty = anon_defn_ty.subst(tcx, anon_decl.substs);
115+
let anon_defn_ty = renumber::renumber_regions(
116+
cx.infcx,
117+
TyContext::Location(Location::START),
118+
&anon_defn_ty,
119+
);
120+
debug!(
121+
"equate_inputs_and_outputs: concrete_ty={:?}",
122+
anon_decl.concrete_ty
123+
);
124+
debug!("equate_inputs_and_outputs: anon_defn_ty={:?}", anon_defn_ty);
125+
obligations.add(
126+
infcx
127+
.at(&cx.misc(cx.last_span), cx.param_env)
128+
.eq(anon_decl.concrete_ty, anon_defn_ty)?,
129+
);
130+
}
131+
132+
debug!("equate_inputs_and_outputs: equated");
133+
134+
Ok(InferOk {
135+
value: Some(anon_type_map),
136+
obligations: obligations.into_vec(),
137+
})
138+
},
139+
).unwrap_or_else(|terr| {
130140
span_mirbug!(
131141
self,
132142
Location::START,
@@ -143,13 +153,17 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
143153
// prove that `T: Iterator` where `T` is the type we
144154
// instantiated it with).
145155
if let Some(anon_type_map) = anon_type_map {
146-
self.fully_perform_op(Locations::All, |_cx| {
147-
infcx.constrain_anon_types(&anon_type_map, universal_regions);
148-
Ok(InferOk {
149-
value: (),
150-
obligations: vec![],
151-
})
152-
}).unwrap();
156+
self.fully_perform_op(
157+
Locations::All,
158+
|| format!("anon_type_map"),
159+
|_cx| {
160+
infcx.constrain_anon_types(&anon_type_map, universal_regions);
161+
Ok(InferOk {
162+
value: (),
163+
obligations: vec![],
164+
})
165+
},
166+
).unwrap();
153167
}
154168
}
155169

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

+39-32
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use dataflow::{FlowAtLocation, FlowsAtLocation};
1211
use borrow_check::nll::region_infer::Cause;
13-
use dataflow::MaybeInitializedPlaces;
12+
use borrow_check::nll::type_check::AtLocation;
1413
use dataflow::move_paths::{HasMoveData, MoveData};
15-
use rustc::mir::{BasicBlock, Location, Mir};
14+
use dataflow::MaybeInitializedPlaces;
15+
use dataflow::{FlowAtLocation, FlowsAtLocation};
16+
use rustc::infer::InferOk;
1617
use rustc::mir::Local;
18+
use rustc::mir::{BasicBlock, Location, Mir};
1719
use rustc::ty::{Ty, TyCtxt, TypeFoldable};
18-
use rustc::infer::InferOk;
19-
use borrow_check::nll::type_check::AtLocation;
2020
use util::liveness::LivenessResults;
2121

2222
use super::TypeChecker;
@@ -170,6 +170,7 @@ impl<'gen, 'typeck, 'flow, 'gcx, 'tcx> TypeLivenessGenerator<'gen, 'typeck, 'flo
170170
/// the regions in its type must be live at `location`. The
171171
/// precise set will depend on the dropck constraints, and in
172172
/// particular this takes `#[may_dangle]` into account.
173+
#[inline(never)]
173174
fn add_drop_live_constraint(
174175
&mut self,
175176
dropped_local: Local,
@@ -191,33 +192,39 @@ impl<'gen, 'typeck, 'flow, 'gcx, 'tcx> TypeLivenessGenerator<'gen, 'typeck, 'flo
191192
//
192193
// For this reason, we avoid calling TypeChecker.normalize, instead doing all normalization
193194
// ourselves in one large 'fully_perform_op' callback.
194-
let kind_constraints = self.cx
195-
.fully_perform_op(location.at_self(), |cx| {
196-
let span = cx.last_span;
197-
198-
let mut final_obligations = Vec::new();
199-
let mut kind_constraints = Vec::new();
200-
201-
let InferOk {
202-
value: kinds,
203-
obligations,
204-
} = cx.infcx
205-
.at(&cx.misc(span), cx.param_env)
206-
.dropck_outlives(dropped_ty);
207-
for kind in kinds {
208-
// All things in the `outlives` array may be touched by
209-
// the destructor and must be live at this point.
210-
let cause = Cause::DropVar(dropped_local, location);
211-
kind_constraints.push((kind, location, cause));
212-
}
213-
214-
final_obligations.extend(obligations);
215-
216-
Ok(InferOk {
217-
value: kind_constraints,
218-
obligations: final_obligations,
219-
})
220-
})
195+
let kind_constraints = self
196+
.cx
197+
.fully_perform_op(
198+
location.at_self(),
199+
|| format!("add_drop_live_constraint(dropped_ty={:?})", dropped_ty),
200+
|cx| {
201+
let span = cx.last_span;
202+
203+
let mut final_obligations = Vec::new();
204+
let mut kind_constraints = Vec::new();
205+
206+
let InferOk {
207+
value: kinds,
208+
obligations,
209+
} = cx
210+
.infcx
211+
.at(&cx.misc(span), cx.param_env)
212+
.dropck_outlives(dropped_ty);
213+
for kind in kinds {
214+
// All things in the `outlives` array may be touched by
215+
// the destructor and must be live at this point.
216+
let cause = Cause::DropVar(dropped_local, location);
217+
kind_constraints.push((kind, location, cause));
218+
}
219+
220+
final_obligations.extend(obligations);
221+
222+
Ok(InferOk {
223+
value: kind_constraints,
224+
obligations: final_obligations,
225+
})
226+
},
227+
)
221228
.unwrap();
222229

223230
for (kind, location, cause) in kind_constraints {

0 commit comments

Comments
 (0)