new move analyser2 (#20471)
* produce better code for closure environment creation * new 'first write' analysis; * scope based move analyser * code cleanup Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com>
This commit is contained in:
parent
cfff454cf9
commit
8d47bf1822
19 changed files with 472 additions and 684 deletions
|
|
@ -15,8 +15,7 @@ proc initO(): O =
|
|||
O(initialized: true)
|
||||
|
||||
proc pair(): tuple[a, b: O] =
|
||||
result.a = initO()
|
||||
result.b = initO()
|
||||
result = (a: initO(), b: initO())
|
||||
|
||||
proc main() =
|
||||
discard pair()
|
||||
|
|
|
|||
|
|
@ -21,21 +21,21 @@ proc merge(lower, greater: owned Node): owned Node =
|
|||
elif greater.isNil:
|
||||
result = lower
|
||||
elif lower.y < greater.y:
|
||||
lower.right = merge(lower.right, greater)
|
||||
lower.right = merge(move lower.right, greater)
|
||||
result = lower
|
||||
else:
|
||||
greater.left = merge(lower, greater.left)
|
||||
greater.left = merge(lower, move greater.left)
|
||||
result = greater
|
||||
|
||||
proc splitBinary(orig: owned Node, value: int32): (owned Node, owned Node) =
|
||||
if orig.isNil:
|
||||
result = (nil, nil)
|
||||
elif orig.x < value:
|
||||
let splitPair = splitBinary(orig.right, value)
|
||||
let splitPair = splitBinary(move orig.right, value)
|
||||
orig.right = splitPair[0]
|
||||
result = (orig, splitPair[1])
|
||||
else:
|
||||
let splitPair = splitBinary(orig.left, value)
|
||||
let splitPair = splitBinary(move orig.left, value)
|
||||
orig.left = splitPair[1]
|
||||
result = (splitPair[0], orig)
|
||||
|
||||
|
|
|
|||
|
|
@ -50,7 +50,7 @@ proc `=destroy`(o: var Pony) =
|
|||
echo "Pony is dying!"
|
||||
|
||||
proc getPony: Pony =
|
||||
result.name = "Sparkles"
|
||||
result = Pony(name: "Sparkles")
|
||||
|
||||
iterator items(p: Pony): int =
|
||||
for i in 1..4:
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ proc createTree(x: int): Foo =
|
|||
proc take2(a, b: sink Foo) =
|
||||
echo a.x, " ", b.x
|
||||
|
||||
proc allowThis() =
|
||||
when false:
|
||||
var otherTree: Foo
|
||||
try:
|
||||
for i in 0..3:
|
||||
|
|
@ -51,5 +51,5 @@ proc preventThis() =
|
|||
else:
|
||||
discard
|
||||
|
||||
allowThis()
|
||||
#allowThis()
|
||||
preventThis()
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ proc createTree(x: int): Foo =
|
|||
proc take2(a, b: sink Foo) =
|
||||
echo a.x, " ", b.x
|
||||
|
||||
proc allowThis() =
|
||||
when false:
|
||||
var otherTree: Foo
|
||||
try:
|
||||
for i in 0..3:
|
||||
|
|
@ -47,7 +47,7 @@ proc preventThis2() =
|
|||
finally:
|
||||
echo otherTree
|
||||
|
||||
allowThis()
|
||||
#allowThis()
|
||||
preventThis2()
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
discard """
|
||||
cmd: '''nim c --newruntime $file'''
|
||||
errormsg: "'=copy' is not available for type <owned Button>; requires a copy because it's not the last read of ':envAlt.b1'; another read is done here: tuse_ownedref_after_move.nim(52, 4)"
|
||||
errormsg: "'=copy' is not available for type <owned Button>; requires a copy because it's not the last read of ':envAlt.b1'; routine: main"
|
||||
line: 48
|
||||
"""
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue