mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
preparations for --newruntime owned refs/callbacks
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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..<ri.len:
|
||||
@@ -686,15 +686,15 @@ proc p(n: PNode; c: var Con): PNode =
|
||||
elif it.kind == nkIdentDefs and hasDestructor(it[0].typ) and not isCursor(it[0]):
|
||||
for j in 0..L-3:
|
||||
let v = it[j]
|
||||
doAssert v.kind == nkSym
|
||||
# move the variable declaration to the top of the frame:
|
||||
c.addTopVar v
|
||||
# make sure it's destroyed at the end of the proc:
|
||||
if not isUnpackedTuple(it[0].sym):
|
||||
c.destroys.add genDestroy(c, v.typ, v)
|
||||
if ri.kind != nkEmpty:
|
||||
let r = moveOrCopy(v, ri, c)
|
||||
result.add r
|
||||
if v.kind == nkSym:
|
||||
# move the variable declaration to the top of the frame:
|
||||
c.addTopVar v
|
||||
# make sure it's destroyed at the end of the proc:
|
||||
if not isUnpackedTuple(it[0].sym):
|
||||
c.destroys.add genDestroy(c, v.typ, v)
|
||||
if ri.kind != nkEmpty:
|
||||
let r = moveOrCopy(v, ri, c)
|
||||
result.add r
|
||||
else:
|
||||
# keep it, but transform 'ri':
|
||||
var varSection = copyNode(n)
|
||||
|
||||
@@ -396,7 +396,7 @@ proc ownedClosureOp(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||
xx.typ = getSysType(c.graph, c.info, tyPointer)
|
||||
var actions = newNodeI(nkStmtList, c.info)
|
||||
let elemType = t.lastSon
|
||||
discard addDestructorCall(c, elemType, newNodeI(nkStmtList, c.info), genDeref(xx))
|
||||
#discard addDestructorCall(c, elemType, newNodeI(nkStmtList, c.info), genDeref(xx))
|
||||
actions.add callCodegenProc(c.graph, "nimDestroyAndDispose", c.info, xx)
|
||||
case c.kind
|
||||
of attachedSink, attachedAsgn:
|
||||
|
||||
@@ -58,9 +58,9 @@ const
|
||||
abstractRange* = {tyGenericInst, tyRange, tyDistinct, tyOrdinal, tyTypeDesc,
|
||||
tyAlias, tyInferred, tySink, tyOwned}
|
||||
abstractVarRange* = {tyGenericInst, tyRange, tyVar, tyDistinct, tyOrdinal,
|
||||
tyTypeDesc, tyAlias, tyInferred, tySink}
|
||||
tyTypeDesc, tyAlias, tyInferred, tySink, tyOwned}
|
||||
abstractInst* = {tyGenericInst, tyDistinct, tyOrdinal, tyTypeDesc, tyAlias,
|
||||
tyInferred, tySink}
|
||||
tyInferred, tySink, tyOwned}
|
||||
abstractInstOwned* = abstractInst + {tyOwned}
|
||||
skipPtrs* = {tyVar, tyPtr, tyRef, tyGenericInst, tyTypeDesc, tyAlias,
|
||||
tyInferred, tySink, tyLent, tyOwned}
|
||||
|
||||
Reference in New Issue
Block a user