From d63d8e08991ac27721066ba39522e0272d9510e4 Mon Sep 17 00:00:00 2001 From: Randy Reddig Date: Sun, 16 Mar 2025 13:35:44 -0700 Subject: [PATCH] internal/wasm-tools, internal/cm: udpate to go.bytecodealliance.org@v0.6.1 and cm@v0.2.1 --- GNUmakefile | 2 +- internal/wasm-tools/go.mod | 4 +-- internal/wasm-tools/go.sum | 8 +++--- src/internal/cm/case.go | 17 ++++++++---- src/internal/cm/list.go | 56 -------------------------------------- 5 files changed, 18 insertions(+), 69 deletions(-) diff --git a/GNUmakefile b/GNUmakefile index 7ac712e0c..1a97269e9 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -277,7 +277,7 @@ wasi-syscall: wasi-cm .PHONY: wasi-cm wasi-cm: rm -rf ./src/internal/cm/* - rsync -rv --delete --exclude go.mod --exclude '*_test.go' --exclude '*.md' --exclude LICENSE $(shell go list -modfile ./internal/wasm-tools/go.mod -m -f {{.Dir}} $(WASM_TOOLS_MODULE)/cm)/ ./src/internal/cm + rsync -rv --delete --exclude go.mod --exclude '*_test.go' --exclude '*_json.go' --exclude '*.md' --exclude LICENSE $(shell go list -modfile ./internal/wasm-tools/go.mod -m -f {{.Dir}} $(WASM_TOOLS_MODULE)/cm)/ ./src/internal/cm # Check for Node.js used during WASM tests. NODEJS_VERSION := $(word 1,$(subst ., ,$(shell node -v | cut -c 2-))) diff --git a/internal/wasm-tools/go.mod b/internal/wasm-tools/go.mod index 47ad4889c..c790a7ab0 100644 --- a/internal/wasm-tools/go.mod +++ b/internal/wasm-tools/go.mod @@ -3,8 +3,8 @@ module github.com/tinygo-org/tinygo/internal/wasm-tools go 1.23.0 require ( - go.bytecodealliance.org v0.6.0 - go.bytecodealliance.org/cm v0.2.0 + go.bytecodealliance.org v0.6.1 + go.bytecodealliance.org/cm v0.2.1 ) require ( diff --git a/internal/wasm-tools/go.sum b/internal/wasm-tools/go.sum index 45b74397d..3f2a32ded 100644 --- a/internal/wasm-tools/go.sum +++ b/internal/wasm-tools/go.sum @@ -29,10 +29,10 @@ github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc= github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= github.com/urfave/cli/v3 v3.0.0-beta1 h1:6DTaaUarcM0wX7qj5Hcvs+5Dm3dyUTBbEwIWAjcw9Zg= github.com/urfave/cli/v3 v3.0.0-beta1/go.mod h1:FnIeEMYu+ko8zP1F9Ypr3xkZMIDqW3DR92yUtY39q1Y= -go.bytecodealliance.org v0.6.0 h1:9ziqj963aEKqOiu5cl87Hb78KImNP4zEABl+OWwBwxk= -go.bytecodealliance.org v0.6.0/go.mod h1:j0lprXhqeVSE8kYN2EjcN9gm+fxUyNWtl//WA+3ypFg= -go.bytecodealliance.org/cm v0.2.0 h1:HMkj1x1LZWU/Ghu2TtUk3VTyS7gyDHLyIfIut0Cpc5M= -go.bytecodealliance.org/cm v0.2.0/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= +go.bytecodealliance.org v0.6.1 h1:H3vVYeEZa8Gs9t9YyZ4ZjA8sr5c6Xfkz3p+cM3543aA= +go.bytecodealliance.org v0.6.1/go.mod h1:qPL6PksrsjAxl6o23HuX4pGO6n3UxiESPbvRn8ZVot0= +go.bytecodealliance.org/cm v0.2.1 h1:sFUQRPfM+ku7hKgFwxGdwjghv4QtTLukpqsAHgE1Tek= +go.bytecodealliance.org/cm v0.2.1/go.mod h1:JD5vtVNZv7sBoQQkvBvAAVKJPhR/bqBH7yYXTItMfZI= golang.org/x/mod v0.24.0 h1:ZfthKaKaT4NrhGVZHO1/WDTwGES4De8KtWO0SIbNJMU= golang.org/x/mod v0.24.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww= golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w= diff --git a/src/internal/cm/case.go b/src/internal/cm/case.go index 65ade4949..fa212bb0c 100644 --- a/src/internal/cm/case.go +++ b/src/internal/cm/case.go @@ -1,7 +1,5 @@ package cm -import "errors" - // CaseUnmarshaler returns an function that can unmarshal text into // [variant] or [enum] case T. // @@ -33,8 +31,7 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te if len(text) == 0 { return errEmpty } - s := string(text) - c, ok := m[s] + c, ok := m[string(text)] if !ok { return errNoMatchingCase } @@ -46,6 +43,14 @@ func CaseUnmarshaler[T ~uint8 | ~uint16 | ~uint32](cases []string) func(v *T, te const linearScanThreshold = 16 var ( - errEmpty = errors.New("empty text") - errNoMatchingCase = errors.New("no matching case") + errEmpty = &stringError{"empty text"} + errNoMatchingCase = &stringError{"no matching case"} ) + +type stringError struct { + err string +} + +func (err *stringError) Error() string { + return err.err +} diff --git a/src/internal/cm/list.go b/src/internal/cm/list.go index 0a171dbd3..22d9d31f2 100644 --- a/src/internal/cm/list.go +++ b/src/internal/cm/list.go @@ -1,8 +1,6 @@ package cm import ( - "bytes" - "encoding/json" "unsafe" ) @@ -62,57 +60,3 @@ func (l list[T]) Data() *T { func (l list[T]) Len() uintptr { return l.len } - -// MarshalJSON implements json.Marshaler. -func (l list[T]) MarshalJSON() ([]byte, error) { - if l.len == 0 { - return []byte("[]"), nil - } - - s := l.Slice() - var zero T - if unsafe.Sizeof(zero) == 1 { - // The default Go json.Encoder will marshal []byte as base64. - // We override that behavior so all int types have the same serialization format. - // []uint8{1,2,3} -> [1,2,3] - // []uint32{1,2,3} -> [1,2,3] - return json.Marshal(sliceOf(s)) - } - return json.Marshal(s) -} - -type slice[T any] []entry[T] - -func sliceOf[S ~[]E, E any](s S) slice[E] { - return *(*slice[E])(unsafe.Pointer(&s)) -} - -type entry[T any] [1]T - -func (v entry[T]) MarshalJSON() ([]byte, error) { - return json.Marshal(v[0]) -} - -// UnmarshalJSON implements json.Unmarshaler. -func (l *list[T]) UnmarshalJSON(data []byte) error { - if bytes.Equal(data, nullLiteral) { - return nil - } - - var s []T - err := json.Unmarshal(data, &s) - if err != nil { - return err - } - - l.data = unsafe.SliceData([]T(s)) - l.len = uintptr(len(s)) - - return nil -} - -// nullLiteral is the JSON representation of a null literal. -// By convention, to approximate the behavior of Unmarshal itself, -// Unmarshalers implement UnmarshalJSON([]byte("null")) as a no-op. -// See https://pkg.go.dev/encoding/json#Unmarshaler for more information. -var nullLiteral = []byte("null")