Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Store logical file names in precomp files
We now use logical file names for annotating sources and construct absolute
paths when printing stack traces. This avoids storing absolute paths in
precompiled files which is a problem for packaging modules for Linux
distributions. It also allows for us to add the name of the requested
module to the backtrace output, alleviating the problem with the undeciferable
SHA-1 file names.
  • Loading branch information
niner committed Feb 21, 2016
1 parent 1066947 commit 37440f0
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 17 deletions.
6 changes: 6 additions & 0 deletions src/core/Backtrace.pm
@@ -1,6 +1,7 @@
my class Exception { ... }

my class Backtrace { ... }
my class CompUnit::RepositoryRegistry is repr('Uninstantiable') { ... }

my $RAKUDO-VERBOSE-STACKFRAME;

Expand Down Expand Up @@ -94,6 +95,11 @@ my class Backtrace {
my $file := $annotations<file>;
next unless $file;

my @parts = $file.split('#', 2);
if @parts.elems == 2 {
$file := CompUnit::RepositoryRegistry.repository-for-name(@parts[0]).prefix.child(@parts[1]).abspath;
}

# now *that's* an evil hack
next if $file.ends-with('BOOTSTRAP.nqp')
|| $file.ends-with('QRegex.nqp')
Expand Down
7 changes: 4 additions & 3 deletions src/core/CompUnit/PrecompilationRepository.pm
Expand Up @@ -23,11 +23,11 @@ class CompUnit::PrecompilationRepository::Default does CompUnit::PrecompilationR
my $lle;
my $profile;

method try-load(CompUnit::PrecompilationId $id, IO::Path $source) returns CompUnit::Handle {
method try-load(CompUnit::PrecompilationId $id, IO::Path $source, :$source-name) 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
or self.precompile($source, $id, :$source-name) and self.load($id) # if not do it now
)
);
my $precompiled = ?$handle;
Expand Down Expand Up @@ -107,7 +107,7 @@ class CompUnit::PrecompilationRepository::Default does CompUnit::PrecompilationR
}
}

method precompile(IO::Path:D $path, CompUnit::PrecompilationId $id, Bool :$force = False) {
method precompile(IO::Path:D $path, CompUnit::PrecompilationId $id, Bool :$force = False, :$source-name) {
my $compiler-id = $*PERL.compiler.id;
my $io = self.store.destination($compiler-id, $id);
my $RMD = $*RAKUDO_MODULE_DEBUG;
Expand Down Expand Up @@ -141,6 +141,7 @@ class CompUnit::PrecompilationRepository::Default does CompUnit::PrecompilationR
$profile,
"--target=" ~ Rakudo::Internals.PRECOMP-TARGET,
"--output=$io",
"--source-name=$source-name",
$path,
:out,
);
Expand Down
2 changes: 1 addition & 1 deletion src/core/CompUnit/Repository/FileSystem.pm
Expand Up @@ -75,7 +75,7 @@ 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.try-load($id, $file);
my $handle = $precomp.try-load($id, $file, :source-name("$file ($spec.short-name())"));
my $precompiled = defined $handle;
$handle //= CompUnit::Loader.load-source-file($file); # precomp failed

Expand Down
53 changes: 41 additions & 12 deletions src/core/CompUnit/Repository/Installation.pm
Expand Up @@ -151,6 +151,12 @@ sub MAIN(:$name is copy, :$auth, :$ver, *@, *%) {
$!version = 1;
}

method !repo-prefix() {
my $repo-prefix = CompUnit::RepositoryRegistry.name-for-repository(self) // '';
$repo-prefix ~= '#' if $repo-prefix;
$repo-prefix
}

method install(Distribution $dist, %sources, %scripts?, %resources?, :$force) {
$!lock.protect( {
my @*MODULES;
Expand Down Expand Up @@ -227,23 +233,41 @@ sub MAIN(:$name is copy, :$auth, :$ver, *@, *%) {
$dist-dir.child($dist-id).spurt: to-json($dist.Hash);

my $precomp = $*REPO.precomp-repository;
my $*RESOURCES = Distribution::Resources.new(:repo(self), :$dist-id);
my %done;
for $dist.provides.values.map(*.values[0]<file>) -> $id {
my $source = $sources-dir.child($id);
if $precomp.may-precomp {
my $repo-prefix = self!repo-prefix;
if $precomp.may-precomp {
my $*RESOURCES = Distribution::Resources.new(:repo(self), :$dist-id);
my %done;
for $dist.provides.kv -> $source-name, $ext {
my $id = $ext.values[0]<file>;
my $source = $sources-dir.child($id);
my $rev-deps-file = ($precomp.store.path($*PERL.compiler.id, $id) ~ '.rev-deps').IO;
my @rev-deps = $rev-deps-file.e ?? $rev-deps-file.lines !! ();

if %done{$id} { note "(Already did $id)" if $verbose; next }
note("Precompiling $id") if $verbose;
$precomp.precompile($source.IO, $id, :force);
if %done{$id} {
note "(Already did $id)" if $verbose;
next;
}
note("Precompiling $id ($source-name)") if $verbose;
$precomp.precompile(
$source.IO,
$id,
:force,
:source-name("$repo-prefix$source.relative($.prefix) ($source-name)"),
);
%done{$id} = 1;
for @rev-deps -> $rev-dep-id {
if %done{$rev-dep-id} { note "(Already did $rev-dep-id)" if $verbose; next }
note("Precompiling $rev-dep-id") if $verbose;
if %done{$rev-dep-id} {
note "(Already did $rev-dep-id)" if $verbose;
next;
}
note("Precompiling rev-dep $rev-dep-id") if $verbose;
my $source = $sources-dir.child($rev-dep-id);
$precomp.precompile($source, $rev-dep-id, :force) if $source.e;
$precomp.precompile(
$source,
$rev-dep-id,
:force,
:source-name($repo-prefix ~ $source.relative($.prefix))
) if $source.e;
%done{$rev-dep-id} = 1;
}
}
Expand Down Expand Up @@ -363,7 +387,12 @@ sub MAIN(:$name is copy, :$auth, :$ver, *@, *%) {
);
my $*RESOURCES = Distribution::Resources.new(:repo(self), :$dist-id);
my $id = $loader.basename;
my $handle = $precomp.try-load($id, $loader);
my $repo-prefix = self!repo-prefix;
my $handle = $precomp.try-load(
$id,
$loader,
:source-name("$repo-prefix$loader.relative($.prefix) ($spec.short-name())"),
);
my $precompiled = defined $handle;
$handle //= CompUnit::Loader.load-source-file($loader);

Expand Down
10 changes: 10 additions & 0 deletions src/core/CompUnit/RepositoryRegistry.pm
Expand Up @@ -181,6 +181,16 @@ class CompUnit::RepositoryRegistry {
!! Nil
}

method name-for-repository(CompUnit::Repository $repo) {
$*REPO; # initialize if not yet done
my $iter := nqp::iterator($custom-lib);
while $iter {
my \pair = nqp::shift($iter);
return nqp::iterkey_s(pair) if nqp::iterval(pair).prefix eq $repo.prefix;
}
Nil
}

method head() { # mostly usefull for access from NQP
$*REPO
}
Expand Down
1 change: 0 additions & 1 deletion src/core/Distribution.pm
Expand Up @@ -34,7 +34,6 @@ class Distribution {
}

role CompUnit::Repository { ... }
class CompUnit::RepositoryRegistry is repr('Uninstantiable') { ... }
class Distribution::Resources does Associative {
has Str $.dist-id;
has Str $.repo;
Expand Down

0 comments on commit 37440f0

Please sign in to comment.