Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Param count mismatch errors and tail-calling a continuation

3 views
Skip to first unread message

Bob Rogers

unread,
Feb 18, 2006, 3:47:14 PM2/18/06
to Perl 6 Internals
The problem is that doing an explicit tailcall of a continuation
without set_params passes the sub's args to the continuation, instead of
no args. As a result, I was getting weird param count mismatch errors
in cases where I was neither passing nor receiving anything. (This is
why I hadn't noticed this until Leo turned on param checking by default;
I assume this is longstanding behavior.)

This brings up a couple of issues:

1. For purposes of error checking, Parrot obviously considers that
tailcall passes arguments, as for function calls, even when tail-calling
a continuation in order to effect a return. Should continuations be
handled specially, or do we want to define that "tailcall" always means
"call"?

2. Passing the sub args to a tail-called sub/continuation strikes me
as buggy, but I can't think of a way to fix this without breaking the
"feature" that it is currently possible to call get_params multiple
times. One such fix is attached. It works by having parrot_pass_args
"use up" the args and params in the PARROT_OP_get_params_pc case. Doing
this for the other cases doesn't seem to break anything else, and
strikes me as a good idea; should I make it happen for all
parrot_pass_args calls?

Alternatively, passing the sub args could be defined as expected
behavior, but that seems error-prone.

If I hear no objections to flushing "multiple get_params" (nor
exhortations to generalize "using up" the args), I will commit the patch
as-is.

-- Bob Rogers
http://rgrjr.dyndns.org/

tailcall-closure-without-set_args.patch

Leopold Toetsch

unread,
Feb 18, 2006, 4:35:31 PM2/18/06
to Bob Rogers, Perl 6 Internals

On Feb 18, 2006, at 21:47, Bob Rogers wrote:

>
> If I hear no objections to flushing "multiple get_params" (nor
> exhortations to generalize "using up" the args), I will commit the
> patch
> as-is.

Multiple get_params don't work with tailcalls as the caller's frame
(with the args inside) is reused by the tailcalled sub (more precisely:
the get_param of a tailcall frees the callers's frame). Therefore this
patch is ok.

That is we have to mandate that there is exactly one get_params as the
first opcode of a sub (currently no get_params is issued for void subs,
but that will change to enable param count checks for that case too).

leo


0 new messages