Update for changes in rustc master.
This commit is contained in:
parent
62294d0c42
commit
1861dbc2ab
1 changed files with 46 additions and 10 deletions
|
@ -1,12 +1,13 @@
|
||||||
use arena::TypedArena;
|
use arena::TypedArena;
|
||||||
|
use rustc::infer;
|
||||||
use rustc::middle::const_eval;
|
use rustc::middle::const_eval;
|
||||||
use rustc::middle::def_id::DefId;
|
use rustc::middle::def_id::DefId;
|
||||||
use rustc::middle::infer;
|
|
||||||
use rustc::middle::subst::{self, Subst, Substs};
|
|
||||||
use rustc::middle::traits;
|
|
||||||
use rustc::middle::ty::{self, TyCtxt};
|
|
||||||
use rustc::mir::mir_map::MirMap;
|
use rustc::mir::mir_map::MirMap;
|
||||||
use rustc::mir::repr as mir;
|
use rustc::mir::repr as mir;
|
||||||
|
use rustc::traits::{self, ProjectionMode};
|
||||||
|
use rustc::ty::fold::TypeFoldable;
|
||||||
|
use rustc::ty::subst::{self, Subst, Substs};
|
||||||
|
use rustc::ty::{self, TyCtxt};
|
||||||
use rustc::util::nodemap::DefIdMap;
|
use rustc::util::nodemap::DefIdMap;
|
||||||
use rustc_data_structures::fnv::FnvHashMap;
|
use rustc_data_structures::fnv::FnvHashMap;
|
||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
|
@ -195,8 +196,8 @@ impl<'a, 'tcx: 'a, 'arena> Interpreter<'a, 'tcx, 'arena> {
|
||||||
|
|
||||||
fn eval_terminator(&mut self, terminator: &mir::Terminator<'tcx>)
|
fn eval_terminator(&mut self, terminator: &mir::Terminator<'tcx>)
|
||||||
-> EvalResult<TerminatorTarget> {
|
-> EvalResult<TerminatorTarget> {
|
||||||
use rustc::mir::repr::Terminator::*;
|
use rustc::mir::repr::TerminatorKind::*;
|
||||||
let target = match *terminator {
|
let target = match terminator.kind {
|
||||||
Return => TerminatorTarget::Return,
|
Return => TerminatorTarget::Return,
|
||||||
|
|
||||||
Goto { target } => TerminatorTarget::Block(target),
|
Goto { target } => TerminatorTarget::Block(target),
|
||||||
|
@ -632,7 +633,7 @@ impl<'a, 'tcx: 'a, 'arena> Interpreter<'a, 'tcx, 'arena> {
|
||||||
}
|
}
|
||||||
|
|
||||||
Slice { .. } => unimplemented!(),
|
Slice { .. } => unimplemented!(),
|
||||||
InlineAsm(_) => unimplemented!(),
|
InlineAsm { .. } => unimplemented!(),
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -973,7 +974,7 @@ impl<'a, 'tcx: 'a, 'arena> Interpreter<'a, 'tcx, 'arena> {
|
||||||
fn fulfill_obligation(&self, trait_ref: ty::PolyTraitRef<'tcx>) -> traits::Vtable<'tcx, ()> {
|
fn fulfill_obligation(&self, trait_ref: ty::PolyTraitRef<'tcx>) -> traits::Vtable<'tcx, ()> {
|
||||||
// Do the initial selection for the obligation. This yields the shallow result we are
|
// Do the initial selection for the obligation. This yields the shallow result we are
|
||||||
// looking for -- that is, what specific impl.
|
// looking for -- that is, what specific impl.
|
||||||
let infcx = infer::normalizing_infer_ctxt(self.tcx, &self.tcx.tables);
|
let infcx = infer::normalizing_infer_ctxt(self.tcx, &self.tcx.tables, ProjectionMode::Any);
|
||||||
let mut selcx = traits::SelectionContext::new(&infcx);
|
let mut selcx = traits::SelectionContext::new(&infcx);
|
||||||
|
|
||||||
let obligation = traits::Obligation::new(
|
let obligation = traits::Obligation::new(
|
||||||
|
@ -997,7 +998,8 @@ impl<'a, 'tcx: 'a, 'arena> Interpreter<'a, 'tcx, 'arena> {
|
||||||
|
|
||||||
/// Trait method, which has to be resolved to an impl method.
|
/// Trait method, which has to be resolved to an impl method.
|
||||||
pub fn trait_method(&self, def_id: DefId, substs: &'tcx Substs<'tcx>)
|
pub fn trait_method(&self, def_id: DefId, substs: &'tcx Substs<'tcx>)
|
||||||
-> (DefId, &'tcx Substs<'tcx>) {
|
-> (DefId, &'tcx Substs<'tcx>)
|
||||||
|
{
|
||||||
let method_item = self.tcx.impl_or_trait_item(def_id);
|
let method_item = self.tcx.impl_or_trait_item(def_id);
|
||||||
let trait_id = method_item.container().id();
|
let trait_id = method_item.container().id();
|
||||||
let trait_ref = ty::Binder(substs.to_trait_ref(self.tcx, trait_id));
|
let trait_ref = ty::Binder(substs.to_trait_ref(self.tcx, trait_id));
|
||||||
|
@ -1009,7 +1011,7 @@ impl<'a, 'tcx: 'a, 'arena> Interpreter<'a, 'tcx, 'arena> {
|
||||||
// and those from the method:
|
// and those from the method:
|
||||||
let impl_substs = vtable_impl.substs.with_method_from(substs);
|
let impl_substs = vtable_impl.substs.with_method_from(substs);
|
||||||
let substs = self.tcx.mk_substs(impl_substs);
|
let substs = self.tcx.mk_substs(impl_substs);
|
||||||
let mth = self.tcx.get_impl_method(impl_did, substs, mname);
|
let mth = get_impl_method(self.tcx, impl_did, substs, mname);
|
||||||
|
|
||||||
(mth.method.def_id, mth.substs)
|
(mth.method.def_id, mth.substs)
|
||||||
}
|
}
|
||||||
|
@ -1072,6 +1074,40 @@ impl<'mir, 'tcx: 'mir> Deref for CachedMir<'mir, 'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub struct ImplMethod<'tcx> {
|
||||||
|
pub method: Rc<ty::Method<'tcx>>,
|
||||||
|
pub substs: &'tcx Substs<'tcx>,
|
||||||
|
pub is_provided: bool,
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Locates the applicable definition of a method, given its name.
|
||||||
|
pub fn get_impl_method<'tcx>(
|
||||||
|
tcx: &TyCtxt<'tcx>,
|
||||||
|
impl_def_id: DefId,
|
||||||
|
substs: &'tcx Substs<'tcx>,
|
||||||
|
name: ast::Name,
|
||||||
|
) -> ImplMethod<'tcx> {
|
||||||
|
assert!(!substs.types.needs_infer());
|
||||||
|
|
||||||
|
let trait_def_id = tcx.trait_id_of_impl(impl_def_id).unwrap();
|
||||||
|
let trait_def = tcx.lookup_trait_def(trait_def_id);
|
||||||
|
let infcx = infer::normalizing_infer_ctxt(tcx, &tcx.tables, ProjectionMode::Any);
|
||||||
|
|
||||||
|
match trait_def.ancestors(impl_def_id).fn_defs(tcx, name).next() {
|
||||||
|
Some(node_item) => {
|
||||||
|
ImplMethod {
|
||||||
|
method: node_item.item,
|
||||||
|
substs: traits::translate_substs(&infcx, impl_def_id, substs, node_item.node),
|
||||||
|
is_provided: node_item.node.is_from_trait(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => {
|
||||||
|
tcx.sess.bug(&format!("method {:?} not found in {:?}", name, impl_def_id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn interpret_start_points<'tcx>(tcx: &TyCtxt<'tcx>, mir_map: &MirMap<'tcx>) {
|
pub fn interpret_start_points<'tcx>(tcx: &TyCtxt<'tcx>, mir_map: &MirMap<'tcx>) {
|
||||||
/// Print the given allocation and all allocations it depends on.
|
/// Print the given allocation and all allocations it depends on.
|
||||||
fn print_allocation_tree(memory: &Memory, alloc_id: memory::AllocId) {
|
fn print_allocation_tree(memory: &Memory, alloc_id: memory::AllocId) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue