Propagate tfGcSafe flag to generic instantiations (#10620)
Fixes a nasty endless loop in the generic instantiation phase.
This commit is contained in:
parent
942495611b
commit
0ebef1764d
2 changed files with 13 additions and 3 deletions
|
|
@ -300,7 +300,6 @@ proc instCopyType*(cl: var TReplTypeVars, t: PType): PType =
|
||||||
proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
|
proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
|
||||||
# tyGenericInvocation[A, tyGenericInvocation[A, B]]
|
# tyGenericInvocation[A, tyGenericInvocation[A, B]]
|
||||||
# is difficult to handle:
|
# is difficult to handle:
|
||||||
const eqFlags = eqTypeFlags + {tfGcSafe}
|
|
||||||
var body = t.sons[0]
|
var body = t.sons[0]
|
||||||
if body.kind != tyGenericBody:
|
if body.kind != tyGenericBody:
|
||||||
internalError(cl.c.config, cl.info, "no generic body")
|
internalError(cl.c.config, cl.info, "no generic body")
|
||||||
|
|
@ -311,7 +310,7 @@ proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
|
||||||
else:
|
else:
|
||||||
result = searchInstTypes(t)
|
result = searchInstTypes(t)
|
||||||
|
|
||||||
if result != nil and eqFlags*result.flags == eqFlags*t.flags:
|
if result != nil and sameFlags(result, t):
|
||||||
when defined(reportCacheHits):
|
when defined(reportCacheHits):
|
||||||
echo "Generic instantiation cached ", typeToString(result), " for ", typeToString(t)
|
echo "Generic instantiation cached ", typeToString(result), " for ", typeToString(t)
|
||||||
return
|
return
|
||||||
|
|
@ -329,7 +328,7 @@ proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
|
||||||
if header != t:
|
if header != t:
|
||||||
# search again after first pass:
|
# search again after first pass:
|
||||||
result = searchInstTypes(header)
|
result = searchInstTypes(header)
|
||||||
if result != nil and eqFlags*result.flags == eqFlags*t.flags:
|
if result != nil and sameFlags(result, t):
|
||||||
when defined(reportCacheHits):
|
when defined(reportCacheHits):
|
||||||
echo "Generic instantiation cached ", typeToString(result), " for ",
|
echo "Generic instantiation cached ", typeToString(result), " for ",
|
||||||
typeToString(t), " header ", typeToString(header)
|
typeToString(t), " header ", typeToString(header)
|
||||||
|
|
|
||||||
|
|
@ -242,3 +242,14 @@ block tvarargs_vs_generics:
|
||||||
withDirectType "string"
|
withDirectType "string"
|
||||||
withOpenArray "string"
|
withOpenArray "string"
|
||||||
withVarargs "string"
|
withVarargs "string"
|
||||||
|
|
||||||
|
block:
|
||||||
|
type
|
||||||
|
Que[T] {.gcsafe.} = object
|
||||||
|
x: T
|
||||||
|
|
||||||
|
proc `=`[T](q: var Que[T]; x: Que[T]) =
|
||||||
|
discard
|
||||||
|
|
||||||
|
var x: Que[int]
|
||||||
|
doAssert(x.x == 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue