refactorings (#20536)

* refactoring

* refactoring: removed unused macroUsagesSection

* enum instead of bool for better readability
This commit is contained in:
Andreas Rumpf 2022-10-10 21:40:07 +02:00 • committed by GitHub
commit 08ae3467b9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 16 additions and 16 deletions

View file

@ -1067,7 +1067,7 @@ proc genProcAux(m: BModule, prc: PSym) =
var returnStmt: Rope = "" var returnStmt: Rope = ""
assert(prc.ast != nil) assert(prc.ast != nil)
var procBody = transformBody(m.g.graph, m.idgen, prc, cache = false) var procBody = transformBody(m.g.graph, m.idgen, prc, dontUseCache)
if sfInjectDestructors in prc.flags: if sfInjectDestructors in prc.flags:
procBody = injectDestructorCalls(m.g.graph, m.idgen, prc, procBody) procBody = injectDestructorCalls(m.g.graph, m.idgen, prc, procBody)

View file

@ -30,7 +30,7 @@ proc genEnumToStrProc*(t: PType; info: TLineInfo; g: ModuleGraph; idgen: IdGener
assert(t.n[i].kind == nkSym) assert(t.n[i].kind == nkSym)
var field = t.n[i].sym var field = t.n[i].sym
let val = if field.ast == nil: field.name.s else: field.ast.strVal let val = if field.ast == nil: field.name.s else: field.ast.strVal
caseStmt.add newTree(nkOfBranch, newSymNode(field), caseStmt.add newTree(nkOfBranch, newIntTypeNode(field.position, t),
newTree(nkStmtList, newTree(nkFastAsgn, newSymNode(res), newStrNode(val, info)))) newTree(nkStmtList, newTree(nkFastAsgn, newSymNode(res), newStrNode(val, info))))
#newIntTypeNode(nkIntLit, field.position, t) #newIntTypeNode(nkIntLit, field.position, t)

View file

@ -43,7 +43,6 @@ type
reexports*: seq[(LitId, PackedItemId)] reexports*: seq[(LitId, PackedItemId)]
compilerProcs*: seq[(LitId, int32)] compilerProcs*: seq[(LitId, int32)]
converters*, methods*, trmacros*, pureEnums*: seq[int32] converters*, methods*, trmacros*, pureEnums*: seq[int32]
macroUsages*: seq[(PackedItemId, PackedLineInfo)]
typeInstCache*: seq[(PackedItemId, PackedItemId)] typeInstCache*: seq[(PackedItemId, PackedItemId)]
procInstCache*: seq[PackedInstantiation] procInstCache*: seq[PackedInstantiation]
@ -597,7 +596,6 @@ proc loadRodFile*(filename: AbsoluteFile; m: var PackedModule; config: ConfigRef
loadSeqSection convertersSection, m.converters loadSeqSection convertersSection, m.converters
loadSeqSection methodsSection, m.methods loadSeqSection methodsSection, m.methods
loadSeqSection pureEnumsSection, m.pureEnums loadSeqSection pureEnumsSection, m.pureEnums
loadSeqSection macroUsagesSection, m.macroUsages
loadSeqSection toReplaySection, m.toReplay.nodes loadSeqSection toReplaySection, m.toReplay.nodes
loadSeqSection topLevelSection, m.topLevel.nodes loadSeqSection topLevelSection, m.topLevel.nodes
@ -661,7 +659,6 @@ proc saveRodFile*(filename: AbsoluteFile; encoder: var PackedEncoder; m: var Pac
storeSeqSection convertersSection, m.converters storeSeqSection convertersSection, m.converters
storeSeqSection methodsSection, m.methods storeSeqSection methodsSection, m.methods
storeSeqSection pureEnumsSection, m.pureEnums storeSeqSection pureEnumsSection, m.pureEnums
storeSeqSection macroUsagesSection, m.macroUsages
storeSeqSection toReplaySection, m.toReplay.nodes storeSeqSection toReplaySection, m.toReplay.nodes
storeSeqSection topLevelSection, m.topLevel.nodes storeSeqSection topLevelSection, m.topLevel.nodes

View file

@ -84,7 +84,6 @@ type
convertersSection convertersSection
methodsSection methodsSection
pureEnumsSection pureEnumsSection
macroUsagesSection
toReplaySection toReplaySection
topLevelSection topLevelSection
bodiesSection bodiesSection

View file

@ -2494,7 +2494,7 @@ proc genProc(oldProc: PProc, prc: PSym): Rope =
else: else:
returnStmt = "return $#;$n" % [a.res] returnStmt = "return $#;$n" % [a.res]
var transformedBody = transformBody(p.module.graph, p.module.idgen, prc, cache = false) var transformedBody = transformBody(p.module.graph, p.module.idgen, prc, dontUseCache)
if sfInjectDestructors in prc.flags: if sfInjectDestructors in prc.flags:
transformedBody = injectDestructorCalls(p.module.graph, p.module.idgen, prc, transformedBody) transformedBody = injectDestructorCalls(p.module.graph, p.module.idgen, prc, transformedBody)

View file

@ -441,7 +441,7 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) =
if innerProc: if innerProc:
if s.isIterator: c.somethingToDo = true if s.isIterator: c.somethingToDo = true
if not c.processed.containsOrIncl(s.id): if not c.processed.containsOrIncl(s.id):
let body = transformBody(c.graph, c.idgen, s, cache = true) let body = transformBody(c.graph, c.idgen, s, useCache)
detectCapturedVars(body, s, c) detectCapturedVars(body, s, c)
let ow = s.skipGenericOwner let ow = s.skipGenericOwner
if ow == owner: if ow == owner:
@ -737,7 +737,7 @@ proc liftCapturedVars(n: PNode; owner: PSym; d: var DetectionPass;
# echo renderTree(s.getBody, {renderIds}) # echo renderTree(s.getBody, {renderIds})
let oldInContainer = c.inContainer let oldInContainer = c.inContainer
c.inContainer = 0 c.inContainer = 0
var body = transformBody(d.graph, d.idgen, s, cache = false) var body = transformBody(d.graph, d.idgen, s, dontUseCache)
body = liftCapturedVars(body, s, d, c) body = liftCapturedVars(body, s, d, c)
if c.envVars.getOrDefault(s.id).isNil: if c.envVars.getOrDefault(s.id).isNil:
s.transformedBody = body s.transformedBody = body

View file

@ -27,7 +27,11 @@ import
when defined(nimPreviewSlimSystem): when defined(nimPreviewSlimSystem):
import std/assertions import std/assertions
proc transformBody*(g: ModuleGraph; idgen: IdGenerator, prc: PSym, cache: bool): PNode type
TransformBodyFlag* = enum
dontUseCache, useCache
proc transformBody*(g: ModuleGraph; idgen: IdGenerator, prc: PSym, flag: TransformBodyFlag): PNode
import closureiters, lambdalifting import closureiters, lambdalifting
@ -114,7 +118,7 @@ proc transformSymAux(c: PTransf, n: PNode): PNode =
let s = n.sym let s = n.sym
if s.typ != nil and s.typ.callConv == ccClosure: if s.typ != nil and s.typ.callConv == ccClosure:
if s.kind in routineKinds: if s.kind in routineKinds:
discard transformBody(c.graph, c.idgen, s, true) discard transformBody(c.graph, c.idgen, s, useCache)
if s.kind == skIterator: if s.kind == skIterator:
if c.tooEarly: return n if c.tooEarly: return n
else: return liftIterSym(c.graph, n, c.idgen, getCurrOwner(c)) else: return liftIterSym(c.graph, n, c.idgen, getCurrOwner(c))
@ -748,7 +752,7 @@ proc transformFor(c: PTransf, n: PNode): PNode =
stmtList.add(newAsgnStmt(c, nkFastAsgn, temp, arg, true)) stmtList.add(newAsgnStmt(c, nkFastAsgn, temp, arg, true))
idNodeTablePut(newC.mapping, formal, temp) idNodeTablePut(newC.mapping, formal, temp)
let body = transformBody(c.graph, c.idgen, iter, true) let body = transformBody(c.graph, c.idgen, iter, useCache)
pushInfoContext(c.graph.config, n.info) pushInfoContext(c.graph.config, n.info)
inc(c.inlining) inc(c.inlining)
stmtList.add(transform(c, body)) stmtList.add(transform(c, body))
@ -1147,7 +1151,7 @@ template liftDefer(c, root) =
if c.deferDetected: if c.deferDetected:
liftDeferAux(root) liftDeferAux(root)
proc transformBody*(g: ModuleGraph; idgen: IdGenerator; prc: PSym; cache: bool): PNode = proc transformBody*(g: ModuleGraph; idgen: IdGenerator; prc: PSym; flag: TransformBodyFlag): PNode =
assert prc.kind in routineKinds assert prc.kind in routineKinds
if prc.transformedBody != nil: if prc.transformedBody != nil:
@ -1167,7 +1171,7 @@ proc transformBody*(g: ModuleGraph; idgen: IdGenerator; prc: PSym; cache: bool):
incl(result.flags, nfTransf) incl(result.flags, nfTransf)
if cache or prc.typ.callConv == ccInline: if flag == useCache or prc.typ.callConv == ccInline:
# genProc for inline procs will be called multiple times from different modules, # genProc for inline procs will be called multiple times from different modules,
# it is important to transform exactly once to get sym ids and locations right # it is important to transform exactly once to get sym ids and locations right
prc.transformedBody = result prc.transformedBody = result

View file

@ -1168,7 +1168,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
let ast = a.sym.ast.shallowCopy let ast = a.sym.ast.shallowCopy
for i in 0..<a.sym.ast.len: for i in 0..<a.sym.ast.len:
ast[i] = a.sym.ast[i] ast[i] = a.sym.ast[i]
ast[bodyPos] = transformBody(c.graph, c.idgen, a.sym, cache=true) ast[bodyPos] = transformBody(c.graph, c.idgen, a.sym, useCache)
ast.copyTree() ast.copyTree()
of opcSymOwner: of opcSymOwner:
decodeB(rkNode) decodeB(rkNode)

View file

@ -2252,7 +2252,7 @@ proc genProc(c: PCtx; s: PSym): int =
c.procToCodePos[s.id] = result c.procToCodePos[s.id] = result
# thanks to the jmp we can add top level statements easily and also nest # thanks to the jmp we can add top level statements easily and also nest
# procs easily: # procs easily:
let body = transformBody(c.graph, c.idgen, s, cache = not isCompileTimeProc(s)) let body = transformBody(c.graph, c.idgen, s, if isCompileTimeProc(s): dontUseCache else: useCache)
let procStart = c.xjmp(body, opcJmp, 0) let procStart = c.xjmp(body, opcJmp, 0)
var p = PProc(blocks: @[], sym: s) var p = PProc(blocks: @[], sym: s)
let oldPrc = c.prc let oldPrc = c.prc