Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all unstable placement features #48333

Merged
merged 1 commit into from
Apr 4, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/grammar/parser-lalr.y
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,6 @@ nonblock_expr
| BREAK lifetime { $$ = mk_node("ExprBreak", 1, $2); }
| YIELD { $$ = mk_node("ExprYield", 0); }
| YIELD expr { $$ = mk_node("ExprYield", 1, $2); }
| nonblock_expr LARROW expr { $$ = mk_node("ExprInPlace", 2, $1, $3); }
| nonblock_expr '=' expr { $$ = mk_node("ExprAssign", 2, $1, $3); }
| nonblock_expr SHLEQ expr { $$ = mk_node("ExprAssignShl", 2, $1, $3); }
| nonblock_expr SHREQ expr { $$ = mk_node("ExprAssignShr", 2, $1, $3); }
Expand Down Expand Up @@ -1463,7 +1462,6 @@ expr
| BREAK ident { $$ = mk_node("ExprBreak", 1, $2); }
| YIELD { $$ = mk_node("ExprYield", 0); }
| YIELD expr { $$ = mk_node("ExprYield", 1, $2); }
| expr LARROW expr { $$ = mk_node("ExprInPlace", 2, $1, $3); }
| expr '=' expr { $$ = mk_node("ExprAssign", 2, $1, $3); }
| expr SHLEQ expr { $$ = mk_node("ExprAssignShl", 2, $1, $3); }
| expr SHREQ expr { $$ = mk_node("ExprAssignShr", 2, $1, $3); }
Expand Down Expand Up @@ -1527,7 +1525,6 @@ expr_nostruct
| BREAK ident { $$ = mk_node("ExprBreak", 1, $2); }
| YIELD { $$ = mk_node("ExprYield", 0); }
| YIELD expr { $$ = mk_node("ExprYield", 1, $2); }
| expr_nostruct LARROW expr_nostruct { $$ = mk_node("ExprInPlace", 2, $1, $3); }
| expr_nostruct '=' expr_nostruct { $$ = mk_node("ExprAssign", 2, $1, $3); }
| expr_nostruct SHLEQ expr_nostruct { $$ = mk_node("ExprAssignShl", 2, $1, $3); }
| expr_nostruct SHREQ expr_nostruct { $$ = mk_node("ExprAssignShr", 2, $1, $3); }
Expand Down
66 changes: 1 addition & 65 deletions src/liballoc/binary_heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@
#![allow(missing_docs)]
#![stable(feature = "rust1", since = "1.0.0")]

use core::ops::{Deref, DerefMut, Place, Placer, InPlace};
use core::ops::{Deref, DerefMut};
use core::iter::{FromIterator, FusedIterator};
use core::mem::{swap, size_of};
use core::ptr;
Expand Down Expand Up @@ -1195,67 +1195,3 @@ impl<'a, T: 'a + Ord + Copy> Extend<&'a T> for BinaryHeap<T> {
self.extend(iter.into_iter().cloned());
}
}

#[unstable(feature = "collection_placement",
reason = "placement protocol is subject to change",
issue = "30172")]
pub struct BinaryHeapPlace<'a, T: 'a>
where T: Clone + Ord {
heap: *mut BinaryHeap<T>,
place: vec::PlaceBack<'a, T>,
}

#[unstable(feature = "collection_placement",
reason = "placement protocol is subject to change",
issue = "30172")]
impl<'a, T: Clone + Ord + fmt::Debug> fmt::Debug for BinaryHeapPlace<'a, T> {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
f.debug_tuple("BinaryHeapPlace")
.field(&self.place)
.finish()
}
}

#[unstable(feature = "collection_placement",
reason = "placement protocol is subject to change",
issue = "30172")]
impl<'a, T: 'a> Placer<T> for &'a mut BinaryHeap<T>
where T: Clone + Ord {
type Place = BinaryHeapPlace<'a, T>;

fn make_place(self) -> Self::Place {
let ptr = self as *mut BinaryHeap<T>;
let place = Placer::make_place(self.data.place_back());
BinaryHeapPlace {
heap: ptr,
place,
}
}
}

