[perl #129790] [OPTIMIZER] Giving a sub to a map fails

[email protected] ("Zoffix Znet via RT")
Newsgroups perl.perl6.compiler
Message-ID <[email protected]>
On Sat, 14 Oct 2017 18:38:47 -0700, [email protected] wrote:
> Maybe it is worth noting that this is pretty much a regression (even
> though an
> old one, and caused by a non-optimizer change).
> 
> (2016-08-09)
> https://github.com/rakudo/rakudo/commit/328402599c16077e182bb38baf68e435b8bc1082
> 
> Output before and after:
> https://gist.github.com/75b15f93438bd038cf0bec26c43eaa9f
> 
> On 2016-10-03 01:32:09, [email protected] wrote:
> > Playing around I found that the following change made your examples
> > work as expected:
> >
> > diff --git a/src/Perl6/Optimizer.nqp b/src/Perl6/Optimizer.nqp
> > index 12398ba..9102b7f 100644
> > --- a/src/Perl6/Optimizer.nqp
> > +++ b/src/Perl6/Optimizer.nqp
> > @@ -1082,7 +1082,8 @@ class Perl6::Optimizer {
> > || nqp::istype($op[0][0], QAST::Stmts) &&
> > nqp::istype(($c1 := $op[0][0][0]), QAST::Op)
> > &&
> > nqp::existskey(%range_bounds, $c1.name)) &&
> > - $!symbols.is_from_core($c1.name) {
> > + $!symbols.is_from_core($c1.name) &&
> > + nqp::defined($op[0][1].ann('code_object')) {
> > self.optimize_for_range($op, $op[0][1], $c1);
> > self.visit_op_children($op);
> > return $op;
> >
> > $ ./perl6 -e '^4 .map: {};'
> > Cannot map a Range to a Hash.
> > Did you mean to add a stub ({...}) or did you mean to .classify?
> > in block <unit> at -e line 1
> >
> > $ ./perl6 -e '^4 .map: 42;'
> > Cannot resolve caller map(Range: Int); none of these signatures
> > match:
> > ($: Hash \h, *%_)
> > (\SELF: &block;; :$label, :$item, *%_)
> > (HyperIterable:D $: &block;; :$label, *%_)
> > in block <unit> at -e line 1
> >
> > $ ./perl6 -e 'sub foo ($) {say "meow"}; ^4 .map: &foo;'
> > meow
> > meow
> > meow
> > meow
> >
> > The original error came from the first two lines in 'method
> > optimize_for_ranges' in src/Perl6/Optimizer.nqp. For some reason
> > $callee.ann('code_object') did not return a code object as expected.
> >
> > method optimize_for_range($op, $callee, $c2) {
> > my $code := $callee.ann('code_object');
> > my $count := $code.count;
> >
> > Now, I have no idea whether my change from above makes sense or
> > whether the annotation for 'code_object' was wrong in the first
> > place.


Thank you for the report. This is now fixed in branch `post-release`.

Fix:  https://github.com/rakudo/rakudo/commit/f3efe5e6b4a9ee5
Test: https://github.com/rakudo/rakudo/commit/f3efe5e6b4a9ee5
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.