]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: flip the default value of GODEBUG=gotypesalias=1
authorAlan Donovan <adonovan@google.com>
Tue, 9 Apr 2024 19:20:21 +0000 (15:20 -0400)
committerAlan Donovan <adonovan@google.com>
Mon, 15 Apr 2024 19:56:15 +0000 (19:56 +0000)
This CL changes the interpretation of the unset value
of gotypesalias to equal "1". The actual deletion of
all the transitional logic will happen in a follow-up.

Note that the compiler still interprets unset as "0".
More work appears to be required within the compiler
before it is safe to flip its default.

Change-Id: I854ab1fd856c7c361a757676b0670e2f23402816
Reviewed-on: https://go-review.googlesource.com/c/go/+/577715
Reviewed-by: Robert Findley <rfindley@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Commit-Queue: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/go/internal/gcimporter/ureader.go
src/go/types/api_test.go
src/go/types/check.go
src/go/types/check_test.go
src/go/types/decl.go
src/go/types/eval_test.go
src/go/types/issues_test.go
src/internal/godebugs/table.go

index b7d7b6c86178f784fbf759151b578d189440dc8a..738dc54d9c779415cb2d10c4853576f2a1538324 100644 (file)
@@ -659,9 +659,10 @@ func pkgScope(pkg *types.Package) *types.Scope {
 
 // newAliasTypeName returns a new TypeName, with a materialized *types.Alias if supported.
 func newAliasTypeName(pos token.Pos, pkg *types.Package, name string, rhs types.Type) *types.TypeName {
-       // When GODEBUG=gotypesalias=1, the Type() of the return value is a
+       // When GODEBUG=gotypesalias=1 or unset, the Type() of the return value is a
        // *types.Alias. Copied from x/tools/internal/aliases.NewAlias.
-       if godebug.New("gotypesalias").Value() == "1" {
+       switch godebug.New("gotypesalias").Value() {
+       case "", "1":
                tname := types.NewTypeName(pos, pkg, name, nil)
                _ = types.NewAlias(tname, rhs) // form TypeName -> Alias cycle
                return tname
index 5d7f793f710aa5581878a034c951d3451c475e17..5ce17e3ddc5d4c78fcfe921c1d750c763960ece7 100644 (file)
@@ -2997,7 +2997,6 @@ func TestTooNew(t *testing.T) {
 
 // This is a regression test for #66704.
 func TestUnaliasTooSoonInCycle(t *testing.T) {
-       t.Setenv("GODEBUG", "gotypesalias=1")
        const src = `package a
 
 var x T[B] // this appears to cause Unalias to be called on B while still Invalid
index d201b3ef9f0d5297e133f42898117f8292c554e7..74849171f24baa0ba2de3e3d49810168956224aa 100644 (file)
@@ -23,7 +23,9 @@ var noposn = atPos(nopos)
 // debugging/development support
 const debug = false // leave on during development
 
-// gotypesalias controls the use of Alias types
+// gotypesalias controls the use of Alias types.
+// As of Apr 12 2024 it is on by default.
+// It will be removed soon.
 var gotypesalias = godebug.New("gotypesalias")
 
 // exprInfo stores information about an untyped expression.
@@ -258,8 +260,14 @@ func NewChecker(conf *Config, fset *token.FileSet, pkg *Package, info *Info) *Ch
        //
        // (previously, pkg.goVersion was mutated here: go.dev/issue/61212)
 
+       enableAlias := false
+       switch gotypesalias.Value() {
+       case "", "1":
+               enableAlias = true
+       }
+
        return &Checker{
-               enableAlias: gotypesalias.Value() == "1",
+               enableAlias: enableAlias,
                conf:        conf,
                ctxt:        conf.Context,
                fset:        fset,
index fc9723a67fa5cf4569bb51e55dead7c0d0ed2d6a..63891e905600bce087f90d2159e8f9ca016023ac 100644 (file)
@@ -124,8 +124,6 @@ func parseFlags(src []byte, flags *flag.FlagSet) error {
 
 // testFiles type-checks the package consisting of the given files, and
 // compares the resulting errors with the ERROR annotations in the source.
-// Except for manual tests, each package is type-checked twice, once without
-// use of Alias types, and once with Alias types.
 //
 // The srcs slice contains the file content for the files named in the
 // filenames slice. The colDelta parameter specifies the tolerance for position
@@ -134,15 +132,6 @@ func parseFlags(src []byte, flags *flag.FlagSet) error {
 //
 // If provided, opts may be used to mutate the Config before type-checking.
 func testFiles(t *testing.T, filenames []string, srcs [][]byte, manual bool, opts ...func(*Config)) {
-       // Alias types are disabled by default
-       testFilesImpl(t, filenames, srcs, manual, opts...)
-       if !manual {
-               t.Setenv("GODEBUG", "gotypesalias=1")
-               testFilesImpl(t, filenames, srcs, manual, opts...)
-       }
-}
-
-func testFilesImpl(t *testing.T, filenames []string, srcs [][]byte, manual bool, opts ...func(*Config)) {
        if len(filenames) == 0 {
                t.Fatal("no source files")
        }
index b5d5334659990898948da0e08b9d22bc476455b3..937163fc7535f8fd13b17154bc25d6a4275d2338 100644 (file)
@@ -608,7 +608,7 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *ast.TypeSpec, def *TypeName
                        Unalias(alias) // resolve alias.actual
                } else {
                        if !versionErr && tparam0 != nil {
-                               check.error(tdecl, UnsupportedFeature, "generic type alias requires GODEBUG=gotypesalias=1")
+                               check.error(tdecl, UnsupportedFeature, "generic type alias requires GODEBUG=gotypesalias=1 or unset")
                                versionErr = true
                        }
 
index c0ac8225acb77cbe20f8c82ae0d078e54900d381..b9afb9117f80c1fe93d9c8b90bb81ff05bd2beed 100644 (file)
@@ -178,8 +178,11 @@ func TestEvalPos(t *testing.T) {
                // Materialized aliases give a different (better)
                // result for the final test, so skip it for now.
                // TODO(adonovan): reenable when gotypesalias=1 is the default.
-               if gotypesalias.Value() == "1" && strings.Contains(src, "interface{R}.Read") {
-                       continue
+               switch gotypesalias.Value() {
+               case "", "1":
+                       if strings.Contains(src, "interface{R}.Read") {
+                               continue
+                       }
                }
 
                files = append(files, file)
index 4f4bf6f07704135fa19f4f6c4ba11911cdd65f0a..eb627eaee7a5ffde7b0319bd1e0e1d4ea7e553a9 100644 (file)
@@ -998,7 +998,7 @@ type A = []int
 type S struct{ A }
 `
 
-       t.Setenv("GODEBUG", "gotypesalias=1")
+       // t.Setenv("GODEBUG", "gotypesalias=1") // now on by default
        pkg := mustTypecheck(src, nil, nil)
 
        S := pkg.Scope().Lookup("S")
index a97c391cd473a918d02008a8163cdd3ac06eb533..e9e043df4c764301dcbdde1978d288d6a56f929c 100644 (file)
@@ -30,7 +30,7 @@ var All = []Info{
        {Name: "gocachehash", Package: "cmd/go"},
        {Name: "gocachetest", Package: "cmd/go"},
        {Name: "gocacheverify", Package: "cmd/go"},
-       {Name: "gotypesalias", Package: "go/types", Opaque: true}, // bug #66216: remove Opaque
+       {Name: "gotypesalias", Package: "go/types", Changed: 23, Old: "0", Opaque: true}, // bug #66216: remove Opaque
        {Name: "http2client", Package: "net/http"},
        {Name: "http2debug", Package: "net/http", Opaque: true},
        {Name: "http2server", Package: "net/http"},