#[unstable(feature = "collection_placement",
reason = "placement protocol is subject to change",
issue = "30172")]
unsafe impl<'a, T> Place<T> for BinaryHeapPlace<'a, T>
where T: Clone + Ord {
fn pointer(&mut self) -> *mut T {
self.place.pointer()
}
}

#[unstable(feature = "collection_placement",
reason = "placement protocol is subject to change",
issue = "30172")]
impl<'a, T> InPlace<T> for BinaryHeapPlace<'a, T>
where T: Clone + Ord {
type Owner = &'a T;

unsafe fn finalize(self) -> &'a T {
self.place.finalize();

let heap: &mut BinaryHeap<T> = &mut *self.heap;
let len = heap.len();
let i = heap.sift_up(0, len - 1);
heap.data.get_unchecked(i)
}
}
151 changes: 1 addition & 150 deletions src/liballoc/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,55 +55,21 @@

#![stable(feature = "rust1", since = "1.0.0")]

use heap::Heap;
use raw_vec::RawVec;

use core::any::Any;
use core::borrow;
use core::cmp::Ordering;
use core::fmt;
use core::hash::{Hash, Hasher};
use core::heap::{Alloc, Layout};
use core::iter::FusedIterator;
use core::marker::{self, Unpin, Unsize};
use core::marker::{Unpin, Unsize};
use core::mem::{self, Pin};
use core::ops::{CoerceUnsized, Deref, DerefMut, Generator, GeneratorState};
use core::ops::{BoxPlace, Boxed, InPlace, Place, Placer};
use core::ptr::{self, NonNull, Unique};
use core::convert::From;
use str::from_boxed_utf8_unchecked;

/// A value that represents the heap. This is the default place that the `box`
/// keyword allocates into when no place is supplied.
///
/// The following two examples are equivalent:
///
/// ```
/// #![feature(box_heap)]
///
/// #![feature(box_syntax, placement_in_syntax)]
/// use std::boxed::HEAP;
///
/// fn main() {
/// let foo: Box<i32> = in HEAP { 5 };
/// let foo = box 5;
/// }
/// ```
#[unstable(feature = "box_heap",
reason = "may be renamed; uncertain about custom allocator design",
issue = "27779")]
pub const HEAP: ExchangeHeapSingleton = ExchangeHeapSingleton { _force_singleton: () };

/// This the singleton type used solely for `boxed::HEAP`.
#[unstable(feature = "box_heap",
reason = "may be renamed; uncertain about custom allocator design",
issue = "27779")]
#[allow(missing_debug_implementations)]
#[derive(Copy, Clone)]
pub struct ExchangeHeapSingleton {
_force_singleton: (),
}

/// A pointer type for heap allocation.
///
/// See the [module-level documentation](../../std/boxed/index.html) for more.
Expand All @@ -112,121 +78,6 @@ pub struct ExchangeHeapSingleton {
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Box<T: ?Sized>(Unique<T>);

/// `IntermediateBox` represents uninitialized backing storage for `Box`.
///
/// FIXME (pnkfelix): Ideally we would just reuse `Box<T>` instead of
/// introducing a separate `IntermediateBox<T>`; but then you hit
/// issues when you e.g. attempt to destructure an instance of `Box`,
/// since it is a lang item and so it gets special handling by the
/// compiler. Easier just to make this parallel type for now.
///
/// FIXME (pnkfelix): Currently the `box` protocol only supports
/// creating instances of sized types. This IntermediateBox is
/// designed to be forward-compatible with a future protocol that
/// supports creating instances of unsized types; that is why the type
/// parameter has the `?Sized` generalization marker, and is also why
/// this carries an explicit size. However, it probably does not need
/// to carry the explicit alignment; that is just a work-around for
/// the fact that the `align_of` intrinsic currently requires the
/// input type to be Sized (which I do not think is strictly
/// necessary).
#[unstable(feature = "placement_in",
reason = "placement box design is still being worked out.",
issue = "27779")]
#[allow(missing_debug_implementations)]
pub struct IntermediateBox<T: ?Sized> {
ptr: *mut u8,
layout: Layout,
marker: marker::PhantomData<*mut T>,
}

