Remove the Core flattener
This big MR entirely removes the "flattener" that took a type and replaced each type-family application with a fresh type variable. The flattener had its origin in the paper Injective type families for Haskell But (a) #25657 showed that flattening doesn't really work. (b) since we wrote the paper we have introduced the so-called "fine-grained" unifier GHC.Core.Unify, which can return * SurelyApart * Unifiable subst * MaybeApart subst where the MaybeApart says that the two types are not unifiable by a substitution, but could (perhaps) be unified "later" after some type family reductions. This turns out to subsume flattening. This MR does a major refactor of GHC.Core.Unify to make it capable of subsuming flattening. The main payload is described in Note [Apartness and type families] and its many wrinkles. The key (non-refactoring) implementation change is to add `um_fam_env` to the `UMState` in the unification monad. Careful review with Richard revealed various bugs in the treament of `kco`, the kind coercion carried around by the unifier, so that is substantially fixed too: see Note [Kind coercions in Unify]. Compile-time performance is improved by 0.1% with a few improvements over 1% and one worsening by 1.3% namely T9872a. (I have not investigated the latter.) Metric Decrease: T9872b T9872c TcPlugin_RewritePerf Metric Increase: T9872a
Showing
- compiler/GHC/Core/Coercion/Opt.hs 1 addition, 1 deletioncompiler/GHC/Core/Coercion/Opt.hs
- compiler/GHC/Core/FamInstEnv.hs 18 additions, 26 deletionscompiler/GHC/Core/FamInstEnv.hs
- compiler/GHC/Core/InstEnv.hs 22 additions, 17 deletionscompiler/GHC/Core/InstEnv.hs
- compiler/GHC/Core/Lint.hs 2 additions, 5 deletionscompiler/GHC/Core/Lint.hs
- compiler/GHC/Core/Predicate.hs 76 additions, 5 deletionscompiler/GHC/Core/Predicate.hs
- compiler/GHC/Core/TyCo/Compare.hs 6 additions, 4 deletionscompiler/GHC/Core/TyCo/Compare.hs
- compiler/GHC/Core/Unify.hs 1133 additions, 977 deletionscompiler/GHC/Core/Unify.hs
- compiler/GHC/Runtime/Heap/Inspect.hs 1 addition, 1 deletioncompiler/GHC/Runtime/Heap/Inspect.hs
- compiler/GHC/Tc/Errors.hs 2 additions, 1 deletioncompiler/GHC/Tc/Errors.hs
- compiler/GHC/Tc/Gen/Pat.hs 1 addition, 1 deletioncompiler/GHC/Tc/Gen/Pat.hs
- compiler/GHC/Tc/Instance/FunDeps.hs 3 additions, 3 deletionscompiler/GHC/Tc/Instance/FunDeps.hs
- compiler/GHC/Tc/Solver/Dict.hs 1 addition, 1 deletioncompiler/GHC/Tc/Solver/Dict.hs
- compiler/GHC/Tc/Solver/Equality.hs 15 additions, 9 deletionscompiler/GHC/Tc/Solver/Equality.hs
- compiler/GHC/Tc/Solver/InertSet.hs 0 additions, 128 deletionscompiler/GHC/Tc/Solver/InertSet.hs
- compiler/GHC/Tc/TyCl.hs 4 additions, 3 deletionscompiler/GHC/Tc/TyCl.hs
- compiler/GHC/Tc/TyCl/Instance.hs 3 additions, 4 deletionscompiler/GHC/Tc/TyCl/Instance.hs
- compiler/GHC/Tc/Types/Constraint.hs 2 additions, 51 deletionscompiler/GHC/Tc/Types/Constraint.hs
- compiler/GHC/Tc/Utils/Instantiate.hs 2 additions, 2 deletionscompiler/GHC/Tc/Utils/Instantiate.hs
- compiler/GHC/Tc/Utils/TcType.hs 2 additions, 1 deletioncompiler/GHC/Tc/Utils/TcType.hs
- compiler/GHC/Tc/Utils/Unify.hs 163 additions, 27 deletionscompiler/GHC/Tc/Utils/Unify.hs
Loading
Please register or sign in to comment