Looking at the B::Concise output for a sync and an async sub, there's one obvious difference: the sync sub starts with a NEXTSTATE op, while the async one doesn't.
$ perl -MO=Concise,-exec,foo -e 'sub foo { eval { 42 } }'
main::foo:
1 <;> nextstate(main 2 -e:1) v:{
2 <|> entertry(other->3)
5 <;> nextstate(main 3 -e:1) v
6 <$> const(IV 42) s
3 <@> leavetry K
4 <1> leavesub[1 ref] K/REFC,1
-e syntax OK
$ perl -MO=Concise,-exec,foo -MFuture::AsyncAwait -e 'async sub foo { 42 }'
main::foo:
1 <0> pushmark v
2 <|> entertry(other->3) l
6 <;> nextstate(main 1733 -e:1) v:%
7 <$> const(IV 42) s
3 <@> leavetry lK
4 <1> leaveasync s
5 <1> leavesub[1 ref] K/REFC,1
-e syntax OK
The attached patch fixes this, and makes coverage work.
$ perl -Mblib -MO=Concise,-exec,foo -MFuture::AsyncAwait -e 'async sub foo { 42 }'
main::foo:
1 <;> nextstate(main 1698 -e:1) v:%,{
2 <0> pushmark v
3 <|> entertry(other->4) l
7 <;> nextstate(main 1700 -e:1) v:%
8 <$> const(IV 42) s
4 <@> leavetry lK
5 <1> leaveasync s
6 <1> leavesub[1 ref] K/REFC,1
-e syntax OK
From 1a3e00239965f432029b91f95498e6cb9048e508 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Dagfinn=20Ilmari=20Manns=C3=A5ker?= <ilmari@ilmari.org>
Date: Thu, 25 Apr 2019 12:15:41 +0100
Subject: [PATCH] Make sure the body of an async sub starts with an OP_NEXSTATE
Omitting it confuses Devel::Cover so it can't see the code inside the sub.
---
lib/Future/AsyncAwait.xs | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/Future/AsyncAwait.xs b/lib/Future/AsyncAwait.xs
index 916e8f2..bff684c 100644
--- a/lib/Future/AsyncAwait.xs
+++ b/lib/Future/AsyncAwait.xs
@@ -1826,10 +1826,11 @@ static int async_keyword_plugin(pTHX_ OP **op_ptr)
body = block_end(save_ix, body);
/* turn block into
- * PUSHMARK; eval { BLOCK }; LEAVEASYNC
+ * NEXTSTATE; PUSHMARK; eval { BLOCK }; LEAVEASYNC
*/
- OP *op = newLISTOP(OP_LINESEQ, 0, newOP(OP_PUSHMARK, 0), NULL);
+ OP *op = newSTATEOP(0, NULL, NULL);
+ op = op_append_elem(OP_LINESEQ, op, newOP(OP_PUSHMARK, 0));
OP *try;
op = op_append_elem(OP_LINESEQ, op, try = newUNOP(OP_ENTERTRY, 0, body));
--
2.21.0