From 0a1ae6610886b8b168f16d8083cc1fe1c5bba2fc Mon Sep 17 00:00:00 2001 From: pmai <pmai> Date: Wed, 6 Feb 2002 23:20:46 +0000 Subject: [PATCH] Allow users to disable tail-call optimization by setting a debug optimization quality is higher than 2. While we claim that debugging is not degraded by TCO, some people evidently believe otherwise, so this change tries to accomodate them, hopefully without disturbing the status-quo too much. --- compiler/envanal.lisp | 9 +++++---- docs/cmu-user/compiler-hint.tex | 7 ++++++- docs/cmu-user/debugger.tex | 17 ++++++++++++++--- 3 files changed, 25 insertions(+), 8 deletions(-) diff --git a/compiler/envanal.lisp b/compiler/envanal.lisp index ac15cfab8..8bedc9124 100644 --- a/compiler/envanal.lisp +++ b/compiler/envanal.lisp @@ -5,7 +5,7 @@ ;;; Carnegie Mellon University, and has been placed in the public domain. ;;; (ext:file-comment - "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/envanal.lisp,v 1.27 1999/12/03 16:27:14 dtc Exp $") + "$Header: /Volumes/share2/src/cmucl/cvs2git/cvsroot/src/compiler/envanal.lisp,v 1.28 2002/02/06 23:20:46 pmai Exp $") ;;; ;;; ********************************************************************** ;;; @@ -401,8 +401,9 @@ (let ((result (return-result ret))) (do-uses (use result) (when (and (immediately-used-p result use) - (or (not (eq (node-derived-type use) *empty-type*)) - (not (basic-combination-p use)) - (eq (basic-combination-kind use) :local))) + (not (policy use (> debug 2))) + (or (not (eq (node-derived-type use) *empty-type*)) + (not (basic-combination-p use)) + (eq (basic-combination-kind use) :local))) (setf (node-tail-p use) t))))))) (undefined-value)) diff --git a/docs/cmu-user/compiler-hint.tex b/docs/cmu-user/compiler-hint.tex index 5e5e0e634..b1c721ef1 100644 --- a/docs/cmu-user/compiler-hint.tex +++ b/docs/cmu-user/compiler-hint.tex @@ -1660,7 +1660,8 @@ will not show some calls that would have been displayed in a non-tail-recursive implementation. In practice, this is not as bad as it sounds\dash{}in fact it isn't really clearly worse, just different. \xlref{debug-tail-recursion} for information about the debugger -implications of tail recursion. +implications of tail recursion, and how to turn it off for the sake of +more conservative backtrace information. In order to ensure that tail-recursion is preserved in arbitrarily complex calling patterns across separately compiled functions, the @@ -1700,6 +1701,10 @@ allocate stack space to represent the binding. Shallow-binding implementations of dynamic scoping also require cleanup code to be evaluated when the scope is exited. +In addition, optimization of tail-recursive calls is inhibited when +the \code{debug} optimization quality is greater than \code{2} +(\pxlref{debugger-policy}.) + \section{Local Call} \label{local-call} diff --git a/docs/cmu-user/debugger.tex b/docs/cmu-user/debugger.tex index ec155ea86..21f959e31 100644 --- a/docs/cmu-user/debugger.tex +++ b/docs/cmu-user/debugger.tex @@ -356,6 +356,11 @@ doubt about how one function called another, it can usually be eliminated by finding the source location in the calling frame (section \ref{source-locations}.) +The elimination of tail-recursive frames can be prevented by disabling +tail-recursion optimization, which happens when the \code{debug} +optimization quality is greater than \code{2} +(\pxlref{debugger-policy}.) + For a more thorough discussion of tail recursion, \pxlref{tail-recursion}. @@ -754,11 +759,17 @@ information, and lifetime information that tells the debugger when arguments are available (even when \code{speed} is \code{3} or the argument is set.) This is the default. +\item[\code{\w{$>$ 2}}] +Any level greater than \code{2} gives level \code{2} and in addition +disables tail-call optimization, so that the backtrace will contain +frames for all invoked functions, even those in tail positions. + \item[\code{3}] Level \code{2} plus all uninterned variables. In addition, lifetime -analysis is disabled (even when \code{speed} is \code{3}), ensuring that all variable -values are available at any known location within the scope of the binding. -This has a speed penalty in addition to the obvious space penalty. +analysis is disabled (even when \code{speed} is \code{3}), ensuring +that all variable values are available at any known location within +the scope of the binding. This has a speed penalty in addition to the +obvious space penalty. \end{Lentry} As you can see, if the \code{speed} quality is \code{3}, debugger performance is -- GitLab