diff options
author | ringabout <43030857+ringabout@users.noreply.github.com> | 2024-02-01 04:36:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-31 21:36:59 +0100 |
commit | 519d976f6241023b05b06188e6d96245d0a6a2fe (patch) | |
tree | 8a5809594f2ca314e061411dabf5666bbaa561a1 | |
parent | 98b083d750b1660c6ed1714485d4c8d5f8b29b34 (diff) | |
download | Nim-519d976f6241023b05b06188e6d96245d0a6a2fe.tar.gz |
compute checksum of nim files early in the pipelines (#23268)
related https://github.com/nim-lang/Nim/issues/21717 configs will be resolved later
-rw-r--r-- | compiler/extccomp.nim | 12 | ||||
-rw-r--r-- | compiler/main.nim | 2 | ||||
-rw-r--r-- | compiler/modulegraphs.nim | 5 | ||||
-rw-r--r-- | compiler/modules.nim | 5 | ||||
-rw-r--r-- | compiler/pipelines.nim | 9 |
5 files changed, 25 insertions, 8 deletions
diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim index 3deab0b74..0ea458e3b 100644 --- a/compiler/extccomp.nim +++ b/compiler/extccomp.nim @@ -19,7 +19,7 @@ import std/[os, osproc, streams, sequtils, times, strtabs, json, jsonutils, suga import std / strutils except addf when defined(nimPreviewSlimSystem): - import std/syncio + import std/[syncio, assertions] import ../dist/checksums/src/checksums/sha1 @@ -999,7 +999,7 @@ type BuildCache = object depfiles: seq[(string, string)] nimexe: string -proc writeJsonBuildInstructions*(conf: ConfigRef) = +proc writeJsonBuildInstructions*(conf: ConfigRef; deps: StringTableRef) = var linkFiles = collect(for it in conf.externalToLink: var it = it if conf.noAbsolutePaths: it = it.extractFilename @@ -1020,10 +1020,14 @@ proc writeJsonBuildInstructions*(conf: ConfigRef) = currentDir: getCurrentDir()) if optRun in conf.globalOptions or isDefined(conf, "nimBetterRun"): bcache.cmdline = conf.commandLine - bcache.depfiles = collect(for it in conf.m.fileInfos: + for it in conf.m.fileInfos: let path = it.fullPath.string if isAbsolute(path): # TODO: else? - (path, $secureHashFile(path))) + if path in deps: + bcache.depfiles.add (path, deps[path]) + else: # backup for configs etc. + bcache.depfiles.add (path, $secureHashFile(path)) + bcache.nimexe = hashNimExe() conf.jsonBuildFile = conf.jsonBuildInstructionsFile conf.jsonBuildFile.string.writeFile(bcache.toJson.pretty) diff --git a/compiler/main.nim b/compiler/main.nim index 4d472da6f..4c7b87e1a 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -155,7 +155,7 @@ proc commandCompileToC(graph: ModuleGraph) = extccomp.callCCompiler(conf) # for now we do not support writing out a .json file with the build instructions when HCR is on if not conf.hcrOn: - extccomp.writeJsonBuildInstructions(conf) + extccomp.writeJsonBuildInstructions(conf, graph.cachedFiles) if optGenScript in graph.config.globalOptions: writeDepsFile(graph) if optGenCDeps in graph.config.globalOptions: diff --git a/compiler/modulegraphs.nim b/compiler/modulegraphs.nim index 89ed4967f..9885a9b45 100644 --- a/compiler/modulegraphs.nim +++ b/compiler/modulegraphs.nim @@ -11,7 +11,7 @@ ## represents a complete Nim project. Single modules can either be kept in RAM ## or stored in a rod-file. -import std/[intsets, tables, hashes] +import std/[intsets, tables, hashes, strtabs] import ../dist/checksums/src/checksums/md5 import ast, astalgo, options, lineinfos,idents, btrees, ropes, msgs, pathutils, packages import ic / [packed_ast, ic] @@ -140,6 +140,8 @@ type idgen*: IdGenerator operators*: Operators + cachedFiles*: StringTableRef + TPassContext* = object of RootObj # the pass's context idgen*: IdGenerator PPassContext* = ref TPassContext @@ -518,6 +520,7 @@ proc initModuleGraphFields(result: ModuleGraph) = result.symBodyHashes = initTable[int, SigHash]() result.operators = initOperators(result) result.emittedTypeInfo = initTable[string, FileIndex]() + result.cachedFiles = newStringTable() proc newModuleGraph*(cache: IdentCache; config: ConfigRef): ModuleGraph = result = ModuleGraph() diff --git a/compiler/modules.nim b/compiler/modules.nim index 0aa1c8930..6e2af8bcc 100644 --- a/compiler/modules.nim +++ b/compiler/modules.nim @@ -14,6 +14,9 @@ import idents, lexer, syntaxes, modulegraphs, lineinfos, pathutils +import ../dist/checksums/src/checksums/sha1 +import std/strtabs + proc resetSystemArtifacts*(g: ModuleGraph) = magicsys.resetSysTypes(g) @@ -42,6 +45,8 @@ proc includeModule*(graph: ModuleGraph; s: PSym, fileIdx: FileIndex): PNode = result = syntaxes.parseFile(fileIdx, graph.cache, graph.config) graph.addDep(s, fileIdx) graph.addIncludeDep(s.position.FileIndex, fileIdx) + let path = toFullPath(graph.config, fileIdx) + graph.cachedFiles[path] = $secureHashFile(path) proc wantMainModule*(conf: ConfigRef) = if conf.projectFull.isEmpty: diff --git a/compiler/pipelines.nim b/compiler/pipelines.nim index 7f318d6f1..58e664953 100644 --- a/compiler/pipelines.nim +++ b/compiler/pipelines.nim @@ -5,10 +5,12 @@ import sem, cgen, modulegraphs, ast, llstream, parser, msgs, import pipelineutils +import ../dist/checksums/src/checksums/sha1 + when not defined(leanCompiler): import jsgen, docgen2 -import std/[syncio, objectdollar, assertions, tables, strutils] +import std/[syncio, objectdollar, assertions, tables, strutils, strtabs] import renderer import ic/replayer import nir/nir @@ -244,7 +246,10 @@ proc compilePipelineModule*(graph: ModuleGraph; fileIdx: FileIndex; flags: TSymF if result == nil: var cachedModules: seq[FileIndex] = @[] result = moduleFromRodFile(graph, fileIdx, cachedModules) - let filename = AbsoluteFile toFullPath(graph.config, fileIdx) + let path = toFullPath(graph.config, fileIdx) + let filename = AbsoluteFile path + if fileExists(filename): # it could be a stdinfile + graph.cachedFiles[path] = $secureHashFile(path) if result == nil: result = newModule(graph, fileIdx) result.flags.incl flags |