Skip to content

Commit 7076bcd

Browse files
committed
store/load ConfigRef fields
1 parent 408683a commit 7076bcd

File tree

1 file changed

+112
-2
lines changed

1 file changed

+112
-2
lines changed

compiler/nimconfcache.nim

Lines changed: 112 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import options, pathutils, condsyms
1+
import options, pathutils, platform, condsyms
22
import std/[assertions, os, sets, strtabs, times]
33
from std/sequtils import addUnique
44
from std/strutils import parseEnum
@@ -20,12 +20,22 @@ proc fromNif[T: enum](result: var set[T]; n: var Cursor) =
2020
# clear it so that it has the same value as it was stored to the cache.
2121
# some switches turn off options that were turned on when conf was initialized.
2222
result = {}
23-
assert n.kind == StringLit
23+
assert n.kind in {StringLit, ParRi}
2424
while n.kind != ParRi:
2525
result.incl parseEnum[T](pool.strings[n.litId])
2626
inc n
2727
inc n
2828

29+
proc fromNif2[T: enum](result: var set[T]; n: var Cursor) =
30+
# same to fromNif but works with enums `parseEnum` doesn't support.
31+
# e.g. TNoteKind
32+
result = {}
33+
assert n.kind in {IntLit, ParRi}
34+
while n.kind != ParRi:
35+
result.incl pool.integers[n.intId].T
36+
inc n
37+
inc n
38+
2939
template buildTree(dest: var TokenBuf; tag: string; body: untyped): untyped =
3040
buildTree(dest, pool.tags.getOrIncl(tag), NoLineInfo, body)
3141

@@ -38,6 +48,10 @@ proc configToNif(conf: ConfigRef; dest: var TokenBuf) =
3848

3949
# store fields that can be changed on config files
4050
# see processSwitch proc in commands.nim
51+
dest.addStrLit $conf.backend
52+
dest.addStrLit $conf.target.targetOS
53+
dest.addStrLit $conf.target.targetCPU
54+
4155
#echo "conf.options"
4256
#echo conf.options
4357
dest.buildTree "options":
@@ -87,6 +101,37 @@ proc configToNif(conf: ConfigRef; dest: var TokenBuf) =
87101
#echo conf.nimbasePattern
88102
dest.addStrLit conf.nimbasePattern
89103

