Skip to content

Commit

Permalink
Fix some failures to catch return outside routine.
Browse files Browse the repository at this point in the history
We actually ended up returning from the first thing we found down the
call stack that could be returned from, which led to some rather odd
behaviors. RT #123732 was a great example; this:

    for ^5 { .say; NEXT { return } }

Ended up with the return binding to the run_phasers method that runs
the NEXT phasers. This also makes return a tad cheaper, and will let
us make return a multi sub too, for further performance win. But this
patch just corrects the semantics.
  • Loading branch information
jnthn committed Dec 1, 2015
1 parent 2b5c41e commit a4ca12a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 8 deletions.
7 changes: 1 addition & 6 deletions src/vm/jvm/runtime/org/perl6/rakudo/RakOps.java
Expand Up @@ -569,12 +569,7 @@ private static SixModelObject getremotelex(CallFrame pad, String name) { /* use

public static SixModelObject p6routinereturn(SixModelObject in, ThreadContext tc) {
CallFrame ctx = tc.curFrame;
SixModelObject cont = null;

for (ctx = ctx.caller; ctx != null; ctx = ctx.caller) {
cont = getremotelex(ctx, "RETURN");
if (cont != null) break;
}
SixModelObject cont = getremotelex(ctx.caller, "RETURN");

if (!(cont instanceof LexoticInstance)) {
SixModelObject thrower = getThrower(tc, "X::ControlFlow::Return");
Expand Down
4 changes: 2 additions & 2 deletions src/vm/moar/ops/perl6_ops.c
Expand Up @@ -358,8 +358,8 @@ static MVMuint8 s_p6routinereturn[] = {
MVM_operand_obj | MVM_operand_read_reg,
};
static void p6routinereturn(MVMThreadContext *tc, MVMuint8 *cur_op) {
MVMRegister *reg = MVM_frame_find_lexical_by_name_rel_caller(tc, str_return,
tc->cur_frame);
MVMRegister *reg = MVM_frame_find_lexical_by_name_rel(tc, str_return,
tc->cur_frame->caller);
MVMObject *ret = (reg ? reg->o : NULL);
if (!MVM_is_null(tc, ret) && IS_CONCRETE(ret) && REPR(ret)->ID == MVM_REPR_ID_Lexotic) {
MVM_args_setup_thunk(tc, NULL, MVM_RETURN_VOID, &one_arg_callsite);
Expand Down

0 comments on commit a4ca12a

Please sign in to comment.