# [MLton] more edits to flatten.fun

Suresh Jagannathan suresh@cs.purdue.edu
Thu, 22 Jan 2004 18:45:10 -0500

```Indeed, it seems the best way to express deep flattening is as you
suggest,
and is actually formalized pretty well in the notes we made at ESOP a
few
years ago.  I think the structure of the analysis described in those
notes

-- Suresh

>
> If you want to hardwire the notion of "flatten everything deeply",
> then you might be able to succeed with an approach like this.  Even
> simpler (at least for fast experimentation), you could simply run the
> flatten pass over and over until it has nothing left to flatten.
>
> Also, I'm curious how your experiments with flattening all tuples (but
> not deeply) went.  It seems like that should be working before
> proceeding onto more complex stuff.
>
> If you want to do deep-flattening experiments, and possibly feed this
> back into our development, it might be better to take a step back and
> think about both the analysis and the transformation.  As it currently
> stands, the analysis cannot express deep flattening because it uses a
> two point lattice, which is only capable of encoding a decision about
> flattening the outermost tuple.
>
> In order to express deep flattening, you need a lattice that reflects
> the complete structure of tuple types and you need to change the
> transformation to do more than single round of detupling.
>
> To get a feel for such a lattice, have a look at
> constant-propagation.fun and useless.fun, both of which analyze tuples
> to their full depth.  I think it would be very nice to have an analog
> of these two passes for flattening, where the Value.t type includes a
> bool associated with each abstract tuple indicating whether or not it
> should be flattened.  The analysis would annotate each variable in the
> program with such a value.  Then, one could write a corresponding
> transformation that works with *any* annotation, inserting the
> appropriate tupling/detupling coercions to convert between tuples with
> different annotations.  The transformation would be a generalization
> of the current flatten.fun, so that if the annotation corresponded to
> it at the outermost tuple in types and always said to keep tuples on
> the inner levels, then we would get exactly the transformation we have
> now.  It would also be easy to experiment with other analyses,
> e.g. one that said "always flatten deeply", or even one that said
> "always flatten the outermost two levels".
>
> I realize this isn't super precise, but hopefully this gives you some
> idea?
>
> _______________________________________________
> MLton mailing list
> MLton@mlton.org
> http://www.mlton.org/mailman/listinfo/mlton
>

```