toy program works with incremental compilation

This commit is contained in:
Andreas Rumpf
2018-06-07 18:24:16 +02:00
parent 12996c08a1
commit 8ba7e7d807
4 changed files with 14 additions and 11 deletions

View File

@@ -66,7 +66,6 @@ proc idNodeTablePut*(t: var TIdNodeTable, key: PIdObj, val: PNode)
proc getSymFromList*(list: PNode, ident: PIdent, start: int = 0): PSym
proc lookupInRecord*(n: PNode, field: PIdent): PSym
proc getModule*(s: PSym): PSym
proc mustRehash*(length, counter: int): bool
proc nextTry*(h, maxHash: Hash): Hash {.inline.}
@@ -157,7 +156,7 @@ proc lookupInRecord(n: PNode, field: PIdent): PSym =
if n.sym.name.id == field.id: result = n.sym
else: return nil
proc getModule(s: PSym): PSym =
proc getModule*(s: PSym): PSym =
result = s
assert((result.kind == skModule) or (result.owner != result))
while result != nil and result.kind != skModule: result = result.owner

View File

@@ -104,6 +104,7 @@ when nimIncremental:
db.exec(sql"""
create table if not exists modules(
id integer primary key,
nimid integer not null,
fullpath varchar(8000) not null,
interfHash varchar(256) not null,
fullHash varchar(256) not null,

View File

@@ -95,8 +95,13 @@ proc includeModule*(graph: ModuleGraph; s: PSym, fileIdx: FileIndex): PNode {.pr
graph.addDep(s, fileIdx)
graph.addIncludeDep(s.position.FileIndex, fileIdx)
proc connectCallbacks*(graph: ModuleGraph) =
graph.includeFileCallback = includeModule
graph.importModuleCallback = importModule
proc compileSystemModule*(graph: ModuleGraph) =
if graph.systemModule == nil:
connectCallbacks(graph)
graph.config.m.systemFileIdx = fileInfoIdx(graph.config, graph.config.libpath / "system.nim")
discard graph.compileModule(graph.config.m.systemFileIdx, {sfSystemModule})
@@ -105,10 +110,6 @@ proc wantMainModule*(conf: ConfigRef) =
fatal(conf, newLineInfo(conf, "command line", 1, 1), errGenerated, "command expects a filename")
conf.projectMainIdx = fileInfoIdx(conf, addFileExt(conf.projectFull, NimExt))
proc connectCallbacks*(graph: ModuleGraph) =
graph.includeFileCallback = includeModule
graph.importModuleCallback = importModule
proc compileProject*(graph: ModuleGraph; projectFileIdx = InvalidFileIDX) =
connectCallbacks(graph)
let conf = graph.config

View File

@@ -42,13 +42,14 @@ proc needsRecompile(g: ModuleGraph; fileIdx: FileIndex; fullpath: string;
proc getModuleId*(g: ModuleGraph; fileIdx: FileIndex; fullpath: string): int =
if g.config.symbolFiles in {disabledSf, writeOnlySf}: return getID()
let module = g.incr.db.getRow(
sql"select id, fullHash from modules where fullpath = ?", fullpath)
sql"select id, fullHash, nimid from modules where fullpath = ?", fullpath)
let currentFullhash = hashFileCached(g.config, fileIdx, fullpath)
if module[0].len == 0:
result = int db.insertID(sql"insert into modules(fullpath, interfHash, fullHash) values (?, ?, ?)",
fullpath, "", currentFullhash)
result = getID()
db.exec(sql"insert into modules(fullpath, interfHash, fullHash, nimid) values (?, ?, ?, ?)",
fullpath, "", currentFullhash, result)
else:
result = parseInt(module[0])
result = parseInt(module[2])
if currentFullhash == module[1]:
# not changed, so use the cached AST:
doAssert(result != 0)
@@ -844,13 +845,14 @@ proc loadNode*(g: ModuleGraph; module: PSym): PNode =
result.add decodeNode(g, b, module.info)
db.exec(sql"insert into controlblock(idgen) values (?)", gFrontEndId)
echo result
replay(g, module, result)
proc setupModuleCache*(g: ModuleGraph) =
if g.config.symbolFiles == disabledSf: return
g.recordStmt = recordStmt
let dbfile = getNimcacheDir(g.config) / "rodfiles.db"
if g.config.symbolFiles == writeOnlySf:
removeFile(dbfile)
if not fileExists(dbfile):
db = open(connection=dbfile, user="nim", password="",
database="nim")