Skip to content

Commit

Permalink
Change asserts to debug_assert
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasWanke committed Apr 4, 2024
1 parent 48c7936 commit 04c764d
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions compiler/vm/src/heap/object_heap/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ impl HeapFunction {
body: InstructionPointer,
) -> Self {
let captured_len = captured.len();
assert_eq!(
debug_assert_eq!(
(captured_len << Self::CAPTURED_LEN_SHIFT) >> Self::CAPTURED_LEN_SHIFT,
captured_len,
"Function captures too many things.",
);

let argument_count_shift_for_max_size =
InlineObject::BITS as usize - Self::CAPTURED_LEN_SHIFT + Self::ARGUMENT_COUNT_SHIFT;
assert_eq!(
debug_assert_eq!(
(argument_count << argument_count_shift_for_max_size)
>> argument_count_shift_for_max_size,
argument_count,
Expand Down
2 changes: 1 addition & 1 deletion compiler/vm/src/heap/object_heap/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl HeapInt {

#[must_use]
pub fn bit_length(self, heap: &mut Heap) -> Int {
assert!(*self.get() >= 0.into());
debug_assert!(*self.get() >= 0.into());
Int::create(heap, true, self.get().bits())
}

Expand Down
8 changes: 4 additions & 4 deletions compiler/vm/src/heap/object_heap/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl HeapList {
}
#[must_use]
fn create_uninitialized(heap: &mut Heap, is_reference_counted: bool, len: usize) -> Self {
assert_eq!(
debug_assert_eq!(
(len << Self::LEN_SHIFT) >> Self::LEN_SHIFT,
len,
"List is too long.",
Expand Down Expand Up @@ -70,7 +70,7 @@ impl HeapList {
}
#[must_use]
pub fn insert(self, heap: &mut Heap, index: usize, value: InlineObject) -> Self {
assert!(index <= self.len());
debug_assert!(index <= self.len());

let len = self.len() + 1;
let new_list = Self::create_uninitialized(heap, true, len);
Expand All @@ -91,7 +91,7 @@ impl HeapList {
}
#[must_use]
pub fn remove(self, heap: &mut Heap, index: usize) -> Self {
assert!(index < self.len());
debug_assert!(index < self.len());

let len = self.len() - 1;
let new_list = Self::create_uninitialized(heap, true, len);
Expand All @@ -111,7 +111,7 @@ impl HeapList {
}
#[must_use]
pub fn replace(self, heap: &mut Heap, index: usize, value: InlineObject) -> Self {
assert!(index < self.len());
debug_assert!(index < self.len());

let new_list = Self::create(heap, true, self.items());
unsafe { ptr::write(new_list.content_word_pointer(index).cast().as_ptr(), value) };
Expand Down
6 changes: 3 additions & 3 deletions compiler/vm/src/heap/object_heap/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ impl HeapObject {
}
pub(super) fn free(self, heap: &mut Heap) {
trace!("Freeing object at {self:p}.");
assert_eq!(self.reference_count().unwrap_or_default(), 0);
debug_assert_eq!(self.reference_count().unwrap_or_default(), 0);
let data = HeapData::from(self);
if DEBUG_ALLOCATIONS {
// No need for pluralization because our heap objects are longer
Expand Down Expand Up @@ -306,7 +306,7 @@ impl From<HeapObject> for HeapData {
let header_word = object.header_word();
match header_word & HeapObject::KIND_MASK {
HeapObject::KIND_INT => {
assert_eq!(
debug_assert_eq!(
header_word & !HeapObject::IS_REFERENCE_COUNTED_MASK,
HeapObject::KIND_INT,
);
Expand All @@ -318,7 +318,7 @@ impl From<HeapObject> for HeapData {
HeapObject::KIND_TEXT => Self::Text(HeapText::new_unchecked(object)),
HeapObject::KIND_FUNCTION => Self::Function(HeapFunction::new_unchecked(object)),
HeapObject::KIND_HIR_ID => {
assert_eq!(
debug_assert_eq!(
header_word & !HeapObject::IS_REFERENCE_COUNTED_MASK,
HeapObject::KIND_HIR_ID,
);
Expand Down
6 changes: 3 additions & 3 deletions compiler/vm/src/heap/object_heap/struct_.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl HeapStruct {
value: &FxHashMap<InlineObject, InlineObject>,
) -> Self {
let len = value.len();
assert_eq!(
debug_assert_eq!(
(len << Self::LEN_SHIFT) >> Self::LEN_SHIFT,
len,
"Struct is too long.",
Expand All @@ -56,7 +56,7 @@ impl HeapStruct {
}
#[must_use]
fn create_uninitialized(heap: &mut Heap, is_reference_counted: bool, len: usize) -> Self {
assert_eq!(
debug_assert_eq!(
(len << Self::LEN_SHIFT) >> Self::LEN_SHIFT,
len,
"Struct is too long.",
Expand Down Expand Up @@ -131,7 +131,7 @@ impl HeapStruct {
}
#[must_use]
pub fn replace_at_index(self, heap: &mut Heap, index: usize, value: InlineObject) -> Self {
assert!(index < self.len());
debug_assert!(index < self.len());

let struct_ = Self::create_uninitialized(heap, true, self.len());
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion compiler/vm/src/heap/object_heap/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl HeapText {
#[must_use]
pub fn create(heap: &mut Heap, is_reference_counted: bool, value: &str) -> Self {
let byte_len = value.len();
assert_eq!(
debug_assert_eq!(
(byte_len << Self::BYTE_LEN_SHIFT) >> Self::BYTE_LEN_SHIFT,
byte_len,
"Text is too long.",
Expand Down
2 changes: 1 addition & 1 deletion compiler/vm/src/heap/object_inline/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ impl InlineObjectTrait for InlineInt {
#[extension_trait]
pub impl I64BitLength for i64 {
fn bit_length(self) -> u32 {
assert!(!self.is_negative());
debug_assert!(!self.is_negative());
Self::BITS - self.leading_zeros()
}
}
Expand Down
6 changes: 3 additions & 3 deletions compiler/vm/src/instructions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ impl MachineState {
self.run_builtin_function(heap, builtin.get(), arguments, responsible)
}
Data::Handle(handle) => {
assert_eq!(handle.argument_count(), arguments.len());
debug_assert_eq!(handle.argument_count(), arguments.len());
InstructionResult::CallHandle(CallHandle {
handle,
arguments: arguments.to_vec(),
Expand All @@ -277,7 +277,7 @@ impl MachineState {
arguments: &[InlineObject],
responsible: HirId,
) -> InstructionResult {
assert_eq!(function.argument_count(), arguments.len());
debug_assert_eq!(function.argument_count(), arguments.len());
if let Some(next_instruction) = self.next_instruction {
self.call_stack.push(next_instruction);
}
Expand All @@ -299,7 +299,7 @@ impl MachineState {
unsafe { value.unwrap_unchecked() }
}
fn pop_multiple_from_data_stack(&mut self, amount: usize) {
assert!(amount <= self.data_stack.len());
debug_assert!(amount <= self.data_stack.len());
self.data_stack.truncate(self.data_stack.len() - amount);
}
}

0 comments on commit 04c764d

Please sign in to comment.