diff options
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/ccgexprs.nim | 8 | ||||
-rw-r--r-- | compiler/ccgstmts.nim | 1 | ||||
-rw-r--r-- | compiler/ccgtypes.nim | 4 | ||||
-rw-r--r-- | compiler/liftdestructors.nim | 39 |
4 files changed, 29 insertions, 23 deletions
diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index e080ca746..7de5e5606 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -1956,14 +1956,14 @@ proc genDestroy(p: BProc; n: PNode) = of tyString: var a: TLoc initLocExpr(p, n[1].skipAddr, a) - linefmt(p, cpsStmts, "if ($1.len && $1.region) {$n" & - " $1.region->dealloc($1.region, $1.p, $1.p->cap + 1 + sizeof(NI) + sizeof(void*)); }$n", + linefmt(p, cpsStmts, "if ($1.len && $1.p->allocator) {$n" & + " $1.p->allocator->dealloc($1.p->allocator, $1.p, $1.p->cap + 1 + sizeof(NI) + sizeof(void*)); }$n", [rdLoc(a)]) of tySequence: var a: TLoc initLocExpr(p, n[1].skipAddr, a) - linefmt(p, cpsStmts, "if ($1.len && $1.region) {$n" & - " $1.region->dealloc($1.region, $1.p, ($1.p->cap * sizeof($2)) + sizeof(NI) + sizeof(void*)); }$n", + linefmt(p, cpsStmts, "if ($1.len && $1.p->allocator) {$n" & + " $1.p->allocator->dealloc($1.p->allocator, $1.p, ($1.p->cap * sizeof($2)) + sizeof(NI) + sizeof(void*)); }$n", [rdLoc(a), getTypeDesc(p.module, t.lastSon)]) else: discard "nothing to do" else: diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index e2790f4f6..1e6e04458 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -17,6 +17,7 @@ const proc getTraverseProc(p: BProc, v: Psym): Rope = if p.config.selectedGC in {gcMarkAndSweep, gcDestructors, gcV2, gcRefc} and + optNimV2 notin p.config.globalOptions and containsGarbageCollectedRef(v.loc.t): # we register a specialized marked proc here; this has the advantage # that it works out of the box for thread local storage then :-) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index ed051170f..6b4e9602b 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -740,7 +740,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope = " #TGenericSeq Sup;$n" if m.config.selectedGC == gcDestructors: appcg(m, m.s[cfsTypes], - "typedef struct{ NI cap;void* allocator;$1 data[SEQ_DECL_SIZE];}$2_Content;$n" & + "typedef struct{ NI cap;#AllocatorObj* allocator;$1 data[SEQ_DECL_SIZE];}$2_Content;$n" & "struct $2 {$n" & " NI len; $2_Content* p;$n" & "};$n", [getTypeDescAux(m, t.sons[0], check), result]) @@ -1254,7 +1254,7 @@ proc genObjectInfoV2(m: BModule, t, origType: PType, name: Rope; info: TLineInfo d = t.destructor.loc.r else: d = rope("NIM_NIL") - + addf(m.s[cfsVars], "TNimType $1;$n", [name]) addf(m.s[cfsTypeInit3], "$1.destructor = $2; $1.size = sizeof($3); $1.name = $4;$n", [ name, d, getTypeDesc(m, t), genTypeInfo2Name(m, t)]) diff --git a/compiler/liftdestructors.nim b/compiler/liftdestructors.nim index aea244a78..046428795 100644 --- a/compiler/liftdestructors.nim +++ b/compiler/liftdestructors.nim @@ -141,22 +141,19 @@ proc considerAsgnOrSink(c: var TLiftCtx; t: PType; body, x, y: PNode; result = true proc addDestructorCall(c: var TLiftCtx; t: PType; body, x: PNode): bool = - let op = t.destructor + var op = t.destructor + if op == nil and useNoGc(c, t): + op = liftBody(c.graph, t, attachedDestructor, c.info) + doAssert op != nil + if op != nil: markUsed(c.graph.config, c.info, op, c.graph.usageSym) onUse(c.info, op) body.add destructorCall(c.graph, op, x) result = true elif useNoGc(c, t): - if sameType(t, c.asgnForType) and c.kind == attachedDestructor: - let op = c.fn - markUsed(c.graph.config, c.info, op, c.graph.usageSym) - onUse(c.info, op) - body.add destructorCall(c.graph, op, x) - result = true - else: - internalError(c.graph.config, c.info, - "type-bound operator could not be resolved") + internalError(c.graph.config, c.info, + "type-bound operator could not be resolved") proc considerOverloadedOp(c: var TLiftCtx; t: PType; body, x, y: PNode): bool = case c.kind @@ -479,19 +476,27 @@ proc liftBody(g: ModuleGraph; typ: PType; kind: TTypeAttachedOp; if kind != attachedDestructor: result.typ.addParam src - liftBodyAux(a, typ, body, newSymNode(dest).newDeref, newSymNode(src)) - # recursion is handled explicitly, do not register the type based operation - # before 'liftBodyAux': - if g.config.selectedGC == gcDestructors and - typ.kind in {tySequence, tyString} and body.len == 0: - discard "do not cache it yet" - else: + if optNimV2 in g.config.globalOptions: case kind of attachedAsgn: typ.assignment = result of attachedSink: typ.sink = result of attachedDeepCopy: typ.deepCopy = result of attachedDestructor: typ.destructor = result + liftBodyAux(a, typ, body, newSymNode(dest).newDeref, newSymNode(src)) + if optNimV2 notin g.config.globalOptions: + # recursion is handled explicitly, do not register the type based operation + # before 'liftBodyAux': + if g.config.selectedGC == gcDestructors and + typ.kind in {tySequence, tyString} and body.len == 0: + discard "do not cache it yet" + else: + case kind + of attachedAsgn: typ.assignment = result + of attachedSink: typ.sink = result + of attachedDeepCopy: typ.deepCopy = result + of attachedDestructor: typ.destructor = result + var n = newNodeI(nkProcDef, info, bodyPos+1) for i in 0 ..< n.len: n.sons[i] = newNodeI(nkEmpty, info) n.sons[namePos] = newSymNode(result) |