Skip to content
Draft
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
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
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
8 changes: 8 additions & 0 deletions crates/test-util/src/wast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,14 @@ impl WastTest {
return true;
}

// This will require a wasm-tools update:
if self
.path
.ends_with("component-model/test/validation/max-value-size.wast")
{
return true;
}

false
}
}
Expand Down
Loading
Loading