diff options
45 files changed, 216 insertions, 202 deletions
diff --git a/compiler/ast.nim b/compiler/ast.nim index 8aa4ca6b1..bf942f784 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -919,7 +919,9 @@ type # for modules, an unique index corresponding # to the module's fileIdx # for variables a slot index for the evaluator - offset*: int # offset of record field + offset*: int32 # offset of record field + disamb*: int32 # disambiguation number; the basic idea is that + # `<procname>__<module>_<disamb>` loc*: TLoc annex*: PLib # additional fields (seldom used, so we use a # reference to another object to save space) @@ -1143,13 +1145,17 @@ type symId*: int32 typeId*: int32 sealed*: bool + disambTable*: CountTable[PIdent] const PackageModuleId* = -3'i32 proc idGeneratorFromModule*(m: PSym): IdGenerator = assert m.kind == skModule - result = IdGenerator(module: m.itemId.module, symId: m.itemId.item, typeId: 0) + result = IdGenerator(module: m.itemId.module, symId: m.itemId.item, typeId: 0, disambTable: initCountTable[PIdent]()) + +proc idGeneratorForPackage*(nextIdWillBe: int32): IdGenerator = + result = IdGenerator(module: PackageModuleId, symId: nextIdWillBe - 1'i32, typeId: 0, disambTable: initCountTable[PIdent]()) proc nextSymId*(x: IdGenerator): ItemId {.inline.} = assert(not x.sealed) @@ -1341,11 +1347,15 @@ when false: echo k echo v -proc newSym*(symKind: TSymKind, name: PIdent, id: ItemId, owner: PSym, +proc newSym*(symKind: TSymKind, name: PIdent, idgen: IdGenerator; owner: PSym, info: TLineInfo; options: TOptions = {}): PSym = # generates a symbol and initializes the hash field too + assert not name.isNil + let id = nextSymId idgen result = PSym(name: name, kind: symKind, flags: {}, info: info, itemId: id, - options: options, owner: owner, offset: defaultOffset) + options: options, owner: owner, offset: defaultOffset, + disamb: getOrDefault(idgen.disambTable, name).int32) + idgen.disambTable.inc name when false: if id.module == 48 and id.item == 39: writeStackTrace() @@ -1559,8 +1569,8 @@ proc copyType*(t: PType, id: ItemId, owner: PSym): PType = proc exactReplica*(t: PType): PType = result = copyType(t, t.itemId, t.owner) -proc copySym*(s: PSym; id: ItemId): PSym = - result = newSym(s.kind, s.name, id, s.owner, s.info, s.options) +proc copySym*(s: PSym; idgen: IdGenerator): PSym = + result = newSym(s.kind, s.name, idgen, s.owner, s.info, s.options) #result.ast = nil # BUGFIX; was: s.ast which made problems result.typ = s.typ result.flags = s.flags @@ -1575,9 +1585,9 @@ proc copySym*(s: PSym; id: ItemId): PSym = result.bitsize = s.bitsize result.alignment = s.alignment -proc createModuleAlias*(s: PSym, id: ItemId, newIdent: PIdent, info: TLineInfo; +proc createModuleAlias*(s: PSym, idgen: IdGenerator, newIdent: PIdent, info: TLineInfo; options: TOptions): PSym = - result = newSym(s.kind, newIdent, id, s.owner, info, options) + result = newSym(s.kind, newIdent, idgen, s.owner, info, options) # keep ID! result.ast = s.ast #result.id = s.id # XXX figure out what to do with the ID. diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index 6cc009bb9..65f938ca0 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -39,10 +39,10 @@ proc fillBackendName(m: BModule; s: PSym) = var result = s.name.s.mangle.rope result.add "__" result.add m.g.graph.ifaces[s.itemId.module].uniqueName - result.add "_" - result.add rope s.itemId.item + result.add "_u" + result.addInt s.itemId.item # s.disamb # if m.hcrOn: - result.add "_" + result.add '_' result.add(idOrSig(s, m.module.name.s.mangle, m.sigConflicts, m.config)) s.loc.r = result writeMangledName(m.ndi, s, m.config) @@ -50,7 +50,9 @@ proc fillBackendName(m: BModule; s: PSym) = proc fillParamName(m: BModule; s: PSym) = if s.loc.r == "": var res = s.name.s.mangle - res.add idOrSig(s, res, m.sigConflicts, m.config) + res.add "_p" + res.addInt s.position + #res.add idOrSig(s, res, m.sigConflicts, m.config) # Take into account if HCR is on because of the following scenario: # if a module gets imported and it has some more importc symbols in it, # some param names might receive the "_0" suffix to distinguish from what @@ -203,7 +205,7 @@ proc isImportedCppType(t: PType): bool = proc isOrHasImportedCppType(typ: PType): bool = searchTypeFor(typ.skipTypes({tyRef}), isImportedCppType) -proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet; kind: TSymKind): Rope +proc getTypeDescAux(m: BModule; origTyp: PType, check: var IntSet; kind: TSymKind): Rope proc isObjLackingTypeField(typ: PType): bool {.inline.} = result = (typ.kind == tyObject) and ((tfFinal in typ.flags) and @@ -247,7 +249,7 @@ proc cacheGetType(tab: TypeCache; sig: SigHash): Rope = # linear search is not necessary anymore: result = tab.getOrDefault(sig) -proc addAbiCheck(m: BModule, t: PType, name: Rope) = +proc addAbiCheck(m: BModule; t: PType, name: Rope) = if isDefined(m.config, "checkAbi") and (let size = getSize(m.config, t); size != szUnknownSize): var msg = "backend & Nim disagree on size for: " msg.addTypeHeader(m.config, t) @@ -272,7 +274,7 @@ proc typeNameOrLiteral(m: BModule; t: PType, literal: string): Rope = else: result = rope(literal) -proc getSimpleTypeDesc(m: BModule, typ: PType): Rope = +proc getSimpleTypeDesc(m: BModule; typ: PType): Rope = const NumericalTypeToStr: array[tyInt..tyUInt64, string] = [ "NI", "NI8", "NI16", "NI32", "NI64", @@ -309,13 +311,13 @@ proc getSimpleTypeDesc(m: BModule, typ: PType): Rope = if cacheGetType(m.typeCache, sig) == "": m.typeCache[sig] = result -proc pushType(m: BModule, typ: PType) = +proc pushType(m: BModule; typ: PType) = for i in 0..high(m.typeStack): # pointer equality is good enough here: if m.typeStack[i] == typ: return m.typeStack.add(typ) -proc getTypePre(m: BModule, typ: PType; sig: SigHash): Rope = +proc getTypePre(m: BModule; typ: PType; sig: SigHash): Rope = if typ == nil: result = rope("void") else: result = getSimpleTypeDesc(m, typ) @@ -328,7 +330,7 @@ proc structOrUnion(t: PType): Rope = if tfUnion in t.flags: cachedUnion else: cachedStruct -proc addForwardStructFormat(m: BModule, structOrUnion: Rope, typename: Rope) = +proc addForwardStructFormat(m: BModule; structOrUnion: Rope, typename: Rope) = if m.compileToCpp: m.s[cfsForwardTypes].addf "$1 $2;$n", [structOrUnion, typename] else: @@ -338,7 +340,7 @@ proc seqStar(m: BModule): string = if optSeqDestructors in m.config.globalOptions: result = "" else: result = "*" -proc getTypeForward(m: BModule, typ: PType; sig: SigHash): Rope = +proc getTypeForward(m: BModule; typ: PType; sig: SigHash): Rope = result = cacheGetType(m.forwTypeCache, sig) if result != "": return result = getTypePre(m, typ, sig) @@ -422,7 +424,7 @@ proc paramStorageLoc(param: PSym): TStorageLoc = else: result = OnUnknown -proc genProcParams(m: BModule, t: PType, rettype, params: var Rope, +proc genProcParams(m: BModule; t: PType, rettype, params: var Rope, check: var IntSet, declareEnvironment=true; weakDep=false) = params = "(" @@ -492,7 +494,7 @@ proc mangleRecFieldName(m: BModule; field: PSym): Rope = result = rope(mangleField(m, field.name)) if result == "": internalError(m.config, field.info, "mangleRecFieldName") -proc genRecordFieldsAux(m: BModule, n: PNode, +proc genRecordFieldsAux(m: BModule; n: PNode, rectype: PType, check: var IntSet; result: var Rope; unionPrefix = "") = case n.kind @@ -562,7 +564,7 @@ proc genRecordFieldsAux(m: BModule, n: PNode, result.addf("$1$3 $2;$n", [getTypeDescAux(m, field.loc.t, check, skField), sname, noAlias]) else: internalError(m.config, n.info, "genRecordFieldsAux()") -proc getRecordFields(m: BModule, typ: PType, check: var IntSet): Rope = +proc getRecordFields(m: BModule; typ: PType, check: var IntSet): Rope = result = newRopeAppender() genRecordFieldsAux(m, typ.n, typ, check, result) @@ -574,7 +576,7 @@ proc fillObjectFields*(m: BModule; typ: PType) = proc mangleDynLibProc(sym: PSym): Rope -proc getRecordDesc(m: BModule, typ: PType, name: Rope, +proc getRecordDesc(m: BModule; typ: PType, name: Rope, check: var IntSet): Rope = # declare the record: var hasField = false @@ -629,7 +631,7 @@ proc getRecordDesc(m: BModule, typ: PType, name: Rope, if tfPacked in typ.flags and hasAttribute notin CC[m.config.cCompiler].props: result.add "#pragma pack(pop)\L" -proc getTupleDesc(m: BModule, typ: PType, name: Rope, +proc getTupleDesc(m: BModule; typ: PType, name: Rope, check: var IntSet): Rope = result = "$1 $2 {$n" % [structOrUnion(typ), name] var desc: Rope = "" @@ -669,7 +671,7 @@ proc resolveStarsInCppType(typ: PType, idx, stars: int): PType = result = if result.kind == tyGenericInst: result[1] else: result.elemType -proc getOpenArrayDesc(m: BModule, t: PType, check: var IntSet; kind: TSymKind): Rope = +proc getOpenArrayDesc(m: BModule; t: PType, check: var IntSet; kind: TSymKind): Rope = let sig = hashType(t, m.config) if kind == skParam: result = getTypeDescWeak(m, t[0], check, kind) & "*" @@ -682,7 +684,7 @@ proc getOpenArrayDesc(m: BModule, t: PType, check: var IntSet; kind: TSymKind): m.s[cfsTypes].addf("typedef struct {$n$2* Field0;$nNI Field1;$n} $1;$n", [result, elemType]) -proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet; kind: TSymKind): Rope = +proc getTypeDescAux(m: BModule; origTyp: PType, check: var IntSet; kind: TSymKind): Rope = # returns only the type's name var t = origTyp.skipTypes(irrelevantForBackend-{tyOwned}) @@ -916,7 +918,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet; kind: TSymKin # fixes bug #145: excl(check, t.id) -proc getTypeDesc(m: BModule, typ: PType; kind = skParam): Rope = +proc getTypeDesc(m: BModule; typ: PType; kind = skParam): Rope = var check = initIntSet() result = getTypeDescAux(m, typ, check, kind) @@ -926,7 +928,7 @@ type clHalfWithEnv, ## fn(args, void* env) type with trailing 'void* env' parameter clFull ## struct {fn(args, void* env), env} -proc getClosureType(m: BModule, t: PType, kind: TClosureTypeKind): Rope = +proc getClosureType(m: BModule; t: PType, kind: TClosureTypeKind): Rope = assert t.kind == tyProc var check = initIntSet() result = getTempName(m) @@ -957,13 +959,13 @@ proc finishTypeDescriptions(m: BModule) = template cgDeclFrmt*(s: PSym): string = s.constraint.strVal -proc isReloadable(m: BModule, prc: PSym): bool = +proc isReloadable(m: BModule; prc: PSym): bool = return m.hcrOn and sfNonReloadable notin prc.flags -proc isNonReloadable(m: BModule, prc: PSym): bool = +proc isNonReloadable(m: BModule; prc: PSym): bool = return m.hcrOn and sfNonReloadable in prc.flags -proc genProcHeader(m: BModule, prc: PSym; result: var Rope; asPtr: bool = false) = +proc genProcHeader(m: BModule; prc: PSym; result: var Rope; asPtr: bool = false) = # using static is needed for inline procs var check = initIntSet() fillBackendName(m, prc) @@ -997,12 +999,12 @@ proc genProcHeader(m: BModule, prc: PSym; result: var Rope; asPtr: bool = false) # ------------------ type info generation ------------------------------------- -proc genTypeInfoV1(m: BModule, t: PType; info: TLineInfo): Rope +proc genTypeInfoV1(m: BModule; t: PType; info: TLineInfo): Rope proc getNimNode(m: BModule): Rope = result = "$1[$2]" % [m.typeNodesName, rope(m.typeNodes)] inc(m.typeNodes) -proc tiNameForHcr(m: BModule, name: Rope): Rope = +proc tiNameForHcr(m: BModule; name: Rope): Rope = return if m.hcrOn: "(*".rope & name & ")" else: name proc genTypeInfoAuxBase(m: BModule; typ, origType: PType; @@ -1051,7 +1053,7 @@ proc genTypeInfoAuxBase(m: BModule; typ, origType: PType; else: m.s[cfsStrData].addf("N_LIB_PRIVATE TNimType $1;$n", [name]) -proc genTypeInfoAux(m: BModule, typ, origType: PType, name: Rope; +proc genTypeInfoAux(m: BModule; typ, origType: PType, name: Rope; info: TLineInfo) = var base: Rope if typ.len > 0 and typ.lastSon != nil: @@ -1065,7 +1067,7 @@ proc genTypeInfoAux(m: BModule, typ, origType: PType, name: Rope; base = rope("0") genTypeInfoAuxBase(m, typ, origType, name, base, info) -proc discriminatorTableName(m: BModule, objtype: PType, d: PSym): Rope = +proc discriminatorTableName(m: BModule; objtype: PType, d: PSym): Rope = # bugfix: we need to search the type that contains the discriminator: var objtype = objtype.skipTypes(abstractPtrs) while lookupInRecord(objtype.n, d.name) == nil: @@ -1076,12 +1078,12 @@ proc discriminatorTableName(m: BModule, objtype: PType, d: PSym): Rope = proc rope(arg: Int128): Rope = rope($arg) -proc discriminatorTableDecl(m: BModule, objtype: PType, d: PSym): Rope = +proc discriminatorTableDecl(m: BModule; objtype: PType, d: PSym): Rope = cgsym(m, "TNimNode") var tmp = discriminatorTableName(m, objtype, d) result = "TNimNode* $1[$2];$n" % [tmp, rope(lengthOrd(m.config, d.typ)+1)] -proc genTNimNodeArray(m: BModule, name: Rope, size: Rope) = +proc genTNimNodeArray(m: BModule; name: Rope, size: Rope) = if m.hcrOn: m.s[cfsData].addf("static TNimNode** $1;$n", [name]) m.hcrCreateTypeInfosProc.addf("\thcrRegisterGlobal($3, \"$1\", sizeof(TNimNode*) * $2, NULL, (void**)&$1);$n", @@ -1089,7 +1091,7 @@ proc genTNimNodeArray(m: BModule, name: Rope, size: Rope) = else: m.s[cfsTypeInit1].addf("static TNimNode* $1[$2];$n", [name, size]) -proc genObjectFields(m: BModule, typ, origType: PType, n: PNode, expr: Rope; +proc genObjectFields(m: BModule; typ, origType: PType, n: PNode, expr: Rope; info: TLineInfo) = case n.kind of nkRecList: @@ -1159,7 +1161,7 @@ proc genObjectFields(m: BModule, typ, origType: PType, n: PNode, expr: Rope; field.loc.r, genTypeInfoV1(m, field.typ, info), makeCString(field.name.s)]) else: internalError(m.config, n.info, "genObjectFields") -proc genObjectInfo(m: BModule, typ, origType: PType, name: Rope; info: TLineInfo) = +proc genObjectInfo(m: BModule; typ, origType: PType, name: Rope; info: TLineInfo) = if typ.kind == tyObject: if incompleteType(typ): localError(m.config, info, "request for RTTI generation for incomplete object: " & @@ -1177,7 +1179,7 @@ proc genObjectInfo(m: BModule, typ, origType: PType, name: Rope; info: TLineInfo t.flags.incl tfObjHasKids t = t[0] -proc genTupleInfo(m: BModule, typ, origType: PType, name: Rope; info: TLineInfo) = +proc genTupleInfo(m: BModule; typ, origType: PType, name: Rope; info: TLineInfo) = genTypeInfoAuxBase(m, typ, typ, name, rope("0"), info) var expr = getNimNode(m) if typ.len > 0: @@ -1199,7 +1201,7 @@ proc genTupleInfo(m: BModule, typ, origType: PType, name: Rope; info: TLineInfo) [expr, rope(typ.len)]) m.s[cfsTypeInit3].addf("$1.node = &$2;$n", [tiNameForHcr(m, name), expr]) -proc genEnumInfo(m: BModule, typ: PType, name: Rope; info: TLineInfo) = +proc genEnumInfo(m: BModule; typ: PType, name: Rope; info: TLineInfo) = # Type information for enumerations is quite heavy, so we do some # optimizations here: The ``typ`` field is never set, as it is redundant # anyway. We generate a cstring array and a loop over it. Exceptional @@ -1240,14 +1242,14 @@ proc genEnumInfo(m: BModule, typ: PType, name: Rope; info: TLineInfo) = # 1 << 2 is {ntfEnumHole} m.s[cfsTypeInit3].addf("$1.flags = 1<<2;$n", [tiNameForHcr(m, name)]) -proc genSetInfo(m: BModule, typ: PType, name: Rope; info: TLineInfo) = +proc genSetInfo(m: BModule; typ: PType, name: Rope; info: TLineInfo) = assert(typ[0] != nil) genTypeInfoAux(m, typ, typ, name, info) var tmp = getNimNode(m) m.s[cfsTypeInit3].addf("$1.len = $2; $1.kind = 0;$n$3.node = &$1;$n", [tmp, rope(firstOrd(m.config, typ)), tiNameForHcr(m, name)]) -proc genArrayInfo(m: BModule, typ: PType, name: Rope; info: TLineInfo) = +proc genArrayInfo(m: BModule; typ: PType, name: Rope; info: TLineInfo) = genTypeInfoAuxBase(m, typ, typ, name, genTypeInfoV1(m, typ[1], info), info) proc fakeClosureType(m: BModule; owner: PSym): PType = @@ -1266,7 +1268,7 @@ proc genDeepCopyProc(m: BModule; s: PSym; result: Rope) = m.s[cfsTypeInit3].addf("$1.deepcopy =(void* (N_RAW_NIMCALL*)(void*))$2;$n", [result, s.loc.r]) -proc declareNimType(m: BModule, name: string; str: Rope, module: int) = +proc declareNimType(m: BModule; name: string; str: Rope, module: int) = let nr = rope(name) if m.hcrOn: m.s[cfsStrData].addf("static $2* $1;$n", [str, nr]) @@ -1335,7 +1337,7 @@ proc genDisplayElem(d: MD5Digest): uint32 = result += uint32(d[i]) result = result shl 8 -proc genDisplay(m: BModule, t: PType, depth: int): Rope = +proc genDisplay(m: BModule; t: PType, depth: int): Rope = result = Rope"{" var x = t var seqs = newSeq[string](depth+1) @@ -1434,7 +1436,7 @@ proc genTypeInfoV2Impl(m: BModule; t, origType: PType, name: Rope; info: TLineIn if t.kind == tyObject and t.len > 0 and t[0] != nil and optEnableDeepCopy in m.config.globalOptions: discard genTypeInfoV1(m, t, info) -proc genTypeInfoV2(m: BModule, t: PType; info: TLineInfo): Rope = +proc genTypeInfoV2(m: BModule; t: PType; info: TLineInfo): Rope = let origType = t # distinct types can have their own destructors var t = skipTypes(origType, irrelevantForBackend + tyUserTypeClasses - {tyDistinct}) @@ -1509,7 +1511,7 @@ proc typeToC(t: PType): string = # be clashes with our special meanings result.addInt ord(c) -proc genTypeInfoV1(m: BModule, t: PType; info: TLineInfo): Rope = +proc genTypeInfoV1(m: BModule; t: PType; info: TLineInfo): Rope = let origType = t var t = skipTypes(origType, irrelevantForBackend + tyUserTypeClasses) @@ -1610,10 +1612,10 @@ proc genTypeInfoV1(m: BModule, t: PType; info: TLineInfo): Rope = result = prefixTI.rope & result & ")".rope -proc genTypeSection(m: BModule, n: PNode) = +proc genTypeSection(m: BModule; n: PNode) = discard -proc genTypeInfo*(config: ConfigRef, m: BModule, t: PType; info: TLineInfo): Rope = +proc genTypeInfo*(config: ConfigRef, m: BModule; t: PType; info: TLineInfo): Rope = if optTinyRtti in config.globalOptions: result = genTypeInfoV2(m, t, info) else: diff --git a/compiler/cgmeth.nim b/compiler/cgmeth.nim index 1711c5f9a..cc37691fd 100644 --- a/compiler/cgmeth.nim +++ b/compiler/cgmeth.nim @@ -113,7 +113,7 @@ proc attachDispatcher(s: PSym, dispatcher: PNode) = s.ast[dispatcherPos] = dispatcher proc createDispatcher(s: PSym; g: ModuleGraph; idgen: IdGenerator): PSym = - var disp = copySym(s, nextSymId(idgen)) + var disp = copySym(s, idgen) incl(disp.flags, sfDispatcher) excl(disp.flags, sfExported) let old = disp.typ @@ -127,7 +127,7 @@ proc createDispatcher(s: PSym; g: ModuleGraph; idgen: IdGenerator): PSym = disp.loc.r = "" if s.typ[0] != nil: if disp.ast.len > resultPos: - disp.ast[resultPos].sym = copySym(s.ast[resultPos].sym, nextSymId(idgen)) + disp.ast[resultPos].sym = copySym(s.ast[resultPos].sym, idgen) else: # We've encountered a method prototype without a filled-in # resultPos slot. We put a placeholder in there that will diff --git a/compiler/closureiters.nim b/compiler/closureiters.nim index 5c048db2b..3c5d3991b 100644 --- a/compiler/closureiters.nim +++ b/compiler/closureiters.nim @@ -183,7 +183,7 @@ proc newStateAssgn(ctx: var Ctx, stateNo: int = -2): PNode = ctx.newStateAssgn(newIntTypeNode(stateNo, ctx.g.getSysType(TLineInfo(), tyInt))) proc newEnvVar(ctx: var Ctx, name: string, typ: PType): PSym = - result = newSym(skVar, getIdent(ctx.g.cache, name), nextSymId(ctx.idgen), ctx.fn, ctx.fn.info) + result = newSym(skVar, getIdent(ctx.g.cache, name), ctx.idgen, ctx.fn, ctx.fn.info) result.typ = typ assert(not typ.isNil) @@ -1348,7 +1348,7 @@ proc freshVars(n: PNode; c: var FreshVarsContext): PNode = let idefs = copyNode(it) for v in 0..it.len-3: if it[v].kind == nkSym: - let x = copySym(it[v].sym, nextSymId(c.idgen)) + let x = copySym(it[v].sym, c.idgen) c.tab[it[v].sym.id] = x idefs.add newSymNode(x) else: @@ -1431,9 +1431,9 @@ proc transformClosureIterator*(g: ModuleGraph; idgen: IdGenerator; fn: PSym, n: # Lambda lifting was not done yet. Use temporary :state sym, which will # be handled specially by lambda lifting. Local temp vars (if needed) # should follow the same logic. - ctx.stateVarSym = newSym(skVar, getIdent(ctx.g.cache, ":state"), nextSymId(idgen), fn, fn.info) + ctx.stateVarSym = newSym(skVar, getIdent(ctx.g.cache, ":state"), idgen, fn, fn.info) ctx.stateVarSym.typ = g.createClosureIterStateType(fn, idgen) - ctx.stateLoopLabel = newSym(skLabel, getIdent(ctx.g.cache, ":stateLoop"), nextSymId(idgen), fn, fn.info) + ctx.stateLoopLabel = newSym(skLabel, getIdent(ctx.g.cache, ":stateLoop"), idgen, fn, fn.info) var pc = PreprocessContext(finallys: @[], config: g.config, idgen: idgen) var n = preprocess(pc, n.toStmtList) #echo "transformed into ", n diff --git a/compiler/concepts.nim b/compiler/concepts.nim index bcf2d4d0e..6a383a937 100644 --- a/compiler/concepts.nim +++ b/compiler/concepts.nim @@ -27,7 +27,7 @@ const proc declareSelf(c: PContext; info: TLineInfo) = ## Adds the magical 'Self' symbols to the current scope. let ow = getCurrOwner(c) - let s = newSym(skType, getIdent(c.cache, "Self"), nextSymId(c.idgen), ow, info) + let s = newSym(skType, getIdent(c.cache, "Self"), c.idgen, ow, info) s.typ = newType(tyTypeDesc, nextTypeId(c.idgen), ow) s.typ.flags.incl {tfUnresolved, tfPacked} s.typ.add newType(tyEmpty, nextTypeId(c.idgen), ow) diff --git a/compiler/enumtostr.nim b/compiler/enumtostr.nim index f8b3744d5..4ae17235b 100644 --- a/compiler/enumtostr.nim +++ b/compiler/enumtostr.nim @@ -6,12 +6,12 @@ when defined(nimPreviewSlimSystem): proc genEnumToStrProc*(t: PType; info: TLineInfo; g: ModuleGraph; idgen: IdGenerator): PSym = - result = newSym(skProc, getIdent(g.cache, "$"), nextSymId idgen, t.owner, info) + result = newSym(skProc, getIdent(g.cache, "$"), idgen, t.owner, info) - let dest = newSym(skParam, getIdent(g.cache, "e"), nextSymId idgen, result, info) + let dest = newSym(skParam, getIdent(g.cache, "e"), idgen, result, info) dest.typ = t - let res = newSym(skResult, getIdent(g.cache, "result"), nextSymId idgen, result, info) + let res = newSym(skResult, getIdent(g.cache, "result"), idgen, result, info) res.typ = getSysType(g, info, tyString) result.typ = newType(tyProc, nextTypeId idgen, t.owner) @@ -67,12 +67,12 @@ proc searchObjCase(t: PType; field: PSym): PNode = doAssert result != nil proc genCaseObjDiscMapping*(t: PType; field: PSym; info: TLineInfo; g: ModuleGraph; idgen: IdGenerator): PSym = - result = newSym(skProc, getIdent(g.cache, "objDiscMapping"), nextSymId idgen, t.owner, info) + result = newSym(skProc, getIdent(g.cache, "objDiscMapping"), idgen, t.owner, info) - let dest = newSym(skParam, getIdent(g.cache, "e"), nextSymId idgen, result, info) + let dest = newSym(skParam, getIdent(g.cache, "e"), idgen, result, info) dest.typ = field.typ - let res = newSym(skResult, getIdent(g.cache, "result"), nextSymId idgen, result, info) + let res = newSym(skResult, getIdent(g.cache, "result"), idgen, result, info) res.typ = getSysType(g, info, tyUInt8) result.typ = newType(tyProc, nextTypeId idgen, t.owner) diff --git a/compiler/evaltempl.nim b/compiler/evaltempl.nim index d4aa466c2..1b090a6d7 100644 --- a/compiler/evaltempl.nim +++ b/compiler/evaltempl.nim @@ -49,7 +49,7 @@ proc evalTemplateAux(templ, actual: PNode, c: var TemplCtx, result: PNode) = internalAssert c.config, sfGenSym in s.flags or s.kind == skType var x = PSym(idTableGet(c.mapping, s)) if x == nil: - x = copySym(s, nextSymId(c.idgen)) + x = copySym(s, c.idgen) # sem'check needs to set the owner properly later, see bug #9476 x.owner = nil # c.genSymOwner #if x.kind == skParam and x.owner.kind == skModule: diff --git a/compiler/ic/ic.nim b/compiler/ic/ic.nim index 36a57f11e..793ece80a 100644 --- a/compiler/ic/ic.nim +++ b/compiler/ic/ic.nim @@ -390,7 +390,7 @@ proc storeSym*(s: PSym; c: var PackedEncoder; m: var PackedModule): PackedItemId assert sfForward notin s.flags var p = PackedSym(kind: s.kind, flags: s.flags, info: s.info.toPackedInfo(c, m), magic: s.magic, - position: s.position, offset: s.offset, options: s.options, + position: s.position, offset: s.offset, disamb: s.disamb, options: s.options, name: s.name.s.toLitId(m)) storeNode(p, s, ast) @@ -830,6 +830,7 @@ proc symHeaderFromPacked(c: var PackedDecoder; g: var PackedModuleGraph; options: s.options, position: if s.kind in {skForVar, skVar, skLet, skTemp}: 0 else: s.position, offset: if s.kind in routineKinds: defaultOffset else: s.offset, + disamb: s.disamb, name: getIdent(c.cache, g[si].fromDisk.strings[s.name]) ) diff --git a/compiler/ic/packed_ast.nim b/compiler/ic/packed_ast.nim index 87b1516fa..dda07dcf2 100644 --- a/compiler/ic/packed_ast.nim +++ b/compiler/ic/packed_ast.nim @@ -63,7 +63,8 @@ type alignment*: int # for alignment options*: TOptions position*: int - offset*: int + offset*: int32 + disamb*: int32 externalName*: LitId # instead of TLoc locFlags*: TLocFlags annex*: PackedLib diff --git a/compiler/importer.nim b/compiler/importer.nim index 0324b2fbc..39a447b70 100644 --- a/compiler/importer.nim +++ b/compiler/importer.nim @@ -236,7 +236,7 @@ proc addUnique[T](x: var seq[T], y: sink T) {.noSideEffect.} = proc importModuleAs(c: PContext; n: PNode, realModule: PSym, importHidden: bool): PSym = result = realModule template createModuleAliasImpl(ident): untyped = - createModuleAlias(realModule, nextSymId c.idgen, ident, n.info, c.config.options) + createModuleAlias(realModule, c.idgen, ident, n.info, c.config.options) if n.kind != nkImportAs: discard elif n.len != 2 or n[1].kind != nkIdent: localError(c.config, n.info, "module alias must be an identifier") diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index 96102d54d..6d5e070f2 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -70,7 +70,7 @@ proc hasDestructor(c: Con; t: PType): bool {.inline.} = assert(not containsGarbageCollectedRef(t)) proc getTemp(c: var Con; s: var Scope; typ: PType; info: TLineInfo): PNode = - let sym = newSym(skTemp, getIdent(c.graph.cache, ":tmpD"), nextSymId c.idgen, c.owner, info) + let sym = newSym(skTemp, getIdent(c.graph.cache, ":tmpD"), c.idgen, c.owner, info) sym.typ = typ s.vars.add(sym) result = newSymNode(sym) @@ -399,7 +399,7 @@ proc destructiveMoveVar(n: PNode; c: var Con; s: var Scope): PNode = else: result = newNodeIT(nkStmtListExpr, n.info, n.typ) - var temp = newSym(skLet, getIdent(c.graph.cache, "blitTmp"), nextSymId c.idgen, c.owner, n.info) + var temp = newSym(skLet, getIdent(c.graph.cache, "blitTmp"), c.idgen, c.owner, n.info) temp.typ = n.typ var v = newNodeI(nkLetSection, n.info) let tempAsNode = newSymNode(temp) @@ -1023,7 +1023,7 @@ proc sameLocation*(a, b: PNode): bool = proc genFieldAccessSideEffects(c: var Con; s: var Scope; dest, ri: PNode; flags: set[MoveOrCopyFlag] = {}): PNode = # with side effects - var temp = newSym(skLet, getIdent(c.graph.cache, "bracketTmp"), nextSymId c.idgen, c.owner, ri[1].info) + var temp = newSym(skLet, getIdent(c.graph.cache, "bracketTmp"), c.idgen, c.owner, ri[1].info) temp.typ = ri[1].typ var v = newNodeI(nkLetSection, ri[1].info) let tempAsNode = newSymNode(temp) diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index f6bc21c01..ce36123b3 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -140,7 +140,7 @@ proc createClosureIterStateType*(g: ModuleGraph; iter: PSym; idgen: IdGenerator) rawAddSon(result, intType) proc createStateField(g: ModuleGraph; iter: PSym; idgen: IdGenerator): PSym = - result = newSym(skField, getIdent(g.cache, ":state"), nextSymId(idgen), iter, iter.info) + result = newSym(skField, getIdent(g.cache, ":state"), idgen, iter, iter.info) result.typ = createClosureIterStateType(g, iter, idgen) proc createEnvObj(g: ModuleGraph; idgen: IdGenerator; owner: PSym; info: TLineInfo): PType = @@ -154,7 +154,7 @@ proc getClosureIterResult*(g: ModuleGraph; iter: PSym; idgen: IdGenerator): PSym result = iter.ast[resultPos].sym else: # XXX a bit hacky: - result = newSym(skResult, getIdent(g.cache, ":result"), nextSymId(idgen), iter, iter.info, {}) + result = newSym(skResult, getIdent(g.cache, ":result"), idgen, iter, iter.info, {}) result.typ = iter.typ[0] incl(result.flags, sfUsed) iter.ast.add newSymNode(result) @@ -267,7 +267,7 @@ proc liftIterSym*(g: ModuleGraph; n: PNode; idgen: IdGenerator; owner: PSym): PN addUniqueField(it.typ.skipTypes({tyOwned})[0], hp, g.cache, idgen) env = indirectAccess(newSymNode(it), hp, hp.info) else: - let e = newSym(skLet, iter.name, nextSymId(idgen), owner, n.info) + let e = newSym(skLet, iter.name, idgen, owner, n.info) e.typ = hp.typ e.flags = hp.flags env = newSymNode(e) @@ -380,7 +380,7 @@ proc createUpField(c: var DetectionPass; dest, dep: PSym; info: TLineInfo) = if c.graph.config.selectedGC == gcDestructors and sfCursor notin upField.flags: localError(c.graph.config, dep.info, "internal error: up reference is not a .cursor") else: - let result = newSym(skField, upIdent, nextSymId(c.idgen), obj.owner, obj.owner.info) + let result = newSym(skField, upIdent, c.idgen, obj.owner, obj.owner.info) result.typ = fieldType when false: if c.graph.config.selectedGC == gcDestructors: @@ -418,7 +418,7 @@ proc addClosureParam(c: var DetectionPass; fn: PSym; info: TLineInfo) = let owner = if fn.kind == skIterator: fn else: fn.skipGenericOwner let t = c.getEnvTypeForOwner(owner, info) if cp == nil: - cp = newSym(skParam, getIdent(c.graph.cache, paramName), nextSymId(c.idgen), fn, fn.info) + cp = newSym(skParam, getIdent(c.graph.cache, paramName), c.idgen, fn, fn.info) incl(cp.flags, sfFromGeneric) cp.typ = t addHiddenParam(fn, cp) @@ -545,7 +545,7 @@ proc accessViaEnvParam(g: ModuleGraph; n: PNode; owner: PSym): PNode = result = n proc newEnvVar(cache: IdentCache; owner: PSym; typ: PType; info: TLineInfo; idgen: IdGenerator): PNode = - var v = newSym(skVar, getIdent(cache, envName), nextSymId(idgen), owner, info) + var v = newSym(skVar, getIdent(cache, envName), idgen, owner, info) v.flags = {sfShadowed, sfGeneratedOp} v.typ = typ result = newSymNode(v) @@ -569,7 +569,7 @@ proc setupEnvVar(owner: PSym; d: var DetectionPass; result = newEnvVar(d.graph.cache, owner, asOwnedRef(d, envVarType), info, d.idgen) c.envVars[owner.id] = result if optOwnedRefs in d.graph.config.globalOptions: - var v = newSym(skVar, getIdent(d.graph.cache, envName & "Alt"), nextSymId d.idgen, owner, info) + var v = newSym(skVar, getIdent(d.graph.cache, envName & "Alt"), d.idgen, owner, info) v.flags = {sfShadowed, sfGeneratedOp} v.typ = envVarType c.unownedEnvVars[owner.id] = newSymNode(v) @@ -653,7 +653,7 @@ proc closureCreationForIter(iter: PNode; d: var DetectionPass; c: var LiftingPass): PNode = result = newNodeIT(nkStmtListExpr, iter.info, iter.sym.typ) let owner = iter.sym.skipGenericOwner - var v = newSym(skVar, getIdent(d.graph.cache, envName), nextSymId(d.idgen), owner, iter.info) + var v = newSym(skVar, getIdent(d.graph.cache, envName), d.idgen, owner, iter.info) incl(v.flags, sfShadowed) v.typ = asOwnedRef(d, getHiddenParam(d.graph, iter.sym).typ) var vnode: PNode @@ -943,7 +943,7 @@ proc liftForLoop*(g: ModuleGraph; body: PNode; idgen: IdGenerator; owner: PSym): let iter = op.sym let hp = getHiddenParam(g, iter) - env = newSym(skLet, iter.name, nextSymId(idgen), owner, body.info) + env = newSym(skLet, iter.name, idgen, owner, body.info) env.typ = hp.typ env.flags = hp.flags diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim index 467f015d8..3fd3c5f37 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/liftdestructors.nim @@ -243,7 +243,7 @@ proc fillBodyObjT(c: var TLiftCtx; t: PType, body, x, y: PNode) = # for every field (dependent on dest.kind): # `=` dest.field, src.field # =destroy(blob) - var dummy = newSym(skTemp, getIdent(c.g.cache, lowerings.genPrefix), nextSymId c.idgen, c.fn, c.info) + var dummy = newSym(skTemp, getIdent(c.g.cache, lowerings.genPrefix), c.idgen, c.fn, c.info) dummy.typ = y.typ if ccgIntroducedPtr(c.g.config, dummy, y.typ): # Because of potential aliasing when the src param is passed by ref, we need to check for equality here, @@ -252,7 +252,7 @@ proc fillBodyObjT(c: var TLiftCtx; t: PType, body, x, y: PNode) = newTreeIT(nkAddr, c.info, makePtrType(c.fn, x.typ, c.idgen), x), newTreeIT(nkAddr, c.info, makePtrType(c.fn, y.typ, c.idgen), y)) cond.typ = getSysType(c.g, x.info, tyBool) body.add genIf(c, cond, newTreeI(nkReturnStmt, c.info, newNodeI(nkEmpty, c.info))) - var temp = newSym(skTemp, getIdent(c.g.cache, lowerings.genPrefix), nextSymId c.idgen, c.fn, c.info) + var temp = newSym(skTemp, getIdent(c.g.cache, lowerings.genPrefix), c.idgen, c.fn, c.info) temp.typ = x.typ incl(temp.flags, sfFromGeneric) var v = newNodeI(nkVarSection, c.info) @@ -464,7 +464,7 @@ proc considerUserDefinedOp(c: var TLiftCtx; t: PType; body, x, y: PNode): bool = result = true proc declareCounter(c: var TLiftCtx; body: PNode; first: BiggestInt): PNode = - var temp = newSym(skTemp, getIdent(c.g.cache, lowerings.genPrefix), nextSymId(c.idgen), c.fn, c.info) + var temp = newSym(skTemp, getIdent(c.g.cache, lowerings.genPrefix), c.idgen, c.fn, c.info) temp.typ = getSysType(c.g, body.info, tyInt) incl(temp.flags, sfFromGeneric) @@ -474,7 +474,7 @@ proc declareCounter(c: var TLiftCtx; body: PNode; first: BiggestInt): PNode = body.add v proc declareTempOf(c: var TLiftCtx; body: PNode; value: PNode): PNode = - var temp = newSym(skTemp, getIdent(c.g.cache, lowerings.genPrefix), nextSymId(c.idgen), c.fn, c.info) + var temp = newSym(skTemp, getIdent(c.g.cache, lowerings.genPrefix), c.idgen, c.fn, c.info) temp.typ = value.typ incl(temp.flags, sfFromGeneric) @@ -954,10 +954,10 @@ proc symPrototype(g: ModuleGraph; typ: PType; owner: PSym; kind: TTypeAttachedOp info: TLineInfo; idgen: IdGenerator): PSym = let procname = getIdent(g.cache, AttachedOpToStr[kind]) - result = newSym(skProc, procname, nextSymId(idgen), owner, info) - let dest = newSym(skParam, getIdent(g.cache, "dest"), nextSymId(idgen), result, info) + result = newSym(skProc, procname, idgen, owner, info) + let dest = newSym(skParam, getIdent(g.cache, "dest"), idgen, result, info) let src = newSym(skParam, getIdent(g.cache, if kind == attachedTrace: "env" else: "src"), - nextSymId(idgen), result, info) + idgen, result, info) dest.typ = makeVarType(typ.owner, typ, idgen) if kind == attachedTrace: src.typ = getSysType(g, info, tyPointer) @@ -972,7 +972,7 @@ proc symPrototype(g: ModuleGraph; typ: PType; owner: PSym; kind: TTypeAttachedOp if kind == attachedAsgn and g.config.selectedGC == gcOrc and cyclicType(typ.skipTypes(abstractInst)): let cycleParam = newSym(skParam, getIdent(g.cache, "cyclic"), - nextSymId(idgen), result, info) + idgen, result, info) cycleParam.typ = getSysType(g, info, tyBool) result.typ.addParam cycleParam @@ -1049,7 +1049,7 @@ proc produceDestructorForDiscriminator*(g: ModuleGraph; typ: PType; field: PSym, a.addMemReset = true let discrimantDest = result.typ.n[1].sym - let dst = newSym(skVar, getIdent(g.cache, "dest"), nextSymId(idgen), result, info) + let dst = newSym(skVar, getIdent(g.cache, "dest"), idgen, result, info) dst.typ = makePtrType(typ.owner, typ, idgen) let dstSym = newSymNode(dst) let d = newDeref(dstSym) diff --git a/compiler/lookups.nim b/compiler/lookups.nim index 3b4599f2c..81ea63c32 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -274,7 +274,7 @@ proc errorSym*(c: PContext, n: PNode): PSym = considerQuotedIdent(c, m) else: getIdent(c.cache, "err:" & renderTree(m)) - result = newSym(skError, ident, nextSymId(c.idgen), getCurrOwner(c), n.info, {}) + result = newSym(skError, ident, c.idgen, getCurrOwner(c), n.info, {}) result.typ = errorType(c) incl(result.flags, sfDiscardable) # pretend it's from the top level scope to prevent cascading errors: diff --git a/compiler/lowerings.nim b/compiler/lowerings.nim index 54a59c80a..bd81773a8 100644 --- a/compiler/lowerings.nim +++ b/compiler/lowerings.nim @@ -79,7 +79,7 @@ proc lowerTupleUnpacking*(g: ModuleGraph; n: PNode; idgen: IdGenerator; owner: P if avoidTemp: tempAsNode = value else: - var temp = newSym(skTemp, getIdent(g.cache, genPrefix), nextSymId(idgen), + var temp = newSym(skTemp, getIdent(g.cache, genPrefix), idgen, owner, value.info, g.config.options) temp.typ = skipTypes(value.typ, abstractInst) incl(temp.flags, sfFromGeneric) @@ -100,7 +100,7 @@ proc evalOnce*(g: ModuleGraph; value: PNode; idgen: IdGenerator; owner: PSym): P ## freely, multiple times. This is frequently required and such a builtin would also be ## handy to have in macros.nim. The value that can be reused is 'result.lastSon'! result = newNodeIT(nkStmtListExpr, value.info, value.typ) - var temp = newSym(skTemp, getIdent(g.cache, genPrefix), nextSymId(idgen), + var temp = newSym(skTemp, getIdent(g.cache, genPrefix), idgen, owner, value.info, g.config.options) temp.typ = skipTypes(value.typ, abstractInst) incl(temp.flags, sfFromGeneric) @@ -126,7 +126,7 @@ proc lowerTupleUnpackingForAsgn*(g: ModuleGraph; n: PNode; idgen: IdGenerator; o let value = n.lastSon result = newNodeI(nkStmtList, n.info) - var temp = newSym(skTemp, getIdent(g.cache, "_"), nextSymId(idgen), owner, value.info, owner.options) + var temp = newSym(skTemp, getIdent(g.cache, "_"), idgen, owner, value.info, owner.options) var v = newNodeI(nkLetSection, value.info) let tempAsNode = newSymNode(temp) #newIdentNode(getIdent(genPrefix & $temp.id), value.info) @@ -144,7 +144,7 @@ proc lowerTupleUnpackingForAsgn*(g: ModuleGraph; n: PNode; idgen: IdGenerator; o proc lowerSwap*(g: ModuleGraph; n: PNode; idgen: IdGenerator; owner: PSym): PNode = result = newNodeI(nkStmtList, n.info) # note: cannot use 'skTemp' here cause we really need the copy for the VM :-( - var temp = newSym(skVar, getIdent(g.cache, genPrefix), nextSymId(idgen), owner, n.info, owner.options) + var temp = newSym(skVar, getIdent(g.cache, genPrefix), idgen, owner, n.info, owner.options) temp.typ = n[1].typ incl(temp.flags, sfFromGeneric) incl(temp.flags, sfGenSym) @@ -171,8 +171,7 @@ proc createObj*(g: ModuleGraph; idgen: IdGenerator; owner: PSym, info: TLineInfo rawAddSon(result, getCompilerProc(g, "RootObj").typ) result.n = newNodeI(nkRecList, info) let s = newSym(skType, getIdent(g.cache, "Env_" & toFilename(g.config, info) & "_" & $owner.name.s), - nextSymId(idgen), - owner, info, owner.options) + idgen, owner, info, owner.options) incl s.flags, sfAnon s.typ = result result.sym = s @@ -234,7 +233,7 @@ proc addField*(obj: PType; s: PSym; cache: IdentCache; idgen: IdGenerator): PSym # because of 'gensym' support, we have to mangle the name with its ID. # This is hacky but the clean solution is much more complex than it looks. var field = newSym(skField, getIdent(cache, s.name.s & $obj.n.len), - nextSymId(idgen), s.owner, s.info, s.options) + idgen, s.owner, s.info, s.options) field.itemId = ItemId(module: s.itemId.module, item: -s.itemId.item) let t = skipIntLit(s.typ, idgen) field.typ = t @@ -250,7 +249,7 @@ proc addField*(obj: PType; s: PSym; cache: IdentCache; idgen: IdGenerator): PSym proc addUniqueField*(obj: PType; s: PSym; cache: IdentCache; idgen: IdGenerator): PSym {.discardable.} = result = lookupInRecord(obj.n, s.itemId) if result == nil: - var field = newSym(skField, getIdent(cache, s.name.s & $obj.n.len), nextSymId(idgen), + var field = newSym(skField, getIdent(cache, s.name.s & $obj.n.len), idgen, s.owner, s.info, s.options) field.itemId = ItemId(module: s.itemId.module, item: -s.itemId.item) let t = skipIntLit(s.typ, idgen) diff --git a/compiler/magicsys.nim b/compiler/magicsys.nim index ab234a2a8..8261b14c7 100644 --- a/compiler/magicsys.nim +++ b/compiler/magicsys.nim @@ -26,7 +26,7 @@ proc getSysSym*(g: ModuleGraph; info: TLineInfo; name: string): PSym = result = systemModuleSym(g, getIdent(g.cache, name)) if result == nil: localError(g.config, info, "system module needs: " & name) - result = newSym(skError, getIdent(g.cache, name), nextSymId(g.idgen), g.systemModule, g.systemModule.info, {}) + result = newSym(skError, getIdent(g.cache, name), g.idgen, g.systemModule, g.systemModule.info, {}) result.typ = newType(tyError, nextTypeId(g.idgen), g.systemModule) if result.kind == skAlias: result = result.owner @@ -39,7 +39,7 @@ proc getSysMagic*(g: ModuleGraph; info: TLineInfo; name: string, m: TMagic): PSy result = r if result != nil: return result localError(g.config, info, "system module needs: " & name) - result = newSym(skError, id, nextSymId(g.idgen), g.systemModule, g.systemModule.info, {}) + result = newSym(skError, id, g.idgen, g.systemModule, g.systemModule.info, {}) result.typ = newType(tyError, nextTypeId(g.idgen), g.systemModule) proc sysTypeFromName*(g: ModuleGraph; info: TLineInfo; name: string): PType = diff --git a/compiler/modulegraphs.nim b/compiler/modulegraphs.nim index 8ffbe20a5..4fdeb354e 100644 --- a/compiler/modulegraphs.nim +++ b/compiler/modulegraphs.nim @@ -411,7 +411,7 @@ proc stopCompile*(g: ModuleGraph): bool {.inline.} = result = g.doStopCompile != nil and g.doStopCompile() proc createMagic*(g: ModuleGraph; idgen: IdGenerator; name: string, m: TMagic): PSym = - result = newSym(skProc, getIdent(g.cache, name), nextSymId(idgen), nil, unknownLineInfo, {}) + result = newSym(skProc, getIdent(g.cache, name), idgen, nil, unknownLineInfo, {}) result.magic = m result.flags = {sfNeverRaises} diff --git a/compiler/nilcheck.nim b/compiler/nilcheck.nim index 91d76b2b8..5cc66f3ea 100644 --- a/compiler/nilcheck.nim +++ b/compiler/nilcheck.nim @@ -909,7 +909,7 @@ proc infix(ctx: NilCheckerContext, l: PNode, r: PNode, magic: TMagic): PNode = else: "" var cache = newIdentCache() - var op = newSym(skVar, cache.getIdent(name), nextSymId ctx.idgen, nil, r.info) + var op = newSym(skVar, cache.getIdent(name), ctx.idgen, nil, r.info) op.magic = magic result = nkInfix.newTree( @@ -920,7 +920,7 @@ proc infix(ctx: NilCheckerContext, l: PNode, r: PNode, magic: TMagic): PNode = proc prefixNot(ctx: NilCheckerContext, node: PNode): PNode = var cache = newIdentCache() - var op = newSym(skVar, cache.getIdent("not"), nextSymId ctx.idgen, nil, node.info) + var op = newSym(skVar, cache.getIdent("not"), ctx.idgen, nil, node.info) op.magic = mNot result = nkPrefix.newTree( diff --git a/compiler/packages.nim b/compiler/packages.nim index d8b97e374..bb54d6154 100644 --- a/compiler/packages.nim +++ b/compiler/packages.nim @@ -8,7 +8,7 @@ # ## Package related procs. -## +## ## See Also: ## * `packagehandling` for package path handling ## * `modulegraphs.getPackage` @@ -22,7 +22,7 @@ when defined(nimPreviewSlimSystem): proc getPackage*(conf: ConfigRef; cache: IdentCache; fileIdx: FileIndex): PSym = ## Return a new package symbol. - ## + ## ## See Also: ## * `modulegraphs.getPackage` let @@ -31,7 +31,7 @@ proc getPackage*(conf: ConfigRef; cache: IdentCache; fileIdx: FileIndex): PSym = info = newLineInfo(fileIdx, 1, 1) pkgName = getPackageName(conf, filename.string) pkgIdent = getIdent(cache, pkgName) - newSym(skPackage, pkgIdent, ItemId(module: PackageModuleId, item: int32(fileIdx)), nil, info) + newSym(skPackage, pkgIdent, idGeneratorForPackage(int32(fileIdx)), nil, info) func getPackageSymbol*(sym: PSym): PSym = ## Return the owning package symbol. @@ -47,7 +47,7 @@ func getPackageId*(sym: PSym): int = func belongsToProjectPackage*(conf: ConfigRef, sym: PSym): bool = ## Return whether the symbol belongs to the project's package. - ## + ## ## See Also: ## * `modulegraphs.belongsToStdlib` conf.mainPackageId == sym.getPackageId diff --git a/compiler/plugins/itersgen.nim b/compiler/plugins/itersgen.nim index 24e26b2b7..1a291c04d 100644 --- a/compiler/plugins/itersgen.nim +++ b/compiler/plugins/itersgen.nim @@ -31,7 +31,7 @@ proc iterToProcImpl*(c: PContext, n: PNode): PNode = return let body = liftIterToProc(c.graph, iter.sym, getBody(c.graph, iter.sym), t, c.idgen) - let prc = newSym(skProc, n[3].ident, nextSymId c.idgen, iter.sym.owner, iter.sym.info) + let prc = newSym(skProc, n[3].ident, c.idgen, iter.sym.owner, iter.sym.info) prc.typ = copyType(iter.sym.typ, nextTypeId c.idgen, prc) excl prc.typ.flags, tfCapturesEnv prc.typ.n.add newSymNode(getEnvParam(iter.sym)) diff --git a/compiler/plugins/locals.nim b/compiler/plugins/locals.nim index 384780f7b..d3046cd65 100644 --- a/compiler/plugins/locals.nim +++ b/compiler/plugins/locals.nim @@ -26,7 +26,7 @@ proc semLocals*(c: PContext, n: PNode): PNode = {tyVarargs, tyOpenArray, tyTypeDesc, tyStatic, tyUntyped, tyTyped, tyEmpty}: if it.owner == owner: - var field = newSym(skField, it.name, nextSymId c.idgen, owner, n.info) + var field = newSym(skField, it.name, c.idgen, owner, n.info) field.typ = it.typ.skipTypes({tyVar}) field.position = counter inc(counter) diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index c752c5263..22677ba01 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -139,7 +139,7 @@ proc pragmaEnsures(c: PContext, n: PNode) = openScope(c) let o = getCurrOwner(c) if o.kind in routineKinds and o.typ != nil and o.typ.sons[0] != nil: - var s = newSym(skResult, getIdent(c.cache, "result"), nextSymId(c.idgen), o, n.info) + var s = newSym(skResult, getIdent(c.cache, "result"), c.idgen, o, n.info) s.typ = o.typ.sons[0] incl(s.flags, sfUsed) addDecl(c, s) @@ -675,7 +675,7 @@ proc processPragma(c: PContext, n: PNode, i: int) = elif it.safeLen != 2 or it[0].kind != nkIdent or it[1].kind != nkIdent: invalidPragma(c, n) - var userPragma = newSym(skTemplate, it[1].ident, nextSymId(c.idgen), c.module, it.info, c.config.options) + var userPragma = newSym(skTemplate, it[1].ident, c.idgen, c.module, it.info, c.config.options) userPragma.ast = newTreeI(nkPragma, n.info, n.sons[i+1..^1]) strTableAdd(c.userPragmas, userPragma) @@ -741,7 +741,7 @@ proc deprecatedStmt(c: PContext; outerPragma: PNode) = if dest == nil or dest.kind in routineKinds: localError(c.config, n.info, warnUser, "the .deprecated pragma is unreliable for routines") let src = considerQuotedIdent(c, n[0]) - let alias = newSym(skAlias, src, nextSymId(c.idgen), dest, n[0].info, c.config.options) + let alias = newSym(skAlias, src, c.idgen, dest, n[0].info, c.config.options) incl(alias.flags, sfExported) if sfCompilerProc in dest.flags: markCompilerProc(c, alias) addInterfaceDecl(c, alias) @@ -763,7 +763,7 @@ proc pragmaGuard(c: PContext; it: PNode; kind: TSymKind): PSym = # We return a dummy symbol; later passes over the type will repair it. # Generic instantiation needs to know about this too. But we're lazy # and perform the lookup on demand instead. - result = newSym(skUnknown, considerQuotedIdent(c, n), nextSymId(c.idgen), nil, n.info, + result = newSym(skUnknown, considerQuotedIdent(c, n), c.idgen, nil, n.info, c.config.options) else: result = qualifiedLookUp(c, n, {checkUndeclared}) @@ -787,7 +787,7 @@ proc semCustomPragma(c: PContext, n: PNode, sym: PSym): PNode = if r.isNil or sfCustomPragma notin r[0].sym.flags: invalidPragma(c, n) return n - + # we have a valid custom pragma if sym != nil and sym.kind in {skEnumField, skForVar, skModule}: illegalCustomPragma(c, n, sym) diff --git a/compiler/sem.nim b/compiler/sem.nim index 1c15f905e..bac029fb9 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -9,6 +9,8 @@ # This module implements the semantic checking pass. +import tables + import ast, strutils, options, astalgo, trees, wordrecg, ropes, msgs, idents, renderer, types, platform, math, @@ -219,7 +221,7 @@ proc commonType*(c: PContext; x: PType, y: PNode): PType = commonType(c, x, y.typ) proc newSymS(kind: TSymKind, n: PNode, c: PContext): PSym = - result = newSym(kind, considerQuotedIdent(c, n), nextSymId c.idgen, getCurrOwner(c), n.info) + result = newSym(kind, considerQuotedIdent(c, n), c.idgen, getCurrOwner(c), n.info) when defined(nimsuggest): suggestDecl(c, n, result) @@ -242,7 +244,7 @@ proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym = # template; we must fix it here: see #909 result.owner = getCurrOwner(c) else: - result = newSym(kind, considerQuotedIdent(c, n), nextSymId c.idgen, getCurrOwner(c), n.info) + result = newSym(kind, considerQuotedIdent(c, n), c.idgen, getCurrOwner(c), n.info) #if kind in {skForVar, skLet, skVar} and result.owner.kind == skModule: # incl(result.flags, sfGlobal) when defined(nimsuggest): @@ -281,7 +283,7 @@ proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym, proc symFromType(c: PContext; t: PType, info: TLineInfo): PSym = if t.sym != nil: return t.sym - result = newSym(skType, getIdent(c.cache, "AnonType"), nextSymId c.idgen, t.owner, info) + result = newSym(skType, getIdent(c.cache, "AnonType"), c.idgen, t.owner, info) result.flags.incl sfAnon result.typ = t diff --git a/compiler/semdata.nim b/compiler/semdata.nim index 90d496c8c..8235eba9c 100644 --- a/compiler/semdata.nim +++ b/compiler/semdata.nim @@ -431,7 +431,7 @@ proc makeTypeSymNode*(c: PContext, typ: PType, info: TLineInfo): PNode = incl typedesc.flags, tfCheckedForDestructor internalAssert(c.config, typ != nil) typedesc.addSonSkipIntLit(typ, c.idgen) - let sym = newSym(skType, c.cache.idAnon, nextSymId(c.idgen), getCurrOwner(c), info, + let sym = newSym(skType, c.cache.idAnon, c.idgen, getCurrOwner(c), info, c.config.options).linkTo(typedesc) result = newSymNode(sym, info) diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 46d83c0e7..a55d74a24 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -846,7 +846,7 @@ proc analyseIfAddressTakenInCall(c: PContext, n: PNode, isConverter = false) = # So we need to make sure we are checking them still when in a converter call if n[i].kind != nkHiddenAddr or isConverter: n[i] = analyseIfAddressTaken(c, n[i].skipAddr(), isOutParam(skipTypes(t[i], abstractInst-{tyTypeDesc}))) - + include semmagic proc evalAtCompileTime(c: PContext, n: PNode): PNode = @@ -1236,7 +1236,7 @@ proc readTypeParameter(c: PContext, typ: PType, # This seems semantically correct and then we'll be able # to return the section symbol directly here let foundType = makeTypeDesc(c, def[2].typ) - return newSymNode(copySym(def[0].sym, nextSymId c.idgen).linkTo(foundType), info) + return newSymNode(copySym(def[0].sym, c.idgen).linkTo(foundType), info) of nkConstSection: for def in statement: @@ -1261,7 +1261,7 @@ proc readTypeParameter(c: PContext, typ: PType, return c.graph.emptyNode else: let foundTyp = makeTypeDesc(c, rawTyp) - return newSymNode(copySym(tParam.sym, nextSymId c.idgen).linkTo(foundTyp), info) + return newSymNode(copySym(tParam.sym, c.idgen).linkTo(foundTyp), info) return nil @@ -2093,7 +2093,7 @@ proc expectString(c: PContext, n: PNode): string = localError(c.config, n.info, errStringLiteralExpected) proc newAnonSym(c: PContext; kind: TSymKind, info: TLineInfo): PSym = - result = newSym(kind, c.cache.idAnon, nextSymId c.idgen, getCurrOwner(c), info) + result = newSym(kind, c.cache.idAnon, c.idgen, getCurrOwner(c), info) proc semExpandToAst(c: PContext, n: PNode): PNode = let macroCall = n[1] @@ -2865,7 +2865,7 @@ proc hoistParamsUsedInDefault(c: PContext, call, letSection, defExpr: var PNode) let paramPos = defExpr.sym.position + 1 if call[paramPos].kind != nkSym: - let hoistedVarSym = newSym(skLet, getIdent(c.graph.cache, genPrefix), nextSymId c.idgen, + let hoistedVarSym = newSym(skLet, getIdent(c.graph.cache, genPrefix), c.idgen, c.p.owner, letSection.info, c.p.owner.options) hoistedVarSym.typ = call[paramPos].typ diff --git a/compiler/semfields.nim b/compiler/semfields.nim index 36e3b57e7..5f3172f81 100644 --- a/compiler/semfields.nim +++ b/compiler/semfields.nim @@ -109,7 +109,7 @@ proc semForFields(c: PContext, n: PNode, m: TMagic): PNode = var trueSymbol = systemModuleSym(c.graph, getIdent(c.cache, "true")) if trueSymbol == nil: localError(c.config, n.info, "system needs: 'true'") - trueSymbol = newSym(skUnknown, getIdent(c.cache, "true"), nextSymId c.idgen, getCurrOwner(c), n.info) + trueSymbol = newSym(skUnknown, getIdent(c.cache, "true"), c.idgen, getCurrOwner(c), n.info) trueSymbol.typ = getSysType(c.graph, n.info, tyBool) result[0] = newSymNode(trueSymbol, n.info) diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index 695f8a01d..7241a4702 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -465,7 +465,7 @@ proc semGenericStmt(c: PContext, n: PNode, flags, ctx) if n[paramsPos].kind != nkEmpty: if n[paramsPos][0].kind != nkEmpty: - addPrelimDecl(c, newSym(skUnknown, getIdent(c.cache, "result"), nextSymId c.idgen, nil, n.info)) + addPrelimDecl(c, newSym(skUnknown, getIdent(c.cache, "result"), c.idgen, nil, n.info)) n[paramsPos] = semGenericStmt(c, n[paramsPos], flags, ctx) n[pragmasPos] = semGenericStmt(c, n[pragmasPos], flags, ctx) var body: PNode diff --git a/compiler/seminst.nim b/compiler/seminst.nim index 25e5b267e..3afbedec7 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -45,7 +45,7 @@ iterator instantiateGenericParamList(c: PContext, n: PNode, pt: TIdTable): PSym var q = a.sym if q.typ.kind in {tyTypeDesc, tyGenericParam, tyStatic, tyConcept}+tyTypeClasses: let symKind = if q.typ.kind == tyStatic: skConst else: skType - var s = newSym(symKind, q.name, nextSymId(c.idgen), getCurrOwner(c), q.info) + var s = newSym(symKind, q.name, c.idgen, getCurrOwner(c), q.info) s.flags.incl {sfUsed, sfFromGeneric} var t = PType(idTableGet(pt, q.typ)) if t == nil: @@ -100,7 +100,7 @@ proc freshGenSyms(c: PContext; n: PNode, owner, orig: PSym, symMap: var TIdTable n.sym = x elif s.owner == nil or s.owner.kind == skPackage: #echo "copied this ", s.name.s - x = copySym(s, nextSymId c.idgen) + x = copySym(s, c.idgen) x.owner = owner idTablePut(symMap, s, x) n.sym = x @@ -128,7 +128,7 @@ proc instantiateBody(c: PContext, n, params: PNode, result, orig: PSym) = idTablePut(symMap, params[i].sym, result.typ.n[param.position+1].sym) freshGenSyms(c, b, result, orig, symMap) - if sfBorrow notin orig.flags: + if sfBorrow notin orig.flags: # We do not want to generate a body for generic borrowed procs. # As body is a sym to the borrowed proc. let resultType = # todo probably refactor it into a function @@ -193,7 +193,7 @@ proc instGenericContainer(c: PContext, info: TLineInfo, header: PType, var param: PSym template paramSym(kind): untyped = - newSym(kind, genParam.sym.name, nextSymId c.idgen, genericTyp.sym, genParam.sym.info) + newSym(kind, genParam.sym.name, c.idgen, genericTyp.sym, genParam.sym.info) if genParam.kind == tyStatic: param = paramSym skConst @@ -263,7 +263,7 @@ proc instantiateProcType(c: PContext, pt: TIdTable, internalAssert c.config, originalParams[i].kind == nkSym let oldParam = originalParams[i].sym - let param = copySym(oldParam, nextSymId c.idgen) + let param = copySym(oldParam, c.idgen) param.owner = prc param.typ = result[i] @@ -340,7 +340,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable, c.matchedConcept = nil let oldScope = c.currentScope while not isTopLevel(c): c.currentScope = c.currentScope.parent - result = copySym(fn, nextSymId c.idgen) + result = copySym(fn, c.idgen) incl(result.flags, sfFromGeneric) result.owner = fn result.ast = n diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim index e72b27d52..6af752770 100644 --- a/compiler/semmagic.nim +++ b/compiler/semmagic.nim @@ -420,14 +420,14 @@ proc turnFinalizerIntoDestructor(c: PContext; orig: PSym; info: TLineInfo): PSym #if n.kind == nkDerefExpr and sameType(n[0].typ, old): # result = - result = copySym(orig, nextSymId c.idgen) + result = copySym(orig, c.idgen) result.info = info result.flags.incl sfFromGeneric result.owner = orig let origParamType = orig.typ[1] let newParamType = makeVarType(result, origParamType.skipTypes(abstractPtrs), c.idgen) let oldParam = orig.typ.n[1].sym - let newParam = newSym(skParam, oldParam.name, nextSymId c.idgen, result, result.info) + let newParam = newSym(skParam, oldParam.name, c.idgen, result, result.info) newParam.typ = newParamType # proc body: result.ast = transform(c, orig.ast, origParamType, newParamType, oldParam, newParam) @@ -493,8 +493,8 @@ proc semNewFinalize(c: PContext; n: PNode): PNode = getAttachedOp(c.graph, t, attachedDestructor).owner == fin: discard "already turned this one into a finalizer" else: - let wrapperSym = newSym(skProc, getIdent(c.graph.cache, fin.name.s & "FinalizerWrapper"), nextSymId c.idgen, fin.owner, fin.info) - let selfSymNode = newSymNode(copySym(fin.ast[paramsPos][1][0].sym, nextSymId c.idgen)) + let wrapperSym = newSym(skProc, getIdent(c.graph.cache, fin.name.s & "FinalizerWrapper"), c.idgen, fin.owner, fin.info) + let selfSymNode = newSymNode(copySym(fin.ast[paramsPos][1][0].sym, c.idgen)) selfSymNode.typ = fin.typ[1] wrapperSym.flags.incl sfUsed diff --git a/compiler/semparallel.nim b/compiler/semparallel.nim index ced479dbe..420a1f2d6 100644 --- a/compiler/semparallel.nim +++ b/compiler/semparallel.nim @@ -486,7 +486,7 @@ proc liftParallel*(g: ModuleGraph; idgen: IdGenerator; owner: PSym; n: PNode): P checkArgs(a, body) var varSection = newNodeI(nkVarSection, n.info) - var temp = newSym(skTemp, getIdent(g.cache, "barrier"), nextSymId idgen, owner, n.info) + var temp = newSym(skTemp, getIdent(g.cache, "barrier"), idgen, owner, n.info) temp.typ = magicsys.getCompilerProc(g, "Barrier").typ incl(temp.flags, sfFromGeneric) let tempNode = newSymNode(temp) diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index f9d06f7a8..ce4febd3f 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -233,7 +233,7 @@ proc markGcUnsafe(a: PEffects; reason: PNode) = if reason.kind == nkSym: a.owner.gcUnsafetyReason = reason.sym else: - a.owner.gcUnsafetyReason = newSym(skUnknown, a.owner.name, nextSymId a.c.idgen, + a.owner.gcUnsafetyReason = newSym(skUnknown, a.owner.name, a.c.idgen, a.owner, reason.info, {}) proc markSideEffect(a: PEffects; reason: PNode | PSym; useLoc: TLineInfo) = @@ -246,7 +246,7 @@ proc markSideEffect(a: PEffects; reason: PNode | PSym; useLoc: TLineInfo) = sym = reason.sym else: let kind = if reason.kind == nkHiddenDeref: skParam else: skUnknown - sym = newSym(kind, a.owner.name, nextSymId a.c.idgen, a.owner, reason.info, {}) + sym = newSym(kind, a.owner.name, a.c.idgen, a.owner, reason.info, {}) else: sym = reason a.c.sideEffects.mgetOrPut(a.owner.id, @[]).add (useLoc, sym) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 20fb12d71..63b3382a8 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -460,7 +460,7 @@ proc fillPartialObject(c: PContext; n: PNode; typ: PType) = let y = considerQuotedIdent(c, n[1]) let obj = x.typ.skipTypes(abstractPtrs) if obj.kind == tyObject and tfPartial in obj.flags: - let field = newSym(skField, getIdent(c.cache, y.s), nextSymId c.idgen, obj.sym, n[1].info) + let field = newSym(skField, getIdent(c.cache, y.s), c.idgen, obj.sym, n[1].info) field.typ = skipIntLit(typ, c.idgen) field.position = obj.n.len obj.n.add newSymNode(field) @@ -599,7 +599,7 @@ proc makeVarTupleSection(c: PContext, n, a, def: PNode, typ: PType, symkind: TSy let useTemp = def.kind notin {nkPar, nkTupleConstr} or symkind == skConst if useTemp: # use same symkind for compatibility with original section - tmpTuple = newSym(symkind, getIdent(c.cache, "tmpTuple"), nextSymId c.idgen, getCurrOwner(c), n.info) + tmpTuple = newSym(symkind, getIdent(c.cache, "tmpTuple"), c.idgen, getCurrOwner(c), n.info) tmpTuple.typ = typ tmpTuple.flags.incl(sfGenSym) lastDef = newNodeI(defkind, a.info) @@ -1127,10 +1127,10 @@ proc semCase(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil popCaseContext(c) closeScope(c) return handleCaseStmtMacro(c, n, flags) - template invalidOrderOfBranches(n: PNode) = + template invalidOrderOfBranches(n: PNode) = localError(c.config, n.info, "invalid order of case branches") break - + for i in 1..<n.len: setCaseContextIdx(c, i) var x = n[i] @@ -1476,7 +1476,7 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) = if tfInheritable in oldFlags and tfFinal in objTy.flags: excl(objTy.flags, tfFinal) let obj = newSym(skType, getIdent(c.cache, s.name.s & ":ObjectType"), - nextSymId c.idgen, getCurrOwner(c), s.info) + c.idgen, getCurrOwner(c), s.info) obj.flags.incl sfGeneratedType let symNode = newSymNode(obj) obj.ast = a.shallowCopy @@ -1656,7 +1656,7 @@ proc swapResult(n: PNode, sRes: PSym, dNode: PNode) = proc addResult(c: PContext, n: PNode, t: PType, owner: TSymKind) = template genResSym(s) = - var s = newSym(skResult, getIdent(c.cache, "result"), nextSymId c.idgen, + var s = newSym(skResult, getIdent(c.cache, "result"), c.idgen, getCurrOwner(c), n.info) s.typ = t incl(s.flags, sfUsed) @@ -1997,7 +1997,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, case n[namePos].kind of nkEmpty: - s = newSym(kind, c.cache.idAnon, nextSymId c.idgen, c.getCurrOwner, n.info) + s = newSym(kind, c.cache.idAnon, c.idgen, c.getCurrOwner, n.info) s.flags.incl sfUsed n[namePos] = newSymNode(s) of nkSym: @@ -2211,7 +2211,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, trackProc(c, s, s.ast[bodyPos]) else: if (s.typ[0] != nil and s.kind != skIterator): - addDecl(c, newSym(skUnknown, getIdent(c.cache, "result"), nextSymId c.idgen, s, n.info)) + addDecl(c, newSym(skUnknown, getIdent(c.cache, "result"), c.idgen, s, n.info)) openScope(c) n[bodyPos] = semGenericStmt(c, n[bodyPos]) diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 6c01be7ea..74865ad58 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -182,7 +182,7 @@ proc onlyReplaceParams(c: var TemplCtx, n: PNode): PNode = result[i] = onlyReplaceParams(c, n[i]) proc newGenSym(kind: TSymKind, n: PNode, c: var TemplCtx): PSym = - result = newSym(kind, considerQuotedIdent(c.c, n), nextSymId c.c.idgen, c.owner, n.info) + result = newSym(kind, considerQuotedIdent(c.c, n), c.c.idgen, c.owner, n.info) incl(result.flags, sfGenSym) incl(result.flags, sfShadowed) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 8f34da72d..288ed9d88 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -981,7 +981,7 @@ proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) = if kind == skMacro: let staticType = findEnforcedStaticType(param.typ) if staticType != nil: - var a = copySym(param, nextSymId c.idgen) + var a = copySym(param, c.idgen) a.typ = staticType.base addDecl(c, a) #elif param.typ != nil and param.typ.kind == tyTypeDesc: @@ -989,7 +989,7 @@ proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) = else: # within a macro, every param has the type NimNode! let nn = getSysSym(c.graph, param.info, "NimNode") - var a = copySym(param, nextSymId c.idgen) + var a = copySym(param, c.idgen) a.typ = nn.typ addDecl(c, a) else: @@ -1019,7 +1019,7 @@ proc addImplicitGeneric(c: PContext; typeClass: PType, typId: PIdent; let owner = if typeClass.sym != nil: typeClass.sym else: getCurrOwner(c) - var s = newSym(skType, finalTypId, nextSymId c.idgen, owner, info) + var s = newSym(skType, finalTypId, c.idgen, owner, info) if sfExplain in owner.flags: s.flags.incl sfExplain if typId == nil: s.flags.incl(sfAnon) s.linkTo(typeClass) @@ -1633,7 +1633,7 @@ proc semTypeClass(c: PContext, n: PNode, prev: PType): PType = internalAssert c.config, dummyName.kind == nkIdent var dummyParam = newSym(if modifier == tyTypeDesc: skType else: skVar, - dummyName.ident, nextSymId c.idgen, owner, param.info) + dummyName.ident, c.idgen, owner, param.info) dummyParam.typ = dummyType incl dummyParam.flags, sfUsed addDecl(c, dummyParam) @@ -1766,7 +1766,7 @@ proc semTypeIdent(c: PContext, n: PNode): PSym = if result.typ.sym == nil: localError(c.config, n.info, errTypeExpected) return errorSym(c, n) - result = result.typ.sym.copySym(nextSymId c.idgen) + result = result.typ.sym.copySym(c.idgen) result.typ = exactReplica(result.typ) result.typ.flags.incl tfUnresolved diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index 2fe8c55e4..50dba515d 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -300,7 +300,7 @@ proc replaceTypeVarsS(cl: var TReplTypeVars, s: PSym): PSym = var g: G[string] ]# - result = copySym(s, nextSymId cl.c.idgen) + result = copySym(s, cl.c.idgen) incl(result.flags, sfFromGeneric) #idTablePut(cl.symMap, s, result) result.owner = s.owner diff --git a/compiler/sighashes.nim b/compiler/sighashes.nim index e46508cf2..4f945da5f 100644 --- a/compiler/sighashes.nim +++ b/compiler/sighashes.nim @@ -267,7 +267,7 @@ proc hashType*(t: PType; conf: ConfigRef; flags: set[ConsiderFlag] = {CoType}): db.exec(sql"INSERT OR IGNORE INTO sighashes(type, hash) VALUES (?, ?)", typeToString(t), $result) -proc hashProc*(s: PSym; conf: ConfigRef): SigHash = +proc hashProc(s: PSym; conf: ConfigRef): SigHash = var c: MD5Context md5Init c hashType c, s.typ, {CoProc}, conf diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 19fa0b599..6c119b71f 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -624,7 +624,7 @@ proc procTypeRel(c: var TCandidate, f, a: PType): TTypeRelation = if f.len != a.len: return result = isEqual # start with maximum; also correct for no # params at all - + if f.flags * {tfIterator} != a.flags * {tfIterator}: return isNone @@ -712,7 +712,7 @@ proc matchUserTypeClass*(m: var TCandidate; ff, a: PType): PType = if alreadyBound != nil: typ = alreadyBound template paramSym(kind): untyped = - newSym(kind, typeParamName, nextSymId(c.idgen), typeClass.sym, typeClass.sym.info, {}) + newSym(kind, typeParamName, c.idgen, typeClass.sym, typeClass.sym.info, {}) block addTypeParam: for prev in typeParams: diff --git a/compiler/sizealignoffsetimpl.nim b/compiler/sizealignoffsetimpl.nim index 987bcde99..e07d55fbc 100644 --- a/compiler/sizealignoffsetimpl.nim +++ b/compiler/sizealignoffsetimpl.nim @@ -12,7 +12,7 @@ proc align(address, alignment: BiggestInt): BiggestInt = result = (address + (alignment - 1)) and not (alignment - 1) -proc align(address, alignment: int): int = +proc align(address, alignment: int32): int32 = result = (address + (alignment - 1)) and not (alignment - 1) const @@ -30,24 +30,24 @@ proc raiseIllegalTypeRecursion() = type OffsetAccum = object - maxAlign: int - offset: int + maxAlign: int32 + offset: int32 -proc inc(arg: var OffsetAccum; value: int) = +proc inc(arg: var OffsetAccum; value: int32) = if unlikely(value == szIllegalRecursion): raiseIllegalTypeRecursion() if value == szUnknownSize or arg.offset == szUnknownSize: arg.offset = szUnknownSize else: arg.offset += value -proc alignmentMax(a, b: int): int = +proc alignmentMax(a, b: int32): int32 = if unlikely(a == szIllegalRecursion or b == szIllegalRecursion): raiseIllegalTypeRecursion() if a == szUnknownSize or b == szUnknownSize: szUnknownSize else: max(a, b) -proc align(arg: var OffsetAccum; value: int) = +proc align(arg: var OffsetAccum; value: int32) = if unlikely(value == szIllegalRecursion): raiseIllegalTypeRecursion() if value == szUnknownSize or arg.maxAlign == szUnknownSize or arg.offset == szUnknownSize: arg.maxAlign = szUnknownSize @@ -65,7 +65,7 @@ proc mergeBranch(arg: var OffsetAccum; value: OffsetAccum) = arg.offset = max(arg.offset, value.offset) arg.maxAlign = max(arg.maxAlign, value.maxAlign) -proc finish(arg: var OffsetAccum): int = +proc finish(arg: var OffsetAccum): int32 = if arg.maxAlign == szUnknownSize or arg.offset == szUnknownSize: result = szUnknownSize arg.offset = szUnknownSize @@ -122,20 +122,20 @@ proc computeObjectOffsetsFoldFunction(conf: ConfigRef; n: PNode; packed: bool; a of nkRecCase: assert(n[0].kind == nkSym) computeObjectOffsetsFoldFunction(conf, n[0], packed, accum) - var maxChildAlign: int = if accum.offset == szUnknownSize: szUnknownSize else: 1 + var maxChildAlign = if accum.offset == szUnknownSize: szUnknownSize.int32 else: 1'i32 if not packed: for i in 1..<n.len: let child = n[i] case child.kind of nkOfBranch, nkElse: # offset parameter cannot be known yet, it needs to know the alignment first - let align = int(computeSubObjectAlign(conf, n[i].lastSon)) + let align = int32(computeSubObjectAlign(conf, n[i].lastSon)) maxChildAlign = alignmentMax(maxChildAlign, align) else: internalError(conf, "computeObjectOffsetsFoldFunction(record case branch)") if maxChildAlign == szUnknownSize: setOffsetsToUnknown(n) - accum.offset = szUnknownSize + accum.offset = szUnknownSize accum.maxAlign = szUnknownSize else: # the union needs to be aligned first, before the offsets can be assigned @@ -150,15 +150,15 @@ proc computeObjectOffsetsFoldFunction(conf: ConfigRef; n: PNode; packed: bool; a for i, child in n.sons: computeObjectOffsetsFoldFunction(conf, child, packed, accum) of nkSym: - var size = szUnknownSize - var align = szUnknownSize + var size = szUnknownSize.int32 + var align = szUnknownSize.int32 if n.sym.bitsize == 0: # 0 represents bitsize not set computeSizeAlign(conf, n.sym.typ) - size = n.sym.typ.size.int - align = if packed: 1 else: n.sym.typ.align.int + size = n.sym.typ.size.int32 + align = if packed: 1 else: n.sym.typ.align.int32 accum.align(align) if n.sym.alignment > 0: - accum.align(n.sym.alignment) + accum.align(n.sym.alignment.int32) n.sym.offset = accum.offset accum.inc(size) else: @@ -180,15 +180,15 @@ proc computeUnionObjectOffsetsFoldFunction(conf: ConfigRef; n: PNode; packed: bo discard finish(branchAccum) accum.mergeBranch(branchAccum) of nkSym: - var size = szUnknownSize - var align = szUnknownSize + var size = szUnknownSize.int32 + var align = szUnknownSize.int32 if n.sym.bitsize == 0: # 0 represents bitsize not set computeSizeAlign(conf, n.sym.typ) - size = n.sym.typ.size.int - align = if packed: 1 else: n.sym.typ.align.int + size = n.sym.typ.size.int32 + align = if packed: 1 else: n.sym.typ.align.int32 accum.align(align) if n.sym.alignment > 0: - accum.align(n.sym.alignment) + accum.align(n.sym.alignment.int32) n.sym.offset = accum.offset accum.inc(size) else: @@ -339,7 +339,7 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) = if typ.n != nil: # is named tuple (has field symbols)? let sym = typ.n[i].sym sym.offset = accum.offset - accum.inc(int(child.size)) + accum.inc(int32(child.size)) typ.paddingAtEnd = int16(accum.finish()) typ.size = if accum.offset == 0: 1 else: accum.offset typ.align = int16(accum.maxAlign) @@ -359,19 +359,19 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) = computeSizeAlign(conf, st) if conf.backend == backendCpp: OffsetAccum( - offset: int(st.size) - int(st.paddingAtEnd), + offset: int32(st.size) - int32(st.paddingAtEnd), maxAlign: st.align ) else: OffsetAccum( - offset: int(st.size), + offset: int32(st.size), maxAlign: st.align ) elif isObjectWithTypeFieldPredicate(typ): # this branch is taken for RootObj OffsetAccum( - offset: conf.target.intSize, - maxAlign: conf.target.intSize + offset: conf.target.intSize.int32, + maxAlign: conf.target.intSize.int32 ) else: OffsetAccum(maxAlign: 1) diff --git a/compiler/spawn.nim b/compiler/spawn.nim index 0931407d4..add36759d 100644 --- a/compiler/spawn.nim +++ b/compiler/spawn.nim @@ -55,7 +55,7 @@ proc typeNeedsNoDeepCopy(t: PType): bool = proc addLocalVar(g: ModuleGraph; varSection, varInit: PNode; idgen: IdGenerator; owner: PSym; typ: PType; v: PNode; useShallowCopy=false): PSym = - result = newSym(skTemp, getIdent(g.cache, genPrefix), nextSymId idgen, owner, varSection.info, + result = newSym(skTemp, getIdent(g.cache, genPrefix), idgen, owner, varSection.info, owner.options) result.typ = typ incl(result.flags, sfFromGeneric) @@ -219,7 +219,7 @@ proc setupArgsForConcurrency(g: ModuleGraph; n: PNode; objType: PType; # localError(n[i].info, "'spawn'ed function cannot refer to 'ref'/closure") let fieldname = if i < formals.len: formals[i].sym.name else: tmpName - var field = newSym(skField, fieldname, nextSymId idgen, objType.owner, n.info, g.config.options) + var field = newSym(skField, fieldname, idgen, objType.owner, n.info, g.config.options) field.typ = argType discard objType.addField(field, g.cache, idgen) result.add newFastAsgnStmt(newDotExpr(scratchObj, field), n[i]) @@ -250,7 +250,7 @@ proc setupArgsForParallelism(g: ModuleGraph; n: PNode; objType: PType; # localError(n.info, "'spawn'ed function cannot refer to 'ref'/closure") let fieldname = if i < formals.len: formals[i].sym.name else: tmpName - var field = newSym(skField, fieldname, nextSymId idgen, objType.owner, n.info, g.config.options) + var field = newSym(skField, fieldname, idgen, objType.owner, n.info, g.config.options) if argType.kind in {tyVarargs, tyOpenArray}: # important special case: we always create a zero-copy slice: @@ -258,7 +258,7 @@ proc setupArgsForParallelism(g: ModuleGraph; n: PNode; objType: PType; slice.typ = n.typ slice[0] = newSymNode(createMagic(g, idgen, "slice", mSlice)) slice[0].typ = getSysType(g, n.info, tyInt) # fake type - var fieldB = newSym(skField, tmpName, nextSymId idgen, objType.owner, n.info, g.config.options) + var fieldB = newSym(skField, tmpName, idgen, objType.owner, n.info, g.config.options) fieldB.typ = getSysType(g, n.info, tyInt) discard objType.addField(fieldB, g.cache, idgen) @@ -268,7 +268,7 @@ proc setupArgsForParallelism(g: ModuleGraph; n: PNode; objType: PType; discard objType.addField(field, g.cache, idgen) result.add newFastAsgnStmt(newDotExpr(scratchObj, field), a) - var fieldA = newSym(skField, tmpName, nextSymId idgen, objType.owner, n.info, g.config.options) + var fieldA = newSym(skField, tmpName, idgen, objType.owner, n.info, g.config.options) fieldA.typ = getSysType(g, n.info, tyInt) discard objType.addField(fieldA, g.cache, idgen) result.add newFastAsgnStmt(newDotExpr(scratchObj, fieldA), n[2]) @@ -343,9 +343,9 @@ proc wrapProcForSpawn*(g: ModuleGraph; idgen: IdGenerator; owner: PSym; spawnExp var fn = n[0] let name = (if fn.kind == nkSym: fn.sym.name.s else: genPrefix) & "Wrapper" - wrapperProc = newSym(skProc, getIdent(g.cache, name), nextSymId idgen, owner, fn.info, g.config.options) - threadParam = newSym(skParam, getIdent(g.cache, "thread"), nextSymId idgen, wrapperProc, n.info, g.config.options) - argsParam = newSym(skParam, getIdent(g.cache, "args"), nextSymId idgen, wrapperProc, n.info, g.config.options) + wrapperProc = newSym(skProc, getIdent(g.cache, name), idgen, owner, fn.info, g.config.options) + threadParam = newSym(skParam, getIdent(g.cache, "thread"), idgen, wrapperProc, n.info, g.config.options) + argsParam = newSym(skParam, getIdent(g.cache, "args"), idgen, wrapperProc, n.info, g.config.options) wrapperProc.flags.incl sfInjectDestructors block: @@ -358,7 +358,7 @@ proc wrapProcForSpawn*(g: ModuleGraph; idgen: IdGenerator; owner: PSym; spawnExp incl(objType.flags, tfFinal) let castExpr = createCastExpr(argsParam, objType, idgen) - var scratchObj = newSym(skVar, getIdent(g.cache, "scratch"), nextSymId idgen, owner, n.info, g.config.options) + var scratchObj = newSym(skVar, getIdent(g.cache, "scratch"), idgen, owner, n.info, g.config.options) block: scratchObj.typ = objType incl(scratchObj.flags, sfFromGeneric) @@ -375,7 +375,7 @@ proc wrapProcForSpawn*(g: ModuleGraph; idgen: IdGenerator; owner: PSym; spawnExp skFunc, skMethod, skConverter}): # for indirect calls we pass the function pointer in the scratchObj var argType = n[0].typ.skipTypes(abstractInst) - var field = newSym(skField, getIdent(g.cache, "fn"), nextSymId idgen, owner, n.info, g.config.options) + var field = newSym(skField, getIdent(g.cache, "fn"), idgen, owner, n.info, g.config.options) field.typ = argType discard objType.addField(field, g.cache, idgen) result.add newFastAsgnStmt(newDotExpr(scratchObj, field), n[0]) @@ -397,7 +397,7 @@ proc wrapProcForSpawn*(g: ModuleGraph; idgen: IdGenerator; owner: PSym; spawnExp if barrier != nil: let typ = newType(tyPtr, nextTypeId idgen, owner) typ.rawAddSon(magicsys.getCompilerProc(g, "Barrier").typ) - var field = newSym(skField, getIdent(g.cache, "barrier"), nextSymId idgen, owner, n.info, g.config.options) + var field = newSym(skField, getIdent(g.cache, "barrier"), idgen, owner, n.info, g.config.options) field.typ = typ discard objType.addField(field, g.cache, idgen) result.add newFastAsgnStmt(newDotExpr(scratchObj, field), barrier) @@ -405,7 +405,7 @@ proc wrapProcForSpawn*(g: ModuleGraph; idgen: IdGenerator; owner: PSym; spawnExp var fvField, fvAsExpr: PNode = nil if spawnKind == srFlowVar: - var field = newSym(skField, getIdent(g.cache, "fv"), nextSymId idgen, owner, n.info, g.config.options) + var field = newSym(skField, getIdent(g.cache, "fv"), idgen, owner, n.info, g.config.options) field.typ = retType discard objType.addField(field, g.cache, idgen) fvField = newDotExpr(scratchObj, field) @@ -416,7 +416,7 @@ proc wrapProcForSpawn*(g: ModuleGraph; idgen: IdGenerator; owner: PSym; spawnExp result.add callCodegenProc(g, "nimFlowVarCreateSemaphore", fvField.info, fvField) elif spawnKind == srByVar: - var field = newSym(skField, getIdent(g.cache, "fv"), nextSymId idgen, owner, n.info, g.config.options) + var field = newSym(skField, getIdent(g.cache, "fv"), idgen, owner, n.info, g.config.options) field.typ = newType(tyPtr, nextTypeId idgen, objType.owner) field.typ.rawAddSon(retType) discard objType.addField(field, g.cache, idgen) diff --git a/compiler/transf.nim b/compiler/transf.nim index 752d031e1..0176a1087 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -91,7 +91,7 @@ proc getCurrOwner(c: PTransf): PSym = else: result = c.module proc newTemp(c: PTransf, typ: PType, info: TLineInfo): PNode = - let r = newSym(skTemp, getIdent(c.graph.cache, genPrefix), nextSymId(c.idgen), getCurrOwner(c), info) + let r = newSym(skTemp, getIdent(c.graph.cache, genPrefix), c.idgen, getCurrOwner(c), info) r.typ = typ #skipTypes(typ, {tyGenericInst, tyAlias, tySink}) incl(r.flags, sfFromGeneric) let owner = getCurrOwner(c) @@ -177,7 +177,7 @@ proc freshVar(c: PTransf; v: PSym): PNode = if owner.isIterator and not c.tooEarly: result = freshVarForClosureIter(c.graph, v, c.idgen, owner) else: - var newVar = copySym(v, nextSymId(c.idgen)) + var newVar = copySym(v, c.idgen) incl(newVar.flags, sfFromGeneric) newVar.owner = owner result = newSymNode(newVar) @@ -249,8 +249,7 @@ proc hasContinue(n: PNode): bool = if hasContinue(n[i]): return true proc newLabel(c: PTransf, n: PNode): PSym = - result = newSym(skLabel, nil, nextSymId(c.idgen), getCurrOwner(c), n.info) - result.name = getIdent(c.graph.cache, genPrefix) + result = newSym(skLabel, getIdent(c.graph.cache, genPrefix), c.idgen, getCurrOwner(c), n.info) proc transformBlock(c: PTransf, n: PNode): PNode = var labl: PSym diff --git a/compiler/vm.nim b/compiler/vm.nim index e00f0f02e..dbb02cffa 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -2123,7 +2123,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = else: regs[rc].node.strVal if k < 0 or k > ord(high(TSymKind)): internalError(c.config, c.debug[pc], "request to create symbol of invalid kind") - var sym = newSym(k.TSymKind, getIdent(c.cache, name), nextSymId c.idgen, c.module.owner, c.debug[pc]) + var sym = newSym(k.TSymKind, getIdent(c.cache, name), c.idgen, c.module.owner, c.debug[pc]) incl(sym.flags, sfGenSym) regs[ra].node = newSymNode(sym) regs[ra].node.flags.incl nfIsRef diff --git a/compiler/vmdeps.nim b/compiler/vmdeps.nim index 118a3031e..75692fcc0 100644 --- a/compiler/vmdeps.nim +++ b/compiler/vmdeps.nim @@ -29,7 +29,7 @@ proc opSlurp*(file: string, info: TLineInfo, module: PSym; conf: ConfigRef): str proc atomicTypeX(cache: IdentCache; name: string; m: TMagic; t: PType; info: TLineInfo; idgen: IdGenerator): PNode = - let sym = newSym(skType, getIdent(cache, name), nextSymId(idgen), t.owner, info) + let sym = newSym(skType, getIdent(cache, name), idgen, t.owner, info) sym.magic = m sym.typ = t result = newSymNode(sym) diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index 5183f2def..48792790d 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -2044,7 +2044,7 @@ proc procIsCallback(c: PCtx; s: PSym): bool = if c.callbackIndex.contains(key): let index = c.callbackIndex[key] doAssert s.offset == -1 - s.offset = -2 - index + s.offset = -2'i32 - index.int32 result = true else: result = false @@ -2344,7 +2344,7 @@ proc genProc(c: PCtx; s: PSym): int = c.patch(procStart) c.gABC(body, opcEof, eofInstr.regA) c.optimizeJumps(result) - s.offset = c.prc.regInfo.len + s.offset = c.prc.regInfo.len.int32 #if s.name.s == "main" or s.name.s == "[]": # echo renderTree(body) # c.echoCode(result) diff --git a/compiler/vmmarshal.nim b/compiler/vmmarshal.nim index e44bc0bea..b48197aef 100644 --- a/compiler/vmmarshal.nim +++ b/compiler/vmmarshal.nim @@ -224,7 +224,7 @@ proc loadAny(p: var JsonParser, t: PType, if pos >= result.len: setLen(result.sons, pos + 1) let fieldNode = newNode(nkExprColonExpr) - fieldNode.add newSymNode(newSym(skField, ident, nextSymId(idgen), nil, unknownLineInfo)) + fieldNode.add newSymNode(newSym(skField, ident, idgen, nil, unknownLineInfo)) fieldNode.add loadAny(p, field.typ, tab, cache, conf, idgen) result[pos] = fieldNode if p.kind == jsonObjectEnd: next(p) diff --git a/tests/ccgbugs/tnoalias.nim b/tests/ccgbugs/tnoalias.nim index 96c3d390b..2c3c2f0f4 100644 --- a/tests/ccgbugs/tnoalias.nim +++ b/tests/ccgbugs/tnoalias.nim @@ -1,5 +1,5 @@ discard """ - ccodecheck: "\\i@'NI* NIM_NOALIAS field;' @'NIM_CHAR* NIM_NOALIAS x__0qEngDE9aYoYsF8tWnyPacw,' @'void* NIM_NOALIAS q'" + ccodecheck: "\\i@'NI* NIM_NOALIAS field;' @'NIM_CHAR* NIM_NOALIAS x_p0,' @'void* NIM_NOALIAS q'" """ type |