104+
dest.buildTree "features":
105+
for f in conf.features:
106+
dest.addStrLit $f
107+
108+
dest.buildTree "legacyFeatures":
109+
for f in conf.legacyFeatures:
110+
dest.addStrLit $f
111+
112+
dest.addStrLit $conf.cCompiler
113+
114+
# stores TNoteKind as int as parseEnum doesn't work
115+
dest.buildTree "modifiedyNotes":
116+
for n in conf.modifiedyNotes:
117+
dest.addIntLit n.ord
118+
dest.buildTree "foreignPackageNotes":
119+
for n in conf.foreignPackageNotes:
120+
dest.addIntLit n.ord
121+
dest.buildTree "notes":
122+
for n in conf.notes:
123+
dest.addIntLit n.ord
124+
dest.buildTree "warningAsErrors":
125+
for n in conf.warningAsErrors:
126+
dest.addIntLit n.ord
127+
dest.buildTree "mainPackageNotes":
128+
for n in conf.mainPackageNotes:
129+
dest.addIntLit n.ord
130+
131+
dest.addIntLit conf.errorMax
132+
dest.addIntLit conf.maxLoopIterationsVM
133+
dest.addIntLit conf.maxCallDepthVM
134+
90135
dest.buildTree "defines":
91136
for def in definedSymbolNames(conf.symbols):
92137
dest.addStrLit def
@@ -137,6 +182,13 @@ proc sourcesChanged(conf: ConfigRef; n: var Cursor; modTime: Time): HashSet[stri
137182
inc n
138183

139184
proc loadConfigsFromNif(conf: ConfigRef; n: var Cursor) =
185+
fromNif conf.backend, n
186+
var targetOS = default(TSystemOS)
187+
var targetCPU = default(TSystemCPU)
188+
fromNif targetOS, n
189+
fromNif targetCPU, n
190+
conf.target.setTarget(targetOS, targetCPU)
191+
140192
expectTag n, "options"
141193
inc n
142194
fromNif(conf.options, n)
@@ -190,6 +242,37 @@ proc loadConfigsFromNif(conf: ConfigRef; n: var Cursor) =
190242
inc n
191243
#echo conf.nimbasePattern
192244

245+
expectTag n, "features"
246+
inc n
247+
fromNif(conf.features, n)
248+
expectTag n, "legacyFeatures"
249+
inc n
250+
fromNif(conf.legacyFeatures, n)
251+
fromNif(conf.cCompiler, n)
252+
253+
expectTag n, "modifiedyNotes"
254+
inc n
255+
fromNif2(conf.modifiedyNotes, n)
256+
expectTag n, "foreignPackageNotes"
257+
inc n
258+
fromNif2(conf.foreignPackageNotes, n)
259+
expectTag n, "notes"
260+
inc n
261+
fromNif2(conf.notes, n)
262+
expectTag n, "warningAsErrors"
263+
inc n
264+
fromNif2(conf.warningAsErrors, n)
265+
expectTag n, "mainPackageNotes"
266+
inc n
267+
fromNif2(conf.mainPackageNotes, n)
268+
269+
conf.errorMax = pool.integers[n.intId]
270+
inc n
271+
conf.maxLoopIterationsVM = pool.integers[n.intId]
272+
inc n
273+
conf.maxCallDepthVM = pool.integers[n.intId]
274+
inc n
275+
193276
conf.symbols.clear
194277
expectTag n, "defines"
195278
inc n
@@ -276,6 +359,9 @@ when isMainModule:
276359
template assertImpl(f: untyped) =
277360
assert x.f == y.f, $x.f & " / " & $y.f
278361

362+
assertImpl backend
363+
assert x.target.targetOS == y.target.targetOS
364+
assert x.target.targetCPU == y.target.targetCPU
279365
assertImpl options
280366
assertImpl globalOptions
281367
assertImpl macrosToExpand
@@ -289,6 +375,17 @@ when isMainModule:
289375
assertImpl numberOfProcessors
290376
assertImpl spellSuggestMax
291377
assertImpl nimbasePattern
378+
assertImpl features
379+
assertImpl legacyFeatures
380+
assertImpl cCompiler
381+
assertImpl modifiedyNotes
382+
assertImpl foreignPackageNotes
383+
assertImpl notes
384+
assertImpl warningAsErrors
385+
assertImpl mainPackageNotes
386+
assertImpl errorMax
387+
assertImpl maxLoopIterationsVM
388+
assertImpl maxCallDepthVM
292389
assertImpl symbols
293390
assertImpl nimblePaths
294391
assertImpl searchPaths
@@ -322,6 +419,8 @@ when isMainModule:
322419

323420
block:
324421
var conf = newConfigRef()
422+
conf.backend = backendCpp
423+
conf.target.setTarget(osAny, cpuArm64)
325424
conf.options = {optObjCheck, optFieldCheck}
326425
conf.globalOptions = {gloptNone, optRun}
327426
conf.macrosToExpand["foomacro"] = "T"
@@ -337,6 +436,17 @@ when isMainModule:
337436
conf.numberOfProcessors = 123
338437
conf.spellSuggestMax = 456
339438
conf.nimbasePattern = "foo/nimbase.h"
439+
conf.features = {callOperator, dynamicBindSym}
440+
conf.legacyFeatures = {laxEffects, emitGenerics}
441+
conf.cCompiler = ccCLang
442+
conf.modifiedyNotes = {}
443+
conf.foreignPackageNotes = {}
444+
conf.notes = {}
445+
conf.warningAsErrors = {}
446+
conf.mainPackageNotes = {}
447+
conf.errorMax = 7
448+
conf.maxLoopIterationsVM = 1234
449+
conf.maxCallDepthVM = 111
340450
conf.symbols.initDefines()
341451
conf.symbols.defineSymbol("test")
342452
conf.nimblePaths = @[AbsoluteDir"/foo", AbsoluteDir"/lib/nimble"]

0 commit comments

Comments
 (0)