gc:destructors: progress

This commit is contained in:
Andreas Rumpf 2019-02-28 22:39:15 +01:00
commit 728ff1004a
6 changed files with 85 additions and 2 deletions

View file

@ -88,6 +88,7 @@ type
allowMetaTypes*: bool # allow types such as seq[Number]
# i.e. the result contains unresolved generics
skipTypedesc*: bool # wether we should skip typeDescs
isReturnType*: bool
owner*: PSym # where this instantiation comes from
recursionLimit: int
@ -594,6 +595,21 @@ proc replaceTypeVarsTAux(cl: var TReplTypeVars, t: PType): PType =
eraseVoidParams(result)
skipIntLiteralParams(result)
of tySequence:
if cl.isReturnType and cl.c.config.selectedGc == gcDestructors and result.destructor.isNil and
result[0].kind != tyEmpty:
let s = cl.c.graph.sysTypes[tySequence]
var old = copyType(s, s.owner, keepId=false)
# Remove the 'T' parameter from tySequence:
old.sons.setLen 0
old.n = nil
old.flags = {tfHasAsgn}
old.addSonSkipIntLit result[0]
result.destructor = old.destructor
result.assignment = old.assignment
result.sink = old.sink
cl.c.typesWithOps.add((result, old))
else: discard
else:
# If this type doesn't refer to a generic type we may still want to run it