refactoring: use the new strings and seqs when optSeqDestructors is active
This commit is contained in:
parent
61ea85687c
commit
ed2fb36bc6
9 changed files with 45 additions and 66 deletions
|
|
@ -79,7 +79,7 @@ proc genLiteral(p: BProc, n: PNode, ty: PType): Rope =
|
||||||
# with the new semantics for 'nil' strings, we can map "" to nil and
|
# with the new semantics for 'nil' strings, we can map "" to nil and
|
||||||
# save tons of allocations:
|
# save tons of allocations:
|
||||||
if n.strVal.len == 0 and optNilSeqs notin p.options and
|
if n.strVal.len == 0 and optNilSeqs notin p.options and
|
||||||
p.config.selectedGC != gcDestructors:
|
optSeqDestructors notin p.config.globalOptions:
|
||||||
result = genNilStringLiteral(p.module, n.info)
|
result = genNilStringLiteral(p.module, n.info)
|
||||||
else:
|
else:
|
||||||
result = genStringLiteral(p.module, n)
|
result = genStringLiteral(p.module, n)
|
||||||
|
|
@ -250,7 +250,7 @@ proc genGenericAsgn(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
# tfShallow flag for the built-in string type too! So we check only
|
# tfShallow flag for the built-in string type too! So we check only
|
||||||
# here for this flag, where it is reasonably safe to do so
|
# here for this flag, where it is reasonably safe to do so
|
||||||
# (for objects, etc.):
|
# (for objects, etc.):
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
linefmt(p, cpsStmts,
|
linefmt(p, cpsStmts,
|
||||||
"$1 = $2;$n",
|
"$1 = $2;$n",
|
||||||
[rdLoc(dest), rdLoc(src)])
|
[rdLoc(dest), rdLoc(src)])
|
||||||
|
|
@ -279,7 +279,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
of tyRef:
|
of tyRef:
|
||||||
genRefAssign(p, dest, src)
|
genRefAssign(p, dest, src)
|
||||||
of tySequence:
|
of tySequence:
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
genGenericAsgn(p, dest, src, flags)
|
genGenericAsgn(p, dest, src, flags)
|
||||||
elif (needToCopy notin flags and src.storage != OnStatic) or canMove(p, src.lode, dest):
|
elif (needToCopy notin flags and src.storage != OnStatic) or canMove(p, src.lode, dest):
|
||||||
genRefAssign(p, dest, src)
|
genRefAssign(p, dest, src)
|
||||||
|
|
@ -288,7 +288,7 @@ proc genAssignment(p: BProc, dest, src: TLoc, flags: TAssignmentFlags) =
|
||||||
[addrLoc(p.config, dest), rdLoc(src),
|
[addrLoc(p.config, dest), rdLoc(src),
|
||||||
genTypeInfo(p.module, dest.t, dest.lode.info)])
|
genTypeInfo(p.module, dest.t, dest.lode.info)])
|
||||||
of tyString:
|
of tyString:
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
genGenericAsgn(p, dest, src, flags)
|
genGenericAsgn(p, dest, src, flags)
|
||||||
elif (needToCopy notin flags and src.storage != OnStatic) or canMove(p, src.lode, dest):
|
elif (needToCopy notin flags and src.storage != OnStatic) or canMove(p, src.lode, dest):
|
||||||
genRefAssign(p, dest, src)
|
genRefAssign(p, dest, src)
|
||||||
|
|
@ -934,7 +934,7 @@ proc genSeqElem(p: BProc, n, x, y: PNode, d: var TLoc) =
|
||||||
a.r = ropecg(p.module, "(*$1)", [a.r])
|
a.r = ropecg(p.module, "(*$1)", [a.r])
|
||||||
|
|
||||||
if lfPrepareForMutation in d.flags and ty.kind == tyString and
|
if lfPrepareForMutation in d.flags and ty.kind == tyString and
|
||||||
p.config.selectedGC == gcDestructors:
|
optSeqDestructors in p.config.globalOptions:
|
||||||
linefmt(p, cpsStmts, "#nimPrepareStrMutationV2($1);$n", [byRefLoc(p, a)])
|
linefmt(p, cpsStmts, "#nimPrepareStrMutationV2($1);$n", [byRefLoc(p, a)])
|
||||||
putIntoDest(p, d, n,
|
putIntoDest(p, d, n,
|
||||||
ropecg(p.module, "$1$3[$2]", [rdLoc(a), rdCharLoc(b), dataField(p)]), a.storage)
|
ropecg(p.module, "$1$3[$2]", [rdLoc(a), rdCharLoc(b), dataField(p)]), a.storage)
|
||||||
|
|
@ -1060,7 +1060,7 @@ proc gcUsage(conf: ConfigRef; n: PNode) =
|
||||||
if conf.selectedGC == gcNone: message(conf, n.info, warnGcMem, n.renderTree)
|
if conf.selectedGC == gcNone: message(conf, n.info, warnGcMem, n.renderTree)
|
||||||
|
|
||||||
proc strLoc(p: BProc; d: TLoc): Rope =
|
proc strLoc(p: BProc; d: TLoc): Rope =
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
result = byRefLoc(p, d)
|
result = byRefLoc(p, d)
|
||||||
else:
|
else:
|
||||||
result = rdLoc(d)
|
result = rdLoc(d)
|
||||||
|
|
@ -1141,7 +1141,7 @@ proc genStrAppend(p: BProc, e: PNode, d: var TLoc) =
|
||||||
add(lens, " + ")
|
add(lens, " + ")
|
||||||
add(appends, ropecg(p.module, "#appendString($1, $2);$n",
|
add(appends, ropecg(p.module, "#appendString($1, $2);$n",
|
||||||
[strLoc(p, dest), rdLoc(a)]))
|
[strLoc(p, dest), rdLoc(a)]))
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
linefmt(p, cpsStmts, "#prepareAdd($1, $2$3);$n",
|
linefmt(p, cpsStmts, "#prepareAdd($1, $2$3);$n",
|
||||||
[byRefLoc(p, dest), lens, L])
|
[byRefLoc(p, dest), lens, L])
|
||||||
else:
|
else:
|
||||||
|
|
@ -1288,7 +1288,7 @@ proc genNewSeq(p: BProc, e: PNode) =
|
||||||
var a, b: TLoc
|
var a, b: TLoc
|
||||||
initLocExpr(p, e.sons[1], a)
|
initLocExpr(p, e.sons[1], a)
|
||||||
initLocExpr(p, e.sons[2], b)
|
initLocExpr(p, e.sons[2], b)
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
let seqtype = skipTypes(e.sons[1].typ, abstractVarRange)
|
let seqtype = skipTypes(e.sons[1].typ, abstractVarRange)
|
||||||
linefmt(p, cpsStmts, "$1.len = $2; $1.p = ($4*) #newSeqPayload($2, sizeof($3));$n",
|
linefmt(p, cpsStmts, "$1.len = $2; $1.p = ($4*) #newSeqPayload($2, sizeof($3));$n",
|
||||||
[a.rdLoc, b.rdLoc, getTypeDesc(p.module, seqtype.lastSon),
|
[a.rdLoc, b.rdLoc, getTypeDesc(p.module, seqtype.lastSon),
|
||||||
|
|
@ -1303,7 +1303,7 @@ proc genNewSeqOfCap(p: BProc; e: PNode; d: var TLoc) =
|
||||||
let seqtype = skipTypes(e.typ, abstractVarRange)
|
let seqtype = skipTypes(e.typ, abstractVarRange)
|
||||||
var a: TLoc
|
var a: TLoc
|
||||||
initLocExpr(p, e.sons[1], a)
|
initLocExpr(p, e.sons[1], a)
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
if d.k == locNone: getTemp(p, e.typ, d, needsInit=false)
|
if d.k == locNone: getTemp(p, e.typ, d, needsInit=false)
|
||||||
linefmt(p, cpsStmts, "$1.len = 0; $1.p = ($4*) #newSeqPayload($2, sizeof($3));$n",
|
linefmt(p, cpsStmts, "$1.len = 0; $1.p = ($4*) #newSeqPayload($2, sizeof($3));$n",
|
||||||
[d.rdLoc, a.rdLoc, getTypeDesc(p.module, seqtype.lastSon),
|
[d.rdLoc, a.rdLoc, getTypeDesc(p.module, seqtype.lastSon),
|
||||||
|
|
@ -1403,7 +1403,7 @@ proc genSeqConstr(p: BProc, n: PNode, d: var TLoc) =
|
||||||
getTemp(p, n.typ, d)
|
getTemp(p, n.typ, d)
|
||||||
|
|
||||||
let l = intLiteral(len(n))
|
let l = intLiteral(len(n))
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
let seqtype = n.typ
|
let seqtype = n.typ
|
||||||
linefmt(p, cpsStmts, "$1.len = $2; $1.p = ($4*) #newSeqPayload($2, sizeof($3));$n",
|
linefmt(p, cpsStmts, "$1.len = $2; $1.p = ($4*) #newSeqPayload($2, sizeof($3));$n",
|
||||||
[rdLoc dest[], l, getTypeDesc(p.module, seqtype.lastSon),
|
[rdLoc dest[], l, getTypeDesc(p.module, seqtype.lastSon),
|
||||||
|
|
@ -1434,7 +1434,7 @@ proc genArrToSeq(p: BProc, n: PNode, d: var TLoc) =
|
||||||
getTemp(p, n.typ, d)
|
getTemp(p, n.typ, d)
|
||||||
# generate call to newSeq before adding the elements per hand:
|
# generate call to newSeq before adding the elements per hand:
|
||||||
let L = toInt(lengthOrd(p.config, n.sons[1].typ))
|
let L = toInt(lengthOrd(p.config, n.sons[1].typ))
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
let seqtype = n.typ
|
let seqtype = n.typ
|
||||||
linefmt(p, cpsStmts, "$1.len = $2; $1.p = ($4*) #newSeqPayload($2, sizeof($3));$n",
|
linefmt(p, cpsStmts, "$1.len = $2; $1.p = ($4*) #newSeqPayload($2, sizeof($3));$n",
|
||||||
[rdLoc d, L, getTypeDesc(p.module, seqtype.lastSon),
|
[rdLoc d, L, getTypeDesc(p.module, seqtype.lastSon),
|
||||||
|
|
@ -1654,7 +1654,7 @@ proc makeAddr(n: PNode): PNode =
|
||||||
result.typ = makePtrType(n.typ)
|
result.typ = makePtrType(n.typ)
|
||||||
|
|
||||||
proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
|
proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
e.sons[1] = makeAddr(e[1])
|
e.sons[1] = makeAddr(e[1])
|
||||||
genCall(p, e, d)
|
genCall(p, e, d)
|
||||||
return
|
return
|
||||||
|
|
@ -1683,7 +1683,7 @@ proc genSetLengthSeq(p: BProc, e: PNode, d: var TLoc) =
|
||||||
gcUsage(p.config, e)
|
gcUsage(p.config, e)
|
||||||
|
|
||||||
proc genSetLengthStr(p: BProc, e: PNode, d: var TLoc) =
|
proc genSetLengthStr(p: BProc, e: PNode, d: var TLoc) =
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
binaryStmtAddr(p, e, d, "setLengthStrV2")
|
binaryStmtAddr(p, e, d, "setLengthStrV2")
|
||||||
else:
|
else:
|
||||||
var a, b, call: TLoc
|
var a, b, call: TLoc
|
||||||
|
|
@ -1897,7 +1897,7 @@ proc genSomeCast(p: BProc, e: PNode, d: var TLoc) =
|
||||||
if srcTyp.kind in {tyPtr, tyPointer} and etyp.kind in IntegralTypes:
|
if srcTyp.kind in {tyPtr, tyPointer} and etyp.kind in IntegralTypes:
|
||||||
putIntoDest(p, d, e, "(($1) (ptrdiff_t) ($2))" %
|
putIntoDest(p, d, e, "(($1) (ptrdiff_t) ($2))" %
|
||||||
[getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.storage)
|
[getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.storage)
|
||||||
elif p.config.selectedGC == gcDestructors and etyp.kind in {tySequence, tyString}:
|
elif optSeqDestructors in p.config.globalOptions and etyp.kind in {tySequence, tyString}:
|
||||||
putIntoDest(p, d, e, "(*($1*) (&$2))" %
|
putIntoDest(p, d, e, "(*($1*) (&$2))" %
|
||||||
[getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.storage)
|
[getTypeDesc(p.module, e.typ), rdCharLoc(a)], a.storage)
|
||||||
else:
|
else:
|
||||||
|
|
@ -2025,7 +2025,7 @@ proc genMove(p: BProc; n: PNode; d: var TLoc) =
|
||||||
resetLoc(p, a)
|
resetLoc(p, a)
|
||||||
|
|
||||||
proc genDestroy(p: BProc; n: PNode) =
|
proc genDestroy(p: BProc; n: PNode) =
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
let arg = n[1].skipAddr
|
let arg = n[1].skipAddr
|
||||||
let t = arg.typ.skipTypes(abstractInst)
|
let t = arg.typ.skipTypes(abstractInst)
|
||||||
case t.kind
|
case t.kind
|
||||||
|
|
@ -2120,7 +2120,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
|
|
||||||
of mConStrStr: genStrConcat(p, e, d)
|
of mConStrStr: genStrConcat(p, e, d)
|
||||||
of mAppendStrCh:
|
of mAppendStrCh:
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
binaryStmtAddr(p, e, d, "nimAddCharV1")
|
binaryStmtAddr(p, e, d, "nimAddCharV1")
|
||||||
else:
|
else:
|
||||||
var dest, b, call: TLoc
|
var dest, b, call: TLoc
|
||||||
|
|
@ -2131,7 +2131,7 @@ proc genMagicExpr(p: BProc, e: PNode, d: var TLoc, op: TMagic) =
|
||||||
genAssignment(p, dest, call, {})
|
genAssignment(p, dest, call, {})
|
||||||
of mAppendStrStr: genStrAppend(p, e, d)
|
of mAppendStrStr: genStrAppend(p, e, d)
|
||||||
of mAppendSeqElem:
|
of mAppendSeqElem:
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
e.sons[1] = makeAddr(e[1])
|
e.sons[1] = makeAddr(e[1])
|
||||||
genCall(p, e, d)
|
genCall(p, e, d)
|
||||||
else:
|
else:
|
||||||
|
|
@ -2713,7 +2713,7 @@ proc getDefaultValue(p: BProc; typ: PType; info: TLineInfo): Rope =
|
||||||
tyTyped, tyTypeDesc, tyStatic, tyRef, tyNil:
|
tyTyped, tyTypeDesc, tyStatic, tyRef, tyNil:
|
||||||
result = rope"NIM_NIL"
|
result = rope"NIM_NIL"
|
||||||
of tyString, tySequence:
|
of tyString, tySequence:
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
result = rope"{0, NIM_NIL}"
|
result = rope"{0, NIM_NIL}"
|
||||||
else:
|
else:
|
||||||
result = rope"NIM_NIL"
|
result = rope"NIM_NIL"
|
||||||
|
|
@ -2855,7 +2855,7 @@ proc genConstExpr(p: BProc, n: PNode): Rope =
|
||||||
of nkBracket, nkPar, nkTupleConstr, nkClosure:
|
of nkBracket, nkPar, nkTupleConstr, nkClosure:
|
||||||
var t = skipTypes(n.typ, abstractInstOwned)
|
var t = skipTypes(n.typ, abstractInstOwned)
|
||||||
if t.kind == tySequence:
|
if t.kind == tySequence:
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
result = genConstSeqV2(p, n, n.typ)
|
result = genConstSeqV2(p, n, n.typ)
|
||||||
else:
|
else:
|
||||||
result = genConstSeq(p, n, n.typ)
|
result = genConstSeq(p, n, n.typ)
|
||||||
|
|
@ -2879,7 +2879,7 @@ proc genConstExpr(p: BProc, n: PNode): Rope =
|
||||||
of nkObjConstr:
|
of nkObjConstr:
|
||||||
result = genConstObjConstr(p, n)
|
result = genConstObjConstr(p, n)
|
||||||
of nkStrLit..nkTripleStrLit:
|
of nkStrLit..nkTripleStrLit:
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
result = genStringLiteralV2Const(p.module, n)
|
result = genStringLiteralV2Const(p.module, n)
|
||||||
else:
|
else:
|
||||||
var d: TLoc
|
var d: TLoc
|
||||||
|
|
|
||||||
|
|
@ -356,7 +356,7 @@ proc addForwardStructFormat(m: BModule, structOrUnion: Rope, typename: Rope) =
|
||||||
m.s[cfsForwardTypes].addf "typedef $1 $2 $2;$n", [structOrUnion, typename]
|
m.s[cfsForwardTypes].addf "typedef $1 $2 $2;$n", [structOrUnion, typename]
|
||||||
|
|
||||||
proc seqStar(m: BModule): string =
|
proc seqStar(m: BModule): string =
|
||||||
if m.config.selectedGC == gcDestructors: result = ""
|
if optSeqDestructors in m.config.globalOptions: result = ""
|
||||||
else: result = "*"
|
else: result = "*"
|
||||||
|
|
||||||
proc getTypeForward(m: BModule, typ: PType; sig: SigHash): Rope =
|
proc getTypeForward(m: BModule, typ: PType; sig: SigHash): Rope =
|
||||||
|
|
@ -390,7 +390,7 @@ proc getTypeDescWeak(m: BModule; t: PType; check: var IntSet): Rope =
|
||||||
pushType(m, t)
|
pushType(m, t)
|
||||||
of tySequence:
|
of tySequence:
|
||||||
let sig = hashType(t)
|
let sig = hashType(t)
|
||||||
if m.config.selectedGC == gcDestructors:
|
if optSeqDestructors in m.config.globalOptions:
|
||||||
if skipTypes(etB.sons[0], typedescInst).kind == tyEmpty:
|
if skipTypes(etB.sons[0], typedescInst).kind == tyEmpty:
|
||||||
internalError(m.config, "cannot map the empty seq type to a C type")
|
internalError(m.config, "cannot map the empty seq type to a C type")
|
||||||
|
|
||||||
|
|
@ -710,7 +710,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
|
||||||
result = name & star
|
result = name & star
|
||||||
m.typeCache[sig] = result
|
m.typeCache[sig] = result
|
||||||
of tySequence:
|
of tySequence:
|
||||||
if m.config.selectedGC == gcDestructors:
|
if optSeqDestructors in m.config.globalOptions:
|
||||||
result = getTypeDescWeak(m, et, check) & star
|
result = getTypeDescWeak(m, et, check) & star
|
||||||
m.typeCache[sig] = result
|
m.typeCache[sig] = result
|
||||||
else:
|
else:
|
||||||
|
|
@ -770,7 +770,7 @@ proc getTypeDescAux(m: BModule, origTyp: PType, check: var IntSet): Rope =
|
||||||
"void* ClE_0;$n} $1;$n",
|
"void* ClE_0;$n} $1;$n",
|
||||||
[result, rettype, desc])
|
[result, rettype, desc])
|
||||||
of tySequence:
|
of tySequence:
|
||||||
if m.config.selectedGC == gcDestructors:
|
if optSeqDestructors in m.config.globalOptions:
|
||||||
result = getTypeDescWeak(m, t, check)
|
result = getTypeDescWeak(m, t, check)
|
||||||
else:
|
else:
|
||||||
# we cannot use getTypeForward here because then t would be associated
|
# we cannot use getTypeForward here because then t would be associated
|
||||||
|
|
@ -926,7 +926,7 @@ proc finishTypeDescriptions(m: BModule) =
|
||||||
var check = initIntSet()
|
var check = initIntSet()
|
||||||
while i < len(m.typeStack):
|
while i < len(m.typeStack):
|
||||||
let t = m.typeStack[i]
|
let t = m.typeStack[i]
|
||||||
if m.config.selectedGC == gcDestructors and t.skipTypes(abstractInst).kind == tySequence:
|
if optSeqDestructors in m.config.globalOptions and t.skipTypes(abstractInst).kind == tySequence:
|
||||||
seqV2ContentType(m, t, check)
|
seqV2ContentType(m, t, check)
|
||||||
else:
|
else:
|
||||||
discard getTypeDescAux(m, t, check)
|
discard getTypeDescAux(m, t, check)
|
||||||
|
|
@ -1351,7 +1351,7 @@ proc genTypeInfo(m: BModule, t: PType; info: TLineInfo): Rope =
|
||||||
genTupleInfo(m, x, x, result, info)
|
genTupleInfo(m, x, x, result, info)
|
||||||
of tySequence:
|
of tySequence:
|
||||||
genTypeInfoAux(m, t, t, result, info)
|
genTypeInfoAux(m, t, t, result, info)
|
||||||
if m.config.selectedGC != gcDestructors:
|
if optSeqDestructors notin m.config.globalOptions:
|
||||||
if m.config.selectedGC >= gcMarkAndSweep:
|
if m.config.selectedGC >= gcMarkAndSweep:
|
||||||
let markerProc = genTraverseProc(m, origType, sig)
|
let markerProc = genTraverseProc(m, origType, sig)
|
||||||
addf(m.s[cfsTypeInit3], "$1.marker = $2;$n", [tiNameForHcr(m, result), markerProc])
|
addf(m.s[cfsTypeInit3], "$1.marker = $2;$n", [tiNameForHcr(m, result), markerProc])
|
||||||
|
|
|
||||||
|
|
@ -293,13 +293,13 @@ proc lenField(p: BProc): Rope =
|
||||||
result = rope(if p.module.compileToCpp: "len" else: "Sup.len")
|
result = rope(if p.module.compileToCpp: "len" else: "Sup.len")
|
||||||
|
|
||||||
proc lenExpr(p: BProc; a: TLoc): Rope =
|
proc lenExpr(p: BProc; a: TLoc): Rope =
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
result = rdLoc(a) & ".len"
|
result = rdLoc(a) & ".len"
|
||||||
else:
|
else:
|
||||||
result = "($1 ? $1->$2 : 0)" % [rdLoc(a), lenField(p)]
|
result = "($1 ? $1->$2 : 0)" % [rdLoc(a), lenField(p)]
|
||||||
|
|
||||||
proc dataField(p: BProc): Rope =
|
proc dataField(p: BProc): Rope =
|
||||||
if p.config.selectedGC == gcDestructors:
|
if optSeqDestructors in p.config.globalOptions:
|
||||||
result = rope".p->data"
|
result = rope".p->data"
|
||||||
else:
|
else:
|
||||||
result = rope"->data"
|
result = rope"->data"
|
||||||
|
|
@ -377,10 +377,10 @@ proc isComplexValueType(t: PType): bool {.inline.} =
|
||||||
(t.kind == tyProc and t.callConv == ccClosure)
|
(t.kind == tyProc and t.callConv == ccClosure)
|
||||||
|
|
||||||
proc resetLoc(p: BProc, loc: var TLoc) =
|
proc resetLoc(p: BProc, loc: var TLoc) =
|
||||||
let containsGcRef = p.config.selectedGC != gcDestructors and containsGarbageCollectedRef(loc.t)
|
let containsGcRef = optSeqDestructors notin p.config.globalOptions and containsGarbageCollectedRef(loc.t)
|
||||||
let typ = skipTypes(loc.t, abstractVarRange)
|
let typ = skipTypes(loc.t, abstractVarRange)
|
||||||
if isImportedCppType(typ): return
|
if isImportedCppType(typ): return
|
||||||
if p.config.selectedGC == gcDestructors and typ.kind in {tyString, tySequence}:
|
if optSeqDestructors in p.config.globalOptions and typ.kind in {tyString, tySequence}:
|
||||||
assert rdLoc(loc) != nil
|
assert rdLoc(loc) != nil
|
||||||
linefmt(p, cpsStmts, "$1.len = 0; $1.p = NIM_NIL;$n", [rdLoc(loc)])
|
linefmt(p, cpsStmts, "$1.len = 0; $1.p = NIM_NIL;$n", [rdLoc(loc)])
|
||||||
elif not isComplexValueType(typ):
|
elif not isComplexValueType(typ):
|
||||||
|
|
@ -411,7 +411,7 @@ proc resetLoc(p: BProc, loc: var TLoc) =
|
||||||
|
|
||||||
proc constructLoc(p: BProc, loc: TLoc, isTemp = false) =
|
proc constructLoc(p: BProc, loc: TLoc, isTemp = false) =
|
||||||
let typ = loc.t
|
let typ = loc.t
|
||||||
if p.config.selectedGC == gcDestructors and skipTypes(typ, abstractInst).kind in {tyString, tySequence}:
|
if optSeqDestructors in p.config.globalOptions and skipTypes(typ, abstractInst).kind in {tyString, tySequence}:
|
||||||
linefmt(p, cpsStmts, "$1.len = 0; $1.p = NIM_NIL;$n", [rdLoc(loc)])
|
linefmt(p, cpsStmts, "$1.len = 0; $1.p = NIM_NIL;$n", [rdLoc(loc)])
|
||||||
elif not isComplexValueType(typ):
|
elif not isComplexValueType(typ):
|
||||||
linefmt(p, cpsStmts, "$1 = ($2)0;$n", [rdLoc(loc),
|
linefmt(p, cpsStmts, "$1 = ($2)0;$n", [rdLoc(loc),
|
||||||
|
|
|
||||||
|
|
@ -452,6 +452,7 @@ proc processSwitch*(switch, arg: string, pass: TCmdLinePass, info: TLineInfo;
|
||||||
of "destructors":
|
of "destructors":
|
||||||
conf.selectedGC = gcDestructors
|
conf.selectedGC = gcDestructors
|
||||||
defineSymbol(conf.symbols, "gcdestructors")
|
defineSymbol(conf.symbols, "gcdestructors")
|
||||||
|
incl conf.globalOptions, optSeqDestructors
|
||||||
of "go":
|
of "go":
|
||||||
conf.selectedGC = gcGo
|
conf.selectedGC = gcGo
|
||||||
defineSymbol(conf.symbols, "gogc")
|
defineSymbol(conf.symbols, "gogc")
|
||||||
|
|
|
||||||
|
|
@ -342,9 +342,9 @@ proc createUpField(c: var DetectionPass; dest, dep: PSym; info: TLineInfo) =
|
||||||
let obj = refObj.skipTypes({tyOwned, tyRef})
|
let obj = refObj.skipTypes({tyOwned, tyRef})
|
||||||
# The assumption here is that gcDestructors means we cannot deal
|
# The assumption here is that gcDestructors means we cannot deal
|
||||||
# with cycles properly, so it's better to produce a weak ref (=ptr) here.
|
# with cycles properly, so it's better to produce a weak ref (=ptr) here.
|
||||||
# This seems to be generally correct but since it's a bit risky it's only
|
# This seems to be generally correct but since it's a bit risky it's disabled
|
||||||
# enabled for gcDestructors.
|
# for now.
|
||||||
let fieldType = if false: # c.graph.config.selectedGC == gcDestructors:
|
let fieldType = if false: # optSeqDestructors in c.graph.config.globalOptions:
|
||||||
c.getEnvTypeForOwnerUp(dep, info) #getHiddenParam(dep).typ
|
c.getEnvTypeForOwnerUp(dep, info) #getHiddenParam(dep).typ
|
||||||
else:
|
else:
|
||||||
c.getEnvTypeForOwner(dep, info)
|
c.getEnvTypeForOwner(dep, info)
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ proc newDeepCopyCall(op: PSym; x, y: PNode): PNode =
|
||||||
result = newAsgnStmt(x, newOpCall(op, y))
|
result = newAsgnStmt(x, newOpCall(op, y))
|
||||||
|
|
||||||
proc useNoGc(c: TLiftCtx; t: PType): bool {.inline.} =
|
proc useNoGc(c: TLiftCtx; t: PType): bool {.inline.} =
|
||||||
result = c.g.config.selectedGC == gcDestructors and
|
result = optSeqDestructors in c.g.config.globalOptions and
|
||||||
({tfHasGCedMem, tfHasOwned} * t.flags != {} or t.isGCedMem)
|
({tfHasGCedMem, tfHasOwned} * t.flags != {} or t.isGCedMem)
|
||||||
|
|
||||||
proc instantiateGeneric(c: var TLiftCtx; op: PSym; t, typeInst: PType): PSym =
|
proc instantiateGeneric(c: var TLiftCtx; op: PSym; t, typeInst: PType): PSym =
|
||||||
|
|
@ -142,7 +142,7 @@ proc instantiateGeneric(c: var TLiftCtx; op: PSym; t, typeInst: PType): PSym =
|
||||||
|
|
||||||
proc considerAsgnOrSink(c: var TLiftCtx; t: PType; body, x, y: PNode;
|
proc considerAsgnOrSink(c: var TLiftCtx; t: PType; body, x, y: PNode;
|
||||||
field: var PSym): bool =
|
field: var PSym): bool =
|
||||||
if c.g.config.selectedGC == gcDestructors:
|
if optSeqDestructors in c.g.config.globalOptions:
|
||||||
let op = field
|
let op = field
|
||||||
if field != nil and sfOverriden in field.flags:
|
if field != nil and sfOverriden in field.flags:
|
||||||
if sfError in op.flags:
|
if sfError in op.flags:
|
||||||
|
|
@ -488,7 +488,7 @@ proc fillBody(c: var TLiftCtx; t: PType; body, x, y: PNode) =
|
||||||
of tySequence:
|
of tySequence:
|
||||||
if useNoGc(c, t):
|
if useNoGc(c, t):
|
||||||
useSeqOrStrOp(c, t, body, x, y)
|
useSeqOrStrOp(c, t, body, x, y)
|
||||||
elif c.g.config.selectedGC == gcDestructors:
|
elif optSeqDestructors in c.g.config.globalOptions:
|
||||||
# note that tfHasAsgn is propagated so we need the check on
|
# note that tfHasAsgn is propagated so we need the check on
|
||||||
# 'selectedGC' here to determine if we have the new runtime.
|
# 'selectedGC' here to determine if we have the new runtime.
|
||||||
discard considerUserDefinedOp(c, t, body, x, y)
|
discard considerUserDefinedOp(c, t, body, x, y)
|
||||||
|
|
|
||||||
|
|
@ -1668,25 +1668,8 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||||
of mSet: result = semSet(c, n, prev)
|
of mSet: result = semSet(c, n, prev)
|
||||||
of mOrdinal: result = semOrdinal(c, n, prev)
|
of mOrdinal: result = semOrdinal(c, n, prev)
|
||||||
of mSeq:
|
of mSeq:
|
||||||
if false: # c.config.selectedGC == gcDestructors and optNimV2 notin c.config.globalOptions:
|
|
||||||
let s = c.graph.sysTypes[tySequence]
|
|
||||||
assert s != nil
|
|
||||||
assert prev == nil
|
|
||||||
result = copyType(s, s.owner, keepId=false)
|
|
||||||
# Remove the 'T' parameter from tySequence:
|
|
||||||
result.sons.setLen 0
|
|
||||||
result.n = nil
|
|
||||||
result.flags = {tfHasAsgn}
|
|
||||||
semContainerArg(c, n, "seq", result)
|
|
||||||
if result.len > 0:
|
|
||||||
var base = result[0]
|
|
||||||
if base.kind in {tyGenericInst, tyAlias, tySink}: base = lastSon(base)
|
|
||||||
if not containsGenericType(base):
|
|
||||||
# base.kind != tyGenericParam:
|
|
||||||
c.typesWithOps.add((result, result))
|
|
||||||
else:
|
|
||||||
result = semContainer(c, n, tySequence, "seq", prev)
|
result = semContainer(c, n, tySequence, "seq", prev)
|
||||||
if c.config.selectedGC == gcDestructors:
|
if optSeqDestructors in c.config.globalOptions:
|
||||||
incl result.flags, tfHasAsgn
|
incl result.flags, tfHasAsgn
|
||||||
of mOpt: result = semContainer(c, n, tyOpt, "opt", prev)
|
of mOpt: result = semContainer(c, n, tyOpt, "opt", prev)
|
||||||
of mVarargs: result = semVarargs(c, n, prev)
|
of mVarargs: result = semVarargs(c, n, prev)
|
||||||
|
|
@ -1862,7 +1845,7 @@ proc processMagicType(c: PContext, m: PSym) =
|
||||||
of mString:
|
of mString:
|
||||||
setMagicType(c.config, m, tyString, szUncomputedSize)
|
setMagicType(c.config, m, tyString, szUncomputedSize)
|
||||||
rawAddSon(m.typ, getSysType(c.graph, m.info, tyChar))
|
rawAddSon(m.typ, getSysType(c.graph, m.info, tyChar))
|
||||||
if c.config.selectedGC == gcDestructors:
|
if optSeqDestructors in c.config.globalOptions:
|
||||||
incl m.typ.flags, tfHasAsgn
|
incl m.typ.flags, tfHasAsgn
|
||||||
of mCstring:
|
of mCstring:
|
||||||
setMagicIntegral(c.config, m, tyCString, c.config.target.ptrSize)
|
setMagicIntegral(c.config, m, tyCString, c.config.target.ptrSize)
|
||||||
|
|
@ -1903,7 +1886,7 @@ proc processMagicType(c: PContext, m: PSym) =
|
||||||
setMagicIntegral(c.config, m, tyUncheckedArray, szUncomputedSize)
|
setMagicIntegral(c.config, m, tyUncheckedArray, szUncomputedSize)
|
||||||
of mSeq:
|
of mSeq:
|
||||||
setMagicType(c.config, m, tySequence, szUncomputedSize)
|
setMagicType(c.config, m, tySequence, szUncomputedSize)
|
||||||
if c.config.selectedGC == gcDestructors:
|
if optSeqDestructors in c.config.globalOptions:
|
||||||
incl m.typ.flags, tfHasAsgn
|
incl m.typ.flags, tfHasAsgn
|
||||||
assert c.graph.sysTypes[tySequence] == nil
|
assert c.graph.sysTypes[tySequence] == nil
|
||||||
c.graph.sysTypes[tySequence] = m.typ
|
c.graph.sysTypes[tySequence] = m.typ
|
||||||
|
|
|
||||||
|
|
@ -2590,11 +2590,6 @@ proc instTypeBoundOp*(c: PContext; dc: PSym; t: PType; info: TLineInfo;
|
||||||
if f.kind in {tyRef, tyPtr}: f = f.lastSon
|
if f.kind in {tyRef, tyPtr}: f = f.lastSon
|
||||||
else:
|
else:
|
||||||
if f.kind == tyVar: f = f.lastSon
|
if f.kind == tyVar: f = f.lastSon
|
||||||
#if c.config.selectedGC == gcDestructors and f.kind == tySequence:
|
|
||||||
# use the canonical type to access the =sink and =destroy etc.
|
|
||||||
# f = c.graph.sysTypes[tySequence]
|
|
||||||
#echo "YUP_---------Formal ", typeToString(f, preferDesc), " real ", typeToString(t, preferDesc), " ", f.id, " ", t.id
|
|
||||||
|
|
||||||
if typeRel(m, f, t) == isNone:
|
if typeRel(m, f, t) == isNone:
|
||||||
localError(c.config, info, "cannot instantiate: '" & dc.name.s & "'")
|
localError(c.config, info, "cannot instantiate: '" & dc.name.s & "'")
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
|
|
@ -231,7 +231,7 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) =
|
||||||
typ.size = conf.target.ptrSize
|
typ.size = conf.target.ptrSize
|
||||||
typ.align = int16(conf.target.ptrSize)
|
typ.align = int16(conf.target.ptrSize)
|
||||||
of tyString:
|
of tyString:
|
||||||
if conf.selectedGC == gcDestructors:
|
if optSeqDestructors in conf.globalOptions:
|
||||||
typ.size = conf.target.ptrSize * 2
|
typ.size = conf.target.ptrSize * 2
|
||||||
else:
|
else:
|
||||||
typ.size = conf.target.ptrSize
|
typ.size = conf.target.ptrSize
|
||||||
|
|
@ -245,7 +245,7 @@ proc computeSizeAlign(conf: ConfigRef; typ: PType) =
|
||||||
typ.paddingAtEnd = szIllegalRecursion
|
typ.paddingAtEnd = szIllegalRecursion
|
||||||
return
|
return
|
||||||
typ.align = int16(conf.target.ptrSize)
|
typ.align = int16(conf.target.ptrSize)
|
||||||
if typ.kind == tySequence and conf.selectedGC == gcDestructors:
|
if typ.kind == tySequence and optSeqDestructors in conf.globalOptions:
|
||||||
typ.size = conf.target.ptrSize * 2
|
typ.size = conf.target.ptrSize * 2
|
||||||
else:
|
else:
|
||||||
typ.size = conf.target.ptrSize
|
typ.size = conf.target.ptrSize
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue