nimsuggest: Clear generic inst cache before partial recompilation (#22783)

fixes #19371
fixes #21093
fixes #22119
This commit is contained in:
Pylgos
2023-10-03 17:22:31 +09:00
committed by GitHub
parent 5d5c39e745
commit db36765afd
3 changed files with 57 additions and 3 deletions

View File

@@ -193,6 +193,24 @@ template benchmark(benchmarkName: untyped, code: untyped) =
let elapsedStr = elapsed.formatFloat(format = ffDecimal, precision = 3)
myLog "CPU Time [" & benchmarkName & "] " & elapsedStr & "s"
proc clearInstCache(graph: ModuleGraph, projectFileIdx: FileIndex) =
if projectFileIdx == InvalidFileIdx:
graph.typeInstCache.clear()
graph.procInstCache.clear()
return
var typeIdsToDelete = newSeq[ItemId]()
for id in graph.typeInstCache.keys:
if id.module == projectFileIdx.int:
typeIdsToDelete.add id
for id in typeIdsToDelete:
graph.typeInstCache.del id
var procIdsToDelete = newSeq[ItemId]()
for id in graph.procInstCache.keys:
if id.module == projectFileIdx.int:
procIdsToDelete.add id
for id in procIdsToDelete:
graph.procInstCache.del id
proc executeNoHooks(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int, tag: string,
graph: ModuleGraph) =
let conf = graph.config
@@ -221,6 +239,7 @@ proc executeNoHooks(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int,
if conf.suggestVersion == 1:
graph.usageSym = nil
if not isKnownFile:
graph.clearInstCache(dirtyIdx)
graph.compileProject(dirtyIdx)
if conf.suggestVersion == 0 and conf.ideCmd in {ideUse, ideDus} and
dirtyfile.isEmpty:
@@ -231,6 +250,7 @@ proc executeNoHooks(cmd: IdeCmd, file, dirtyfile: AbsoluteFile, line, col: int,
graph.markClientsDirty dirtyIdx
if conf.ideCmd != ideMod:
if isKnownFile:
graph.clearInstCache(modIdx)
graph.compileProject(modIdx)
if conf.ideCmd in {ideUse, ideDus}:
let u = if conf.suggestVersion != 1: graph.symFromInfo(conf.m.trackPos) else: graph.usageSym
@@ -716,9 +736,7 @@ proc recompilePartially(graph: ModuleGraph, projectFileIdx = InvalidFileIdx) =
# inst caches are breaking incremental compilation when the cache caches stuff
# from dirty buffer
# TODO: investigate more efficient way to achieve the same
# graph.typeInstCache.clear()
# graph.procInstCache.clear()
graph.clearInstCache(projectFileIdx)
GC_fullCollect()

View File

@@ -0,0 +1,18 @@
type
Hello[T] = object
value: T
proc printHelloValue[T](hello: Hello[T]) =
echo hello.value
proc main() =
let a = Hello[float]()
p#[!]#rintHelloValue(a)
main()
discard """
$nimsuggest --tester $file
>def $1
def;;skProc;;tgenerics.printHelloValue;;proc (hello: Hello[printHelloValue.T]);;$file;;5;;5;;"";;100
"""

View File

@@ -0,0 +1,18 @@
type
Hello[T] = object
value: T
proc printHelloValue[T](hello: Hello[T]) =
echo hello.value
proc main() =
let a = Hello[float]()
p#[!]#rintHelloValue(a)
main()
discard """
$nimsuggest --v3 --tester $file
>def $1
def;;skProc;;tv3_generics.printHelloValue;;proc (hello: Hello[printHelloValue.T]);;$file;;5;;5;;"";;100
"""