diff --git a/server/src/engine/core/index/key.rs b/server/src/engine/core/index/key.rs index 4090c380..2b42fabc 100644 --- a/server/src/engine/core/index/key.rs +++ b/server/src/engine/core/index/key.rs @@ -110,6 +110,9 @@ impl PrimaryIndexKey { dc.as_raw() } .dwordqn_load_qw_nw(); + if cfg!(debug_assertions) && tag < TagUnique::Bin { + assert_eq!(b, mem::ZERO_BLOCK.as_ptr() as usize); + } Self { tag, data: unsafe { @@ -131,6 +134,9 @@ impl PrimaryIndexKey { } fn __compute_vdata_offset(&self) -> [usize; 2] { let (len, data) = self.data.dwordqn_load_qw_nw(); + if cfg!(debug_assertions) && self.tag < TagUnique::Bin { + assert_eq!(data, mem::ZERO_BLOCK.as_ptr() as usize); + } let actual_len = (len as usize) * (self.tag >= TagUnique::Bin) as usize; [data, actual_len] } diff --git a/server/src/engine/core/model/cell.rs b/server/src/engine/core/model/cell.rs index effd8cfc..69c5d0e3 100644 --- a/server/src/engine/core/model/cell.rs +++ b/server/src/engine/core/model/cell.rs @@ -32,7 +32,7 @@ use { spec::{Dataspec1D, DataspecMeta1D}, tag::{CUTag, DataTag, TagClass}, }, - mem::{DwordNN, DwordQN, NativeQword, WordIO}, + mem::{DwordNN, DwordQN, NativeQword, SpecialPaddedWord, WordIO}, }, core::{fmt, mem, mem::ManuallyDrop, slice, str}, parking_lot::RwLock, @@ -49,7 +49,10 @@ impl Datacell { pub fn new_bool(b: bool) -> Self { unsafe { // UNSAFE(@ohsayan): Correct because we are initializing Self with the correct tag - Self::new(CUTag::BOOL, DataRaw::word(WordIO::store(b))) + Self::new( + CUTag::BOOL, + DataRaw::word(SpecialPaddedWord::store(b).dword_promote()), + ) } } pub unsafe fn read_bool(&self) -> bool { @@ -68,7 +71,10 @@ impl Datacell { pub fn new_uint(u: u64) -> Self { unsafe { // UNSAFE(@ohsayan): Correct because we are initializing Self with the correct tag - Self::new(CUTag::UINT, DataRaw::word(WordIO::store(u))) + Self::new( + CUTag::UINT, + DataRaw::word(SpecialPaddedWord::store(u).dword_promote()), + ) } } pub unsafe fn read_uint(&self) -> u64 { @@ -84,10 +90,13 @@ impl Datacell { self.try_uint().unwrap() } // sint - pub fn new_sint(u: i64) -> Self { + pub fn new_sint(i: i64) -> Self { unsafe { // UNSAFE(@ohsayan): Correct because we are initializing Self with the correct tag - Self::new(CUTag::SINT, DataRaw::word(WordIO::store(u))) + Self::new( + CUTag::SINT, + DataRaw::word(SpecialPaddedWord::store(i).dword_promote()), + ) } } pub unsafe fn read_sint(&self) -> i64 { @@ -106,7 +115,10 @@ impl Datacell { pub fn new_float(f: f64) -> Self { unsafe { // UNSAFE(@ohsayan): Correct because we are initializing Self with the correct tag - Self::new(CUTag::FLOAT, DataRaw::word(WordIO::store(f))) + Self::new( + CUTag::FLOAT, + DataRaw::word(SpecialPaddedWord::store(f).dword_promote()), + ) } } pub unsafe fn read_float(&self) -> f64 { diff --git a/server/src/engine/mem/mod.rs b/server/src/engine/mem/mod.rs index d99940e0..4c318e9d 100644 --- a/server/src/engine/mem/mod.rs +++ b/server/src/engine/mem/mod.rs @@ -35,7 +35,7 @@ mod tests; pub use astr::AStr; pub use uarray::UArray; pub use vinline::VInline; -pub use word::{DwordNN, DwordQN, QwordNNNN, TwordNNN, WordIO}; +pub use word::{DwordNN, DwordQN, QwordNNNN, TwordNNN, WordIO, ZERO_BLOCK}; // imports use std::alloc::{self, Layout}; diff --git a/server/src/util/mod.rs b/server/src/util/mod.rs index 42d8deec..042c74a8 100644 --- a/server/src/util/mod.rs +++ b/server/src/util/mod.rs @@ -24,8 +24,6 @@ * */ -use std::mem::{self, ManuallyDrop}; - #[macro_use] mod macros; pub mod compiler; @@ -41,7 +39,7 @@ use { core::{ fmt::{self, Debug}, marker::PhantomData, - mem::MaybeUninit, + mem::{self, MaybeUninit}, ops::Deref, }, std::process, @@ -52,11 +50,7 @@ pub const IS_ON_CI: bool = option_env!("CI").is_some(); const EXITCODE_ONE: i32 = 0x01; pub fn bx_to_vec(bx: Box<[T]>) -> Vec { - let mut md = ManuallyDrop::new(bx); - // damn you, miri - let ptr = md.as_mut_ptr() as usize as *mut T; - let len = md.len(); - unsafe { Vec::from_raw_parts(ptr, len, len) } + Vec::from(bx) } /// # Unsafe unwrapping