Skip to content

Commit 24c28f7

Browse files
committed
include nodeId in the cache key insead
1 parent c9f7b9e commit 24c28f7

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

internal/checker/checker.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ type ReverseMappedTypeKey struct {
226226
type IterationTypesKey struct {
227227
typeId TypeId
228228
use IterationUse
229+
nodeId ast.NodeId
229230
}
230231

231232
// FlowLoopKey
@@ -5881,26 +5882,21 @@ func (c *Checker) getIterationTypesOfIterable(t *Type, use IterationUse, errorNo
58815882
if IsTypeAny(t) {
58825883
return IterationTypes{c.anyType, c.anyType, c.anyType}
58835884
}
5884-
key := IterationTypesKey{typeId: t.id, use: use & IterationUseCacheFlags}
5885-
// If we are reporting errors and encounter a cached `noIterationTypes`, we should ignore the cached value and continue as if nothing was cached.
5886-
// In addition, we should not cache any new results for this call.
5887-
noCache := false
5888-
if cached, ok := c.iterationTypesCache[key]; ok {
5889-
if errorNode == nil || cached.hasTypes() {
5890-
return cached
5891-
}
5892-
noCache = true
5885+
var nodeId ast.NodeId
5886+
if errorNode != nil {
5887+
nodeId = ast.GetNodeId(errorNode)
58935888
}
5894-
result := c.getIterationTypesOfIterableWorker(t, use, errorNode, noCache)
5895-
if !noCache {
5896-
c.iterationTypesCache[key] = result
5889+
key := IterationTypesKey{typeId: t.id, use: use & IterationUseCacheFlags, nodeId: nodeId}
5890+
if cached, ok := c.iterationTypesCache[key]; ok {
5891+
return cached
58975892
}
5893+
result := c.getIterationTypesOfIterableWorker(t, use, errorNode)
58985894
return result
58995895
}
59005896

5901-
func (c *Checker) getIterationTypesOfIterableWorker(t *Type, use IterationUse, errorNode *ast.Node, noCache bool) IterationTypes {
5897+
func (c *Checker) getIterationTypesOfIterableWorker(t *Type, use IterationUse, errorNode *ast.Node) IterationTypes {
59025898
if t.flags&TypeFlagsUnion != 0 {
5903-
return c.combineIterationTypes(core.Map(t.Types(), func(t *Type) IterationTypes { return c.getIterationTypesOfIterableWorker(t, use, errorNode, noCache) }))
5899+
return c.combineIterationTypes(core.Map(t.Types(), func(t *Type) IterationTypes { return c.getIterationTypesOfIterableWorker(t, use, errorNode) }))
59045900
}
59055901
if use&IterationUseAllowsAsyncIterablesFlag != 0 {
59065902
iterationTypes := c.getIterationTypesOfIterableFast(t, c.asyncIterationTypesResolver)

0 commit comments

Comments
 (0)