diff --git a/compiler/ast.nim b/compiler/ast.nim index 6754f11409..9708252f0e 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -591,7 +591,7 @@ type TNode*{.final, acyclic.} = object # on a 32bit machine, this takes 32 bytes when defined(useNodeIds): id*: int - typ*: PType + typField: PType info*: TLineInfo flags*: TNodeFlags case kind*: TNodeKind @@ -814,6 +814,9 @@ type template nodeId(n: PNode): int = cast[int](n) +template typ*(n: PNode): PType = + n.typField + proc owner*(s: PSym|PType): PSym {.inline.} = result = s.ownerField @@ -1138,7 +1141,7 @@ proc newNodeIT*(kind: TNodeKind, info: TLineInfo, typ: PType): PNode = ## new node with line info, type, and no children result = newNode(kind) result.info = info - result.typ = typ + result.typ() = typ proc newNode*(kind: TNodeKind, info: TLineInfo): PNode = ## new node with line info, no type, and no children @@ -1284,13 +1287,13 @@ proc newIdentNode*(ident: PIdent, info: TLineInfo): PNode = proc newSymNode*(sym: PSym): PNode = result = newNode(nkSym) result.sym = sym - result.typ = sym.typ + result.typ() = sym.typ result.info = sym.info proc newSymNode*(sym: PSym, info: TLineInfo): PNode = result = newNode(nkSym) result.sym = sym - result.typ = sym.typ + result.typ() = sym.typ result.info = info proc newOpenSym*(n: PNode): PNode {.inline.} = @@ -1370,7 +1373,7 @@ proc newIntTypeNode*(intVal: BiggestInt, typ: PType): PNode = result = newNode(nkIntLit) else: raiseAssert $kind result.intVal = intVal - result.typ = typ + result.typ() = typ proc newIntTypeNode*(intVal: Int128, typ: PType): PNode = # XXX: introduce range check @@ -1672,7 +1675,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): @@ -1690,7 +1693,7 @@ proc copyNode*(src: PNode): PNode = template transitionNodeKindCommon(k: TNodeKind) = let obj {.inject.} = n[] - n[] = TNode(kind: k, typ: obj.typ, info: obj.info, flags: obj.flags) + n[] = TNode(kind: k, typField: n.typ, info: obj.info, flags: obj.flags) # n.comment = obj.comment # shouldn't be needed, the address doesnt' change when defined(useNodeIds): n.id = obj.id @@ -1741,7 +1744,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/ccgcalls.nim b/compiler/ccgcalls.nim index ac607e3ada..788f7a470b 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -336,7 +336,7 @@ proc genArg(p: BProc, n: PNode, param: PSym; call: PNode; result: var Rope; need # 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.flags.incl tfVarIsPtr a = initLocExprSingleUse(p, n) a = withTmpIfNeeded(p, a, needsTmp) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 587dee5b58..f1598ce817 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1626,7 +1626,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: @@ -3077,7 +3077,7 @@ proc expr(p: BProc, n: PNode, d: var TLoc) = # addr ( deref ( x )) --> x var x = n[0][0] if n.typ.skipTypes(abstractVar).kind != tyOpenArray: - x.typ = n.typ + x.typ() = n.typ expr(p, x, d) return genAddr(p, n, d) diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 091f5c8429..266d486b0a 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 ca97d04944..fe6da1c1eb 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: @@ -675,7 +675,7 @@ proc defaultNodeField(c: PContext, a: PNode, aTyp: PType, checkDefault: bool): P semExprWithType(c, child), node )) - result.typ = aTyp + result.typ() = aTyp else: result = nil of tyTuple: @@ -684,7 +684,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 72dcedf99c..89d1b6a7b4 100644 --- a/compiler/semcall.nim +++ b/compiler/semcall.nim @@ -636,7 +636,7 @@ proc instGenericConvertersArg*(c: PContext, a: PNode, x: TCandidate) = if s.isGenericRoutineStrict: let finalCallee = generateInstance(c, s, x.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) = @@ -671,13 +671,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 @@ -700,7 +700,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 = @@ -784,7 +784,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.flags, tfCheckedForDestructor return let gp = finalCallee.ast[genericParamsPos] @@ -811,7 +811,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 @@ -821,7 +821,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.} = @@ -830,7 +830,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, @@ -849,7 +849,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 efExplain notin flags: # repeat the overload resolution, # this time enabling all the diagnostic output (this should fail again) @@ -893,9 +893,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): PNode = assert n.kind == nkBracketExpr diff --git a/compiler/semdata.nim b/compiler/semdata.nim index 1888d8f6e1..688cd97009 100644 --- a/compiler/semdata.nim +++ b/compiler/semdata.nim @@ -195,29 +195,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") @@ -449,7 +449,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 = @@ -508,7 +508,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 = @@ -564,7 +564,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}: diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index ef389c7ca4..e45ef74c4c 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -56,11 +56,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) @@ -82,14 +82,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 @@ -101,7 +101,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) @@ -110,7 +110,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) @@ -194,7 +194,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: @@ -216,7 +216,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) @@ -227,7 +227,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 @@ -395,7 +395,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 @@ -413,7 +413,7 @@ proc semConv(c: PContext, n: PNode; flags: TExprFlags = {}, expectedType: PType if targetType.kind == tyOwned: t.flags.incl tfHasOwned result = newNodeI(nkType, n.info) - result.typ = makeTypeDesc(c, t) + result.typ() = makeTypeDesc(c, t) return result.add copyTree(n[0]) @@ -429,10 +429,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 @@ -440,7 +440,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): @@ -490,7 +490,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 @@ -504,18 +504,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 @@ -531,7 +531,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` @@ -581,7 +581,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: @@ -590,7 +590,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}) @@ -604,7 +604,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): @@ -634,7 +634,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) @@ -707,7 +707,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) @@ -729,12 +729,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 @@ -1002,7 +1002,7 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode = if n[i].typ.isNil or n[i].typ.kind != tyStatic or tfUnresolved notin n[i].typ.flags: break maybeLabelAsStatic - n.typ = newTypeS(tyStatic, c, n.typ) + n.typ() = newTypeS(tyStatic, c, n.typ) n.typ.flags.incl tfUnresolved # optimization pass: not necessary for correctness of the semantic pass @@ -1091,7 +1091,7 @@ proc semOverloadedCallAnalyseEffects(c: PContext, n: PNode, nOrig: PNode, if efWantIterable in flags: let typ = newTypeS(tyIterable, c) rawAddSon(typ, result.typ) - result.typ = typ + result.typ() = typ proc resolveIndirectCall(c: PContext; n, nOrig: PNode; t: PType): TCandidate = @@ -1178,7 +1178,7 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType elif n0.typ.kind == tyFromExpr and c.inGenericContext > 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 @@ -1436,7 +1436,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: @@ -1482,11 +1482,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 @@ -1495,7 +1495,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) @@ -1521,7 +1521,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: @@ -1529,7 +1529,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: @@ -1538,12 +1538,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 @@ -1561,14 +1561,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) @@ -1615,7 +1615,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: @@ -1655,12 +1655,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) @@ -1669,7 +1669,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 @@ -1718,9 +1718,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) @@ -1765,7 +1765,7 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode = 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) @@ -1787,18 +1787,18 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode = 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 @@ -1808,7 +1808,7 @@ proc semSubscript(c: PContext, n: PNode, flags: TExprFlags): PNode = 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" % @@ -1900,7 +1900,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.} = @@ -2068,7 +2068,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: @@ -2079,7 +2079,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: @@ -2127,7 +2127,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 @@ -2230,7 +2230,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 @@ -2268,7 +2268,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 @@ -2341,10 +2341,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 = @@ -2514,7 +2514,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: @@ -2558,7 +2558,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 = @@ -2600,7 +2600,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: @@ -2626,9 +2626,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 @@ -2636,7 +2636,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': @@ -2767,18 +2767,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.flags.incl tfIsConstructor var expectedElementType: PType = nil if expectedType != nil and ( @@ -2804,7 +2804,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: @@ -2919,7 +2919,7 @@ proc semTupleFieldsConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType if n[i][1].typ.kind == tyTypeDesc: localError(c.config, n[i][1].info, "typedesc not allowed as tuple field.") - n[i][1].typ = errorType(c) + n[i][1].typ() = errorType(c) var f = newSymS(skField, n[i][0], c) f.typ = skipIntLit(n[i][1].typ.skipTypes({tySink}), c.idgen) @@ -2928,7 +2928,7 @@ proc semTupleFieldsConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType typ.n.add newSymNode(f) n[i][0] = newSymNode(f) result.add n[i] - result.typ = typ + result.typ() = typ proc semTuplePositionsConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType = nil): PNode = result = n # we don't modify n, but compute the type: @@ -2949,7 +2949,7 @@ proc semTuplePositionsConstr(c: PContext, n: PNode, flags: TExprFlags; expectedT # `const foo = if true: (0, nil) else: (1, new(int))` n[i] = fitNode(c, expectedElemType, n[i], n[i].info) addSonSkipIntLit(typ, n[i].typ.skipTypes({tySink}), c.idgen) - result.typ = typ + result.typ() = typ include semobjconstr @@ -2971,7 +2971,7 @@ proc semBlock(c: PContext, n: PNode; flags: TExprFlags; expectedType: PType = ni styleCheckDef(c, labl) onDef(n[0].info, labl) n[1] = semExpr(c, n[1], flags, expectedType) - n.typ = n[1].typ + n.typ() = n[1].typ if isEmptyType(n.typ): n.transitionSonsKind(nkBlockStmt) else: n.transitionSonsKind(nkBlockExpr) closeScope(c) @@ -3049,7 +3049,7 @@ proc semTupleConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PTyp if isTupleType: # expressions as ``(int, string)`` are reinterpret as type expressions result = n var typ = semTypeNode(c, n, nil).skipTypes({tyTypeDesc}) - result.typ = makeTypeDesc(c, typ) + result.typ() = makeTypeDesc(c, typ) else: result = tupexp @@ -3271,10 +3271,10 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType if expectedType != nil and ( let expected = expectedType.skipTypes(abstractRange-{tyDistinct}); expected.kind == typeKind): - result.typ = expected + result.typ() = expected changeType(c, result, expectedType, check=true) else: - result.typ = getSysType(c.graph, n.info, typeKind) + result.typ() = getSysType(c.graph, n.info, typeKind) result = n when defined(nimsuggest): @@ -3309,7 +3309,7 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType # localError(c.config, n.info, errInstantiateXExplicitly, s.name.s) # "procs literals" are 'owned' if optOwnedRefs in c.config.globalOptions: - result.typ = makeVarType(c, result.typ, tyOwned) + result.typ() = makeVarType(c, result.typ, tyOwned) of skEnumField: result = enumFieldSymChoice(c, n, s, flags) else: @@ -3338,11 +3338,11 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType discard of nkNilLit: if result.typ == nil: - result.typ = getNilType(c) + result.typ() = getNilType(c) if expectedType != nil and expectedType.kind notin {tyUntyped, tyTyped}: var m = newCandidate(c, result.typ) if typeRel(m, expectedType, result.typ) >= isSubtype: - result.typ = expectedType + result.typ() = expectedType # or: result = fitNode(c, expectedType, result, n.info) of nkIntLit: if result.typ == nil: @@ -3370,10 +3370,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) @@ -3382,9 +3382,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) @@ -3399,13 +3399,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/semfold.nim b/compiler/semfold.nim index 80144ccc04..8acb312c63 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 @@ -316,7 +316,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: @@ -411,7 +411,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: @@ -428,7 +428,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) @@ -438,12 +438,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: @@ -514,10 +514,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 @@ -636,7 +636,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: @@ -749,7 +749,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: @@ -760,7 +760,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 @@ -777,7 +777,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 74f77a679c..cb51973857 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, diff --git a/compiler/seminst.nim b/compiler/seminst.nim index 00f81a2f27..ab00810f92 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 727f364706..67cc86a14d 100644 --- a/compiler/semmacrosanity.nim +++ b/compiler/semmacrosanity.nim @@ -50,8 +50,8 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef) = 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) elif x.kind == tyProc and x.callConv == ccClosure: - n.typ = t + n.typ() = t elif x.kind == tyOpenArray: # `opcSlice` transforms slices into tuples if n.kind == nkTupleConstr: let @@ -88,39 +88,39 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef) = 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) 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: annotateType(m, x.elemType, conf) else: 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 cf5cfad6d8..44356fe957 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) + result.typ() = makePtrType(c, x.typ) proc semTypeOf(c: PContext; n: PNode): PNode = var m = BiggestInt 1 # typeOfIter @@ -55,7 +55,7 @@ proc semTypeOf(c: PContext; n: PNode): PNode = result.add typExpr if typExpr.typ.kind == tyFromExpr: typExpr.typ.flags.incl tfNonConstExpr - result.typ = makeTypeDesc(c, typExpr.typ) + result.typ() = makeTypeDesc(c, typExpr.typ) type SemAsgnMode = enum asgnNormal, noOverloadedSubscript, noOverloadedAsgn @@ -76,7 +76,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.flags.incl tfNonConstExpr return bracketNotFoundError(c, x, flags) @@ -189,15 +189,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 @@ -267,7 +267,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) @@ -383,7 +383,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: @@ -392,10 +392,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 = @@ -430,9 +430,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. @@ -442,7 +442,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): @@ -527,7 +527,7 @@ proc semNewFinalize(c: PContext; n: PNode): PNode = setOwner(fin, fin.instantiatedFrom) 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.flags.incl sfUsed let wrapper = c.semExpr(c, newProcNode(nkProcDef, fin.info, body = newTree(nkCall, newSymNode(fin), selfSymNode), @@ -545,7 +545,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) # TODO: suppress var destructor warnings; if newFinalizer is not # TODO: deprecated, try to implement plain T destructor @@ -601,7 +601,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) @@ -614,7 +614,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: @@ -657,7 +657,7 @@ proc magicsAfterOverloadResolution(c: PContext, n: 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 mWasMoved: result = n @@ -699,7 +699,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 048053115e..e90e0bc810 100644 --- a/compiler/semobjconstr.nim +++ b/compiler/semobjconstr.nim @@ -188,7 +188,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, @@ -475,7 +475,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.flags.incl tfHasOwned diff --git a/compiler/semparallel.nim b/compiler/semparallel.nim index 23a8e63626..b0071979bc 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 0a160897f9..76c3d5290b 100644 --- a/compiler/sempass2.nim +++ b/compiler/sempass2.nim @@ -193,7 +193,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 @@ -411,7 +411,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 @@ -426,12 +426,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) = @@ -1210,7 +1210,7 @@ proc track(tracked: PEffects, n: PNode) = if n.sym.typ != nil and tfHasAsgn in n.sym.typ.flags: tracked.owner.flags.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 2bf5877402..8728359e9f 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() @@ -438,7 +438,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 f71d7986a5..9954e3c123 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -237,10 +237,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: @@ -250,7 +250,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: @@ -268,10 +268,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: @@ -281,7 +281,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) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 6e509ddc1f..870b515121 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -480,7 +480,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 @@ -1381,7 +1381,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 @@ -1519,7 +1519,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, # XXX This rather hacky way keeps 'tflatmap' compiling: if tfHasMeta notin oldFlags: result.flags.excl tfHasMeta - result.n.typ = r + result.n.typ() = r if isCurrentlyGeneric(): for n in genericParams: @@ -1536,8 +1536,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 @@ -1550,15 +1550,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 @@ -1970,7 +1970,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) @@ -2269,7 +2269,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) = @@ -2416,7 +2416,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 09cf422b49..6a7d140cc8 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.flags.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: @@ -696,7 +696,7 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType = 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 9643f37655..b76696230d 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -444,11 +444,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, @@ -457,10 +457,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) @@ -2167,16 +2167,16 @@ 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) 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 @@ -2204,13 +2204,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): @@ -2257,7 +2257,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) @@ -2303,7 +2303,7 @@ proc userConvMatch(c: PContext, m: var TCandidate, f, a: PType, incl(c.converters[i].flags, 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 @@ -2356,7 +2356,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) = @@ -2412,7 +2412,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: @@ -2531,7 +2531,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: @@ -2587,7 +2587,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) @@ -2613,7 +2613,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) @@ -2878,7 +2878,7 @@ proc matchesAux(c: PContext, n, nOrig: PNode, m: var TCandidate, marker: var Int m.baseTypeMatch = false m.typedescMatched = false n[a][1] = prepareOperand(c, formal.typ, n[a][1]) - 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 @@ -3052,7 +3052,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 1dd481ec0b..3a3457cb89 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 58d5a4928c..99b3b55332 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 a302fb52d4..3db861481a 100644 --- a/compiler/transf.nim +++ b/compiler/transf.nim @@ -356,7 +356,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]) @@ -487,9 +487,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: @@ -497,9 +497,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 @@ -513,7 +513,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 @@ -572,7 +572,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: @@ -600,7 +600,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: @@ -613,7 +613,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. @@ -833,7 +833,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) @@ -941,7 +941,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] @@ -998,7 +998,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]) @@ -1202,7 +1202,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 a441b0ea2b..fef564f586 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -1685,7 +1685,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 @@ -1725,7 +1725,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 diff --git a/compiler/vm.nim b/compiler/vm.nim index 93d2f9daed..1be04a922d 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): @@ -1532,10 +1532,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 @@ -1577,7 +1577,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 @@ -1679,7 +1679,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 = @@ -1848,7 +1848,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 928c64dd57..6d481fbb3c 100644 --- a/compiler/vtables.nim +++ b/compiler/vtables.nim @@ -33,13 +33,13 @@ proc dispatch(x: Base, params: ...) = dispatchObject, newIntNode(nkIntLit, index) ) - getVTableCall.typ = base.typ + getVTableCall.typ() = base.typ 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..