cursor inference bugfix

This commit is contained in:
Andreas Rumpf
2020-07-20 18:37:14 +02:00
parent 80d3ef9952
commit 3a4e4cec4d
2 changed files with 65 additions and 4 deletions

View File

@@ -237,10 +237,11 @@ proc analyse(c: var Con; n: PNode) =
# assignments like 'x.field = value' mean that 'x' itself cannot
# be a cursor:
let r = locationRoot(n[0])
if r != nil and r.typ.skipTypes(abstractInst).kind notin {tyPtr, tyRef}:
if r != nil:
# however, an assignment like 'it.field = x' does not influence r's
# cursorness property:
c.mayOwnData.incl r.id
if r.typ.skipTypes(abstractInst).kind notin {tyPtr, tyRef}:
c.mayOwnData.incl r.id
c.mutations.incl r.id
if hasDestructor(n[1].typ):

View File

@@ -1,6 +1,9 @@
discard """
output: '''(repo: "", package: "meo", ext: "")'''
cmd: '''nim c --gc:arc --expandArc:newTarget --hint:Performance:off $file'''
output: '''(repo: "", package: "meo", ext: "")
doing shady stuff...
3
6'''
cmd: '''nim c --gc:arc --expandArc:newTarget --expandArc:delete --hint:Performance:off $file'''
nimout: '''--expandArc: newTarget
var
@@ -23,6 +26,14 @@ result = (
let blitTmp_2 = :tmp_2
blitTmp_2)
`=destroy`(splat)
-- end of expandArc ------------------------
--expandArc: delete
var saved
var sibling_cursor = target.parent.left
`=`(saved, sibling_cursor.right)
`=`(sibling_cursor.right, saved.left)
`=sink`(sibling_cursor.parent, saved)
-- end of expandArc ------------------------'''
"""
@@ -35,3 +46,52 @@ proc newTarget*(path: string): Target =
result = (repo: splat.dir, package: splat.name, ext: splat.ext)
echo newTarget("meo")
type
Node = ref object
left, right, parent: Node
value: int
proc delete(target: var Node) =
var sibling = target.parent.left # b3
var saved = sibling.right # b3.right -> r4
sibling.right = saved.left # b3.right -> r4.left = nil
sibling.parent = saved # b3.parent -> r5 = r4
#[after this proc:
b 5
/ \
b 3 b 6
]#
#[before:
r 5
/ \
b 3 b 6 - to delete
/ \
empty r 4
]#
proc main =
var five = Node(value: 5)
var six = Node(value: 6)
six.parent = five
five.right = six
var three = Node(value: 3)
three.parent = five
five.left = three
var four = Node(value: 4)
four.parent = three
three.right = four
echo "doing shady stuff..."
delete(six)
# need both of these echos
echo five.left.value
echo five.right.value
main()