Skip to content

Commit 07c2c72

Browse files
committed
Update to build with latest rustc nightly
* Macro syntax changed (mandatory closing semicolon). * Array sytanx changed (`[ty, ..n]` replaced by `[ty; n]`). * Enums became namespaced. * `proc()` syntax got replaced by `move ||`. * `#[deriving(x)]` became deprected and got replaced by `#[derive(x)]`. * Some APIs changed (around pointers, slices, vectors, hashes, locks, strings, threads).
1 parent c63f564 commit 07c2c72

File tree

8 files changed

+76
-71
lines changed

8 files changed

+76
-71
lines changed

macros/src/atom/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,4 +139,4 @@ macro_rules! qualname (($ns:tt, $local:tt) => (
139139
ns: ns!($ns),
140140
local: atom!($local),
141141
}
142-
))
142+
));

macros/src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@ use rustc::plugin::Registry;
2525
macro_rules! bail ( ($cx:expr, $sp:expr, $msg:expr) => ({
2626
$cx.span_err($sp, $msg);
2727
return ::syntax::ext::base::DummyResult::any($sp);
28-
}))
28+
}));
2929

3030
macro_rules! bail_if ( ($e:expr, $cx:expr, $sp:expr, $msg:expr) => (
3131
if $e { bail!($cx, $sp, $msg) }
32-
))
32+
));
3333

3434
macro_rules! expect ( ($cx:expr, $sp:expr, $e:expr, $msg:expr) => (
3535
match $e {
3636
Some(x) => x,
3737
None => bail!($cx, $sp, $msg),
3838
}
39-
))
39+
));
4040

4141
mod atom;
4242

shared/repr.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
#![allow(dead_code, unused_imports)]
1515

1616
use core::{mem, raw, intrinsics};
17-
use core::option::{Option, Some, None};
18-
use core::ptr::RawPtr;
19-
use core::slice::{SlicePrelude, AsSlice};
17+
use core::option::Option::{self, Some, None};
18+
use core::ptr::PtrExt;
19+
use core::slice::{AsSlice, SliceExt};
2020
use core::slice::bytes;
2121

2222
pub use self::UnpackedAtom::{Dynamic, Inline, Static};
@@ -35,7 +35,7 @@ pub enum UnpackedAtom {
3535
Dynamic(*mut ()),
3636

3737
/// Length + bytes of string.
38-
Inline(u8, [u8, ..7]),
38+
Inline(u8, [u8; 7]),
3939

4040
/// Index in static interning table.
4141
Static(u32),
@@ -91,7 +91,7 @@ impl UnpackedAtom {
9191
INLINE_TAG => {
9292
let len = ((data & 0xf0) >> 4) as uint;
9393
debug_assert!(len <= MAX_INLINE_LEN);
94-
let mut buf: [u8, ..7] = [0, ..7];
94+
let mut buf: [u8; 7] = [0; 7];
9595
let src: &[u8] = mem::transmute(inline_atom_slice(&data));
9696
bytes::copy_memory(buf.as_mut_slice(), src);
9797
Inline(len as u8, buf)

src/atom/bench.rs

Lines changed: 41 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -44,37 +44,37 @@ macro_rules! check_type (($name:ident, $x:expr, $p:pat) => (
4444
_ => panic!("atom has wrong type"),
4545
}
4646
}
47-
))
47+
));
4848

4949
macro_rules! bench_tiny_op (($name:ident, $op:ident, $ctor_x:expr, $ctor_y:expr) => (
5050
#[bench]
5151
fn $name(b: &mut Bencher) {
5252
const n: uint = 1000;
53-
let xs = Vec::from_elem(n, $ctor_x);
54-
let ys = Vec::from_elem(n, $ctor_y);
53+
let xs: Vec<_> = repeat($ctor_x).take(n).collect();
54+
let ys: Vec<_> = repeat($ctor_y).take(n).collect();
5555

5656
b.iter(|| {
5757
for (x, y) in xs.iter().zip(ys.iter()) {
5858
black_box(x.$op(y));
5959
}
6060
});
6161
}
62-
))
62+
));
6363

