aboutsummaryrefslogtreecommitdiff
path: root/src/go/parser/resolver.go
diff options
context:
space:
mode:
authorRob Findley <rfindley@google.com>2021-03-05 10:57:48 -0500
committerRobert Findley <rfindley@google.com>2021-04-13 22:24:31 +0000
commitefaf75a2166d397b2050cc0bb1b60b0c80698e2d (patch)
treec1ec333957953f7ed90c0883b85fe786fb3f7596 /src/go/parser/resolver.go
parent693859542e71fdd9186fff759bf121e9df197fed (diff)
downloadgo-efaf75a2166d397b2050cc0bb1b60b0c80698e2d.tar.gz
go-efaf75a2166d397b2050cc0bb1b60b0c80698e2d.zip
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>
Diffstat (limited to 'src/go/parser/resolver.go')
-rw-r--r--src/go/parser/resolver.go6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/go/parser/resolver.go b/src/go/parser/resolver.go
index dd77b685e3..1e357e26df 100644
--- a/src/go/parser/resolver.go
+++ b/src/go/parser/resolver.go
@@ -7,6 +7,7 @@ package parser
import (
"fmt"
"go/ast"
+ "go/internal/typeparams"
"go/token"
)
@@ -450,10 +451,10 @@ func (r *resolver) Visit(node ast.Node) ast.Visitor {
// at the identifier in the TypeSpec and ends at the end of the innermost
// containing block.
r.declare(spec, nil, r.topScope, ast.Typ, spec.Name)
- if spec.TParams != nil {
+ if tparams := typeparams.Get(spec); tparams != nil {
r.openScope(spec.Pos())
defer r.closeScope()
- r.walkFieldList(r.topScope, spec.TParams, ast.Typ)
+ r.walkFieldList(r.topScope, tparams, ast.Typ)
}
ast.Walk(r, spec.Type)
}
@@ -476,7 +477,6 @@ func (r *resolver) Visit(node ast.Node) ast.Visitor {
}
func (r *resolver) walkFuncType(scope *ast.Scope, typ *ast.FuncType) {
- r.walkFieldList(scope, typ.TParams, ast.Typ)
r.walkFieldList(scope, typ.Params, ast.Var)
r.walkFieldList(scope, typ.Results, ast.Var)
}