Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions compiler/ast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ type
tfIsOutParam
tfSendable
tfImplicitStatic
tfWeakened # for tyDistinct means "weak distinct"

TTypeFlags* = set[TTypeFlag]

Expand Down
10 changes: 8 additions & 2 deletions compiler/semtypes.nim
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ proc addSonSkipIntLitChecked(c: PContext; father, son: PType; it: PNode, id: IdG
propagateToOwner(father, s)

proc semDistinct(c: PContext, n: PNode, prev: PType): PType =
if n.len == 0: return newConstraint(c, tyDistinct)
if n.kind != nkDistinctTy or n.len == 0: return newConstraint(c, tyDistinct)
if prevIsKind(prev, tyDistinct):
# the symbol already has a distinct type (likely resem), don't create a new type
return skipGenericPrev(prev)
Expand Down Expand Up @@ -2291,6 +2291,11 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
result = s.typ.base
elif prev == nil:
result = s.typ
elif prev.sym != nil and sfImportc in prev.sym.flags:
let tmp = newNode(nkDistinctTy)
tmp.add n
result = semDistinct(c, tmp, prev)
result.flags.incl tfWeakened
else:
let alias = maybeAliasType(c, s.typ, prev)
if alias != nil:
Expand Down Expand Up @@ -2339,7 +2344,8 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
of nkPtrTy: result = semAnyRef(c, n, tyPtr, prev)
of nkVarTy: result = semVarOutType(c, n, prev, {})
of nkOutTy: result = semVarOutType(c, n, prev, {tfIsOutParam})
of nkDistinctTy: result = semDistinct(c, n, prev)
of nkDistinctTy:
result = semDistinct(c, n, prev)
of nkStaticTy: result = semStaticType(c, n[0], prev)
of nkProcTy, nkIteratorTy:
if n.len == 0 or n[0].kind == nkEmpty:
Expand Down
21 changes: 18 additions & 3 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ proc sumGeneric(t: PType): int =
while true:
case t.kind
of tyAlias, tySink, tyNot: t = t.skipModifier
of tyArray, tyRef, tyPtr, tyDistinct, tyUncheckedArray,
of tyArray, tyRef, tyPtr, tyUncheckedArray,
tyOpenArray, tyVarargs, tySet, tyRange, tySequence,
tyLent, tyOwned, tyVar:
t = t.elementType
Expand Down Expand Up @@ -364,6 +364,9 @@ proc sumGeneric(t: PType): int =
for _, a in t.paramTypes:
result += sumGeneric(a)
break
of tyDistinct:
result += ord(tfWeakened notin t.flags)
t = t.base
else:
if t.isConcept:
result += t.reduceToBase.conceptBody.len
Expand Down Expand Up @@ -1357,6 +1360,13 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
# Foo[templateCall(T)] shouldn't fail early if Foo has a constraint
# and we can't evaluate `templateCall(T)` yet
return isGeneric
of tyDistinct:
if f.kind != tyDistinct:
let coerceDistincts = c.coerceDistincts or tfWeakened in a.flags
if coerceDistincts:
inc c.inheritancePenalty
return typeRel(c, f, a.base, flags)

else: discard

case f.kind
Expand Down Expand Up @@ -1552,11 +1562,16 @@ proc typeRel(c: var TCandidate, f, aOrig: PType,
result = isSubtype
of tyDistinct:
a = a.skipTypes({tyOwned, tyGenericInst, tyRange})
let coerceDistincts = c.coerceDistincts or tfWeakened in f.flags
if a.kind == tyDistinct:
if sameDistinctTypes(f, a): result = isEqual
#elif f.base.kind == tyAnything: result = isGeneric # issue 4435
elif c.coerceDistincts: result = typeRel(c, f.base, a, flags)
elif c.coerceDistincts: result = typeRel(c, f.base, a, flags)
elif coerceDistincts:
inc c.inheritancePenalty
result = typeRel(c, f.base, a, flags)
elif coerceDistincts:
inc c.inheritancePenalty
result = typeRel(c, f.base, a, flags)
of tySet:
if a.kind == tySet:
if f[0].kind != tyGenericParam and a[0].kind == tyEmpty:
Expand Down
2 changes: 1 addition & 1 deletion lib/pure/net.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1374,7 +1374,7 @@ proc uniRecv(socket: Socket, buffer: pointer, size, flags: cint): int =

proc readIntoBuf(socket: Socket, flags: int32): int =
result = 0
result = uniRecv(socket, addr(socket.buffer), socket.buffer.high, flags)
result = uniRecv(socket, addr(socket.buffer), socket.buffer.high.cint, flags)
if result < 0:
# Save it in case it gets reset (the Nim codegen occasionally may call
# Win API functions which reset it).
Expand Down
Loading