Skip to content

Commit 1723c18

Browse files
committed
---
yaml --- r: 218295 b: refs/heads/beta c: 2be6107 h: refs/heads/master i: 218293: b99fa2e 218291: fec7bb3 218287: 6ec088f v: v3
1 parent 95f81ee commit 1723c18

File tree

16 files changed

+146
-87
lines changed

16 files changed

+146
-87
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ refs/tags/0.9: 36870b185fc5f5486636d4515f0e22677493f225
2323
refs/tags/0.10: ac33f2b15782272ae348dbd7b14b8257b2148b5a
2424
refs/tags/0.11.0: e1247cb1d0d681be034adb4b558b5a0c0d5720f9
2525
refs/tags/0.12.0: f0c419429ef30723ceaf6b42f9b5a2aeb5d2e2d1
26-
refs/heads/beta: 18adf6230e2e229d4d73391cebff060afc5e5aaa
26+
refs/heads/beta: 2be61079f119f53663c079a0d1b131e6bec4ea03
2727
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
2828
refs/heads/tmp: 50df2a09b8b9dd4883eb27d833a8482799175a3b
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f

branches/beta/src/liballoc/arc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ use core::atomic;
7777
use core::atomic::Ordering::{Relaxed, Release, Acquire, SeqCst};
7878
use core::fmt;
7979
use core::cmp::Ordering;
80-
use core::mem::{align_of_val, size_of_val};
80+
use core::mem::{min_align_of_val, size_of_val};
8181
use core::intrinsics::drop_in_place;
8282
use core::mem;
8383
use core::nonzero::NonZero;
@@ -241,7 +241,7 @@ impl<T: ?Sized> Arc<T> {
241241

242242
if self.inner().weak.fetch_sub(1, Release) == 1 {
243243
atomic::fence(Acquire);
244-
deallocate(ptr as *mut u8, size_of_val(&*ptr), align_of_val(&*ptr))
244+
deallocate(ptr as *mut u8, size_of_val(&*ptr), min_align_of_val(&*ptr))
245245
}
246246
}
247247
}
@@ -565,7 +565,7 @@ impl<T: ?Sized> Drop for Weak<T> {
565565
atomic::fence(Acquire);
566566
unsafe { deallocate(ptr as *mut u8,
567567
size_of_val(&*ptr),
568-
align_of_val(&*ptr)) }
568+
min_align_of_val(&*ptr)) }
569569
}
570570
}
571571
}

branches/beta/src/liballoc/rc.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ use core::fmt;
162162
use core::hash::{Hasher, Hash};
163163
use core::intrinsics::{assume, drop_in_place};
164164
use core::marker::{self, Unsize};
165-
use core::mem::{self, align_of, size_of, align_of_val, size_of_val, forget};
165+
use core::mem::{self, min_align_of, size_of, min_align_of_val, size_of_val, forget};
166166
use core::nonzero::NonZero;
167167
use core::ops::{CoerceUnsized, Deref};
168168
use core::ptr;
@@ -246,7 +246,7 @@ impl<T> Rc<T> {
246246
// destruct the box and skip our Drop
247247
// we can ignore the refcounts because we know we're unique
248248
deallocate(*rc._ptr as *mut u8, size_of::<RcBox<T>>(),
249-
align_of::<RcBox<T>>());
249+
min_align_of::<RcBox<T>>());
250250
forget(rc);
251251
Ok(val)
252252
}
@@ -496,7 +496,7 @@ impl<T: ?Sized> Drop for Rc<T> {
496496
if self.weak() == 0 {
497497
deallocate(ptr as *mut u8,
498498
size_of_val(&*ptr),
499-
align_of_val(&*ptr))
499+
min_align_of_val(&*ptr))
500500
}
501501
}
502502
}
@@ -805,7 +805,7 @@ impl<T: ?Sized> Drop for Weak<T> {
805805
// the strong pointers have disappeared.
806806
if self.weak() == 0 {
807807
deallocate(ptr as *mut u8, size_of_val(&*ptr),
808-
align_of_val(&*ptr))
808+
min_align_of_val(&*ptr))
809809
}
810810
}
811811
}

branches/beta/src/libarena/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ impl<'longer_than_self> Arena<'longer_than_self> {
244244
fn alloc_copy<T, F>(&self, op: F) -> &mut T where F: FnOnce() -> T {
245245
unsafe {
246246
let ptr = self.alloc_copy_inner(mem::size_of::<T>(),
247-
mem::align_of::<T>());
247+
mem::min_align_of::<T>());
248248
let ptr = ptr as *mut T;
249249
ptr::write(&mut (*ptr), op());
250250
return &mut *ptr;
@@ -300,7 +300,7 @@ impl<'longer_than_self> Arena<'longer_than_self> {
300300
let tydesc = get_tydesc::<T>();
301301
let (ty_ptr, ptr) =
302302
self.alloc_noncopy_inner(mem::size_of::<T>(),
303-
mem::align_of::<T>());
303+
mem::min_align_of::<T>());
304304
let ty_ptr = ty_ptr as *mut usize;
305305
let ptr = ptr as *mut T;
306306
// Write in our tydesc along with a bit indicating that it
@@ -393,7 +393,7 @@ struct TypedArenaChunk<T> {
393393

394394
fn calculate_size<T>(capacity: usize) -> usize {
395395
let mut size = mem::size_of::<TypedArenaChunk<T>>();
396-
size = round_up(size, mem::align_of::<T>());
396+
size = round_up(size, mem::min_align_of::<T>());
397397
let elem_size = mem::size_of::<T>();
398398
let elems_size = elem_size.checked_mul(capacity).unwrap();
399399
size = size.checked_add(elems_size).unwrap();
@@ -405,7 +405,7 @@ impl<T> TypedArenaChunk<T> {
405405
unsafe fn new(next: *mut TypedArenaChunk<T>, capacity: usize)
406406
-> *mut TypedArenaChunk<T> {
407407
let size = calculate_size::<T>(capacity);
408-
let chunk = allocate(size, mem::align_of::<TypedArenaChunk<T>>())
408+
let chunk = allocate(size, mem::min_align_of::<TypedArenaChunk<T>>())
409409
as *mut TypedArenaChunk<T>;
410410
if chunk.is_null() { alloc::oom() }
411411
(*chunk).next = next;
@@ -431,7 +431,7 @@ impl<T> TypedArenaChunk<T> {
431431
let size = calculate_size::<T>(self.capacity);
432432
let self_ptr: *mut TypedArenaChunk<T> = self;
433433
deallocate(self_ptr as *mut u8, size,
434-
mem::align_of::<TypedArenaChunk<T>>());
434+
mem::min_align_of::<TypedArenaChunk<T>>());
435435
if !next.is_null() {
436436
let capacity = (*next).capacity;
437437
(*next).destroy(capacity);
@@ -444,7 +444,7 @@ impl<T> TypedArenaChunk<T> {
444444
let this: *const TypedArenaChunk<T> = self;
445445
unsafe {
446446
mem::transmute(round_up(this.offset(1) as usize,
447-
mem::align_of::<T>()))
447+
mem::min_align_of::<T>()))
448448
}
449449
}
450450

branches/beta/src/libcollections/btree/node.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,12 +163,12 @@ fn test_offset_calculation() {
163163
}
164164

165165
fn calculate_allocation_generic<K, V>(capacity: usize, is_leaf: bool) -> (usize, usize) {
166-
let (keys_size, keys_align) = (capacity * mem::size_of::<K>(), mem::align_of::<K>());
167-
let (vals_size, vals_align) = (capacity * mem::size_of::<V>(), mem::align_of::<V>());
166+
let (keys_size, keys_align) = (capacity * mem::size_of::<K>(), mem::min_align_of::<K>());
167+
let (vals_size, vals_align) = (capacity * mem::size_of::<V>(), mem::min_align_of::<V>());
168168
let (edges_size, edges_align) = if is_leaf {
169169
(0, 1)
170170
} else {
171-
((capacity + 1) * mem::size_of::<Node<K, V>>(), mem::align_of::<Node<K, V>>())
171+
((capacity + 1) * mem::size_of::<Node<K, V>>(), mem::min_align_of::<Node<K, V>>())
172172
};
173173

174174
calculate_allocation(
@@ -181,11 +181,11 @@ fn calculate_allocation_generic<K, V>(capacity: usize, is_leaf: bool) -> (usize,
181181
fn calculate_offsets_generic<K, V>(capacity: usize, is_leaf: bool) -> (usize, usize) {
182182
let keys_size = capacity * mem::size_of::<K>();
183183
let vals_size = capacity * mem::size_of::<V>();
184-
let vals_align = mem::align_of::<V>();
184+
let vals_align = mem::min_align_of::<V>();
185185
let edges_align = if is_leaf {
186186
1
187187
} else {
188-
mem::align_of::<Node<K, V>>()
188+
mem::min_align_of::<Node<K, V>>()
189189
};
190190

191191
calculate_offsets(

branches/beta/src/libcollections/vec.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<T> Vec<T> {
219219
} else {
220220
let size = capacity.checked_mul(mem::size_of::<T>())
221221
.expect("capacity overflow");
222-
let ptr = unsafe { allocate(size, mem::align_of::<T>()) };
222+
let ptr = unsafe { allocate(size, mem::min_align_of::<T>()) };
223223
if ptr.is_null() { ::alloc::oom() }
224224
unsafe { Vec::from_raw_parts(ptr as *mut T, 0, capacity) }
225225
}
@@ -393,7 +393,7 @@ impl<T> Vec<T> {
393393
let ptr = reallocate(*self.ptr as *mut u8,
394394
self.cap * mem::size_of::<T>(),
395395
self.len * mem::size_of::<T>(),
396-
mem::align_of::<T>()) as *mut T;
396+
mem::min_align_of::<T>()) as *mut T;
397397
if ptr.is_null() { ::alloc::oom() }
398398
self.ptr = Unique::new(ptr);
399399
}
@@ -866,9 +866,9 @@ impl<T> Vec<T> {
866866
// FIXME: Assert statically that the types `T` and `U` have the
867867
// same minimal alignment in case they are not zero-sized.
868868

869-
// These asserts are necessary because the `align_of` of the
869+
// These asserts are necessary because the `min_align_of` of the
870870
// types are passed to the allocator by `Vec`.
871-
assert!(mem::align_of::<T>() == mem::align_of::<U>());
871+
assert!(mem::min_align_of::<T>() == mem::min_align_of::<U>());
872872

873873
// This `as isize` cast is safe, because the size of the elements of the
874874
// vector is not 0, and:
@@ -1269,9 +1269,9 @@ impl<T> Vec<T> {
12691269
#[inline(never)]
12701270
unsafe fn alloc_or_realloc<T>(ptr: *mut T, old_size: usize, size: usize) -> *mut T {
12711271
if old_size == 0 {
1272-
allocate(size, mem::align_of::<T>()) as *mut T
1272+
allocate(size, mem::min_align_of::<T>()) as *mut T
12731273
} else {
1274-
reallocate(ptr as *mut u8, old_size, size, mem::align_of::<T>()) as *mut T
1274+
reallocate(ptr as *mut u8, old_size, size, mem::min_align_of::<T>()) as *mut T
12751275
}
12761276
}
12771277

@@ -1280,7 +1280,7 @@ unsafe fn dealloc<T>(ptr: *mut T, len: usize) {
12801280
if mem::size_of::<T>() != 0 {
12811281
deallocate(ptr as *mut u8,
12821282
len * mem::size_of::<T>(),
1283-
mem::align_of::<T>())
1283+
mem::min_align_of::<T>())
12841284
}
12851285
}
12861286

@@ -1482,7 +1482,7 @@ impl<T> FromIterator<T> for Vec<T> {
14821482
None => return Vec::new(),
14831483
Some(element) => {
14841484
let (lower, _) = iterator.size_hint();
1485-
let mut vector = Vec::with_capacity(lower.saturating_add(1));
1485+
let mut vector = Vec::with_capacity(1 + lower);
14861486
unsafe {
14871487
ptr::write(vector.get_unchecked_mut(0), element);
14881488
vector.set_len(1);
@@ -1570,11 +1570,10 @@ impl<T> Vec<T> {
15701570
let len = self.len();
15711571
if len == self.capacity() {
15721572
let (lower, _) = iterator.size_hint();
1573-
self.reserve(lower.saturating_add(1));
1573+
self.reserve(lower + 1);
15741574
}
15751575
unsafe {
15761576
ptr::write(self.get_unchecked_mut(len), element);
1577-
// NB can't overflow since we would have had to alloc the address space
15781577
self.set_len(len + 1);
15791578
}
15801579
}

branches/beta/src/libcollections/vec_deque.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<T> Drop for VecDeque<T> {
6767
if mem::size_of::<T>() != 0 {
6868
heap::deallocate(*self.ptr as *mut u8,
6969
self.cap * mem::size_of::<T>(),
70-
mem::align_of::<T>())
70+
mem::min_align_of::<T>())
7171
}
7272
}
7373
}
@@ -172,7 +172,7 @@ impl<T> VecDeque<T> {
172172

173173
let ptr = unsafe {
174174
if mem::size_of::<T>() != 0 {
175-
let ptr = heap::allocate(size, mem::align_of::<T>()) as *mut T;;
175+
let ptr = heap::allocate(size, mem::min_align_of::<T>()) as *mut T;;
176176
if ptr.is_null() { ::alloc::oom() }
177177
Unique::new(ptr)
178178
} else {
@@ -340,7 +340,7 @@ impl<T> VecDeque<T> {
340340
let ptr = heap::reallocate(*self.ptr as *mut u8,
341341
old,
342342
new,
343-
mem::align_of::<T>()) as *mut T;
343+
mem::min_align_of::<T>()) as *mut T;
344344
if ptr.is_null() { ::alloc::oom() }
345345
self.ptr = Unique::new(ptr);
346346
}
@@ -460,7 +460,7 @@ impl<T> VecDeque<T> {
460460
let ptr = heap::reallocate(*self.ptr as *mut u8,
461461
old,
462462
new_size,
463-
mem::align_of::<T>()) as *mut T;
463+
mem::min_align_of::<T>()) as *mut T;
464464
if ptr.is_null() { ::alloc::oom() }
465465
self.ptr = Unique::new(ptr);
466466
}

branches/beta/src/libcore/mem.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ pub fn size_of_val<T: ?Sized>(val: &T) -> usize {
155155
/// ```
156156
#[inline]
157157
#[stable(feature = "rust1", since = "1.0.0")]
158-
#[deprecated(reason = "use `align_of` instead", since = "1.2.0")]
159158
pub fn min_align_of<T>() -> usize {
160159
unsafe { intrinsics::min_align_of::<T>() }
161160
}
@@ -171,14 +170,14 @@ pub fn min_align_of<T>() -> usize {
171170
/// ```
172171
#[inline]
173172
#[stable(feature = "rust1", since = "1.0.0")]
174-
#[deprecated(reason = "use `align_of_val` instead", since = "1.2.0")]
175173
pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
176174
unsafe { intrinsics::min_align_of_val(val) }
177175
}
178176

179177
/// Returns the alignment in memory for a type.
180178
///
181-
/// This is the alignment used for struct fields. It may be smaller than the preferred alignment.
179+
/// This function will return the alignment, in bytes, of a type in memory. If the alignment
180+
/// returned is adhered to, then the type is guaranteed to function properly.
182181
///
183182
/// # Examples
184183
///
@@ -190,10 +189,17 @@ pub fn min_align_of_val<T: ?Sized>(val: &T) -> usize {
190189
#[inline]
191190
#[stable(feature = "rust1", since = "1.0.0")]
192191
pub fn align_of<T>() -> usize {
193-
unsafe { intrinsics::min_align_of::<T>() }
192+
// We use the preferred alignment as the default alignment for a type. This
193+
// appears to be what clang migrated towards as well:
194+
//
195+
// http://lists.cs.uiuc.edu/pipermail/cfe-commits/Week-of-Mon-20110725/044411.html
196+
unsafe { intrinsics::pref_align_of::<T>() }
194197
}
195198

196-
/// Returns the ABI-required minimum alignment of the type of the value that `val` points to
199+
/// Returns the alignment of the type of the value that `_val` points to.
200+
///
201+
/// This is similar to `align_of`, but function will properly handle types such as trait objects
202+
/// (in the future), returning the alignment for an arbitrary value at runtime.
197203
///
198204
/// # Examples
199205
///
@@ -204,8 +210,8 @@ pub fn align_of<T>() -> usize {
204210
/// ```
205211
#[inline]
206212
#[stable(feature = "rust1", since = "1.0.0")]
207-
pub fn align_of_val<T: ?Sized>(val: &T) -> usize {
208-
unsafe { intrinsics::min_align_of_val(val) }
213+
pub fn align_of_val<T>(_val: &T) -> usize {
214+
align_of::<T>()
209215
}
210216

211217
/// Creates a value initialized to zero.

branches/beta/src/librustc/metadata/tydecode.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -843,15 +843,15 @@ fn parse_type_param_def_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F)
843843

844844
fn parse_object_lifetime_default<'a,'tcx, F>(st: &mut PState<'a,'tcx>,
845845
conv: &mut F)
846-
-> Option<ty::ObjectLifetimeDefault>
846+
-> ty::ObjectLifetimeDefault
847847
where F: FnMut(DefIdSource, ast::DefId) -> ast::DefId,
848848
{
849849
match next(st) {
850-
'n' => None,
851-
'a' => Some(ty::ObjectLifetimeDefault::Ambiguous),
850+
'a' => ty::ObjectLifetimeDefault::Ambiguous,
851+
'b' => ty::ObjectLifetimeDefault::BaseDefault,
852852
's' => {
853853
let region = parse_region_(st, conv);
854-
Some(ty::ObjectLifetimeDefault::Specific(region))
854+
ty::ObjectLifetimeDefault::Specific(region)
855855
}
856856
_ => panic!("parse_object_lifetime_default: bad input")
857857
}

branches/beta/src/librustc/metadata/tyencode.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,12 +414,12 @@ pub fn enc_type_param_def<'a, 'tcx>(w: &mut Encoder, cx: &ctxt<'a, 'tcx>,
414414

415415
fn enc_object_lifetime_default<'a, 'tcx>(w: &mut Encoder,
416416
cx: &ctxt<'a, 'tcx>,
417-
default: Option<ty::ObjectLifetimeDefault>)
417+
default: ty::ObjectLifetimeDefault)
418418
{
419419
match default {
420-
None => mywrite!(w, "n"),
421-
Some(ty::ObjectLifetimeDefault::Ambiguous) => mywrite!(w, "a"),
422-
Some(ty::ObjectLifetimeDefault::Specific(r)) => {
420+
ty::ObjectLifetimeDefault::Ambiguous => mywrite!(w, "a"),
421+
ty::ObjectLifetimeDefault::BaseDefault => mywrite!(w, "b"),
422+
ty::ObjectLifetimeDefault::Specific(r) => {
423423
mywrite!(w, "s");
424424
enc_region(w, cx, r);
425425
}

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2051,6 +2051,9 @@ pub enum ObjectLifetimeDefault {
20512051
/// `T:'a` constraints are found.
20522052
Ambiguous,
20532053

2054+
/// Use the base default, typically 'static, but in a fn body it is a fresh variable
2055+
BaseDefault,
2056+
20542057
/// Use the given region as the default.
20552058
Specific(Region),
20562059
}
@@ -2062,7 +2065,7 @@ pub struct TypeParameterDef<'tcx> {
20622065
pub space: subst::ParamSpace,
20632066
pub index: u32,
20642067
pub default: Option<Ty<'tcx>>,
2065-
pub object_lifetime_default: Option<ObjectLifetimeDefault>,
2068+
pub object_lifetime_default: ObjectLifetimeDefault,
20662069
}
20672070

20682071
#[derive(RustcEncodable, RustcDecodable, Clone, Debug)]
@@ -7764,6 +7767,7 @@ impl<'tcx> fmt::Debug for ObjectLifetimeDefault {
77647767
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
77657768
match *self {
77667769
ObjectLifetimeDefault::Ambiguous => write!(f, "Ambiguous"),
7770+
ObjectLifetimeDefault::BaseDefault => format!("BaseDefault"),
77677771
ObjectLifetimeDefault::Specific(ref r) => write!(f, "{:?}", r),
77687772
}
77697773
}

branches/beta/src/librustc/middle/ty_fold.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,9 @@ impl<'tcx> TypeFoldable<'tcx> for ty::ObjectLifetimeDefault {
369369
ty::ObjectLifetimeDefault::Ambiguous =>
370370
ty::ObjectLifetimeDefault::Ambiguous,
371371

372+
ty::ObjectLifetimeDefault::BaseDefault =>
373+
ty::ObjectLifetimeDefault::BaseDefault,
374+
372375
ty::ObjectLifetimeDefault::Specific(r) =>
373376
ty::ObjectLifetimeDefault::Specific(r.fold_with(folder)),
374377
}

0 commit comments

Comments
 (0)