IC: added basic test case for methods (#17679)

* IC: added basic test case for methods

* IC: better methods test
This commit is contained in:
Andreas Rumpf 2021-04-09 06:59:25 +02:00 • committed by GitHub
commit 13b958eb45
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 8 deletions

View file

@ -30,12 +30,16 @@ proc unpackTree(g: ModuleGraph; thisModule: int;
var decoder = initPackedDecoder(g.config, g.cache)
result = loadNodes(decoder, g.packed, thisModule, tree, n)
proc generateCodeForModule(g: ModuleGraph; m: var LoadedModule; alive: var AliveSyms) =
proc setupBackendModule(g: ModuleGraph; m: var LoadedModule) =
if g.backend == nil:
g.backend = cgendata.newModuleList(g)
assert g.backend != nil
var bmod = cgen.newModule(BModuleList(g.backend), m.module, g.config)
bmod.idgen = idgenFromLoadedModule(m)
proc generateCodeForModule(g: ModuleGraph; m: var LoadedModule; alive: var AliveSyms) =
var bmod = BModuleList(g.backend).modules[m.module.position]
assert bmod != nil
bmod.flags.incl useAliveDataFromDce
bmod.alive = move alive[m.module.position]
@ -118,6 +122,27 @@ proc generateCode*(g: ModuleGraph) =
for i in 0..high(g.packed):
echo i, " is of status ", g.packed[i].status, " ", toFullPath(g.config, FileIndex(i))
# First pass: Setup all the backend modules for all the modules that have
# changed:
for i in 0..high(g.packed):
# case statement here to enforce exhaustive checks.
case g.packed[i].status
of undefined:
discard "nothing to do"
of loading, stored:
assert false
of storing, outdated:
setupBackendModule(g, g.packed[i])
of loaded:
# Even though this module didn't change, DCE might trigger a change.
# Consider this case: Module A uses symbol S from B and B does not use
# S itself. A is then edited not to use S either. Thus we have to
# recompile B in order to remove S from the final result.
if aliveSymsChanged(g.config, g.packed[i].module.position, alive):
g.packed[i].loadedButAliveSetChanged = true
setupBackendModule(g, g.packed[i])
# Second pass: Code generation.
for i in 0..high(g.packed):
# case statement here to enforce exhaustive checks.
case g.packed[i].status
@ -130,11 +155,7 @@ proc generateCode*(g: ModuleGraph) =
closeRodFile(g, g.packed[i].module)
storeAliveSyms(g.config, g.packed[i].module.position, alive)
of loaded:
# Even though this module didn't change, DCE might trigger a change.
# Consider this case: Module A uses symbol S from B and B does not use
# S itself. A is then edited not to use S either. Thus we have to
# recompile B in order to remove S from the final result.
if aliveSymsChanged(g.config, g.packed[i].module.position, alive):
if g.packed[i].loadedButAliveSetChanged:
generateCodeForModule(g, g.packed[i], alive)
else:
addFileToLink(g.config, g.packed[i].module)

View file

@ -666,7 +666,7 @@ type
LoadedModule* = object
status*: ModuleStatus
symsInit, typesInit: bool
symsInit, typesInit, loadedButAliveSetChanged*: bool
fromDisk*: PackedModule
syms: seq[PSym] # indexed by itemId
types: seq[PType]