Skip to content

Commit 2c1ed41

Browse files
committed
---
yaml --- r: 72127 b: refs/heads/dist-snap c: 04df19c h: refs/heads/master i: 72125: be58f60 72123: 0adf2c2 72119: fb4139a 72111: 20d9f07 72095: 59df540 72063: 79b0b28 v: v3
1 parent 06d0708 commit 2c1ed41

File tree

2 files changed

+134
-26
lines changed

2 files changed

+134
-26
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
99
refs/heads/incoming: b50030718cf28f2a5a81857a26b57442734fe854
10-
refs/heads/dist-snap: 3ffaaab9e9e3a2437fd9ed5b04cf3ba3695cc2d2
10+
refs/heads/dist-snap: 04df19c5ca78d94e01dacbfb99471509128c6f8a
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1313
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/librustc/middle/ty.rs

Lines changed: 133 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ struct ctxt_ {
307307
used_unsafe: @mut HashSet<ast::node_id>,
308308
}
309309

310-
enum tbox_flag {
310+
pub enum tbox_flag {
311311
has_params = 1,
312312
has_self = 2,
313313
needs_infer = 4,
@@ -320,9 +320,9 @@ enum tbox_flag {
320320
needs_subst = 1 | 2 | 8
321321
}
322322

323-
type t_box = &'static t_box_;
323+
pub type t_box = &'static t_box_;
324324

325-
struct t_box_ {
325+
pub struct t_box_ {
326326
sty: sty,
327327
id: uint,
328328
flags: uint,
@@ -513,6 +513,57 @@ pub struct substs {
513513
tps: ~[t]
514514
}
515515

516+
mod primitives {
517+
use super::{sty, t_box_};
518+
519+
use core::option::None;
520+
use syntax::ast;
521+
522+
macro_rules! def_prim_ty(
523+
($name:ident, $sty:expr, $id:expr) => (
524+
pub static $name: t_box_ = t_box_ {
525+
sty: $sty,
526+
id: $id,
527+
flags: 0,
528+
o_def_id: None,
529+
};
530+
)
531+
)
532+
533+
def_prim_ty!(TY_NIL, super::ty_nil, 0)
534+
def_prim_ty!(TY_BOOL, super::ty_bool, 1)
535+
def_prim_ty!(TY_INT, super::ty_int(ast::ty_i), 2)
536+
def_prim_ty!(TY_CHAR, super::ty_int(ast::ty_char), 3)
537+
def_prim_ty!(TY_I8, super::ty_int(ast::ty_i8), 4)
538+
def_prim_ty!(TY_I16, super::ty_int(ast::ty_i16), 5)
539+
def_prim_ty!(TY_I32, super::ty_int(ast::ty_i32), 6)
540+
def_prim_ty!(TY_I64, super::ty_int(ast::ty_i64), 7)
541+
def_prim_ty!(TY_UINT, super::ty_uint(ast::ty_u), 8)
542+
def_prim_ty!(TY_U8, super::ty_uint(ast::ty_u8), 9)
543+
def_prim_ty!(TY_U16, super::ty_uint(ast::ty_u16), 10)
544+
def_prim_ty!(TY_U32, super::ty_uint(ast::ty_u32), 11)
545+
def_prim_ty!(TY_U64, super::ty_uint(ast::ty_u64), 12)
546+
def_prim_ty!(TY_FLOAT, super::ty_float(ast::ty_f), 13)
547+
def_prim_ty!(TY_F32, super::ty_float(ast::ty_f32), 14)
548+
def_prim_ty!(TY_F64, super::ty_float(ast::ty_f64), 15)
549+
550+
pub static TY_BOT: t_box_ = t_box_ {
551+
sty: super::ty_bot,
552+
id: 16,
553+
flags: super::has_ty_bot as uint,
554+
o_def_id: None,
555+
};
556+
557+
pub static TY_ERR: t_box_ = t_box_ {
558+
sty: super::ty_err,
559+
id: 17,
560+
flags: super::has_ty_err as uint,
561+
o_def_id: None,
562+
};
563+
564+
pub static LAST_PRIMITIVE_ID: uint = 18;
565+
}
566+
516567
// NB: If you change this, you'll probably want to change the corresponding
517568
// AST structure in libsyntax/ast.rs as well.
518569
#[deriving(Eq)]
@@ -852,7 +903,7 @@ pub fn mk_ctxt(s: session::Session,
852903
@ctxt_ {
853904
diag: s.diagnostic(),
854905
interner: @mut HashMap::new(),
855-
next_id: @mut 0,
906+
next_id: @mut primitives::LAST_PRIMITIVE_ID,
856907
vecs_implicitly_copyable: vecs_implicitly_copyable,
857908
legacy_modes: legacy_modes,
858909
cstore: s.cstore,
@@ -901,6 +952,17 @@ fn mk_t(cx: ctxt, +st: sty) -> t { mk_t_with_id(cx, st, None) }
901952
// Interns a type/name combination, stores the resulting box in cx.interner,
902953
// and returns the box as cast to an unsafe ptr (see comments for t above).
903954
fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option<ast::def_id>) -> t {
955+
// Check for primitive types.
956+
match st {
957+
ty_nil => return mk_nil(cx),
958+
ty_err => return mk_err(cx),
959+
ty_bool => return mk_bool(cx),
960+
ty_int(i) => return mk_mach_int(cx, i),
961+
ty_uint(u) => return mk_mach_uint(cx, u),
962+
ty_float(f) => return mk_mach_float(cx, f),
963+
_ => {}
964+
};
965+
904966
let key = intern_key { sty: to_unsafe_ptr(&st), o_def_id: o_def_id };
905967
match cx.interner.find(&key) {
906968
Some(t) => unsafe { return cast::transmute(&t.sty); },
@@ -996,49 +1058,95 @@ fn mk_t_with_id(cx: ctxt, +st: sty, o_def_id: Option<ast::def_id>) -> t {
9961058
}
9971059
}
9981060

999-
pub fn mk_nil(cx: ctxt) -> t { mk_t(cx, ty_nil) }
1061+
#[inline(always)]
1062+
pub fn mk_prim_t(cx: ctxt, primitive: &'static t_box_) -> t {
1063+
unsafe {
1064+
cast::transmute::<&'static t_box_, t>(primitive)
1065+
}
1066+
}
1067+
1068+
#[inline(always)]
1069+
pub fn mk_nil(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_NIL) }
10001070

1001-
pub fn mk_err(cx: ctxt) -> t { mk_t(cx, ty_err) }
1071+
#[inline(always)]
1072+
pub fn mk_err(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_ERR) }
10021073

1003-
pub fn mk_bot(cx: ctxt) -> t { mk_t(cx, ty_bot) }
1074+
#[inline(always)]
1075+
pub fn mk_bot(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_BOT) }
10041076

1005-
pub fn mk_bool(cx: ctxt) -> t { mk_t(cx, ty_bool) }
1077+
#[inline(always)]
1078+
pub fn mk_bool(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_BOOL) }
10061079

1007-
pub fn mk_int(cx: ctxt) -> t { mk_t(cx, ty_int(ast::ty_i)) }
1080+
#[inline(always)]
1081+
pub fn mk_int(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_INT) }
10081082

1009-
pub fn mk_i8(cx: ctxt) -> t { mk_t(cx, ty_int(ast::ty_i8)) }
1083+
#[inline(always)]
1084+
pub fn mk_i8(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_I8) }
10101085

