You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
from strformat import `&`
type X =distinctintproc`=sink`(p1: var X; p2: X) =echo&"=sink {cast[int](p2)}"proc`=copy`(p1: var X; p2: X) =echo&"=copy {cast[int](p2)}"proc`=destroy`(p: var X) =echo&"=destroy {cast[int](p)}"procmain=echo"~~~~~~~~~~"block:
procbyLet(v: int): owned X =let x =X(v)
x
discardbyLet(1)
echo"~~~~~~~~~~"block:
procbyVar(v: int): owned X =var x =X(v)
x
discardbyVar(2)
echo"~~~~~~~~~~"block:
procbyCast(v: int): owned X =cast[X](v)
discardbyCast(3)
echo"~~~~~~~~~~"block:
procbyConv(v: int): owned X = (X)(v)
discardbyConv(4)
echo"~~~~~~~~~~"block:
procbyVarMove(v: int): owned X =var x =X(v)
move(x)
discardbyVarMove(5)
echo"~~~~~~~~~~"block:
procbyVarWasMoved(v: int): owned X =var x =X(v)
result= x
wasMoved(x)
discardbyVarWasMoved(6)
echo"~~~~~~~~~~"main()
Nim Compiler Version 1.6.0 [Linux: amd64]
Compiled at 2021-10-19
Copyright (c) 2006-2021 by Andreas Rumpf
git hash: 727c6378d2464090564dbcd9bc8b9ac648467e38
active boot switches: -d:release
The text was updated successfully, but these errors were encountered:
derekdai
changed the title
Reduce calls of =copy for return value
Prevent =copy if return value is the last use
Oct 27, 2021
Related to this forum post.
Example
Current Output
Expected Output
Possible Solution
Additional Information
The text was updated successfully, but these errors were encountered: