Check that `ref` types are not passed to threads
For memory reasons, types containing refs should not be passed to the argument of a thread.
This PR enforces this.
Because the macro system is not available from thread as thread is imported by the system module, we use typedesc (an implementation suggested by beef331 here).
The code recursively checks that the object passed does not contains ref inside nested fields.
A test is added to make sure this actually works.
https://github.com/status-im/nim-testutils seems to contain a bug. Inside ntu.nim:
proc spawnTest(child: var Thread[ThreadPayload]; test: TestSpec;
core: int): bool =
a thread is created and ThreadPayload is passed to it.
We have:
type ThreadPayload = object
core: int
spec: TestSpec
In another file, we have:
TestSpec* = ref object
section*: string
args*: string
....
It seems to be working!
../../lib/std/typedthreads.nim(305, 25) Error: type mismatch: got <Thread[system.void], proc (){.nimcall, gcsafe.}, void>
but expected one of:
proc (t: var Thread[system.void], tp: proc (){.nimcall, gcsafe.}){.noSideEffect, gcsafe.}
I don't understand this error in the tests. They are the same type, there is no mismatch. The compiler does not seem in understand that there are two createThread function, a generic and a non-generic one.