Merge pull request #15027 from nim-lang/araq-cursor-fix
cursor inference bugfix
This commit is contained in:
commit
c8a72e0748
2 changed files with 65 additions and 4 deletions
|
|
@ -237,10 +237,11 @@ proc analyse(c: var Con; n: PNode) =
|
||||||
# assignments like 'x.field = value' mean that 'x' itself cannot
|
# assignments like 'x.field = value' mean that 'x' itself cannot
|
||||||
# be a cursor:
|
# be a cursor:
|
||||||
let r = locationRoot(n[0])
|
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
|
# however, an assignment like 'it.field = x' does not influence r's
|
||||||
# cursorness property:
|
# 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
|
c.mutations.incl r.id
|
||||||
|
|
||||||
if hasDestructor(n[1].typ):
|
if hasDestructor(n[1].typ):
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,9 @@
|
||||||
discard """
|
discard """
|
||||||
output: '''(repo: "", package: "meo", ext: "")'''
|
output: '''(repo: "", package: "meo", ext: "")
|
||||||
cmd: '''nim c --gc:arc --expandArc:newTarget --hint:Performance:off $file'''
|
doing shady stuff...
|
||||||
|
3
|
||||||
|
6'''
|
||||||
|
cmd: '''nim c --gc:arc --expandArc:newTarget --expandArc:delete --hint:Performance:off $file'''
|
||||||
nimout: '''--expandArc: newTarget
|
nimout: '''--expandArc: newTarget
|
||||||
|
|
||||||
var
|
var
|
||||||
|
|
@ -23,6 +26,14 @@ result = (
|
||||||
let blitTmp_2 = :tmp_2
|
let blitTmp_2 = :tmp_2
|
||||||
blitTmp_2)
|
blitTmp_2)
|
||||||
`=destroy`(splat)
|
`=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 ------------------------'''
|
-- end of expandArc ------------------------'''
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
@ -35,3 +46,52 @@ proc newTarget*(path: string): Target =
|
||||||
result = (repo: splat.dir, package: splat.name, ext: splat.ext)
|
result = (repo: splat.dir, package: splat.name, ext: splat.ext)
|
||||||
|
|
||||||
echo newTarget("meo")
|
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()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue