diff --git a/compiler/ast.nim b/compiler/ast.nim index 6b00935c61..e8755390d2 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -82,9 +82,6 @@ proc setOwner*(s: PType; owner: PSym) {.inline.} = if s.state == Partial: loadType(s) s.ownerFieldImpl = owner -# Accessor procs for TSym fields -# Note: kind is kept as a direct field for case statement compatibility -# but we still provide an accessor that checks state proc kind*(s: PSym): TSymKind {.inline.} = if s.state == Partial: loadSym(s) result = s.kindImpl diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 7fd7b0f8bd..7dd72ce171 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -61,7 +61,7 @@ proc hcrOn(p: BProc): bool = p.module.config.hcrOn proc addForwardedProc(m: BModule, prc: PSym) = m.g.forwardedProcs.add(prc) -proc newModule*(g: BModuleList; module: PSym; conf: ConfigRef): BModule +proc newModule*(g: BModuleList; module: PSym; conf: ConfigRef; idgen: IdGenerator): BModule proc findPendingModule(m: BModule, s: PSym): BModule = # TODO fixme @@ -72,7 +72,7 @@ proc findPendingModule(m: BModule, s: PSym): BModule = var ms = getModule(s) result = m.g.modules[ms.position] if result == nil: - result = newModule(m.g, ms, m.config) + result = newModule(m.g, ms, m.config, idGeneratorFromModule(ms)) proc initLoc(k: TLocKind, lode: PNode, s: TStorageLoc, flags: TLocFlags = {}): TLoc = result = TLoc(k: k, storage: s, lode: lode, @@ -2372,9 +2372,10 @@ proc rawNewModule(g: BModuleList; module: PSym, filename: AbsoluteFile): BModule proc rawNewModule(g: BModuleList; module: PSym; conf: ConfigRef): BModule = result = rawNewModule(g, module, AbsoluteFile toFullPath(conf, module.position.FileIndex)) -proc newModule(g: BModuleList; module: PSym; conf: ConfigRef): BModule = +proc newModule(g: BModuleList; module: PSym; conf: ConfigRef; idgen: IdGenerator): BModule = # we should create only one cgen module for each module sym result = rawNewModule(g, module, conf) + result.idgen = idgen if module.position >= g.modules.len: setLen(g.modules, module.position + 1) #growCache g.modules, module.position @@ -2387,8 +2388,7 @@ template injectG() {.dirty.} = proc setupCgen*(graph: ModuleGraph; module: PSym; idgen: IdGenerator): PPassContext = injectG() - result = newModule(g, module, graph.config) - result.idgen = idgen + result = newModule(g, module, graph.config, idgen) if optGenIndex in graph.config.globalOptions and g.generatedHeader == nil: let f = if graph.config.headerFile.len > 0: AbsoluteFile graph.config.headerFile else: graph.config.projectFull diff --git a/compiler/ic/cbackend.nim b/compiler/ic/cbackend.nim index 91147d5e07..1cf5301bc0 100644 --- a/compiler/ic/cbackend.nim +++ b/compiler/ic/cbackend.nim @@ -37,8 +37,7 @@ 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) + var bmod = cgen.newModule(BModuleList(g.backend), m.module, g.config, idgenFromLoadedModule(m)) proc generateCodeForModule(g: ModuleGraph; m: var LoadedModule; alive: var AliveSyms) = var bmod = BModuleList(g.backend).modules[m.module.position] diff --git a/compiler/nifbackend.nim b/compiler/nifbackend.nim index 7732844cb1..65f2eee276 100644 --- a/compiler/nifbackend.nim +++ b/compiler/nifbackend.nim @@ -52,7 +52,7 @@ proc setupNifBackendModule(g: ModuleGraph; module: PSym): BModule = ## Set up a BModule for code generation from a NIF module. if g.backend == nil: g.backend = cgendata.newModuleList(g) - result = cgen.newModule(BModuleList(g.backend), module, g.config) + result = cgen.newModule(BModuleList(g.backend), module, g.config, idGeneratorFromModule(module)) proc generateCodeForModule(g: ModuleGraph; module: PSym) = ## Generate C code for a single module. diff --git a/compiler/transf.nim b/compiler/transf.nim index 5c56c1997a..8312181034 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -65,16 +65,14 @@ proc newTransNode(a: PNode): PNode {.inline.} = proc newTransNode(kind: TNodeKind, info: TLineInfo, sons: int): PNode {.inline.} = - var x = newNodeI(kind, info) - newSeq(x.sons, sons) - result = x + result = newNodeI(kind, info) + newSeq(result.sons, sons) proc newTransNode(kind: TNodeKind, n: PNode, sons: int): PNode {.inline.} = - var x = newNodeIT(kind, n.info, n.typ) - newSeq(x.sons, sons) -# x.flags = n.flags - result = x + result = newNodeIT(kind, n.info, n.typ) + newSeq(result.sons, sons) + # x.flags = n.flags proc newTransCon(owner: PSym): PTransCon = assert owner != nil