removed nimKeepAlive as it's not necessary with interior pointer checking
This commit is contained in:
parent
f58cc49672
commit
1d1752cac7
2 changed files with 20 additions and 51 deletions
|
|
@ -7,9 +7,6 @@
|
||||||
# distribution, for details about the copyright.
|
# distribution, for details about the copyright.
|
||||||
#
|
#
|
||||||
|
|
||||||
type
|
|
||||||
TAfterCallActions = tuple[p: BProc, actions: PRope]
|
|
||||||
|
|
||||||
proc leftAppearsOnRightSide(le, ri: PNode): bool =
|
proc leftAppearsOnRightSide(le, ri: PNode): bool =
|
||||||
if le != nil:
|
if le != nil:
|
||||||
for i in 1 .. <ri.len:
|
for i in 1 .. <ri.len:
|
||||||
|
|
@ -59,9 +56,6 @@ proc fixupCall(p: BProc, le, ri: PNode, d: var TLoc, pl: PRope) =
|
||||||
app(p.s[cpsStmts], pl)
|
app(p.s[cpsStmts], pl)
|
||||||
appf(p.s[cpsStmts], ";$n")
|
appf(p.s[cpsStmts], ";$n")
|
||||||
|
|
||||||
proc emitAfterCallActions(aca: TAfterCallActions) {.inline.} =
|
|
||||||
app(aca.p.s[cpsStmts], aca.actions)
|
|
||||||
|
|
||||||
proc isInCurrentFrame(p: BProc, n: PNode): bool =
|
proc isInCurrentFrame(p: BProc, n: PNode): bool =
|
||||||
# checks if `n` is an expression that refers to the current frame;
|
# checks if `n` is an expression that refers to the current frame;
|
||||||
# this does not work reliably because of forwarding + inlining can break it
|
# this does not work reliably because of forwarding + inlining can break it
|
||||||
|
|
@ -82,59 +76,48 @@ proc isInCurrentFrame(p: BProc, n: PNode): bool =
|
||||||
result = isInCurrentFrame(p, n.sons[0])
|
result = isInCurrentFrame(p, n.sons[0])
|
||||||
else: nil
|
else: nil
|
||||||
|
|
||||||
proc genKeepAlive(aca: var TAfterCallActions, n: PNode, a: TLoc) {.inline.} =
|
proc openArrayLoc(p: BProc, n: PNode): PRope =
|
||||||
if a.s == onStack and optRefcGC in gGlobalOptions:
|
|
||||||
aca.p.module.appcg(aca.actions,
|
|
||||||
"#nimKeepAlive((#TGenericSeq*)$1);$n", [a.rdLoc])
|
|
||||||
|
|
||||||
proc openArrayLoc(aca: var TAfterCallActions, n: PNode): PRope =
|
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
initLocExpr(aca.p, n, a)
|
initLocExpr(p, n, a)
|
||||||
case skipTypes(a.t, abstractVar).kind
|
case skipTypes(a.t, abstractVar).kind
|
||||||
of tyOpenArray:
|
of tyOpenArray:
|
||||||
result = ropef("$1, $1Len0", [rdLoc(a)])
|
result = ropef("$1, $1Len0", [rdLoc(a)])
|
||||||
of tyString, tySequence:
|
of tyString, tySequence:
|
||||||
result = ropef("$1->data, $1->$2", [a.rdLoc, lenField()])
|
result = ropef("$1->data, $1->$2", [a.rdLoc, lenField()])
|
||||||
genKeepAlive(aca, n, a)
|
|
||||||
of tyArray, tyArrayConstr:
|
of tyArray, tyArrayConstr:
|
||||||
result = ropef("$1, $2", [rdLoc(a), toRope(lengthOrd(a.t))])
|
result = ropef("$1, $2", [rdLoc(a), toRope(lengthOrd(a.t))])
|
||||||
else: InternalError("openArrayLoc: " & typeToString(a.t))
|
else: InternalError("openArrayLoc: " & typeToString(a.t))
|
||||||
|
|
||||||
proc genArgStringToCString(aca: var TAfterCallActions,
|
proc genArgStringToCString(p: BProc,
|
||||||
n: PNode): PRope {.inline.} =
|
n: PNode): PRope {.inline.} =
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
initLocExpr(aca.p, n.sons[0], a)
|
initLocExpr(p, n.sons[0], a)
|
||||||
result = ropef("$1->data", [a.rdLoc])
|
result = ropef("$1->data", [a.rdLoc])
|
||||||
# we don't guarantee save string->cstring conversions anyway, so we use
|
|
||||||
# an additional check to improve performance:
|
|
||||||
if isInCurrentFrame(aca.p, n): genKeepAlive(aca, n, a)
|
|
||||||
|
|
||||||
proc genArg(aca: var TAfterCallActions, n: PNode, param: PSym): PRope =
|
proc genArg(p: BProc, n: PNode, param: PSym): PRope =
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
if n.kind == nkStringToCString:
|
if n.kind == nkStringToCString:
|
||||||
result = genArgStringToCString(aca, n)
|
result = genArgStringToCString(p, n)
|
||||||
elif skipTypes(param.typ, abstractVar).kind == tyOpenArray:
|
elif skipTypes(param.typ, abstractVar).kind == tyOpenArray:
|
||||||
var n = if n.kind != nkHiddenAddr: n else: n.sons[0]
|
var n = if n.kind != nkHiddenAddr: n else: n.sons[0]
|
||||||
result = openArrayLoc(aca, n)
|
result = openArrayLoc(p, n)
|
||||||
elif ccgIntroducedPtr(param):
|
elif ccgIntroducedPtr(param):
|
||||||
initLocExpr(aca.p, n, a)
|
initLocExpr(p, n, a)
|
||||||
result = addrLoc(a)
|
result = addrLoc(a)
|
||||||
else:
|
else:
|
||||||
initLocExpr(aca.p, n, a)
|
initLocExpr(p, n, a)
|
||||||
result = rdLoc(a)
|
result = rdLoc(a)
|
||||||
|
|
||||||
proc genArgNoParam(aca: var TAfterCallActions, n: PNode): PRope =
|
proc genArgNoParam(p: BProc, n: PNode): PRope =
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
if n.kind == nkStringToCString:
|
if n.kind == nkStringToCString:
|
||||||
result = genArgStringToCString(aca, n)
|
result = genArgStringToCString(p, n)
|
||||||
else:
|
else:
|
||||||
initLocExpr(aca.p, n, a)
|
initLocExpr(p, n, a)
|
||||||
result = rdLoc(a)
|
result = rdLoc(a)
|
||||||
|
|
||||||
proc genPrefixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
proc genPrefixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
var op: TLoc
|
var op: TLoc
|
||||||
var aca: TAfterCallActions
|
|
||||||
aca.p = p
|
|
||||||
# this is a hotspot in the compiler
|
# this is a hotspot in the compiler
|
||||||
initLocExpr(p, ri.sons[0], op)
|
initLocExpr(p, ri.sons[0], op)
|
||||||
var pl = con(op.r, "(")
|
var pl = con(op.r, "(")
|
||||||
|
|
@ -145,17 +128,14 @@ proc genPrefixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
assert(sonsLen(typ) == sonsLen(typ.n))
|
assert(sonsLen(typ) == sonsLen(typ.n))
|
||||||
if i < sonsLen(typ):
|
if i < sonsLen(typ):
|
||||||
assert(typ.n.sons[i].kind == nkSym)
|
assert(typ.n.sons[i].kind == nkSym)
|
||||||
app(pl, genArg(aca, ri.sons[i], typ.n.sons[i].sym))
|
app(pl, genArg(p, ri.sons[i], typ.n.sons[i].sym))
|
||||||
else:
|
else:
|
||||||
app(pl, genArgNoParam(aca, ri.sons[i]))
|
app(pl, genArgNoParam(p, ri.sons[i]))
|
||||||
if i < length - 1: app(pl, ", ")
|
if i < length - 1: app(pl, ", ")
|
||||||
fixupCall(p, le, ri, d, pl)
|
fixupCall(p, le, ri, d, pl)
|
||||||
emitAfterCallActions(aca)
|
|
||||||
|
|
||||||
proc genInfixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
proc genInfixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
var op, a: TLoc
|
var op, a: TLoc
|
||||||
var aca: TAfterCallActions
|
|
||||||
aca.p = p
|
|
||||||
initLocExpr(p, ri.sons[0], op)
|
initLocExpr(p, ri.sons[0], op)
|
||||||
var pl: PRope = nil
|
var pl: PRope = nil
|
||||||
var typ = ri.sons[0].typ # getUniqueType() is too expensive here!
|
var typ = ri.sons[0].typ # getUniqueType() is too expensive here!
|
||||||
|
|
@ -164,7 +144,7 @@ proc genInfixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
assert(sonsLen(typ) == sonsLen(typ.n))
|
assert(sonsLen(typ) == sonsLen(typ.n))
|
||||||
|
|
||||||
var param = typ.n.sons[1].sym
|
var param = typ.n.sons[1].sym
|
||||||
app(pl, genArg(aca, ri.sons[1], param))
|
app(pl, genArg(p, ri.sons[1], param))
|
||||||
|
|
||||||
if skipTypes(param.typ, {tyGenericInst}).kind == tyPtr: app(pl, "->")
|
if skipTypes(param.typ, {tyGenericInst}).kind == tyPtr: app(pl, "->")
|
||||||
else: app(pl, ".")
|
else: app(pl, ".")
|
||||||
|
|
@ -174,18 +154,15 @@ proc genInfixCall(p: BProc, le, ri: PNode, d: var TLoc) =
|
||||||
assert(sonsLen(typ) == sonsLen(typ.n))
|
assert(sonsLen(typ) == sonsLen(typ.n))
|
||||||
if i < sonsLen(typ):
|
if i < sonsLen(typ):
|
||||||
assert(typ.n.sons[i].kind == nkSym)
|
assert(typ.n.sons[i].kind == nkSym)
|
||||||
app(pl, genArg(aca, ri.sons[i], typ.n.sons[i].sym))
|
app(pl, genArg(p, ri.sons[i], typ.n.sons[i].sym))
|
||||||
else:
|
else:
|
||||||
app(pl, genArgNoParam(aca, ri.sons[i]))
|
app(pl, genArgNoParam(p, ri.sons[i]))
|
||||||
if i < length - 1: app(pl, ", ")
|
if i < length - 1: app(pl, ", ")
|
||||||
fixupCall(p, le, ri, d, pl)
|
fixupCall(p, le, ri, d, pl)
|
||||||
emitAfterCallActions(aca)
|
|
||||||
|
|
||||||
proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
|
proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
|
||||||
# generates a crappy ObjC call
|
# generates a crappy ObjC call
|
||||||
var op, a: TLoc
|
var op, a: TLoc
|
||||||
var aca: TAfterCallActions
|
|
||||||
aca.p = p
|
|
||||||
initLocExpr(p, ri.sons[0], op)
|
initLocExpr(p, ri.sons[0], op)
|
||||||
var pl = toRope"["
|
var pl = toRope"["
|
||||||
var typ = ri.sons[0].typ # getUniqueType() is too expensive here!
|
var typ = ri.sons[0].typ # getUniqueType() is too expensive here!
|
||||||
|
|
@ -194,12 +171,12 @@ proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
|
||||||
assert(sonsLen(typ) == sonsLen(typ.n))
|
assert(sonsLen(typ) == sonsLen(typ.n))
|
||||||
|
|
||||||
if length > 1:
|
if length > 1:
|
||||||
app(pl, genArg(aca, ri.sons[1], typ.n.sons[1].sym))
|
app(pl, genArg(p, ri.sons[1], typ.n.sons[1].sym))
|
||||||
app(pl, " ")
|
app(pl, " ")
|
||||||
app(pl, op.r)
|
app(pl, op.r)
|
||||||
if length > 2:
|
if length > 2:
|
||||||
app(pl, ": ")
|
app(pl, ": ")
|
||||||
app(pl, genArg(aca, ri.sons[2], typ.n.sons[2].sym))
|
app(pl, genArg(p, ri.sons[2], typ.n.sons[2].sym))
|
||||||
for i in countup(3, length-1):
|
for i in countup(3, length-1):
|
||||||
assert(sonsLen(typ) == sonsLen(typ.n))
|
assert(sonsLen(typ) == sonsLen(typ.n))
|
||||||
if i >= sonsLen(typ):
|
if i >= sonsLen(typ):
|
||||||
|
|
@ -209,7 +186,7 @@ proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
|
||||||
app(pl, " ")
|
app(pl, " ")
|
||||||
app(pl, param.name.s)
|
app(pl, param.name.s)
|
||||||
app(pl, ": ")
|
app(pl, ": ")
|
||||||
app(pl, genArg(aca, ri.sons[i], param))
|
app(pl, genArg(p, ri.sons[i], param))
|
||||||
if typ.sons[0] != nil:
|
if typ.sons[0] != nil:
|
||||||
if isInvalidReturnType(typ.sons[0]):
|
if isInvalidReturnType(typ.sons[0]):
|
||||||
if sonsLen(ri) > 1: app(pl, " ")
|
if sonsLen(ri) > 1: app(pl, " ")
|
||||||
|
|
@ -242,7 +219,6 @@ proc genNamedParamCall(p: BProc, ri: PNode, d: var TLoc) =
|
||||||
app(pl, "]")
|
app(pl, "]")
|
||||||
app(p.s[cpsStmts], pl)
|
app(p.s[cpsStmts], pl)
|
||||||
appf(p.s[cpsStmts], ";$n")
|
appf(p.s[cpsStmts], ";$n")
|
||||||
emitAfterCallActions(aca)
|
|
||||||
|
|
||||||
proc genCall(p: BProc, e: PNode, d: var TLoc) =
|
proc genCall(p: BProc, e: PNode, d: var TLoc) =
|
||||||
if e.sons[0].kind == nkSym and sfInfixCall in e.sons[0].sym.flags and
|
if e.sons[0].kind == nkSym and sfInfixCall in e.sons[0].sym.flags and
|
||||||
|
|
|
||||||
|
|
@ -34,8 +34,6 @@ const
|
||||||
rcWhite = 0b010 # member of a garbage cycle
|
rcWhite = 0b010 # member of a garbage cycle
|
||||||
rcPurple = 0b011 # possible root of a cycle
|
rcPurple = 0b011 # possible root of a cycle
|
||||||
rcZct = 0b100 # in ZCT
|
rcZct = 0b100 # in ZCT
|
||||||
rcMarked = 0b101 # dummy write to keep C code generator from
|
|
||||||
# eliminating the root
|
|
||||||
rcRed = 0b101 # Candidate cycle undergoing sigma-computation
|
rcRed = 0b101 # Candidate cycle undergoing sigma-computation
|
||||||
rcOrange = 0b110 # Candidate cycle awaiting epoch boundary
|
rcOrange = 0b110 # Candidate cycle awaiting epoch boundary
|
||||||
rcShift = 3 # shift by rcShift to get the reference counter
|
rcShift = 3 # shift by rcShift to get the reference counter
|
||||||
|
|
@ -588,11 +586,6 @@ proc gcMark(gch: var TGcHeap, p: pointer) {.inline.} =
|
||||||
add(gch.decStack, cell)
|
add(gch.decStack, cell)
|
||||||
sysAssert(allocInv(gch.region), "gcMark end")
|
sysAssert(allocInv(gch.region), "gcMark end")
|
||||||
|
|
||||||
proc nimKeepAlive(p: PGenericSeq) {.compilerRtl, noinline.} =
|
|
||||||
var c = usrToCell(p)
|
|
||||||
if isAllocatedPtr(gch.region, c):
|
|
||||||
c.refcount = c.refcount or rcMarked
|
|
||||||
|
|
||||||
proc markThreadStacks(gch: var TGcHeap) =
|
proc markThreadStacks(gch: var TGcHeap) =
|
||||||
when hasThreadSupport and hasSharedHeap:
|
when hasThreadSupport and hasSharedHeap:
|
||||||
{.error: "not fully implemented".}
|
{.error: "not fully implemented".}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue