This commit is contained in:
Andreas Rumpf 2021-07-01 06:51:08 +02:00 • committed by GitHub
commit 41c29cb3a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 72 additions and 17 deletions

View file

@ -1057,7 +1057,7 @@ proc moveOrCopy(dest, ri: PNode; c: var Con; s: var Scope, isDecl = false): PNod
result = c.genCopy(dest, ri) result = c.genCopy(dest, ri)
result.add p(ri, c, s, consumed) result.add p(ri, c, s, consumed)
c.finishCopy(result, dest, isFromSink = false) c.finishCopy(result, dest, isFromSink = false)
of nkHiddenSubConv, nkHiddenStdConv, nkConv, nkObjDownConv, nkObjUpConv: of nkHiddenSubConv, nkHiddenStdConv, nkConv, nkObjDownConv, nkObjUpConv, nkCast:
result = c.genSink(dest, p(ri, c, s, sinkArg), isDecl) result = c.genSink(dest, p(ri, c, s, sinkArg), isDecl)
of nkStmtListExpr, nkBlockExpr, nkIfExpr, nkCaseStmt, nkTryStmt: of nkStmtListExpr, nkBlockExpr, nkIfExpr, nkCaseStmt, nkTryStmt:
template process(child, s): untyped = moveOrCopy(dest, child, c, s, isDecl) template process(child, s): untyped = moveOrCopy(dest, child, c, s, isDecl)

View file

@ -1,48 +1,81 @@
discard """ discard """
output: '''@[1] output: '''@[1]
@[116, 101, 115, 116] @[116, 101, 115, 116]
@[1953719668, 875770417]''' @[1953719668, 875770417]
destroying O1'''
cmd: '''nim c --gc:arc --expandArc:main --expandArc:main1 --expandArc:main2 --expandArc:main3 --hints:off --assertions:off $file''' cmd: '''nim c --gc:arc --expandArc:main --expandArc:main1 --expandArc:main2 --expandArc:main3 --hints:off --assertions:off $file'''
nimout: '''--expandArc: main nimout: '''--expandArc: main
var var
data data
:tmpD :tmpD
`=copy`(data, cast[string](encode(cast[seq[byte]]( :tmpD_1
:tmpD = newString(100) :tmpD_2
:tmpD)))) data =
`=destroy`(:tmpD) wasMoved(:tmpD)
`=destroy`(data) `=copy`(:tmpD, cast[string](
:tmpD_2 = encode(cast[seq[byte]](
:tmpD_1 = newString(100)
:tmpD_1))
:tmpD_2))
:tmpD
`=destroy`(:tmpD_2)
`=destroy_1`(:tmpD_1)
`=destroy_1`(data)
-- end of expandArc ------------------------ -- end of expandArc ------------------------
--expandArc: main1 --expandArc: main1
var var
s s
data data
:tmpD
:tmpD_1
s = newString(100) s = newString(100)
`=copy`(data, cast[string](encode(toOpenArrayByte(s, 0, len(s) - 1)))) data =
`=destroy`(data) wasMoved(:tmpD)
`=destroy`(s) `=copy`(:tmpD, cast[string](
:tmpD_1 = encode(toOpenArrayByte(s, 0, len(s) - 1))
:tmpD_1))
:tmpD
`=destroy`(:tmpD_1)
`=destroy_1`(data)
`=destroy_1`(s)
-- end of expandArc ------------------------ -- end of expandArc ------------------------
--expandArc: main2 --expandArc: main2
var var
s s
data data
:tmpD
:tmpD_1
s = newSeq(100) s = newSeq(100)
`=copy`(data, cast[string](encode(s))) data =
`=destroy`(data) wasMoved(:tmpD)
`=destroy_1`(s) `=copy`(:tmpD, cast[string](
:tmpD_1 = encode(s)
:tmpD_1))
:tmpD
`=destroy`(:tmpD_1)
`=destroy_1`(data)
`=destroy`(s)
-- end of expandArc ------------------------ -- end of expandArc ------------------------
--expandArc: main3 --expandArc: main3
var var
data data
:tmpD :tmpD
`=copy`(data, cast[string](encode do: :tmpD_1
:tmpD = newSeq(100) :tmpD_2
:tmpD)) data =
`=destroy`(:tmpD) wasMoved(:tmpD)
`=copy`(:tmpD, cast[string](
:tmpD_2 = encode do:
:tmpD_1 = newSeq(100)
:tmpD_1
:tmpD_2))
:tmpD
`=destroy`(:tmpD_2)
`=destroy`(:tmpD_1)
`=destroy_1`(data) `=destroy_1`(data)
-- end of expandArc ------------------------''' -- end of expandArc ------------------------'''
""" """
@ -89,3 +122,25 @@ echo a
#issue 11204 #issue 11204
var ac {.compileTime.} = @["a", "b"] var ac {.compileTime.} = @["a", "b"]
const bc = ac.len const bc = ac.len
type
O = object of RootRef
i: int
O1 = object of O
O2 = object of O
proc `=destroy`(o: var O) =
echo "destroying O"
proc `=destroy`(o: var O1) =
echo "destroying O1"
proc `=destroy`(o: var O2) =
echo "destroying O2"
proc test =
let o3 = cast[ref O2]((ref O1)())
test()