Skip to content

Commit bf2ad79

Browse files
authored
Implement upstream spec changes for component text syntax (#2562)
* Implement upstream spec changes for component text syntax This commit is an implementation of WebAssembly/component-model#655 where parsing of components is updated in a few locations. This is a breaking change to the text format so it's done in a manner where both the previous and new form are accepted. The plan is to have a release or two of accepting the old syntax and new, then have a release or two of defaulting to only accepting the new syntax, followed by eventually removing support for the old syntax. * Run cargo-fmt
1 parent 6575033 commit bf2ad79

93 files changed

Lines changed: 1643 additions & 286 deletions

File tree

Some content is hidden

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

crates/wasm-compose/tests/compositions/connect-resources/composed.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
(export "get-logger" (func $import-get-logger-lowered))
9090
)
9191
(alias core export $module-indirect-instance "[dtor]logger" (core func $logger-dtor (;3;)))
92-
(type $logger-resource (;2;) (resource (rep i32) (dtor (func $logger-dtor))))
92+
(type $logger-resource (;2;) (resource (rep i32) (dtor $logger-dtor)))
9393
(core func $logger-new (;4;) (canon resource.new $logger-resource))
9494
(core instance $logger-new-instance (;2;)
9595
(export "[resource-new]logger" (func $logger-new))

crates/wasm-compose/tests/compositions/connect-resources/logger.wat

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
)
5555

