Wednesday, July 22, 2009

Linguistic tools for diagnostics

I've written before about how the stack gets misunderstood as a history thanks to non-tail-recursive languages. Of course, stack traces are indispensable: they're essential for debugging, and they're also useful for reporting crash information from live applications.

But this conflates two very different language requirements in one feature: the need for nested (unbounded, if your language isn't broken) function application, and the need for diagnostics of dynamic errors.

The first is what continuations and stacks are all about, of course: functions can't call each other function calls can't be nested in compound expressions without the language runtime keeping track of the work it has left to do. But the second is an independent need: there's all sorts of diagnostic information that's potentially useful, and the stack just happens to be one source of information that's already there.

Now, as it turns out, it's a pretty useful source of information. And if you happen not to have proper tail recursion, it's even more useful, since it provides a path through the function call graph. But I've been finding stack traces in Scheme less informative, because with proper tail calls, there's less function-call history in the continuation.

I recognize that sometimes the "complexity budget" in language design necessitates using one feature to satisfy multiple requirements. But I'd like to see more investigation of linguistic diagnostics designed independently of existing language features. For example, it might be useful to provide configurable tracing facilities that record program history during runtime, where the tuning of how much gets recorded is completely independent of the space semantics of the evaluator. So you have a properly tail recursive semantics with a flexible tracing facility grafted on top.

What classifies a language feature as "purely diagnostic" might be that it is designed not to change the observable behavior of the program, but merely to report some additional information. Contracts-as-projections is an example.

Update: rephrased my rookie characterization of continuations.


grant rettke said...

Hi Dave,

Are you interested in the user facing aspects of such a tool, for example generate a Graphviz file that traces execution?

Or are you interested in the implementation of the tool itself?

Leo Meyerovich said...

I've actually been playing with extending JavaScript/web browser runtimes with an aspect system for the past month or so. Our interest has been cheaply and directly exposing useful hooks for enforcing common security policies, but, on the back of my mind, coopting our instrumentation for easier profiling and tracing has been tantalizing. For example, you might build a dtrace-like utility on top. We're interested in keeping costs close to zero (as opposed to something heavy like FBJS, Caja, or postMessage), so the interplay with interpreter features is interesting.

Ronald Garcia said...

You might appreciate Bil Lewis' talk at danfest about debugging support for Java (plus he's just plain entertaining.