Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that ref types are not passed to threads #23485

Open
wants to merge 2 commits into
base: devel
Choose a base branch
from

Conversation

vanyle
Copy link
Contributor

@vanyle vanyle commented Apr 8, 2024

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.

@vanyle
Copy link
Contributor Author

vanyle commented Apr 9, 2024

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!

@vanyle
Copy link
Contributor Author

vanyle commented Apr 13, 2024

../../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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant