diff --git a/compiler/ccgcalls.nim b/compiler/ccgcalls.nim index a58f59c512daf..9ff6144c5b27c 100644 --- a/compiler/ccgcalls.nim +++ b/compiler/ccgcalls.nim @@ -80,7 +80,7 @@ proc fixupCall(p: BProc, le, ri: PNode, d: var TLoc, var pl = callee & "(" & params # getUniqueType() is too expensive here: var typ = skipTypes(ri[0].typ, abstractInst) - if typ[0] != nil: + if typ[0] != nil and typ[0].kind != tyVoid: if isInvalidReturnType(p.config, typ): if params.len != 0: pl.add(", ") # beware of 'result = p(result)'. We may need to allocate a temporary: @@ -308,8 +308,11 @@ proc genArg(p: BProc, n: PNode, param: PSym; call: PNode; result: var Rope; need else: addRdLoc(a, result) else: - initLocExprSingleUse(p, n, a) - addRdLoc(withTmpIfNeeded(p, a, needsTmp), result) + if param.typ.kind == tyVoid: + expr(p, n, a) + else: + initLocExprSingleUse(p, n, a) + addRdLoc(withTmpIfNeeded(p, a, needsTmp), result) #assert result != nil proc genArgNoParam(p: BProc, n: PNode; result: var Rope; needsTmp = false) = @@ -404,6 +407,8 @@ proc genParams(p: BProc, ri: PNode, typ: PType; result: var Rope) = result.add(", ") oldLen = result.len genArg(p, ri[i], paramType.sym, ri, result, needTmp[i-1]) + elif paramType.typ.kind == tyVoid: + genArg(p, ri[i], paramType.sym, ri, result, needTmp[i-1]) else: if oldLen != result.len: result.add(", ") @@ -459,7 +464,7 @@ proc genClosureCall(p: BProc, le, ri: PNode, d: var TLoc) = let rawProc = getClosureType(p.module, typ, clHalf) let canRaise = p.config.exc == excGoto and canRaiseDisp(p, ri[0]) - if typ[0] != nil: + if typ[0] != nil and typ[0].kind != tyVoid: if isInvalidReturnType(p.config, typ): if ri.len > 1: pl.add(", ") # beware of 'result = p(result)'. We may need to allocate a temporary: diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index dae04ba63f6e3..9c73754630770 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2987,7 +2987,7 @@ proc expr(p: BProc, n: PNode, d: var TLoc) = internalError(p.config, n.info, "expr: temp not init " & sym.name.s & "_" & $sym.id) putLocIntoDest(p, d, sym.loc) of skParam: - if sym.loc.r == "" or sym.loc.t == nil: + if n.typ.kind != tyVoid and (sym.loc.r == "" or sym.loc.t == nil): # echo "FAILED FOR PRCO ", p.prc.name.s # debug p.prc.typ.n # echo renderTree(p.prc.ast, {renderIds}) diff --git a/compiler/ccgstmts.nim b/compiler/ccgstmts.nim index fbdb9a347073b..74024271b6852 100644 --- a/compiler/ccgstmts.nim +++ b/compiler/ccgstmts.nim @@ -17,7 +17,7 @@ const proc registerTraverseProc(p: BProc, v: PSym) = var traverseProc = "" - if p.config.selectedGC in {gcMarkAndSweep, gcHooks, gcRefc} and + if v.typ.kind != tyVoid and p.config.selectedGC in {gcMarkAndSweep, gcHooks, gcRefc} and optOwnedRefs notin p.config.globalOptions and containsGarbageCollectedRef(v.loc.t): # we register a specialized marked proc here; this has the advantage @@ -1615,8 +1615,11 @@ proc genAsgn(p: BProc, e: PNode, fastAsgn: bool) = else: let le = e[0] let ri = e[1] + let letype = le.typ.skipTypes(skipPtrs) + if letype.kind == tyVoid: + return var a: TLoc - discard getTypeDesc(p.module, le.typ.skipTypes(skipPtrs), skVar) + discard getTypeDesc(p.module, letype, skVar) initLoc(a, locNone, le, OnUnknown) a.flags.incl(lfEnforceDeref) a.flags.incl(lfPrepareForMutation) diff --git a/compiler/ccgtypes.nim b/compiler/ccgtypes.nim index ff43c003d5638..60b5a7a705d97 100644 --- a/compiler/ccgtypes.nim +++ b/compiler/ccgtypes.nim @@ -427,7 +427,8 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var Rope, check: var IntSet, declareEnvironment=true; weakDep=false) = params = "(" - if t[0] == nil or isInvalidReturnType(m.config, t): + if t[0] == nil or t[0].kind == tyVoid or isInvalidReturnType(m.config, t): + rettype = "void" else: rettype = getTypeDescAux(m, t[0], check, skResult) @@ -463,7 +464,7 @@ proc genProcParams(m: BModule, t: PType, rettype, params: var Rope, params.addf(", NI $1Len_$2", [param.loc.r, j.rope]) inc(j) arr = arr[0].skipTypes({tySink}) - if t[0] != nil and isInvalidReturnType(m.config, t): + if t[0] != nil and t[0].kind != tyVoid and isInvalidReturnType(m.config, t): var arr = t[0] if params != "(": params.add(", ") if mapReturnType(m.config, t[0]) != ctArray: diff --git a/compiler/cgen.nim b/compiler/cgen.nim index 6fa60cbcd2ab2..e9969a98d4cb1 100644 --- a/compiler/cgen.nim +++ b/compiler/cgen.nim @@ -586,6 +586,8 @@ proc treatGlobalDifferentlyForHCR(m: BModule, s: PSym): bool = proc assignGlobalVar(p: BProc, n: PNode; value: Rope) = let s = n.sym + if s.typ.kind == tyVoid: return + if s.loc.k == locNone: fillBackendName(p.module, s) fillLoc(s.loc, locGlobalVar, n, OnHeap) @@ -1077,7 +1079,7 @@ proc genProcAux(m: BModule, prc: PSym) = if sfInjectDestructors in prc.flags: procBody = injectDestructorCalls(m.g.graph, m.idgen, prc, procBody) - if sfPure notin prc.flags and prc.typ[0] != nil: + if sfPure notin prc.flags and prc.typ[0] != nil and prc.typ[0].kind != tyVoid: if resultPos >= prc.ast.len: internalError(m.config, prc.info, "proc has no result symbol") let resNode = prc.ast[resultPos] diff --git a/compiler/seminst.nim b/compiler/seminst.nim index bd5eb1ec319c3..d206bb433cf71 100644 --- a/compiler/seminst.nim +++ b/compiler/seminst.nim @@ -299,7 +299,7 @@ proc instantiateProcType(c: PContext, pt: TIdTable, if result[0] != nil: propagateToOwner(result, result[0]) - eraseVoidParams(result) + #eraseVoidParams(result) skipIntLiteralParams(result, c.idgen) prc.typ = result diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 5461b7983a9d9..87fb61ed37869 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -1347,8 +1347,8 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode, if isType: localError(c.config, a.info, "':' expected") if kind in {skTemplate, skMacro}: typ = newTypeS(tyUntyped, c) - elif skipTypes(typ, {tyGenericInst, tyAlias, tySink}).kind == tyVoid: - continue + #elif skipTypes(typ, {tyGenericInst, tyAlias, tySink}).kind == tyVoid: + # continue for j in 0..