Skip to content

Commit

Permalink
Merge pull request #255 from visualfc/go121
Browse files Browse the repository at this point in the history
support Go1.21
  • Loading branch information
visualfc authored Sep 13, 2023
2 parents 324155a + 9589e30 commit 7a0ea7b
Show file tree
Hide file tree
Showing 416 changed files with 101,685 additions and 420 deletions.
110 changes: 110 additions & 0 deletions .github/workflows/go121.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Go1.21

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:

macos:
name: Test Go1.21 for macOS
runs-on: macos-latest
steps:

- name: Set up Go 1.21
uses: actions/setup-go@v2
with:
go-version: 1.21.x

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Build
run: go build -v .

- name: Install igop
run: go install -v ./cmd/igop

- name: Go Test
run: GOARCH=amd64 go test -race -v .

- name: Test $GOROOT/test
run: GOARCH=amd64 go run ./cmd/igoptest

linux:
name: Test Go1.21 for Linux
runs-on: ubuntu-latest
steps:

- name: Set up Go 1.21
uses: actions/setup-go@v2
with:
go-version: 1.21.x

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Build
run: go build -v .

- name: Install igop
run: go install -v ./cmd/igop

- name: Go Test amd64
run: GOARCH=amd64 go test -race -v .

- name: Test $GOROOT/test
run: GOARCH=amd64 go run ./cmd/igoptest

windows:
name: Test Go1.21 for Windows
runs-on: windows-latest
steps:

- name: Set up Go 1.21
uses: actions/setup-go@v2
with:
go-version: 1.21.x

- name: Check out code into the Go module directory
uses: actions/checkout@v2

- name: Get dependencies
run: |
go get -v -t -d ./...
- name: Build
run: go build -v .

- name: Install igop
run: go install -v ./cmd/igop

