You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
type X =object
v: inttype Y =object
x: X
y: X
proc`=destroy`(x: var X) =echo"Destroying X"procf() =var y: Y =Y()
echo y
procg() =var y: Y
echo y
echo"calling f"f()
echo"calling g"g()
calling f
(x: (v: 0), y: (v: 0))
Destroying X
Destroying X
calling g
(x: (v: 0), y: (v: 0))
In f, we initialize y to its defaults and destructors get called - in g we do the same but implicitly and the destructors are not called - I would expect the behavior to be the same in both cases so as to maintain semantic equivalence for both forms of default-init.
This is just cursor inference in action. y in g is optimized to a .cursor and so the destruction step is elided. Works your way when you compile it via --cursorInference:off.
We can disable the cursor optimizer for types with custom destructors but cursor inference for custom types is as useful as it is for builtin types and the "spec" allows it.
Yes, sure. Heap allocations can be optimized away as long as the observable behavior doesn't change. And side effects in destructors don't count as observable, just like in C++. (Not sure how good of an idea that one is but C++ got away with it for good.)
Description
In
f
, we initialize y to its defaults and destructors get called - ing
we do the same but implicitly and the destructors are not called - I would expect the behavior to be the same in both cases so as to maintain semantic equivalence for both forms of default-init.Nim Version
https://play.nim-lang.org/#ix=4kHG - latest on play
Current Output
No response
Expected Output
No response
Possible Solution
No response
Additional Information
No response
The text was updated successfully, but these errors were encountered: