Skip to content

Commit c702be7

Browse files
committed
compiler: align with current wasm types proposal
golang/go#66984 - Remove int and uint as allowed types in params, results, pointers, or struct fields - Only allow small integers in pointers, arrays, or struct fields
1 parent d2dd19e commit c702be7

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

compiler/symbol.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -442,7 +442,9 @@ func isValidWasmType(typ types.Type, site wasmSite) bool {
442442
switch typ.Kind() {
443443
case types.Bool:
444444
return true
445-
case types.Int, types.Uint, types.Int8, types.Uint8, types.Int16, types.Uint16, types.Int32, types.Uint32, types.Int64, types.Uint64:
445+
case types.Int8, types.Uint8, types.Int16, types.Uint16:
446+
return site == siteIndirect
447+
case types.Int32, types.Uint32, types.Int64, types.Uint64:
446448
return true
447449
case types.Float32, types.Float64:
448450
return true

compiler/testdata/errors.go

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,28 @@ type Uint uint32
1616
type S struct {
1717
a [4]uint32
1818
b uintptr
19-
c int
2019
d float32
2120
e float64
2221
}
2322

2423
//go:wasmimport modulename validparam
25-
func validparam(a int32, b uint64, c float64, d unsafe.Pointer, e Uint, f uintptr, g string, h *int32, i *S)
24+
func validparam(a int32, b uint64, c float64, d unsafe.Pointer, e Uint, f uintptr, g string, h *int32, i *S, j *[8]uint8)
2625

2726
// ERROR: //go:wasmimport modulename invalidparam: unsupported parameter type [4]uint32
2827
// ERROR: //go:wasmimport modulename invalidparam: unsupported parameter type []byte
2928
// ERROR: //go:wasmimport modulename invalidparam: unsupported parameter type struct{a int}
3029
// ERROR: //go:wasmimport modulename invalidparam: unsupported parameter type chan struct{}
3130
// ERROR: //go:wasmimport modulename invalidparam: unsupported parameter type func()
31+
// ERROR: //go:wasmimport modulename invalidparam: unsupported parameter type int
32+
// ERROR: //go:wasmimport modulename invalidparam: unsupported parameter type uint
33+
// ERROR: //go:wasmimport modulename invalidparam: unsupported parameter type [8]int
3234
//
3335
//go:wasmimport modulename invalidparam
34-
func invalidparam(a [4]uint32, b []byte, c struct{ a int }, d chan struct{}, e func())
36+
func invalidparam(a [4]uint32, b []byte, c struct{ a int }, d chan struct{}, e func(), f int, g uint, h [8]int)
3537

3638
//go:wasmimport modulename validreturn_int32
3739
func validreturn_int32() int32
3840

39-
//go:wasmimport modulename validreturn_int
40-
func validreturn_int() int
41-
4241
//go:wasmimport modulename validreturn_ptr_int32
4342
func validreturn_ptr_int32() *int32
4443

@@ -48,6 +47,9 @@ func validreturn_ptr_string() *string
4847
//go:wasmimport modulename validreturn_ptr_struct
4948
func validreturn_ptr_struct() *S
5049

50+
//go:wasmimport modulename validreturn_ptr_array
51+
func validreturn_ptr_array() *[8]uint8
52+
5153
//go:wasmimport modulename validreturn_unsafe_pointer
5254
func validreturn_unsafe_pointer() unsafe.Pointer
5355

@@ -56,11 +58,26 @@ func validreturn_unsafe_pointer() unsafe.Pointer
5658
//go:wasmimport modulename manyreturns
5759
func manyreturns() (int32, int32)
5860

61+
// ERROR: //go:wasmimport modulename invalidreturn_int: unsupported result type int
62+
//
63+
//go:wasmimport modulename invalidreturn_int
64+
func invalidreturn_int() int
65+
66+
// ERROR: //go:wasmimport modulename invalidreturn_int: unsupported result type uint
67+
//
68+
//go:wasmimport modulename invalidreturn_int
69+
func invalidreturn_uint() uint
70+
5971
// ERROR: //go:wasmimport modulename invalidreturn_func: unsupported result type func()
6072
//
6173
//go:wasmimport modulename invalidreturn_func
6274
func invalidreturn_func() func()
6375

76+
// ERROR: //go:wasmimport modulename invalidreturn_pointer_array_int: unsupported result type *[8]int
77+
//
78+
//go:wasmimport modulename invalidreturn_pointer_array_int
79+
func invalidreturn_pointer_array_int() *[8]int
80+
6481
// ERROR: //go:wasmimport modulename invalidreturn_slice_byte: unsupported result type []byte
6582
//
6683
//go:wasmimport modulename invalidreturn_slice_byte

0 commit comments

Comments
 (0)