Skip to content

Remove ret_style and instead check whether fn return type is bot #4383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,6 @@ fn parse_arg_data(data: @~[u8], crate_num: int, pos: uint, tcx: ty::ctxt,
parse_arg(st, conv)
}

fn parse_ret_ty(st: @pstate, conv: conv_did) -> (ast::ret_style, ty::t) {
match peek(st) {
'!' => { next(st); (ast::noreturn, ty::mk_bot(st.tcx)) }
_ => (ast::return_val, parse_ty(st, conv))
}
}

fn parse_path(st: @pstate) -> @ast::path {
let mut idents: ~[ast::ident] = ~[];
fn is_last(c: char) -> bool { return c == '(' || c == ':'; }
Expand Down Expand Up @@ -437,14 +430,13 @@ fn parse_ty_fn(st: @pstate, conv: conv_did) -> ty::FnTy {
inputs.push({mode: mode, ty: parse_ty(st, conv)});
}
st.pos += 1u; // eat the ']'
let (ret_style, ret_ty) = parse_ret_ty(st, conv);
let ret_ty = parse_ty(st, conv);
return FnTyBase {
meta: FnMeta {purity: purity,
proto: proto,
onceness: onceness,
bounds: bounds,
region: region,
ret_style: ret_style},
region: region},
sig: FnSig {inputs: inputs,
output: ret_ty}
};
Expand Down
5 changes: 1 addition & 4 deletions src/librustc/metadata/tyencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,7 @@ fn enc_ty_fn(w: io::Writer, cx: @ctxt, ft: ty::FnTy) {
enc_arg(w, cx, *arg);
}
w.write_char(']');
match ft.meta.ret_style {
noreturn => w.write_char('!'),
_ => enc_ty(w, cx, ft.sig.output)
}
enc_ty(w, cx, ft.sig.output);
}

fn enc_bounds(w: io::Writer, cx: @ctxt, bs: @~[ty::param_bound]) {
Expand Down
26 changes: 14 additions & 12 deletions src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,20 +580,22 @@ fn check_item_type_limits(cx: ty::ctxt, it: @ast::item) {
}
}

