[MLton] Var.t -> Type.t ?

Stephen Weeks MLton@mlton.org
Fri, 16 Jan 2004 10:16:44 -0800

>  Property.getSetOnce
> 	 (Var.plist, Property.initFun
> 	             (fn _ => {rep = let val r = Rep.new ()
> 				     in if Rep.flattenALL then r
>                                         else (Rep.tuplize r; r)
> 				     end,
> 			       tuple = ref NONE}))
> Is there anyway to get a Type from a Var?  Or better yet, a different way
> to accomplish setting varTuple?

I see two ways to go.  You could use a property to associate each
variable with its type.  You would do this with a new property that is
set using Function.foreachVar or Program.foreachVar.  Then, in the
initFun above you could have access to the variable (and hence it's
type) by replacing the _ with x.  Another possibility is to avoid the
use of the initFun entirely, change it to an initRaise, and set the
varTuple for each variable at its binding site (in doitStatement), at
which point the type is available.  This will probably require doing a
Function.dfs instead of Vector.foreach (blocks, ...) to make sure that
variable definitions are visited before uses.

I'd opt for the latter.

> doitTransfer does not set varTuple for any of its args, yet it calls
> flattens, so I will need to set varTuple there as well correct (once
> again the problem of not have the type readily available)?

You only need to set varTuple at each binding occurrence.  Transfers
don't bind variables, so I don't think you need to do anything there.
Variables are bound in formals to functions and blocks and in
statements -- have a look at Function.foreachVar and
Program.foreachVar in ssa-tree.fun to see this.

There may bit a bit more trickiness for PrimApp expressions that deal
with tuples, since the type of primitives don't change.  You may need
to insert some extra coercions in the transformation before/after