[Openmcl-devel] Recursive tracing/advising?

Jared C. Davis jared at cs.utexas.edu
Wed Jul 25 07:25:00 PDT 2007


Hi,

This is great, and seems to work perfectly for what I'm trying to do.
It even seems that I can just redefine the function with the NOTINLINE
added, after having originally defined it without NOTINLINE, and
tracing immediately picks up what I'm trying to do.  I don't think
I'll need anything else. :)

Thanks,
   Jared

On 7/25/07, Gary Byers <gb at clozure.com> wrote:
> When a (globally named) function FOO is defined with DEFUN, the compiler's
> allowed to assume that functional references to that function name
> refer to the function being defined (unless they're lexically shadowed);
> it can therefore skip the implicit SYMBOL-FUNCTION ("call whatever is
> in the function cell of FOO") on a self-call (a call to FOO from within
> FOO.)  This saves an instruction or two on those calls, but (since
> TRACE works by changing what SYMBOL-FUNCTION returns) those inlined
> self-calls can't be traced.
>
> The compiler can't do this (can't even assume that something defined
> by DEFUN won't be redefined later) if the function name is declared
> NOTINLINE at the point of the self call:
>
> (defun fact (n)         ; other traditional definition
>    (declare (NOTINILINE FACT)) ; and the compiler can't ignore NOTINLINE
>    (if (zerop n) 1 (* n (fact (1- n)))))
>
> There's a way to say "as a matter of policy, I'd rather have the
> ability to trace functions which call themselves and are defined with
> DEFUN and don't care about saving a few cycles per self-call"; I'm
> travelling at the moment and don't have a good enough net connection
> to explain that, but if you're interested I'll try to explain it when
> I get back.
>
>
>
> On Tue, 24 Jul 2007, Jared C. Davis wrote:
>
> > Hi,
> >
> > Is there a way to get trace to show me recursive calls in addition to
> > the outermost call?  For example, if I try to trace fact as below, it
> > only prints the call of (FACT 10 1):
> >
> >    ? (defun fact (x acc)
> >        (if (= x 0)
> >            acc
> >          (fact (- x 1) (* x acc))))
> >    FACT
> >
> >    ? (trace fact)
> >    NIL
> >
> >    ? (fact 10 1)
> >    0> Calling (FACT 10 1)
> >    <0 FACT returned 3628800
> >
> > I'd like to be able to see the call of (FACT 10 1), (FACT 9 10), (FACT
> > 8 90), etc., all the way down.
> >
> > Right now the only way I know how to do this is to change the
> > definition of fact so it calls some new function, say fact-note, upon
> > each iteration with the relevant arguments.  I can then trace
> > fact-note instead of fact, to see all the calls.  But I don't like
> > this, because it makes my definition more complicated to support
> > tracing, and the function I'm actually interested in tracing is
> > already very complicated.
> >
> > I've tried using both trace and CCL:advise with :when :after, but that
> > seems to give me the same trouble.
> >
> > Thanks!
> >   Jared
> >
> > --
> > Jared C. Davis <jared at cs.utexas.edu>
> > 3600 Greystone Drive #604
> > Austin, TX 78731
> > http://www.cs.utexas.edu/users/jared/
> > _______________________________________________
> > Openmcl-devel mailing list
> > Openmcl-devel at clozure.com
> > http://clozure.com/mailman/listinfo/openmcl-devel
> >
> >
>


-- 
Jared C. Davis <jared at cs.utexas.edu>
3600 Greystone Drive #604
Austin, TX 78731
http://www.cs.utexas.edu/users/jared/



More information about the Openmcl-devel mailing list