[PATCH 0/3] Support for mandatory tail calls
Basile Starynkevitch
basile@starynkevitch.net
Thu May 19 04:31:00 GMT 2016
On 05/19/2016 12:12 AM, Jeff Law wrote:
> On 05/17/2016 04:01 PM, David Malcolm wrote:
>> There have been requests [1] for libgccjit to better support
>> functional programming by supporting the contination-passing style,
>> in which every function "returns" by calling a "continuation"
>> function pointer.
>>
>> These calls must be guaranteed to be implemented as a jump,
>> otherwise the program could consume an arbitrary amount of stack
>> space as it executed.
>>
>> This patch kit implements this.
>>
>> Patch 1 is a preliminary tweak to calls.c
>>
>> Patch 2 implements a new flag in tree.h: CALL_EXPR_MUST_TAIL_CALL,
>> which makes calls.c try harder to implement a flagged call as a
>> tail-call/sibling call, and makes it issue an error if
>> the optimization is impossible. It doesn't implement any
>> frontend support for setting the flag (instead using a plugin
>> to test it). We had some discussion on the jit list about possibly
>> introducing a new builtin for this, but the patch punts on this
>> issue.
> I wonder if we should have an attribute so that the flag can be set
> for C/C++ code. I've seen requests for forcing tail calls in C/C++
> code several times in the past, precisely to support continuations.
Why an attribute? Attributes are on declarations. I think it should
better be some pragma like _Pragma(GCC tail cail, foo(x,y)) or some
builtin (or else some syntax extension like goto return foo(x,y); ...)
because what we really want is to annotate a particular call to be
tail-recursive.
Cheers
--
Basile STARYNKEVITCH http://starynkevitch.net/Basile/
email: basile<at>starynkevitch<dot>net mobile: +33 6 8501 2359
8, rue de la Faiencerie, 92340 Bourg La Reine, France
*** opinions {are only mine, sont seulement les miennes} ***
More information about the Gcc-patches
mailing list