Skip to content

Commit 88a9c3e

Browse files
committed
Build the MIR using the liberated fn sigs, and track the return type
1 parent 6d7c66e commit 88a9c3e

File tree

3 files changed

+49
-29
lines changed

3 files changed

+49
-29
lines changed

src/librustc_mir/build/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
use hair;
1212
use rustc::middle::region::CodeExtent;
13-
use rustc::middle::ty::Ty;
13+
use rustc::middle::ty::{FnOutput, Ty};
1414
use rustc_data_structures::fnv::FnvHashMap;
1515
use rustc_front::hir;
1616
use repr::*;
@@ -75,13 +75,14 @@ macro_rules! unpack {
7575
///////////////////////////////////////////////////////////////////////////
7676
// construct() -- the main entry point for building MIR for a function
7777

78-
pub fn construct<'a, 'tcx>(mut hir: Cx<'a, 'tcx>,
79-
_span: Span,
80-
implicit_arguments: Vec<Ty<'tcx>>,
81-
explicit_arguments: Vec<(Ty<'tcx>, PatNode<'tcx>)>,
82-
argument_extent: CodeExtent,
83-
ast_block: &'tcx hir::Block)
84-
-> Mir<'tcx> {
78+
pub fn construct<'a,'tcx>(mut hir: Cx<'a,'tcx>,
79+
_span: Span,
80+
implicit_arguments: Vec<Ty<'tcx>>,
81+
explicit_arguments: Vec<(Ty<'tcx>, PatNode<'tcx>)>,
82+
argument_extent: CodeExtent,
83+
return_ty: FnOutput<'tcx>,
84+
ast_block: &'tcx hir::Block)
85+
-> Mir<'tcx> {
8586
let cfg = CFG { basic_blocks: vec![] };
8687

8788
// 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>,
121122
var_decls: builder.var_decls,
122123
arg_decls: arg_decls,
123124
temp_decls: builder.temp_decls,
125+
return_ty: return_ty,
124126
}
125127
}
126128

src/librustc_mir/mir_map.rs

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -189,26 +189,42 @@ impl<'a, 'm, 'tcx> visit::Visitor<'tcx> for InnerDump<'a,'m,'tcx> {
189189
}
190190
}
191191

192-
fn build_mir<'a, 'tcx: 'a>(cx: Cx<'a, 'tcx>,
193-
implicit_arg_tys: Vec<Ty<'tcx>>,
194-
fn_id: ast::NodeId,
195-
span: Span,
196-
decl: &'tcx hir::FnDecl,
197-
body: &'tcx hir::Block)
198-
-> Result<Mir<'tcx>, ErrorReported> {
199-
let arguments = decl.inputs
200-
.iter()
201-
.map(|arg| {
202-
let ty = cx.tcx().node_id_to_type(arg.id);
203-
(ty, PatNode::irrefutable(&arg.pat))
204-
})
205-
.collect();
206-
207-
let parameter_scope = cx.tcx().region_maps.lookup_code_extent(CodeExtentData::ParameterScope {
208-
fn_id: fn_id,
209-
body_id: body.id,
210-
});
211-
Ok(build::construct(cx, span, implicit_arg_tys, arguments, parameter_scope, body))
192+
fn build_mir<'a,'tcx:'a>(cx: Cx<'a,'tcx>,
193+
implicit_arg_tys: Vec<Ty<'tcx>>,
194+
fn_id: ast::NodeId,
195+
span: Span,
196+
decl: &'tcx hir::FnDecl,
197+
body: &'tcx hir::Block)
198+
-> Result<Mir<'tcx>, ErrorReported> {
199+
// fetch the fully liberated fn signature (that is, all bound
200+
// types/lifetimes replaced)
201+
let fn_sig = match cx.tcx().tables.borrow().liberated_fn_sigs.get(&fn_id) {
202+
Some(f) => f.clone(),
203+
None => {
204+
cx.tcx().sess.span_bug(span,
205+
&format!("no liberated fn sig for {:?}", fn_id));
206+
}
207+
};
208+
209+
let arguments =
210+
decl.inputs
211+
.iter()
212+
.enumerate()
213+
.map(|(index, arg)| {
214+
(fn_sig.inputs[index], PatNode::irrefutable(&arg.pat))
215+
})
216+
.collect();
217+
218+
let parameter_scope =
219+
cx.tcx().region_maps.lookup_code_extent(
220+
CodeExtentData::ParameterScope { fn_id: fn_id, body_id: body.id });
221+
Ok(build::construct(cx,
222+
span,
223+
implicit_arg_tys,
224+
arguments,
225+
parameter_scope,
226+
fn_sig.output,
227+
body))
212228
}
213229

214230
fn closure_self_ty<'a, 'tcx>(tcx: &ty::ctxt<'tcx>,

src/librustc_mir/repr.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use rustc::middle::const_eval::ConstVal;
1212
use rustc::middle::def_id::DefId;
1313
use rustc::middle::region::CodeExtent;
1414
use rustc::middle::subst::Substs;
15-
use rustc::middle::ty::{AdtDef, ClosureSubsts, Region, Ty};
15+
use rustc::middle::ty::{AdtDef, ClosureSubsts, FnOutput, Region, Ty};
1616
use rustc_back::slice;
1717
use rustc_data_structures::fnv::FnvHashMap;
1818
use rustc_front::hir::InlineAsm;
@@ -25,6 +25,8 @@ use std::u32;
2525
pub struct Mir<'tcx> {
2626
pub basic_blocks: Vec<BasicBlockData<'tcx>>,
2727

28+
pub return_ty: FnOutput<'tcx>,
29+
2830
// for every node id
2931
pub extents: FnvHashMap<CodeExtent, Vec<GraphExtent>>,
3032

0 commit comments

Comments
 (0)