compiler: make symbolfiles feature compile again
This commit is contained in:
parent
c6e10a442d
commit
76aab9baf1
3 changed files with 18 additions and 18 deletions
|
|
@ -12,7 +12,7 @@
|
||||||
|
|
||||||
const nimIncremental* = defined(nimIncremental)
|
const nimIncremental* = defined(nimIncremental)
|
||||||
|
|
||||||
import options, lineinfos
|
import options, lineinfos, pathutils
|
||||||
|
|
||||||
when nimIncremental:
|
when nimIncremental:
|
||||||
import ast, msgs, intsets, btrees, db_sqlite, std / sha1
|
import ast, msgs, intsets, btrees, db_sqlite, std / sha1
|
||||||
|
|
@ -45,10 +45,10 @@ when nimIncremental:
|
||||||
incr.r.types = initBTree[int, PType]()
|
incr.r.types = initBTree[int, PType]()
|
||||||
|
|
||||||
|
|
||||||
proc hashFileCached*(conf: ConfigRef; fileIdx: FileIndex; fullpath: string): string =
|
proc hashFileCached*(conf: ConfigRef; fileIdx: FileIndex; fullpath: AbsoluteFile): string =
|
||||||
result = msgs.getHash(conf, fileIdx)
|
result = msgs.getHash(conf, fileIdx)
|
||||||
if result.len == 0:
|
if result.len == 0:
|
||||||
result = $secureHashFile(fullpath)
|
result = $secureHashFile(string fullpath)
|
||||||
msgs.setHash(conf, fileIdx, result)
|
msgs.setHash(conf, fileIdx, result)
|
||||||
|
|
||||||
proc toDbFileId*(incr: var IncrementalCtx; conf: ConfigRef; fileIdx: FileIndex): int =
|
proc toDbFileId*(incr: var IncrementalCtx; conf: ConfigRef; fileIdx: FileIndex): int =
|
||||||
|
|
@ -57,7 +57,7 @@ when nimIncremental:
|
||||||
let row = incr.db.getRow(sql"select id, fullhash from filenames where fullpath = ?",
|
let row = incr.db.getRow(sql"select id, fullhash from filenames where fullpath = ?",
|
||||||
fullpath)
|
fullpath)
|
||||||
let id = row[0]
|
let id = row[0]
|
||||||
let fullhash = hashFileCached(conf, fileIdx, fullpath)
|
let fullhash = hashFileCached(conf, fileIdx, AbsoluteFile fullpath)
|
||||||
if id.len == 0:
|
if id.len == 0:
|
||||||
result = int incr.db.insertID(sql"insert into filenames(fullpath, fullhash) values (?, ?)",
|
result = int incr.db.insertID(sql"insert into filenames(fullpath, fullhash) values (?, ?)",
|
||||||
fullpath, fullhash)
|
fullpath, fullhash)
|
||||||
|
|
@ -70,7 +70,7 @@ when nimIncremental:
|
||||||
if dbId == -1: return FileIndex(-1)
|
if dbId == -1: return FileIndex(-1)
|
||||||
let fullpath = incr.db.getValue(sql"select fullpath from filenames where id = ?", dbId)
|
let fullpath = incr.db.getValue(sql"select fullpath from filenames where id = ?", dbId)
|
||||||
doAssert fullpath.len > 0, "cannot find file name for DB ID " & $dbId
|
doAssert fullpath.len > 0, "cannot find file name for DB ID " & $dbId
|
||||||
result = fileInfoIdx(conf, fullpath)
|
result = fileInfoIdx(conf, AbsoluteFile fullpath)
|
||||||
|
|
||||||
|
|
||||||
proc addModuleDep*(incr: var IncrementalCtx; conf: ConfigRef;
|
proc addModuleDep*(incr: var IncrementalCtx; conf: ConfigRef;
|
||||||
|
|
|
||||||
|
|
@ -66,7 +66,7 @@ proc compileModule*(graph: ModuleGraph; fileIdx: FileIndex; flags: TSymFlags): P
|
||||||
if sfMainModule in result.flags:
|
if sfMainModule in result.flags:
|
||||||
graph.config.mainPackageId = result.owner.id
|
graph.config.mainPackageId = result.owner.id
|
||||||
|
|
||||||
result.id = getModuleId(graph, fileIdx, toFullPath(graph.config, fileIdx))
|
result.id = getModuleId(graph, fileIdx, AbsoluteFile toFullPath(graph.config, fileIdx))
|
||||||
discard processModule(graph, result,
|
discard processModule(graph, result,
|
||||||
if sfMainModule in flags and graph.config.projectIsStdin: stdin.llStreamOpen else: nil)
|
if sfMainModule in flags and graph.config.projectIsStdin: stdin.llStreamOpen else: nil)
|
||||||
elif graph.isDirty(result):
|
elif graph.isDirty(result):
|
||||||
|
|
|
||||||
|
|
@ -34,10 +34,10 @@ proc encodeConfig(g: ModuleGraph): string =
|
||||||
|
|
||||||
depConfigFields(serialize)
|
depConfigFields(serialize)
|
||||||
|
|
||||||
proc needsRecompile(g: ModuleGraph; fileIdx: FileIndex; fullpath: string;
|
proc needsRecompile(g: ModuleGraph; fileIdx: FileIndex; fullpath: AbsoluteFile;
|
||||||
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 = ?",
|
||||||
fullpath)
|
fullpath.string)
|
||||||
if root[0].len == 0: return true
|
if root[0].len == 0: return true
|
||||||
if root[1] != hashFileCached(g.config, fileIdx, fullpath):
|
if root[1] != hashFileCached(g.config, fileIdx, fullpath):
|
||||||
return true
|
return true
|
||||||
|
|
@ -47,22 +47,22 @@ proc needsRecompile(g: ModuleGraph; fileIdx: FileIndex; fullpath: string;
|
||||||
# check dependencies (recursively):
|
# check dependencies (recursively):
|
||||||
for row in db.fastRows(sql"select fullpath from filenames where id in (select dependency from deps where module = ?)",
|
for row in db.fastRows(sql"select fullpath from filenames where id in (select dependency from deps where module = ?)",
|
||||||
root[0]):
|
root[0]):
|
||||||
let dep = row[0]
|
let dep = AbsoluteFile row[0]
|
||||||
if needsRecompile(g, g.config.fileInfoIdx(dep), dep, cycleCheck):
|
if needsRecompile(g, g.config.fileInfoIdx(dep), dep, cycleCheck):
|
||||||
return true
|
return true
|
||||||
return false
|
return false
|
||||||
|
|
||||||
proc getModuleId*(g: ModuleGraph; fileIdx: FileIndex; fullpath: string): int =
|
proc getModuleId*(g: ModuleGraph; fileIdx: FileIndex; fullpath: AbsoluteFile): int =
|
||||||
if g.config.symbolFiles in {disabledSf, writeOnlySf} or
|
if g.config.symbolFiles in {disabledSf, writeOnlySf} or
|
||||||
g.incr.configChanged:
|
g.incr.configChanged:
|
||||||
return getID()
|
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 = ?", string 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 = getID()
|
result = getID()
|
||||||
db.exec(sql"insert into modules(fullpath, interfHash, fullHash, nimid) values (?, ?, ?, ?)",
|
db.exec(sql"insert into modules(fullpath, interfHash, fullHash, nimid) values (?, ?, ?, ?)",
|
||||||
fullpath, "", currentFullhash, result)
|
string fullpath, "", currentFullhash, result)
|
||||||
else:
|
else:
|
||||||
result = parseInt(module[2])
|
result = parseInt(module[2])
|
||||||
if currentFullhash == module[1]:
|
if currentFullhash == module[1]:
|
||||||
|
|
@ -70,7 +70,7 @@ proc getModuleId*(g: ModuleGraph; fileIdx: FileIndex; fullpath: string): int =
|
||||||
doAssert(result != 0)
|
doAssert(result != 0)
|
||||||
var cycleCheck = initIntSet()
|
var cycleCheck = initIntSet()
|
||||||
if not needsRecompile(g, fileIdx, fullpath, cycleCheck):
|
if not needsRecompile(g, fileIdx, fullpath, cycleCheck):
|
||||||
echo "cached successfully! ", fullpath
|
echo "cached successfully! ", string fullpath
|
||||||
return -result
|
return -result
|
||||||
db.exec(sql"update modules set fullHash = ? where id = ?", currentFullhash, module[0])
|
db.exec(sql"update modules set fullHash = ? where id = ?", currentFullhash, module[0])
|
||||||
db.exec(sql"delete from deps where module = ?", module[0])
|
db.exec(sql"delete from deps where module = ?", module[0])
|
||||||
|
|
@ -792,7 +792,7 @@ proc replay(g: ModuleGraph; module: PSym; n: PNode) =
|
||||||
of "error": localError(g.config, n.info, errUser, n[1].strVal)
|
of "error": localError(g.config, n.info, errUser, n[1].strVal)
|
||||||
of "compile":
|
of "compile":
|
||||||
internalAssert g.config, n.len == 3 and n[2].kind == nkStrLit
|
internalAssert g.config, n.len == 3 and n[2].kind == nkStrLit
|
||||||
var cf = Cfile(cname: n[1].strVal, obj: n[2].strVal,
|
var cf = Cfile(cname: AbsoluteFile n[1].strVal, obj: AbsoluteFile n[2].strVal,
|
||||||
flags: {CfileFlag.External})
|
flags: {CfileFlag.External})
|
||||||
extccomp.addExternalFileToCompile(g.config, cf)
|
extccomp.addExternalFileToCompile(g.config, cf)
|
||||||
of "link":
|
of "link":
|
||||||
|
|
@ -841,7 +841,7 @@ proc replay(g: ModuleGraph; module: PSym; n: PNode) =
|
||||||
of nkImportStmt:
|
of nkImportStmt:
|
||||||
for x in n:
|
for x in n:
|
||||||
internalAssert g.config, x.kind == nkStrLit
|
internalAssert g.config, x.kind == nkStrLit
|
||||||
let imported = g.importModuleCallback(g, module, fileInfoIdx(g.config, n[0].strVal))
|
let imported = g.importModuleCallback(g, module, fileInfoIdx(g.config, AbsoluteFile n[0].strVal))
|
||||||
internalAssert g.config, imported.id < 0
|
internalAssert g.config, imported.id < 0
|
||||||
of nkStmtList, nkStmtListExpr:
|
of nkStmtList, nkStmtListExpr:
|
||||||
for x in n: replay(g, module, x)
|
for x in n: replay(g, module, x)
|
||||||
|
|
@ -864,16 +864,16 @@ proc loadNode*(g: ModuleGraph; module: PSym): PNode =
|
||||||
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) / RelativeFile"rodfiles.db"
|
||||||
if g.config.symbolFiles == writeOnlySf:
|
if g.config.symbolFiles == writeOnlySf:
|
||||||
removeFile(dbfile)
|
removeFile(dbfile)
|
||||||
if not fileExists(dbfile):
|
if not fileExists(dbfile):
|
||||||
db = open(connection=dbfile, user="nim", password="",
|
db = open(connection=string dbfile, user="nim", password="",
|
||||||
database="nim")
|
database="nim")
|
||||||
createDb(db)
|
createDb(db)
|
||||||
db.exec(sql"insert into config(config) values (?)", encodeConfig(g))
|
db.exec(sql"insert into config(config) values (?)", encodeConfig(g))
|
||||||
else:
|
else:
|
||||||
db = open(connection=dbfile, user="nim", password="",
|
db = open(connection=string dbfile, user="nim", password="",
|
||||||
database="nim")
|
database="nim")
|
||||||
let oldConfig = db.getValue(sql"select config from config")
|
let oldConfig = db.getValue(sql"select config from config")
|
||||||
g.incr.configChanged = oldConfig != encodeConfig(g)
|
g.incr.configChanged = oldConfig != encodeConfig(g)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue