Skip to content

Commit e3eca91

Browse files
committed
Change literal representation to not truncate
Also shuffles around the organization of numeric literals and types, separating by int/uint/float instead of machine-vs-non-machine types. This simplifies some code. Closes #974 Closes #1252
1 parent 6daa233 commit e3eca91

24 files changed

+479
-731
lines changed

src/comp/driver/session.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import syntax::{ast, codemap};
33
import syntax::ast::node_id;
44
import codemap::span;
5-
import syntax::ast::ty_mach;
5+
import syntax::ast::{int_ty, uint_ty, float_ty};
66
import std::{option};
77
import std::option::{some, none};
88
import syntax::parse::parser::parse_sess;
@@ -17,9 +17,9 @@ type config =
1717
{os: os,
1818
arch: arch,
1919
target_strs: target_strs::t,
20-
int_type: ty_mach,
21-
uint_type: ty_mach,
22-
float_type: ty_mach};
20+
int_type: int_ty,
21+
uint_type: uint_ty,
22+
float_type: float_ty};
2323

2424
type options =
2525
// The crate config requested for the session, which may be combined

src/comp/metadata/tydecode.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -174,16 +174,16 @@ fn parse_ty(st: @pstate, sd: str_def) -> ty::t {
174174
'l' { ret ty::mk_float(st.tcx); }
175175
'M' {
176176
alt next(st) as char {
177-
'b' { ret ty::mk_mach(st.tcx, ast::ty_u8); }
178-
'w' { ret ty::mk_mach(st.tcx, ast::ty_u16); }
179-
'l' { ret ty::mk_mach(st.tcx, ast::ty_u32); }
180-
'd' { ret ty::mk_mach(st.tcx, ast::ty_u64); }
181-
'B' { ret ty::mk_mach(st.tcx, ast::ty_i8); }
182-
'W' { ret ty::mk_mach(st.tcx, ast::ty_i16); }
183-
'L' { ret ty::mk_mach(st.tcx, ast::ty_i32); }
184-
'D' { ret ty::mk_mach(st.tcx, ast::ty_i64); }
185-
'f' { ret ty::mk_mach(st.tcx, ast::ty_f32); }
186-
'F' { ret ty::mk_mach(st.tcx, ast::ty_f64); }
177+
'b' { ret ty::mk_mach_uint(st.tcx, ast::ty_u8); }
178+
'w' { ret ty::mk_mach_uint(st.tcx, ast::ty_u16); }
179+
'l' { ret ty::mk_mach_uint(st.tcx, ast::ty_u32); }
180+
'd' { ret ty::mk_mach_uint(st.tcx, ast::ty_u64); }
181+
'B' { ret ty::mk_mach_int(st.tcx, ast::ty_i8); }
182+
'W' { ret ty::mk_mach_int(st.tcx, ast::ty_i16); }
183+
'L' { ret ty::mk_mach_int(st.tcx, ast::ty_i32); }
184+
'D' { ret ty::mk_mach_int(st.tcx, ast::ty_i64); }
185+
'f' { ret ty::mk_mach_float(st.tcx, ast::ty_f32); }
186+
'F' { ret ty::mk_mach_float(st.tcx, ast::ty_f64); }
187187
}
188188
}
189189
'c' { ret ty::mk_char(st.tcx); }

src/comp/metadata/tyencode.rs

+18-10
Original file line numberDiff line numberDiff line change
@@ -90,24 +90,32 @@ fn enc_sty(w: io::writer, cx: @ctxt, st: ty::sty) {
9090
ty::ty_nil. { w.write_char('n'); }
9191
ty::ty_bot. { w.write_char('z'); }
9292
ty::ty_bool. { w.write_char('b'); }
93-
ty::ty_int. { w.write_char('i'); }
94-
ty::ty_uint. { w.write_char('u'); }
95-
ty::ty_float. { w.write_char('l'); }
96-
ty::ty_machine(mach) {
97-
alt mach {
98-
ty_u8. { w.write_str("Mb"); }
99-
ty_u16. { w.write_str("Mw"); }
100-
ty_u32. { w.write_str("Ml"); }
101-
ty_u64. { w.write_str("Md"); }
93+
ty::ty_int(t) {
94+
alt t {
95+
ty_i. { w.write_char('i'); }
96+
ty_char. { w.write_char('c'); }
10297
ty_i8. { w.write_str("MB"); }
10398
ty_i16. { w.write_str("MW"); }
10499
ty_i32. { w.write_str("ML"); }
105100
ty_i64. { w.write_str("MD"); }
101+
}
102+
}
103+
ty::ty_uint(t) {
104+
alt t {
105+
ty_u. { w.write_char('u'); }
106+
ty_u8. { w.write_str("Mb"); }
107+
ty_u16. { w.write_str("Mw"); }
108+
ty_u32. { w.write_str("Ml"); }
109+
ty_u64. { w.write_str("Md"); }
110+
}
111+
}
112+
ty::ty_float(t) {
113+
alt t {
114+
ty_f. { w.write_char('l'); }
106115
ty_f32. { w.write_str("Mf"); }
107116
ty_f64. { w.write_str("MF"); }
108117
}
109118
}
110-
ty::ty_char. { w.write_char('c'); }
111119
ty::ty_str. { w.write_char('S'); }
112120
ty::ty_tag(def, tys) {
113121
w.write_str("t[");

src/comp/middle/alias.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -553,9 +553,8 @@ fn local_id_of_node(cx: ctx, id: node_id) -> uint {
553553
fn copy_is_expensive(tcx: ty::ctxt, ty: ty::t) -> bool {
554554
fn score_ty(tcx: ty::ctxt, ty: ty::t) -> uint {
555555
ret alt ty::struct(tcx, ty) {
556-
ty::ty_nil. | ty::ty_bot. | ty::ty_bool. | ty::ty_int. |
557-
ty::ty_uint. | ty::ty_float. | ty::ty_machine(_) |
558-
ty::ty_char. | ty::ty_type. | ty::ty_native(_) |
556+
ty::ty_nil. | ty::ty_bot. | ty::ty_bool. | ty::ty_int(_) |
557+
ty::ty_uint(_) | ty::ty_float(_) | ty::ty_type. | ty::ty_native(_) |
559558
ty::ty_ptr(_) { 1u }
560559
ty::ty_box(_) { 3u }
561560
ty::ty_constr(t, _) | ty::ty_res(_, t, _) { score_ty(tcx, t) }

src/comp/middle/gc.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ fn add_gc_root(cx: @block_ctxt, llval: ValueRef, ty: ty::t) -> @block_ctxt {
102102

103103
fn type_is_gc_relevant(cx: ty::ctxt, ty: ty::t) -> bool {
104104
alt ty::struct(cx, ty) {
105-
ty::ty_nil. | ty::ty_bot. | ty::ty_bool. | ty::ty_int. | ty::ty_float. |
106-
ty::ty_uint. | ty::ty_machine(_) | ty::ty_char. | ty::ty_str. |
105+
ty::ty_nil. | ty::ty_bot. | ty::ty_bool. | ty::ty_int(_) |
106+
ty::ty_float(_) | ty::ty_uint(_) | ty::ty_str. |
107107
ty::ty_type. | ty::ty_native(_) | ty::ty_ptr(_) | ty::ty_type. |
108108
ty::ty_native(_) {
109109
ret false;

src/comp/middle/shape.rs

+16-66
Original file line numberDiff line numberDiff line change
@@ -299,54 +299,27 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
299299
let s = [];
300300

301301
alt ty::struct(ccx.tcx, t) {
302-
ty::ty_nil. | ty::ty_bool. | ty::ty_machine(ast::ty_u8.) | ty::ty_bot. {
303-
s += [shape_u8];
304-
}
305-
306-
307-
308-
309-
310-
ty::ty_int. {
311-
s += [s_int(ccx.tcx)];
312-
}
313-
ty::ty_float. { s += [s_float(ccx.tcx)]; }
314-
315-
316-
317-
318-
319-
ty::ty_uint. | ty::ty_ptr(_) | ty::ty_type. | ty::ty_native(_) {
320-
s += [s_uint(ccx.tcx)];
321-
}
322-
323-
324-
325-
326-
327-
ty::ty_machine(ast::ty_i8.) {
328-
s += [shape_i8];
329-
}
330-
ty::ty_machine(ast::ty_u16.) { s += [shape_u16]; }
331-
ty::ty_machine(ast::ty_i16.) { s += [shape_i16]; }
332-
ty::ty_machine(ast::ty_u32.) | ty::ty_char. { s += [shape_u32]; }
333-
ty::ty_machine(ast::ty_i32.) { s += [shape_i32]; }
334-
ty::ty_machine(ast::ty_u64.) { s += [shape_u64]; }
335-
ty::ty_machine(ast::ty_i64.) { s += [shape_i64]; }
336-
337-
ty::ty_machine(ast::ty_f32.) { s += [shape_f32]; }
338-
ty::ty_machine(ast::ty_f64.) { s += [shape_f64]; }
339-
302+
ty::ty_nil. | ty::ty_bool. | ty::ty_uint(ast::ty_u8.) |
303+
ty::ty_bot. { s += [shape_u8]; }
304+
ty::ty_int(ast::ty_i.) { s += [s_int(ccx.tcx)]; }
305+
ty::ty_float(ast::ty_f.) { s += [s_float(ccx.tcx)]; }
306+
ty::ty_uint(ast::ty_u.) | ty::ty_ptr(_) | ty::ty_type. |
307+
ty::ty_native(_) { s += [s_uint(ccx.tcx)]; }
308+
ty::ty_int(ast::ty_i8.) { s += [shape_i8]; }
309+
ty::ty_uint(ast::ty_u16.) { s += [shape_u16]; }
310+
ty::ty_int(ast::ty_i16.) { s += [shape_i16]; }
311+
ty::ty_uint(ast::ty_u32.) { s += [shape_u32]; }
312+
ty::ty_int(ast::ty_i32.) | ty::ty_int(ast::ty_char.) {s += [shape_i32];}
313+
ty::ty_uint(ast::ty_u64.) { s += [shape_u64]; }
314+
ty::ty_int(ast::ty_i64.) { s += [shape_i64]; }
315+
ty::ty_float(ast::ty_f32.) { s += [shape_f32]; }
316+
ty::ty_float(ast::ty_f64.) { s += [shape_f64]; }
340317
ty::ty_str. {
341318
s += [shape_vec];
342319
add_bool(s, true); // type is POD
343-
let unit_ty = ty::mk_mach(ccx.tcx, ast::ty_u8);
320+
let unit_ty = ty::mk_mach_uint(ccx.tcx, ast::ty_u8);
344321
add_substr(s, shape_of(ccx, unit_ty, ty_param_map, is_obj_body));
345322
}
346-
347-
348-
349-
350323
ty::ty_tag(did, tps) {
351324
alt tag_kind(ccx, did) {
352325
tk_unit. {
@@ -382,11 +355,6 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
382355
}
383356
}
384357
}
385-
386-
387-
388-
389-
390358
ty::ty_box(mt) {
391359
s += [shape_box];
392360
add_substr(s, shape_of(ccx, mt.ty, ty_param_map, is_obj_body));
@@ -416,21 +384,11 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
416384
}
417385
add_substr(s, sub);
418386
}
419-
420-
421-
422-
423-
424387
ty::ty_fn(_, _, _, _, _) {
425388
s += [shape_fn];
426389
}
427390
ty::ty_native_fn(_, _) { s += [shape_u32]; }
428391
ty::ty_obj(_) { s += [shape_obj]; }
429-
430-
431-
432-
433-
434392
ty::ty_res(did, raw_subt, tps) {
435393
let subt = ty::substitute_type_params(ccx.tcx, tps, raw_subt);
436394
let ri = {did: did, t: subt};
@@ -445,17 +403,9 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t, ty_param_map: [uint],
445403
add_substr(s, shape_of(ccx, subt, ty_param_map, is_obj_body));
446404

447405
}
448-
449-
450-
451-
452406
ty::ty_var(n) {
453407
fail "shape_of ty_var";
454408
}
455-
456-
457-
458-
459409
ty::ty_param(n, _) {
460410
if is_obj_body {
461411
// Just write in the parameter number.

src/comp/middle/trans.rs

+13-62
Original file line numberDiff line numberDiff line change
@@ -130,20 +130,9 @@ fn type_of_inner(cx: @crate_ctxt, sp: span, t: ty::t)
130130
T_nil() /* ...I guess? */
131131
}
132132
ty::ty_bool. { T_bool() }
133-
ty::ty_int. { cx.int_type }
134-
ty::ty_float. { cx.float_type }
135-
ty::ty_uint. { cx.int_type }
136-
ty::ty_machine(tm) {
137-
alt tm {
138-
ast::ty_i8. | ast::ty_u8. { T_i8() }
139-
ast::ty_i16. | ast::ty_u16. { T_i16() }
140-
ast::ty_i32. | ast::ty_u32. { T_i32() }
141-
ast::ty_i64. | ast::ty_u64. { T_i64() }
142-
ast::ty_f32. { T_f32() }
143-
ast::ty_f64. { T_f64() }
144-
}
145-
}
146-
ty::ty_char. { T_char() }
133+
ty::ty_int(t) { T_int_ty(cx, t) }
134+
ty::ty_uint(t) { T_uint_ty(cx, t) }
135+
ty::ty_float(t) { T_float_ty(cx, t) }
147136
ty::ty_str. { T_ptr(T_vec(cx, T_i8())) }
148137
ty::ty_tag(did, _) { type_of_tag(cx, sp, did, t) }
149138
ty::ty_box(mt) {
@@ -1516,23 +1505,10 @@ fn compare_scalar_types(cx: @block_ctxt, lhs: ValueRef, rhs: ValueRef,
15161505

15171506
alt ty::struct(bcx_tcx(cx), t) {
15181507
ty::ty_nil. { ret rslt(cx, f(nil_type)); }
1519-
ty::ty_bool. | ty::ty_uint. | ty::ty_ptr(_) | ty::ty_char. {
1520-
ret rslt(cx, f(unsigned_int));
1521-
}
1522-
ty::ty_int. { ret rslt(cx, f(signed_int)); }
1523-
ty::ty_float. { ret rslt(cx, f(floating_point)); }
1524-
ty::ty_machine(_) {
1525-
if ty::type_is_fp(bcx_tcx(cx), t) {
1526-
// Floating point machine types
1527-
ret rslt(cx, f(floating_point));
1528-
} else if ty::type_is_signed(bcx_tcx(cx), t) {
1529-
// Signed, integral machine types
1530-
ret rslt(cx, f(signed_int));
1531-
} else {
1532-
// Unsigned, integral machine types
1533-
ret rslt(cx, f(unsigned_int));
1534-
}
1535-
}
1508+
ty::ty_bool. | ty::ty_ptr(_) { ret rslt(cx, f(unsigned_int)); }
1509+
ty::ty_int(_) { ret rslt(cx, f(signed_int)); }
1510+
ty::ty_uint(_) { ret rslt(cx, f(unsigned_int)); }
1511+
ty::ty_float(_) { ret rslt(cx, f(floating_point)); }
15361512
ty::ty_type. {
15371513
ret rslt(trans_fail(cx, none,
15381514
"attempt to compare values of type type"),
@@ -2120,36 +2096,11 @@ fn store_temp_expr(cx: @block_ctxt, action: copy_action, dst: ValueRef,
21202096

21212097
fn trans_crate_lit(cx: @crate_ctxt, lit: ast::lit) -> ValueRef {
21222098
alt lit.node {
2123-
ast::lit_int(i) { ret C_int(cx, i); }
2124-
ast::lit_uint(u) { ret C_uint(cx, u); }
2125-
ast::lit_mach_int(tm, i) {
2126-
// FIXME: the entire handling of mach types falls apart
2127-
// if target int width is larger than host, at the moment;
2128-
// re-do the mach-int types using 'big' when that works.
2129-
2130-
let t = cx.int_type;
2131-
let s = True;
2132-
alt tm {
2133-
ast::ty_u8. { t = T_i8(); s = False; }
2134-
ast::ty_u16. { t = T_i16(); s = False; }
2135-
ast::ty_u32. { t = T_i32(); s = False; }
2136-
ast::ty_u64. { t = T_i64(); s = False; }
2137-
ast::ty_i8. { t = T_i8(); }
2138-
ast::ty_i16. { t = T_i16(); }
2139-
ast::ty_i32. { t = T_i32(); }
2140-
ast::ty_i64. { t = T_i64(); }
2141-
}
2142-
ret C_integral(t, i as u64, s);
2143-
}
2144-
ast::lit_float(fs) { ret C_float(cx, fs); }
2145-
ast::lit_mach_float(tm, s) {
2146-
let t = cx.float_type;
2147-
alt tm { ast::ty_f32. { t = T_f32(); } ast::ty_f64. { t = T_f64(); } }
2148-
ret C_floating(s, t);
2149-
}
2150-
ast::lit_char(c) { ret C_integral(T_char(), c as u64, False); }
2151-
ast::lit_bool(b) { ret C_bool(b); }
2152-
ast::lit_nil. { ret C_nil(); }
2099+
ast::lit_int(i, t) { C_integral(T_int_ty(cx, t), i as u64, True) }
2100+
ast::lit_uint(u, t) { C_integral(T_uint_ty(cx, t), u, False) }
2101+
ast::lit_float(fs, t) { C_floating(fs, T_float_ty(cx, t)) }
2102+
ast::lit_bool(b) { C_bool(b) }
2103+
ast::lit_nil. { C_nil() }
21532104
ast::lit_str(s) {
21542105
cx.sess.span_unimpl(lit.span, "unique string in this context");
21552106
}
@@ -4359,7 +4310,7 @@ fn trans_fail_expr(bcx: @block_ctxt, sp_opt: option::t<span>,
43594310
if ty::type_is_str(tcx, e_ty) {
43604311
let data = tvec::get_dataptr(
43614312
bcx, expr_res.val, type_of_or_i8(
4362-
bcx, ty::mk_mach(tcx, ast::ty_u8)));
4313+
bcx, ty::mk_mach_uint(tcx, ast::ty_u8)));
43634314
ret trans_fail_value(bcx, sp_opt, data);
43644315
} else if bcx.unreachable {
43654316
ret bcx;

src/comp/middle/trans_common.rs

+29-6
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,35 @@ fn T_int(targ_cfg: @session::config) -> TypeRef {
485485
};
486486
}
487487

488+
fn T_int_ty(cx: @crate_ctxt, t: ast::int_ty) -> TypeRef {
489+
alt t {
490+
ast::ty_i. { cx.int_type }
491+
ast::ty_char. { T_char() }
492+
ast::ty_i8. { T_i8() }
493+
ast::ty_i16. { T_i16() }
494+
ast::ty_i32. { T_i32() }
495+
ast::ty_i64. { T_i64() }
496+
}
497+
}
498+
499+
fn T_uint_ty(cx: @crate_ctxt, t: ast::uint_ty) -> TypeRef {
500+
alt t {
501+
ast::ty_u. { cx.int_type }
502+
ast::ty_u8. { T_i8() }
503+
ast::ty_u16. { T_i16() }
504+
ast::ty_u32. { T_i32() }
505+
ast::ty_u64. { T_i64() }
506+
}
507+
}
508+
509+
fn T_float_ty(cx: @crate_ctxt, t: ast::float_ty) -> TypeRef {
510+
alt t {
511+
ast::ty_f. { cx.float_type }
512+
ast::ty_f32. { T_f32() }
513+
ast::ty_f64. { T_f64() }
514+
}
515+
}
516+
488517
fn T_float(targ_cfg: @session::config) -> TypeRef {
489518
ret alt targ_cfg.arch {
490519
session::arch_x86. { T_f64() }
@@ -734,12 +763,6 @@ fn C_integral(t: TypeRef, u: u64, sign_extend: Bool) -> ValueRef {
734763
ret llvm::LLVMRustConstInt(t, u_hi, u_lo, sign_extend);
735764
}
736765

737-
fn C_float(cx: @crate_ctxt, s: str) -> ValueRef {
738-
ret str::as_buf(s, {|buf|
739-
llvm::LLVMConstRealOfString(cx.float_type, buf)
740-
});
741-
}
742-
743766
fn C_floating(s: str, t: TypeRef) -> ValueRef {
744767
ret str::as_buf(s, {|buf| llvm::LLVMConstRealOfString(t, buf) });
745768
}

0 commit comments

Comments
 (0)