Skip to content

Commit 10909d8

Browse files
committed
internal/lsp/cache: remove type info trimming
This broke staticcheck and x/tools/refactor, most notably used for our rename support. Doesn't look like a winner. Roll it back :( Updates golang/go#45457. Change-Id: I30d5aa160fd9319329d36b2a534ee3c756090726 Reviewed-on: https://go-review.googlesource.com/c/tools/+/311549 Trust: Heschi Kreinick <[email protected]> Run-TryBot: Heschi Kreinick <[email protected]> Reviewed-by: Robert Findley <[email protected]> gopls-CI: kokoro <[email protected]>
1 parent 1dce19d commit 10909d8

File tree

1 file changed

+1
-36
lines changed

1 file changed

+1
-36
lines changed

internal/lsp/cache/check.go

Lines changed: 1 addition & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ func typeCheck(ctx context.Context, snapshot *snapshot, m *metadata, mode source
446446
typesinternal.SetUsesCgo(cfg)
447447

448448
check := types.NewChecker(cfg, fset, pkg.types, pkg.typesInfo)
449+
449450
// Type checking errors are handled via the config, so ignore them here.
450451
_ = check.Files(files)
451452
// If the context was cancelled, we may have returned a ton of transient
@@ -454,12 +455,6 @@ func typeCheck(ctx context.Context, snapshot *snapshot, m *metadata, mode source
454455
return nil, ctx.Err()
455456
}
456457

457-
// staticcheck requires full type information. Reduce memory usage for
458-
// everyone else.
459-
if !snapshot.view.Options().Staticcheck {
460-
trimTypesInfo(files, pkg.typesInfo)
461-
}
462-
463458
// We don't care about a package's errors unless we have parsed it in full.
464459
if mode != source.ParseFull {
465460
return pkg, nil
@@ -800,33 +795,3 @@ func isValidImport(pkgPath, importPkgPath packagePath) bool {
800795
type importerFunc func(path string) (*types.Package, error)
801796

802797
func (f importerFunc) Import(path string) (*types.Package, error) { return f(path) }
803-
804-
func trimTypesInfo(files []*ast.File, info *types.Info) {
805-
for _, file := range files {
806-
ast.Inspect(file, func(n ast.Node) bool {
807-
if n == nil {
808-
return false
809-
}
810-
cl, ok := n.(*ast.CompositeLit)
811-
if !ok {
812-
return true
813-
}
814-
815-
// types.Info.Types for long slice/array literals are particularly
816-
// expensive. Try to clear them out.
817-
if _, ok := cl.Type.(*ast.ArrayType); !ok {
818-
return true
819-
}
820-
821-
for _, elt := range cl.Elts {
822-
// Only delete information for basic literals; other elements,
823-
// like constants and function calls, could still be relevant.
824-
if _, ok := elt.(*ast.BasicLit); ok {
825-
delete(info.Types, elt)
826-
}
827-
}
828-
829-
return true
830-
})
831-
}
832-
}

0 commit comments

Comments
 (0)