Skip to content

Commit 0c63e6d

Browse files
committed
---
yaml --- r: 194505 b: refs/heads/tmp c: 3902190 h: refs/heads/master i: 194503: e5eda09 v: v3
1 parent 6846b04 commit 0c63e6d

File tree

43 files changed

+387
-673
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+387
-673
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ refs/heads/building: 126db549b038c84269a1e4fe46f051b2c15d6970
3434
refs/heads/beta: a3b13610c5b93d9ada072471a001a5613df6a960
3535
refs/heads/windistfix: 7608dbad651f02e837ed05eef3d74a6662a6e928
3636
refs/tags/1.0.0-alpha: e42bd6d93a1d3433c486200587f8f9e12590a4d7
37-
refs/heads/tmp: 242ed0b7c0f6a21096f2cc3e1ad1bdb176d02545
37+
refs/heads/tmp: 3902190ac4d64962b2c1ac9a6ae88777b7112f82
3838
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3939
refs/tags/homu-tmp: 123a754cb8356d0e78837dd4e58103ad801309ff
4040
refs/heads/gate: 97c84447b65164731087ea82685580cc81424412

branches/tmp/src/liballoc/arc.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,8 @@ impl<T> Drop for Arc<T> {
354354
// more than once (but it is guaranteed to be zeroed after the first if
355355
// it's run more than once)
356356
let ptr = *self._ptr;
357-
if ptr.is_null() { return }
357+
// if ptr.is_null() { return }
358+
if ptr.is_null() || ptr as usize == mem::POST_DROP_USIZE { return }
358359

359360
// Because `fetch_sub` is already atomic, we do not need to synchronize
360361
// with other threads unless we are going to delete the object. This
@@ -485,7 +486,7 @@ impl<T> Drop for Weak<T> {
485486
let ptr = *self._ptr;
486487

487488
// see comments above for why this check is here
488-
if ptr.is_null() { return }
489+
if ptr.is_null() || ptr as usize == mem::POST_DROP_USIZE { return }
489490

490491
// If we find out that we were the last weak pointer, then its time to
491492
// deallocate the data entirely. See the discussion in Arc::drop() about

branches/tmp/src/liballoc/rc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ use core::default::Default;
160160
use core::fmt;
161161
use core::hash::{Hasher, Hash};
162162
use core::marker;
163-
use core::mem::{min_align_of, size_of, forget};
163+
use core::mem::{self, min_align_of, size_of, forget};
164164
use core::nonzero::NonZero;
165165
use core::ops::{Deref, Drop};
166166
use core::option::Option;
@@ -407,7 +407,7 @@ impl<T> Drop for Rc<T> {
407407
fn drop(&mut self) {
408408
unsafe {
409409
let ptr = *self._ptr;
410-
if !ptr.is_null() {
410+
if !ptr.is_null() && ptr as usize != mem::POST_DROP_USIZE {
411411
self.dec_strong();
412412
if self.strong() == 0 {
413413
ptr::read(&**self); // destroy the contained object
@@ -718,7 +718,7 @@ impl<T> Drop for Weak<T> {
718718
fn drop(&mut self) {
719719
unsafe {
720720
let ptr = *self._ptr;
721-
if !ptr.is_null() {
721+
if !ptr.is_null() && ptr as usize != mem::POST_DROP_USIZE {
722722
self.dec_weak();
723723
// the weak count starts at 1, and will only go to zero if all
724724
// the strong pointers have disappeared.

branches/tmp/src/libcollections/btree/map.rs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,39 +1143,15 @@ impl<'a, K, V> DoubleEndedIterator for RangeMut<'a, K, V> {
11431143
}
11441144

11451145
impl<'a, K: Ord, V> Entry<'a, K, V> {
1146+
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
11461147
#[unstable(feature = "std_misc",
11471148
reason = "will soon be replaced by or_insert")]
1148-
#[deprecated(since = "1.0",
1149-
reason = "replaced with more ergonomic `or_insert` and `or_insert_with`")]
1150-
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
11511149
pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, K, V>> {
11521150
match self {
11531151
Occupied(entry) => Ok(entry.into_mut()),
11541152
Vacant(entry) => Err(entry),
11551153
}
11561154
}
1157-
1158-
#[unstable(feature = "collections",
1159-
reason = "matches entry v3 specification, waiting for dust to settle")]
1160-
/// Ensures a value is in the entry by inserting the default if empty, and returns
1161-
/// a mutable reference to the value in the entry.
1162-
pub fn or_insert(self, default: V) -> &'a mut V {
1163-
match self {
1164-
Occupied(entry) => entry.into_mut(),
1165-
Vacant(entry) => entry.insert(default),
1166-
}
1167-
}
1168-
1169-
#[unstable(feature = "collections",
1170-
reason = "matches entry v3 specification, waiting for dust to settle")]
1171-
/// Ensures a value is in the entry by inserting the result of the default function if empty,
1172-
/// and returns a mutable reference to the value in the entry.
1173-
pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
1174-
match self {
1175-
Occupied(entry) => entry.into_mut(),
1176-
Vacant(entry) => entry.insert(default()),
1177-
}
1178-
}
11791155
}
11801156

11811157
impl<'a, K: Ord, V> VacantEntry<'a, K, V> {
@@ -1587,12 +1563,21 @@ impl<K: Ord, V> BTreeMap<K, V> {
15871563
/// ```
15881564
/// # #![feature(collections)]
15891565
/// use std::collections::BTreeMap;
1566+
/// use std::collections::btree_map::Entry;
15901567
///
15911568
/// let mut count: BTreeMap<&str, usize> = BTreeMap::new();
15921569
///
15931570
/// // count the number of occurrences of letters in the vec
1594-
/// for x in vec!["a","b","a","c","a","b"] {
1595-
/// *count.entry(x).or_insert(0) += 1;
1571+
/// for x in vec!["a","b","a","c","a","b"].iter() {
1572+
/// match count.entry(*x) {
1573+
/// Entry::Vacant(view) => {
1574+
/// view.insert(1);
1575+
/// },
1576+
/// Entry::Occupied(mut view) => {
1577+
/// let v = view.get_mut();
1578+
/// *v += 1;
1579+
/// },
1580+
/// }
15961581
/// }
15971582
///
15981583
/// assert_eq!(count["a"], 3);

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,11 @@ impl<T> Drop for RawItems<T> {
280280
#[unsafe_destructor]
281281
impl<K, V> Drop for Node<K, V> {
282282
fn drop(&mut self) {
283-
if self.keys.is_null() {
283+
if self.keys.is_null() ||
284+
(unsafe { self.keys.get() as *const K as usize == mem::POST_DROP_USIZE })
285+
{
284286
// Since we have #[unsafe_no_drop_flag], we have to watch
285-
// out for a null value being stored in self.keys. (Using
287+
// out for the sentinel value being stored in self.keys. (Using
286288
// null is technically a violation of the `Unique`
287289
// requirements, though.)
288290
return;

branches/tmp/src/libcollections/vec.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,7 @@ impl<T> Drop for Vec<T> {
16941694
fn drop(&mut self) {
16951695
// This is (and should always remain) a no-op if the fields are
16961696
// zeroed (when moving out, because of #[unsafe_no_drop_flag]).
1697-
if self.cap != 0 {
1697+
if self.cap != 0 && self.cap != mem::POST_DROP_USIZE {
16981698
unsafe {
16991699
for x in &*self {
17001700
ptr::read(x);
@@ -1977,7 +1977,7 @@ impl<'a, T> ExactSizeIterator for Drain<'a, T> {}
19771977
#[stable(feature = "rust1", since = "1.0.0")]
19781978
impl<'a, T> Drop for Drain<'a, T> {
19791979
fn drop(&mut self) {
1980-
// self.ptr == self.end == null if drop has already been called,
1980+
// self.ptr == self.end == mem::POST_DROP_USIZE if drop has already been called,
19811981
// so we can use #[unsafe_no_drop_flag].
19821982

19831983
// destroy the remaining elements

branches/tmp/src/libcollections/vec_map.rs

Lines changed: 11 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -632,12 +632,21 @@ impl<V> VecMap<V> {
632632
/// ```
633633
/// # #![feature(collections)]
634634
/// use std::collections::VecMap;
635+
/// use std::collections::vec_map::Entry;
635636
///
636637
/// let mut count: VecMap<u32> = VecMap::new();
637638
///
638639
/// // count the number of occurrences of numbers in the vec
639-
/// for x in vec![1, 2, 1, 2, 3, 4, 1, 2, 4] {
640-
/// *count.entry(x).or_insert(0) += 1;
640+
/// for x in vec![1, 2, 1, 2, 3, 4, 1, 2, 4].iter() {
641+
/// match count.entry(*x) {
642+
/// Entry::Vacant(view) => {
643+
/// view.insert(1);
644+
/// },
645+
/// Entry::Occupied(mut view) => {
646+
/// let v = view.get_mut();
647+
/// *v += 1;
648+
/// },
649+
/// }
641650
/// }
642651
///
643652
/// assert_eq!(count[1], 3);
@@ -666,37 +675,13 @@ impl<V> VecMap<V> {
666675
impl<'a, V> Entry<'a, V> {
667676
#[unstable(feature = "collections",
668677
reason = "will soon be replaced by or_insert")]
669-
#[deprecated(since = "1.0",
670-
reason = "replaced with more ergonomic `or_insert` and `or_insert_with`")]
671678
/// Returns a mutable reference to the entry if occupied, or the VacantEntry if vacant
672679
pub fn get(self) -> Result<&'a mut V, VacantEntry<'a, V>> {
673680
match self {
674681
Occupied(entry) => Ok(entry.into_mut()),
675682
Vacant(entry) => Err(entry),
676683
}
677684
}
678-
679-
#[unstable(feature = "collections",
680-
reason = "matches entry v3 specification, waiting for dust to settle")]
681-
/// Ensures a value is in the entry by inserting the default if empty, and returns
682-
/// a mutable reference to the value in the entry.
683-
pub fn or_insert(self, default: V) -> &'a mut V {
684-
match self {
685-
Occupied(entry) => entry.into_mut(),
686-
Vacant(entry) => entry.insert(default),
687-
}
688-
}
689-
690-
#[unstable(feature = "collections",
691-
reason = "matches entry v3 specification, waiting for dust to settle")]
692-
/// Ensures a value is in the entry by inserting the result of the default function if empty,
693-
/// and returns a mutable reference to the value in the entry.
694-
pub fn or_insert_with<F: FnOnce() -> V>(self, default: F) -> &'a mut V {
695-
match self {
696-
Occupied(entry) => entry.into_mut(),
697-
Vacant(entry) => entry.insert(default()),
698-
}
699-
}
700685
}
701686

702687
impl<'a, V> VacantEntry<'a, V> {

branches/tmp/src/libcore/intrinsics.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,13 +191,35 @@ extern "rust-intrinsic" {
191191
/// crate it is invoked in.
192192
pub fn type_id<T: ?Sized + 'static>() -> u64;
193193

194+
/// Create a value initialized to so that its drop flag,
195+
/// if any, says that it has been dropped.
196+
///
197+
/// `init_dropped` is unsafe because it returns a datum with all
198+
/// of its bytes set to the drop flag, which generally does not
199+
/// correspond to a valid value.
200+
///
201+
/// This intrinsic is likely to be deprecated in the future when
202+
/// Rust moves to non-zeroing dynamic drop (and thus removes the
203+
/// embedded drop flags that are being established by this
204+
/// intrinsic).
205+
#[cfg(not(stage0))]
206+
pub fn init_dropped<T>() -> T;
207+
194208
/// Create a value initialized to zero.
195209
///
196210
/// `init` is unsafe because it returns a zeroed-out datum,
197-
/// which is unsafe unless T is Copy.
211+
/// which is unsafe unless T is `Copy`. Also, even if T is
212+
/// `Copy`, an all-zero value may not correspond to any legitimate
213+
/// state for the type in question.
198214
pub fn init<T>() -> T;
199215

200216
/// Create an uninitialized value.
217+
///
218+
/// `uninit` is unsafe because there is no guarantee of what its
219+
/// contents are. In particular its drop-flag may be set to any
220+
/// state, which means it may claim either dropped or
221+
/// undropped. In the general case one must use `ptr::write` to
222+
/// initialize memory previous set to the result of `uninit`.
201223
pub fn uninit<T>() -> T;
202224

203225
/// Move a value out of scope without running drop glue.

branches/tmp/src/libcore/mem.rs

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,29 @@ pub unsafe fn zeroed<T>() -> T {
158158
intrinsics::init()
159159
}
160160

161+
/// Create a value initialized to an unspecified series of bytes.
162+
///
163+
/// The byte sequence usually indicates that the value at the memory
164+
/// in question has been dropped. Thus, *if* T carries a drop flag,
165+
/// any associated destructor will not be run when the value falls out
166+
/// of scope.
167+
///
168+
/// Some code at one time used the `zeroed` function above to
169+
/// accomplish this goal.
170+
///
171+
/// This function is expected to be deprecated with the transition
172+
/// to non-zeroing drop.
173+
#[inline]
174+
#[unstable(feature = "filling_drop")]
175+
pub unsafe fn dropped<T>() -> T {
176+
let mut x: T = uninitialized();
177+
let p: *mut u8 = transmute(&mut x as *mut T);
178+
for i in 0..size_of::<T>() {
179+
*p.offset(i as isize) = POST_DROP_U8;
180+
}
181+
x
182+
}
183+
161184
/// Create an uninitialized value.
162185
///
163186
/// Care must be taken when using this function, if the type `T` has a destructor and the value
@@ -291,6 +314,40 @@ pub fn replace<T>(dest: &mut T, mut src: T) -> T {
291314
#[stable(feature = "rust1", since = "1.0.0")]
292315
pub fn drop<T>(_x: T) { }
293316

317+
macro_rules! repeat_u8_as_u32 {
318+
($name:expr) => { (($name as u32) << 24 |
319+
($name as u32) << 16 |
320+
($name as u32) << 8 |
321+
($name as u32)) }
322+
}
323+
macro_rules! repeat_u8_as_u64 {
324+
($name:expr) => { ((repeat_u8_as_u32!($name) as u64) << 32 |
325+
(repeat_u8_as_u32!($name) as u64)) }
326+
}
327+
328+
// NOTE: Keep synchronized with values used in librustc_trans::trans::adt.
329+
//
330+
// In particular, the POST_DROP_U8 marker must never equal the
331+
// DTOR_NEEDED_U8 marker.
332+
//
333+
// For a while pnkfelix was using 0xc1 here.
334+
// But having the sign bit set is a pain, so 0x1d is probably better.
335+
//
336+
// And of course, 0x00 brings back the old world of zero'ing on drop.
337+
#[cfg(not(stage0))] pub const POST_DROP_U8: u8 = 0x0;
338+
#[cfg(not(stage0))] pub const POST_DROP_U32: u32 = repeat_u8_as_u32!(POST_DROP_U8);
339+
#[cfg(not(stage0))] pub const POST_DROP_U64: u64 = repeat_u8_as_u64!(POST_DROP_U8);
340+
341+
#[cfg(target_pointer_width = "32")]
342+
#[cfg(not(stage0))] pub const POST_DROP_USIZE: usize = POST_DROP_U32 as usize;
343+
#[cfg(target_pointer_width = "64")]
344+
#[cfg(not(stage0))] pub const POST_DROP_USIZE: usize = POST_DROP_U64 as usize;
345+
346+
#[cfg(stage0)] pub const POST_DROP_U8: u8 = 0;
347+
#[cfg(stage0)] pub const POST_DROP_U32: u32 = 0;
348+
#[cfg(stage0)] pub const POST_DROP_U64: u64 = 0;
349+
#[cfg(stage0)] pub const POST_DROP_USIZE: usize = 0;
350+
294351
/// Interprets `src` as `&U`, and then reads `src` without moving the contained value.
295352
///
296353
/// This function will unsafely assume the pointer `src` is valid for `sizeof(U)` bytes by

branches/tmp/src/libcore/ptr.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,21 @@ pub unsafe fn read_and_zero<T>(dest: *mut T) -> T {
230230
tmp
231231
}
232232

233+
/// Variant of read_and_zero that writes the specific drop-flag byte
234+
/// (which may be more apropriate than zero).
235+
#[inline(always)]
236+
#[unstable(feature = "core",
237+
reason = "may play a larger role in std::ptr future extensions")]
238+
pub unsafe fn read_and_drop<T>(dest: *mut T) -> T {
239+
// Copy the data out from `dest`:
240+
let tmp = read(&*dest);
241+
242+
// Now mark `dest` as dropped:
243+
write_bytes(dest, mem::POST_DROP_U8, 1);
244+
245+
tmp
246+
}
247+
233248
/// Overwrites a memory location with the given value without reading or
234249
/// dropping the old value.
235250
///

branches/tmp/src/librustc/metadata/loader.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ impl<'a> Context<'a> {
426426
info!("lib candidate: {}", path.display());
427427

428428
let hash_str = hash.to_string();
429-
let slot = candidates.entry(hash_str)
430-
.or_insert_with(|| (HashMap::new(), HashMap::new()));
429+
let slot = candidates.entry(hash_str).get().unwrap_or_else(
430+
|vacant_entry| vacant_entry.insert((HashMap::new(), HashMap::new())));
431431
let (ref mut rlibs, ref mut dylibs) = *slot;
432432
if rlib {
433433
rlibs.insert(fs::realpath(path).unwrap(), kind);

branches/tmp/src/librustc/middle/dataflow.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,12 @@ fn build_nodeid_to_index(decl: Option<&ast::FnDecl>,
160160

161161
cfg.graph.each_node(|node_idx, node| {
162162
if let cfg::CFGNodeData::AST(id) = node.data {
163-
index.entry(id).or_insert(vec![]).push(node_idx);
163+
match index.entry(id).get() {
164+
Ok(v) => v.push(node_idx),
165+
Err(e) => {
166+
e.insert(vec![node_idx]);
167+
}
168+
}
164169
}
165170
true
166171
});
@@ -180,7 +185,12 @@ fn build_nodeid_to_index(decl: Option<&ast::FnDecl>,
180185
visit::walk_fn_decl(&mut formals, decl);
181186
impl<'a, 'v> visit::Visitor<'v> for Formals<'a> {
182187
fn visit_pat(&mut self, p: &ast::Pat) {
183-
self.index.entry(p.id).or_insert(vec![]).push(self.entry);
188+
match self.index.entry(p.id).get() {
189+
Ok(v) => v.push(self.entry),
190+
Err(e) => {
191+
e.insert(vec![self.entry]);
192+
}
193+
}
184194
visit::walk_pat(self, p)
185195
}
186196
}

0 commit comments

Comments
 (0)