mirror of
https://github.com/golang/go
synced 2024-11-26 16:46:58 -07:00
[dev.typeparams] all: add GOEXPERIMENT=unified knob
Setting `-gcflags=all=-d=unified` works for normal builds/tests, but seems to have trouble with the test/run.go regress tests. So add a GOEXPERIMENT knob to allow another way to turn on unified IR construction, which plays better with all.bash. While here, update two existing test expectations that currently fail during GOEXPERIMENT=unified ./all.bash: 1. misc/cgo/errors/testdata/err2.go is testing column positions, and types2 gets one case slightly better, and another case slightly worse. For now, the test case is updated to accept both. 2. fixedbugs/issue42284.go is added to the list of known failures, because it fails for unified IR. (It's an escape analysis test, and escape analysis is working as expected; but unified is formatting an imported constant value differently than the test's regexp expects.) Updates #46786. Change-Id: I40a4a70fa1b85ac87fcc85a43687f5d81e011ec0 Reviewed-on: https://go-review.googlesource.com/c/go/+/328215 Run-TryBot: Matthew Dempsky <mdempsky@google.com> Trust: Matthew Dempsky <mdempsky@google.com> Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
This commit is contained in:
parent
b14fd720a8
commit
804ecc2581
12
misc/cgo/errors/testdata/err2.go
vendored
12
misc/cgo/errors/testdata/err2.go
vendored
@ -91,10 +91,18 @@ func main() {
|
|||||||
|
|
||||||
// issue 26745
|
// issue 26745
|
||||||
_ = func(i int) int {
|
_ = func(i int) int {
|
||||||
return C.i + 1 // ERROR HERE: 14
|
// typecheck reports at column 14 ('+'), but types2 reports at
|
||||||
|
// column 10 ('C').
|
||||||
|
// TODO(mdempsky): Investigate why, and see if types2 can be
|
||||||
|
// updated to match typecheck behavior.
|
||||||
|
return C.i + 1 // ERROR HERE: \b(10|14)\b
|
||||||
}
|
}
|
||||||
_ = func(i int) {
|
_ = func(i int) {
|
||||||
C.fi(i) // ERROR HERE: 7
|
// typecheck reports at column 7 ('('), but types2 reports at
|
||||||
|
// column 8 ('i'). The types2 position is more correct, but
|
||||||
|
// updating typecheck here is fundamentally challenging because of
|
||||||
|
// IR limitations.
|
||||||
|
C.fi(i) // ERROR HERE: \b(7|8)\b
|
||||||
}
|
}
|
||||||
|
|
||||||
C.fi = C.fi // ERROR HERE
|
C.fi = C.fi // ERROR HERE
|
||||||
|
@ -159,7 +159,11 @@ func ParseFlags() {
|
|||||||
Flag.LinkShared = &Ctxt.Flag_linkshared
|
Flag.LinkShared = &Ctxt.Flag_linkshared
|
||||||
Flag.Shared = &Ctxt.Flag_shared
|
Flag.Shared = &Ctxt.Flag_shared
|
||||||
Flag.WB = true
|
Flag.WB = true
|
||||||
|
|
||||||
Debug.InlFuncsWithClosures = 1
|
Debug.InlFuncsWithClosures = 1
|
||||||
|
if buildcfg.Experiment.Unified {
|
||||||
|
Debug.Unified = 1
|
||||||
|
}
|
||||||
|
|
||||||
Debug.Checkptr = -1 // so we can tell whether it is set explicitly
|
Debug.Checkptr = -1 // so we can tell whether it is set explicitly
|
||||||
|
|
||||||
|
9
src/internal/goexperiment/exp_unified_off.go
Normal file
9
src/internal/goexperiment/exp_unified_off.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// Code generated by mkconsts.go. DO NOT EDIT.
|
||||||
|
|
||||||
|
//go:build !goexperiment.unified
|
||||||
|
// +build !goexperiment.unified
|
||||||
|
|
||||||
|
package goexperiment
|
||||||
|
|
||||||
|
const Unified = false
|
||||||
|
const UnifiedInt = 0
|
9
src/internal/goexperiment/exp_unified_on.go
Normal file
9
src/internal/goexperiment/exp_unified_on.go
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
// Code generated by mkconsts.go. DO NOT EDIT.
|
||||||
|
|
||||||
|
//go:build goexperiment.unified
|
||||||
|
// +build goexperiment.unified
|
||||||
|
|
||||||
|
package goexperiment
|
||||||
|
|
||||||
|
const Unified = true
|
||||||
|
const UnifiedInt = 1
|
@ -59,6 +59,10 @@ type Flags struct {
|
|||||||
PreemptibleLoops bool
|
PreemptibleLoops bool
|
||||||
StaticLockRanking bool
|
StaticLockRanking bool
|
||||||
|
|
||||||
|
// Unified enables the compiler's unified IR construction
|
||||||
|
// experiment.
|
||||||
|
Unified bool
|
||||||
|
|
||||||
// Regabi is split into several sub-experiments that can be
|
// Regabi is split into several sub-experiments that can be
|
||||||
// enabled individually. Not all combinations work.
|
// enabled individually. Not all combinations work.
|
||||||
// The "regabi" GOEXPERIMENT is an alias for all "working"
|
// The "regabi" GOEXPERIMENT is an alias for all "working"
|
||||||
|
54
test/run.go
54
test/run.go
@ -60,6 +60,7 @@ func defaultAllCodeGen() bool {
|
|||||||
var (
|
var (
|
||||||
goos, goarch string
|
goos, goarch string
|
||||||
cgoEnabled bool
|
cgoEnabled bool
|
||||||
|
unifiedEnabled bool
|
||||||
|
|
||||||
// dirs are the directories to look for *.go files in.
|
// dirs are the directories to look for *.go files in.
|
||||||
// TODO(bradfitz): just use all directories?
|
// TODO(bradfitz): just use all directories?
|
||||||
@ -95,10 +96,27 @@ func main() {
|
|||||||
|
|
||||||
goos = getenv("GOOS", runtime.GOOS)
|
goos = getenv("GOOS", runtime.GOOS)
|
||||||
goarch = getenv("GOARCH", runtime.GOARCH)
|
goarch = getenv("GOARCH", runtime.GOARCH)
|
||||||
cgoEnv, err := exec.Command(goTool(), "env", "CGO_ENABLED").Output()
|
|
||||||
if err == nil {
|
cgoCmd := exec.Command(goTool(), "env", "CGO_ENABLED")
|
||||||
cgoEnabled, _ = strconv.ParseBool(strings.TrimSpace(string(cgoEnv)))
|
cgoEnv, err := cgoCmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("running %v: %v", cgoCmd, err)
|
||||||
}
|
}
|
||||||
|
cgoEnabled, _ = strconv.ParseBool(strings.TrimSpace(string(cgoEnv)))
|
||||||
|
|
||||||
|
// TODO(mdempsky): Change this to just "go env GOEXPERIMENT" after
|
||||||
|
// CL 328751 is merged back to dev.typeparams. In the mean time, we
|
||||||
|
// infer whether the "unified" experiment is defult enabled by
|
||||||
|
// inspecting the output from `go tool compile -V`.
|
||||||
|
compileCmd := exec.Command(goTool(), "tool", "compile", "-V")
|
||||||
|
compileOutput, err := compileCmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("running %v: %v", compileCmd, err)
|
||||||
|
}
|
||||||
|
// TODO(mdempsky): This will give false negatives if the unified
|
||||||
|
// experiment is enabled by default, but presumably at that point we
|
||||||
|
// won't need to disable tests for it anymore anyway.
|
||||||
|
unifiedEnabled = strings.Contains(string(compileOutput), "unified")
|
||||||
|
|
||||||
findExecCmd()
|
findExecCmd()
|
||||||
|
|
||||||
@ -290,6 +308,10 @@ type test struct {
|
|||||||
err error
|
err error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// usesTypes2 reports whether the compiler uses types2 for this test
|
||||||
|
// configuration (irrespective of flags specified by the test itself).
|
||||||
|
func (t *test) usesTypes2() bool { return unifiedEnabled || t.glevel != 0 }
|
||||||
|
|
||||||
func startTests(dir, gofile string, glevels []int) []*test {
|
func startTests(dir, gofile string, glevels []int) []*test {
|
||||||
tests := make([]*test, len(glevels))
|
tests := make([]*test, len(glevels))
|
||||||
for i, glevel := range glevels {
|
for i, glevel := range glevels {
|
||||||
@ -519,8 +541,8 @@ func (t *test) run() {
|
|||||||
close(t.donec)
|
close(t.donec)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
if t.glevel > 0 && !*force {
|
if t.usesTypes2() && !*force {
|
||||||
// Files excluded from generics testing.
|
// Files excluded from types2 testing.
|
||||||
filename := strings.Replace(t.goFileName(), "\\", "/", -1) // goFileName() uses \ on Windows
|
filename := strings.Replace(t.goFileName(), "\\", "/", -1) // goFileName() uses \ on Windows
|
||||||
if excludedFiles[filename] {
|
if excludedFiles[filename] {
|
||||||
if *verbose {
|
if *verbose {
|
||||||
@ -666,27 +688,35 @@ func (t *test) run() {
|
|||||||
// at the specified -G level. If so, it may update flags as
|
// at the specified -G level. If so, it may update flags as
|
||||||
// necessary to test with -G.
|
// necessary to test with -G.
|
||||||
validForGLevel := func(tool Tool) bool {
|
validForGLevel := func(tool Tool) bool {
|
||||||
if t.glevel == 0 {
|
if !t.usesTypes2() {
|
||||||
// default -G level; always valid
|
// tests should always pass when run w/o types2 (i.e., using the
|
||||||
|
// legacy typechecker).
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
hasGFlag := false
|
||||||
for _, flag := range flags {
|
for _, flag := range flags {
|
||||||
if strings.Contains(flag, "-G") {
|
if strings.Contains(flag, "-G") {
|
||||||
// test provides explicit -G flag already
|
hasGFlag = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if hasGFlag && t.glevel != 0 {
|
||||||
|
// test provides explicit -G flag already; don't run again
|
||||||
if *verbose {
|
if *verbose {
|
||||||
fmt.Printf("excl\t%s\n", t.goFileName())
|
fmt.Printf("excl\t%s\n", t.goFileName())
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
switch tool {
|
switch tool {
|
||||||
case Build, Run:
|
case Build, Run:
|
||||||
// ok; handled in goGcflags
|
// ok; handled in goGcflags
|
||||||
|
|
||||||
case Compile:
|
case Compile:
|
||||||
|
if !hasGFlag {
|
||||||
flags = append(flags, fmt.Sprintf("-G=%v", t.glevel))
|
flags = append(flags, fmt.Sprintf("-G=%v", t.glevel))
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// we don't know how to add -G for this test yet
|
// we don't know how to add -G for this test yet
|
||||||
@ -2026,6 +2056,9 @@ func overlayDir(dstRoot, srcRoot string) error {
|
|||||||
|
|
||||||
// List of files that the compiler cannot errorcheck with the new typechecker (compiler -G option).
|
// List of files that the compiler cannot errorcheck with the new typechecker (compiler -G option).
|
||||||
// Temporary scaffolding until we pass all the tests at which point this map can be removed.
|
// Temporary scaffolding until we pass all the tests at which point this map can be removed.
|
||||||
|
//
|
||||||
|
// TODO(mdempsky): Split exclude list to disambiguate whether the
|
||||||
|
// failure is within types2, -G=3, or unified.
|
||||||
var excludedFiles = map[string]bool{
|
var excludedFiles = map[string]bool{
|
||||||
"directive.go": true, // misplaced compiler directive checks
|
"directive.go": true, // misplaced compiler directive checks
|
||||||
"float_lit3.go": true, // types2 reports extra errors
|
"float_lit3.go": true, // types2 reports extra errors
|
||||||
@ -2079,10 +2112,11 @@ var excludedFiles = map[string]bool{
|
|||||||
"fixedbugs/issue33460.go": true, // types2 reports alternative positions in separate error
|
"fixedbugs/issue33460.go": true, // types2 reports alternative positions in separate error
|
||||||
"fixedbugs/issue42058a.go": true, // types2 doesn't report "channel element type too large"
|
"fixedbugs/issue42058a.go": true, // types2 doesn't report "channel element type too large"
|
||||||
"fixedbugs/issue42058b.go": true, // types2 doesn't report "channel element type too large"
|
"fixedbugs/issue42058b.go": true, // types2 doesn't report "channel element type too large"
|
||||||
"fixedbugs/issue46725.go": true, // fix applied to typecheck needs to be ported to irgen/transform
|
"fixedbugs/issue42284.go": true, // unified formats important constant expression differently in diagnostics
|
||||||
"fixedbugs/issue4232.go": true, // types2 reports (correct) extra errors
|
"fixedbugs/issue4232.go": true, // types2 reports (correct) extra errors
|
||||||
"fixedbugs/issue4452.go": true, // types2 reports (correct) extra errors
|
"fixedbugs/issue4452.go": true, // types2 reports (correct) extra errors
|
||||||
"fixedbugs/issue4510.go": true, // types2 reports different (but ok) line numbers
|
"fixedbugs/issue4510.go": true, // types2 reports different (but ok) line numbers
|
||||||
|
"fixedbugs/issue46725.go": true, // fix applied to typecheck needs to be ported to irgen/transform
|
||||||
"fixedbugs/issue5609.go": true, // types2 needs a better error message
|
"fixedbugs/issue5609.go": true, // types2 needs a better error message
|
||||||
"fixedbugs/issue7525b.go": true, // types2 reports init cycle error on different line - ok otherwise
|
"fixedbugs/issue7525b.go": true, // types2 reports init cycle error on different line - ok otherwise
|
||||||
"fixedbugs/issue7525c.go": true, // types2 reports init cycle error on different line - ok otherwise
|
"fixedbugs/issue7525c.go": true, // types2 reports init cycle error on different line - ok otherwise
|
||||||
|
Loading…
Reference in New Issue
Block a user