Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion crates/cranelift/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,3 @@ gc-drc = ["gc", "wasmtime-environ/gc-drc"]
gc-null = ["gc", "wasmtime-environ/gc-null"]
stack-switching = []
threads = ["wasmtime-environ/threads"]

1 change: 0 additions & 1 deletion crates/environ/src/component/translate/adapt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,6 @@ impl<'data> Translator<'_, 'data> {
names.push(name);
}
let wasm = module.encode();
wasmparser::Validator::new().validate_all(&wasm).unwrap();
let imports = module.imports().to_vec();

// Extend the lifetime of the owned `wasm: Vec<u8>` on the stack to
Expand Down
4 changes: 2 additions & 2 deletions crates/wasmtime/src/runtime/component/func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl Func {
/// panics if `store` does not own this function.
pub fn call(
&self,
mut store: impl AsContextMut<Data: Send>,
mut store: impl AsContextMut,
params: &[Val],
results: &mut [Val],
) -> Result<()> {
Expand Down Expand Up @@ -397,7 +397,7 @@ impl Func {

fn call_impl(
&self,
mut store: impl AsContextMut<Data: Send>,
mut store: impl AsContextMut,
params: &[Val],
results: &mut [Val],
) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/component/func/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ pub struct LowerContext<'a, T: 'static> {
pub types: &'a ComponentTypes,

/// Index of the component instance that's being lowered into.
pub(crate) instance: Instance,
instance: Instance,
}

#[doc(hidden)]
Expand Down
6 changes: 3 additions & 3 deletions crates/wasmtime/src/runtime/component/func/typed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ where
/// Panics if this is called on a function in an asynchronous store. This
/// only works with functions defined within a synchronous store. Also
/// panics if `store` does not own this function.
pub fn call(&self, store: impl AsContextMut<Data: Send>, params: Params) -> Result<Return>
pub fn call(&self, store: impl AsContextMut, params: Params) -> Result<Return>
where
Return: Send + Sync + 'static,
{
Expand All @@ -184,7 +184,7 @@ where
/// panics if `store` does not own this function.
#[cfg(feature = "async")]
pub async fn call_async(
self,
&self,
mut store: impl AsContextMut<Data: Send>,
params: Params,
) -> Result<Return>
Expand Down Expand Up @@ -379,7 +379,7 @@ where
}
}

fn call_impl(&self, mut store: impl AsContextMut<Data: Send>, params: Params) -> Result<Return>
fn call_impl(&self, mut store: impl AsContextMut, params: Params) -> Result<Return>
where
Return: Send + Sync + 'static,
{
Expand Down
2 changes: 1 addition & 1 deletion crates/wasmtime/src/runtime/component/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ impl<T: 'static> Linker<T> {
use wasmtime_environ::component::ComponentTypes;
use wasmtime_environ::component::TypeDef;
// Recursively stub out all imports of the component with a function that traps.
fn stub_item<T: 'static>(
fn stub_item<T>(
linker: &mut LinkerInstance<T>,
item_name: &str,
item_def: &TypeDef,
Expand Down
66 changes: 4 additions & 62 deletions crates/wasmtime/src/runtime/vm/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
//! cranelift-compiled adapters, will use this `VMComponentContext` as well.

use crate::component::{Component, Instance, InstancePre, ResourceType, RuntimeImport};
use crate::prelude::*;
use crate::runtime::component::ComponentInstanceId;
use crate::runtime::vm::{
Export, ExportFunction, ExportGlobal, ExportGlobalKind, SendSyncPtr, VMArrayCallFunction,
Expand Down Expand Up @@ -109,7 +108,7 @@ pub struct ComponentInstance {
imports: Arc<PrimaryMap<RuntimeImportIndex, RuntimeImport>>,

/// Self-pointer back to `Store<T>` and its functions.
store: Option<VMStoreRawPtr>,
store: VMStoreRawPtr,

/// Cached ABI return value from the last-invoked function call along with
/// the function index that was invoked.
Expand Down Expand Up @@ -224,7 +223,7 @@ impl ComponentInstance {
.byte_sub(mem::size_of::<ComponentInstance>())
.cast::<ComponentInstance>();
let reference = ptr.as_mut();
let store = &mut *reference.store();
let store = &mut *reference.store.0.as_ptr();
let instance = Instance::from_wasmtime(store, reference.id);
f(store, instance)
}
Expand Down Expand Up @@ -297,8 +296,8 @@ impl ComponentInstance {
),
component: component.clone(),
resource_types,
store: Some(VMStoreRawPtr(store)),
imports: imports.clone(),
store: VMStoreRawPtr(store),
post_return_arg: None,
vmctx: VMComponentContext {
_marker: marker::PhantomPinned,
Expand Down Expand Up @@ -343,13 +342,6 @@ impl ComponentInstance {
}
}

/// Returns the store that this component was created with.
///
/// This will panic if this instance has been removed from its store.
pub fn store(&self) -> *mut dyn VMStore {
self.store.unwrap().0.as_ptr()
}

/// Returns the runtime memory definition corresponding to the index of the
/// memory provided.
///
Expand Down Expand Up @@ -600,7 +592,7 @@ impl ComponentInstance {
*self.vmctx_plus_offset_mut(self.offsets.builtins()) =
VmPtr::from(NonNull::from(&libcalls::VMComponentBuiltins::INIT));
*self.vmctx_plus_offset_mut(self.offsets.vm_store_context()) =
VmPtr::from(self.store.unwrap().0.as_ref().vm_store_context_ptr());
VmPtr::from(self.store.0.as_ref().vm_store_context_ptr());

for i in 0..self.offsets.num_runtime_component_instances {
let i = RuntimeComponentInstanceIndex::from_u32(i);
Expand Down Expand Up @@ -690,56 +682,6 @@ impl ComponentInstance {
resource.instance == component.defined_resource_instances[idx]
}

/// Implementation of the `resource.new` intrinsic for `i32`
/// representations.
pub fn resource_new32(
&mut self,
store: &mut dyn VMStore,
ty: TypeResourceTableIndex,
rep: u32,
) -> Result<u32> {
self.resource_tables(store)
.resource_new(TypedResource::Component { ty, rep })
}

/// Implementation of the `resource.rep` intrinsic for `i32`
/// representations.
pub fn resource_rep32(
&mut self,
store: &mut dyn VMStore,
ty: TypeResourceTableIndex,
index: u32,
) -> Result<u32> {
self.resource_tables(store)
.resource_rep(TypedResourceIndex::Component { ty, index })
}

/// Implementation of the `resource.drop` intrinsic.
pub fn resource_drop(
&mut self,
store: &mut dyn VMStore,
ty: TypeResourceTableIndex,
index: u32,
) -> Result<Option<u32>> {
self.resource_tables(store)
.resource_drop(TypedResourceIndex::Component { ty, index })
}

/// NB: this is intended to be a private method. This does not have
/// `host_table` information at this time meaning it's only suitable for
/// working with resources specified to this component which is currently
/// all that this is used for.
///
/// If necessary though it's possible to enhance the `Store` trait to thread
/// through the relevant information and get `host_table` to be `Some` here.
fn resource_tables<'a>(&'a mut self, store: &'a mut dyn VMStore) -> ResourceTables<'a> {
ResourceTables {
host_table: None,
calls: store.component_calls(),
guest: Some((&mut self.instance_resource_tables, self.component.types())),
}
}

/// Returns the runtime state of resources associated with this component.
#[inline]
pub fn guest_tables(
Expand Down