IC: added basic test case for methods (#17679)
* IC: added basic test case for methods * IC: better methods test
This commit is contained in:
parent
e4b64eee89
commit
13b958eb45
4 changed files with 64 additions and 8 deletions
|
|
@ -30,12 +30,16 @@ proc unpackTree(g: ModuleGraph; thisModule: int;
|
||||||
var decoder = initPackedDecoder(g.config, g.cache)
|
var decoder = initPackedDecoder(g.config, g.cache)
|
||||||
result = loadNodes(decoder, g.packed, thisModule, tree, n)
|
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:
|
if g.backend == nil:
|
||||||
g.backend = cgendata.newModuleList(g)
|
g.backend = cgendata.newModuleList(g)
|
||||||
|
assert g.backend != nil
|
||||||
var bmod = cgen.newModule(BModuleList(g.backend), m.module, g.config)
|
var bmod = cgen.newModule(BModuleList(g.backend), m.module, g.config)
|
||||||
bmod.idgen = idgenFromLoadedModule(m)
|
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.flags.incl useAliveDataFromDce
|
||||||
bmod.alive = move alive[m.module.position]
|
bmod.alive = move alive[m.module.position]
|
||||||
|
|
||||||
|
|
@ -118,6 +122,27 @@ proc generateCode*(g: ModuleGraph) =
|
||||||
for i in 0..high(g.packed):
|
for i in 0..high(g.packed):
|
||||||
echo i, " is of status ", g.packed[i].status, " ", toFullPath(g.config, FileIndex(i))
|
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):
|
for i in 0..high(g.packed):
|
||||||
# case statement here to enforce exhaustive checks.
|
# case statement here to enforce exhaustive checks.
|
||||||
case g.packed[i].status
|
case g.packed[i].status
|
||||||
|
|
@ -130,11 +155,7 @@ proc generateCode*(g: ModuleGraph) =
|
||||||
closeRodFile(g, g.packed[i].module)
|
closeRodFile(g, g.packed[i].module)
|
||||||
storeAliveSyms(g.config, g.packed[i].module.position, alive)
|
storeAliveSyms(g.config, g.packed[i].module.position, alive)
|
||||||
of loaded:
|
of loaded:
|
||||||
# Even though this module didn't change, DCE might trigger a change.
|
if g.packed[i].loadedButAliveSetChanged:
|
||||||
# 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):
|
|
||||||
generateCodeForModule(g, g.packed[i], alive)
|
generateCodeForModule(g, g.packed[i], alive)
|
||||||
else:
|
else:
|
||||||
addFileToLink(g.config, g.packed[i].module)
|
addFileToLink(g.config, g.packed[i].module)
|
||||||
|
|
|
||||||
|
|
@ -666,7 +666,7 @@ type
|
||||||
|
|
||||||
LoadedModule* = object
|
LoadedModule* = object
|
||||||
status*: ModuleStatus
|
status*: ModuleStatus
|
||||||
symsInit, typesInit: bool
|
symsInit, typesInit, loadedButAliveSetChanged*: bool
|
||||||
fromDisk*: PackedModule
|
fromDisk*: PackedModule
|
||||||
syms: seq[PSym] # indexed by itemId
|
syms: seq[PSym] # indexed by itemId
|
||||||
types: seq[PType]
|
types: seq[PType]
|
||||||
|
|
|
||||||
7
tests/ic/mbaseobj.nim
Normal file
7
tests/ic/mbaseobj.nim
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
|
||||||
|
type
|
||||||
|
Base* = ref object of RootObj
|
||||||
|
s*: string
|
||||||
|
|
||||||
|
method m*(b: Base) {.base.} =
|
||||||
|
echo "Base ", b.s
|
||||||
28
tests/ic/tmethods.nim
Normal file
28
tests/ic/tmethods.nim
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
discard """
|
||||||
|
output: '''Base abc'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
import mbaseobj
|
||||||
|
|
||||||
|
var c = Base(s: "abc")
|
||||||
|
m c
|
||||||
|
|
||||||
|
#!EDIT!#
|
||||||
|
|
||||||
|
discard """
|
||||||
|
output: '''Base abc
|
||||||
|
Inherited abc'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
import mbaseobj
|
||||||
|
|
||||||
|
type
|
||||||
|
Inherited = ref object of Base
|
||||||
|
|
||||||
|
method m(i: Inherited) =
|
||||||
|
procCall m(Base i)
|
||||||
|
echo "Inherited ", i.s
|
||||||
|
|
||||||
|
var c = Inherited(s: "abc")
|
||||||
|
m c
|
||||||
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue