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
Implement `MaybeUninit` #53508
Merged
Merged
Implement `MaybeUninit` #53508
Changes from 1 commit
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
7bb5b3e
add MaybeUninit and deprecate mem::{uninitialized,zeroed}
japaric 96572cb
panic when instantiating an uninhabited type via mem::{uninitialized,…
japaric 851acdd
core: fix deprecated warnings
japaric 7c37c6d
alloc: fix deprecated warnings
japaric ce8503d
don't deprecate mem::{uninitialized,zeroed} just yet
japaric a6d011a
adapt to change in Session API
japaric af101fd
address Mark-Simulacrum comments
japaric ce6e6f9
use is_uninhabited in more places
japaric 33c10ea
improve panic message
japaric bc5b567
move our check to reuse a previous computation
japaric d864edc
improve the run-pass test
japaric 758ce16
add empty enum to the test cases
japaric 8fb0e80
address RalfJung's comment
japaric 8482c93
gdb_rust_pretty_printing: adapt to the changes in the layout of btree…
japaric 7fea7f4
make the nil-enum test work again
japaric dd9f019
fix tidy
japaric 41b242e
add codegen test
japaric d266722
the test requires unwinding so we don't run it on the wasm32-bare target
japaric 1cdbad2
allow dead_code
japaric File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.
Diff settings
alloc: fix deprecated warnings
- Loading branch information...
| @@ -42,7 +42,7 @@ | |||
| // This implies that even an empty internal node has at least one edge. | |||
|
|
|||
| use core::marker::PhantomData; | |||
| use core::mem; | |||
| use core::mem::{self, MaybeUninit}; | |||
| use core::ptr::{self, Unique, NonNull}; | |||
| use core::slice; | |||
|
|
|||
| @@ -73,7 +73,7 @@ struct LeafNode<K, V> { | |||
| /// This node's index into the parent node's `edges` array. | |||
| /// `*node.parent.edges[node.parent_idx]` should be the same thing as `node`. | |||
| /// This is only guaranteed to be initialized when `parent` is nonnull. | |||
| parent_idx: u16, | |||
| parent_idx: MaybeUninit<u16>, | |||
|
|
|||
| /// The number of keys and values this node stores. | |||
| /// | |||
| @@ -83,8 +83,8 @@ struct LeafNode<K, V> { | |||
|
|
|||
| /// The arrays storing the actual data of the node. Only the first `len` elements of each | |||
| /// array are initialized and valid. | |||
| keys: [K; CAPACITY], | |||
| vals: [V; CAPACITY], | |||
| keys: MaybeUninit<[K; CAPACITY]>, | |||
| vals: MaybeUninit<[V; CAPACITY]>, | |||
eddyb
Member
|
|||
| } | |||
|
|
|||
| impl<K, V> LeafNode<K, V> { | |||
| @@ -94,10 +94,10 @@ impl<K, V> LeafNode<K, V> { | |||
| LeafNode { | |||
| // As a general policy, we leave fields uninitialized if they can be, as this should | |||
| // be both slightly faster and easier to track in Valgrind. | |||
| keys: mem::uninitialized(), | |||
| vals: mem::uninitialized(), | |||
| keys: MaybeUninit::uninitialized(), | |||
| vals: MaybeUninit::uninitialized(), | |||
| parent: ptr::null(), | |||
| parent_idx: mem::uninitialized(), | |||
| parent_idx: MaybeUninit::uninitialized(), | |||
| len: 0 | |||
| } | |||
| } | |||
| @@ -115,10 +115,10 @@ unsafe impl Sync for LeafNode<(), ()> {} | |||
| // ever take a pointer past the first key. | |||
| static EMPTY_ROOT_NODE: LeafNode<(), ()> = LeafNode { | |||
| parent: ptr::null(), | |||
| parent_idx: 0, | |||
| parent_idx: MaybeUninit::uninitialized(), | |||
| len: 0, | |||
| keys: [(); CAPACITY], | |||
| vals: [(); CAPACITY], | |||
| keys: MaybeUninit::uninitialized(), | |||
| vals: MaybeUninit::uninitialized(), | |||
| }; | |||
|
|
|||
| /// The underlying representation of internal nodes. As with `LeafNode`s, these should be hidden | |||
| @@ -430,7 +430,7 @@ impl<BorrowType, K, V, Type> NodeRef<BorrowType, K, V, Type> { | |||
| root: self.root, | |||
| _marker: PhantomData | |||
| }, | |||
| idx: self.as_leaf().parent_idx as usize, | |||
| idx: unsafe { usize::from(*self.as_leaf().parent_idx.get_ref()) }, | |||
| _marker: PhantomData | |||
| }) | |||
| } else { | |||
| @@ -567,7 +567,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> { | |||
| // the node, which is allowed by LLVM. | |||
| unsafe { | |||
| slice::from_raw_parts( | |||
| self.as_leaf().keys.as_ptr(), | |||
| self.as_leaf().keys.get_ref().as_ptr(), | |||
RalfJung
Member
|
|||
| self.len() | |||
| ) | |||
| } | |||
| @@ -578,7 +578,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Immut<'a>, K, V, Type> { | |||
| debug_assert!(!self.is_shared_root()); | |||
| unsafe { | |||
| slice::from_raw_parts( | |||
| self.as_leaf().vals.as_ptr(), | |||
| self.as_leaf().vals.get_ref().as_ptr(), | |||
| self.len() | |||
| ) | |||
| } | |||
| @@ -605,7 +605,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> { | |||
| } else { | |||
| unsafe { | |||
| slice::from_raw_parts_mut( | |||
| &mut self.as_leaf_mut().keys as *mut [K] as *mut K, | |||
| self.as_leaf_mut().keys.get_mut() as *mut [K] as *mut K, | |||
| self.len() | |||
| ) | |||
| } | |||
| @@ -616,7 +616,7 @@ impl<'a, K: 'a, V: 'a, Type> NodeRef<marker::Mut<'a>, K, V, Type> { | |||
| debug_assert!(!self.is_shared_root()); | |||
| unsafe { | |||
| slice::from_raw_parts_mut( | |||
| &mut self.as_leaf_mut().vals as *mut [V] as *mut V, | |||
| self.as_leaf_mut().vals.get_mut() as *mut [V] as *mut V, | |||
| self.len() | |||
| ) | |||
| } | |||
| @@ -1013,7 +1013,7 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker:: | |||
| let ptr = self.node.as_internal_mut() as *mut _; | |||
| let mut child = self.descend(); | |||
| child.as_leaf_mut().parent = ptr; | |||
| child.as_leaf_mut().parent_idx = idx; | |||
| child.as_leaf_mut().parent_idx.set(idx); | |||
| } | |||
|
|
|||
| /// Unsafely asserts to the compiler some static information about whether the underlying | |||
| @@ -1152,12 +1152,12 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Leaf>, marker::KV> | |||
|
|
|||
| ptr::copy_nonoverlapping( | |||
| self.node.keys().as_ptr().add(self.idx + 1), | |||
| new_node.keys.as_mut_ptr(), | |||
| new_node.keys.get_mut().as_mut_ptr(), | |||
| new_len | |||
| ); | |||
| ptr::copy_nonoverlapping( | |||
| self.node.vals().as_ptr().add(self.idx + 1), | |||
| new_node.vals.as_mut_ptr(), | |||
| new_node.vals.get_mut().as_mut_ptr(), | |||
| new_len | |||
| ); | |||
|
|
|||
| @@ -1210,12 +1210,12 @@ impl<'a, K, V> Handle<NodeRef<marker::Mut<'a>, K, V, marker::Internal>, marker:: | |||
|
|
|||
| ptr::copy_nonoverlapping( | |||
| self.node.keys().as_ptr().add(self.idx + 1), | |||
| new_node.data.keys.as_mut_ptr(), | |||
| new_node.data.keys.get_mut().as_mut_ptr(), | |||
| new_len | |||
| ); | |||
| ptr::copy_nonoverlapping( | |||
| self.node.vals().as_ptr().add(self.idx + 1), | |||
| new_node.data.vals.as_mut_ptr(), | |||
| new_node.data.vals.get_mut().as_mut_ptr(), | |||
| new_len | |||
| ); | |||
| ptr::copy_nonoverlapping( | |||
ProTip!
Use n and p to navigate between commits in a pull request.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Based on the comment above, should this instead be
[MaybeUninit<V>; CAPACITY]?(That might be a pain, though, and this is no worse than before, so might not be this PR.)