Rename ast::controlflow to ast::ret_style
It will include information about returning by alias.
This commit is contained in:
parent
f6fe07d1f3
commit
6eb9738a66
13 changed files with 58 additions and 61 deletions
|
|
@ -254,7 +254,7 @@ type fn_info =
|
|||
// Doesn't seem to work without the @ -- bug
|
||||
{constrs: constr_map,
|
||||
num_constraints: uint,
|
||||
cf: controlflow,
|
||||
cf: ret_style,
|
||||
i_return: tsconstr,
|
||||
i_diverge: tsconstr,
|
||||
used_vars: @mutable [node_id]};
|
||||
|
|
@ -489,10 +489,10 @@ fn new_crate_ctxt(cx: ty::ctxt) -> crate_ctxt {
|
|||
/* Use e's type to determine whether it returns.
|
||||
If it has a function type with a ! annotation,
|
||||
the answer is noreturn. */
|
||||
fn controlflow_expr(ccx: crate_ctxt, e: @expr) -> controlflow {
|
||||
fn controlflow_expr(ccx: crate_ctxt, e: @expr) -> ret_style {
|
||||
alt ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, e.id)) {
|
||||
ty::ty_fn(_, _, _, cf, _) { ret cf; }
|
||||
_ { ret return; }
|
||||
_ { ret return_val; }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
import syntax::ast;
|
||||
import ast::{method, item, item_fn, _fn, obj_field, _obj, stmt, ident,
|
||||
fn_ident, node_id, def_id, ty_param, crate, return, noreturn,
|
||||
fn_ident, node_id, def_id, ty_param, crate, return_val, noreturn,
|
||||
expr};
|
||||
import syntax::ast_util::local_def;
|
||||
import syntax::visit;
|
||||
|
|
@ -119,7 +119,7 @@ fn check_states_against_conditions(fcx: fn_ctxt, f: _fn, tps: [ast::ty_param],
|
|||
if f.proto != ast::proto_iter &&
|
||||
!promises(fcx, post, fcx.enclosing.i_return) &&
|
||||
!type_is_nil(fcx.ccx.tcx, ret_ty_of_fn(fcx.ccx.tcx, id)) &&
|
||||
f.decl.cf == return {
|
||||
f.decl.cf == return_val {
|
||||
fcx.ccx.tcx.sess.span_err(f.body.span,
|
||||
"In function " + fcx.name +
|
||||
", not all control paths \
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ fn find_pre_post_item(ccx: crate_ctxt, i: item) {
|
|||
enclosing:
|
||||
{constrs: @new_def_hash::<constraint>(),
|
||||
num_constraints: 0u,
|
||||
cf: return,
|
||||
cf: return_val,
|
||||
i_return: ninit(0, ""),
|
||||
i_diverge: ninit(0, ""),
|
||||
used_vars: v},
|
||||
|
|
|
|||
|
|
@ -169,7 +169,7 @@ fn find_pre_post_state_two(fcx: fn_ctxt, pres: prestate, lhs: @expr,
|
|||
|
||||
fn find_pre_post_state_call(fcx: fn_ctxt, pres: prestate, a: @expr,
|
||||
id: node_id, ops: [init_op], bs: [@expr],
|
||||
cf: controlflow) -> bool {
|
||||
cf: ret_style) -> bool {
|
||||
let changed = find_pre_post_state_expr(fcx, pres, a);
|
||||
// FIXME: This could be a typestate constraint
|
||||
if vec::len(bs) != vec::len(ops) {
|
||||
|
|
@ -183,7 +183,7 @@ fn find_pre_post_state_call(fcx: fn_ctxt, pres: prestate, a: @expr,
|
|||
}
|
||||
|
||||
fn find_pre_post_state_exprs(fcx: fn_ctxt, pres: prestate, id: node_id,
|
||||
ops: [init_op], es: [@expr], cf: controlflow) ->
|
||||
ops: [init_op], es: [@expr], cf: ret_style) ->
|
||||
bool {
|
||||
let rs = seq_states(fcx, pres, anon_bindings(ops, es));
|
||||
let changed = rs.changed | set_prestate_ann(fcx.ccx, id, pres);
|
||||
|
|
@ -333,7 +333,7 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
|
|||
ret find_pre_post_state_exprs(fcx, pres, e.id,
|
||||
vec::init_elt(init_assign,
|
||||
vec::len(elts)), elts,
|
||||
return);
|
||||
return_val);
|
||||
}
|
||||
expr_call(operator, operands) {
|
||||
ret find_pre_post_state_call(fcx, pres, operator, e.id,
|
||||
|
|
@ -354,7 +354,7 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
|
|||
i += 1;
|
||||
}
|
||||
ret find_pre_post_state_call(fcx, pres, operator, e.id, ops, args,
|
||||
return);
|
||||
return_val);
|
||||
}
|
||||
expr_path(_) { ret pure_exp(fcx.ccx, e.id, pres); }
|
||||
expr_log(_, ex) {
|
||||
|
|
@ -381,7 +381,7 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
|
|||
find_pre_post_state_exprs(fcx, pres, e.id,
|
||||
vec::init_elt(init_assign,
|
||||
vec::len(fields)),
|
||||
field_exprs(fields), return);
|
||||
field_exprs(fields), return_val);
|
||||
alt maybe_base {
|
||||
none. {/* do nothing */ }
|
||||
some(base) {
|
||||
|
|
@ -397,7 +397,7 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
|
|||
ret find_pre_post_state_exprs(fcx, pres, e.id,
|
||||
vec::init_elt(init_assign,
|
||||
vec::len(elts)), elts,
|
||||
return);
|
||||
return_val);
|
||||
}
|
||||
expr_copy(a) { ret find_pre_post_state_sub(fcx, pres, a, e.id, none); }
|
||||
expr_move(lhs, rhs) {
|
||||
|
|
|
|||
|
|
@ -185,7 +185,7 @@ type method =
|
|||
ident: ast::ident,
|
||||
inputs: [arg],
|
||||
output: t,
|
||||
cf: controlflow,
|
||||
cf: ret_style,
|
||||
constrs: [@constr]};
|
||||
|
||||
type constr_table = hashmap<ast::node_id, [constr]>;
|
||||
|
|
@ -255,7 +255,7 @@ tag sty {
|
|||
ty_vec(mt);
|
||||
ty_ptr(mt);
|
||||
ty_rec([field]);
|
||||
ty_fn(ast::proto, [arg], t, controlflow, [@constr]);
|
||||
ty_fn(ast::proto, [arg], t, ret_style, [@constr]);
|
||||
ty_native_fn(ast::native_abi, [arg], t);
|
||||
ty_obj([method]);
|
||||
ty_res(def_id, t, [t]);
|
||||
|
|
@ -556,7 +556,7 @@ fn mk_constr(cx: ctxt, t: t, cs: [@type_constr]) -> t {
|
|||
|
||||
fn mk_tup(cx: ctxt, ts: [t]) -> t { ret gen_ty(cx, ty_tup(ts)); }
|
||||
|
||||
fn mk_fn(cx: ctxt, proto: ast::proto, args: [arg], ty: t, cf: controlflow,
|
||||
fn mk_fn(cx: ctxt, proto: ast::proto, args: [arg], ty: t, cf: ret_style,
|
||||
constrs: [@constr]) -> t {
|
||||
ret gen_ty(cx, ty_fn(proto, args, ty, cf, constrs));
|
||||
}
|
||||
|
|
@ -583,7 +583,7 @@ fn mk_native(cx: ctxt, did: def_id) -> t { ret gen_ty(cx, ty_native(did)); }
|
|||
|
||||
fn mk_iter_body_fn(cx: ctxt, output: t) -> t {
|
||||
ret mk_fn(cx, ast::proto_block, [{mode: ast::by_ref, ty: output}],
|
||||
ty::mk_nil(cx), ast::return, []);
|
||||
ty::mk_nil(cx), ast::return_val, []);
|
||||
}
|
||||
|
||||
// Returns the one-level-deep type structure of the given type.
|
||||
|
|
@ -1948,16 +1948,12 @@ mod unify {
|
|||
fn unify_fn(cx: @ctxt, e_proto: ast::proto, a_proto: ast::proto,
|
||||
expected: t, actual: t, expected_inputs: [arg],
|
||||
expected_output: t, actual_inputs: [arg], actual_output: t,
|
||||
expected_cf: controlflow, actual_cf: controlflow,
|
||||
expected_cf: ret_style, actual_cf: ret_style,
|
||||
_expected_constrs: [@constr], actual_constrs: [@constr]) ->
|
||||
result {
|
||||
if e_proto != a_proto { ret ures_err(terr_mismatch); }
|
||||
alt expected_cf {
|
||||
ast::return. { }
|
||||
|
||||
|
||||
|
||||
|
||||
ast::return_val. { }
|
||||
// ok
|
||||
ast::noreturn. {
|
||||
alt actual_cf {
|
||||
|
|
|
|||
|
|
@ -593,8 +593,8 @@ mod collect {
|
|||
}
|
||||
|
||||
let t_fn =
|
||||
ty::mk_fn(cx.tcx, ast::proto_fn, t_inputs, t_obj.ty, ast::return,
|
||||
[]);
|
||||
ty::mk_fn(cx.tcx, ast::proto_fn, t_inputs, t_obj.ty,
|
||||
ast::return_val, []);
|
||||
let tpt = {kinds: ty_param_kinds(ty_params), ty: t_fn};
|
||||
cx.tcx.tcache.insert(local_def(ctor_id), tpt);
|
||||
ret tpt;
|
||||
|
|
@ -704,8 +704,8 @@ mod collect {
|
|||
let tag_t = ty::mk_tag(cx.tcx, tag_id, ty_param_tys);
|
||||
// FIXME: this will be different for constrained types
|
||||
result_ty =
|
||||
ty::mk_fn(cx.tcx, ast::proto_fn, args, tag_t, ast::return,
|
||||
[]);
|
||||
ty::mk_fn(cx.tcx, ast::proto_fn, args, tag_t,
|
||||
ast::return_val, []);
|
||||
}
|
||||
let tpt = {kinds: ty_param_kinds(ty_params), ty: result_ty};
|
||||
cx.tcx.tcache.insert(local_def(variant.node.id), tpt);
|
||||
|
|
@ -774,11 +774,11 @@ mod collect {
|
|||
ty::mk_res(cx.tcx, local_def(it.id), t_arg.ty,
|
||||
mk_ty_params(cx, tps));
|
||||
let t_ctor =
|
||||
ty::mk_fn(cx.tcx, ast::proto_fn, [t_arg], t_res, ast::return,
|
||||
[]);
|
||||
ty::mk_fn(cx.tcx, ast::proto_fn, [t_arg], t_res,
|
||||
ast::return_val, []);
|
||||
let t_dtor =
|
||||
ty::mk_fn(cx.tcx, ast::proto_fn, [t_arg], ty::mk_nil(cx.tcx),
|
||||
ast::return, []);
|
||||
ast::return_val, []);
|
||||
write::ty_only(cx.tcx, it.id, t_res);
|
||||
write::ty_only(cx.tcx, ctor_id, t_ctor);
|
||||
cx.tcx.tcache.insert(local_def(ctor_id),
|
||||
|
|
@ -2010,7 +2010,7 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
|
|||
proto = ast::proto_fn;
|
||||
arg_tys = arg_tys_;
|
||||
rt = rt_;
|
||||
cf = ast::return;
|
||||
cf = ast::return_val;
|
||||
constrs = [];
|
||||
}
|
||||
_ { fail "LHS of bind expr didn't have a function type?!"; }
|
||||
|
|
@ -2685,7 +2685,7 @@ fn arg_is_argv_ty(tcx: ty::ctxt, a: ty::arg) -> bool {
|
|||
fn check_main_fn_ty(tcx: ty::ctxt, main_id: ast::node_id) {
|
||||
let main_t = ty::node_id_to_monotype(tcx, main_id);
|
||||
alt ty::struct(tcx, main_t) {
|
||||
ty::ty_fn(ast::proto_fn., args, rs, ast::return., constrs) {
|
||||
ty::ty_fn(ast::proto_fn., args, rs, ast::return_val., constrs) {
|
||||
let ok = vec::len(constrs) == 0u;
|
||||
ok &= ty::type_is_nil(tcx, rs);
|
||||
let num_args = vec::len(args);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue