Skip to content
Open
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
8 changes: 1 addition & 7 deletions crates/cranelift/src/compiler/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,7 +1189,7 @@ impl<'a> TrampolineCompiler<'a> {
}

if self.compiler.tunables.concurrency_support {
Some(self.enter_sync_call_inline(instance, def.instance))
Some(self.enter_sync_call_inline(def.instance))
} else {
None
}
Expand Down Expand Up @@ -1286,14 +1286,9 @@ impl<'a> TrampolineCompiler<'a> {
/// otherwise do eagerly.
fn enter_sync_call_inline(
&mut self,
caller_instance: RuntimeComponentInstanceIndex,
callee_instance: RuntimeComponentInstanceIndex,
) -> ir::StackSlot {
let vmctx = self.caller_vmctx();
let caller_instance = self
.builder
.ins()
.iconst(ir::types::I32, i64::from(caller_instance.as_u32()));
let callee_async = self.builder.ins().iconst(ir::types::I32, 0);
let callee_instance = self
.builder
Expand All @@ -1304,7 +1299,6 @@ impl<'a> TrampolineCompiler<'a> {
&mut self.alias_regions,
vmctx,
crate::component_sync_call::EnterArgs {
caller_instance,
callee_async,
callee_instance,
},
Expand Down
7 changes: 0 additions & 7 deletions crates/cranelift/src/component_sync_call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ use wasmtime_environ::{GetPtrSize, NUM_COMPONENT_CONTEXT_SLOTS, PtrSize};
/// `VMDeferredThread`, to be replayed by the host if it ever has to promote the
/// deferred thread into a real one.
pub struct EnterArgs {
/// The component instance performing the call.
pub caller_instance: ir::Value,
/// Whether the callee is async-lifted, as an `i32` boolean.
pub callee_async: ir::Value,
/// The component instance being called into.
Expand Down Expand Up @@ -79,11 +77,6 @@ where
.store(&mut builder.cursor(), slot_addr, parent);

// Record the deferred `enter_sync_call` arguments.
alias_regions.vm_deferred_thread().caller_instance().store(
&mut builder.cursor(),
slot_addr,
args.caller_instance,
);
alias_regions.vm_deferred_thread().callee_async().store(
&mut builder.cursor(),
slot_addr,
Expand Down
9 changes: 4 additions & 5 deletions crates/cranelift/src/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2076,18 +2076,17 @@ impl<'a, 'func, 'module_env> Call<'a, 'func, 'module_env> {
/// defers the heavyweight task bookkeeping the `enter_sync_call` libcall
/// would otherwise do eagerly.
///
/// `real_call_args` is `[callee_vmctx, caller_vmctx, caller_instance,
/// callee_async, callee_instance]`.
/// `real_call_args` is `[callee_vmctx, caller_vmctx, callee_async,
/// callee_instance]`.
fn lower_fact_enter_sync_call(&mut self, real_call_args: &[ir::Value]) -> CallRets {
let vmctx = self.env.vmctx_val(&mut self.builder.cursor());
let slot = crate::component_sync_call::enter(
self.builder,
&mut self.env.alias_regions,
vmctx,
crate::component_sync_call::EnterArgs {
caller_instance: real_call_args[2],
callee_async: real_call_args[3],
callee_instance: real_call_args[4],
callee_async: real_call_args[2],
callee_instance: real_call_args[3],
},
);

Expand Down
2 changes: 1 addition & 1 deletion crates/environ/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ macro_rules! foreach_builtin_component_function {
resource_transfer_own(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;
resource_transfer_borrow(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;

enter_sync_call(vmctx: vmctx, caller_instance: u32, callee_async: u32, callee_instance: u32) -> bool;
enter_sync_call(vmctx: vmctx, callee_async: u32, callee_instance: u32) -> bool;
exit_sync_call(vmctx: vmctx) -> bool;

#[cfg(feature = "component-model-async")]
Expand Down
3 changes: 3 additions & 0 deletions crates/environ/src/component/dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,9 @@ pub struct ComponentDfg {
/// Interned map of id-to-`CanonicalOptions`, or all sets-of-options used by
/// this component.
pub options: Intern<OptionsId, CanonicalOptions>,

/// The thread-transparency analysis for this component.
pub transparency: ThreadTransparency,
}

/// Possible side effects that are possible with instantiating this component.
Expand Down
2 changes: 2 additions & 0 deletions crates/environ/src/component/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use wasmparser::{Chunk, ComponentExternName, Encoding, Parser, Payload, Validato
mod adapt;
pub use self::adapt::*;
mod inline;
mod thread_transparency;
pub use self::thread_transparency::ThreadTransparency;

/// Structure used to translate a component and parse it.
pub struct Translator<'a, 'data> {
Expand Down
9 changes: 8 additions & 1 deletion crates/environ/src/component/translate/adapt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,14 @@ impl<'data> Translator<'_, 'data> {
let mut names = Vec::with_capacity(adapter_module.adapters.len());
for adapter in adapter_module.adapters.iter() {
let name = format!("adapter{}", adapter.as_u32());
module.adapt(&name, &component.adapters[*adapter]);
let adapter = &component.adapters[*adapter];
module.adapt(
&name,
adapter,
component
.transparency
.adapter_is_transparent(self.types.types(), adapter),
);
names.push(name);
}
let wasm = module.encode();
Expand Down
35 changes: 23 additions & 12 deletions crates/environ/src/component/translate/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub(super) fn run(
// the root frame which are then used for recording the exports of the
// component.
inliner.result.num_runtime_component_instances += 1;
inliner.result.transparency.push_root_instance(index);
let frame = InlinerFrame::new(index, result, ComponentClosure::default(), args, None);
let resources_snapshot = types.resources_mut().clone();
let mut frames = vec![(frame, resources_snapshot)];
Expand Down Expand Up @@ -185,8 +186,8 @@ struct Inliner<'a> {
/// incrementally processed via the `initializers` list here. Note that the
/// inliner frames are stored on the heap to avoid recursion based on user
/// input.
struct InlinerFrame<'a> {
instance: RuntimeComponentInstanceIndex,
pub(super) struct InlinerFrame<'a> {
pub(super) instance: RuntimeComponentInstanceIndex,

/// The remaining initializers to process when instantiating this component.
initializers: std::slice::Iter<'a, LocalInitializer<'a>>,
Expand Down Expand Up @@ -215,7 +216,7 @@ struct InlinerFrame<'a> {
modules: PrimaryMap<ModuleIndex, ModuleDef<'a>>,

// component model index spaces
component_funcs: PrimaryMap<ComponentFuncIndex, ComponentFuncDef<'a>>,
pub(super) component_funcs: PrimaryMap<ComponentFuncIndex, ComponentFuncDef<'a>>,
module_instances: PrimaryMap<ModuleInstanceIndex, ModuleInstanceDef<'a>>,
component_instances: PrimaryMap<ComponentInstanceIndex, ComponentInstanceDef<'a>>,
components: PrimaryMap<ComponentIndex, ComponentDef<'a>>,
Expand Down Expand Up @@ -258,7 +259,7 @@ struct ComponentClosure<'a> {
/// values and so this is used to ensure that we primarily only deal with
/// individual functions and modules instead of synthetic instances.
#[derive(Clone, PartialEq, Hash, Eq)]
struct ImportPath<'a> {
pub(super) struct ImportPath<'a> {
index: ImportIndex,
path: Vec<Cow<'a, str>>,
}
Expand All @@ -268,7 +269,7 @@ struct ImportPath<'a> {
/// This is the "value" of an item defined within a component and is used to
/// represent both imports and exports.
#[derive(Clone)]
enum ComponentItemDef<'a> {
pub(super) enum ComponentItemDef<'a> {
Component(ComponentDef<'a>),
Instance(ComponentInstanceDef<'a>),
Func(ComponentFuncDef<'a>),
Expand All @@ -277,7 +278,7 @@ enum ComponentItemDef<'a> {
}

#[derive(Clone)]
enum ModuleDef<'a> {
pub(super) enum ModuleDef<'a> {
/// A core wasm module statically defined within the original component.
///
/// The `StaticModuleIndex` indexes into the `static_modules` map in the
Expand Down Expand Up @@ -309,7 +310,7 @@ enum ModuleInstanceDef<'a> {
}

#[derive(Clone)]
enum ComponentFuncDef<'a> {
pub(super) enum ComponentFuncDef<'a> {
/// A compile-time builtin intrinsic.
UnsafeIntrinsic(UnsafeIntrinsic),

Expand All @@ -328,7 +329,7 @@ enum ComponentFuncDef<'a> {
}

#[derive(Clone)]
enum ComponentInstanceDef<'a> {
pub(super) enum ComponentInstanceDef<'a> {
/// The `__wasmtime_intrinsics` instance that exports all of our
/// compile-time builtin intrinsics.
Intrinsics,
Expand Down Expand Up @@ -356,7 +357,7 @@ enum ComponentInstanceDef<'a> {
}

#[derive(Clone)]
struct ComponentDef<'a> {
pub(super) struct ComponentDef<'a> {
index: StaticComponentIndex,
closure: ComponentClosure<'a>,
}
Expand Down Expand Up @@ -437,6 +438,11 @@ impl<'a> Inliner<'a> {
use LocalInitializer::*;

let (frame, _) = frames.last_mut().unwrap();

self.result
.transparency
.process_initializer(types, frame, initializer);

match initializer {
// When a component imports an item the actual definition of the
// item is looked up here (not at runtime) via its name. The
Expand Down Expand Up @@ -1297,13 +1303,18 @@ impl<'a> Inliner<'a> {
self.result.num_runtime_component_instances,
);
self.result.num_runtime_component_instances += 1;
let args = args
.iter()
.map(|(name, item)| Ok((*name, frame.item(*item, types)?)))
.collect::<Result<HashMap<_, _>>>()?;

self.result.transparency.push_instance(index, &args);

let frame = InlinerFrame::new(
index,
&self.nested_components[component.index],
component.closure.clone(),
args.iter()
.map(|(name, item)| Ok((*name, frame.item(*item, types)?)))
.collect::<Result<_>>()?,
args,
Some(*ty),
);
return Ok(Some(frame));
Expand Down
Loading
Loading