diff options
author | cooldome <cdome@bk.ru> | 2020-04-05 15:44:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-05 16:44:15 +0200 |
commit | 6d4f07f2ead4f8800efdc26476768b30b0bb04bc (patch) | |
tree | 9906b8b74ae55a2c79a99e340e16f9a718dcb22b /compiler | |
parent | 09ca19208f7c9aa52e71b50cf53cc369612e3fce (diff) | |
download | Nim-6d4f07f2ead4f8800efdc26476768b30b0bb04bc.tar.gz |
Fix sym owner in wrapper proc (#13878)
Co-authored-by: cooldome <ariabushenko@bk.ru>
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/spawn.nim | 54 |
1 files changed, 27 insertions, 27 deletions
diff --git a/compiler/spawn.nim b/compiler/spawn.nim index 2c206b599..d566e0bd9 100644 --- a/compiler/spawn.nim +++ b/compiler/spawn.nim @@ -116,24 +116,22 @@ stmtList: proc createWrapperProc(g: ModuleGraph; f: PNode; threadParam, argsParam: PSym; varSection, varInit, call, barrier, fv: PNode; - spawnKind: TSpawnResult): PSym = + spawnKind: TSpawnResult, result: PSym) = var body = newNodeI(nkStmtList, f.info) - body.flags.incl nfTransf # do not transform further - var threadLocalBarrier: PSym if barrier != nil: var varSection2 = newNodeI(nkVarSection, barrier.info) - threadLocalBarrier = addLocalVar(g, varSection2, nil, argsParam.owner, + threadLocalBarrier = addLocalVar(g, varSection2, nil, result, barrier.typ, barrier) body.add varSection2 body.add callCodegenProc(g, "barrierEnter", threadLocalBarrier.info, threadLocalBarrier.newSymNode) var threadLocalProm: PSym if spawnKind == srByVar: - threadLocalProm = addLocalVar(g, varSection, nil, argsParam.owner, fv.typ, fv) + threadLocalProm = addLocalVar(g, varSection, nil, result, fv.typ, fv) elif fv != nil: internalAssert g.config, fv.typ.kind == tyGenericInst - threadLocalProm = addLocalVar(g, varSection, nil, argsParam.owner, fv.typ, fv) + threadLocalProm = addLocalVar(g, varSection, nil, result, fv.typ, fv) body.add varSection body.add varInit if fv != nil and spawnKind != srByVar: @@ -184,9 +182,6 @@ proc createWrapperProc(g: ModuleGraph; f: PNode; threadParam, argsParam: PSym; t.n.add threadParam.newSymNode t.n.add argsParam.newSymNode - let name = (if f.kind == nkSym: f.sym.name.s else: genPrefix) & "Wrapper" - result = newSym(skProc, getIdent(g.cache, name), argsParam.owner, f.info, - argsParam.options) let emptyNode = newNodeI(nkEmpty, f.info) result.ast = newProcNode(nkProcDef, f.info, body = body, params = params, name = newSymNode(result), pattern = emptyNode, @@ -201,7 +196,8 @@ proc createCastExpr(argsParam: PSym; objType: PType): PNode = result.typ = newType(tyPtr, objType.owner) result.typ.rawAddSon(objType) -proc setupArgsForConcurrency(g: ModuleGraph; n: PNode; objType: PType; scratchObj: PSym, +proc setupArgsForConcurrency(g: ModuleGraph; n: PNode; objType: PType; + owner: PSym; scratchObj: PSym, castExpr, call, varSection, varInit, result: PNode) = let formals = n[0].typ.n @@ -221,7 +217,7 @@ proc setupArgsForConcurrency(g: ModuleGraph; n: PNode; objType: PType; scratchOb objType.addField(field, g.cache) result.add newFastAsgnStmt(newDotExpr(scratchObj, field), n[i]) - let temp = addLocalVar(g, varSection, varInit, objType.owner, argType, + let temp = addLocalVar(g, varSection, varInit, owner, argType, indirectAccess(castExpr, field, n.info)) call.add(newSymNode(temp)) @@ -242,7 +238,8 @@ proc getRoot*(n: PNode): PSym = if getMagic(n) == mSlice: result = getRoot(n[1]) else: discard -proc setupArgsForParallelism(g: ModuleGraph; n: PNode; objType: PType; scratchObj: PSym; +proc setupArgsForParallelism(g: ModuleGraph; n: PNode; objType: PType; + owner: PSym; scratchObj: PSym; castExpr, call, varSection, varInit, result: PNode) = let formals = n[0].typ.n @@ -281,7 +278,7 @@ proc setupArgsForParallelism(g: ModuleGraph; n: PNode; objType: PType; scratchOb result.add newFastAsgnStmt(newDotExpr(scratchObj, fieldA), n[2]) result.add newFastAsgnStmt(newDotExpr(scratchObj, fieldB), n[3]) - let threadLocal = addLocalVar(g, varSection,nil, objType.owner, fieldA.typ, + let threadLocal = addLocalVar(g, varSection,nil, owner, fieldA.typ, indirectAccess(castExpr, fieldA, n.info), useShallowCopy=true) slice[2] = threadLocal.newSymNode @@ -296,7 +293,7 @@ proc setupArgsForParallelism(g: ModuleGraph; n: PNode; objType: PType; scratchOb # the array itself does not need to go through a thread local variable: slice[1] = genDeref(indirectAccess(castExpr, field, n.info)) - let threadLocal = addLocalVar(g, varSection,nil, objType.owner, fieldB.typ, + let threadLocal = addLocalVar(g, varSection,nil, owner, fieldB.typ, indirectAccess(castExpr, fieldB, n.info), useShallowCopy=true) slice[3] = threadLocal.newSymNode @@ -308,7 +305,7 @@ proc setupArgsForParallelism(g: ModuleGraph; n: PNode; objType: PType; scratchOb field.typ = a.typ objType.addField(field, g.cache) result.add newFastAsgnStmt(newDotExpr(scratchObj, field), a) - let threadLocal = addLocalVar(g, varSection,nil, objType.owner, field.typ, + let threadLocal = addLocalVar(g, varSection,nil, owner, field.typ, indirectAccess(castExpr, field, n.info), useShallowCopy=true) call.add(genDeref(threadLocal.newSymNode)) @@ -318,7 +315,7 @@ proc setupArgsForParallelism(g: ModuleGraph; n: PNode; objType: PType; scratchOb objType.addField(field, g.cache) result.add newFastAsgnStmt(newDotExpr(scratchObj, field), n) let threadLocal = addLocalVar(g, varSection, varInit, - objType.owner, field.typ, + owner, field.typ, indirectAccess(castExpr, field, n.info), useShallowCopy=true) call.add(threadLocal.newSymNode) @@ -346,9 +343,13 @@ proc wrapProcForSpawn*(g: ModuleGraph; owner: PSym; spawnExpr: PNode; retType: P if optThreadAnalysis in g.config.globalOptions: if {tfThread, tfNoSideEffect} * n[0].typ.flags == {}: localError(g.config, n.info, "'spawn' takes a GC safe call expression") - var - threadParam = newSym(skParam, getIdent(g.cache, "thread"), owner, n.info, g.config.options) - argsParam = newSym(skParam, getIdent(g.cache, "args"), owner, n.info, g.config.options) + + var fn = n[0] + let + name = (if fn.kind == nkSym: fn.sym.name.s else: genPrefix) & "Wrapper" + wrapperProc = newSym(skProc, getIdent(g.cache, name), owner, fn.info, g.config.options) + threadParam = newSym(skParam, getIdent(g.cache, "thread"), wrapperProc, n.info, g.config.options) + argsParam = newSym(skParam, getIdent(g.cache, "args"), wrapperProc, n.info, g.config.options) block: let ptrType = getSysType(g, n.info, tyPointer) threadParam.typ = ptrType @@ -368,7 +369,6 @@ proc wrapProcForSpawn*(g: ModuleGraph; owner: PSym; spawnExpr: PNode; retType: P result.add varSectionB var call = newNodeIT(nkCall, n.info, n.typ) - var fn = n[0] # templates and macros are in fact valid here due to the nature of # the transformation: if fn.kind == nkClosure or (fn.typ != nil and fn.typ.callConv == ccClosure): @@ -391,10 +391,10 @@ proc wrapProcForSpawn*(g: ModuleGraph; owner: PSym; spawnExpr: PNode; retType: P var varSection = newNodeI(nkVarSection, n.info) var varInit = newNodeI(nkStmtList, n.info) if barrier.isNil: - setupArgsForConcurrency(g, n, objType, scratchObj, castExpr, call, + setupArgsForConcurrency(g, n, objType, wrapperProc, scratchObj, castExpr, call, varSection, varInit, result) else: - setupArgsForParallelism(g, n, objType, scratchObj, castExpr, call, + setupArgsForParallelism(g, n, objType, wrapperProc, scratchObj, castExpr, call, varSection, varInit, result) var barrierAsExpr: PNode = nil @@ -428,11 +428,11 @@ proc wrapProcForSpawn*(g: ModuleGraph; owner: PSym; spawnExpr: PNode; retType: P fvAsExpr = indirectAccess(castExpr, field, n.info) result.add newFastAsgnStmt(newDotExpr(scratchObj, field), genAddrOf(dest)) - let wrapper = createWrapperProc(g, fn, threadParam, argsParam, - varSection, varInit, call, - barrierAsExpr, fvAsExpr, spawnKind) - result.add callCodegenProc(g, "nimSpawn" & $spawnExpr.len, wrapper.info, - wrapper.newSymNode, genAddrOf(scratchObj.newSymNode), nil, spawnExpr) + createWrapperProc(g, fn, threadParam, argsParam, + varSection, varInit, call, + barrierAsExpr, fvAsExpr, spawnKind, wrapperProc) + result.add callCodegenProc(g, "nimSpawn" & $spawnExpr.len, wrapperProc.info, + wrapperProc.newSymNode, genAddrOf(scratchObj.newSymNode), nil, spawnExpr) if spawnKind == srFlowVar: result.add fvField |