I think the CLI/R is an interesting study in design compromise.

Tail calling is apparently slow because the activation records of the
old and new method have to be swapped. Conversely, jmp should be quite
fast.

Regarding the CLI spec, part of Partition III, Section 2.1 reads:

"There may also be implementation-specific restrictions that prevent the
tail. prefix from being obeyed in certain cases. While an implementation
is free to ignore the tail. prefix under these circumstances, they
should be clearly documented as they can affect the behavior of
programs.

CLI implementations are required to honor tail. call requests where
caller and callee methods can be statically determined to lie in the
same assembly; and where the caller is not in a synchronized region; and
where caller and callee satisfy all conditions listed in the
"Verifiability" rules below. (To "honor" the tail. prefix means to
remove the caller's frame, rather than revert to a regular call
sequence). Consequently, a CLI implementation need not honor tail. calli
or tail. callvirt sequences."

So my original statement was quite inaccurate: Apparently tail.call will
be honored in the situations outlined above. (Except if the
implementation explicitly notes that it doesn't? I'm not sure of the
precedence of the first paragraph.) The verification rules are simply
that control doesn't transfer directly to the call (it is acceptable to
br to the following ret, however), the return type of the called method
and that of the calling method are compatible, and that the called
method does not take any managed pointers (this is to stop a managed
pointer to the caller's stack frame, which is about to be removed, being
passed to the callee).

Dominic Cooney

-----Original Message-----
From: Moderated discussion of advanced .NET topics.
[mailto:[EMAIL PROTECTED]] On Behalf Of Dejan Jelovic
Sent: Thursday, 23 January 2003 11:15 PM
To: [EMAIL PROTECTED]
Subject: Re: [ADVANCED-DOTNET] tailcall speed

Dominic Cooney wrote:

> Tailcall is more for its semantic value (e.g. for
> implementing Scheme) than speed. It is somewhat
> marginal because CLI implementers do not need to
> honour the tail hint (although the CLR does).

Hmmm. It may be there for the semantic value, but if it's so slow then
people will not use compilers that are based on it. So Scheme under .NET
will remain an academic exercise instead of being a valid production
lanugage choice.

BTW, are you sure that CLI implementers do not need to honor the tail
token? If so that makes it useless. A program that uses it would blow
the stack on platforms that don't.

Dejan
www.jelovic.com

You can read messages from the Advanced DOTNET archive, unsubscribe from
Advanced DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

You can read messages from the Advanced DOTNET archive, unsubscribe from Advanced 
DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to