Skip to content

Commit

Permalink
Revert "internal/aliases: add a function to conditionally enable alia…
Browse files Browse the repository at this point in the history
…ses"

This reverts commit f8f3c13.

Reason for revert: https://go.dev/cl/619395 appears to be a better solution for the same problem.

Change-Id: Ie3f290fca74b2cc2627484504b6db780f89b3bb4
Reviewed-on: https://go-review.googlesource.com/c/tools/+/619415
Reviewed-by: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Tim King <taking@google.com>
  • Loading branch information
timothy-king authored and Go LUCI committed Oct 10, 2024
1 parent 4f6e118 commit 50179f2
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 130 deletions.
54 changes: 0 additions & 54 deletions internal/aliases/aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
package aliases

import (
"go/build"
"go/token"
"go/types"
"os"
"slices"
"strings"
"sync"
)

// Package aliases defines backward compatible shims
Expand Down Expand Up @@ -41,52 +36,3 @@ func NewAlias(enabled bool, pos token.Pos, pkg *types.Package, name string, rhs
}
return types.NewTypeName(pos, pkg, name, rhs)
}

// ConditionallyEnableGoTypesAlias enables the gotypesalias GODEBUG setting if
// * the version of go used to compile the program is between 1.23 and 1.26,
// * gotypesalias are not already enabled, and
// * gotypesalias is not set in GODEBUG already
// exactly once. Otherwise it does nothing.
//
// Recommended usage is to do the following within a main package:
//
// func init() { ConditionallyEnableGoTypesAlias() }
//
// within a module with go version 1.22 or in GOPATH mode.
func ConditionallyEnableGoTypesAlias() { conditionallyEnableGoTypesAliasOnce() }

var conditionallyEnableGoTypesAliasOnce = sync.OnceFunc(conditionallyEnableGoTypesAlias)

func conditionallyEnableGoTypesAlias() {
// Let R be the version of go the program was compiled with. Then
// if R < 1.22, do nothing as gotypesalias is meaningless,
// if R == 1.22, do not turn on gotypesalias (latent bugs),
// if 1.23 <= R && R <= 1.26, turn on gotypesalias, and
// if R >= 1.27, this is a guaranteed no-op.

if !slices.Contains(build.Default.ReleaseTags, "go1.23") {
return // R < 1.23 (do nothing)
}
if slices.Contains(build.Default.ReleaseTags, "go1.27") {
return // R >= 1.27 (do nothing)
}
// 1.23 <= R <= 1.26
_, anyIsAlias := types.Universe.Lookup("any").Type().(*types.Alias)
if anyIsAlias {
return // gotypesalias are already enabled.
}

// Does GODEBUG have gotypesalias set already?
godebugs := strings.Split(os.Getenv("GODEBUG"), ",")
for _, p := range godebugs {
if strings.HasPrefix(strings.TrimSpace(p), "gotypesalias=") {
// gotypesalias is set in GODEBUG already.
// Do not override this setting.
return
}
}

// Enable gotypesalias.
godebugs = append(godebugs, "gotypesalias=1")
os.Setenv("GODEBUG", strings.Join(godebugs, ","))
}
76 changes: 0 additions & 76 deletions internal/aliases/enable_test.go

This file was deleted.

0 comments on commit 50179f2

Please sign in to comment.