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:
parent
01f09567c4
commit
045e026d0e
8 changed files with 135 additions and 47 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
35
tests/destructor/tobjfield_analysis.nim
Normal file
35
tests/destructor/tobjfield_analysis.nim
Normal 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()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue