IC: further progress

This commit is contained in:
Araq
2018-11-22 23:17:38 +01:00
parent 962b2e4b39
commit 61d08ebcd8
3 changed files with 30 additions and 11 deletions

View File

@@ -100,7 +100,7 @@ proc importAllSymbolsExcept(c: PContext, fromMod: PSym, exceptSet: IntSet) =
if s.kind != skModule:
if s.kind != skEnumField:
if s.kind notin ExportableSymKinds:
internalError(c.config, s.info, "importAllSymbols: " & $s.kind)
internalError(c.config, s.info, "importAllSymbols: " & $s.kind & " " & s.name.s)
if exceptSet.isNil or s.name.id notin exceptSet:
rawImportSymbol(c, s)
s = nextIter(i, fromMod.tab)

View File

@@ -190,7 +190,7 @@ template toFullPath*(conf: ConfigRef; info: TLineInfo): string =
proc toMsgFilename*(conf: ConfigRef; info: TLineInfo): string =
if info.fileIndex.int32 < 0:
result = "???"
return
return
let absPath = conf.m.fileInfos[info.fileIndex.int32].fullPath.string
let relPath = conf.m.fileInfos[info.fileIndex.int32].projPath.string
if optListFullPaths in conf.globalOptions:

View File

@@ -366,13 +366,7 @@ proc storeType(g: ModuleGraph; t: PType) =
db.exec(sql"insert into types(nimid, module, data) values (?, ?, ?)",
t.id, mid, buf)
proc storeNode*(g: ModuleGraph; module: PSym; n: PNode) =
if g.config.symbolFiles == disabledSf: return
var buf = newStringOfCap(160)
encodeNode(g, module.info, n, buf)
db.exec(sql"insert into toplevelstmts(module, position, data) values (?, ?, ?)",
abs(module.id), module.offset, buf)
inc module.offset
proc transitiveClosure(g: ModuleGraph) =
var i = 0
while true:
if i > 10_000:
@@ -391,9 +385,25 @@ proc storeNode*(g: ModuleGraph; module: PSym; n: PNode) =
break
inc i
proc storeNode*(g: ModuleGraph; module: PSym; n: PNode) =
if g.config.symbolFiles == disabledSf: return
var buf = newStringOfCap(160)
encodeNode(g, module.info, n, buf)
db.exec(sql"insert into toplevelstmts(module, position, data) values (?, ?, ?)",
abs(module.id), module.offset, buf)
inc module.offset
transitiveClosure(g)
proc recordStmt*(g: ModuleGraph; module: PSym; n: PNode) =
storeNode(g, module, n)
proc storeFilename(g: ModuleGraph; fullpath: AbsoluteFile; fileIdx: FileIndex) =
let id = db.getValue(sql"select id from filenames where fullpath = ?", fullpath.string)
if id.len == 0:
let fullhash = hashFileCached(g.config, fileIdx, fullpath)
db.exec(sql"insert into filenames(nimid, fullpath, fullhash) values (?, ?, ?)",
int(fileIdx), fullpath.string, fullhash)
proc storeRemaining*(g: ModuleGraph; module: PSym) =
if g.config.symbolFiles == disabledSf: return
var stillForwarded: seq[PSym] = @[]
@@ -403,6 +413,13 @@ proc storeRemaining*(g: ModuleGraph; module: PSym) =
else:
stillForwarded.add s
swap w.forwardedSyms, stillForwarded
transitiveClosure(g)
var nimid = 0
for x in items(g.config.m.fileInfos):
# don't store the "command line" entry:
if nimid != 0:
storeFilename(g, x.fullPath, FileIndex(nimid))
inc nimid
# ---------------- decoder -----------------------------------
@@ -880,20 +897,22 @@ proc setupModuleCache*(g: ModuleGraph) =
if g.config.symbolFiles == writeOnlySf:
removeFile(dbfile)
createDir getNimcacheDir(g.config)
let ec = encodeConfig(g)
if not fileExists(dbfile):
db = open(connection=string dbfile, user="nim", password="",
database="nim")
createDb(db)
db.exec(sql"insert into config(config) values (?)", encodeConfig(g))
db.exec(sql"insert into config(config) values (?)", ec)
else:
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)
g.incr.configChanged = oldConfig != ec
# ensure the filename IDs stay consistent:
for row in db.rows(sql"select fullpath, nimid from filenames order by nimid"):
let id = fileInfoIdx(g.config, AbsoluteFile row[0])
doAssert id.int == parseInt(row[1])
db.exec(sql"update config set config = ?", ec)
db.exec(sql"pragma journal_mode=off")
# This MUST be turned off, otherwise it's way too slow even for testing purposes:
db.exec(sql"pragma SYNCHRONOUS=off")