From 0df0ca0f43117120bd7cc900ebf765f9b799438a Mon Sep 17 00:00:00 2001 From: Robert Findley Date: Tue, 28 Sep 2021 18:05:55 -0400 Subject: [PATCH] internal/typeparams: hide go1.18 API usage behind a build constraint Temporarily hide usage of the new go/types API, so that we can safely tag x/tools@v0.1.7 without risk of further breakage when these APIs change. Updates golang/go#48632 Change-Id: Idba02d09644622b3d973a684a76514c86eefa17f Reviewed-on: https://go-review.googlesource.com/c/tools/+/352854 Trust: Robert Findley Run-TryBot: Robert Findley Reviewed-by: Rebecca Stambler gopls-CI: kokoro TryBot-Result: Go Bot --- go/internal/gcimporter/gcimporter_test.go | 7 +++++++ go/internal/gcimporter/iexport_go118_test.go | 4 ++-- go/internal/gcimporter/iexport_test.go | 8 ++++++-- go/internal/gcimporter/support_go117.go | 4 ++-- go/internal/gcimporter/support_go118.go | 4 ++-- internal/typeparams/enabled_go117.go | 4 ++-- internal/typeparams/enabled_go118.go | 4 ++-- internal/typeparams/typeparams_go117.go | 4 ++-- internal/typeparams/typeparams_go118.go | 4 ++-- internal/typeparams/typeparams_test.go | 4 ++-- 10 files changed, 29 insertions(+), 18 deletions(-) diff --git a/go/internal/gcimporter/gcimporter_test.go b/go/internal/gcimporter/gcimporter_test.go index e5eb9ed3fd..c586f1fc3e 100644 --- a/go/internal/gcimporter/gcimporter_test.go +++ b/go/internal/gcimporter/gcimporter_test.go @@ -22,6 +22,7 @@ import ( "time" "golang.org/x/tools/internal/testenv" + "golang.org/x/tools/internal/typeparams" ) func TestMain(m *testing.M) { @@ -106,6 +107,12 @@ func testDir(t *testing.T, dir string, endTime time.Time) (nimports int) { for _, ext := range pkgExts { if strings.HasSuffix(f.Name(), ext) { name := f.Name()[0 : len(f.Name())-len(ext)] // remove extension + if testenv.UsesGenerics(name) && !typeparams.Enabled { + // golang/go#48632: Skip generic packages when type parameters are + // not enabled, as a temporary measure to allow avoiding the new + // go/types API on Go 1.18. + continue + } if testPath(t, filepath.Join(dir, name), dir) != nil { nimports++ } diff --git a/go/internal/gcimporter/iexport_go118_test.go b/go/internal/gcimporter/iexport_go118_test.go index 3c9610ea75..631d2b7358 100644 --- a/go/internal/gcimporter/iexport_go118_test.go +++ b/go/internal/gcimporter/iexport_go118_test.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build go1.18 -// +build go1.18 +//go:build typeparams && go1.18 +// +build typeparams,go1.18 package gcimporter_test diff --git a/go/internal/gcimporter/iexport_test.go b/go/internal/gcimporter/iexport_test.go index 084679bbd4..f247d97a37 100644 --- a/go/internal/gcimporter/iexport_test.go +++ b/go/internal/gcimporter/iexport_test.go @@ -32,6 +32,7 @@ import ( "golang.org/x/tools/go/internal/gcimporter" "golang.org/x/tools/go/loader" "golang.org/x/tools/internal/testenv" + "golang.org/x/tools/internal/typeparams" ) func readExportFile(filename string) ([]byte, error) { @@ -96,9 +97,12 @@ func TestIExportData_stdlib(t *testing.T) { // TODO(#48595): fix this test with GOEXPERIMENT=unified. isUnified := isUnifiedBuilder() for _, path := range buildutil.AllPackages(conf.Build) { - if !(isUnified && testenv.UsesGenerics(path)) { - conf.Import(path) + if testenv.UsesGenerics(path) && (isUnified || !typeparams.Enabled) { + // golang/go#48632: Skip generic packages if we can't handle type + // parameters. + continue } + conf.Import(path) } // Create a package containing type and value errors to ensure diff --git a/go/internal/gcimporter/support_go117.go b/go/internal/gcimporter/support_go117.go index d892273efb..817a147ef0 100644 --- a/go/internal/gcimporter/support_go117.go +++ b/go/internal/gcimporter/support_go117.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !go1.18 -// +build !go1.18 +//go:build !typeparams || !go1.18 +// +build !typeparams !go1.18 package gcimporter diff --git a/go/internal/gcimporter/support_go118.go b/go/internal/gcimporter/support_go118.go index 2c98f0acbb..e6b81fc50e 100644 --- a/go/internal/gcimporter/support_go118.go +++ b/go/internal/gcimporter/support_go118.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build go1.18 -// +build go1.18 +//go:build typeparams && go1.18 +// +build typeparams,go1.18 package gcimporter diff --git a/internal/typeparams/enabled_go117.go b/internal/typeparams/enabled_go117.go index 18212390e1..72d010e518 100644 --- a/internal/typeparams/enabled_go117.go +++ b/internal/typeparams/enabled_go117.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !go1.18 -// +build !go1.18 +//go:build !typeparams || !go1.18 +// +build !typeparams !go1.18 package typeparams diff --git a/internal/typeparams/enabled_go118.go b/internal/typeparams/enabled_go118.go index d67148823c..642fc8ee21 100644 --- a/internal/typeparams/enabled_go118.go +++ b/internal/typeparams/enabled_go118.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build go1.18 -// +build go1.18 +//go:build typeparams && go1.18 +// +build typeparams,go1.18 package typeparams diff --git a/internal/typeparams/typeparams_go117.go b/internal/typeparams/typeparams_go117.go index 479b5561d7..12817af856 100644 --- a/internal/typeparams/typeparams_go117.go +++ b/internal/typeparams/typeparams_go117.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build !go1.18 -// +build !go1.18 +//go:build !typeparams || !go1.18 +// +build !typeparams !go1.18 package typeparams diff --git a/internal/typeparams/typeparams_go118.go b/internal/typeparams/typeparams_go118.go index 16c6c0d157..8ab17b7779 100644 --- a/internal/typeparams/typeparams_go118.go +++ b/internal/typeparams/typeparams_go118.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build go1.18 -// +build go1.18 +//go:build typeparams && go1.18 +// +build typeparams,go1.18 package typeparams diff --git a/internal/typeparams/typeparams_test.go b/internal/typeparams/typeparams_test.go index 9302ad75c1..68e6409fa6 100644 --- a/internal/typeparams/typeparams_test.go +++ b/internal/typeparams/typeparams_test.go @@ -2,8 +2,8 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -//go:build go1.18 -// +build go1.18 +//go:build typeparams && go1.18 +// +build typeparams,go1.18 package typeparams_test