diff --git a/compiler/ast.nim b/compiler/ast.nim index 99647e2930..35e334b6ab 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -1611,21 +1611,13 @@ proc createModuleAlias*(s: PSym, idgen: IdGenerator, newIdent: PIdent, info: TLi result.loc = s.loc result.annex = s.annex -proc initStrTable*(x: var TStrTable) = - x.counter = 0 - newSeq(x.data, StartSize) +proc initStrTable*(): TStrTable = + result = TStrTable(counter: 0) + newSeq(result.data, StartSize) -proc newStrTable*: TStrTable = - result = default(TStrTable) - initStrTable(result) - -proc initIdTable*(x: var TIdTable) = - x.counter = 0 - newSeq(x.data, StartSize) - -proc newIdTable*: TIdTable = - result = default(TIdTable) - initIdTable(result) +proc initIdTable*(): TIdTable = + result = TIdTable(counter: 0) + newSeq(result.data, StartSize) proc resetIdTable*(x: var TIdTable) = x.counter = 0 @@ -1633,17 +1625,17 @@ proc resetIdTable*(x: var TIdTable) = setLen(x.data, 0) setLen(x.data, StartSize) -proc initObjectSet*(x: var TObjectSet) = - x.counter = 0 - newSeq(x.data, StartSize) +proc initObjectSet*(): TObjectSet = + result = TObjectSet(counter: 0) + newSeq(result.data, StartSize) -proc initIdNodeTable*(x: var TIdNodeTable) = - x.counter = 0 - newSeq(x.data, StartSize) +proc initIdNodeTable*(): TIdNodeTable = + result = TIdNodeTable(counter: 0) + newSeq(result.data, StartSize) -proc initNodeTable*(x: var TNodeTable) = - x.counter = 0 - newSeq(x.data, StartSize) +proc initNodeTable*(): TNodeTable = + result = TNodeTable(counter: 0) + newSeq(result.data, StartSize) proc skipTypes*(t: PType, kinds: TTypeKinds; maxIters: int): PType = result = t diff --git a/compiler/cgen.nim b/compiler/cgen.nim index de15e8ca4f..5aafc506b2 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -1981,7 +1981,7 @@ proc rawNewModule(g: BModuleList; module: PSym, filename: AbsoluteFile): BModule result.preInitProc = newProc(nil, result) result.preInitProc.flags.incl nimErrorFlagDisabled result.preInitProc.labels = 100_000 # little hack so that unique temporaries are generated - initNodeTable(result.dataCache) + result.dataCache = initNodeTable() result.typeStack = @[] result.typeNodesName = getTempName(result) result.nimTypesName = getTempName(result) diff --git a/compiler/docgen.nim b/compiler/docgen.nim index 933fe57f6f..a6f75b6263 100644 --- a/compiler/docgen.nim +++ b/compiler/docgen.nim @@ -373,7 +373,7 @@ proc newDocumentor*(filename: AbsoluteFile; cache: IdentCache; conf: ConfigRef, result.seenSymbols = newStringTable(modeCaseInsensitive) result.id = 100 result.jEntriesFinal = newJArray() - initStrTable result.types + result.types = initStrTable() result.onTestSnippet = proc (gen: var RstGenerator; filename, cmd: string; status: int; content: string) {.gcsafe.} = if conf.docCmd == docCmdSkip: return diff --git a/compiler/evaltempl.nim b/compiler/evaltempl.nim index ff5c311549..a5d888858f 100644 --- a/compiler/evaltempl.nim +++ b/compiler/evaltempl.nim @@ -187,7 +187,7 @@ proc evalTemplate*(n: PNode, tmpl, genSymOwner: PSym; ctx.genSymOwner = genSymOwner ctx.config = conf ctx.ic = ic - initIdTable(ctx.mapping) + ctx.mapping = initIdTable() ctx.instID = instID[] ctx.idgen = idgen diff --git a/compiler/lookups.nim b/compiler/lookups.nim index 8b9dd71fdc..3cf759981f 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -72,7 +72,7 @@ proc addUniqueSym*(scope: PScope, s: PSym): PSym = proc openScope*(c: PContext): PScope {.discardable.} = result = PScope(parent: c.currentScope, - symbols: newStrTable(), + symbols: initStrTable(), depthLevel: c.scopeDepth + 1) c.currentScope = result @@ -404,7 +404,7 @@ proc openShadowScope*(c: PContext) = ## opens a shadow scope, just like any other scope except the depth is the ## same as the parent -- see `isShadowScope`. c.currentScope = PScope(parent: c.currentScope, - symbols: newStrTable(), + symbols: initStrTable(), depthLevel: c.scopeDepth) proc closeShadowScope*(c: PContext) = diff --git a/compiler/magicsys.nim b/compiler/magicsys.nim index 1b692f5d62..1a9daa9f2b 100644 --- a/compiler/magicsys.nim +++ b/compiler/magicsys.nim @@ -81,8 +81,8 @@ proc getSysType*(g: ModuleGraph; info: TLineInfo; kind: TTypeKind): PType = proc resetSysTypes*(g: ModuleGraph) = g.systemModule = nil - initStrTable(g.compilerprocs) - initStrTable(g.exposed) + g.compilerprocs = initStrTable() + g.exposed = initStrTable() for i in low(g.sysTypes)..high(g.sysTypes): g.sysTypes[i] = nil @@ -124,7 +124,7 @@ proc registerNimScriptSymbol*(g: ModuleGraph; s: PSym) = proc getNimScriptSymbol*(g: ModuleGraph; name: string): PSym = strTableGet(g.exposed, getIdent(g.cache, name)) -proc resetNimScriptSymbols*(g: ModuleGraph) = initStrTable(g.exposed) +proc resetNimScriptSymbols*(g: ModuleGraph) = g.exposed = initStrTable() proc getMagicEqSymForType*(g: ModuleGraph; t: PType; info: TLineInfo): PSym = case t.kind diff --git a/compiler/modulegraphs.nim b/compiler/modulegraphs.nim index f9d0578b5c..b983334535 100644 --- a/compiler/modulegraphs.nim +++ b/compiler/modulegraphs.nim @@ -142,7 +142,7 @@ type isFrontend: bool] proc resetForBackend*(g: ModuleGraph) = - initStrTable(g.compilerprocs) + g.compilerprocs = initStrTable() g.typeInstCache.clear() g.procInstCache.clear() for a in mitems(g.attachedOps): @@ -196,8 +196,8 @@ template semtabAll*(g: ModuleGraph, m: PSym): TStrTable = g.ifaces[m.position].interfHidden proc initStrTables*(g: ModuleGraph, m: PSym) = - initStrTable(semtab(g, m)) - initStrTable(semtabAll(g, m)) + semtab(g, m) = initStrTable() + semtabAll(g, m) = initStrTable() proc strTableAdds*(g: ModuleGraph, m: PSym, s: PSym) = strTableAdd(semtab(g, m), s) @@ -459,7 +459,7 @@ proc initModuleGraphFields(result: ModuleGraph) = # A module ID of -1 means that the symbol is not attached to a module at all, # but to the module graph: result.idgen = IdGenerator(module: -1'i32, symId: 0'i32, typeId: 0'i32) - initStrTable(result.packageSyms) + result.packageSyms = initStrTable() result.deps = initIntSet() result.importDeps = initTable[FileIndex, seq[FileIndex]]() result.ifaces = @[] @@ -469,9 +469,9 @@ proc initModuleGraphFields(result: ModuleGraph) = result.suggestSymbols = initTable[FileIndex, seq[SymInfoPair]]() result.suggestErrors = initTable[FileIndex, seq[Suggest]]() result.methods = @[] - initStrTable(result.compilerprocs) - initStrTable(result.exposed) - initStrTable(result.packageTypes) + result.compilerprocs = initStrTable() + result.exposed = initStrTable() + result.packageTypes = initStrTable() result.emptyNode = newNode(nkEmpty) result.cacheSeqs = initTable[string, PNode]() result.cacheCounters = initTable[string, BiggestInt]() @@ -488,7 +488,7 @@ proc newModuleGraph*(cache: IdentCache; config: ConfigRef): ModuleGraph = initModuleGraphFields(result) proc resetAllModules*(g: ModuleGraph) = - initStrTable(g.packageSyms) + g.packageSyms = initStrTable() g.deps = initIntSet() g.ifaces = @[] g.importStack = @[] @@ -496,8 +496,8 @@ proc resetAllModules*(g: ModuleGraph) = g.usageSym = nil g.owners = @[] g.methods = @[] - initStrTable(g.compilerprocs) - initStrTable(g.exposed) + g.compilerprocs = initStrTable() + g.exposed = initStrTable() initModuleGraphFields(g) proc getModule*(g: ModuleGraph; fileIdx: FileIndex): PSym = diff --git a/compiler/sem.nim b/compiler/sem.nim index 42e6313581..f19f273b5d 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -462,7 +462,7 @@ proc semAfterMacroCall(c: PContext, call, macroResult: PNode, # e.g. template foo(T: typedesc): seq[T] # We will instantiate the return type here, because # we now know the supplied arguments - var paramTypes = newIdTable() + var paramTypes = initIdTable() for param, value in genericParamsInMacroCall(s, call): idTablePut(paramTypes, param.typ, value.typ) diff --git a/compiler/semdata.nim b/compiler/semdata.nim index e783e2168e..0446da6760 100644 --- a/compiler/semdata.nim +++ b/compiler/semdata.nim @@ -251,7 +251,7 @@ proc popProcCon*(c: PContext) {.inline.} = c.p = c.p.next proc put*(p: PProcCon; key, val: PSym) = if not p.mappingExists: - initIdTable(p.mapping) + p.mapping = initIdTable() p.mappingExists = true #echo "put into table ", key.info p.mapping.idTablePut(key, val) @@ -317,13 +317,13 @@ proc newContext*(graph: ModuleGraph; module: PSym): PContext = result.converters = @[] result.patterns = @[] result.includedFiles = initIntSet() - initStrTable(result.pureEnumFields) - initStrTable(result.userPragmas) + result.pureEnumFields = initStrTable() + result.userPragmas = initStrTable() result.generics = @[] result.unknownIdents = initIntSet() result.cache = graph.cache result.graph = graph - initStrTable(result.signatures) + result.signatures = initStrTable() result.features = graph.config.features if graph.config.symbolFiles != disabledSf: let id = module.position @@ -388,7 +388,7 @@ proc reexportSym*(c: PContext; s: PSym) = proc newLib*(kind: TLibKind): PLib = new(result) - result.kind = kind #initObjectSet(result.syms) + result.kind = kind #result.syms = initObjectSet() proc addToLib*(lib: PLib, sym: PSym) = #if sym.annex != nil and not isGenericRoutine(sym): diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index dca4ce6e0d..52eef76316 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -2361,8 +2361,7 @@ proc instantiateCreateFlowVarCall(c: PContext; t: PType; let sym = magicsys.getCompilerProc(c.graph, "nimCreateFlowVar") if sym == nil: localError(c.config, info, "system needs: nimCreateFlowVar") - var bindings: TIdTable = default(TIdTable) - initIdTable(bindings) + var bindings: TIdTable = initIdTable() bindings.idTablePut(sym.ast[genericParamsPos][0].typ, t) result = c.semGenerateInstance(c, sym, bindings, info) # since it's an instantiation, we unmark it as a compilerproc. Otherwise diff --git a/compiler/seminst.nim b/compiler/seminst.nim index 0dc3e3cfc9..c7735903e0 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -122,8 +122,7 @@ proc instantiateBody(c: PContext, n, params: PNode, result, orig: PSym) = inc c.inGenericInst # add it here, so that recursive generic procs are possible: var b = n[bodyPos] - var symMap: TIdTable - initIdTable symMap + var symMap: TIdTable = initIdTable() if params != nil: for i in 1..