Skip to content

Commit 71abee6

Browse files
committed
internal/aliases: expose Enabled
The predicate that determines whether the type checker creates types.Alias nodes is complex: it depends on an environment variable (GODEBUG) that is somewhat tricky to parse correctly, since it is a rightmost-wins list. Critically, however, its default value is a function of the go directive in the application's go.mod file, which is inaccessible to logic in x/tools (per-file build tags can detect the toolchain version, but not the go.mod version). Equally critically, the current effective value of the gotypesalias variable changes when os.Setenv(GODEBUG) is called, which happens in tests, and there is no way to detect those events; therefore any attempt to cache the value is wrong. This change exposes a simplified version of the Enabled function from aliases, which always computes the ground truth by invoking the type checker, regardless of cost. It also adds an 'enabled' parameter to NewAlias so that callers can amortize this cost. Also, various minor cleanups related to aliases. Updates golang/go#64581 Change-Id: If926edefb8e1c1f63c17e4fad0a808e27bac6d5b Reviewed-on: https://go-review.googlesource.com/c/tools/+/580455 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: Robert Findley <[email protected]>
1 parent 6b28e98 commit 71abee6

File tree

2 files changed

+5
-29
lines changed

2 files changed

+5
-29
lines changed

go.mod

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
11
module github.com/apstndb/gotoolsdiff
22

3-
go 1.19
3+
go 1.19 // => default GODEBUG has gotypesalias=0
44

55
require (
6+
github.com/google/go-cmp v0.6.0
67
github.com/yuin/goldmark v1.4.13
78
golang.org/x/mod v0.17.0
89
golang.org/x/net v0.24.0
9-
)
10-
11-
require golang.org/x/sync v0.7.0
12-
13-
require github.com/google/go-cmp v0.6.0 // indirect
14-
15-
require (
16-
golang.org/x/sys v0.19.0 // indirect
10+
golang.org/x/sync v0.7.0
1711
golang.org/x/telemetry v0.0.0-20240228155512-f48c80bd79b2
1812
)
13+
14+
require golang.org/x/sys v0.19.0 // indirect

internal/testenv/exec.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"reflect"
1313
"runtime"
1414
"strconv"
15-
"strings"
1615
"sync"
1716
"testing"
1817
"time"
@@ -191,22 +190,3 @@ func Command(t testing.TB, name string, args ...string) *exec.Cmd {
191190
t.Helper()
192191
return CommandContext(t, context.Background(), name, args...)
193192
}
194-
195-
// SkipMaterializedAliases skips the test if go/types would create
196-
// instances of types.Alias, which some tests do not yet handle
197-
// correctly.
198-
func SkipMaterializedAliases(t *testing.T, message string) {
199-
if hasMaterializedAliases(Go1Point()) {
200-
t.Skipf("%s", message)
201-
}
202-
}
203-
204-
func hasMaterializedAliases(minor int) bool {
205-
if minor >= 23 && !strings.Contains(os.Getenv("GODEBUG"), "gotypesalias=0") {
206-
return true // gotypesalias=1 became the default in go1.23
207-
}
208-
if minor == 22 && strings.Contains(os.Getenv("GODEBUG"), "gotypesalias=1") {
209-
return true // gotypesalias=0 was the default in go1.22
210-
}
211-
return false // types.Alias didn't exist in go1.21
212-
}

0 commit comments

Comments
 (0)