Skip to content

Commit 6eb9738

Browse files
committed
Rename ast::controlflow to ast::ret_style
It will include information about returning by alias.
1 parent f6fe07d commit 6eb9738

File tree

13 files changed

+58
-61
lines changed

13 files changed

+58
-61
lines changed

src/comp/front/test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ fn mk_tests(cx: test_ctxt) -> @ast::item {
178178
output: ret_ty,
179179
purity: ast::impure_fn,
180180
il: ast::il_normal,
181-
cf: ast::return,
181+
cf: ast::return_val,
182182
constraints: []};
183183
let proto = ast::proto_fn;
184184

@@ -205,7 +205,7 @@ fn empty_fn_ty() -> ast::ty {
205205
let proto = ast::proto_fn;
206206
let input_ty = [];
207207
let ret_ty = @nospan(ast::ty_nil);
208-
let cf = ast::return;
208+
let cf = ast::return_val;
209209
let constrs = [];
210210
ret nospan(ast::ty_fn(proto, input_ty, ret_ty, cf, constrs));
211211
}
@@ -298,7 +298,7 @@ fn mk_main(cx: test_ctxt) -> @ast::item {
298298
output: @ret_ty,
299299
purity: ast::impure_fn,
300300
il: ast::il_normal,
301-
cf: ast::return,
301+
cf: ast::return_val,
302302
constraints: []};
303303
let proto = ast::proto_fn;
304304

src/comp/metadata/tydecode.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ fn parse_hex(st: @pstate) -> uint {
371371
}
372372

