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

Wrapped method fails when precompiled #2620

Open
jonathanstowe opened this issue Jan 18, 2019 · 0 comments

Comments

Projects
None yet
2 participants
@jonathanstowe
Copy link
Contributor

commented Jan 18, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.