IC: more things work

This commit is contained in:
Araq 2018-12-03 18:57:44 +01:00
commit f86b827d9e
3 changed files with 34 additions and 23 deletions

View file

@ -17,18 +17,7 @@ import
proc resetSystemArtifacts*(g: ModuleGraph) = proc resetSystemArtifacts*(g: ModuleGraph) =
magicsys.resetSysTypes(g) magicsys.resetSysTypes(g)
proc newModule(graph: ModuleGraph; fileIdx: FileIndex): PSym = proc partialInitModule(result: PSym; graph: ModuleGraph; fileIdx: FileIndex; filename: string) =
# We cannot call ``newSym`` here, because we have to circumvent the ID
# mechanism, which we do in order to assign each module a persistent ID.
new(result)
result.id = -1 # for better error checking
result.kind = skModule
let filename = toFullPath(graph.config, fileIdx)
result.name = getIdent(graph.cache, splitFile(filename).name)
if not isNimIdentifier(result.name.s):
rawMessage(graph.config, errGenerated, "invalid module name: " & result.name.s)
result.info = newLineInfo(fileIdx, 1, 1)
let let
pck = getPackageName(graph.config, filename) pck = getPackageName(graph.config, filename)
pck2 = if pck.len > 0: pck else: "unknown" pck2 = if pck.len > 0: pck else: "unknown"
@ -38,13 +27,11 @@ proc newModule(graph: ModuleGraph; fileIdx: FileIndex): PSym =
packSym = newSym(skPackage, getIdent(graph.cache, pck2), nil, result.info) packSym = newSym(skPackage, getIdent(graph.cache, pck2), nil, result.info)
initStrTable(packSym.tab) initStrTable(packSym.tab)
graph.packageSyms.strTableAdd(packSym) graph.packageSyms.strTableAdd(packSym)
result.owner = packSym result.owner = packSym
result.position = int fileIdx result.position = int fileIdx
if int(fileIdx) >= graph.modules.len: if int(fileIdx) >= graph.modules.len:
setLen(graph.modules, int(fileIdx) + 1) setLen(graph.modules, int(fileIdx) + 1)
#growCache graph.modules, int fileIdx
graph.modules[result.position] = result graph.modules[result.position] = result
incl(result.flags, sfUsed) incl(result.flags, sfUsed)
@ -58,16 +45,36 @@ proc newModule(graph: ModuleGraph; fileIdx: FileIndex): PSym =
# strTableIncl() for error corrections: # strTableIncl() for error corrections:
discard strTableIncl(packSym.tab, result) discard strTableIncl(packSym.tab, result)
proc newModule(graph: ModuleGraph; fileIdx: FileIndex): PSym =
# We cannot call ``newSym`` here, because we have to circumvent the ID
# mechanism, which we do in order to assign each module a persistent ID.
new(result)
result.id = -1 # for better error checking
result.kind = skModule
let filename = toFullPath(graph.config, fileIdx)
result.name = getIdent(graph.cache, splitFile(filename).name)
if not isNimIdentifier(result.name.s):
rawMessage(graph.config, errGenerated, "invalid module name: " & result.name.s)
result.info = newLineInfo(fileIdx, 1, 1)
partialInitModule(result, graph, fileIdx, filename)
proc compileModule*(graph: ModuleGraph; fileIdx: FileIndex; flags: TSymFlags): PSym = proc compileModule*(graph: ModuleGraph; fileIdx: FileIndex; flags: TSymFlags): PSym =
result = graph.getModule(fileIdx) result = graph.getModule(fileIdx)
if result == nil: if result == nil:
result = newModule(graph, fileIdx) let filename = toFullPath(graph.config, fileIdx)
result.flags = result.flags + flags let (r, id) = loadModuleSym(graph, fileIdx, AbsoluteFile filename)
if sfMainModule in result.flags: result = r
graph.config.mainPackageId = result.owner.id if result == nil:
result = newModule(graph, fileIdx)
result.id = getModuleId(graph, fileIdx, AbsoluteFile toFullPath(graph.config, fileIdx)) result.flags = result.flags + flags
registerModule(graph, result) if sfMainModule in result.flags:
graph.config.mainPackageId = result.owner.id
result.id = id
registerModule(graph, result)
else:
partialInitModule(result, graph, fileIdx, filename)
result.id = id
assert result.id < 0
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):

View file

@ -16,7 +16,7 @@ when not nimIncremental:
template storeNode*(g: ModuleGraph; module: PSym; n: PNode) = discard template storeNode*(g: ModuleGraph; module: PSym; n: PNode) = discard
template loadNode*(g: ModuleGraph; module: PSym): PNode = newNode(nkStmtList) template loadNode*(g: ModuleGraph; module: PSym): PNode = newNode(nkStmtList)
template getModuleId*(g: ModuleGraph; fileIdx: FileIndex; fullpath: AbsoluteFile): int = getID() proc loadModuleSym*(g: ModuleGraph; fileIdx: FileIndex; fullpath: AbsoluteFile): (PSym, int) {.inline.} = (nil, getID())
template addModuleDep*(g: ModuleGraph; module, fileIdx: FileIndex; isIncludeFile: bool) = discard template addModuleDep*(g: ModuleGraph; module, fileIdx: FileIndex; isIncludeFile: bool) = discard

View file

@ -52,7 +52,7 @@ proc needsRecompile(g: ModuleGraph; fileIdx: FileIndex; fullpath: AbsoluteFile;
return true return true
return false return false
proc getModuleId*(g: ModuleGraph; fileIdx: FileIndex; fullpath: AbsoluteFile): int = proc getModuleId(g: ModuleGraph; fileIdx: FileIndex; fullpath: AbsoluteFile): int =
## Analyse the known dependency graph. ## Analyse the known dependency graph.
if g.config.symbolFiles == disabledSf: return getID() if g.config.symbolFiles == disabledSf: return getID()
when false: when false:
@ -82,6 +82,10 @@ proc getModuleId*(g: ModuleGraph; fileIdx: FileIndex; fullpath: AbsoluteFile): i
db.exec(sql"delete from toplevelstmts where module = ?", module[0]) db.exec(sql"delete from toplevelstmts where module = ?", module[0])
db.exec(sql"delete from statics where module = ?", module[0]) db.exec(sql"delete from statics where module = ?", module[0])
proc loadModuleSym*(g: ModuleGraph; fileIdx: FileIndex; fullpath: AbsoluteFile): (PSym, int) =
let id = getModuleId(g, fileIdx, fullpath)
result = (g.incr.r.syms.getOrDefault(abs id), id)
proc pushType(w: var Writer, t: PType) = proc pushType(w: var Writer, t: PType) =
if not containsOrIncl(w.tmarks, t.uniqueId): if not containsOrIncl(w.tmarks, t.uniqueId):
w.tstack.add(t) w.tstack.add(t)