Skip to content

Commit

Permalink
go/types: flip the default value of GODEBUG=gotypesalias=1
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
adonovan committed Apr 15, 2024
1 parent cfbe6cd commit cf760ce
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 21 deletions.
5 changes: 3 additions & 2 deletions src/go/internal/gcimporter/ureader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/go/types/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions src/go/types/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
11 changes: 0 additions & 11 deletions src/go/types/check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion src/go/types/decl.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
7 changes: 5 additions & 2 deletions src/go/types/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/go/types/issues_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion src/internal/godebugs/table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down

0 comments on commit cf760ce

Please sign in to comment.