toy program works with incremental compilation

This commit is contained in:
Andreas Rumpf 2018-06-07 18:24:16 +02:00
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 getSymFromList*(list: PNode, ident: PIdent, start: int = 0): PSym
proc lookupInRecord*(n: PNode, field: PIdent): PSym proc lookupInRecord*(n: PNode, field: PIdent): PSym
proc getModule*(s: PSym): PSym
proc mustRehash*(length, counter: int): bool proc mustRehash*(length, counter: int): bool
proc nextTry*(h, maxHash: Hash): Hash {.inline.} 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 if n.sym.name.id == field.id: result = n.sym
else: return nil else: return nil
proc getModule(s: PSym): PSym = proc getModule*(s: PSym): PSym =
result = s result = s
assert((result.kind == skModule) or (result.owner != result)) assert((result.kind == skModule) or (result.owner != result))
while result != nil and result.kind != skModule: result = result.owner while result != nil and result.kind != skModule: result = result.owner

View file

@ -104,6 +104,7 @@ when nimIncremental:
db.exec(sql""" db.exec(sql"""
create table if not exists modules( create table if not exists modules(
id integer primary key, id integer primary key,
nimid integer not null,
fullpath varchar(8000) not null, fullpath varchar(8000) not null,
interfHash varchar(256) not null, interfHash varchar(256) not null,
fullHash 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.addDep(s, fileIdx)
graph.addIncludeDep(s.position.FileIndex, fileIdx) graph.addIncludeDep(s.position.FileIndex, fileIdx)
proc connectCallbacks*(graph: ModuleGraph) =
graph.includeFileCallback = includeModule
graph.importModuleCallback = importModule
proc compileSystemModule*(graph: ModuleGraph) = proc compileSystemModule*(graph: ModuleGraph) =
if graph.systemModule == nil: if graph.systemModule == nil:
connectCallbacks(graph)
graph.config.m.systemFileIdx = fileInfoIdx(graph.config, graph.config.libpath / "system.nim") graph.config.m.systemFileIdx = fileInfoIdx(graph.config, graph.config.libpath / "system.nim")
discard graph.compileModule(graph.config.m.systemFileIdx, {sfSystemModule}) 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") fatal(conf, newLineInfo(conf, "command line", 1, 1), errGenerated, "command expects a filename")
conf.projectMainIdx = fileInfoIdx(conf, addFileExt(conf.projectFull, NimExt)) conf.projectMainIdx = fileInfoIdx(conf, addFileExt(conf.projectFull, NimExt))
proc connectCallbacks*(graph: ModuleGraph) =
graph.includeFileCallback = includeModule
graph.importModuleCallback = importModule
proc compileProject*(graph: ModuleGraph; projectFileIdx = InvalidFileIDX) = proc compileProject*(graph: ModuleGraph; projectFileIdx = InvalidFileIDX) =
connectCallbacks(graph) connectCallbacks(graph)
let conf = graph.config 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 = 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}: return getID()
let module = g.incr.db.getRow( 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) let currentFullhash = hashFileCached(g.config, fileIdx, fullpath)
if module[0].len == 0: if module[0].len == 0:
result = int db.insertID(sql"insert into modules(fullpath, interfHash, fullHash) values (?, ?, ?)", result = getID()
fullpath, "", currentFullhash) db.exec(sql"insert into modules(fullpath, interfHash, fullHash, nimid) values (?, ?, ?, ?)",
fullpath, "", currentFullhash, result)
else: else:
result = parseInt(module[0]) result = parseInt(module[2])
if currentFullhash == module[1]: if currentFullhash == module[1]:
# not changed, so use the cached AST: # not changed, so use the cached AST:
doAssert(result != 0) doAssert(result != 0)
@ -844,13 +845,14 @@ proc loadNode*(g: ModuleGraph; module: PSym): PNode =
result.add decodeNode(g, b, module.info) result.add decodeNode(g, b, module.info)
db.exec(sql"insert into controlblock(idgen) values (?)", gFrontEndId) db.exec(sql"insert into controlblock(idgen) values (?)", gFrontEndId)
echo result
replay(g, module, result) replay(g, module, result)
proc setupModuleCache*(g: ModuleGraph) = proc setupModuleCache*(g: ModuleGraph) =
if g.config.symbolFiles == disabledSf: return if g.config.symbolFiles == disabledSf: return
g.recordStmt = recordStmt g.recordStmt = recordStmt
let dbfile = getNimcacheDir(g.config) / "rodfiles.db" let dbfile = getNimcacheDir(g.config) / "rodfiles.db"
if g.config.symbolFiles == writeOnlySf:
removeFile(dbfile)
if not fileExists(dbfile): if not fileExists(dbfile):
db = open(connection=dbfile, user="nim", password="", db = open(connection=dbfile, user="nim", password="",
database="nim") database="nim")