From cf47a29a83641fe9a1f4875b2c433f2d74d7618d Mon Sep 17 00:00:00 2001 From: araq Date: Sun, 7 Dec 2025 18:40:38 +0100 Subject: [PATCH 01/13] IC: loader: progress --- compiler/ast2nif.nim | 48 ++++++++++++++++---------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index b5f229d94afa..77b51306e693 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -887,24 +887,6 @@ proc loadTypeStub(c: var DecodeContext; n: var Cursor): PType = else: raiseAssert "type expected but got " & $n.kind -proc loadTypeStubWithLocalSyms(c: var DecodeContext; n: var Cursor; thisModule: string; - localSyms: var Table[string, PSym]): PType = - ## Like loadTypeStub but also extracts local symbols from inline type definitions - if n.kind == DotToken: - result = nil - inc n - elif n.kind == Symbol: - let s = n.symId - result = loadTypeStub(c, s) - inc n - elif n.kind == ParLe and n.tagId == tdefTag: - # First extract local symbols from the inline type - let s = n.firstSon.symId - extractLocalSymsFromTree(c, n, thisModule, localSyms) - result = loadTypeStub(c, s) - else: - raiseAssert "type expected but got " & $n.kind - proc loadSymStub(c: var DecodeContext; t: SymId; thisModule: string; localSyms: var Table[string, PSym]): PSym = let symAsStr = pool.syms[t] @@ -1089,12 +1071,9 @@ proc loadSymFromCursor(c: var DecodeContext; s: PSym; n: var Cursor; thisModule: else: loadField s.positionImpl - # For routine symbols, pre-scan the type to find local symbol definitions - # (generic params, params). These sdefs are written inline in the type. - if s.kindImpl in routineKinds: - s.typImpl = loadTypeStubWithLocalSyms(c, n, thisModule, localSyms) - else: - s.typImpl = loadTypeStub(c, n) + # Local symbols were already extracted upfront in loadSym, so we can use + # the simple loadTypeStub here. + s.typImpl = loadTypeStub(c, n) s.ownerFieldImpl = loadSymStub(c, n, thisModule, localSyms) # Load the AST for routine symbols (procs, funcs, etc.) if s.kindImpl in routineKinds: @@ -1118,11 +1097,17 @@ proc loadSym*(c: var DecodeContext; s: PSym) = expect n, ParLe if n.tagId != sdefTag: raiseAssert "(sd) expected" - # Extract line info from the sdef tag before moving past it + + # Pre-scan the ENTIRE symbol definition to extract ALL local symbols upfront. + # This ensures local symbols are registered before any references to them, + # regardless of where they appear in the definition (in types, nested procs, etc.) + var localSyms = initTable[string, PSym]() + var scanCursor = n + extractLocalSymsFromTree(c, scanCursor, c.mods[symsModule].suffix, localSyms) + + # Now parse the symbol definition with all local symbols pre-registered s.infoImpl = c.infos.oldLineInfo(n.info) inc n - # Create localSyms for any local symbols encountered in the AST - var localSyms = initTable[string, PSym]() loadSymFromCursor(c, s, n, c.mods[symsModule].suffix, localSyms) @@ -1132,7 +1117,7 @@ template withNode(c: var DecodeContext; n: var Cursor; result: PNode; kind: TNod let flags = loadAtom(TNodeFlags, n) result = newNodeI(kind, info) result.flags = flags - result.typField = c.loadTypeStub n + result.typField = c.loadTypeStub(n) body skipParRi n @@ -1164,7 +1149,7 @@ proc loadNode(c: var DecodeContext; n: var Cursor; thisModule: string; case pool.tags[n.tagId] of hiddenTypeTagName: inc n - let typ = c.loadTypeStub n + let typ = c.loadTypeStub(n) let info = c.infos.oldLineInfo(n.info) result = newSymNode(c.loadSymStub(n, thisModule, localSyms), info) result.typField = typ @@ -1216,7 +1201,7 @@ proc loadNode(c: var DecodeContext; n: var Cursor; thisModule: string; let info = c.infos.oldLineInfo(n.info) inc n let flags = loadAtom(TNodeFlags, n) - let typ = c.loadTypeStub n + let typ = c.loadTypeStub(n) expect n, Ident result = newIdentNode(c.cache.getIdent(pool.strings[n.litId]), info) inc n @@ -1349,7 +1334,8 @@ proc populateInterfaceTablesFromIndex(c: var DecodeContext; module: FileIndex; continue # skip types let basename = extractBasename(nifName) - let shouldInclude = case kind + let shouldInclude = + case kind of ExportIdx: true # export all of FromexportIdx: basename in nameSet # only specific names of ExportexceptIdx: basename notin nameSet # all except specific names From 39d5ecce1fadb7928ff28ce889e3d1f5d07a1617 Mon Sep 17 00:00:00 2001 From: araq Date: Tue, 9 Dec 2025 13:09:36 +0100 Subject: [PATCH 02/13] IC: progress --- compiler/ast2nif.nim | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index 77b51306e693..de3f9450c13c 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -515,10 +515,21 @@ proc writeNode(w: var Writer; dest: var TokenBuf; n: PNode; forAst = false) = dest.addDotToken else: case n.kind - of nkEmpty, nkNone: + of nkNone: + assert n.typField == nil, "nkNone should not have a type" let info = trLineInfo(w, n.info) dest.addParLe pool.tags.getOrIncl(toNifTag(n.kind)), info dest.addParRi + of nkEmpty: + if n.typField != nil: + w.withNode dest, n: + let info = trLineInfo(w, n.info) + dest.addParLe pool.tags.getOrIncl(toNifTag(n.kind)), info + dest.addParRi + else: + let info = trLineInfo(w, n.info) + dest.addParLe pool.tags.getOrIncl(toNifTag(n.kind)), info + dest.addParRi of nkIdent: # nkIdent uses flags and typ when it is a generic parameter w.withNode dest, n: @@ -1196,6 +1207,9 @@ proc loadNode(c: var DecodeContext; n: var Cursor; thisModule: string; of nkEmpty: result = newNodeI(nkEmpty, c.infos.oldLineInfo(n.info)) inc n + if n.kind != ParRi: + result.flags = loadAtom(TNodeFlags, n) + result.typField = c.loadTypeStub(n) skipParRi n of nkIdent: let info = c.infos.oldLineInfo(n.info) From f77e86de12482c046b3053faee9ec611614b07da Mon Sep 17 00:00:00 2001 From: araq Date: Wed, 10 Dec 2025 00:07:36 +0100 Subject: [PATCH 03/13] progress --- compiler/ast2nif.nim | 124 +++++++++++++++++++++++-------------------- 1 file changed, 65 insertions(+), 59 deletions(-) diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index de3f9450c13c..f90c8807f585 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -217,6 +217,13 @@ proc toNifSymName(w: var Writer; sym: PSym): string = result.add '.' result.add modname(module, w.infos.config) +proc globalName(sym: PSym; config: ConfigRef): string = + result = sym.name.s + result.add '.' + result.addInt sym.disamb + result.add '.' + result.add modname(sym.itemId.module, config) + type ParsedSymName* = object name*: string @@ -271,13 +278,13 @@ proc writeNode(w: var Writer; dest: var TokenBuf; n: PNode; forAst = false) proc writeType(w: var Writer; dest: var TokenBuf; typ: PType) proc writeSym(w: var Writer; dest: var TokenBuf; sym: PSym) -proc typeToNifSym(w: var Writer; typ: PType): string = +proc typeToNifSym(typ: PType; config: ConfigRef): string = result = "`t" result.addInt ord(typ.kind) result.add '.' result.addInt typ.uniqueId.item result.add '.' - result.add modname(typ.uniqueId.module, w.infos.config) + result.add modname(typ.uniqueId.module, config) proc writeLoc(w: var Writer; dest: var TokenBuf; loc: TLoc) = dest.addIdent toNifTag(loc.k) @@ -287,7 +294,7 @@ proc writeLoc(w: var Writer; dest: var TokenBuf; loc: TLoc) = proc writeTypeDef(w: var Writer; dest: var TokenBuf; typ: PType) = dest.buildTree tdefTag: - dest.addSymDef pool.syms.getOrIncl(w.typeToNifSym(typ)), NoLineInfo + dest.addSymDef pool.syms.getOrIncl(typeToNifSym(typ, w.infos.config)), NoLineInfo #dest.addIdent toNifTag(typ.kind) writeFlags(dest, typ.flagsImpl) @@ -319,7 +326,7 @@ proc writeType(w: var Writer; dest: var TokenBuf; typ: PType) = # Collect for later unloading after entire module is written w.writtenTypes.add typ else: - dest.addSymUse pool.syms.getOrIncl(w.typeToNifSym(typ)), NoLineInfo + dest.addSymUse pool.syms.getOrIncl(typeToNifSym(typ, w.infos.config)), NoLineInfo proc writeBool(dest: var TokenBuf; b: bool) = dest.buildTree (if b: "true" else: "false"): @@ -586,12 +593,19 @@ proc writeNode(w: var Writer; dest: var TokenBuf; n: PNode; forAst = false) = # Writing AST inside sdef or anonymous proc: write full structure inc w.inProc var ast = n + var skipParams = false if n[namePos].kind == nkSym: ast = n[namePos].sym.astImpl if ast == nil: ast = n + else: skipParams = true w.withNode dest, ast: for i in 0 ..< ast.len: - writeNode(w, dest, ast[i], forAst) + if i == paramsPos and skipParams: + # Parameter are redundant with s.typ.n and even dangerous as for generic instances + # we do not adapt the symbols properly + addDotToken(dest) + else: + writeNode(w, dest, ast[i], forAst) dec w.inProc of nkLambda, nkDo: # Lambdas are expressions, always write full structure @@ -787,8 +801,8 @@ type DecodeContext* = object infos: LineInfoWriter #moduleIds: Table[string, int32] - types: Table[ItemId, (PType, NifIndexEntry)] - syms: Table[ItemId, (PSym, NifIndexEntry)] + types: Table[string, (PType, NifIndexEntry)] + syms: Table[string, (PSym, NifIndexEntry)] mods: Table[FileIndex, NifModule] cache: IdentCache @@ -841,12 +855,12 @@ proc loadTypeStub(c: var DecodeContext; t: SymId): PType = inc i if i < name.len and name[i] == '.': inc i let suffix = name.substr(i) - let id = ItemId(module: moduleId(c, suffix).int32, item: itemId) - result = c.types.getOrDefault(id)[0] + result = c.types.getOrDefault(name)[0] if result == nil: + let id = ItemId(module: moduleId(c, suffix).int32, item: itemId) let offs = c.getOffset(id.module.FileIndex, name) result = PType(itemId: id, uniqueId: id, kind: TTypeKind(k), state: Partial) - c.types[id] = (result, offs) + c.types[name] = (result, offs) proc extractLocalSymsFromTree(c: var DecodeContext; n: var Cursor; thisModule: string; localSyms: var Table[string, PSym]) = @@ -912,16 +926,16 @@ proc loadSymStub(c: var DecodeContext; t: SymId; thisModule: string; else: raiseAssert "local symbol '" & symAsStr & "' not found in localSyms." # Global symbol - look up in index for lazy loading - let module = moduleId(c, sn.module) - let val = addr c.mods[module].symCounter - inc val[] - - let id = ItemId(module: module.int32, item: val[]) - result = c.syms.getOrDefault(id)[0] + result = c.syms.getOrDefault(symAsStr)[0] if result == nil: + let module = moduleId(c, sn.module) + let val = addr c.mods[module].symCounter + inc val[] + let id = ItemId(module: module.int32, item: val[]) + let offs = c.getOffset(module, symAsStr) result = PSym(itemId: id, kindImpl: skStub, name: c.cache.getIdent(sn.name), disamb: sn.count.int32, state: Partial) - c.syms[id] = (result, offs) + c.syms[symAsStr] = (result, offs) proc loadSymStub(c: var DecodeContext; n: var Cursor; thisModule: string; localSyms: var Table[string, PSym]): PSym = @@ -983,7 +997,8 @@ 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.FileIndex, c.types[t.itemId][1], buf) + let typeName = typeToNifSym(t, c.infos.config) + var n = cursorFromIndexEntry(c, t.itemId.module.FileIndex, c.types[typeName][1], buf) expect n, ParLe if n.tagId != tdefTag: @@ -1103,7 +1118,8 @@ proc loadSym*(c: var DecodeContext; s: PSym) = s.state = Sealed var buf = createTokenBuf(30) let symsModule = s.itemId.module.FileIndex - var n = cursorFromIndexEntry(c, symsModule, c.syms[s.itemId][1], buf) + let nifname = globalName(s, c.infos.config) + var n = cursorFromIndexEntry(c, symsModule, c.syms[nifname][1], buf) expect n, ParLe if n.tagId != sdefTag: @@ -1282,18 +1298,17 @@ proc loadSymFromIndexEntry(c: var DecodeContext; module: FileIndex; nifName: string; entry: NifIndexEntry; thisModule: string): PSym = ## Loads a symbol from the NIF index entry using the entry directly. ## Creates a symbol stub without looking up in the index (since the index may be moved out). - let symAsStr = nifName - let sn = parseSymName(symAsStr) - let symModule = moduleId(c, if sn.module.len > 0: sn.module else: thisModule) - let val = addr c.mods[symModule].symCounter - inc val[] - - let id = ItemId(module: symModule.int32, item: val[]) - result = c.syms.getOrDefault(id)[0] + result = c.syms.getOrDefault(nifName)[0] if result == nil: - # Use the entry directly instead of looking it up in the index + let symAsStr = nifName + let sn = parseSymName(symAsStr) + let symModule = moduleId(c, if sn.module.len > 0: sn.module else: thisModule) + let val = addr c.mods[symModule].symCounter + inc val[] + + let id = ItemId(module: symModule.int32, item: val[]) result = PSym(itemId: id, kindImpl: skStub, name: c.cache.getIdent(sn.name), disamb: sn.count.int32, state: Partial) - c.syms[id] = (result, entry) + c.syms[symAsStr] = (result, entry) proc extractBasename(nifName: string): string = ## Extract the base name from a NIF name (ident.disamb.module -> ident) @@ -1400,52 +1415,43 @@ proc parseTypeSymIdToItemId*(c: var DecodeContext; symId: nifstreams.SymId): Ite else: result = ItemId(module: -1, item: item) -proc resolveHookSym*(c: var DecodeContext; symId: nifstreams.SymId): PSym = - ## Resolves a hook SymId to PSym. - let symAsStr = pool.syms[symId] +proc resolveSym(c: var DecodeContext; symAsStr: string; alsoConsiderPrivate: bool): PSym = + result = c.syms.getOrDefault(symAsStr)[0] + if result != nil: + return result + let sn = parseSymName(symAsStr) if sn.module.len == 0: return nil # Local symbols shouldn't be hooks let module = moduleId(c, sn.module) # Look up the symbol in the module's index - let offs = c.mods[module].index.public.getOrDefault(symAsStr) + var offs = c.mods[module].index.public.getOrDefault(symAsStr) if offs.offset == 0: - return nil + if alsoConsiderPrivate: + offs = c.mods[module].index.private.getOrDefault(symAsStr) + if offs.offset == 0: + return nil + else: + return nil # Create a stub symbol let val = addr c.mods[module].symCounter inc val[] let id = ItemId(module: int32(module), item: val[]) - result = c.syms.getOrDefault(id)[0] - if result == nil: - result = PSym(itemId: id, kindImpl: skProc, name: c.cache.getIdent(sn.name), - disamb: sn.count.int32, state: Partial) - c.syms[id] = (result, offs) + result = PSym(itemId: id, kindImpl: skProc, name: c.cache.getIdent(sn.name), + disamb: sn.count.int32, state: Partial) + c.syms[symAsStr] = (result, offs) + +proc resolveHookSym*(c: var DecodeContext; symId: nifstreams.SymId): PSym = + ## Resolves a hook SymId to PSym. + let symAsStr = pool.syms[symId] + result = resolveSym(c, symAsStr, false) proc tryResolveCompilerProc*(c: var DecodeContext; name: string; moduleFileIdx: FileIndex): PSym = ## Tries to resolve a compiler proc from a module by checking the NIF index. ## Returns nil if the symbol doesn't exist. let suffix = moduleSuffix(c.infos.config, moduleFileIdx) let symName = name & ".0." & suffix - - # Check if module index is loaded, if not load it - let module = moduleId(c, suffix) - - # Check if symbol exists in the index (check both public and private) - var offs = c.mods[module].index.public.getOrDefault(symName) - if offs.offset == 0: - offs = c.mods[module].index.private.getOrDefault(symName) - if offs.offset == 0: - return nil - - # Create a stub symbol - let val = addr c.mods[module].symCounter - inc val[] - let id = ItemId(module: int32(module), item: val[]) - result = c.syms.getOrDefault(id)[0] - if result == nil: - result = PSym(itemId: id, kindImpl: skProc, name: c.cache.getIdent(name), - disamb: 0, state: Partial) - c.syms[id] = (result, offs) + result = resolveSym(c, symName, true) proc loadNifModule*(c: var DecodeContext; f: FileIndex; interf, interfHidden: var TStrTable; hooks: var Table[nifstreams.SymId, HooksPerType]; From 447bf7e1986f275eeeb68780b91465d248dadd8e Mon Sep 17 00:00:00 2001 From: Araq Date: Wed, 10 Dec 2025 00:57:19 +0100 Subject: [PATCH 04/13] progress --- compiler/ast2nif.nim | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index f90c8807f585..8e6797aea2de 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -205,13 +205,17 @@ const # Symbol kinds that are always local to a proc and should never have module suffix skLocalSymKinds = {skParam, skGenericParam, skForVar, skResult, skTemp} +proc isLocalSym(sym: PSym): bool {.inline.} = + sym.kindImpl in skLocalSymKinds or + (sym.kindImpl in {skVar, skLet} and {sfGlobal, sfThread} * sym.flagsImpl == {}) + proc toNifSymName(w: var Writer; sym: PSym): string = ## Generate NIF name for a symbol: local names are `ident.disamb`, ## global names are `ident.disamb.moduleSuffix` result = sym.name.s result.add '.' result.addInt sym.disamb - if sym.kindImpl notin skLocalSymKinds and sym.itemId notin w.locals: + if not isLocalSym(sym) and sym.itemId notin w.locals: # Global symbol: ident.disamb.moduleSuffix let module = sym.itemId.module result.add '.' @@ -305,6 +309,8 @@ proc writeTypeDef(w: var Writer; dest: var TokenBuf; typ: PType) = dest.addIntLit typ.itemId.item # nonUniqueId writeType(w, dest, typ.typeInstImpl) + #if typ.kind in {tyProc, tyIterator} and typ.nImpl != nil and typ.nImpl.kind != nkFormalParams: + writeNode(w, dest, typ.nImpl) writeSym(w, dest, typ.ownerFieldImpl) writeSym(w, dest, typ.symImpl) @@ -342,8 +348,6 @@ proc writeLib(w: var Writer; dest: var TokenBuf; lib: PLib) = dest.addStrLit lib.name writeNode w, dest, lib.path -proc writeSymDef(w: var Writer; dest: var TokenBuf; sym: PSym) # forward declaration - proc collectGenericParams(w: var Writer; n: PNode) = ## Pre-collect generic param symbols into w.locals before writing the type. ## This ensures generic params get consistent short names, and their sdefs @@ -428,7 +432,7 @@ proc shouldWriteSymDef(w: Writer; sym: PSym): bool {.inline.} = # (due to being in w.locals or being in skLocalSymKinds), it MUST have an sdef. # Otherwise it gets written as a bare SymUse and can't be found when loading. if sym.itemId.module == w.currentModule: - if sym.itemId in w.locals or sym.kindImpl in skLocalSymKinds: + if sym.itemId in w.locals or isLocalSym(sym): return true # Would be written without module suffix, needs sdef if sym.state == Complete: return true # Normal case for global symbols From 7fd02fc31a2c7cdf60c0e8673b6d610cf3ea4003 Mon Sep 17 00:00:00 2001 From: araq Date: Wed, 10 Dec 2025 12:31:44 +0100 Subject: [PATCH 05/13] progress --- compiler/ast.nim | 19 +-- compiler/ast2nif.nim | 2 + compiler/astdef.nim | 3 +- compiler/ccgcalls.nim | 4 +- compiler/ccgexprs.nim | 2 +- compiler/cgen.nim | 2 +- compiler/cgmeth.nim | 2 +- compiler/closureiters.nim | 4 +- compiler/docgen.nim | 2 +- compiler/evalffi.nim | 14 +-- compiler/evaltempl.nim | 2 +- compiler/guards.nim | 4 +- compiler/ic/enum2nif.nim | 4 + compiler/ic/ic.nim | 4 +- compiler/injectdestructors.nim | 14 +-- compiler/lambdalifting.nim | 4 +- compiler/liftdestructors.nim | 58 ++++----- compiler/liftlocals.nim | 4 +- compiler/lowerings.nim | 26 ++-- compiler/magicsys.nim | 2 +- compiler/nilcheck.nim | 4 +- compiler/nimsets.nim | 4 +- compiler/pragmas.nim | 4 +- compiler/sem.nim | 20 ++-- compiler/semcall.nim | 26 ++-- compiler/semdata.nim | 28 ++--- compiler/semexprs.nim | 198 +++++++++++++++---------------- compiler/semfields.nim | 2 +- compiler/semfold.nim | 28 ++--- compiler/semgnrc.nim | 20 ++-- compiler/seminst.nim | 2 +- compiler/semmacrosanity.nim | 22 ++-- compiler/semmagic.nim | 38 +++--- compiler/semobjconstr.nim | 4 +- compiler/semparallel.nim | 4 +- compiler/sempass2.nim | 10 +- compiler/semstmts.nim | 48 ++++---- compiler/semtempl.nim | 14 +-- compiler/semtypes.nim | 24 ++-- compiler/semtypinst.nim | 6 +- compiler/sigmatch.nim | 48 ++++---- compiler/sizealignoffsetimpl.nim | 6 +- compiler/spawn.nim | 10 +- compiler/transf.nim | 30 ++--- compiler/types.nim | 10 +- compiler/vm.nim | 16 +-- compiler/vmdeps.nim | 8 +- compiler/vmgen.nim | 12 +- compiler/vtables.nim | 4 +- tools/enumgen.nim | 4 +- 50 files changed, 421 insertions(+), 409 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index 67f111c984dd..3f6bf4c40693 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -29,9 +29,6 @@ export astdef when not defined(nimKochBootstrap): import ast2nif -template typ*(n: PNode): PType = - n.typField - when not defined(nimKochBootstrap): var program* {.threadvar.}: DecodeContext @@ -426,6 +423,14 @@ proc excl*(t: PType; flags: set[TTypeFlag]) {.inline.} = if t.state == Partial: loadType(t) t.flagsImpl.excl(flags) +proc typ*(n: PNode): PType {.inline.} = + result = n.typField + if result == nil and nfLazyType in n.flags: + result = n.sym.typ + +proc `typ=`*(n: PNode, val: sink PType) {.inline.} = + n.typField = val + template nodeId(n: PNode): int = cast[int](n) type Gconfig = object @@ -769,7 +774,7 @@ proc withInfo*(n: PNode, info: TLineInfo): PNode = proc newSymNode*(sym: PSym): PNode = result = newNode(nkSym) result.sym = sym - result.typ() = sym.typ + result.typField = sym.typ result.info = sym.info proc newOpenSym*(n: PNode): PNode {.inline.} = @@ -879,7 +884,7 @@ proc newIntTypeNode*(intVal: BiggestInt, typ: PType): PNode = result = newNode(nkIntLit) else: raiseAssert $kind result.intVal = intVal - result.typ() = typ + result.typField = typ proc newIntTypeNode*(intVal: Int128, typ: PType): PNode = # XXX: introduce range check @@ -1180,7 +1185,7 @@ proc copyNode*(src: PNode): PNode = return nil result = newNode(src.kind) result.info = src.info - result.typ() = src.typ + result.typ = src.typ result.flags = src.flags * PersistentNodeFlags result.comment = src.comment when defined(useNodeIds): @@ -1249,7 +1254,7 @@ template copyNodeImpl(dst, src, processSonsStmt) = dst.info = src.info when defined(nimsuggest): result.endInfo = src.endInfo - dst.typ() = src.typ + dst.typ = src.typ dst.flags = src.flags * PersistentNodeFlags dst.comment = src.comment when defined(useNodeIds): diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index 8e6797aea2de..a7d4de8906f5 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -1166,6 +1166,8 @@ proc loadNode(c: var DecodeContext; n: var Cursor; thisModule: string; inc n else: result = newSymNode(c.loadSymStub(n, thisModule, localSyms), info) + if result.typField == nil: + result.flags.incl nfLazyType of DotToken: result = nil inc n diff --git a/compiler/astdef.nim b/compiler/astdef.nim index ffd02f3a96d4..2aefc7659ffd 100644 --- a/compiler/astdef.nim +++ b/compiler/astdef.nim @@ -323,6 +323,7 @@ type nfDisabledOpenSym # temporary: node should be nkOpenSym but cannot # because openSym experimental switch is disabled # gives warning instead + nfLazyType # node has a lazy type TNodeFlags* = set[TNodeFlag] TTypeFlag* = enum # keep below 32 for efficiency reasons (now: 47) @@ -866,7 +867,7 @@ const nfFromTemplate, nfDefaultRefsParam, nfExecuteOnReload, nfLastRead, nfFirstWrite, nfSkipFieldChecking, - nfDisabledOpenSym} + nfDisabledOpenSym, nfLazyType} namePos* = 0 patternPos* = 1 # empty except for term rewriting macros genericParamsPos* = 2 diff --git a/compiler/ccgcalls.nim b/compiler/ccgcalls.nim index e520f89f66af..f4169315e446 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -368,7 +368,7 @@ proc genArg(p: BProc, n: PNode, param: PSym; call: PNode; result: var Builder; n # variable. Thus, we create a temporary pointer variable instead. let needsIndirect = mapType(p.config, n[0].typ, mapTypeChooser(n[0]) == skParam) != ctArray if needsIndirect: - n.typ() = n.typ.exactReplica + n.typ = n.typ.exactReplica n.typ.incl tfVarIsPtr a = initLocExprSingleUse(p, n) a = withTmpIfNeeded(p, a, needsTmp) @@ -498,7 +498,7 @@ proc genClosureCall(p: BProc, le, ri: PNode, d: var TLoc) = else: cCall(p, params, e) cIfExpr(e, - eCall, + eCall, cCall(cCast(pTyp, p), params)) template callIter(rp, params: Snippet): Snippet = diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 20b1db25e62f..4bc8193ecb52 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1916,7 +1916,7 @@ proc genSeqConstr(p: BProc, n: PNode, d: var TLoc) = proc genArrToSeq(p: BProc, n: PNode, d: var TLoc) = var elem, arr: TLoc if n[1].kind == nkBracket: - n[1].typ() = n.typ + n[1].typ = n.typ genSeqConstr(p, n[1], d) return if d.k == locNone: diff --git a/compiler/cgen.nim b/compiler/cgen.nim index a932c180ff5c..d3d68970f8ef 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -97,7 +97,7 @@ proc t(a: TLoc): PType {.inline.} = proc lodeTyp(t: PType): PNode = result = newNode(nkEmpty) - result.typ() = t + result.typ = t proc isSimpleConst(typ: PType): bool = let t = skipTypes(typ, abstractVar) diff --git a/compiler/cgmeth.nim b/compiler/cgmeth.nim index 2d1e7ed0fd4a..924d03314447 100644 --- a/compiler/cgmeth.nim +++ b/compiler/cgmeth.nim @@ -55,7 +55,7 @@ proc methodCall*(n: PNode; conf: ConfigRef): PNode = # replace ordinary method by dispatcher method: let disp = getDispatcher(result[0].sym) if disp != nil: - result[0].typ() = disp.typ + result[0].typ = disp.typ result[0].sym = disp # change the arguments to up/downcasts to fit the dispatcher's parameters: for i in 1.. 0: var asgnExpr = newTree(nkObjConstr, newNodeIT(nkType, a.info, aTyp)) - asgnExpr.typ() = aTyp + asgnExpr.typ = aTyp asgnExpr.sons.add child result = semExpr(c, asgnExpr) else: @@ -710,11 +710,11 @@ proc defaultNodeField(c: PContext, a: PNode, aTyp: PType, checkDefault: bool): P let node = newNode(nkIntLit) node.intVal = toInt64(lengthOrd(c.graph.config, aTypSkip)) let typeNode = newNode(nkType) - typeNode.typ() = makeTypeDesc(c, aTypSkip[1]) + typeNode.typ = makeTypeDesc(c, aTypSkip[1]) result = semExpr(c, newTree(nkCall, newTree(nkBracketExpr, newSymNode(getSysSym(c.graph, a.info, "arrayWithDefault"), a.info), typeNode), node )) - result.typ() = aTyp + result.typ = aTyp else: result = nil of tyTuple: @@ -723,7 +723,7 @@ proc defaultNodeField(c: PContext, a: PNode, aTyp: PType, checkDefault: bool): P let children = defaultFieldsForTuple(c, aTypSkip.n, hasDefault, checkDefault) if hasDefault and children.len > 0: result = newNodeI(nkTupleConstr, a.info) - result.typ() = aTyp + result.typ = aTyp result.sons.add children result = semExpr(c, result) else: diff --git a/compiler/semcall.nim b/compiler/semcall.nim index c07a79f5d1e5..77a86d9d74b4 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -695,7 +695,7 @@ proc instGenericConvertersArg*(c: PContext, a: PNode, x: TCandidate) = internalError(c.config, a.info, "generic converter failed rematch") let finalCallee = generateInstance(c, s, convMatch.bindings, a.info) a[0].sym = finalCallee - a[0].typ() = finalCallee.typ + a[0].typ = finalCallee.typ #a.typ = finalCallee.typ.returnType proc instGenericConvertersSons*(c: PContext, n: PNode, x: TCandidate) = @@ -730,13 +730,13 @@ proc inferWithMetatype(c: PContext, formal: PType, # This almost exactly replicates the steps taken by the compiler during # param matching. It performs an embarrassing amount of back-and-forth # type jugling, but it's the price to pay for consistency and correctness - result.typ() = generateTypeInstance(c, m.bindings, arg.info, + result.typ = generateTypeInstance(c, m.bindings, arg.info, formal.skipTypes({tyCompositeTypeClass})) else: typeMismatch(c.config, arg.info, formal, arg.typ, arg) # error correction: result = copyTree(arg) - result.typ() = formal + result.typ = formal proc updateDefaultParams(c: PContext, call: PNode) = # In generic procs, the default parameter may be unique for each @@ -759,7 +759,7 @@ proc updateDefaultParams(c: PContext, call: PNode) = pushInfoContext(c.config, call.info, call[0].sym.detailedInfo) typeMismatch(c.config, def.info, formal.typ, def.typ, formal.ast) popInfoContext(c.config) - def.typ() = errorType(c) + def.typ = errorType(c) call[i] = def proc getCallLineInfo(n: PNode): TLineInfo = @@ -846,7 +846,7 @@ proc semResolvedCall(c: PContext, x: var TCandidate, result = x.call result[0] = newSymNode(finalCallee, getCallLineInfo(result[0])) if containsGenericType(result.typ): - result.typ() = newTypeS(tyError, c) + result.typ = newTypeS(tyError, c) incl result.typ, tfCheckedForDestructor return let gp = finalCallee.ast[genericParamsPos] @@ -873,7 +873,7 @@ proc semResolvedCall(c: PContext, x: var TCandidate, # this node will be used in template substitution, # pretend this is an untyped node and let regular sem handle the type # to prevent problems where a generic parameter is treated as a value - tn.typ() = nil + tn.typ = nil x.call.add tn else: internalAssert c.config, false @@ -885,7 +885,7 @@ proc semResolvedCall(c: PContext, x: var TCandidate, markConvertersUsed(c, result) result[0] = newSymNode(finalCallee, getCallLineInfo(result[0])) if finalCallee.magic notin {mArrGet, mArrPut}: - result.typ() = finalCallee.typ.returnType + result.typ = finalCallee.typ.returnType updateDefaultParams(c, result) proc canDeref(n: PNode): bool {.inline.} = @@ -894,7 +894,7 @@ proc canDeref(n: PNode): bool {.inline.} = proc tryDeref(n: PNode): PNode = result = newNodeI(nkHiddenDeref, n.info) - result.typ() = n.typ.skipTypes(abstractInst)[0] + result.typ = n.typ.skipTypes(abstractInst)[0] result.add n proc semOverloadedCall(c: PContext, n, nOrig: PNode, @@ -913,7 +913,7 @@ proc semOverloadedCall(c: PContext, n, nOrig: PNode, else: if c.inGenericContext > 0 and c.matchedConcept == nil: result = semGenericStmt(c, n) - result.typ() = makeTypeFromExpr(c, result.copyTree) + result.typ = makeTypeFromExpr(c, result.copyTree) elif efNoUndeclared in flags: result = nil elif efExplain notin flags: @@ -964,9 +964,9 @@ proc setGenericParams(c: PContext, n, expectedParams: PNode) = nil e = semExprWithType(c, n[i], expectedType = constraint) if e.typ == nil: - n[i].typ() = errorType(c) + n[i].typ = errorType(c) else: - n[i].typ() = e.typ.skipTypes({tyTypeDesc}) + n[i].typ = e.typ.skipTypes({tyTypeDesc}) proc explicitGenericInstantiation(c: PContext, n: PNode, s: PSym, doError: bool): PNode = assert n.kind == nkBracketExpr @@ -983,7 +983,7 @@ proc explicitGenericInstantiation(c: PContext, n: PNode, s: PSym, doError: bool) # same as in semOverloadedCall, make expression untyped, # may have failed match due to unresolved types result = semGenericStmt(c, n) - result.typ() = makeTypeFromExpr(c, result.copyTree) + result.typ = makeTypeFromExpr(c, result.copyTree) elif doError: notFoundError(c, n, errors) elif a.kind in {nkClosedSymChoice, nkOpenSymChoice}: @@ -1001,7 +1001,7 @@ proc explicitGenericInstantiation(c: PContext, n: PNode, s: PSym, doError: bool) # any failing match stops building the symchoice for correctness, # can also make it untyped from the start result = semGenericStmt(c, n) - result.typ() = makeTypeFromExpr(c, result.copyTree) + result.typ = makeTypeFromExpr(c, result.copyTree) return # get rid of nkClosedSymChoice if not ambiguous: if result.len == 0: diff --git a/compiler/semdata.nim b/compiler/semdata.nim index c29429370ee5..b1dd28ec4ca8 100644 --- a/compiler/semdata.nim +++ b/compiler/semdata.nim @@ -201,29 +201,29 @@ proc getIntLitType*(c: PContext; literal: PNode): PType = proc setIntLitType*(c: PContext; result: PNode) = let i = result.intVal case c.config.target.intSize - of 8: result.typ() = getIntLitType(c, result) + of 8: result.typ = getIntLitType(c, result) of 4: if i >= low(int32) and i <= high(int32): - result.typ() = getIntLitType(c, result) + result.typ = getIntLitType(c, result) else: - result.typ() = getSysType(c.graph, result.info, tyInt64) + result.typ = getSysType(c.graph, result.info, tyInt64) of 2: if i >= low(int16) and i <= high(int16): - result.typ() = getIntLitType(c, result) + result.typ = getIntLitType(c, result) elif i >= low(int32) and i <= high(int32): - result.typ() = getSysType(c.graph, result.info, tyInt32) + result.typ = getSysType(c.graph, result.info, tyInt32) else: - result.typ() = getSysType(c.graph, result.info, tyInt64) + result.typ = getSysType(c.graph, result.info, tyInt64) of 1: # 8 bit CPUs are insane ... if i >= low(int8) and i <= high(int8): - result.typ() = getIntLitType(c, result) + result.typ = getIntLitType(c, result) elif i >= low(int16) and i <= high(int16): - result.typ() = getSysType(c.graph, result.info, tyInt16) + result.typ = getSysType(c.graph, result.info, tyInt16) elif i >= low(int32) and i <= high(int32): - result.typ() = getSysType(c.graph, result.info, tyInt32) + result.typ = getSysType(c.graph, result.info, tyInt32) else: - result.typ() = getSysType(c.graph, result.info, tyInt64) + result.typ = getSysType(c.graph, result.info, tyInt64) else: internalError(c.config, result.info, "invalid int size") @@ -460,7 +460,7 @@ when false: proc makeStaticExpr*(c: PContext, n: PNode): PNode = result = newNodeI(nkStaticExpr, n.info) result.sons = @[n] - result.typ() = if n.typ != nil and n.typ.kind == tyStatic: n.typ + result.typ = if n.typ != nil and n.typ.kind == tyStatic: n.typ else: newTypeS(tyStatic, c, n.typ) proc makeAndType*(c: PContext, t1, t2: PType): PType = @@ -519,7 +519,7 @@ proc errorType*(c: PContext): PType = proc errorNode*(c: PContext, n: PNode): PNode = result = newNodeI(nkEmpty, n.info) - result.typ() = errorType(c) + result.typ = errorType(c) # These mimic localError template localErrorNode*(c: PContext, n: PNode, info: TLineInfo, msg: TMsgKind, arg: string): PNode = @@ -575,7 +575,7 @@ proc symFromType*(c: PContext; t: PType, info: TLineInfo): PSym = proc symNodeFromType*(c: PContext, t: PType, info: TLineInfo): PNode = result = newSymNode(symFromType(c, t, info), info) - result.typ() = makeTypeDesc(c, t) + result.typ = makeTypeDesc(c, t) proc markIndirect*(c: PContext, s: PSym) {.inline.} = if s.kind in {skProc, skFunc, skConverter, skMethod, skIterator}: @@ -789,7 +789,7 @@ proc replaceHookMagic*(c: PContext, n: PNode, kind: TTypeAttachedOp): PNode = result[0] = newSymNode(op) if op.typ.len == 3: let boolLit = newIntLit(c.graph, n.info, 1) - boolLit.typ() = getSysType(c.graph, n.info, tyBool) + boolLit.typ = getSysType(c.graph, n.info, tyBool) result.add boolLit of attachedWasMoved: result = n diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 31b3770459d7..e17d2b42dc93 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -55,11 +55,11 @@ proc semOperand(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = if result.typ != nil: if result.typ.kind in {tyVar, tyLent}: result = newDeref(result) elif {efWantStmt, efAllowStmt} * flags != {}: - result.typ() = newTypeS(tyVoid, c) + result.typ = newTypeS(tyVoid, c) else: localError(c.config, n.info, errExprXHasNoType % renderTree(result, {renderNoComments})) - result.typ() = errorType(c) + result.typ = errorType(c) proc semExprCheck(c: PContext, n: PNode, flags: TExprFlags, expectedType: PType = nil): PNode = rejectEmptyNode(n) @@ -81,14 +81,14 @@ proc semExprCheck(c: PContext, n: PNode, flags: TExprFlags, expectedType: PType proc semExprWithType(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType = nil): PNode = result = semExprCheck(c, n, flags-{efTypeAllowed}, expectedType) if result.typ == nil and efInTypeof in flags: - result.typ() = c.voidType + result.typ = c.voidType elif result.typ == nil or result.typ == c.enforceVoidContext: localError(c.config, n.info, errExprXHasNoType % renderTree(result, {renderNoComments})) - result.typ() = errorType(c) + result.typ = errorType(c) elif result.typ.kind == tyError: # associates the type error to the current owner - result.typ() = errorType(c) + result.typ = errorType(c) elif efTypeAllowed in flags and result.typ.kind == tyProc and hasUnresolvedParams(result, {}): # mirrored with semOperand but only on efTypeAllowed @@ -100,7 +100,7 @@ proc semExprWithType(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType else: errProcHasNoConcreteType % n.renderTree localError(c.config, n.info, err) - result.typ() = errorType(c) + result.typ = errorType(c) else: if result.typ.kind in {tyVar, tyLent}: result = newDeref(result) @@ -109,7 +109,7 @@ proc semExprNoDeref(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = if result.typ == nil: localError(c.config, n.info, errExprXHasNoType % renderTree(result, {renderNoComments})) - result.typ() = errorType(c) + result.typ = errorType(c) proc semSymGenericInstantiation(c: PContext, n: PNode, s: PSym): PNode = result = symChoice(c, n, s, scClosed) @@ -195,7 +195,7 @@ proc semOpenSym(c: PContext, n: PNode, flags: TExprFlags, expectedType: PType, result = nil if not isSym: # set symchoice node type back to None - n.typ() = newTypeS(tyNone, c) + n.typ = newTypeS(tyNone, c) proc semSymChoice(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType = nil): PNode = if n.kind == nkOpenSymChoice: @@ -217,7 +217,7 @@ proc semSymChoice(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: P err.add " " & candidate.owner.name.s & "." & candidate.name.s err.add ": " & typeToString(candidate.typ) & "\n" localError(c.config, n.info, err) - n.typ() = errorType(c) + n.typ = errorType(c) result = n if result.kind == nkSym: result = semSym(c, result, result.sym, flags) @@ -228,7 +228,7 @@ proc inlineConst(c: PContext, n: PNode, s: PSym): PNode {.inline.} = localError(c.config, n.info, "constant of type '" & typeToString(s.typ) & "' has no value") result = newSymNode(s) else: - result.typ() = s.typ + result.typ = s.typ result.info = n.info type @@ -396,7 +396,7 @@ proc semConv(c: PContext, n: PNode; flags: TExprFlags = {}, expectedType: PType var evaluated = semStaticExpr(c, n[1], expectedType) if evaluated.kind == nkType or evaluated.typ.kind == tyTypeDesc: result = n - result.typ() = c.makeTypeDesc semStaticType(c, evaluated, nil) + result.typ = c.makeTypeDesc semStaticType(c, evaluated, nil) return elif targetType.base.kind == tyNone: return evaluated @@ -414,7 +414,7 @@ proc semConv(c: PContext, n: PNode; flags: TExprFlags = {}, expectedType: PType if targetType.kind == tyOwned: t.incl tfHasOwned result = newNodeI(nkType, n.info) - result.typ() = makeTypeDesc(c, t) + result.typ = makeTypeDesc(c, t) return result.add copyTree(n[0]) @@ -430,10 +430,10 @@ proc semConv(c: PContext, n: PNode; flags: TExprFlags = {}, expectedType: PType if targetType.kind != tyGenericParam and targetType.isMetaType: let final = inferWithMetatype(c, targetType, op, true) result.add final - result.typ() = final.typ + result.typ = final.typ return - result.typ() = targetType + result.typ = targetType # XXX op is overwritten later on, this is likely added too early # here or needs to be overwritten too then. result.add op @@ -441,7 +441,7 @@ proc semConv(c: PContext, n: PNode; flags: TExprFlags = {}, expectedType: PType if targetType.kind == tyGenericParam or (op.typ != nil and op.typ.kind == tyFromExpr and c.inGenericContext > 0): # expression is compiled early in a generic body - result.typ() = makeTypeFromExpr(c, copyTree(result)) + result.typ = makeTypeFromExpr(c, copyTree(result)) return result if not isSymChoice(op): @@ -491,7 +491,7 @@ proc semCast(c: PContext, n: PNode): PNode = if not isCastable(c, targetType, castedExpr.typ, n.info): localError(c.config, n.info, "expression cannot be cast to '$1'" % $targetType) result = newNodeI(nkCast, n.info) - result.typ() = targetType + result.typ = targetType result.add copyTree(n[0]) result.add castedExpr @@ -505,18 +505,18 @@ proc semLowHigh(c: PContext, n: PNode, m: TMagic): PNode = var typ = skipTypes(n[1].typ, abstractVarRange + {tyTypeDesc, tyUserTypeClassInst}) case typ.kind of tySequence, tyString, tyCstring, tyOpenArray, tyVarargs: - n.typ() = getSysType(c.graph, n.info, tyInt) + n.typ = getSysType(c.graph, n.info, tyInt) of tyArray: - n.typ() = typ.indexType + n.typ = typ.indexType if n.typ.kind == tyRange and emptyRange(n.typ.n[0], n.typ.n[1]): #Invalid range - n.typ() = getSysType(c.graph, n.info, tyInt) + n.typ = getSysType(c.graph, n.info, tyInt) of tyInt..tyInt64, tyChar, tyBool, tyEnum, tyUInt..tyUInt64, tyFloat..tyFloat64: - n.typ() = n[1].typ.skipTypes({tyTypeDesc}) + n.typ = n[1].typ.skipTypes({tyTypeDesc}) of tyGenericParam: # prepare this for resolving in semtypinst: # we must use copyTree here in order to avoid creating a cycle # that could easily turn into an infinite recursion in semtypinst - n.typ() = makeTypeFromExpr(c, n.copyTree) + n.typ = makeTypeFromExpr(c, n.copyTree) else: localError(c.config, n.info, "invalid argument for: " & opToStr[m]) result = n @@ -532,7 +532,7 @@ proc fixupStaticType(c: PContext, n: PNode) = # apply this measure only in code that is enlightened to work # with static types. if n.typ.kind != tyStatic: - n.typ() = newTypeS(tyStatic, c, n.typ) + n.typ = newTypeS(tyStatic, c, n.typ) n.typ.n = n # XXX: cycles like the one here look dangerous. # Consider using `n.copyTree` @@ -582,7 +582,7 @@ proc isOpImpl(c: PContext, n: PNode, flags: TExprFlags): PNode = # `res = sameType(t1, t2)` would be wrong, e.g. for `int is (int|float)` result = newIntNode(nkIntLit, ord(res)) - result.typ() = n.typ + result.typ = n.typ proc semIs(c: PContext, n: PNode, flags: TExprFlags): PNode = if n.len != 3 or n[2].kind == nkEmpty: @@ -591,7 +591,7 @@ proc semIs(c: PContext, n: PNode, flags: TExprFlags): PNode = let boolType = getSysType(c.graph, n.info, tyBool) result = n - n.typ() = boolType + n.typ = boolType var liftLhs = true n[1] = semExprWithType(c, n[1], {efDetermineType, efWantIterator}) @@ -605,7 +605,7 @@ proc semIs(c: PContext, n: PNode, flags: TExprFlags): PNode = n[1] = evaluated else: result = newIntNode(nkIntLit, 0) - result.typ() = boolType + result.typ = boolType return elif t2.kind == tyTypeDesc and (t2.base.kind == tyNone or tfExplicit in t2.flags): @@ -635,7 +635,7 @@ proc semOpAux(c: PContext, n: PNode) = let info = a[0].info a[0] = newIdentNode(considerQuotedIdent(c, a[0], a), info) a[1] = semExprWithType(c, a[1], flags) - a.typ() = a[1].typ + a.typ = a[1].typ else: n[i] = semExprWithType(c, a, flags) @@ -708,7 +708,7 @@ proc changeType(c: PContext; n: PNode, newType: PType, check: bool) = localError(c.config, n.info, "cannot convert '" & n.sym.name.s & "' to '" & typeNameAndDesc(newType) & "'") else: discard - n.typ() = newType + n.typ = newType proc arrayConstrType(c: PContext, n: PNode): PType = var typ = newTypeS(tyArray, c) @@ -730,12 +730,12 @@ proc semArrayConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PTyp var expectedElementType, expectedIndexType: PType = nil var expectedBase: PType = nil if constructType: - result.typ() = newTypeS(tyArray, c) + result.typ = newTypeS(tyArray, c) rawAddSon(result.typ, nil) # index type if expectedType != nil: expectedBase = expectedType.skipTypes(abstractRange-{tyDistinct}) else: - result.typ() = n.typ + result.typ = n.typ expectedBase = n.typ.skipTypes(abstractRange) # include tyDistinct this time if expectedBase != nil: case expectedBase.kind @@ -815,9 +815,9 @@ proc semArrayConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PTyp for i in 0.. 0: # don't make assumptions, entire expression needs to be tyFromExpr result = semGenericStmt(c, n) - result.typ() = makeTypeFromExpr(c, result.copyTree) + result.typ = makeTypeFromExpr(c, result.copyTree) return else: n[0] = n0 @@ -1361,7 +1361,7 @@ proc semSym(c: PContext, n: PNode, sym: PSym, flags: TExprFlags): PNode = of tyStatic: if typ.n != nil: result = typ.n - result.typ() = typ.base + result.typ = typ.base else: result = newSymNode(s, n.info) else: @@ -1407,11 +1407,11 @@ proc semSym(c: PContext, n: PNode, sym: PSym, flags: TExprFlags): PNode = onUse(n.info, s) if s.typ.kind == tyStatic: result = newSymNode(s, n.info) - result.typ() = s.typ + result.typ = s.typ elif s.ast != nil: result = semExpr(c, s.ast) else: - n.typ() = s.typ + n.typ = s.typ return n of skType: if n.kind != nkDotExpr: # dotExpr is already checked by builtinFieldAccess @@ -1422,7 +1422,7 @@ proc semSym(c: PContext, n: PNode, sym: PSym, flags: TExprFlags): PNode = if s.typ.kind == tyStatic and s.typ.base.kind != tyNone and s.typ.n != nil: return s.typ.n result = newSymNode(s, n.info) - result.typ() = makeTypeDesc(c, s.typ) + result.typ = makeTypeDesc(c, s.typ) of skField: # old code, not sure if it's live code: markUsed(c, n.info, s) @@ -1448,7 +1448,7 @@ proc tryReadingGenericParam(c: PContext, n: PNode, i: PIdent, t: PType): PNode = if result == c.graph.emptyNode: if c.inGenericContext > 0: result = semGenericStmt(c, n) - result.typ() = makeTypeFromExpr(c, result.copyTree) + result.typ = makeTypeFromExpr(c, result.copyTree) else: result = nil of tyUserTypeClasses: @@ -1456,7 +1456,7 @@ proc tryReadingGenericParam(c: PContext, n: PNode, i: PIdent, t: PType): PNode = result = readTypeParameter(c, t, i, n.info) elif c.inGenericContext > 0: result = semGenericStmt(c, n) - result.typ() = makeTypeFromExpr(c, copyTree(result)) + result.typ = makeTypeFromExpr(c, copyTree(result)) else: result = nil of tyGenericBody, tyCompositeTypeClass: @@ -1465,12 +1465,12 @@ proc tryReadingGenericParam(c: PContext, n: PNode, i: PIdent, t: PType): PNode = if result != nil: # generic parameter exists, stop here but delay until instantiation result = semGenericStmt(c, n) - result.typ() = makeTypeFromExpr(c, copyTree(result)) + result.typ = makeTypeFromExpr(c, copyTree(result)) else: result = nil elif c.inGenericContext > 0 and t.containsUnresolvedType: result = semGenericStmt(c, n) - result.typ() = makeTypeFromExpr(c, copyTree(result)) + result.typ = makeTypeFromExpr(c, copyTree(result)) else: result = nil @@ -1488,14 +1488,14 @@ proc tryReadingTypeField(c: PContext, n: PNode, i: PIdent, ty: PType): PNode = if f != nil: result = newSymNode(f) result.info = n.info - result.typ() = ty + result.typ = ty markUsed(c, n.info, f) onUse(n.info, f) of tyObject, tyTuple: if ty.n != nil and ty.n.kind == nkRecList: let field = lookupInRecord(ty.n, i) if field != nil: - n.typ() = makeTypeDesc(c, field.typ) + n.typ = makeTypeDesc(c, field.typ) result = n of tyGenericInst: result = tryReadingTypeField(c, n, i, ty.skipModifier) @@ -1542,7 +1542,7 @@ proc builtinFieldAccess(c: PContext; n: PNode; flags: var TExprFlags): PNode = # tyFromExpr, but when this happen in a macro this is not a built-in # field access and we leave the compiler to compile a normal call: if getCurrOwner(c).kind != skMacro: - n.typ() = makeTypeFromExpr(c, n.copyTree) + n.typ = makeTypeFromExpr(c, n.copyTree) flags.incl efCannotBeDotCall return n else: @@ -1582,12 +1582,12 @@ proc builtinFieldAccess(c: PContext; n: PNode; flags: var TExprFlags): PNode = n[0] = makeDeref(n[0]) n[1] = newSymNode(f) # we now have the correct field n[1].info = info # preserve the original info - n.typ() = f.typ + n.typ = f.typ if check == nil: result = n else: check[0] = n - check.typ() = n.typ + check.typ = n.typ result = check elif ty.kind == tyTuple and ty.n != nil: f = getSymFromList(ty.n, i) @@ -1596,7 +1596,7 @@ proc builtinFieldAccess(c: PContext; n: PNode; flags: var TExprFlags): PNode = onUse(n[1].info, f) n[0] = makeDeref(n[0]) n[1] = newSymNode(f) - n.typ() = f.typ + n.typ = f.typ result = n # we didn't find any field, let's look for a generic param @@ -1662,9 +1662,9 @@ proc semDeref(c: PContext, n: PNode, flags: TExprFlags): PNode = result = n var t = skipTypes(n[0].typ, {tyGenericInst, tyVar, tyLent, tyAlias, tySink, tyOwned}) case t.kind - of tyRef, tyPtr: n.typ() = t.elementType + of tyRef, tyPtr: n.typ = t.elementType of tyMetaTypes, tyFromExpr: - n.typ() = makeTypeFromExpr(c, n.copyTree) + n.typ = makeTypeFromExpr(c, n.copyTree) else: result = nil #GlobalError(n[0].info, errCircumNeedsPointer) @@ -1697,7 +1697,7 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags, afterOverloading = f if arr.kind == tyStatic: if arr.base.kind == tyNone: result = n - result.typ() = semStaticType(c, n[1], nil) + result.typ = semStaticType(c, n[1], nil) return elif arr.n != nil: return semSubscript(c, arr.n, flags, afterOverloading) @@ -1719,18 +1719,18 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags, afterOverloading = f if arg != nil: n[1] = arg result = n - result.typ() = elemType(arr) + result.typ = elemType(arr) # Other types have a bit more of leeway elif n[1].typ.skipTypes(abstractRange-{tyDistinct}).kind in {tyInt..tyInt64, tyUInt..tyUInt64}: result = n - result.typ() = elemType(arr) + result.typ = elemType(arr) of tyTypeDesc: # The result so far is a tyTypeDesc bound # a tyGenericBody. The line below will substitute # it with the instantiated type. result = n - result.typ() = makeTypeDesc(c, semTypeNode(c, n, nil)) + result.typ = makeTypeDesc(c, semTypeNode(c, n, nil)) #result = symNodeFromType(c, semTypeNode(c, n, nil), n.info) of tyTuple: if n.len != 2: return nil @@ -1740,7 +1740,7 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags, afterOverloading = f if skipTypes(n[1].typ, {tyGenericInst, tyRange, tyOrdinal, tyAlias, tySink}).kind in {tyInt..tyInt64}: let idx = getOrdValue(n[1]) - if idx >= 0 and idx < arr.len: n.typ() = arr[toInt(idx)] + if idx >= 0 and idx < arr.len: n.typ = arr[toInt(idx)] else: localError(c.config, n.info, "invalid index $1 in subscript for tuple of length $2" % @@ -1837,7 +1837,7 @@ proc takeImplicitAddr(c: PContext, n: PNode; isLent: bool): PNode = localError(c.config, n.info, errExprHasNoAddress) result = newNodeIT(nkHiddenAddr, n.info, if n.typ.kind in {tyVar, tyLent}: n.typ else: makePtrType(c, n.typ)) if n.typ.kind in {tyVar, tyLent}: - n.typ() = n.typ.elementType + n.typ = n.typ.elementType result.add(n) proc asgnToResultVar(c: PContext, n, le, ri: PNode) {.inline.} = @@ -2031,7 +2031,7 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode = let lhs = n[0] let rhs = semExprWithType(c, n[1], {efTypeAllowed}, le) if lhs.kind == nkSym and lhs.sym.kind == skResult: - n.typ() = c.enforceVoidContext + n.typ = c.enforceVoidContext if c.p.owner.kind != skMacro and resultTypeIsInferrable(lhs.sym.typ): var rhsTyp = rhs.typ if rhsTyp.kind in tyUserTypeClasses and rhsTyp.isResolvedUserTypeClass: @@ -2042,7 +2042,7 @@ proc semAsgn(c: PContext, n: PNode; mode=asgnNormal): PNode = internalAssert c.config, c.p.resultSym != nil # Make sure the type is valid for the result variable typeAllowedCheck(c, n.info, rhsTyp, skResult) - lhs.typ() = rhsTyp + lhs.typ = rhsTyp c.p.resultSym.typ = rhsTyp c.p.owner.typ.setReturnType rhsTyp else: @@ -2090,7 +2090,7 @@ proc semProcBody(c: PContext, n: PNode; expectedType: PType = nil): PNode = if result.kind == nkNilLit: # or ImplicitlyDiscardable(result): # new semantic: 'result = x' triggers the void context - result.typ() = nil + result.typ = nil elif result.kind == nkStmtListExpr and result.typ.kind == tyNil: # to keep backwards compatibility bodies like: # nil @@ -2193,7 +2193,7 @@ proc semDefined(c: PContext, n: PNode): PNode = result = newIntNode(nkIntLit, 0) result.intVal = ord isDefined(c.config, considerQuotedIdentOrDot(c, n[1], n).s) result.info = n.info - result.typ() = getSysType(c.graph, n.info, tyBool) + result.typ = getSysType(c.graph, n.info, tyBool) proc lookUpForDeclared(c: PContext, n: PNode, onlyCurrentScope: bool): PSym = case n.kind @@ -2229,7 +2229,7 @@ proc semDeclared(c: PContext, n: PNode, onlyCurrentScope: bool): PNode = result = newIntNode(nkIntLit, 0) result.intVal = ord lookUpForDeclared(c, n[1], onlyCurrentScope) != nil result.info = n.info - result.typ() = getSysType(c.graph, n.info, tyBool) + result.typ = getSysType(c.graph, n.info, tyBool) proc expectMacroOrTemplateCall(c: PContext, n: PNode): PSym = ## The argument to the proc should be nkCall(...) or similar @@ -2302,10 +2302,10 @@ proc semExpandToAst(c: PContext, n: PNode): PNode = localError(c.config, n.info, "getAst takes a call, but got " & n.renderTree) # Preserve the magic symbol in order to be handled in evals.nim internalAssert c.config, n[0].sym.magic == mExpandToAst - #n.typ() = getSysSym("NimNode").typ # expandedSym.getReturnType + #n.typ = getSysSym("NimNode").typ # expandedSym.getReturnType if n.kind == nkStmtList and n.len == 1: result = n[0] else: result = n - result.typ() = sysTypeFromName(c.graph, n.info, "NimNode") + result.typ = sysTypeFromName(c.graph, n.info, "NimNode") proc semExpandToAst(c: PContext, n: PNode, magicSym: PSym, flags: TExprFlags = {}): PNode = @@ -2475,7 +2475,7 @@ proc semCompiles(c: PContext, n: PNode, flags: TExprFlags): PNode = result = newIntNode(nkIntLit, ord(tryExpr(c, n[1], flags) != nil)) result.info = n.info - result.typ() = getSysType(c.graph, n.info, tyBool) + result.typ = getSysType(c.graph, n.info, tyBool) proc semShallowCopy(c: PContext, n: PNode, flags: TExprFlags): PNode = if n.len == 3: @@ -2520,7 +2520,7 @@ proc semSizeof(c: PContext, n: PNode): PNode = else: n[1] = semExprWithType(c, n[1], {efDetermineType}) #restoreOldStyleType(n[1]) - n.typ() = getSysType(c.graph, n.info, tyInt) + n.typ = getSysType(c.graph, n.info, tyInt) result = foldSizeOf(c.config, n, n) proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags; expectedType: PType = nil): PNode = @@ -2562,7 +2562,7 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags; expectedType: P markUsed(c, n.info, s) checkSonsLen(n, 2, c.config) result = newStrNodeT(renderTree(n[1], {renderNoComments}), n, c.graph) - result.typ() = getSysType(c.graph, n.info, tyString) + result.typ = getSysType(c.graph, n.info, tyString) of mParallel: markUsed(c, n.info, s) if parallel notin c.features: @@ -2588,9 +2588,9 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags; expectedType: P let typ = result[^1].typ if not typ.isEmptyType: if spawnResult(typ, c.inParallelStmt > 0) == srFlowVar: - result.typ() = createFlowVar(c, typ, n.info) + result.typ = createFlowVar(c, typ, n.info) else: - result.typ() = typ + result.typ = typ result.add instantiateCreateFlowVarCall(c, typ, n.info).newSymNode else: result.add c.graph.emptyNode @@ -2598,7 +2598,7 @@ proc semMagic(c: PContext, n: PNode, s: PSym, flags: TExprFlags; expectedType: P markUsed(c, n.info, s) result = setMs(n, s) result[1] = semExpr(c, n[1]) - result.typ() = n[1].typ + result.typ = n[1].typ of mPlugin: markUsed(c, n.info, s) # semDirectOp with conditional 'afterCallActions': @@ -2729,18 +2729,18 @@ proc semWhen(c: PContext, n: PNode, semCheck = true): PNode = else: illFormedAst(n, c.config) if cannotResolve: result = semGenericStmt(c, n) - result.typ() = makeTypeFromExpr(c, result.copyTree) + result.typ = makeTypeFromExpr(c, result.copyTree) return if result == nil: result = newNodeI(nkEmpty, n.info) if whenNimvm: - result.typ() = typ + result.typ = typ if n.len == 1: result.add(newTree(nkElse, newNode(nkStmtList))) proc semSetConstr(c: PContext, n: PNode, expectedType: PType = nil): PNode = result = newNodeI(nkCurly, n.info) - result.typ() = newTypeS(tySet, c) + result.typ = newTypeS(tySet, c) result.typ.incl tfIsConstructor var expectedElementType: PType = nil if expectedType != nil and ( @@ -2771,7 +2771,7 @@ proc semSetConstr(c: PContext, n: PNode, expectedType: PType = nil): PNode = if doSetType: typ = skipTypes(n[i][1].typ, {tyGenericInst, tyVar, tyLent, tyOrdinal, tyAlias, tySink}) - n[i].typ() = n[i][2].typ # range node needs type too + n[i].typ = n[i][2].typ # range node needs type too elif n[i].kind == nkRange: # already semchecked if doSetType: @@ -2802,9 +2802,9 @@ proc semSetConstr(c: PContext, n: PNode, expectedType: PType = nil): PNode = for i in 0..= isSubtype: - result.typ() = expectedType + result.typ = expectedType # or: result = fitNode(c, expectedType, result, n.info) of nkIntLit: if result.typ == nil: @@ -3392,10 +3392,10 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType if expectedType != nil and ( let expected = expectedType.skipTypes(abstractRange-{tyDistinct}); expected.kind in {tyFloat..tyFloat128}): - result.typ() = expected + result.typ = expected changeType(c, result, expectedType, check=true) else: - result.typ() = getSysType(c.graph, n.info, tyFloat64) + result.typ = getSysType(c.graph, n.info, tyFloat64) of nkFloat32Lit: directLiteral(tyFloat32) of nkFloat64Lit: directLiteral(tyFloat64) of nkFloat128Lit: directLiteral(tyFloat128) @@ -3404,9 +3404,9 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType if expectedType != nil and ( let expected = expectedType.skipTypes(abstractRange-{tyDistinct}); expected.kind in {tyString, tyCstring}): - result.typ() = expectedType + result.typ = expectedType else: - result.typ() = getSysType(c.graph, n.info, tyString) + result.typ = getSysType(c.graph, n.info, tyString) of nkCharLit: directLiteral(tyChar) of nkDotExpr: result = semFieldAccess(c, n, flags) @@ -3421,13 +3421,13 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType let modifier = n.modifierTypeKindOfNode if modifier != tyNone: var baseType = semExpr(c, n[0]).typ.skipTypes({tyTypeDesc}) - result.typ() = c.makeTypeDesc(newTypeS(modifier, c, baseType)) + result.typ = c.makeTypeDesc(newTypeS(modifier, c, baseType)) return var typ = semTypeNode(c, n, nil).skipTypes({tyTypeDesc}) - result.typ() = makeTypeDesc(c, typ) + result.typ = makeTypeDesc(c, typ) of nkStmtListType: let typ = semTypeNode(c, n, nil) - result.typ() = makeTypeDesc(c, typ) + result.typ = makeTypeDesc(c, typ) of nkCall, nkInfix, nkPrefix, nkPostfix, nkCommand, nkCallStrLit: # check if it is an expression macro: checkMinSonsLen(n, 1, c.config) diff --git a/compiler/semfields.nim b/compiler/semfields.nim index 5bace728f31e..775895e431cc 100644 --- a/compiler/semfields.nim +++ b/compiler/semfields.nim @@ -24,7 +24,7 @@ proc wrapNewScope(c: PContext, n: PNode): PNode {.inline.} = # a scope has to be opened in the codegen as well for reused # template instantiations let trueLit = newIntLit(c.graph, n.info, 1) - trueLit.typ() = getSysType(c.graph, n.info, tyBool) + trueLit.typ = getSysType(c.graph, n.info, tyBool) result = newTreeI(nkIfStmt, n.info, newTreeI(nkElifBranch, n.info, trueLit, n)) proc instFieldLoopBody(c: TFieldInstCtx, n: PNode, forLoop: PNode): PNode = diff --git a/compiler/semfold.nim b/compiler/semfold.nim index f5acbe66ca8d..b134d666d387 100644 --- a/compiler/semfold.nim +++ b/compiler/semfold.nim @@ -38,7 +38,7 @@ proc newIntNodeT*(intVal: Int128, n: PNode; idgen: IdGenerator; g: ModuleGraph): # original type was 'int', not a distinct int etc. if n.typ.kind == tyInt: # access cache for the int lit type - result.typ() = getIntLitTypeG(g, result, idgen) + result.typ = getIntLitTypeG(g, result, idgen) result.info = n.info proc newFloatNodeT*(floatVal: BiggestFloat, n: PNode; g: ModuleGraph): PNode = @@ -46,12 +46,12 @@ proc newFloatNodeT*(floatVal: BiggestFloat, n: PNode; g: ModuleGraph): PNode = result = newFloatNode(nkFloat32Lit, floatVal) else: result = newFloatNode(nkFloatLit, floatVal) - result.typ() = n.typ + result.typ = n.typ result.info = n.info proc newStrNodeT*(strVal: string, n: PNode; g: ModuleGraph): PNode = result = newStrNode(nkStrLit, strVal) - result.typ() = n.typ + result.typ = n.typ result.info = n.info proc getConstExpr*(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode @@ -319,7 +319,7 @@ proc evalOp(m: TMagic, n, a, b, c: PNode; idgen: IdGenerator; g: ModuleGraph): P of mEnumToStr: result = newStrNodeT(ordinalValToString(a, g), n, g) of mArrToSeq: result = copyTree(a) - result.typ() = n.typ + result.typ = n.typ of mCompileOption: result = newIntNodeT(toInt128(ord(commands.testCompileOption(g.config, a.getStr, n.info))), n, idgen, g) of mCompileOptionArg: @@ -414,7 +414,7 @@ proc foldConv(n, a: PNode; idgen: IdGenerator; g: ModuleGraph; check = false): P result = newIntNodeT(toInt128(a.getOrdValue != 0), n, idgen, g) of tyBool, tyEnum: # xxx shouldn't we disallow `tyEnum`? result = a - result.typ() = n.typ + result.typ = n.typ else: raiseAssert $srcTyp.kind of tyInt..tyInt64, tyUInt..tyUInt64: @@ -431,7 +431,7 @@ proc foldConv(n, a: PNode; idgen: IdGenerator; g: ModuleGraph; check = false): P result = newIntNodeT(val, n, idgen, g) else: result = a - result.typ() = n.typ + result.typ = n.typ if check and result.kind in {nkCharLit..nkUInt64Lit} and dstTyp.kind notin {tyUInt..tyUInt64}: rangeCheck(n, getInt(result), g) @@ -441,12 +441,12 @@ proc foldConv(n, a: PNode; idgen: IdGenerator; g: ModuleGraph; check = false): P result = newFloatNodeT(toFloat64(getOrdValue(a)), n, g) else: result = a - result.typ() = n.typ + result.typ = n.typ of tyOpenArray, tyVarargs, tyProc, tyPointer: result = nil else: result = a - result.typ() = n.typ + result.typ = n.typ proc getArrayConstr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode = if n.kind == nkBracket: @@ -518,10 +518,10 @@ proc foldConStrStr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode proc newSymNodeTypeDesc*(s: PSym; idgen: IdGenerator; info: TLineInfo): PNode = result = newSymNode(s, info) if s.typ.kind != tyTypeDesc: - result.typ() = newType(tyTypeDesc, idgen, s.owner) + result.typ = newType(tyTypeDesc, idgen, s.owner) result.typ.addSonSkipIntLit(s.typ, idgen) else: - result.typ() = s.typ + result.typ = s.typ proc foldDefine(m, s: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode = result = nil @@ -640,7 +640,7 @@ proc getConstExpr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode if s.typ.kind == tyStatic: if s.typ.n != nil and tfUnresolved notin s.typ.flags: result = s.typ.n - result.typ() = s.typ.base + result.typ = s.typ.base elif s.typ.isIntLit: result = s.typ.n else: @@ -753,7 +753,7 @@ proc getConstExpr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode if a == nil: return if leValueConv(n[1], a) and leValueConv(a, n[2]): result = a # a <= x and x <= b - result.typ() = n.typ + result.typ = n.typ elif n.typ.kind in {tyUInt..tyUInt64}: discard "don't check uints" else: @@ -764,7 +764,7 @@ proc getConstExpr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode var a = getConstExpr(m, n[0], idgen, g) if a == nil: return result = a - result.typ() = n.typ + result.typ = n.typ of nkHiddenStdConv, nkHiddenSubConv, nkConv: var a = getConstExpr(m, n[1], idgen, g) if a == nil: return @@ -781,7 +781,7 @@ proc getConstExpr(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode not (n.typ.kind == tyProc and a.typ.kind == tyProc): # we allow compile-time 'cast' for pointer types: result = a - result.typ() = n.typ + result.typ = n.typ of nkBracketExpr: result = foldArrayAccess(m, n, idgen, g) of nkDotExpr: result = foldFieldAccess(m, n, idgen, g) of nkCheckedFieldExpr: diff --git a/compiler/semgnrc.nim b/compiler/semgnrc.nim index 92deca323151..10bb33bcdc7d 100644 --- a/compiler/semgnrc.nim +++ b/compiler/semgnrc.nim @@ -78,10 +78,10 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym, if result.kind == nkSym: result = newOpenSym(result) else: - result.typ() = nil + result.typ = nil else: result.flags.incl nfDisabledOpenSym - result.typ() = nil + result.typ = nil case s.kind of skUnknown: # Introduced in this pass! Leave it as an identifier. @@ -116,7 +116,7 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym, result = newOpenSym(result) else: result.flags.incl nfDisabledOpenSym - result.typ() = nil + result.typ = nil else: result = n else: @@ -126,7 +126,7 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym, result = newOpenSym(result) else: result.flags.incl nfDisabledOpenSym - result.typ() = nil + result.typ = nil onUse(n.info, s) of skParam: result = n @@ -145,7 +145,7 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym, result = newOpenSym(result) else: result.flags.incl nfDisabledOpenSym - result.typ() = nil + result.typ = nil elif c.inGenericContext > 0 and withinConcept notin flags: # don't leave generic param as identifier node in generic type, # sigmatch will try to instantiate generic type AST without all params @@ -157,7 +157,7 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym, result = newOpenSym(result) else: result.flags.incl nfDisabledOpenSym - result.typ() = nil + result.typ = nil else: result = n onUse(n.info, s) @@ -168,7 +168,7 @@ proc semGenericStmtSymbol(c: PContext, n: PNode, s: PSym, result = newOpenSym(result) else: result.flags.incl nfDisabledOpenSym - result.typ() = nil + result.typ = nil onUse(n.info, s) proc lookup(c: PContext, n: PNode, flags: TSemGenericFlags, @@ -248,13 +248,13 @@ proc addTempDecl(c: PContext; n: PNode; kind: TSymKind) = onDef(n.info, s) proc addTempDeclToIdents(c: PContext; n: PNode; kind: TSymKind; inCall: bool) = - case n.kind + case n.kind of nkIdent: if inCall: addTempDecl(c, n, kind) of nkCallKinds: for s in n: - addTempDeclToIdents(c, s, kind, true) + addTempDeclToIdents(c, s, kind, true) else: for s in n: addTempDeclToIdents(c, s, kind, inCall) @@ -632,7 +632,7 @@ proc semGenericStmt(c: PContext, n: PNode, # treat as mixin context for user pragmas & macro args x[j] = semGenericStmt(c, x[j], flags+{withinMixin}, ctx) elif prag == wInvalid: - # only sem if not a language-level pragma + # only sem if not a language-level pragma # treat as mixin context for user pragmas & macro args result[i] = semGenericStmt(c, x, flags+{withinMixin}, ctx) of nkExprColonExpr, nkExprEqExpr: diff --git a/compiler/seminst.nim b/compiler/seminst.nim index f0364db53a61..9a2f3ac002bb 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -302,7 +302,7 @@ proc instantiateProcType(c: PContext, pt: LayeredIdTable, # the only way the default value might be inserted). param.ast = errorNode(c, def) # we know the node is empty, we need the actual type for error message - param.ast.typ() = def.typ + param.ast.typ = def.typ else: param.ast = fitNodePostMatch(c, typeToFit, converted) param.typ = result[i] diff --git a/compiler/semmacrosanity.nim b/compiler/semmacrosanity.nim index 1675114c2b0d..12e0271f000d 100644 --- a/compiler/semmacrosanity.nim +++ b/compiler/semmacrosanity.nim @@ -93,8 +93,8 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef; producedClosure: var boo case n.kind of nkObjConstr: let x = t.skipTypes(abstractPtrs) - n.typ() = t - n[0].typ() = t + n.typ = t + n[0].typ = t for i in 1..= x.kidsLen: globalError conf, n.info, "invalid field at index " & $i else: annotateType(n[i], x[i], conf, producedClosure) elif x.kind == tyProc and x.callConv == ccClosure: - n.typ() = t + n.typ = t if n.len > 1 and n[1].kind notin {nkEmpty, nkNilLit}: producedClosure = true elif x.kind == tyOpenArray: # `opcSlice` transforms slices into tuples @@ -136,18 +136,18 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef; producedClosure: var boo globalError(conf, n.info, "Incorrectly generated tuple constr") n[] = bracketExpr[] - n.typ() = t + n.typ = t else: globalError(conf, n.info, "() must have a tuple type") of nkBracket: if x.kind in {tyArray, tySequence, tyOpenArray}: - n.typ() = t + n.typ = t for m in n: annotateType(m, x.elemType, conf, producedClosure) else: globalError(conf, n.info, "[] must have some form of array type") of nkCurly: if x.kind in {tySet}: - n.typ() = t + n.typ = t for m in n: if m.kind == nkRange: annotateType(m[0], x.elemType, conf, producedClosure) @@ -158,22 +158,22 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef; producedClosure: var boo globalError(conf, n.info, "{} must have the set type") of nkFloatLit..nkFloat128Lit: if x.kind in {tyFloat..tyFloat128}: - n.typ() = t + n.typ = t else: globalError(conf, n.info, "float literal must have some float type") of nkCharLit..nkUInt64Lit: if x.kind in {tyInt..tyUInt64, tyBool, tyChar, tyEnum}: - n.typ() = t + n.typ = t else: globalError(conf, n.info, "integer literal must have some int type") of nkStrLit..nkTripleStrLit: if x.kind in {tyString, tyCstring}: - n.typ() = t + n.typ = t else: globalError(conf, n.info, "string literal must be of some string type") of nkNilLit: if x.kind in NilableTypes+{tyString, tySequence}: - n.typ() = t + n.typ = t else: globalError(conf, n.info, "nil literal must be of some pointer type") else: discard diff --git a/compiler/semmagic.nim b/compiler/semmagic.nim index 029135764bf7..9de290f4ce32 100644 --- a/compiler/semmagic.nim +++ b/compiler/semmagic.nim @@ -18,7 +18,7 @@ proc addDefaultFieldForNew(c: PContext, n: PNode): PNode = let typ = result[1].typ # new(x) if typ.skipTypes({tyGenericInst, tyAlias, tySink}).kind == tyRef and typ.skipTypes({tyGenericInst, tyAlias, tySink})[0].kind == tyObject: var asgnExpr = newTree(nkObjConstr, newNodeIT(nkType, result[1].info, typ)) - asgnExpr.typ() = typ + asgnExpr.typ = typ var t = typ.skipTypes({tyGenericInst, tyAlias, tySink})[0] while true: asgnExpr.sons.add defaultFieldsForTheUninitialized(c, t.n, false) @@ -38,7 +38,7 @@ proc semAddr(c: PContext; n: PNode): PNode = if isAssignable(c, x) notin {arLValue, arLocalLValue, arAddressableConst, arLentValue}: localError(c.config, n.info, errExprHasNoAddress) result.add x - result.typ() = makePtrType(c, x.typ.skipTypes({tySink})) + result.typ = makePtrType(c, x.typ.skipTypes({tySink})) proc semTypeOf(c: PContext; n: PNode): PNode = var m = BiggestInt 1 # typeOfIter @@ -63,7 +63,7 @@ proc semTypeOf(c: PContext; n: PNode): PNode = t.incl tfNonConstExpr else: t = base - result.typ() = makeTypeDesc(c, t) + result.typ = makeTypeDesc(c, t) type SemAsgnMode = enum asgnNormal, noOverloadedSubscript, noOverloadedAsgn @@ -84,7 +84,7 @@ proc semArrGet(c: PContext; n: PNode; flags: TExprFlags): PNode = if a.typ != nil and a.typ.kind in {tyGenericParam, tyFromExpr}: # expression is compiled early in a generic body result = semGenericStmt(c, x) - result.typ() = makeTypeFromExpr(c, copyTree(result)) + result.typ = makeTypeFromExpr(c, copyTree(result)) result.typ.incl tfNonConstExpr return let s = # extract sym from first arg @@ -208,15 +208,15 @@ proc evalTypeTrait(c: PContext; traitCall: PNode, operand: PType, context: PSym) let preferStr = traitCall[2].strVal prefer = parseEnum[TPreferedDesc](preferStr) result = newStrNode(nkStrLit, operand.typeToString(prefer)) - result.typ() = getSysType(c.graph, traitCall[1].info, tyString) + result.typ = getSysType(c.graph, traitCall[1].info, tyString) result.info = traitCall.info of "name", "$": result = newStrNode(nkStrLit, operand.typeToString(preferTypeName)) - result.typ() = getSysType(c.graph, traitCall[1].info, tyString) + result.typ = getSysType(c.graph, traitCall[1].info, tyString) result.info = traitCall.info of "arity": result = newIntNode(nkIntLit, operand.len - ord(operand.kind==tyProc)) - result.typ() = newType(tyInt, c.idgen, context) + result.typ = newType(tyInt, c.idgen, context) result.info = traitCall.info of "genericHead": var arg = operand @@ -286,7 +286,7 @@ proc semOrd(c: PContext, n: PNode): PNode = discard else: localError(c.config, n.info, errOrdinalTypeExpected % typeToString(parType, preferDesc)) - result.typ() = errorType(c) + result.typ = errorType(c) proc semBindSym(c: PContext, n: PNode): PNode = result = copyNode(n) @@ -402,7 +402,7 @@ proc semOf(c: PContext, n: PNode): PNode = message(c.config, n.info, hintConditionAlwaysTrue, renderTree(n)) result = newIntNode(nkIntLit, 1) result.info = n.info - result.typ() = getSysType(c.graph, n.info, tyBool) + result.typ = getSysType(c.graph, n.info, tyBool) return result elif diff == high(int): if commonSuperclass(a, b) == nil: @@ -411,10 +411,10 @@ proc semOf(c: PContext, n: PNode): PNode = message(c.config, n.info, hintConditionAlwaysFalse, renderTree(n)) result = newIntNode(nkIntLit, 0) result.info = n.info - result.typ() = getSysType(c.graph, n.info, tyBool) + result.typ = getSysType(c.graph, n.info, tyBool) else: localError(c.config, n.info, "'of' takes 2 arguments") - n.typ() = getSysType(c.graph, n.info, tyBool) + n.typ = getSysType(c.graph, n.info, tyBool) result = n proc semUnown(c: PContext; n: PNode): PNode = @@ -449,9 +449,9 @@ proc semUnown(c: PContext; n: PNode): PNode = result = t result = copyTree(n[1]) - result.typ() = unownedType(c, result.typ) + result.typ = unownedType(c, result.typ) # little hack for injectdestructors.nim (see bug #11350): - #result[0].typ() = nil + #result[0].typ = nil proc turnFinalizerIntoDestructor(c: PContext; orig: PSym; info: TLineInfo): PSym = # We need to do 2 things: Replace n.typ which is a 'ref T' by a 'var T' type. @@ -461,7 +461,7 @@ proc turnFinalizerIntoDestructor(c: PContext; orig: PSym; info: TLineInfo): PSym proc transform(c: PContext; n: PNode; old, fresh: PType; oldParam, newParam: PSym): PNode = result = shallowCopy(n) if sameTypeOrNil(n.typ, old): - result.typ() = fresh + result.typ = fresh if n.kind == nkSym and n.sym == oldParam: result.sym = newParam for i in 0 ..< safeLen(n): @@ -550,7 +550,7 @@ proc semNewFinalize(c: PContext; n: PNode): PNode = else: 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 + selfSymNode.typ = fin.typ.firstParamType wrapperSym.flagsImpl.incl sfUsed let wrapper = c.semExpr(c, newProcNode(nkProcDef, fin.info, body = newTree(nkCall, newSymNode(fin), selfSymNode), @@ -568,7 +568,7 @@ proc semNewFinalize(c: PContext; n: PNode): PNode = let selfSymbolType = makePtrType(c, origParamType.skipTypes(abstractPtrs)) let selfPtr = newNodeI(nkHiddenAddr, transFormedSym.ast[bodyPos][1].info) selfPtr.add transFormedSym.ast[bodyPos][1] - selfPtr.typ() = selfSymbolType + selfPtr.typ = selfSymbolType transFormedSym.ast[bodyPos][1] = c.semExpr(c, selfPtr) bindTypeHook(c, transFormedSym, n, attachedDestructor) result = addDefaultFieldForNew(c, n) @@ -623,7 +623,7 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode, of mTypeTrait: result = semTypeTraits(c, n) of mAstToStr: result = newStrNodeT(renderTree(n[1], {renderNoComments}), n, c.graph) - result.typ() = getSysType(c.graph, n.info, tyString) + result.typ = getSysType(c.graph, n.info, tyString) of mInstantiationInfo: result = semInstantiationInfo(c, n) of mOrd: result = semOrd(c, n) of mOf: result = semOf(c, n) @@ -636,7 +636,7 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode, result = semDynamicBindSym(c, n) of mProcCall: result = n - result.typ() = n[1].typ + result.typ = n[1].typ of mDotDot: result = n of mPlugin: @@ -692,7 +692,7 @@ proc magicsAfterOverloadResolution(c: PContext, n: PNode, result = n if result.typ != nil and expectedType != nil and result.typ.kind == tySequence and expectedType.kind == tySequence and result.typ.elementType.kind == tyEmpty: - result.typ() = expectedType # type inference for empty sequence # bug #21377 + result.typ = expectedType # type inference for empty sequence # bug #21377 of mEnsureMove: result = n if n[1].kind in {nkStmtListExpr, nkBlockExpr, diff --git a/compiler/semobjconstr.nim b/compiler/semobjconstr.nim index aab17e5443a7..d9317c3320b8 100644 --- a/compiler/semobjconstr.nim +++ b/compiler/semobjconstr.nim @@ -192,7 +192,7 @@ proc collectOrAddMissingCaseFields(c: PContext, branchNode: PNode, newNodeIT(nkType, constrCtx.initExpr.info, asgnType) ) asgnExpr.flags.incl nfSkipFieldChecking - asgnExpr.typ() = recTyp + asgnExpr.typ = recTyp defaults.add newTree(nkExprColonExpr, newSymNode(sym), asgnExpr) proc collectBranchFields(c: PContext, n: PNode, discriminatorVal: PNode, @@ -482,7 +482,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType if t.kind == tyRef: t = skipTypes(t.elementType, {tyGenericInst, tyAlias, tySink, tyOwned}) if optOwnedRefs in c.config.globalOptions: - result.typ() = makeVarType(c, result.typ, tyOwned) + result.typ = makeVarType(c, result.typ, tyOwned) # we have to watch out, there are also 'owned proc' types that can be used # multiple times as long as they don't have closures. result.typ.incl tfHasOwned diff --git a/compiler/semparallel.nim b/compiler/semparallel.nim index 78d59dfb29a4..a91a212331de 100644 --- a/compiler/semparallel.nim +++ b/compiler/semparallel.nim @@ -407,9 +407,9 @@ proc transformSlices(g: ModuleGraph; idgen: IdGenerator; n: PNode): PNode = result = copyNode(n) var typ = newType(tyOpenArray, idgen, result.typ.owner) typ.add result.typ.elementType - result.typ() = typ + result.typ = typ let opSlice = newSymNode(createMagic(g, idgen, "slice", mSlice)) - opSlice.typ() = getSysType(g, n.info, tyInt) + opSlice.typ = getSysType(g, n.info, tyInt) result.add opSlice result.add n[1] let slice = n[2].skipStmtList diff --git a/compiler/sempass2.nim b/compiler/sempass2.nim index dfb76983a04a..73853a9d6b48 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -196,7 +196,7 @@ proc guardDotAccess(a: PEffects; n: PNode) = let dot = newNodeI(nkDotExpr, n.info, 2) dot[0] = n[0] dot[1] = newSymNode(g) - dot.typ() = g.typ + dot.typ = g.typ for L in a.locked: #if a.guards.sameSubexprs(dot, L): return if guards.sameTree(dot, L): return @@ -417,7 +417,7 @@ proc throws(tracked, n, orig: PNode) = if n.typ == nil or n.typ.kind != tyError: if orig != nil: let x = copyTree(orig) - x.typ() = n.typ + x.typ = n.typ tracked.add x else: tracked.add n @@ -432,12 +432,12 @@ proc excType(g: ModuleGraph; n: PNode): PType = proc createRaise(g: ModuleGraph; n: PNode): PNode = result = newNode(nkType) - result.typ() = getEbase(g, n.info) + result.typ = getEbase(g, n.info) if not n.isNil: result.info = n.info proc createTag(g: ModuleGraph; n: PNode): PNode = result = newNode(nkType) - result.typ() = g.sysTypeFromName(n.info, "RootEffect") + result.typ = g.sysTypeFromName(n.info, "RootEffect") if not n.isNil: result.info = n.info proc addRaiseEffect(a: PEffects, e, comesFrom: PNode) = @@ -1245,7 +1245,7 @@ proc track(tracked: PEffects, n: PNode) = if n.sym.typ != nil and tfHasAsgn in n.sym.typ.flags: 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 + if n.typ == nil or (not hasDestructor(n.typ) and sameType(n.typ, n.sym.typ)): n.typ = n.sym.typ of nkHiddenAddr, nkAddr: if n[0].kind == nkSym and isLocalSym(tracked, n[0].sym) and n.typ.kind notin {tyVar, tyLent}: diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index bb9c96fcf0e4..c86af27c9179 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -112,11 +112,11 @@ proc semWhile(c: PContext, n: PNode; flags: TExprFlags): PNode = dec(c.p.nestedLoopCounter) closeScope(c) if n[1].typ == c.enforceVoidContext: - result.typ() = c.enforceVoidContext + result.typ = c.enforceVoidContext elif efInTypeof in flags: - result.typ() = n[1].typ + result.typ = n[1].typ elif implicitlyDiscardable(n[1]): - result[1].typ() = c.enforceVoidContext + result[1].typ = c.enforceVoidContext proc semProc(c: PContext, n: PNode): PNode @@ -275,7 +275,7 @@ proc fixNilType(c: PContext; n: PNode) = elif n.kind in {nkStmtList, nkStmtListExpr}: n.transitionSonsKind(nkStmtList) for it in n: fixNilType(c, it) - n.typ() = nil + n.typ = nil proc discardCheck(c: PContext, result: PNode, flags: TExprFlags) = if c.matchedConcept != nil or efInTypeof in flags: return @@ -331,14 +331,14 @@ proc semIf(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil): for it in n: discardCheck(c, it.lastSon, flags) result.transitionSonsKind(nkIfStmt) # propagate any enforced VoidContext: - if typ == c.enforceVoidContext: result.typ() = c.enforceVoidContext + if typ == c.enforceVoidContext: result.typ = c.enforceVoidContext else: for it in n: let j = it.len-1 if not endsInNoReturn(it[j]): it[j] = fitNode(c, typ, it[j], it[j].info) result.transitionSonsKind(nkIfExpr) - result.typ() = typ + result.typ = typ proc semTry(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil): PNode = var check = initIntSet() @@ -439,7 +439,7 @@ proc semTry(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = nil) discardCheck(c, n[0], flags) for i in 1.. 0: # from templates diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 33761da70011..7335ff0dc31e 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -238,10 +238,10 @@ proc semTemplSymbol(c: var TemplCtx, n: PNode, s: PSym; isField, isAmbiguous: bo if result.kind == nkSym: result = newOpenSym(result) else: - result.typ() = nil + result.typ = nil else: result.flags.incl nfDisabledOpenSym - result.typ() = nil + result.typ = nil of skGenericParam: if isField and sfGenSym in s.flags: result = n else: @@ -251,7 +251,7 @@ proc semTemplSymbol(c: var TemplCtx, n: PNode, s: PSym; isField, isAmbiguous: bo result = newOpenSym(result) else: result.flags.incl nfDisabledOpenSym - result.typ() = nil + result.typ = nil of skParam: result = n of skType: @@ -269,10 +269,10 @@ proc semTemplSymbol(c: var TemplCtx, n: PNode, s: PSym; isField, isAmbiguous: bo if result.kind == nkSym: result = newOpenSym(result) else: - result.typ() = nil + result.typ = nil else: result.flags.incl nfDisabledOpenSym - result.typ() = nil + result.typ = nil else: if isField and sfGenSym in s.flags: result = n else: @@ -282,7 +282,7 @@ proc semTemplSymbol(c: var TemplCtx, n: PNode, s: PSym; isField, isAmbiguous: bo result = newOpenSym(result) else: result.flags.incl nfDisabledOpenSym - result.typ() = nil + result.typ = nil # Issue #12832 when defined(nimsuggest): suggestSym(c.c.graph, n.info, s, c.c.graph.usageSym, false) @@ -544,7 +544,7 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = let x = n[i] let prag = whichPragma(x) if prag == wInvalid: - # only sem if not a language-level pragma + # only sem if not a language-level pragma result[i] = semTemplBody(c, x) elif x.kind in nkPragmaCallKinds: # is pragma, but value still needs to be checked diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index a64eaaa041d0..82cc5890cde3 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -535,7 +535,7 @@ proc firstRange(config: ConfigRef, t: PType): PNode = result = newFloatNode(nkFloatLit, firstFloat(t)) else: result = newIntNode(nkIntLit, firstOrd(config, t)) - result.typ() = t + result.typ = t proc semTuple(c: PContext, n: PNode, prev: PType): PType = var typ: PType @@ -1148,7 +1148,7 @@ proc semAnyRef(c: PContext; n: PNode; kind: TTypeKind; prev: PType): PType = let t = newTypeS(tySink, c, result) result = t else: discard - if result.kind == tyRef and + if result.kind == tyRef and c.config.selectedGC in {gcArc, gcOrc, gcAtomicArc} and tfTriggersCompileTime notin result.flags: result.incl tfHasAsgn @@ -1470,7 +1470,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, elif hasUnresolvedArgs(c, def): # template default value depends on other parameter # don't do any typechecking - def.typ() = makeTypeFromExpr(c, def.copyTree) + def.typ = makeTypeFromExpr(c, def.copyTree) break determineType elif typ != nil and typ.kind == tyTyped: canBeVoid = true @@ -1615,7 +1615,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, # XXX This rather hacky way keeps 'tflatmap' compiling: if tfHasMeta notin oldFlags: result.excl tfHasMeta - result.n.typ() = r + result.n.typ = r if isCurrentlyGeneric(): for n in genericParams: @@ -1632,8 +1632,8 @@ proc semStmtListType(c: PContext, n: PNode, prev: PType): PType = n[i] = semStmt(c, n[i], {}) if n.len > 0: result = semTypeNode(c, n[^1], prev) - n.typ() = result - n[^1].typ() = result + n.typ = result + n[^1].typ = result else: result = nil @@ -1646,15 +1646,15 @@ proc semBlockType(c: PContext, n: PNode, prev: PType): PType = if n[0].kind notin {nkEmpty, nkSym}: addDecl(c, newSymS(skLabel, n[0], c)) result = semStmtListType(c, n[1], prev) - n[1].typ() = result - n.typ() = result + n[1].typ = result + n.typ = result closeScope(c) c.p.breakInLoop = oldBreakInLoop dec(c.p.nestedBlockCounter) proc semGenericParamInInvocation(c: PContext, n: PNode): PType = result = semTypeNode(c, n, nil) - n.typ() = makeTypeDesc(c, result) + n.typ = makeTypeDesc(c, result) proc trySemObjectTypeForInheritedGenericInst(c: PContext, n: PNode, t: PType): bool = var @@ -2089,7 +2089,7 @@ proc semTypeIdent(c: PContext, n: PNode): PSym = n.transitionNoneToSym() n.sym = result n.info = oldInfo - n.typ() = result.typ + n.typ = result.typ else: localError(c.config, n.info, "identifier expected") result = errorSym(c, n) @@ -2388,7 +2388,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType = when false: localError(c.config, n.info, "type expected, but got: " & renderTree(n)) result = newOrPrevType(tyError, prev, c) - n.typ() = result + n.typ = result dec c.inTypeContext proc setMagicType(conf: ConfigRef; m: PSym, kind: TTypeKind, size: int) = @@ -2535,7 +2535,7 @@ proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode = else: # the following line fixes ``TV2*[T:SomeNumber=TR] = array[0..1, T]`` # from manyloc/named_argument_bug/triengine: - def.typ() = def.typ.skipTypes({tyTypeDesc}) + def.typ = def.typ.skipTypes({tyTypeDesc}) if not containsGenericType(def.typ): def = fitNode(c, typ, def, def.info) diff --git a/compiler/semtypinst.nim b/compiler/semtypinst.nim index 598e67773051..031683d04ab5 100644 --- a/compiler/semtypinst.nim +++ b/compiler/semtypinst.nim @@ -110,7 +110,7 @@ proc prepareNode*(cl: var TReplTypeVars, n: PNode): PNode = return if tfUnresolved in t.flags: prepareNode(cl, t.n) else: t.n result = copyNode(n) - result.typ() = t + result.typ = t if result.kind == nkSym: result.sym = if n.typ != nil and n.typ == n.sym.typ: @@ -264,7 +264,7 @@ proc replaceTypeVarsN(cl: var TReplTypeVars, n: PNode; start=0; expectedType: PT if n.typ.kind == tyFromExpr: # type of node should not be evaluated as a static value n.typ.incl tfNonConstExpr - result.typ() = replaceTypeVarsT(cl, n.typ) + result.typ = replaceTypeVarsT(cl, n.typ) checkMetaInvariants(cl, result.typ) case n.kind of nkNone..pred(nkSym), succ(nkSym)..nkNilLit: @@ -706,7 +706,7 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType, isInstValue = false): if not cl.allowMetaTypes and result.n != nil and result.base.kind != tyNone: result.n = cl.c.semConstExpr(cl.c, result.n) - result.n.typ() = result.base + result.n.typ = result.base of tyGenericInst, tyUserTypeClassInst: bailout() diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index a43c41ff7c0b..5b38f99b6d4d 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -454,11 +454,11 @@ template describeArgImpl(c: PContext, n: PNode, i: int, startIdx = 1; prefer = p arg = c.semTryExpr(c, n[i][1]) if arg == nil: arg = n[i][1] - arg.typ() = newTypeS(tyUntyped, c) + arg.typ = newTypeS(tyUntyped, c) else: if arg.typ == nil: - arg.typ() = newTypeS(tyVoid, c) - n[i].typ() = arg.typ + arg.typ = newTypeS(tyVoid, c) + n[i].typ = arg.typ n[i][1] = arg else: if arg.typ.isNil and arg.kind notin {nkStmtList, nkDo, nkElse, @@ -467,10 +467,10 @@ template describeArgImpl(c: PContext, n: PNode, i: int, startIdx = 1; prefer = p arg = c.semTryExpr(c, n[i]) if arg == nil: arg = n[i] - arg.typ() = newTypeS(tyUntyped, c) + arg.typ = newTypeS(tyUntyped, c) else: if arg.typ == nil: - arg.typ() = newTypeS(tyVoid, c) + arg.typ = newTypeS(tyVoid, c) n[i] = arg if arg.typ != nil and arg.typ.kind == tyError: return result.add argTypeToString(arg, prefer) @@ -2181,18 +2181,18 @@ proc implicitConv(kind: TNodeKind, f: PType, arg: PNode, m: TCandidate, result = newNodeI(kind, arg.info) if containsGenericType(f): if not m.matchedErrorType: - result.typ() = getInstantiatedType(c, arg, m, f).skipTypes({tySink}) + result.typ = getInstantiatedType(c, arg, m, f).skipTypes({tySink}) else: - result.typ() = errorType(c) + result.typ = errorType(c) else: - result.typ() = f.skipTypes({tySink}) + result.typ = f.skipTypes({tySink}) # keep varness if arg.typ != nil and arg.typ.kind == tyVar: - result.typ() = toVar(result.typ, tyVar, c.idgen) + result.typ = toVar(result.typ, tyVar, c.idgen) # copy the tfVarIsPtr flag result.typ.flags = arg.typ.flags else: - result.typ() = result.typ.skipTypes({tyVar}) + result.typ = result.typ.skipTypes({tyVar}) if result.typ == nil: internalError(c.graph.config, arg.info, "implicitConv") result.add c.graph.emptyNode @@ -2220,13 +2220,13 @@ proc convertLiteral(kind: TNodeKind, c: PContext, m: TCandidate; n: PNode, newTy result.add x else: result.addConsiderNil convertLiteral(kind, c, m, n[i], elemType(newType)) - result.typ() = newType + result.typ = newType return of nkBracket: result = copyNode(n) for i in 0.. lastOrd(c.config, newType): return nil result = copyNode(n) - result.typ() = newType + result.typ = newType return of nkFloatLit..nkFloat64Lit: if newType.skipTypes(abstractVarRange-{tyTypeDesc}).kind == tyFloat: if not floatRangeCheck(n.floatVal, newType): return nil result = copyNode(n) - result.typ() = newType + result.typ = newType return of nkSym: if n.sym.kind == skEnumField and not sameTypeOrNil(n.sym.typ, newType) and isOrdinalType(newType): @@ -2273,7 +2273,7 @@ proc convertLiteral(kind: TNodeKind, c: PContext, m: TCandidate; n: PNode, newTy if value < firstOrd(c.config, newType) or value > lastOrd(c.config, newType): return nil result = copyNode(n) - result.typ() = newType + result.typ = newType return else: discard return implicitConv(kind, newType, n, m, c) @@ -2320,7 +2320,7 @@ proc userConvMatch(c: PContext, m: var TCandidate, f, a: PType, incl(c.converters[i].flagsImpl, sfUsed) markOwnerModuleAsUsed(c, c.converters[i]) var s = newSymNode(c.converters[i]) - s.typ() = c.converters[i].typ + s.typ = c.converters[i].typ s.info = arg.info result = newNodeIT(nkHiddenCallConv, arg.info, dest) result.add s @@ -2374,7 +2374,7 @@ proc localConvMatch(c: PContext, m: var TCandidate, f, a: PType, if result.kind == nkCall: result.transitionSonsKind(nkHiddenCallConv) inc(m.convMatches) if r == isGeneric: - result.typ() = getInstantiatedType(c, arg, m, base(f)) + result.typ = getInstantiatedType(c, arg, m, base(f)) m.baseTypeMatch = true proc incMatches(m: var TCandidate; r: TTypeRelation; convMatch = 1) = @@ -2430,7 +2430,7 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType, let typ = newTypeS(tyStatic, c, son = evaluated.typ) typ.n = evaluated arg = copyTree(arg) # fix #12864 - arg.typ() = typ + arg.typ = typ a = typ else: if m.callee.kind == tyGenericBody: @@ -2548,7 +2548,7 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType, # doesn't work: `proc foo[T](): array[T, int] = ...; foo[3]()` (see #23204) (arg.typ.isIntLit and not m.isNoCall): result = arg.copyTree - result.typ() = getInstantiatedType(c, arg, m, f).skipTypes({tySink}) + result.typ = getInstantiatedType(c, arg, m, f).skipTypes({tySink}) else: result = arg of isBothMetaConvertible: @@ -2604,7 +2604,7 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType, of isGeneric: inc(m.convMatches) result = copyTree(arg) - result.typ() = getInstantiatedType(c, arg, m, base(f)) + result.typ = getInstantiatedType(c, arg, m, base(f)) m.baseTypeMatch = true of isFromIntLit: inc(m.intConvMatches, 256) @@ -2630,7 +2630,7 @@ proc staticAwareTypeRel(m: var TCandidate, f: PType, arg: var PNode): TTypeRelat # The ast of the type does not point to the symbol. # Without this we will never resolve a `static proc` with overloads let copiedNode = copyNode(arg) - copiedNode.typ() = exactReplica(copiedNode.typ) + copiedNode.typ = exactReplica(copiedNode.typ) copiedNode.typ.n = arg arg = copiedNode typeRel(m, f, arg.typ) @@ -2899,7 +2899,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode, m: var TCandidate, marker: var Int var newlyTyped = false n[a][1] = prepareOperand(c, formal.typ, n[a][1], newlyTyped) if newlyTyped: m.newlyTypedOperands.add(a) - n[a].typ() = n[a][1].typ + n[a].typ = n[a][1].typ arg = paramTypesMatch(m, formal.typ, n[a].typ, n[a][1], n[a][1]) m.firstMismatch.kind = kTypeMismatch @@ -3079,7 +3079,7 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) = if m.calleeSym != nil: m.calleeSym.detailedInfo else: "") typeMismatch(c.config, formal.ast.info, formal.typ, formal.ast.typ, formal.ast) popInfoContext(c.config) - formal.ast.typ() = errorType(c) + formal.ast.typ = errorType(c) if nfDefaultRefsParam in formal.ast.flags: m.call.flags.incl nfDefaultRefsParam var defaultValue = copyTree(formal.ast) diff --git a/compiler/sizealignoffsetimpl.nim b/compiler/sizealignoffsetimpl.nim index 3a3457cb897a..1dd481ec0bc5 100644 --- a/compiler/sizealignoffsetimpl.nim +++ b/compiler/sizealignoffsetimpl.nim @@ -477,7 +477,7 @@ template foldSizeOf*(conf: ConfigRef; n: PNode; fallback: PNode): PNode = if size >= 0: let res = newIntNode(nkIntLit, size) res.info = node.info - res.typ() = node.typ + res.typ = node.typ res else: fallback @@ -491,7 +491,7 @@ template foldAlignOf*(conf: ConfigRef; n: PNode; fallback: PNode): PNode = if align >= 0: let res = newIntNode(nkIntLit, align) res.info = node.info - res.typ() = node.typ + res.typ = node.typ res else: fallback @@ -519,7 +519,7 @@ template foldOffsetOf*(conf: ConfigRef; n: PNode; fallback: PNode): PNode = if offset >= 0: let tmp = newIntNode(nkIntLit, offset) tmp.info = node.info - tmp.typ() = node.typ + tmp.typ = node.typ tmp else: fallback diff --git a/compiler/spawn.nim b/compiler/spawn.nim index c769d17dad89..cd5d8031ccd1 100644 --- a/compiler/spawn.nim +++ b/compiler/spawn.nim @@ -16,7 +16,7 @@ from trees import getMagic, getRoot proc callProc(a: PNode): PNode = result = newNodeI(nkCall, a.info) result.add a - result.typ() = a.typ.returnType + result.typ = a.typ.returnType # we have 4 cases to consider: # - a void proc --> nothing to do @@ -117,7 +117,7 @@ proc castToVoidPointer(g: ModuleGraph, n: PNode, fvField: PNode): PNode = result = newNodeI(nkCast, fvField.info) result.add newNodeI(nkEmpty, fvField.info) result.add fvField - result.typ() = ptrType + result.typ = ptrType proc createWrapperProc(g: ModuleGraph; f: PNode; threadParam, argsParam: PSym; varSection, varInit, call, barrier, fv: PNode; @@ -200,7 +200,7 @@ proc createCastExpr(argsParam: PSym; objType: PType; idgen: IdGenerator): PNode result = newNodeI(nkCast, argsParam.info) result.add newNodeI(nkEmpty, argsParam.info) result.add newSymNode(argsParam) - result.typ() = newType(tyPtr, idgen, objType.owner) + result.typ = newType(tyPtr, idgen, objType.owner) result.typ.rawAddSon(objType) template checkMagicProcs(g: ModuleGraph, n: PNode, formal: PNode) = @@ -266,9 +266,9 @@ proc setupArgsForParallelism(g: ModuleGraph; n: PNode; objType: PType; if argType.kind in {tyVarargs, tyOpenArray}: # important special case: we always create a zero-copy slice: let slice = newNodeI(nkCall, n.info, 4) - slice.typ() = n.typ + slice.typ = n.typ slice[0] = newSymNode(createMagic(g, idgen, "slice", mSlice)) - slice[0].typ() = getSysType(g, n.info, tyInt) # fake type + slice[0].typ = getSysType(g, n.info, tyInt) # fake type var fieldB = newSym(skField, tmpName, idgen, objType.owner, n.info, g.config.options) fieldB.typ = getSysType(g, n.info, tyInt) discard objType.addField(fieldB, g.cache, idgen) diff --git a/compiler/transf.nim b/compiler/transf.nim index b388b36958e5..5c56c1997a81 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -364,7 +364,7 @@ proc transformAsgn(c: PTransf, n: PNode): PNode = # given tuple type newTupleConstr[i] = def[0] - newTupleConstr.typ() = rhs.typ + newTupleConstr.typ = rhs.typ let asgnNode = newTransNode(nkAsgn, n.info, 2) asgnNode[0] = transform(c, n[0]) @@ -498,9 +498,9 @@ proc transformAddrDeref(c: PTransf, n: PNode, kinds: TNodeKinds, isAddr = false) n[0][0] = m[0] result = n[0] if n.typ.skipTypes(abstractVar).kind != tyOpenArray: - result.typ() = n.typ + result.typ = n.typ elif n.typ.skipTypes(abstractInst).kind in {tyVar}: - result.typ() = toVar(result.typ, n.typ.skipTypes(abstractInst).kind, c.idgen) + result.typ = toVar(result.typ, n.typ.skipTypes(abstractInst).kind, c.idgen) of nkHiddenStdConv, nkHiddenSubConv, nkConv: var m = n[0][1] if m.kind in kinds: @@ -508,9 +508,9 @@ proc transformAddrDeref(c: PTransf, n: PNode, kinds: TNodeKinds, isAddr = false) n[0][1] = m[0] result = n[0] if n.typ.skipTypes(abstractVar).kind != tyOpenArray: - result.typ() = n.typ + result.typ = n.typ elif n.typ.skipTypes(abstractInst).kind in {tyVar}: - result.typ() = toVar(result.typ, n.typ.skipTypes(abstractInst).kind, c.idgen) + result.typ = toVar(result.typ, n.typ.skipTypes(abstractInst).kind, c.idgen) else: if n[0].kind in kinds and not (n[0][0].kind == nkSym and n[0][0].sym.kind == skForVar and @@ -525,7 +525,7 @@ proc transformAddrDeref(c: PTransf, n: PNode, kinds: TNodeKinds, isAddr = false) # addr ( deref ( x )) --> x result = n[0][0] if n.typ.skipTypes(abstractVar).kind != tyOpenArray: - result.typ() = n.typ + result.typ = n.typ proc generateThunk(c: PTransf; prc: PNode, dest: PType): PNode = ## Converts 'prc' into '(thunk, nil)' so that it's compatible with @@ -566,7 +566,7 @@ proc transformConv(c: PTransf, n: PNode): PNode = getSysType(c.graph, n.info, tyInt32) else: getSysType(c.graph, n.info, tyInt64) - result[0] = + result[0] = newTreeIT(n.kind, n.info, n.typ, n[0], newTreeIT(nkConv, n.info, intType, newNodeIT(nkType, n.info, intType), transform(c, n[1])) @@ -611,7 +611,7 @@ proc transformConv(c: PTransf, n: PNode): PNode = else: result = transform(c, n[1]) #result = transformSons(c, n) - result.typ() = takeType(n.typ, n[1].typ, c.graph, c.idgen) + result.typ = takeType(n.typ, n[1].typ, c.graph, c.idgen) #echo n.info, " came here and produced ", typeToString(result.typ), # " from ", typeToString(n.typ), " and ", typeToString(n[1].typ) of tyCstring: @@ -639,7 +639,7 @@ proc transformConv(c: PTransf, n: PNode): PNode = result[0] = transform(c, n[1]) else: result = transform(c, n[1]) - result.typ() = n.typ + result.typ = n.typ else: result = transformSons(c, n) of tyObject: @@ -652,7 +652,7 @@ proc transformConv(c: PTransf, n: PNode): PNode = result[0] = transform(c, n[1]) else: result = transform(c, n[1]) - result.typ() = n.typ + result.typ = n.typ of tyGenericParam, tyOrdinal: result = transform(c, n[1]) # happens sometimes for generated assignments, etc. @@ -838,7 +838,7 @@ proc transformFor(c: PTransf, n: PNode): PNode = addVar(v, temp) stmtList.add(newAsgnStmt(c, nkFastAsgn, temp, arg[0], true)) let newD = newDeref(temp) - newD.typ() = t + newD.typ = t newC.mapping[formal.itemId] = newD else: # generate a temporary and produce an assignment statement: @@ -892,7 +892,7 @@ proc transformCase(c: PTransf, n: PNode): PNode = # as an expr let kind = if n.typ != nil: nkIfExpr else: nkIfStmt ifs = newTransNode(kind, it.info, 0) - ifs.typ() = n.typ + ifs.typ = n.typ ifs.add(e) of nkElse: if ifs == nil: result.add(e) @@ -1026,7 +1026,7 @@ proc transformExceptBranch(c: PTransf, n: PNode): PNode = let convNode = newTransNode(nkHiddenSubConv, n[1].info, 2) convNode[0] = newNodeI(nkEmpty, n.info) convNode[1] = excCall - convNode.typ() = excTypeNode.typ.toRef(c.idgen) + convNode.typ = excTypeNode.typ.toRef(c.idgen) # -> let exc = ... let identDefs = newTransNode(nkIdentDefs, n[1].info, 3) identDefs[0] = n[0][2] @@ -1086,7 +1086,7 @@ proc transformDerefBlock(c: PTransf, n: PNode): PNode = # We transform (block: x)[] to (block: x[]) let e0 = n[0] result = shallowCopy(e0) - result.typ() = n.typ + result.typ = n.typ for i in 0 ..< e0.len - 1: result[i] = e0[i] result[e0.len-1] = newTreeIT(nkHiddenDeref, n.info, n.typ, e0[e0.len-1]) @@ -1291,7 +1291,7 @@ proc liftDeferAux(n: PNode) = tryStmt.add deferPart n[i] = tryStmt n.sons.setLen(i+1) - n.typ() = tryStmt.typ + n.typ = tryStmt.typ goOn = true break for i in 0..n.safeLen-1: diff --git a/compiler/types.nim b/compiler/types.nim index 6fcf2e14e207..61d6ba201e6a 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -102,7 +102,7 @@ const # typedescX is used if we're sure tyTypeDesc should be included (or skipped) typedescPtrs* = abstractPtrs + {tyTypeDesc} typedescInst* = abstractInst + {tyTypeDesc, tyOwned, tyUserTypeClass} - + # incorrect definition of `[]` and `[]=` for these types in system.nim arrPutGetMagicApplies* = {tyArray, tyOpenArray, tyString, tySequence, tyCstring, tyTuple} @@ -1238,7 +1238,7 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool = x + {tyRange} else: x - + template withoutShallowFlags(body) = let oldFlags = c.flags c.flags.excl IgnoreRangeShallow @@ -1744,7 +1744,7 @@ proc skipHidden*(n: PNode): PNode = proc skipConvTakeType*(n: PNode): PNode = result = n.skipConv - result.typ() = n.typ + result.typ = n.typ proc isEmptyContainer*(t: PType): bool = case t.kind @@ -1784,7 +1784,7 @@ proc skipHiddenSubConv*(n: PNode; g: ModuleGraph; idgen: IdGenerator): PNode = result = n else: result = copyTree(result) - result.typ() = dest + result.typ = dest else: result = n @@ -2014,7 +2014,7 @@ proc nominalRoot*(t: PType): PType = ## i.e. the type directly associated with the symbol where the root ## nominal type of `t` was defined, skipping things like generic instances, ## aliases, `var`/`sink`/`typedesc` modifiers - ## + ## ## instead of returning the uninstantiated body of a generic type, ## returns the type of the symbol instead (with tyGenericBody type) result = nil diff --git a/compiler/vm.nim b/compiler/vm.nim index bd07f7f7bdae..08ac142f3700 100644 --- a/compiler/vm.nim +++ b/compiler/vm.nim @@ -202,7 +202,7 @@ proc copyValue(src: PNode): PNode = return src result = newNode(src.kind) result.info = src.info - result.typ() = src.typ + result.typ = src.typ result.flags = src.flags * PersistentNodeFlags result.comment = src.comment when defined(useNodeIds): @@ -1557,10 +1557,10 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = # Set the `name` field of the exception var exceptionNameNode = newStrNode(nkStrLit, c.currentExceptionA.typ.sym.name.s) if c.currentExceptionA[2].kind == nkExprColonExpr: - exceptionNameNode.typ() = c.currentExceptionA[2][1].typ + exceptionNameNode.typ = c.currentExceptionA[2][1].typ c.currentExceptionA[2][1] = exceptionNameNode else: - exceptionNameNode.typ() = c.currentExceptionA[2].typ + exceptionNameNode.typ = c.currentExceptionA[2].typ c.currentExceptionA[2] = exceptionNameNode c.exceptionInstr = pc @@ -1602,7 +1602,7 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg = let instr2 = c.code[pc] let count = regs[instr2.regA].intVal.int regs[ra].node = newNodeI(nkBracket, c.debug[pc]) - regs[ra].node.typ() = typ + regs[ra].node.typ = typ newSeq(regs[ra].node.sons, count) for i in 0.. x @@ -1696,7 +1696,7 @@ proc genAsgn(c: PCtx; le, ri: PNode; requiresCopy: bool) = proc genTypeLit(c: PCtx; t: PType; dest: var TDest) = var n = newNode(nkType) - n.typ() = t + n.typ = t genLit(c, n, dest) proc isEmptyBody(n: PNode): bool = @@ -1865,7 +1865,7 @@ proc genCheckedObjAccessAux(c: PCtx; n: PNode; dest: var TDest; flags: TGenFlags let fieldName = $accessExpr[1] let msg = genFieldDefect(c.config, fieldName, disc.sym) let strLit = newStrNode(msg, accessExpr[1].info) - strLit.typ() = strType + strLit.typ = strType c.genLit(strLit, msgReg) c.gABC(n, opcInvalidField, msgReg, discVal) c.freeTemp(discVal) diff --git a/compiler/vtables.nim b/compiler/vtables.nim index b9c64ef687c7..61d0330bbe5e 100644 --- a/compiler/vtables.nim +++ b/compiler/vtables.nim @@ -32,13 +32,13 @@ proc dispatch(x: Base, params: ...) = dispatchObject, newIntNode(nkIntLit, index) ) - getVTableCall.typ() = getSysType(g, unknownLineInfo, tyPointer) + getVTableCall.typ = getSysType(g, unknownLineInfo, tyPointer) var vTableCall = newNodeIT(nkCall, base.info, base.typ.returnType) var castNode = newTree(nkCast, newNodeIT(nkType, base.info, base.typ), getVTableCall) - castNode.typ() = base.typ + castNode.typ = base.typ vTableCall.add castNode for col in 1.. Date: Wed, 10 Dec 2025 14:11:08 +0100 Subject: [PATCH 06/13] progress --- compiler/ast.nim | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/compiler/ast.nim b/compiler/ast.nim index 3f6bf4c40693..6b00935c6115 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -363,8 +363,7 @@ proc size*(t: PType): BiggestInt {.inline.} = result = t.sizeImpl proc `size=`*(t: PType, val: BiggestInt) {.inline.} = - assert t.state != Sealed - if t.state == Partial: loadType(t) + backendEnsureMutable t t.sizeImpl = val proc align*(t: PType): int16 {.inline.} = @@ -372,8 +371,7 @@ proc align*(t: PType): int16 {.inline.} = result = t.alignImpl proc `align=`*(t: PType, val: int16) {.inline.} = - assert t.state != Sealed - if t.state == Partial: loadType(t) + backendEnsureMutable t t.alignImpl = val proc paddingAtEnd*(t: PType): int16 {.inline.} = @@ -381,8 +379,7 @@ proc paddingAtEnd*(t: PType): int16 {.inline.} = result = t.paddingAtEndImpl proc `paddingAtEnd=`*(t: PType, val: int16) {.inline.} = - assert t.state != Sealed - if t.state == Partial: loadType(t) + backendEnsureMutable t t.paddingAtEndImpl = val proc loc*(t: PType): TLoc {.inline.} = From 4f6e808fca1c2acb2c55e6678d30a522167a2426 Mon Sep 17 00:00:00 2001 From: araq Date: Wed, 10 Dec 2025 20:33:10 +0100 Subject: [PATCH 07/13] rename --- compiler/ast2nif.nim | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index a7d4de8906f5..ea5a8ee0a84a 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -844,7 +844,7 @@ proc getOffset(c: var DecodeContext; module: FileIndex; nifName: string): NifInd proc loadNode(c: var DecodeContext; n: var Cursor; thisModule: string; localSyms: var Table[string, PSym]): PNode -proc loadTypeStub(c: var DecodeContext; t: SymId): PType = +proc createTypeStub(c: var DecodeContext; t: SymId): PType = let name = pool.syms[t] assert name.startsWith("`t") var i = len("`t") @@ -907,12 +907,12 @@ proc loadTypeStub(c: var DecodeContext; n: var Cursor): PType = inc n elif n.kind == Symbol: let s = n.symId - result = loadTypeStub(c, s) + result = createTypeStub(c, s) inc n elif n.kind == ParLe and n.tagId == tdefTag: let s = n.firstSon.symId skip n - result = loadTypeStub(c, s) + result = createTypeStub(c, s) else: raiseAssert "type expected but got " & $n.kind @@ -1208,6 +1208,7 @@ proc loadNode(c: var DecodeContext; n: var Cursor; thisModule: string; let id = ItemId(module: module.int32, item: val[]) sym = PSym(itemId: id, kindImpl: skStub, name: c.cache.getIdent(sn.name), disamb: sn.count.int32, state: Complete) + echo "registering local sym: ", symName localSyms[symName] = sym # register for later references # Now fully load the symbol from the sdef inc n # skip `sd` tag From d39f328852ef7110528b13dd1d27004d666c5097 Mon Sep 17 00:00:00 2001 From: araq Date: Thu, 11 Dec 2025 08:31:43 +0100 Subject: [PATCH 08/13] things begin to make sense --- compiler/ast2nif.nim | 41 +++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index ea5a8ee0a84a..cf1e02ad3534 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -901,7 +901,9 @@ proc extractLocalSymsFromTree(c: var DecodeContext; n: var Cursor; thisModule: s break inc n -proc loadTypeStub(c: var DecodeContext; n: var Cursor): PType = +proc loadTypeFromCursor(c: var DecodeContext; n: var Cursor; t: PType; localSyms: var Table[string, PSym]) + +proc loadTypeStub(c: var DecodeContext; n: var Cursor; localSyms: var Table[string, PSym]): PType = if n.kind == DotToken: result = nil inc n @@ -911,8 +913,8 @@ proc loadTypeStub(c: var DecodeContext; n: var Cursor): PType = inc n elif n.kind == ParLe and n.tagId == tdefTag: let s = n.firstSon.symId - skip n result = createTypeStub(c, s) + loadTypeFromCursor(c, n, result, localSyms) else: raiseAssert "type expected but got " & $n.kind @@ -997,21 +999,11 @@ proc loadLoc(c: var DecodeContext; n: var Cursor; loc: var TLoc) = loadField loc.flags loadField loc.snippet -proc loadType*(c: var DecodeContext; t: PType) = - if t.state != Partial: return - t.state = Sealed - var buf = createTokenBuf(30) - let typeName = typeToNifSym(t, c.infos.config) - var n = cursorFromIndexEntry(c, t.itemId.module.FileIndex, c.types[typeName][1], buf) - +proc loadTypeFromCursor(c: var DecodeContext; n: var Cursor; t: PType; localSyms: var Table[string, PSym]) = expect n, ParLe if n.tagId != tdefTag: raiseAssert "(td) expected" - # Pre-scan the ENTIRE type definition for local symbol definitions (sdefs). - # We need to do this before loading any fields, because local symbols may be - # defined anywhere in the type and referenced anywhere else. - var localSyms = initTable[string, PSym]() var scanCursor = n # copy cursor at start of type let typesModule = parseSymName(pool.syms[n.firstSon.symId]).module extractLocalSymsFromTree(c, scanCursor, typesModule, localSyms) @@ -1028,17 +1020,26 @@ proc loadType*(c: var DecodeContext; t: PType) = loadField t.paddingAtEndImpl loadField t.itemId.item # nonUniqueId - t.typeInstImpl = loadTypeStub(c, n) + t.typeInstImpl = loadTypeStub(c, n, localSyms) t.nImpl = loadNode(c, n, typesModule, localSyms) t.ownerFieldImpl = loadSymStub(c, n, typesModule, localSyms) t.symImpl = loadSymStub(c, n, typesModule, localSyms) loadLoc c, n, t.locImpl while n.kind != ParRi: - t.sonsImpl.add loadTypeStub(c, n) + t.sonsImpl.add loadTypeStub(c, n, localSyms) skipParRi n +proc loadType*(c: var DecodeContext; t: PType) = + if t.state != Partial: return + t.state = Sealed + var buf = createTokenBuf(30) + let typeName = typeToNifSym(t, c.infos.config) + var n = cursorFromIndexEntry(c, t.itemId.module.FileIndex, c.types[typeName][1], buf) + var localSyms = initTable[string, PSym]() + loadTypeFromCursor(c, n, t, localSyms) + proc loadAnnex(c: var DecodeContext; n: var Cursor; thisModule: string; localSyms: var Table[string, PSym]): PLib = if n.kind == DotToken: result = nil @@ -1103,7 +1104,7 @@ proc loadSymFromCursor(c: var DecodeContext; s: PSym; n: var Cursor; thisModule: # Local symbols were already extracted upfront in loadSym, so we can use # the simple loadTypeStub here. - s.typImpl = loadTypeStub(c, n) + s.typImpl = loadTypeStub(c, n, localSyms) s.ownerFieldImpl = loadSymStub(c, n, thisModule, localSyms) # Load the AST for routine symbols (procs, funcs, etc.) if s.kindImpl in routineKinds: @@ -1148,7 +1149,7 @@ template withNode(c: var DecodeContext; n: var Cursor; result: PNode; kind: TNod let flags = loadAtom(TNodeFlags, n) result = newNodeI(kind, info) result.flags = flags - result.typField = c.loadTypeStub(n) + result.typField = c.loadTypeStub(n, localSyms) body skipParRi n @@ -1182,7 +1183,7 @@ proc loadNode(c: var DecodeContext; n: var Cursor; thisModule: string; case pool.tags[n.tagId] of hiddenTypeTagName: inc n - let typ = c.loadTypeStub(n) + let typ = c.loadTypeStub(n, localSyms) let info = c.infos.oldLineInfo(n.info) result = newSymNode(c.loadSymStub(n, thisModule, localSyms), info) result.typField = typ @@ -1232,13 +1233,13 @@ proc loadNode(c: var DecodeContext; n: var Cursor; thisModule: string; inc n if n.kind != ParRi: result.flags = loadAtom(TNodeFlags, n) - result.typField = c.loadTypeStub(n) + result.typField = c.loadTypeStub(n, localSyms) skipParRi n of nkIdent: let info = c.infos.oldLineInfo(n.info) inc n let flags = loadAtom(TNodeFlags, n) - let typ = c.loadTypeStub(n) + let typ = c.loadTypeStub(n, localSyms) expect n, Ident result = newIdentNode(c.cache.getIdent(pool.strings[n.litId]), info) inc n From 97dfba822280ca2c06e572de8010becfa8accbe6 Mon Sep 17 00:00:00 2001 From: araq Date: Thu, 11 Dec 2025 08:48:44 +0100 Subject: [PATCH 09/13] disabled debug echo --- compiler/ast2nif.nim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index cf1e02ad3534..ddf41e1abc41 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -1209,7 +1209,7 @@ proc loadNode(c: var DecodeContext; n: var Cursor; thisModule: string; let id = ItemId(module: module.int32, item: val[]) sym = PSym(itemId: id, kindImpl: skStub, name: c.cache.getIdent(sn.name), disamb: sn.count.int32, state: Complete) - echo "registering local sym: ", symName + #echo "registering local sym: ", symName localSyms[symName] = sym # register for later references # Now fully load the symbol from the sdef inc n # skip `sd` tag From 95aca6facbde6376f5543d754a380d9c029ab2c9 Mon Sep 17 00:00:00 2001 From: araq Date: Thu, 11 Dec 2025 08:48:53 +0100 Subject: [PATCH 10/13] generally useful refactoring --- compiler/cgen.nim | 23 +++++++++++------------ compiler/ic/cbackend.nim | 2 +- compiler/nifbackend.nim | 2 +- compiler/pipelines.nim | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index d3d68970f8ef..1b64a64dafa5 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -1285,7 +1285,7 @@ proc genProcBody(p: BProc; procBody: PNode) = p.blocks[0].sections[cpsInit].addAssignmentWithValue("nimErr_"): p.blocks[0].sections[cpsInit].addCall(cgsymValue(p.module, "nimErrorFlag")) -proc genProcAux*(m: BModule, prc: PSym) = +proc genProcLvl3*(m: BModule, prc: PSym) = var p = newProc(prc, m) var header = newBuilder("") let isCppMember = m.config.backend == backendCpp and sfCppMember * prc.flags != {} @@ -1469,8 +1469,7 @@ proc genProcPrototype(m: BModule, sym: PSym) = include inliner -# TODO: figure out how to rename this - it DOES generate a forward declaration -proc genProcNoForward(m: BModule, prc: PSym) = +proc genProcLvl2(m: BModule, prc: PSym) = if lfImportCompilerProc in prc.loc.flags: fillProcLoc(m, prc.ast[namePos]) useHeader(m, prc) @@ -1511,7 +1510,7 @@ proc genProcNoForward(m: BModule, prc: PSym) = let prcCopy = prc # copyInlineProc(prc, m.idgen) fillProcLoc(m, prcCopy.ast[namePos]) genProcPrototype(m, prcCopy) - genProcAux(m, prcCopy) + genProcLvl3(m, prcCopy) else: let m2 = if m.config.symbolFiles != disabledSf: m else: findPendingModule(m, prc) @@ -1522,7 +1521,7 @@ proc genProcNoForward(m: BModule, prc: PSym) = # #prc.loc.snippet = nil # #prc.loc.snippet = mangleName(m, prc) genProcPrototype(m, prc) - genProcAux(m, prc) + genProcLvl3(m, prc) elif sfImportc notin prc.flags: var q = findPendingModule(m, prc) fillProcLoc(q, prc.ast[namePos]) @@ -1543,7 +1542,7 @@ proc genProcNoForward(m: BModule, prc: PSym) = # which will actually become a function pointer if isReloadable(m, prc): genProcPrototype(q, prc) - genProcAux(q, prc) + genProcLvl3(q, prc) else: fillProcLoc(m, prc.ast[namePos]) useHeader(m, prc) @@ -1569,13 +1568,13 @@ proc genProc(m: BModule, prc: PSym) = addForwardedProc(m, prc) fillProcLoc(m, prc.ast[namePos]) else: - genProcNoForward(m, prc) + genProcLvl2(m, prc) if {sfExportc, sfCompilerProc} * prc.flags == {sfExportc} and m.g.generatedHeader != nil and lfNoDecl notin prc.loc.flags: genProcPrototype(m.g.generatedHeader, prc) if prc.typ.callConv == ccInline: if not containsOrIncl(m.g.generatedHeader.declaredThings, prc.id): - genProcAux(m.g.generatedHeader, prc) + genProcLvl3(m.g.generatedHeader, prc) proc genVarPrototype(m: BModule, n: PNode) = #assert(sfGlobal in sym.flags) @@ -2523,7 +2522,7 @@ proc writeModule(m: BModule, pending: bool) = while m.queue.len > 0: let sym = m.queue.pop() - genProcNoForward(m, sym) + genProcLvl2(m, sym) finishTypeDescriptions(m) if sfMainModule in m.module.flags: @@ -2588,7 +2587,7 @@ proc finalCodegenActions*(graph: ModuleGraph; m: BModule; n: PNode) = body.add graph.globalDestructors[i] body.flags.incl nfTransf # should not be further transformed let dtor = generateLibraryDestroyGlobals(graph, m, body, optGenDynLib in m.config.globalOptions) - genProcAux(m, dtor) + genProcLvl3(m, dtor) if pipelineutils.skipCodegen(m.config, n): return if moduleHasChanged(graph, m.module): # if the module is cached, we don't regenerate the main proc @@ -2641,7 +2640,7 @@ proc finalCodegenActions*(graph: ModuleGraph; m: BModule; n: PNode) = proc genForwardedProcs(g: BModuleList) = # Forward declared proc:s lack bodies when first encountered, so they're given # a second pass here - # Note: ``genProcNoForward`` may add to ``forwardedProcs`` + # Note: ``genProcLvl2`` may add to ``forwardedProcs`` while g.forwardedProcs.len > 0: let prc = g.forwardedProcs.pop() @@ -2649,7 +2648,7 @@ proc genForwardedProcs(g: BModuleList) = if sfForward in prc.flags: internalError(m.config, prc.info, "still forwarded: " & prc.name.s) - genProcNoForward(m, prc) + genProcLvl2(m, prc) proc cgenWriteModules*(backend: RootRef, config: ConfigRef) = let g = BModuleList(backend) diff --git a/compiler/ic/cbackend.nim b/compiler/ic/cbackend.nim index 83f1b4cc75bd..91147d5e0710 100644 --- a/compiler/ic/cbackend.nim +++ b/compiler/ic/cbackend.nim @@ -52,7 +52,7 @@ proc generateCodeForModule(g: ModuleGraph; m: var LoadedModule; alive: var Alive finalCodegenActions(g, bmod, newNodeI(nkStmtList, m.module.info)) for disp in getDispatchers(g): - genProcAux(bmod, disp) + genProcLvl3(bmod, disp) m.fromDisk.backendFlags = cgen.whichInitProcs(bmod) proc replayTypeInfo(g: ModuleGraph; m: var LoadedModule; origin: FileIndex) = diff --git a/compiler/nifbackend.nim b/compiler/nifbackend.nim index 7cd8b1f580a8..7732844cb112 100644 --- a/compiler/nifbackend.nim +++ b/compiler/nifbackend.nim @@ -72,7 +72,7 @@ proc generateCodeForModule(g: ModuleGraph; module: PSym) = # Generate dispatcher methods for disp in getDispatchers(g): - genProcAux(bmod, disp) + genProcLvl3(bmod, disp) proc generateCode*(g: ModuleGraph; mainFileIdx: FileIndex) = ## Main entry point for NIF-based C code generation. diff --git a/compiler/pipelines.nim b/compiler/pipelines.nim index 58f77b6533a3..1c17bae0babd 100644 --- a/compiler/pipelines.nim +++ b/compiler/pipelines.nim @@ -220,7 +220,7 @@ proc processPipelineModule*(graph: ModuleGraph; module: PSym; idgen: IdGenerator if retTyp != nil: # TODO: properly semcheck the code of dispatcher? createTypeBoundOps(graph, ctx, retTyp, disp.ast.info, idgen) - genProcAux(m, disp) + genProcLvl3(m, disp) discard closePContext(graph, ctx, nil) of JSgenPass: when not defined(leanCompiler): From 12bed23c654ea02106f92916dd2a45e6b4c7f4e8 Mon Sep 17 00:00:00 2001 From: araq Date: Thu, 11 Dec 2025 10:00:53 +0100 Subject: [PATCH 11/13] bugfix --- compiler/ast2nif.nim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index ddf41e1abc41..fc7fa8082028 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -914,7 +914,11 @@ proc loadTypeStub(c: var DecodeContext; n: var Cursor; localSyms: var Table[stri elif n.kind == ParLe and n.tagId == tdefTag: let s = n.firstSon.symId result = createTypeStub(c, s) - loadTypeFromCursor(c, n, result, localSyms) + if result.state == Partial: + result.state = Sealed # Mark as loaded to prevent loadType from re-loading with empty localSyms + loadTypeFromCursor(c, n, result, localSyms) + else: + skip n # Type already loaded, skip over the td block else: raiseAssert "type expected but got " & $n.kind @@ -1209,7 +1213,6 @@ proc loadNode(c: var DecodeContext; n: var Cursor; thisModule: string; let id = ItemId(module: module.int32, item: val[]) sym = PSym(itemId: id, kindImpl: skStub, name: c.cache.getIdent(sn.name), disamb: sn.count.int32, state: Complete) - #echo "registering local sym: ", symName localSyms[symName] = sym # register for later references # Now fully load the symbol from the sdef inc n # skip `sd` tag From 1514706def81dbfe10986bd85bac95780cc51f8b Mon Sep 17 00:00:00 2001 From: araq Date: Thu, 11 Dec 2025 10:06:48 +0100 Subject: [PATCH 12/13] consts work --- compiler/ast2nif.nim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/compiler/ast2nif.nim b/compiler/ast2nif.nim index fc7fa8082028..aa67d5e8c996 100644 --- a/compiler/ast2nif.nim +++ b/compiler/ast2nif.nim @@ -406,8 +406,9 @@ proc writeSymDef(w: var Writer; dest: var TokenBuf; sym: PSym) = writeType(w, dest, sym.typImpl) writeSym(w, dest, sym.ownerFieldImpl) - # Store the AST for routine symbols (procs, funcs, etc.) - if sym.kindImpl in routineKinds: + # Store the AST for routine symbols and constants + # Constants need their AST for astdef() to return the constant's value + if sym.kindImpl in routineKinds + {skConst}: writeNode(w, dest, sym.astImpl, forAst = true) else: dest.addDotToken @@ -1110,8 +1111,9 @@ proc loadSymFromCursor(c: var DecodeContext; s: PSym; n: var Cursor; thisModule: # the simple loadTypeStub here. s.typImpl = loadTypeStub(c, n, localSyms) s.ownerFieldImpl = loadSymStub(c, n, thisModule, localSyms) - # Load the AST for routine symbols (procs, funcs, etc.) - if s.kindImpl in routineKinds: + # Load the AST for routine symbols and constants + # Constants need their AST for astdef() to return the constant's value + if s.kindImpl in routineKinds + {skConst}: s.astImpl = loadNode(c, n, thisModule, localSyms) elif n.kind == DotToken: inc n From c1205b2f0aab9bcda6917795fefdc34db9a9e8d8 Mon Sep 17 00:00:00 2001 From: araq Date: Thu, 11 Dec 2025 14:33:53 +0100 Subject: [PATCH 13/13] IC backend: progress --- compiler/cgen.nim | 6 +++++- compiler/commands.nim | 1 - 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 1b64a64dafa5..7fd7b0f8bdf3 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -61,6 +61,8 @@ proc hcrOn(p: BProc): bool = p.module.config.hcrOn proc addForwardedProc(m: BModule, prc: PSym) = m.g.forwardedProcs.add(prc) +proc newModule*(g: BModuleList; module: PSym; conf: ConfigRef): BModule + proc findPendingModule(m: BModule, s: PSym): BModule = # TODO fixme if m.config.symbolFiles == v2Sf or optCompress in m.config.globalOptions: @@ -69,6 +71,8 @@ proc findPendingModule(m: BModule, s: PSym): BModule = else: var ms = getModule(s) result = m.g.modules[ms.position] + if result == nil: + result = newModule(m.g, ms, m.config) proc initLoc(k: TLocKind, lode: PNode, s: TStorageLoc, flags: TLocFlags = {}): TLoc = result = TLoc(k: k, storage: s, lode: lode, @@ -2368,7 +2372,7 @@ proc rawNewModule(g: BModuleList; module: PSym, filename: AbsoluteFile): BModule proc rawNewModule(g: BModuleList; module: PSym; conf: ConfigRef): BModule = result = rawNewModule(g, module, AbsoluteFile toFullPath(conf, module.position.FileIndex)) -proc newModule*(g: BModuleList; module: PSym; conf: ConfigRef): BModule = +proc newModule(g: BModuleList; module: PSym; conf: ConfigRef): BModule = # we should create only one cgen module for each module sym result = rawNewModule(g, module, conf) if module.position >= g.modules.len: diff --git a/compiler/commands.nim b/compiler/commands.nim index f782c6dc3d4e..622e5536fe71 100644 --- a/compiler/commands.nim +++ b/compiler/commands.nim @@ -514,7 +514,6 @@ proc setCmd*(conf: ConfigRef, cmd: Command) = of cmdCompileToNif: conf.backend = backendNif of cmdNifC: conf.backend = backendC # NIF to C compilation - conf.globalOptions.incl optCompress # enable NIF loading of cmdM: # cmdM requires optCompress for proper IC handling (include files, etc.) conf.globalOptions.incl optCompress