weave
weave copied to clipboard
Examples in README.md do not compile
Given that I was playing around and noticed it: I was unable to compile any of the examples. Sporadically I tested
import weave
func initialize(buffer: ptr UncheckedArray[float32], len: int) =
for i in 0 ..< len:
buffer[i] = i.float32
proc transpose(M, N: int, bufIn, bufOut: ptr UncheckedArray[float32]) =
## Transpose a MxN matrix into a NxM matrix with nested for loops
parallelFor j in 0 ..< N:
captures: {M, N, bufIn, bufOut}
parallelFor i in 0 ..< M:
captures: {j, M, N, bufIn, bufOut}
bufOut[j*M+i] = bufIn[i*N+j]
proc main() =
let M = 200
let N = 2000
let input = newSeq[float32](M*N)
# We can't work with seq directly as it's managed by GC, take a ptr to the buffer.
let bufIn = cast[ptr UncheckedArray[float32]](input[0].unsafeAddr)
bufIn.initialize(M*N)
var output = newSeq[float32](N*M)
let bufOut = cast[ptr UncheckedArray[float32]](output[0].addr)
init(Weave)
transpose(M, N, bufIn, bufOut)
exit(Weave)
main()
On nim 2.0.0, 2.0.4 and 1.6.20, all of them have various versions of compiler errors:
With 1.6.20: nim r -f --cc:clang -d:useMalloc --threads:on src/playground.nim:
/home/isofruit/.cache/nim/playground_d/@m..@s..@[email protected]@[email protected]@[email protected]:450:17: error: incompatible function pointer types assigning to 'tyProc__4SVlZZPmetqBimNsH9cHcOA' (aka 'void (*)(void *)') from 'void (tyObject_LookAsideList__heA8P1gVJ9ac9by6gcye6wkQ *)' (aka 'void (struct tyObject_LookAsideList__heA8P1gVJ9ac9by6gcye6wkQ *)') [-Wincompatible-function-pointer-types]
450 | (*hook).Field0 = cacheMaintenanceEx__OOZOOZOOZOnimbleZpkgs50Zweave4548O52O48455749b56ef51495657515651a5657f5553e51c5153c5452545655b56a5455bf535257ZweaveZscheduler_u79;
| ^ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
Error: execution of an external compiler program 'clang -c -w -ferror-limit=3 -pthread -I/home/isofruit/.choosenim/toolchains/nim-1.6.20/lib -I/home/isofruit/dev/playground/src -o /home/isofruit/.cache/nim/playground_d/@m..@s..@[email protected]@[email protected]@[email protected] /home/isofruit/.cache/nim/playground_d/@m..@s..@[email protected]@[email protected]@[email protected]' failed with exit code: 1
With 2.0.0: nim r -f --cc:clang -d:useMalloc src/playground.nim
/home/isofruit/.nimble/pkgs2/weave-0.4.0-91b8ef3189383a89f75e3c35c64687b8a67bf549/weave/parallel_tasks.nim(166, 16) Error: type mismatch: got 'proc (param`gensym1: pointer){.nimcall.}' for 'async_fib' but expected 'proc (param: pointer){.nimcall, gcsafe.}'
Pragma mismatch: got '{..}', but expected '{.gcsafe.}'.
Similar issues appear with the other examples I sporadically tested, leading me to assume that none of them currently work.
It's a gcc 14 issue, which also blocks https://github.com/nim-lang/Nim/pull/23649
in https://github.com/mratsim/weave/blob/b6255afa5816ee431dbf2f59cc6bc605d8d657b8/weave/memory/lookaside_lists.nim#L162
hook.onHeartbeat = cast[type hook.onHeartbeat](cacheMaintenanceEx[T])
but onHeartbeat is of proc(env: pointer){.nimcall.} type, it shoud be cast as the type of onHeartbeat instead. It looks easy to solve
Isn't that what I'm already doing?
Did you mean cast[proc(env: pointer){.nimcall.}](...) ?
Unfortunately it seems like Nim skips materializing the cast
and it also happens with Clang
https://github.com/nim-lang/Nim/pull/23683 fixed the issue of skipping cast function types. Would you mind checking it?
I have also restarted a new run of action => https://github.com/nim-lang/Nim/pull/23649