sink type begins to compile
This commit is contained in:
parent
e4081a7201
commit
2015895357
3 changed files with 31 additions and 16 deletions
|
|
@ -181,9 +181,18 @@ proc semConv(c: PContext, n: PNode): PNode =
|
||||||
result = newNodeI(nkConv, n.info)
|
result = newNodeI(nkConv, n.info)
|
||||||
var targetType = semTypeNode(c, n.sons[0], nil).skipTypes({tyTypeDesc})
|
var targetType = semTypeNode(c, n.sons[0], nil).skipTypes({tyTypeDesc})
|
||||||
maybeLiftType(targetType, c, n[0].info)
|
maybeLiftType(targetType, c, n[0].info)
|
||||||
result.addSon copyTree(n.sons[0])
|
|
||||||
var op = semExprWithType(c, n.sons[1])
|
|
||||||
|
|
||||||
|
if targetType.kind in {tySink, tyLent}:
|
||||||
|
let baseType = semTypeNode(c, n.sons[1], nil).skipTypes({tyTypeDesc})
|
||||||
|
let t = newTypeS(targetType.kind, c)
|
||||||
|
t.rawAddSonNoPropagationOfTypeFlags baseType
|
||||||
|
result = newNodeI(nkType, n.info)
|
||||||
|
result.typ = makeTypeDesc(c, t)
|
||||||
|
return
|
||||||
|
|
||||||
|
result.addSon copyTree(n.sons[0])
|
||||||
|
|
||||||
|
var op = semExprWithType(c, n.sons[1])
|
||||||
if targetType.isMetaType:
|
if targetType.isMetaType:
|
||||||
let final = inferWithMetatype(c, targetType, op, true)
|
let final = inferWithMetatype(c, targetType, op, true)
|
||||||
result.addSon final
|
result.addSon final
|
||||||
|
|
@ -191,6 +200,8 @@ proc semConv(c: PContext, n: PNode): PNode =
|
||||||
return
|
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.
|
||||||
addSon(result, op)
|
addSon(result, op)
|
||||||
|
|
||||||
if not isSymChoice(op):
|
if not isSymChoice(op):
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,8 @@ proc sumGeneric(t: PType): int =
|
||||||
while true:
|
while true:
|
||||||
case t.kind
|
case t.kind
|
||||||
of tyGenericInst, tyArray, tyRef, tyPtr, tyDistinct,
|
of tyGenericInst, tyArray, tyRef, tyPtr, tyDistinct,
|
||||||
tyOpenArray, tyVarargs, tySet, tyRange, tySequence, tyGenericBody:
|
tyOpenArray, tyVarargs, tySet, tyRange, tySequence, tyGenericBody,
|
||||||
|
tyLent:
|
||||||
t = t.lastSon
|
t = t.lastSon
|
||||||
inc result
|
inc result
|
||||||
of tyOr:
|
of tyOr:
|
||||||
|
|
@ -207,7 +208,7 @@ proc sumGeneric(t: PType): int =
|
||||||
of tyStatic:
|
of tyStatic:
|
||||||
return t.sons[0].sumGeneric + 1
|
return t.sons[0].sumGeneric + 1
|
||||||
of tyGenericParam, tyExpr, tyStmt: break
|
of tyGenericParam, tyExpr, tyStmt: break
|
||||||
of tyAlias: t = t.lastSon
|
of tyAlias, tySink: t = t.lastSon
|
||||||
of tyBool, tyChar, tyEnum, tyObject, tyPointer,
|
of tyBool, tyChar, tyEnum, tyObject, tyPointer,
|
||||||
tyString, tyCString, tyInt..tyInt64, tyFloat..tyFloat128,
|
tyString, tyCString, tyInt..tyInt64, tyFloat..tyFloat128,
|
||||||
tyUInt..tyUInt64, tyCompositeTypeClass:
|
tyUInt..tyUInt64, tyCompositeTypeClass:
|
||||||
|
|
@ -464,7 +465,7 @@ proc skipToObject(t: PType; skipped: var SkippedPtr): PType =
|
||||||
inc ptrs
|
inc ptrs
|
||||||
skipped = skippedPtr
|
skipped = skippedPtr
|
||||||
r = r.lastSon
|
r = r.lastSon
|
||||||
of tyGenericBody, tyGenericInst, tyAlias:
|
of tyGenericBody, tyGenericInst, tyAlias, tySink:
|
||||||
r = r.lastSon
|
r = r.lastSon
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
@ -524,7 +525,7 @@ proc allowsNil(f: PType): TTypeRelation {.inline.} =
|
||||||
result = if tfNotNil notin f.flags: isSubtype else: isNone
|
result = if tfNotNil notin f.flags: isSubtype else: isNone
|
||||||
|
|
||||||
proc inconsistentVarTypes(f, a: PType): bool {.inline.} =
|
proc inconsistentVarTypes(f, a: PType): bool {.inline.} =
|
||||||
result = f.kind != a.kind and (f.kind == tyVar or a.kind == tyVar)
|
result = f.kind != a.kind and (f.kind in {tyVar, tyLent} or a.kind in {tyVar, tyLent})
|
||||||
|
|
||||||
proc procParamTypeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
proc procParamTypeRel(c: var TCandidate, f, a: PType): TTypeRelation =
|
||||||
## For example we have:
|
## For example we have:
|
||||||
|
|
@ -889,7 +890,7 @@ proc inferStaticsInRange(c: var TCandidate,
|
||||||
doInferStatic(lowerBound, upperBound.intVal + 1 - lengthOrd(concrete))
|
doInferStatic(lowerBound, upperBound.intVal + 1 - lengthOrd(concrete))
|
||||||
|
|
||||||
template subtypeCheck() =
|
template subtypeCheck() =
|
||||||
if result <= isSubrange and f.lastSon.skipTypes(abstractInst).kind in {tyRef, tyPtr, tyVar}:
|
if result <= isSubrange and f.lastSon.skipTypes(abstractInst).kind in {tyRef, tyPtr, tyVar, tyLent}:
|
||||||
result = isNone
|
result = isNone
|
||||||
|
|
||||||
proc isCovariantPtr(c: var TCandidate, f, a: PType): bool =
|
proc isCovariantPtr(c: var TCandidate, f, a: PType): bool =
|
||||||
|
|
@ -897,7 +898,7 @@ proc isCovariantPtr(c: var TCandidate, f, a: PType): bool =
|
||||||
assert f.kind == a.kind
|
assert f.kind == a.kind
|
||||||
|
|
||||||
template baseTypesCheck(lhs, rhs: PType): bool =
|
template baseTypesCheck(lhs, rhs: PType): bool =
|
||||||
lhs.kind notin {tyPtr, tyRef, tyVar} and
|
lhs.kind notin {tyPtr, tyRef, tyVar, tyLent} and
|
||||||
typeRel(c, lhs, rhs, {trNoCovariance}) == isSubtype
|
typeRel(c, lhs, rhs, {trNoCovariance}) == isSubtype
|
||||||
|
|
||||||
case f.kind
|
case f.kind
|
||||||
|
|
@ -983,17 +984,17 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
|
||||||
template doBind: bool = trDontBind notin flags
|
template doBind: bool = trDontBind notin flags
|
||||||
|
|
||||||
# var and static arguments match regular modifier-free types
|
# var and static arguments match regular modifier-free types
|
||||||
var a = aOrig.skipTypes({tyStatic, tyVar}).maybeSkipDistinct(c.calleeSym)
|
var a = aOrig.skipTypes({tyStatic, tyVar, tyLent}).maybeSkipDistinct(c.calleeSym)
|
||||||
# XXX: Theoretically, maybeSkipDistinct could be called before we even
|
# XXX: Theoretically, maybeSkipDistinct could be called before we even
|
||||||
# start the param matching process. This could be done in `prepareOperand`
|
# start the param matching process. This could be done in `prepareOperand`
|
||||||
# for example, but unfortunately `prepareOperand` is not called in certain
|
# for example, but unfortunately `prepareOperand` is not called in certain
|
||||||
# situation when nkDotExpr are rotated to nkDotCalls
|
# situation when nkDotExpr are rotated to nkDotCalls
|
||||||
|
|
||||||
if aOrig.kind == tyAlias:
|
if aOrig.kind in {tyAlias, tySink}:
|
||||||
return typeRel(c, f, lastSon(aOrig))
|
return typeRel(c, f, lastSon(aOrig))
|
||||||
|
|
||||||
if a.kind == tyGenericInst and
|
if a.kind == tyGenericInst and
|
||||||
skipTypes(f, {tyVar}).kind notin {
|
skipTypes(f, {tyVar, tyLent}).kind notin {
|
||||||
tyGenericBody, tyGenericInvocation,
|
tyGenericBody, tyGenericInvocation,
|
||||||
tyGenericInst, tyGenericParam} + tyTypeClasses:
|
tyGenericInst, tyGenericParam} + tyTypeClasses:
|
||||||
return typeRel(c, f, lastSon(a))
|
return typeRel(c, f, lastSon(a))
|
||||||
|
|
@ -1105,8 +1106,8 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
|
||||||
of tyFloat32: result = handleFloatRange(f, a)
|
of tyFloat32: result = handleFloatRange(f, a)
|
||||||
of tyFloat64: result = handleFloatRange(f, a)
|
of tyFloat64: result = handleFloatRange(f, a)
|
||||||
of tyFloat128: result = handleFloatRange(f, a)
|
of tyFloat128: result = handleFloatRange(f, a)
|
||||||
of tyVar:
|
of tyVar, tyLent:
|
||||||
if aOrig.kind == tyVar: result = typeRel(c, f.base, aOrig.base)
|
if aOrig.kind == f.kind: result = typeRel(c, f.base, aOrig.base)
|
||||||
else: result = typeRel(c, f.base, aOrig, flags + {trNoCovariance})
|
else: result = typeRel(c, f.base, aOrig, flags + {trNoCovariance})
|
||||||
subtypeCheck()
|
subtypeCheck()
|
||||||
of tyArray:
|
of tyArray:
|
||||||
|
|
@ -1311,7 +1312,7 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
|
||||||
of tyEmpty, tyVoid:
|
of tyEmpty, tyVoid:
|
||||||
if a.kind == f.kind: result = isEqual
|
if a.kind == f.kind: result = isEqual
|
||||||
|
|
||||||
of tyAlias:
|
of tyAlias, tySink:
|
||||||
result = typeRel(c, lastSon(f), a)
|
result = typeRel(c, lastSon(f), a)
|
||||||
|
|
||||||
of tyGenericInst:
|
of tyGenericInst:
|
||||||
|
|
@ -1497,7 +1498,7 @@ proc typeRelImpl(c: var TCandidate, f, aOrig: PType,
|
||||||
considerPreviousT:
|
considerPreviousT:
|
||||||
let targetKind = f.sons[0].kind
|
let targetKind = f.sons[0].kind
|
||||||
let effectiveArgType = a.skipTypes({tyRange, tyGenericInst,
|
let effectiveArgType = a.skipTypes({tyRange, tyGenericInst,
|
||||||
tyBuiltInTypeClass, tyAlias})
|
tyBuiltInTypeClass, tyAlias, tySink})
|
||||||
let typeClassMatches = targetKind == effectiveArgType.kind and
|
let typeClassMatches = targetKind == effectiveArgType.kind and
|
||||||
not effectiveArgType.isEmptyContainer
|
not effectiveArgType.isEmptyContainer
|
||||||
if typeClassMatches or
|
if typeClassMatches or
|
||||||
|
|
@ -2068,7 +2069,8 @@ proc prepareNamedParam(a: PNode) =
|
||||||
proc arrayConstr(c: PContext, n: PNode): PType =
|
proc arrayConstr(c: PContext, n: PNode): PType =
|
||||||
result = newTypeS(tyArray, c)
|
result = newTypeS(tyArray, c)
|
||||||
rawAddSon(result, makeRangeType(c, 0, 0, n.info))
|
rawAddSon(result, makeRangeType(c, 0, 0, n.info))
|
||||||
addSonSkipIntLit(result, skipTypes(n.typ, {tyGenericInst, tyVar, tyOrdinal}))
|
addSonSkipIntLit(result, skipTypes(n.typ,
|
||||||
|
{tyGenericInst, tyVar, tyLent, tyOrdinal}))
|
||||||
|
|
||||||
proc arrayConstr(c: PContext, info: TLineInfo): PType =
|
proc arrayConstr(c: PContext, info: TLineInfo): PType =
|
||||||
result = newTypeS(tyArray, c)
|
result = newTypeS(tyArray, c)
|
||||||
|
|
|
||||||
|
|
@ -581,6 +581,8 @@ proc typeToString(typ: PType, prefer: TPreferedDesc = preferName): string =
|
||||||
if len(prag) != 0: add(result, "{." & prag & ".}")
|
if len(prag) != 0: add(result, "{." & prag & ".}")
|
||||||
of tyVarargs:
|
of tyVarargs:
|
||||||
result = typeToStr[t.kind] % typeToString(t.sons[0])
|
result = typeToStr[t.kind] % typeToString(t.sons[0])
|
||||||
|
of tySink:
|
||||||
|
result = "sink " & typeToString(t.sons[0])
|
||||||
else:
|
else:
|
||||||
result = typeToStr[t.kind]
|
result = typeToStr[t.kind]
|
||||||
result.addTypeFlags(t)
|
result.addTypeFlags(t)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue