async macro: general stability improvements [bugfix] (#11787)

This commit is contained in:
Andreas Rumpf
2019-07-19 16:47:38 +02:00
committed by GitHub
parent 903d06bab8
commit 70e8551e37

View File

@@ -129,7 +129,7 @@ proc processBody(node, retFutureSym: NimNode,
result.add newNimNode(nnkReturnStmt, node).add(newNilLit())
return # Don't process the children of this return stmt
of nnkCommand, nnkCall:
if node[0].kind == nnkIdent and node[0].eqIdent("await"):
if node[0].eqIdent("await"):
case node[1].kind
of nnkIdent, nnkInfix, nnkDotExpr, nnkCall, nnkCommand:
# await x
@@ -142,7 +142,7 @@ proc processBody(node, retFutureSym: NimNode,
else:
error("Invalid node kind in 'await', got: " & $node[1].kind)
elif node.len > 1 and node[1].kind == nnkCommand and
node[1][0].kind == nnkIdent and node[1][0].eqIdent("await"):
node[1][0].eqIdent("await"):
# foo await x
var newCommand = node
result.createVar("future" & $node[0].toStrLit, node[1][1], newCommand[1],
@@ -151,7 +151,7 @@ proc processBody(node, retFutureSym: NimNode,
of nnkVarSection, nnkLetSection:
case node[0][^1].kind
of nnkCommand:
if node[0][^1][0].kind == nnkIdent and node[0][^1][0].eqIdent("await"):
if node[0][^1][0].eqIdent("await"):
# var x = await y
var newVarSection = node # TODO: Should this use copyNimNode?
result.createVar("future" & node[0][0].strVal, node[0][^1][1],
@@ -167,7 +167,7 @@ proc processBody(node, retFutureSym: NimNode,
else: discard
of nnkDiscardStmt:
# discard await x
if node[0].kind == nnkCommand and node[0][0].kind == nnkIdent and
if node[0].kind == nnkCommand and
node[0][0].eqIdent("await"):
var newDiscard = node
result.createVar("futureDiscard_" & $toStrLit(node[0][1]), node[0][1],
@@ -358,16 +358,15 @@ proc stripAwait(node: NimNode): NimNode =
case node.kind
of nnkCommand, nnkCall:
if node[0].kind == nnkIdent and node[0].eqIdent("await"):
if node[0].eqIdent("await"):
node[0] = emptyNoopSym
elif node.len > 1 and node[1].kind == nnkCommand and
node[1][0].kind == nnkIdent and node[1][0].eqIdent("await"):
elif node.len > 1 and node[1].kind == nnkCommand and node[1][0].eqIdent("await"):
# foo await x
node[1][0] = emptyNoopSym
of nnkVarSection, nnkLetSection:
case node[0][^1].kind
of nnkCommand:
if node[0][^1][0].kind == nnkIdent and node[0][^1][0].eqIdent("await"):
if node[0][^1][0].eqIdent("await"):
# var x = await y
node[0][^1][0] = emptyNoopSym
else: discard
@@ -380,8 +379,7 @@ proc stripAwait(node: NimNode): NimNode =
else: discard
of nnkDiscardStmt:
# discard await x
if node[0].kind == nnkCommand and node[0][0].kind == nnkIdent and
node[0][0].eqIdent("await"):
if node[0].kind == nnkCommand and node[0][0].eqIdent("await"):
node[0][0] = emptyNoopSym
else: discard
@@ -441,3 +439,8 @@ macro multisync*(prc: untyped): untyped =
result = newStmtList()
result.add(asyncSingleProc(asyncPrc))
result.add(sync)
proc await*[T](x: T) =
## The 'await' keyword is also defined here for technical
## reasons. (Generic symbol lookup prepass.)
{.error: "Await only available within .async".}