Skip Menu |

This queue is for tickets about the Future-AsyncAwait CPAN distribution.

Report information
The Basics
Id: 128309
Status: resolved
Priority: 0/
Queue: Future-AsyncAwait

People
Owner: Nobody in particular
Requestors: leonerd-cpan [...] leonerd.org.uk
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.20
Fixed in: 0.25



Subject: Devel::Cover can't see into async subs
Taking some F:AA-based source and running $ cover -test gives some misleading output. Devel::Cove doesn't report any lines of code inside `async sub`s as being hit, but it also doesn't report them as _not_ being hit. It literally doesn't think there's code there. (Devel::Cover version 1.31) -- Paul Evans
For comparison, nytprof can see inside them fine. -- Paul Evans
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
Subject: 0001-Make-sure-the-body-of-an-async-sub-starts-with-an-OP.patch
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
Thanks. That applies cleanly and doesn't upset any of my test perls. Now applied. -- Paul Evans
Fix released in 0.25. -- Paul Evans