From 8ffb80e954164b000df54e41b2b6b818c8f6e997 Mon Sep 17 00:00:00 2001 From: Etan Kissling Date: Tue, 5 Sep 2023 21:36:35 +0200 Subject: [PATCH] avoid `Taskpool.spawn` within `{.async.}` for Nim 2.0 (#5393) In Nim 2.0, attempting to use `Taskpool.spawn` inside `{.async.}` `proc` leads to `Error: cannot generate destructor for generic type: Isolated`. Add an intermediate wrapper `proc` that performs the `spawn` operation to workaround the problem. --- beacon_chain/gossip_processing/batch_validation.nim | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/beacon_chain/gossip_processing/batch_validation.nim b/beacon_chain/gossip_processing/batch_validation.nim index 55648c8d4..1fa749754 100644 --- a/beacon_chain/gossip_processing/batch_validation.nim +++ b/beacon_chain/gossip_processing/batch_validation.nim @@ -228,6 +228,13 @@ proc batchVerifyTask(task: ptr BatchTask) {.nimcall.} = discard task[].signal.fireSync() +proc spawnBatchVerifyTask(tp: Taskpool, task: ptr BatchTask) = + # Inlining this `proc` leads to compilation problems on Nim 2.0 + # - Error: cannot generate destructor for generic type: Isolated + # Workaround: Ensure that `tp.spawn` is not used within an `{.async.}` proc + # Possibly related to: https://github.com/nim-lang/Nim/issues/22305 + tp.spawn batchVerifyTask(task) + proc batchVerifyAsync*( verifier: ref BatchVerifier, signal: ThreadSignalPtr, batch: ref Batch): Future[bool] {.async.} = @@ -245,7 +252,7 @@ proc batchVerifyAsync*( let taskPtr = addr task doAssert verifier[].taskpool.numThreads > 1, "Must have at least one separate thread or signal will never be fired" - verifier[].taskpool.spawn batchVerifyTask(taskPtr) + verifier[].taskpool.spawnBatchVerifyTask(taskPtr) await signal.wait() task.ok.load()