Skip to content

Commit ecb994e

Browse files
committed
---
yaml --- r: 13500 b: refs/heads/master c: 8ab15c0 h: refs/heads/master v: v3
1 parent 54ef31c commit ecb994e

File tree

17 files changed

+193
-203
lines changed

17 files changed

+193
-203
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 77e6573929702731bc0bd2c41724e6a587c7f268
2+
refs/heads/master: 8ab15c0266260faadd2804623c729efcb14e7315
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: 4a81779abd786ff22d71434c6d9a5917ea4cdfff
55
refs/heads/try: 2898dcc5d97da9427ac367542382b6239d9c0bbf

trunk/src/libsyntax/ast.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ enum lit_ {
402402
lit_str(@str),
403403
lit_int(i64, int_ty),
404404
lit_uint(u64, uint_ty),
405-
lit_int_unsuffixed(i64),
405+
lit_int_unsuffixed(i64, int_ty),
406406
lit_float(@str, float_ty),
407407
lit_nil,
408408
lit_bool(bool),

trunk/src/libsyntax/parse/classify.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn ends_in_lit_int(ex: @ast::expr) -> bool {
5454
ast::expr_lit(node) {
5555
alt node {
5656
@{node: ast::lit_int(_, ast::ty_i), _} |
57-
@{node: ast::lit_int_unsuffixed(_), _}
57+
@{node: ast::lit_int_unsuffixed(_, ast::ty_i), _}
5858
{ true }
5959
_ { false }
6060
}

trunk/src/libsyntax/parse/lexer.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ fn scan_number(c: char, rdr: reader) -> token::token {
285285

286286
#debug["lexing %s as an unsuffixed integer literal",
287287
num_str];
288-
ret token::LIT_INT_UNSUFFIXED(parsed as i64);
288+
ret token::LIT_INT_UNSUFFIXED(parsed as i64, ast::ty_i);
289289
}
290290
}
291291

trunk/src/libsyntax/parse/parser.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,7 +501,7 @@ class parser {
501501
let lo = self.span.lo;
502502
self.bump();
503503
alt copy self.token {
504-
token::LIT_INT_UNSUFFIXED(num) {
504+
token::LIT_INT_UNSUFFIXED(num, _) {
505505
self.bump();
506506
some(mac_var(num as uint))
507507
}
@@ -534,7 +534,7 @@ class parser {
534534
token::UNDERSCORE {
535535
self.bump(); some(vstore_fixed(none))
536536
}
537-
token::LIT_INT_UNSUFFIXED(i) if i >= 0i64 {
537+
token::LIT_INT_UNSUFFIXED(i, _) if i >= 0i64 {
538538
self.bump(); some(vstore_fixed(some(i as uint)))
539539
}
540540
token::BINOP(token::AND) {
@@ -553,7 +553,7 @@ class parser {
553553
alt tok {
554554
token::LIT_INT(i, it) { lit_int(i, it) }
555555
token::LIT_UINT(u, ut) { lit_uint(u, ut) }
556-
token::LIT_INT_UNSUFFIXED(i) { lit_int_unsuffixed(i) }
556+
token::LIT_INT_UNSUFFIXED(i, it) { lit_int_unsuffixed(i, it) }
557557
token::LIT_FLOAT(s, ft) { lit_float(self.get_str(s), ft) }
558558
token::LIT_STR(s) { lit_str(self.get_str(s)) }
559559
token::LPAREN { self.expect(token::RPAREN); lit_nil }

trunk/src/libsyntax/parse/token.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ enum token {
5757
/* Literals */
5858
LIT_INT(i64, ast::int_ty),
5959
LIT_UINT(u64, ast::uint_ty),
60-
LIT_INT_UNSUFFIXED(i64),
60+
LIT_INT_UNSUFFIXED(i64, ast::int_ty),
6161
LIT_FLOAT(str_num, ast::float_ty),
6262
LIT_STR(str_num),
6363

@@ -129,8 +129,8 @@ fn to_str(in: interner<@str>, t: token) -> str {
129129
LIT_UINT(u, t) {
130130
uint::to_str(u as uint, 10u) + ast_util::uint_ty_to_str(t)
131131
}
132-
LIT_INT_UNSUFFIXED(i) {
133-
int::to_str(i as int, 10u)
132+
LIT_INT_UNSUFFIXED(i, t) {
133+
int::to_str(i as int, 10u) + ast_util::int_ty_to_str(t)
134134
}
135135
LIT_FLOAT(s, t) {
136136
*interner::get(in, s) +
@@ -160,7 +160,7 @@ pure fn can_begin_expr(t: token) -> bool {
160160
TILDE { true }
161161
LIT_INT(_, _) { true }
162162
LIT_UINT(_, _) { true }
163-
LIT_INT_UNSUFFIXED(_) { true }
163+
LIT_INT_UNSUFFIXED(_, _) { true }
164164
LIT_FLOAT(_, _) { true }
165165
LIT_STR(_) { true }
166166
POUND { true }
@@ -178,7 +178,7 @@ fn is_lit(t: token) -> bool {
178178
alt t {
179179
LIT_INT(_, _) { true }
180180
LIT_UINT(_, _) { true }
181-
LIT_INT_UNSUFFIXED(_) { true }
181+
LIT_INT_UNSUFFIXED(_, _) { true }
182182
LIT_FLOAT(_, _) { true }
183183
LIT_STR(_) { true }
184184
_ { false }

trunk/src/libsyntax/print/pprust.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,11 +1628,15 @@ fn print_literal(s: ps, &&lit: @ast::lit) {
16281628
u64::to_str(u, 10u)
16291629
+ ast_util::uint_ty_to_str(t));
16301630
}
1631-
ast::lit_int_unsuffixed(i) {
1631+
ast::lit_int_unsuffixed(i, t) {
16321632
if i < 0_i64 {
1633-
word(s.s, "-" + u64::to_str(-i as u64, 10u));
1633+
word(s.s,
1634+
"-" + u64::to_str(-i as u64, 10u)
1635+
+ ast_util::int_ty_to_str(t));
16341636
} else {
1635-
word(s.s, u64::to_str(i as u64, 10u));
1637+
word(s.s,
1638+
u64::to_str(i as u64, 10u)
1639+
+ ast_util::int_ty_to_str(t));
16361640
}
16371641
}
16381642
ast::lit_float(f, t) {

trunk/src/rustc/metadata/tyencode.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,9 +278,10 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
278278
w.write_uint(id.to_uint());
279279
}
280280
ty::ty_var_integral(id) {
281+
// TODO: should we have a different character for these? (Issue #1425)
281282
w.write_char('X');
282-
w.write_char('I');
283283
w.write_uint(id.to_uint());
284+
w.write_str("(integral)");
284285
}
285286
ty::ty_param(id, did) {
286287
w.write_char('p');

trunk/src/rustc/middle/const_eval.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ fn lit_to_const(lit: @lit) -> const_val {
111111
lit_str(s) { const_str(*s) }
112112
lit_int(n, _) { const_int(n) }
113113
lit_uint(n, _) { const_uint(n) }
114-
lit_int_unsuffixed(n) { const_int(n) }
114+
lit_int_unsuffixed(n, _) { const_int(n) }
115115
lit_float(n, _) { const_float(option::get(float::from_str(*n)) as f64) }
116116
lit_nil { const_int(0i64) }
117117
lit_bool(b) { const_int(b as i64) }

trunk/src/rustc/middle/trans/base.rs

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,25 +1473,15 @@ fn store_temp_expr(cx: block, action: copy_action, dst: ValueRef,
14731473
ret move_val(cx, action, dst, src, t);
14741474
}
14751475

1476-
fn trans_crate_lit(cx: @crate_ctxt, e: @ast::expr, lit: ast::lit)
1477-
-> ValueRef {
1476+
fn trans_crate_lit(cx: @crate_ctxt, lit: ast::lit) -> ValueRef {
14781477
let _icx = cx.insn_ctxt("trans_crate_lit");
14791478
alt lit.node {
14801479
ast::lit_int(i, t) { C_integral(T_int_ty(cx, t), i as u64, True) }
14811480
ast::lit_uint(u, t) { C_integral(T_uint_ty(cx, t), u, False) }
1482-
ast::lit_int_unsuffixed(i) {
1483-
let lit_int_ty = ty::node_id_to_type(cx.tcx, e.id);
1484-
alt ty::get(lit_int_ty).struct {
1485-
ty::ty_int(t) {
1486-
C_integral(T_int_ty(cx, t), i as u64, True)
1487-
}
1488-
ty::ty_uint(t) {
1489-
C_integral(T_uint_ty(cx, t), i as u64, False)
1490-
}
1491-
_ { cx.sess.span_bug(lit.span,
1492-
"integer literal doesn't have a type");
1493-
}
1494-
}
1481+
ast::lit_int_unsuffixed(i, t) {
1482+
// FIXME (#1425): should we be using cx.fcx.infcx to figure out what
1483+
// to actually generate from this?
1484+
C_integral(T_int_ty(cx, t), i as u64, True)
14951485
}
14961486
ast::lit_float(fs, t) { C_floating(*fs, T_float_ty(cx, t)) }
14971487
ast::lit_bool(b) { C_bool(b) }
@@ -1502,13 +1492,13 @@ fn trans_crate_lit(cx: @crate_ctxt, e: @ast::expr, lit: ast::lit)
15021492
}
15031493
}
15041494

1505-
fn trans_lit(cx: block, e: @ast::expr, lit: ast::lit, dest: dest) -> block {
1495+
fn trans_lit(cx: block, lit: ast::lit, dest: dest) -> block {
15061496
let _icx = cx.insn_ctxt("trans_lit");
15071497
if dest == ignore { ret cx; }
15081498
alt lit.node {
15091499
ast::lit_str(s) { tvec::trans_estr(cx, s, ast::vstore_uniq, dest) }
15101500
_ {
1511-
store_in_dest(cx, trans_crate_lit(cx.ccx(), e, lit), dest)
1501+
store_in_dest(cx, trans_crate_lit(cx.ccx(), lit), dest)
15121502
}
15131503
}
15141504
}
@@ -3594,7 +3584,7 @@ fn trans_expr(bcx: block, e: @ast::expr, dest: dest) -> block {
35943584
}
35953585
ast::expr_tup(args) { ret trans_tup(bcx, args, dest); }
35963586
ast::expr_vstore(e, v) { ret tvec::trans_vstore(bcx, e, v, dest); }
3597-
ast::expr_lit(lit) { ret trans_lit(bcx, e, *lit, dest); }
3587+
ast::expr_lit(lit) { ret trans_lit(bcx, *lit, dest); }
35983588
ast::expr_vec(args, _) {
35993589
ret tvec::trans_evec(bcx, args, ast::vstore_uniq, e.id, dest);
36003590
}
@@ -4694,7 +4684,7 @@ fn trans_enum_variant(ccx: @crate_ctxt, enum_id: ast::node_id,
46944684
fn trans_const_expr(cx: @crate_ctxt, e: @ast::expr) -> ValueRef {
46954685
let _icx = cx.insn_ctxt("trans_const_expr");
46964686
alt e.node {
4697-
ast::expr_lit(lit) { ret trans_crate_lit(cx, e, *lit); }
4687+
ast::expr_lit(lit) { ret trans_crate_lit(cx, *lit); }
46984688
ast::expr_binary(b, e1, e2) {
46994689
let te1 = trans_const_expr(cx, e1);
47004690
let te2 = trans_const_expr(cx, e2);

trunk/src/rustc/middle/trans/native.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -812,6 +812,26 @@ fn trans_intrinsic(ccx: @crate_ctxt, decl: ValueRef, item: @ast::native_item,
812812
Store(bcx, C_uint(ccx, shape::llsize_of_real(ccx, lltp_ty)),
813813
fcx.llretptr);
814814
}
815+
"move_val" {
816+
let tp_ty = substs.tys[0];
817+
let src = {bcx: bcx,
818+
val: get_param(decl, first_real_arg + 1u),
819+
kind: owned };
820+
bcx = move_val(bcx, DROP_EXISTING,
821+
get_param(decl, first_real_arg),
822+
src,
823+
tp_ty);
824+
}
825+
"move_val_init" {
826+
let tp_ty = substs.tys[0];
827+
let src = {bcx: bcx,
828+
val: get_param(decl, first_real_arg + 1u),
829+
kind: owned };
830+
bcx = move_val(bcx, INIT,
831+
get_param(decl, first_real_arg),
832+
src,
833+
tp_ty);
834+
}
815835
"min_align_of" {
816836
let tp_ty = substs.tys[0];
817837
let lltp_ty = type_of::type_of(ccx, tp_ty);

trunk/src/rustc/middle/trans/type_use.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ fn type_uses_for(ccx: @crate_ctxt, fn_id: def_id, n_tps: uint)
7979
let flags = alt check *i.ident {
8080
"visit_ty" { 3u }
8181
"size_of" | "pref_align_of" | "min_align_of" |
82-
"init" | "reinterpret_cast" { use_repr }
82+
"init" | "reinterpret_cast" | "move_val" | "move_val_init" {
83+
use_repr
84+
}
8385
"get_tydesc" | "needs_drop" { use_tydesc }
8486
"forget" | "addr_of" { 0u }
8587
};

trunk/src/rustc/middle/ty.rs

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ export ty_float, mk_float, mk_mach_float, type_is_fp;
8484
export ty_fn, fn_ty, mk_fn;
8585
export ty_fn_proto, ty_fn_ret, ty_fn_ret_style, tys_in_fn_ty;
8686
export ty_int, mk_int, mk_mach_int, mk_char;
87-
export mk_i8, mk_u8, mk_i16, mk_u16, mk_i32, mk_u32, mk_i64, mk_u64;
8887
export ty_str, mk_str, type_is_str;
8988
export ty_vec, mk_vec, type_is_vec;
9089
export ty_estr, mk_estr;
@@ -417,8 +416,7 @@ enum type_err {
417416
terr_vstores_differ(terr_vstore_kind, vstore, vstore),
418417
terr_in_field(@type_err, ast::ident),
419418
terr_sorts(t, t),
420-
terr_self_substs,
421-
terr_no_integral_type,
419+
terr_self_substs
422420
}
423421

424422
enum param_bound {
@@ -444,7 +442,7 @@ impl of vid for tv_vid {
444442

445443
impl of vid for tvi_vid {
446444
fn to_uint() -> uint { *self }
447-
fn to_str() -> str { #fmt["<VI%u>", self.to_uint()] }
445+
fn to_str() -> str { #fmt["<V (integral) %u>", self.to_uint()] }
448446
}
449447

450448
impl of vid for region_vid {
@@ -621,26 +619,12 @@ fn mk_bool(cx: ctxt) -> t { mk_t(cx, ty_bool) }
621619

622620
fn mk_int(cx: ctxt) -> t { mk_t(cx, ty_int(ast::ty_i)) }
623621

624-
fn mk_i8(cx: ctxt) -> t { mk_t(cx, ty_int(ast::ty_i8)) }
625-
626-
fn mk_i16(cx: ctxt) -> t { mk_t(cx, ty_int(ast::ty_i16)) }
627-
628-
fn mk_i32(cx: ctxt) -> t { mk_t(cx, ty_int(ast::ty_i32)) }
629-
630-
fn mk_i64(cx: ctxt) -> t { mk_t(cx, ty_int(ast::ty_i64)) }
631-
632622
fn mk_float(cx: ctxt) -> t { mk_t(cx, ty_float(ast::ty_f)) }
633623

634624
fn mk_uint(cx: ctxt) -> t { mk_t(cx, ty_uint(ast::ty_u)) }
635625

636626
fn mk_u8(cx: ctxt) -> t { mk_t(cx, ty_uint(ast::ty_u8)) }
637627

638-
fn mk_u16(cx: ctxt) -> t { mk_t(cx, ty_uint(ast::ty_u16)) }
639-
640-
fn mk_u32(cx: ctxt) -> t { mk_t(cx, ty_uint(ast::ty_u32)) }
641-
642-
fn mk_u64(cx: ctxt) -> t { mk_t(cx, ty_uint(ast::ty_u64)) }
643-
644628
fn mk_mach_int(cx: ctxt, tm: ast::int_ty) -> t { mk_t(cx, ty_int(tm)) }
645629

646630
fn mk_mach_uint(cx: ctxt, tm: ast::uint_ty) -> t { mk_t(cx, ty_uint(tm)) }
@@ -1204,7 +1188,7 @@ pure fn type_is_unique(ty: t) -> bool {
12041188
pure fn type_is_scalar(ty: t) -> bool {
12051189
alt get(ty).struct {
12061190
ty_nil | ty_bool | ty_int(_) | ty_float(_) | ty_uint(_) |
1207-
ty_var_integral(_) | ty_type | ty_ptr(_) | ty_rptr(_, _) { true }
1191+
ty_type | ty_ptr(_) | ty_rptr(_, _) { true }
12081192
_ { false }
12091193
}
12101194
}
@@ -1843,7 +1827,7 @@ fn type_structurally_contains_uniques(cx: ctxt, ty: t) -> bool {
18431827

18441828
fn type_is_integral(ty: t) -> bool {
18451829
alt get(ty).struct {
1846-
ty_var_integral(_) | ty_int(_) | ty_uint(_) | ty_bool { true }
1830+
ty_int(_) | ty_uint(_) | ty_bool { true }
18471831
_ { false }
18481832
}
18491833
}
@@ -2547,10 +2531,6 @@ fn type_err_to_str(cx: ctxt, err: type_err) -> str {
25472531
terr_self_substs {
25482532
ret "inconsistent self substitution"; // XXX this is more of a bug
25492533
}
2550-
terr_no_integral_type {
2551-
ret "couldn't determine an appropriate integral type for integer \
2552-
literal";
2553-
}
25542534
}
25552535
}
25562536

@@ -2986,7 +2966,7 @@ fn is_binopable(_cx: ctxt, ty: t, op: ast::binop) -> bool {
29862966
fn tycat(ty: t) -> int {
29872967
alt get(ty).struct {
29882968
ty_bool { tycat_bool }
2989-
ty_int(_) | ty_uint(_) | ty_var_integral(_) { tycat_int }
2969+
ty_int(_) | ty_uint(_) { tycat_int }
29902970
ty_float(_) { tycat_float }
29912971
ty_estr(_) | ty_str { tycat_str }
29922972
ty_evec(_, _) | ty_vec(_) { tycat_vec }

trunk/src/rustc/middle/typeck/check.rs

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ import middle::ty::{tv_vid, vid};
7373
import regionmanip::{replace_bound_regions_in_fn_ty, region_of};
7474
import rscope::{anon_rscope, binding_rscope, empty_rscope, in_anon_rscope};
7575
import rscope::{in_binding_rscope, region_scope, type_rscope};
76-
import syntax::ast::{ty_char, ty_i};
76+
import syntax::ast::{ty_char, ty_i8, ty_i16, ty_i32, ty_i64, ty_i};
7777
import typeck::infer::{root, to_str};
7878
import typeck::infer::{unify_methods}; // infcx.set()
79+
import typeck::infer::{min_8bit_tys, min_16bit_tys, min_32bit_tys,
80+
min_64bit_tys};
7981

8082
type fn_ctxt =
8183
// var_bindings, locals and next_var_id are shared
@@ -454,6 +456,7 @@ impl methods for @fn_ctxt {
454456
none { result::err("no block is in scope here") }
455457
}
456458
}
459+
#[inline(always)]
457460
fn write_ty(node_id: ast::node_id, ty: ty::t) {
458461
#debug["write_ty(%d, %s) in fcx %s",
459462
node_id, ty_to_str(self.tcx(), ty), self.tag()];
@@ -621,13 +624,29 @@ fn check_lit(fcx: @fn_ctxt, lit: @ast::lit) -> ty::t {
621624
ast::lit_str(_) { ty::mk_str(tcx) }
622625
ast::lit_int(_, t) { ty::mk_mach_int(tcx, t) }
623626
ast::lit_uint(_, t) { ty::mk_mach_uint(tcx, t) }
624-
ast::lit_int_unsuffixed(v) {
627+
ast::lit_int_unsuffixed(v, t) {
625628
// An unsuffixed integer literal could have any integral type,
626629
// so we create an integral type variable for it.
627-
ty::mk_var_integral(tcx, fcx.infcx.next_ty_var_integral_id());
630+
let vid = fcx.infcx.next_ty_var_integral_id();
631+
632+
// We need to sniff at the value `v` and figure out how big of
633+
// an int it is; that determines the range of possible types
634+
// that the integral type variable could take on.
635+
let possible_types = alt v {
636+
0i64 to 127i64 { min_8bit_tys() }
637+
128i64 to 65535i64 { min_16bit_tys() }
638+
65536i64 to 4294967295i64 { min_32bit_tys() }
639+
_ { min_64bit_tys() }
640+
};
641+
642+
// Store the set of possible types and return the integral
643+
// type variable.
644+
fcx.infcx.set(fcx.infcx.tvib, vid,
645+
root(possible_types));
646+
ty::mk_var_integral(tcx, vid);
628647

629648
// FIXME: remove me when #1425 is finished.
630-
ty::mk_mach_int(tcx, ty_i)
649+
ty::mk_mach_int(tcx, t)
631650
}
632651
ast::lit_float(_, t) { ty::mk_mach_float(tcx, t) }
633652
ast::lit_nil { ty::mk_nil(tcx) }
@@ -2303,6 +2322,11 @@ fn check_intrinsic_type(ccx: @crate_ctxt, it: @ast::native_item) {
23032322
param(ccx, 1u)) }
23042323
"addr_of" { (1u, [arg(ast::by_ref, param(ccx, 0u))],
23052324
ty::mk_imm_ptr(tcx, param(ccx, 0u))) }
2325+
"move_val" | "move_val_init" {
2326+
(1u, [arg(ast::by_mutbl_ref, param(ccx, 0u)),
2327+
arg(ast::by_move, param(ccx, 0u))],
2328+
ty::mk_nil(tcx))
2329+
}
23062330
"needs_drop" { (1u, [], ty::mk_bool(tcx)) }
23072331

23082332
"visit_ty" {

0 commit comments

Comments
 (0)