Skip to content
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
42 changes: 4 additions & 38 deletions crates/cranelift/src/compiler/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1129,12 +1129,6 @@ impl<'a> TrampolineCompiler<'a> {
// may_leave = load.i32 vmctx+$instance_flags_offset
// trapz may_leave, $TRAP_CANNOT_LEAVE_COMPONENT
//
// ;; set may_block to false, saving the old value to restore
// ;; later, but only if the component instances differ and
// ;; concurrency is enabled
// old_may_block = load.i32 vmctx+$may_block_offset
// store 0, vmctx+$may_block_offset
//
// ;; enter a sync call, but only if the component instances
// ;; differ and concurrency is enabled. This pushes an on-stack
// ;; `VMDeferredThread` and zeroes the live context slots; see
Expand All @@ -1158,11 +1152,6 @@ impl<'a> TrampolineCompiler<'a> {
// ...
// ;; ============================================================
//
// ;; if needed, exit the sync call entered above and restore the
// ;; old value of may_block
// ...
// store old_may_block, vmctx+$may_block_offset
//
// jump return_block
//
// return_block:
Expand Down Expand Up @@ -1191,32 +1180,16 @@ impl<'a> TrampolineCompiler<'a> {
self.builder.switch_to_block(run_destructor_block);

// If this is a component-defined resource, the `may_leave` flag must be
// checked. Additionally, if concurrency is enabled, the `may_block`
// field must be updated and a sync call entered.
// checked. Additionally, if concurrency is enabled, the sync call will
// be entered.
let entered_sync_call = if has_destructor && let Some(def) = resource_def {
// Skip the may-leave check for self-owned resources.
if self.types[resource].unwrap_concrete_instance() != def.instance {
self.check_may_leave_instance(self.types[resource].unwrap_concrete_instance());
}

if self.compiler.tunables.concurrency_support {
// Stash the old value of `may_block` and then set it to false.
let old_may_block = self
.alias_regions
.vmcomponent()
.task_may_block()
.readonly()
.load(&mut self.builder.cursor(), vmctx);
let zero = self.builder.ins().iconst(ir::types::I32, i64::from(0));
self.alias_regions.vmcomponent().task_may_block().store(
&mut self.builder.cursor(),
vmctx,
zero,
);

let slot = self.enter_sync_call_inline(instance, def.instance);

Some((old_may_block, slot))
Some(self.enter_sync_call_inline(instance, def.instance))
} else {
None
}
Expand Down Expand Up @@ -1296,15 +1269,8 @@ impl<'a> TrampolineCompiler<'a> {
self.builder.seal_block(continuation);
}

if let Some((old_may_block, slot)) = entered_sync_call {
if let Some(slot) = entered_sync_call {
self.exit_sync_call_inline(vmctx, slot);

// Restore the old value of `may_block`
self.alias_regions.vmcomponent().task_may_block().store(
&mut self.builder.cursor(),
vmctx,
old_may_block,
);
}

self.builder.ins().jump(return_block, &[]);
Expand Down
5 changes: 0 additions & 5 deletions crates/cranelift/src/func_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,6 @@ impl<'module_environment> FuncEnvironment<'module_environment> {
.vmcomponent()
.may_leave(instance)
.region(func),
Some(KnownGlobal::TaskMayBlock) => self
.alias_regions
.vmcomponent()
.task_may_block()
.region(func),
None => self.alias_regions.public_global_region(func),
},
}
Expand Down
5 changes: 0 additions & 5 deletions crates/environ/src/compile/module_environ.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,6 @@ pub enum KnownGlobal {
/// flag.
#[cfg(feature = "component-model")]
ComponentInstanceFlags(crate::component::RuntimeComponentInstanceIndex),

/// The runtime-managed flag recording whether the currently-executing task
/// may perform blocking operations.
#[cfg(feature = "component-model")]
TaskMayBlock,
}

/// The result of translating via `ModuleEnvironment`.
Expand Down
2 changes: 0 additions & 2 deletions crates/environ/src/component/dfg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,6 @@ pub enum CoreDef {
InstanceFlags(RuntimeComponentInstanceIndex),
Trampoline(TrampolineIndex),
UnsafeIntrinsic(ModuleInternedTypeIndex, UnsafeIntrinsic),
TaskMayBlock,

/// This is a special variant not present in `info::CoreDef` which
/// represents that this definition refers to a fused adapter function. This
Expand Down Expand Up @@ -913,7 +912,6 @@ impl LinearizeDfg<'_> {
}
info::CoreDef::UnsafeIntrinsic(*i)
}
CoreDef::TaskMayBlock => info::CoreDef::TaskMayBlock,
}
}

Expand Down
4 changes: 0 additions & 4 deletions crates/environ/src/component/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,6 @@ pub enum CoreDef {
Trampoline(TrampolineIndex),
/// An intrinsic for compile-time builtins.
UnsafeIntrinsic(UnsafeIntrinsic),
/// Reference to a wasm global which represents a runtime-managed boolean
/// indicating whether the currently-running task may perform a blocking
/// operation.
TaskMayBlock,
}

impl<T> From<CoreExport<T>> for CoreDef
Expand Down
13 changes: 4 additions & 9 deletions crates/environ/src/component/translate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,6 @@ impl<'a, 'data> Translator<'a, 'data> {
CoreDef::InstanceFlags(_) => {
unreachable!("instance flags are not a function")
}
CoreDef::TaskMayBlock => {
unreachable!("task_may_block is not a function")
}

// We could in theory inline these trampolines, so it
// could potentially make sense to record that we
Expand Down Expand Up @@ -1976,7 +1973,6 @@ struct Ambiguous {
fn component_flags(def: &CoreDef) -> Option<KnownGlobal> {
match def {
CoreDef::InstanceFlags(instance) => Some(KnownGlobal::ComponentInstanceFlags(*instance)),
CoreDef::TaskMayBlock => Some(KnownGlobal::TaskMayBlock),
CoreDef::Export(_) | CoreDef::Trampoline(_) | CoreDef::UnsafeIntrinsic(_) => None,
}
}
Expand Down Expand Up @@ -2043,10 +2039,9 @@ fn resolve_core_export(
// The chain bottoms out in something that is not an export of
// another instance in this component, so there is no defining module
// for us to name.
CoreDef::InstanceFlags(_)
| CoreDef::Trampoline(_)
| CoreDef::UnsafeIntrinsic(_)
| CoreDef::TaskMayBlock => return None,
CoreDef::InstanceFlags(_) | CoreDef::Trampoline(_) | CoreDef::UnsafeIntrinsic(_) => {
return None;
}
}
}
}
Expand Down Expand Up @@ -2111,7 +2106,7 @@ fn ambiguous_entities(
}
}

CoreDef::InstanceFlags(_) | CoreDef::TaskMayBlock => {
CoreDef::InstanceFlags(_) => {
ambiguous.flags.insert(component_flags(def).unwrap());
}

Expand Down
6 changes: 1 addition & 5 deletions crates/environ/src/component/translate/adapt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,6 @@ pub struct AdapterOptions {
/// The Wasmtime-assigned component instance index where the options were
/// originally specified.
pub instance: RuntimeComponentInstanceIndex,
/// The ancestors (i.e. chain of instantiating instances) of the instance
/// specified in the `instance` field.
pub ancestors: Vec<RuntimeComponentInstanceIndex>,
/// How strings are encoded.
pub string_encoding: StringEncoding,
/// The async callback function used by these options, if specified.
Expand Down Expand Up @@ -455,8 +452,7 @@ impl PartitionAdapterModules {
// These items can't transitively depend on an adapter
dfg::CoreDef::Trampoline(_)
| dfg::CoreDef::InstanceFlags(_)
| dfg::CoreDef::UnsafeIntrinsic(..)
| dfg::CoreDef::TaskMayBlock => {}
| dfg::CoreDef::UnsafeIntrinsic(..) => {}
}
}

Expand Down
6 changes: 0 additions & 6 deletions crates/environ/src/component/translate/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1583,12 +1583,6 @@ impl<'a> Inliner<'a> {
let post_return = options.post_return.map(|i| frame.funcs[i].1.clone());
AdapterOptions {
instance: frame.instance,
ancestors: frames
.iter()
.rev()
.skip(1)
.map(|(frame, _)| frame.instance)
.collect(),
string_encoding: options.string_encoding,
callback,
post_return,
Expand Down
5 changes: 0 additions & 5 deletions crates/environ/src/component/vmcomponent_offsets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ pub struct VMComponentOffsets<P> {
// plus this `VMComponentContext`'s total size. These are all computed by the
// generated `compute_field_offsets` and read by the generated accessors of
// the same names.
task_may_block: u32,
may_leave: u32,
trampoline_func_refs: u32,
intrinsic_func_refs: u32,
Expand Down Expand Up @@ -165,7 +164,6 @@ impl<P: PtrSize> VMComponentOffsets<P> {
0
},
num_resources: component.num_resources,
task_may_block: 0,
may_leave: 0,
trampoline_func_refs: 0,
intrinsic_func_refs: 0,
Expand All @@ -183,7 +181,6 @@ impl<P: PtrSize> VMComponentOffsets<P> {

// The component-model flags must land where a compiler that only knows
// the pointer size can find them.
debug_assert_eq!(ret.task_may_block(), ret.ptr.vmcomponent().task_may_block());
debug_assert!(
(0..ret.num_runtime_component_instances)
.map(RuntimeComponentInstanceIndex::from_u32)
Expand Down Expand Up @@ -248,8 +245,6 @@ mod tests {
};
let offsets = VMComponentOffsets::new(ptr, &component);

assert_eq!(offsets.task_may_block(), ptr.vmcomponent().task_may_block());

for i in 0..num_runtime_component_instances {
let index = RuntimeComponentInstanceIndex::from_u32(i);
assert_eq!(
Expand Down
27 changes: 0 additions & 27 deletions crates/environ/src/fact.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ pub struct Module<'a> {
helper_worklist: Vec<(FunctionId, Helper)>,

exports: Vec<(u32, String)>,

task_may_block: Option<GlobalIndex>,
}

struct AdapterData {
Expand All @@ -137,9 +135,6 @@ struct AdapterOptions {
/// The Wasmtime-assigned component instance index where the options were
/// originally specified.
instance: RuntimeComponentInstanceIndex,
/// The ancestors (i.e. chain of instantiating instances) of the instance
/// specified in the `instance` field.
ancestors: Vec<RuntimeComponentInstanceIndex>,
/// The ascribed type of this adapter.
ty: TypeFuncIndex,
/// The global that represents the instance flags for where this adapter
Expand Down Expand Up @@ -298,7 +293,6 @@ impl<'a> Module<'a> {
imported_unsafe_intrinsics: HashMap::new(),
imported_traps: HashMap::new(),
exports: Vec::new(),
task_may_block: None,
}
}

Expand Down Expand Up @@ -352,7 +346,6 @@ impl<'a> Module<'a> {
fn import_options(&mut self, ty: TypeFuncIndex, options: &AdapterOptionsDfg) -> AdapterOptions {
let AdapterOptionsDfg {
instance,
ancestors,
string_encoding,
post_return: _, // handled above
callback,
Expand Down Expand Up @@ -429,7 +422,6 @@ impl<'a> Module<'a> {

AdapterOptions {
instance: *instance,
ancestors: ancestors.clone(),
ty,
flags,
post_return: None,
Expand Down Expand Up @@ -491,25 +483,6 @@ impl<'a> Module<'a> {
idx
}

fn import_task_may_block(&mut self) -> GlobalIndex {
if let Some(task_may_block) = self.task_may_block {
task_may_block
} else {
let task_may_block = self.import_global(
"instance",
"task_may_block",
GlobalType {
val_type: ValType::I32,
mutable: true,
shared: false,
},
CoreDef::TaskMayBlock,
);
self.task_may_block = Some(task_may_block);
task_may_block
}
}

fn import_transcoder(&mut self, transcoder: transcode::Transcoder) -> FuncIndex {
*self
.imported_transcoders
Expand Down
52 changes: 4 additions & 48 deletions crates/environ/src/fact/trampoline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,6 @@ pub(super) fn compile(module: &mut Module<'_>, adapter: &AdapterData) {
)
}

// If the lift and lower instances are equal, or if one is an ancestor of
// the other, we trap unconditionally. This ensures that recursive
// reentrance via an adapter is impossible.
if adapter.lift.instance == adapter.lower.instance
|| adapter.lower.ancestors.contains(&adapter.lift.instance)
|| adapter.lift.ancestors.contains(&adapter.lower.instance)
{
let (mut compiler, _, _) = compiler(module, adapter);
compiler.trap(Trap::CannotEnterComponent);
compiler.finish();
return;
}

// This closure compiles a function to be exported to the host which host to
// lift the parameters from the caller and lower them to the callee.
//
Expand Down Expand Up @@ -769,25 +756,7 @@ impl<'a, 'b> Compiler<'a, 'b> {
let saved_lower_may_leave =
self.trap_if_not_may_leave(adapter.lower.flags, Trap::CannotLeaveComponent);

let old_task_may_block = if self.module.tunables.concurrency_support {
// Save, clear, and later restore the `may_block` field.
let task_may_block = self.module.import_task_may_block();
let old_task_may_block = if self.types[adapter.lift.ty].async_ {
self.instruction(GlobalGet(task_may_block.as_u32()));
self.instruction(I32Eqz);
self.instruction(If(BlockType::Empty));
self.trap(Trap::CannotBlockSyncTask);
self.instruction(End);
None
} else {
let task_may_block = self.module.import_task_may_block();
self.instruction(GlobalGet(task_may_block.as_u32()));
let old_task_may_block = self.local_set_new_tmp(ValType::I32);
self.instruction(I32Const(0));
self.instruction(GlobalSet(task_may_block.as_u32()));
Some(old_task_may_block)
};

if self.module.tunables.concurrency_support {
// Push a task onto the current task stack.
//
// Note that for sync-to-sync calls, we replace this call with
Expand All @@ -809,8 +778,6 @@ impl<'a, 'b> Compiler<'a, 'b> {
));
let enter_sync_call = self.module.import_enter_sync_call();
self.instruction(Call(enter_sync_call.as_u32()));

old_task_may_block
} else if self.emit_resource_call {
assert!(!self.types[adapter.lift.ty].async_);
self.instruction(I32Const(
Expand All @@ -822,10 +789,7 @@ impl<'a, 'b> Compiler<'a, 'b> {
));
let enter_sync_call = self.module.import_enter_sync_call();
self.instruction(Call(enter_sync_call.as_u32()));
None
} else {
None
};
}

// Perform the translation of arguments. Note that the `may_leave` flag
// is cleared around this invocation for the callee as per the
Expand Down Expand Up @@ -874,7 +838,9 @@ impl<'a, 'b> Compiler<'a, 'b> {
// With all the arguments on the stack the actual target function is
// now invoked. The core wasm results of the function are then placed
// into locals for result translation afterwards.

self.instruction(Call(adapter.callee.as_u32()));

let mut result_locals = Vec::with_capacity(lift_sig.results.len());
let mut temps = Vec::new();
for ty in lift_sig.results.iter().rev() {
Expand Down Expand Up @@ -944,16 +910,6 @@ impl<'a, 'b> Compiler<'a, 'b> {
self.free_temp_local(tmp);
}

if self.module.tunables.concurrency_support {
// Restore old `may_block_field`
if let Some(old_task_may_block) = old_task_may_block {
let task_may_block = self.module.import_task_may_block();
self.instruction(LocalGet(old_task_may_block.idx));
self.instruction(GlobalSet(task_may_block.as_u32()));
self.free_temp_local(old_task_may_block);
}
}

self.exit_exception_barrier();

self.finish()
Expand Down
Loading
Loading