Finer analysis for array access (#16787)

* Refine the analysis for array access
* Cleanup
* Add comments
This commit is contained in:
Clyybber 2021-01-24 21:01:41 +01:00 • committed by GitHub
commit 301e5838ec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 106 additions and 29 deletions

View file

@ -92,10 +92,20 @@ copy
destroy
destroy
destroy
sink
sink
destroy
copy
(f: 1)
destroy
destroy
part-to-whole assigment:
sink
(children: @[])
destroy
sink
(children: @[])
destroy
copy
destroy
'''
@ -675,6 +685,16 @@ proc caseNotAConstant =
caseNotAConstant()
proc potentialSelfAssign(i: var int) =
var a: array[2, OO]
a[i] = OO(f: 1)
a[1] = OO(f: 2)
a[i+1] = a[i] # This must not =sink, but =copy
inc i
echo a[i-1] # (f: 1)
potentialSelfAssign (var xi = 0; xi)
#--------------------------------------------------------------------
echo "part-to-whole assigment:"
@ -700,6 +720,17 @@ proc partToWholeSeq =
partToWholeSeq()
proc partToWholeSeqRTIndex =
var i = 0
var t = Tree(children: @[Tree()])
t = t.children[i] # See comment in partToWholeSeq
var tc = TreeDefaultHooks(children: @[TreeDefaultHooks()])
tc = tc.children[i] # See comment in partToWholeSeq
echo tc
partToWholeSeqRTIndex()
type List = object
next: ref List