diff options
author | Bryan C. Mills <bcmills@google.com> | 2020-07-21 16:50:59 -0400 |
---|---|---|
committer | Bryan C. Mills <bcmills@google.com> | 2020-08-24 20:44:20 +0000 |
commit | 2a9636dc2bdbb2865dde686352de528c6953c7bf (patch) | |
tree | efd5c630066050839754cc543998487c06cca11a /src/cmd/go/internal/modload/modfile.go | |
parent | c777863f77bb77be2e6c336b78dee2089647ff0e (diff) | |
download | go-2a9636dc2bdbb2865dde686352de528c6953c7bf.tar.gz go-2a9636dc2bdbb2865dde686352de528c6953c7bf.zip |
cmd/go/internal/modload: cache the Go language version for each module globally
Previously, this cache was a member of the (ephemeral) modload.loader
struct. However, the Go language version for a given module version
does not vary based on the build list, the set of loaded packages, the
build tags in use, the meaning of the "all" pattern, or anything else
that can be configured for an instance of the package loader. The map
containing that information is therefore not appropriate as a field of
the (configurable, package-list-dependent) loader struct.
The Go language version mapping could, in theory, be read from the
go.mod file in the module cache (or replacement directory) every time
it is needed: this map is just a cache, and as such it belongs
alongside the other caches and indexes in the modload package, which
are currently found in modfile.go.
We may want to do the same sort of global caching for the mapping from
each module.Version to its list of direct requirements (which are
similarly idempotent), but for now that is left for a future change.
For #36460
For #36876
Change-Id: I90ac176ffea97f30c47d6540c3dfb874dc9cfa4f
Reviewed-on: https://go-review.googlesource.com/c/go/+/244078
Reviewed-by: Jay Conrod <jayconrod@google.com>
Reviewed-by: Michael Matloob <matloob@golang.org>
Diffstat (limited to 'src/cmd/go/internal/modload/modfile.go')
-rw-r--r-- | src/cmd/go/internal/modload/modfile.go | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/src/cmd/go/internal/modload/modfile.go b/src/cmd/go/internal/modload/modfile.go index 9a166cae54..9ff00e9b5c 100644 --- a/src/cmd/go/internal/modload/modfile.go +++ b/src/cmd/go/internal/modload/modfile.go @@ -7,6 +7,7 @@ package modload import ( "cmd/go/internal/base" "cmd/go/internal/cfg" + "sync" "golang.org/x/mod/modfile" "golang.org/x/mod/module" @@ -164,3 +165,9 @@ func (i *modFileIndex) modFileIsDirty(modFile *modfile.File) bool { return false } + +// rawGoVersion records the Go version parsed from each module's go.mod file. +// +// If a module is replaced, the version of the replacement is keyed by the +// replacement module.Version, not the version being replaced. +var rawGoVersion sync.Map // map[module.Version]string |