зеркало из https://github.com/golang/tools.git
all: apply versions.InitFileVersions in x/tools.
Updates golang/go#62605 Change-Id: I127b57f4eb5b6d2521dde7f139048987614e1904 Reviewed-on: https://go-review.googlesource.com/c/tools/+/533975 Reviewed-by: Robert Findley <rfindley@google.com> Run-TryBot: Tim King <taking@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
Родитель
aafa2e00a0
Коммит
b03756e1f3
|
@ -51,6 +51,7 @@ import (
|
|||
"golang.org/x/tools/go/analysis/internal/analysisflags"
|
||||
"golang.org/x/tools/internal/facts"
|
||||
"golang.org/x/tools/internal/typeparams"
|
||||
"golang.org/x/tools/internal/versions"
|
||||
)
|
||||
|
||||
// A Config describes a compilation unit to be analyzed.
|
||||
|
@ -262,6 +263,7 @@ func run(fset *token.FileSet, cfg *Config, analyzers []*analysis.Analyzer) ([]re
|
|||
Selections: make(map[*ast.SelectorExpr]*types.Selection),
|
||||
}
|
||||
typeparams.InitInstanceInfo(info)
|
||||
versions.InitFileVersions(info)
|
||||
|
||||
pkg, err := tc.Check(cfg.ImportPath, fset, files, info)
|
||||
if err != nil {
|
||||
|
|
|
@ -24,6 +24,7 @@ import (
|
|||
"golang.org/x/tools/go/ast/astutil"
|
||||
"golang.org/x/tools/go/internal/cgo"
|
||||
"golang.org/x/tools/internal/typeparams"
|
||||
"golang.org/x/tools/internal/versions"
|
||||
)
|
||||
|
||||
var ignoreVendor build.ImportMode
|
||||
|
@ -1040,6 +1041,7 @@ func (imp *importer) newPackageInfo(path, dir string) *PackageInfo {
|
|||
dir: dir,
|
||||
}
|
||||
typeparams.InitInstanceInfo(&info.Info)
|
||||
versions.InitFileVersions(&info.Info)
|
||||
|
||||
// Copy the types.Config so we can vary it across PackageInfos.
|
||||
tc := imp.conf.TypeChecker
|
||||
|
|
|
@ -29,6 +29,7 @@ import (
|
|||
"golang.org/x/tools/internal/packagesinternal"
|
||||
"golang.org/x/tools/internal/typeparams"
|
||||
"golang.org/x/tools/internal/typesinternal"
|
||||
"golang.org/x/tools/internal/versions"
|
||||
)
|
||||
|
||||
// A LoadMode controls the amount of detail to return when loading.
|
||||
|
@ -1018,6 +1019,7 @@ func (ld *loader) loadPackage(lpkg *loaderPackage) {
|
|||
Selections: make(map[*ast.SelectorExpr]*types.Selection),
|
||||
}
|
||||
typeparams.InitInstanceInfo(lpkg.TypesInfo)
|
||||
versions.InitFileVersions(lpkg.TypesInfo)
|
||||
lpkg.TypesSizes = ld.sizes
|
||||
|
||||
importer := importerFunc(func(path string) (*types.Package, error) {
|
||||
|
|
|
@ -82,6 +82,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"golang.org/x/tools/internal/typeparams"
|
||||
"golang.org/x/tools/internal/versions"
|
||||
)
|
||||
|
||||
type opaqueType struct {
|
||||
|
@ -1744,8 +1745,7 @@ func (b *builder) forStmt(fn *Function, s *ast.ForStmt, label *lblock) {
|
|||
// Use forStmtGo122 instead if it applies.
|
||||
if s.Init != nil {
|
||||
if assign, ok := s.Init.(*ast.AssignStmt); ok && assign.Tok == token.DEFINE {
|
||||
major, minor := parseGoVersion(fn.goversion)
|
||||
afterGo122 := major >= 1 && minor >= 22
|
||||
afterGo122 := versions.Compare(fn.goversion, "go1.21") > 0
|
||||
if afterGo122 {
|
||||
b.forStmtGo122(fn, s, label)
|
||||
return
|
||||
|
@ -2195,9 +2195,7 @@ func (b *builder) rangeStmt(fn *Function, s *ast.RangeStmt, label *lblock) {
|
|||
}
|
||||
}
|
||||
|
||||
major, minor := parseGoVersion(fn.goversion)
|
||||
afterGo122 := major >= 1 && minor >= 22
|
||||
|
||||
afterGo122 := versions.Compare(fn.goversion, "go1.21") > 0
|
||||
if s.Tok == token.DEFINE && !afterGo122 {
|
||||
// pre-go1.22: If iteration variables are defined (:=), this
|
||||
// occurs once outside the loop.
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
"sync"
|
||||
|
||||
"golang.org/x/tools/internal/typeparams"
|
||||
"golang.org/x/tools/internal/versions"
|
||||
)
|
||||
|
||||
// NewProgram returns a new SSA Program.
|
||||
|
@ -245,7 +246,7 @@ func (prog *Program) CreatePackage(pkg *types.Package, files []*ast.File, info *
|
|||
if len(files) > 0 {
|
||||
// Go source package.
|
||||
for _, file := range files {
|
||||
goversion := goversionOf(p, file)
|
||||
goversion := versions.Lang(versions.FileVersions(p.info, file))
|
||||
for _, decl := range file.Decls {
|
||||
membersFromDecl(p, decl, goversion)
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@ import (
|
|||
"golang.org/x/tools/go/ssa"
|
||||
"golang.org/x/tools/go/ssa/interp"
|
||||
"golang.org/x/tools/go/ssa/ssautil"
|
||||
"golang.org/x/tools/internal/testenv"
|
||||
"golang.org/x/tools/internal/typeparams"
|
||||
)
|
||||
|
||||
|
@ -172,7 +173,12 @@ func run(t *testing.T, input string, goroot string) {
|
|||
t.Skipf("skipping: width32.go checks behavior for a 32-bit int")
|
||||
}
|
||||
|
||||
conf := loader.Config{Build: &ctx}
|
||||
gover := ""
|
||||
if p := testenv.Go1Point(); p > 0 {
|
||||
gover = fmt.Sprintf("go1.%d", p)
|
||||
}
|
||||
|
||||
conf := loader.Config{Build: &ctx, TypeChecker: types.Config{GoVersion: gover}}
|
||||
if _, err := conf.FromArgs([]string{input}, true); err != nil {
|
||||
t.Fatalf("FromArgs(%s) failed: %s", input, err)
|
||||
}
|
||||
|
|
|
@ -11,7 +11,6 @@ package ssa
|
|||
// the originating syntax, as specified.
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"go/ast"
|
||||
"go/token"
|
||||
"go/types"
|
||||
|
@ -132,31 +131,6 @@ func findNamedFunc(pkg *Package, pos token.Pos) *Function {
|
|||
return nil
|
||||
}
|
||||
|
||||
// goversionOf returns the goversion of a node in the package
|
||||
// where the node is either a function declaration or the initial
|
||||
// value of a package level variable declaration.
|
||||
func goversionOf(p *Package, file *ast.File) string {
|
||||
if p.info == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
// TODO(taking): Update to the following when internal/versions available:
|
||||
// return versions.Lang(versions.FileVersions(p.info, file))
|
||||
return fileVersions(file)
|
||||
}
|
||||
|
||||
// TODO(taking): Remove when internal/versions is available.
|
||||
var fileVersions = func(file *ast.File) string { return "" }
|
||||
|
||||
// parses a goXX.YY version or returns a negative version on an error.
|
||||
// TODO(taking): Switch to a permanent solution when internal/versions is submitted.
|
||||
func parseGoVersion(x string) (major, minor int) {
|
||||
if _, err := fmt.Sscanf(x, "go%d.%d", &major, &minor); err != nil || major < 0 || minor < 0 {
|
||||
return -1, -1
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// ValueForExpr returns the SSA Value that corresponds to non-constant
|
||||
// expression e.
|
||||
//
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"golang.org/x/tools/go/packages"
|
||||
"golang.org/x/tools/go/ssa"
|
||||
"golang.org/x/tools/internal/typeparams"
|
||||
"golang.org/x/tools/internal/versions"
|
||||
)
|
||||
|
||||
// Packages creates an SSA program for a set of packages.
|
||||
|
@ -165,7 +166,7 @@ func BuildPackage(tc *types.Config, fset *token.FileSet, pkg *types.Package, fil
|
|||
Selections: make(map[*ast.SelectorExpr]*types.Selection),
|
||||
}
|
||||
typeparams.InitInstanceInfo(info)
|
||||
// versions.InitFileVersions(info) // TODO(taking): Enable when internal/versions is available.
|
||||
versions.InitFileVersions(info)
|
||||
if err := types.NewChecker(tc, fset, pkg, info).Files(files); err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
// Copyright 2023 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
//go:build go1.22
|
||||
// +build go1.22
|
||||
|
||||
package ssa
|
||||
|
||||
import (
|
||||
"go/ast"
|
||||
)
|
||||
|
||||
func init() {
|
||||
fileVersions = func(file *ast.File) string {
|
||||
if maj, min := parseGoVersion(file.GoVersion); maj >= 0 && min >= 0 {
|
||||
return file.GoVersion
|
||||
}
|
||||
return ""
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import (
|
|||
|
||||
"golang.org/x/tools/go/types/typeutil"
|
||||
"golang.org/x/tools/internal/typeparams"
|
||||
"golang.org/x/tools/internal/versions"
|
||||
)
|
||||
|
||||
func TestStaticCallee(t *testing.T) {
|
||||
|
@ -129,6 +130,7 @@ func testStaticCallee(t *testing.T, contents []string) {
|
|||
Selections: make(map[*ast.SelectorExpr]*types.Selection),
|
||||
}
|
||||
typeparams.InitInstanceInfo(info)
|
||||
versions.InitFileVersions(info)
|
||||
|
||||
var files []*ast.File
|
||||
for i, content := range contents {
|
||||
|
|
|
@ -16,6 +16,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"golang.org/x/tools/internal/typeparams"
|
||||
"golang.org/x/tools/internal/versions"
|
||||
"golang.org/x/tools/refactor/satisfy"
|
||||
)
|
||||
|
||||
|
@ -228,6 +229,7 @@ func constraints(t *testing.T, src string) []string {
|
|||
Selections: make(map[*ast.SelectorExpr]*types.Selection),
|
||||
}
|
||||
typeparams.InitInstanceInfo(info)
|
||||
versions.InitFileVersions(info)
|
||||
conf := types.Config{
|
||||
Importer: importer.Default(),
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче