Skip to content

Commit 8ba7e7d

Browse files
committed
toy program works with incremental compilation
1 parent 12996c0 commit 8ba7e7d

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

compiler/astalgo.nim

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ proc idNodeTablePut*(t: var TIdNodeTable, key: PIdObj, val: PNode)
6666

6767
proc getSymFromList*(list: PNode, ident: PIdent, start: int = 0): PSym
6868
proc lookupInRecord*(n: PNode, field: PIdent): PSym
69-
proc getModule*(s: PSym): PSym
7069
proc mustRehash*(length, counter: int): bool
7170
proc nextTry*(h, maxHash: Hash): Hash {.inline.}
7271

@@ -157,7 +156,7 @@ proc lookupInRecord(n: PNode, field: PIdent): PSym =
157156
if n.sym.name.id == field.id: result = n.sym
158157
else: return nil
159158

160-
proc getModule(s: PSym): PSym =
159+
proc getModule*(s: PSym): PSym =
161160
result = s
162161
assert((result.kind == skModule) or (result.owner != result))
163162
while result != nil and result.kind != skModule: result = result.owner

compiler/incremental.nim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ when nimIncremental:
104104
db.exec(sql"""
105105
create table if not exists modules(
106106
id integer primary key,
107+
nimid integer not null,
107108
fullpath varchar(8000) not null,
108109
interfHash varchar(256) not null,
109110
fullHash varchar(256) not null,

compiler/modules.nim

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,13 @@ proc includeModule*(graph: ModuleGraph; s: PSym, fileIdx: FileIndex): PNode {.pr
9595
graph.addDep(s, fileIdx)
9696
graph.addIncludeDep(s.position.FileIndex, fileIdx)
9797

98+
proc connectCallbacks*(graph: ModuleGraph) =
99+
graph.includeFileCallback = includeModule
100+
graph.importModuleCallback = importModule
101+
98102
proc compileSystemModule*(graph: ModuleGraph) =
99103
if graph.systemModule == nil:
104+
connectCallbacks(graph)
100105
graph.config.m.systemFileIdx = fileInfoIdx(graph.config, graph.config.libpath / "system.nim")
101106
discard graph.compileModule(graph.config.m.systemFileIdx, {sfSystemModule})
102107

@@ -105,10 +110,6 @@ proc wantMainModule*(conf: ConfigRef) =
105110
fatal(conf, newLineInfo(conf, "command line", 1, 1), errGenerated, "command expects a filename")
106111
conf.projectMainIdx = fileInfoIdx(conf, addFileExt(conf.projectFull, NimExt))
107112

108-
proc connectCallbacks*(graph: ModuleGraph) =
109-
graph.includeFileCallback = includeModule
110-
graph.importModuleCallback = importModule
111-
112113
proc compileProject*(graph: ModuleGraph; projectFileIdx = InvalidFileIDX) =
113114
connectCallbacks(graph)
114115
let conf = graph.config

compiler/rodimpl.nim

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ proc needsRecompile(g: ModuleGraph; fileIdx: FileIndex; fullpath: string;
4242
proc getModuleId*(g: ModuleGraph; fileIdx: FileIndex; fullpath: string): int =
4343
if g.config.symbolFiles in {disabledSf, writeOnlySf}: return getID()
4444
let module = g.incr.db.getRow(
45-
sql"select id, fullHash from modules where fullpath = ?", fullpath)
45+
sql"select id, fullHash, nimid from modules where fullpath = ?", fullpath)
4646
let currentFullhash = hashFileCached(g.config, fileIdx, fullpath)
4747
if module[0].len == 0:
48-
result = int db.insertID(sql"insert into modules(fullpath, interfHash, fullHash) values (?, ?, ?)",
49-
fullpath, "", currentFullhash)
48+
result = getID()
49+
db.exec(sql"insert into modules(fullpath, interfHash, fullHash, nimid) values (?, ?, ?, ?)",
50+
fullpath, "", currentFullhash, result)
5051
else:
51-
result = parseInt(module[0])
52+
result = parseInt(module[2])
5253
if currentFullhash == module[1]:
5354
# not changed, so use the cached AST:
5455
doAssert(result != 0)
@@ -844,13 +845,14 @@ proc loadNode*(g: ModuleGraph; module: PSym): PNode =
844845
result.add decodeNode(g, b, module.info)
845846

846847
db.exec(sql"insert into controlblock(idgen) values (?)", gFrontEndId)
847-
echo result
848848
replay(g, module, result)
849849

850850
proc setupModuleCache*(g: ModuleGraph) =
851851
if g.config.symbolFiles == disabledSf: return
852852
g.recordStmt = recordStmt
853853
let dbfile = getNimcacheDir(g.config) / "rodfiles.db"
854+
if g.config.symbolFiles == writeOnlySf:
855+
removeFile(dbfile)
854856
if not fileExists(dbfile):
855857
db = open(connection=dbfile, user="nim", password="",
856858
database="nim")

0 commit comments

Comments
 (0)