all: delete aliastypeparams GOEXPERIMENT

Always enable aliastypeparams and remove the GOEXPERIMENT.

Change-Id: Ic38fe25b0bba312a7f83f7bb94b57ab75ce0f0c3
Reviewed-on: https://go-review.googlesource.com/c/go/+/691956
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Mark Freeman <markfreeman@google.com>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
This commit is contained in:
Cherry Mui 2025-07-30 16:16:48 -04:00
parent 74421a305b
commit 00a7bdcb55
22 changed files with 19 additions and 76 deletions

View file

@ -7,7 +7,6 @@ package noder
import (
"cmp"
"fmt"
"internal/buildcfg"
"internal/pkgbits"
"internal/types/errors"
"io"
@ -464,11 +463,8 @@ func readPackage(pr *pkgReader, importpkg *types.Pkg, localStub bool) {
// writeUnifiedExport writes to `out` the finalized, self-contained
// Unified IR export data file for the current compilation unit.
func writeUnifiedExport(out io.Writer) {
// Use V2 as the encoded version aliastypeparams GOEXPERIMENT is enabled.
version := pkgbits.V1
if buildcfg.Experiment.AliasTypeParams {
version = pkgbits.V2
}
// Use V2 as the encoded version for aliastypeparams.
version := pkgbits.V2
l := linker{
pw: pkgbits.NewPkgEncoder(version, base.Debug.SyncFrames),

View file

@ -96,11 +96,8 @@ type pkgWriter struct {
// newPkgWriter returns an initialized pkgWriter for the specified
// package.
func newPkgWriter(m posMap, pkg *types2.Package, info *types2.Info, otherInfo map[*syntax.FuncLit]bool) *pkgWriter {
// Use V2 as the encoded version aliastypeparams GOEXPERIMENT is enabled.
version := pkgbits.V1
if buildcfg.Experiment.AliasTypeParams {
version = pkgbits.V2
}
// Use V2 as the encoded version for aliastypeparams.
version := pkgbits.V2
return &pkgWriter{
PkgEncoder: pkgbits.NewPkgEncoder(version, base.Debug.SyncFrames),

View file

@ -8,7 +8,6 @@ import (
"cmd/compile/internal/syntax"
"fmt"
"go/constant"
"internal/buildcfg"
. "internal/types/errors"
"slices"
)
@ -525,10 +524,6 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *syntax.TypeDecl, def *TypeN
// handle type parameters even if not allowed (Alias type is supported)
if tparam0 != nil {
if !versionErr && !buildcfg.Experiment.AliasTypeParams {
check.error(tdecl, UnsupportedFeature, "generic type alias requires GOEXPERIMENT=aliastypeparams")
versionErr = true
}
check.openScope(tdecl, "type parameters")
defer check.closeScope()
check.collectTypeParams(&alias.tparams, tdecl.TParamList)

View file

@ -11,7 +11,6 @@ import (
"cmd/compile/internal/syntax"
"errors"
"fmt"
"internal/buildcfg"
. "internal/types/errors"
)
@ -130,10 +129,6 @@ func (check *Checker) instance(pos syntax.Pos, orig genericType, targs []Type, e
res = check.newNamedInstance(pos, orig, targs, expanding) // substituted lazily
case *Alias:
if !buildcfg.Experiment.AliasTypeParams {
assert(expanding == nil) // Alias instances cannot be reached from Named types
}
// verify type parameter count (see go.dev/issue/71198 for a test case)
tparams := orig.TypeParams()
if !check.validateTArgLen(pos, orig.obj.Name(), tparams.Len(), len(targs)) {

View file

@ -99,8 +99,7 @@ var testObjects = []struct {
{"type t = struct{f int}", "t", "type p.t = struct{f int}", false},
{"type t = func(int)", "t", "type p.t = func(int)", false},
{"type A = B; type B = int", "A", "type p.A = p.B", true},
{"type A[P ~int] = struct{}", "A", "type p.A[P ~int] = struct{}", true}, // requires GOEXPERIMENT=aliastypeparams
{"type A[P ~int] = struct{}", "A", "type p.A[P ~int] = struct{}", true},
{"var v int", "v", "var p.v int", false},
{"func f(int) string", "f", "func p.f(int) string", false},
@ -114,10 +113,6 @@ func TestObjectString(t *testing.T) {
for i, test := range testObjects {
t.Run(fmt.Sprint(i), func(t *testing.T) {
if test.alias {
revert := setGOEXPERIMENT("aliastypeparams")
defer revert()
}
src := "package p; " + test.src
conf := Config{Error: func(error) {}, Importer: defaultImporter(), EnableAlias: test.alias}
pkg, err := typecheck(src, &conf, nil)

View file

@ -332,6 +332,8 @@ func TestStdFixed(t *testing.T) {
"issue49814.go", // go/types does not have constraints on array size
"issue56103.go", // anonymous interface cycles; will be a type checker error in 1.22
"issue52697.go", // types2 does not have constraints on stack size
"issue68054.go", // this test requires GODEBUG=gotypesalias=1
"issue68580.go", // this test requires GODEBUG=gotypesalias=1
"issue73309.go", // this test requires GODEBUG=gotypesalias=1
"issue73309b.go", // this test requires GODEBUG=gotypesalias=1

View file

@ -9,7 +9,6 @@ import (
"go/ast"
"go/constant"
"go/token"
"internal/buildcfg"
. "internal/types/errors"
"slices"
)
@ -600,10 +599,6 @@ func (check *Checker) typeDecl(obj *TypeName, tdecl *ast.TypeSpec, def *TypeName
// handle type parameters even if not allowed (Alias type is supported)
if tparam0 != nil {
if !versionErr && !buildcfg.Experiment.AliasTypeParams {
check.error(tdecl, UnsupportedFeature, "generic type alias requires GOEXPERIMENT=aliastypeparams")
versionErr = true
}
check.openScope(tdecl, "type parameters")
defer check.closeScope()
check.collectTypeParams(&alias.tparams, tdecl.TypeParams)

View file

@ -14,7 +14,6 @@ import (
"errors"
"fmt"
"go/token"
"internal/buildcfg"
. "internal/types/errors"
)
@ -133,10 +132,6 @@ func (check *Checker) instance(pos token.Pos, orig genericType, targs []Type, ex
res = check.newNamedInstance(pos, orig, targs, expanding) // substituted lazily
case *Alias:
if !buildcfg.Experiment.AliasTypeParams {
assert(expanding == nil) // Alias instances cannot be reached from Named types
}
// verify type parameter count (see go.dev/issue/71198 for a test case)
tparams := orig.TypeParams()
if !check.validateTArgLen(pos, orig.obj.Name(), tparams.Len(), len(targs)) {

View file

@ -99,8 +99,7 @@ var testObjects = []struct {
{"type t = struct{f int}", "t", "type p.t = struct{f int}", false},
{"type t = func(int)", "t", "type p.t = func(int)", false},
{"type A = B; type B = int", "A", "type p.A = p.B", true},
{"type A[P ~int] = struct{}", "A", "type p.A[P ~int] = struct{}", true}, // requires GOEXPERIMENT=aliastypeparams
{"type A[P ~int] = struct{}", "A", "type p.A[P ~int] = struct{}", true},
{"var v int", "v", "var p.v int", false},
{"func f(int) string", "f", "func p.f(int) string", false},
@ -115,8 +114,6 @@ func TestObjectString(t *testing.T) {
for i, test := range testObjects {
t.Run(fmt.Sprint(i), func(t *testing.T) {
if test.alias {
revert := setGOEXPERIMENT("aliastypeparams")
defer revert()
t.Setenv("GODEBUG", "gotypesalias=1")
}

View file

@ -334,6 +334,8 @@ func TestStdFixed(t *testing.T) {
"issue49814.go", // go/types does not have constraints on array size
"issue56103.go", // anonymous interface cycles; will be a type checker error in 1.22
"issue52697.go", // go/types does not have constraints on stack size
"issue68054.go", // this test requires GODEBUG=gotypesalias=1
"issue68580.go", // this test requires GODEBUG=gotypesalias=1
"issue73309.go", // this test requires GODEBUG=gotypesalias=1
"issue73309b.go", // this test requires GODEBUG=gotypesalias=1

View file

@ -79,10 +79,9 @@ func ParseGOEXPERIMENT(goos, goarch, goexp string) (*ExperimentFlags, error) {
dwarf5Supported := (goos != "darwin" && goos != "ios" && goos != "aix")
baseline := goexperiment.Flags{
RegabiWrappers: regabiSupported,
RegabiArgs: regabiSupported,
AliasTypeParams: true,
Dwarf5: dwarf5Supported,
RegabiWrappers: regabiSupported,
RegabiArgs: regabiSupported,
Dwarf5: dwarf5Supported,
}
// Start with the statically enabled set of experiments.

View file

@ -1,8 +0,0 @@
// Code generated by mkconsts.go. DO NOT EDIT.
//go:build !goexperiment.aliastypeparams
package goexperiment
const AliasTypeParams = false
const AliasTypeParamsInt = 0

View file

@ -1,8 +0,0 @@
// Code generated by mkconsts.go. DO NOT EDIT.
//go:build goexperiment.aliastypeparams
package goexperiment
const AliasTypeParams = true
const AliasTypeParamsInt = 1

View file

@ -100,11 +100,6 @@ type Flags struct {
// inlining phase within the Go compiler.
NewInliner bool
// AliasTypeParams enables type parameters for alias types.
// Requires that gotypesalias=1 is set with GODEBUG.
// This flag will be removed with Go 1.25.
AliasTypeParams bool
// Synctest enables the testing/synctest package.
Synctest bool

View file

@ -1,4 +1,4 @@
// -goexperiment=aliastypeparams -gotypesalias=1
// -gotypesalias=1
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style

View file

@ -1,4 +1,4 @@
// -goexperiment=aliastypeparams -gotypesalias=1
// -gotypesalias=1
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style

View file

@ -1,4 +1,4 @@
// -lang=go1.23 -gotypesalias=1 -goexperiment=aliastypeparams
// -lang=go1.23 -gotypesalias=1
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style

View file

@ -1,4 +1,4 @@
// compile -goexperiment aliastypeparams
// compile
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style

View file

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build goexperiment.aliastypeparams
package a
type A[T any] = struct{ F T }

View file

@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build goexperiment.aliastypeparams
package main
import (

View file

@ -1,4 +1,4 @@
// runindir -goexperiment aliastypeparams -gomodversion "1.23"
// runindir -gomodversion "1.23"
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style

View file

@ -1,4 +1,4 @@
// compile -goexperiment aliastypeparams
// compile
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style