about summary refs log tree commit diff
path: root/src/libsyntax
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-07-14 10:19:21 -0700
committerbors <bors@rust-lang.org>2013-07-14 10:19:21 -0700
commit1c35ab322ff2f26962a3550fffc2fa4154224b64 (patch)
treed95eb9acc27f980f2365330b3aa9566e8eec2010 /src/libsyntax
parent66e2857253ff9bc8ce299398ad5bb346d64e3fc3 (diff)
parent9fd2ac7428afa4f414f32b8b4876ca817ee85f16 (diff)
downloadrust-1c35ab322ff2f26962a3550fffc2fa4154224b64.tar.gz
rust-1c35ab322ff2f26962a3550fffc2fa4154224b64.zip
auto merge of #7751 : alexcrichton/rust/finish-tls, r=pcwalton
This changes the interface to `get`, and it also changes the keys to be static slices instead of static functions.

This allows the removal of the `unsafe` interface because while functions can monomorphize from different types to the same actual function, static slices cannot do this.

From at least what I can tell, we don't need to worry about LLVM coalescing these addresses. If we ever use the `unnamed_addr` it looks like there's cause for worry, but there doesn't appear to be any coalescing atm.
Diffstat (limited to 'src/libsyntax')
-rw-r--r--src/libsyntax/ast_util.rs24
-rw-r--r--src/libsyntax/ext/expand.rs16
-rw-r--r--src/libsyntax/ext/pipes/proto.rs3
-rw-r--r--src/libsyntax/parse/token.rs24
-rw-r--r--src/libsyntax/syntax.rs2
5 files changed, 34 insertions, 35 deletions
diff --git a/src/libsyntax/ast_util.rs b/src/libsyntax/ast_util.rs
index 7567dc0000b..a1d209d19ac 100644
--- a/src/libsyntax/ast_util.rs
+++ b/src/libsyntax/ast_util.rs
@@ -20,7 +20,6 @@ use std::hashmap::HashMap;
 use std::int;
 use std::num;
 use std::option;
