This commit is contained in:
Andreas Rumpf 2021-09-04 15:57:16 +02:00 • committed by GitHub
commit e8dad482a3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 2 deletions

View file

@ -91,7 +91,8 @@ proc sameInstantiation(a, b: TInstantiation): bool =
for i in 0..a.concreteTypes.high: for i in 0..a.concreteTypes.high:
if not compareTypes(a.concreteTypes[i], b.concreteTypes[i], if not compareTypes(a.concreteTypes[i], b.concreteTypes[i],
flags = {ExactTypeDescValues, flags = {ExactTypeDescValues,
ExactGcSafety}): return ExactGcSafety,
PickyCAliases}): return
result = true result = true
proc genericCacheGet(g: ModuleGraph; genericSym: PSym, entry: TInstantiation; proc genericCacheGet(g: ModuleGraph; genericSym: PSym, entry: TInstantiation;

View file

@ -51,7 +51,7 @@ proc searchInstTypes*(g: ModuleGraph; key: PType): PType =
for j in 1..high(key.sons): for j in 1..high(key.sons):
# XXX sameType is not really correct for nested generics? # XXX sameType is not really correct for nested generics?
if not compareTypes(inst[j], key[j], if not compareTypes(inst[j], key[j],
flags = {ExactGenericParams}): flags = {ExactGenericParams, PickyCAliases}):
break matchType break matchType
return inst return inst

View file

@ -896,6 +896,7 @@ type
ExactConstraints ExactConstraints
ExactGcSafety ExactGcSafety
AllowCommonBase AllowCommonBase
PickyCAliases # be picky about the distinction between 'cint' and 'int32'
TTypeCmpFlags* = set[TTypeCmpFlag] TTypeCmpFlags* = set[TTypeCmpFlag]
@ -1144,6 +1145,13 @@ proc sameTypeAux(x, y: PType, c: var TSameTypeClosure): bool =
of tyEmpty, tyChar, tyBool, tyNil, tyPointer, tyString, tyCstring, of tyEmpty, tyChar, tyBool, tyNil, tyPointer, tyString, tyCstring,
tyInt..tyUInt64, tyTyped, tyUntyped, tyVoid: tyInt..tyUInt64, tyTyped, tyUntyped, tyVoid:
result = sameFlags(a, b) result = sameFlags(a, b)
if result and PickyCAliases in c.flags:
# additional requirement for the caching of generics for importc'ed types:
# the symbols must be identical too:
let symFlagsA = if a.sym != nil: a.sym.flags else: {}
let symFlagsB = if b.sym != nil: b.sym.flags else: {}
if (symFlagsA+symFlagsB) * {sfImportc, sfExportc} != {}:
result = symFlagsA == symFlagsB
of tyStatic, tyFromExpr: of tyStatic, tyFromExpr:
result = exprStructuralEquivalent(a.n, b.n) and sameFlags(a, b) result = exprStructuralEquivalent(a.n, b.n) and sameFlags(a, b)
if result and a.len == b.len and a.len == 1: if result and a.len == b.len and a.len == 1:

View file

@ -463,3 +463,14 @@ proc putValue[T](n: T) =
echo b.n echo b.n
useForward() useForward()
# bug #16246
proc testWeirdTypeAliases() =
var values = newSeq[cuint](8)
# var values: seq[cuint] does not produce codegen error
var drawCb = proc(): seq[uint32] =
result = newSeq[uint32](10)
testWeirdTypeAliases()