nim-works / nimskull

An in development statically typed systems programming language; with sustainability at its core. We, the community of users, maintain it.
https://nim-works.github.io/nimskull/index.html
Other
275 stars 39 forks source link

Compiler crashes when compiling for iOS with threads on #1436

Closed DiThi closed 1 month ago

DiThi commented 1 month ago

Specification

Compile anything for iOS with threads on

Example

Run nim c -c --os:ios --threads:on anything.nim with any file.

Actual Output

nim.nim                  nim
nim.nim                  handleCmdLine
main.nim                 mainCommand
main.nim                 compileToBackend
main.nim                 commandCompileToC
cbackend.nim             generateCode
cbackend.nim             generateCode
backends.nim             translate
mirgen.nim               generateCode
mirgen.nim               gen
mirgen.nim               gen
mirgen.nim               genAsgn
mirgen.nim               genAsgnSource
mirgen.nim               genx
mirgen.nim               genx
mirgen.nim               genx
mirgen.nim               genx
mirgen.nim               genx
mirgen.nim               genCallOrMagic
mirgen.nim               genCall
mirgen.nim               genArgs
mirgen.nim               genArg
mirgen.nim               emitOperandTree
mirgen.nim               genArgExpression
mirgen.nim               genx
mirgen.nim               genx
mirgen.nim               genx
mirgen.nim               genx
mirgen.nim               genCallOrMagic
mirgen.nim               genMagic
mirgen.nim               genCall
mirgen.nim               genArgs
mirgen.nim               genArg
mirgen.nim               emitOperandTree
mirgen.nim               genArgExpression
mirgen.nim               exprToPmir
proto_mir.nim            exprToPmir
proto_mir.nim            exprToPmir
proto_mir.nim            symbolToPmir
idioms.nim               unreachableImpl
idioms.nim               unreachableImpl
assertions.nim           raiseAssert
fatal.nim                sysFatal
Error: unhandled exception: proto_mir.nim(559, 16) unreachable: skType [AssertionDefect]

Expected Output

No crash. Showing an error if those lines that make it crash are wrong.

Possible Solution

I have a workaround but it doesn't fix what causes this crash.

Additional Information

Error is caused by lines 132 and 184 in syslocks.nim. Trying to use sizeof with these two imported structs fail.

My workaround is as follows:

# I declare the `sizeof` as an imported variable
var sizeofSysLockObj {.importc:"sizeof(pthread_mutex_t)",nodecl.}: csize_t
# Then I use it instead of csize_t(sizeof(SysLockObj))
L = cast[SysLock](c_malloc(sizeofSysLockObj))
# and same thing with SysCondObj