Skip to content

Commit

Permalink
add test for go1.23rc1
Browse files Browse the repository at this point in the history
  • Loading branch information
xhd2015 committed Jul 22, 2024
1 parent b2c1918 commit 2ccac8a
Show file tree
Hide file tree
Showing 42 changed files with 1,739 additions and 147 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/go-next.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go

name: Go Next

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:

tests-with-go-next:
strategy:
matrix:
os: [ ubuntu-latest]
go: [ '1.23rc1' ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3

- name: Set up Go
run: |
curl -fsSL -o go.tar.gz "https://go.dev/dl/go${{matrix.go}}.linux-amd64.tar.gz"
mkdir setup
tar -C setup -xzf go.tar.gz
ls setup
GOROOT=$PWD/setup/go PATH=$PWD/setup/go/bin:$PATH go version
- name: Test
run: GOROOT=$PWD/setup/go PATH=$PWD/setup/go/bin:$PATH go run ./script/run-test --reset-instrument --debug -v
4 changes: 2 additions & 2 deletions cmd/xgo/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -711,8 +711,8 @@ func checkGoVersion(goroot string, noInstrument bool) (*goinfo.GoVersion, error)
}
if !noInstrument {
minor := goVersion.Minor
if goVersion.Major != 1 || (minor < 17 || minor > 22) {
return nil, fmt.Errorf("only supports go1.17.0 ~ go1.22.1, current: %s", goVersionStr)
if goVersion.Major != 1 || (minor < 17 || minor > 23) {
return nil, fmt.Errorf("only supports go1.17 ~ go1.23, current: %s", goVersionStr)
}
}
return goVersion, nil
Expand Down
2 changes: 1 addition & 1 deletion cmd/xgo/patch.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func patchRuntimeAndCompiler(origGoroot string, goroot string, xgoSrc string, go
}

// runtime
err := patchRuntimeAndTesting(goroot, goVersion)
err := patchRuntimeAndTesting(origGoroot, goroot, goVersion)
if err != nil {
return err
}
Expand Down
6 changes: 4 additions & 2 deletions cmd/xgo/patch/runtime_def.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ func __xgo_get_pc_name_impl(pc uintptr) string {
`

// start with go1.21, the runtime.FuncForPC(pc).Name()
// was wrapped in funcNameForPrint(...), we unwrap it
// NOTE: when upgrading to go1.23, should check
// is wrapped in funcNameForPrint(...), we unwrap it.
// it is confirmed that in go1.21,go1.22 and go1.23,
// the name is wrapped.
// NOTE: when upgrading to go1.24, should check
// the implementation again
const RuntimeGetFuncName_Go121 = `
func __xgo_get_pc_name_impl(pc uintptr) string {
Expand Down
6 changes: 5 additions & 1 deletion cmd/xgo/patch_compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func patchGcMain(goroot string, goVersion *goinfo.GoVersion) error {
go120 := goVersion.Major == 1 && goVersion.Minor == 20
go121 := goVersion.Major == 1 && goVersion.Minor == 21
go122 := goVersion.Major == 1 && goVersion.Minor == 22
go123 := goVersion.Major == 1 && goVersion.Minor == 23

return editFile(file, func(content string) (string, error) {
imports := []string{
Expand Down Expand Up @@ -247,7 +248,7 @@ func patchGcMain(goroot string, goVersion *goinfo.GoVersion) error {
}else{`+flagNSwitch+`
}
`)
} else if go122 {
} else if go122 || go123 {
// go1.22 also does not respect rewritten content when inlined
// NOTE: the override of LowerL is inserted after xgo_patch.Patch()
content = addContentAfter(content,
Expand Down Expand Up @@ -286,6 +287,9 @@ func patchCompilerNoder(goroot string, goVersion *goinfo.GoVersion) error {
noderFiles = patch.NoderFiles_1_21
} else if minor == 22 {
noderFiles = patch.NoderFiles_1_21
} else if minor == 23 {
// TODO: verify
noderFiles = patch.NoderFiles_1_21
}
}
if noderFiles == "" {
Expand Down
69 changes: 56 additions & 13 deletions cmd/xgo/patch_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import (

"github.com/xhd2015/xgo/cmd/xgo/patch"
"github.com/xhd2015/xgo/support/filecopy"
"github.com/xhd2015/xgo/support/fileutil"
"github.com/xhd2015/xgo/support/goinfo"
ast_patch "github.com/xhd2015/xgo/support/transform/patch"
)

var xgoAutoGenRegisterFuncHelper = _FilePath{"src", "runtime", "__xgo_autogen_register_func_helper.go"}
Expand Down Expand Up @@ -57,12 +59,12 @@ var runtimeFiles = []_FilePath{
timeSleep,
}

func patchRuntimeAndTesting(goroot string, goVersion *goinfo.GoVersion) error {
func patchRuntimeAndTesting(origGoroot string, goroot string, goVersion *goinfo.GoVersion) error {
err := patchRuntimeProc(goroot, goVersion)
if err != nil {
return err
}
err = patchRuntimeTesting(goroot)
err = patchRuntimeTesting(origGoroot, goroot, goVersion)
if err != nil {
return err
}
Expand Down Expand Up @@ -114,8 +116,8 @@ func addRuntimeFunctions(goroot string, goVersion *goinfo.GoVersion, xgoSrc stri
}

// func name patch
if goVersion.Major > 1 || goVersion.Minor > 22 {
panic("should check the implementation of runtime.FuncForPC(pc).Name() to ensure __xgo_get_pc_name is not wrapped in print format above go1.22")
if goVersion.Major > 1 || goVersion.Minor > 23 {
panic("should check the implementation of runtime.FuncForPC(pc).Name() to ensure __xgo_get_pc_name is not wrapped in print format above go1.23,it is confirmed that in go1.21,go1.22 and go1.23 the name is wrapped in funcNameForPrint(...).")
}
if goVersion.Major > 1 || goVersion.Minor >= 21 {
content = append(content, []byte(patch.RuntimeGetFuncName_Go121)...)
Expand Down Expand Up @@ -149,14 +151,17 @@ func patchRuntimeProc(goroot string, goVersion *goinfo.GoVersion) error {
)

procDecl := `func newproc(fn`
newProc := `newg := newproc1(fn, gp, pc)`
if goVersion.Major == 1 && goVersion.Minor <= 17 {
// to avoid typo check
const size = "s" + "i" + "z"
procDecl = `func newproc(` + size + ` int32`
newProc = `newg := newproc1(fn, argp, ` + size + `, gp, pc)`
newProc := `newg := newproc1(fn, gp, pc, false, waitReasonZero)`
if goVersion.Major == 1 {
if goVersion.Minor <= 17 {
// to avoid typo check
const size = "s" + "i" + "z"
procDecl = `func newproc(` + size + ` int32`
newProc = `newg := newproc1(fn, argp, ` + size + `, gp, pc)`
} else if goVersion.Minor <= 22 {
newProc = `newg := newproc1(fn, gp, pc)`
}
}

// see https://github.com/xhd2015/xgo/issues/67
content = addContentAtIndex(
content,
Expand Down Expand Up @@ -206,8 +211,46 @@ func patchRuntimeProc(goroot string, goVersion *goinfo.GoVersion) error {
return nil
}

func patchRuntimeTesting(goroot string) error {
return testingFilePatch.Apply(goroot, nil)
func patchRuntimeTesting(origGoroot string, goroot string, goVersion *goinfo.GoVersion) error {
if goVersion.Major == 1 && goVersion.Minor <= 22 {
return testingFilePatch.Apply(goroot, nil)
}
// go 1.23
srcFile := testingFilePatch.FilePath.Join(origGoroot)
srcCode, err := fileutil.ReadFile(srcFile)
if err != nil {
return err
}
newCode, err := ast_patch.Patch(string(srcCode), `package testing
//prepend <define_callbacks>`+toInsertCode(patch.TestingCallbackDeclarations+patch.TestingEndCallbackDeclarations)+`
func tRunner(t *T, fn func(t *T)) {
//...
t.start = highPrecisionTimeNow()
//prepend <apply_callbacks>`+toInsertCode(patch.TestingStart+patch.TestingEnd)+`
fn(t)
}
`)
if err != nil {
return err
}
err = fileutil.WriteFile(testingFilePatch.FilePath.Join(goroot), []byte(newCode))
if err != nil {
return err
}
return nil
}

func toInsertCode(code string) string {
lines := strings.Split(code, "\n")
for i, line := range lines {
if i == 0 {
lines[i] = " " + line
} else {
lines[i] = "// " + line
}
}
return strings.Join(lines, "\n")
}

// only required if need to mock time.Sleep
Expand Down
4 changes: 2 additions & 2 deletions cmd/xgo/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import "fmt"

// auto updated
const VERSION = "1.0.46"
const REVISION = "ab32ad121c57c321089d61906f2dd36898b7bcd1+1"
const NUMBER = 294
const REVISION = "b2c1918871f0a8bc3ea4bb9cf46e297d21c5f433+1"
const NUMBER = 295

// manually updated
const CORE_VERSION = "1.0.43"
Expand Down
123 changes: 0 additions & 123 deletions patch/adapter_go1.22.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,128 +3,5 @@

package patch

import (
"go/constant"

"cmd/compile/internal/base"
"cmd/compile/internal/ir"
"cmd/compile/internal/reflectdata"
"cmd/compile/internal/typecheck"
"cmd/compile/internal/types"
"cmd/internal/src"
)

const goMajor = 1
const goMinor = 22

const genericTrapNeedsWorkaround = true
const closureMayBeEliminatedDueToIfConst = false

func forEachFunc(callback func(fn *ir.Func) bool) {
for _, fn := range typecheck.Target.Funcs {
if !callback(fn) {
return
}
}
}

// go 1.20 does not require type
func NewNilExpr(pos src.XPos, t *types.Type) *ir.NilExpr {
return ir.NewNilExpr(pos, t)
}

func AddFuncs(fn *ir.Func) {
typecheck.Target.Funcs = append(typecheck.Target.Funcs, fn)
}

func NewFunc(fpos, npos src.XPos, sym *types.Sym, typ *types.Type) *ir.Func {
return ir.NewFunc(fpos, npos, sym, typ)
}

func NewSignature(pkg *types.Pkg, recv *types.Field, tparams, params, results []*types.Field) *types.Type {
return types.NewSignature(recv, params, results)
}

func NewBasicLit(pos src.XPos, t *types.Type, val constant.Value) ir.Node {
return ir.NewBasicLit(pos, t, val)
}

// NOTE: []*types.Field instead of *types.Type(go1.21)
func takeAddrs(fn *ir.Func, t []*types.Field, nameOnly bool) ir.Expr {
if len(t) == 0 {
return NewNilExpr(fn.Pos(), intfSlice)
}
paramList := make([]ir.Node, len(t))
i := 0
ForEachField(t, func(field *types.Field) bool {
paramList[i] = takeAddr(fn, field, nameOnly)
i++
return true
})
return ir.NewCompLitExpr(fn.Pos(), ir.OCOMPLIT, intfSlice, paramList)
}

// NOTE: []*types.Field instead of *types.Type(go1.21)
func getFieldNames(pos src.XPos, fn *ir.Func, t []*types.Field) ir.Expr {
if len(t) == 0 {
return NewNilExpr(pos, strSlice)
}
paramList := make([]ir.Node, len(t))
i := 0
ForEachField(t, func(field *types.Field) bool {
fieldName := getFieldName(fn, field)
paramList[i] = NewStringLit(pos, fieldName)
i++
return true
})
return ir.NewCompLitExpr(pos, ir.OCOMPLIT, strSlice, paramList)
}

func getTypeNames(params []*types.Field) []ir.Node {
paramNames := make([]ir.Node, 0, len(params))
for _, p := range params {
paramNames = append(paramNames, p.Nname.(*ir.Name))
}
return paramNames
}

func ForEachField(params []*types.Field, callback func(field *types.Field) bool) {
n := len(params)
for i := 0; i < n; i++ {
if !callback(params[i]) {
return
}
}
}

func GetFieldIndex(fields []*types.Field, i int) *types.Field {
return fields[i]
}

func getCallee(callNode *ir.CallExpr) ir.Node {
return callNode.Fun
}

// TODO: maybe go1.22 does not need this
func SetConvTypeWordPtr(conv *ir.ConvExpr, t *types.Type) {
conv.TypeWord = reflectdata.TypePtrAt(base.Pos, types.NewPtr(t))
}
func SetConvTypeWord(conv *ir.ConvExpr, t *types.Type) {
conv.TypeWord = reflectdata.TypePtrAt(base.Pos, t)
}

func getFuncResultsType(funcType *types.Type) *types.Type {
panic("getFuncResultsType should not be called above go1.19")
}

func canInsertTrap(fn *ir.Func) bool {
return true
}

func NewNameAt(pos src.XPos, sym *types.Sym, typ *types.Type) *ir.Name {
return ir.NewNameAt(pos, sym, typ)
}

func isClosureWrapperForGeneric(fn *ir.Func) bool {
return false
}
Loading

0 comments on commit 2ccac8a

Please sign in to comment.