6464
macro_rules! bench_one (
65-
(x_static $x:expr, $y:expr) => (check_type!(check_type_x, $x, Static(..)));
66-
(x_inline $x:expr, $y:expr) => (check_type!(check_type_x, $x, Inline(..)));
67-
(x_dynamic $x:expr, $y:expr) => (check_type!(check_type_x, $x, Dynamic(..)));
68-
(y_static $x:expr, $y:expr) => (check_type!(check_type_y, $y, Static(..)));
69-
(y_inline $x:expr, $y:expr) => (check_type!(check_type_y, $y, Inline(..)));
70-
(y_dynamic $x:expr, $y:expr) => (check_type!(check_type_y, $y, Dynamic(..)));
71-
(is_static $x:expr, $y:expr) => (bench_one!(x_static $x, $y) bench_one!(y_static $x, $y));
72-
(is_inline $x:expr, $y:expr) => (bench_one!(x_inline $x, $y) bench_one!(y_inline $x, $y));
73-
(is_dynamic $x:expr, $y:expr) => (bench_one!(x_dynamic $x, $y) bench_one!(y_dynamic $x, $y));
74-
75-
(eq $x:expr, $_y:expr) => (bench_tiny_op!(eq_x_1000, eq, $x, $x));
76-
(ne $x:expr, $y:expr) => (bench_tiny_op!(ne_x_1000, ne, $x, $y));
77-
(lt $x:expr, $y:expr) => (bench_tiny_op!(lt_x_1000, lt, $x, $y));
65+
(x_static $x:expr, $y:expr) => (check_type!(check_type_x, $x, Static(..)););
66+
(x_inline $x:expr, $y:expr) => (check_type!(check_type_x, $x, Inline(..)););
67+
(x_dynamic $x:expr, $y:expr) => (check_type!(check_type_x, $x, Dynamic(..)););
68+
(y_static $x:expr, $y:expr) => (check_type!(check_type_y, $y, Static(..)););
69+
(y_inline $x:expr, $y:expr) => (check_type!(check_type_y, $y, Inline(..)););
70+
(y_dynamic $x:expr, $y:expr) => (check_type!(check_type_y, $y, Dynamic(..)););
71+
(is_static $x:expr, $y:expr) => (bench_one!(x_static $x, $y); bench_one!(y_static $x, $y););
72+
(is_inline $x:expr, $y:expr) => (bench_one!(x_inline $x, $y); bench_one!(y_inline $x, $y););
73+
(is_dynamic $x:expr, $y:expr) => (bench_one!(x_dynamic $x, $y); bench_one!(y_dynamic $x, $y););
74+
75+
(eq $x:expr, $_y:expr) => (bench_tiny_op!(eq_x_1000, eq, $x, $x););
76+
(ne $x:expr, $y:expr) => (bench_tiny_op!(ne_x_1000, ne, $x, $y););
77+
(lt $x:expr, $y:expr) => (bench_tiny_op!(lt_x_1000, lt, $x, $y););
7878

7979
(intern $x:expr, $_y:expr) => (
8080
#[bench]
@@ -122,7 +122,7 @@ macro_rules! bench_one (
122122
});
123123
}
124124
);
125-
)
125+
);
126126

127127
macro_rules! bench_all (
128128
([ $($which:ident)+ ] for $name:ident = $x:expr, $y:expr) => (
@@ -135,61 +135,62 @@ macro_rules! bench_all (
135135
use collections::vec::Vec;
136136
use test::{Bencher, black_box};
137137
use std::string::ToString;
138+
use std::iter::repeat;
138139

139140
use atom::Atom;
140141
use atom::repr::{Static, Inline, Dynamic};
141142

142143
use super::mk;
143144

144145
$(
145-
bench_one!($which $x, $y)
146+
bench_one!($which $x, $y);
146147
)+
147148
}
148149
);
149-
)
150+
);
150151

151152
pub const longer_dynamic_a: &'static str
152153
= "Thee Silver Mt. Zion Memorial Orchestra & Tra-La-La Band";
153154
pub const longer_dynamic_b: &'static str
154155
= "Thee Silver Mt. Zion Memorial Orchestra & Tra-La-La Ban!";
155156

156-
bench_all!([eq ne lt clone_string] for short_string = "e", "f")
157-
bench_all!([eq ne lt clone_string] for medium_string = "xyzzy01", "xyzzy02")
157+
bench_all!([eq ne lt clone_string] for short_string = "e", "f");
158+
bench_all!([eq ne lt clone_string] for medium_string = "xyzzy01", "xyzzy02");
158159
bench_all!([eq ne lt clone_string]
159-
for longer_string = super::longer_dynamic_a, super::longer_dynamic_b)
160+
for longer_string = super::longer_dynamic_a, super::longer_dynamic_b);
160161

161162
bench_all!([eq ne intern as_slice clone is_static lt]
162-
for static_atom = atom!(a), atom!(b))
163+
for static_atom = atom!(a), atom!(b));
163164

164165
bench_all!([intern as_slice clone is_inline]
165-
for short_inline_atom = mk("e"), mk("f"))
166+
for short_inline_atom = mk("e"), mk("f"));
166167

167168
bench_all!([eq ne intern as_slice clone is_inline lt]
168-
for medium_inline_atom = mk("xyzzy01"), mk("xyzzy02"))
169+
for medium_inline_atom = mk("xyzzy01"), mk("xyzzy02"));
169170