1011-
pub fn mk_i16(cx: ctxt) -> t { mk_t(cx, ty_int(ast::ty_i16)) }
1086+
#[inline(always)]
1087+
pub fn mk_i16(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_I16) }
10121088

1013-
pub fn mk_i32(cx: ctxt) -> t { mk_t(cx, ty_int(ast::ty_i32)) }
1089+
#[inline(always)]
1090+
pub fn mk_i32(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_I32) }
10141091

1015-
pub fn mk_i64(cx: ctxt) -> t { mk_t(cx, ty_int(ast::ty_i64)) }
1092+
#[inline(always)]
1093+
pub fn mk_i64(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_I64) }
10161094

1017-
pub fn mk_float(cx: ctxt) -> t { mk_t(cx, ty_float(ast::ty_f)) }
1095+
#[inline(always)]
1096+
pub fn mk_float(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_FLOAT) }
10181097

1019-
pub fn mk_uint(cx: ctxt) -> t { mk_t(cx, ty_uint(ast::ty_u)) }
1098+
#[inline(always)]
1099+
pub fn mk_f32(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_F32) }
10201100

1021-
pub fn mk_u8(cx: ctxt) -> t { mk_t(cx, ty_uint(ast::ty_u8)) }
1101+
#[inline(always)]
1102+
pub fn mk_f64(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_F64) }
10221103

