Skip to content

Commit 3ba9237

Browse files
committed
Update for changes in rustc nightly.
1 parent 82dfa72 commit 3ba9237

File tree

1 file changed

+48
-37
lines changed

1 file changed

+48
-37
lines changed

src/interpreter.rs

+48-37
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
use rustc::infer;
21
use rustc::middle::const_val;
32
use rustc::hir::def_id::DefId;
43
use rustc::mir::mir_map::MirMap;
@@ -25,7 +24,7 @@ const TRACE_EXECUTION: bool = true;
2524

2625
struct GlobalEvalContext<'a, 'tcx: 'a> {
2726
/// The results of the type checker, from rustc.
28-
tcx: &'a TyCtxt<'tcx>,
27+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
2928

3029
/// A mapping from NodeIds to Mir, from rustc. Only contains MIR for crate-local items.
3130
mir_map: &'a MirMap<'tcx>,
@@ -124,7 +123,7 @@ enum TerminatorTarget {
124123
}
125124

126125
impl<'a, 'tcx> GlobalEvalContext<'a, 'tcx> {
127-
fn new(tcx: &'a TyCtxt<'tcx>, mir_map: &'a MirMap<'tcx>) -> Self {
126+
fn new(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir_map: &'a MirMap<'tcx>) -> Self {
128127
GlobalEvalContext {
129128
tcx: tcx,
130129
mir_map: mir_map,
@@ -367,7 +366,7 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
367366
let last_ty = self.operand_ty(last_arg);
368367
let last_layout = self.type_layout(last_ty);
369368
match (&last_ty.sty, last_layout) {
370-
(&ty::TyTuple(ref fields),
369+
(&ty::TyTuple(fields),
371370
&Layout::Univariant { ref variant, .. }) => {
372371
let offsets = iter::once(0)
373372
.chain(variant.offset_after_field.iter()
@@ -1063,7 +1062,7 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
10631062

10641063
fn monomorphize(&self, ty: ty::Ty<'tcx>) -> ty::Ty<'tcx> {
10651064
let substituted = ty.subst(self.tcx, self.substs());
1066-
infer::normalize_associated_type(self.tcx, &substituted)
1065+
self.tcx.normalize_associated_type(&substituted)
10671066
}
10681067

10691068
fn type_needs_drop(&self, ty: ty::Ty<'tcx>) -> bool {
@@ -1080,7 +1079,7 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
10801079
}
10811080

10821081
fn type_is_sized(&self, ty: ty::Ty<'tcx>) -> bool {
1083-
ty.is_sized(&self.tcx.empty_parameter_environment(), DUMMY_SP)
1082+
ty.is_sized(self.tcx, &self.tcx.empty_parameter_environment(), DUMMY_SP)
10841083
}
10851084

10861085
fn type_size(&self, ty: ty::Ty<'tcx>) -> usize {
@@ -1091,10 +1090,10 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
10911090
// TODO(solson): Is this inefficient? Needs investigation.
10921091
let ty = self.monomorphize(ty);
10931092

1094-
let infcx = infer::normalizing_infer_ctxt(self.tcx, &self.tcx.tables, ProjectionMode::Any);
1095-
1096-
// TODO(solson): Report this error properly.
1097-
ty.layout(&infcx).unwrap()
1093+
self.tcx.normalizing_infer_ctxt(ProjectionMode::Any).enter(|infcx| {
1094+
// TODO(solson): Report this error properly.
1095+
ty.layout(&infcx).unwrap()
1096+
})
10981097
}
10991098

11001099
pub fn read_primval(&mut self, ptr: Pointer, ty: ty::Ty<'tcx>) -> EvalResult<PrimVal> {
@@ -1173,30 +1172,31 @@ impl<'a, 'b, 'mir, 'tcx> FnEvalContext<'a, 'b, 'mir, 'tcx> {
11731172
fn fulfill_obligation(&self, trait_ref: ty::PolyTraitRef<'tcx>) -> traits::Vtable<'tcx, ()> {
11741173
// Do the initial selection for the obligation. This yields the shallow result we are
11751174
// looking for -- that is, what specific impl.
1176-
let infcx = infer::normalizing_infer_ctxt(self.tcx, &self.tcx.tables, ProjectionMode::Any);
1177-
let mut selcx = traits::SelectionContext::new(&infcx);
1178-
1179-
let obligation = traits::Obligation::new(
1180-
traits::ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID),
1181-
trait_ref.to_poly_trait_predicate(),
1182-
);
1183-
let selection = selcx.select(&obligation).unwrap().unwrap();
1184-
1185-
// Currently, we use a fulfillment context to completely resolve all nested obligations.
1186-
// This is because they can inform the inference of the impl's type parameters.
1187-
let mut fulfill_cx = traits::FulfillmentContext::new();
1188-
let vtable = selection.map(|predicate| {
1189-
fulfill_cx.register_predicate_obligation(&infcx, predicate);
1190-
});
1191-
infer::drain_fulfillment_cx_or_panic(
1192-
DUMMY_SP, &infcx, &mut fulfill_cx, &vtable
1193-
)
1175+
self.tcx.normalizing_infer_ctxt(ProjectionMode::Any).enter(|infcx| {
1176+
let mut selcx = traits::SelectionContext::new(&infcx);
1177+
1178+
let obligation = traits::Obligation::new(
1179+
traits::ObligationCause::misc(DUMMY_SP, ast::DUMMY_NODE_ID),
1180+
trait_ref.to_poly_trait_predicate(),
1181+
);
1182+
let selection = selcx.select(&obligation).unwrap().unwrap();
1183+
1184+
// Currently, we use a fulfillment context to completely resolve all nested obligations.
1185+
// This is because they can inform the inference of the impl's type parameters.
1186+
let mut fulfill_cx = traits::FulfillmentContext::new();
1187+
let vtable = selection.map(|predicate| {
1188+
fulfill_cx.register_predicate_obligation(&infcx, predicate);
1189+
});
1190+
infcx.drain_fulfillment_cx_or_panic(DUMMY_SP, &mut fulfill_cx, &vtable)
1191+
})
11941192
}
11951193

11961194
/// Trait method, which has to be resolved to an impl method.
1197-
pub fn trait_method(&self, def_id: DefId, substs: &'tcx Substs<'tcx>)
1198-
-> (DefId, &'tcx Substs<'tcx>)
1199-
{
1195+
pub fn trait_method(
1196+
&self,
1197+
def_id: DefId,
1198+
substs: &'tcx Substs<'tcx>
1199+
) -> (DefId, &'tcx Substs<'tcx>) {
12001200
let method_item = self.tcx.impl_or_trait_item(def_id);
12011201
let trait_id = method_item.container().id();
12021202
let trait_ref = ty::Binder(substs.to_trait_ref(self.tcx, trait_id));
@@ -1279,8 +1279,8 @@ pub struct ImplMethod<'tcx> {
12791279
}
12801280

12811281
/// Locates the applicable definition of a method, given its name.
1282-
pub fn get_impl_method<'tcx>(
1283-
tcx: &TyCtxt<'tcx>,
1282+
pub fn get_impl_method<'a, 'tcx>(
1283+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
12841284
impl_def_id: DefId,
12851285
substs: &'tcx Substs<'tcx>,
12861286
name: ast::Name,
@@ -1289,23 +1289,34 @@ pub fn get_impl_method<'tcx>(
12891289

12901290
let trait_def_id = tcx.trait_id_of_impl(impl_def_id).unwrap();
12911291
let trait_def = tcx.lookup_trait_def(trait_def_id);
1292-
let infcx = infer::normalizing_infer_ctxt(tcx, &tcx.tables, ProjectionMode::Any);
12931292

12941293
match trait_def.ancestors(impl_def_id).fn_defs(tcx, name).next() {
12951294
Some(node_item) => {
1295+
let substs = tcx.normalizing_infer_ctxt(ProjectionMode::Any).enter(|infcx| {
1296+
let substs = traits::translate_substs(&infcx, impl_def_id,
1297+
substs, node_item.node);
1298+
tcx.lift(&substs).unwrap_or_else(|| {
1299+
bug!("trans::meth::get_impl_method: translate_substs \
1300+
returned {:?} which contains inference types/regions",
1301+
substs);
1302+
})
1303+
});
12961304
ImplMethod {
12971305
method: node_item.item,
1298-
substs: traits::translate_substs(&infcx, impl_def_id, substs, node_item.node),
1306+
substs: substs,
12991307
is_provided: node_item.node.is_from_trait(),
13001308
}
13011309
}
13021310
None => {
1303-
bug!("method {:?} not found in {:?}", name, impl_def_id);
1311+
bug!("method {:?} not found in {:?}", name, impl_def_id)
13041312
}
13051313
}
13061314
}
13071315

1308-
pub fn interpret_start_points<'tcx>(tcx: &TyCtxt<'tcx>, mir_map: &MirMap<'tcx>) {
1316+
pub fn interpret_start_points<'a, 'tcx>(
1317+
tcx: TyCtxt<'a, 'tcx, 'tcx>,
1318+
mir_map: &MirMap<'tcx>,
1319+
) {
13091320
for (&id, mir) in &mir_map.map {
13101321
for attr in tcx.map.attrs(id) {
13111322
use syntax::attr::AttrMetaMethods;

0 commit comments

Comments
 (0)