Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
p6rt opened this issue Nov 15, 2014 · 8 comments
Closed

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

p6rt opened this issue Nov 15, 2014 · 8 comments

Comments

@p6rt
Copy link

p6rt commented Nov 15, 2014

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

Searchable as RT123216$

@p6rt
Copy link
Author

p6rt commented Dec 29, 2012

From @moritz

Test file​:

sub postfix​:<_post_l_>($a) is assoc<left> is equiv(&prefix​:<+>) {
  "<$a>"
}
sub prefix​:<_pre_l_> ($a) is assoc<left> 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
Copy link
Author

p6rt commented Nov 15, 2014

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​:<MYPLUS>) {
  -$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​:<MYMINUS>) {
  [+] @​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
Copy link
Author

p6rt commented Nov 21, 2014

From @FROGGS

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

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

sub prefix​:<MYMINUS>($a) is looser(&infix​:<MYPLUS>) 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​:<MYMINUS>($a) is assoc('unary') { -$a }; say (MYMINUS 1); # works
sub prefix​:<MYMINUS>($a) is assoc('left') { -$a }; say (MYMINUS 1); # fails
sub prefix​:<MYMINUS>($a) is assoc('right') { -$a }; say (MYMINUS 1); # fails
sub prefix​:<MYMINUS>($a) is assoc('list') { -$a }; say (MYMINUS 1); # fails
sub prefix​:<MYMINUS>($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
Copy link
Author

p6rt commented Nov 21, 2014

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

@p6rt
Copy link
Author

p6rt commented Sep 9, 2015

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
Copy link
Author

p6rt commented Dec 1, 2017

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) rakudo/rakudo@2b303a0

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_⏏<EOL>
    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) rakudo/rakudo@f9f0883

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

@p6rt
Copy link
Author

p6rt commented Dec 11, 2017

From @zoffixznet

Tests​: Raku/roast@8cbbf89c9e43a65c544c05c4

@p6rt
Copy link
Author

p6rt commented Dec 11, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant