Skip to content

Commit 8f4d991

Browse files
committed
async/stream/future plumbing for wasmtime-environ
I've split this out of bytecodealliance#9582 to make review easier. This patch includes the plumbing needed to route async/stream/future/error-context data from `wit-parser`, through the various layers of `wasmtime-environ`, and on to `wasmtime-cranelift` and `wasmtime`. The `wasmtime::runtime`, `wasmtime_environ::fact`, and `wasmtime_cranelift::compiler::component` modules only contain `todo!()` stubs to begin with; I'll flesh those out in later PRs. Signed-off-by: Joel Dice <[email protected]> remove debugging code Signed-off-by: Joel Dice <[email protected]> revert comment formatting change in trap_encoding.rs Signed-off-by: Joel Dice <[email protected]> deduplicate code in inline.rs Signed-off-by: Joel Dice <[email protected]> remove `ComponentTypesBuilder::error_context_type` This was just an alias for `error_context_table_type`, which I've made public. Signed-off-by: Joel Dice <[email protected]> defer `VMComponentOffsets` changes to a future PR Signed-off-by: Joel Dice <[email protected]>
1 parent 636435f commit 8f4d991

File tree

22 files changed

+1701
-91
lines changed

22 files changed

+1701
-91
lines changed

crates/cranelift/src/compiler/component.rs

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,103 @@ impl<'a> TrampolineCompiler<'a> {
9494
Trampoline::AlwaysTrap => {
9595
self.translate_always_trap();
9696
}
97+
Trampoline::TaskBackpressure { instance } => {
98+
_ = instance;
99+
todo!()
100+
}
101+
Trampoline::TaskReturn => todo!(),
102+
Trampoline::TaskWait {
103+
instance,
104+
async_,
105+
memory,
106+
} => {
107+
_ = (instance, async_, memory);
108+
todo!()
109+
}
110+
Trampoline::TaskPoll {
111+
instance,
112+
async_,
113+
memory,
114+
} => {
115+
_ = (instance, async_, memory);
116+
todo!()
117+
}
118+
Trampoline::TaskYield { async_ } => {
119+
_ = async_;
120+
todo!()
121+
}
122+
Trampoline::SubtaskDrop { instance } => {
123+
_ = instance;
124+
todo!()
125+
}
126+
Trampoline::StreamNew { ty } => {
127+
_ = ty;
128+
todo!()
129+
}
130+
Trampoline::StreamRead { ty, options } => {
131+
_ = (ty, options);
132+
todo!()
133+
}
134+
Trampoline::StreamWrite { ty, options } => {
135+
_ = (ty, options);
136+
todo!()
137+
}
138+
Trampoline::StreamCancelRead { ty, async_ } => {
139+
_ = (ty, async_);
140+
todo!()
141+
}
142+
Trampoline::StreamCancelWrite { ty, async_ } => {
143+
_ = (ty, async_);
144+
todo!()
145+
}
146+
Trampoline::StreamCloseReadable { ty } => {
147+
_ = ty;
148+
todo!()
149+
}
150+
Trampoline::StreamCloseWritable { ty } => {
151+
_ = ty;
152+
todo!()
153+
}
154+
Trampoline::FutureNew { ty } => {
155+
_ = ty;
156+
todo!()
157+
}
158+
Trampoline::FutureRead { ty, options } => {
159+
_ = (ty, options);
160+
todo!()
161+
}
162+
Trampoline::FutureWrite { ty, options } => {
163+
_ = (ty, options);
164+
todo!()
165+
}
166+
Trampoline::FutureCancelRead { ty, async_ } => {
167+
_ = (ty, async_);
168+
todo!()
169+
}
170+
Trampoline::FutureCancelWrite { ty, async_ } => {
171+
_ = (ty, async_);
172+
todo!()
173+
}
174+
Trampoline::FutureCloseReadable { ty } => {
175+
_ = ty;
176+
todo!()
177+
}
178+
Trampoline::FutureCloseWritable { ty } => {
179+
_ = ty;
180+
todo!()
181+
}
182+
Trampoline::ErrorContextNew { ty, options } => {
183+
_ = (ty, options);
184+
todo!()
185+
}
186+
Trampoline::ErrorContextDebugMessage { ty, options } => {
187+
_ = (ty, options);
188+
todo!()
189+
}
190+
Trampoline::ErrorContextDrop { ty } => {
191+
_ = ty;
192+
todo!()
193+
}
97194
Trampoline::ResourceNew(ty) => self.translate_resource_new(*ty),
98195
Trampoline::ResourceRep(ty) => self.translate_resource_rep(*ty),
99196
Trampoline::ResourceDrop(ty) => self.translate_resource_drop(*ty),
@@ -115,6 +212,26 @@ impl<'a> TrampolineCompiler<'a> {
115212
me.raise_if_host_trapped(rets.pop().unwrap());
116213
})
117214
}
215+
Trampoline::AsyncEnterCall => todo!(),
216+
Trampoline::AsyncExitCall {
217+
callback,
218+
post_return,
219+
} => {
220+
_ = (callback, post_return);
221+
todo!()
222+
}
223+
Trampoline::FutureTransfer => {
224+
_ = host::future_transfer;
225+
todo!()
226+
}
227+
Trampoline::StreamTransfer => {
228+
_ = host::stream_transfer;
229+
todo!()
230+
}
231+
Trampoline::ErrorContextTransfer => {
232+
_ = host::error_context_transfer;
233+
todo!()
234+
}
118235
}
119236
}
120237

@@ -159,8 +276,14 @@ impl<'a> TrampolineCompiler<'a> {
159276
realloc,
160277
post_return,
161278
string_encoding,
279+
callback: _,
280+
async_,
162281
} = *options;
163282

283+
if async_ {
284+
todo!()
285+
}
286+
164287
// vmctx: *mut VMComponentContext
165288
host_sig.params.push(ir::AbiParam::new(pointer_type));
166289
callee_args.push(vmctx);

crates/environ/examples/factc.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,8 @@ impl Factc {
147147
realloc: Some(dummy_def()),
148148
// Lowering never allows `post-return`
149149
post_return: None,
150+
async_: false,
151+
callback: None,
150152
},
151153
lift_options: AdapterOptions {
152154
instance: RuntimeComponentInstanceIndex::from_u32(1),
@@ -159,6 +161,8 @@ impl Factc {
159161
} else {
160162
None
161163
},
164+
async_: false,
165+
callback: None,
162166
},
163167
func: dummy_def(),
164168
});

crates/environ/src/component.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ macro_rules! foreach_builtin_component_function {
8383
resource_enter_call(vmctx: vmctx);
8484
resource_exit_call(vmctx: vmctx) -> bool;
8585

86+
future_transfer(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;
87+
stream_transfer(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;
88+
error_context_transfer(vmctx: vmctx, src_idx: u32, src_table: u32, dst_table: u32) -> u64;
89+
8690
trap(vmctx: vmctx, code: u8);
8791

8892
utf8_to_utf8(src: ptr_u8, len: size, dst: ptr_u8) -> bool;

0 commit comments

Comments
 (0)