Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Centralize more precompilation code
  • Loading branch information
niner committed Jan 9, 2016
1 parent be32628 commit 9932802
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 33 deletions.
21 changes: 21 additions & 0 deletions src/core/CompUnit/PrecompilationRepository.pm
Expand Up @@ -22,6 +22,27 @@ class CompUnit::PrecompilationRepository::Default does CompUnit::PrecompilationR

my $lle;

method try-load(CompUnit::PrecompilationId $id, IO::Path $source) returns CompUnit::Handle {
my $handle = (
self.may-precomp and (
self.load($id, :since($source.modified)) # already precompiled?
or self.precompile($source, $id) and self.load($id) # if not do it now
)
);
my $precompiled = ?$handle;

if $*W and $*W.is_precompilation_mode {
if $precompiled {
say "$id $source";
}
else {
nqp::exit(0);
}
}

$handle ?? $handle !! Nil
}

method !load-handle-for-path(IO::Path $path) {
my $preserve_global := nqp::ifnull(nqp::gethllsym('perl6', 'GLOBAL'), Mu);
if $*RAKUDO_MODULE_DEBUG -> $RMD { $RMD("Loading precompiled $path") }
Expand Down
26 changes: 8 additions & 18 deletions src/core/CompUnit/Repository/FileSystem.pm
Expand Up @@ -75,26 +75,16 @@ class CompUnit::Repository::FileSystem does CompUnit::Repository::Locally does C

my $id = nqp::sha1($name ~ $*REPO.id);
my $*RESOURCES = Distribution::Resources.new(:repo(self), :dist-id(''));
my $handle = (
$precomp.may-precomp and (
$precomp.load($id, :since($file.modified)) # already precompiled?
or $precomp.precompile($file, $id) and $precomp.load($id) # if not do it now
)
);
my $precompiled = ?$handle;

if $*W and $*W.is_precompilation_mode {
if $precompiled {
say "$id $file";
}
else {
nqp::exit(0);
}
}
$handle ||= CompUnit::Loader.load-source-file($file); # precomp failed
my $handle = $precomp.try-load($id, $file);
my $precompiled = defined $handle;
$handle //= CompUnit::Loader.load-source-file($file); # precomp failed

return %!loaded{$name} = %seen{$base} = CompUnit.new(
:short-name($name), :$handle, :repo(self), :repo-id($id), :$precompiled
:short-name($name),
:$handle,
:repo(self),
:repo-id($id),
:$precompiled,
);
}

Expand Down
17 changes: 2 additions & 15 deletions src/core/CompUnit/Repository/Installation.pm
Expand Up @@ -298,24 +298,11 @@ sub MAIN(:$name is copy, :$auth, :$ver, *@, *%) {
$dist<provides>{$spec.short-name}<pm pm6>.first(*.so)<file>
);
my $*RESOURCES = Distribution::Resources.new(:repo(self), :$dist-id);
my $handle;
my $id = $loader.basename;
if $precomp.may-precomp {
$handle = (
$precomp.load($id, :since($loader.modified)) # already precompiled?
or $precomp.precompile($loader, $id) and $precomp.load($id) # if not do it now
);
if $*W and $*W.is_precompilation_mode {
if $handle {
say "$id $loader";
}
else {
nqp::exit(0);
}
}
}
my $handle = $precomp.try-load($id, $loader);
my $precompiled = defined $handle;
$handle //= CompUnit::Loader.load-source-file($loader);

my $compunit = CompUnit.new(
:$handle,
:short-name($spec.short-name),
Expand Down

0 comments on commit 9932802

Please sign in to comment.