Skip to content

Commit

Permalink
x/tools: assume go1.22 and simplify
Browse files Browse the repository at this point in the history
This CL does not include simplifications to gopls.

Updates golang/go#65917
Updates golang/go#69095

Change-Id: I2b54992681e2c671324e22668d8401962a1d2363
Reviewed-on: https://go-review.googlesource.com/c/tools/+/593683
Reviewed-by: Robert Findley <[email protected]>
LUCI-TryBot-Result: Go LUCI <[email protected]>
  • Loading branch information
adonovan committed Sep 20, 2024
1 parent 1d5e334 commit 3bb0ed7
Show file tree
Hide file tree
Showing 45 changed files with 135 additions and 467 deletions.
13 changes: 0 additions & 13 deletions cmd/bisect/go119.go

This file was deleted.

2 changes: 0 additions & 2 deletions cmd/bisect/go120.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.20

package main

import (
Expand Down
20 changes: 0 additions & 20 deletions cmd/bisect/rand.go

This file was deleted.

2 changes: 0 additions & 2 deletions cmd/deadcode/deadcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.20

package main

import (
Expand Down
2 changes: 0 additions & 2 deletions cmd/deadcode/deadcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.20

package main_test

import (
Expand Down
4 changes: 0 additions & 4 deletions go/analysis/internal/checker/checker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,10 +223,6 @@ func NewT1() *T1 { return &T1{T} }
// duplicate list errors with findings (issue #67790)
{name: "list-error-findings", pattern: []string{cperrFile}, analyzers: []*analysis.Analyzer{renameAnalyzer}, code: 3},
} {
if test.name == "despite-error" && testenv.Go1Point() < 20 {
// The behavior in the comment on the despite-error test only occurs for Go 1.20+.
continue
}
if got := checker.Run(test.pattern, test.analyzers); got != test.code {
t.Errorf("got incorrect exit code %d for test %s; want %d", got, test.name, test.code)
}
Expand Down
2 changes: 0 additions & 2 deletions go/analysis/passes/directive/directive_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ import (
"golang.org/x/tools/go/analysis"
"golang.org/x/tools/go/analysis/analysistest"
"golang.org/x/tools/go/analysis/passes/directive"
"golang.org/x/tools/internal/testenv"
)

func Test(t *testing.T) {
testenv.NeedsGo1Point(t, 16)
analyzer := *directive.Analyzer
analyzer.Run = func(pass *analysis.Pass) (interface{}, error) {
defer func() {
Expand Down
21 changes: 1 addition & 20 deletions go/analysis/passes/loopclosure/loopclosure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,10 @@ import (

"golang.org/x/tools/go/analysis/analysistest"
"golang.org/x/tools/go/analysis/passes/loopclosure"
"golang.org/x/tools/internal/testenv"
"golang.org/x/tools/internal/testfiles"
)

func Test(t *testing.T) {
// legacy loopclosure test expectations are incorrect > 1.21.
testenv.SkipAfterGo1Point(t, 21)

testdata := analysistest.TestData()
analysistest.Run(t, testdata, loopclosure.Analyzer,
"a", "golang.org/...", "subtests", "typeparams")
}

func TestVersions22(t *testing.T) {
t.Skip("Disabled for golang.org/cl/603895. Fix and re-enable.")
testenv.NeedsGo1Point(t, 22)

func TestVersions(t *testing.T) {
dir := testfiles.ExtractTxtarFileToTmp(t, filepath.Join(analysistest.TestData(), "src", "versions", "go22.txtar"))
analysistest.Run(t, dir, loopclosure.Analyzer, "golang.org/fake/versions")
}

func TestVersions18(t *testing.T) {
t.Skip("Disabled for golang.org/cl/603895. Fix and re-enable.")
dir := testfiles.ExtractTxtarFileToTmp(t, filepath.Join(analysistest.TestData(), "src", "versions", "go18.txtar"))
analysistest.Run(t, dir, loopclosure.Analyzer, "golang.org/fake/versions")
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Test loopclosure at go version go1.22.

The go1.19 build tag is necessary to force the file version.
The go1.21 build tag is necessary to force the file version.

-- go.mod --
module golang.org/fake/versions

go 1.22
-- pre.go --
//go:build go1.19
//go:build go1.21

package versions

Expand Down
2 changes: 0 additions & 2 deletions go/analysis/passes/slog/slog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import (
"testing"

"golang.org/x/tools/go/analysis/analysistest"
"golang.org/x/tools/internal/testenv"
)

func Test(t *testing.T) {
testenv.NeedsGo1Point(t, 21)
testdata := analysistest.TestData()
analysistest.Run(t, testdata, Analyzer, "a", "b")
}
3 changes: 0 additions & 3 deletions go/analysis/passes/stdversion/stdversion_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,13 @@ import (

"golang.org/x/tools/go/analysis/analysistest"
"golang.org/x/tools/go/analysis/passes/stdversion"
"golang.org/x/tools/internal/testenv"
"golang.org/x/tools/internal/testfiles"
)

func Test(t *testing.T) {
t.Skip("Disabled for golang.org/cl/603895. Fix and re-enable.")
// The test relies on go1.21 std symbols, but the analyzer
// itself requires the go1.22 implementation of versions.FileVersions.
testenv.NeedsGo1Point(t, 22)

dir := testfiles.ExtractTxtarFileToTmp(t, filepath.Join(analysistest.TestData(), "test.txtar"))
analysistest.Run(t, dir, stdversion.Analyzer,
"example.com/a",
Expand Down
12 changes: 0 additions & 12 deletions go/ssa/interp/interp_go120_test.go

This file was deleted.

12 changes: 0 additions & 12 deletions go/ssa/interp/interp_go121_test.go

This file was deleted.

10 changes: 0 additions & 10 deletions go/ssa/interp/interp_go122_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
// 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 interp_test

import (
Expand All @@ -19,13 +16,6 @@ import (
"golang.org/x/tools/internal/testenv"
)

func init() {
testdataTests = append(testdataTests,
"rangevarlifetime_go122.go",
"forvarlifetime_go122.go",
)
}

// TestExperimentRange tests files in testdata with GOEXPERIMENT=range set.
func TestExperimentRange(t *testing.T) {
testenv.NeedsGoExperiment(t, "range")
Expand Down
4 changes: 4 additions & 0 deletions go/ssa/interp/interp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@ var testdataTests = []string{
"fixedbugs/issue66783.go",
"typeassert.go",
"zeros.go",
"slice2array.go",
"minmax.go",
"rangevarlifetime_go122.go",
"forvarlifetime_go122.go",
}

func init() {
Expand Down
2 changes: 0 additions & 2 deletions go/ssa/interp/testdata/forvarlifetime_go122.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.22

package main

import (
Expand Down
2 changes: 1 addition & 1 deletion go/ssa/interp/testdata/forvarlifetime_old.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.19
//go:build go1.21

// goversion can be pinned to anything strictly before 1.22.

Expand Down
2 changes: 1 addition & 1 deletion go/ssa/interp/testdata/rangevarlifetime_old.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build go1.19
//go:build go1.21

// goversion can be pinned to anything strictly before 1.22.

Expand Down
2 changes: 1 addition & 1 deletion internal/aliases/aliases_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestNewAlias(t *testing.T) {
t.Errorf("Expected Unalias(A)==%q. got %q", want, got)
}

if testenv.Go1Point() >= 22 && godebug != "gotypesalias=0" {
if godebug != "gotypesalias=0" {
if _, ok := A.Type().(*types.Alias); !ok {
t.Errorf("Expected A.Type() to be a types.Alias(). got %q", A.Type())
}
Expand Down
3 changes: 1 addition & 2 deletions internal/analysisinternal/analysis.go
Original file line number Diff line number Diff line change
Expand Up @@ -415,8 +415,7 @@ func CheckReadable(pass *analysis.Pass, filename string) error {
return nil
}
for _, f := range pass.Files {
// TODO(adonovan): use go1.20 f.FileStart
if pass.Fset.File(f.Pos()).Name() == filename {
if pass.Fset.File(f.FileStart).Name() == filename {
return nil
}
}
Expand Down
7 changes: 6 additions & 1 deletion internal/gcimporter/bimport.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,13 @@ func predeclared() []types.Type {

// used internally by gc; never used by this package or in .a files
anyType{},

// comparable
types.Universe.Lookup("comparable").Type(),

// any
types.Universe.Lookup("any").Type(),
}
predecl = append(predecl, additionalPredeclared()...)
})
return predecl
}
Expand Down
11 changes: 8 additions & 3 deletions internal/gcimporter/gcimporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,19 @@ func Import(packages map[string]*types.Package, path, srcDir string, lookup func
// Select appropriate importer.
if len(data) > 0 {
switch data[0] {
case 'v', 'c', 'd': // binary, till go1.10
case 'v', 'c', 'd':
// binary: emitted by cmd/compile till go1.10; obsolete.
return nil, fmt.Errorf("binary (%c) import format is no longer supported", data[0])

case 'i': // indexed, till go1.19
case 'i':
// indexed: emitted by cmd/compile till go1.19;
// now used only for serializing go/types.
// See https://github.com/golang/go/issues/69491.
_, pkg, err := IImportData(fset, packages, data[1:], id)
return pkg, err

case 'u': // unified, from go1.20
case 'u':
// unified: emitted by cmd/compile since go1.20.
_, pkg, err := UImportData(fset, packages, data[1:size], id)
return pkg, err

Expand Down
3 changes: 1 addition & 2 deletions internal/gcimporter/iexport.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ import (

"golang.org/x/tools/go/types/objectpath"
"golang.org/x/tools/internal/aliases"
"golang.org/x/tools/internal/tokeninternal"
)

// IExportShallow encodes "shallow" export data for the specified package.
Expand Down Expand Up @@ -441,7 +440,7 @@ func (p *iexporter) encodeFile(w *intWriter, file *token.File, needed []uint64)
// Sort the set of needed offsets. Duplicates are harmless.
sort.Slice(needed, func(i, j int) bool { return needed[i] < needed[j] })

lines := tokeninternal.GetLines(file) // byte offset of each line start
lines := file.Lines() // byte offset of each line start
w.uint64(uint64(len(lines)))

// Rather than record the entire array of line start offsets,
Expand Down
6 changes: 1 addition & 5 deletions internal/gcimporter/iexport_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,4 @@ package gcimporter

var IExportCommon = iexportCommon

const (
IExportVersion = iexportVersion
IExportVersionGenerics = iexportVersionGenerics
IExportVersionGo1_18 = iexportVersionGo1_18
)
const IExportVersion = iexportVersionGenerics
3 changes: 0 additions & 3 deletions internal/gcimporter/iexport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

// This is a copy of bexport_test.go for iexport.go.

//go:build go1.11
// +build go1.11

package gcimporter_test

import (
Expand Down
1 change: 1 addition & 0 deletions internal/gcimporter/iimport.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ const (
iexportVersionPosCol = 1
iexportVersionGo1_18 = 2
iexportVersionGenerics = 2
iexportVersion = iexportVersionGenerics

iexportVersionCurrent = 2
)
Expand Down
34 changes: 0 additions & 34 deletions internal/gcimporter/support_go118.go

This file was deleted.

Loading

0 comments on commit 3bb0ed7

Please sign in to comment.