Skip to content

Commit c58b48c

Browse files
committed
Revert "Wrap subs in a NQPRoutine code object when NQPRoutine is in scope."
This causes fails on the JVM. This reverts commit 3890c61.
1 parent 3890c61 commit c58b48c

File tree

5 files changed

+14
-83
lines changed

5 files changed

+14
-83
lines changed

src/NQP/Actions.nqp

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -790,33 +790,6 @@ class NQP::Actions is HLL::Actions {
790790
method routine_declarator:sym<sub>($/) { make $<routine_def>.ast; }
791791
method routine_declarator:sym<method>($/) { make $<method_def>.ast; }
792792

793-
# returns a QAST node to create the code object or 0 if not possible
794-
method wrap_sub_in_code_object($block,$name) {
795-
my $BLOCK := $*W.cur_lexpad();
796-
797-
my $code_type_name := 'NQPRoutine';
798-
my $have_code_type;
799-
try {
800-
my $code_type := $*W.find_sym([$code_type_name]);
801-
$have_code_type := $*PACKAGE.HOW.name($*PACKAGE) ne $code_type_name;
802-
}
803-
804-
if $have_code_type {
805-
my $code_object := $*W.create_code($block, $name, 0);
806-
807-
my $node := QAST::Op.new(
808-
:op('callmethod'), :name('clone'),
809-
QAST::WVal.new( :value($code_object) ));
810-
811-
812-
$node<block_past> := $block;
813-
$node<code_object> := $code_object; # so that we can avoid a clone if don't need it
814-
$node;
815-
} else {
816-
0;
817-
}
818-
}
819-
820793
method routine_def($/) {
821794
# If it's just got * as a body, make a multi-dispatch enterer.
822795
# Otherwise, need to build a sub.
@@ -833,10 +806,6 @@ class NQP::Actions is HLL::Actions {
833806
}
834807
my $block := $past;
835808

836-
my $lexpast := QAST::Op.new( :op('takeclosure'), $past );
837-
$lexpast<sink> := $past;
838-
$lexpast<block_past> := $block;
839-
840809
if $<deflongname> {
841810
my $name := ~$<sigil>[0] ~ $<deflongname>[0].ast;
842811
$past.name($name);
@@ -914,25 +883,12 @@ class NQP::Actions is HLL::Actions {
914883
}
915884
else {
916885
my $BLOCK := $*W.cur_lexpad();
917-
918-
if self.wrap_sub_in_code_object($past,$name) -> $node {
919-
$BLOCK[0].push(QAST::Op.new(
920-
:op('bind'),
921-
QAST::Var.new( :name('&' ~ $name), :scope('lexical'), :decl('var') ),
922-
QAST::WVal.new( :value($node<code_object>) )
923-
));
924-
$BLOCK[0].push($past);
925-
$lexpast := $node;
926-
} else {
927-
$BLOCK[0].push(QAST::Op.new(
928-
:op('bind'),
929-
QAST::Var.new( :name('&' ~ $name), :scope('lexical'), :decl('var') ),
930-
$past
931-
));
932-
}
933-
886+
$BLOCK[0].push(QAST::Op.new(
887+
:op('bind'),
888+
QAST::Var.new( :name('&' ~ $name), :scope('lexical'), :decl('var') ),
889+
$past
890+
));
934891
$BLOCK.symbol('&' ~ $name, :scope('lexical'));
935-
936892
if $*SCOPE eq 'our' {
937893
# Need to install it at loadinit time but also re-bind
938894
# it per invocation.
@@ -960,15 +916,14 @@ class NQP::Actions is HLL::Actions {
960916
}
961917
}
962918
else {
963-
if self.wrap_sub_in_code_object($past,'<anon>') -> $node {
964-
my $BLOCK := $*W.cur_lexpad();
965-
$BLOCK[0].push($past);
966-
$lexpast := $node;
967-
} elsif $*W.is_precompilation_mode() {
919+
if $*W.is_precompilation_mode() {
968920
$*W.create_code($past, '<anon>', 0)
969921
}
970922
}
971923

924+
my $lexpast := QAST::Op.new( :op('takeclosure'), $past );
925+
$lexpast<sink> := $past;
926+
$lexpast<block_past> := $block;
972927
make $lexpast;
973928

974929
# Apply traits.

src/NQP/World.nqp

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,7 @@ class NQP::World is HLL::World {
270270
}
271271
else {
272272
# Create a fresh stub code, and set its name.
273-
274-
if nqp::istype($stub_code,NQPRoutine) {
275-
$dummy := $stub_code.freshcoderef();
276-
} else { # old nqp versions
277-
$dummy := nqp::freshcoderef($stub_code);
278-
}
279-
273+
$dummy := nqp::freshcoderef($stub_code);
280274
nqp::setcodename($dummy, $name);
281275

282276
# Tag it as a static code ref and add it to the root code refs set.

src/core/NQPRoutine.nqp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -350,11 +350,6 @@ my knowhow NQPRoutine {
350350
}
351351

352352
method signature() { $!signature }
353-
354-
method freshcoderef() {
355-
nqp::freshcoderef($!do);
356-
}
357-
358353
}
359354
nqp::setinvokespec(NQPRoutine, NQPRoutine, '$!do', nqp::null);
360355
nqp::setboolspec(NQPRoutine, 5, nqp::null());

t/nqp/68-subs-are-codeobjs.t

Lines changed: 0 additions & 11 deletions
This file was deleted.

t/serialization/03-closures.t

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@ sub add_to_sc($sc, $idx, $obj) {
4545
{
4646
my $sc := nqp::createsc('TEST_SC_2_IN');
4747
my $sh := nqp::list_s();
48-
49-
my $sub := sub make_meth_with($x) {
48+
49+
my $raw_sub := nqp::getstaticcode(sub make_meth_with($x) {
5050
my $m := method () { $x };
5151
$m;
52-
};
53-
54-
my $raw_sub := nqp::getstaticcode(nqp::getattr($sub, NQPRoutine, '$!do'));
55-
52+
});
53+
5654
my $m1 := $raw_sub('dolphin');
5755
my $m2 := $raw_sub('whale');
5856

0 commit comments

Comments
 (0)