From 64e0f75ab4b1bf53fac681631ae7bfcd33beb663 Mon Sep 17 00:00:00 2001 From: Grant Nelson Date: Wed, 8 Nov 2023 13:09:17 -0700 Subject: [PATCH] Adding v1.19 transition for reflect and reflectlite Reduced to v1.19 only Update Go version to 1.19.13 to begin work on Go 1.19 support. --- .github/workflows/lint.yaml | 2 +- .github/workflows/measure-size.yml | 2 +- README.md | 12 ++++---- circle.yml | 2 +- .../src/internal/reflectlite/reflectlite.go | 29 +++++++++---------- compiler/natives/src/reflect/reflect.go | 23 +++++++-------- compiler/version_check.go | 7 ++--- 7 files changed, 37 insertions(+), 40 deletions(-) diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 5f6c971e7..03fa75d9c 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -12,7 +12,7 @@ jobs: - uses: actions/setup-go@v3 with: - go-version: "1.18.10" + go-version: "1.19.13" - name: golangci-lint uses: golangci/golangci-lint-action@v3 diff --git a/.github/workflows/measure-size.yml b/.github/workflows/measure-size.yml index d193b0df6..ee4024e6a 100644 --- a/.github/workflows/measure-size.yml +++ b/.github/workflows/measure-size.yml @@ -11,7 +11,7 @@ jobs: fetch-depth: 0 - uses: actions/setup-go@v2 with: - go-version: '~1.18.10' + go-version: '~1.19.13' - uses: gopherjs/output-size-action/measure@main with: name: jQuery TodoMVC diff --git a/README.md b/README.md index 63c5aabee..f29bb9084 100644 --- a/README.md +++ b/README.md @@ -31,21 +31,21 @@ Nearly everything, including Goroutines ([compatibility documentation](https://g ### Installation and Usage -GopherJS [requires Go 1.18 or newer](https://github.com/gopherjs/gopherjs/blob/master/doc/compatibility.md#go-version-compatibility). If you need an older Go +GopherJS [requires Go 1.19 or newer](https://github.com/gopherjs/gopherjs/blob/master/doc/compatibility.md#go-version-compatibility). If you need an older Go version, you can use an [older GopherJS release](https://github.com/gopherjs/gopherjs/releases). Install GopherJS with `go install`: ``` -go install github.com/gopherjs/gopherjs@v1.18.0-beta3 # Or replace 'v1.18.0-beta3' with another version. +go install github.com/gopherjs/gopherjs@v1.19.0-alpha1 # Or replace 'v1.19.0-alpha1' with another version. ``` -If your local Go distribution as reported by `go version` is newer than Go 1.18, then you need to set the `GOPHERJS_GOROOT` environment variable to a directory that contains a Go 1.18 distribution. For example: +If your local Go distribution as reported by `go version` is newer than Go 1.19, then you need to set the `GOPHERJS_GOROOT` environment variable to a directory that contains a Go 1.19 distribution. For example: ``` -go install golang.org/dl/go1.18.10@latest -go1.18.10 download -export GOPHERJS_GOROOT="$(go1.18.10 env GOROOT)" # Also add this line to your .profile or equivalent. +go install golang.org/dl/go1.19.13@latest +go1.19.13 download +export GOPHERJS_GOROOT="$(go1.19.13 env GOROOT)" # Also add this line to your .profile or equivalent. ``` Now you can use `gopherjs build [package]`, `gopherjs build [files]` or `gopherjs install [package]` which behave similar to the `go` tool. For `main` packages, these commands create a `.js` file and `.js.map` source map in the current directory or in `$GOPATH/bin`. The generated JavaScript file can be used as usual in a website. Use `gopherjs help [command]` to get a list of possible command line flags, e.g. for minification and automatically watching for changes. diff --git a/circle.yml b/circle.yml index 12b0aa45f..62031ce4b 100644 --- a/circle.yml +++ b/circle.yml @@ -54,7 +54,7 @@ workflows: parameters: go_version: type: string - default: "1.18.10" + default: "1.19.13" nvm_version: type: string default: "0.38.0" diff --git a/compiler/natives/src/internal/reflectlite/reflectlite.go b/compiler/natives/src/internal/reflectlite/reflectlite.go index 0be1eb09b..d48f15987 100644 --- a/compiler/natives/src/internal/reflectlite/reflectlite.go +++ b/compiler/natives/src/internal/reflectlite/reflectlite.go @@ -50,7 +50,7 @@ func reflectType(typ *js.Object) *rtype { rt := &rtype{ size: uintptr(typ.Get("size").Int()), kind: uint8(typ.Get("kind").Int()), - str: newNameOff(newName(internalStr(typ.Get("string")), "", typ.Get("exported").Bool())), + str: newNameOff(newName(internalStr(typ.Get("string")), "", typ.Get("exported").Bool(), false)), } js.InternalObject(rt).Set(idJsType, typ) typ.Set(idReflectType, js.InternalObject(rt)) @@ -69,7 +69,7 @@ func reflectType(typ *js.Object) *rtype { continue } reflectMethods = append(reflectMethods, method{ - name: newNameOff(newName(internalStr(m.Get("name")), "", exported)), + name: newNameOff(newName(internalStr(m.Get("name")), "", exported, false)), mtyp: newTypeOff(reflectType(m.Get("typ"))), }) } @@ -81,12 +81,12 @@ func reflectType(typ *js.Object) *rtype { continue } reflectMethods = append(reflectMethods, method{ - name: newNameOff(newName(internalStr(m.Get("name")), "", exported)), + name: newNameOff(newName(internalStr(m.Get("name")), "", exported, false)), mtyp: newTypeOff(reflectType(m.Get("typ"))), }) } ut := &uncommonType{ - pkgPath: newNameOff(newName(internalStr(typ.Get("pkg")), "", false)), + pkgPath: newNameOff(newName(internalStr(typ.Get("pkg")), "", false, false)), mcount: uint16(methodSet.Length()), xcount: xcount, _methods: reflectMethods, @@ -141,13 +141,13 @@ func reflectType(typ *js.Object) *rtype { for i := range imethods { m := methods.Index(i) imethods[i] = imethod{ - name: newNameOff(newName(internalStr(m.Get("name")), "", internalStr(m.Get("pkg")) == "")), + name: newNameOff(newName(internalStr(m.Get("name")), "", internalStr(m.Get("pkg")) == "", false)), typ: newTypeOff(reflectType(m.Get("typ"))), } } setKindType(rt, &interfaceType{ rtype: *rt, - pkgPath: newName(internalStr(typ.Get("pkg")), "", false), + pkgPath: newName(internalStr(typ.Get("pkg")), "", false, false), methods: imethods, }) case Map: @@ -168,19 +168,15 @@ func reflectType(typ *js.Object) *rtype { reflectFields := make([]structField, fields.Length()) for i := range reflectFields { f := fields.Index(i) - offsetEmbed := uintptr(i) << 1 - if f.Get("embedded").Bool() { - offsetEmbed |= 1 - } reflectFields[i] = structField{ - name: newName(internalStr(f.Get("name")), internalStr(f.Get("tag")), f.Get("exported").Bool()), - typ: reflectType(f.Get("typ")), - offsetEmbed: offsetEmbed, + name: newName(internalStr(f.Get("name")), internalStr(f.Get("tag")), f.Get("exported").Bool(), f.Get("embedded").Bool()), + typ: reflectType(f.Get("typ")), + offset: uintptr(i), } } setKindType(rt, &structType{ rtype: *rt, - pkgPath: newName(internalStr(typ.Get("pkgPath")), "", false), + pkgPath: newName(internalStr(typ.Get("pkgPath")), "", false, false), fields: reflectFields, }) } @@ -242,6 +238,7 @@ type nameData struct { name string tag string exported bool + embedded bool } var nameMap = make(map[*byte]*nameData) @@ -250,13 +247,15 @@ func (n name) name() (s string) { return nameMap[n.bytes].name } func (n name) tag() (s string) { return nameMap[n.bytes].tag } func (n name) pkgPath() string { return "" } func (n name) isExported() bool { return nameMap[n.bytes].exported } +func (n name) embedded() bool { return nameMap[n.bytes].embedded } -func newName(n, tag string, exported bool) name { +func newName(n, tag string, exported, embedded bool) name { b := new(byte) nameMap[b] = &nameData{ name: n, tag: tag, exported: exported, + embedded: embedded, } return name{ bytes: b, diff --git a/compiler/natives/src/reflect/reflect.go b/compiler/natives/src/reflect/reflect.go index 3261d70ca..ed5a90835 100644 --- a/compiler/natives/src/reflect/reflect.go +++ b/compiler/natives/src/reflect/reflect.go @@ -63,7 +63,7 @@ func reflectType(typ *js.Object) *rtype { rt := &rtype{ size: uintptr(typ.Get("size").Int()), kind: uint8(typ.Get("kind").Int()), - str: resolveReflectName(newName(internalStr(typ.Get("string")), "", typ.Get("exported").Bool())), + str: resolveReflectName(newName(internalStr(typ.Get("string")), "", typ.Get("exported").Bool(), false)), } js.InternalObject(rt).Set("jsType", typ) typ.Set("reflectType", js.InternalObject(rt)) @@ -99,7 +99,7 @@ func reflectType(typ *js.Object) *rtype { }) } ut := &uncommonType{ - pkgPath: resolveReflectName(newName(internalStr(typ.Get("pkg")), "", false)), + pkgPath: resolveReflectName(newName(internalStr(typ.Get("pkg")), "", false, false)), mcount: uint16(methodSet.Length()), xcount: xcount, _methods: reflectMethods, @@ -160,7 +160,7 @@ func reflectType(typ *js.Object) *rtype { } setKindType(rt, &interfaceType{ rtype: *rt, - pkgPath: newName(internalStr(typ.Get("pkg")), "", false), + pkgPath: newName(internalStr(typ.Get("pkg")), "", false, false), methods: imethods, }) case Map: @@ -181,19 +181,15 @@ func reflectType(typ *js.Object) *rtype { reflectFields := make([]structField, fields.Length()) for i := range reflectFields { f := fields.Index(i) - offsetEmbed := uintptr(i) << 1 - if f.Get("embedded").Bool() { - offsetEmbed |= 1 - } reflectFields[i] = structField{ - name: newName(internalStr(f.Get("name")), internalStr(f.Get("tag")), f.Get("exported").Bool()), - typ: reflectType(f.Get("typ")), - offsetEmbed: offsetEmbed, + name: newName(internalStr(f.Index.Get("name")), internalStr(f.Get("tag")), f.Get("exported").Bool(), f.Get("embedded").Bool()), + typ: reflectType(f.Get("typ")), + offset: uintptr(i), } } setKindType(rt, &structType{ rtype: *rt, - pkgPath: newName(internalStr(typ.Get("pkgPath")), "", false), + pkgPath: newName(internalStr(typ.Get("pkgPath")), "", false, false), fields: reflectFields, }) } @@ -257,6 +253,7 @@ type nameData struct { name string tag string exported bool + embedded bool pkgPath string } @@ -266,16 +263,18 @@ func (n name) name() (s string) { return nameMap[n.bytes].name } func (n name) tag() (s string) { return nameMap[n.bytes].tag } func (n name) pkgPath() string { return nameMap[n.bytes].pkgPath } func (n name) isExported() bool { return nameMap[n.bytes].exported } +func (n name) embedded() bool { return nameMap[n.bytes].embedded } func (n name) setPkgPath(pkgpath string) { nameMap[n.bytes].pkgPath = pkgpath } -func newName(n, tag string, exported bool) name { +func newName(n, tag string, exported, embedded bool) name { b := new(byte) nameMap[b] = &nameData{ name: n, tag: tag, exported: exported, + embedded: embedded, } return name{ bytes: b, diff --git a/compiler/version_check.go b/compiler/version_check.go index 536bfddca..36bd4acd3 100644 --- a/compiler/version_check.go +++ b/compiler/version_check.go @@ -1,5 +1,4 @@ -//go:build go1.18 -// +build go1.18 +//go:build go1.19 package compiler @@ -13,10 +12,10 @@ import ( ) // Version is the GopherJS compiler version string. -const Version = "1.18.0-beta3+go1.18.10" +const Version = "1.19.0-alpha1+go1.19.13" // GoVersion is the current Go 1.x version that GopherJS is compatible with. -const GoVersion = 18 +const GoVersion = 19 // CheckGoVersion checks the version of the Go distribution // at goroot, and reports an error if it's not compatible