Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to flush precompiled perl6 modules?

I am trying to refactor some code. My approach (using vi) is to copy my old libraries from /lib to /lib2. That way I can hack out big sections, but still have a framework to refactor.

So I go ahead and change mymain.p6 header from use lib '../lib'; to use lib '../lib2';. Then I delete a chunk of the lines in ../lib2/mylibrary.pm6 and make darn sure :w is doing what I expect.

Imagine my surprise when my program still works perfectly despite having been largely deleted. It even works when I rm -R /lib, so nothing back there is persisting.

Is there a chance that I have a precomp of the old lib module lying around? If so, how can I flush it?

This is Rakudo Star version 2019.03.1 built on MoarVM version 2019.03 implementing Perl 6.d.

like image 989
p6steve Avatar asked Aug 12 '19 18:08

p6steve


2 Answers

Precompiled modules are stored in the precomp directory. You can try to rename or delete the ~/.precomp directory.

See also this SO question here.

like image 124
LuVa Avatar answered Nov 23 '22 19:11

LuVa


Update. Well I thought I'd replicated the scenario. It was reliably showing the bug during a one hour period. But now it isn't. Which is pretty disturbing. Investigation continues...


I've replicated @p6steve's scenario in case someone wishes to report this as a bug. At the moment I'm with @p6steve (per comment below) in that I'm going to treat this as a DIHWIDT rather than a reportable bug. That said, now we have a golf'd summary.

Original main program using path1 followed by the module it uses directly and then the one that uses:

use lib 'path1';
use lib1;
say $lib1::value;

unit module lib1;
use lib2;
our $value = $lib2::value;

unit module lib2;
our $value = 1;

This displays 1.

If the libs are copied to a fresh directory, including the .precomp directory, and then the lib2 is edited but the lib1 is not, the change to lib2 is ignored.

Here it is on glot.io before and after copying the libs and their .precomp directory and then editing the libs.

Original answer

Thank you for editing your question. That gives us all more to go on. :)

I'd like to try to get to the bottom of it and hope you're willing to have a go too. This (n)answer and comments below it will record our progress.

From your comment on @ValleLukas' answer:

Then I noticed ../lib2/.precomp directory - so realised library precomps are stored in the library folder. That did the job!

Here's my first guess at what happened:

You copied lib en masse to lib2. This copied the precomp directory with it.

You modified the use lib ... statement in mymain.p6 to refer to lib2.

Your mymain.p6 code includes a use module-that-directly-or-indirectly-uses-mylibrary.

You modify mylibrary.pm6.

But nothing changes! Why not?

You haven't touched module-that-directly-or-indirectly-uses-mylibrary, so Rakudo uses the precompiled version of that module from the lib2/.precomp directory.

Speculating...

Perhaps the fact that that precompiled version exists leads the precompilation logic to presume that if it also finds a precompiled version of a module that's used by module-that-directly-or-indirectly-uses-mylibrary then it can go ahead and use that and not even bother to check how its timestamp compares to the source version.

Does this match your scenario? If not, which bits does it get wrong?

like image 34
raiph Avatar answered Nov 23 '22 17:11

raiph