Skip to content

Commit 6519762

Browse files
Synchronize the wit-bindgen type AST with the component model (#318)
* WIP: Update for component model multireturn and removal of unit This PR updates wit-bindgen for the latest changes to the component model: - the return of multireturn - removal of the `unit` type - a new syntax for optional types in results, streams, futures and variants all of which go hand in hand. This also pulls in the latest versions of wasm-encoder, wasmprinter, and wasmparser crates to get their updates for these component model changes. * Get all wit-bindgen tests working * Implement tests for multi-return Exercise this throughout the runtime tests and additionally add a few variants in codegen tests to ensure that this is exercised. * Update markdown generator Co-authored-by: George Kulakowski <[email protected]>
1 parent d375b85 commit 6519762

File tree

56 files changed

+1844
-1004
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1844
-1004
lines changed

Cargo.lock

+10-19
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindgen-core/src/lib.rs

+37-13
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,9 @@ impl Types {
204204
for (_, ty) in f.params.iter() {
205205
self.set_param_result_ty(iface, ty, true, false);
206206
}
207-
self.set_param_result_ty(iface, &f.result, false, true);
207+
for ty in f.results.iter_types() {
208+
self.set_param_result_ty(iface, ty, false, true);
209+
}
208210
}
209211
}
210212

@@ -232,7 +234,7 @@ impl Types {
232234
TypeDefKind::Enum(_) => {}
233235
TypeDefKind::Variant(v) => {
234236
for case in v.cases.iter() {
235-
info |= self.type_info(iface, &case.ty);
237+
info |= self.optional_type_info(iface, case.ty.as_ref());
236238
}
237239
}
238240
TypeDefKind::List(ty) => {
@@ -246,20 +248,20 @@ impl Types {
246248
info = self.type_info(iface, ty);
247249
}
248250
TypeDefKind::Result(r) => {
249-
info = self.type_info(iface, &r.ok);
250-
info |= self.type_info(iface, &r.err);
251+
info = self.optional_type_info(iface, r.ok.as_ref());
252+
info |= self.optional_type_info(iface, r.err.as_ref());
251253
}
252254
TypeDefKind::Union(u) => {
253255
for case in u.cases.iter() {
254256
info |= self.type_info(iface, &case.ty);
255257
}
256258
}
257259
TypeDefKind::Future(ty) => {
258-
info = self.type_info(iface, ty);
260+
info = self.optional_type_info(iface, ty.as_ref());
259261
}
260262
TypeDefKind::Stream(stream) => {
261-
info = self.type_info(iface, &stream.element);
262-
info |= self.type_info(iface, &stream.end);
263+
info = self.optional_type_info(iface, stream.element.as_ref());
264+
info |= self.optional_type_info(iface, stream.end.as_ref());
263265
}
264266
}
265267
self.type_info.insert(ty, info);
@@ -277,6 +279,13 @@ impl Types {
277279
info
278280
}
279281

282+
fn optional_type_info(&mut self, iface: &Interface, ty: Option<&Type>) -> TypeInfo {
283+
match ty {
284+
Some(ty) => self.type_info(iface, ty),
285+
None => TypeInfo::default(),
286+
}
287+
}
288+
280289
fn set_param_result_id(&mut self, iface: &Interface, ty: TypeId, param: bool, result: bool) {
281290
match &iface.types[ty].kind {
282291
TypeDefKind::Record(r) => {
@@ -293,25 +302,27 @@ impl Types {
293302
TypeDefKind::Enum(_) => {}
294303
TypeDefKind::Variant(v) => {
295304
for case in v.cases.iter() {
296-
self.set_param_result_ty(iface, &case.ty, param, result)
305+
self.set_param_result_optional_ty(iface, case.ty.as_ref(), param, result)
297306
}
298307
}
299308
TypeDefKind::List(ty) | TypeDefKind::Type(ty) | TypeDefKind::Option(ty) => {
300309
self.set_param_result_ty(iface, ty, param, result)
301310
}
302311
TypeDefKind::Result(r) => {
303-
self.set_param_result_ty(iface, &r.ok, param, result);
304-
self.set_param_result_ty(iface, &r.err, param, result);
312+
self.set_param_result_optional_ty(iface, r.ok.as_ref(), param, result);
313+
self.set_param_result_optional_ty(iface, r.err.as_ref(), param, result);
305314
}
306315
TypeDefKind::Union(u) => {
307316
for case in u.cases.iter() {
308317
self.set_param_result_ty(iface, &case.ty, param, result)
309318
}
310319
}
311-
TypeDefKind::Future(ty) => self.set_param_result_ty(iface, ty, param, result),
320+
TypeDefKind::Future(ty) => {
321+
self.set_param_result_optional_ty(iface, ty.as_ref(), param, result)
322+
}
312323
TypeDefKind::Stream(stream) => {
313-
self.set_param_result_ty(iface, &stream.element, param, result);
314-
self.set_param_result_ty(iface, &stream.end, param, result);
324+
self.set_param_result_optional_ty(iface, stream.element.as_ref(), param, result);
325+
self.set_param_result_optional_ty(iface, stream.end.as_ref(), param, result);
315326
}
316327
}
317328
}
@@ -330,6 +341,19 @@ impl Types {
330341
_ => {}
331342
}
332343
}
344+
345+
fn set_param_result_optional_ty(
346+
&mut self,
347+
iface: &Interface,
348+
ty: Option<&Type>,
349+
param: bool,
350+
result: bool,
351+
) {
352+
match ty {
353+
Some(ty) => self.set_param_result_ty(iface, ty, param, result),
354+
None => (),
355+
}
356+
}
333357
}
334358

335359
#[derive(Default)]

0 commit comments

Comments
 (0)