Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Lift GLOBALish merging code out of CompUnit
Moved the Perl 6 code to Stash::merge-symbols and the call site to
CompUnitRepo::load_module so we no longer need to pass around GLOBALish.
Just loading a CompUnit should no longer influence the environment.
That's up to the user.
  • Loading branch information
niner committed Nov 5, 2015
1 parent 25e99f0 commit cc06108
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 38 deletions.
18 changes: 9 additions & 9 deletions src/Perl6/ModuleLoader.nqp
Expand Up @@ -88,7 +88,7 @@ class Perl6::ModuleLoader does Perl6::ModuleLoaderVMConfig {
my $UNIT := nqp::ctxlexpad($module_ctx);
if +@GLOBALish {
unless nqp::isnull($UNIT<GLOBALish>) {
self.merge_globals(@GLOBALish[0], $UNIT<GLOBALish>);
self.merge_globals(@GLOBALish[0].WHO, $UNIT<GLOBALish>.WHO);
}
}
return $UNIT;
Expand Down Expand Up @@ -137,34 +137,34 @@ class Perl6::ModuleLoader does Perl6::ModuleLoaderVMConfig {
for stash_hash($source) {
my $sym := $_.key;
if !%known_symbols{$sym} {
($target.WHO){$sym} := $_.value;
($target){$sym} := $_.value;
}
elsif ($target.WHO){$sym} =:= $_.value {
elsif ($target){$sym} =:= $_.value {
# No problemo; a symbol can't conflict with itself.
}
else {
my $source_mo := $_.value.HOW;
my $source_is_stub := $source_mo.HOW.name($source_mo) eq $stub_how
|| $source_mo.HOW.name($source_mo) eq $nqp_stub_how;
my $target_mo := ($target.WHO){$sym}.HOW;
my $target_mo := ($target){$sym}.HOW;
my $target_is_stub := $target_mo.HOW.name($target_mo) eq $stub_how
|| $source_mo.HOW.name($source_mo) eq $nqp_stub_how;
if $source_is_stub && $target_is_stub {
# Both stubs. We can safely merge the symbols from
# the source into the target that's importing them.
self.merge_globals(($target.WHO){$sym}, $_.value);
self.merge_globals(($target){$sym}.WHO, $_.value.WHO);
}
elsif $source_is_stub {
# The target has a real package, but the source is a
# stub. Also fine to merge source symbols into target.
self.merge_globals(($target.WHO){$sym}, $_.value);
self.merge_globals(($target){$sym}.WHO, $_.value.WHO);
}
elsif $target_is_stub {
# The tricky case: here the interesting package is the
# one in the module. So we merge the other way around
# and install that as the result.
self.merge_globals($_.value, ($target.WHO){$sym});
($target.WHO){$sym} := $_.value;
self.merge_globals($_.value.WHO, ($target){$sym}.WHO);
($target){$sym} := $_.value;
}
else {
nqp::die("P6M Merging GLOBAL symbols failed: duplicate definition of symbol $sym");
Expand Down Expand Up @@ -223,7 +223,7 @@ class Perl6::ModuleLoader does Perl6::ModuleLoaderVMConfig {
}

sub stash_hash($pkg) {
my $hash := $pkg.WHO;
my $hash := $pkg;
unless nqp::ishash($hash) {
$hash := $hash.FLATTENABLE_HASH();
}
Expand Down
11 changes: 1 addition & 10 deletions src/core/CompUnit.pm
Expand Up @@ -110,9 +110,7 @@ RAKUDO_MODULE_DEBUG("Precomping with %*ENV<RAKUDO_PRECOMP_WITH>")
True;
}

proto method load(CompUnit:D: |) { * }
multi method load(CompUnit:D: ) { self.load(Any) }
multi method load(CompUnit:D: \GLOBALish, :$line) {
method load(CompUnit:D: :$line) {
$global.protect( {
my int $DEBUG = $*RAKUDO_MODULE_DEBUG;
RAKUDO_MODULE_DEBUG("going to load $!name") if $DEBUG;
Expand Down Expand Up @@ -186,13 +184,6 @@ RAKUDO_MODULE_DEBUG("Precomping with %*ENV<RAKUDO_PRECOMP_WITH>")
}
}
}

# Provided we have a mainline and need to do global merging...
my $globalish := $!handle.globalish-package;
if $globalish !=== Stash {
# Merge any globals.
nqp::gethllsym('perl6', 'ModuleLoader').merge_globals(GLOBALish, $globalish);
}
} ) }

method unit() {
Expand Down
14 changes: 4 additions & 10 deletions src/core/CompUnit/Repository/FileSystem.pm
Expand Up @@ -12,7 +12,6 @@ class CompUnit::Repository::FileSystem does CompUnit::Repository::Locally does C

method need(
CompUnit::DependencySpecification $spec,
\GLOBALish is raw = Any,
CompUnit::PrecompilationRepository :$precomp = self.precomp-repository(),
:$line
)
Expand All @@ -27,11 +26,6 @@ class CompUnit::Repository::FileSystem does CompUnit::Repository::Locally does C
my $compunit;

if $handle {
my $globalish := $handle.globalish-package;
if $globalish !=== Stash {
# Merge any globals.
nqp::gethllsym('perl6', 'ModuleLoader').merge_globals(GLOBALish, $globalish);
}
return %!loaded{$name} = %seen{$base} = CompUnit.new(
$base, :name($name), :extension(''), :has-precomp, :$handle, :repo(self)
);
Expand Down Expand Up @@ -70,15 +64,15 @@ class CompUnit::Repository::FileSystem does CompUnit::Repository::Locally does C
}

if $compunit {
$compunit.load(GLOBALish, :$line);
$compunit.load(:$line);
return %!loaded{$compunit.name} = $compunit;
}

return self.next-repo.need($spec, GLOBALish, :$precomp, :$line) if self.next-repo;
return self.next-repo.need($spec, :$precomp, :$line) if self.next-repo;
nqp::die("Could not find $spec in:\n" ~ $*REPO.repo-chain.map(*.Str).join("\n").indent(4));
}

method load(Str:D $file, \GLOBALish is raw = Any, :$line) returns CompUnit:D {
method load(Str:D $file, :$line) returns CompUnit:D {
state Str $precomp-ext = $*VM.precomp-ext; # should be $?VM probably
my $dir-sep := $*SPEC.dir-sep;

Expand All @@ -92,7 +86,7 @@ class CompUnit::Repository::FileSystem does CompUnit::Repository::Locally does C
my $compunit = %seen{$path} = CompUnit.new(
$path, :$file, :extension(''), :has-source(!$has_precomp), :$has_precomp, :repo(self)
);
$compunit.load(GLOBALish, :$line);
$compunit.load(:$line);
return %!loaded{$compunit.name} = $compunit;
}

Expand Down
9 changes: 4 additions & 5 deletions src/core/CompUnit/Repository/Installation.pm
Expand Up @@ -188,7 +188,6 @@ See http://design.perl6.org/S22.html#provides for more information.\n";

method need(
CompUnit::DependencySpecification $spec,
\GLOBALish is raw = Any,
CompUnit::PrecompilationRepository :$precomp = self.precomp-repository(),
:$line
)
Expand Down Expand Up @@ -217,21 +216,21 @@ See http://design.perl6.org/S22.html#provides for more information.\n";
with $candi<provides>{$spec.short-name}{$*VM.precomp-ext} -> $pc {
if $*PERL<compiler>.version eqv $pc<cver> {
my $compunit = CompUnit.new($loader, :has_precomp($pc<file>), :repo(self));
$compunit.load(GLOBALish, :$line);
$compunit.load(:$line);
return %!loaded{$compunit.name} = $compunit;
}
}
my $compunit = CompUnit.new($loader, :repo(self));
$compunit.load(GLOBALish, :$line);
$compunit.load(:$line);
return %!loaded{$compunit.name} = $compunit;
}
}
}
return self.next-repo.need($spec, GLOBALish, :$precomp, :$line) if self.next-repo;
return self.next-repo.need($spec, :$precomp, :$line) if self.next-repo;
nqp::die("Could not find $spec in:\n" ~ $*REPO.repo-chain.map(*.Str).join("\n").indent(4));
}

method load(Str:D $file, \GLOBALish is raw = Any, :$line) returns CompUnit:D {
method load(Str:D $file, :$line) returns CompUnit:D {
return self.next-repo.load($file, :$line) if self.next-repo;
nqp::die("Could not find $file in:\n" ~ $*REPO.repo-chain.map(*.Str).join("\n").indent(4));
}
Expand Down
8 changes: 4 additions & 4 deletions src/core/CompUnitRepo.pm
Expand Up @@ -76,11 +76,10 @@ RAKUDO_MODULE_DEBUG("Looking in $spec for $name")
}
}
else {
return (
my $compunit := (
$file
?? $*REPO.load(
$file,
GLOBALish,
:$line
)
!! $*REPO.need(
Expand All @@ -89,10 +88,11 @@ RAKUDO_MODULE_DEBUG("Looking in $spec for $name")
:auth-matcher(%opts<auth>),
:version-matcher(%opts<ver>),
),
GLOBALish,
:$line,
)
).handle;
);
GLOBALish.WHO.merge-symbols($compunit.handle.globalish-package.WHO);
$compunit.handle
}
# elsif $file {
# nqp::die("Could not find file '$file' for module $module_name");
Expand Down
6 changes: 6 additions & 0 deletions src/core/Stash.pm
Expand Up @@ -32,6 +32,12 @@ my class Stash { # declared in BOOTSTRAP
nqp::bindkey($storage, $key, $pkg)
}
}

method merge-symbols(Stash:D: Stash $globalish) {
if $globalish !=== Stash {
nqp::gethllsym('perl6', 'ModuleLoader').merge_globals(self, $globalish);
}
}
}

# vim: ft=perl6 expandtab sw=4

0 comments on commit cc06108

Please sign in to comment.