diff options
-rw-r--r-- | compiler/incremental.nim | 7 | ||||
-rw-r--r-- | compiler/rodimpl.nim | 33 |
2 files changed, 29 insertions, 11 deletions
diff --git a/compiler/incremental.nim b/compiler/incremental.nim index c0d89a598..2008d35de 100644 --- a/compiler/incremental.nim +++ b/compiler/incremental.nim @@ -33,6 +33,7 @@ when nimIncremental: db*: DbConn w*: Writer r*: Reader + configChanged*: bool proc init*(incr: var IncrementalCtx) = incr.w.sstack = @[] @@ -93,6 +94,12 @@ when nimIncremental: """) db.exec(sql""" + create table if not exists config( + config varchar(8000) not null + ); + """) + + db.exec(sql""" create table if not exists filenames( id integer primary key, fullpath varchar(8000) not null, diff --git a/compiler/rodimpl.nim b/compiler/rodimpl.nim index 955e881e2..7d24e4e67 100644 --- a/compiler/rodimpl.nim +++ b/compiler/rodimpl.nim @@ -11,16 +11,29 @@ import strutils, os, intsets, tables, ropes, db_sqlite, msgs, options, types, renderer, rodutils, idents, astalgo, btrees, magicsys, cgmeth, extccomp, - btrees, trees + btrees, trees, condsyms, nversion ## Todo: -## - Make conditional symbols and the configuration part of a module's -## dependencies. Also include the rodfile "version". ## - Dependency computation should use *signature* hashes in order to ## avoid recompiling dependent modules. +## - Patch the rest of the compiler to do lazy loading of proc bodies. +## - Patch the C codegen to cache proc bodies and maybe types. template db(): DbConn = g.incr.db +proc encodeConfig(g: ModuleGraph): string = + result = newStringOfCap(100) + result.add RodFileVersion + for d in definedSymbolNames(g.config.symbols): + result.add ' ' + result.add d + + template serialize(field) = + result.add ' ' + result.add($g.config.field) + + depConfigFields(serialize) + proc needsRecompile(g: ModuleGraph; fileIdx: FileIndex; fullpath: string; cycleCheck: var IntSet): bool = let root = db.getRow(sql"select id, fullhash from filenames where fullpath = ?", @@ -40,7 +53,9 @@ proc needsRecompile(g: ModuleGraph; fileIdx: FileIndex; fullpath: string; return false proc getModuleId*(g: ModuleGraph; fileIdx: FileIndex; fullpath: string): int = - if g.config.symbolFiles in {disabledSf, writeOnlySf}: return getID() + if g.config.symbolFiles in {disabledSf, writeOnlySf} or + g.incr.configChanged: + return getID() let module = g.incr.db.getRow( sql"select id, fullHash, nimid from modules where fullpath = ?", fullpath) let currentFullhash = hashFileCached(g.config, fileIdx, fullpath) @@ -64,13 +79,6 @@ proc getModuleId*(g: ModuleGraph; fileIdx: FileIndex; fullpath: string): int = db.exec(sql"delete from toplevelstmts where module = ?", module[0]) db.exec(sql"delete from statics where module = ?", module[0]) -when false: - proc getDefines(): string = - result = "" - for d in definedSymbolNames(): - if result.len != 0: add(result, " ") - add(result, d) - proc pushType(w: var Writer, t: PType) = if not containsOrIncl(w.tmarks, t.id): w.tstack.add(t) @@ -863,9 +871,12 @@ proc setupModuleCache*(g: ModuleGraph) = db = open(connection=dbfile, user="nim", password="", database="nim") createDb(db) + db.exec(sql"insert into config(config) values (?)", encodeConfig(g)) else: db = open(connection=dbfile, user="nim", password="", database="nim") + let oldConfig = db.getValue(sql"select config from config") + g.incr.configChanged = oldConfig != encodeConfig(g) db.exec(sql"pragma journal_mode=off") db.exec(sql"pragma SYNCHRONOUS=off") db.exec(sql"pragma LOCKING_MODE=exclusive") |