Skip to content

Draft: Decompose when making a type concrete

sheaf requested to merge sheaf/ghc:T23883 into master

This MR aims to fix #23883.

@simonpj laid out a plan in #23883 (comment 522363), but it turned out that it was not sufficient, as the compiler would still panic after changing mkScaledFunTys to tcMkScaledFunTys.

My idea to fix the issue more comprehensively is to instead ensure that, when making a type concrete, we decompose the resulting equalities as much as possible.

For example; suppose we want to make

TYPE a[sk]

concrete. We used to simply create a concrete metavariable kappa and emit

[W] kappa[conc] ~# TYPE a[sk]

With this patch, we instead create the concrete metavariable gamma and emit

[W] gamma[conc] ~# a[sk]

which is equivalent to decomposing the previous equality with the substitution

kappa[conc] := TYPE gamma[conc]

These changes mean that the compiler no longer panics on calls such as

typeTypeOrConstraint kappa
getRuntimeRep kappa

because we will instead be calling

typeTypeOrConstraint (TYPE gamma) = TypeLike
getRuntimeRep (TYPE gamma) = gamma

See Note [Decompose when making a type concrete] in GHC.Tc.Utils.Concrete.

TODO:

  • See if we can get rid of other calls to tcMkScaledFunTys in the compiler, as they may no longer panic after this change.
  • Investigate changes in the testsuite.
Edited by sheaf

Merge request reports