jit-experiments icon indicating copy to clipboard operation
jit-experiments copied to clipboard

Loop/scope AST corner cases?

Open tsee opened this issue 11 years ago • 4 comments

It seems there's a number of funky corner cases around blocks and loops where ASTification currently DWI don't Ms. Just so I don't have to shave yaks right now.

A few examples:

perl author_tools/jit_ast_dump.pl -c -e 'do{}'

segfaults.

perl author_tools/jit_ast_dump.pl -c -e 'foreach my $x (1..10) {1}'

gives a bare StatementSequence for the block.

perl author_tools/jit_ast_dump.pl -c -e 'my $x = 1; do{1}; $x = 1;'

Does not produce a single StatementSequence to hold it all:

----------------------------------------------
# StatementSequence
#   Statement (eval 13):1
#     Binop 'sassign' (
#       VD ($) = 1 : Any
#       C = (IV)1
#     )
----------------------------------------------
# StatementSequence
#   Statement (eval 13):1
#     Binop 'sassign' (
#       V ($) = 1 : Any
#       C = (IV)1
#     )
----------------------------------------------
# Block 'scope' (
#   'UnJITable subtree'
# )
----------------------------------------------
B::Concise::compile(CODE(0x1afcee0))
a  <1> leavesub[1 ref] K/REFC,1 ->(end)
-     <@> lineseq KP ->a
1        <;> nextstate(main 2 (eval 13):1) v:%,2048 ->2
4        <2> sassign vKS/2 ->5
2           <$> const[IV 1] s ->3
3           <0> padsv[$x:2,4] sRM*/LVINTRO ->4
5        <;> nextstate(main 4 (eval 13):1) v:%,2048 ->6
-        <1> null vK*/1 ->6
-           <@> scope vK ->-
-              <0> ex-nextstate v ->-
-              <0> ex-const v ->-
6        <;> nextstate(main 4 (eval 13):1) v:%,{,2048 ->7
9        <2> sassign sKS/2 ->a
7           <$> const[IV 1] s ->8
8           <0> padsv[$x:2,4] sRM* ->9

tsee avatar Oct 07 '13 16:10 tsee

Fixed the segfault on the first case, and the AST for the second case.

While looking for a proper fix for cases 1 and 3, I found this snippet, and I'm not sure whether it handles the case of an empty do{}, so I can refactor it as part of the fix, or it handles another case entirely

    // empty list is not really a kid, don't include in child list
    delete kid_term;
    // FIXME segv on "perl author_tools/jit_ast_dump.pl -c -e '@x = () x 12'" since the OP_STUB is "important"

mbarbon avatar Oct 07 '13 21:10 mbarbon

The FIXME is clearly another case.

Funnily enough, I had a fix for do{} myself but failed to commit/push it before the train arrived.

Rats.

By the way: keyword plugin for "for" works as you say, but will require a complete rewrite of all the keyword plugin code we have so far.

tsee avatar Oct 08 '13 04:10 tsee

You mean for the segfault or for the 3rd case? In the latter case feel free to push it (I haven't finished the fix yet).

mbarbon avatar Oct 08 '13 06:10 mbarbon

No, the do{} segv. That was a trivial fix, though, so no harm done.

Curiously, my fix was to put an Empty into the block, whereas you chose not to ASTify it at all (according to my one-liner). Is that on purpose?

tsee avatar Oct 08 '13 06:10 tsee