Skip to content

Commit

Permalink
An attempt at rewriting the Env initialization logic
Browse files Browse the repository at this point in the history
Instead of creating a Hash at each startup with the val()ed values
of the outer environment, simply clone the result of nqp::getenvhash
and put this in a subclass of Hash, and provide the val() logic on
demand.

This proved quite an exercise in yak-shaving, and the result was really
inconclusive for yours truly.  On top of that, it appears to tickle a
precompilation bug that only shows up when doing "make spectest" with
a high number of TEST_JOBS.  Rather than just throwing away this code,
I thought I'd keep it in a branch, just in case someone could make use
of this in the future.
  • Loading branch information
lizmat committed Dec 14, 2019
1 parent a04af36 commit 04cc3fd
Show file tree
Hide file tree
Showing 11 changed files with 37 additions and 23 deletions.
20 changes: 20 additions & 0 deletions src/core.c/Env.pm6
@@ -1,3 +1,23 @@
class Env is Hash {
multi method new(Env:) {
nqp::p6bindattrinvres(
nqp::create(self),Map,'$!storage',nqp::clone(nqp::getenvhash)
)
}
method AT-KEY(Env:D: Str:D $key) {
nqp::existskey(nqp::getattr(self,Map,'$!storage'),$key)
?? val(nqp::atkey(nqp::getattr(self,Map,'$!storage'),$key))
!! nextsame
}
method ASSIGN-KEY(Env:D: Str:D $key, \value) {
nqp::bindkey(
nqp::getattr(self,Map,'$!storage'),
$key,
nqp::unbox_s(value.Str)
)
}
}

Rakudo::Internals.REGISTER-DYNAMIC: '$*CWD', {
# PROCESS::<$CWD> = nqp::p6box_s(nqp::cwd());
my $CWD := nqp::p6box_s(nqp::cwd());
Expand Down
6 changes: 4 additions & 2 deletions src/core.c/Exception.pm6
Expand Up @@ -383,7 +383,8 @@ do {
:what("PERL6_EXCEPTIONS_HANDLER env var");
my $class := ::("Exceptions::$handler");
unless nqp::istype($class,Failure) {
temp %*ENV<PERL6_EXCEPTIONS_HANDLER> = ""; # prevent looping
temp %*ENV;
%*ENV<PERL6_EXCEPTIONS_HANDLER> = ""; # prevent looping
unless $class.process($e) {
nqp::getcurhllsym('&THE_END')();
return
Expand All @@ -393,7 +394,8 @@ do {
if %*ENV<RAKU_EXCEPTIONS_HANDLER> -> $handler {
my $class := ::("Exceptions::$handler");
unless nqp::istype($class,Failure) {
temp %*ENV<RAKU_EXCEPTIONS_HANDLER> = ""; # prevent looping
temp %*ENV;
%*ENV<RAKU_EXCEPTIONS_HANDLER> = ""; # prevent looping
unless $class.process($e) {
nqp::getcurhllsym('&THE_END')();
return
Expand Down
19 changes: 0 additions & 19 deletions src/core.c/Rakudo/Internals.pm6
Expand Up @@ -154,25 +154,6 @@ my class Rakudo::Internals {
0;
}

method createENV() {
nqp::stmts(
(my $hash := nqp::hash),
(my $iter := nqp::iterator(nqp::getenvhash)),
nqp::while(
$iter,
nqp::bindkey(
$hash,
nqp::iterkey_s(nqp::shift($iter)),
nqp::assign(
nqp::p6scalarfromdesc(nqp::null),
val(nqp::iterval($iter))
)
)
),
$hash
)
}

# Helper method for prefix:<let>/prefix:<temp>, which really do the same
# thing apart from where they store data. Takes the IterationBuffer in
# which to save data, the container to be inspected, and the type of op
Expand Down
6 changes: 5 additions & 1 deletion src/core.c/control.pm6
Expand Up @@ -211,7 +211,11 @@ sub CLONE-HASH-DECONTAINERIZED(\hash) {
nqp::iterkey_s(nqp::shift(iter)),
nqp::if(
nqp::defined(nqp::iterval(iter)),
nqp::decont(nqp::iterval(iter)).Str,
nqp::if(
nqp::iseq_s(nqp::iterval(iter).^name,'BOOTStr'),
nqp::iterval(iter),
nqp::unbox_s(nqp::decont(nqp::iterval(iter)).Str)
),
''
)
)
Expand Down
3 changes: 2 additions & 1 deletion src/core.c/core_prologue.pm6
Expand Up @@ -56,7 +56,8 @@ my class Rakudo::Internals::IterationSet is repr('VMHash') { }
my constant $?NL = "\x0A";

# Make sure we have an environment
PROCESS::<%ENV> := Rakudo::Internals.createENV;
my class Env { ... }
PROCESS::<%ENV> := Env.new;

# This thread pool scheduler will be the default one.
#?if !js
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/03-corekeys-6c.t
Expand Up @@ -529,6 +529,7 @@ my @expected = (
Q{Encoding},
Q{Endian},
Q{Enumeration},
Q{Env},
Q{Exception},
Q{Exceptions},
Q{Failure},
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/03-corekeys-6d.t
Expand Up @@ -529,6 +529,7 @@ my @expected = (
Q{Encoding},
Q{Endian},
Q{Enumeration},
Q{Env},
Q{Exception},
Q{Exceptions},
Q{Failure},
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/03-corekeys-6e.t
Expand Up @@ -530,6 +530,7 @@ my @expected = (
Q{Encoding},
Q{Endian},
Q{Enumeration},
Q{Env},
Q{Exception},
Q{Exceptions},
Q{Failure},
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/03-corekeys.t
Expand Up @@ -531,6 +531,7 @@ my @allowed =
Q{Encoding},
Q{Endian},
Q{Enumeration},
Q{Env},
Q{Exception},
Q{Exceptions},
Q{Failure},
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/04-settingkeys-6c.t
Expand Up @@ -529,6 +529,7 @@ my %allowed = (
Q{Encoding},
Q{Endian},
Q{Enumeration},
Q{Env},
Q{Exception},
Q{Exceptions},
Q{Failure},
Expand Down
1 change: 1 addition & 0 deletions t/02-rakudo/04-settingkeys-6e.t
Expand Up @@ -528,6 +528,7 @@ my %allowed = (
Q{Encoding},
Q{Endian},
Q{Enumeration},
Q{Env},
Q{Exception},
Q{Exceptions},
Q{Failure},
Expand Down

0 comments on commit 04cc3fd

Please sign in to comment.