Skip to content

Commit

Permalink
Progress on compilation: it passes trait resolution, borrowcheck, and…
Browse files Browse the repository at this point in the history
… the lint for missing docs, but then gets to a MIR ICE.
  • Loading branch information
aweinstock314 committed Jan 21, 2020
1 parent 2915511 commit 649507d
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/base/allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use crate::base::{DefaultAllocator, Scalar};
pub trait Allocator<N: Scalar, R: Dim, C: Dim = U1>: Any + Sized {
/// The type of buffer this allocator can instanciate.
type Buffer: ContiguousStorageMut<N, R, C, InitializedTag> + Clone;
/// The type of a buffer of uninitialized memory from this allocator
type UninitBuffer: ContiguousStorageMut<N, R, C, UninitializedTag>;

/// Allocates a buffer with the given number of rows and columns without initializing its content.
Expand Down
2 changes: 1 addition & 1 deletion src/base/array_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,10 +295,10 @@ where
#[inline]
fn clone_owned(&self) -> <UninitializedTag as GenericOverInitializednessAllocatorDispatch<N, R, C, DefaultAllocator>>::Owned
where DefaultAllocator: Allocator<N, R, C> {
unimplemented!();
/*let it = self.iter().cloned();
DefaultAllocator::allocate_from_iterator(self.shape().0, self.shape().1, it)*/
panic!("attempted to clone potentially uninitialized memory");
}

#[inline]
Expand Down
3 changes: 2 additions & 1 deletion src/base/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ where
CStride: Dim,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
ArrayStorage<N, R, C>: Storage<N, R, C, InitializedTag>,
Prod<R::Value, C::Value>: ArrayLength<mem::MaybeUninit<N>>,
{
fn from(matrix_slice: MatrixSlice<'a, N, R, C, RStride, CStride>) -> Self {
matrix_slice.into_owned()
Expand Down Expand Up @@ -394,6 +394,7 @@ where
CStride: Dim,
R::Value: Mul<C::Value>,
Prod<R::Value, C::Value>: ArrayLength<N>,
Prod<R::Value, C::Value>: ArrayLength<mem::MaybeUninit<N>>,
{
fn from(matrix_slice: MatrixSliceMut<'a, N, R, C, RStride, CStride>) -> Self {
matrix_slice.into_owned()
Expand Down
1 change: 1 addition & 0 deletions src/base/default_allocator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ where
type Buffer = ArrayStorage<N, R, C>;
type UninitBuffer = ArrayStorage<mem::MaybeUninit<N>, R, C>;

// TODO: replace Self::Buffer with Self::UninitBuffer to start the refactoring for replacing mem::uninitialized with mem::MaybeUninit
#[inline]
unsafe fn allocate_uninitialized(_: R, _: C) -> Self::Buffer {
mem::uninitialized()
Expand Down
8 changes: 7 additions & 1 deletion src/base/storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,21 +34,27 @@ pub type RStride<N, R, C = U1, G = InitializedTag> =
pub type CStride<N, R, C = U1, G = InitializedTag> =
<<DefaultAllocator as Allocator<N, R, C>>::Buffer as Storage<N, R, C, G>>::CStride;

/// A tag indicating that memory is uninitialized, used for trait resolution
pub struct UninitializedTag;
/// A tag indicating that memory is initialized, used for trait resolution
pub struct InitializedTag;

/// GenericOverInitializedness is a type-level function for computing the type of a Storage implementation's Scalars based on whether they are initialized or uninitialized.
pub unsafe trait GenericOverInitializedness<N: Scalar, R: Dim, C: Dim = U1> {
/// The computed type for possibly-initialized Scalars
type Scalar;
}
unsafe impl<N: Scalar, R: Dim, C: Dim> GenericOverInitializedness<N, R, C> for UninitializedTag {
type Scalar = mem::MaybeUninit<N>;
//type Scalar = N;
}
unsafe impl<N: Scalar, R: Dim, C: Dim> GenericOverInitializedness<N, R, C> for InitializedTag {
type Scalar = N;
}

/// GenericOverInitializednessAllocatorDispatch is a type-level function for computing the type of the whole buffer based on whether the elements are initialized or uninitialized.
/// It is a separate trait from GenericOverInitializedness in order to properly scope the bounds on the Allocator in Storage impls to just {into_owned, clone_owned}.
pub unsafe trait GenericOverInitializednessAllocatorDispatch<N: Scalar, R: Dim, C: Dim, A: Allocator<N, R, C>>: GenericOverInitializedness<N, R, C> where Self: Sized {
/// The computed type for possibly-initialized owned buffers
type Owned: ContiguousStorageMut<N, R, C, Self>;
}
unsafe impl<N: Scalar, R: Dim, C: Dim, A: Allocator<N, R, C>> GenericOverInitializednessAllocatorDispatch<N, R, C, A> for UninitializedTag {
Expand Down
6 changes: 4 additions & 2 deletions src/base/vec_storage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@ where DefaultAllocator: Allocator<N, Dynamic, C, UninitBuffer = Self>
#[inline]
fn clone_owned(&self) -> <UninitializedTag as GenericOverInitializednessAllocatorDispatch<N, Dynamic, C, DefaultAllocator>>::Owned
where DefaultAllocator: Allocator<N, Dynamic, C> {
*self.clone()
//*self.clone()
panic!("attempted to clone potentially uninitialized memory");
}

#[inline]
Expand Down Expand Up @@ -320,7 +321,8 @@ where DefaultAllocator: Allocator<N, R, Dynamic, UninitBuffer = Self>
#[inline]
fn clone_owned(&self) -> <UninitializedTag as GenericOverInitializednessAllocatorDispatch<N, R, Dynamic, DefaultAllocator>>::Owned
where DefaultAllocator: Allocator<N, R, Dynamic> {
*self.clone()
//*self.clone()
panic!("attempted to clone potentially uninitialized memory");
}

#[inline]
Expand Down

0 comments on commit 649507d

Please sign in to comment.