From 2e68fa3c15d47ef9e54f81e368e6189fcfd2e257 Mon Sep 17 00:00:00 2001 From: Michael Pratt Date: Tue, 24 Jan 2023 14:54:23 -0800 Subject: [PATCH] Enable analysis of packages using type parameters Upstream analyzers support type parameters now, so we no longer need to skip analysis. PiperOrigin-RevId: 504383378 --- tools/checkinfo/checkinfo.go | 8 ++++++-- tools/nogo/check/check.go | 17 +---------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/tools/checkinfo/checkinfo.go b/tools/checkinfo/checkinfo.go index 702847099..cf9eef571 100644 --- a/tools/checkinfo/checkinfo.go +++ b/tools/checkinfo/checkinfo.go @@ -74,12 +74,16 @@ func walkObject(pass *analysis.Pass, obj types.Object) { pass.ExportObjectFact(obj, &a) pass.ExportObjectFact(obj, &s) case *types.TypeName: - // Skip if just an alias, or if not underlying type. If it is - // not an alias, then it must be package-local. + // Skip if just an alias, or if not underlying type, or if a + // type parameter. If it is not an alias, then it must be + // package-local. typ := x.Type() if x.IsAlias() || typ == nil || typ.Underlying() == nil { break } + if _, ok := typ.(*types.TypeParam); ok { + break + } // Add basic information. a := Align(pass.TypesSizes.Alignof(typ)) s := Size(pass.TypesSizes.Sizeof(typ)) diff --git a/tools/nogo/check/check.go b/tools/nogo/check/check.go index 96f2d4fa4..c3fd0e9df 100644 --- a/tools/nogo/check/check.go +++ b/tools/nogo/check/check.go @@ -365,6 +365,7 @@ func (i *importer) checkPackage(path string, srcs []string) (*types.Package, Fin } typesInfo := &types.Info{ Types: make(map[ast.Expr]types.TypeAndValue), + Instances: make(map[*ast.Ident]types.Instance), Uses: make(map[*ast.Ident]types.Object), Defs: make(map[*ast.Ident]types.Object), Implicits: make(map[ast.Node]types.Object), @@ -726,12 +727,6 @@ func SplitPackages(srcs []string, srcRootPrefix string) map[string][]string { continue } - // Skip unsupported packages explicitly. - if _, ok := usesTypeParams[pkg]; ok { - log.Printf("WARNING: Skipping package %q: type param analysis not yet supported.", pkg) - continue - } - // Add to the package. sources[pkg] = append(sources[pkg], filename) } @@ -739,16 +734,6 @@ func SplitPackages(srcs []string, srcRootPrefix string) map[string][]string { return sources } -// Go standard library packages using Go 1.18 type parameter features. -// -// As of writing, analysis tooling is not updated to support type parameters -// and will choke on these packages. We skip these packages entirely for now. -// -// TODO(b/201686256): remove once tooling can handle type parameters. -var usesTypeParams = map[string]struct{}{ - "sync/atomic": {}, // https://go.dev/issue/50860 -} - // Bundle checks a bundle of files (typically the standard library). func Bundle(sources map[string][]string) (FindingSet, facts.Serializer, error) { // Process all packages.