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 644da2d commit 4c9281c
Show file tree
Hide file tree
Showing 44 changed files with 1,775 additions and 170 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
10 changes: 10 additions & 0 deletions cmd/xgo/go_build.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import (
"path/filepath"
)

const GO_MAJOR_1 = 1
const GO_VERSION_16 = 16 // unspported

Check warning on line 10 in cmd/xgo/go_build.go

View workflow job for this annotation

GitHub Actions / check-build

"unspported" should be "unsupported".
const GO_VERSION_17 = 17
const GO_VERSION_18 = 18
const GO_VERSION_19 = 19
const GO_VERSION_20 = 20
const GO_VERSION_21 = 21
const GO_VERSION_22 = 22
const GO_VERSION_23 = 23

func buildCompiler(goroot string, output string) error {
args := []string{"build"}
if isDevelopment {
Expand Down
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
7 changes: 5 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 Expand Up @@ -200,6 +202,7 @@ if os.Getenv("XGO_COMPILER_ENABLE")=="true" {
}
`

// only missing in go1.21 and below
const NodesGen = `
func (n *node) SetPos(p Pos) {
n.pos = p
Expand Down
46 changes: 25 additions & 21 deletions cmd/xgo/patch_compiler.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func patchCompilerInternal(goroot string, goVersion *goinfo.GoVersion) error {
if err != nil {
return fmt.Errorf("patching noder: %w", err)
}
if goVersion.Major == 1 && (goVersion.Minor == 18 || goVersion.Minor == 19) {
if goVersion.Major == GO_MAJOR_1 && (goVersion.Minor == GO_VERSION_18 || goVersion.Minor == GO_VERSION_19) {
err := poatchIRGenericGen(goroot, goVersion)
if err != nil {
return fmt.Errorf("patching generic trap: %w", err)
Expand Down Expand Up @@ -120,16 +120,16 @@ func getInternalPatch(goroot string, subDirs ...string) string {
}

func patchSyntaxNode(goroot string, goVersion *goinfo.GoVersion) error {
if goVersion.Major > 1 || goVersion.Minor >= 22 {
if goVersion.Major > 1 || goVersion.Minor >= GO_VERSION_22 {
return nil
}
var fragments []string

if goVersion.Major == 1 {
if goVersion.Minor < 22 {
if goVersion.Minor <= GO_VERSION_21 {
fragments = append(fragments, patch.NodesGen)
}
if goVersion.Minor <= 17 {
if goVersion.Minor <= GO_VERSION_17 {
fragments = append(fragments, patch.Nodes_Inspect_117)
}
}
Expand All @@ -142,14 +142,15 @@ func patchSyntaxNode(goroot string, goVersion *goinfo.GoVersion) error {

func patchGcMain(goroot string, goVersion *goinfo.GoVersion) error {
file := filepath.Join(goroot, filepath.Join(gcMain...))
go116AndUnder := goVersion.Major == 1 && goVersion.Minor <= 16
go117 := goVersion.Major == 1 && goVersion.Minor == 17
go118 := goVersion.Major == 1 && goVersion.Minor == 18
go119 := goVersion.Major == 1 && goVersion.Minor == 19
go119AndUnder := goVersion.Major == 1 && goVersion.Minor <= 19
go120 := goVersion.Major == 1 && goVersion.Minor == 20
go121 := goVersion.Major == 1 && goVersion.Minor == 21
go122 := goVersion.Major == 1 && goVersion.Minor == 22
go116AndUnder := goVersion.Major == 1 && goVersion.Minor <= GO_VERSION_16
go117 := goVersion.Major == 1 && goVersion.Minor == GO_VERSION_17
go118 := goVersion.Major == 1 && goVersion.Minor == GO_VERSION_18
go119 := goVersion.Major == 1 && goVersion.Minor == GO_VERSION_19
go119AndUnder := goVersion.Major == 1 && goVersion.Minor <= GO_VERSION_19
go120 := goVersion.Major == GO_MAJOR_1 && goVersion.Minor == GO_VERSION_20
go121 := goVersion.Major == GO_MAJOR_1 && goVersion.Minor == GO_VERSION_21
go122 := goVersion.Major == GO_MAJOR_1 && goVersion.Minor == GO_VERSION_22
go123 := goVersion.Major == GO_MAJOR_1 && goVersion.Minor == GO_VERSION_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 All @@ -269,22 +270,25 @@ func patchGcMain(goroot string, goVersion *goinfo.GoVersion) error {
func patchCompilerNoder(goroot string, goVersion *goinfo.GoVersion) error {
files := []string(noderFile)
var noderFiles string
if goVersion.Major == 1 {
if goVersion.Major == GO_MAJOR_1 {
minor := goVersion.Minor
if minor == 16 {
if minor == GO_VERSION_16 {
files = []string(noderFile16)
noderFiles = patch.NoderFiles_1_17
} else if minor == 17 {
} else if minor == GO_VERSION_17 {
noderFiles = patch.NoderFiles_1_17
} else if minor == 18 {
} else if minor == GO_VERSION_18 {
noderFiles = patch.NoderFiles_1_17
} else if minor == 19 {
} else if minor == GO_VERSION_19 {
noderFiles = patch.NoderFiles_1_17
} else if minor == 20 {
} else if minor == GO_VERSION_20 {
noderFiles = patch.NoderFiles_1_20
} else if minor == 21 {
} else if minor == GO_VERSION_21 {
noderFiles = patch.NoderFiles_1_21
} else if minor == GO_VERSION_22 {
noderFiles = patch.NoderFiles_1_21
} else if minor == 22 {
} else if minor == GO_VERSION_23 {
// TODO: verify
noderFiles = patch.NoderFiles_1_21
}
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/xgo/patch_compiler_ast_type_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ var syntaxPrinterPatch = &FilePatch{
p.printRawNode(n.X)
`,
CheckGoVersion: func(goVersion *goinfo.GoVersion) bool {
return goVersion.Major == 1 && goVersion.Minor <= 22
return goVersion.Major == GO_MAJOR_1 && goVersion.Minor <= GO_VERSION_23
},
},
},
Expand Down Expand Up @@ -383,13 +383,13 @@ func patchCompilerForConstTrap(goroot string, goVersion *goinfo.GoVersion) error
if err != nil {
return err
}
if goVersion.Major == 1 && goVersion.Minor <= 21 {
if goVersion.Major == GO_MAJOR_1 && goVersion.Minor <= GO_VERSION_21 {
err = noderExprPatch.Apply(goroot, goVersion)
if err != nil {
return err
}
}
if goVersion.Major == 1 && goVersion.Minor <= 22 {
if goVersion.Major == GO_MAJOR_1 && goVersion.Minor <= GO_VERSION_23 {
err = syntaxPrinterPatch.Apply(goroot, goVersion)
if err != nil {
return err
Expand Down
71 changes: 58 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 > GO_MAJOR_1 || goVersion.Minor > GO_VERSION_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,19 @@ 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 == GO_MAJOR_1 {
if goVersion.Minor <= GO_VERSION_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 <= GO_VERSION_22 {
newProc = `newg := newproc1(fn, gp, pc)`
} else if goVersion.Minor <= GO_VERSION_23 {
newProc = `newg := newproc1(fn, gp, pc, false, waitReasonZero)`
}
}

// see https://github.com/xhd2015/xgo/issues/67
content = addContentAtIndex(
content,
Expand Down Expand Up @@ -206,8 +213,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 == GO_MAJOR_1 && goVersion.Minor <= GO_VERSION_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 = "b2c1918871f0a8bc3ea4bb9cf46e297d21c5f433+1"
const NUMBER = 295
const REVISION = "644da2d2357b7ad0c9fb4b72995bf0b526fc4cf4+1"
const NUMBER = 296

// manually updated
const CORE_VERSION = "1.0.43"
Expand Down
Loading

0 comments on commit 4c9281c

Please sign in to comment.