From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,170d8c9368cab115,start X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!postnews.google.com!z14g2000cwz.googlegroups.com!not-for-mail From: "Chad R. Meiners" Newsgroups: comp.lang.ada Subject: Tail Recursion (Why it appears that Gnat 3.15p does support it) Date: 13 Jan 2005 14:04:47 -0800 Organization: http://groups.google.com Message-ID: <1105653887.848989.268410@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: 67.167.137.129 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1105653893 23623 127.0.0.1 (13 Jan 2005 22:04:53 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 13 Jan 2005 22:04:53 +0000 (UTC) User-Agent: G2/0.2 Complaints-To: groups-abuse@google.com Injection-Info: z14g2000cwz.googlegroups.com; posting-host=67.167.137.129; posting-account=paoWPg0AAABe-C1bfTlsEbfoc5yNqKFn Xref: g2news1.google.com comp.lang.ada:7743 Date: 2005-01-13T14:04:47-08:00 List-Id: I have noticed that Gnat 3.15p does not optimize the tail recursion in the following program. with Ada.Text_IO; use Ada.Text_IO; procedure Tail is type Int is mod 2**64; procedure Fib(First, Second : Int) is Next : constant Int := First + Second; begin Put(Int'Image(Next) & ", "); Fib(Second,Next); end Fib; begin Put("1, 1, "); Fib(1,1); end Tail; Does anyone know why GNAT (or any other compiler) does not always reuse stack frames for all subroutines that appear right before a return? Is there some requirement that prevents such naive optimizations? Incidently, if anyone knows of a compiler that does optimize the tail recursion for this program please let me know. Thank you, Chad R. Meiners