-use std::cast;
 use std::local_data;
 
 pub fn path_name_i(idents: &[ident]) -> ~str {
@@ -695,18 +694,17 @@ pub fn new_sctable_internal() -> SCTable {
 
 // fetch the SCTable from TLS, create one if it doesn't yet exist.
 pub fn get_sctable() -> @mut SCTable {
-    unsafe {
-        let sctable_key = (cast::transmute::<(uint, uint),
-                           &fn:Copy(v: @@mut SCTable)>(
-                               (-4 as uint, 0u)));
-        match local_data::get(sctable_key, |k| k.map(|&k| *k)) {
-            None => {
-                let new_table = @@mut new_sctable_internal();
-                local_data::set(sctable_key,new_table);
-                *new_table
-            },
-            Some(intr) => *intr
-        }
+    #[cfg(not(stage0))]
+    static sctable_key: local_data::Key<@@mut SCTable> = &local_data::Key;
+    #[cfg(stage0)]
+    fn sctable_key(_: @@mut SCTable) {}
+    match local_data::get(sctable_key, |k| k.map(|&k| *k)) {
+        None => {
+            let new_table = @@mut new_sctable_internal();
+            local_data::set(sctable_key,new_table);
+            *new_table
+        },
+        Some(intr) => *intr
     }
 }
 
diff --git a/src/libsyntax/ext/expand.rs b/src/libsyntax/ext/expand.rs
index 2c3f42cca9a..b45cde6a8e3 100644
--- a/src/libsyntax/ext/expand.rs
+++ b/src/libsyntax/ext/expand.rs
@@ -579,11 +579,13 @@ pub fn core_macros() -> @str {
         { pub $c:ident: $in:ty -> $out:ty; } => {
 
             pub mod $c {
-                fn key(_x: @::std::condition::Handler<$in,$out>) { }
+                #[allow(non_uppercase_statics)];
+                static key: ::std::local_data::Key<
+                    @::std::condition::Handler<$in, $out>> =
+                    &::std::local_data::Key;
 
-                #[allow(non_uppercase_statics)]
                 pub static cond :
-                    ::std::condition::Condition<'static,$in,$out> =
+                    ::std::condition::Condition<$in,$out> =
                     ::std::condition::Condition {
                         name: stringify!($c),
                         key: key
@@ -595,11 +597,13 @@ pub fn core_macros() -> @str {
 
             // FIXME (#6009): remove mod's `pub` below once variant above lands.
             pub mod $c {
-                fn key(_x: @::std::condition::Handler<$in,$out>) { }
+                #[allow(non_uppercase_statics)];
+                static key: ::std::local_data::Key<
+                    @::std::condition::Handler<$in, $out>> =
+                    &::std::local_data::Key;
 
-                #[allow(non_uppercase_statics)]
                 pub static cond :
-                    ::std::condition::Condition<'static,$in,$out> =
+                    ::std::condition::Condition<$in,$out> =
                     ::std::condition::Condition {
                         name: stringify!($c),
                         key: key
diff --git a/src/libsyntax/ext/pipes/proto.rs b/src/libsyntax/ext/pipes/proto.rs
index 75424b60390..5866b8a5af5 100644
--- a/src/libsyntax/ext/pipes/proto.rs
+++ b/src/libsyntax/ext/pipes/proto.rs
@@ -144,7 +144,8 @@ pub struct protocol_ {
 impl protocol_ {
     /// Get a state.
     pub fn get_state(&self, name: &str) -> state {
-        *self.states.iter().find_(|i| name == i.name).get()
+        let mut i = self.states.iter();
+        *i.find_(|i| name == i.name).get()
     }
 
     pub fn get_state_by_id(&self, id: uint) -> state { self.states[id] }
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs
index 46e0ef32321..01860c3ae99 100644
--- a/src/libsyntax/parse/token.rs
+++ b/src/libsyntax/parse/token.rs
@@ -15,7 +15,6 @@ use parse::token;
 use util::interner::StrInterner;
 use util::interner;
 
-use std::cast;
 use std::cmp::Equiv;
 use std::local_data;
 use std::rand;
@@ -485,18 +484,17 @@ fn mk_fresh_ident_interner() -> @ident_interner {
 // if an interner exists in TLS, return it. Otherwise, prepare a
 // fresh one.
 pub fn get_ident_interner() -> @ident_interner {
-    unsafe {
-        let key =
-            (cast::transmute::<(uint, uint),
-             &fn:Copy(v: @@::parse::token::ident_interner)>(
-                 (-3 as uint, 0u)));
-        match local_data::get(key, |k| k.map(|&k| *k)) {
-            Some(interner) => *interner,
-            None => {
-                let interner = mk_fresh_ident_interner();
-                local_data::set(key, @interner);
-                interner
-            }
+    #[cfg(not(stage0))]
+    static key: local_data::Key<@@::parse::token::ident_interner> =
+        &local_data::Key;
+    #[cfg(stage0)]
+    fn key(_: @@::parse::token::ident_interner) {}
+    match local_data::get(key, |k| k.map(|&k| *k)) {
+        Some(interner) => *interner,
+        None => {
+            let interner = mk_fresh_ident_interner();
+            local_data::set(key, @interner);
+            interner
         }
     }
 }
diff --git a/src/libsyntax/syntax.rs b/src/libsyntax/syntax.rs
index 7cb211a402b..7a1e9923ab7 100644
--- a/src/libsyntax/syntax.rs
+++ b/src/libsyntax/syntax.rs
@@ -20,8 +20,6 @@
 #[license = "MIT/ASL2"];
 #[crate_type = "lib"];
 
-#[allow(non_camel_case_types)];
-#[allow(non_uppercase_statics)];
 #[deny(deprecated_pattern)];
 
 extern mod extra;