Skip to content

Commit

Permalink
Fix code objects created BEGIN time EVAL getting lost in precompilation
Browse files Browse the repository at this point in the history
This is a follow up to the actual fixes in NQP to add frames created by a
nested compiler (e.g. BEGIN time EVAL, traits or role bodies) to the outer
compilation unit, so they make it into a precomp file.

This also replaces the need for backend specific mast_frames argument with
more generic handling by the backend itself.
  • Loading branch information
niner committed Jun 7, 2020
1 parent 792a0f0 commit 537f887
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Perl6/Compiler.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Perl6::Compiler is HLL::Compiler {
nqp::shift($argiter) if $argiter && !nqp::defined(%options<e>);
nqp::bindhllsym('Raku', '$!ARGITER', $argiter);
my $super := nqp::findmethod(HLL::Compiler, 'command_eval');
my %*COMPILING;
my %*COMPILING := nqp::clone(nqp::ifnull(nqp::getlexdyn('%*COMPILING'), nqp::hash()));
%*COMPILING<%?OPTIONS> := %options;
$super(self, |@args, |%options);
}
Expand Down
12 changes: 6 additions & 6 deletions src/Perl6/Grammar.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -526,22 +526,22 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
self.set_how('package', nqp::knowhow());
# Will we use the result of this? (Yes for EVAL and REPL).
my $*NEED_RESULT := nqp::existskey(%*COMPILING<%?OPTIONS>, 'outer_ctx');
my $*NEED_RESULT := nqp::existskey(%*COMPILING<%?OPTIONS>, 'outer_ctx')
|| nqp::existskey(%*COMPILING<%?OPTIONS>, 'need_result');
# Symbol table and serialization context builder - keeps track of
# objects that cross the compile-time/run-time boundary that are
# associated with this compilation unit.
my $file := nqp::getlexdyn('$?FILES');
my $source_id := nqp::sha1($file ~ (
nqp::defined(%*COMPILING<%?OPTIONS><outer_ctx>)
?? self.target() ~ SerializationContextId.next-id()
!! self.target()));
my $outer_world := nqp::getlexdyn('$*W');
my $is_nested := (
$outer_world
&& nqp::defined(%*COMPILING<%?OPTIONS><outer_ctx>)
&& $outer_world.is_precompilation_mode()
);
my $source_id := nqp::sha1($file ~ (
$is_nested
?? self.target() ~ SerializationContextId.next-id()
!! self.target()));
my $*W := $is_nested
?? $outer_world.create_nested()
Expand Down
6 changes: 2 additions & 4 deletions src/Perl6/World.nqp
Original file line number Diff line number Diff line change
Expand Up @@ -521,10 +521,6 @@ class Perl6::World is HLL::World {
@!CHECKs := [];
}

method create_nested() {
Perl6::World.new(:handle(self.handle), :context(self.context()))
}

method lang-ver-before(str $want) {
nqp::chars($want) == 1 || nqp::die(
'Version to $*W.lang-ver-before'
Expand Down Expand Up @@ -4421,6 +4417,8 @@ class Perl6::World is HLL::World {
# Does any cleanups needed after compilation.
method cleanup() {
for self.context().cleanup_tasks() { $_() }

self.finish;
}

# Represents a longname after having parsed it.
Expand Down
4 changes: 0 additions & 4 deletions src/core.c/ForeignCode.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ $lang = 'Raku' if $lang eq 'perl6';
$context := CALLER:: unless nqp::defined($context);
my $eval_ctx := nqp::getattr(nqp::decont($context), PseudoStash, '$!ctx');
my $?FILES := $filename // 'EVAL_' ~ Rakudo::Internals::EvalIdSource.next-id;
my \mast_frames := nqp::hash();
my $*CTXSAVE; # make sure we don't use the EVAL's MAIN context for the
# currently compiling compilation unit

Expand All @@ -67,7 +66,6 @@ $lang = 'Raku' if $lang eq 'perl6';
$code,
:outer_ctx($eval_ctx),
:global(GLOBAL),
:mast_frames(mast_frames),
:language_version(nqp::getcomp('Raku').language_version),
|(:optimize($_) with nqp::getcomp('Raku').cli-options<optimize>),
|(%(:grammar($LANG<MAIN>), :actions($LANG<MAIN-actions>)) if $LANG);
Expand All @@ -76,8 +74,6 @@ $lang = 'Raku' if $lang eq 'perl6';
Nil
}
else {
$*W.add_additional_frames(mast_frames)
if $*W and $*W.is_precompilation_mode; # we are still compiling
nqp::forceouterctx(
nqp::getattr($compiled,ForeignCode,'$!do'),$eval_ctx
);
Expand Down
2 changes: 1 addition & 1 deletion tools/templates/NQP_REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2020.05-49-gdb4395b5b
2020.05-58-gf18e01790

0 comments on commit 537f887

Please sign in to comment.