Enable analysis of packages using type parameters

Upstream analyzers support type parameters now, so we no longer need to skip
analysis.

PiperOrigin-RevId: 504383378
This commit is contained in:
Michael Pratt
2023-01-24 14:56:58 -08:00
committed by gVisor bot
parent 0a580e0fbf
commit 2e68fa3c15
2 changed files with 7 additions and 18 deletions
+6 -2
View File
@@ -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))
+1 -16
View File
@@ -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.