Skip to content

Commit 94950b1

Browse files
committed
Remove ret_style and instead check whether fn return type is bot
cc rust-lang#3681
1 parent fcc470c commit 94950b1

File tree

18 files changed

+64
-139
lines changed

18 files changed

+64
-139
lines changed

src/librustc/metadata/tydecode.rs

+2-10
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,6 @@ fn parse_arg_data(data: @~[u8], crate_num: int, pos: uint, tcx: ty::ctxt,
9090
parse_arg(st, conv)
9191
}
9292

93-
fn parse_ret_ty(st: @pstate, conv: conv_did) -> (ast::ret_style, ty::t) {
94-
match peek(st) {
95-
'!' => { next(st); (ast::noreturn, ty::mk_bot(st.tcx)) }
96-
_ => (ast::return_val, parse_ty(st, conv))
97-
}
98-
}
99-
10093
fn parse_path(st: @pstate) -> @ast::path {
10194
let mut idents: ~[ast::ident] = ~[];
10295
fn is_last(c: char) -> bool { return c == '(' || c == ':'; }
@@ -437,14 +430,13 @@ fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::FnTy {
437430
inputs.push({mode: mode, ty: parse_ty(st, conv)});
438431
}
439432
st.pos += 1u; // eat the ']'
440-
let (ret_style, ret_ty) = parse_ret_ty(st, conv);
433+
let ret_ty = parse_ty(st, conv);
441434
return FnTyBase {
442435
meta: FnMeta {purity: purity,
443436
proto: proto,
444437
onceness: onceness,
445438
bounds: bounds,
446-
region: region,
447-
ret_style: ret_style},
439+
region: region},
448440
sig: FnSig {inputs: inputs,
449441
output: ret_ty}
450442
};

src/librustc/metadata/tyencode.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -388,10 +388,7 @@ fn enc_ty_fn(w: io::Writer, cx: @ctxt, ft: ty::FnTy) {
388388
enc_arg(w, cx, *arg);
389389
}
390390
w.write_char(']');
391-
match ft.meta.ret_style {
392-
noreturn => w.write_char('!'),
393-
_ => enc_ty(w, cx, ft.sig.output)
394-
}
391+
enc_ty(w, cx, ft.sig.output);
395392
}
396393

397394
fn enc_bounds(w: io::Writer, cx: @ctxt, bs: @~[ty::param_bound]) {

src/librustc/middle/lint.rs

+14-12
Original file line numberDiff line numberDiff line change
@@ -580,20 +580,22 @@ fn check_item_type_limits(cx: ty::ctxt, it: @ast::item) {
580580
}
581581
}
582582

583-
let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
584-
visit_expr: fn@(e: @ast::expr) {
585-
match e.node {
586-
ast::expr_binary(ref binop, @ref l, @ref r) => {
587-
if is_comparison(*binop)
588-
&& !check_limits(cx, *binop, l, r) {
589-
cx.sess.span_lint(
590-
type_limits, e.id, it.id, e.span,
591-
~"comparison is useless due to type limits");
592-
}
583+
let visit_expr: @fn(@ast::expr) = |e| {
584+
match e.node {
585+
ast::expr_binary(ref binop, @ref l, @ref r) => {
586+
if is_comparison(*binop)
587+
&& !check_limits(cx, *binop, l, r) {
588+
cx.sess.span_lint(
589+
type_limits, e.id, it.id, e.span,
590+
~"comparison is useless due to type limits");
593591
}
594-
_ => ()
595592
}
596-
},
593+
_ => ()
594+
}
595+
};
596+
597+
let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
598+
visit_expr: visit_expr,
597599
.. *visit::default_simple_visitor()
598600
}));
599601
visit::visit_item(it, (), visit);

