mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-24 15:41:43 +00:00
progress
This commit is contained in:
@@ -679,7 +679,7 @@ proc loadAtom[T: int16|int32|int64](t: typedesc[T]; n: var Cursor): T =
|
||||
result = pool.integers[n.intId].T
|
||||
inc n
|
||||
|
||||
template loadField(field) =
|
||||
template loadField(field) {.dirty.} =
|
||||
field = loadAtom(typeof(field), n)
|
||||
|
||||
proc loadLoc(c: var DecodeContext; n: var Cursor; loc: var TLoc) =
|
||||
@@ -713,7 +713,7 @@ proc loadType*(c: var DecodeContext; t: PType) =
|
||||
t.n = loadNode(c, n)
|
||||
t.setOwner loadSymStub(c, n)
|
||||
t.sym = loadSymStub(c, n)
|
||||
loadLoc c, n, t.loc
|
||||
loadLoc c, n, t.locImpl
|
||||
|
||||
var kids: seq[PType] = @[]
|
||||
while n.kind != ParRi:
|
||||
|
||||
@@ -369,7 +369,7 @@ proc genArg(p: BProc, n: PNode, param: PSym; call: PNode; result: var Builder; n
|
||||
let needsIndirect = mapType(p.config, n[0].typ, mapTypeChooser(n[0]) == skParam) != ctArray
|
||||
if needsIndirect:
|
||||
n.typ() = n.typ.exactReplica
|
||||
n.typ.flags.incl tfVarIsPtr
|
||||
n.typ.incl tfVarIsPtr
|
||||
a = initLocExprSingleUse(p, n)
|
||||
a = withTmpIfNeeded(p, a, needsTmp)
|
||||
if needsIndirect: a.flags.incl lfIndirect
|
||||
|
||||
@@ -158,9 +158,10 @@ proc getTypeName(m: BModule; typ: PType; sig: SigHash): Rope =
|
||||
else:
|
||||
break
|
||||
let typ = if typ.kind in {tyAlias, tySink, tyOwned}: typ.elementType else: typ
|
||||
ensureMutable typ
|
||||
if typ.loc.snippet == "":
|
||||
typ.typeName(typ.loc.snippet)
|
||||
typ.loc.snippet.add $sig
|
||||
typ.typeName(typ.locImpl.snippet)
|
||||
typ.locImpl.snippet.add $sig
|
||||
else:
|
||||
when defined(debugSigHashes):
|
||||
# check consistency:
|
||||
@@ -1459,7 +1460,7 @@ proc genObjectInfo(m: BModule; typ, origType: PType, name: Rope; info: TLineInfo
|
||||
var t = typ.baseClass
|
||||
while t != nil:
|
||||
t = t.skipTypes(skipPtrs)
|
||||
t.flags.incl tfObjHasKids
|
||||
t.incl tfObjHasKids
|
||||
t = t.baseClass
|
||||
|
||||
proc genTupleInfo(m: BModule; typ, origType: PType, name: Rope; info: TLineInfo) =
|
||||
|
||||
@@ -33,7 +33,7 @@ proc iterToProcImpl*(c: PContext, n: PNode): PNode =
|
||||
|
||||
let prc = newSym(skProc, n[3].ident, c.idgen, iter.sym.owner, iter.sym.info)
|
||||
prc.typ = copyType(iter.sym.typ, c.idgen, prc)
|
||||
excl prc.typ.flags, tfCapturesEnv
|
||||
excl prc.typ, tfCapturesEnv
|
||||
prc.typ.n.add newSymNode(getEnvParam(iter.sym))
|
||||
prc.typ.rawAddSon t
|
||||
let orig = iter.sym.ast
|
||||
|
||||
@@ -126,7 +126,7 @@ proc fitNodeConsiderViewType(c: PContext, formal: PType, arg: PNode; info: TLine
|
||||
#classifyViewType(formal) != noView:
|
||||
result = newNodeIT(nkHiddenAddr, a.info, formal)
|
||||
result.add a
|
||||
formal.flags.incl tfVarIsPtr
|
||||
formal.incl tfVarIsPtr
|
||||
else:
|
||||
result = a
|
||||
|
||||
|
||||
@@ -847,7 +847,7 @@ proc semResolvedCall(c: PContext, x: var TCandidate,
|
||||
result[0] = newSymNode(finalCallee, getCallLineInfo(result[0]))
|
||||
if containsGenericType(result.typ):
|
||||
result.typ() = newTypeS(tyError, c)
|
||||
incl result.typ.flags, tfCheckedForDestructor
|
||||
incl result.typ, tfCheckedForDestructor
|
||||
return
|
||||
let gp = finalCallee.ast[genericParamsPos]
|
||||
if gp.isGenericParams:
|
||||
@@ -945,7 +945,7 @@ proc explicitGenericSym(c: PContext, n: PNode, s: PSym, errors: var CandidateErr
|
||||
diagnostics: m.diagnostics))
|
||||
return nil
|
||||
var newInst = generateInstance(c, s, m.bindings, n.info)
|
||||
newInst.typ.flags.excl tfUnresolved
|
||||
newInst.typ.excl tfUnresolved
|
||||
let info = getCallLineInfo(n)
|
||||
markUsed(c, info, s, isGenericInstance = false)
|
||||
onUse(info, s, isGenericInstance = false)
|
||||
|
||||
@@ -412,7 +412,7 @@ proc semConv(c: PContext, n: PNode; flags: TExprFlags = {}, expectedType: PType
|
||||
let baseType = semTypeNode(c, n[1], nil).skipTypes({tyTypeDesc})
|
||||
let t = newTypeS(targetType.kind, c, baseType)
|
||||
if targetType.kind == tyOwned:
|
||||
t.flags.incl tfHasOwned
|
||||
t.incl tfHasOwned
|
||||
result = newNodeI(nkType, n.info)
|
||||
result.typ() = makeTypeDesc(c, t)
|
||||
return
|
||||
@@ -919,7 +919,7 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode =
|
||||
tfUnresolved notin n[i].typ.flags:
|
||||
break maybeLabelAsStatic
|
||||
n.typ() = newTypeS(tyStatic, c, n.typ)
|
||||
n.typ.flags.incl tfUnresolved
|
||||
n.typ.incl tfUnresolved
|
||||
|
||||
# optimization pass: not necessary for correctness of the semantic pass
|
||||
if (callee.kind == skConst or
|
||||
@@ -1847,10 +1847,10 @@ proc asgnToResultVar(c: PContext, n, le, ri: PNode) {.inline.} =
|
||||
if x.sym.kind == skResult and (x.typ.kind in {tyVar, tyLent} or classifyViewType(x.typ) != noView):
|
||||
n[0] = x # 'result[]' --> 'result'
|
||||
n[1] = takeImplicitAddr(c, ri, x.typ.kind == tyLent)
|
||||
x.typ.flags.incl tfVarIsPtr
|
||||
x.typ.incl tfVarIsPtr
|
||||
#echo x.info, " setting it for this type ", typeToString(x.typ), " ", n.info
|
||||
elif sfGlobal in x.sym.flags:
|
||||
x.typ.flags.incl tfVarIsPtr
|
||||
x.typ.incl tfVarIsPtr
|
||||
|
||||
proc borrowCheck(c: PContext, n, le, ri: PNode) =
|
||||
const
|
||||
@@ -2124,7 +2124,7 @@ proc semYieldVarResult(c: PContext, n: PNode, restype: PType) =
|
||||
var t = skipTypes(restype, {tyGenericInst, tyAlias, tySink})
|
||||
case t.kind
|
||||
of tyVar, tyLent:
|
||||
t.flags.incl tfVarIsPtr # bugfix for #4048, #4910, #6892
|
||||
t.incl tfVarIsPtr # bugfix for #4048, #4910, #6892
|
||||
if n[0].kind in {nkHiddenStdConv, nkHiddenSubConv}:
|
||||
n[0] = n[0][1]
|
||||
n[0] = takeImplicitAddr(c, n[0], t.kind == tyLent)
|
||||
@@ -2132,7 +2132,7 @@ proc semYieldVarResult(c: PContext, n: PNode, restype: PType) =
|
||||
for i in 0..<t.len:
|
||||
let e = skipTypes(t[i], {tyGenericInst, tyAlias, tySink})
|
||||
if e.kind in {tyVar, tyLent}:
|
||||
e.flags.incl tfVarIsPtr # bugfix for #4048, #4910, #6892
|
||||
e.incl tfVarIsPtr # bugfix for #4048, #4910, #6892
|
||||
let tupleConstr = if n[0].kind in {nkHiddenStdConv, nkHiddenSubConv}: n[0][1] else: n[0]
|
||||
if tupleConstr.kind in {nkPar, nkTupleConstr}:
|
||||
if tupleConstr[i].kind == nkExprColonExpr:
|
||||
@@ -2741,7 +2741,7 @@ proc semWhen(c: PContext, n: PNode, semCheck = true): PNode =
|
||||
proc semSetConstr(c: PContext, n: PNode, expectedType: PType = nil): PNode =
|
||||
result = newNodeI(nkCurly, n.info)
|
||||
result.typ() = newTypeS(tySet, c)
|
||||
result.typ.flags.incl tfIsConstructor
|
||||
result.typ.incl tfIsConstructor
|
||||
var expectedElementType: PType = nil
|
||||
if expectedType != nil and (
|
||||
let expected = expectedType.skipTypes(abstractRange-{tyDistinct});
|
||||
|
||||
@@ -257,7 +257,7 @@ proc instantiateProcType(c: PContext, pt: LayeredIdTable,
|
||||
let needsStaticSkipping = resulti.kind == tyFromExpr
|
||||
let needsTypeDescSkipping = resulti.kind == tyTypeDesc and tfUnresolved in resulti.flags
|
||||
if resulti.kind == tyFromExpr:
|
||||
resulti.flags.incl tfNonConstExpr
|
||||
resulti.incl tfNonConstExpr
|
||||
result[i] = replaceTypeVarsT(cl, resulti)
|
||||
if needsStaticSkipping:
|
||||
result[i] = result[i].skipTypes({tyStatic})
|
||||
@@ -282,7 +282,7 @@ proc instantiateProcType(c: PContext, pt: LayeredIdTable,
|
||||
if oldParam.ast != nil:
|
||||
var def = oldParam.ast.copyTree
|
||||
if def.typ.kind == tyFromExpr:
|
||||
def.typ.flags.incl tfNonConstExpr
|
||||
def.typ.incl tfNonConstExpr
|
||||
if not isIntLit(def.typ):
|
||||
def = prepareNode(cl, def)
|
||||
|
||||
|
||||
@@ -54,13 +54,13 @@ proc semTypeOf(c: PContext; n: PNode): PNode =
|
||||
let typExpr = semExprWithType(c, n[1], if m == 1: {efInTypeof} else: {})
|
||||
result.add typExpr
|
||||
if typExpr.typ.kind == tyFromExpr:
|
||||
typExpr.typ.flags.incl tfNonConstExpr
|
||||
typExpr.typ.incl tfNonConstExpr
|
||||
var t = typExpr.typ
|
||||
if t.kind == tyStatic:
|
||||
let base = t.skipTypes({tyStatic})
|
||||
if c.inGenericContext > 0 and base.containsGenericType:
|
||||
t = makeTypeFromExpr(c, copyTree(typExpr))
|
||||
t.flags.incl tfNonConstExpr
|
||||
t.incl tfNonConstExpr
|
||||
else:
|
||||
t = base
|
||||
result.typ() = makeTypeDesc(c, t)
|
||||
@@ -85,7 +85,7 @@ proc semArrGet(c: PContext; n: PNode; flags: TExprFlags): PNode =
|
||||
# expression is compiled early in a generic body
|
||||
result = semGenericStmt(c, x)
|
||||
result.typ() = makeTypeFromExpr(c, copyTree(result))
|
||||
result.typ.flags.incl tfNonConstExpr
|
||||
result.typ.incl tfNonConstExpr
|
||||
return
|
||||
let s = # extract sym from first arg
|
||||
if n.len > 1:
|
||||
@@ -442,7 +442,7 @@ proc semUnown(c: PContext; n: PNode): PNode =
|
||||
copyTypeProps(c.graph, c.idgen.module, result, t)
|
||||
|
||||
result[^1] = b
|
||||
result.flags.excl tfHasOwned
|
||||
result.excl tfHasOwned
|
||||
else:
|
||||
result = t
|
||||
else:
|
||||
|
||||
@@ -485,7 +485,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType
|
||||
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
|
||||
result.typ.incl tfHasOwned
|
||||
if t.kind != tyObject:
|
||||
return localErrorNode(c, result, if t.kind != tyGenericBody:
|
||||
"object constructor needs an object type".dup(addTypeNodeDeclaredLoc(c.config, t))
|
||||
|
||||
@@ -1119,7 +1119,7 @@ proc semForVars(c: PContext, n: PNode; flags: TExprFlags): PNode =
|
||||
v.typ = newTypeS(iter.kind, c)
|
||||
v.typ.add iterAfterVarLent[i]
|
||||
if tfVarIsPtr in iter.flags:
|
||||
v.typ.flags.incl tfVarIsPtr
|
||||
v.typ.incl tfVarIsPtr
|
||||
else:
|
||||
v.typ = iter[i]
|
||||
n[0][i] = newSymNode(v)
|
||||
@@ -1177,7 +1177,7 @@ proc semForVars(c: PContext, n: PNode; flags: TExprFlags): PNode =
|
||||
v.typ = newTypeS(iter.kind, c)
|
||||
v.typ.add iterAfterVarLent[i]
|
||||
if tfVarIsPtr in iter.flags:
|
||||
v.typ.flags.incl tfVarIsPtr
|
||||
v.typ.incl tfVarIsPtr
|
||||
else:
|
||||
v.typ = iter[i]
|
||||
n[i] = newSymNode(v)
|
||||
@@ -1549,7 +1549,7 @@ proc checkCovariantParamsUsages(c: PContext; genericType: PType) =
|
||||
|
||||
case t.kind
|
||||
of tyGenericParam:
|
||||
t.flags.incl tfWeakCovariant
|
||||
t.incl tfWeakCovariant
|
||||
return true
|
||||
of tyObject:
|
||||
for field in t.n:
|
||||
@@ -1575,7 +1575,7 @@ proc checkCovariantParamsUsages(c: PContext; genericType: PType) =
|
||||
error("covariant param '" & param.sym.name.s &
|
||||
"' used in a non-covariant position")
|
||||
elif tfWeakCovariant in formalFlags:
|
||||
param.flags.incl tfWeakCovariant
|
||||
param.incl tfWeakCovariant
|
||||
result = true
|
||||
elif tfContravariant in param.flags:
|
||||
let formalParam = targetBody[i-1].sym
|
||||
@@ -1667,11 +1667,11 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||
body.size = -1 # could not be computed properly
|
||||
if body.kind == tyObject:
|
||||
# add flags applied to generic type to object (nominal) type
|
||||
incl(body.flags, oldFlags)
|
||||
incl(body, oldFlags)
|
||||
# {.inheritable, final.} is already disallowed, but
|
||||
# object might have been assumed to be final
|
||||
if tfInheritable in oldFlags and tfFinal in body.flags:
|
||||
excl(body.flags, tfFinal)
|
||||
excl(body, tfFinal)
|
||||
s.typ[^1] = body
|
||||
if tfCovariant in s.typ.flags:
|
||||
checkCovariantParamsUsages(c, s.typ)
|
||||
@@ -1720,7 +1720,7 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||
# flag might be copied from alias/instantiation:
|
||||
let t = body.skipTypes({tyAlias, tyGenericInst})
|
||||
if not (t.kind == tyDistinct and tfBorrowDot in t.flags):
|
||||
excl s.typ.flags, tfBorrowDot
|
||||
excl s.typ, tfBorrowDot
|
||||
localError(c.config, name.info, "only a 'distinct' type can borrow `.`")
|
||||
let aa = a[2]
|
||||
if aa.kind in {nkRefTy, nkPtrTy} and aa.len == 1 and
|
||||
@@ -1730,14 +1730,14 @@ proc typeSectionRightSidePass(c: PContext, n: PNode) =
|
||||
if st.kind == tyGenericBody: st = st.typeBodyImpl
|
||||
internalAssert c.config, st.kind in {tyPtr, tyRef}
|
||||
internalAssert c.config, st.last.sym == nil
|
||||
incl st.flags, tfRefsAnonObj
|
||||
incl st, tfRefsAnonObj
|
||||
let objTy = st.last
|
||||
# add flags for `ref object` etc to underlying `object`
|
||||
incl(objTy.flags, oldFlags)
|
||||
incl(objTy, oldFlags)
|
||||
# {.inheritable, final.} is already disallowed, but
|
||||
# object might have been assumed to be final
|
||||
if tfInheritable in oldFlags and tfFinal in objTy.flags:
|
||||
excl(objTy.flags, tfFinal)
|
||||
excl(objTy, tfFinal)
|
||||
let obj = newSym(skType, getIdent(c.cache, s.name.s & ":ObjectType"),
|
||||
c.idgen, getCurrOwner(c), s.info)
|
||||
obj.flagsImpl.incl sfGeneratedType
|
||||
@@ -2129,7 +2129,7 @@ proc bindDupHook(c: PContext; s: PSym; n: PNode; op: TTypeAttachedOp) =
|
||||
if cond:
|
||||
var obj = t.firstParamType
|
||||
while true:
|
||||
incl(obj.flags, tfHasAsgn)
|
||||
incl(obj, tfHasAsgn)
|
||||
if obj.kind in {tyGenericBody, tyGenericInst}: obj = obj.skipModifier
|
||||
elif obj.kind == tyGenericInvocation: obj = obj.genericHead
|
||||
else: break
|
||||
@@ -2184,7 +2184,7 @@ proc bindTypeHook(c: PContext; s: PSym; n: PNode; op: TTypeAttachedOp) =
|
||||
if cond:
|
||||
var obj = t.firstParamType.skipTypes({tyVar})
|
||||
while true:
|
||||
incl(obj.flags, tfHasAsgn)
|
||||
incl(obj, tfHasAsgn)
|
||||
if obj.kind in {tyGenericBody, tyGenericInst}: obj = obj.skipModifier
|
||||
elif obj.kind == tyGenericInvocation: obj = obj.genericHead
|
||||
else: break
|
||||
@@ -2269,7 +2269,7 @@ proc semOverride(c: PContext, s: PSym, n: PNode) =
|
||||
if t.len == 3 and t.returnType == nil and t.firstParamType.kind == tyVar:
|
||||
var obj = t.firstParamType.elementType
|
||||
while true:
|
||||
incl(obj.flags, tfHasAsgn)
|
||||
incl(obj, tfHasAsgn)
|
||||
if obj.kind == tyGenericBody: obj = obj.skipModifier
|
||||
elif obj.kind == tyGenericInvocation: obj = obj.genericHead
|
||||
else: break
|
||||
@@ -2497,10 +2497,10 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
||||
if n[patternPos].kind != nkEmpty:
|
||||
n[patternPos] = semPattern(c, n[patternPos], s)
|
||||
if s.kind == skIterator:
|
||||
s.typ.flags.incl(tfIterator)
|
||||
s.typ.incl(tfIterator)
|
||||
elif s.kind == skFunc:
|
||||
incl(s, sfNoSideEffect)
|
||||
incl(s.typ.flags, tfNoSideEffect)
|
||||
incl(s.typ, tfNoSideEffect)
|
||||
|
||||
var (proto, comesFromShadowScope) =
|
||||
if isAnon: (nil, false)
|
||||
@@ -2546,7 +2546,7 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
||||
|
||||
if n[pragmasPos].kind != nkEmpty and sfBorrow notin s.flags:
|
||||
setEffectsForProcType(c.graph, s.typ, n[pragmasPos], s)
|
||||
s.typ.flags.incl tfEffectSystemWorkaround
|
||||
s.typ.incl tfEffectSystemWorkaround
|
||||
|
||||
# To ease macro generation that produce forwarded .async procs we now
|
||||
# allow a bit redundancy in the pragma declarations. The rule is
|
||||
@@ -2724,7 +2724,7 @@ proc semIterator(c: PContext, n: PNode): PNode =
|
||||
# we require first class iterators to be marked with 'closure' explicitly
|
||||
# -- at least for 0.9.2.
|
||||
if s.typ.callConv == ccClosure:
|
||||
incl(s.typ.flags, tfCapturesEnv)
|
||||
incl(s.typ, tfCapturesEnv)
|
||||
else:
|
||||
s.typ.callConv = ccInline
|
||||
if result[bodyPos].kind == nkEmpty and s.magic == mNone and c.inConceptDecl == 0:
|
||||
|
||||
@@ -62,7 +62,7 @@ proc newOrPrevType(kind: TTypeKind, prev: PType, c: PContext): PType =
|
||||
|
||||
proc newConstraint(c: PContext, k: TTypeKind): PType =
|
||||
result = newTypeS(tyBuiltInTypeClass, c)
|
||||
result.flags.incl tfCheckedForDestructor
|
||||
result.incl tfCheckedForDestructor
|
||||
result.addSonSkipIntLit(newTypeS(k, c), c.idgen)
|
||||
|
||||
proc skipGenericPrev(prev: PType): PType =
|
||||
@@ -151,7 +151,7 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType =
|
||||
if i != 1:
|
||||
if x != counter:
|
||||
needsReorder = true
|
||||
incl(result.flags, tfEnumHasHoles)
|
||||
incl(result, tfEnumHasHoles)
|
||||
e.ast = strVal # might be nil
|
||||
counter = x
|
||||
of nkSym:
|
||||
@@ -212,7 +212,7 @@ proc semEnum(c: PContext, n: PNode, prev: PType): PType =
|
||||
if isPure and sfExported in result.sym.flags:
|
||||
addPureEnum(c, LazySym(sym: result.sym))
|
||||
if tfNotNil in e.typ.flags and not hasNull:
|
||||
result.flags.incl tfRequiresInit
|
||||
result.incl tfRequiresInit
|
||||
setToStringProc(c.graph, result, genEnumToStrProc(result, n.info, c.graph, c.idgen))
|
||||
|
||||
proc semSet(c: PContext, n: PNode, prev: PType): PType =
|
||||
@@ -378,7 +378,7 @@ proc semRangeAux(c: PContext, n: PNode, prev: PType): PType =
|
||||
for i in 0..1:
|
||||
if hasUnresolvedArgs(c, range[i]):
|
||||
result.n.add makeStaticExpr(c, range[i])
|
||||
result.flags.incl tfUnresolved
|
||||
result.incl tfUnresolved
|
||||
else:
|
||||
result.n.add semConstExpr(c, range[i])
|
||||
|
||||
@@ -398,15 +398,15 @@ proc semRange(c: PContext, n: PNode, prev: PType): PType =
|
||||
if not isDefined(c.config, "nimPreviewRangeDefault"):
|
||||
let n = result.n
|
||||
if n[0].kind in {nkCharLit..nkUInt64Lit} and n[0].intVal > 0:
|
||||
incl(result.flags, tfRequiresInit)
|
||||
incl(result, tfRequiresInit)
|
||||
elif n[1].kind in {nkCharLit..nkUInt64Lit} and n[1].intVal < 0:
|
||||
incl(result.flags, tfRequiresInit)
|
||||
incl(result, tfRequiresInit)
|
||||
elif n[0].kind in {nkFloatLit..nkFloat64Lit} and
|
||||
n[0].floatVal > 0.0:
|
||||
incl(result.flags, tfRequiresInit)
|
||||
incl(result, tfRequiresInit)
|
||||
elif n[1].kind in {nkFloatLit..nkFloat64Lit} and
|
||||
n[1].floatVal < 0.0:
|
||||
incl(result.flags, tfRequiresInit)
|
||||
incl(result, tfRequiresInit)
|
||||
else:
|
||||
if n[1].kind == nkInfix and considerQuotedIdent(c, n[1][0]).s == "..<":
|
||||
localError(c.config, n[0].info, "range types need to be constructed with '..', '..<' is not supported")
|
||||
@@ -453,10 +453,10 @@ proc semArrayIndex(c: PContext, n: PNode): PType =
|
||||
let info = if n.safeLen > 1: n[1].info else: n.info
|
||||
localError(c.config, info, errOrdinalTypeExpected % typeToString(e.typ, preferDesc))
|
||||
result = makeRangeWithStaticExpr(c, e)
|
||||
if c.inGenericContext > 0: result.flags.incl tfUnresolved
|
||||
if c.inGenericContext > 0: result.incl tfUnresolved
|
||||
else:
|
||||
result = e.typ.skipTypes({tyTypeDesc})
|
||||
result.flags.incl tfImplicitStatic
|
||||
result.incl tfImplicitStatic
|
||||
elif e.kind in (nkCallKinds + {nkBracketExpr}) and hasUnresolvedArgs(c, e):
|
||||
if not isOrdinalType(e.typ.skipTypes({tyStatic, tyAlias, tyGenericInst, tySink})):
|
||||
localError(c.config, n[1].info, errOrdinalTypeExpected % typeToString(e.typ, preferDesc))
|
||||
@@ -1075,8 +1075,8 @@ proc semObjectNode(c: PContext, n: PNode, prev: PType; flags: TTypeFlags): PType
|
||||
c.forwardTypeUpdates.add (result, n) # we retry in the final pass
|
||||
rawAddSon(result, realBase)
|
||||
if realBase == nil and tfInheritable in flags:
|
||||
result.flags.incl tfInheritable
|
||||
if tfAcyclic in flags: result.flags.incl tfAcyclic
|
||||
result.incl tfInheritable
|
||||
if tfAcyclic in flags: result.incl tfAcyclic
|
||||
if result.n.isNil:
|
||||
result.n = newNodeI(nkRecList, n.info)
|
||||
else:
|
||||
@@ -1091,9 +1091,9 @@ proc semObjectNode(c: PContext, n: PNode, prev: PType; flags: TTypeFlags): PType
|
||||
s.typ = result
|
||||
pragma(c, s, n[0], typePragmas)
|
||||
if base == nil and tfInheritable notin result.flags:
|
||||
incl(result.flags, tfFinal)
|
||||
incl(result, tfFinal)
|
||||
if c.inGenericContext == 0 and computeRequiresInit(c, result):
|
||||
result.flags.incl tfRequiresInit
|
||||
result.incl tfRequiresInit
|
||||
|
||||
proc semAnyRef(c: PContext; n: PNode; kind: TTypeKind; prev: PType): PType =
|
||||
if n.len < 1:
|
||||
@@ -1136,13 +1136,13 @@ proc semAnyRef(c: PContext; n: PNode; kind: TTypeKind; prev: PType): PType =
|
||||
addSonSkipIntLit(result, region, c.idgen)
|
||||
addSonSkipIntLit(result, t, c.idgen)
|
||||
if tfPartial in result.flags:
|
||||
if result.elementType.kind == tyObject: incl(result.elementType.flags, tfPartial)
|
||||
if result.elementType.kind == tyObject: incl(result.elementType, tfPartial)
|
||||
# if not isNilable: result.flags.incl tfNotNil
|
||||
case wrapperKind
|
||||
of tyOwned:
|
||||
if optOwnedRefs in c.config.globalOptions:
|
||||
let t = newTypeS(tyOwned, c, result)
|
||||
t.flags.incl tfHasOwned
|
||||
t.incl tfHasOwned
|
||||
result = t
|
||||
of tySink:
|
||||
let t = newTypeS(tySink, c, result)
|
||||
@@ -1151,7 +1151,7 @@ proc semAnyRef(c: PContext; n: PNode; kind: TTypeKind; prev: PType): PType =
|
||||
if result.kind == tyRef and
|
||||
c.config.selectedGC in {gcArc, gcOrc, gcAtomicArc} and
|
||||
tfTriggersCompileTime notin result.flags:
|
||||
result.flags.incl tfHasAsgn
|
||||
result.incl tfHasAsgn
|
||||
|
||||
proc findEnforcedStaticType(t: PType): PType =
|
||||
# This handles types such as `static[T] and Foo`,
|
||||
@@ -1211,7 +1211,7 @@ proc addImplicitGeneric(c: PContext; typeClass: PType, typId: PIdent;
|
||||
if sfExplain in owner.flags: s.incl sfExplain
|
||||
if typId == nil: s.incl(sfAnon)
|
||||
s.linkTo(typeClass)
|
||||
typeClass.flags.incl tfImplicitTypeParam
|
||||
typeClass.incl tfImplicitTypeParam
|
||||
s.position = genericParams.len
|
||||
genericParams.add newSymNode(s)
|
||||
result = typeClass
|
||||
@@ -1244,7 +1244,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||
localError(c.config, info, errMacroBodyDependsOnGenericTypes % paramName)
|
||||
result = addImplicitGeneric(c, newTypeS(tyStatic, c, base),
|
||||
paramTypId, info, genericParams, paramName)
|
||||
if result != nil: result.flags.incl({tfHasStatic, tfUnresolved})
|
||||
if result != nil: result.incl({tfHasStatic, tfUnresolved})
|
||||
|
||||
of tyTypeDesc:
|
||||
if tfUnresolved notin paramType.flags:
|
||||
@@ -1255,7 +1255,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||
# XXX Why doesn't this check for tyTypeDesc instead?
|
||||
paramTypId = nil
|
||||
let t = newTypeS(tyTypeDesc, c, paramType.base)
|
||||
incl t.flags, tfCheckedForDestructor
|
||||
incl t, tfCheckedForDestructor
|
||||
result = addImplicitGeneric(c, t, paramTypId, info, genericParams, paramName)
|
||||
else:
|
||||
result = nil
|
||||
@@ -1305,7 +1305,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||
for i in 0..<paramType.len - 1:
|
||||
if paramType[i].kind == tyStatic:
|
||||
var staticCopy = paramType[i].exactReplica
|
||||
staticCopy.flags.incl tfInferrableStatic
|
||||
staticCopy.incl tfInferrableStatic
|
||||
result.rawAddSon staticCopy
|
||||
else:
|
||||
result.rawAddSon newTypeS(tyAnything, c)
|
||||
@@ -1343,7 +1343,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||
let liftBody = recurse(paramType.skipModifier, true)
|
||||
if liftBody != nil:
|
||||
result = liftBody
|
||||
result.flags.incl tfHasMeta
|
||||
result.incl tfHasMeta
|
||||
#result.shouldHaveMeta
|
||||
|
||||
of tyGenericInvocation:
|
||||
@@ -1374,7 +1374,7 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||
markUsed(c, paramType.sym.info, paramType.sym)
|
||||
onUse(paramType.sym.info, paramType.sym)
|
||||
if tfWildcard in paramType.flags:
|
||||
paramType.flags.excl tfWildcard
|
||||
paramType.excl tfWildcard
|
||||
paramType.sym.transitionGenericParamToType()
|
||||
|
||||
else: result = nil
|
||||
@@ -1497,7 +1497,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||
# surprising behavior. We must instead fix the expected type of
|
||||
# the proc to be the unbound typedesc type:
|
||||
typ = newTypeS(tyTypeDesc, c, newTypeS(tyNone, c))
|
||||
typ.flags.incl tfCheckedForDestructor
|
||||
typ.incl tfCheckedForDestructor
|
||||
|
||||
elif def.typ != nil and def.typ.kind != tyFromExpr: # def.typ can be void
|
||||
# if def.typ != nil and def.typ.kind != tyNone:
|
||||
@@ -1588,7 +1588,7 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||
# 'auto' as a return type does not imply a generic:
|
||||
elif r.kind == tyAnything:
|
||||
r = copyType(r, c.idgen, r.owner)
|
||||
r.flags.incl tfRetType
|
||||
r.incl tfRetType
|
||||
elif r.kind == tyStatic:
|
||||
# type allowed should forbid this type
|
||||
discard
|
||||
@@ -1600,13 +1600,13 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||
r = lifted
|
||||
#if r.kind != tyGenericParam:
|
||||
#echo "came here for ", typeToString(r)
|
||||
r.flags.incl tfRetType
|
||||
r.incl tfRetType
|
||||
r = skipIntLit(r, c.idgen)
|
||||
if kind == skIterator:
|
||||
# see tchainediterators
|
||||
# in cases like iterator foo(it: iterator): typeof(it)
|
||||
# we don't need to change the return type to iter[T]
|
||||
result.flags.incl tfIterator
|
||||
result.incl tfIterator
|
||||
# XXX Would be nice if we could get rid of this
|
||||
result[0] = r
|
||||
let oldFlags = result.flags
|
||||
@@ -1614,17 +1614,17 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||
if oldFlags != result.flags:
|
||||
# XXX This rather hacky way keeps 'tflatmap' compiling:
|
||||
if tfHasMeta notin oldFlags:
|
||||
result.flags.excl tfHasMeta
|
||||
result.excl tfHasMeta
|
||||
result.n.typ() = r
|
||||
|
||||
if isCurrentlyGeneric():
|
||||
for n in genericParams:
|
||||
if {sfUsed, sfAnon} * n.sym.flags == {}:
|
||||
result.flags.incl tfUnresolved
|
||||
result.incl tfUnresolved
|
||||
|
||||
if tfWildcard in n.sym.typ.flags:
|
||||
n.sym.transitionGenericParamToType()
|
||||
n.sym.typ.flags.excl tfWildcard
|
||||
n.sym.typ.excl tfWildcard
|
||||
|
||||
proc semStmtListType(c: PContext, n: PNode, prev: PType): PType =
|
||||
checkMinSonsLen(n, 1, c.config)
|
||||
@@ -1847,7 +1847,7 @@ proc semTypeClass(c: PContext, n: PNode, prev: PType): PType =
|
||||
# if n.len == 0: return newConstraint(c, tyTypeClass)
|
||||
if isNewStyleConcept(n):
|
||||
result = newOrPrevType(tyConcept, prev, c)
|
||||
result.flags.incl tfCheckedForDestructor
|
||||
result.incl tfCheckedForDestructor
|
||||
result.n = semConceptDeclaration(c, n)
|
||||
return result
|
||||
|
||||
@@ -1858,7 +1858,7 @@ proc semTypeClass(c: PContext, n: PNode, prev: PType): PType =
|
||||
var owner = getCurrOwner(c)
|
||||
var candidateTypeSlot = newTypeS(tyAlias, c, c.errorType)
|
||||
result = newOrPrevType(tyUserTypeClass, prev, c, son = candidateTypeSlot)
|
||||
result.flags.incl tfCheckedForDestructor
|
||||
result.incl tfCheckedForDestructor
|
||||
result.n = n
|
||||
|
||||
if inherited.kind != nkEmpty:
|
||||
@@ -1880,8 +1880,8 @@ proc semTypeClass(c: PContext, n: PNode, prev: PType): PType =
|
||||
# if modifier == tyRef:
|
||||
# dummyType.flags.incl tfNotNil
|
||||
if modifier == tyTypeDesc:
|
||||
dummyType.flags.incl tfConceptMatchedTypeSym
|
||||
dummyType.flags.incl tfCheckedForDestructor
|
||||
dummyType.incl tfConceptMatchedTypeSym
|
||||
dummyType.incl tfCheckedForDestructor
|
||||
else:
|
||||
dummyName = param
|
||||
dummyType = candidateTypeSlot
|
||||
@@ -1979,7 +1979,7 @@ proc semStaticType(c: PContext, childNode: PNode, prev: PType): PType =
|
||||
result = newOrPrevType(tyStatic, prev, c)
|
||||
var base = semTypeNode(c, childNode, nil).skipTypes({tyTypeDesc, tyAlias})
|
||||
result.rawAddSon(base)
|
||||
result.flags.incl tfHasStatic
|
||||
result.incl tfHasStatic
|
||||
|
||||
proc semTypeOf(c: PContext; n: PNode; prev: PType): PType =
|
||||
openScope(c)
|
||||
@@ -1989,12 +1989,12 @@ proc semTypeOf(c: PContext; n: PNode; prev: PType): PType =
|
||||
closeScope(c)
|
||||
result = ex.typ
|
||||
if result.kind == tyFromExpr:
|
||||
result.flags.incl tfNonConstExpr
|
||||
result.incl tfNonConstExpr
|
||||
elif result.kind == tyStatic:
|
||||
let base = result.skipTypes({tyStatic})
|
||||
if c.inGenericContext > 0 and base.containsGenericType:
|
||||
result = makeTypeFromExpr(c, copyTree(ex))
|
||||
result.flags.incl tfNonConstExpr
|
||||
result.incl tfNonConstExpr
|
||||
else:
|
||||
result = base
|
||||
fixupTypeOf(c, prev, result)
|
||||
@@ -2014,12 +2014,12 @@ proc semTypeOf2(c: PContext; n: PNode; prev: PType): PType =
|
||||
closeScope(c)
|
||||
result = ex.typ
|
||||
if result.kind == tyFromExpr:
|
||||
result.flags.incl tfNonConstExpr
|
||||
result.incl tfNonConstExpr
|
||||
elif result.kind == tyStatic:
|
||||
let base = result.skipTypes({tyStatic})
|
||||
if c.inGenericContext > 0 and base.containsGenericType:
|
||||
result = makeTypeFromExpr(c, copyTree(ex))
|
||||
result.flags.incl tfNonConstExpr
|
||||
result.incl tfNonConstExpr
|
||||
else:
|
||||
result = base
|
||||
fixupTypeOf(c, prev, result)
|
||||
@@ -2053,14 +2053,14 @@ proc semTypeIdent(c: PContext, n: PNode): PSym =
|
||||
return errorSym(c, n)
|
||||
result = result.typ.sym.copySym(c.idgen)
|
||||
result.typ = exactReplica(result.typ)
|
||||
result.typ.flags.incl tfUnresolved
|
||||
result.typ.incl tfUnresolved
|
||||
|
||||
if result.kind == skGenericParam:
|
||||
if result.typ.kind == tyGenericParam and result.typ.len == 0 and
|
||||
tfWildcard in result.typ.flags:
|
||||
# collapse the wild-card param to a type
|
||||
result.transitionGenericParamToType()
|
||||
result.typ.flags.excl tfWildcard
|
||||
result.typ.excl tfWildcard
|
||||
return
|
||||
else:
|
||||
localError(c.config, n.info, errTypeExpected)
|
||||
@@ -2102,7 +2102,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||
# for ``typeof(countup(1,3))``, see ``tests/ttoseq``.
|
||||
checkSonsLen(n, 1, c.config)
|
||||
result = semTypeOf(c, n[0], prev)
|
||||
if result.kind == tyTypeDesc: result.flags.incl tfExplicit
|
||||
if result.kind == tyTypeDesc: result.incl tfExplicit
|
||||
of nkPar:
|
||||
if n.len == 1: result = semTypeNode(c, n[0], prev)
|
||||
else:
|
||||
@@ -2122,7 +2122,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||
if result.skipTypes({tyGenericInst, tyAlias, tySink, tyOwned}).kind in NilableTypes+GenericTypes:
|
||||
if tfNotNil in result.flags:
|
||||
result = freshType(c, result, prev)
|
||||
result.flags.excl(tfNotNil)
|
||||
result.excl(tfNotNil)
|
||||
else:
|
||||
localError(c.config, n.info, errGenerated, "invalid type")
|
||||
elif n[0].kind notin nkIdentKinds:
|
||||
@@ -2185,7 +2185,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||
result = makeTypeFromExpr(c, newTree(nkStmtListType, n.copyTree))
|
||||
of NilableTypes + {tyGenericInvocation, tyForward}:
|
||||
result = freshType(c, result, prev)
|
||||
result.flags.incl(tfNotNil)
|
||||
result.incl(tfNotNil)
|
||||
else:
|
||||
localError(c.config, n.info, errGenerated, "invalid type")
|
||||
of 2:
|
||||
@@ -2231,11 +2231,11 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||
of mSeq:
|
||||
result = semContainer(c, n, tySequence, "seq", prev)
|
||||
if optSeqDestructors in c.config.globalOptions:
|
||||
incl result.flags, tfHasAsgn
|
||||
incl result, tfHasAsgn
|
||||
of mVarargs: result = semVarargs(c, n, prev)
|
||||
of mTypeDesc, mType, mTypeOf:
|
||||
result = makeTypeDesc(c, semTypeNode(c, n[1], nil))
|
||||
result.flags.incl tfExplicit
|
||||
result.incl tfExplicit
|
||||
of mStatic:
|
||||
result = semStaticType(c, n[1], prev)
|
||||
of mExpr:
|
||||
@@ -2354,7 +2354,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||
result = newTypeS(tyBuiltInTypeClass, c)
|
||||
let child = newTypeS(tyProc, c)
|
||||
if n.kind == nkIteratorTy:
|
||||
child.flags.incl tfIterator
|
||||
child.incl tfIterator
|
||||
if n.len > 0 and n[1].kind != nkEmpty and n[1].len > 0:
|
||||
# typeclass with pragma
|
||||
let symKind = if n.kind == nkIteratorTy: skIterator else: skProc
|
||||
@@ -2372,9 +2372,9 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||
result = newOrPrevType(tyError, prev, c)
|
||||
|
||||
if n.kind == nkIteratorTy and result.kind == tyProc:
|
||||
result.flags.incl(tfIterator)
|
||||
result.incl(tfIterator)
|
||||
if result.callConv == ccClosure and c.config.selectedGC in {gcArc, gcOrc, gcAtomicArc}:
|
||||
result.flags.incl tfHasAsgn
|
||||
result.incl tfHasAsgn
|
||||
of nkEnumTy: result = semEnum(c, n, prev)
|
||||
of nkType: result = n.typ
|
||||
of nkStmtListType: result = semStmtListType(c, n, prev)
|
||||
@@ -2404,7 +2404,7 @@ proc setMagicType(conf: ConfigRef; m: PSym, kind: TTypeKind, size: int) =
|
||||
|
||||
proc setMagicIntegral(conf: ConfigRef; m: PSym, kind: TTypeKind, size: int) =
|
||||
setMagicType(conf, m, kind, size)
|
||||
incl m.typ.flags, tfCheckedForDestructor
|
||||
incl m.typ, tfCheckedForDestructor
|
||||
|
||||
proc processMagicType(c: PContext, m: PSym) =
|
||||
case m.magic
|
||||
@@ -2428,7 +2428,7 @@ proc processMagicType(c: PContext, m: PSym) =
|
||||
setMagicType(c.config, m, tyString, szUncomputedSize)
|
||||
rawAddSon(m.typ, getSysType(c.graph, m.info, tyChar))
|
||||
if optSeqDestructors in c.config.globalOptions:
|
||||
incl m.typ.flags, tfHasAsgn
|
||||
incl m.typ, tfHasAsgn
|
||||
of mCstring:
|
||||
setMagicIntegral(c.config, m, tyCstring, c.config.target.ptrSize)
|
||||
rawAddSon(m.typ, getSysType(c.graph, m.info, tyChar))
|
||||
@@ -2465,7 +2465,7 @@ proc processMagicType(c: PContext, m: PSym) =
|
||||
of mSeq:
|
||||
setMagicType(c.config, m, tySequence, szUncomputedSize)
|
||||
if optSeqDestructors in c.config.globalOptions:
|
||||
incl m.typ.flags, tfHasAsgn
|
||||
incl m.typ, tfHasAsgn
|
||||
if defined(nimsuggest) or c.config.cmd == cmdCheck: # bug #18985
|
||||
discard
|
||||
else:
|
||||
@@ -2478,8 +2478,8 @@ proc processMagicType(c: PContext, m: PSym) =
|
||||
setMagicIntegral(c.config, m, tyIterable, 0)
|
||||
rawAddSon(m.typ, newTypeS(tyNone, c))
|
||||
of mPNimrodNode:
|
||||
incl m.typ.flags, tfTriggersCompileTime
|
||||
incl m.typ.flags, tfCheckedForDestructor
|
||||
incl m.typ, tfTriggersCompileTime
|
||||
incl m.typ, tfCheckedForDestructor
|
||||
of mException: discard
|
||||
of mBuiltinType:
|
||||
case m.name.s
|
||||
@@ -2487,7 +2487,7 @@ proc processMagicType(c: PContext, m: PSym) =
|
||||
of "sink": setMagicType(c.config, m, tySink, szUncomputedSize)
|
||||
of "owned":
|
||||
setMagicType(c.config, m, tyOwned, c.config.target.ptrSize)
|
||||
incl m.typ.flags, tfHasOwned
|
||||
incl m.typ, tfHasOwned
|
||||
else: localError(c.config, m.info, errTypeExpected)
|
||||
else: localError(c.config, m.info, errTypeExpected)
|
||||
|
||||
@@ -2520,7 +2520,7 @@ proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode =
|
||||
if typ.kind == tyTypeDesc:
|
||||
if typ.elementType.kind == tyNone:
|
||||
typ = newTypeS(tyTypeDesc, c, newTypeS(tyNone, c))
|
||||
incl typ.flags, tfCheckedForDestructor
|
||||
incl typ, tfCheckedForDestructor
|
||||
else:
|
||||
typ = semGenericConstraints(c, typ)
|
||||
|
||||
@@ -2538,9 +2538,9 @@ proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode =
|
||||
|
||||
if typ == nil:
|
||||
typ = newTypeS(tyGenericParam, c)
|
||||
if father == nil: typ.flags.incl tfWildcard
|
||||
if father == nil: typ.incl tfWildcard
|
||||
|
||||
typ.flags.incl tfGenericTypeParam
|
||||
typ.incl tfGenericTypeParam
|
||||
|
||||
for j in 0..<a.len-2:
|
||||
var finalType: PType
|
||||
@@ -2562,7 +2562,7 @@ proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode =
|
||||
localError(c.config, paramName.info, errInOutFlagNotExtern % $paramName[0])
|
||||
covarianceFlag = if paramName[0].ident.s == "in": tfContravariant
|
||||
else: tfCovariant
|
||||
if father != nil: father.flags.incl tfCovariant
|
||||
if father != nil: father.incl tfCovariant
|
||||
paramName = paramName[1]
|
||||
|
||||
var s = if finalType.kind == tyStatic or tfWildcard in typ.flags:
|
||||
@@ -2570,7 +2570,7 @@ proc semGenericParamList(c: PContext, n: PNode, father: PType = nil): PNode =
|
||||
else:
|
||||
newSymG(skType, paramName, c).linkTo(finalType)
|
||||
|
||||
if covarianceFlag != tfUnresolved: s.typ.flags.incl(covarianceFlag)
|
||||
if covarianceFlag != tfUnresolved: s.typ.incl(covarianceFlag)
|
||||
if def.kind != nkEmpty: s.ast = def
|
||||
s.position = result.len
|
||||
result.addSym(s)
|
||||
|
||||
@@ -2370,7 +2370,7 @@ proc execProc*(c: PCtx; sym: PSym; args: openArray[PNode]): PNode =
|
||||
proc errorNode(idgen: IdGenerator; owner: PSym, n: PNode): PNode =
|
||||
result = newNodeI(nkEmpty, n.info)
|
||||
result.typ() = newType(tyError, idgen, owner)
|
||||
result.typ.flags.incl tfCheckedForDestructor
|
||||
result.typ.incl tfCheckedForDestructor
|
||||
|
||||
proc evalStmt*(c: PCtx, n: PNode) =
|
||||
let n = transformExpr(c.graph, c.idgen, c.module, n)
|
||||
|
||||
Reference in New Issue
Block a user