+ support isGenericInstance parameter in findSymInfoIndex and use it to mark caught exceptions only for isGenericInstance=true records

This commit is contained in:
Nikolay Nikolov
2024-05-14 20:18:12 +03:00
parent 34ab3ebcc7
commit 9b31d4aaa6
2 changed files with 20 additions and 2 deletions

View File

@@ -957,7 +957,7 @@ proc checkForSink(tracked: PEffects; n: PNode) =
proc markCaughtExceptions(tracked: PEffects; g: ModuleGraph; info: TLineInfo; s: PSym; usageSym: var PSym) =
when defined(nimsuggest):
proc internalMarkCaughtExceptions(tracked: PEffects; q: var SuggestFileSymbolDatabase; info: TLineInfo) =
var si = q.findSymInfoIndex(info)
var si = q.findSymInfoIndex(info, true)
if si != -1:
q.caughtExceptionsSet[si] = true
for w1 in tracked.caughtExceptions.nodes:

View File

@@ -216,7 +216,11 @@ proc add*(s: var SuggestFileSymbolDatabase; v: SymInfoPair) =
proc add*(s: var SuggestSymbolDatabase; v: SymInfoPair; trackCaughtExceptions: bool) =
s.mgetOrPut(v.info.fileIndex, newSuggestFileSymbolDatabase(v.info.fileIndex, trackCaughtExceptions)).add(v)
proc findSymInfoIndex*(s: var SuggestFileSymbolDatabase; li: TLineInfo): int =
proc findSymInfoIndex*(s: var SuggestFileSymbolDatabase; li: TLineInfo; isGenericInstance: bool): int =
# if trackCaughtExceptions is false, then all records in the database are not generic instances, so
# if we're searching for a generic instance, we find none
if isGenericInstance and not s.trackCaughtExceptions:
return -1
doAssert(li.fileIndex == s.fileIndex)
if not s.isSorted:
s.sort()
@@ -225,3 +229,17 @@ proc findSymInfoIndex*(s: var SuggestFileSymbolDatabase; li: TLineInfo): int =
col: li.col
)
result = binarySearch(s.lineInfo, q, cmp)
# if trackCaughtExceptions is false, then all records in the database are not generic instances, so
# if we're a searching for a non-generic instance, then we're done, we return what we have found
if not isGenericInstance and not s.trackCaughtExceptions:
return
# in this case trackCaughtExceptions is true, and the database contains both generic and non-generic instances, so we need
# to check the isGenericInstance flag also
if result != -1:
# search through a sequence of equal lineInfos to find a matching isGenericInstance
while result > 0 and s.isGenericInstance[result] != isGenericInstance and cmp(s.lineInfo[result], s.lineInfo[result - 1]) == 0:
dec result
while result < (s.lineInfo.len - 1) and s.isGenericInstance[result] != isGenericInstance and cmp(s.lineInfo[result], s.lineInfo[result + 1]) == 0:
inc result
if s.isGenericInstance[result] != isGenericInstance:
result = -1