Skip to content
This repository was archived by the owner on Sep 8, 2025. It is now read-only.

Commit 6b2a379

Browse files
authored
Merge pull request #168 from bytecodealliance/dicej/spec-fixes
fix various behavior mismatches relative to the spec
2 parents a176e9e + de4b75c commit 6b2a379

21 files changed

Lines changed: 2152 additions & 393 deletions

File tree

crates/cranelift/src/compiler/component.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use cranelift_codegen::ir::condcodes::IntCC;
66
use cranelift_codegen::ir::{self, InstBuilder, MemFlags, Value};
77
use cranelift_codegen::isa::{CallConv, TargetIsa};
88
use cranelift_frontend::FunctionBuilder;
9-
use wasmtime_environ::fact::SYNC_ENTER_FIXED_PARAMS;
9+
use wasmtime_environ::fact::SYNC_PREPARE_FIXED_PARAMS;
1010
use wasmtime_environ::{component::*, CompiledFunctionBody};
1111
use wasmtime_environ::{
1212
HostCall, ModuleInternedTypeIndex, PtrSize, TrapSentinel, Tunables, WasmFuncType, WasmValType,
@@ -255,13 +255,13 @@ impl<'a> TrampolineCompiler<'a> {
255255
me.raise_if_host_trapped(rets.pop().unwrap());
256256
})
257257
}
258-
Trampoline::SyncEnterCall { memory } => self.translate_sync_enter(*memory),
259-
Trampoline::SyncExitCall { callback } => self.translate_sync_exit(*callback),
260-
Trampoline::AsyncEnterCall { memory } => self.translate_async_enter(*memory),
261-
Trampoline::AsyncExitCall {
258+
Trampoline::SyncPrepareCall { memory } => self.translate_sync_prepare(*memory),
259+
Trampoline::SyncStartCall { callback } => self.translate_sync_start(*callback),
260+
Trampoline::AsyncPrepareCall { memory } => self.translate_async_prepare(*memory),
261+
Trampoline::AsyncStartCall {
262262
callback,
263263
post_return,
264-
} => self.translate_async_exit(*callback, *post_return),
264+
} => self.translate_async_start(*callback, *post_return),
265265
Trampoline::FutureTransfer => {
266266
self.translate_host_libcall(host::future_transfer, |me, rets| {
267267
rets[0] = me.raise_if_negative_one_and_truncate(rets[0]);
@@ -349,9 +349,10 @@ impl<'a> TrampolineCompiler<'a> {
349349
Abi::Array => {
350350
// TODO: A guest could hypothetically export the same intrinsic
351351
// it imported, allowing the host to call it directly. We need
352-
// to support that here (except for `sync-enter`, `sync-exit`,
353-
// `async-enter`, and `async-exit`, which are only ever called
354-
// from FACT-generated Wasm code and never exported).
352+
// to support that here (except for `sync-prepare`,
353+
// `sync-start`, `async-prepare`, and `async-start`, which are
354+
// only ever called from FACT-generated Wasm code and never
355+
// exported).
355356
//
356357
// https://github.com/bytecodealliance/wasmtime/issues/10143
357358
self.builder.ins().trap(TRAP_INTERNAL_ASSERT);
@@ -470,7 +471,7 @@ impl<'a> TrampolineCompiler<'a> {
470471
);
471472
}
472473

473-
fn translate_sync_enter(&mut self, memory: Option<RuntimeMemoryIndex>) {
474+
fn translate_sync_prepare(&mut self, memory: Option<RuntimeMemoryIndex>) {
474475
match self.abi {
475476
Abi::Wasm => {}
476477

@@ -488,7 +489,7 @@ impl<'a> TrampolineCompiler<'a> {
488489
let pointer_type = self.isa.pointer_type();
489490
let wasm_func_ty = &self.types[self.signature].unwrap_func();
490491

491-
let param_offset = SYNC_ENTER_FIXED_PARAMS.len();
492+
let param_offset = SYNC_PREPARE_FIXED_PARAMS.len();
492493
let spill_offset = param_offset + 2;
493494

494495
let (values_vec_ptr, len) = self.compiler.allocate_stack_array_and_spill_args(
@@ -516,13 +517,13 @@ impl<'a> TrampolineCompiler<'a> {
516517

517518
self.translate_intrinsic_libcall(
518519
vmctx,
519-
host::sync_enter,
520+
host::sync_prepare,
520521
&callee_args,
521522
TrapSentinel::Falsy,
522523
);
523524
}
524525

525-
fn translate_sync_exit(&mut self, callback: Option<RuntimeCallbackIndex>) {
526+
fn translate_sync_start(&mut self, callback: Option<RuntimeCallbackIndex>) {
526527
match self.abi {
527528
Abi::Wasm => {}
528529

@@ -556,7 +557,7 @@ impl<'a> TrampolineCompiler<'a> {
556557
callee_args.push(values_vec_ptr);
557558
callee_args.push(values_vec_len);
558559

559-
let call = self.call_libcall(vmctx, host::sync_exit, &callee_args);
560+
let call = self.call_libcall(vmctx, host::sync_start, &callee_args);
560561

561562
let succeeded = self.builder.func.dfg.inst_results(call)[0];
562563
self.raise_if_host_trapped(succeeded);
@@ -571,7 +572,7 @@ impl<'a> TrampolineCompiler<'a> {
571572
self.builder.ins().return_(&results);
572573
}
573574

574-
fn translate_async_enter(&mut self, memory: Option<RuntimeMemoryIndex>) {
575+
fn translate_async_prepare(&mut self, memory: Option<RuntimeMemoryIndex>) {
575576
match self.abi {
576577
Abi::Wasm => {}
577578

@@ -593,13 +594,13 @@ impl<'a> TrampolineCompiler<'a> {
593594

594595
self.translate_intrinsic_libcall(
595596
vmctx,
596-
host::async_enter,
597+
host::async_prepare,
597598
&callee_args,
598599
TrapSentinel::Falsy,
599600
);
600601
}
601602

602-
fn translate_async_exit(
603+
fn translate_async_start(
603604
&mut self,
604605
callback: Option<RuntimeCallbackIndex>,
605606
post_return: Option<RuntimePostReturnIndex>,
@@ -629,7 +630,7 @@ impl<'a> TrampolineCompiler<'a> {
629630

630631
self.translate_intrinsic_libcall(
631632
vmctx,
632-
host::async_exit,
633+
host::async_start,
633634
&callee_args,
634635
TrapSentinel::NegativeOne,
635636
);

crates/environ/src/component.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ macro_rules! foreach_builtin_component_function {
106106
#[cfg(feature = "component-model-async")]
107107
subtask_cancel(vmctx: vmctx, caller_instance: u32, async_: u8, task_id: u32) -> u64;
108108
#[cfg(feature = "component-model-async")]
109-
sync_enter(vmctx: vmctx, memory: ptr_u8, start: ptr_u8, return_: ptr_u8, caller_instance: u32, callee_instance: u32, task_return_type: u32, string_encoding: u32, result_count: u32, storage: ptr_u8, storage_len: size) -> bool;
109+
sync_prepare(vmctx: vmctx, memory: ptr_u8, start: ptr_u8, return_: ptr_u8, caller_instance: u32, callee_instance: u32, task_return_type: u32, string_encoding: u32, result_count: u32, storage: ptr_u8, storage_len: size) -> bool;
110110
#[cfg(feature = "component-model-async")]
111-
sync_exit(vmctx: vmctx, callback: ptr_u8, callee: ptr_u8, param_count: u32, storage: ptr_u8, storage_len: size) -> bool;
111+
sync_start(vmctx: vmctx, callback: ptr_u8, callee: ptr_u8, param_count: u32, storage: ptr_u8, storage_len: size) -> bool;
112112
#[cfg(feature = "component-model-async")]
113-
async_enter(vmctx: vmctx, memory: ptr_u8, start: ptr_u8, return_: ptr_u8, caller_instance: u32, callee_instance: u32, task_return_type: u32, string_encoding: u32, params: u32, results: u32) -> bool;
113+
async_prepare(vmctx: vmctx, memory: ptr_u8, start: ptr_u8, return_: ptr_u8, caller_instance: u32, callee_instance: u32, task_return_type: u32, string_encoding: u32, params: u32, results: u32) -> bool;
114114
#[cfg(feature = "component-model-async")]
115-
async_exit(vmctx: vmctx, callback: ptr_u8, post_return: ptr_u8, callee: ptr_u8, param_count: u32, result_count: u32, flags: u32) -> u64;
115+
async_start(vmctx: vmctx, callback: ptr_u8, post_return: ptr_u8, callee: ptr_u8, param_count: u32, result_count: u32, flags: u32) -> u64;
116116
#[cfg(feature = "component-model-async")]
117117
future_new(vmctx: vmctx, ty: u32) -> u64;
118118
#[cfg(feature = "component-model-async")]

crates/environ/src/component/dfg.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -383,16 +383,16 @@ pub enum Trampoline {
383383
ResourceTransferBorrow,
384384
ResourceEnterCall,
385385
ResourceExitCall,
386-
SyncEnterCall {
386+
SyncPrepareCall {
387387
memory: Option<MemoryId>,
388388
},
389-
SyncExitCall {
389+
SyncStartCall {
390390
callback: Option<CallbackId>,
391391
},
392-
AsyncEnterCall {
392+
AsyncPrepareCall {
393393
memory: Option<MemoryId>,
394394
},
395-
AsyncExitCall {
395+
AsyncStartCall {
396396
callback: Option<CallbackId>,
397397
post_return: Option<PostReturnId>,
398398
},
@@ -895,19 +895,19 @@ impl LinearizeDfg<'_> {
895895
Trampoline::ResourceTransferBorrow => info::Trampoline::ResourceTransferBorrow,
896896
Trampoline::ResourceEnterCall => info::Trampoline::ResourceEnterCall,
897897
Trampoline::ResourceExitCall => info::Trampoline::ResourceExitCall,
898-
Trampoline::SyncEnterCall { memory } => info::Trampoline::SyncEnterCall {
898+
Trampoline::SyncPrepareCall { memory } => info::Trampoline::SyncPrepareCall {
899899
memory: memory.map(|v| self.runtime_memory(v)),
900900
},
901-
Trampoline::SyncExitCall { callback } => info::Trampoline::SyncExitCall {
901+
Trampoline::SyncStartCall { callback } => info::Trampoline::SyncStartCall {
902902
callback: callback.map(|v| self.runtime_callback(v)),
903903
},
904-
Trampoline::AsyncEnterCall { memory } => info::Trampoline::AsyncEnterCall {
904+
Trampoline::AsyncPrepareCall { memory } => info::Trampoline::AsyncPrepareCall {
905905
memory: memory.map(|v| self.runtime_memory(v)),
906906
},
907-
Trampoline::AsyncExitCall {
907+
Trampoline::AsyncStartCall {
908908
callback,
909909
post_return,
910-
} => info::Trampoline::AsyncExitCall {
910+
} => info::Trampoline::AsyncStartCall {
911911
callback: callback.map(|v| self.runtime_callback(v)),
912912
post_return: post_return.map(|v| self.runtime_post_return(v)),
913913
},

crates/environ/src/component/info.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -956,39 +956,39 @@ pub enum Trampoline {
956956
/// Same as `ResourceEnterCall` except for when exiting a call.
957957
ResourceExitCall,
958958

959-
/// An intrinsic used by FACT-generated modules to begin a call involving a
960-
/// sync-lowered import and async-lifted export.
961-
SyncEnterCall {
959+
/// An intrinsic used by FACT-generated modules to prepare a call involving
960+
/// a sync-lowered import and async-lifted export.
961+
SyncPrepareCall {
962962
/// The memory used to verify that the memory specified for the
963963
/// `task.return` that is called at runtime matches the one specified in
964964
/// the lifted export.
965965
memory: Option<RuntimeMemoryIndex>,
966966
},
967967

968-
/// An intrinsic used by FACT-generated modules to complete a call involving
969-
/// a sync-lowered import and async-lifted export.
970-
SyncExitCall {
968+
/// An intrinsic used by FACT-generated modules to start a call involving a
969+
/// sync-lowered import and async-lifted export.
970+
SyncStartCall {
971971
/// The callee's callback function, if any.
972972
callback: Option<RuntimeCallbackIndex>,
973973
},
974974

975-
/// An intrinsic used by FACT-generated modules to begin a call involving an
976-
/// async-lowered import function.
977-
AsyncEnterCall {
975+
/// An intrinsic used by FACT-generated modules to prepare a call involving
976+
/// an async-lowered import function.
977+
AsyncPrepareCall {
978978
/// The memory used to verify that the memory specified for the
979979
/// `task.return` that is called at runtime (if any) matches the one
980980
/// specified in the lifted export.
981981
memory: Option<RuntimeMemoryIndex>,
982982
},
983983

984-
/// An intrinsic used by FACT-generated modules to complete a call involving
984+
/// An intrinsic used by FACT-generated modules to start a call involving
985985
/// an async-lowered import function.
986986
///
987-
/// Note that `AsyncEnterCall` and `AsyncExitCall` could theoretically be
987+
/// Note that `AsyncPrepareCall` and `AsyncStartCall` could theoretically be
988988
/// combined into a single `AsyncCall` intrinsic, but we separate them to
989989
/// allow the FACT-generated module to optionally call the callee directly
990990
/// without an intermediate host stack frame.
991-
AsyncExitCall {
991+
AsyncStartCall {
992992
/// The callee's callback, if any.
993993
callback: Option<RuntimeCallbackIndex>,
994994

@@ -1086,10 +1086,10 @@ impl Trampoline {
10861086
ResourceTransferBorrow => format!("component-resource-transfer-borrow"),
10871087
ResourceEnterCall => format!("component-resource-enter-call"),
10881088
ResourceExitCall => format!("component-resource-exit-call"),
1089-
SyncEnterCall { .. } => format!("component-sync-enter-call"),
1090-
SyncExitCall { .. } => format!("component-sync-exit-call"),
1091-
AsyncEnterCall { .. } => format!("component-async-enter-call"),
1092-
AsyncExitCall { .. } => format!("component-async-exit-call"),
1089+
SyncPrepareCall { .. } => format!("component-sync-prepare-call"),
1090+
SyncStartCall { .. } => format!("component-sync-start-call"),
1091+
AsyncPrepareCall { .. } => format!("component-async-prepare-call"),
1092+
AsyncStartCall { .. } => format!("component-async-start-call"),
10931093
FutureTransfer => format!("future-transfer"),
10941094
StreamTransfer => format!("stream-transfer"),
10951095
ErrorContextTransfer => format!("error-context-transfer"),

crates/environ/src/component/translate/adapt.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -305,25 +305,25 @@ fn fact_import_to_core_def(
305305
}
306306
fact::Import::ResourceEnterCall => simple_intrinsic(dfg::Trampoline::ResourceEnterCall),
307307
fact::Import::ResourceExitCall => simple_intrinsic(dfg::Trampoline::ResourceExitCall),
308-
fact::Import::SyncEnterCall { memory } => {
309-
simple_intrinsic(dfg::Trampoline::SyncEnterCall {
308+
fact::Import::SyncPrepareCall { memory } => {
309+
simple_intrinsic(dfg::Trampoline::SyncPrepareCall {
310310
memory: memory.as_ref().map(|v| dfg.memories.push(unwrap_memory(v))),
311311
})
312312
}
313-
fact::Import::SyncExitCall { callback } => {
314-
simple_intrinsic(dfg::Trampoline::SyncExitCall {
313+
fact::Import::SyncStartCall { callback } => {
314+
simple_intrinsic(dfg::Trampoline::SyncStartCall {
315315
callback: callback.clone().map(|v| dfg.callbacks.push(v)),
316316
})
317317
}
318-
fact::Import::AsyncEnterCall { memory } => {
319-
simple_intrinsic(dfg::Trampoline::AsyncEnterCall {
318+
fact::Import::AsyncPrepareCall { memory } => {
319+
simple_intrinsic(dfg::Trampoline::AsyncPrepareCall {
320320
memory: memory.as_ref().map(|v| dfg.memories.push(unwrap_memory(v))),
321321
})
322322
}
323-
fact::Import::AsyncExitCall {
323+
fact::Import::AsyncStartCall {
324324
callback,
325325
post_return,
326-
} => simple_intrinsic(dfg::Trampoline::AsyncExitCall {
326+
} => simple_intrinsic(dfg::Trampoline::AsyncStartCall {
327327
callback: callback.clone().map(|v| dfg.callbacks.push(v)),
328328
post_return: post_return.clone().map(|v| dfg.post_returns.push(v)),
329329
}),

0 commit comments

Comments
 (0)