mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
compiler: make symbolfiles feature compile again
This commit is contained in:
@@ -12,7 +12,7 @@
|
||||
|
||||
const nimIncremental* = defined(nimIncremental)
|
||||
|
||||
import options, lineinfos
|
||||
import options, lineinfos, pathutils
|
||||
|
||||
when nimIncremental:
|
||||
import ast, msgs, intsets, btrees, db_sqlite, std / sha1
|
||||
@@ -45,10 +45,10 @@ when nimIncremental:
|
||||
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)
|
||||
if result.len == 0:
|
||||
result = $secureHashFile(fullpath)
|
||||
result = $secureHashFile(string fullpath)
|
||||
msgs.setHash(conf, fileIdx, result)
|
||||
|
||||
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 = ?",
|
||||
fullpath)
|
||||
let id = row[0]
|
||||
let fullhash = hashFileCached(conf, fileIdx, fullpath)
|
||||
let fullhash = hashFileCached(conf, fileIdx, AbsoluteFile fullpath)
|
||||
if id.len == 0:
|
||||
result = int incr.db.insertID(sql"insert into filenames(fullpath, fullhash) values (?, ?)",
|
||||
fullpath, fullhash)
|
||||
@@ -70,7 +70,7 @@ when nimIncremental:
|
||||
if dbId == -1: return FileIndex(-1)
|
||||
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
|
||||
result = fileInfoIdx(conf, fullpath)
|
||||
result = fileInfoIdx(conf, AbsoluteFile fullpath)
|
||||
|
||||
|
||||
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:
|
||||
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,
|
||||
if sfMainModule in flags and graph.config.projectIsStdin: stdin.llStreamOpen else: nil)
|
||||
elif graph.isDirty(result):
|
||||
|
||||
@@ -34,10 +34,10 @@ proc encodeConfig(g: ModuleGraph): string =
|
||||
|
||||
depConfigFields(serialize)
|
||||
|
||||
proc needsRecompile(g: ModuleGraph; fileIdx: FileIndex; fullpath: string;
|
||||
proc needsRecompile(g: ModuleGraph; fileIdx: FileIndex; fullpath: AbsoluteFile;
|
||||
cycleCheck: var IntSet): bool =
|
||||
let root = db.getRow(sql"select id, fullhash from filenames where fullpath = ?",
|
||||
fullpath)
|
||||
fullpath.string)
|
||||
if root[0].len == 0: return true
|
||||
if root[1] != hashFileCached(g.config, fileIdx, fullpath):
|
||||
return true
|
||||
@@ -47,22 +47,22 @@ proc needsRecompile(g: ModuleGraph; fileIdx: FileIndex; fullpath: string;
|
||||
# check dependencies (recursively):
|
||||
for row in db.fastRows(sql"select fullpath from filenames where id in (select dependency from deps where module = ?)",
|
||||
root[0]):
|
||||
let dep = row[0]
|
||||
let dep = AbsoluteFile row[0]
|
||||
if needsRecompile(g, g.config.fileInfoIdx(dep), dep, cycleCheck):
|
||||
return true
|
||||
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
|
||||
g.incr.configChanged:
|
||||
return getID()
|
||||
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)
|
||||
if module[0].len == 0:
|
||||
result = getID()
|
||||
db.exec(sql"insert into modules(fullpath, interfHash, fullHash, nimid) values (?, ?, ?, ?)",
|
||||
fullpath, "", currentFullhash, result)
|
||||
string fullpath, "", currentFullhash, result)
|
||||
else:
|
||||
result = parseInt(module[2])
|
||||
if currentFullhash == module[1]:
|
||||
@@ -70,7 +70,7 @@ proc getModuleId*(g: ModuleGraph; fileIdx: FileIndex; fullpath: string): int =
|
||||
doAssert(result != 0)
|
||||
var cycleCheck = initIntSet()
|
||||
if not needsRecompile(g, fileIdx, fullpath, cycleCheck):
|
||||
echo "cached successfully! ", fullpath
|
||||
echo "cached successfully! ", string fullpath
|
||||
return -result
|
||||
db.exec(sql"update modules set fullHash = ? where id = ?", currentFullhash, 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 "compile":
|
||||
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})
|
||||
extccomp.addExternalFileToCompile(g.config, cf)
|
||||
of "link":
|
||||
@@ -841,7 +841,7 @@ proc replay(g: ModuleGraph; module: PSym; n: PNode) =
|
||||
of nkImportStmt:
|
||||
for x in n:
|
||||
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
|
||||
of nkStmtList, nkStmtListExpr:
|
||||
for x in n: replay(g, module, x)
|
||||
@@ -864,16 +864,16 @@ proc loadNode*(g: ModuleGraph; module: PSym): PNode =
|
||||
proc setupModuleCache*(g: ModuleGraph) =
|
||||
if g.config.symbolFiles == disabledSf: return
|
||||
g.recordStmt = recordStmt
|
||||
let dbfile = getNimcacheDir(g.config) / "rodfiles.db"
|
||||
let dbfile = getNimcacheDir(g.config) / RelativeFile"rodfiles.db"
|
||||
if g.config.symbolFiles == writeOnlySf:
|
||||
removeFile(dbfile)
|
||||
if not fileExists(dbfile):
|
||||
db = open(connection=dbfile, user="nim", password="",
|
||||
db = open(connection=string dbfile, user="nim", password="",
|
||||
database="nim")
|
||||
createDb(db)
|
||||
db.exec(sql"insert into config(config) values (?)", encodeConfig(g))
|
||||
else:
|
||||
db = open(connection=dbfile, user="nim", password="",
|
||||
db = open(connection=string dbfile, user="nim", password="",
|
||||
database="nim")
|
||||
let oldConfig = db.getValue(sql"select config from config")
|
||||
g.incr.configChanged = oldConfig != encodeConfig(g)
|
||||
|
||||
Reference in New Issue
Block a user