Skip to content

Commit 5e6b696

Browse files
committed
---
yaml --- r: 107845 b: refs/heads/dist-snap c: 60ffbeb h: refs/heads/master i: 107843: 7ed4224 v: v3
1 parent f542624 commit 5e6b696

File tree

21 files changed

+228
-214
lines changed

21 files changed

+228
-214
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: f64fdf524a434f0e5cd0bc91d09c144723f3c90d
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: 147ecfdd8221e4a4d4e090486829a06da1e0ca3c
9-
refs/heads/dist-snap: 5afc63a2aef113d49944b6ee5f7a743198a6aff1
9+
refs/heads/dist-snap: 60ffbeb2a495d097e38f51348ebcf5a884947c25
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
1212
refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0

branches/dist-snap/src/libarena/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use std::ptr;
3636
use std::kinds::marker;
3737
use std::mem;
3838
use std::rt::global_heap;
39-
use std::uint;
4039
use std::unstable::intrinsics::{TyDesc, get_tydesc};
4140
use std::unstable::intrinsics;
4241
use std::util;
@@ -180,7 +179,7 @@ impl Arena {
180179
let new_min_chunk_size = num::max(n_bytes, chunk_size);
181180
self.chunks.set(@Cons(self.pod_head.clone(), self.chunks.get()));
182181
self.pod_head =
183-
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), true);
182+
chunk(num::next_power_of_two(new_min_chunk_size + 1u), true);
184183

185184
return self.alloc_pod_inner(n_bytes, align);
186185
}
@@ -222,7 +221,7 @@ impl Arena {
222221
let new_min_chunk_size = num::max(n_bytes, chunk_size);
223222
self.chunks.set(@Cons(self.head.clone(), self.chunks.get()));
224223
self.head =
225-
chunk(uint::next_power_of_two(new_min_chunk_size + 1u), false);
224+
chunk(num::next_power_of_two(new_min_chunk_size + 1u), false);
226225

227226
return self.alloc_nonpod_inner(n_bytes, align);
228227
}

branches/dist-snap/src/libextra/ringbuf.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ impl<'a, T> Iterator<&'a mut T> for MutItems<'a, T> {
303303
&mut self.remaining2
304304
};
305305
self.nelts -= 1;
306-
Some(r.mut_shift_ref().get_mut_ref())
306+
Some(r.mut_shift_ref().unwrap().get_mut_ref())
307307
}
308308

309309
#[inline]
@@ -325,7 +325,7 @@ impl<'a, T> DoubleEndedIterator<&'a mut T> for MutItems<'a, T> {
325325
&mut self.remaining1
326326
};
327327
self.nelts -= 1;
328-
Some(r.mut_pop_ref().get_mut_ref())
328+
Some(r.mut_pop_ref().unwrap().get_mut_ref())
329329
}
330330
}
331331

branches/dist-snap/src/librustc/metadata/common.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ pub static tag_items_data_item_variant: uint = 0x0eu;
3535

3636
pub static tag_items_data_parent_item: uint = 0x0fu;
3737

38+
pub static tag_items_data_item_is_tuple_struct_ctor: uint = 0x10u;
39+
3840
pub static tag_index: uint = 0x11u;
3941

4042
pub static tag_index_buckets: uint = 0x12u;

branches/dist-snap/src/librustc/metadata/decoder.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -980,9 +980,26 @@ pub fn get_static_methods_if_impl(intr: @IdentInterner,
980980
return Some(static_impl_methods);
981981
}
982982

