Skip to content

Commit 69ccfc7

Browse files
committed
Stubs need a fresh LexInfo for closure serialization to work. Gets us a little further with role serialization.
1 parent 790fc9a commit 69ccfc7

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/NQP/World.pm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ class NQP::World is HLL::World {
182182
$dummy := $past<compile_time_dummy>;
183183
}
184184
else {
185-
$dummy := pir::clone__PP($stub_code);
185+
$dummy := pir::nqp_fresh_stub__PP($stub_code);
186186
pir::assign__vPS($dummy, $name);
187187
if $is_dispatcher {
188188
# The dispatcher will get cloned if more candidates are added in

src/ops/nqp.ops

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ BEGIN_OPS_PREAMBLE
1111
#include "../6model/serialization_context.h"
1212
#include "../guts/multi_dispatch.h"
1313
#include "../pmc/pmc_dispatchersub.h"
14+
#include "../pmc/pmc_nqplexinfo.h"
1415
#include "pmc_sub.h"
1516

1617
/* SHA1 algorithm. */
@@ -2177,3 +2178,26 @@ inline op nqp_sha1(out STR, in STR) :base_core {
21772178
Parrot_str_free_cstring(cstr);
21782179
$1 = Parrot_str_new_init(interp, &output, 40, Parrot_utf8_encoding_ptr, 0);
21792180
}
2181+
2182+
2183+
/*
2184+
2185+
=item nqp_fresh_stub
2186+
2187+
Takes the Parrot Sub in $2 and makes a clone of it along with a fresh NQPLexInfo.
2188+
(This is used for closure to static resolution).
2189+
2190+
=cut
2191+
2192+
*/
2193+
inline op nqp_fresh_stub(out PMC, in PMC) :base_core {
2194+
if ($2->vtable->base_type == enum_class_Sub) {
2195+
$1 = VTABLE_clone(interp, $2);
2196+
PARROT_SUB($1)->lex_info = VTABLE_clone(interp, PARROT_SUB($2)->lex_info);
2197+
PARROT_NQPLEXINFO(PARROT_SUB($1)->lex_info)->static_code = $1;
2198+
}
2199+
else {
2200+
Parrot_ex_throw_from_c_args(interp, NULL, EXCEPTION_INVALID_OPERATION,
2201+
"nqp_fresh_sub can only operate on a Parrot Sub");
2202+
}
2203+
}

0 commit comments

Comments
 (0)