373373
fn parse_ty_fn(st: @pstate, sd: str_def) ->
374-
{args: [ty::arg], ty: ty::t, cf: ast::controlflow, cs: [@ty::constr]} {
374+
{args: [ty::arg], ty: ty::t, cf: ast::ret_style, cs: [@ty::constr]} {
375375
assert (next(st) as char == '[');
376376
let inputs: [ty::arg] = [];
377377
while peek(st) as char != ']' {
@@ -391,7 +391,7 @@ fn parse_ty_fn(st: @pstate, sd: str_def) ->
391391
a_bang. {
392392
ret {args: inputs, ty: ty::mk_bot(st.tcx), cf: ast::noreturn, cs: cs};
393393
}
394-
a_ty(t) { ret {args: inputs, ty: t, cf: ast::return, cs: cs}; }
394+
a_ty(t) { ret {args: inputs, ty: t, cf: ast::return_val, cs: cs}; }
395395
}
396396
}
397397

src/comp/metadata/tyencode.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
148148
native_abi_llvm. { w.write_char('l'); }
149149
native_abi_x86stdcall. { w.write_char('s'); }
150150
}
151-
enc_ty_fn(w, cx, args, out, return, []);
151+
enc_ty_fn(w, cx, args, out, return_val, []);
152152
}
153153
ty::ty_obj(methods) {
154154
w.write_str("O[");
@@ -199,7 +199,7 @@ fn enc_proto(w: io::writer, proto: proto) {
199199
}
200200

201201
fn enc_ty_fn(w: io::writer, cx: @ctxt, args: [ty::arg], out: ty::t,
202-
cf: controlflow, constrs: [@ty::constr]) {
202+
cf: ret_style, constrs: [@ty::constr]) {
203203
w.write_char('[');
204204
for arg: ty::arg in args {
205205
alt arg.mode {
@@ -219,7 +219,6 @@ fn enc_ty_fn(w: io::writer, cx: @ctxt, args: [ty::arg], out: ty::t,
219219
enc_constr(w, cx, c);
220220
}
221221
alt cf { noreturn. { w.write_char('!'); } _ { enc_ty(w, cx, out); } }
222-
223222
}
224223

225224
// FIXME less copy-and-paste

src/comp/middle/tstate/auxiliary.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ type fn_info =
254254
// Doesn't seem to work without the @ -- bug
255255
{constrs: constr_map,
256256
num_constraints: uint,
257-
cf: controlflow,
257+
cf: ret_style,
258258
i_return: tsconstr,
259259
i_diverge: tsconstr,
260260
used_vars: @mutable [node_id]};
@@ -489,10 +489,10 @@ fn new_crate_ctxt(cx: ty::ctxt) -> crate_ctxt {
489489
/* Use e's type to determine whether it returns.
490490
If it has a function type with a ! annotation,
491491
the answer is noreturn. */
492-
fn controlflow_expr(ccx: crate_ctxt, e: @expr) -> controlflow {
492+
fn controlflow_expr(ccx: crate_ctxt, e: @expr) -> ret_style {
493493
alt ty::struct(ccx.tcx, ty::node_id_to_type(ccx.tcx, e.id)) {
494494
ty::ty_fn(_, _, _, cf, _) { ret cf; }
495-
_ { ret return; }
495+
_ { ret return_val; }
496496
}
497497
}
498498

src/comp/middle/tstate/ck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
import syntax::ast;
33
import ast::{method, item, item_fn, _fn, obj_field, _obj, stmt, ident,
4-
fn_ident, node_id, def_id, ty_param, crate, return, noreturn,
4+
fn_ident, node_id, def_id, ty_param, crate, return_val, noreturn,
55
expr};
66
import syntax::ast_util::local_def;
77
import syntax::visit;
@@ -119,7 +119,7 @@ fn check_states_against_conditions(fcx: fn_ctxt, f: _fn, tps: [ast::ty_param],
119119
if f.proto != ast::proto_iter &&
120120
!promises(fcx, post, fcx.enclosing.i_return) &&
121121
!type_is_nil(fcx.ccx.tcx, ret_ty_of_fn(fcx.ccx.tcx, id)) &&
122-
f.decl.cf == return {
122+
f.decl.cf == return_val {
123123
fcx.ccx.tcx.sess.span_err(f.body.span,
124124
"In function " + fcx.name +
125125
", not all control paths \

src/comp/middle/tstate/pre_post_conditions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn find_pre_post_item(ccx: crate_ctxt, i: item) {
5252
enclosing:
5353
{constrs: @new_def_hash::<constraint>(),
5454
num_constraints: 0u,
55-
cf: return,
55+
cf: return_val,
5656
i_return: ninit(0, ""),
5757
i_diverge: ninit(0, ""),
5858
used_vars: v},

src/comp/middle/tstate/states.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ fn find_pre_post_state_two(fcx: fn_ctxt, pres: prestate, lhs: @expr,
169169

170170
fn find_pre_post_state_call(fcx: fn_ctxt, pres: prestate, a: @expr,
171171
id: node_id, ops: [init_op], bs: [@expr],
172-
cf: controlflow) -> bool {
172+
cf: ret_style) -> bool {
173173
let changed = find_pre_post_state_expr(fcx, pres, a);
174174
// FIXME: This could be a typestate constraint
175175
if vec::len(bs) != vec::len(ops) {
@@ -183,7 +183,7 @@ fn find_pre_post_state_call(fcx: fn_ctxt, pres: prestate, a: @expr,
183183
}
184184

185185
fn find_pre_post_state_exprs(fcx: fn_ctxt, pres: prestate, id: node_id,
186-
ops: [init_op], es: [@expr], cf: controlflow) ->
186+
ops: [init_op], es: [@expr], cf: ret_style) ->
187187
bool {
188188
let rs = seq_states(fcx, pres, anon_bindings(ops, es));
189189
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 {
333333
ret find_pre_post_state_exprs(fcx, pres, e.id,
334334
vec::init_elt(init_assign,
335335
vec::len(elts)), elts,
336-
return);
336+
return_val);
337337
}
338338
expr_call(operator, operands) {
339339
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 {
354354
i += 1;
355355
}
356356
ret find_pre_post_state_call(fcx, pres, operator, e.id, ops, args,
357-
return);
357+
return_val);
358358
}
359359
expr_path(_) { ret pure_exp(fcx.ccx, e.id, pres); }
360360
expr_log(_, ex) {
@@ -381,7 +381,7 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
381381
find_pre_post_state_exprs(fcx, pres, e.id,
382382
vec::init_elt(init_assign,
383383
vec::len(fields)),
384-
field_exprs(fields), return);
384+
field_exprs(fields), return_val);
385385
alt maybe_base {
386386
none. {/* do nothing */ }
387387
some(base) {
@@ -397,7 +397,7 @@ fn find_pre_post_state_expr(fcx: fn_ctxt, pres: prestate, e: @expr) -> bool {
397397
ret find_pre_post_state_exprs(fcx, pres, e.id,
398398
vec::init_elt(init_assign,
399399
vec::len(elts)), elts,
400-
return);
400+
return_val);
401401
}
402402
expr_copy(a) { ret find_pre_post_state_sub(fcx, pres, a, e.id, none); }
403403
expr_move(lhs, rhs) {

src/comp/middle/ty.rs

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ type method =
185185
ident: ast::ident,
186186
inputs: [arg],
187187
output: t,
188-
cf: controlflow,
188+
cf: ret_style,
189189
constrs: [@constr]};
190190

191191
type constr_table = hashmap<ast::node_id, [constr]>;
@@ -255,7 +255,7 @@ tag sty {
255255
ty_vec(mt);
256256
ty_ptr(mt);
257257
ty_rec([field]);
258-
ty_fn(ast::proto, [arg], t, controlflow, [@constr]);
258+
ty_fn(ast::proto, [arg], t, ret_style, [@constr]);
259259
ty_native_fn(ast::native_abi, [arg], t);
260260
ty_obj([method]);
261261
ty_res(def_id, t, [t]);
@@ -556,7 +556,7 @@ fn mk_constr(cx: ctxt, t: t, cs: [@type_constr]) -> t {
556556

557557
fn mk_tup(cx: ctxt, ts: [t]) -> t { ret gen_ty(cx, ty_tup(ts)); }
558558

559-
fn mk_fn(cx: ctxt, proto: ast::proto, args: [arg], ty: t, cf: controlflow,
559+
fn mk_fn(cx: ctxt, proto: ast::proto, args: [arg], ty: t, cf: ret_style,
560560
constrs: [@constr]) -> t {
561561
ret gen_ty(cx, ty_fn(proto, args, ty, cf, constrs));
562562
}
@@ -583,7 +583,7 @@ fn mk_native(cx: ctxt, did: def_id) -> t { ret gen_ty(cx, ty_native(did)); }
583583

584584
fn mk_iter_body_fn(cx: ctxt, output: t) -> t {
585585
ret mk_fn(cx, ast::proto_block, [{mode: ast::by_ref, ty: output}],
586-
ty::mk_nil(cx), ast::return, []);
586+
ty::mk_nil(cx), ast::return_val, []);
587587
}
588588

589589
// Returns the one-level-deep type structure of the given type.
@@ -1948,16 +1948,12 @@ mod unify {
19481948
fn unify_fn(cx: @ctxt, e_proto: ast::proto, a_proto: ast::proto,
19491949
expected: t, actual: t, expected_inputs: [arg],
19501950
expected_output: t, actual_inputs: [arg], actual_output: t,
1951-
expected_cf: controlflow, actual_cf: controlflow,
1951+
expected_cf: ret_style, actual_cf: ret_style,
19521952
_expected_constrs: [@constr], actual_constrs: [@constr]) ->
19531953
result {
19541954
if e_proto != a_proto { ret ures_err(terr_mismatch); }
19551955
alt expected_cf {
1956-
ast::return. { }
1957-
1958-
1959-
1960-
1956+
ast::return_val. { }
19611957
// ok
19621958
ast::noreturn. {
19631959
alt actual_cf {

src/comp/middle/typeck.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -593,8 +593,8 @@ mod collect {
593593
}
594594

595595
let t_fn =
596-
ty::mk_fn(cx.tcx, ast::proto_fn, t_inputs, t_obj.ty, ast::return,
597-
[]);
596+
ty::mk_fn(cx.tcx, ast::proto_fn, t_inputs, t_obj.ty,
597+
ast::return_val, []);
598598
let tpt = {kinds: ty_param_kinds(ty_params), ty: t_fn};
599599
cx.tcx.tcache.insert(local_def(ctor_id), tpt);
600600
ret tpt;
@@ -704,8 +704,8 @@ mod collect {
704704
let tag_t = ty::mk_tag(cx.tcx, tag_id, ty_param_tys);
705705
// FIXME: this will be different for constrained types
706706
result_ty =
707-
ty::mk_fn(cx.tcx, ast::proto_fn, args, tag_t, ast::return,
708-
[]);
707+
ty::mk_fn(cx.tcx, ast::proto_fn, args, tag_t,
708+
ast::return_val, []);
709709
}
710710
let tpt = {kinds: ty_param_kinds(ty_params), ty: result_ty};
711711
cx.tcx.tcache.insert(local_def(variant.node.id), tpt);
@@ -774,11 +774,11 @@ mod collect {
774774
ty::mk_res(cx.tcx, local_def(it.id), t_arg.ty,
775775
mk_ty_params(cx, tps));
776776
let t_ctor =
777-
ty::mk_fn(cx.tcx, ast::proto_fn, [t_arg], t_res, ast::return,
778-
[]);
777+
ty::mk_fn(cx.tcx, ast::proto_fn, [t_arg], t_res,
778+
ast::return_val, []);
779779
let t_dtor =
780780
ty::mk_fn(cx.tcx, ast::proto_fn, [t_arg], ty::mk_nil(cx.tcx),
781-
ast::return, []);
781+
ast::return_val, []);
782782
write::ty_only(cx.tcx, it.id, t_res);
783783
write::ty_only(cx.tcx, ctor_id, t_ctor);
784784
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,
20102010
proto = ast::proto_fn;
20112011
arg_tys = arg_tys_;
20122012
rt = rt_;
2013-
cf = ast::return;
2013+
cf = ast::return_val;
20142014
constrs = [];
20152015
}
20162016
_ { 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 {
26852685
fn check_main_fn_ty(tcx: ty::ctxt, main_id: ast::node_id) {
26862686
let main_t = ty::node_id_to_monotype(tcx, main_id);
26872687
alt ty::struct(tcx, main_t) {
2688-
ty::ty_fn(ast::proto_fn., args, rs, ast::return., constrs) {
2688+
ty::ty_fn(ast::proto_fn., args, rs, ast::return_val., constrs) {
26892689
let ok = vec::len(constrs) == 0u;
26902690
ok &= ty::type_is_nil(tcx, rs);
26912691
let num_args = vec::len(args);

src/comp/syntax/ast.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ type ty_method_ =
261261
ident: ident,
262262
inputs: [ty_arg],
263263
output: @ty,
264-
cf: controlflow,
264+
cf: ret_style,
265265
constrs: [@constr]};
266266

267267
type ty_field = spanned<ty_field_>;
@@ -311,7 +311,7 @@ tag ty_ {
311311
ty_port(@ty);
312312
ty_chan(@ty);
313313
ty_rec([ty_field]);
314-
ty_fn(proto, [ty_arg], @ty, controlflow, [@constr]);
314+
ty_fn(proto, [ty_arg], @ty, ret_style, [@constr]);
315315
ty_obj([ty_method]);
316316
ty_tup([@ty]);
317317
ty_path(path, node_id);
@@ -369,22 +369,19 @@ type fn_decl =
369369
output: @ty,
370370
purity: purity,
371371
il: inlineness,
372-
cf: controlflow,
372+
cf: ret_style,
373373
constraints: [@constr]};
374374

375375
tag purity {
376376
pure_fn; // declared with "pure fn"
377377
impure_fn; // declared with "fn"
378378
}
379379

380-
tag controlflow {
380+
tag ret_style {
381381
noreturn; // functions with return type _|_ that always
382382
// raise an error or exit (i.e. never return to the caller)
383-
384-
385-
386-
387-
return; // everything else
383+
return_val; // everything else
384+
return_alias;
388385
}
389386

390387
type _fn = {decl: fn_decl, proto: proto, body: blk};

src/comp/syntax/parse/parser.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,10 +289,10 @@ fn parse_ty_fn(proto: ast::proto, p: parser) -> ast::ty_ {
289289
// auto constrs = parse_constrs(~[], p);
290290
let constrs: [@ast::constr] = [];
291291
let output: @ast::ty;
292-
let cf = ast::return;
292+
let cf = ast::return_val;
293293
if p.peek() == token::RARROW {
294294
p.bump();
295-
let tmp = parse_ty_or_bang(p);
295+
let tmp = parse_ret_ty(p);
296296
alt tmp {
297297
a_ty(t) { output = t; }
298298
a_bang. {
@@ -452,7 +452,12 @@ fn parse_ty_postfix(orig_t: ast::ty_, p: parser, colons_before_params: bool)
452452
}
453453
}
454454

455-
fn parse_ty_or_bang(p: parser) -> ty_or_bang {
455+
fn parse_ret_ty(p: parser) -> ty_or_bang {
456+
/* if eat(p, token::RARROW) {
457+
458+
} else {
459+
460+
}*/
456461
alt p.peek() {
457462
token::NOT. { p.bump(); ret a_bang; }
458463
_ { ret a_ty(parse_ty(p, false)); }
@@ -1766,7 +1771,7 @@ fn parse_fn_decl(p: parser, purity: ast::purity, il: ast::inlineness) ->
17661771
}
17671772
if p.peek() == token::RARROW {
17681773
p.bump();
1769-
rslt = parse_ty_or_bang(p);
1774+
rslt = parse_ret_ty(p);
17701775
} else {
17711776
rslt = a_ty(@spanned(inputs.span.lo, inputs.span.hi, ast::ty_nil));
17721777
}
@@ -1776,7 +1781,7 @@ fn parse_fn_decl(p: parser, purity: ast::purity, il: ast::inlineness) ->
17761781
output: t,
17771782
purity: purity,
17781783
il: il,
1779-
cf: ast::return,
1784+
cf: ast::return_val,
17801785
constraints: constrs};
17811786
}
17821787
a_bang. {
@@ -1803,7 +1808,7 @@ fn parse_fn_block_decl(p: parser) -> ast::fn_decl {
18031808
output: @spanned(p.get_lo_pos(), p.get_hi_pos(), ast::ty_infer),
18041809
purity: ast::impure_fn,
18051810
il: ast::il_normal,
1806-
cf: ast::return,
1811+
cf: ast::return_val,
18071812
constraints: []};
18081813
}
18091814

@@ -1899,7 +1904,7 @@ fn parse_item_res(p: parser, attrs: [ast::attribute]) -> @ast::item {
18991904
output: @spanned(lo, lo, ast::ty_nil),
19001905
purity: ast::impure_fn,
19011906
il: ast::il_normal,
1902-
cf: ast::return,
1907+
cf: ast::return_val,
19031908
constraints: []};
19041909
let f = {decl: decl, proto: ast::proto_fn, body: dtor};
19051910
ret mk_item(p, lo, dtor.span.hi, ident,

0 commit comments

Comments
 (0)