983+
/// If node_id is the constructor of a tuple struct, retrieve the NodeId of
984+
/// the actual type definition, otherwise, return None
985+
pub fn get_tuple_struct_definition_if_ctor(cdata: Cmd,
986+
node_id: ast::NodeId) -> Option<ast::NodeId> {
987+
let item = lookup_item(node_id, cdata.data());
988+
let mut ret = None;
989+
reader::tagged_docs(item, tag_items_data_item_is_tuple_struct_ctor, |_| {
990+
ret = Some(item_reqd_and_translated_parent_item(cdata.cnum, item));
991+
false
992+
});
993+
ret.map(|x| x.node)
994+
}
995+
983996
pub fn get_item_attrs(cdata: Cmd,
984997
node_id: ast::NodeId,
985998
f: |~[@ast::MetaItem]|) {
999+
// The attributes for a tuple struct are attached to the definition, not the ctor;
1000+
// we assume that someone passing in a tuple struct ctor is actually wanting to
1001+
// look at the definition
1002+
let node_id = get_tuple_struct_definition_if_ctor(cdata, node_id).unwrap_or(node_id);
9861003
let item = lookup_item(node_id, cdata.data());
9871004
reader::tagged_docs(item, tag_attributes, |attributes| {
9881005
reader::tagged_docs(attributes, tag_attribute, |attribute| {

branches/dist-snap/src/librustc/metadata/encoder.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,12 @@ fn encode_info_for_struct_ctor(ecx: &EncodeContext,
778778
encode_symbol(ecx, ebml_w, ctor_id);
779779
}
780780

781+
// indicate that this is a tuple struct ctor, because downstream users will normally want
782+
// the tuple struct definition, but without this there is no way for them to tell that
783+
// they actually have a ctor rather than a normal function
784+
ebml_w.start_tag(tag_items_data_item_is_tuple_struct_ctor);
785+
ebml_w.end_tag();
786+
781787
ebml_w.end_tag();
782788
}
783789

branches/dist-snap/src/librustc/middle/trans/cleanup.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
662662
// Check if a landing pad block exists; if not, create one.
663663
{
664664
let mut scopes = self.scopes.borrow_mut();
665-
let last_scope = scopes.get().mut_last();
665+
let last_scope = scopes.get().mut_last().unwrap();
666666
match last_scope.cached_landing_pad {
667667
Some(llbb) => { return llbb; }
668668
None => {

branches/dist-snap/src/libstd/at_vec.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ pub mod raw {
177177
use cast::{transmute, transmute_copy};
178178
use container::Container;
179179
use option::None;
180-
use ptr;
181180
use mem;
182-
use uint;
181+
use num::next_power_of_two;
182+
use ptr;
183183
use unstable::intrinsics::{move_val_init, TyDesc};
184184
use unstable::intrinsics;
185185
use unstable::raw::{Box, Vec};
@@ -293,7 +293,7 @@ pub mod raw {
293293
*/
294294
#[inline]
295295
pub unsafe fn reserve_at_least<T>(v: &mut @[T], n: uint) {
296-
reserve(v, uint::next_power_of_two(n));
296+
reserve(v, next_power_of_two(n));
297297
}
298298
}
299299

branches/dist-snap/src/libstd/hashmap.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ use num;
6464
use option::{None, Option, Some};
6565
use rand::Rng;
6666
use rand;
67-
use uint;
6867
use util::replace;
6968
use vec::{ImmutableVector, MutableVector, OwnedVector, Items, MutItems};
7069
use vec_ng;
@@ -388,7 +387,7 @@ impl<K: Hash + Eq, V> HashMap<K, V> {
388387
pub fn reserve_at_least(&mut self, n: uint) {
389388
if n > self.buckets.len() {
390389
let buckets = n * 4 / 3 + 1;
391-
self.resize(uint::next_power_of_two(buckets));
390+
self.resize(num::next_power_of_two(buckets));
392391
}
393392
}
394393

branches/dist-snap/src/libstd/num/int.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,10 +120,3 @@ impl CheckedMul for int {
120120
}
121121
}
122122
}
123-
124-
#[test]
125-
fn test_overflows() {
126-
assert!((::int::MAX > 0));
127-
assert!((::int::MIN <= 0));
128-
assert!((::int::MIN + ::int::MAX + 1 == 0));
129-
}

branches/dist-snap/src/libstd/num/int_macros.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,13 @@ mod tests {
445445
use num::CheckedDiv;
446446
use num::Bitwise;
447447

448+
#[test]
449+
fn test_overflows() {
450+
assert!(MAX > 0);
451+
assert!(MIN <= 0);
452+
assert_eq!(MIN + MAX + 1, 0);
453+
}
454+
448455
#[test]
449456
fn test_num() {
450457
num::test_num(10 as $T, 2 as $T);

branches/dist-snap/src/libstd/num/mod.rs

Lines changed: 75 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,39 @@ pub trait Primitive: Clone
440440
/// A collection of traits relevant to primitive signed and unsigned integers
441441
pub trait Int: Integer
442442
+ Primitive
443-
+ Bitwise {}
443+
+ Bitwise
444+
+ CheckedAdd
445+
+ CheckedSub
446+
// + CheckedMul // FIXME #8849: currently not impled on 32-bit
447+
+ CheckedDiv {}
448+
449+
/// Returns the smallest power of 2 greater than or equal to `n`.
450+
#[inline]
451+
pub fn next_power_of_two<T: Unsigned + Int>(n: T) -> T {
452+
let halfbits: T = cast(size_of::<T>() * 4).unwrap();
453+
let mut tmp: T = n - one();
454+
let mut shift: T = one();
455+
while shift <= halfbits {
456+
tmp = tmp | (tmp >> shift);
457+
shift = shift << one();
458+
}
459+
tmp + one()
460+
}
461+
462+
/// Returns the smallest power of 2 greater than or equal to `n`. If the next
463+
/// power of two is greater than the type's maximum value, `None` is returned,
464+
/// otherwise the power of 2 is wrapped in `Some`.
465+
#[inline]
466+
pub fn checked_next_power_of_two<T: Unsigned + Int>(n: T) -> Option<T> {
467+
let halfbits: T = cast(size_of::<T>() * 4).unwrap();
468+
let mut tmp: T = n - one();
469+
let mut shift: T = one();
470+
while shift <= halfbits {
471+
tmp = tmp | (tmp >> shift);
472+
shift = shift << one();
473+
}
474+
tmp.checked_add(&one())
475+
}
444476

445477
/// Used for representing the classification of floating point numbers
446478
#[deriving(Eq)]
@@ -1589,6 +1621,48 @@ mod tests {
15891621
assert_eq!(third.checked_mul(&4), None);
15901622
}
15911623

1624+
macro_rules! test_next_power_of_two(
1625+
($test_name:ident, $T:ident) => (
1626+
fn $test_name() {
1627+
#[test];
1628+
assert_eq!(next_power_of_two::<$T>(0), 0);
1629+
let mut next_power = 1;
1630+
for i in range::<$T>(1, 40) {
1631+
assert_eq!(next_power_of_two(i), next_power);
1632+
if i == next_power { next_power *= 2 }
1633+
}
1634+
}
1635+
)
1636+
)
1637+
1638+
test_next_power_of_two!(test_next_power_of_two_u8, u8)
1639+
test_next_power_of_two!(test_next_power_of_two_u16, u16)
1640+
test_next_power_of_two!(test_next_power_of_two_u32, u32)
1641+
test_next_power_of_two!(test_next_power_of_two_u64, u64)
1642+
test_next_power_of_two!(test_next_power_of_two_uint, uint)
1643+
1644+
macro_rules! test_checked_next_power_of_two(
1645+
($test_name:ident, $T:ident) => (
1646+
fn $test_name() {
1647+
#[test];
1648+
assert_eq!(checked_next_power_of_two::<$T>(0), None);
1649+
let mut next_power = 1;
1650+
for i in range::<$T>(1, 40) {
1651+
assert_eq!(checked_next_power_of_two(i), Some(next_power));
1652+
if i == next_power { next_power *= 2 }
1653+
}
1654+
assert!(checked_next_power_of_two::<$T>($T::MAX / 2).is_some());
1655+
assert_eq!(checked_next_power_of_two::<$T>($T::MAX - 1), None);
1656+
assert_eq!(checked_next_power_of_two::<$T>($T::MAX), None);
1657+
}
1658+
)
1659+
)
1660+
1661+
test_checked_next_power_of_two!(test_checked_next_power_of_two_u8, u8)
1662+
test_checked_next_power_of_two!(test_checked_next_power_of_two_u16, u16)
1663+
test_checked_next_power_of_two!(test_checked_next_power_of_two_u32, u32)
1664+
test_checked_next_power_of_two!(test_checked_next_power_of_two_u64, u64)
1665+
test_checked_next_power_of_two!(test_checked_next_power_of_two_uint, uint)
15921666

15931667
#[deriving(Eq)]
15941668
struct Value { x: int }

0 commit comments

Comments
 (0)