mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-10 05:38:10 +00:00
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:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user