diff options
author | Araq <rumpf_a@web.de> | 2014-06-02 09:13:16 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-06-02 09:13:16 +0200 |
commit | b78173788d1f5e45091c31039e82960187db1277 (patch) | |
tree | 5ac0df3c2a60e035a0b0d455495e156b02cde505 /compiler | |
parent | e6d12f3f6ee933f295dd83a64f5f0e6eba77e1d1 (diff) | |
download | Nim-b78173788d1f5e45091c31039e82960187db1277.tar.gz |
bugfix: codegen for promises
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/lowerings.nim | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/compiler/lowerings.nim b/compiler/lowerings.nim index df2816a0e..2fff4a6f1 100644 --- a/compiler/lowerings.nim +++ b/compiler/lowerings.nim @@ -205,7 +205,7 @@ proc createNimCreatePromiseCall(prom, threadParam: PNode): PNode = let castExpr = newNodeIT(nkCast, prom.info, prom.typ) castExpr.add emptyNode castExpr.add callCodeGenProc("nimCreatePromise", threadParam, size) - result = newFastAsgnStmt(prom, castExpr) + result = castExpr proc createWrapperProc(f: PNode; threadParam, argsParam: PSym; varSection, call, barrier, prom: PNode; @@ -216,9 +216,14 @@ proc createWrapperProc(f: PNode; threadParam, argsParam: PSym; var threadLocalProm: PSym if spawnKind == srByVar: threadLocalProm = addLocalVar(varSection, argsParam.owner, prom.typ, prom) + elif prom != nil: + internalAssert prom.typ.kind == tyGenericInst + threadLocalProm = addLocalVar(varSection, argsParam.owner, prom.typ, + createNimCreatePromiseCall(prom, threadParam.newSymNode)) + body.add varSection if prom != nil and spawnKind != srByVar: - body.add createNimCreatePromiseCall(prom, threadParam.newSymNode) + body.add newFastAsgnStmt(prom, threadLocalProm.newSymNode) if barrier == nil: body.add callCodeGenProc("nimPromiseCreateCondVar", prom) @@ -230,10 +235,12 @@ proc createWrapperProc(f: PNode; threadParam, argsParam: PSym; if fk == promInvalid: localError(f.info, "cannot create a promise of type: " & typeToString(prom.typ.sons[1])) - body.add newAsgnStmt(indirectAccess(prom, + body.add newAsgnStmt(indirectAccess(threadLocalProm.newSymNode, if fk == promGC: "data" else: "blob", prom.info), call) if barrier == nil: - body.add callCodeGenProc("nimPromiseSignal", prom) + # by now 'prom' is shared and thus might have beeen overwritten! we need + # to use the thread-local view instead: + body.add callCodeGenProc("nimPromiseSignal", threadLocalProm.newSymNode) else: body.add call if barrier != nil: |