Skip to content

Commit f9015c3

Browse files
bogglegraydon
authored andcommitted
---
yaml --- r: 6557 b: refs/heads/master c: 29f7cdf h: refs/heads/master i: 6555: 6b5f504 v: v3
1 parent 29903bb commit f9015c3

File tree

5 files changed

+34
-6
lines changed

5 files changed

+34
-6
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: d116a6f2d39d6fe9484b5c1b5f818756a78fd3bc
2+
refs/heads/master: 29f7cdffa4688aa539be4f0f6d2eab7f5af8a2d6

trunk/src/comp/middle/trans.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4086,7 +4086,14 @@ fn trans_expr(bcx: @block_ctxt, e: @ast::expr, dest: dest) -> @block_ctxt {
40864086
if !ty::expr_is_lval(tcx, a) { ret trans_expr(bcx, a, dest); }
40874087
else { ret lval_to_dps(bcx, a, dest); }
40884088
}
4089-
ast::expr_cast(val, _) { ret trans_cast(bcx, val, e.id, dest); }
4089+
ast::expr_cast(val, _) {
4090+
alt tcx.cast_map.find(e.id) {
4091+
option::none. { ret trans_cast(bcx, val, e.id, dest); }
4092+
some { alt option::get(some) {
4093+
ty::triv_cast. { ret trans_expr(bcx, val, dest); }
4094+
} }
4095+
}
4096+
}
40904097
ast::expr_anon_obj(anon_obj) {
40914098
ret trans_anon_obj(bcx, e.span, anon_obj, e.id, dest);
40924099
}

trunk/src/comp/middle/ty.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ export ast_constr_to_constr;
3232
export bind_params_in_type;
3333
export block_ty;
3434
export constr;
35+
export cast_type;
3536
export constr_general;
3637
export constr_table;
3738
export count_ty_params;
@@ -102,6 +103,7 @@ export substitute_type_params;
102103
export t;
103104
export tag_variants;
104105
export tag_variant_with_id;
106+
export triv_cast;
105107
export triv_eq_ty;
106108
export ty_param_substs_opt_and_ty;
107109
export ty_param_kinds_and_ty;
@@ -201,6 +203,12 @@ type mt = {ty: t, mut: ast::mutability};
201203
// the types of AST nodes.
202204
type creader_cache = hashmap<{cnum: int, pos: uint, len: uint}, ty::t>;
203205

206+
tag cast_type {
207+
/* cast may be ignored after substituting primitive with machine types
208+
since expr already has the right type */
209+
triv_cast;
210+
}
211+
204212
type ctxt =
205213
// constr_table fn_constrs,
206214
// We need the ext_map just for printing the types of tags defined in
@@ -209,6 +217,7 @@ type ctxt =
209217
sess: session::session,
210218
def_map: resolve::def_map,
211219
ext_map: resolve::ext_map,
220+
cast_map: hashmap<ast::node_id, cast_type>,
212221
node_types: node_type_table,
213222
items: ast_map::map,
214223
freevars: freevars::freevar_map,
@@ -396,6 +405,7 @@ fn mk_ctxt(s: session::session, dm: resolve::def_map,
396405
sess: s,
397406
def_map: dm,
398407
ext_map: em,
408+
cast_map: ast_util::new_node_hash(),
399409
node_types: ntt,
400410
items: amap,
401411
freevars: freevars,

trunk/src/comp/middle/typeck.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2101,15 +2101,19 @@ fn check_expr_with_unifier(fcx: @fn_ctxt, expr: @ast::expr, unify: unifier,
21012101
ast::expr_cast(e, t) {
21022102
bot = check_expr(fcx, e);
21032103
let t_1 = ast_ty_to_ty_crate(fcx.ccx, t);
2104-
// FIXME: there are more forms of cast to support, eventually.
2104+
let t_e = expr_ty(tcx, e);
21052105

2106-
if !(type_is_scalar(fcx, expr.span, expr_ty(tcx, e)) &&
2107-
type_is_scalar(fcx, expr.span, t_1)) {
2106+
// FIXME there are more forms of cast to support, eventually.
2107+
if !( type_is_scalar(fcx, expr.span, t_e)
2108+
&& type_is_scalar(fcx, expr.span, t_1)) {
21082109
tcx.sess.span_err(expr.span,
21092110
"non-scalar cast: " +
21102111
ty_to_str(tcx, expr_ty(tcx, e)) + " as " +
21112112
ty_to_str(tcx, t_1));
21122113
}
2114+
2115+
if ty::triv_eq_ty(tcx, t_1, t_e)
2116+
{ tcx.cast_map.insert(expr.id, ty::triv_cast); }
21132117
write::ty_only_fixup(fcx, id, t_1);
21142118
}
21152119
ast::expr_vec(args, mut) {

trunk/src/comp/syntax/ast_util.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
1-
import std::{str, option};
1+
import std::{str, option, int, map};
22
import codemap::span;
33
import ast::*;
44

55
fn respan<copy T>(sp: span, t: T) -> spanned<T> {
66
ret {node: t, span: sp};
77
}
88

9+
fn new_node_hash<copy V>() -> map::hashmap<node_id, V> {
10+
fn node_id_hash(&&i: node_id) -> uint { ret int::hash(i as int); }
11+
fn node_id_eq(&&a: node_id, &&b: node_id) -> bool
12+
{ ret int::eq(a as int, b as int); }
13+
ret map::mk_hashmap(node_id_hash, node_id_eq);
14+
}
15+
916
/* assuming that we're not in macro expansion */
1017
fn mk_sp(lo: uint, hi: uint) -> span {
1118
ret {lo: lo, hi: hi, expanded_from: codemap::os_none};

0 commit comments

Comments
 (0)