-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #277 from bytecodealliance/ydnar/async
all: initial support for async types
- Loading branch information
Showing
31 changed files
with
427 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// This file exists for testing this package without WebAssembly, | ||
// allowing empty function bodies with a //go:wasmimport directive. | ||
// See https://pkg.go.dev/cmd/compile for more information. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package cm | ||
|
||
import "unsafe" | ||
|
||
// ErrorContext represents the Component Model [error-context] type, | ||
// an immutable, non-deterministic, host-defined value meant to aid in debugging. | ||
// | ||
// [error-context]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#error-context-type | ||
type ErrorContext struct { | ||
_ HostLayout | ||
errorContext | ||
} | ||
|
||
type errorContext uint32 | ||
|
||
// Error implements the [error] interface. It returns the debug message associated with err. | ||
func (err errorContext) Error() string { | ||
return err.DebugMessage() | ||
} | ||
|
||
// String implements [fmt.Stringer]. | ||
func (err errorContext) String() string { | ||
return err.DebugMessage() | ||
} | ||
|
||
// DebugMessage represents the Canonical ABI [error-context.debug-message] function. | ||
// | ||
// [error-context.debug-message]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#error-contextdebug-message | ||
func (err errorContext) DebugMessage() string { | ||
var s string | ||
errorContextDebugMessage(err, unsafe.Pointer(&s)) | ||
return s | ||
} | ||
|
||
//go:wasmimport canon error-context.debug-message | ||
//go:noescape | ||
func errorContextDebugMessage(err errorContext, msg unsafe.Pointer) | ||
|
||
// Drop represents the Canonical ABI [error-context.drop] function. | ||
// | ||
// [error-context.drop]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#error-contextdrop | ||
func (err errorContext) Drop() { | ||
errorContextDrop(err) | ||
} | ||
|
||
//go:wasmimport canon error-context.drop | ||
//go:noescape | ||
func errorContextDrop(err errorContext) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cm | ||
|
||
// Future represents the Component Model [future] type. | ||
// A future is a special case of stream. In non-error cases, | ||
// a future delivers exactly one value before being automatically closed. | ||
// | ||
// [future]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#asynchronous-value-types | ||
type Future[T any] struct { | ||
_ HostLayout | ||
future[T] | ||
} | ||
|
||
type future[T any] uint32 | ||
|
||
// TODO: implement methods on type future |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package cm | ||
|
||
// Stream represents the Component Model [stream] type. | ||
// A stream is a special case of stream. In non-error cases, | ||
// a stream delivers exactly one value before being automatically closed. | ||
// | ||
// [stream]: https://github.com/WebAssembly/component-model/blob/main/design/mvp/Explainer.md#asynchronous-value-types | ||
type Stream[T any] struct { | ||
_ HostLayout | ||
stream[T] | ||
} | ||
|
||
type stream[T any] uint32 | ||
|
||
// TODO: implement methods on type stream |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package foo:foo; | ||
|
||
interface error-contexts { | ||
type foo = error-context; | ||
|
||
bar: func(x: foo, y: error-context, z: future<error-context>) -> result<stream<error-context>, error-context>; | ||
} | ||
|
||
world foo { | ||
import error-contexts; | ||
export error-contexts; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
{ | ||
"worlds": [ | ||
{ | ||
"name": "foo", | ||
"imports": { | ||
"interface-0": { | ||
"interface": { | ||
"id": 0 | ||
} | ||
} | ||
}, | ||
"exports": { | ||
"interface-0": { | ||
"interface": { | ||
"id": 0 | ||
} | ||
} | ||
}, | ||
"package": 0 | ||
} | ||
], | ||
"interfaces": [ | ||
{ | ||
"name": "error-contexts", | ||
"types": { | ||
"foo": 0 | ||
}, | ||
"functions": { | ||
"bar": { | ||
"name": "bar", | ||
"kind": "freestanding", | ||
"params": [ | ||
{ | ||
"name": "x", | ||
"type": 0 | ||
}, | ||
{ | ||
"name": "y", | ||
"type": 1 | ||
}, | ||
{ | ||
"name": "z", | ||
"type": 2 | ||
} | ||
], | ||
"results": [ | ||
{ | ||
"type": 4 | ||
} | ||
] | ||
} | ||
}, | ||
"package": 0 | ||
} | ||
], | ||
"types": [ | ||
{ | ||
"name": "foo", | ||
"kind": "errorcontext", | ||
"owner": { | ||
"interface": 0 | ||
} | ||
}, | ||
{ | ||
"name": null, | ||
"kind": "errorcontext", | ||
"owner": null | ||
}, | ||
{ | ||
"name": null, | ||
"kind": { | ||
"future": 1 | ||
}, | ||
"owner": null | ||
}, | ||
{ | ||
"name": null, | ||
"kind": { | ||
"stream": 1 | ||
}, | ||
"owner": null | ||
}, | ||
{ | ||
"name": null, | ||
"kind": { | ||
"result": { | ||
"ok": 3, | ||
"err": 1 | ||
} | ||
}, | ||
"owner": null | ||
} | ||
], | ||
"packages": [ | ||
{ | ||
"name": "foo:foo", | ||
"interfaces": { | ||
"error-contexts": 0 | ||
}, | ||
"worlds": { | ||
"foo": 0 | ||
} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package foo:foo; | ||
|
||
interface error-contexts { | ||
type foo = error-context; | ||
bar: func(x: foo, y: error-context, z: future<error-context>) -> result<stream<error-context>, error-context>; | ||
} | ||
|
||
world foo { | ||
import error-contexts; | ||
export error-contexts; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{ | ||
"worlds": [], | ||
"interfaces": [ | ||
{ | ||
"name": "error-contexts", | ||
"types": { | ||
"t1": 0 | ||
}, | ||
"functions": { | ||
"foo": { | ||
"name": "foo", | ||
"kind": "freestanding", | ||
"params": [ | ||
{ | ||
"name": "x", | ||
"type": 1 | ||
}, | ||
{ | ||
"name": "y", | ||
"type": 0 | ||
} | ||
], | ||
"results": [ | ||
{ | ||
"type": 2 | ||
} | ||
] | ||
} | ||
}, | ||
"package": 0 | ||
} | ||
], | ||
"types": [ | ||
{ | ||
"name": "t1", | ||
"kind": "errorcontext", | ||
"owner": { | ||
"interface": 0 | ||
} | ||
}, | ||
{ | ||
"name": null, | ||
"kind": "errorcontext", | ||
"owner": null | ||
}, | ||
{ | ||
"name": null, | ||
"kind": { | ||
"result": { | ||
"ok": null, | ||
"err": 1 | ||
} | ||
}, | ||
"owner": null | ||
} | ||
], | ||
"packages": [ | ||
{ | ||
"name": "foo:error-contexts", | ||
"interfaces": { | ||
"error-contexts": 0 | ||
}, | ||
"worlds": {} | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package foo:error-contexts; | ||
|
||
interface error-contexts { | ||
type t1 = error-context; | ||
foo: func(x: error-context, y: t1) -> result<_, error-context>; | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.