Skip to content

Commit 324f57a

Browse files
committed
rustc: Check call and bind expressions using a set of region bindings
1 parent bdf968c commit 324f57a

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

src/rustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1538,7 +1538,7 @@ mod unify {
15381538
import result::{result, ok, err, chain, map, map2};
15391539

15401540
export fixup_vars;
1541-
export mk_var_bindings;
1541+
export mk_var_bindings, mk_region_bindings;
15421542
export resolve_type_structure;
15431543
export resolve_type_var;
15441544
export unify;

src/rustc/middle/typeck.rs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2141,6 +2141,11 @@ fn check_expr_fn_with_unifier(fcx: @fn_ctxt,
21412141
check_fn(fcx.ccx, proto, decl, body, expr.id, some(fcx));
21422142
}
21432143

2144+
type check_call_or_bind_result = {
2145+
bot: bool,
2146+
rb: @ty::unify::region_bindings
2147+
};
2148+
21442149
fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
21452150
expected: ty::t) -> bool {
21462151

@@ -2150,7 +2155,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
21502155
// A generic function to factor out common logic from call and bind
21512156
// expressions.
21522157
fn check_call_or_bind(fcx: @fn_ctxt, sp: span, id: ast::node_id,
2153-
fty: ty::t, args: [option<@ast::expr>]) -> bool {
2158+
fty: ty::t, args: [option<@ast::expr>])
2159+
-> check_call_or_bind_result {
21542160
// Replaces "caller" regions in the arguments with the local region.
21552161
fn instantiate_caller_regions(fcx: @fn_ctxt, id: ast::node_id,
21562162
args: [ty::arg]) -> [ty::arg] {
@@ -2185,6 +2191,9 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
21852191
};
21862192
}
21872193

2194+
let rb = ty::unify::mk_region_bindings();
2195+
let unifier = bind demand::with_region_bindings(_, _, rb, _, _);
2196+
21882197
let sty = structure_of(fcx, sp, fty);
21892198
// Grab the argument types
21902199
let arg_tys = alt sty {
@@ -2222,6 +2231,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
22222231
arg_tys = vec::from_elem(supplied_arg_count, dummy);
22232232
}
22242233

2234+
// FIXME: This should instantiate re_params instead.
22252235
arg_tys = instantiate_caller_regions(fcx, id, arg_tys);
22262236

22272237
// Check the arguments.
@@ -2241,8 +2251,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
22412251
_ { false }
22422252
};
22432253
if is_block == check_blocks {
2244-
bot |= check_expr_with_unifier(
2245-
fcx, a, demand::simple, arg_tys[i].ty);
2254+
let t = arg_tys[i].ty;
2255+
bot |= check_expr_with_unifier(fcx, a, unifier, t);
22462256
}
22472257
}
22482258
none { }
@@ -2251,7 +2261,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
22512261
}
22522262
ret bot;
22532263
};
2254-
check_args(false) | check_args(true)
2264+
let bot = check_args(false) | check_args(true);
2265+
ret { bot: bot, rb: rb };
22552266
}
22562267

22572268
// A generic function for checking assignment expressions
@@ -2272,10 +2283,15 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
22722283
args_opt_0 += [some::<@ast::expr>(arg)];
22732284
}
22742285

2275-
let bot = check_expr(fcx, f);
2286+
let mut bot = check_expr(fcx, f);
22762287
// Call the generic checker.
2277-
bot | check_call_or_bind(fcx, sp, id, expr_ty(fcx.ccx.tcx, f),
2278-
args_opt_0)
2288+
let ccobr = check_call_or_bind(fcx, sp, id, expr_ty(fcx.ccx.tcx, f),
2289+
args_opt_0);
2290+
bot |= ccobr.bot;
2291+
2292+
// TODO: Munge return type.
2293+
2294+
ret bot;
22792295
}
22802296

22812297
// A generic function for doing all of the checking for call expressions
@@ -2690,8 +2706,11 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
26902706
ast::expr_bind(f, args) {
26912707
// Call the generic checker.
26922708
bot = check_expr(fcx, f);
2693-
bot |= check_call_or_bind(fcx, expr.span, expr.id, expr_ty(tcx, f),
2694-
args);
2709+
let ccobr = check_call_or_bind(fcx, expr.span, expr.id,
2710+
expr_ty(tcx, f), args);
2711+
bot |= ccobr.bot;
2712+
2713+
// TODO: Perform substitutions on the return type.
26952714

26962715
// Pull the argument and return types out.
26972716
let proto, arg_tys, rt, cf, constrs;

0 commit comments

Comments
 (0)