Skip to content

Commit e2e077c

Browse files
committed
Remove trivial cast checker
I consider the added complexity not justified at this point, and it interacts badly with the patches for issue #828. Feel free to discuss.
1 parent e31983a commit e2e077c

File tree

10 files changed

+36
-194
lines changed

10 files changed

+36
-194
lines changed

src/comp/middle/check_const.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ fn check_expr(sess: session, e: @expr, &&is_const: bool, v: visit::vt<bool>) {
4343
"disallowed operator in constant expression");
4444
ret;
4545
}
46-
expr_cast(_, _) { }
4746
expr_lit(@{node: lit_str(_), _}) {
4847
sess.span_err(e.span,
4948
"string constants are not supported");

src/comp/middle/trans.rs

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3581,12 +3581,7 @@ fn trans_expr(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt {
35813581
}
35823582
else { ret lval_to_dps(bcx, a, dest); }
35833583
}
3584-
ast::expr_cast(val, _) {
3585-
alt tcx.cast_map.find(e.id) {
3586-
some(ty::triv_cast.) { ret trans_expr(bcx, val, dest); }
3587-
_ { ret trans_cast(bcx, val, e.id, dest); }
3588-
}
3589-
}
3584+
ast::expr_cast(val, _) { ret trans_cast(bcx, val, e.id, dest); }
35903585
ast::expr_anon_obj(anon_obj) {
35913586
ret trans_anon_obj(bcx, e.span, anon_obj, e.id, dest);
35923587
}
@@ -3615,7 +3610,7 @@ fn trans_expr(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt {
36153610
// that is_call_expr(ex) -- but we don't support that
36163611
// yet
36173612
// FIXME
3618-
check (ast_util::is_tail_call_expr(ex));
3613+
check (ast_util::is_call_expr(ex));
36193614
ret trans_be(bcx, ex);
36203615
}
36213616
ast::expr_fail(expr) {
@@ -3952,8 +3947,7 @@ fn trans_ret(bcx: @block_ctxt, e: option::t<@ast::expr>) -> @block_ctxt {
39523947
fn build_return(bcx: @block_ctxt) { Br(bcx, bcx_fcx(bcx).llreturn); }
39533948

39543949
// fn trans_be(cx: &@block_ctxt, e: &@ast::expr) -> result {
3955-
fn trans_be(cx: @block_ctxt, e: @ast::expr) :
3956-
ast_util::is_tail_call_expr(e) ->
3950+
fn trans_be(cx: @block_ctxt, e: @ast::expr) : ast_util::is_call_expr(e) ->
39573951
@block_ctxt {
39583952
// FIXME: Turn this into a real tail call once
39593953
// calling convention issues are settled
@@ -4728,16 +4722,6 @@ fn trans_impl(cx: @local_ctxt, name: ast::ident, methods: [@ast::method],
47284722
// that does so later on?
47294723
fn trans_const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
47304724
alt e.node {
4731-
ast::expr_cast(e1, _) {
4732-
alt ccx_tcx(cx).cast_map.find(e.id) {
4733-
some(ty::triv_cast.) { trans_const_expr(cx, e1) }
4734-
_ {
4735-
cx.sess.span_err(e.span,
4736-
"non-trivial cast in constant expression");
4737-
fail;
4738-
}
4739-
}
4740-
}
47414725
ast::expr_lit(lit) { ret trans_crate_lit(cx, *lit); }
47424726
ast::expr_binary(b, e1, e2) {
47434727
let te1 = trans_const_expr(cx, e1);

src/comp/middle/ty.rs

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ export ast_constr_to_constr;
3131
export bind_params_in_type;
3232
export block_ty;
3333
export constr;
34-
export cast_type;
3534
export constr_general;
3635
export constr_table;
3736
export count_ty_params;
@@ -106,8 +105,6 @@ export substitute_type_params;
106105
export t;
107106
export tag_variants;
108107
export tag_variant_with_id;
109-
export triv_cast;
110-
export triv_eq_ty;
111108
export ty_param_substs_opt_and_ty;
112109
export ty_param_kinds_and_ty;
113110
export ty_native_fn;
@@ -133,7 +130,6 @@ export ty_param;
133130
export ty_ptr;
134131
export ty_rec;
135132
export ty_tag;
136-
export ty_to_machine_ty;
137133
export ty_tup;
138134
export ty_type;
139135
export ty_send_type;
@@ -214,17 +210,10 @@ type creader_cache = hashmap<{cnum: int, pos: uint, len: uint}, ty::t>;
214210
type tag_var_cache =
215211
@smallintmap::smallintmap<@mutable [variant_info]>;
216212

217-
tag cast_type {
218-
/* cast may be ignored after substituting primitive with machine types
219-
since expr already has the right type */
220-
triv_cast;
221-
}
222-
223213
type ctxt =
224214
@{ts: @type_store,
225215
sess: session::session,
226216
def_map: resolve::def_map,
227-
cast_map: hashmap<ast::node_id, cast_type>,
228217
node_types: node_type_table,
229218
items: ast_map::map,
230219
freevars: freevars::freevar_map,
@@ -420,7 +409,6 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map, amap: ast_map::map,
420409
@{ts: ts,
421410
sess: s,
422411
def_map: dm,
423-
cast_map: ast_util::new_node_hash(),
424412
node_types: ntt,
425413
items: amap,
426414
freevars: freevars,
@@ -1423,42 +1411,6 @@ fn eq_raw_ty(&&a: @raw_t, &&b: @raw_t) -> bool {
14231411
// the types are interned.
14241412
fn eq_ty(&&a: t, &&b: t) -> bool { a == b }
14251413

1426-
1427-
// Convert type to machine type
1428-
// (i.e. replace uint, int, float with target architecture machine types)
1429-
//
1430-
// FIXME somewhat expensive but this should only be called rarely
1431-
fn ty_to_machine_ty(cx: ctxt, ty: t) -> t {
1432-
fn sub_fn(cx: ctxt, uint_ty: t, int_ty: t, float_ty: t, in: t) -> t {
1433-
alt struct(cx, in) {
1434-
ty_uint(ast::ty_u.) { ret uint_ty; }
1435-
ty_int(ast::ty_i.) { ret int_ty; }
1436-
ty_float(ast::ty_f.) { ret float_ty; }
1437-
_ { ret in; }
1438-
}
1439-
}
1440-
1441-
let cfg = cx.sess.get_targ_cfg();
1442-
let uint_ty = mk_mach_uint(cx, cfg.uint_type);
1443-
let int_ty = mk_mach_int(cx, cfg.int_type);
1444-
let float_ty = mk_mach_float(cx, cfg.float_type);
1445-
let fold_m = fm_general(bind sub_fn(cx, uint_ty, int_ty, float_ty, _));
1446-
1447-
ret fold_ty(cx, fold_m, ty);
1448-
}
1449-
1450-
// Two types are trivially equal if they are either
1451-
// equal or if they are equal after substituting all occurences of
1452-
// machine independent primitive types by their machine type equivalents
1453-
// for the current target architecture
1454-
fn triv_eq_ty(cx: ctxt, &&a: t, &&b: t) -> bool {
1455-
let a = alt interner::get(*cx.ts, a).struct
1456-
{ ty_named(t, _) { t } _ { a } };
1457-
let b = alt interner::get(*cx.ts, b).struct
1458-
{ ty_named(t, _) { t } _ { b } };
1459-
a == b || ty_to_machine_ty(cx, a) == ty_to_machine_ty(cx, b)
1460-
}
1461-
14621414
// Type lookups
14631415
fn node_id_to_ty_param_substs_opt_and_ty(cx: ctxt, id: ast::node_id) ->
14641416
ty_param_substs_opt_and_ty {

src/comp/middle/typeck.rs

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1850,21 +1850,8 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
18501850
}
18511851
ast::expr_be(e) {
18521852
// FIXME: prove instead of assert
1853-
assert (ast_util::is_tail_call_expr(e));
1853+
assert (ast_util::is_call_expr(e));
18541854
check_expr_with(fcx, e, fcx.ret_ty);
1855-
1856-
alt e.node {
1857-
ast::expr_cast(_, _) {
1858-
alt tcx.cast_map.find(e.id) {
1859-
option::some(ty::triv_cast.) { }
1860-
_ { tcx.sess.span_err(expr.span,
1861-
"non-trivial cast of tail-call return value");
1862-
}
1863-
}
1864-
}
1865-
_ { /* regular tail call */ }
1866-
}
1867-
18681855
bot = true;
18691856
write::nil_ty(tcx, id);
18701857
}
@@ -2066,19 +2053,19 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
20662053
ast::expr_cast(e, t) {
20672054
bot = check_expr(fcx, e);
20682055
let t_1 = ast_ty_to_ty_crate(fcx.ccx, t);
2069-
let t_e = expr_ty(tcx, e);
2056+
let t_e = ty::expr_ty(tcx, e);
20702057

20712058
if ty::type_is_nil(tcx, t_e) {
20722059
tcx.sess.span_err(expr.span,
20732060
"cast from nil: " +
2074-
ty_to_str(tcx, expr_ty(tcx, e)) + " as " +
2061+
ty_to_str(tcx, t_e) + " as " +
20752062
ty_to_str(tcx, t_1));
20762063
}
20772064

20782065
if ty::type_is_nil(tcx, t_1) {
20792066
tcx.sess.span_err(expr.span,
20802067
"cast to nil: " +
2081-
ty_to_str(tcx, expr_ty(tcx, e)) + " as " +
2068+
ty_to_str(tcx, t_e) + " as " +
20822069
ty_to_str(tcx, t_1));
20832070
}
20842071

@@ -2087,14 +2074,9 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
20872074
&& type_is_scalar(fcx, expr.span, t_1)) {
20882075
tcx.sess.span_err(expr.span,
20892076
"non-scalar cast: " +
2090-
ty_to_str(tcx, expr_ty(tcx, e)) + " as " +
2077+
ty_to_str(tcx, t_e) + " as " +
20912078
ty_to_str(tcx, t_1));
20922079
}
2093-
2094-
// mark as triv_cast for later dropping in trans
2095-
if ty::triv_eq_ty(tcx, t_1, t_e)
2096-
{ tcx.cast_map.insert(expr.id, ty::triv_cast); }
2097-
20982080
write::ty_only_fixup(fcx, id, t_1);
20992081
}
21002082
ast::expr_vec(args, mut) {

src/comp/syntax/ast_util.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,10 @@
1-
import core::{str, option, int};
2-
import std::map;
31
import codemap::span;
42
import ast::*;
53

64
fn respan<copy T>(sp: span, t: T) -> spanned<T> {
75
ret {node: t, span: sp};
86
}
97

10-
fn new_node_hash<copy V>() -> map::hashmap<node_id, V> {
11-
fn node_id_hash(&&i: node_id) -> uint { ret int::hash(i as int); }
12-
fn node_id_eq(&&a: node_id, &&b: node_id) -> bool
13-
{ ret int::eq(a as int, b as int); }
14-
ret map::mk_hashmap(node_id_hash, node_id_eq);
15-
}
16-
178
/* assuming that we're not in macro expansion */
189
fn mk_sp(lo: uint, hi: uint) -> span {
1910
ret {lo: lo, hi: hi, expanded_from: codemap::os_none};
@@ -198,14 +189,6 @@ pure fn is_call_expr(e: @expr) -> bool {
198189
alt e.node { expr_call(_, _, _) { true } _ { false } }
199190
}
200191

201-
pure fn is_tail_call_expr(e: @expr) -> bool {
202-
alt e.node {
203-
expr_call(_, _, _) { true }
204-
expr_cast(inner_e, _) { is_call_expr(inner_e) }
205-
_ { false }
206-
}
207-
}
208-
209192
fn is_constraint_arg(e: @expr) -> bool {
210193
alt e.node {
211194
expr_lit(_) { ret true; }

src/comp/syntax/parse/parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -958,7 +958,7 @@ fn parse_bottom_expr(p: parser) -> @ast::expr {
958958
let e = parse_expr(p);
959959

960960
// FIXME: Is this the right place for this check?
961-
if /*check*/ ast_util::is_tail_call_expr(e) {
961+
if /*check*/ast_util::is_call_expr(e) {
962962
hi = e.span.hi;
963963
ex = ast::expr_be(e);
964964
} else { p.fatal("Non-call expression in tail call"); }

0 commit comments

Comments
 (0)