From 13d30b9341c755fa4b9b6d33f25e0692ada923bc Mon Sep 17 00:00:00 2001 From: araq Date: Tue, 11 Nov 2025 10:51:02 +0100 Subject: [PATCH] progress --- compiler/ast.nim | 36 +++++++++++- compiler/ccgexprs.nim | 5 +- compiler/ccgstmts.nim | 22 +++++--- compiler/ccgtypes.nim | 62 ++++++++++++--------- compiler/cgen.nim | 67 +++++++++++++--------- compiler/cgmeth.nim | 6 +- compiler/closureiters.nim | 2 +- compiler/enumtostr.nim | 6 +- compiler/importer.nim | 3 +- compiler/injectdestructors.nim | 4 +- compiler/jsgen.nim | 36 ++++++++---- compiler/lambdalifting.nim | 12 ++-- compiler/liftdestructors.nim | 34 +++++++----- compiler/main.nim | 2 +- compiler/modules.nim | 4 +- compiler/pipelines.nim | 8 +-- compiler/pragmas.nim | 83 ++++++++++++++-------------- compiler/scriptconfig.nim | 2 +- compiler/sem.nim | 2 +- compiler/semexprs.nim | 13 +++-- compiler/semgnrc.nim | 10 ++-- compiler/seminst.nim | 14 ++--- compiler/semmagic.nim | 6 +- compiler/semparallel.nim | 2 +- compiler/sempass2.nim | 10 ++-- compiler/semstmts.nim | 68 +++++++++++------------ compiler/semtempl.nim | 33 ++++++----- compiler/semtypes.nim | 19 ++++--- compiler/sighashes.nim | 4 +- compiler/sinkparameter_inference.nim | 3 +- compiler/spawn.nim | 6 +- compiler/transf.nim | 6 +- compiler/vm.nim | 2 +- compiler/vmgen.nim | 2 +- compiler/vmprofiler.nim | 2 +- 35 files changed, 344 insertions(+), 252 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index 99478d51c6..14f437c763 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -846,6 +846,10 @@ proc loadSym*(s: PSym) {.inline.} = ## This is a forward declaration - implementation should be provided elsewhere. discard +proc ensureMutable*(s: PSym) {.inline.} = + assert s.state != Sealed + if s.state == Partial: loadSym(s) + proc owner*(s: PSym|PType): PSym {.inline.} = when s is PSym: if s.state == Partial: loadSym(s) @@ -855,6 +859,7 @@ proc owner*(s: PSym|PType): PSym {.inline.} = proc setOwner*(s: PSym|PType, owner: PSym) {.inline.} = when s is PSym: + assert s.state != Sealed if s.state == Partial: loadSym(s) s.ownerFieldImpl = owner else: @@ -868,6 +873,7 @@ proc kind*(s: PSym): TSymKind {.inline.} = result = s.kind proc `kind=`*(s: PSym, val: TSymKind) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.kind = val @@ -876,6 +882,7 @@ proc gcUnsafetyReason*(s: PSym): PSym {.inline.} = result = s.gcUnsafetyReasonImpl proc `gcUnsafetyReason=`*(s: PSym, val: PSym) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.gcUnsafetyReasonImpl = val @@ -884,6 +891,7 @@ proc transformedBody*(s: PSym): PNode {.inline.} = result = s.transformedBodyImpl proc `transformedBody=`*(s: PSym, val: PNode) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.transformedBodyImpl = val @@ -892,6 +900,7 @@ proc guard*(s: PSym): PSym {.inline.} = result = s.guardImpl proc `guard=`*(s: PSym, val: PSym) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.guardImpl = val @@ -900,6 +909,7 @@ proc bitsize*(s: PSym): int {.inline.} = result = s.bitsizeImpl proc `bitsize=`*(s: PSym, val: int) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.bitsizeImpl = val @@ -908,6 +918,7 @@ proc alignment*(s: PSym): int {.inline.} = result = s.alignmentImpl proc `alignment=`*(s: PSym, val: int) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.alignmentImpl = val @@ -916,6 +927,7 @@ proc magic*(s: PSym): TMagic {.inline.} = result = s.magicImpl proc `magic=`*(s: PSym, val: TMagic) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.magicImpl = val @@ -924,6 +936,7 @@ proc typ*(s: PSym): PType {.inline.} = result = s.typImpl proc `typ=`*(s: PSym, val: PType) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.typImpl = val @@ -932,6 +945,7 @@ proc info*(s: PSym): TLineInfo {.inline.} = result = s.infoImpl proc `info=`*(s: PSym, val: TLineInfo) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.infoImpl = val @@ -941,6 +955,7 @@ when defined(nimsuggest): result = s.endInfoImpl proc `endInfo=`*(s: PSym, val: TLineInfo) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.endInfoImpl = val @@ -949,6 +964,7 @@ when defined(nimsuggest): result = s.hasUserSpecifiedTypeImpl proc `hasUserSpecifiedType=`*(s: PSym, val: bool) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.hasUserSpecifiedTypeImpl = val @@ -957,6 +973,7 @@ proc flags*(s: PSym): TSymFlags {.inline.} = result = s.flagsImpl proc `flags=`*(s: PSym, val: TSymFlags) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.flagsImpl = val @@ -965,6 +982,7 @@ proc ast*(s: PSym): PNode {.inline.} = result = s.astImpl proc `ast=`*(s: PSym, val: PNode) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.astImpl = val @@ -973,6 +991,7 @@ proc options*(s: PSym): TOptions {.inline.} = result = s.optionsImpl proc `options=`*(s: PSym, val: TOptions) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.optionsImpl = val @@ -981,6 +1000,7 @@ proc position*(s: PSym): int {.inline.} = result = s.positionImpl proc `position=`*(s: PSym, val: int) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.positionImpl = val @@ -989,6 +1009,7 @@ proc offset*(s: PSym): int32 {.inline.} = result = s.offsetImpl proc `offset=`*(s: PSym, val: int32) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.offsetImpl = val @@ -997,6 +1018,7 @@ proc loc*(s: PSym): TLoc {.inline.} = result = s.locImpl proc `loc=`*(s: PSym, val: TLoc) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.locImpl = val @@ -1005,6 +1027,7 @@ proc annex*(s: PSym): PLib {.inline.} = result = s.annexImpl proc `annex=`*(s: PSym, val: PLib) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.annexImpl = val @@ -1014,6 +1037,7 @@ when hasFFI: result = s.cnameImpl proc `cname=`*(s: PSym, val: string) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.cnameImpl = val @@ -1022,6 +1046,7 @@ proc constraint*(s: PSym): PNode {.inline.} = result = s.constraintImpl proc `constraint=`*(s: PSym, val: PNode) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.constraintImpl = val @@ -1030,26 +1055,32 @@ proc instantiatedFrom*(s: PSym): PSym {.inline.} = result = s.instantiatedFromImpl proc `instantiatedFrom=`*(s: PSym, val: PSym) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.instantiatedFromImpl = val proc setSnippet*(s: PSym; val: sink string) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.locImpl.snippet = val proc incl*(s: PSym; flag: TSymFlag) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.flagsImpl.incl(flag) proc incl*(s: PSym; flags: set[TSymFlag]) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) - s.flagsImpl.incl(flag) + s.flagsImpl.incl(flags) proc incl*(s: PSym; flag: TLocFlag) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.locImpl.flags.incl(flag) proc excl*(s: PSym; flag: TSymFlag) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.flagsImpl.excl(flag) @@ -1059,6 +1090,7 @@ when defined(nimsuggest): result = s.allUsagesImpl proc `allUsages=`*(s: PSym, val: seq[TLineInfo]) {.inline.} = + assert s.state != Sealed if s.state == Partial: loadSym(s) s.allUsagesImpl = val @@ -2290,7 +2322,7 @@ template incompleteType*(t: PType): bool = t.sym != nil and {sfForward, sfNoForward} * t.sym.flags == {sfForward} template typeCompleted*(s: PSym) = - incl s.flags, sfNoForward + incl s, sfNoForward template detailedInfo*(sym: PSym): string = sym.name.s diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index d3e215ea56..bb73a9d96f 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -3359,8 +3359,9 @@ proc genConstSetup(p: BProc; sym: PSym): bool = useHeader(m, sym) if sym.loc.k == locNone: fillBackendName(p.module, sym) - fillLoc(sym.loc, locData, sym.astdef, OnStatic) - if m.hcrOn: incl(sym.loc.flags, lfIndirect) + ensureMutable sym + fillLoc(sym.locImpl, locData, sym.astdef, OnStatic) + if m.hcrOn: incl(sym, lfIndirect) result = lfNoDecl notin sym.loc.flags proc genConstHeader(m, q: BModule; p: BProc, sym: PSym) = diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index 3aedca9a96..15fb55c346 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -126,9 +126,10 @@ proc genVarTuple(p: BProc, n: PNode) = let vn = n[i] let v = vn.sym if sfCompileTime in v.flags: continue + ensureMutable v if sfGlobal in v.flags: assignGlobalVar(p, vn, "") - genObjectInit(p, cpsInit, v.typ, v.loc, constructObj) + genObjectInit(p, cpsInit, v.typ, v.locImpl, constructObj) registerTraverseProc(p, v) else: assignLocalVar(p, vn) @@ -142,9 +143,9 @@ proc genVarTuple(p: BProc, n: PNode) = if t.n[i].kind != nkSym: internalError(p.config, n.info, "genVarTuple") mangleRecFieldName(p.module, t.n[i].sym) field.snippet = dotField(rtup, fieldName) - putLocIntoDest(p, v.loc, field) + putLocIntoDest(p, v.locImpl, field) if forHcr or isGlobalInBlock: - hcrGlobals.add((loc: v.loc, tp: CNil)) + hcrGlobals.add((loc: v.locImpl, tp: CNil)) if forHcr: # end the block where the tuple gets initialized @@ -460,7 +461,8 @@ proc genSingleVar(p: BProc, v: PSym; vn, value: PNode) = if value.kind != nkEmpty and valueAsRope.len == 0: genLineDir(targetProc, vn) if not isCppCtorCall: - loadInto(targetProc, vn, value, v.loc) + ensureMutable v + loadInto(targetProc, vn, value, v.locImpl) if forHcr: endBlockWith(targetProc): finishBranch(p.s(cpsStmts), hcrInit) @@ -736,7 +738,8 @@ proc genBlock(p: BProc, n: PNode, d: var TLoc) = # named block? assert(n[0].kind == nkSym) var sym = n[0].sym - sym.loc.k = locOther + ensureMutable sym + sym.locImpl.k = locOther sym.position = p.breakIdx+1 expr(p, n[1], d) endSimpleBlock(p, scope) @@ -1250,7 +1253,8 @@ proc genTryCpp(p: BProc, t: PNode, d: var TLoc) = initElifBranch(p.s(cpsStmts), ifStmt, orExpr) if exvar != nil: fillLocalName(p, exvar.sym) - fillLoc(exvar.sym.loc, locTemp, exvar, OnStack) + ensureMutable exvar.sym + fillLoc(exvar.sym.locImpl, locTemp, exvar, OnStack) linefmt(p, cpsStmts, "$1 $2 = T$3_;$n", [getTypeDesc(p.module, exvar.sym.typ), rdLoc(exvar.sym.loc), rope(etmp+1)]) # we handled the error: @@ -1298,7 +1302,8 @@ proc genTryCpp(p: BProc, t: PNode, d: var TLoc) = if isImportedException(typeNode.typ, p.config): let exvar = t[i][j][2] # ex1 in `except ExceptType as ex1:` fillLocalName(p, exvar.sym) - fillLoc(exvar.sym.loc, locTemp, exvar, OnStack) + ensureMutable exvar.sym + fillLoc(exvar.sym.locImpl, locTemp, exvar, OnStack) startBlockWith(p): lineCg(p, cpsStmts, "catch ($1& $2) {$n", [getTypeDesc(p.module, typeNode.typ), rdLoc(exvar.sym.loc)]) genExceptBranchBody(t[i][^1]) # exception handler body will duplicated for every type @@ -1389,7 +1394,8 @@ proc genTryCppOld(p: BProc, t: PNode, d: var TLoc) = if t[i][j].isInfixAs(): let exvar = t[i][j][2] # ex1 in `except ExceptType as ex1:` fillLocalName(p, exvar.sym) - fillLoc(exvar.sym.loc, locTemp, exvar, OnUnknown) + ensureMutable exvar.sym + fillLoc(exvar.sym.locImpl, locTemp, exvar, OnUnknown) startBlockWith(p): lineCg(p, cpsStmts, "catch ($1& $2) {$n", [getTypeDesc(p.module, t[i][j][1].typ), rdLoc(exvar.sym.loc)]) else: diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index cdfa46cdd2..bee0d656a5 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -84,7 +84,8 @@ proc fillBackendName(m: BModule; s: PSym) = if m.hcrOn: result.add '_' result.add(idOrSig(s, m.module.name.s.mangle, m.sigConflicts, m.config)) - s.loc.snippet = result + ensureMutable s + s.locImpl.snippet = result proc fillParamName(m: BModule; s: PSym) = if s.loc.snippet == "": @@ -107,7 +108,8 @@ proc fillParamName(m: BModule; s: PSym) = # and a function called in main or proxy uses `socket` as a parameter name. # That would lead to either needing to reload `proxy` or to overwrite the # executable file for the main module, which is running (or both!) -> error. - s.loc.snippet = res.rope + ensureMutable s + s.locImpl.snippet = res.rope proc fillLocalName(p: BProc; s: PSym) = assert s.kind in skLocalVars+{skTemp} @@ -122,7 +124,8 @@ proc fillLocalName(p: BProc; s: PSym) = elif s.kind != skResult: result.add "_" & rope(counter+1) p.sigConflicts.inc(key) - s.loc.snippet = result + ensureMutable s + s.locImpl.snippet = result proc scopeMangledParam(p: BProc; param: PSym) = ## parameter generation only takes BModule, not a BProc, so we have to @@ -300,12 +303,13 @@ proc addAbiCheck(m: BModule; t: PType, name: Rope) = proc fillResult(conf: ConfigRef; param: PNode, proctype: PType) = - fillLoc(param.sym.loc, locParam, param, "Result", + ensureMutable param.sym + fillLoc(param.sym.locImpl, locParam, param, "Result", OnStack) let t = param.sym.typ if mapReturnType(conf, t) != ctArray and isInvalidReturnType(conf, proctype): - incl(param.sym.loc.flags, lfIndirect) - param.sym.loc.storage = OnUnknown + incl(param.sym.locImpl.flags, lfIndirect) + param.sym.locImpl.storage = OnUnknown proc typeNameOrLiteral(m: BModule; t: PType, literal: string): Rope = if t.sym != nil and sfImportc in t.sym.flags and t.sym.magic == mNone: @@ -524,14 +528,15 @@ proc genMemberProcParams(m: BModule; prc: PSym, superCall, rettype, name, params var types, names, args: seq[string] = @[] if not isCtor: var this = t.n[1].sym + ensureMutable this fillParamName(m, this) - fillLoc(this.loc, locParam, t.n[1], + fillLoc(this.locImpl, locParam, t.n[1], this.paramStorageLoc) if this.typ.kind == tyPtr: - this.loc.snippet = "this" + this.locImpl.snippet = "this" else: - this.loc.snippet = "(*this)" - names.add this.loc.snippet + this.locImpl.snippet = "(*this)" + names.add this.locImpl.snippet types.add getTypeDescWeak(m, this.typ, check, dkParam) let firstParam = if isCtor: 1 else: 2 @@ -545,13 +550,14 @@ proc genMemberProcParams(m: BModule; prc: PSym, superCall, rettype, name, params else: descKind = dkRefParam var typ, name: string + ensureMutable param fillParamName(m, param) - fillLoc(param.loc, locParam, t.n[i], + fillLoc(param.locImpl, locParam, t.n[i], param.paramStorageLoc) if ccgIntroducedPtr(m.config, param, t.returnType) and descKind == dkParam: typ = getTypeDescWeak(m, param.typ, check, descKind) & "*" - incl(param.loc.flags, lfIndirect) - param.loc.storage = OnUnknown + incl(param.locImpl.flags, lfIndirect) + param.locImpl.storage = OnUnknown elif weakDep: typ = getTypeDescWeak(m, param.typ, check, descKind) else: @@ -559,7 +565,7 @@ proc genMemberProcParams(m: BModule; prc: PSym, superCall, rettype, name, params if sfNoalias in param.flags: typ.add("NIM_NOALIAS ") - name = param.loc.snippet + name = param.locImpl.snippet types.add typ names.add name if sfCodegenDecl notin param.flags: @@ -601,14 +607,15 @@ proc genProcParams(m: BModule; t: PType, rettype: var Rope, params: var Builder, else: descKind = dkRefParam if isCompileTimeOnly(param.typ): continue + ensureMutable param fillParamName(m, param) - fillLoc(param.loc, locParam, t.n[i], + fillLoc(param.locImpl, locParam, t.n[i], param.paramStorageLoc) var typ: Rope if ccgIntroducedPtr(m.config, param, t.returnType) and descKind == dkParam: typ = ptrType(getTypeDescWeak(m, param.typ, check, descKind)) - incl(param.loc.flags, lfIndirect) - param.loc.storage = OnUnknown + incl(param.locImpl.flags, lfIndirect) + param.locImpl.storage = OnUnknown elif weakDep: typ = (getTypeDescWeak(m, param.typ, check, descKind)) else: @@ -620,9 +627,9 @@ proc genProcParams(m: BModule; t: PType, rettype: var Rope, params: var Builder, var j = 0 while arr.kind in {tyOpenArray, tyVarargs}: # this fixes the 'sort' bug: - if param.typ.kind in {tyVar, tyLent}: param.loc.storage = OnUnknown + if param.typ.kind in {tyVar, tyLent}: param.locImpl.storage = OnUnknown # need to pass hidden parameter: - params.addParam(paramBuilder, name = param.loc.snippet & "Len_" & $j, typ = NimInt) + params.addParam(paramBuilder, name = param.locImpl.snippet & "Len_" & $j, typ = NimInt) inc(j) arr = arr[0].skipTypes({tySink}) if t.returnType != nil and isInvalidReturnType(m.config, t): @@ -707,7 +714,8 @@ proc genRecordFieldsAux(m: BModule; n: PNode, if field.typ.kind == tyVoid: return #assert(field.ast == nil) let sname = mangleRecFieldName(m, field) - fillLoc(field.loc, locField, n, unionPrefix & sname, OnUnknown) + ensureMutable field + fillLoc(field.locImpl, locField, n, unionPrefix & sname, OnUnknown) # for importcpp'ed objects, we only need to set field.loc, but don't # have to recurse via 'getTypeDescAux'. And not doing so prevents problems # with heavily templatized C++ code: @@ -1155,7 +1163,8 @@ proc genMemberProcHeader(m: BModule; prc: PSym; result: var Builder; asPtr: bool let isCtor = sfConstructor in prc.flags var check = initIntSet() fillBackendName(m, prc) - fillLoc(prc.loc, locProc, prc.ast[namePos], OnUnknown) + ensureMutable prc + fillLoc(prc.locImpl, locProc, prc.ast[namePos], OnUnknown) var memberOp = "#." #only virtual var typ: PType if isCtor: @@ -1187,7 +1196,7 @@ proc genMemberProcHeader(m: BModule; prc: PSym; result: var Builder; asPtr: bool superCall = "" else: if not isCtor: - prc.loc.snippet = "$1$2(@)" % [memberOp, name] + prc.locImpl.snippet = "$1$2(@)" % [memberOp, name] elif superCall != "": superCall = " : " & superCall @@ -1202,14 +1211,15 @@ proc genProcHeader(m: BModule; prc: PSym; result: var Builder; visibility: var D # using static is needed for inline procs var check = initIntSet() fillBackendName(m, prc) - fillLoc(prc.loc, locProc, prc.ast[namePos], OnUnknown) + ensureMutable prc + fillLoc(prc.locImpl, locProc, prc.ast[namePos], OnUnknown) var rettype: Snippet = "" var desc = newBuilder("") genProcParams(m, prc.typ, rettype, desc, check, true, false) let params = extract(desc) # handle the 2 options for hotcodereloading codegen - function pointer # (instead of forward declaration) or header for function body with "_actual" postfix - var name = prc.loc.snippet + var name = prc.locImpl.snippet if not asPtr and isReloadable(m, prc): name.add("_actual") # careful here! don't access ``prc.ast`` as that could reload large parts of @@ -1645,8 +1655,8 @@ proc generateRttiDestructor(g: ModuleGraph; typ: PType; owner: PSym; kind: TType n[bodyPos] = body result.ast = n - incl result.flags, sfFromGeneric - incl result.flags, sfGeneratedOp + incl result.flagsImpl, sfFromGeneric + incl result.flagsImpl, sfGeneratedOp proc genHook(m: BModule; t: PType; info: TLineInfo; op: TTypeAttachedOp; result: var Builder) = let theProc = getAttachedOp(m.g.graph, t, op) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 508e003a55..518613c1bd 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -600,7 +600,8 @@ proc initLocalVar(p: BProc, v: PSym, immediateAsgn: bool) = # ``var v = X()`` gets transformed into ``X(&v)``. # Nowadays the logic in ccgcalls deals with this case however. if not immediateAsgn: - constructLoc(p, v.loc) + ensureMutable v + constructLoc(p, v.locImpl) proc getTemp(p: BProc, t: PType, needsInit=false): TLoc = inc(p.labels) @@ -646,8 +647,9 @@ proc localVarDecl(res: var Builder, p: BProc; n: PNode, let s = n.sym if s.loc.k == locNone: fillLocalName(p, s) - fillLoc(s.loc, locLocalVar, n, OnStack) - if s.kind == skLet: incl(s.loc.flags, lfNoDeepCopy) + ensureMutable s + fillLoc(s.locImpl, locLocalVar, n, OnStack) + if s.kind == skLet: incl(s, lfNoDeepCopy) genCLineDir(res, p, n.info, p.config) @@ -707,15 +709,17 @@ proc assignGlobalVar(p: BProc, n: PNode; value: Rope) = let s = n.sym if s.loc.k == locNone: fillBackendName(p.module, s) - fillLoc(s.loc, locGlobalVar, n, OnHeap) - if treatGlobalDifferentlyForHCR(p.module, s): incl(s.loc.flags, lfIndirect) + ensureMutable s + fillLoc(s.locImpl, locGlobalVar, n, OnHeap) + if treatGlobalDifferentlyForHCR(p.module, s): incl(s, lfIndirect) if lfDynamicLib in s.loc.flags: var q = findPendingModule(p.module, s) if q != nil and not containsOrIncl(q.declaredThings, s.id): varInDynamicLib(q, s) else: - s.loc.snippet = mangleDynLibProc(s) + ensureMutable s + s.locImpl.snippet = mangleDynLibProc(s) if value != "": internalError(p.config, n.info, ".dynlib variables cannot have a value") return @@ -755,12 +759,14 @@ proc assignGlobalVar(p: BProc, n: PNode; value: Rope) = genGlobalVarDecl(p.module.s[cfsVars], p, n, td, initializer = initializer) if p.withinLoop > 0 and value == "": # fixes tests/run/tzeroarray: - resetLoc(p, s.loc) + ensureMutable s + resetLoc(p, s.locImpl) proc callGlobalVarCppCtor(p: BProc; v: PSym; vn, value: PNode; didGenTemp: var bool) = let s = vn.sym fillBackendName(p.module, s) - fillLoc(s.loc, locGlobalVar, vn, OnHeap) + ensureMutable s + fillLoc(s.locImpl, locGlobalVar, vn, OnHeap) let td = getTypeDesc(p.module, vn.sym.typ, dkVar) var val = genCppParamsForCtor(p, value, didGenTemp) if didGenTemp: return # generated in the caller @@ -779,7 +785,8 @@ proc fillProcLoc(m: BModule; n: PNode) = let sym = n.sym if sym.loc.k == locNone: fillBackendName(m, sym) - fillLoc(sym.loc, locProc, n, OnStack) + ensureMutable sym + fillLoc(sym.locImpl, locProc, n, OnStack) proc getLabel(p: BProc): TLabel = inc(p.labels) @@ -948,7 +955,8 @@ proc symInDynamicLib(m: BModule, sym: PSym) = var extname = sym.loc.snippet if not isCall: loadDynamicLib(m, lib) var tmp = mangleDynLibProc(sym) - sym.loc.snippet = tmp # from now on we only need the internal name + ensureMutable sym + sym.locImpl.snippet = tmp # from now on we only need the internal name sym.typ.sym = nil # generate a new name inc(m.labels, 2) if isCall: @@ -990,9 +998,10 @@ proc varInDynamicLib(m: BModule, sym: PSym) = var lib = sym.annex var extname = sym.loc.snippet loadDynamicLib(m, lib) - incl(sym.loc.flags, lfIndirect) + incl(sym, lfIndirect) var tmp = mangleDynLibProc(sym) - sym.loc.snippet = tmp # from now on we only need the internal name + ensureMutable sym + sym.locImpl.snippet = tmp # from now on we only need the internal name inc(m.labels, 2) let t = ptrType(getTypeDesc(m, sym.typ, dkVar)) # cgsym has side effects, do it first: @@ -1005,7 +1014,8 @@ proc varInDynamicLib(m: BModule, sym: PSym) = m.s[cfsVars].addVar(name = sym.loc.snippet, typ = t) proc symInDynamicLibPartial(m: BModule, sym: PSym) = - sym.loc.snippet = mangleDynLibProc(sym) + ensureMutable sym + sym.locImpl.snippet = mangleDynLibProc(sym) sym.typ.sym = nil # generate a new name proc cgsymImpl(m: BModule; sym: PSym) {.inline.} = @@ -1300,7 +1310,7 @@ proc genProcAux*(m: BModule, prc: PSym) = let resNode = prc.ast[resultPos] let res = resNode.sym # get result symbol if not isInvalidReturnType(m.config, prc.typ) and sfConstructor notin prc.flags: - if sfNoInit in prc.flags: incl(res.flags, sfNoInit) + if sfNoInit in prc.flags: incl(res, sfNoInit) if sfNoInit in prc.flags and p.module.compileToCpp and (let val = easyResultAsgn(procBody); val != nil): var a: TLoc = initLocExprSingleUse(p, val) let ra = rdLoc(a) @@ -1321,9 +1331,11 @@ proc genProcAux*(m: BModule, prc: PSym) = returnBuilder.addReturn(rres) returnStmt = extract(returnBuilder) elif sfConstructor in prc.flags: - resNode.sym.loc.flags.incl lfIndirect - fillLoc(resNode.sym.loc, locParam, resNode, "this", OnHeap) - prc.loc.snippet = getTypeDesc(m, resNode.sym.loc.t, dkVar) + resNode.sym.incl lfIndirect + ensureMutable resNode.sym + fillLoc(resNode.sym.locImpl, locParam, resNode, "this", OnHeap) + ensureMutable prc + prc.locImpl.snippet = getTypeDesc(m, resNode.sym.locImpl.t, dkVar) else: fillResult(p.config, resNode, prc.typ) assignParam(p, res, prc.typ.returnType) @@ -1336,10 +1348,12 @@ proc genProcAux*(m: BModule, prc: PSym) = if sfNoInit in prc.flags: discard elif allPathsAsgnResult(p, procBody) == InitSkippable: discard else: - resetLoc(p, res.loc) + ensureMutable res + resetLoc(p, res.locImpl) if skipTypes(res.typ, abstractInst).kind == tyArray: #incl(res.loc.flags, lfIndirect) - res.loc.storage = OnUnknown + ensureMutable res + res.locImpl.storage = OnUnknown for i in 1.. resultPos: disp.ast[resultPos].sym = copySym(s.ast[resultPos].sym, idgen) diff --git a/compiler/closureiters.nim b/compiler/closureiters.nim index 8b61106abc..6c9bb56080 100644 --- a/compiler/closureiters.nim +++ b/compiler/closureiters.nim @@ -198,7 +198,7 @@ proc newStateAssgn(ctx: var Ctx, toValue: PNode): PNode = proc newEnvVar(ctx: var Ctx, name: string, typ: PType): PSym = result = newSym(skVar, getIdent(ctx.g.cache, name), ctx.idgen, ctx.fn, ctx.fn.info) result.typ = typ - result.flags.incl sfNoInit + result.flagsImpl.incl sfNoInit assert(not typ.isNil, "Env var needs a type") let envParam = getEnvParam(ctx.fn) diff --git a/compiler/enumtostr.nim b/compiler/enumtostr.nim index 2223be2ffb..0227e3023e 100644 --- a/compiler/enumtostr.nim +++ b/compiler/enumtostr.nim @@ -47,8 +47,7 @@ proc genEnumToStrProc*(t: PType; info: TLineInfo; g: ModuleGraph; idgen: IdGener n[bodyPos] = body n[resultPos] = newSymNode(res) result.ast = n - incl result.flags, sfFromGeneric - incl result.flags, sfNeverRaises + incl result.flagsImpl, {sfFromGeneric, sfNeverRaises} proc searchObjCaseImpl(obj: PNode; field: PSym): PNode = case obj.kind @@ -110,5 +109,4 @@ proc genCaseObjDiscMapping*(t: PType; field: PSym; info: TLineInfo; g: ModuleGra n[bodyPos] = body n[resultPos] = newSymNode(res) result.ast = n - incl result.flags, sfFromGeneric - incl result.flags, sfNeverRaises + incl result.flagsImpl, {sfFromGeneric, sfNeverRaises} diff --git a/compiler/importer.nim b/compiler/importer.nim index 23814ae50f..8ff3bcfdb3 100644 --- a/compiler/importer.nim +++ b/compiler/importer.nim @@ -245,7 +245,8 @@ proc importModuleAs(c: PContext; n: PNode, realModule: PSym, importHidden, track # avoids modifying `realModule`, see D20201209T194412 for `import {.all.}` result = createModuleAliasImpl(realModule.name) if importHidden: - result.options.incl optImportHidden + ensureMutable result + result.optionsImpl.incl optImportHidden let moduleIdent = if n.kind in {nkInfix, nkImportAs}: n[^1] else: n result.info = moduleIdent.info if trackUnusedImport: diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index 1f2cff7e5f..223783a3f9 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -1155,7 +1155,7 @@ proc ownsData(c: var Con; s: var Scope; orig: PNode; flags: set[MoveOrCopyFlag]) if n.kind in nkCallKinds and n.typ != nil and hasDestructor(c, n.typ): result = newNodeIT(nkStmtListExpr, orig.info, orig.typ) let tmp = c.getTemp(s, n.typ, n.info) - tmp.sym.flags.incl sfSingleUsedTemp + tmp.sym.flagsImpl.incl sfSingleUsedTemp result.add newTree(nkFastAsgn, tmp, copyTree(n)) s.final.add c.genDestroy(tmp) n[] = tmp[] @@ -1330,7 +1330,7 @@ proc addSinkCopy(c: var Con; s: var Scope; sinkParams: seq[PSym]; n: PNode): PNo for param in sinkParams: if param.id in mutatedSet: let newSym = newSym(skTemp, getIdent(c.graph.cache, "sinkCopy"), c.idgen, param.owner, n.info) - newSym.flags.incl sfFromGeneric + newSym.flagsImpl.incl sfFromGeneric newSym.typ = param.typ.elementType mapping[param.id] = newSym let v = newNodeI(nkVarSection, n.info) diff --git a/compiler/jsgen.nim b/compiler/jsgen.nim index fd8ef583d0..acd49110ab 100644 --- a/compiler/jsgen.nim +++ b/compiler/jsgen.nim @@ -277,7 +277,8 @@ proc mangleName(m: BModule, s: PSym): Rope = else: result.add("_") result.add(rope(s.id)) - s.loc.snippet = result + ensureMutable s + s.locImpl.snippet = result proc escapeJSString(s: string): string = result = newStringOfCap(s.len + s.len shr 2) @@ -1002,7 +1003,8 @@ proc genTry(p: PProc, n: PNode, r: var TCompRes) = # If some branch requires a local alias introduce it here. This is needed # since JS cannot do ``catch x as y``. if excAlias != nil: - excAlias.sym.loc.snippet = mangleName(p.module, excAlias.sym) + ensureMutable excAlias.sym + excAlias.sym.locImpl.snippet = mangleName(p.module, excAlias.sym) lineF(p, "var $1 = lastJSError;$n", excAlias.sym.loc.snippet) gen(p, n[i][^1], a) moveInto(p, a, r) @@ -1135,7 +1137,8 @@ proc genBlock(p: PProc, n: PNode, r: var TCompRes) = # named block? if (n[0].kind != nkSym): internalError(p.config, n.info, "genBlock") var sym = n[0].sym - sym.loc.k = locOther + ensureMutable sym + sym.locImpl.k = locOther sym.position = idx+1 let labl = p.unique lineF(p, "Label$1: {$n", [labl.rope]) @@ -1234,7 +1237,8 @@ proc generateHeader(p: PProc, prc: PSym): Rope = # to keep it simple let env = prc.ast[paramsPos].lastSon assert env.kind == nkSym, "env is missing" - env.sym.loc.snippet = "this" + ensureMutable env.sym + env.sym.locImpl.snippet = "this" for i in 1.. 0 @@ -2577,7 +2591,9 @@ proc genObjConstr(p: PProc, n: PNode, r: var TCompRes) = let val = it[1] gen(p, val, a) var f = it[0].sym - if f.loc.snippet == "": f.loc.snippet = mangleName(p.module, f) + if f.loc.snippet == "": + ensureMutable f + f.locImpl.snippet = mangleName(p.module, f) fieldIDs.incl(lookupFieldAgain(n.typ.skipTypes({tyDistinct}), f).id) let typ = val.typ.skipTypes(abstractInst) diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index e9195644e1..0fca8b980f 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -161,7 +161,7 @@ proc getClosureIterResult*(g: ModuleGraph; iter: PSym; idgen: IdGenerator): PSym # XXX a bit hacky: result = newSym(skResult, getIdent(g.cache, ":result"), idgen, iter, iter.info, {}) result.typ = iter.typ.returnType - incl(result.flags, sfUsed) + incl(result.flagsImpl, sfUsed) iter.ast.add newSymNode(result) proc addHiddenParam(routine: PSym, param: PSym) = @@ -228,7 +228,7 @@ proc makeClosure*(g: ModuleGraph; idgen: IdGenerator; prc: PSym; env: PNode; inf #if isClosureIterator(result.typ): createTypeBoundOps(g, nil, result.typ, info, idgen) if tfHasAsgn in result.typ.flags or optSeqDestructors in g.config.globalOptions: - prc.flags.incl sfInjectDestructors + prc.incl sfInjectDestructors template liftingHarmful(conf: ConfigRef; owner: PSym): bool = ## lambda lifting can be harmful for JS-like code generators. @@ -240,7 +240,7 @@ proc createTypeBoundOpsLL(g: ModuleGraph; refType: PType; info: TLineInfo; idgen createTypeBoundOps(g, nil, refType.elementType, info, idgen) createTypeBoundOps(g, nil, refType, info, idgen) if tfHasAsgn in refType.flags or optSeqDestructors in g.config.globalOptions: - owner.flags.incl sfInjectDestructors + owner.incl sfInjectDestructors proc genCreateEnv(env: PNode): PNode = var c = newNodeIT(nkObjConstr, env.info, env.typ) @@ -414,7 +414,7 @@ proc addClosureParam(c: var DetectionPass; fn: PSym; info: TLineInfo) = let t = c.getEnvTypeForOwner(owner, info) if cp == nil: cp = newSym(skParam, getIdent(c.graph.cache, paramName), c.idgen, fn, fn.info) - incl(cp.flags, sfFromGeneric) + incl(cp.flagsImpl, sfFromGeneric) cp.typ = t addHiddenParam(fn, cp) elif cp.typ != t and fn.kind != skIterator: @@ -624,7 +624,7 @@ proc rawClosureCreation(owner: PSym; if owner.kind != skMacro: createTypeBoundOps(d.graph, nil, fieldAccess.typ, env.info, d.idgen) if tfHasAsgn in fieldAccess.typ.flags or optSeqDestructors in d.graph.config.globalOptions: - owner.flags.incl sfInjectDestructors + owner.incl sfInjectDestructors let upField = lookupInRecord(env.typ.skipTypes({tyOwned, tyRef, tyPtr}).n, getIdent(d.graph.cache, upName)) if upField != nil: @@ -666,7 +666,7 @@ proc closureCreationForIter(owner: PSym, iter: PNode; result = newNodeIT(nkStmtListExpr, iter.info, iter.sym.typ) let iterOwner = iter.sym.skipGenericOwner var v = newSym(skVar, getIdent(d.graph.cache, envName), d.idgen, iterOwner, iter.info) - incl(v.flags, sfShadowed) + incl(v.flagsImpl, sfShadowed) v.typ = asOwnedRef(d, getHiddenParam(d.graph, iter.sym).typ) var vnode: PNode if iterOwner.isIterator: diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim index 5d8fbc179d..b4b2fd28da 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/liftdestructors.nim @@ -284,7 +284,7 @@ proc fillBodyObjT(c: var TLiftCtx; t: PType, body, x, y: PNode) = body.add genIf(c, cond, newTreeI(nkReturnStmt, c.info, newNodeI(nkEmpty, 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) + incl(temp, sfFromGeneric) var v = newNodeI(nkVarSection, c.info) let blob = newSymNode(temp) v.addVar(blob, x) @@ -393,7 +393,8 @@ proc considerAsgnOrSink(c: var TLiftCtx; t: PType; body, x, y: PNode; if op != nil and op != c.fn and (sfOverridden in op.flags or destructorOverridden): if sfError in op.flags: - incl c.fn.flags, sfError + ensureMutable c.fn + incl c.fn.flagsImpl, sfError #else: # markUsed(c.g.config, c.info, op, c.g.usageSym) onUse(c.info, op) @@ -419,7 +420,8 @@ proc considerAsgnOrSink(c: var TLiftCtx; t: PType; body, x, y: PNode; if op == nil: op = produceSym(c.g, c.c, t, c.kind, c.info, c.idgen) if sfError in op.flags: - incl c.fn.flags, sfError + ensureMutable c.fn + incl c.fn.flagsImpl, sfError #else: # markUsed(c.g.config, c.info, op, c.g.usageSym) onUse(c.info, op) @@ -535,7 +537,7 @@ proc considerUserDefinedOp(c: var TLiftCtx; t: PType; body, x, y: PNode): bool = proc declareCounter(c: var TLiftCtx; body: PNode; first: BiggestInt): PNode = 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) + incl(temp.flagsImpl, sfFromGeneric) var v = newNodeI(nkVarSection, c.info) result = newSymNode(temp) @@ -545,7 +547,7 @@ proc declareCounter(c: var TLiftCtx; body: PNode; first: BiggestInt): PNode = proc declareTempOf(c: var TLiftCtx; body: PNode; value: PNode): PNode = var temp = newSym(skTemp, getIdent(c.g.cache, lowerings.genPrefix), c.idgen, c.fn, c.info) temp.typ = value.typ - incl(temp.flags, sfFromGeneric) + incl(temp.flagsImpl, sfFromGeneric) var v = newNodeI(nkVarSection, c.info) result = newSymNode(temp) @@ -1120,8 +1122,7 @@ proc symDupPrototype(g: ModuleGraph; typ: PType; owner: PSym; kind: TTypeAttache n[bodyPos] = newNodeI(nkStmtList, info) n[resultPos] = newSymNode(res) result.ast = n - incl result.flags, sfFromGeneric - incl result.flags, sfGeneratedOp + incl result.flagsImpl, {sfFromGeneric, sfGeneratedOp} proc symPrototype(g: ModuleGraph; typ: PType; owner: PSym; kind: TTypeAttachedOp; info: TLineInfo; idgen: IdGenerator; isDiscriminant = false): PSym = @@ -1163,10 +1164,10 @@ proc symPrototype(g: ModuleGraph; typ: PType; owner: PSym; kind: TTypeAttachedOp n[paramsPos] = result.typ.n n[bodyPos] = newNodeI(nkStmtList, info) result.ast = n - incl result.flags, sfFromGeneric - incl result.flags, sfGeneratedOp + incl result.flagsImpl, sfFromGeneric + incl result.flagsImpl, sfGeneratedOp if kind == attachedWasMoved: - incl result.flags, sfNoSideEffect + incl result.flagsImpl, sfNoSideEffect incl result.typ.flags, tfNoSideEffect proc genTypeFieldCopy(c: var TLiftCtx; t: PType; body, x, y: PNode) = @@ -1200,7 +1201,8 @@ proc produceSym(g: ModuleGraph; c: PContext; typ: PType; kind: TTypeAttachedOp; if kind == attachedSink and destructorOverridden(g, typ): ## compiler can use a combination of `=destroy` and memCopy for sink op - dest.flags.incl sfCursor + ensureMutable dest + dest.flagsImpl.incl sfCursor let op = getAttachedOp(g, typ, attachedDestructor) result.ast[bodyPos].add newOpCall(a, op, if op.typ.firstParamType.kind == tyVar: d[0] else: d) result.ast[bodyPos].add newAsgnStmt(d, src) @@ -1222,13 +1224,15 @@ proc produceSym(g: ModuleGraph; c: PContext; typ: PType; kind: TTypeAttachedOp; genTypeFieldCopy(a, typ, result.ast[bodyPos], d, src) if not a.canRaise: - incl result.flags, sfNeverRaises + ensureMutable result + incl result.flagsImpl, sfNeverRaises result.ast[pragmasPos] = newNodeI(nkPragma, info) result.ast[pragmasPos].add newTree(nkExprColonExpr, newIdentNode(g.cache.getIdent("raises"), info), newNodeI(nkBracket, info)) if kind == attachedDestructor: - incl result.options, optQuirky + ensureMutable result + incl result.optionsImpl, optQuirky completePartialOp(g, idgen.module, typ, kind, result) @@ -1253,7 +1257,9 @@ proc produceDestructorForDiscriminator*(g: ModuleGraph; typ: PType; field: PSym, result.ast[bodyPos].add v let placeHolder = newNodeIT(nkSym, info, getSysType(g, info, tyPointer)) fillBody(a, typ, result.ast[bodyPos], d, placeHolder) - if not a.canRaise: incl result.flags, sfNeverRaises + if not a.canRaise: + ensureMutable result + incl result.flagsImpl, sfNeverRaises template liftTypeBoundOps*(c: PContext; typ: PType; info: TLineInfo) = diff --git a/compiler/main.nim b/compiler/main.nim index 08b57722c4..377c85b6e1 100644 --- a/compiler/main.nim +++ b/compiler/main.nim @@ -200,7 +200,7 @@ proc commandInteractive(graph: ModuleGraph) = discard graph.compilePipelineModule(fileInfoIdx(graph.config, graph.config.projectFull), {}) else: var m = graph.makeStdinModule() - incl(m.flags, sfMainModule) + incl(m, sfMainModule) var idgen = IdGenerator(module: m.itemId.module, symId: m.itemId.item, typeId: 0) let s = llStreamOpenStdIn(onPrompt = proc() = flushDot(graph.config)) discard processPipelineModule(graph, m, idgen, s) diff --git a/compiler/modules.nim b/compiler/modules.nim index 7f56119ccc..8f050a9cc6 100644 --- a/compiler/modules.nim +++ b/compiler/modules.nim @@ -32,9 +32,9 @@ proc newModule*(graph: ModuleGraph; fileIdx: FileIndex): PSym = let filename = AbsoluteFile toFullPath(graph.config, fileIdx) # We cannot call ``newSym`` here, because we have to circumvent the ID # mechanism, which we do in order to assign each module a persistent ID. - result = PSym(kind: skModule, itemId: ItemId(module: int32(fileIdx), item: 0'i32), + result = PSym(kindImpl: skModule, itemId: ItemId(module: int32(fileIdx), item: 0'i32), name: getModuleIdent(graph, filename), - info: newLineInfo(fileIdx, 1, 1)) + infoImpl: newLineInfo(fileIdx, 1, 1)) if not isNimIdentifier(result.name.s): rawMessage(graph.config, errGenerated, "invalid module name: '" & result.name.s & "'; a module name must be a valid Nim identifier.") diff --git a/compiler/pipelines.nim b/compiler/pipelines.nim index 2116428b28..c42d25d151 100644 --- a/compiler/pipelines.nim +++ b/compiler/pipelines.nim @@ -90,7 +90,7 @@ proc prePass*(c: PContext; n: PNode) = let feature = parseEnum[Feature](name.strVal) if feature == codeReordering: c.features.incl feature - c.module.flags.incl sfReorder + c.module.incl sfReorder except ValueError: discard else: @@ -254,14 +254,14 @@ proc compilePipelineModule*(graph: ModuleGraph; fileIdx: FileIndex; flags: TSymF graph.cachedFiles[path] = $secureHashFile(path) if result == nil: result = newModule(graph, fileIdx) - result.flags.incl flags + result.incl flags registerModule(graph, result) processModuleAux("import") else: if sfSystemModule in flags: graph.systemModule = result if sfMainModule in flags and graph.config.cmd == cmdM: - result.flags.incl flags + result.incl flags registerModule(graph, result) processModuleAux("import") partialInitModule(result, graph, fileIdx, filename) @@ -273,7 +273,7 @@ proc compilePipelineModule*(graph: ModuleGraph; fileIdx: FileIndex; flags: TSymF replayStateChanges(graph.packed.pm[m.int].module, graph) replayGenericCacheInformation(graph, m.int) elif graph.isDirty(result): - result.flags.excl sfDirty + result.excl sfDirty # reset module fields: initStrTables(graph, result) result.ast = nil diff --git a/compiler/pragmas.nim b/compiler/pragmas.nim index a5b55663bc..afddf24299 100644 --- a/compiler/pragmas.nim +++ b/compiler/pragmas.nim @@ -1017,33 +1017,33 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, of wHeader: var lib = getLib(c, libHeader, getStrLitNode(c, it)) addToLib(lib, sym) - incl(sym.flags, sfImportc) - incl(sym.loc.flags, lfHeader) - incl(sym.loc.flags, lfNoDecl) + incl(sym, sfImportc) + incl(sym.locImpl.flags, lfHeader) + incl(sym.locImpl.flags, lfNoDecl) # implies nodecl, because otherwise header would not make sense - if sym.loc.snippet == "": sym.loc.snippet = rope(sym.name.s) + if sym.locImpl.snippet == "": sym.locImpl.snippet = rope(sym.name.s) of wNoSideEffect: noVal(c, it) if sym != nil: - incl(sym.flags, sfNoSideEffect) + incl(sym, sfNoSideEffect) if sym.typ != nil: incl(sym.typ.flags, tfNoSideEffect) of wSideEffect: noVal(c, it) - incl(sym.flags, sfSideEffect) + incl(sym, sfSideEffect) of wNoreturn: noVal(c, it) # Disable the 'noreturn' annotation when in the "Quirky Exceptions" mode! if c.config.exc != excQuirky: - incl(sym.flags, sfNoReturn) + incl(sym, sfNoReturn) if sym.typ.returnType != nil: localError(c.config, sym.ast[paramsPos][0].info, ".noreturn with return type not allowed") of wNoDestroy: noVal(c, it) - incl(sym.flags, sfGeneratedOp) + incl(sym, sfGeneratedOp) of wNosinks: noVal(c, it) - incl(sym.flags, sfWasForwarded) + incl(sym, sfWasForwarded) of wDynlib: processDynLib(c, it, sym) of wCompilerProc, wCore: @@ -1052,25 +1052,25 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, recordPragma(c, it, "cppdefine", sym.name.s) if sfFromGeneric notin sym.flags: markCompilerProc(c, sym) of wNonReloadable: - sym.flags.incl sfNonReloadable + sym.incl sfNonReloadable of wProcVar: # old procvar annotation, no longer needed noVal(c, it) of wExplain: - sym.flags.incl sfExplain + sym.incl sfExplain of wDeprecated: if sym != nil and sym.kind in routineKinds + {skType, skVar, skLet, skConst}: if it.kind in nkPragmaCallKinds: discard getStrLitNode(c, it) - incl(sym.flags, sfDeprecated) + incl(sym, sfDeprecated) elif sym != nil and sym.kind != skModule: # We don't support the extra annotation field if it.kind in nkPragmaCallKinds: localError(c.config, it.info, "annotation to deprecated not supported here") - incl(sym.flags, sfDeprecated) + incl(sym, sfDeprecated) # At this point we're quite sure this is a statement and applies to the # whole module elif it.kind in nkPragmaCallKinds: deprecatedStmt(c, it) - else: incl(c.module.flags, sfDeprecated) + else: incl(c.module, sfDeprecated) of wVarargs: noVal(c, it) if sym.typ == nil: invalidPragma(c, it) @@ -1080,7 +1080,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, typeBorrow(c, sym, it) else: noVal(c, it) - incl(sym.flags, sfBorrow) + incl(sym, sfBorrow) of wFinal: noVal(c, it) if sym.typ == nil: invalidPragma(c, it) @@ -1092,7 +1092,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, of wPackage: noVal(c, it) if sym.typ == nil: invalidPragma(c, it) - else: incl(sym.flags, sfForward) + else: incl(sym, sfForward) of wAcyclic: noVal(c, it) if sym.typ == nil: invalidPragma(c, it) @@ -1103,7 +1103,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, else: incl(sym.typ.flags, tfShallow) of wThread: noVal(c, it) - incl(sym.flags, sfThread) + incl(sym, sfThread) if sym.typ != nil: incl(sym.typ.flags, tfThread) if sym.typ.callConv == ccClosure: sym.typ.callConv = ccNimCall @@ -1116,7 +1116,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, of wGcSafe: noVal(c, it) if sym != nil: - if sym.kind != skType: incl(sym.flags, sfThread) + if sym.kind != skType: incl(sym, sfThread) if sym.typ != nil: incl(sym.typ.flags, tfGcSafe) else: invalidPragma(c, it) else: @@ -1140,8 +1140,8 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, # distinguish properly between # ``proc p() {.error}`` and ``proc p() = {.error: "msg".}`` if it.kind in nkPragmaCallKinds: discard getStrLitNode(c, it) - incl(sym.flags, sfError) - excl(sym.flags, sfForward) + incl(sym, sfError) + excl(sym, sfForward) else: let s = expectStrLit(c, it) recordPragma(c, it, "error", s) @@ -1151,18 +1151,18 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, of wUndef: processUndef(c, it) of wCompile: let m = sym.getModule() - incl(m.flags, sfUsed) + incl(m.flagsImpl, sfUsed) processCompile(c, it) of wLink: processLink(c, it) of wPassl: let m = sym.getModule() - incl(m.flags, sfUsed) + incl(m.flagsImpl, sfUsed) let s = expectStrLit(c, it) extccomp.addLinkOption(c.config, s) recordPragma(c, it, "passl", s) of wPassc: let m = sym.getModule() - incl(m.flags, sfUsed) + incl(m.flagsImpl, sfUsed) let s = expectStrLit(c, it) extccomp.addCompileOption(c.config, s) recordPragma(c, it, "passc", s) @@ -1180,16 +1180,16 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, result = true of wPragma: if not sym.isNil and sym.kind == skTemplate: - sym.flags.incl sfCustomPragma + sym.incl sfCustomPragma else: processPragma(c, n, i) result = true of wDiscardable: noVal(c, it) - if sym != nil: incl(sym.flags, sfDiscardable) + if sym != nil: incl(sym, sfDiscardable) of wNoInit: noVal(c, it) - if sym != nil: incl(sym.flags, sfNoInit) + if sym != nil: incl(sym, sfNoInit) of wCodegenDecl: processCodegenDecl(c, it, sym) of wChecks, wObjChecks, wFieldChecks, wRangeChecks, wBoundChecks, wOverflowChecks, wNilChecks, wAssertions, wWarnings, wHints, @@ -1199,7 +1199,8 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, processOption(c, it, c.config.options) of wStackTrace, wLineTrace: if sym.kind in {skProc, skMethod, skConverter}: - processOption(c, it, sym.options) + ensureMutable sym + processOption(c, it, sym.optionsImpl) else: processOption(c, it, c.config.options) of FirstCallConv..LastCallConv: @@ -1238,7 +1239,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, of wRequiresInit: noVal(c, it) if sym.kind == skField: - sym.flags.incl sfRequiresInit + sym.incl sfRequiresInit elif sym.typ != nil: incl(sym.typ.flags, tfNeedsFullInit) else: @@ -1246,7 +1247,8 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, of wByRef: noVal(c, it) if sym != nil and sym.kind == skParam: - sym.options.incl optByRef + ensureMutable sym + sym.optionsImpl.incl optByRef elif sym == nil or sym.typ == nil: processOption(c, it, c.config.options) else: @@ -1254,7 +1256,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, of wByCopy: noVal(c, it) if sym.kind == skParam: - incl(sym.flags, sfByCopy) + incl(sym, sfByCopy) elif sym.kind != skType or sym.typ == nil: invalidPragma(c, it) else: incl(sym.typ.flags, tfByCopy) of wPartial: @@ -1289,7 +1291,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, if sym == nil or sym.kind notin {skVar, skLet}: invalidPragma(c, it) else: - sym.flags.incl sfGoto + sym.incl sfGoto of wExportNims: if sym == nil: invalidPragma(c, it) else: magicsys.registerNimScriptSymbol(c.graph, sym) @@ -1304,7 +1306,7 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, noVal(c, it) of wBase: noVal(c, it) - sym.flags.incl sfBase + sym.incl sfBase of wIntDefine: processDefineConst(c, n, sym, mIntDefine) of wStrDefine: @@ -1314,21 +1316,22 @@ proc singlePragma(c: PContext, sym: PSym, n: PNode, i: var int, of wUsed: noVal(c, it) if sym == nil: invalidPragma(c, it) - else: sym.flags.incl sfUsed + else: sym.incl sfUsed of wLiftLocals: - sym.flags.incl(sfForceLift) + sym.incl(sfForceLift) of wRequires, wInvariant, wAssume, wAssert: pragmaProposition(c, it) of wEnsures: pragmaEnsures(c, it) of wEnforceNoRaises: - sym.flags.incl sfNeverRaises + sym.incl sfNeverRaises of wQuirky: - sym.flags.incl sfNeverRaises + sym.incl sfNeverRaises if sym.kind in {skProc, skMethod, skConverter, skFunc, skIterator}: - sym.options.incl optQuirky + ensureMutable sym + sym.optionsImpl.incl optQuirky of wSystemRaisesDefect: - sym.flags.incl sfSystemRaisesDefect + sym.incl sfSystemRaisesDefect of wVirtual: processVirtual(c, it, sym, sfVirtual) of wMember: @@ -1385,9 +1388,9 @@ proc implicitPragmas*(c: PContext, sym: PSym, info: TLineInfo, var lib = c.optionStack[^1].dynlib if {lfDynamicLib, lfHeader} * sym.loc.flags == {} and sfImportc in sym.flags and lib != nil: - incl(sym.loc.flags, lfDynamicLib) + incl(sym, lfDynamicLib) addToLib(lib, sym) - if sym.loc.snippet == "": sym.loc.snippet = rope(sym.name.s) + if sym.locImpl.snippet == "": sym.locImpl.snippet = rope(sym.name.s) proc hasPragma*(n: PNode, pragma: TSpecialWord): bool = if n == nil: return false diff --git a/compiler/scriptconfig.nim b/compiler/scriptconfig.nim index e3d2bcd458..e2df695268 100644 --- a/compiler/scriptconfig.nim +++ b/compiler/scriptconfig.nim @@ -215,7 +215,7 @@ proc runNimScript*(cache: IdentCache; scriptName: AbsoluteFile; conf.selectedGC = gcUnselected var m = graph.makeModule(scriptName) - incl(m.flags, sfMainModule) + incl(m, sfMainModule) var vm = setupVM(m, cache, scriptName.string, graph, idgen) graph.vm = vm diff --git a/compiler/sem.nim b/compiler/sem.nim index 38da68a0b0..48a6aacf30 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -260,7 +260,7 @@ proc newSymG*(kind: TSymKind, n: PNode, c: PContext): PSym = else: result = newSym(kind, considerQuotedIdent(c, n), c.idgen, getCurrOwner(c), n.info) if find(result.name.s, '`') >= 0: - result.flags.incl sfWasGenSym + result.flagsImpl.incl sfWasGenSym #if kind in {skForVar, skLet, skVar} and result.owner.kind == skModule: # incl(result.flags, sfGlobal) when defined(nimsuggest): diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index c1b49a19e9..4ec7beebeb 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -1920,7 +1920,7 @@ proc makeTupleAssignments(c: PContext; n: PNode): PNode = let temp = newSym(skTemp, getIdent(c.cache, "tmpTupleAsgn"), c.idgen, getCurrOwner(c), n.info) temp.typ = value.typ - temp.flags.incl(sfGenSym) + temp.flagsImpl.incl(sfGenSym) var v = newNodeI(nkLetSection, value.info) let tempNode = newSymNode(temp) #newIdentNode(getIdent(genPrefix & $temp.id), value.info) var vpart = newNodeI(nkIdentDefs, v.info, 3) @@ -1937,7 +1937,7 @@ proc makeTupleAssignments(c: PContext; n: PNode): PNode = # generate `let _ = temp[i]` which should generate a destructor let utemp = newSym(skLet, lhs[i].ident, c.idgen, getCurrOwner(c), lhs[i].info) utemp.typ = value.typ[i] - temp.flags.incl(sfGenSym) + temp.flagsImpl.incl(sfGenSym) var uv = newNodeI(nkLetSection, lhs[i].info) let utempNode = newSymNode(utemp) var uvpart = newNodeI(nkIdentDefs, v.info, 3) @@ -2376,7 +2376,7 @@ proc semQuoteAst(c: PContext, n: PNode): PNode = processQuotations(c, quotedBlock, op, quotes, ids) let dummyTemplateSym = newAnonSym(c, skTemplate, n.info) - incl(dummyTemplateSym.flags, sfTemplateRedefinition) + incl(dummyTemplateSym.flagsImpl, sfTemplateRedefinition) var dummyTemplate = newProcNode( nkTemplateDef, quotedBlock.info, body = quotedBlock, params = c.graph.emptyNode, @@ -2505,8 +2505,9 @@ proc instantiateCreateFlowVarCall(c: PContext; t: PType; # since it's an instantiation, we unmark it as a compilerproc. Otherwise # codegen would fail: if sfCompilerProc in result.flags: - result.flags.excl {sfCompilerProc, sfExportc, sfImportc} - result.loc.snippet = "" + ensureMutable result + result.flagsImpl.excl {sfCompilerProc, sfExportc, sfImportc} + result.locImpl.snippet = "" proc setMs(n: PNode, s: PSym): PNode = result = n @@ -3216,7 +3217,7 @@ proc enumFieldSymChoice(c: PContext, n: PNode, s: PSym; flags: TExprFlags): PNod a = initOverloadIter(o, c, n) while a != nil: if a.kind == skEnumField: - incl(a.flags, sfUsed) + incl(a.flagsImpl, sfUsed) markOwnerModuleAsUsed(c, a) result.add newSymNode(a, info) onUse(info, a) diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index 9268498040..92deca3231 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -50,13 +50,13 @@ proc semGenericStmtScope(c: PContext, n: PNode, result = semGenericStmt(c, n, flags, ctx) closeScope(c) -template isMixedIn(sym): bool = +template isMixedIn(sym): bool {.dirty.} = let s = sym s.name.id in ctx.toMixin or (withinConcept in flags and s.magic == mNone and s.kind in OverloadableSyms) -template canOpenSym(s): bool = +template canOpenSym(s): bool {.dirty.} = {withinMixin, withinConcept} * flags == {withinMixin} and s.id notin ctx.toBind proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym, @@ -65,7 +65,7 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym, fromDotExpr=false): PNode = result = nil semIdeForTemplateOrGenericCheck(c.config, n, ctx.cursorInBody) - incl(s.flags, sfUsed) + incl(s.flagsImpl, sfUsed) template maybeDotChoice(c: PContext, n: PNode, s: PSym, fromDotExpr: bool) = if fromDotExpr: result = symChoice(c, n, s, scForceOpen) @@ -274,7 +274,7 @@ proc semGenericStmt(c: PContext, n: PNode, result = lookup(c, n, flags, ctx) if result != nil and result.kind == nkSym: assert result.sym != nil - incl result.sym.flags, sfUsed + incl result.sym.flagsImpl, sfUsed markOwnerModuleAsUsed(c, result.sym) of nkDotExpr: #let luf = if withinMixin notin flags: {checkUndeclared} else: {} @@ -318,7 +318,7 @@ proc semGenericStmt(c: PContext, n: PNode, var first = int ord(withinConcept in flags) var mixinContext = false if s != nil: - incl(s.flags, sfUsed) + incl(s.flagsImpl, sfUsed) mixinContext = s.magic in {mDefined, mDeclared, mDeclaredInScope, mCompiles, mAstToStr} let whichChoice = if s.id in ctx.toBind: scClosed elif s.isMixedIn: scForceOpen diff --git a/compiler/seminst.nim b/compiler/seminst.nim index 7db6469d92..628d010bcd 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -24,7 +24,7 @@ proc addObjFieldsToLocalScope(c: PContext; n: PNode) = let f = n.sym if f.kind == skField and fieldVisible(c, f): c.currentScope.symbols.strTableIncl(f, onConflictKeepOld=true) - incl(f.flags, sfUsed) + incl(f.flagsImpl, sfUsed) # it is not an error to shadow fields via parameters else: discard @@ -42,7 +42,7 @@ iterator instantiateGenericParamList(c: PContext, n: PNode, pt: LayeredIdTable): 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, c.idgen, getCurrOwner(c), q.info) - s.flags.incl {sfUsed, sfFromGeneric} + s.flagsImpl.incl {sfUsed, sfFromGeneric} var t = lookup(pt, q.typ) if t == nil: if tfRetType in q.typ.flags: @@ -149,7 +149,7 @@ proc instantiateBody(c: PContext, n, params: PNode, result, orig: PSym) = nil b = semProcBody(c, b, resultType) result.ast[bodyPos] = hloBody(c, b) - excl(result.flags, sfForward) + excl(result, sfForward) trackProc(c, result, result.ast[bodyPos]) dec c.inGenericInst @@ -208,7 +208,7 @@ proc instGenericContainer(c: PContext, info: TLineInfo, header: PType, # this scope was not created by the user, # unused params shouldn't be reported. - param.flags.incl sfUsed + param.flagsImpl.incl sfUsed addDecl(c, param) result = replaceTypeVarsT(cl, header) @@ -337,7 +337,7 @@ proc instantiateOnlyProcType(c: PContext, pt: LayeredIdTable, prc: PSym, info: T # examples are in texplicitgenerics # might be buggy, see rest of generateInstance if problems occur let fakeSym = copySym(prc, c.idgen) - incl(fakeSym.flags, sfFromGeneric) + incl(fakeSym.flagsImpl, sfFromGeneric) fakeSym.instantiatedFrom = prc openScope(c) for s in instantiateGenericParamList(c, prc.ast[genericParamsPos], pt): @@ -393,7 +393,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: LayeredIdTable, let oldScope = c.currentScope while not isTopLevel(c): c.currentScope = c.currentScope.parent result = copySym(fn, c.idgen) - incl(result.flags, sfFromGeneric) + incl(result, sfFromGeneric) result.instantiatedFrom = fn if sfGlobal in result.flags and c.config.symbolFiles != disabledSf: let passc = getLocalPassC(c, producer) @@ -438,7 +438,7 @@ proc generateInstance(c: PContext, fn: PSym, pt: LayeredIdTable, inc i #echo "INSTAN ", fn.name.s, " ", typeToString(result.typ), " ", entry.concreteTypes.len if tfTriggersCompileTime in result.typ.flags: - incl(result.flags, sfCompileTime) + incl(result, sfCompileTime) n[genericParamsPos] = c.graph.emptyNode var oldPrc = genericCacheGet(c.graph, fn, entry[], c.compilesContextId) if oldPrc == nil: diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim index 0ad6117813..7ec913a874 100644 --- a/compiler/semmagic.nim +++ b/compiler/semmagic.nim @@ -34,7 +34,7 @@ proc semAddr(c: PContext; n: PNode): PNode = result = newNodeI(nkAddr, n.info) let x = semExprWithType(c, n) if x.kind == nkSym: - x.sym.flags.incl(sfAddrTaken) + x.sym.flagsImpl.incl(sfAddrTaken) if isAssignable(c, x) notin {arLValue, arLocalLValue, arAddressableConst, arLentValue}: localError(c.config, n.info, errExprHasNoAddress) result.add x @@ -471,7 +471,7 @@ proc turnFinalizerIntoDestructor(c: PContext; orig: PSym; info: TLineInfo): PSym result = copySym(orig, c.idgen) result.info = info - result.flags.incl sfFromGeneric + result.incl sfFromGeneric setOwner(result, orig) let origParamType = orig.typ.firstParamType let newParamType = makeVarType(result, origParamType.skipTypes(abstractPtrs), c.idgen) @@ -551,7 +551,7 @@ proc semNewFinalize(c: PContext; n: PNode): PNode = 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.firstParamType - wrapperSym.flags.incl sfUsed + wrapperSym.flagsImpl.incl sfUsed let wrapper = c.semExpr(c, newProcNode(nkProcDef, fin.info, body = newTree(nkCall, newSymNode(fin), selfSymNode), params = nkFormalParams.newTree(c.graph.emptyNode, diff --git a/compiler/semparallel.nim b/compiler/semparallel.nim index b0071979bc..78d59dfb29 100644 --- a/compiler/semparallel.nim +++ b/compiler/semparallel.nim @@ -491,7 +491,7 @@ proc liftParallel*(g: ModuleGraph; idgen: IdGenerator; owner: PSym; n: PNode): P var varSection = newNodeI(nkVarSection, 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) + incl(temp.flagsImpl, sfFromGeneric) let tempNode = newSymNode(temp) varSection.addVar tempNode diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index aa3e865ffd..1b4b15ac3e 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -141,7 +141,7 @@ proc createTypeBoundOps(tracked: PEffects, typ: PType; info: TLineInfo; explicit if tracked.config.selectedGC == gcRefc or optSeqDestructors in tracked.config.globalOptions or tfHasAsgn in typ.flags: - tracked.owner.flags.incl sfInjectDestructors + tracked.owner.incl sfInjectDestructors proc isLocalSym(a: PEffects, s: PSym): bool = s.typ != nil and (s.kind in {skLet, skVar, skResult} or (s.kind == skParam and isOutParam(s.typ))) and @@ -206,7 +206,7 @@ proc guardDotAccess(a: PEffects; n: PNode) = proc makeVolatile(a: PEffects; s: PSym) {.inline.} = if a.inTryStmt > 0 and a.config.exc == excSetjmp: - incl(s.flags, sfVolatile) + incl(s, sfVolatile) proc varDecl(a: PEffects; n: PNode) {.inline.} = if n.kind == nkSym: @@ -373,7 +373,7 @@ proc useVarNoInitCheck(a: PEffects; n: PNode; s: PSym) = proc useVar(a: PEffects, n: PNode) = let s = n.sym if a.inExceptOrFinallyStmt > 0: - incl s.flags, sfUsedInFinallyOrExcept + incl s, sfUsedInFinallyOrExcept if isLocalSym(a, s): if sfNoInit in s.flags: # If the variable is explicitly marked as .noinit. do not emit any error @@ -1243,7 +1243,7 @@ proc track(tracked: PEffects, n: PNode) = of nkSym: useVar(tracked, n) if n.sym.typ != nil and tfHasAsgn in n.sym.typ.flags: - tracked.owner.flags.incl sfInjectDestructors + tracked.owner.incl sfInjectDestructors # bug #15038: ensure consistency if n.typ == nil or (not hasDestructor(n.typ) and sameType(n.typ, n.sym.typ)): n.typ() = n.sym.typ of nkHiddenAddr, nkAddr: @@ -1682,7 +1682,7 @@ proc trackProc*(c: PContext; s: PSym, body: PNode) = t.scopes[res.id] = t.currentBlock if sfNoInit in s.flags: # marks result "noinit" - incl res.flags, sfNoInit + incl res, sfNoInit track(t, body) diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 1d6312e55c..9e5c54320e 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -79,7 +79,7 @@ proc semBreakOrContinue(c: PContext, n: PNode): PNode = if s.kind == skLabel and s.owner.id == c.p.owner.id: var x = newSymNode(s) x.info = n.info - incl(s.flags, sfUsed) + incl(s.flagsImpl, sfUsed) n[0] = x suggestSym(c.graph, x.info, s, c.graph.usageSym) onUse(x.info, s) @@ -483,13 +483,13 @@ proc identWithin(n: PNode, s: PIdent): bool = proc semIdentDef(c: PContext, n: PNode, kind: TSymKind, reportToNimsuggest = true): PSym = if isTopLevel(c): result = semIdentWithPragma(c, kind, n, {sfExported}, fromTopLevel = true) - incl(result.flags, sfGlobal) + incl(result, sfGlobal) #if kind in {skVar, skLet}: # echo "global variable here ", n.info, " ", result.name.s else: result = semIdentWithPragma(c, kind, n, {}) if result.owner.kind == skModule: - incl(result.flags, sfGlobal) + incl(result, sfGlobal) result.options = c.config.options if reportToNimsuggest: @@ -520,7 +520,7 @@ proc addToVarSection(c: PContext; result: var PNode; orig, identDefs: PNode) = proc isDiscardUnderscore(v: PSym): bool = if v.name.id == ord(wUnderscore): - v.flags.incl(sfGenSym) + v.incl(sfGenSym) result = true else: result = false @@ -779,7 +779,7 @@ proc makeVarTupleSection(c: PContext, n, a, def: PNode, typ: PType, symkind: TSy # use same symkind for compatibility with original section let temp = newSym(symkind, getIdent(c.cache, "tmpTuple"), c.idgen, getCurrOwner(c), n.info) temp.typ = typ - temp.flags.incl(sfGenSym) + temp.flagsImpl.incl(sfGenSym) lastDef = newNodeI(defkind, a.info) newSons(lastDef, 3) lastDef[0] = newSymNode(temp) @@ -937,11 +937,11 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode = else: if v.owner == nil: setOwner(v, c.p.owner) when oKeepVariableNames: - if c.inUnrolledContext > 0: v.flags.incl(sfShadowed) + if c.inUnrolledContext > 0: v.incl(sfShadowed) else: let shadowed = findShadowedVar(c, v) if shadowed != nil: - shadowed.flags.incl(sfShadowed) + shadowed.incl(sfShadowed) if shadowed.kind == skResult and sfGenSym notin v.flags: message(c.config, a.info, warnResultShadowed) if def.kind != nkEmpty: @@ -1113,7 +1113,7 @@ proc semForVars(c: PContext, n: PNode; flags: TExprFlags): PNode = for i in 0.. resultPos and n[resultPos] != nil: @@ -2158,8 +2158,8 @@ proc bindDupHook(c: PContext; s: PSym; n: PNode; op: TTypeAttachedOp) = localError(c.config, n.info, errGenerated, "signature for '=dup' must be proc[T: object](x: T): T") - incl(s.flags, sfUsed) - incl(s.flags, sfOverridden) + incl(s.flagsImpl, sfUsed) + incl(s, sfOverridden) proc bindTypeHook(c: PContext; s: PSym; n: PNode; op: TTypeAttachedOp) = let t = s.typ @@ -2216,8 +2216,8 @@ proc bindTypeHook(c: PContext; s: PSym; n: PNode; op: TTypeAttachedOp) = else: localError(c.config, n.info, errGenerated, "signature for '" & s.name.s & "' must be proc[T: object](x: var T)") - incl(s.flags, sfUsed) - incl(s.flags, sfOverridden) + incl(s.flagsImpl, sfUsed) + incl(s, sfOverridden) proc semOverride(c: PContext, s: PSym, n: PNode) = let name = s.name.s.normalize @@ -2257,12 +2257,12 @@ proc semOverride(c: PContext, s: PSym, n: PNode) = else: localError(c.config, n.info, errGenerated, "signature for 'deepCopy' must be proc[T: ptr|ref](x: T): T") - incl(s.flags, sfUsed) - incl(s.flags, sfOverridden) + incl(s.flagsImpl, sfUsed) + incl(s, sfOverridden) of "=", "=copy", "=sink": if s.magic == mAsgn: return - incl(s.flags, sfUsed) - incl(s.flags, sfOverridden) + incl(s.flagsImpl, sfUsed) + incl(s, sfOverridden) if name == "=": message(c.config, n.info, warnDeprecated, "Overriding `=` hook is deprecated; Override `=copy` hook instead") let t = s.typ @@ -2428,8 +2428,8 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, case n[namePos].kind of nkEmpty: s = newSym(kind, c.cache.idAnon, c.idgen, c.getCurrOwner, n.info) - s.flags.incl sfUsed - s.flags.incl sfGenSym + s.flagsImpl.incl sfUsed + s.incl sfGenSym n[namePos] = newSymNode(s) of nkSym: s = n[namePos].sym @@ -2455,7 +2455,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, #s.scope = c.currentScope if s.kind in {skMacro, skTemplate}: # push noalias flag at first to prevent unwanted recursive calls: - incl(s.flags, sfNoalias) + incl(s, sfNoalias) # before compiling the proc params & body, set as current the scope # where the proc was declared @@ -2493,13 +2493,13 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, n[genericParamsPos] = n[miscPos][1] n[miscPos] = c.graph.emptyNode - if tfTriggersCompileTime in s.typ.flags: incl(s.flags, sfCompileTime) + if tfTriggersCompileTime in s.typ.flags: incl(s, sfCompileTime) if n[patternPos].kind != nkEmpty: n[patternPos] = semPattern(c, n[patternPos], s) if s.kind == skIterator: s.typ.flags.incl(tfIterator) elif s.kind == skFunc: - incl(s.flags, sfNoSideEffect) + incl(s, sfNoSideEffect) incl(s.typ.flags, tfNoSideEffect) var (proto, comesFromShadowScope) = @@ -2573,8 +2573,8 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, if sfForward notin proto.flags and proto.magic == mNone: wrongRedefinition(c, n.info, proto.name.s, proto.info) if not comesFromShadowScope: - excl(proto.flags, sfForward) - incl(proto.flags, sfWasForwarded) + excl(proto, sfForward) + incl(proto, sfWasForwarded) suggestSym(c.graph, s.info, proto, c.graph.usageSym) closeScope(c) # close scope with wrong parameter symbols openScope(c) # open scope for old (correct) parameter symbols @@ -2676,8 +2676,8 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind, if s.kind in {skProc, skFunc} and s.typ.returnType != nil and s.typ.returnType.kind == tyAnything: localError(c.config, n[paramsPos][0].info, "return type 'auto' cannot be used in forward declarations") - incl(s.flags, sfForward) - incl(s.flags, sfWasForwarded) + incl(s, sfForward) + incl(s, sfWasForwarded) elif sfBorrow in s.flags: semBorrow(c, n, s) sideEffectsCheck(c, s) @@ -2794,10 +2794,10 @@ proc semMacroDef(c: PContext, n: PNode): PNode = if param.typ.kind != tyUntyped: allUntyped = false # no default value, parameters required in call if param.ast == nil: nullary = false - if allUntyped: incl(s.flags, sfAllUntyped) + if allUntyped: incl(s, sfAllUntyped) if nullary and n[genericParamsPos].kind == nkEmpty: # macro can be called with alias syntax, remove pushed noalias flag - excl(s.flags, sfNoalias) + excl(s, sfNoalias) if n[bodyPos].kind == nkEmpty: localError(c.config, n.info, errImplOfXexpected % s.name.s) diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index c424b801f5..33761da700 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -68,7 +68,7 @@ proc symChoice(c: PContext, n: PNode, s: PSym, r: TSymChoiceRule; if not isField or sfGenSym notin s.flags: result = newSymNode(s, info) # possibly not final field sym - incl(s.flags, sfUsed) + incl(s.flagsImpl, sfUsed) markOwnerModuleAsUsed(c, s) onUse(info, s) else: @@ -85,7 +85,7 @@ proc symChoice(c: PContext, n: PNode, s: PSym, r: TSymChoiceRule; a = initOverloadIter(o, c, n) while a != nil: if a.kind != skModule and (not isField or sfGenSym notin a.flags): - incl(a.flags, sfUsed) + incl(a.flagsImpl, sfUsed) markOwnerModuleAsUsed(c, a) result.add newSymNode(a, info) onUse(info, a) @@ -180,8 +180,7 @@ proc semTemplBodyScope(c: var TemplCtx, n: PNode): PNode = proc newGenSym(kind: TSymKind, n: PNode, c: var TemplCtx): PSym = result = newSym(kind, considerQuotedIdent(c.c, n), c.c.idgen, c.owner, n.info) - incl(result.flags, sfGenSym) - incl(result.flags, sfShadowed) + incl(result.flagsImpl, {sfGenSym, sfShadowed}) proc addLocalDecl(c: var TemplCtx, n: var PNode, k: TSymKind) = # locals default to 'gensym', fields default to 'inject': @@ -218,10 +217,10 @@ proc addLocalDecl(c: var TemplCtx, n: var PNode, k: TSymKind) = onDef(n.info, local) replaceIdentBySym(c.c, n, newSymNode(local, n.info)) if k == skParam and c.inTemplateHeader > 0: - local.flags.incl sfTemplateParam + local.incl sfTemplateParam proc semTemplSymbol(c: var TemplCtx, n: PNode, s: PSym; isField, isAmbiguous: bool): PNode = - incl(s.flags, sfUsed) + incl(s.flagsImpl, sfUsed) # bug #12885; ideally sem'checking is performed again afterwards marking # the symbol as used properly, but the nfSem mechanism currently prevents # that from happening, so we mark the module as used here already: @@ -298,7 +297,7 @@ proc semRoutineInTemplName(c: var TemplCtx, n: PNode, explicitInject: bool): PNo if s != nil: if s.owner == c.owner and (s.kind == skParam or (sfGenSym in s.flags and not explicitInject)): - incl(s.flags, sfUsed) + incl(s.flagsImpl, sfUsed) result = newSymNode(s, n.info) onUse(n.info, s) else: @@ -384,7 +383,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = let s = qualifiedLookUp(c.c, n, {}) if s != nil: if s.owner == c.owner and s.kind == skParam and sfTemplateParam in s.flags: - incl(s.flags, sfUsed) + incl(s.flagsImpl, sfUsed) result = newSymNode(s, n.info) onUse(n.info, s) elif contains(c.toBind, s.id): @@ -394,7 +393,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = elif s.owner == c.owner and sfGenSym in s.flags and c.noGenSym == 0: # template tmp[T](x: var seq[T]) = # var yz: T - incl(s.flags, sfUsed) + incl(s.flagsImpl, sfUsed) result = newSymNode(s, n.info) onUse(n.info, s) else: @@ -608,7 +607,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = # do not symchoice a quoted template parameter (bug #2390): if s.owner == c.owner and s.kind == skParam and n.kind == nkAccQuoted and n.len == 1: - incl(s.flags, sfUsed) + incl(s.flagsImpl, sfUsed) onUse(n.info, s) return newSymNode(s, n.info) elif contains(c.toBind, s.id): @@ -688,7 +687,7 @@ proc semTemplateDef(c: PContext, n: PNode): PNode = var s: PSym if isTopLevel(c): s = semIdentVis(c, skTemplate, n[namePos], {sfExported}) - incl(s.flags, sfGlobal) + incl(s, sfGlobal) else: s = semIdentVis(c, skTemplate, n[namePos], {}) assert s.kind == skTemplate @@ -701,7 +700,7 @@ proc semTemplateDef(c: PContext, n: PNode): PNode = # check parameter list: #s.scope = c.currentScope # push noalias flag at first to prevent unwanted recursive calls: - incl(s.flags, sfNoalias) + incl(s, sfNoalias) pushOwner(c, s) openScope(c) n[namePos] = newSymNode(s) @@ -724,8 +723,8 @@ proc semTemplateDef(c: PContext, n: PNode): PNode = for i in 1.. 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), c.idgen, c.module.owner, c.debug[pc]) - incl(sym.flags, sfGenSym) + incl(sym.flagsImpl, sfGenSym) regs[ra].node = newSymNode(sym) regs[ra].node.flags.incl nfIsRef of opcNccValue: diff --git a/compiler/vmgen.nim b/compiler/vmgen.nim index aa848bca87..450694d6cf 100644 --- a/compiler/vmgen.nim +++ b/compiler/vmgen.nim @@ -1790,7 +1790,7 @@ proc genRdVar(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags) = # see tests/t99bott for an example that triggers it: cannotEval(c, n) -template needsRegLoad(): untyped = +template needsRegLoad(): untyped {.dirty.} = {gfNode, gfNodeAddr} * flags == {} and fitsRegister(n.typ.skipTypes({tyVar, tyLent, tyStatic})) diff --git a/compiler/vmprofiler.nim b/compiler/vmprofiler.nim index 3f0db84bdd..38d9f1532f 100644 --- a/compiler/vmprofiler.nim +++ b/compiler/vmprofiler.nim @@ -1,5 +1,5 @@ -import options, vmdef, lineinfos, msgs +import ast, options, vmdef, lineinfos, msgs import std/[times, strutils, tables]