use build;
use rustc::dep_graph::DepNode;
use rustc::hir::def_id::DefId;
-use rustc::mir::repr::Mir;
+use rustc::mir::Mir;
use rustc::mir::transform::MirSource;
use rustc::mir::visit::MutVisitor;
use pretty;
use hair::cx::Cx;
-use rustc::mir::mir_map::MirMap;
use rustc::infer::InferCtxtBuilder;
use rustc::traits::Reveal;
use rustc::ty::{self, Ty, TyCtxt};
use std::mem;
-pub fn build_mir_for_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) -> MirMap<'tcx> {
- let mut map = MirMap::new(tcx.dep_graph.clone());
- {
- let mut dump = BuildMir {
- tcx: tcx,
- map: &mut map,
- };
- tcx.visit_all_items_in_krate(DepNode::Mir, &mut dump);
- }
- map
+pub fn build_mir_for_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
+ tcx.visit_all_items_in_krate(DepNode::Mir, &mut BuildMir {
+ tcx: tcx
+ });
}
/// A pass to lift all the types and substitutions in a Mir
// BuildMir -- walks a crate, looking for fn items and methods to build MIR from
struct BuildMir<'a, 'tcx: 'a> {
- tcx: TyCtxt<'a, 'tcx, 'tcx>,
- map: &'a mut MirMap<'tcx>,
+ tcx: TyCtxt<'a, 'tcx, 'tcx>
}
/// Helper type of a temporary returned by BuildMir::cx(...).
struct CxBuilder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
src: MirSource,
def_id: DefId,
- infcx: InferCtxtBuilder<'a, 'gcx, 'tcx>,
- map: &'a mut MirMap<'gcx>,
+ infcx: InferCtxtBuilder<'a, 'gcx, 'tcx>
}
impl<'a, 'gcx, 'tcx> BuildMir<'a, 'gcx> {
CxBuilder {
src: src,
infcx: self.tcx.infer_ctxt(None, Some(param_env), Reveal::NotSpecializable),
- def_id: def_id,
- map: self.map
+ def_id: def_id
}
}
}
fn build<F>(&'tcx mut self, f: F)
where F: for<'b> FnOnce(Cx<'b, 'gcx, 'tcx>) -> (Mir<'tcx>, build::ScopeAuxiliaryVec)
{
- let src = self.src;
- let mir = self.infcx.enter(|infcx| {
+ let (src, def_id) = (self.src, self.def_id);
+ self.infcx.enter(|infcx| {
let (mut mir, scope_auxiliary) = f(Cx::new(&infcx, src));
// Convert the Mir to global types.
+ let tcx = infcx.tcx.global_tcx();
let mut globalizer = GlobalizeMir {
- tcx: infcx.tcx.global_tcx(),
+ tcx: tcx,
span: mir.span
};
globalizer.visit_mir(&mut mir);
mem::transmute::<Mir, Mir<'gcx>>(mir)
};
- pretty::dump_mir(infcx.tcx.global_tcx(), "mir_map", &0,
- src, &mir, Some(&scope_auxiliary));
+ pretty::dump_mir(tcx, "mir_map", &0, src, &mir, Some(&scope_auxiliary));
- mir
+ let mir = tcx.alloc_mir(mir);
+ assert!(tcx.mir_map.borrow_mut().insert(def_id, mir).is_none());
});
-
- assert!(self.map.map.insert(self.def_id, mir).is_none())
}
}
// Array lengths, i.e. [T; constant].
fn visit_ty(&mut self, ty: &'tcx hir::Ty) {
- if let hir::TyFixedLengthVec(_, ref length) = ty.node {
+ if let hir::TyArray(_, ref length) = ty.node {
self.build_const_integer(length);
}
intravisit::walk_ty(self, ty);
id: ast::NodeId) {
// fetch the fully liberated fn signature (that is, all bound
// types/lifetimes replaced)
- let fn_sig = match self.tcx.tables.borrow().liberated_fn_sigs.get(&id) {
+ let fn_sig = match self.tcx.tables().liberated_fn_sigs.get(&id) {
Some(f) => f.clone(),
None => {
span_bug!(span, "no liberated fn sig for {:?}", id);
closure_expr_id: ast::NodeId,
body_id: ast::NodeId)
-> Ty<'tcx> {
- let closure_ty = tcx.node_id_to_type(closure_expr_id);
+ let closure_ty = tcx.tables().node_id_to_type(closure_expr_id);
// We're just hard-coding the idea that the signature will be
// &self or &mut self and hence will have a bound region with