Skip to content

Commit

Permalink
Merge branch 'master' into joachim/branch-protection
Browse files Browse the repository at this point in the history
  • Loading branch information
mergify[bot] authored Aug 24, 2021
2 parents 1fc4621 + 00f045f commit e209374
Show file tree
Hide file tree
Showing 24 changed files with 362 additions and 251 deletions.
4 changes: 2 additions & 2 deletions perf-delta.nix
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ in
nixpkgs.runCommandNoCC "perf-delta" {
nativeBuildInputs = [ nixpkgs.coreutils diff-stats ];
} ''
cat > $out
echo "Comparing from ${from} to ${to}:" > $out
if cmp -s ${wasm-hash-base} ${wasm-hash-pr}
then
echo "This PR does not affect the produced WebAssembly code." >> $out
echo "The produced WebAssembly code seems to be completely unchanged." >> $out
else
diff-stats ${baseJobs.tests.perf}/stats.csv ${prJobs.tests.perf}/stats.csv >> $out;
fi
Expand Down
6 changes: 3 additions & 3 deletions rts/motoko-rts-tests/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::memory::TestMemory;

use motoko_rts::bigint::{self, *};
use motoko_rts::buf::Buf;
use motoko_rts::types::{Bytes, SkewedPtr, Words};
use motoko_rts::types::{Bytes, Value, Words};

// mp functions below are implemented separately for tests as we can't modify mp_int source code to
// pass a generic heap argument (then monomorphise it for IC).
Expand Down Expand Up @@ -67,7 +67,7 @@ pub unsafe fn test() {
}

// Check leb128 encode/decode roundtrip
unsafe fn test_bigint_leb128(n: SkewedPtr) {
unsafe fn test_bigint_leb128(n: Value) {
let mut buf = [0u8; 100];
let s = bigint_leb128_size(n);
let mut buf_ = Buf {
Expand All @@ -81,7 +81,7 @@ unsafe fn test_bigint_leb128(n: SkewedPtr) {
}

// Check sleb128 encode/decode roundtrip
unsafe fn test_bigint_sleb128(n: SkewedPtr) {
unsafe fn test_bigint_sleb128(n: Value) {
let mut buf = [0u8; 100];
let s = bigint_sleb128_size(n);
bigint_sleb128_encode(n, buf.as_mut_ptr());
Expand Down
18 changes: 12 additions & 6 deletions rts/motoko-rts-tests/src/continuation_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::memory::TestMemory;
use motoko_rts::continuation_table::{
continuation_count, recall_continuation, remember_continuation,
};
use motoko_rts::types::{SkewedPtr, Words};
use motoko_rts::types::{Value, Words};

pub unsafe fn test() {
println!("Testing continuation table ...");
Expand All @@ -18,25 +18,31 @@ pub unsafe fn test() {

let mut references: [u32; N] = [0; N];
for i in 0..N {
references[i] = remember_continuation(&mut heap, SkewedPtr((i << 2).wrapping_sub(1)));
references[i] = remember_continuation(
&mut heap,
Value::from_raw(((i as u32) << 2).wrapping_sub(1)),
);
assert_eq!(continuation_count(), (i + 1) as u32);
}

for i in 0..N / 2 {
let c = recall_continuation(references[i]);
assert_eq!(c.0, (i << 2).wrapping_sub(1));
assert_eq!(c.get_raw(), (i << 2).wrapping_sub(1) as u32);
assert_eq!(continuation_count(), (N - i - 1) as u32);
}

for i in 0..N / 2 {
references[i] = remember_continuation(&mut heap, SkewedPtr((i << 2).wrapping_sub(1)));
references[i] = remember_continuation(
&mut heap,
Value::from_raw(((i as u32) << 2).wrapping_sub(1)),
);
assert_eq!(continuation_count(), (N / 2 + i + 1) as u32);
}

for i in (0..N).rev() {
assert_eq!(
recall_continuation(references[i]).0,
(i << 2).wrapping_sub(1)
recall_continuation(references[i]).get_raw(),
(i << 2).wrapping_sub(1) as u32,
);
assert_eq!(continuation_count(), i as u32);
}
Expand Down
5 changes: 2 additions & 3 deletions rts/motoko-rts-tests/src/gc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,9 +316,8 @@ fn check_continuation_table(mut offset: usize, continuation_table: &[ObjectIdx],
impl GC {
fn run(&self, mut heap: MotokoHeap) {
let heap_base = heap.heap_base_address() as u32;
let static_roots = skew(heap.static_root_array_address());
let continuation_table_ptr_address =
heap.continuation_table_ptr_address() as *mut SkewedPtr;
let static_roots = Value::from_ptr(heap.static_root_array_address());
let continuation_table_ptr_address = heap.continuation_table_ptr_address() as *mut Value;

let heap_1 = heap.clone();
let heap_2 = heap.clone();
Expand Down
6 changes: 3 additions & 3 deletions rts/motoko-rts-tests/src/gc/heap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub struct MotokoHeap {
}

impl Memory for MotokoHeap {
unsafe fn alloc_words(&mut self, n: Words<u32>) -> SkewedPtr {
unsafe fn alloc_words(&mut self, n: Words<u32>) -> Value {
self.inner.borrow_mut().alloc_words(n)
}
}
Expand Down Expand Up @@ -216,7 +216,7 @@ impl MotokoHeapInner {
}
}

unsafe fn alloc_words(&mut self, n: Words<u32>) -> SkewedPtr {
unsafe fn alloc_words(&mut self, n: Words<u32>) -> Value {
let bytes = n.to_bytes();

// Update heap pointer
Expand All @@ -227,7 +227,7 @@ impl MotokoHeapInner {
// Grow memory if needed
self.grow_memory(new_hp as usize);

skew(old_hp)
Value::from_ptr(old_hp)
}

unsafe fn grow_memory(&mut self, ptr: usize) {
Expand Down
6 changes: 3 additions & 3 deletions rts/motoko-rts-tests/src/memory.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use motoko_rts::memory::Memory;
use motoko_rts::types::{skew, SkewedPtr, Words};
use motoko_rts::types::{Value, Words};

pub struct TestMemory {
heap: Box<[u8]>,
Expand Down Expand Up @@ -27,7 +27,7 @@ impl TestMemory {
}

impl Memory for TestMemory {
unsafe fn alloc_words(&mut self, n: Words<u32>) -> SkewedPtr {
unsafe fn alloc_words(&mut self, n: Words<u32>) -> Value {
let bytes = n.to_bytes();

// Update heap pointer
Expand All @@ -38,6 +38,6 @@ impl Memory for TestMemory {
// Grow memory if needed
self.grow_memory(new_hp as usize);

skew(old_hp)
Value::from_ptr(old_hp)
}
}
6 changes: 3 additions & 3 deletions rts/motoko-rts-tests/src/text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use motoko_rts::text::{
text_singleton, text_size,
};
use motoko_rts::text_iter::{text_iter, text_iter_done, text_iter_next};
use motoko_rts::types::{Bytes, SkewedPtr, Words, TAG_BLOB};
use motoko_rts::types::{Bytes, Value, Words, TAG_BLOB};

use std::convert::TryFrom;

Expand All @@ -17,12 +17,12 @@ use proptest::test_runner::{Config, TestCaseError, TestCaseResult, TestRunner};
static STR: &str = "abcdefgh";

struct TextIter<'a, M: Memory> {
obj: SkewedPtr,
obj: Value,
mem: &'a mut M,
}

impl<'a, M: Memory> TextIter<'a, M> {
fn from_text(mem: &'a mut M, text: SkewedPtr) -> Self {
fn from_text(mem: &'a mut M, text: Value) -> Self {
TextIter {
obj: unsafe { text_iter(mem, text) },
mem,
Expand Down
Loading

0 comments on commit e209374

Please sign in to comment.