From a2ad0697694139eaed78fe83dce99ded348dee3d Mon Sep 17 00:00:00 2001 From: Araq Date: Thu, 11 Apr 2019 12:42:51 +0200 Subject: [PATCH] preparations for --newruntime owned refs/callbacks --- compiler/ccgcalls.nim | 6 +++--- compiler/ccgexprs.nim | 28 ++++++++++++++-------------- compiler/injectdestructors.nim | 20 ++++++++++---------- compiler/liftdestructors.nim | 2 +- compiler/types.nim | 4 ++-- 5 files changed, 30 insertions(+), 30 deletions(-) diff --git a/compiler/ccgcalls.nim b/compiler/ccgcalls.nim index 94cedf339f..e46e2c47db 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -185,7 +185,7 @@ proc genPrefixCall(p: BProc, le, ri: PNode, d: var TLoc) = initLocExpr(p, ri.sons[0], op) var params: Rope # getUniqueType() is too expensive here: - var typ = skipTypes(ri.sons[0].typ, abstractInst) + var typ = skipTypes(ri.sons[0].typ, abstractInstOwned) assert(typ.kind == tyProc) assert(sonsLen(typ) == sonsLen(typ.n)) var length = sonsLen(ri) @@ -531,7 +531,7 @@ proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) = line(p, cpsStmts, pl) proc genCall(p: BProc, e: PNode, d: var TLoc) = - if e.sons[0].typ.skipTypes({tyGenericInst, tyAlias, tySink}).callConv == ccClosure: + if e.sons[0].typ.skipTypes({tyGenericInst, tyAlias, tySink, tyOwned}).callConv == ccClosure: genClosureCall(p, nil, e, d) elif e.sons[0].kind == nkSym and sfInfixCall in e.sons[0].sym.flags: genInfixCall(p, nil, e, d) @@ -542,7 +542,7 @@ proc genCall(p: BProc, e: PNode, d: var TLoc) = postStmtActions(p) proc genAsgnCall(p: BProc, le, ri: PNode, d: var TLoc) = - if ri.sons[0].typ.skipTypes({tyGenericInst, tyAlias, tySink}).callConv == ccClosure: + if ri.sons[0].typ.skipTypes({tyGenericInst, tyAlias, tySink, tyOwned}).callConv == ccClosure: genClosureCall(p, le, ri, d) elif ri.sons[0].kind == nkSym and sfInfixCall in ri.sons[0].sym.flags: genInfixCall(p, le, ri, d) diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 00afd04fa6..cc054b33a2 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -613,7 +613,7 @@ proc genEqProc(p: BProc, e: PNode, d: var TLoc) = assert(e.sons[2].typ != nil) initLocExpr(p, e.sons[1], a) initLocExpr(p, e.sons[2], b) - if a.t.skipTypes(abstractInst).callConv == ccClosure: + if a.t.skipTypes(abstractInstOwned).callConv == ccClosure: putIntoDest(p, d, e, "($1.ClP_0 == $2.ClP_0 && $1.ClE_0 == $2.ClE_0)" % [rdLoc(a), rdLoc(b)]) else: @@ -660,8 +660,8 @@ proc unaryArith(p: BProc, e: PNode, d: var TLoc, op: TMagic) = proc isCppRef(p: BProc; typ: PType): bool {.inline.} = result = p.module.compileToCpp and - skipTypes(typ, abstractInst).kind == tyVar and - tfVarIsPtr notin skipTypes(typ, abstractInst).flags + skipTypes(typ, abstractInstOwned).kind == tyVar and + tfVarIsPtr notin skipTypes(typ, abstractInstOwned).flags proc genDeref(p: BProc, e: PNode, d: var TLoc; enforceDeref=false) = let mt = mapType(p.config, e.sons[0].typ) @@ -775,7 +775,7 @@ proc genRecordField(p: BProc, e: PNode, d: var TLoc) = genRecordFieldAux(p, e, d, a) var r = rdLoc(a) var f = e.sons[1].sym - let ty = skipTypes(a.t, abstractInst + tyUserTypeClasses) + let ty = skipTypes(a.t, abstractInstOwned + tyUserTypeClasses) if ty.kind == tyTuple: # we found a unique tuple type which lacks field information # so we use Field$i @@ -1288,7 +1288,7 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) = # we skip this step here: if not p.module.compileToCpp: if handleConstExpr(p, e, d): return - var t = e.typ.skipTypes(abstractInst) + var t = e.typ.skipTypes(abstractInstOwned) let isRef = t.kind == tyRef # check if we need to construct the object in a temporary @@ -1304,7 +1304,7 @@ proc genObjConstr(p: BProc, e: PNode, d: var TLoc) = r = rdLoc(tmp) if isRef: rawGenNew(p, tmp, nil) - t = t.lastSon.skipTypes(abstractInst) + t = t.lastSon.skipTypes(abstractInstOwned) r = "(*$1)" % [r] gcUsage(p.config, e) else: @@ -1462,12 +1462,12 @@ proc genOf(p: BProc, x: PNode, typ: PType, d: var TLoc) = var dest = skipTypes(typ, typedescPtrs) var r = rdLoc(a) var nilCheck: Rope = nil - var t = skipTypes(a.t, abstractInst) + var t = skipTypes(a.t, abstractInstOwned) while t.kind in {tyVar, tyLent, tyPtr, tyRef}: if t.kind notin {tyVar, tyLent}: nilCheck = r if t.kind notin {tyVar, tyLent} or not p.module.compileToCpp: r = ropecg(p.module, "(*$1)", [r]) - t = skipTypes(t.lastSon, typedescInst) + t = skipTypes(t.lastSon, typedescInst+{tyOwned}) discard getTypeDesc(p.module, t) if not p.module.compileToCpp: while t.kind == tyObject and t.sons[0] != nil: @@ -1826,7 +1826,7 @@ proc genSomeCast(p: BProc, e: PNode, d: var TLoc) = # through its address: var a: TLoc initLocExpr(p, e.sons[1], a) - let etyp = skipTypes(e.typ, abstractRange) + let etyp = skipTypes(e.typ, abstractRange+{tyOwned}) if etyp.kind in ValueTypes and lfIndirect notin a.flags: putIntoDest(p, d, e, "(*($1*) ($2))" % [getTypeDesc(p.module, e.typ), addrLoc(p.config, a)], a.storage) @@ -2374,7 +2374,7 @@ proc downConv(p: BProc, n: PNode, d: var TLoc) = var a: TLoc initLocExpr(p, arg, a) var r = rdLoc(a) - let isRef = skipTypes(arg.typ, abstractInst).kind in {tyRef, tyPtr, tyVar, tyLent} + let isRef = skipTypes(arg.typ, abstractInstOwned).kind in {tyRef, tyPtr, tyVar, tyLent} if isRef: add(r, "->Sup") else: @@ -2386,7 +2386,7 @@ proc downConv(p: BProc, n: PNode, d: var TLoc) = # (see bug #837). However sometimes using a temporary is not correct: # init(TFigure(my)) # where it is passed to a 'var TFigure'. We test # this by ensuring the destination is also a pointer: - if d.k == locNone and skipTypes(n.typ, abstractInst).kind in {tyRef, tyPtr, tyVar, tyLent}: + if d.k == locNone and skipTypes(n.typ, abstractInstOwned).kind in {tyRef, tyPtr, tyVar, tyLent}: getTemp(p, n.typ, d) linefmt(p, cpsStmts, "$1 = &$2;$n", [rdLoc(d), r]) else: @@ -2618,7 +2618,7 @@ proc genNamedConstExpr(p: BProc, n: PNode): Rope = else: result = genConstExpr(p, n) proc getDefaultValue(p: BProc; typ: PType; info: TLineInfo): Rope = - var t = skipTypes(typ, abstractRange-{tyTypeDesc}) + var t = skipTypes(typ, abstractRange+{tyOwned}-{tyTypeDesc}) case t.kind of tyBool: result = rope"NIM_FALSE" of tyEnum, tyChar, tyInt..tyInt64, tyUInt..tyUInt64: result = rope"0" @@ -2693,7 +2693,7 @@ proc getNullValueAuxT(p: BProc; orig, t: PType; obj, cons: PNode, result: var Ro proc genConstObjConstr(p: BProc; n: PNode): Rope = result = nil - let t = n.typ.skipTypes(abstractInst) + let t = n.typ.skipTypes(abstractInstOwned) var count = 0 #if not isObjLackingTypeField(t) and not p.module.compileToCpp: # addf(result, "{$1}", [genTypeInfo(p.module, t)]) @@ -2760,7 +2760,7 @@ proc genConstExpr(p: BProc, n: PNode): Rope = toBitSet(p.config, n, cs) result = genRawSetData(cs, int(getSize(p.config, n.typ))) of nkBracket, nkPar, nkTupleConstr, nkClosure: - var t = skipTypes(n.typ, abstractInst) + var t = skipTypes(n.typ, abstractInstOwned) if t.kind == tySequence: if p.config.selectedGc == gcDestructors: result = genConstSeqV2(p, n, n.typ) diff --git a/compiler/injectdestructors.nim b/compiler/injectdestructors.nim index 45aae73a05..a65819cf08 100644 --- a/compiler/injectdestructors.nim +++ b/compiler/injectdestructors.nim @@ -591,7 +591,7 @@ proc moveOrCopy(dest, ri: PNode; c: var Con): PNode = # so these all act like 'sink' parameters: ri2[i].sons[1] = pArg(ri[i][1], c, isSink = true) result.add ri2 - of nkTupleConstr: + of nkTupleConstr, nkClosure: result = genSink(c, dest.typ, dest, ri) let ri2 = copyTree(ri) for i in 0..