--gc:destructors: baby steps

This commit is contained in:
Andreas Rumpf 2018-12-15 13:54:41 +01:00
commit e3a668a33b
5 changed files with 27 additions and 25 deletions

View file

@ -296,7 +296,8 @@ proc makePtrType(c: Con, baseType: PType): PType =
template genOp(opr, opname, ri) =
let op = opr
if op == nil:
globalError(c.graph.config, dest.info, "internal error: '" & opname & "' operator not found for type " & typeToString(t))
globalError(c.graph.config, dest.info, "internal error: '" & opname &
"' operator not found for type " & typeToString(t))
elif op.ast[genericParamsPos].kind != nkEmpty:
globalError(c.graph.config, dest.info, "internal error: '" & opname & "' operator is generic")
patchHead op

View file

@ -1427,6 +1427,12 @@ proc maybeAddResult(c: PContext, s: PSym, n: PNode) =
addResult(c, s.typ.sons[0], n.info, s.kind)
addResultNode(c, n)
proc canonType(c: PContext, t: PType): PType =
if t.kind == tySequence:
result = c.graph.sysTypes[tySequence]
else:
result = t
proc semOverride(c: PContext, s: PSym, n: PNode) =
case s.name.s.normalize
of "=destroy":
@ -1440,6 +1446,7 @@ proc semOverride(c: PContext, s: PSym, n: PNode) =
elif obj.kind == tyGenericInvocation: obj = obj.sons[0]
else: break
if obj.kind in {tyObject, tyDistinct, tySequence, tyString}:
obj = canonType(c, obj)
if obj.destructor.isNil:
obj.destructor = s
else:
@ -1491,6 +1498,8 @@ proc semOverride(c: PContext, s: PSym, n: PNode) =
objB = objB.sons[0]
else: break
if obj.kind in {tyObject, tyDistinct, tySequence, tyString} and sameType(obj, objB):
# attach these ops to the canonical tySequence
obj = canonType(c, obj)
let opr = if s.name.s == "=": addr(obj.assignment) else: addr(obj.sink)
if opr[].isNil:
opr[] = s

View file

@ -1551,10 +1551,7 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
# XXX figure out why this has children already...
result.sons.setLen 0
result.n = nil
if c.config.selectedGc == gcDestructors:
result.flags = {tfHasAsgn}
else:
result.flags = {}
result.flags = {tfHasAsgn}
semContainerArg(c, n, "seq", result)
else:
result = semContainer(c, n, tySequence, "seq", prev)

View file

@ -70,12 +70,6 @@ proc `=sink`[T](x: var seq[T]; y: seq[T]) =
a.len = b.len
a.p = b.p
when false:
proc incrSeqV3(s: PGenericSeq, typ: PNimType): PGenericSeq {.compilerProc.}
proc setLengthSeqV2(s: PGenericSeq, typ: PNimType, newLen: int): PGenericSeq {.
compilerRtl.}
proc newSeq(typ: PNimType, len: int): pointer {.compilerRtl.}
type
PayloadBase = object

View file

@ -3431,6 +3431,10 @@ when not defined(JS): #and not defined(nimscript):
when defined(memtracker):
include "system/memtracker"
when defined(gcDestructors):
include "core/strs"
include "core/seqs"
when hostOS == "standalone":
include "system/embedded"
else:
@ -3479,10 +3483,7 @@ when not defined(JS): #and not defined(nimscript):
{.pop.}
{.push stack_trace: off, profiler:off.}
when hasAlloc:
when defined(gcDestructors):
include "core/strs"
include "core/seqs"
else:
when not defined(gcDestructors):
include "system/sysstr"
{.pop.}
when hasAlloc: include "system/strmantle"