]> Cypherpunks.ru repositories - gostls13.git/commit
go/*,cmd/gofmt: guard AST changes with the typeparams build tag
authorRob Findley <rfindley@google.com>
Fri, 5 Mar 2021 15:57:48 +0000 (10:57 -0500)
committerRobert Findley <rfindley@google.com>
Tue, 13 Apr 2021 22:24:31 +0000 (22:24 +0000)
commitefaf75a2166d397b2050cc0bb1b60b0c80698e2d
treec1ec333957953f7ed90c0883b85fe786fb3f7596
parent693859542e71fdd9186fff759bf121e9df197fed
go/*,cmd/gofmt: guard AST changes with the typeparams build tag

This CL changes our approach to guarding type parameter functionality
and API. Previously, we guarded type parameter functionality with the
parser.parseTypeParams parser mode, and were in the process of hiding
the type parameter API behind the go1.18 build constraint.

These mechanisms had several limitations:
 + Requiring the parser.parseTypeParams mode to be set meant that
   existing tooling would have to opt-in to type parameters in all
   places where it parses Go files.
 + The parseTypeParams mode value had to be copied in several places.
 + go1.18 is not specific to typeparams, making it difficult to set up
   the builders to run typeparams tests.

This CL addresses the above limitations, and completes the task of
hiding the AST API, by switching to a new 'typeparams' build constraint
and adding a new go/internal/typeparams helper package.

The typeparams build constraint is used to conditionally compile the new
AST changes. The typeparams package provides utilities for accessing and
writing the new AST data, so that we don't have to fragment our parser
or type checker logic across build constraints. The typeparams.Enabled
const is used to guard tests that require type parameter support.

The parseTypeParams parser mode is gone, replaced by a new
typeparams.DisableParsing mode with the opposite sense. Now, type
parameters are only parsed if go/parser is compiled with the typeparams
build constraint set AND typeparams.DisableParsing not set. This new
parser mode allows opting out of type parameter parsing for tests.

How exactly to run tests on builders is left to a follow-up CL.

Updates #44933

Change-Id: I3091e42a2e5e2f23e8b2ae584f415a784b9fbd65
Reviewed-on: https://go-review.googlesource.com/c/go/+/300649
Trust: Robert Findley <rfindley@google.com>
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
35 files changed:
src/cmd/gofmt/gofmt.go
src/cmd/gofmt/gofmt_test.go
src/cmd/gofmt/gofmt_typeparams_test.go [moved from src/cmd/gofmt/gofmt_go1.18.go with 73% similarity]
src/go/ast/ast.go
src/go/ast/ast_notypeparams.go [new file with mode: 0644]
src/go/ast/ast_typeparams.go [new file with mode: 0644]
src/go/ast/walk.go
src/go/ast/walk_notypeparams.go [new file with mode: 0644]
src/go/ast/walk_typeparams.go [new file with mode: 0644]
src/go/build/deps_test.go
src/go/internal/typeparams/common.go [new file with mode: 0644]
src/go/internal/typeparams/notypeparams.go [new file with mode: 0644]
src/go/internal/typeparams/typeparams.go [new file with mode: 0644]
src/go/parser/error_test.go
src/go/parser/interface.go
src/go/parser/parser.go
src/go/parser/resolver.go
src/go/parser/resolver_test.go
src/go/parser/short_test.go
src/go/printer/nodes.go
src/go/printer/printer_test.go
src/go/printer/testdata/declarations.golden
src/go/printer/testdata/declarations.input
src/go/printer/testdata/generics.golden
src/go/printer/testdata/generics.input
src/go/types/api_test.go
src/go/types/api_typeparams.go [moved from src/go/types/api_go1.18.go with 90% similarity]
src/go/types/api_typeparams_test.go [moved from src/go/types/api_go1.18_test.go with 98% similarity]
src/go/types/assignments.go
src/go/types/call.go
src/go/types/check_test.go
src/go/types/decl.go
src/go/types/exprstring.go
src/go/types/resolver.go
src/go/types/typexpr.go