Skip to content

Commit

Permalink
Propagate tfGcSafe flag to generic instantiations (#10620)
Browse files Browse the repository at this point in the history
Fixes a nasty endless loop in the generic instantiation phase.
  • Loading branch information
LemonBoy authored and Araq committed Feb 10, 2019
1 parent 4910608 commit 5fd9bf9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 2 additions & 3 deletions compiler/semtypinst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@ proc instCopyType*(cl: var TReplTypeVars, t: PType): PType =
proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
# tyGenericInvocation[A, tyGenericInvocation[A, B]]
# is difficult to handle:
const eqFlags = eqTypeFlags + {tfGcSafe}
var body = t.sons[0]
if body.kind != tyGenericBody:
internalError(cl.c.config, cl.info, "no generic body")
Expand All @@ -311,7 +310,7 @@ proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
else:
result = searchInstTypes(t)

if result != nil and eqFlags*result.flags == eqFlags*t.flags:
if result != nil and sameFlags(result, t):
when defined(reportCacheHits):
echo "Generic instantiation cached ", typeToString(result), " for ", typeToString(t)
return
Expand All @@ -329,7 +328,7 @@ proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
if header != t:
# search again after first pass:
result = searchInstTypes(header)
if result != nil and eqFlags*result.flags == eqFlags*t.flags:
if result != nil and sameFlags(result, t):
when defined(reportCacheHits):
echo "Generic instantiation cached ", typeToString(result), " for ",
typeToString(t), " header ", typeToString(header)
Expand Down
11 changes: 11 additions & 0 deletions tests/generics/tgenerics_various.nim
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,14 @@ block tvarargs_vs_generics:
withDirectType "string"
withOpenArray "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)

0 comments on commit 5fd9bf9

Please sign in to comment.