Skip to content

Commit 3035b51

Browse files
committed
---
yaml --- r: 146768 b: refs/heads/try2 c: fb279aa h: refs/heads/master v: v3
1 parent 75bb624 commit 3035b51

File tree

20 files changed

+608
-436
lines changed

20 files changed

+608
-436
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: ab2a99f69918f3e0bb6eb22f4523be07ac0222da
8+
refs/heads/try2: fb279aa02a7ff2ed069791f60a5159d73c8ed993
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/doc/tutorial.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1320,7 +1320,8 @@ let z = x; // this moves `x` into `z`, rather than creating a new owner
13201320

13211321
assert_eq!(*z.borrow(), [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);
13221322

1323-
let mut a = Rc::new([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]); // the variable is mutable, but not the box
1323+
// the variable is mutable, but not the contents of the box
1324+
let mut a = Rc::new([10, 9, 8, 7, 6, 5, 4, 3, 2, 1]);
13241325
a = z;
13251326
~~~
13261327

branches/try2/src/librustc/front/feature_gate.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,9 @@ impl Visitor<()> for Context {
152152
},
153153
ast::ty_box(_) => {
154154
self.gate_feature("managed_boxes", t.span,
155-
"The managed box syntax will be replaced \
156-
by a library type, and a garbage \
157-
collector is not yet implemented. \
158-
Consider using the `std::rc::Rc` type \
159-
for reference counted pointers.");
155+
"The managed box syntax is being replaced by the `std::gc::Gc`
156+
and `std::rc::Rc` types. Equivalent functionality to managed
157+
trait objects will be implemented but is currently missing.");
160158
}
161159
_ => {}
162160
}

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

Lines changed: 397 additions & 356 deletions
Large diffs are not rendered by default.

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

Lines changed: 5 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use middle::privacy;
2222
use std::hashmap::HashSet;
2323
use syntax::ast;
2424
use syntax::ast_map;
25-
use syntax::ast_util::{def_id_of_def, is_local, local_def};
25+
use syntax::ast_util::{def_id_of_def, is_local};
2626
use syntax::attr;
2727
use syntax::parse::token;
2828
use syntax::visit::Visitor;
@@ -310,47 +310,13 @@ impl ReachableContext {
310310
}
311311
}
312312

313-
// Implementations of exported structs/enums need to get
314-
// added to the worklist (as all their methods should be
315-
// accessible)
316-
ast::item_struct(*) | ast::item_enum(*) => {
317-
let def = local_def(item.id);
318-
let impls = match self.tcx.inherent_impls.find(&def) {
319-
Some(&impls) => impls,
320-
None => return
321-
};
322-
for imp in impls.iter() {
323-
if is_local(imp.did) {
324-
self.worklist.push(imp.did.node);
325-
}
326-
}
327-
}
328-
329-
// Propagate through this impl
330-
ast::item_impl(_, _, _, ref methods) => {
331-
for method in methods.iter() {
332-
self.worklist.push(method.id);
333-
}
334-
}
335-
336-
// Default methods of exported traits need to all be
337-
// accessible.
338-
ast::item_trait(_, _, ref methods) => {
339-
for method in methods.iter() {
340-
match *method {
341-
ast::required(*) => {}
342-
ast::provided(ref method) => {
343-
self.worklist.push(method.id);
344-
}
345-
}
346-
}
347-
}
348-
349313
// These are normal, nothing reachable about these
350314
// inherently and their children are already in the
351-
// worklist
315+
// worklist, as determined by the privacy pass
352316
ast::item_static(*) | ast::item_ty(*) |
353-
ast::item_mod(*) | ast::item_foreign_mod(*) => {}
317+
ast::item_mod(*) | ast::item_foreign_mod(*) |
318+
ast::item_impl(*) | ast::item_trait(*) |
319+
ast::item_struct(*) | ast::item_enum(*) => {}
354320

355321
_ => {
356322
self.tcx.sess.span_bug(item.span,

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2759,6 +2759,7 @@ pub fn declare_intrinsics(llmod: ModuleRef) -> HashMap<&'static str, ValueRef> {
27592759
[i8p, Type::i8(), Type::i64(), Type::i32(), Type::i1()], Type::void());
27602760

27612761
ifn!(intrinsics, "llvm.trap", [], Type::void());
2762+
ifn!(intrinsics, "llvm.debugtrap", [], Type::void());
27622763
ifn!(intrinsics, "llvm.frameaddress", [Type::i32()], i8p);
27632764

27642765
ifn!(intrinsics, "llvm.powi.f32", [Type::f32(), Type::i32()], Type::f32());

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,11 @@ pub fn trans_intrinsic(ccx: @mut CrateContext,
228228
Call(bcx, llfn, [], []);
229229
Unreachable(bcx);
230230
}
231+
"breakpoint" => {
232+
let llfn = bcx.ccx().intrinsics.get_copy(&("llvm.debugtrap"));
233+
Call(bcx, llfn, [], []);
234+
RetVoid(bcx);
235+
}
231236
"size_of" => {
232237
let tp_ty = substs.tys[0];
233238
let lltp_ty = type_of::type_of(ccx, tp_ty);

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3968,7 +3968,8 @@ pub fn check_intrinsic_type(ccx: @mut CrateCtxt, it: @ast::foreign_item) {
39683968

39693969
} else {
39703970
match name {
3971-
"abort" => (0, ~[], ty::mk_bot()),
3971+
"abort" => (0, ~[], ty::mk_bot()),
3972+
"breakpoint" => (0, ~[], ty::mk_nil()),
39723973
"size_of" |
39733974
"pref_align_of" | "min_align_of" => (1u, ~[], ty::mk_uint()),
39743975
"init" => (1u, ~[], param(ccx, 0u)),

branches/try2/src/libstd/rand/distributions/mod.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -444,17 +444,17 @@ mod tests {
444444
fn test_rand_sample() {
445445
let mut rand_sample = RandSample::<ConstRand>;
446446

447-
assert_eq!(*rand_sample.sample(task_rng()), 0);
448-
assert_eq!(*rand_sample.ind_sample(task_rng()), 0);
447+
assert_eq!(*rand_sample.sample(&mut task_rng()), 0);
448+
assert_eq!(*rand_sample.ind_sample(&mut task_rng()), 0);
449449
}
450450

451451
#[test]
452452
fn test_normal() {
453453
let mut norm = Normal::new(10.0, 10.0);
454-
let rng = task_rng();
454+
let mut rng = task_rng();
455455
for _ in range(0, 1000) {
456-
norm.sample(rng);
457-
norm.ind_sample(rng);
456+
norm.sample(&mut rng);
457+
norm.ind_sample(&mut rng);
458458
}
459459
}
460460
#[test]
@@ -466,10 +466,10 @@ mod tests {
466466
#[test]
467467
fn test_exp() {
468468
let mut exp = Exp::new(10.0);
469-
let rng = task_rng();
469+
let mut rng = task_rng();
470470
for _ in range(0, 1000) {
471-
assert!(exp.sample(rng) >= 0.0);
472-
assert!(exp.ind_sample(rng) >= 0.0);
471+
assert!(exp.sample(&mut rng) >= 0.0);
472+
assert!(exp.ind_sample(&mut rng) >= 0.0);
473473
}
474474
}
475475
#[test]

branches/try2/src/libstd/rand/distributions/range.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ mod tests {
183183

184184
#[test]
185185
fn test_integers() {
186-
let rng = task_rng();
186+
let mut rng = task_rng();
187187
macro_rules! t (
188188
($($ty:ty),*) => {{
189189
$(
@@ -193,9 +193,9 @@ mod tests {
193193
for &(low, high) in v.iter() {
194194
let mut sampler: Range<$ty> = Range::new(low, high);
195195
for _ in range(0, 1000) {
196-
let v = sampler.sample(rng);
196+
let v = sampler.sample(&mut rng);
197197
assert!(low <= v && v < high);
198-
let v = sampler.ind_sample(rng);
198+
let v = sampler.ind_sample(&mut rng);
199199
assert!(low <= v && v < high);
200200
}
201201
}
@@ -208,7 +208,7 @@ mod tests {
208208

209209
#[test]
210210
fn test_floats() {
211-
let rng = task_rng();
211+
let mut rng = task_rng();
212212
macro_rules! t (
213213
($($ty:ty),*) => {{
214214
$(
@@ -219,9 +219,9 @@ mod tests {
219219
for &(low, high) in v.iter() {
220220
let mut sampler: Range<$ty> = Range::new(low, high);
221221
for _ in range(0, 1000) {
222-
let v = sampler.sample(rng);
222+
let v = sampler.sample(&mut rng);
223223
assert!(low <= v && v < high);
224-
let v = sampler.ind_sample(rng);
224+
let v = sampler.ind_sample(&mut rng);
225225
assert!(low <= v && v < high);
226226
}
227227
}

branches/try2/src/libstd/rand/mod.rs

Lines changed: 29 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -577,11 +577,24 @@ impl reseeding::Reseeder<StdRng> for TaskRngReseeder {
577577
}
578578
}
579579
static TASK_RNG_RESEED_THRESHOLD: uint = 32_768;
580+
type TaskRngInner = reseeding::ReseedingRng<StdRng, TaskRngReseeder>;
580581
/// The task-local RNG.
581-
pub type TaskRng = reseeding::ReseedingRng<StdRng, TaskRngReseeder>;
582+
#[no_send]
583+
pub struct TaskRng {
584+
// This points into TLS (specifically, it points to the endpoint
585+
// of a ~ stored in TLS, to make it robust against TLS moving
586+
// things internally) and so this struct cannot be legally
587+
// transferred between tasks *and* it's unsafe to deallocate the
588+
// RNG other than when a task is finished.
589+
//
590+
// The use of unsafe code here is OK if the invariants above are
591+
// satisfied; and it allows us to avoid (unnecessarily) using a
592+
// GC'd or RC'd pointer.
593+
priv rng: *mut TaskRngInner
594+
}
582595

583596
// used to make space in TLS for a random number generator
584-
local_data_key!(TASK_RNG_KEY: @mut TaskRng)
597+
local_data_key!(TASK_RNG_KEY: ~TaskRngInner)
585598

586599
/// Retrieve the lazily-initialized task-local random number
587600
/// generator, seeded by the system. Intended to be used in method
@@ -594,34 +607,34 @@ local_data_key!(TASK_RNG_KEY: @mut TaskRng)
594607
/// if the operating system random number generator is rigged to give
595608
/// the same sequence always. If absolute consistency is required,
596609
/// explicitly select an RNG, e.g. `IsaacRng` or `Isaac64Rng`.
597-
pub fn task_rng() -> @mut TaskRng {
598-
let r = local_data::get(TASK_RNG_KEY, |k| k.map(|k| *k));
599-
match r {
610+
pub fn task_rng() -> TaskRng {
611+
local_data::get_mut(TASK_RNG_KEY, |rng| match rng {
600612
None => {
601-
let rng = @mut reseeding::ReseedingRng::new(StdRng::new(),
613+
let mut rng = ~reseeding::ReseedingRng::new(StdRng::new(),
602614
TASK_RNG_RESEED_THRESHOLD,
603615
TaskRngReseeder);
616+
let ptr = &mut *rng as *mut TaskRngInner;
617+
604618
local_data::set(TASK_RNG_KEY, rng);
605-
rng
619+
620+
TaskRng { rng: ptr }
606621
}
607-
Some(rng) => rng
608-
}
622+
Some(rng) => TaskRng { rng: &mut **rng }
623+
})
609624
}
610625

611-
// Allow direct chaining with `task_rng`
612-
impl<R: Rng> Rng for @mut R {
613-
#[inline]
626+
impl Rng for TaskRng {
614627
fn next_u32(&mut self) -> u32 {
615-
(**self).next_u32()
628+
unsafe { (*self.rng).next_u32() }
616629
}
617-
#[inline]
630+
618631
fn next_u64(&mut self) -> u64 {
619-
(**self).next_u64()
632+
unsafe { (*self.rng).next_u64() }
620633
}
621634

622635
#[inline]
623636
fn fill_bytes(&mut self, bytes: &mut [u8]) {
624-
(**self).fill_bytes(bytes);
637+
unsafe { (*self.rng).fill_bytes(bytes) }
625638
}
626639
}
627640

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ extern {
2020
#[inline]
2121
pub fn get_box_size(body_size: uint, body_align: uint) -> uint {
2222
let header_size = size_of::<raw::Box<()>>();
23-
// FIXME (#2699): This alignment calculation is suspicious. Is it right?
2423
let total_size = align_to(header_size, body_align) + body_size;
2524
total_size
2625
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ extern "rust-intrinsic" {
176176
/// Abort the execution of the process.
177177
pub fn abort() -> !;
178178

179+
/// Execute a breakpoint trap, for inspection by a debugger.
180+
#[cfg(not(stage0))]
181+
pub fn breakpoint();
182+
179183
/// Atomic compare and exchange, sequentially consistent.
180184
pub fn atomic_cxchg(dst: &mut int, old: int, src: int) -> int;
181185
/// Atomic compare and exchange, acquire ordering.

branches/try2/src/libstd/vec.rs

Lines changed: 70 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3862,10 +3862,10 @@ mod bench {
38623862
}
38633863

38643864
#[bench]
3865-
fn add(b: &mut BenchHarness) {
3865+
fn add(bh: &mut BenchHarness) {
38663866
let xs: &[int] = [5, ..10];
38673867
let ys: &[int] = [5, ..10];
3868-
do b.iter() {
3868+
do bh.iter() {
38693869
xs + ys;
38703870
}
38713871
}
@@ -3885,4 +3885,72 @@ mod bench {
38853885
xss.connect_vec(&0);
38863886
}
38873887
}
3888+
3889+
#[bench]
3890+
fn push(bh: &mut BenchHarness) {
3891+
let mut vec: ~[uint] = ~[0u];
3892+
do bh.iter() {
3893+
vec.push(0);
3894+
}
3895+
}
3896+
3897+
#[bench]
3898+
fn starts_with_same_vector(bh: &mut BenchHarness) {
3899+
let vec: ~[uint] = vec::from_fn(100, |i| i);
3900+
do bh.iter() {
3901+
vec.starts_with(vec);
3902+
}
3903+
}
3904+
3905+
#[bench]
3906+
fn starts_with_single_element(bh: &mut BenchHarness) {
3907+
let vec: ~[uint] = ~[0u];
3908+
do bh.iter() {
3909+
vec.starts_with(vec);
3910+
}
3911+
}
3912+
3913+
#[bench]
3914+
fn starts_with_diff_one_element_at_end(bh: &mut BenchHarness) {
3915+
let vec: ~[uint] = vec::from_fn(100, |i| i);
3916+
let mut match_vec: ~[uint] = vec::from_fn(99, |i| i);
3917+
match_vec.push(0);
3918+
do bh.iter() {
3919+
vec.starts_with(match_vec);
3920+
}
3921+
}
3922+
3923+
#[bench]
3924+
fn ends_with_same_vector(bh: &mut BenchHarness) {
3925+
let vec: ~[uint] = vec::from_fn(100, |i| i);
3926+
do bh.iter() {
3927+
vec.ends_with(vec);
3928+
}
3929+
}
3930+
3931+
#[bench]
3932+
fn ends_with_single_element(bh: &mut BenchHarness) {
3933+
let vec: ~[uint] = ~[0u];
3934+
do bh.iter() {
3935+
vec.ends_with(vec);
3936+
}
3937+
}
3938+
3939+
#[bench]
3940+
fn ends_with_diff_one_element_at_beginning(bh: &mut BenchHarness) {
3941+
let vec: ~[uint] = vec::from_fn(100, |i| i);
3942+
let mut match_vec: ~[uint] = vec::from_fn(100, |i| i);
3943+
match_vec[0] = 200;
3944+
do bh.iter() {
3945+
vec.starts_with(match_vec);
3946+
}
3947+
}
3948+
3949+
#[bench]
3950+
fn contains_last_element(bh: &mut BenchHarness) {
3951+
let vec: ~[uint] = vec::from_fn(100, |i| i);
3952+
do bh.iter() {
3953+
vec.contains(&99u);
3954+
}
3955+
}
38883956
}

0 commit comments

Comments
 (0)