Optimizer too smart....
Stephen Weeks
MLton@research.nj.nec.com
Wed, 2 Feb 2000 22:46:28 -0800 (PST)
> I tracked the bug down... it's the transparency optimization that's causing
> the bug...
>
> i.e. a datataype is being turned into a tuple... .. I think, I can hack
> around this problem myself... I need to disable the transparency
> optimization only for constructors that are region allocated. This shouldn't be
> hard to do at all as I can figure this out just by looking at the type of
> the value carried by the constructor.
>
> Should, I just be able to hack simplify-types.fun and have things work, or
> might disabling transparency have some no so obvious effects?
I think you should be able to modify "fun transparent ..." to do what
you want. You might have to do something similar in
backend/representation.fun, since it also turns datatypes with one
variant into tuples. However ...
I think I now understand your problem. You generate primitives which
have a certain argument type (the datatype), and simplify-types is
changing the argument type to the tuple type -- hence the type error.
If this is correct, I think that the right fix is to use the single
polymorphic primitive instead of the dynamically generated family, and
let the optimization passes patch the type args (as they already have
to do for other polymorphic primitives). This means you won't have to
change any of the optimization passes, and would only have to muck
with prim.fun and extract-targs.fun in the way I described earlier --
and you could stick with your type-safe => runtime-safe scheme.
Many of the Cps optimization passes (e.g. useless,
constant-propagation) assume that cprims only take arguments of the
types described in the FFI section of the manual (unfortunately this
invariant is never stated nor checked). Thus, if you want primitives
taking tuples and datatypes (neither of which are allowed for cprims),
the only safe solution is to make the primitives be recognized by the
compiler and to either make them polymorphic (which I recommend in
this case) or fix all of the optimization passes to patch the types.