@@ -149,12 +149,12 @@ proc deconstructForStmt(n: NimNode): tuple[syms: seq[NimNode],
149149 syms.add n[i]
150150 result = (syms: syms, call: n[n.len - 2 ], body: n[n.len - 1 ])
151151
152- proc finalizeJoin (fn: JoinStmt , send: SendStmt , outTyp, joinId, idxSym: NimNode ): NimNode =
152+ proc finalizeJoin (fn: JoinStmt , send: SendStmt , inTyp, outTyp, joinId, idxSym: NimNode ): NimNode =
153153 # # Replace the `send` identifier by a correct pointer cast / load from buffer
154154 # # setup
155155 let sl = genSym (nskParam, " slice" ) # # XXX: update
156156 let data = quote do : # load data / extract from MSlice
157- when not `outTyp `.supportsCopyMem:
157+ when not `inTyp `.supportsCopyMem: # (int, inTyp) == outTyp
158158 when WriteFiles :
159159 let path = $ (`sl`)
160160 loadBuffer [`outTyp`](path, DeleteFiles )
@@ -181,6 +181,9 @@ proc patchSendTmpl(sen: SendStmt, oId, idxSym: NimNode): NimNode =
181181
182182macro forked * (n: ForLoopStmt ): untyped =
183183 # # XXX: Extend to not force `evalOb` and `uRd` on the input side! Also allow copy & load there
184+ # Note: in the code below we currently work around:
185+ # `https://github.com/nim-lang/Nim/issues/24378`
186+
184187 # Deconstruct the `ForLoopStmt` into its pieces
185188 let (syms, call, body) = deconstructForStmt (n)
186189 # Extract all the relevant pieces of the for loop stmt
@@ -193,7 +196,8 @@ macro forked*(n: ForLoopStmt): untyped =
193196 let oId = genSym (nskLet, " o" )
194197 let joinId = genSym (nskTemplate, " join" )
195198 let ppId = genSym (nskVar, " pp" )
196- let Wid = genSym (nskType, " W" ) # write type (without index!)
199+ let WIn = genSym (nskType, " WIn" )
200+ let WId = genSym (nskType, " W" ) # write type (without index!)
197201
198202 # Get iterator, and iteration variables for loop
199203 let iterCall = iter.iter
@@ -211,18 +215,18 @@ macro forked*(n: ForLoopStmt): untyped =
211215 fakeBody.add senId
212216
213217 # finalize the `join` `onReply` logic
214- let finJoin = finalizeJoin (join, sen, Wid , joinId, idxSym)
218+ let finJoin = finalizeJoin (join, sen, WIn , WId , joinId, idxSym)
215219
216220 # finalize the body (i.e. patch `send` template)
217221 loopBody.add patchSendTmpl (sen, oId, idxSym)
218222 let jobs = iter.jobs
219223 result = quote do :
220224 type RIn = typeof (`iterCall`) # parent ⇒ child type (user)
221225 type R = (int , RIn ) # actual type we transfer (job index, user data)
222- type WIn = typeof (`fakeBody`) # child ⇒ parent type (user)
223- type `WId` = (int , Win ) # actual type we transfer (job index, user data)
226+ type ` WIn` = typeof (`fakeBody`) # child ⇒ parent type (user)
227+ type `WId` = (int , `WIn` ) # actual type we transfer (job index, user data)
224228 let jobs = if `jobs` > 0 : `jobs` else : parseInt (getEnv (" PP_JOBS" , $ countProcessors ()))
225- when not `WId `.supportsCopyMem:
229+ when not `WIn `.supportsCopyMem: # if `WIn` supports memcopy, so does `(int, WIn)`. Due to https://github.com/nim-lang/Nim/issues/24378
226230 var `ppId` = ppFramesLenPfx (R, `oId`, `sId`, `idxSym`, jobs, `loopBody`)
227231 else :
228232 var `ppId` = ppFramesOb (R, `WId`, `oId`, `sId`, `idxSym`, jobs, `loopBody`)
0 commit comments