mirror of
https://github.com/golang/go.git
synced 2025-05-05 23:53:05 +00:00
internal/lsp: don't cache analysis.Pass on actionHandle
There is no need to cache the pass on the actionHandle, as it does not need to be reused and does not live outside the exec function. Change-Id: I1737271383776b35718df3475b4f888232d57ae4 Reviewed-on: https://go-review.googlesource.com/c/tools/+/203177 Run-TryBot: Rebecca Stambler <rstambler@golang.org> Reviewed-by: Michael Matloob <matloob@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
parent
dc9d807def
commit
e7a0da15e1
20
internal/lsp/cache/analysis.go
vendored
20
internal/lsp/cache/analysis.go
vendored
@ -56,7 +56,6 @@ type actionHandle struct {
|
|||||||
analyzer *analysis.Analyzer
|
analyzer *analysis.Analyzer
|
||||||
deps []*actionHandle
|
deps []*actionHandle
|
||||||
pkg *pkg
|
pkg *pkg
|
||||||
pass *analysis.Pass
|
|
||||||
isroot bool
|
isroot bool
|
||||||
objectFacts map[objectFactKey]analysis.Fact
|
objectFacts map[objectFactKey]analysis.Fact
|
||||||
packageFacts map[packageFactKey]analysis.Fact
|
packageFacts map[packageFactKey]analysis.Fact
|
||||||
@ -223,7 +222,6 @@ func (act *actionHandle) exec(ctx context.Context, fset *token.FileSet) ([]*sour
|
|||||||
AllObjectFacts: act.allObjectFacts,
|
AllObjectFacts: act.allObjectFacts,
|
||||||
AllPackageFacts: act.allPackageFacts,
|
AllPackageFacts: act.allPackageFacts,
|
||||||
}
|
}
|
||||||
act.pass = pass
|
|
||||||
|
|
||||||
if act.pkg.IsIllTyped() {
|
if act.pkg.IsIllTyped() {
|
||||||
return nil, nil, errors.Errorf("analysis skipped due to errors in package: %v", act.pkg.GetErrors())
|
return nil, nil, errors.Errorf("analysis skipped due to errors in package: %v", act.pkg.GetErrors())
|
||||||
@ -238,8 +236,12 @@ func (act *actionHandle) exec(ctx context.Context, fset *token.FileSet) ([]*sour
|
|||||||
}
|
}
|
||||||
|
|
||||||
// disallow calls after Run
|
// disallow calls after Run
|
||||||
pass.ExportObjectFact = nil
|
pass.ExportObjectFact = func(obj types.Object, fact analysis.Fact) {
|
||||||
pass.ExportPackageFact = nil
|
panic(fmt.Sprintf("%s: Pass.ExportObjectFact(%s, %T) called after Run", act, obj, fact))
|
||||||
|
}
|
||||||
|
pass.ExportPackageFact = func(fact analysis.Fact) {
|
||||||
|
panic(fmt.Sprintf("%s: Pass.ExportPackageFact(%T) called after Run", act, fact))
|
||||||
|
}
|
||||||
|
|
||||||
var errors []*source.Error
|
var errors []*source.Error
|
||||||
for _, diag := range diagnostics {
|
for _, diag := range diagnostics {
|
||||||
@ -313,10 +315,6 @@ func (act *actionHandle) importObjectFact(obj types.Object, ptr analysis.Fact) b
|
|||||||
|
|
||||||
// exportObjectFact implements Pass.ExportObjectFact.
|
// exportObjectFact implements Pass.ExportObjectFact.
|
||||||
func (act *actionHandle) exportObjectFact(obj types.Object, fact analysis.Fact) {
|
func (act *actionHandle) exportObjectFact(obj types.Object, fact analysis.Fact) {
|
||||||
if act.pass.ExportObjectFact == nil {
|
|
||||||
panic(fmt.Sprintf("%s: Pass.ExportObjectFact(%s, %T) called after Run", act, obj, fact))
|
|
||||||
}
|
|
||||||
|
|
||||||
if obj.Pkg() != act.pkg.types {
|
if obj.Pkg() != act.pkg.types {
|
||||||
panic(fmt.Sprintf("internal error: in analysis %s of package %s: Fact.Set(%s, %T): can't set facts on objects belonging another package",
|
panic(fmt.Sprintf("internal error: in analysis %s of package %s: Fact.Set(%s, %T): can't set facts on objects belonging another package",
|
||||||
act.analyzer, act.pkg.ID(), obj, fact))
|
act.analyzer, act.pkg.ID(), obj, fact))
|
||||||
@ -352,11 +350,7 @@ func (act *actionHandle) importPackageFact(pkg *types.Package, ptr analysis.Fact
|
|||||||
|
|
||||||
// exportPackageFact implements Pass.ExportPackageFact.
|
// exportPackageFact implements Pass.ExportPackageFact.
|
||||||
func (act *actionHandle) exportPackageFact(fact analysis.Fact) {
|
func (act *actionHandle) exportPackageFact(fact analysis.Fact) {
|
||||||
if act.pass.ExportPackageFact == nil {
|
key := packageFactKey{act.pkg.types, factType(fact)}
|
||||||
panic(fmt.Sprintf("%s: Pass.ExportPackageFact(%T) called after Run", act, fact))
|
|
||||||
}
|
|
||||||
|
|
||||||
key := packageFactKey{act.pass.Pkg, factType(fact)}
|
|
||||||
act.packageFacts[key] = fact // clobber any existing entry
|
act.packageFacts[key] = fact // clobber any existing entry
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user