Skip to content

Commit 642053c

Browse files
committed
---
yaml --- r: 146934 b: refs/heads/try2 c: 7bb166e h: refs/heads/master v: v3
1 parent 7002c65 commit 642053c

File tree

11 files changed

+78
-113
lines changed

11 files changed

+78
-113
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: 156054f55cb1289d5828d09099a5a7ff5a44c5bd
8+
refs/heads/try2: 7bb166ef4f5d9629aba514dccaf4f3fb094a3cbb
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/librustc/middle/lang_items.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,16 @@ pub enum LangItem {
8282
OpaqueStructLangItem, // 38
8383

8484
EventLoopFactoryLangItem, // 39
85-
86-
TypeIdLangItem, // 40
8785
}
8886

8987
pub struct LanguageItems {
90-
items: [Option<ast::DefId>, ..41]
88+
items: [Option<ast::DefId>, ..40]
9189
}
9290

9391
impl LanguageItems {
9492
pub fn new() -> LanguageItems {
9593
LanguageItems {
96-
items: [ None, ..41 ]
94+
items: [ None, ..40 ]
9795
}
9896
}
9997

@@ -150,8 +148,6 @@ impl LanguageItems {
150148

151149
39 => "event_loop_factory",
152150

153-
40 => "type_id",
154-
155151
_ => "???"
156152
}
157153
}
@@ -302,9 +298,6 @@ impl LanguageItems {
302298
pub fn event_loop_factory(&self) -> Option<ast::DefId> {
303299
self.items[EventLoopFactoryLangItem as uint]
304300
}
305-
pub fn type_id(&self) -> Option<ast::DefId> {
306-
self.items[TypeIdLangItem as uint]
307-
}
308301
}
309302

