]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: stop using internal/godebug
authorRuss Cox <rsc@golang.org>
Wed, 24 Apr 2024 16:56:44 +0000 (12:56 -0400)
committerGopher Robot <gobot@golang.org>
Thu, 9 May 2024 13:50:03 +0000 (13:50 +0000)
The main reason not to use internal/godebug is that
people often set GODEBUGs to change the behavior
of the programs they are running with 'go run' or 'go test'.
We don't want the compiler to behave differently as well
in that case: that's too many changes.

Using internal/godebug also breaks bootstrapping
with toolchains that don't have it, or future toolchains
that have a different API in that package.

Change-Id: Ib5a8a74e2451649d8838b71f274b4e3a78939dfa
Reviewed-on: https://go-review.googlesource.com/c/go/+/581495
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/cmd/compile/internal/importer/ureader.go
src/cmd/compile/internal/types2/check.go

index 3488f1314882e369594e12c116210c19dfe60fce..d3c7d4516f7ee81a48c26679a846e145e7e12b40 100644 (file)
@@ -9,15 +9,15 @@ import (
        "cmd/compile/internal/syntax"
        "cmd/compile/internal/types2"
        "cmd/internal/src"
-       "internal/godebug"
        "internal/pkgbits"
 )
 
 type pkgReader struct {
        pkgbits.PkgDecoder
 
-       ctxt    *types2.Context
-       imports map[string]*types2.Package
+       ctxt        *types2.Context
+       imports     map[string]*types2.Package
+       enableAlias bool // whether to use aliases
 
        posBases []*syntax.PosBase
        pkgs     []*types2.Package
@@ -30,6 +30,9 @@ func ReadPackage(ctxt *types2.Context, imports map[string]*types2.Package, input
 
                ctxt:    ctxt,
                imports: imports,
+               // Currently, the compiler panics when using Alias types.
+               // TODO(gri) set to true once this is fixed (issue #66873)
+               enableAlias: false,
 
                posBases: make([]*syntax.PosBase, input.NumElems(pkgbits.RelocPosBase)),
                pkgs:     make([]*types2.Package, input.NumElems(pkgbits.RelocPkg)),
@@ -410,7 +413,7 @@ func (pr *pkgReader) objIdx(idx pkgbits.Index) (*types2.Package, string) {
                case pkgbits.ObjAlias:
                        pos := r.pos()
                        typ := r.typ()
-                       return newAliasTypeName(pos, objPkg, objName, typ)
+                       return newAliasTypeName(pr.enableAlias, pos, objPkg, objName, typ)
 
                case pkgbits.ObjConst:
                        pos := r.pos()
@@ -536,16 +539,13 @@ func (r *reader) ident(marker pkgbits.SyncMarker) (*types2.Package, string) {
 }
 
 // newAliasTypeName returns a new TypeName, with a materialized *types2.Alias if supported.
-func newAliasTypeName(pos syntax.Pos, pkg *types2.Package, name string, rhs types2.Type) *types2.TypeName {
+func newAliasTypeName(aliases bool, pos syntax.Pos, pkg *types2.Package, name string, rhs types2.Type) *types2.TypeName {
        // Copied from x/tools/internal/aliases.NewAlias via
        // GOROOT/src/go/internal/gcimporter/ureader.go.
-       if gotypesalias.Value() == "1" {
+       if aliases {
                tname := types2.NewTypeName(pos, pkg, name, nil)
                _ = types2.NewAlias(tname, rhs) // form TypeName -> Alias cycle
                return tname
        }
        return types2.NewTypeName(pos, pkg, name, rhs)
 }
-
-// gotypesalias controls the use of Alias types.
-var gotypesalias = godebug.New("#gotypesalias")
index 9203a102177116ed671e19dc022295332ea9cb83..a347467b597b7b80d2f105342da4203aac219435 100644 (file)
@@ -10,7 +10,6 @@ import (
        "cmd/compile/internal/syntax"
        "fmt"
        "go/constant"
-       "internal/godebug"
        . "internal/types/errors"
        "sync/atomic"
 )
@@ -21,12 +20,6 @@ var nopos syntax.Pos
 // debugging/development support
 const debug = false // leave on during development
 
-// gotypesalias controls the use of Alias types.
-// As of Apr 16 2024 they are used by default.
-// To disable their use, set GODEBUG to gotypesalias=0.
-// This GODEBUG flag will be removed in the near future (tentatively Go 1.24).
-var gotypesalias = godebug.New("gotypesalias")
-
 // _aliasAny changes the behavior of [Scope.Lookup] for "any" in the
 // [Universe] scope.
 //