dfa.nim: track object/tuple field accesses more precisely; sink(o.x); sink(o.y) needs to compile; activate the tuple unpacking transf.nim bugfix

This commit is contained in:
Araq
2019-04-15 17:57:59 +02:00
parent 01f09567c4
commit 045e026d0e
8 changed files with 135 additions and 47 deletions

View File

@@ -23,5 +23,5 @@ proc test(): auto =
var (a, b, _) = test()
doAssert: assign_counter == 0
doAssert: sink_counter == 9
doAssert assign_counter == 0
doAssert sink_counter == 12 # + 3 because of the conservative tuple unpacking transformation

View File

@@ -88,8 +88,8 @@ proc `-`*(a: sink Matrix; b: Matrix): Matrix =
doAssert(a.len == b.len) # non destructive use before sink is ok
result = a
for i in 0 ..< result.m:
for j in 0 ..< result.n:
result[i, j] = a[i, j] - b[i, j]
for j in 0 ..< result.n:
result[i, j] = a[i, j] - b[i, j]
proc info =
echo "after ", allocCount, " ", deallocCount

View File

@@ -0,0 +1,35 @@
discard """
output: '''works'''
"""
type
MyVal = object
f: ptr float
proc `=destroy`(x: var MyVal) =
if x.f != nil:
dealloc(x.f)
proc `=sink`(x1: var MyVal, x2: Myval) =
if x1.f != x2.f:
`=destroy`(x1)
x1.f = x2.f
proc `=`(x1: var MyVal, x2: Myval) {.error.}
proc newVal(x: float): MyVal =
result.f = create(float)
result.f[] = x
proc sinkMe(x: sink MyVal) =
discard
proc main =
var y = (newVal(3.0), newVal(4.0))
sinkMe y[0]
sinkMe y[1]
echo "works"
main()