Skip to content

Commit b959ec8

Browse files
committed
---
yaml --- r: 146424 b: refs/heads/try2 c: 1c56652 h: refs/heads/master v: v3
1 parent b146da9 commit b959ec8

File tree

14 files changed

+369
-99
lines changed

14 files changed

+369
-99
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: 77e0235983ba3ad16f99123604dbbd1401ba8d6c
8+
refs/heads/try2: 1c56652640c6f376cf454c63c7dd80eabe28ed5e
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/trans/intrinsic.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
285285
let td = PointerCast(bcx, static_ti.tydesc, userland_tydesc_ty);
286286
Ret(bcx, td);
287287
}
288+
"type_id" => {
289+
let hash = ty::hash_crate_independent(ccx.tcx, substs.tys[0],
290+
ccx.link_meta.extras_hash);
291+
Ret(bcx, C_i64(hash as i64))
292+
}
288293
"init" => {
289294
let tp_ty = substs.tys[0];
290295
let lltp_ty = type_of::type_of(ccx, tp_ty);

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

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4745,3 +4745,154 @@ pub fn trait_of_method(tcx: ctxt, def_id: ast::DefId)
47454745

47464746
result
47474747
}
4748+
4749+
/// Creates a hash of the type `t` which will be the same no matter what crate
4750+
/// context it's calculated within. This is used by the `type_id` intrinsic.
4751+
pub fn hash_crate_independent(tcx: ctxt, t: t, local_hash: @str) -> u64 {
4752+
use std::hash::{SipState, Streaming};
4753+
use metadata::cstore;
4754+
4755+
let mut hash = SipState::new(0, 0);
4756+
let region = |_hash: &mut SipState, r: Region| {
4757+
match r {
4758+
re_static => {}
4759+
4760+
re_empty | re_bound(*) | re_free(*) | re_scope(*) | re_infer(*) =>
4761+
tcx.sess.bug("non-static region found when hashing a type")
4762+
}
4763+
};
4764+
let vstore = |hash: &mut SipState, v: vstore| {
4765+
match v {
4766+
vstore_fixed(_) => hash.input([0]),
4767+
vstore_uniq => hash.input([1]),
4768+
vstore_box => hash.input([2]),
4769+
vstore_slice(r) => {
4770+
hash.input([3]);
4771+
region(hash, r);
4772+
}
4773+
}
4774+
};
4775+
let did = |hash: &mut SipState, did: DefId| {
4776+
let h = if ast_util::is_local(did) {
4777+
local_hash
4778+
} else {
4779+
cstore::get_crate_hash(tcx.sess.cstore, did.crate)
4780+
};
4781+
hash.input(h.as_bytes());
4782+
iter(hash, &did.node);
4783+
};
4784+
let mt = |hash: &mut SipState, mt: mt| {
4785+
iter(hash, &mt.mutbl);
4786+
};
4787+
fn iter<T: IterBytes>(hash: &mut SipState, t: &T) {
4788+
do t.iter_bytes(true) |bytes| { hash.input(bytes); true };
4789+
}
4790+
do ty::walk_ty(t) |t| {
4791+
match ty::get(t).sty {
4792+
ty_nil => hash.input([0]),
4793+
ty_bot => hash.input([1]),
4794+
ty_bool => hash.input([2]),
4795+
ty_char => hash.input([3]),
4796+
ty_int(i) => {
4797+
hash.input([4]);
4798+
iter(&mut hash, &i);
4799+
}
4800+
ty_uint(u) => {
4801+
hash.input([5]);
4802+
iter(&mut hash, &u);
4803+
}
4804+
ty_float(f) => {
4805+
hash.input([6]);
4806+
iter(&mut hash, &f);
4807+
}
4808+
ty_estr(v) => {
4809+
hash.input([7]);
4810+
vstore(&mut hash, v);
4811+
}
4812+
ty_enum(d, _) => {
4813+
hash.input([8]);
4814+
did(&mut hash, d);
4815+
}
4816+
ty_box(m) => {
4817+
hash.input([9]);
4818+
mt(&mut hash, m);
4819+
}
4820+
ty_uniq(m) => {
4821+
hash.input([10]);
4822+
mt(&mut hash, m);
4823+
}
4824+
ty_evec(m, v) => {
4825+
hash.input([11]);
4826+
mt(&mut hash, m);
4827+
vstore(&mut hash, v);
4828+
}
4829+
ty_ptr(m) => {
4830+
hash.input([12]);
4831+
mt(&mut hash, m);
4832+
}
4833+
ty_rptr(r, m) => {
4834+
hash.input([13]);
4835+
region(&mut hash, r);
4836+
mt(&mut hash, m);
4837+
}
4838+
ty_bare_fn(ref b) => {
4839+
hash.input([14]);
4840+
iter(&mut hash, &b.purity);
4841+
iter(&mut hash, &b.abis);
4842+
}
4843+
ty_closure(ref c) => {
4844+
hash.input([15]);
4845+
iter(&mut hash, &c.purity);
4846+
iter(&mut hash, &c.sigil);
4847+
iter(&mut hash, &c.onceness);
4848+
iter(&mut hash, &c.bounds);
4849+
region(&mut hash, c.region);
4850+
}
4851+
ty_trait(d, _, store, m, bounds) => {
4852+
hash.input([17]);
4853+
did(&mut hash, d);
4854+
match store {
4855+
BoxTraitStore => hash.input([0]),
4856+
UniqTraitStore => hash.input([1]),
4857+
RegionTraitStore(r) => {
4858+
hash.input([2]);
4859+
region(&mut hash, r);
4860+
}
4861+
}
4862+
iter(&mut hash, &m);
4863+
iter(&mut hash, &bounds);
4864+
}
4865+
ty_struct(d, _) => {
4866+
hash.input([18]);
4867+
did(&mut hash, d);
4868+
}
4869+
ty_tup(ref inner) => {
4870+
hash.input([19]);
4871+
iter(&mut hash, &inner.len());
4872+
}
4873+
ty_param(p) => {
4874+
hash.input([20]);
4875+
iter(&mut hash, &p.idx);
4876+
did(&mut hash, p.def_id);
4877+
}
4878+
ty_self(d) => {
4879+
hash.input([21]);
4880+
did(&mut hash, d);
4881+
}
4882+
ty_infer(_) => unreachable!(),
4883+
ty_err => hash.input([23]),
4884+
ty_type => hash.input([24]),
4885+
ty_opaque_box => hash.input([25]),
4886+
ty_opaque_closure_ptr(s) => {
4887+
hash.input([26]);
4888+
iter(&mut hash, &s);
4889+
}
4890+
ty_unboxed_vec(m) => {
4891+
hash.input([27]);
4892+
mt(&mut hash, m);
4893+
}
4894+
}
4895+
}
4896+
4897+
hash.result_u64()
4898+
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3755,6 +3755,7 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
37553755
});
37563756
(1u, ~[], td_ptr)
37573757
}
3758+
"type_id" => (1u, ~[], ty::mk_u64()),
37583759
"visit_tydesc" => {
37593760
let tydesc_ty = match ty::get_tydesc_ty(ccx.tcx) {
37603761
Ok(t) => t,

branches/try2/src/libstd/any.rs

Lines changed: 46 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,38 @@ use cast::transmute;
1515
use cmp::Eq;
1616
use option::{Option, Some, None};
1717
use to_str::ToStr;
18-
use unstable::intrinsics::{TyDesc, get_tydesc, forget};
18+
use unstable::intrinsics;
1919
use util::Void;
2020

2121
///////////////////////////////////////////////////////////////////////////////
2222
// TypeId
23-
// FIXME: #9913 - Needs proper intrinsic support to work reliably cross crate
2423
///////////////////////////////////////////////////////////////////////////////
2524

2625
/// `TypeId` represents a globally unique identifier for a type
26+
#[cfg(stage0)]
2727
pub struct TypeId {
28-
priv t: *TyDesc
28+
priv t: *intrinsics::TyDesc,
29+
}
30+
31+
/// `TypeId` represents a globally unique identifier for a type
32+
#[cfg(not(stage0))]
33+
pub struct TypeId {
34+
priv t: u64,
2935
}
3036

3137
impl TypeId {
3238
/// Returns the `TypeId` of the type this generic function has been instantiated with
3339
#[inline]
34-
pub fn of<T>() -> TypeId {
35-
TypeId{ t: unsafe { get_tydesc::<T>() } }
40+
#[cfg(stage0)]
41+
pub fn of<T: 'static>() -> TypeId {
42+
TypeId{ t: unsafe { intrinsics::get_tydesc::<T>() } }
43+
}
44+
45+
/// Returns the `TypeId` of the type this generic function has been instantiated with
46+
#[inline]
47+
#[cfg(not(stage0))]
48+
pub fn of<T: 'static>() -> TypeId {
49+
TypeId{ t: unsafe { intrinsics::type_id::<T>() } }
3650
}
3751
}
3852

@@ -50,22 +64,32 @@ impl Eq for TypeId {
5064
/// The `Any` trait is implemented by all types, and can be used as a trait object
5165
/// for dynamic typing
5266
pub trait Any {
67+
/// Get the `TypeId` of `self`
68+
fn get_type_id(&self) -> TypeId;
69+
70+
/// Get a void pointer to `self`
71+
fn as_void_ptr(&self) -> *Void;
72+
73+
/// Get a mutable void pointer to `self`
74+
fn as_mut_void_ptr(&mut self) -> *mut Void;
75+
}
76+
77+
impl<T: 'static> Any for T {
5378
/// Get the `TypeId` of `self`
5479
fn get_type_id(&self) -> TypeId {
55-
TypeId::of::<Self>()
80+
TypeId::of::<T>()
5681
}
5782

5883
/// Get a void pointer to `self`
5984
fn as_void_ptr(&self) -> *Void {
60-
self as *Self as *Void
85+
self as *T as *Void
6186
}
6287

6388
/// Get a mutable void pointer to `self`
6489
fn as_mut_void_ptr(&mut self) -> *mut Void {
65-
self as *mut Self as *mut Void
90+
self as *mut T as *mut Void
6691
}
6792
}
68-
impl<T> Any for T {}
6993

7094
///////////////////////////////////////////////////////////////////////////////
7195
// Extension methods for Any trait objects.
@@ -75,16 +99,16 @@ impl<T> Any for T {}
7599
/// Extension methods for a referenced `Any` trait object
76100
pub trait AnyRefExt<'self> {
77101
/// Returns true if the boxed type is the same as `T`
78-
fn is<T>(self) -> bool;
102+
fn is<T: 'static>(self) -> bool;
79103

80104
/// Returns some reference to the boxed value if it is of type `T`, or
81105
/// `None` if it isn't.
82-
fn as_ref<T>(self) -> Option<&'self T>;
106+
fn as_ref<T: 'static>(self) -> Option<&'self T>;
83107
}
84108