310303
struct LanguageItemCollector {
@@ -389,7 +382,6 @@ impl LanguageItemCollector {
389382
item_refs.insert("ty_visitor", TyVisitorTraitLangItem as uint);
390383
item_refs.insert("opaque", OpaqueStructLangItem as uint);
391384
item_refs.insert("event_loop_factory", EventLoopFactoryLangItem as uint);
392-
item_refs.insert("type_id", TypeIdLangItem as uint);
393385

394386
LanguageItemCollector {
395387
session: session,

branches/try2/src/librustc/middle/trans/controlflow.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ pub fn trans_if(bcx: @mut Block,
7777
return with_scope(bcx, thn.info(), "if_true_then", |bcx| {
7878
let bcx_out = trans_block(bcx, thn, dest);
7979
debuginfo::clear_source_location(bcx.fcx);
80-
trans_block_cleanups(bcx_out, block_cleanups(bcx))
80+
bcx_out
8181
})
8282
} else {
8383
let mut trans = TransItemVisitor { ccx: bcx.fcx.ccx } ;
@@ -90,9 +90,9 @@ pub fn trans_if(bcx: @mut Block,
9090
elexpr.info(),
9191
"if_false_then",
9292
|bcx| {
93-
let bcx_out = trans_if_else(bcx, elexpr, dest);
93+
let bcx_out = trans_if_else(bcx, elexpr, dest, false);
9494
debuginfo::clear_source_location(bcx.fcx);
95-
trans_block_cleanups(bcx_out, block_cleanups(bcx))
95+
bcx_out
9696
})
9797
}
9898
// if false { .. }
@@ -116,7 +116,7 @@ pub fn trans_if(bcx: @mut Block,
116116
let (else_bcx_in, next_bcx) = match els {
117117
Some(elexpr) => {
118118
let else_bcx_in = scope_block(bcx, elexpr.info(), "else");
119-
let else_bcx_out = trans_if_else(else_bcx_in, elexpr, dest);
119+
let else_bcx_out = trans_if_else(else_bcx_in, elexpr, dest, true);
120120
(else_bcx_in, join_blocks(bcx, [then_bcx_out, else_bcx_out]))
121121
}
122122
_ => {
@@ -138,7 +138,7 @@ pub fn trans_if(bcx: @mut Block,
138138

139139
// trans `else [ if { .. } ... | { .. } ]`
140140
fn trans_if_else(else_bcx_in: @mut Block, elexpr: @ast::Expr,
141-
dest: expr::Dest) -> @mut Block {
141+
dest: expr::Dest, cleanup: bool) -> @mut Block {
142142
let else_bcx_out = match elexpr.node {
143143
ast::ExprIf(_, _, _) => {
144144
let elseif_blk = ast_util::block_from_expr(elexpr);
@@ -150,8 +150,12 @@ pub fn trans_if(bcx: @mut Block,
150150
// would be nice to have a constraint on ifs
151151
_ => else_bcx_in.tcx().sess.bug("strange alternative in if")
152152
};
153-
debuginfo::clear_source_location(else_bcx_in.fcx);
154-
trans_block_cleanups(else_bcx_out, block_cleanups(else_bcx_in))
153+
if cleanup {
154+
debuginfo::clear_source_location(else_bcx_in.fcx);
155+
trans_block_cleanups(else_bcx_out, block_cleanups(else_bcx_in))
156+
} else {
157+
else_bcx_out
158+
}
155159
}
156160
}
157161

branches/try2/src/librustc/middle/trans/intrinsic.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -287,16 +287,7 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
287287
"type_id" => {
288288
let hash = ty::hash_crate_independent(ccx.tcx, substs.tys[0],
289289
ccx.link_meta.extras_hash);
290-
// NB: This needs to be kept in lockstep with the TypeId struct in
291-
// libstd/unstable/intrinsics.rs
292-
let val = C_named_struct(type_of::type_of(ccx, output_type), [C_u64(hash)]);
293-
match bcx.fcx.llretptr {
294-
Some(ptr) => {
295-
Store(bcx, val, ptr);
296-
RetVoid(bcx);
297-
},
298-
None => Ret(bcx, val)
299-
}
290+
Ret(bcx, C_i64(hash as i64))
300291
}
301292
"init" => {
302293
let tp_ty = substs.tys[0];

branches/try2/src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,6 @@ use middle::typeck::rscope::RegionScope;
105105
use middle::typeck::{lookup_def_ccx};
106106
use middle::typeck::no_params;
107107
use middle::typeck::{require_same_types, method_map, vtable_map};
108-
use middle::lang_items::TypeIdLangItem;
109108
use util::common::{block_query, indenter, loop_query};
110109
use util::ppaux::UserString;
111110
use util::ppaux;
@@ -4014,17 +4013,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
40144013
});
40154014
(1u, ~[], td_ptr)
40164015
}
4017-
"type_id" => {
4018-
let langid = ccx.tcx.lang_items.require(TypeIdLangItem);
4019-
match langid {
4020-
Ok(did) => (1u, ~[], ty::mk_struct(ccx.tcx, did, substs {
4021-
self_ty: None,
4022-
tps: ~[],
4023-
regions: ty::NonerasedRegions(opt_vec::Empty)
4024-
}) ),
4025-
Err(msg) => { tcx.sess.span_fatal(it.span, msg); }
4026-
}
4027-
},
4016+
"type_id" => (1u, ~[], ty::mk_u64()),
40284017
"visit_tydesc" => {
40294018
let tydesc_ty = match ty::get_tydesc_ty(ccx.tcx) {
40304019
Ok(t) => t,

branches/try2/src/libstd/any.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,28 +12,22 @@
1212
//! of any type.
1313
1414
use cast::transmute;
15-
#[cfg(stage0)]
1615
use cmp::Eq;
1716
use option::{Option, Some, None};
18-
#[cfg(stage0)]
1917
use to_bytes::{IterBytes, Cb};
2018
use to_str::ToStr;
2119
use unstable::intrinsics;
2220
use util::Void;
23-
#[cfg(not(stage0))]
24-
use unstable::intrinsics::TypeId;
2521

2622
///////////////////////////////////////////////////////////////////////////////
2723
// TypeId
2824
///////////////////////////////////////////////////////////////////////////////
2925

3026
/// `TypeId` represents a globally unique identifier for a type
31-
#[cfg(stage0)]
3227
pub struct TypeId {
3328
priv t: u64,
3429
}
3530

36-
#[cfg(stage0)]
3731
impl TypeId {
3832
/// Returns the `TypeId` of the type this generic function has been instantiated with
3933
#[inline]
@@ -42,15 +36,13 @@ impl TypeId {
4236
}
4337
}
4438

45-
#[cfg(stage0)]
4639
impl Eq for TypeId {
4740
#[inline]
4841
fn eq(&self, &other: &TypeId) -> bool {
4942
self.t == other.t
5043
}
5144
}
5245

53-
#[cfg(stage0)]
5446
impl IterBytes for TypeId {
5547
fn iter_bytes(&self, lsb0: bool, f: Cb) -> bool {
5648
self.t.iter_bytes(lsb0, f)
@@ -197,6 +189,29 @@ mod tests {
197189

198190
static TEST: &'static str = "Test";
199191

192+
#[test]
193+
fn type_id() {
194+
let (a, b, c) = (TypeId::of::<uint>(), TypeId::of::<&'static str>(),
195+
TypeId::of::<Test>());
196+
let (d, e, f) = (TypeId::of::<uint>(), TypeId::of::<&'static str>(),
197+
TypeId::of::<Test>());
198+
199+
assert!(a != b);
200+
assert!(a != c);
201+
assert!(b != c);
202+
203+
assert_eq!(a, d);
204+
assert_eq!(b, e);
205+
assert_eq!(c, f);
206+
}
207+
208+
#[test]
209+
fn type_id_hash() {
210+
let (a, b) = (TypeId::of::<uint>(), TypeId::of::<uint>());
211+
212+
assert_eq!(a.hash(), b.hash());
213+
}
214+
200215
#[test]
201216
fn any_as_void_ptr() {
202217
let (a, b, c) = (~5u as ~Any, ~TEST as ~Any, ~Test as ~Any);

branches/try2/src/libstd/unstable/intrinsics.rs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ A quick refresher on memory ordering:
3434

3535
// This is needed to prevent duplicate lang item definitions.
3636
#[cfg(test)]
37-
pub use realstd::unstable::intrinsics::{TyDesc, Opaque, TyVisitor, TypeId};
37+
pub use realstd::unstable::intrinsics::{TyDesc, Opaque, TyVisitor};
3838

3939
pub type GlueFn = extern "Rust" fn(*i8);
4040

@@ -313,11 +313,7 @@ extern "rust-intrinsic" {
313313
/// Gets an identifier which is globally unique to the specified type. This
314314
/// function will return the same value for a type regardless of whichever
315315
/// crate it is invoked in.
316-
#[cfg(stage0)]
317316
pub fn type_id<T: 'static>() -> u64;
318-
#[cfg(not(stage0))]
319-
pub fn type_id<T: 'static>() -> TypeId;
320-
321317

322318
/// Create a value initialized to zero.
323319
///
@@ -490,22 +486,3 @@ extern "rust-intrinsic" {
490486
#[cfg(target_endian = "big")] pub fn to_be32(x: i32) -> i32 { x }
491487
#[cfg(target_endian = "little")] pub fn to_be64(x: i64) -> i64 { unsafe { bswap64(x) } }
492488
#[cfg(target_endian = "big")] pub fn to_be64(x: i64) -> i64 { x }
493-
494-
495-
/// `TypeId` represents a globally unique identifier for a type
496-
#[lang="type_id"] // This needs to be kept in lockstep with the code in trans/intrinsic.rs and
497-
// middle/lang_items.rs
498-
#[deriving(Eq, IterBytes)]
499-
#[cfg(not(test))]
500-
pub struct TypeId {
501-
priv t: u64,
502-
}
503-
504-
#[cfg(not(test))]
505-
impl TypeId {
506-
/// Returns the `TypeId` of the type this generic function has been instantiated with
507-
#[cfg(not(stage0))]
508-
pub fn of<T: 'static>() -> TypeId {
509-
unsafe { type_id::<T>() }
510-
}
511-
}

branches/try2/src/test/auxiliary/typeid-intrinsic.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use std::unstable::intrinsics;
12-
use std::unstable::intrinsics::TypeId;
1312

1413
pub struct A;
1514
pub struct B(Option<A>);
@@ -21,13 +20,13 @@ pub type F = Option<int>;
2120
pub type G = uint;
2221
pub type H = &'static str;
2322

24-
pub unsafe fn id_A() -> TypeId { intrinsics::type_id::<A>() }
25-
pub unsafe fn id_B() -> TypeId { intrinsics::type_id::<B>() }
26-
pub unsafe fn id_C() -> TypeId { intrinsics::type_id::<C>() }
27-
pub unsafe fn id_D() -> TypeId { intrinsics::type_id::<D>() }
28-
pub unsafe fn id_E() -> TypeId { intrinsics::type_id::<E>() }
29-
pub unsafe fn id_F() -> TypeId { intrinsics::type_id::<F>() }
30-
pub unsafe fn id_G() -> TypeId { intrinsics::type_id::<G>() }
31-
pub unsafe fn id_H() -> TypeId { intrinsics::type_id::<H>() }
23+
pub unsafe fn id_A() -> u64 { intrinsics::type_id::<A>() }
24+
pub unsafe fn id_B() -> u64 { intrinsics::type_id::<B>() }
25+
pub unsafe fn id_C() -> u64 { intrinsics::type_id::<C>() }
26+
pub unsafe fn id_D() -> u64 { intrinsics::type_id::<D>() }
27+
pub unsafe fn id_E() -> u64 { intrinsics::type_id::<E>() }
28+
pub unsafe fn id_F() -> u64 { intrinsics::type_id::<F>() }
29+
pub unsafe fn id_G() -> u64 { intrinsics::type_id::<G>() }
30+
pub unsafe fn id_H() -> u64 { intrinsics::type_id::<H>() }
3231

33-
pub unsafe fn foo<T: 'static>() -> TypeId { intrinsics::type_id::<T>() }
32+
pub unsafe fn foo<T: 'static>() -> u64 { intrinsics::type_id::<T>() }

branches/try2/src/test/auxiliary/typeid-intrinsic2.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use std::unstable::intrinsics;
12-
use std::unstable::intrinsics::TypeId;
1312

1413
pub struct A;
1514
pub struct B(Option<A>);
@@ -21,13 +20,13 @@ pub type F = Option<int>;
2120
pub type G = uint;
2221
pub type H = &'static str;
2322

24-
pub unsafe fn id_A() -> TypeId { intrinsics::type_id::<A>() }
25-
pub unsafe fn id_B() -> TypeId { intrinsics::type_id::<B>() }
26-
pub unsafe fn id_C() -> TypeId { intrinsics::type_id::<C>() }
27-
pub unsafe fn id_D() -> TypeId { intrinsics::type_id::<D>() }
28-
pub unsafe fn id_E() -> TypeId { intrinsics::type_id::<E>() }
29-
pub unsafe fn id_F() -> TypeId { intrinsics::type_id::<F>() }
30-
pub unsafe fn id_G() -> TypeId { intrinsics::type_id::<G>() }
31-
pub unsafe fn id_H() -> TypeId { intrinsics::type_id::<H>() }
23+
pub unsafe fn id_A() -> u64 { intrinsics::type_id::<A>() }
24+
pub unsafe fn id_B() -> u64 { intrinsics::type_id::<B>() }
25+
pub unsafe fn id_C() -> u64 { intrinsics::type_id::<C>() }
26+
pub unsafe fn id_D() -> u64 { intrinsics::type_id::<D>() }
27+
pub unsafe fn id_E() -> u64 { intrinsics::type_id::<E>() }
28+
pub unsafe fn id_F() -> u64 { intrinsics::type_id::<F>() }
29+
pub unsafe fn id_G() -> u64 { intrinsics::type_id::<G>() }
30+
pub unsafe fn id_H() -> u64 { intrinsics::type_id::<H>() }
3231

33-
pub unsafe fn foo<T: 'static>() -> TypeId { intrinsics::type_id::<T>() }
32+
pub unsafe fn foo<T: 'static>() -> u64 { intrinsics::type_id::<T>() }
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
pub fn main() {
12+
if true {
13+
let _a = ~3;
14+
}
15+
if false {
16+
fail!()
17+
} else {
18+
let _a = ~3;
19+
}
20+
}

branches/try2/src/test/run-pass/typeid-intrinsic.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ extern mod other1(name = "typeid-intrinsic");
1616
extern mod other2(name = "typeid-intrinsic2");
1717

1818
use std::unstable::intrinsics;
19-
use std::unstable::intrinsics::TypeId;
2019

2120
struct A;
22-
struct Test;
2321

2422
fn main() {
2523
unsafe {
@@ -52,23 +50,4 @@ fn main() {
5250
assert_eq!(intrinsics::type_id::<A>(), other1::foo::<A>());
5351
assert_eq!(other2::foo::<A>(), other1::foo::<A>());
5452
}
55-
56-
// sanity test of TypeId
57-
let (a, b, c) = (TypeId::of::<uint>(), TypeId::of::<&'static str>(),
58-
TypeId::of::<Test>());
59-
let (d, e, f) = (TypeId::of::<uint>(), TypeId::of::<&'static str>(),
60-
TypeId::of::<Test>());
61-
62-
assert!(a != b);
63-
assert!(a != c);
64-
assert!(b != c);
65-
66-
assert_eq!(a, d);
67-
assert_eq!(b, e);
68-
assert_eq!(c, f);
69-
70-
// check it has a hash
71-
let (a, b) = (TypeId::of::<uint>(), TypeId::of::<uint>());
72-
73-
assert_eq!(a.hash(), b.hash());
7453
}

0 commit comments

Comments
 (0)