develooper Front page | perl.perl5.porters | Postings from July 2021

Re: RFC 0004 - defer {} syntax

Thread Previous | Thread Next
Dave Mitchell
July 5, 2021 15:39
Re: RFC 0004 - defer {} syntax
Message ID:
On Wed, Jun 16, 2021 at 11:15:40PM +0100, Paul "LeoNerd" Evans wrote:
> # defer {} syntax

Just a few random thoughts and observations:

First, I approve of the idea and the name.

* What value does defer return (in either scalar and list context)? E.g.

    sub foo { defer { BLOCK } }
    my $x = foo(); # what is $x?
    my @x = foo(); # what is @x?

    # (while I assume this is a syntax error):
    my $x = defer { BLOCK };

* Does your implementation handle Deparse ok? (and B, Concise etc?)

* Does it  peephole optimise the BLOCK? And does it test for it?

I usually test for this by putting an $a[0] in the code block and then
checking in t/perf/opcount.t that there is at least one aelemfast op
(which is what small constant array indices are optimised to).

* is it called on die(), exit(), exception, etc?

Is it clearly documented (and tested) what it does for every possible type
of scope exit?  I see it croaks on last etc. Destructors are called on
exit() - is a defer block too?

* what happens if the sub gets deleted mid-flow:

    sub foo {
        defer { delete $::{foo} }
        defer { .. do more stuff .. } # might this SEGV?

Decaffeinated coffee is like dehydrated water

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About