Skip to content

Commit

Permalink
Merge pull request #16 from ydnar/ydnar/wasip2
Browse files Browse the repository at this point in the history
internal/wasi: regenerate WASI 0.2 bindings with explicit lift/lower code
  • Loading branch information
dgryski authored Jun 24, 2024
2 parents 1184f89 + 6921ce6 commit 11a6e1d
Show file tree
Hide file tree
Showing 35 changed files with 2,214 additions and 2,037 deletions.
28 changes: 20 additions & 8 deletions compiler/symbol.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ func (c *compilerContext) checkWasmImport(f *ssa.Function, pragma string) {
c.addError(f.Signature.Results().At(1).Pos(), fmt.Sprintf("%s: too many return values", pragma))
} else if f.Signature.Results().Len() == 1 {
result := f.Signature.Results().At(0)
if !isValidWasmType(result.Type(), true) {
if !isValidWasmType(result.Type(), false) {
c.addError(result.Pos(), fmt.Sprintf("%s: unsupported result type %s", pragma, result.Type().String()))
}
}
Expand All @@ -373,30 +373,42 @@ func (c *compilerContext) checkWasmImport(f *ssa.Function, pragma string) {
}
}

// Check whether the type maps directly to a WebAssembly type, according to:
// https://github.com/golang/go/issues/59149
// Check whether the type maps directly to a WebAssembly type.
//
// Update: this reflects the relaxed type restrictions proposed here:
// This reflects the relaxed type restrictions proposed here (except for structs.HostLayout):
// https://github.com/golang/go/issues/66984
func isValidWasmType(typ types.Type, isReturn bool) bool {
//
// This previously reflected the additional restrictions documented here:
// https://github.com/golang/go/issues/59149
func isValidWasmType(typ types.Type, isPointerOrField bool) bool {
switch typ := typ.Underlying().(type) {
case *types.Basic:
switch typ.Kind() {
case types.Bool:
return true
case types.Int8, types.Uint8, types.Int16, types.Uint16, types.Int32, types.Uint32, types.Int64, types.Uint64:
case types.Int, types.Uint, types.Int8, types.Uint8, types.Int16, types.Uint16, types.Int32, types.Uint32, types.Int64, types.Uint64:
return true
case types.Float32, types.Float64:
return true
case types.Uintptr, types.UnsafePointer:
return true
case types.String:
return true
return isPointerOrField
}
case *types.Array:
return isPointerOrField && isValidWasmType(typ.Elem(), true)
case *types.Struct:
if !isPointerOrField {
return false
}
for i := 0; i < typ.NumFields(); i++ {
if !isValidWasmType(typ.Field(i).Type(), true) {
return false
}
}
return true
case *types.Pointer:
return isValidWasmType(typ.Elem(), isReturn)
return isValidWasmType(typ.Elem(), true)
}
return false
}
Expand Down
6 changes: 6 additions & 0 deletions src/internal/wasi/cli/v0.2.0/command/command.wit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 23 additions & 26 deletions src/internal/wasi/cli/v0.2.0/environment/environment.wit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions src/internal/wasi/cli/v0.2.0/exit/exit.wit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions src/internal/wasi/cli/v0.2.0/run/run.exports.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 7 additions & 14 deletions src/internal/wasi/cli/v0.2.0/run/run.wit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 8 additions & 10 deletions src/internal/wasi/cli/v0.2.0/stderr/stderr.wit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 8 additions & 10 deletions src/internal/wasi/cli/v0.2.0/stdin/stdin.wit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 8 additions & 10 deletions src/internal/wasi/cli/v0.2.0/stdout/stdout.wit.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 11a6e1d

Please sign in to comment.