(Darn, I got scooped by Xach.)

As of 1.0.0.18 SBCL has a proper xref implementation, used for answering questions like "where is this function getting called from". I hope it will be more usable than the (very clever) heap-groveling hack that M-x slime-list-callers uses. The intended benefits of the xref over that approach are:

  • More information: also supports who-macroexpands, who-binds, etc in addition to who-calls.

  • More usable: Slime will take you directly to the correct form, not just the right toplevel form.

  • More accurate: The heap-groveling would for example completely miss inlined functions (but see below for some examples of less accuracy).

  • More reliable: The heap-groveling would also lead to assertions being triggered in the SBCL internals that it was abusing.

  • Faster: lookups should be an order of magnitude faster.

There are some cases where xref information isn't currently stored. As a rule of thumb, if there's a defun or defmethod involved on some level, xreffing will work. Otherwise it probably won't. The latter case covers code like:

  • A macro expanded at the toplevel

    (defmacro def-foo () )
    (def-foo )
    
  • Code inside a lambda that's not inside a named function (slime-list-callers will show this call to BAR, slime-who-calls won't)

    (defvar *a*
      (lambda () (bar))
    
  • Code in a defclass initform (likewise)

    (defclass ()
       ((a :initform (bar))))
    
  • Code inside a macrolet definition body

    (defun foo ()
      (macrolet ((bar ()
                   (baz)))
        (bar)))
    

I have some ideas on how to get xref information recorded also for these, and other similar cases, but haven't yet worked out the details. If you run into any situations (other than the ones listed above) where the xref isn't working as you expect it to, I'd love to hear from you.

To use new xref, you'll also need to upgrade to CVS Slime, and the use the normal Slime cross-referencing commands. Thanks to ITA Software for funding the work on the xref (and on some other SBCL improvements, which I never got around to blogging about).