close #9691 and close #10913('spawn'ed function cannot have a 'typed' or 'untyped' parameter) (#17775)

This commit is contained in:
flywind 2021-04-20 21:39:58 +08:00 • committed by GitHub
commit c776498170
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 40 additions and 1 deletions

View file

@ -192,6 +192,11 @@ proc createCastExpr(argsParam: PSym; objType: PType; idgen: IdGenerator): PNode
result.typ = newType(tyPtr, nextTypeId idgen, objType.owner) result.typ = newType(tyPtr, nextTypeId idgen, objType.owner)
result.typ.rawAddSon(objType) result.typ.rawAddSon(objType)
template checkMagicProcs(g: ModuleGraph, n: PNode, formal: PNode) =
if (formal.typ.kind == tyVarargs and formal.typ[0].kind in {tyTyped, tyUntyped}) or
formal.typ.kind in {tyTyped, tyUntyped}:
localError(g.config, n.info, "'spawn'ed function cannot have a 'typed' or 'untyped' parameter")
proc setupArgsForConcurrency(g: ModuleGraph; n: PNode; objType: PType; proc setupArgsForConcurrency(g: ModuleGraph; n: PNode; objType: PType;
idgen: IdGenerator; owner: PSym; scratchObj: PSym, idgen: IdGenerator; owner: PSym; scratchObj: PSym,
castExpr, call, castExpr, call,
@ -205,6 +210,9 @@ proc setupArgsForConcurrency(g: ModuleGraph; n: PNode; objType: PType;
if i < formals.len: if i < formals.len:
if formals[i].typ.kind in {tyVar, tyLent}: if formals[i].typ.kind in {tyVar, tyLent}:
localError(g.config, n[i].info, "'spawn'ed function cannot have a 'var' parameter") localError(g.config, n[i].info, "'spawn'ed function cannot have a 'var' parameter")
checkMagicProcs(g, n[i], formals[i])
if formals[i].typ.kind in {tyTypeDesc, tyStatic}: if formals[i].typ.kind in {tyTypeDesc, tyStatic}:
continue continue
#elif containsTyRef(argType): #elif containsTyRef(argType):
@ -233,6 +241,9 @@ proc setupArgsForParallelism(g: ModuleGraph; n: PNode; objType: PType;
let n = n[i] let n = n[i]
if i < formals.len and formals[i].typ.kind in {tyStatic, tyTypeDesc}: if i < formals.len and formals[i].typ.kind in {tyStatic, tyTypeDesc}:
continue continue
checkMagicProcs(g, n, formals[i])
let argType = skipTypes(if i < formals.len: formals[i].typ else: n.typ, let argType = skipTypes(if i < formals.len: formals[i].typ else: n.typ,
abstractInst) abstractInst)
#if containsTyRef(argType): #if containsTyRef(argType):
@ -420,4 +431,3 @@ proc wrapProcForSpawn*(g: ModuleGraph; idgen: IdGenerator; owner: PSym; spawnExp
wrapperProc.newSymNode, genAddrOf(scratchObj.newSymNode, idgen), nil, spawnExpr) wrapperProc.newSymNode, genAddrOf(scratchObj.newSymNode, idgen), nil, spawnExpr)
if spawnKind == srFlowVar: result.add fvField if spawnKind == srFlowVar: result.add fvField

20
tests/parallel/t10913.nim Normal file
View file

@ -0,0 +1,20 @@
discard """
matrix: "--threads:on"
errormsg: "'spawn'ed function cannot have a 'typed' or 'untyped' parameter"
"""
# bug #10913
import threadpool
proc useParallel*[T](unused: T) =
# use a generic T here to show the problem.
{.push experimental: "parallel".}
parallel:
for i in 0..4:
spawn echo "echo in parallel"
sync()
{.pop.}
useParallel(1)

9
tests/parallel/t9691.nim Normal file
View file

@ -0,0 +1,9 @@
discard """
matrix: "--threads:on"
errormsg: "'spawn'ed function cannot have a 'typed' or 'untyped' parameter"
"""
# bug #9691
import threadpool
spawn echo()