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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,170d8c9368cab115 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!news2.google.com!newsprint.newsread.com!newsread.com!news-xfer.newsread.com!newspeer.monmouth.com!newsfeed.icl.net!newsfeed.fjserv.net!syros.belnet.be!news.belnet.be!newsmi-eu.news.garr.it!NewsITBone-GARR!newsserver.cilea.it!news.crs4.it!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: Tail Recursion (Why it appears that Gnat 3.15p does support it) Date: 14 Jan 2005 10:04:02 +0100 Organization: CRS4, Center for Adv. Studies, Research and Development in Sardinia Message-ID: References: <1105653887.848989.268410@z14g2000cwz.googlegroups.com> NNTP-Posting-Host: jacob.crs4.it Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit X-Trace: pietro.crs4.it 1105692135 13930 156.148.71.80 (14 Jan 2005 08:42:15 GMT) X-Complaints-To: news@nntpserver.crs4.it. NNTP-Posting-Date: 14 Jan 2005 08:42:15 GMT User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2 Xref: g2news1.google.com comp.lang.ada:7757 Date: 2005-01-14T08:42:15+00:00 List-Id: Chad R. Meiners wrote: > 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? Could it be related to the parameter passing rules in Ada? And would it really be faster? If the arguments for Fib are not copied in the order you have written them in the procedure specification and a single stack frame is reused, the program will not behave correctly. But alternating between two stack frames should be safe enough. Jacob -- �By becoming continuous, war has fundamentally changed its character. In past ages, a war, almost by definition, was something that sooner or later came to an end, usually in unmistakable victory or defeat.� -- Nineteen Eighty-Four, George Orwell �I don't think you can win [the war on terror].� -- George W. Bush