src/librustc/middle/trans/base.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,10 @@ fn compare_scalar_types(cx: block, lhs: ValueRef, rhs: ValueRef,
493493
fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
494494
nt: scalar_type, op: ast::binop) -> ValueRef {
495495
let _icx = cx.insn_ctxt("compare_scalar_values");
496-
fn die_(cx: block) -> ! {
496+
fn die(cx: block) -> ! {
497497
cx.tcx().sess.bug(~"compare_scalar_values: must be a\
498498
comparison operator");
499499
}
500-
let die = fn@() -> ! { die_(cx) };
501500
match nt {
502501
nil_type => {
503502
// We don't need to do actual comparisons for nil.
@@ -506,7 +505,7 @@ fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
506505
ast::eq | ast::le | ast::ge => return C_bool(true),
507506
ast::ne | ast::lt | ast::gt => return C_bool(false),
508507
// refinements would be nice
509-
_ => die()
508+
_ => die(cx)
510509
}
511510
}
512511
floating_point => {
@@ -517,7 +516,7 @@ fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
517516
ast::le => lib::llvm::RealOLE,
518517
ast::gt => lib::llvm::RealOGT,
519518
ast::ge => lib::llvm::RealOGE,
520-
_ => die()
519+
_ => die(cx)
521520
};
522521
return FCmp(cx, cmp, lhs, rhs);
523522
}
@@ -529,7 +528,7 @@ fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
529528
ast::le => lib::llvm::IntSLE,
530529
ast::gt => lib::llvm::IntSGT,
531530
ast::ge => lib::llvm::IntSGE,
532-
_ => die()
531+
_ => die(cx)
533532
};
534533
return ICmp(cx, cmp, lhs, rhs);
535534
}
@@ -541,7 +540,7 @@ fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
541540
ast::le => lib::llvm::IntULE,
542541
ast::gt => lib::llvm::IntUGT,
543542
ast::ge => lib::llvm::IntUGE,
544-
_ => die()
543+
_ => die(cx)
545544
};
546545
return ICmp(cx, cmp, lhs, rhs);
547546
}

src/librustc/middle/trans/foreign.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1022,8 +1022,7 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item,
10221022
proto: ast::ProtoBorrowed,
10231023
onceness: ast::Many,
10241024
region: ty::re_bound(ty::br_anon(0)),
1025-
bounds: @~[],
1026-
ret_style: ast::return_val},
1025+
bounds: @~[]},
10271026
sig: FnSig {inputs: ~[{mode: ast::expl(ast::by_val),
10281027
ty: star_u8}],
10291028
output: ty::mk_nil(bcx.tcx())}

src/librustc/middle/trans/monomorphize.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,7 @@ fn normalize_for_monomorphization(tcx: ty::ctxt, ty: ty::t) -> Option<ty::t> {
280280
proto: fty.meta.proto,
281281
onceness: ast::Many,
282282
region: ty::re_static,
283-
bounds: @~[],
284-
ret_style: ast::return_val},
283+
bounds: @~[]},
285284
sig: FnSig {inputs: ~[],
286285
output: ty::mk_nil(tcx)}}))
287286
}
@@ -292,8 +291,7 @@ fn normalize_for_monomorphization(tcx: ty::ctxt, ty: ty::t) -> Option<ty::t> {
292291
proto: ast::ProtoBox,
293292
onceness: ast::Many,
294293
region: ty::re_static,
295-
bounds: @~[],
296-
ret_style: ast::return_val},
294+
bounds: @~[]},
297295
sig: FnSig {inputs: ~[],
298296
output: ty::mk_nil(tcx)}}))
299297
}

