Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use :since with CompUnit

Tags:

raku

I am trying to create a cache of POD6 by precompiling them using the CompUnit set of classes.

I can create, store and retrieve pod as follows:

use v6.c;
use nqp;
my $precomp-store =     CompUnit::PrecompilationStore::File.new(prefix=>'cache'.IO);
my $precomp = CompUnit::PrecompilationRepository::Default.new(store=> $precomp-store );
my $key = nqp::sha1('test.pod6');
'test.pod6'.IO.spurt(q:to/CONTENT/);
=begin pod
=TITLE More and more

Some more text

=end pod

CONTENT
$precomp.precompile('test.pod6'.IO, $key, :force);
my $handle = $precomp.load($key, )[0];
my $resurrected = nqp::atkey($handle.unit,'$=pod')[0];
say $resurrected ~~ Pod::Block::Named;

So now I change the POD, how do I use the :since flag? I thought that if :since contains a time after the compilation, then the value of the handle would be Nil. That does not seem to be the case.

my $new-handle = $precomp.load($key, :since('test.pod6'.IO.modified));
say 'I got a new handle' with $new-handle;

Output is 'I got a new handle'.

What I am doing wrong? Here is a pastebin link with code and output: https://pastebin.com/wtA9a0nP

like image 604
Richard Hainsworth Avatar asked Oct 26 '18 08:10

Richard Hainsworth


People also ask

Can I use past perfect with since?

FOR and SINCE can also both be used with the past perfect. SINCE can only be used with perfect tenses. FOR can also be used with the simple past.

Do we put comma after since?

As and since We usually put a comma before since after the main clause: [result]I hope they've decided to come as [reason]I wanted to hear about their India trip. [result]They're rather expensive, since [reason]they're quite hard to find. We often use as and since clauses at the beginning of the sentence.

How do you use since in a sentence?

I haven't eaten since breakfast. Since the party, she has not spoken to him at all. The company has been in its present location since the beginning of the century. We've been waiting for you since 10 o'clock.


1 Answers

Module loading code caches look ups and essentially start with:

$lock.protect: { 
    return %loaded{$id} if %loaded{$id}:exists; 
}

So the question becomes "how do I load a module and then unload it (so i can load it again)?" to which the answer is: you cannot unload a module. You can however change the filename, distribution longname ( via changing the name, auth, api, or version ), or precomp id -- whatever a specific CompUnit::Repository uses to uniquely identify modules -- to bypass the cache.

What seems to be overlooked is that $key is intended to represent an immutable name, such that it will always point at the same content. What version of foo.pm should be loaded for Module Used::Inside::A if foo.pm is being loaded by Module A and B at the same time, Module A loads foo first, and then Module B modifies foo? The old version Module A loaded, or the ( possibly conflicting with previous version ) Module B loaded version? And how would this differentiation work for precomp file generation themselves ( which again can happen in parallel )?

Of course if we ignore the above we could add code to make expensive .IO.modified calls for every single module load for all CompUnit::Repository types ( slowing down startup speed ) to say "hey this immutable thing changed". But the granularity of file system modified timestamps on some OS's made the check pretty fragile ( especially for multi-threaded module loading with precomp files being generated ), meaning that even more expensive calls to get a checksum would be necessary every single time.

like image 191
ugexe Avatar answered Oct 22 '22 21:10

ugexe