Skip to content

Commit

Permalink
Fix GC tests under MIRI
Browse files Browse the repository at this point in the history
  • Loading branch information
fitzgen committed Oct 31, 2024
1 parent edae0f1 commit acd4bb2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions crates/wasmtime/src/runtime/vm/gc/enabled/drc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -685,8 +685,8 @@ unsafe impl GcHeap for DrcHeap {
activations_table.reset();
}

fn heap_slice(&self) -> &[u8] {
let ptr = self.heap.as_ptr();
fn heap_slice(&self) -> &[UnsafeCell<u8>] {
let ptr = self.heap.as_ptr().cast();
let len = self.heap.len();
unsafe { core::slice::from_raw_parts(ptr, len) }
}
Expand Down
5 changes: 3 additions & 2 deletions crates/wasmtime/src/runtime/vm/gc/enabled/null.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
use core::{
alloc::Layout,
any::Any,
cell::UnsafeCell,
num::{NonZeroU32, NonZeroUsize},
};
use wasmtime_environ::{
Expand Down Expand Up @@ -199,8 +200,8 @@ unsafe impl GcHeap for NullHeap {
self.no_gc_count -= 1;
}

fn heap_slice(&self) -> &[u8] {
let ptr = self.heap.as_ptr();
fn heap_slice(&self) -> &[UnsafeCell<u8>] {
let ptr = self.heap.as_ptr().cast();
let len = self.heap.len();
unsafe { core::slice::from_raw_parts(ptr, len) }
}
Expand Down
6 changes: 4 additions & 2 deletions crates/wasmtime/src/runtime/vm/gc/gc_runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use crate::runtime::vm::{
ExternRefHostDataId, ExternRefHostDataTable, GcHeapObject, SendSyncPtr, TypedGcRef, VMArrayRef,
VMExternRef, VMGcHeader, VMGcObjectDataMut, VMGcRef, VMStructRef,
};
use core::{alloc::Layout, any::Any, marker, mem, num::NonZeroUsize, ops::Range, ptr};
use core::{
alloc::Layout, any::Any, cell::UnsafeCell, marker, mem, num::NonZeroUsize, ops::Range, ptr,
};
use wasmtime_environ::{GcArrayLayout, GcStructLayout, GcTypeLayouts, VMSharedTypeIndex};

/// Trait for integrating a garbage collector with the runtime.
Expand Down Expand Up @@ -383,7 +385,7 @@ pub unsafe trait GcHeap: 'static + Send + Sync {
/// The heap slice must be the GC heap region, and the region must remain
/// valid (i.e. not moved or resized) for JIT code until `self` is dropped
/// or `self.reset()` is called.
fn heap_slice(&self) -> &[u8];
fn heap_slice(&self) -> &[UnsafeCell<u8>];

/// Get a mutable slice of the raw bytes of the GC heap.
///
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmtime/src/runtime/vm/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,8 @@ impl Instance {

unsafe fn set_gc_heap(&mut self, gc_store: Option<&mut GcStore>) {
if let Some(gc_store) = gc_store {
let heap = gc_store.gc_heap.heap_slice();
*self.gc_heap_base() = heap.as_ptr().cast_mut();
let heap = gc_store.gc_heap.heap_slice_mut();
*self.gc_heap_base() = heap.as_mut_ptr();
*self.gc_heap_bound() = heap.len();
*self.gc_heap_data() = gc_store.gc_heap.vmctx_gc_heap_data();
} else {
Expand Down
3 changes: 1 addition & 2 deletions tests/wast.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::{bail, Context};
use bstr::ByteSlice;
use libtest_mimic::{Arguments, FormatSetting, Trial};
use rustix::path::Arg;
use std::path::Path;
use std::sync::{Condvar, LazyLock, Mutex};
use wasmtime::{
Expand Down Expand Up @@ -43,7 +42,7 @@ fn add_tests(trials: &mut Vec<Trial>, path: &Path) {
}

let test_uses_gc_types = path.iter().any(|part| {
part.as_str().map_or(false, |s| {
part.to_str().map_or(false, |s| {
s.contains("gc")
|| s.contains("function-references")
|| s.contains("reference-types")
Expand Down

0 comments on commit acd4bb2

Please sign in to comment.