IC: progress (#25420)

This commit is contained in:
Andreas Rumpf
2026-01-09 13:10:04 +01:00
committed by GitHub
parent b3273e732d
commit 01eedd916c
16 changed files with 26 additions and 40 deletions

View File

@@ -109,9 +109,11 @@ proc mangleModuleName*(conf: ConfigRef; path: AbsoluteFile): string =
of FromSearchPath: "@p"
of FromNimblePath: "@n"
# Note: We encode ".." specially as "@d" to avoid issues with changeFileExt
# which would misinterpret ".." as "name.ext" and strip the second part.
prefix & best.multiReplace(
{$os.DirSep: "@s", $os.AltSep: "@s", "#": "@h", "@": "@@", ":": "@c"})
{"..": "@d", $os.DirSep: "@s", $os.AltSep: "@s", "#": "@h", "@": "@@", ":": "@c"})
proc demangleModuleName*(path: string): string =
## Demangle a relative module path.
result = path.multiReplace({"@@": "@", "@h": "#", "@s": "/", "@m": "", "@p": "", "@n": "", "@c": ":"})
result = path.multiReplace({"@@": "@", "@d": "..", "@h": "#", "@s": "/", "@m": "", "@p": "", "@n": "", "@c": ":"})

View File

@@ -242,8 +242,11 @@ proc processPipelineModule*(graph: ModuleGraph; module: PSym; idgen: IdGenerator
raiseAssert "use setPipeLinePass to set a proper PipelinePass"
when not defined(nimKochBootstrap):
if (optCompress in graph.config.globalOptions or graph.config.cmd == cmdM) and
not graph.config.isDefined("nimscript"):
# For cmdM: only write NIF for the main module, not for imported modules
# (imported modules should be loaded from existing NIF files)
let shouldWriteNif = (optCompress in graph.config.globalOptions) or
(graph.config.cmd == cmdM and sfMainModule in module.flags)
if shouldWriteNif and not graph.config.isDefined("nimscript"):
topLevelStmts.add finalNode
# Collect replay actions from both pragma computations and VM state diff
var replayActions: seq[PNode] = @[]
@@ -294,6 +297,16 @@ proc compilePipelineModule*(graph: ModuleGraph; fileIdx: FileIndex; flags: TSymF
"nim m requires precompiled NIF for import: " & toFullPath(graph.config, fileIdx) &
" (expected: " & nifPath & ")")
return nil # Don't fall through to compile from source
else:
# Module successfully loaded from NIF file - use it and skip processing
result = precomp.module
if sfSystemModule in flags:
graph.systemModule = result
partialInitModule(result, graph, fileIdx, AbsoluteFile(toFullPath(graph.config, fileIdx)))
# Replay state changes from the loaded NIF module
if result.ast != nil:
replayStateChanges(result, graph)
return result # Return early, don't process from source
if result == nil and graph.config.cmd != cmdM:
# Fall back to ROD file loading (not used for cmdM which uses NIF only)
result = moduleFromRodFile(graph, fileIdx, cachedModules)

View File

@@ -27,6 +27,7 @@ const
"io",
"js",
"ic",
"ic_disabled",
"lib",
"manyloc",
"nimble-packages",
@@ -489,46 +490,16 @@ proc testNimblePackages(r: var TResults; cat: Category; packageFilter: string) =
proc icTests(r: var TResults; testsDir: string, cat: Category, options: string;
isNavigatorTest: bool) =
const
tooltests = ["compiler/nim.nim"]
writeOnly = " --incremental:writeonly "
readOnly = " --incremental:readonly "
incrementalOn = " --incremental:legacy -d:nimIcIntegrityChecks "
navTestConfig = " --ic:legacy -d:nimIcNavigatorTests --hint:Conf:off --warnings:off "
template test(x: untyped) =
testSpecWithNimcache(r, makeRawTest(file, x & options, cat), nimcache)
template editedTest(x: untyped) =
var test = makeTest(file, x & options, cat)
if isNavigatorTest:
test.spec.action = actionCompile
test.spec.targets = {getTestSpecTarget()}
template editedTest() =
var test = makeTest(file, options, cat)
test.spec.targets = {targetC}
test.spec.cmd = compilerPrefix & " ic --hint:Conf:off --warnings:off $options " & file
testSpecWithNimcache(r, test, nimcache)
template checkTest() =
var test = makeRawTest(file, options, cat)
test.spec.cmd = compilerPrefix & " check --hint:Conf:off --warnings:off --ic:legacy $options " & file
testSpecWithNimcache(r, test, nimcache)
if not isNavigatorTest:
for file in tooltests:
let nimcache = nimcacheDir(file, options, getTestSpecTarget())
removeDir(nimcache)
let oldPassed = r.passed
checkTest()
if r.passed == oldPassed+1:
checkTest()
if r.passed == oldPassed+2:
checkTest()
const tempExt = "_temp.nim"
for it in walkDirRec(testsDir):
# for it in ["tests/ic/timports.nim"]: # debugging: to try a specific test
if isTestFile(it) and not it.endsWith(tempExt):
let nimcache = nimcacheDir(it, options, getTestSpecTarget())
let nimcache = nimcacheDir(it, options, targetC)
removeDir(nimcache)
let content = readFile(it)
@@ -536,7 +507,7 @@ proc icTests(r: var TResults; testsDir: string, cat: Category, options: string;
let file = it.replace(".nim", tempExt)
writeFile(file, fragment)
let oldPassed = r.passed
editedTest(if isNavigatorTest: navTestConfig else: incrementalOn)
editedTest()
if r.passed != oldPassed+1: break
# ----------------------------------------------------------------------------