diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2022-10-10 21:40:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-10 21:40:07 +0200 |
commit | 08ae3467b9b3f52fa568bbf06a9057a87020158b (patch) | |
tree | e125729b8b989ce2d9b2bd88f3b494d0900a3166 | |
parent | e290b028aba9fd50a69ed8c0346ee323f9287a13 (diff) | |
download | Nim-08ae3467b9b3f52fa568bbf06a9057a87020158b.tar.gz |
refactorings (#20536)
* refactoring * refactoring: removed unused macroUsagesSection * enum instead of bool for better readability
-rw-r--r-- | compiler/cgen.nim | 2 | ||||
-rw-r--r-- | compiler/enumtostr.nim | 2 | ||||
-rw-r--r-- | compiler/ic/ic.nim | 3 | ||||
-rw-r--r-- | compiler/ic/rodfiles.nim | 1 | ||||
-rw-r--r-- | compiler/jsgen.nim | 2 | ||||
-rw-r--r-- | compiler/lambdalifting.nim | 4 | ||||
-rw-r--r-- | compiler/transf.nim | 14 | ||||
-rw-r--r-- | compiler/vm.nim | 2 | ||||
-rw-r--r-- | compiler/vmgen.nim | 2 |
9 files changed, 16 insertions, 16 deletions
diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 794abc1ad..e2b7c67ad 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -1067,7 +1067,7 @@ proc genProcAux(m: BModule, prc: PSym) = var returnStmt: Rope = "" 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: procBody = injectDestructorCalls(m.g.graph, m.idgen, prc, procBody) diff --git a/compiler/enumtostr.nim b/compiler/enumtostr.nim index 4a28d066c..f8b3744d5 100644 --- a/compiler/enumtostr.nim +++ b/compiler/enumtostr.nim @@ -30,7 +30,7 @@ proc genEnumToStrProc*(t: PType; info: TLineInfo; g: ModuleGraph; idgen: IdGener assert(t.n[i].kind == nkSym) var field = t.n[i].sym 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)))) #newIntTypeNode(nkIntLit, field.position, t) diff --git a/compiler/ic/ic.nim b/compiler/ic/ic.nim index 866237f08..40e4a5cfb 100644 --- a/compiler/ic/ic.nim +++ b/compiler/ic/ic.nim @@ -43,7 +43,6 @@ type reexports*: seq[(LitId, PackedItemId)] compilerProcs*: seq[(LitId, int32)] converters*, methods*, trmacros*, pureEnums*: seq[int32] - macroUsages*: seq[(PackedItemId, PackedLineInfo)] typeInstCache*: seq[(PackedItemId, PackedItemId)] procInstCache*: seq[PackedInstantiation] @@ -597,7 +596,6 @@ proc loadRodFile*(filename: AbsoluteFile; m: var PackedModule; config: ConfigRef loadSeqSection convertersSection, m.converters loadSeqSection methodsSection, m.methods loadSeqSection pureEnumsSection, m.pureEnums - loadSeqSection macroUsagesSection, m.macroUsages loadSeqSection toReplaySection, m.toReplay.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 methodsSection, m.methods storeSeqSection pureEnumsSection, m.pureEnums - storeSeqSection macroUsagesSection, m.macroUsages storeSeqSection toReplaySection, m.toReplay.nodes storeSeqSection topLevelSection, m.topLevel.nodes diff --git a/compiler/ic/rodfiles.nim b/compiler/ic/rodfiles.nim index 496db0564..46a67c843 100644 --- a/compiler/ic/rodfiles.nim +++ b/compiler/ic/rodfiles.nim @@ -84,7 +84,6 @@ type convertersSection methodsSection pureEnumsSection - macroUsagesSection toReplaySection topLevelSection bodiesSection diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index 5d90af920..de157ed49 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -2494,7 +2494,7 @@ proc genProc(oldProc: PProc, prc: PSym): Rope = else: 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: transformedBody = injectDestructorCalls(p.module.graph, p.module.idgen, prc, transformedBody) diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index 29c1f5b7a..ca9b29a77 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -441,7 +441,7 @@ proc detectCapturedVars(n: PNode; owner: PSym; c: var DetectionPass) = if innerProc: if s.isIterator: c.somethingToDo = true 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) let ow = s.skipGenericOwner if ow == owner: @@ -737,7 +737,7 @@ proc liftCapturedVars(n: PNode; owner: PSym; d: var DetectionPass; # echo renderTree(s.getBody, {renderIds}) let oldInContainer = c.inContainer 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) if c.envVars.getOrDefault(s.id).isNil: s.transformedBody = body diff --git a/compiler/transf.nim b/compiler/transf.nim index be7e43c49..738b1a603 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -27,7 +27,11 @@ import when defined(nimPreviewSlimSystem): 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 @@ -114,7 +118,7 @@ proc transformSymAux(c: PTransf, n: PNode): PNode = let s = n.sym if s.typ != nil and s.typ.callConv == ccClosure: 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 c.tooEarly: return n 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)) 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) inc(c.inlining) stmtList.add(transform(c, body)) @@ -1147,7 +1151,7 @@ template liftDefer(c, root) = if c.deferDetected: 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 if prc.transformedBody != nil: @@ -1167,7 +1171,7 @@ proc transformBody*(g: ModuleGraph; idgen: IdGenerator; prc: PSym; cache: bool): 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, # it is important to transform exactly once to get sym ids and locations right prc.transformedBody = result diff --git a/compiler/vm.nim b/compiler/vm.nim index 7a6dbd0ee..a7d65d1a1 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -1168,7 +1168,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = let ast = a.sym.ast.shallowCopy for i in 0..<a.sym.ast.len: 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() of opcSymOwner: decodeB(rkNode) diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 117c1bc84..ec2d068b7 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -2252,7 +2252,7 @@ proc genProc(c: PCtx; s: PSym): int = c.procToCodePos[s.id] = result # thanks to the jmp we can add top level statements easily and also nest # 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) var p = PProc(blocks: @[], sym: s) let oldPrc = c.prc |