migrate the static param handling to ReplaceTypeVars; fix tgenericvariant
This commit is contained in:
parent
af7c3251cd
commit
754e2ef1db
6 changed files with 38 additions and 26 deletions
|
|
@ -204,12 +204,15 @@ proc tryConstExpr(c: PContext, n: PNode): PNode =
|
||||||
result = getConstExpr(c.module, e)
|
result = getConstExpr(c.module, e)
|
||||||
if result != nil: return
|
if result != nil: return
|
||||||
|
|
||||||
result = evalConstExpr(c.module, e)
|
try:
|
||||||
if result == nil or result.kind == nkEmpty:
|
result = evalConstExpr(c.module, e)
|
||||||
|
if result == nil or result.kind == nkEmpty:
|
||||||
|
return nil
|
||||||
|
|
||||||
|
result = fixupTypeAfterEval(c, result, e)
|
||||||
|
except:
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
result = fixupTypeAfterEval(c, result, e)
|
|
||||||
|
|
||||||
proc semConstExpr(c: PContext, n: PNode): PNode =
|
proc semConstExpr(c: PContext, n: PNode): PNode =
|
||||||
var e = semExprWithType(c, n)
|
var e = semExprWithType(c, n)
|
||||||
if e == nil:
|
if e == nil:
|
||||||
|
|
|
||||||
|
|
@ -594,7 +594,7 @@ proc addParamOrResult(c: PContext, param: PSym, kind: TSymKind) =
|
||||||
let typedescId = getIdent"typedesc"
|
let typedescId = getIdent"typedesc"
|
||||||
|
|
||||||
template shouldHaveMeta(t) =
|
template shouldHaveMeta(t) =
|
||||||
InternalAssert tfHasMeta in result.lastSon.flags
|
InternalAssert tfHasMeta in t.flags
|
||||||
# result.lastSon.flags.incl tfHasMeta
|
# result.lastSon.flags.incl tfHasMeta
|
||||||
|
|
||||||
proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
|
|
@ -677,7 +677,8 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
result = newTypeS(tyGenericInvokation, c)
|
result = newTypeS(tyGenericInvokation, c)
|
||||||
result.rawAddSon(paramType)
|
result.rawAddSon(paramType)
|
||||||
for i in 0 .. paramType.sonsLen - 2:
|
for i in 0 .. paramType.sonsLen - 2:
|
||||||
result.rawAddSon(copyType(paramType.sons[i], getCurrOwner(), true))
|
result.rawAddSon newTypeS(tyAnything, c)
|
||||||
|
# result.rawAddSon(copyType(paramType.sons[i], getCurrOwner(), true))
|
||||||
result = instGenericContainer(c, paramType.sym.info, result,
|
result = instGenericContainer(c, paramType.sym.info, result,
|
||||||
allowMetaTypes = true)
|
allowMetaTypes = true)
|
||||||
result.lastSon.shouldHaveMeta
|
result.lastSon.shouldHaveMeta
|
||||||
|
|
@ -696,20 +697,29 @@ proc liftParamType(c: PContext, procKind: TSymKind, genericParams: PNode,
|
||||||
if liftBody != nil:
|
if liftBody != nil:
|
||||||
result = liftBody
|
result = liftBody
|
||||||
result.shouldHaveMeta
|
result.shouldHaveMeta
|
||||||
|
|
||||||
|
of tyGenericInvokation:
|
||||||
|
for i in 1 .. <paramType.sonsLen:
|
||||||
|
let lifted = liftingWalk(paramType.sons[i])
|
||||||
|
if lifted != nil: paramType.sons[i] = lifted
|
||||||
|
|
||||||
|
let expanded = instGenericContainer(c, info, paramType,
|
||||||
|
allowMetaTypes = true)
|
||||||
|
result = liftingWalk(expanded)
|
||||||
|
|
||||||
of tyTypeClass, tyBuiltInTypeClass, tyAnd, tyOr, tyNot:
|
of tyTypeClass, tyBuiltInTypeClass, tyAnd, tyOr, tyNot:
|
||||||
result = addImplicitGeneric(copyType(paramType, getCurrOwner(), true))
|
result = addImplicitGeneric(copyType(paramType, getCurrOwner(), true))
|
||||||
|
|
||||||
of tyExpr:
|
of tyExpr:
|
||||||
if procKind notin {skMacro, skTemplate}:
|
if procKind notin {skMacro, skTemplate}:
|
||||||
result = addImplicitGeneric(newTypeS(tyGenericParam, c))
|
result = addImplicitGeneric(newTypeS(tyAnything, c))
|
||||||
|
|
||||||
of tyGenericParam:
|
of tyGenericParam:
|
||||||
if tfGenericTypeParam in paramType.flags and false:
|
if tfGenericTypeParam in paramType.flags and false:
|
||||||
if paramType.sonsLen > 0:
|
if paramType.sonsLen > 0:
|
||||||
result = liftingWalk(paramType.lastSon)
|
result = liftingWalk(paramType.lastSon)
|
||||||
else:
|
else:
|
||||||
result = addImplicitGeneric(newTypeS(tyGenericParam, c))
|
result = addImplicitGeneric(newTypeS(tyAnything, c))
|
||||||
|
|
||||||
else: nil
|
else: nil
|
||||||
|
|
||||||
|
|
@ -860,7 +870,7 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
|
||||||
return newOrPrevType(tyError, prev, c)
|
return newOrPrevType(tyError, prev, c)
|
||||||
|
|
||||||
var isConcrete = true
|
var isConcrete = true
|
||||||
|
|
||||||
for i in 1 .. <m.call.len:
|
for i in 1 .. <m.call.len:
|
||||||
let typ = m.call[i].typ.skipTypes({tyTypeDesc})
|
let typ = m.call[i].typ.skipTypes({tyTypeDesc})
|
||||||
if containsGenericType(typ): isConcrete = false
|
if containsGenericType(typ): isConcrete = false
|
||||||
|
|
@ -878,6 +888,7 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType =
|
||||||
allowMetaTypes = not isConcrete)
|
allowMetaTypes = not isConcrete)
|
||||||
if not isConcrete and result.kind == tyGenericInst:
|
if not isConcrete and result.kind == tyGenericInst:
|
||||||
result.lastSon.shouldHaveMeta
|
result.lastSon.shouldHaveMeta
|
||||||
|
|
||||||
|
|
||||||
proc semTypeExpr(c: PContext, n: PNode): PType =
|
proc semTypeExpr(c: PContext, n: PNode): PType =
|
||||||
var n = semExprWithType(c, n, {efDetermineType})
|
var n = semExprWithType(c, n, {efDetermineType})
|
||||||
|
|
|
||||||
|
|
@ -263,25 +263,24 @@ proc propagateFieldFlags(t: PType, n: PNode) =
|
||||||
of nkSym:
|
of nkSym:
|
||||||
propagateToOwner(t, n.sym.typ)
|
propagateToOwner(t, n.sym.typ)
|
||||||
of nkRecList, nkRecCase, nkOfBranch, nkElse:
|
of nkRecList, nkRecCase, nkOfBranch, nkElse:
|
||||||
for son in n.sons:
|
if n.sons != nil:
|
||||||
propagateFieldFlags(t, son)
|
for son in n.sons:
|
||||||
|
propagateFieldFlags(t, son)
|
||||||
else: discard
|
else: discard
|
||||||
|
|
||||||
proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
|
proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
|
||||||
result = t
|
result = t
|
||||||
if t == nil: return
|
if t == nil: return
|
||||||
|
|
||||||
if t.kind == tyStatic and t.sym != nil and t.sym.kind == skGenericParam:
|
#if t.kind == tyStatic and t.sym != nil and t.sym.kind == skGenericParam:
|
||||||
let s = lookupTypeVar(cl, t)
|
# let s = lookupTypeVar(cl, t)
|
||||||
return if s != nil: s else: t
|
# return if s != nil: s else: t
|
||||||
|
|
||||||
|
if t.kind in {tyStatic, tyGenericParam} + tyTypeClasses:
|
||||||
|
let lookup = PType(idTableGet(cl.typeMap, t))
|
||||||
|
if lookup != nil: return lookup
|
||||||
|
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyGenericParam, tyTypeClasses:
|
|
||||||
let lookup = lookupTypeVar(cl, t)
|
|
||||||
if lookup != nil:
|
|
||||||
result = lookup
|
|
||||||
if result.kind == tyGenericInvokation:
|
|
||||||
result = handleGenericInvokation(cl, result)
|
|
||||||
of tyGenericInvokation:
|
of tyGenericInvokation:
|
||||||
result = handleGenericInvokation(cl, t)
|
result = handleGenericInvokation(cl, t)
|
||||||
of tyGenericBody:
|
of tyGenericBody:
|
||||||
|
|
|
||||||
|
|
@ -649,8 +649,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
|
||||||
if a.kind == tyEmpty: result = isEqual
|
if a.kind == tyEmpty: result = isEqual
|
||||||
|
|
||||||
of tyGenericInst:
|
of tyGenericInst:
|
||||||
if a.kind == tyGenericInst:
|
if a.kind == tyGenericInst and a.base == f.base:
|
||||||
if a.base != f.base: return isNone
|
|
||||||
for i in 1 .. f.sonsLen-2:
|
for i in 1 .. f.sonsLen-2:
|
||||||
result = typeRel(c, f.sons[i], a.sons[i])
|
result = typeRel(c, f.sons[i], a.sons[i])
|
||||||
if result == isNone: return
|
if result == isNone: return
|
||||||
|
|
|
||||||
|
|
@ -1227,8 +1227,8 @@ proc getSize(typ: PType): BiggestInt =
|
||||||
if result < 0: internalError("getSize: " & $typ.kind)
|
if result < 0: internalError("getSize: " & $typ.kind)
|
||||||
|
|
||||||
proc containsGenericTypeIter(t: PType, closure: PObject): bool =
|
proc containsGenericTypeIter(t: PType, closure: PObject): bool =
|
||||||
result = t.kind in GenericTypes + tyTypeClasses +
|
result = t.kind in GenericTypes + tyTypeClasses + {tyTypeDesc} or
|
||||||
{tyTypeDesc, tyStatic}
|
t.kind == tyStatic and t.n == nil
|
||||||
|
|
||||||
proc containsGenericType*(t: PType): bool =
|
proc containsGenericType*(t: PType): bool =
|
||||||
result = iterOverType(t, containsGenericTypeIter, nil)
|
result = iterOverType(t, containsGenericTypeIter, nil)
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
line: 1847
|
line: 1855
|
||||||
file: "system.nim"
|
file: "system.nim"
|
||||||
errormsg: "can raise an unlisted exception: ref EIO"
|
errormsg: "can raise an unlisted exception: ref EIO"
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue