Raku / old-issue-tracker

Tickets from RT
https://github.com/Raku/old-issue-tracker/issues
2 stars 1 forks source link

QRPA: Can't pop from an empty array! #3585

Closed p6rt closed 6 years ago

p6rt commented 9 years ago

Migrated from rt.perl.org#123216 (status was 'resolved')

Searchable as RT123216$

p6rt commented 11 years ago

From @moritz

Test file​:

sub postfix​:\<_post_l_>($a) is assoc\ is equiv(&prefix​:\<+>) {   "\<$a>" } sub prefix​:\<_pre_l_> ($a) is assoc\ is equiv(&prefix​:\<+>) {   "($a)" } _pre_l_ 'a' _post_l_

./perl6 -Ilib foo.pl ===SORRY!=== ResizablePMCArray​: Can't pop from an empty array!

Maybe also of interest​:

./perl6 --ll-exception -Ilib foo.pl ResizablePMCArray​: Can't pop from an empty array! current instr.​: 'EXPR_reduce' pc 15766 (src/stage2/gen/NQPHLL.pir​:5721) (src/stage2/gen/NQPHLL.pm​:688) called from Sub 'EXPR' pc 15628 (src/stage2/gen/NQPHLL.pir​:5657) (src/stage2/gen/NQPHLL.pm​:489) called from Sub 'EXPR' pc 207808 (src/gen/perl6-grammar.pir​:69050) (src/Perl6/Grammar.pm​:2845) called from Sub 'statement' pc 58086 (src/gen/perl6-grammar.pir​:20310) (src/Perl6/Grammar.pm​:929) called from Sub 'statementlist' pc 56325 (src/gen/perl6-grammar.pir​:19748) (src/Perl6/Grammar.pm​:903) called from Sub 'comp_unit' pc 51125 (src/gen/perl6-grammar.pir​:17855) (src/Perl6/Grammar.pm​:702) called from Sub 'TOP' pc 20860 (src/gen/perl6-grammar.pir​:7632) (src/Perl6/Grammar.pm​:334)

the exception comes from this part here​:

  op_infix​:   .local pmc right, left   right = pop termstack   left = pop termstack # \<-- HERE   op[0] = left   op[1] = right   $P0 = opO['reducecheck']   if null $P0 goto op_infix_1   $S0 = $P0   self.$S0(op)

p6rt commented 9 years ago

From zheglov1887@gmail.com

Not sure what is causing this (using Perl only a few days). I have the following example

  use v6 ;   sub infix​:«MYPLUS»(*@​a) is assoc('list') {   [+] @​a ;   }

  sub prefix​:«MYMINUS»($a) is looser(&infix​:\) {   -$a ;   }

  # QRPA​: Can't pop from an empty array!   say (MYMINUS 1 MYPLUS 2 MYPLUS 3) ;

However the following equivalent example works as expected

  use v6 ;   sub prefix​:«MYMINUS»($a) {   -$a ;   }

  sub infix​:«MYPLUS»(*@​a) is assoc('list') is tighter(&prefix​:\) {   [+] @​a ;   }

  # prints -6 as expected   say (MYMINUS 1 MYPLUS 2 MYPLUS 3) ;

Output of perl6 --version is This is perl6 version 2014.10-121-g7dd7292 built on parrot 6.9.0 revision RELEASE_6_9_0-72-g4b90157

Thanks, Vladimir

p6rt commented 9 years ago

From @FROGGS

The prefix op must be unary, so this works​:

sub infix​:\(*@​a) is assoc('list') { [+] @​a }

sub prefix​:\($a) is looser(&infix​:\) is assoc('unary') { -$a }

say (MYMINUS (1 MYPLUS 2 MYPLUS 3)); # -6

The problem and the weird (LTA) error message turn up when the prefix op has any other assoc, for example​:

sub prefix​:\($a) is assoc('unary') { -$a }; say (MYMINUS 1); # works sub prefix​:\($a) is assoc('left') { -$a }; say (MYMINUS 1); # fails sub prefix​:\($a) is assoc('right') { -$a }; say (MYMINUS 1); # fails sub prefix​:\($a) is assoc('list') { -$a }; say (MYMINUS 1); # fails sub prefix​:\($a) is assoc('non') { -$a }; say (MYMINUS 1); # fails

I don't what would be the best way to solve that error message. 1) make prefix ops unary by default? 2) complain about prefix ops that are not unary, and suggest to make them unary? 3) both?

p6rt commented 9 years ago

The RT System itself - Status changed from 'new' to 'open'

p6rt commented 9 years ago

From @ShimmerFairy

There is no unary associativity, according to S03​:

  Using two ! symbols below generically to represent any pair of operators that   have the same precedence, the associativities specified above for binary operators   are interpreted as follows​:

  Assoc Meaning of $a ! $b ! $c   ===== =========================   L left ($a ! $b) ! $c   R right $a ! ($b ! $c)   N non ILLEGAL   C chain ($a ! $b) and ($b ! $c)   X list infix​:\<!>($a; $b; $c)   O N/A (not really an operator)

  For unaries this is interpreted as​:

  Assoc Meaning of !$a!   ===== =========================   L left (!$a)!   R right !($a!)   N non ILLEGAL

So on the surface I think the issue here is that rakudo is using a 'unary' associativity as a cheat, rather than correctly implementing unary associativities. (S03 further notes that standard Perl 6 doesn't take advantage of associativity on unaries, since it keeps each level consistently prefix/postfix, which would explain why rakudo can get away with a 'unary' assoc for standard P6)

p6rt commented 6 years ago

From @AlexDaniel

Heh, what a clusterfuck! OK let's try to untangle this ticket.

The second issue mentioned in this ticket (MVMArray​: Can't pop from an empty array) was fixed. ✓ Output on all releases​: https://gist.github.com/Whateverable/5d30c8b09af4ddee8bdb67693cd0f6e0 Fixed in (2015-03-30) https://github.com/rakudo/rakudo/commit/2b303a0dcffdda7f833ff9bef01a6e833e2c2422

Therefore, 「testneeded」.

As for the OP, it seems to be fixed too, but the code is probably not supposed to work. See​:

'a' _post_l_

↑ There's whitespace before the postfix and that's not supposed to work. It also doesn't help that the chosen operator is a valid identifier.

That said​:   say _pre_l_ 'a'_post_l_ # OUTPUT​:

===SORRY!=== Error while compiling /home/alex/./deleteme.pm6 Operators '_pre_l_ ' and '_post_l_' are non-associative and require parentheses at /home/alex/./deleteme.p6​:7 ------> say _pre_l_ 'a'_post_l_⏏\     expecting any of​:         postfix

As per the last comment, there's no unary associativity, so my best guess is that it is not supposed to work (at least at this point).

So we can change the code like the error message suggests​:

say (_pre_l_ 'a')_post_l_ # OUTPUT​: «\<(a)>␤»

Note that the other way is not going to work because it looks too much like a method call. But that works! ✓

Here's the output on all releases​: https://gist.github.com/Whateverable/f80d6512dedef6a7914d9d24a7f27138 And that's when it was fixed​: (2017-04-04) https://github.com/rakudo/rakudo/commit/f9f0883c6cef3695c5150d336f5e6552e1be4a4c

So I'd say 「testneeded」 (that is, two tests needed), but see RT#​131099 for further progress on assoc with non-infix ops.

p6rt commented 6 years ago

From @zoffixznet

Tests​: https://github.com/perl6/roast/commit/8cbbf89c9e43a65c544c05c4

p6rt commented 6 years ago

@zoffixznet - Status changed from 'open' to 'resolved'