[MLton] profiling and tail calls

Matthew Fluet fluet@cs.cornell.edu
Tue, 16 Nov 2004 19:44:32 -0500 (EST)

> Wouldn't a better way than using Leave calls be simply to put enter calls
> just after all non-tail calls?  I.e., you never leave, you just re-enter
> your caller.  This would keep everything tail-recursive (or not) and would
> probably decrease the number of calls to these routines as a nice side effect.

IIRC, Enter/Leave are never "called" as functions.  They are just
syntactic markers in CoreML / XML / SXML / SSA.  At some point in either
RSSA or Machine, they are used to infer stack segments, which correspond
to lexical nesting of Enter/Leave.  These segments are what get encoded
into sequences of source function indices, and a frame index gets mapped
to such a sequence.  At this point, we can drop the Leave and the Enter
only sticks around as a marker for where to put a label, so that the time
profiling can be mapped to a particular label, which has a mapping to a
sequence of source function indices.