1023-
pub fn mk_u16(cx: ctxt) -> t { mk_t(cx, ty_uint(ast::ty_u16)) }
1104+
#[inline(always)]
1105+
pub fn mk_uint(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_UINT) }
10241106

1025-
pub fn mk_u32(cx: ctxt) -> t { mk_t(cx, ty_uint(ast::ty_u32)) }
1107+
#[inline(always)]
1108+
pub fn mk_u8(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_U8) }
10261109

1027-
pub fn mk_u64(cx: ctxt) -> t { mk_t(cx, ty_uint(ast::ty_u64)) }
1110+
#[inline(always)]
1111+
pub fn mk_u16(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_U16) }
10281112

1029-
pub fn mk_f32(cx: ctxt) -> t { mk_t(cx, ty_float(ast::ty_f32)) }
1113+
#[inline(always)]
1114+
pub fn mk_u32(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_U32) }
10301115

1031-
pub fn mk_f64(cx: ctxt) -> t { mk_t(cx, ty_float(ast::ty_f64)) }
1116+
#[inline(always)]
1117+
pub fn mk_u64(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_U64) }
10321118

1033-
pub fn mk_mach_int(cx: ctxt, tm: ast::int_ty) -> t { mk_t(cx, ty_int(tm)) }
1119+
pub fn mk_mach_int(cx: ctxt, tm: ast::int_ty) -> t {
1120+
match tm {
1121+
ast::ty_i => mk_int(cx),
1122+
ast::ty_char => mk_char(cx),
1123+
ast::ty_i8 => mk_i8(cx),
1124+
ast::ty_i16 => mk_i16(cx),
1125+
ast::ty_i32 => mk_i32(cx),
1126+
ast::ty_i64 => mk_i64(cx),
1127+
}
1128+
}
10341129

1035-
pub fn mk_mach_uint(cx: ctxt, tm: ast::uint_ty) -> t { mk_t(cx, ty_uint(tm)) }
1130+
pub fn mk_mach_uint(cx: ctxt, tm: ast::uint_ty) -> t {
1131+
match tm {
1132+
ast::ty_u => mk_uint(cx),
1133+
ast::ty_u8 => mk_u8(cx),
1134+
ast::ty_u16 => mk_u16(cx),
1135+
ast::ty_u32 => mk_u32(cx),
1136+
ast::ty_u64 => mk_u64(cx),
1137+
}
1138+
}
10361139

10371140
pub fn mk_mach_float(cx: ctxt, tm: ast::float_ty) -> t {
1038-
mk_t(cx, ty_float(tm))
1141+
match tm {
1142+
ast::ty_f => mk_float(cx),
1143+
ast::ty_f32 => mk_f32(cx),
1144+
ast::ty_f64 => mk_f64(cx),
1145+
}
10391146
}
10401147

1041-
pub fn mk_char(cx: ctxt) -> t { mk_t(cx, ty_int(ast::ty_char)) }
1148+
#[inline(always)]
1149+
pub fn mk_char(cx: ctxt) -> t { mk_prim_t(cx, &primitives::TY_CHAR) }
10421150

10431151
pub fn mk_estr(cx: ctxt, t: vstore) -> t {
10441152
mk_t(cx, ty_estr(t))

0 commit comments

Comments
 (0)