Rakudo: Wrapped method fails when precompiled

Created on 18 Jan 2019  路  3Comments  路  Source: rakudo/rakudo

This was originally reported in RT (https://rt.perl.org/Public/Bug/Display.html?id=127860) but I've re-tested and it still occurs:

Original 2016 ticket

It appears that the Metamodel::WrapDispatcher can't find the candidate to execute when the wrapped method is pre-compiled.

This can be recreated in several ways, first by wrapping the method in an over-ridden add_method:

lib/Vum.pm:

class MetamodelX::FooHOW is Metamodel::ClassHOW {
    method add_method(Mu \type, $name, &code) {
        say "adding $name";
        my &wrapper = method (|c) { say "running $name"; callsame; };
        &code.wrap( &wrapper );
        self.Metamodel::ClassHOW::add_method(type, $name, &code);
   }
   method compose(Mu \type) {
       self.Metamodel::ClassHOW::compose(type);
   }
}

my package EXPORTHOW {
    package SUPERSEDE {
       constant class = MetamodelX::FooHOW;
    }
}

And lib/Boo.pm :

use Vum;

#no precompilation;

class Boo {
   has $.rabble;
   method rack() {
      say "rabble : ";
   }
}

And exercised with "perl6 -Ilib ...":

use Boo;

my $b = Boo.new(rabble => "hoodoo");

say $b.rack;

This will fail with:

Cannot invoke this object
  in method <anon> at /home/jonathan/devel/perl6/Vum/lib/Vum.pm (Vum) line 4
  in any enter at gen/moar/m-Metamodel.nqp line 3947
  in block <unit> at tt line 5

(Which points to the enter method of WrapDispatch.) Which would appear that it is not getting the appropriate Callable from .candidates[0]. With the "no precompilation" un-commented in Boo.pm this will work fine.

Just to check that this wasn't something mysterious in the MOP it can also be replicated with:

lib/Wom.pm:

module Wom {
   multi sub trait_mod:<is>(Method $m, :$brapped!) is export {
      $m.wrap(method (|c) { say "wrapped"; callsame });
   }
}

lib/Bok.pm:

use Wom;

#no precompilation;

class Bok {
   has $.rabble;
   method rack() is brapped {
      say "rabble : ";
   }
}

And exercised with the similar script run with "perl6 -Ilib ..." :

use Bok;

my $b = Bok.new(rabble => "hoodoo");

say $b.rack;

Then this will also fail identically without the "no precompilation".

This afflicts OO::Monitors in the ecosystem which cannot be used in a module that will be precompiled, and I suspect this is also at the heart of a problem with Staticish which similarly doesn't work if used in a module which is precompiled.

This is with:

This is Rakudo version 2016.03-98-g61d231c built on MoarVM version 2016.03-84-g4afd7b6

2019 Update

I've retested with

This is Rakudo version 2018.12-122-g5625ebc15 built on MoarVM version 2018.12-13-g473324ee3
implementing Perl 6.d.

And the results are the same. Additionally I have added use soft in the modules and it doesn't make any difference to the result.

precompilation

Most helpful comment

perl6/roast#518

All 3 comments

Both cases are fixed. Most likely with #2749.

Confirmed. Hopefully tested so it doesn't recur.

perl6/roast#518

Was this page helpful?
0 / 5 - 0 ratings