tools/internal/testenv
Alan Donovan 440f3c37e4 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 <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
2024-04-23 20:27:57 +00:00
..
exec.go internal/aliases: expose Enabled 2024-04-23 20:27:57 +00:00
testenv.go gopls/internal/cache: fix crash in snapshot.Analyze with patch versions 2024-04-03 19:36:59 +00:00
testenv_notunix.go all: fix non-gopls short tests on js/wasm and update for wasip1/wasm 2023-04-20 14:27:21 +00:00
testenv_unix.go internal/testenv: add a Command function that replaces exec.Command 2022-11-21 16:54:26 +00:00