- name: Go Test amd64
run: |
set GOARCH=amd64
go test -race -v .
- name: Test $GOROOT/test amd64
run: |
set GOARCH=amd64
go run ./cmd/igoptest
- name: Go Test 386
run: |
set GOARCH=386
go test -v .
- name: Go $GOROOT/test 386
run: |
set GOARCH=386
go run ./cmd/igoptest
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
[![Go1.18](https://github.com/goplus/igop/workflows/Go1.18/badge.svg)](https://github.com/goplus/igop/actions/workflows/go118.yml)
[![Go1.19](https://github.com/goplus/igop/workflows/Go1.19/badge.svg)](https://github.com/goplus/igop/actions/workflows/go119.yml)
[![Go1.20](https://github.com/goplus/igop/workflows/Go1.20/badge.svg)](https://github.com/goplus/igop/actions/workflows/go120.yml)
[![Go1.21](https://github.com/goplus/igop/workflows/Go1.21/badge.svg)](https://github.com/goplus/igop/actions/workflows/go121.yml)
[![Go Reference](https://pkg.go.dev/badge/github.com/goplus/igop.svg)](https://pkg.go.dev/github.com/goplus/igop)


### Go Version

- Go1.14 ~ Go1.20
- Go1.14 ~ Go1.21
- macOS Linux Windows WebAssembly GopherJS and more.

### ABI
Expand All @@ -26,10 +27,11 @@ support ABI0 and ABIInternal
- Go1.18: amd64 arm64 ppc64/ppc64le
- Go1.19: amd64 arm64 ppc64/ppc64le riscv64
- Go1.20: amd64 arm64 ppc64/ppc64le riscv64
- Go1.21: amd64 arm64 ppc64/ppc64le riscv64

### Generics

- support generics (Go1.18/Go1.19/Go1.20)
- support generics (Go1.18/Go1.19/Go1.20/Go1.21)
- support [Go1.20 nested type-parameterized declarations](https://github.com/golang/go/blob/master/test/typeparam/nested.go) on Go1.18/Go1.19 (Experimental)

### runtime.GC
Expand Down
7 changes: 7 additions & 0 deletions builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,11 +552,18 @@ func (interp *Interp) callBuiltinByStack(caller *frame, fn string, ssaArgs []ssa
panic(err)
}
caller.setReg(ir, uintptr(offset))
case "clear":
arg0 := caller.reg(ia[0])
valueClear(reflect.ValueOf(arg0))
default:
panic("unknown built-in: " + fn)
}
}

func valueClear(v reflect.Value) {
reflect.ValueOf(v).MethodByName("Clear").Call(nil)
}

const ptrSize = 4 << (^uintptr(0) >> 63)

const maxUintptr = ^uintptr(0)
Expand Down
5 changes: 4 additions & 1 deletion cmd/igoptest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func init() {

ver := runtime.Version()[:6]
switch ver {
case "go1.17", "go1.18", "go1.19", "go1.20":
case "go1.17", "go1.18", "go1.19", "go1.20", "go1.21":
// gorootTestSkips["fixedbugs/issue45045.go"] = "runtime.SetFinalizer"
// gorootTestSkips["fixedbugs/issue46725.go"] = "runtime.SetFinalizer"
gorootTestSkips["abi/fibish.go"] = "slow, 34s"
Expand All @@ -86,6 +86,9 @@ func init() {
gorootTestSkips["typeparam/cons.go"] = "skip golang.org/x/tools v0.7.0 on go1.18"
gorootTestSkips["typeparam/list2.go"] = "skip golang.org/x/tools v0.7.0 on go1.18"
}
if ver == "go1.21" {
gorootTestSkips["fixedbugs/issue19658.go"] = "skip command"
}
case "go1.16":
gorootTestSkips["fixedbugs/issue7740.go"] = "BUG, const float"
case "go1.15":
Expand Down
40 changes: 37 additions & 3 deletions cmd/internal/export/exportpkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,16 @@ var (
)

func exportPkg(pkg *Package, sname string, id string, tagList []string) ([]byte, error) {
imports := []string{fmt.Sprintf("%v %q\n", sname, pkg.Path)}
imports = append(imports, `"reflect"`)
var imports []string
if pkg.usedPkg {
imports = append(imports, fmt.Sprintf("q %q", pkg.Path))
imports = append(imports, "")
} else {
imports = append(imports, fmt.Sprintf("_ %q", pkg.Path))
}
if !pkg.IsEmpty() {
imports = append(imports, `"reflect"`)
}
if len(pkg.UntypedConsts) > 0 || len(pkg.TypedConsts) > 0 {
imports = append(imports, `"go/constant"`)
var hasToken bool
Expand All @@ -73,10 +81,12 @@ func exportPkg(pkg *Package, sname string, id string, tagList []string) ([]byte,
tmpl := template_pkg
if pkg.IsEmpty() {
tmpl = template_empty_pkg
imports = []string{fmt.Sprintf("_ %q", pkg.Path)}
}
if len(pkg.Source) > 0 {
tmpl = template_link_pkg
if pkg.IsEmpty() {
tmpl = template_emtpy_link_pkg
}
if len(pkg.Links) > 0 {
imports = append(imports, `_ "unsafe"`)
}
Expand Down Expand Up @@ -183,3 +193,27 @@ func init() {
$LINKS
var source = $SOURCE
`

var template_emtpy_link_pkg = `// export by github.com/goplus/igop/cmd/qexp
$TAGS
package $PKGNAME
import (
$IMPORTS
"github.com/goplus/igop"
)
func init() {
igop.RegisterPackage(&igop.Package {
Name: "$PKGNAME",
Path: "$PKGPATH",
Deps: map[string]string{$DEPS},
Source: source,
})
}
$LINKS
var source = $SOURCE
`
9 changes: 7 additions & 2 deletions cmd/internal/export/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,14 @@ type Package struct {
UntypedConsts []string
Links []string
Source string
usedPkg bool
}

func (p *Package) IsEmpty() bool {
return len(p.NamedTypes) == 0 && len(p.Interfaces) == 0 &&
len(p.AliasTypes) == 0 && len(p.Vars) == 0 &&
len(p.Funcs) == 0 && len(p.Consts) == 0 &&
len(p.TypedConsts) == 0 && len(p.UntypedConsts) == 0 &&
len(p.Source) == 0
len(p.TypedConsts) == 0 && len(p.UntypedConsts) == 0
}

/*
Expand Down Expand Up @@ -369,8 +369,10 @@ func (p *Program) ExportPkg(path string, sname string) (*Package, error) {
} else {
e.TypedConsts = append(e.TypedConsts, fmt.Sprintf("%q : {reflect.TypeOf(%v), %v}", t.Name(), pkgName+"."+t.Name(), p.constToLit(named, t.Val())))
}
e.usedPkg = true
case *types.Var:
e.Vars = append(e.Vars, fmt.Sprintf("%q : reflect.ValueOf(&%v)", t.Name(), pkgName+"."+t.Name()))
e.usedPkg = true
case *types.Func:
if hasTypeParam(t.Type()) {
if !flagExportSource {
Expand All @@ -380,6 +382,7 @@ func (p *Program) ExportPkg(path string, sname string) (*Package, error) {
continue
}
e.Funcs = append(e.Funcs, fmt.Sprintf("%q : reflect.ValueOf(%v)", t.Name(), pkgName+"."+t.Name()))
e.usedPkg = true
case *types.TypeName:
if hasTypeParam(t.Type()) {
if !flagExportSource {
Expand All @@ -398,6 +401,7 @@ func (p *Program) ExportPkg(path string, sname string) (*Package, error) {
default:
e.AliasTypes = append(e.AliasTypes, fmt.Sprintf("%q: reflect.TypeOf((*%v.%v)(nil)).Elem()", name, sname, name))
}
e.usedPkg = true
continue
}
typeName := t.Name()
Expand All @@ -406,6 +410,7 @@ func (p *Program) ExportPkg(path string, sname string) (*Package, error) {
} else {
e.NamedTypes = append(e.NamedTypes, fmt.Sprintf("%q : reflect.TypeOf((*%v.%v)(nil)).Elem()", typeName, pkgName, typeName))
}
e.usedPkg = true
default:
log.Panicf("unreachable %v %T\n", name, t)
}
Expand Down
15 changes: 12 additions & 3 deletions cmd/internal/export/typeparam_go118.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,22 @@ import (
)

func hasTypeParam(t types.Type) bool {
switch t := t.(type) {
switch t1 := t.(type) {
case *types.TypeParam:
return true
case *types.Named:
return t.TypeParams() != nil
if i, ok := t.Underlying().(*types.Interface); ok {
for n := 0; n < i.NumEmbeddeds(); n++ {
if hasTypeParam(i.EmbeddedType(n)) {
return true
}
}
}
return t1.TypeParams() != nil
case *types.Signature:
return t.TypeParams() != nil
return t1.TypeParams() != nil
case *types.Union:
return true
}
return false
}
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.14
require (
github.com/goplus/gop v1.1.6
github.com/goplus/gox v1.11.37
github.com/goplus/reflectx v1.1.1
github.com/goplus/reflectx v1.2.1
github.com/modern-go/reflect2 v1.0.2
github.com/peterh/liner v1.2.2
github.com/qiniu/x v1.11.9
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ github.com/goplus/libc v0.3.13/go.mod h1:xqG4/g3ilKBE/UDn5vkaE7RRQPQPyspj7ecuMuv
github.com/goplus/mod v0.9.12/go.mod h1:YoPIowz71rnLLROA4YG0AC8bzDtPRyMaQwgTRLr8ri4=
github.com/goplus/mod v0.11.2 h1:kgIdro905lTZgqGecTbZ416O8ayN+ca2DR5OB4ayeWI=
github.com/goplus/mod v0.11.2/go.mod h1:d40I3nOr2qkGfLUjwc/BqLSq3oUUlQy5+/SpdiBKgY4=
github.com/goplus/reflectx v1.1.1 h1:4acdcG7+uIHdl7le1vAEt9M2HwGWNlVqv1fd4YsdCg0=
github.com/goplus/reflectx v1.1.1/go.mod h1:wHOS9ilbB4zrecI0W1dMmkW9JMcpXV7VjALVbNU9xfM=
github.com/goplus/reflectx v1.2.1 h1:y3Bq7cmP/zO++VFpZetC3zljVM3LkGivh2GgUJLu4wI=
github.com/goplus/reflectx v1.2.1/go.mod h1:wHOS9ilbB4zrecI0W1dMmkW9JMcpXV7VjALVbNU9xfM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/mattn/go-runewidth v0.0.3 h1:a+kO+98RDGEfo6asOGMmpodZq4FNtnGP54yps8BzLR4=
github.com/mattn/go-runewidth v0.0.3/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU=
Expand Down
49 changes: 49 additions & 0 deletions interp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2636,3 +2636,52 @@ func main() {
}
t.Log("cancel context:", err)
}

func TestReflectArray(t *testing.T) {
var src = `package main
import (
"reflect"
"fmt"
)
type IntArray [2]int
func (i IntArray) String() string {
return fmt.Sprintf("(%v,%v)", i[0], i[1])
}
func (i *IntArray) Set(x, y int) {
*(*int)(&i[0]), *(*int)(&i[1]) = x, y
}
func (i IntArray) Get() (int, int) {
return i[0], i[1]
}
func (i IntArray) Scale(v int) IntArray {
return IntArray{i[0] * v, i[1] * v}
}
func main() {
var a IntArray
a.Set(100,200)
b := a.Scale(5)
if b[0] != 500 || b[1] != 1000 {
panic("error")
}
typ := reflect.TypeOf((*IntArray)(nil)).Elem()
v := reflect.New(typ).Elem()
v.Addr().MethodByName("Set").Call([]reflect.Value{reflect.ValueOf(100),reflect.ValueOf(200)})
x := v.MethodByName("Scale").Call([]reflect.Value{reflect.ValueOf(5)})
if x[0].Index(0).Int() != 500 || x[0].Index(1).Int() != 1000 {
panic("error reflect")
}
}
`
ctx := igop.NewContext(0)
_, err := ctx.RunFile("main.go", src, nil)
if err != nil {
t.Fatal(err)
}
}
4 changes: 2 additions & 2 deletions pkg/archive/tar/go120_export.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// export by github.com/goplus/igop/cmd/qexp

//go:build go1.20
// +build go1.20
//go:build go1.20 && !go1.21
// +build go1.20,!go1.21

package tar

Expand Down
Loading

0 comments on commit 7a0ea7b

Please sign in to comment.