src/librustc/middle/trans/reflect.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -219,11 +219,7 @@ impl reflector {
219219
ast::extern_fn => 3u
220220
};
221221
let protoval = ast_proto_constant(fty.meta.proto);
222-
let retval = match fty.meta.ret_style {
223-
ast::noreturn => 0u,
224-
ast::return_val => 1u
225-
};
226-
// XXX: Must we allocate here?
222+
let retval = if ty::type_is_bot(fty.sig.output) {0u} else {1u};
227223
let extra = ~[self.c_uint(pureval),
228224
self.c_uint(protoval),
229225
self.c_uint(vec::len(fty.sig.inputs)),

src/librustc/middle/ty.rs

+5-29
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export ty_opaque_closure_ptr, mk_opaque_closure_ptr;
116116
export ty_opaque_box, mk_opaque_box;
117117
export ty_float, mk_float, mk_mach_float, type_is_fp;
118118
export ty_fn, FnTy, FnTyBase, FnMeta, FnSig, mk_fn;
119-
export ty_fn_proto, ty_fn_purity, ty_fn_ret, ty_fn_ret_style, tys_in_fn_ty;
119+
export ty_fn_proto, ty_fn_purity, ty_fn_ret, tys_in_fn_ty;
120120
export ty_int, mk_int, mk_mach_int, mk_char;
121121
export mk_i8, mk_u8, mk_i16, mk_u16, mk_i32, mk_u32, mk_i64, mk_u64;
122122
export mk_f32, mk_f64;
@@ -219,7 +219,6 @@ export terr_regions_not_same, terr_regions_no_overlap;
219219
export terr_regions_insufficiently_polymorphic;
220220
export terr_regions_overly_polymorphic;
221221
export terr_proto_mismatch;
222-
export terr_ret_style_mismatch;
223222
export terr_fn, terr_trait;
224223
export purity_to_str;
225224
export onceness_to_str;
@@ -517,15 +516,13 @@ pure fn type_id(t: t) -> uint { get(t).id }
517516
* - `onceness` indicates whether the function can be called one time or many
518517
* times.
519518
* - `region` is the region bound on the function's upvars (often &static).
520-
* - `bounds` is the parameter bounds on the function's upvars.
521-
* - `ret_style` indicates whether the function returns a value or fails. */
519+
* - `bounds` is the parameter bounds on the function's upvars. */
522520
struct FnMeta {
523521
purity: ast::purity,
524522
proto: ast::Proto,
525523
onceness: ast::Onceness,
526524
region: Region,
527-
bounds: @~[param_bound],
528-
ret_style: ret_style
525+
bounds: @~[param_bound]
529526
}
530527

531528
/**
@@ -695,7 +692,6 @@ struct expected_found<T> {
695692
// Data structures used in type unification
696693
enum type_err {
697694
terr_mismatch,
698-
terr_ret_style_mismatch(expected_found<ast::ret_style>),
699695
terr_purity_mismatch(expected_found<purity>),
700696
terr_onceness_mismatch(expected_found<Onceness>),
701697
terr_mutability,
@@ -2819,11 +2815,10 @@ impl arg : to_bytes::IterBytes {
28192815
28202816
impl FnMeta : to_bytes::IterBytes {
28212817
pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) {
2822-
to_bytes::iter_bytes_5(&self.purity,
2818+
to_bytes::iter_bytes_4(&self.purity,
28232819
&self.proto,
28242820
&self.region,
28252821
&self.bounds,
2826-
&self.ret_style,
28272822
lsb0, f);
28282823
}
28292824
}
@@ -2969,13 +2964,6 @@ pure fn ty_fn_ret(fty: t) -> t {
29692964
}
29702965
}
29712966

2972-
fn ty_fn_ret_style(fty: t) -> ast::ret_style {
2973-
match get(fty).sty {
2974-
ty_fn(ref f) => f.meta.ret_style,
2975-
_ => fail ~"ty_fn_ret_style() called on non-fn type"
2976-
}
2977-
}
2978-
29792967
fn is_fn_ty(fty: t) -> bool {
29802968
match get(fty).sty {
29812969
ty_fn(_) => true,
@@ -3435,17 +3423,6 @@ fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str {
34353423

34363424
match *err {
34373425
terr_mismatch => ~"types differ",
3438-
terr_ret_style_mismatch(values) => {
3439-
fn to_str(s: ast::ret_style) -> ~str {
3440-
match s {
3441-
ast::noreturn => ~"non-returning",
3442-
ast::return_val => ~"return-by-value"
3443-
}
3444-
}
3445-
fmt!("expected %s function, found %s function",
3446-
to_str(values.expected),
3447-
to_str(values.expected))
3448-
}
34493426
terr_purity_mismatch(values) => {
34503427
fmt!("expected %s fn but found %s fn",
34513428
purity_to_str(values.expected),
@@ -4406,8 +4383,7 @@ impl FnMeta : cmp::Eq {
44064383
pure fn eq(&self, other: &FnMeta) -> bool {
44074384
(*self).purity == (*other).purity &&
44084385
(*self).proto == (*other).proto &&
4409-
(*self).bounds == (*other).bounds &&
4410-
(*self).ret_style == (*other).ret_style
4386+
(*self).bounds == (*other).bounds
44114387
}
44124388
pure fn ne(&self, other: &FnMeta) -> bool { !(*self).eq(other) }
44134389
}

src/librustc/middle/typeck/astconv.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -507,8 +507,7 @@ fn ty_of_fn_decl<AC: ast_conv, RS: region_scope Copy Durable>(
507507
proto: ast_proto,
508508
onceness: onceness,
509509
region: bound_region,
510-
bounds: bounds,
511-
ret_style: decl.cf},
510+
bounds: bounds},
512511
sig: FnSig {inputs: input_tys,
513512
output: output_ty}
514513
}

src/librustc/middle/typeck/check/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
10881088

10891089
let supplied_arg_count = args.len();
10901090

1091+
bot |= ty::type_is_bot(fn_ty.sig.output);
1092+
10911093
// Grab the argument types, supplying fresh type variables
10921094
// if the wrong number of arguments were supplied
10931095
let expected_arg_count = fn_ty.sig.inputs.len();
@@ -1215,7 +1217,6 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
12151217
// Pull the return type out of the type of the function.
12161218
match structure_of(fcx, sp, fty) {
12171219
ty::ty_fn(ref f) => {
1218-
bot |= (f.meta.ret_style == ast::noreturn);
12191220
fcx.write_ty(call_expr_id, f.sig.output);
12201221
return bot;
12211222
}
@@ -3073,8 +3074,7 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) {
30733074
proto: ast::ProtoBorrowed,
30743075
onceness: ast::Once,
30753076
region: ty::re_bound(ty::br_anon(0)),
3076-
bounds: @~[],
3077-
ret_style: ast::return_val},
3077+
bounds: @~[]},
30783078
sig: FnSig {inputs: ~[{mode: ast::expl(ast::by_val),
30793079
ty: ty::mk_imm_ptr(
30803080
ccx.tcx,
@@ -3286,8 +3286,7 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) {
32863286
proto: ast::ProtoBare,
32873287
onceness: ast::Many,
32883288
region: ty::re_static,
3289-
bounds: @~[],
3290-
ret_style: ast::return_val},
3289+
bounds: @~[]},
32913290
sig: FnSig {inputs: inputs,
32923291
output: output}
32933292
});

src/librustc/middle/typeck/collect.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,7 @@ fn get_enum_variant_types(ccx: @crate_ctxt,
161161
proto: ast::ProtoBare,
162162
onceness: ast::Many,
163163
bounds: @~[],
164-
region: ty::re_static,
165-
ret_style: ast::return_val},
164+
region: ty::re_static},
166165
sig: FnSig {inputs: args,
167166
output: enum_ty}
168167
}));
@@ -195,8 +194,7 @@ fn get_enum_variant_types(ccx: @crate_ctxt,
195194
proto: ast::ProtoBare,
196195
onceness: ast::Many,
197196
bounds: @~[],
198-
region: ty::re_static,
199-
ret_style: ast::return_val},
197+
region: ty::re_static},
200198
sig: FnSig {inputs: struct_fields, output: enum_ty }}));
201199
}
202200
ast::enum_variant_kind(ref enum_definition) => {
@@ -698,8 +696,7 @@ fn convert_struct(ccx: @crate_ctxt,
698696
proto: ast::ProtoBare,
699697
onceness: ast::Many,
700698
bounds: @~[],
701-
region: ty::re_static,
702-
ret_style: ast::return_val,
699+
region: ty::re_static
703700
},
704701
sig: FnSig {
705702
inputs: do struct_def.fields.map |field| {
@@ -967,8 +964,7 @@ fn ty_of_foreign_fn_decl(ccx: @crate_ctxt,
967964
onceness: ast::Many,
968965
proto: ast::ProtoBare,
969966
bounds: @~[],
970-
region: ty::re_static,
971-
ret_style: ast::return_val},
967+
region: ty::re_static},
972968
sig: FnSig {inputs: input_tys,
973969
output: output_ty}
974970
});

src/librustc/middle/typeck/infer/combine.rs

+1-4
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ trait combine {
8888
fn modes(a: ast::mode, b: ast::mode) -> cres<ast::mode>;
8989
fn args(a: ty::arg, b: ty::arg) -> cres<ty::arg>;
9090
fn protos(p1: ast::Proto, p2: ast::Proto) -> cres<ast::Proto>;
91-
fn ret_styles(r1: ret_style, r2: ret_style) -> cres<ret_style>;
9291
fn purities(a: purity, b: purity) -> cres<purity>;
9392
fn oncenesses(a: Onceness, b: Onceness) -> cres<Onceness>;
9493
fn contraregions(a: ty::Region, b: ty::Region) -> cres<ty::Region>;
@@ -331,15 +330,13 @@ fn super_fn_metas<C:combine>(
331330
{
332331
let p = if_ok!(self.protos(a_f.proto, b_f.proto));
333332
let r = if_ok!(self.contraregions(a_f.region, b_f.region));
334-
let rs = if_ok!(self.ret_styles(a_f.ret_style, b_f.ret_style));
335333
let purity = if_ok!(self.purities(a_f.purity, b_f.purity));
336334
let onceness = if_ok!(self.oncenesses(a_f.onceness, b_f.onceness));
337335
Ok(FnMeta {purity: purity,
338336
proto: p,
339337
region: r,
340338
onceness: onceness,
341-
bounds: a_f.bounds, // XXX: This is wrong!
342-
ret_style: rs})
339+
bounds: a_f.bounds}) // XXX: This is wrong!
343340
}
344341

345342
fn super_fn_sigs<C:combine>(

src/librustc/middle/typeck/infer/glb.rs

-12
Original file line numberDiff line numberDiff line change
@@ -105,18 +105,6 @@ impl Glb: combine {
105105
}
106106
}
107107

108-
fn ret_styles(r1: ret_style, r2: ret_style) -> cres<ret_style> {
109-
match (r1, r2) {
110-
(ast::return_val, ast::return_val) => {
111-
Ok(ast::return_val)
112-
}
113-
(ast::noreturn, _) |
114-
(_, ast::noreturn) => {
115-
Ok(ast::noreturn)
116-
}
117-
}
118-
}
119-
120108
fn regions(a: ty::Region, b: ty::Region) -> cres<ty::Region> {
121109
debug!("%s.regions(%?, %?)",
122110
self.tag(),

0 commit comments

Comments
 (0)