5656
(alias core export $module-indirect-instance "[dtor]logger" (core func $logger-dtor))
57-
(type $logger-resource (resource (rep i32) (dtor (func $logger-dtor))))
57+
(type $logger-resource (resource (rep i32) (dtor (core func $logger-dtor))))
5858
(core func $logger-new (canon resource.new $logger-resource))
5959
(core instance $logger-new-instance
6060
(export "[resource-new]logger" (func $logger-new))

crates/wasmprinter/src/component.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,8 @@ impl Printer<'_, '_> {
568568
if let Some(dtor) = dtor {
569569
self.result.write_str(" ")?;
570570
self.start_group("dtor ")?;
571-
self.start_group("func ")?;
572571
self.print_idx(&states.last().unwrap().core.func_names, dtor)?;
573572
self.end_group()?;
574-
self.end_group()?;
575573
}
576574
self.end_group()?;
577575
}
@@ -969,9 +967,7 @@ impl Printer<'_, '_> {
969967
self.print_intrinsic(state, "canon thread.spawn-indirect ", &|me, state| {
970968
me.print_idx(&state.core.type_names, func_ty_index)?;
971969
me.result.write_str(" ")?;
972-
me.start_group("table ")?;
973-
me.print_idx(&state.core.table_names, table_index)?;
974-
me.end_group()
970+
me.print_idx(&state.core.table_names, table_index)
975971
})?;
976972
}
977973
CanonicalFunction::ThreadAvailableParallelism => {
@@ -1185,9 +1181,7 @@ impl Printer<'_, '_> {
11851181
self.print_intrinsic(state, "canon thread.new-indirect ", &|me, state| {
11861182
me.print_idx(&state.core.type_names, func_ty_index)?;
11871183
me.result.write_str(" ")?;
1188-
me.start_group("table ")?;
1189-
me.print_idx(&state.core.table_names, table_index)?;
1190-
me.end_group()
1184+
me.print_idx(&state.core.table_names, table_index)
11911185
})?;
11921186
}
11931187
CanonicalFunction::ThreadResumeLater => {

crates/wast/src/component/binary.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -344,24 +344,24 @@ impl<'a> Encoder<'a> {
344344
}
345345
CoreFuncKind::ResourceNew(info) => {
346346
self.core_func_names.push(name);
347-
self.funcs.resource_new(info.ty.into());
347+
self.funcs.resource_new((&info.ty).into());
348348
}
349349
CoreFuncKind::ResourceDrop(info) => {
350350
self.core_func_names.push(name);
351-
self.funcs.resource_drop(info.ty.into());
351+
self.funcs.resource_drop((&info.ty).into());
352352
}
353353
CoreFuncKind::ResourceRep(info) => {
354354
self.core_func_names.push(name);
355-
self.funcs.resource_rep(info.ty.into());
355+
self.funcs.resource_rep((&info.ty).into());
356356
}
357357
CoreFuncKind::ThreadSpawnRef(info) => {
358358
self.core_func_names.push(name);
359-
self.funcs.thread_spawn_ref(info.ty.into());
359+
self.funcs.thread_spawn_ref(info.ty.idx.into());
360360
}
361361
CoreFuncKind::ThreadSpawnIndirect(info) => {
362362
self.core_func_names.push(name);
363363
self.funcs
364-
.thread_spawn_indirect(info.ty.into(), info.table.idx.into());
364+
.thread_spawn_indirect(info.ty.idx.into(), info.table.idx.into());
365365
}
366366
CoreFuncKind::ThreadAvailableParallelism(_info) => {
367367
self.core_func_names.push(name);
@@ -406,63 +406,67 @@ impl<'a> Encoder<'a> {
406406
}
407407
CoreFuncKind::StreamNew(info) => {
408408
self.core_func_names.push(name);
409-
self.funcs.stream_new(info.ty.into());
409+
self.funcs.stream_new((&info.ty).into());
410410
}
411411
CoreFuncKind::StreamRead(info) => {
412412
self.core_func_names.push(name);
413413
self.funcs
414-
.stream_read(info.ty.into(), info.opts.iter().map(Into::into));
414+
.stream_read((&info.ty).into(), info.opts.iter().map(Into::into));
415415
}
416416
CoreFuncKind::StreamWrite(info) => {
417417
self.core_func_names.push(name);
418418
self.funcs
419-
.stream_write(info.ty.into(), info.opts.iter().map(Into::into));
419+
.stream_write((&info.ty).into(), info.opts.iter().map(Into::into));
420420
}
421421
CoreFuncKind::StreamCancelRead(info) => {
422422
self.core_func_names.push(name);
423-
self.funcs.stream_cancel_read(info.ty.into(), info.async_);
423+
self.funcs
424+
.stream_cancel_read((&info.ty).into(), info.async_);
424425
}
425426
CoreFuncKind::StreamCancelWrite(info) => {
426427
self.core_func_names.push(name);
427-
self.funcs.stream_cancel_write(info.ty.into(), info.async_);
428+
self.funcs
429+
.stream_cancel_write((&info.ty).into(), info.async_);
428430
}
429431
CoreFuncKind::StreamDropReadable(info) => {
430432
self.core_func_names.push(name);
431-
self.funcs.stream_drop_readable(info.ty.into());
433+
self.funcs.stream_drop_readable((&info.ty).into());
432434
}
433435
CoreFuncKind::StreamDropWritable(info) => {
434436
self.core_func_names.push(name);
435-
self.funcs.stream_drop_writable(info.ty.into());
437+
self.funcs.stream_drop_writable((&info.ty).into());
436438
}
437439
CoreFuncKind::FutureNew(info) => {
438440
self.core_func_names.push(name);
439-
self.funcs.future_new(info.ty.into());
441+
self.funcs.future_new((&info.ty).into());
440442
}
441443
CoreFuncKind::FutureRead(info) => {
442444
self.core_func_names.push(name);
443445
self.funcs
444-
.future_read(info.ty.into(), info.opts.iter().map(Into::into));
446+
.future_read((&info.ty).into(), info.opts.iter().map(Into::into));
445447
}
446448
CoreFuncKind::FutureWrite(info) => {
447449
self.core_func_names.push(name);
448450
self.funcs
449-
.future_write(info.ty.into(), info.opts.iter().map(Into::into));
451+
.future_write((&info.ty).into(), info.opts.iter().map(Into::into));
450452
}
451453
CoreFuncKind::FutureCancelRead(info) => {
452454
self.core_func_names.push(name);
453-
self.funcs.future_cancel_read(info.ty.into(), info.async_);
455+
self.funcs
456+
.future_cancel_read((&info.ty).into(), info.async_);
454457
}
455458
CoreFuncKind::FutureCancelWrite(info) => {
456459
self.core_func_names.push(name);
457-
self.funcs.future_cancel_write(info.ty.into(), info.async_);
460+
self.funcs
461+
.future_cancel_write((&info.ty).into(), info.async_);
458462
}
459463
CoreFuncKind::FutureDropReadable(info) => {
460464
self.core_func_names.push(name);
461-
self.funcs.future_drop_readable(info.ty.into());
465+
self.funcs.future_drop_readable((&info.ty).into());
462466
}
463467
CoreFuncKind::FutureDropWritable(info) => {
464468
self.core_func_names.push(name);
465-
self.funcs.future_drop_writable(info.ty.into());
469+
self.funcs.future_drop_writable((&info.ty).into());
466470
}
467471
CoreFuncKind::ErrorContextNew(info) => {
468472
self.core_func_names.push(name);
@@ -507,7 +511,7 @@ impl<'a> Encoder<'a> {
507511
CoreFuncKind::ThreadNewIndirect(info) => {
508512
self.core_func_names.push(name);
509513
self.funcs
510-
.thread_new_indirect(info.ty.into(), info.table.idx.into());
514+
.thread_new_indirect(info.ty.idx.into(), info.table.idx.into());
511515
}
512516
CoreFuncKind::ThreadResumeLater => {
513517
self.core_func_names.push(name);

0 commit comments

Comments
 (0)