170171
bench_all!([intern as_slice clone is_dynamic]
171-
for min_dynamic_atom = mk("xyzzy001"), mk("xyzzy002"))
172+
for min_dynamic_atom = mk("xyzzy001"), mk("xyzzy002"));
172173

173174
bench_all!([eq ne intern as_slice clone is_dynamic lt]
174-
for longer_dynamic_atom = mk(super::longer_dynamic_a), mk(super::longer_dynamic_b))
175+
for longer_dynamic_atom = mk(super::longer_dynamic_a), mk(super::longer_dynamic_b));
175176

176177
bench_all!([intern as_slice clone is_static]
177-
for static_at_runtime = mk("a"), mk("b"))
178+
for static_at_runtime = mk("a"), mk("b"));
178179

179180
bench_all!([ne lt x_static y_inline]
180-
for static_vs_inline = atom!(a), mk("f"))
181+
for static_vs_inline = atom!(a), mk("f"));
181182

182183
bench_all!([ne lt x_static y_dynamic]
183-
for static_vs_dynamic = atom!(a), mk(super::longer_dynamic_b))
184+
for static_vs_dynamic = atom!(a), mk(super::longer_dynamic_b));
184185

185186
bench_all!([ne lt x_inline y_dynamic]
186-
for inline_vs_dynamic = mk("e"), mk(super::longer_dynamic_b))
187+
for inline_vs_dynamic = mk("e"), mk(super::longer_dynamic_b));
187188

188189
macro_rules! bench_rand ( ($name:ident, $len:expr) => (
189190
#[bench]
190191
fn $name(b: &mut Bencher) {
191192
use std::{str, rand};
192-
use std::slice::{SlicePrelude, AsSlice};
193+
use std::slice::{AsSlice, SliceExt};
193194
use std::rand::Rng;
194195

195196
let mut gen = rand::weak_rng();
@@ -200,19 +201,19 @@ macro_rules! bench_rand ( ($name:ident, $len:expr) => (
200201
// I measured the overhead of random string generation
201202
// as about 3-12% at one point.
202203

203-
let mut buf: [u8, ..$len] = [0, ..$len];
204+
let mut buf: [u8; $len] = [0; $len];
204205
gen.fill_bytes(buf.as_mut_slice());
205206
for n in buf.iter_mut() {
206207
// shift into printable ASCII
207208
*n = (*n % 0x40) + 0x20;
208209
}
209-
let s = unsafe { str::raw::from_utf8(buf.as_slice()) };
210+
let s = unsafe { str::from_utf8(buf.as_slice()).unwrap() };
210211
black_box(Atom::from_slice(s));
211212
});
212213
}
213-
))
214+
));
214215

215-
bench_rand!(intern_rand_008, 8)
216-
bench_rand!(intern_rand_032, 32)
217-
bench_rand!(intern_rand_128, 128)
218-
bench_rand!(intern_rand_512, 512)
216+
bench_rand!(intern_rand_008, 8);
217+
bench_rand!(intern_rand_032, 32);
218+
bench_rand!(intern_rand_128, 128);
219+
bench_rand!(intern_rand_512, 512);

src/atom/mod.rs

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,27 @@ use phf::OrderedSet;
1515
use xxhash::XXHasher;
1616

1717
use core::fmt;
18+
use core::iter::RandomAccessIterator;
1819
use core::mem;
1920
use core::ptr;
2021
use core::slice::bytes;
2122
use core::str;
22-
use core::atomic::{AtomicInt, SeqCst};
2323
use alloc::heap;
2424
use alloc::boxed::Box;
2525
use collections::string::String;
26-
use collections::hash::{Hash, Hasher};
26+
use std::cmp::Ordering::{self, Equal};
27+
use std::hash::{Hash, Hasher};
2728
use std::sync::Mutex;
29+
use std::sync::atomic::AtomicInt;
30+
use std::sync::atomic::Ordering::SeqCst;
2831

2932
use self::repr::{UnpackedAtom, Static, Inline, Dynamic};
3033

3134
#[cfg(feature = "log-events")]
3235
use event;
3336

3437
#[cfg(not(feature = "log-events"))]
35-
macro_rules! log (($e:expr) => (()))
38+
macro_rules! log (($e:expr) => (()));
3639

3740
#[path="../../shared/repr.rs"]
3841
pub mod repr;
@@ -45,7 +48,7 @@ static static_atom_set: OrderedSet<&'static str> = static_atom_set!();
4548

4649
struct StringCache {
4750
hasher: XXHasher,
48-
buckets: [*mut StringCacheEntry, ..4096],
51+
buckets: [*mut StringCacheEntry; 4096],
4952
}
5053