85109
impl<'self> AnyRefExt<'self> for &'self Any {
86110
#[inline]
87-
fn is<T>(self) -> bool {
111+
fn is<T: 'static>(self) -> bool {
88112
// Get TypeId of the type this function is instantiated with
89113
let t = TypeId::of::<T>();
90114

@@ -96,7 +120,7 @@ impl<'self> AnyRefExt<'self> for &'self Any {
96120
}
97121

98122
#[inline]
99-
fn as_ref<T>(self) -> Option<&'self T> {
123+
fn as_ref<T: 'static>(self) -> Option<&'self T> {
100124
if self.is::<T>() {
101125
Some(unsafe { transmute(self.as_void_ptr()) })
102126
} else {
@@ -109,12 +133,12 @@ impl<'self> AnyRefExt<'self> for &'self Any {
109133
pub trait AnyMutRefExt<'self> {
110134
/// Returns some mutable reference to the boxed value if it is of type `T`, or
111135
/// `None` if it isn't.
112-
fn as_mut<T>(self) -> Option<&'self mut T>;
136+
fn as_mut<T: 'static>(self) -> Option<&'self mut T>;
113137
}
114138

115139
impl<'self> AnyMutRefExt<'self> for &'self mut Any {
116140
#[inline]
117-
fn as_mut<T>(self) -> Option<&'self mut T> {
141+
fn as_mut<T: 'static>(self) -> Option<&'self mut T> {
118142
if self.is::<T>() {
119143
Some(unsafe { transmute(self.as_mut_void_ptr()) })
120144
} else {
@@ -127,19 +151,19 @@ impl<'self> AnyMutRefExt<'self> for &'self mut Any {
127151
pub trait AnyOwnExt {
128152
/// Returns the boxed value if it is of type `T`, or
129153
/// `None` if it isn't.
130-
fn move<T>(self) -> Option<~T>;
154+
fn move<T: 'static>(self) -> Option<~T>;
131155
}
132156

133157
impl AnyOwnExt for ~Any {
134158
#[inline]
135-
fn move<T>(self) -> Option<~T> {
159+
fn move<T: 'static>(self) -> Option<~T> {
136160
if self.is::<T>() {
137161
unsafe {
138162
// Extract the pointer to the boxed value, temporary alias with self
139163
let ptr: ~T = transmute(self.as_void_ptr());
140164

141165
// Prevent destructor on self being run
142-
forget(self);
166+
intrinsics::forget(self);
143167

144168
Some(ptr)
145169
}
@@ -174,8 +198,10 @@ mod tests {
174198

175199
#[test]
176200
fn type_id() {
177-
let (a, b, c) = (TypeId::of::<uint>(), TypeId::of::<&str>(), TypeId::of::<Test>());
178-
let (d, e, f) = (TypeId::of::<uint>(), TypeId::of::<&str>(), TypeId::of::<Test>());
201+
let (a, b, c) = (TypeId::of::<uint>(), TypeId::of::<&'static str>(),
202+
TypeId::of::<Test>());
203+
let (d, e, f) = (TypeId::of::<uint>(), TypeId::of::<&'static str>(),
204+
TypeId::of::<Test>());
179205

180206
assert!(a != b);
181207
assert!(a != c);

branches/try2/src/libstd/rt/kill.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,9 @@ use cell::Cell;
155155
use option::{Option, Some, None};
156156
use prelude::*;
157157
use rt::task::Task;
158-
use rt::task::UnwindMessageLinked;
159158
use rt::task::{UnwindResult, Failure};
160159
use task::spawn::Taskgroup;
160+
use task::LinkedFailure;
161161
use to_bytes::IterBytes;
162162
use unstable::atomics::{AtomicUint, Relaxed};
163163
use unstable::sync::{UnsafeArc, UnsafeArcSelf, UnsafeArcT, LittleLock};
@@ -597,7 +597,7 @@ impl Death {
597597
}
598598

599599
if !success {
600-
result = Cell::new(Failure(UnwindMessageLinked));
600+
result = Cell::new(Failure(~LinkedFailure as ~Any));
601601
}
602602
}
603603
on_exit(result.take());

0 commit comments

Comments
 (0)