Build the MIR using the liberated fn sigs, and track the return type
This commit is contained in:
parent
6d7c66e6e8
commit
88a9c3e764
3 changed files with 48 additions and 28 deletions
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
use hair;
|
use hair;
|
||||||
use rustc::middle::region::CodeExtent;
|
use rustc::middle::region::CodeExtent;
|
||||||
use rustc::middle::ty::Ty;
|
use rustc::middle::ty::{FnOutput, Ty};
|
||||||
use rustc_data_structures::fnv::FnvHashMap;
|
use rustc_data_structures::fnv::FnvHashMap;
|
||||||
use rustc_front::hir;
|
use rustc_front::hir;
|
||||||
use repr::*;
|
use repr::*;
|
||||||
|
@ -75,13 +75,14 @@ macro_rules! unpack {
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
// construct() -- the main entry point for building MIR for a function
|
// construct() -- the main entry point for building MIR for a function
|
||||||
|
|
||||||
pub fn construct<'a, 'tcx>(mut hir: Cx<'a, 'tcx>,
|
pub fn construct<'a,'tcx>(mut hir: Cx<'a,'tcx>,
|
||||||
_span: Span,
|
_span: Span,
|
||||||
implicit_arguments: Vec<Ty<'tcx>>,
|
implicit_arguments: Vec<Ty<'tcx>>,
|
||||||
explicit_arguments: Vec<(Ty<'tcx>, PatNode<'tcx>)>,
|
explicit_arguments: Vec<(Ty<'tcx>, PatNode<'tcx>)>,
|
||||||
argument_extent: CodeExtent,
|
argument_extent: CodeExtent,
|
||||||
ast_block: &'tcx hir::Block)
|
return_ty: FnOutput<'tcx>,
|
||||||
-> Mir<'tcx> {
|
ast_block: &'tcx hir::Block)
|
||||||
|
-> Mir<'tcx> {
|
||||||
let cfg = CFG { basic_blocks: vec![] };
|
let cfg = CFG { basic_blocks: vec![] };
|
||||||
|
|
||||||
// it's handy to have a temporary of type `()` sometimes, so make
|
// it's handy to have a temporary of type `()` sometimes, so make
|
||||||
|
@ -121,6 +122,7 @@ pub fn construct<'a, 'tcx>(mut hir: Cx<'a, 'tcx>,
|
||||||
var_decls: builder.var_decls,
|
var_decls: builder.var_decls,
|
||||||
arg_decls: arg_decls,
|
arg_decls: arg_decls,
|
||||||
temp_decls: builder.temp_decls,
|
temp_decls: builder.temp_decls,
|
||||||
|
return_ty: return_ty,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -189,26 +189,42 @@ impl<'a, 'm, 'tcx> visit::Visitor<'tcx> for InnerDump<'a,'m,'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn build_mir<'a, 'tcx: 'a>(cx: Cx<'a, 'tcx>,
|
fn build_mir<'a,'tcx:'a>(cx: Cx<'a,'tcx>,
|
||||||
implicit_arg_tys: Vec<Ty<'tcx>>,
|
implicit_arg_tys: Vec<Ty<'tcx>>,
|
||||||
fn_id: ast::NodeId,
|
fn_id: ast::NodeId,
|
||||||
span: Span,
|
span: Span,
|
||||||
decl: &'tcx hir::FnDecl,
|
decl: &'tcx hir::FnDecl,
|
||||||
body: &'tcx hir::Block)
|
body: &'tcx hir::Block)
|
||||||
-> Result<Mir<'tcx>, ErrorReported> {
|
-> Result<Mir<'tcx>, ErrorReported> {
|
||||||
let arguments = decl.inputs
|
// fetch the fully liberated fn signature (that is, all bound
|
||||||
.iter()
|
// types/lifetimes replaced)
|
||||||
.map(|arg| {
|
let fn_sig = match cx.tcx().tables.borrow().liberated_fn_sigs.get(&fn_id) {
|
||||||
let ty = cx.tcx().node_id_to_type(arg.id);
|
Some(f) => f.clone(),
|
||||||
(ty, PatNode::irrefutable(&arg.pat))
|
None => {
|
||||||
})
|
cx.tcx().sess.span_bug(span,
|
||||||
.collect();
|
&format!("no liberated fn sig for {:?}", fn_id));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let parameter_scope = cx.tcx().region_maps.lookup_code_extent(CodeExtentData::ParameterScope {
|
let arguments =
|
||||||
fn_id: fn_id,
|
decl.inputs
|
||||||
body_id: body.id,
|
.iter()
|
||||||
});
|
.enumerate()
|
||||||
Ok(build::construct(cx, span, implicit_arg_tys, arguments, parameter_scope, body))
|
.map(|(index, arg)| {
|
||||||
|
(fn_sig.inputs[index], PatNode::irrefutable(&arg.pat))
|
||||||
|
})
|
||||||
|
.collect();
|
||||||
|
|
||||||
|
let parameter_scope =
|
||||||
|
cx.tcx().region_maps.lookup_code_extent(
|
||||||
|
CodeExtentData::ParameterScope { fn_id: fn_id, body_id: body.id });
|
||||||
|
Ok(build::construct(cx,
|
||||||
|
span,
|
||||||
|
implicit_arg_tys,
|
||||||
|
arguments,
|
||||||
|
parameter_scope,
|
||||||
|
fn_sig.output,
|
||||||
|
body))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn closure_self_ty<'a, 'tcx>(tcx: &ty::ctxt<'tcx>,
|
fn closure_self_ty<'a, 'tcx>(tcx: &ty::ctxt<'tcx>,
|
||||||
|
|
|
@ -12,7 +12,7 @@ use rustc::middle::const_eval::ConstVal;
|
||||||
use rustc::middle::def_id::DefId;
|
use rustc::middle::def_id::DefId;
|
||||||
use rustc::middle::region::CodeExtent;
|
use rustc::middle::region::CodeExtent;
|
||||||
use rustc::middle::subst::Substs;
|
use rustc::middle::subst::Substs;
|
||||||
use rustc::middle::ty::{AdtDef, ClosureSubsts, Region, Ty};
|
use rustc::middle::ty::{AdtDef, ClosureSubsts, FnOutput, Region, Ty};
|
||||||
use rustc_back::slice;
|
use rustc_back::slice;
|
||||||
use rustc_data_structures::fnv::FnvHashMap;
|
use rustc_data_structures::fnv::FnvHashMap;
|
||||||
use rustc_front::hir::InlineAsm;
|
use rustc_front::hir::InlineAsm;
|
||||||
|
@ -25,6 +25,8 @@ use std::u32;
|
||||||
pub struct Mir<'tcx> {
|
pub struct Mir<'tcx> {
|
||||||
pub basic_blocks: Vec<BasicBlockData<'tcx>>,
|
pub basic_blocks: Vec<BasicBlockData<'tcx>>,
|
||||||
|
|
||||||
|
pub return_ty: FnOutput<'tcx>,
|
||||||
|
|
||||||
// for every node id
|
// for every node id
|
||||||
pub extents: FnvHashMap<CodeExtent, Vec<GraphExtent>>,
|
pub extents: FnvHashMap<CodeExtent, Vec<GraphExtent>>,
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue