Skip to content

Commit 0403dba

Browse files
authored
Merge pull request #277 from bytecodealliance/ydnar/async
all: initial support for async types
2 parents 41ab7de + 6d17128 commit 0403dba

File tree

31 files changed

+427
-87
lines changed

31 files changed

+427
-87
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ on:
1414

1515
env:
1616
go-modules: ./... ./cm/...
17-
wasm-tools-version: "1.219.1"
17+
wasm-tools-version: "1.222.0"
1818
wasmtime-version: "26.0.0"
1919

2020
jobs:

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
1010

1111
### Changed
1212

13-
- Incremental support for Component Model async types `stream<T>` and `future<T>`.
13+
- Initial support for Component Model [async](https://github.com/WebAssembly/component-model/blob/main/design/mvp/Async.md) types `stream`, `future`, and `error-context`.
14+
- Breaking: generated `*.wasm.go` files will now have correct WIT kebab-case base name. Interfaces or worlds with `-` in their name will require removal of the previous `*.wasm.go` files.
1415
- Dropped support for TinyGo v0.32.0.
1516

1617
## [v0.5.0] — 2024-12-14

cm/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
44

5+
## [Unreleased]
6+
7+
### Added
8+
9+
- Initial support for Component Model [async](https://github.com/WebAssembly/component-model/blob/main/design/mvp/Async.md) types `stream`, `future`, and `error-context`.
10+
511
## [v0.1.0] — 2024-12-14
612

713
Initial version, extracted into module [`go.bytecodealliance.org/cm`](https://pkg.go.dev/go.bytecodealliance.org/cm).

cm/empty.s

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// This file exists for testing this package without WebAssembly,
2+
// allowing empty function bodies with a //go:wasmimport directive.
3+
// See https://pkg.go.dev/cmd/compile for more information.

cm/error.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package cm
2+
3+
import "unsafe"
4+
5+
// ErrorContext represents the Component Model [error-context] type,
6+
// an immutable, non-deterministic, host-defined value meant to aid in debugging.
7+
//
8+
// [error-context]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#error-context-type
9+
type ErrorContext struct {
10+
_ HostLayout
11+
errorContext
12+
}
13+
14+
type errorContext uint32
15+
16+
// Error implements the [error] interface. It returns the debug message associated with err.
17+
func (err errorContext) Error() string {
18+
return err.DebugMessage()
19+
}
20+
21+
// String implements [fmt.Stringer].
22+
func (err errorContext) String() string {
23+
return err.DebugMessage()
24+
}
25+
26+
// DebugMessage represents the Canonical ABI [error-context.debug-message] function.
27+
//
28+
// [error-context.debug-message]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#error-contextdebug-message
29+
func (err errorContext) DebugMessage() string {
30+
var s string
31+
errorContextDebugMessage(err, unsafe.Pointer(&s))
32+
return s
33+
}
34+
35+
//go:wasmimport canon error-context.debug-message
36+
//go:noescape
37+
func errorContextDebugMessage(err errorContext, msg unsafe.Pointer)
38+
39+
// Drop represents the Canonical ABI [error-context.drop] function.
40+
//
41+
// [error-context.drop]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#error-contextdrop
42+
func (err errorContext) Drop() {
43+
errorContextDrop(err)
44+
}
45+
46+
//go:wasmimport canon error-context.drop
47+
//go:noescape
48+
func errorContextDrop(err errorContext)

cm/future.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package cm
2+
3+
// Future represents the Component Model [future] type.
4+
// A future is a special case of stream. In non-error cases,
5+
// a future delivers exactly one value before being automatically closed.
6+
//
7+
// [future]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#asynchronous-value-types
8+
type Future[T any] struct {
9+
_ HostLayout
10+
future[T]
11+
}
12+
13+
type future[T any] uint32
14+
15+
// TODO: implement methods on type future

cm/stream.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package cm
2+
3+
// Stream represents the Component Model [stream] type.
4+
// A stream is a special case of stream. In non-error cases,
5+
// a stream delivers exactly one value before being automatically closed.
6+
//
7+
// [stream]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#asynchronous-value-types
8+
type Stream[T any] struct {
9+
_ HostLayout
10+
stream[T]
11+
}
12+
13+
type stream[T any] uint32
14+
15+
// TODO: implement methods on type stream

testdata/codegen/error-context.wit

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package foo:foo;
2+
3+
interface error-contexts {
4+
type foo = error-context;
5+
6+
bar: func(x: foo, y: error-context, z: future<error-context>) -> result<stream<error-context>, error-context>;
7+
}
8+
9+
world foo {
10+
import error-contexts;
11+
export error-contexts;
12+
}
13+
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
{
2+
"worlds": [
3+
{
4+
"name": "foo",
5+
"imports": {
6+
"interface-0": {
7+
"interface": {
8+
"id": 0
9+
}
10+
}
11+
},
12+
"exports": {
13+
"interface-0": {
14+
"interface": {
15+
"id": 0
16+
}
17+
}
18+
},
19+
"package": 0
20+
}
21+
],
22+
"interfaces": [
23+
{
24+
"name": "error-contexts",
25+
"types": {
26+
"foo": 0
27+
},
28+
"functions": {
29+
"bar": {
30+
"name": "bar",
31+
"kind": "freestanding",
32+
"params": [
33+
{
34+
"name": "x",
35+
"type": 0
36+
},
37+
{
38+
"name": "y",
39+
"type": 1
40+
},
41+
{
42+
"name": "z",
43+
"type": 2
44+
}
45+
],
46+
"results": [
47+
{
48+
"type": 4
49+
}
50+
]
51+
}
52+
},
53+
"package": 0
54+
}
55+
],
56+
"types": [
57+
{
58+
"name": "foo",
59+
"kind": "errorcontext",
60+
"owner": {
61+
"interface": 0
62+
}
63+
},
64+
{
65+
"name": null,
66+
"kind": "errorcontext",
67+
"owner": null
68+
},
69+
{
70+
"name": null,
71+
"kind": {
72+
"future": 1
73+
},
74+
"owner": null
75+
},
76+
{
77+
"name": null,
78+
"kind": {
79+
"stream": 1
80+
},
81+
"owner": null
82+
},
83+
{
84+
"name": null,
85+
"kind": {
86+
"result": {
87+
"ok": 3,
88+
"err": 1
89+
}
90+
},
91+
"owner": null
92+
}
93+
],
94+
"packages": [
95+
{
96+
"name": "foo:foo",
97+
"interfaces": {
98+
"error-contexts": 0
99+
},
100+
"worlds": {
101+
"foo": 0
102+
}
103+
}
104+
]
105+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package foo:foo;
2+
3+
interface error-contexts {
4+
type foo = error-context;
5+
bar: func(x: foo, y: error-context, z: future<error-context>) -> result<stream<error-context>, error-context>;
6+
}
7+
8+
world foo {
9+
import error-contexts;
10+
export error-contexts;
11+
}

0 commit comments

Comments
 (0)