#[unstable(feature = "placement_in",
reason = "placement box design is still being worked out.",
issue = "27779")]
unsafe impl<T> Place<T> for IntermediateBox<T> {
fn pointer(&mut self) -> *mut T {
self.ptr as *mut T
}
}

unsafe fn finalize<T>(b: IntermediateBox<T>) -> Box<T> {
let p = b.ptr as *mut T;
mem::forget(b);
Box::from_raw(p)
}

fn make_place<T>() -> IntermediateBox<T> {
let layout = Layout::new::<T>();

let p = if layout.size() == 0 {
mem::align_of::<T>() as *mut u8
} else {
unsafe {
Heap.alloc(layout.clone()).unwrap_or_else(|err| {
Heap.oom(err)
})
}
};

IntermediateBox {
ptr: p,
layout,
marker: marker::PhantomData,
}
}

#[unstable(feature = "placement_in",
reason = "placement box design is still being worked out.",
issue = "27779")]
impl<T> BoxPlace<T> for IntermediateBox<T> {
fn make_place() -> IntermediateBox<T> {
make_place()
}
}

#[unstable(feature = "placement_in",
reason = "placement box design is still being worked out.",
issue = "27779")]
impl<T> InPlace<T> for IntermediateBox<T> {
type Owner = Box<T>;
unsafe fn finalize(self) -> Box<T> {
finalize(self)
}
}

#[unstable(feature = "placement_new_protocol", issue = "27779")]
impl<T> Boxed for Box<T> {
type Data = T;
type Place = IntermediateBox<T>;
unsafe fn finalize(b: IntermediateBox<T>) -> Box<T> {
finalize(b)
}
}

#[unstable(feature = "placement_in",
reason = "placement box design is still being worked out.",
issue = "27779")]
impl<T> Placer<T> for ExchangeHeapSingleton {
type Place = IntermediateBox<T>;

fn make_place(self) -> IntermediateBox<T> {
make_place()
}
}

#[unstable(feature = "placement_in",
reason = "placement box design is still being worked out.",
issue = "27779")]
impl<T: ?Sized> Drop for IntermediateBox<T> {
fn drop(&mut self) {
if self.layout.size() > 0 {
unsafe {
Heap.dealloc(self.ptr, self.layout.clone())
}
}
}
}

impl<T> Box<T> {
/// Allocates memory on the heap and then places `x` into it.
///
Expand Down
12 changes: 4 additions & 8 deletions src/liballoc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
#![deny(missing_debug_implementations)]

#![cfg_attr(test, allow(deprecated))] // rand
#![cfg_attr(test, feature(placement_in))]
#![cfg_attr(not(test), feature(core_float))]
#![cfg_attr(not(test), feature(exact_size_is_empty))]
#![cfg_attr(not(test), feature(generator_trait))]
Expand Down Expand Up @@ -108,8 +107,6 @@
#![feature(optin_builtin_traits)]
#![feature(pattern)]
#![feature(pin)]
#![feature(placement_in_syntax)]
#![feature(placement_new_protocol)]
#![feature(ptr_internals)]
#![feature(rustc_attrs)]
#![feature(slice_get_slice)]
Expand All @@ -128,8 +125,8 @@
#![feature(pointer_methods)]
#![feature(inclusive_range_fields)]

#![cfg_attr(not(test), feature(fn_traits, placement_new_protocol, swap_with_slice, i128))]
#![cfg_attr(test, feature(test, box_heap))]
#![cfg_attr(not(test), feature(fn_traits, swap_with_slice, i128))]
#![cfg_attr(test, feature(test))]

// Allow testing this library

Expand Down Expand Up @@ -159,13 +156,12 @@ pub mod heap;

// Need to conditionally define the mod from `boxed.rs` to avoid
// duplicating the lang-items when building in test cfg; but also need
// to allow code to have `use boxed::HEAP;`
// and `use boxed::Box;` declarations.
// to allow code to have `use boxed::Box;` declarations.
#[cfg(not(test))]
pub mod boxed;
#[cfg(test)]
mod boxed {
pub use std::boxed::{Box, IntermediateBox, HEAP};
pub use std::boxed::Box;
}
#[cfg(test)]
mod boxed_test;
Expand Down
Loading