5154
lazy_static! {
@@ -59,6 +62,8 @@ struct StringCacheEntry {
5962
string: String,
6063
}
6164

65+
unsafe impl Send for *mut StringCacheEntry { }
66+
6267
impl StringCacheEntry {
6368
fn new(next: *mut StringCacheEntry, hash: u64, string_to_add: &str) -> StringCacheEntry {
6469
StringCacheEntry {
@@ -161,7 +166,7 @@ impl StringCache {
161166
// NOTE: Deriving Eq here implies that a given string must always
162167
// be interned the same way.
163168
#[unsafe_no_drop_flag]
164-
#[deriving(Eq, Hash, PartialEq)]
169+
#[derive(Eq, Hash, PartialEq)]
165170
pub struct Atom {
166171
/// This field is public so that the `atom!()` macro can use it.
167172
/// You should not otherwise access this field.
@@ -180,17 +185,17 @@ impl Atom {
180185
None => {
181186
let len = string_to_add.len();
182187
if len <= repr::MAX_INLINE_LEN {
183-
let mut buf: [u8, ..7] = [0, ..7];
188+
let mut buf: [u8; 7] = [0; 7];
184189
bytes::copy_memory(buf.as_mut_slice(), string_to_add.as_bytes());
185190
Inline(len as u8, buf)
186191
} else {
187-
Dynamic(STRING_CACHE.lock().add(string_to_add) as *mut ())
192+
Dynamic(STRING_CACHE.lock().unwrap().add(string_to_add) as *mut ())
188193
}
189194
}
190195
};
191196

192197
let data = unsafe { unpacked.pack() };
193-
log!(event::Intern(data))
198+
log!(event::Intern(data));
194199
Atom { data: data }
195200
}
196201

@@ -199,8 +204,7 @@ impl Atom {
199204
match self.unpack() {
200205
Inline(..) => {
201206
let buf = repr::inline_orig_bytes(&self.data);
202-
debug_assert!(str::is_utf8(buf));
203-
str::from_utf8_unchecked(buf)
207+
str::from_utf8(buf).unwrap()
204208
},
205209
Static(idx) => *static_atom_set.iter().idx(idx as uint).expect("bad static atom"),
206210
Dynamic(entry) => {
@@ -235,15 +239,15 @@ impl Drop for Atom {
235239
fn drop(&mut self) {
236240
// Out of line to guide inlining.
237241
fn drop_slow(this: &mut Atom) {
238-
STRING_CACHE.lock().remove(this.data);
242+
STRING_CACHE.lock().unwrap().remove(this.data);
239243
}
240244

241245
unsafe {
242246
match repr::from_packed_dynamic(self.data) {
243247
// We use #[unsafe_no_drop_flag] so that Atom will be only 64
244248
// bits. That means we need to ignore a NULL pointer here,
245249
// which represents a value that was moved out.
246-
Some(entry) if entry.is_not_null() => {
250+
Some(entry) if !entry.is_null() => {
247251
let entry = entry as *mut StringCacheEntry;
248252
if (*entry).ref_count.fetch_sub(1, SeqCst) == 1 {
249253
drop_slow(self);
@@ -295,7 +299,7 @@ mod tests {
295299
use core::prelude::*;
296300

297301
use std::fmt;
298-
use std::task::spawn;
302+
use std::thread::Thread;
299303
use super::Atom;
300304
use super::repr::{Static, Inline, Dynamic};
301305

@@ -325,7 +329,7 @@ mod tests {
325329
$t => (),
326330
_ => panic!("atom has wrong type"),
327331
}
328-
))
332+
));
329333

330334
#[test]
331335
fn test_types() {
@@ -423,10 +427,10 @@ mod tests {
423427
let y = $y;
424428
if x != y {
425429
panic!("assertion failed: {} != {}",
426-
format_args!(fmt::format, $fmt, x).as_slice(),
427-
format_args!(fmt::format, $fmt, y).as_slice());
430+
format_args!($fmt, x),
431+
format_args!($fmt, y));
428432
}
429-
}))
433+
}));
430434

431435
#[test]
432436
fn repr() {
@@ -468,7 +472,7 @@ mod tests {
468472
#[test]
469473
fn test_threads() {
470474
for _ in range(0u32, 100u32) {
471-
spawn(proc() {
475+
Thread::spawn(move || {
472476
let _ = Atom::from_slice("a dynamic string");
473477
let _ = Atom::from_slice("another string");
474478
});

src/event.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ pub fn log(e: Event) {
3333
LOG.lock().push(e);
3434
}
3535

36-
macro_rules! log (($e:expr) => (::event::log($e)))
36+
macro_rules! log (($e:expr) => (::event::log($e)));

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#![crate_name = "string_cache"]
1111
#![crate_type = "rlib"]
1212

13-
#![feature(phase, macro_rules, default_type_params, globs)]
13+
#![feature(phase, macro_rules, default_type_params, globs, old_orphan_check)]
1414
#![no_std]
1515

1616
#[phase(plugin, link)]

0 commit comments

Comments
 (0)