rustc: Implement the #[global_allocator] attribute

This PR is an implementation of [RFC 1974] which specifies a new method of
defining a global allocator for a program. This obsoletes the old
`#![allocator]` attribute and also removes support for it.

[RFC 1974]: https://github.com/rust-lang/rfcs/pull/197

The new `#[global_allocator]` attribute solves many issues encountered with the
`#![allocator]` attribute such as composition and restrictions on the crate
graph itself. The compiler now has much more control over the ABI of the
allocator and how it's implemented, allowing much more freedom in terms of how
this feature is implemented.

cc #27389
This commit is contained in:
Alex Crichton 2017-06-03 14:54:08 -07:00
parent 4c225c4d17
commit 695dee063b
115 changed files with 2860 additions and 1201 deletions

View file

@ -48,7 +48,7 @@ use core::ptr::{self, Unique};
use core::slice;
use boxed::Box;
use heap;
use heap::{Heap, Alloc, Layout};
const B: usize = 6;
pub const MIN_LEN: usize = B - 1;
@ -254,11 +254,7 @@ impl<K, V> Root<K, V> {
self.as_mut().as_leaf_mut().parent = ptr::null();
unsafe {
heap::deallocate(
top,
mem::size_of::<InternalNode<K, V>>(),
mem::align_of::<InternalNode<K, V>>()
);
Heap.dealloc(top, Layout::new::<InternalNode<K, V>>());
}
}
}
@ -445,7 +441,7 @@ impl<K, V> NodeRef<marker::Owned, K, V, marker::Leaf> {
> {
let ptr = self.as_leaf() as *const LeafNode<K, V> as *const u8 as *mut u8;
let ret = self.ascend().ok();
heap::deallocate(ptr, mem::size_of::<LeafNode<K, V>>(), mem::align_of::<LeafNode<K, V>>());
Heap.dealloc(ptr, Layout::new::<LeafNode<K, V>>());
ret
}
}
@ -466,11 +462,7 @@ impl<K, V> NodeRef<marker::Owned, K, V, marker::Internal> {
> {
let ptr = self.as_internal() as *const InternalNode<K, V> as *const u8 as *mut u8;
let ret = self.ascend().ok();
heap::deallocate(
ptr,
mem::size_of::<InternalNode<K, V>>(),
mem::align_of::<InternalNode<K, V>>()
);
Heap.dealloc(ptr, Layout::new::<InternalNode<K, V>>());
ret
}
}
@ -1252,16 +1244,14 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker::
).correct_parent_link();
}
heap::deallocate(
Heap.dealloc(
right_node.node.get() as *mut u8,
mem::size_of::<InternalNode<K, V>>(),
mem::align_of::<InternalNode<K, V>>()
Layout::new::<InternalNode<K, V>>(),
);
} else {
heap::deallocate(
Heap.dealloc(
right_node.node.get() as *mut u8,
mem::size_of::<LeafNode<K, V>>(),
mem::align_of::<LeafNode<K, V>>()
Layout::new::<LeafNode<K, V>>(),
);
}