diff --git a/compiler/ast.nim b/compiler/ast.nim index 5f55c7ffa9..99478d51c6 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -695,32 +695,33 @@ type ItemState* = enum Complete # completely in memory Partial # partially in memory + Sealed # complete in memory, already written to NIF file, so further mutations are not allowed PLib* = ref TLib - TSym* {.acyclic.} = object # Keep in sync with PackedSym + TSym* {.acyclic.} = object # Keep in sync with ast2nif.nim itemId*: ItemId # proc and type instantiations are cached in the generic symbol state*: ItemState - case kind*: TSymKind + case kindImpl*: TSymKind # Note: kept as 'kind' for case statement, but accessor checks state of routineKinds: #procInstCache*: seq[PInstantiation] - gcUnsafetyReason*: PSym # for better error messages regarding gcsafe - transformedBody*: PNode # cached body after transf pass + gcUnsafetyReasonImpl*: PSym # for better error messages regarding gcsafe + transformedBodyImpl*: PNode # cached body after transf pass of skLet, skVar, skField, skForVar: - guard*: PSym - bitsize*: int - alignment*: int # for alignment + guardImpl*: PSym + bitsizeImpl*: int + alignmentImpl*: int # for alignment else: nil - magic*: TMagic - typ*: PType + magicImpl*: TMagic + typImpl*: PType name*: PIdent - info*: TLineInfo + infoImpl*: TLineInfo when defined(nimsuggest): - endInfo*: TLineInfo - hasUserSpecifiedType*: bool # used for determining whether to display inlay type hints - ownerField: PSym - flags*: TSymFlags - ast*: PNode # syntax tree of proc, iterator, etc.: + endInfoImpl*: TLineInfo + hasUserSpecifiedTypeImpl*: bool # used for determining whether to display inlay type hints + ownerFieldImpl: PSym + flagsImpl*: TSymFlags + astImpl*: PNode # syntax tree of proc, iterator, etc.: # the whole proc including header; this is used # for easy generation of proper error messages # for variant record fields the discriminant @@ -728,8 +729,8 @@ type # for modules, it's a placeholder for compiler # generated code that will be appended to the # module after the sem pass (see appendToModule) - options*: TOptions - position*: int # used for many different things: + optionsImpl*: TOptions + positionImpl*: int # used for many different things: # for enum fields its position; # for fields its offset # for parameters its position (starting with 0) @@ -739,23 +740,23 @@ type # for modules, an unique index corresponding # to the module's fileIdx # for variables a slot index for the evaluator - offset*: int32 # offset of record field + offsetImpl*: int32 # offset of record field disamb*: int32 # disambiguation number; the basic idea is that # `___` is unique - loc*: TLoc - annex*: PLib # additional fields (seldom used, so we use a + locImpl*: TLoc + annexImpl*: PLib # additional fields (seldom used, so we use a # reference to another object to save space) when hasFFI: - cname*: string # resolved C declaration name in importc decl, e.g.: + cnameImpl*: string # resolved C declaration name in importc decl, e.g.: # proc fun() {.importc: "$1aux".} => cname = funaux - constraint*: PNode # additional constraints like 'lit|result'; also + constraintImpl*: PNode # additional constraints like 'lit|result'; also # misused for the codegenDecl and virtual pragmas in the hope # it won't cause problems # for skModule the string literal to output for # deprecated modules. - instantiatedFrom*: PSym # for instances, the generic symbol where it came from. + instantiatedFromImpl*: PSym # for instances, the generic symbol where it came from. when defined(nimsuggest): - allUsages*: seq[TLineInfo] + allUsagesImpl*: seq[TLineInfo] TTypeSeq* = seq[PType] @@ -840,11 +841,226 @@ template nodeId(n: PNode): int = cast[int](n) template typ*(n: PNode): PType = n.typField +proc loadSym*(s: PSym) {.inline.} = + ## Loads a symbol from NIF file if it's in Partial state. + ## This is a forward declaration - implementation should be provided elsewhere. + discard + proc owner*(s: PSym|PType): PSym {.inline.} = - result = s.ownerField + when s is PSym: + if s.state == Partial: loadSym(s) + result = s.ownerFieldImpl + else: + result = s.ownerField proc setOwner*(s: PSym|PType, owner: PSym) {.inline.} = - s.ownerField = owner + when s is PSym: + if s.state == Partial: loadSym(s) + s.ownerFieldImpl = owner + else: + s.ownerField = owner + +# Accessor procs for TSym fields +# Note: kind is kept as a direct field for case statement compatibility +# but we still provide an accessor that checks state +proc kind*(s: PSym): TSymKind {.inline.} = + if s.state == Partial: loadSym(s) + result = s.kind + +proc `kind=`*(s: PSym, val: TSymKind) {.inline.} = + if s.state == Partial: loadSym(s) + s.kind = val + +proc gcUnsafetyReason*(s: PSym): PSym {.inline.} = + if s.state == Partial: loadSym(s) + result = s.gcUnsafetyReasonImpl + +proc `gcUnsafetyReason=`*(s: PSym, val: PSym) {.inline.} = + if s.state == Partial: loadSym(s) + s.gcUnsafetyReasonImpl = val + +proc transformedBody*(s: PSym): PNode {.inline.} = + if s.state == Partial: loadSym(s) + result = s.transformedBodyImpl + +proc `transformedBody=`*(s: PSym, val: PNode) {.inline.} = + if s.state == Partial: loadSym(s) + s.transformedBodyImpl = val + +proc guard*(s: PSym): PSym {.inline.} = + if s.state == Partial: loadSym(s) + result = s.guardImpl + +proc `guard=`*(s: PSym, val: PSym) {.inline.} = + if s.state == Partial: loadSym(s) + s.guardImpl = val + +proc bitsize*(s: PSym): int {.inline.} = + if s.state == Partial: loadSym(s) + result = s.bitsizeImpl + +proc `bitsize=`*(s: PSym, val: int) {.inline.} = + if s.state == Partial: loadSym(s) + s.bitsizeImpl = val + +proc alignment*(s: PSym): int {.inline.} = + if s.state == Partial: loadSym(s) + result = s.alignmentImpl + +proc `alignment=`*(s: PSym, val: int) {.inline.} = + if s.state == Partial: loadSym(s) + s.alignmentImpl = val + +proc magic*(s: PSym): TMagic {.inline.} = + if s.state == Partial: loadSym(s) + result = s.magicImpl + +proc `magic=`*(s: PSym, val: TMagic) {.inline.} = + if s.state == Partial: loadSym(s) + s.magicImpl = val + +proc typ*(s: PSym): PType {.inline.} = + if s.state == Partial: loadSym(s) + result = s.typImpl + +proc `typ=`*(s: PSym, val: PType) {.inline.} = + if s.state == Partial: loadSym(s) + s.typImpl = val + +proc info*(s: PSym): TLineInfo {.inline.} = + if s.state == Partial: loadSym(s) + result = s.infoImpl + +proc `info=`*(s: PSym, val: TLineInfo) {.inline.} = + if s.state == Partial: loadSym(s) + s.infoImpl = val + +when defined(nimsuggest): + proc endInfo*(s: PSym): TLineInfo {.inline.} = + if s.state == Partial: loadSym(s) + result = s.endInfoImpl + + proc `endInfo=`*(s: PSym, val: TLineInfo) {.inline.} = + if s.state == Partial: loadSym(s) + s.endInfoImpl = val + + proc hasUserSpecifiedType*(s: PSym): bool {.inline.} = + if s.state == Partial: loadSym(s) + result = s.hasUserSpecifiedTypeImpl + + proc `hasUserSpecifiedType=`*(s: PSym, val: bool) {.inline.} = + if s.state == Partial: loadSym(s) + s.hasUserSpecifiedTypeImpl = val + +proc flags*(s: PSym): TSymFlags {.inline.} = + if s.state == Partial: loadSym(s) + result = s.flagsImpl + +proc `flags=`*(s: PSym, val: TSymFlags) {.inline.} = + if s.state == Partial: loadSym(s) + s.flagsImpl = val + +proc ast*(s: PSym): PNode {.inline.} = + if s.state == Partial: loadSym(s) + result = s.astImpl + +proc `ast=`*(s: PSym, val: PNode) {.inline.} = + if s.state == Partial: loadSym(s) + s.astImpl = val + +proc options*(s: PSym): TOptions {.inline.} = + if s.state == Partial: loadSym(s) + result = s.optionsImpl + +proc `options=`*(s: PSym, val: TOptions) {.inline.} = + if s.state == Partial: loadSym(s) + s.optionsImpl = val + +proc position*(s: PSym): int {.inline.} = + if s.state == Partial: loadSym(s) + result = s.positionImpl + +proc `position=`*(s: PSym, val: int) {.inline.} = + if s.state == Partial: loadSym(s) + s.positionImpl = val + +proc offset*(s: PSym): int32 {.inline.} = + if s.state == Partial: loadSym(s) + result = s.offsetImpl + +proc `offset=`*(s: PSym, val: int32) {.inline.} = + if s.state == Partial: loadSym(s) + s.offsetImpl = val + +proc loc*(s: PSym): TLoc {.inline.} = + if s.state == Partial: loadSym(s) + result = s.locImpl + +proc `loc=`*(s: PSym, val: TLoc) {.inline.} = + if s.state == Partial: loadSym(s) + s.locImpl = val + +proc annex*(s: PSym): PLib {.inline.} = + if s.state == Partial: loadSym(s) + result = s.annexImpl + +proc `annex=`*(s: PSym, val: PLib) {.inline.} = + if s.state == Partial: loadSym(s) + s.annexImpl = val + +when hasFFI: + proc cname*(s: PSym): string {.inline.} = + if s.state == Partial: loadSym(s) + result = s.cnameImpl + + proc `cname=`*(s: PSym, val: string) {.inline.} = + if s.state == Partial: loadSym(s) + s.cnameImpl = val + +proc constraint*(s: PSym): PNode {.inline.} = + if s.state == Partial: loadSym(s) + result = s.constraintImpl + +proc `constraint=`*(s: PSym, val: PNode) {.inline.} = + if s.state == Partial: loadSym(s) + s.constraintImpl = val + +proc instantiatedFrom*(s: PSym): PSym {.inline.} = + if s.state == Partial: loadSym(s) + result = s.instantiatedFromImpl + +proc `instantiatedFrom=`*(s: PSym, val: PSym) {.inline.} = + if s.state == Partial: loadSym(s) + s.instantiatedFromImpl = val + +proc setSnippet*(s: PSym; val: sink string) {.inline.} = + if s.state == Partial: loadSym(s) + s.locImpl.snippet = val + +proc incl*(s: PSym; flag: TSymFlag) {.inline.} = + if s.state == Partial: loadSym(s) + s.flagsImpl.incl(flag) + +proc incl*(s: PSym; flags: set[TSymFlag]) {.inline.} = + if s.state == Partial: loadSym(s) + s.flagsImpl.incl(flag) + +proc incl*(s: PSym; flag: TLocFlag) {.inline.} = + if s.state == Partial: loadSym(s) + s.locImpl.flags.incl(flag) + +proc excl*(s: PSym; flag: TSymFlag) {.inline.} = + if s.state == Partial: loadSym(s) + s.flagsImpl.excl(flag) + +when defined(nimsuggest): + proc allUsages*(s: PSym): seq[TLineInfo] {.inline.} = + if s.state == Partial: loadSym(s) + result = s.allUsagesImpl + + proc `allUsages=`*(s: PSym, val: seq[TLineInfo]) {.inline.} = + if s.state == Partial: loadSym(s) + s.allUsagesImpl = val type Gconfig = object # we put comments in a side channel to avoid increasing `sizeof(TNode)`, which @@ -1091,15 +1307,17 @@ proc getDeclPragma*(n: PNode): PNode = proc extractPragma*(s: PSym): PNode = ## gets the pragma node of routine/type/var/let/const symbol `s` if s.kind in routineKinds: # bug #24167 - if s.ast[pragmasPos] != nil and s.ast[pragmasPos].kind != nkEmpty: - result = s.ast[pragmasPos] + let astVal = s.ast + if astVal != nil and astVal[pragmasPos] != nil and astVal[pragmasPos].kind != nkEmpty: + result = astVal[pragmasPos] else: result = nil elif s.kind in {skType, skVar, skLet, skConst}: - if s.ast != nil and s.ast.len > 0: - if s.ast[0].kind == nkPragmaExpr and s.ast[0].len > 1: + let astVal = s.ast + if astVal != nil and astVal.len > 0: + if astVal[0].kind == nkPragmaExpr and astVal[0].len > 1: # s.ast = nkTypedef / nkPragmaExpr / [nkSym, nkPragma] - result = s.ast[0][1] + result = astVal[0][1] else: result = nil else: @@ -1126,7 +1344,7 @@ when defined(useNodeIds): const nodeIdToDebug* = -1 # 2322968 var gNodeId: int -template newNodeImpl(info2) = +template newNodeImpl(info2) {.dirty.} = result = PNode(kind: kind, info: info2) when false: # this would add overhead, so we skip it; it results in a small amount of leaked entries @@ -1229,8 +1447,8 @@ proc newSym*(symKind: TSymKind, name: PIdent, idgen: IdGenerator; owner: 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, ownerField: owner, offset: defaultOffset, + result = PSym(name: name, kindImpl: symKind, flagsImpl: {}, infoImpl: info, itemId: id, + optionsImpl: options, ownerFieldImpl: owner, offsetImpl: defaultOffset, disamb: getOrDefault(idgen.disambTable, name).int32) idgen.disambTable.inc name when false: @@ -1241,10 +1459,11 @@ proc newSym*(symKind: TSymKind, name: PIdent, idgen: IdGenerator; owner: PSym, proc astdef*(s: PSym): PNode = # get only the definition (initializer) portion of the ast - if s.ast != nil and s.ast.kind in {nkIdentDefs, nkConstDef}: - s.ast[2] + let astVal = s.ast + if astVal != nil and astVal.kind in {nkIdentDefs, nkConstDef}: + astVal[2] else: - s.ast + astVal proc isMetaType*(t: PType): bool = return t.kind in tyMetaTypes or @@ -1256,31 +1475,33 @@ proc isUnresolvedStatic*(t: PType): bool = proc linkTo*(t: PType, s: PSym): PType {.discardable.} = t.sym = s - s.typ = t + s.typImpl = t result = t proc linkTo*(s: PSym, t: PType): PSym {.discardable.} = t.sym = s - s.typ = t + s.typImpl = t result = s template fileIdx*(c: PSym): FileIndex = # XXX: this should be used only on module symbols - c.position.FileIndex + c.position().FileIndex template filename*(c: PSym): string = # XXX: this should be used only on module symbols - c.position.FileIndex.toFilename + c.position().FileIndex.toFilename proc appendToModule*(m: PSym, n: PNode) = ## The compiler will use this internally to add nodes that will be ## appended to the module after the sem pass - if m.ast == nil: - m.ast = newNode(nkStmtList) - m.ast.sons = @[n] + var astVal = m.ast + if astVal == nil: + astVal = newNode(nkStmtList) + astVal.sons = @[n] + m.astImpl = astVal else: - assert m.ast.kind == nkStmtList - m.ast.sons.add(n) + assert astVal.kind == nkStmtList + astVal.sons.add(n) const # for all kind of hash tables: GrowthFactor* = 2 # must be power of 2, > 0 @@ -1582,9 +1803,11 @@ proc assignType*(dest, src: PType) = # this fixes 'type TLock = TSysLock': if src.sym != nil: if dest.sym != nil: - dest.sym.flags.incl src.sym.flags-{sfUsed, sfExported} - if dest.sym.annex == nil: dest.sym.annex = src.sym.annex - mergeLoc(dest.sym.loc, src.sym.loc) + var destFlags = dest.sym.flags + var srcFlags = src.sym.flags + dest.sym.flagsImpl = destFlags + (srcFlags - {sfUsed, sfExported}) + if dest.sym.annex == nil: dest.sym.annexImpl = src.sym.annex + mergeLoc(dest.sym.locImpl, src.sym.loc) else: dest.sym = src.sym newSons(dest, src.sons.len) @@ -1604,31 +1827,31 @@ proc exactReplica*(t: PType): PType = 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 - result.magic = s.magic - result.options = s.options - result.position = s.position - result.loc = s.loc - result.annex = s.annex # BUGFIX - result.constraint = s.constraint + #result.astImpl = nil # BUGFIX; was: s.ast which made problems + result.typImpl = s.typ + result.flagsImpl = s.flags + result.magicImpl = s.magic + result.optionsImpl = s.options + result.positionImpl = s.position + result.locImpl = s.loc + result.annexImpl = s.annex # BUGFIX + result.constraintImpl = s.constraint if result.kind in {skVar, skLet, skField}: - result.guard = s.guard - result.bitsize = s.bitsize - result.alignment = s.alignment + result.guardImpl = s.guard + result.bitsizeImpl = s.bitsize + result.alignmentImpl = s.alignment proc createModuleAlias*(s: PSym, idgen: IdGenerator, newIdent: PIdent, info: TLineInfo; options: TOptions): PSym = result = newSym(s.kind, newIdent, idgen, s.owner, info, options) # keep ID! - result.ast = s.ast + result.astImpl = s.ast #result.id = s.id # XXX figure out what to do with the ID. - result.flags = s.flags - result.options = s.options - result.position = s.position - result.loc = s.loc - result.annex = s.annex + result.flagsImpl = s.flags + result.optionsImpl = s.options + result.positionImpl = s.position + result.locImpl = s.loc + result.annexImpl = s.annex proc initStrTable*(): TStrTable = result = TStrTable(counter: 0) @@ -1754,28 +1977,28 @@ proc transitionNoneToSym*(n: PNode) = template transitionSymKindCommon*(k: TSymKind) = let obj {.inject.} = s[] - s[] = TSym(kind: k, itemId: obj.itemId, magic: obj.magic, typ: obj.typ, name: obj.name, - info: obj.info, ownerField: obj.ownerField, flags: obj.flags, ast: obj.ast, - options: obj.options, position: obj.position, offset: obj.offset, - loc: obj.loc, annex: obj.annex, constraint: obj.constraint) + s[] = TSym(kindImpl: k, itemId: obj.itemId, magicImpl: obj.magicImpl, typImpl: obj.typImpl, name: obj.name, + infoImpl: obj.infoImpl, ownerFieldImpl: obj.ownerFieldImpl, flagsImpl: obj.flagsImpl, astImpl: obj.astImpl, + optionsImpl: obj.optionsImpl, positionImpl: obj.positionImpl, offsetImpl: obj.offsetImpl, + locImpl: obj.locImpl, annexImpl: obj.annexImpl, constraintImpl: obj.constraintImpl) when hasFFI: - s.cname = obj.cname + s.cnameImpl = obj.cnameImpl when defined(nimsuggest): - s.allUsages = obj.allUsages + s.allUsagesImpl = obj.allUsagesImpl proc transitionGenericParamToType*(s: PSym) = transitionSymKindCommon(skType) proc transitionRoutineSymKind*(s: PSym, kind: range[skProc..skTemplate]) = transitionSymKindCommon(kind) - s.gcUnsafetyReason = obj.gcUnsafetyReason - s.transformedBody = obj.transformedBody + s.gcUnsafetyReasonImpl = obj.gcUnsafetyReasonImpl + s.transformedBodyImpl = obj.transformedBodyImpl proc transitionToLet*(s: PSym) = transitionSymKindCommon(skLet) - s.guard = obj.guard - s.bitsize = obj.bitsize - s.alignment = obj.alignment + s.guardImpl = obj.guardImpl + s.bitsizeImpl = obj.bitsizeImpl + s.alignmentImpl = obj.alignmentImpl template copyNodeImpl(dst, src, processSonsStmt) = if src == nil: return diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index aa552d61c4..e49f59ab20 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -118,8 +118,6 @@ type deps: TokenBuf # include&import deps infos: LineInfoWriter currentModule: int32 - writtenSyms: HashSet[ItemId] - writtenTypes: HashSet[ItemId] decodedFileIndices: HashSet[FileIndex] moduleToNifSuffix: Table[FileIndex, string] locals: HashSet[ItemId] # track proc-local symbols @@ -233,7 +231,8 @@ proc writeTypeDef(w: var Writer; dest: var TokenBuf; typ: PType) = proc writeType(w: var Writer; dest: var TokenBuf; typ: PType) = if typ == nil: dest.addDotToken() - elif typ.itemId.module == w.currentModule and not w.writtenTypes.containsOrIncl(typ.uniqueId): + elif typ.itemId.module == w.currentModule and typ.state == Complete: + typ.state = Sealed writeTypeDef(w, dest, typ) else: dest.buildTree tuseTag: @@ -288,7 +287,8 @@ proc writeSymDef(w: var Writer; dest: var TokenBuf; sym: PSym) = proc writeSym(w: var Writer; dest: var TokenBuf; sym: PSym) = if sym == nil: dest.addDotToken() - elif sym.itemId.module == w.currentModule and not w.writtenSyms.containsOrIncl(sym.itemId): + elif sym.itemId.module == w.currentModule and sym.state == Complete: + sym.state = Sealed writeSymDef(w, dest, sym) else: # NIF has direct support for symbol references so we don't need to use a tag here, @@ -298,7 +298,8 @@ proc writeSym(w: var Writer; dest: var TokenBuf; sym: PSym) = proc writeSymNode(w: var Writer; dest: var TokenBuf; n: PNode; sym: PSym) = if sym == nil: dest.addDotToken() - elif sym.itemId.module == w.currentModule and not w.writtenSyms.containsOrIncl(sym.itemId): + elif sym.itemId.module == w.currentModule and sym.state == Complete: + sym.state = Sealed if n.typ != n.sym.typ: dest.buildTree hiddenTypeTag, trLineInfo(w, n.info): writeSymDef(w, dest, sym) @@ -629,7 +630,7 @@ proc loadSymStub(c: var DecodeContext; t: SymId): PSym = result = c.syms.getOrDefault(id)[0] if result == nil: let offs = c.getOffset(module, symAsStr) - result = PSym(itemId: id, kind: skStub, name: c.cache.getIdent(sn.name), disamb: sn.count.int32, state: Partial) + result = PSym(itemId: id, kindImpl: skStub, name: c.cache.getIdent(sn.name), disamb: sn.count.int32, state: Partial) c.syms[id] = (result, offs) proc loadSymStub(c: var DecodeContext; n: var Cursor): PSym = @@ -689,6 +690,7 @@ proc loadLoc(c: var DecodeContext; n: var Cursor; loc: var TLoc) = proc loadType*(c: var DecodeContext; t: PType) = if t.state != Partial: return + t.state = Sealed var buf = createTokenBuf(30) var n = cursorFromIndexEntry(c, t.itemId.module, c.types[t.itemId][1], buf) @@ -739,7 +741,8 @@ proc loadAnnex(c: var DecodeContext; n: var Cursor): PLib = raiseAssert "`lib/annex` information expected" proc loadSym*(c: var DecodeContext; s: PSym) = - if s.kind != skStub: return + if s.state != Partial: return + s.state = Sealed var buf = createTokenBuf(30) var n = cursorFromIndexEntry(c, s.itemId.module, c.syms[s.itemId][1], buf) @@ -777,7 +780,7 @@ proc loadSym*(c: var DecodeContext; s: PSym) = s.setOwner loadSymStub(c, n) # We do not store `sym.ast` here but instead set it in the deserializer #writeNode(w, sym.ast) - loadLoc c, n, s.loc + loadLoc c, n, s.locImpl s.constraint = loadNode(c, n) s.instantiatedFrom = loadSymStub(c, n) skipParRi n diff --git a/compiler/ic/ic.nim b/compiler/ic/ic.nim index ecc6069e75..340193641c 100644 --- a/compiler/ic/ic.nim +++ b/compiler/ic/ic.nim @@ -899,11 +899,11 @@ proc moduleIndex*(c: var PackedDecoder; g: var PackedModuleGraph; thisModule: in proc symHeaderFromPacked(c: var PackedDecoder; g: var PackedModuleGraph; s: PackedSym; si, item: int32): PSym = result = PSym(itemId: ItemId(module: si, item: item), - kind: s.kind, magic: s.magic, flags: s.flags, - info: translateLineInfo(c, g, si, s.info), - 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, + kindImpl: s.kind, magicImpl: s.magic, flagsImpl: s.flags, + infoImpl: translateLineInfo(c, g, si, s.info), + optionsImpl: s.options, + positionImpl: if s.kind in {skForVar, skVar, skLet, skTemp}: 0 else: s.position, + offsetImpl: if s.kind in routineKinds: defaultOffset else: s.offset, disamb: s.disamb, name: getIdent(c.cache, g[si].fromDisk.strings[s.name]) ) @@ -945,8 +945,8 @@ proc symBodyFromPacked(c: var PackedDecoder; g: var PackedModuleGraph; setOwner(result, loadSym(c, g, si, s.owner)) let externalName = g[si].fromDisk.strings[s.externalName] if externalName != "": - result.loc.snippet = externalName - result.loc.flags = s.locFlags + result.locImpl.snippet = externalName + result.locImpl.flags = s.locFlags result.instantiatedFrom = loadSym(c, g, si, s.instantiatedFrom) proc needsRecompile(g: var PackedModuleGraph; conf: ConfigRef; cache: IdentCache; @@ -1058,12 +1058,12 @@ proc setupLookupTables(g: var PackedModuleGraph; conf: ConfigRef; cache: IdentCa let filename = AbsoluteFile toFullPath(conf, 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. - m.module = PSym(kind: skModule, itemId: ItemId(module: int32(fileIdx), item: 0'i32), + m.module = PSym(kindImpl: skModule, itemId: ItemId(module: int32(fileIdx), item: 0'i32), name: getIdent(cache, splitFile(filename).name), - info: newLineInfo(fileIdx, 1, 1), - position: int(fileIdx)) + infoImpl: newLineInfo(fileIdx, 1, 1), + positionImpl: int(fileIdx)) setOwner(m.module, getPackage(conf, cache, fileIdx)) - m.module.flags = m.fromDisk.moduleFlags + m.module.flagsImpl = m.fromDisk.moduleFlags proc loadToReplayNodes(g: var PackedModuleGraph; conf: ConfigRef; cache: IdentCache; fileIdx: FileIndex; m: var LoadedModule) = diff --git a/compiler/lookups.nim b/compiler/lookups.nim index acaad9d9b4..bbc5b4df40 100644 --- a/compiler/lookups.nim +++ b/compiler/lookups.nim @@ -311,7 +311,7 @@ proc errorSym*(c: PContext, ident: PIdent, info: TLineInfo): PSym = ## creates an error symbol to avoid cascading errors (for IDE support) result = newSym(skError, ident, c.idgen, getCurrOwner(c), info, {}) result.typ = errorType(c) - incl(result.flags, sfDiscardable) + incl(result.flagsImpl, sfDiscardable) # pretend it's from the top level scope to prevent cascading errors: if c.config.cmd != cmdInteractive and c.compilesContextId == 0: c.moduleScope.addSym(result) diff --git a/compiler/lowerings.nim b/compiler/lowerings.nim index a55d2776d8..95359c6a66 100644 --- a/compiler/lowerings.nim +++ b/compiler/lowerings.nim @@ -82,7 +82,7 @@ proc lowerTupleUnpacking*(g: ModuleGraph; n: PNode; idgen: IdGenerator; owner: P 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) + incl(temp.flagsImpl, sfFromGeneric) tempAsNode = newSymNode(temp) var v = newNodeI(nkVarSection, value.info) @@ -103,7 +103,7 @@ proc evalOnce*(g: ModuleGraph; value: PNode; idgen: IdGenerator; owner: PSym): P 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) + incl(temp.flagsImpl, sfFromGeneric) var v = newNodeI(nkLetSection, value.info) let tempAsNode = newSymNode(temp) @@ -127,8 +127,8 @@ proc lowerSwap*(g: ModuleGraph; n: PNode; idgen: IdGenerator; owner: PSym): PNod # note: cannot use 'skTemp' here cause we really need the copy for the VM :-( 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) + incl(temp.flagsImpl, sfFromGeneric) + incl(temp.flagsImpl, sfGenSym) var v = newNodeI(nkVarSection, n.info) let tempAsNode = newSymNode(temp) @@ -153,7 +153,7 @@ proc createObj*(g: ModuleGraph; idgen: IdGenerator; owner: PSym, info: TLineInfo result.n = newNodeI(nkRecList, info) let s = newSym(skType, getIdent(g.cache, "Env_" & toFilename(g.config, info) & "_" & $owner.name.s), idgen, owner, info, owner.options) - incl s.flags, sfAnon + incl s.flagsImpl, sfAnon s.typ = result result.sym = s diff --git a/compiler/modulegraphs.nim b/compiler/modulegraphs.nim index 51b9e5e4eb..cb6772dda1 100644 --- a/compiler/modulegraphs.nim +++ b/compiler/modulegraphs.nim @@ -681,13 +681,13 @@ proc markDirty*(g: ModuleGraph; fileIdx: FileIndex) = if m != nil: g.suggestSymbols.del(fileIdx) g.suggestErrors.del(fileIdx) - incl m.flags, sfDirty + incl m.flagsImpl, sfDirty proc unmarkAllDirty*(g: ModuleGraph) = for i in 0i32.. depthf: a.skipGenericAlias else: a let rootf = if skipBoth or depthf > deptha: f.skipGenericAlias else: f - + if f.isConcept: result = enterConceptMatch(c, rootf, roota, flags) elif a.kind == tyGenericInst: @@ -2316,7 +2316,7 @@ proc userConvMatch(c: PContext, m: var TCandidate, f, a: PType, let fdest = typeRel(m, f, dest) if fdest in {isEqual, isGeneric} and not (dest.kind == tyLent and f.kind in {tyVar}): # can't fully mark used yet, may not be used in final call - incl(c.converters[i].flags, sfUsed) + incl(c.converters[i].flagsImpl, sfUsed) markOwnerModuleAsUsed(c, c.converters[i]) var s = newSymNode(c.converters[i]) s.typ() = c.converters[i].typ diff --git a/compiler/suggest.nim b/compiler/suggest.nim index 3953936eb6..7be74f5190 100644 --- a/compiler/suggest.nim +++ b/compiler/suggest.nim @@ -43,7 +43,7 @@ when defined(nimsuggest): const sep = '\t' -type +type ImportContext = object isMultiImport: bool # True if we're in a [...] context baseDir: string # e.g., "folder/" in "import folder/[..." @@ -707,9 +707,9 @@ proc markOwnerModuleAsUsed(c: PContext; s: PSym) = proc markUsed(c: PContext; info: TLineInfo; s: PSym; checkStyle = true; isGenericInstance = false) = if not isGenericInstance: let conf = c.config - incl(s.flags, sfUsed) + incl(s.flagsImpl, sfUsed) if s.kind == skEnumField and s.owner != nil: - incl(s.owner.flags, sfUsed) + incl(s.owner.flagsImpl, sfUsed) if sfDeprecated in s.owner.flags: warnAboutDeprecated(conf, info, s) if {sfDeprecated, sfError} * s.flags != {}: @@ -788,7 +788,7 @@ proc extractImportContextFromAst(n: PNode, cursorCol: int): ImportContext = proc findModuleFile(c: PContext, partialPath: string): seq[string] = result = @[] let currentModuleDir = parentDir(toFullPath(c.config, FileIndex(c.module.position))) - + proc tryAddModule(path, baseName: string) = if fileExists(path & ".nim"): result.add(baseName) @@ -800,7 +800,7 @@ proc findModuleFile(c: PContext, partialPath: string): seq[string] = let (_, name, ext) = splitFile(path) if kind == pcFile: if ext == ".nim" and name.startsWith(file): - result.add(name) + result.add(name) proc collectImportModulesFromDir(dir: string, result: var seq[string]) = for kind, path in walkDir(dir): @@ -809,10 +809,10 @@ proc findModuleFile(c: PContext, partialPath: string): seq[string] = if kind == pcFile: if ext == ".nim" and name.startsWith(partialPath): result.add(name) - else: + else: if name.startsWith(partialPath): result.add(name) - + if '/' in partialPath: let parts = partialPath.split('/') let dir = parts[0] @@ -839,13 +839,13 @@ proc suggestModuleNames(c: PContext, n: PNode) = column: n.info.col.int, doc: "", quality: 100, - contextFits: true, + contextFits: true, prefix: if partialPath.len > 0: prefixMatch(path, partialPath) else: PrefixMatch.None, symkind: byte skModule ) suggestions.add(suggest) - + let importCtx = extractImportContextFromAst(n, c.config.m.trackPos.col) var searchPath = "" if importCtx.baseDir.len > 0: @@ -901,7 +901,7 @@ proc suggestExprNoCheck*(c: PContext, n: PNode) = if outputs.len > 0 and c.config.ideCmd in {ideSug, ideCon, ideDef}: produceOutput(outputs, c.config) suggestQuit() - + proc suggestExpr*(c: PContext, n: PNode) = if exactEquals(c.config.m.trackPos, n.info): suggestExprNoCheck(c, n) diff --git a/compiler/varpartitions.nim b/compiler/varpartitions.nim index 1711fea46a..ddba3d4bcb 100644 --- a/compiler/varpartitions.nim +++ b/compiler/varpartitions.nim @@ -1014,6 +1014,6 @@ proc computeCursors*(s: PSym; n: PNode; g: ModuleGraph) = if par.s[rid].con.kind == isRootOf and dangerousMutation(par.graphs[par.s[rid].con.graphIndex], par.s[i]): discard "cannot cursor into a graph that is mutated" else: - v.sym.flags.incl sfCursor + v.sym.flagsImpl.incl sfCursor when false: echo "this is now a cursor ", v.sym, " ", par.s[rid].flags, " ", g.config $ v.sym.info