From a695688faf93912c942324bb9a860feab6b12e0d Mon Sep 17 00:00:00 2001 From: Jaremy Creechley Date: Mon, 3 Jun 2024 14:14:12 +0100 Subject: [PATCH] fix gc args issue --- codex/slots/proofs/backends/asynccircoms.nim | 25 ++++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/codex/slots/proofs/backends/asynccircoms.nim b/codex/slots/proofs/backends/asynccircoms.nim index 2e46e9ea..2efd02f5 100644 --- a/codex/slots/proofs/backends/asynccircoms.nim +++ b/codex/slots/proofs/backends/asynccircoms.nim @@ -14,13 +14,23 @@ import ./circomcompat logScope: topics = "codex asyncprover" -type AsyncCircomCompat* = object - circom*: CircomCompat - tp*: Taskpool +type + AsyncCircomCompat* = object + circom*: CircomCompat + tp*: Taskpool + + ProverArgs[H] = object + circom: CircomCompat + data: ProofInputs[H] + proc proveTask[H]( - circom: CircomCompat, data: ProofInputs[H], results: SignalQueuePtr[?!CircomProof] + args: ptr ProverArgs[H], results: SignalQueuePtr[?!CircomProof] ) = + + let circom = args[].circom + let data = args[].data + let proof = circom.prove(data) if (let sent = results.send(proof); sent.isErr()): @@ -34,12 +44,17 @@ proc prove*[H]( without queue =? newSignalQueue[?!CircomProof](maxItems = 1), qerr: return failure(qerr) + var args = (ref ProverArgs[H])(circom: self.circom, data: input) + GC_ref(args) + proc spawnTask() = - self.tp.spawn proveTask(self.circom, input, queue) + self.tp.spawn proveTask(args[].addr, queue) spawnTask() let taskRes = await queue.recvAsync() + GC_unref(args) + if (let res = queue.release(); res.isErr): error "Error releasing proof queue ", msg = res.error().msg without proofRes =? taskRes, perr: