diff options
author | Pylgos <43234674+Pylgos@users.noreply.github.com> | 2023-10-03 17:22:31 +0900 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-03 10:22:31 +0200 |
commit | db36765afd41fac8b30d0564f0f86e7315bd781d (patch) | |
tree | 2136eee7eb494cd6decd56ec584b3fc9fa4283f0 | |
parent | 5d5c39e7452af71162c6d9b499dffe86d9c2d485 (diff) | |
download | Nim-db36765afd41fac8b30d0564f0f86e7315bd781d.tar.gz |
nimsuggest: Clear generic inst cache before partial recompilation (#22783)
fixes #19371 fixes #21093 fixes #22119
-rw-r--r-- | nimsuggest/nimsuggest.nim | 24 | ||||
-rw-r--r-- | nimsuggest/tests/tgenerics.nim | 18 | ||||
-rw-r--r-- | nimsuggest/tests/tv3_generics.nim | 18 |
3 files changed, 57 insertions, 3 deletions
diff --git a/nimsuggest/nimsuggest.nim b/nimsuggest/nimsuggest.nim index 649ece06b..28faf9e3c 100644 --- a/nimsuggest/nimsuggest.nim +++ b/nimsuggest/nimsuggest.nim @@ -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() diff --git a/nimsuggest/tests/tgenerics.nim b/nimsuggest/tests/tgenerics.nim new file mode 100644 index 000000000..7f490321c --- /dev/null +++ b/nimsuggest/tests/tgenerics.nim @@ -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 +""" diff --git a/nimsuggest/tests/tv3_generics.nim b/nimsuggest/tests/tv3_generics.nim new file mode 100644 index 000000000..2bfb2ca1d --- /dev/null +++ b/nimsuggest/tests/tv3_generics.nim @@ -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 +""" |