Skip to content

Commit

Permalink
Revert more changes
Browse files Browse the repository at this point in the history
  • Loading branch information
osa1 committed Sep 10, 2021
1 parent e131e61 commit 5aa4d24
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 25 deletions.
2 changes: 1 addition & 1 deletion rts/motoko-rts/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub unsafe fn mp_realloc<M: Memory>(
) -> *mut libc::c_void {
let bigint = BigInt::from_payload(ptr as *mut mp_digit);

debug_assert_eq!({ (*bigint).header.tag }, TAG_BIGINT);
debug_assert_eq!((*bigint).header.tag, TAG_BIGINT);
debug_assert_eq!(bigint.len(), old_size);

if new_size > bigint.len() {
Expand Down
16 changes: 8 additions & 8 deletions rts/motoko-rts/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ pub(crate) unsafe fn print_boxed_object(buf: &mut WriteBuf, p: usize) {
let _ = write!(
buf,
"<Object size={:#x} hash_ptr={:#x} field=[",
{ (*object).size },
{ (*object).hash_ptr },
(*object).size,
(*object).hash_ptr
);
for i in 0..object.size() {
let val = object.get(i);
Expand All @@ -161,7 +161,7 @@ pub(crate) unsafe fn print_boxed_object(buf: &mut WriteBuf, p: usize) {
}
TAG_ARRAY => {
let array = obj as *mut Array;
let _ = write!(buf, "<Array len={:#x}", { (*array).len });
let _ = write!(buf, "<Array len={:#x}", (*array).len);

for i in 0..::core::cmp::min(10, (*array).len) {
let _ = write!(buf, " {:#x}", array.get(i).get_raw());
Expand All @@ -175,15 +175,15 @@ pub(crate) unsafe fn print_boxed_object(buf: &mut WriteBuf, p: usize) {
}
TAG_BITS64 => {
let bits64 = obj as *const Bits64;
let _ = write!(buf, "<Bits64 {:#x}>", { (*bits64).bits() });
let _ = write!(buf, "<Bits64 {:#x}>", (*bits64).bits());
}
TAG_MUTBOX => {
let mutbox = obj as *const MutBox;
let _ = write!(buf, "<MutBox field={:#x}>", (*mutbox).field.get_raw());
}
TAG_CLOSURE => {
let closure = obj as *const Closure;
let _ = write!(buf, "<Closure size={:#x}>", { (*closure).size });
let _ = write!(buf, "<Closure size={:#x}>", (*closure).size);
}
TAG_SOME => {
let some = obj as *const Some;
Expand All @@ -194,7 +194,7 @@ pub(crate) unsafe fn print_boxed_object(buf: &mut WriteBuf, p: usize) {
let _ = write!(
buf,
"<Variant tag={:#x} field={:#x}>",
{ (*variant).tag },
(*variant).tag,
(*variant).field.get_raw()
);
}
Expand All @@ -208,7 +208,7 @@ pub(crate) unsafe fn print_boxed_object(buf: &mut WriteBuf, p: usize) {
}
TAG_BITS32 => {
let bits32 = obj as *const Bits32;
let _ = write!(buf, "<Bits32 {:#x}>", { (*bits32).bits });
let _ = write!(buf, "<Bits32 {:#x}>", (*bits32).bits);
}
TAG_BIGINT => {
// Add more details here as needed
Expand All @@ -221,7 +221,7 @@ pub(crate) unsafe fn print_boxed_object(buf: &mut WriteBuf, p: usize) {
"<Concat n_bytes={:#x} obj1={:#x} obj2={:#x}>",
(*concat).n_bytes.0,
(*concat).text1.get_raw(),
(*concat).text2.get_raw(),
(*concat).text2.get_raw()
);
}
TAG_ONE_WORD_FILLER => {
Expand Down
4 changes: 1 addition & 3 deletions rts/motoko-rts/src/gc/mark_compact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ use crate::visitor::{pointer_to_dynamic_heap, visit_pointer_fields};

use motoko_rts_macros::ic_mem_fn;

use core::ptr::addr_of_mut;

#[ic_mem_fn(ic_only)]
unsafe fn schedule_compacting_gc<M: Memory>(mem: &mut M) {
if super::should_do_gc() {
Expand Down Expand Up @@ -163,7 +161,7 @@ unsafe fn mark_fields<M: Memory>(mem: &mut M, obj: *mut Obj, obj_tag: Tag, heap_

/// Specialized version of `mark_fields` for root `MutBox`es.
unsafe fn mark_root_mutbox_fields<M: Memory>(mem: &mut M, mutbox: *mut MutBox, heap_base: u32) {
let field_addr = addr_of_mut!((*mutbox).field);
let field_addr = &mut (*mutbox).field;
// TODO: Not sure if this check is necessary?
if pointer_to_dynamic_heap(field_addr, heap_base as usize) {
// TODO: We should be able to omit the "already marked" check here as no two root MutBox
Expand Down
9 changes: 4 additions & 5 deletions rts/motoko-rts/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::constants::WORD_SIZE;
use crate::rts_trap_with;
use crate::tommath_bindings::{mp_digit, mp_int};

use core::ops::{Add, AddAssign, Div, Mul, Sub, SubAssign};
use core::ptr::addr_of;

use crate::constants::WORD_SIZE;
use crate::rts_trap_with;

pub fn size_of<T>() -> Words<u32> {
Bytes(::core::mem::size_of::<T>() as u32).to_words()
Expand Down Expand Up @@ -492,7 +491,7 @@ impl BigInt {
/// output parameters of mp_add() this way.
pub unsafe fn mp_int_ptr(self: *mut BigInt) -> *const mp_int {
(*self).mp_int.dp = self.payload_addr();
addr_of!((*self).mp_int)
&(*self).mp_int
}
}

Expand Down
14 changes: 6 additions & 8 deletions rts/motoko-rts/src/visitor.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
use crate::rts_trap_with;
use crate::types::*;

use core::ptr::addr_of_mut;

/// A visitor that passes field addresses of fields with pointers to dynamic heap to the given
/// callback
pub unsafe fn visit_pointer_fields<F>(
Expand Down Expand Up @@ -38,7 +36,7 @@ pub unsafe fn visit_pointer_fields<F>(

TAG_MUTBOX => {
let mutbox = obj as *mut MutBox;
let field_addr = addr_of_mut!((*mutbox).field);
let field_addr = &mut (*mutbox).field;
if pointer_to_dynamic_heap(field_addr, heap_base) {
visit_ptr_field(field_addr);
}
Expand All @@ -57,35 +55,35 @@ pub unsafe fn visit_pointer_fields<F>(

TAG_SOME => {
let some = obj as *mut Some;
let field_addr = addr_of_mut!((*some).field);
let field_addr = &mut (*some).field;
if pointer_to_dynamic_heap(field_addr, heap_base) {
visit_ptr_field(field_addr);
}
}

TAG_VARIANT => {
let variant = obj as *mut Variant;
let field_addr = addr_of_mut!((*variant).field);
let field_addr = &mut (*variant).field;
if pointer_to_dynamic_heap(field_addr, heap_base) {
visit_ptr_field(field_addr);
}
}

TAG_CONCAT => {
let concat = obj as *mut Concat;
let field1_addr = addr_of_mut!((*concat).text1);
let field1_addr = &mut (*concat).text1;
if pointer_to_dynamic_heap(field1_addr, heap_base) {
visit_ptr_field(field1_addr);
}
let field2_addr = addr_of_mut!((*concat).text2);
let field2_addr = &mut (*concat).text2;
if pointer_to_dynamic_heap(field2_addr, heap_base) {
visit_ptr_field(field2_addr);
}
}

TAG_OBJ_IND => {
let obj_ind = obj as *mut ObjInd;
let field_addr = addr_of_mut!((*obj_ind).field);
let field_addr = &mut (*obj_ind).field;
if pointer_to_dynamic_heap(field_addr, heap_base) {
visit_ptr_field(field_addr);
}
Expand Down

0 comments on commit 5aa4d24

Please sign in to comment.