diff --git a/.github/workflows/nightly-test.yml b/.github/workflows/nightly-test.yml index a4ec990b..6cdccbc4 100644 --- a/.github/workflows/nightly-test.yml +++ b/.github/workflows/nightly-test.yml @@ -28,7 +28,7 @@ jobs: - uses: actions/checkout@v4 with: path: xgo - ref: master + ref: fix-const-expr-type-recognition - name: Set up Go uses: actions/setup-go@v4 @@ -39,6 +39,7 @@ jobs: run: | cd xgo go install ./cmd/xgo + xgo exec --reset-instrument --log-debug go version xgo revision - uses: actions/checkout@v4 @@ -48,7 +49,11 @@ jobs: - name: Test pocketbase/pocketbase continue-on-error: true - run: cd pocketbase/pocketbase && xgo test -v ./... + run: | + cd pocketbase/pocketbase + xgo test -v ./... + echo $? > test-exit-code.txt + echo "exit code is $(cat test-exit-code.txt)" - uses: actions/checkout@v4 with: @@ -57,7 +62,12 @@ jobs: - name: Test gohugoio/hugo continue-on-error: true - run: cd gohugoio/hugo && xgo test -v ./... + run: | + cd gohugoio/hugo + xgo test -v ./... + echo $? > test-exit-code.txt + echo "exit code is $?" + echo "exit code is $(cat test-exit-code.txt)" - uses: actions/checkout@v4 with: @@ -66,5 +76,15 @@ jobs: - name: Test kubernetes/kubernetes continue-on-error: true - run: cd kubernetes/kubernetes && xgo test -v ./... - \ No newline at end of file + run: | + cd kubernetes/kubernetes + xgo test -v ./... + echo $? > test-exit-code.txt + echo "exit code is $(cat test-exit-code.txt)" + + - name: Summary + run: | + echo "exit code:" + echo " pocketbase/pocketbase: $(cat pocketbase/pocketbase/test-exit-code.txt)" + echo " gohugoio/hugo: $(cat gohugoio/hugo/test-exit-code.txt)" + echo " kubernetes/kubernetes: $(cat kubernetes/kubernetes/test-exit-code.txt)" \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index bc78c57a..d84b2610 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -25,7 +25,7 @@ go run -tags dev ./cmd/xgo help go test -tags dev -run TestHelloWorld -v ./test ``` -NOTE: when developing, always add `-tags dev` to tell go that we building with dev mode. +NOTE: when developing, always add `-tags dev` to tell go that we are building in dev mode. If you want to check instrumented GOROOT, run: ```sh @@ -53,7 +53,7 @@ We can also explicitly specify all expected go versions we want to pass: go run ./script/run-test/ --include go1.17.13 --include go1.18.10 --include go1.19.13 --include go1.20.14 --include go1.21.8 --include go1.22.1 ``` -If there were testing cache, we can force the test re-run by adding a `-count=1` flag: +If there were testing cache, we can force the test to re-run by adding a `-count=1` flag: ```sh go run ./script/run-test/ --include go1.17.13 --include go1.18.10 --include go1.19.13 --include go1.20.14 --include go1.21.8 --include go1.22.1 -count=1 ``` diff --git a/cmd/xgo/patch_compiler_ast_type_check.go b/cmd/xgo/patch_compiler_ast_type_check.go index a25684a9..ff75718f 100644 --- a/cmd/xgo/patch_compiler_ast_type_check.go +++ b/cmd/xgo/patch_compiler_ast_type_check.go @@ -305,6 +305,7 @@ var noderExprPatch = &FilePatch{ }, } +// /Users/xhd2015/.xgo/go-instrument-dev/go1.22.2_Us_xh_Pr_xh_xg_go_go_e9d4e1e8/go1.22.2/src/cmd/compile/internal/syntax/printer.go var syntaxPrinterPatch = &FilePatch{ FilePath: _FilePath{"src", "cmd", "compile", "internal", "syntax", "printer.go"}, Patches: []*Patch{ @@ -321,7 +322,7 @@ var syntaxPrinterPatch = &FilePatch{ p.printRawNode(n.X) `, CheckGoVersion: func(goVersion *goinfo.GoVersion) bool { - return goVersion.Major == 1 && goVersion.Minor <= 21 + return goVersion.Major == 1 && goVersion.Minor <= 22 }, }, }, @@ -387,6 +388,8 @@ func patchCompilerForConstTrap(goroot string, goVersion *goinfo.GoVersion) error if err != nil { return err } + } + if goVersion.Major == 1 && goVersion.Minor <= 22 { err = syntaxPrinterPatch.Apply(goroot, goVersion) if err != nil { return err diff --git a/cmd/xgo/runtime_gen/core/version.go b/cmd/xgo/runtime_gen/core/version.go index f73a70e2..a1eefbf7 100755 --- a/cmd/xgo/runtime_gen/core/version.go +++ b/cmd/xgo/runtime_gen/core/version.go @@ -7,8 +7,8 @@ import ( ) const VERSION = "1.0.37" -const REVISION = "63941402b67d43bbac6c7d3eb342916bff70f2a3+1" -const NUMBER = 233 +const REVISION = "cf49f7ce9b237a85a242c245e9846294b3c8347b+1" +const NUMBER = 234 // these fields will be filled by compiler const XGO_VERSION = "" diff --git a/cmd/xgo/version.go b/cmd/xgo/version.go index 69a5f44e..621eccf0 100644 --- a/cmd/xgo/version.go +++ b/cmd/xgo/version.go @@ -3,8 +3,8 @@ package main import "fmt" const VERSION = "1.0.37" -const REVISION = "63941402b67d43bbac6c7d3eb342916bff70f2a3+1" -const NUMBER = 233 +const REVISION = "cf49f7ce9b237a85a242c245e9846294b3c8347b+1" +const NUMBER = 234 func getRevision() string { revSuffix := "" diff --git a/patch/syntax/vars.go b/patch/syntax/vars.go index bf6512c4..66ac2b05 100644 --- a/patch/syntax/vars.go +++ b/patch/syntax/vars.go @@ -832,6 +832,19 @@ func getConstDeclValueType(expr syntax.Expr) string { return "bool" } // NOTE: nil is not a constant + case *syntax.Operation: + // binary operation + if isBoolOp(expr.Op) { + return "bool" + } + if expr.X != nil { + return getConstDeclValueType(expr.X) + } + if expr.Y != nil { + return getConstDeclValueType(expr.Y) + } + case *syntax.ParenExpr: + return getConstDeclValueType(expr.X) } return "" } diff --git a/runtime/core/version.go b/runtime/core/version.go index f73a70e2..a1eefbf7 100644 --- a/runtime/core/version.go +++ b/runtime/core/version.go @@ -7,8 +7,8 @@ import ( ) const VERSION = "1.0.37" -const REVISION = "63941402b67d43bbac6c7d3eb342916bff70f2a3+1" -const NUMBER = 233 +const REVISION = "cf49f7ce9b237a85a242c245e9846294b3c8347b+1" +const NUMBER = 234 // these fields will be filled by compiler const XGO_VERSION = "" diff --git a/runtime/test/bugs/hugoio/hugio_math.go b/runtime/test/bugs/hugoio/hugio_math.go new file mode 100644 index 00000000..ade83905 --- /dev/null +++ b/runtime/test/bugs/hugoio/hugio_math.go @@ -0,0 +1,13 @@ +package hugoio + +const ( + bias = 1023 + shift = 64 - 11 - 1 +) + +func round(x float64) { + var e uint + + if e < bias+shift { + } +} diff --git a/runtime/test/bugs/hugoio/hugio_math_test.go b/runtime/test/bugs/hugoio/hugio_math_test.go new file mode 100644 index 00000000..1cd01982 --- /dev/null +++ b/runtime/test/bugs/hugoio/hugio_math_test.go @@ -0,0 +1,9 @@ +// see https://github.com/xhd2015/xgo/issues/142#issuecomment-2128262593 + +package hugoio + +import "testing" + +func TestRound(t *testing.T) { + round(0) +} diff --git a/runtime/test/bugs/pocketbase/pocketbase_schema.go b/runtime/test/bugs/pocketbase/pocketbase_schema.go new file mode 100644 index 00000000..9089f726 --- /dev/null +++ b/runtime/test/bugs/pocketbase/pocketbase_schema.go @@ -0,0 +1,15 @@ +// see https://github.com/xhd2015/xgo/issues/142 +package pocketbase + +const DefaultDateLayout = "2006-01-02 15:04:05.000Z" + +// from https://github.com/pocketbase/pocketbase/blob/4937acb3e2685273998506b715e2b54e33174172/models/schema/schema_field.go#L591 +func chainedConst() { + // the problem only appears when chained const with + // following call with arg + wrap(DefaultDateLayout).Min(nil) +} + +func wrap(e string) interface{ Min(t interface{}) } { + return nil +} diff --git a/runtime/test/debug/debug_test.go b/runtime/test/debug/debug_test.go index bcf75e1a..63d9f2c9 100644 --- a/runtime/test/debug/debug_test.go +++ b/runtime/test/debug/debug_test.go @@ -5,25 +5,12 @@ package debug -import ( - "testing" +const DefaultDateLayout = "2006-01-02 15:04:05.000Z" - "github.com/xhd2015/xgo/runtime/mock" - "github.com/xhd2015/xgo/runtime/test/mock_var/sub" -) - -var c sub.Mapping = sub.Mapping{ - 1: "hello", +func chainedConst() { + wrap(DefaultDateLayout).Min(nil) } -func TestThirdPartyTypeMethodVar(t *testing.T) { - mock.Patch(&c, func() sub.Mapping { - return sub.Mapping{ - 1: "mock", - } - }) - txt := c.Get(1) - if txt != "mock" { - t.Fatalf("expect c[1] to be %s, actual: %s", "mock", txt) - } +func wrap(e string) interface{ Min(t interface{}) } { + return nil } diff --git a/script/download-go/main.go b/script/download-go/main.go index 5822260a..6855810b 100644 --- a/script/download-go/main.go +++ b/script/download-go/main.go @@ -128,7 +128,7 @@ func downloadGo(cmd string, version string) error { return err } - goTmpDir, err := os.MkdirTemp("", "go") + goTmpDir, err := os.MkdirTemp(".", "go") if err != nil { return err } diff --git a/script/run-test/main.go b/script/run-test/main.go index 7ff9734c..7d782219 100644 --- a/script/run-test/main.go +++ b/script/run-test/main.go @@ -97,6 +97,12 @@ var extraSubTests = []*TestCase{ dir: "runtime/test/trap_stdlib_any", flags: []string{"--trap-stdlib"}, }, + { + // see https://github.com/xhd2015/xgo/issues/142 + name: "bugs_regression", + dir: "runtime/test/bugs", + flags: []string{"./..."}, + }, } func main() {