I've got this old tool written in Nim with the --mm:refc flag (haven't gotten around to porting it to orc yet). Lately, it's been throwing this weird error my way: "SIGSEGV: Illegal storage access (Attempt to read from nil?)".
So, I dug into the code, and it seems the issue is in the updated Nim 2.0 destructor syntax. Here's the snippet:
type
Obj1 = object
n: int
Ref1 = ref Obj1
Obj2 = object
n: int
Ref2 = ref Obj2
proc `=destroy`(x: var Obj1) =
echo "Obj1", repr x
proc `=destroy`(x: Obj2) =
echo "Obj2", repr x
for i in 1..10:
discard Ref1(n: i)
discard Ref2(n: i)
GC_FullCollect()
Compile with --mm:refc, the output looks pretty crazy:
Obj2 [n = 1664083685488]
Obj1 [n = 1]
Obj2 [n = 1664083685552]
Obj1 [n = 2]
Obj2 [n = 1664083685488]
Obj1 [n = 3]
Obj2 [n = 1664083685552]
Obj1 [n = 4]
Obj2 [n = 1664083685488]
Obj1 [n = 5]
Obj2 [n = 1664083685552]
Obj1 [n = 6]
Obj2 [n = 1664083685488]
Obj1 [n = 7]
Obj2 [n = 1664083685552]
Obj1 [n = 8]
Obj2 [n = 1664083685488]
Obj1 [n = 9]
When compiled with --mm:refc -d:release --cpu:i386, the same code will simply crash.
The new destructor should not applied to refc, I will disallow it for refc.
Did you try the example with --mm:orc --cpu:i386?
--mm:orc has no problems.
Since the new destructor shouldn't be applied, is there a way to use refc in Nim 2.0 without encountering a deprecated message?
I've observed that certain code using when defined(nimAllowNonVarDestructor) to choose the destructor ends up using the wrong version for refc.
https://github.com/nim-lang/threading/blob/master/threading/channels.nim