summary refs log tree commit diff stats
path: root/compiler
diff options
context:
space:
mode:
authorȘtefan Talpalaru <stefantalpalaru@yahoo.com>2022-02-24 08:31:40 +0100
committerGitHub <noreply@github.com>2022-02-24 08:31:40 +0100
commit0c915b5e47e554d657f6533f262cebbcf1554e8f (patch)
tree83f9c8d515b0f7dc8a1d53842dc036dc6f235205 /compiler
parent516db3bac389ea554166ee1a6671b5005159a30a (diff)
downloadNim-0c915b5e47e554d657f6533f262cebbcf1554e8f.tar.gz
compile pragma: cache the result sooner (#19554)
extccomp.addExternalFileToCompile() relies on hashes to decide whether
an external C file needs recompilation or not.

Due to short-circuit evaluation of boolean expressions, the procedure
that generates a corresponding hash file is not called the first time an
external file is compiled, so an avoidable recompilation is triggered
the next build.

This patch fixes that by moving the proc call with a desired side
effect from its boolean expression, so it's executed unconditionally.
Diffstat (limited to 'compiler')
-rw-r--r--compiler/extccomp.nim4
1 files changed, 3 insertions, 1 deletions
diff --git a/compiler/extccomp.nim b/compiler/extccomp.nim
index e7e1bcd51..124cc2c34 100644
--- a/compiler/extccomp.nim
+++ b/compiler/extccomp.nim
@@ -649,8 +649,10 @@ proc externalFileChanged(conf: ConfigRef; cfile: Cfile): bool =
       close(f)
 
 proc addExternalFileToCompile*(conf: ConfigRef; c: var Cfile) =
+  # we want to generate the hash file unconditionally
+  let extFileChanged = externalFileChanged(conf, c)
   if optForceFullMake notin conf.globalOptions and fileExists(c.obj) and
-      not externalFileChanged(conf, c):
+      not extFileChanged:
     c.flags.incl CfileFlag.Cached
   else:
     # make sure Nim keeps recompiling the external file on reruns