let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
visit_expr: fn@(e: @ast::expr) {
match e.node {
ast::expr_binary(ref binop, @ref l, @ref r) => {
if is_comparison(*binop)
&& !check_limits(cx, *binop, l, r) {
cx.sess.span_lint(
type_limits, e.id, it.id, e.span,
~"comparison is useless due to type limits");
}
let visit_expr: @fn(@ast::expr) = |e| {
match e.node {
ast::expr_binary(ref binop, @ref l, @ref r) => {
if is_comparison(*binop)
&& !check_limits(cx, *binop, l, r) {
cx.sess.span_lint(
type_limits, e.id, it.id, e.span,
~"comparison is useless due to type limits");
}
_ => ()
}
},
_ => ()
}
};

let visit = item_stopping_visitor(visit::mk_simple_visitor(@{
visit_expr: visit_expr,
.. *visit::default_simple_visitor()
}));
visit::visit_item(it, (), visit);
Expand Down
11 changes: 5 additions & 6 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,10 @@ fn compare_scalar_types(cx: block, lhs: ValueRef, rhs: ValueRef,
fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
nt: scalar_type, op: ast::binop) -> ValueRef {
let _icx = cx.insn_ctxt("compare_scalar_values");
fn die_(cx: block) -> ! {
fn die(cx: block) -> ! {
cx.tcx().sess.bug(~"compare_scalar_values: must be a\
comparison operator");
}
let die = fn@() -> ! { die_(cx) };
match nt {
nil_type => {
// We don't need to do actual comparisons for nil.
Expand All @@ -506,7 +505,7 @@ fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
ast::eq | ast::le | ast::ge => return C_bool(true),
ast::ne | ast::lt | ast::gt => return C_bool(false),
// refinements would be nice
_ => die()
_ => die(cx)
}
}
floating_point => {
Expand All @@ -517,7 +516,7 @@ fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
ast::le => lib::llvm::RealOLE,
ast::gt => lib::llvm::RealOGT,
ast::ge => lib::llvm::RealOGE,
_ => die()
_ => die(cx)
};
return FCmp(cx, cmp, lhs, rhs);
}
Expand All @@ -529,7 +528,7 @@ fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
ast::le => lib::llvm::IntSLE,
ast::gt => lib::llvm::IntSGT,
ast::ge => lib::llvm::IntSGE,
_ => die()
_ => die(cx)
};
return ICmp(cx, cmp, lhs, rhs);
}
Expand All @@ -541,7 +540,7 @@ fn compare_scalar_values(cx: block, lhs: ValueRef, rhs: ValueRef,
ast::le => lib::llvm::IntULE,
ast::gt => lib::llvm::IntUGT,
ast::ge => lib::llvm::IntUGE,
_ => die()
_ => die(cx)
};
return ICmp(cx, cmp, lhs, rhs);
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/trans/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1022,8 +1022,7 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::foreign_item,
proto: ast::ProtoBorrowed,
onceness: ast::Many,
region: ty::re_bound(ty::br_anon(0)),
bounds: @~[],
ret_style: ast::return_val},
bounds: @~[]},
sig: FnSig {inputs: ~[{mode: ast::expl(ast::by_val),
ty: star_u8}],
output: ty::mk_nil(bcx.tcx())}
Expand Down
6 changes: 2 additions & 4 deletions src/librustc/middle/trans/monomorphize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,7 @@ fn normalize_for_monomorphization(tcx: ty::ctxt, ty: ty::t) -> Option<ty::t> {
proto: fty.meta.proto,
onceness: ast::Many,
region: ty::re_static,
bounds: @~[],
ret_style: ast::return_val},
bounds: @~[]},
sig: FnSig {inputs: ~[],
output: ty::mk_nil(tcx)}}))
}
Expand All @@ -292,8 +291,7 @@ fn normalize_for_monomorphization(tcx: ty::ctxt, ty: ty::t) -> Option<ty::t> {
proto: ast::ProtoBox,
onceness: ast::Many,
region: ty::re_static,
bounds: @~[],
ret_style: ast::return_val},
bounds: @~[]},
sig: FnSig {inputs: ~[],
output: ty::mk_nil(tcx)}}))
}
Expand Down
6 changes: 1 addition & 5 deletions src/librustc/middle/trans/reflect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,11 +219,7 @@ impl reflector {
ast::extern_fn => 3u
};
let protoval = ast_proto_constant(fty.meta.proto);
let retval = match fty.meta.ret_style {
ast::noreturn => 0u,
ast::return_val => 1u
};
// XXX: Must we allocate here?
let retval = if ty::type_is_bot(fty.sig.output) {0u} else {1u};
let extra = ~[self.c_uint(pureval),
self.c_uint(protoval),
self.c_uint(vec::len(fty.sig.inputs)),
Expand Down
34 changes: 5 additions & 29 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export ty_opaque_closure_ptr, mk_opaque_closure_ptr;
export ty_opaque_box, mk_opaque_box;
export ty_float, mk_float, mk_mach_float, type_is_fp;
export ty_fn, FnTy, FnTyBase, FnMeta, FnSig, mk_fn;
export ty_fn_proto, ty_fn_purity, ty_fn_ret, ty_fn_ret_style, tys_in_fn_ty;
export ty_fn_proto, ty_fn_purity, ty_fn_ret, tys_in_fn_ty;
export ty_int, mk_int, mk_mach_int, mk_char;
export mk_i8, mk_u8, mk_i16, mk_u16, mk_i32, mk_u32, mk_i64, mk_u64;
export mk_f32, mk_f64;
Expand Down Expand Up @@ -219,7 +219,6 @@ export terr_regions_not_same, terr_regions_no_overlap;
export terr_regions_insufficiently_polymorphic;
export terr_regions_overly_polymorphic;
export terr_proto_mismatch;
export terr_ret_style_mismatch;
export terr_fn, terr_trait;
export purity_to_str;
export onceness_to_str;
Expand Down Expand Up @@ -517,15 +516,13 @@ pure fn type_id(t: t) -> uint { get(t).id }
* - `onceness` indicates whether the function can be called one time or many
* times.
* - `region` is the region bound on the function's upvars (often &static).
* - `bounds` is the parameter bounds on the function's upvars.
* - `ret_style` indicates whether the function returns a value or fails. */
* - `bounds` is the parameter bounds on the function's upvars. */
struct FnMeta {
purity: ast::purity,
proto: ast::Proto,
onceness: ast::Onceness,
region: Region,
bounds: @~[param_bound],
ret_style: ret_style
bounds: @~[param_bound]
}

/**
Expand Down Expand Up @@ -695,7 +692,6 @@ struct expected_found<T> {
// Data structures used in type unification
enum type_err {
terr_mismatch,
terr_ret_style_mismatch(expected_found<ast::ret_style>),
terr_purity_mismatch(expected_found<purity>),
terr_onceness_mismatch(expected_found<Onceness>),
terr_mutability,
Expand Down Expand Up @@ -2819,11 +2815,10 @@ impl arg : to_bytes::IterBytes {

impl FnMeta : to_bytes::IterBytes {
pure fn iter_bytes(&self, +lsb0: bool, f: to_bytes::Cb) {
to_bytes::iter_bytes_5(&self.purity,
to_bytes::iter_bytes_4(&self.purity,
&self.proto,
&self.region,
&self.bounds,
&self.ret_style,
lsb0, f);
}
}
Expand Down Expand Up @@ -2969,13 +2964,6 @@ pure fn ty_fn_ret(fty: t) -> t {
}
}

fn ty_fn_ret_style(fty: t) -> ast::ret_style {
match get(fty).sty {
ty_fn(ref f) => f.meta.ret_style,
_ => fail ~"ty_fn_ret_style() called on non-fn type"
}
}

fn is_fn_ty(fty: t) -> bool {
match get(fty).sty {
ty_fn(_) => true,
Expand Down Expand Up @@ -3435,17 +3423,6 @@ fn type_err_to_str(cx: ctxt, err: &type_err) -> ~str {

match *err {
terr_mismatch => ~"types differ",
terr_ret_style_mismatch(values) => {
fn to_str(s: ast::ret_style) -> ~str {
match s {
ast::noreturn => ~"non-returning",
ast::return_val => ~"return-by-value"
}
}
fmt!("expected %s function, found %s function",
to_str(values.expected),
to_str(values.expected))
}
terr_purity_mismatch(values) => {
fmt!("expected %s fn but found %s fn",
purity_to_str(values.expected),
Expand Down Expand Up @@ -4406,8 +4383,7 @@ impl FnMeta : cmp::Eq {
pure fn eq(&self, other: &FnMeta) -> bool {
(*self).purity == (*other).purity &&
(*self).proto == (*other).proto &&
(*self).bounds == (*other).bounds &&
(*self).ret_style == (*other).ret_style
(*self).bounds == (*other).bounds
}
pure fn ne(&self, other: &FnMeta) -> bool { !(*self).eq(other) }
}
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -507,8 +507,7 @@ fn ty_of_fn_decl<AC: ast_conv, RS: region_scope Copy Durable>(
proto: ast_proto,
onceness: onceness,
region: bound_region,
bounds: bounds,
ret_style: decl.cf},
bounds: bounds},
sig: FnSig {inputs: input_tys,
output: output_ty}
}
Expand Down
9 changes: 4 additions & 5 deletions src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,

let supplied_arg_count = args.len();

bot |= ty::type_is_bot(fn_ty.sig.output);

// Grab the argument types, supplying fresh type variables
// if the wrong number of arguments were supplied
let expected_arg_count = fn_ty.sig.inputs.len();
Expand Down Expand Up @@ -1215,7 +1217,6 @@ fn check_expr_with_unifier(fcx: @fn_ctxt,
// Pull the return type out of the type of the function.
match structure_of(fcx, sp, fty) {
ty::ty_fn(ref f) => {
bot |= (f.meta.ret_style == ast::noreturn);
fcx.write_ty(call_expr_id, f.sig.output);
return bot;
}
Expand Down Expand Up @@ -3073,8 +3074,7 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) {
proto: ast::ProtoBorrowed,
onceness: ast::Once,
region: ty::re_bound(ty::br_anon(0)),
bounds: @~[],
ret_style: ast::return_val},
bounds: @~[]},
sig: FnSig {inputs: ~[{mode: ast::expl(ast::by_val),
ty: ty::mk_imm_ptr(
ccx.tcx,
Expand Down Expand Up @@ -3286,8 +3286,7 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::foreign_item) {
proto: ast::ProtoBare,
onceness: ast::Many,
region: ty::re_static,
bounds: @~[],
ret_style: ast::return_val},
bounds: @~[]},
sig: FnSig {inputs: inputs,
output: output}
});
Expand Down
12 changes: 4 additions & 8 deletions src/librustc/middle/typeck/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,7 @@ fn get_enum_variant_types(ccx: @crate_ctxt,
proto: ast::ProtoBare,
onceness: ast::Many,
bounds: @~[],
region: ty::re_static,
ret_style: ast::return_val},
region: ty::re_static},
sig: FnSig {inputs: args,
output: enum_ty}
}));
Expand Down Expand Up @@ -195,8 +194,7 @@ fn get_enum_variant_types(ccx: @crate_ctxt,
proto: ast::ProtoBare,
onceness: ast::Many,
bounds: @~[],
region: ty::re_static,
ret_style: ast::return_val},
region: ty::re_static},
sig: FnSig {inputs: struct_fields, output: enum_ty }}));
}
ast::enum_variant_kind(ref enum_definition) => {
Expand Down Expand Up @@ -698,8 +696,7 @@ fn convert_struct(ccx: @crate_ctxt,
proto: ast::ProtoBare,
onceness: ast::Many,
bounds: @~[],
region: ty::re_static,
ret_style: ast::return_val,
region: ty::re_static
},
sig: FnSig {
inputs: do struct_def.fields.map |field| {
Expand Down Expand Up @@ -967,8 +964,7 @@ fn ty_of_foreign_fn_decl(ccx: @crate_ctxt,
onceness: ast::Many,
proto: ast::ProtoBare,
bounds: @~[],
region: ty::re_static,
ret_style: ast::return_val},
region: ty::re_static},
sig: FnSig {inputs: input_tys,
output: output_ty}
});
Expand Down
5 changes: 1 addition & 4 deletions src/librustc/middle/typeck/infer/combine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ trait combine {
fn modes(a: ast::mode, b: ast::mode) -> cres<ast::mode>;
fn args(a: ty::arg, b: ty::arg) -> cres<ty::arg>;
fn protos(p1: ast::Proto, p2: ast::Proto) -> cres<ast::Proto>;
fn ret_styles(r1: ret_style, r2: ret_style) -> cres<ret_style>;
fn purities(a: purity, b: purity) -> cres<purity>;
fn oncenesses(a: Onceness, b: Onceness) -> cres<Onceness>;
fn contraregions(a: ty::Region, b: ty::Region) -> cres<ty::Region>;
Expand Down Expand Up @@ -331,15 +330,13 @@ fn super_fn_metas<C:combine>(
{
let p = if_ok!(self.protos(a_f.proto, b_f.proto));
let r = if_ok!(self.contraregions(a_f.region, b_f.region));
let rs = if_ok!(self.ret_styles(a_f.ret_style, b_f.ret_style));
let purity = if_ok!(self.purities(a_f.purity, b_f.purity));
let onceness = if_ok!(self.oncenesses(a_f.onceness, b_f.onceness));
Ok(FnMeta {purity: purity,
proto: p,
region: r,
onceness: onceness,
bounds: a_f.bounds, // XXX: This is wrong!
ret_style: rs})
bounds: a_f.bounds}) // XXX: This is wrong!
}

fn super_fn_sigs<C:combine>(
Expand Down
12 changes: 0 additions & 12 deletions src/librustc/middle/typeck/infer/glb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,6 @@ impl Glb: combine {
}
}

fn ret_styles(r1: ret_style, r2: ret_style) -> cres<ret_style> {
match (r1, r2) {
(ast::return_val, ast::return_val) => {
Ok(ast::return_val)
}
(ast::noreturn, _) |
(_, ast::noreturn) => {
Ok(ast::noreturn)
}
}
}

fn regions(a: ty::Region, b: ty::Region) -> cres<ty::Region> {
debug!("%s.regions(%?, %?)",
self.tag(),
Expand Down
Loading