incremental compilation: save the configuration
This commit is contained in:
parent
8db27d30e6
commit
90b1030dec
2 changed files with 29 additions and 11 deletions
|
|
@ -33,6 +33,7 @@ when nimIncremental:
|
||||||
db*: DbConn
|
db*: DbConn
|
||||||
w*: Writer
|
w*: Writer
|
||||||
r*: Reader
|
r*: Reader
|
||||||
|
configChanged*: bool
|
||||||
|
|
||||||
proc init*(incr: var IncrementalCtx) =
|
proc init*(incr: var IncrementalCtx) =
|
||||||
incr.w.sstack = @[]
|
incr.w.sstack = @[]
|
||||||
|
|
@ -92,6 +93,12 @@ when nimIncremental:
|
||||||
);
|
);
|
||||||
""")
|
""")
|
||||||
|
|
||||||
|
db.exec(sql"""
|
||||||
|
create table if not exists config(
|
||||||
|
config varchar(8000) not null
|
||||||
|
);
|
||||||
|
""")
|
||||||
|
|
||||||
db.exec(sql"""
|
db.exec(sql"""
|
||||||
create table if not exists filenames(
|
create table if not exists filenames(
|
||||||
id integer primary key,
|
id integer primary key,
|
||||||
|
|
|
||||||
|
|
@ -11,16 +11,29 @@
|
||||||
|
|
||||||
import strutils, os, intsets, tables, ropes, db_sqlite, msgs, options, types,
|
import strutils, os, intsets, tables, ropes, db_sqlite, msgs, options, types,
|
||||||
renderer, rodutils, idents, astalgo, btrees, magicsys, cgmeth, extccomp,
|
renderer, rodutils, idents, astalgo, btrees, magicsys, cgmeth, extccomp,
|
||||||
btrees, trees
|
btrees, trees, condsyms, nversion
|
||||||
|
|
||||||
## Todo:
|
## 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
|
## - Dependency computation should use *signature* hashes in order to
|
||||||
## avoid recompiling dependent modules.
|
## 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
|
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;
|
proc needsRecompile(g: ModuleGraph; fileIdx: FileIndex; fullpath: string;
|
||||||
cycleCheck: var IntSet): bool =
|
cycleCheck: var IntSet): bool =
|
||||||
let root = db.getRow(sql"select id, fullhash from filenames where fullpath = ?",
|
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
|
return false
|
||||||
|
|
||||||
proc getModuleId*(g: ModuleGraph; fileIdx: FileIndex; fullpath: string): int =
|
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(
|
let module = g.incr.db.getRow(
|
||||||
sql"select id, fullHash, nimid from modules where fullpath = ?", fullpath)
|
sql"select id, fullHash, nimid from modules where fullpath = ?", fullpath)
|
||||||
let currentFullhash = hashFileCached(g.config, fileIdx, 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 toplevelstmts where module = ?", module[0])
|
||||||
db.exec(sql"delete from statics 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) =
|
proc pushType(w: var Writer, t: PType) =
|
||||||
if not containsOrIncl(w.tmarks, t.id):
|
if not containsOrIncl(w.tmarks, t.id):
|
||||||
w.tstack.add(t)
|
w.tstack.add(t)
|
||||||
|
|
@ -863,9 +871,12 @@ proc setupModuleCache*(g: ModuleGraph) =
|
||||||
db = open(connection=dbfile, user="nim", password="",
|
db = open(connection=dbfile, user="nim", password="",
|
||||||
database="nim")
|
database="nim")
|
||||||
createDb(db)
|
createDb(db)
|
||||||
|
db.exec(sql"insert into config(config) values (?)", encodeConfig(g))
|
||||||
else:
|
else:
|
||||||
db = open(connection=dbfile, user="nim", password="",
|
db = open(connection=dbfile, user="nim", password="",
|
||||||
database="nim")
|
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 journal_mode=off")
|
||||||
db.exec(sql"pragma SYNCHRONOUS=off")
|
db.exec(sql"pragma SYNCHRONOUS=off")
|
||||||
db.exec(sql"pragma LOCKING_MODE=exclusive")
|
db.exec(sql"pragma LOCKING_MODE=exclusive")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue