Eliminate unsafeEqualityProof in CorePrep
The main idea here is to avoid treating * case e of {} * case unsafeEqualityProof of UnsafeRefl co -> blah specially in CoreToStg. Instead, nail them in CorePrep, by converting case e of {} ==> e |> unsafe-co case unsafeEqualityProof of UnsafeRefl cv -> blah ==> blah[unsafe-co/cv] in GHC.Core.Prep. Now expressions that we want to treat as trivial really are trivial. We can get rid of cpExprIsTrivial. And we fix #19700. A downside is that, at least under unsafeEqualityProof, we substitute in types and coercions, which is more work. But a big advantage is that it's all very simple and principled: CorePrep really gets rid of the unsafeCoerce stuff, as it does empty case, runRW#, lazyId etc. I've updated the overview in GHC.Core.Prep, and added Note [Unsafe coercions] in GHC.Core.Prep Note [Implementing unsafeCoerce] in base:Unsafe.Coerce We get 3% fewer bytes allocated when compiling perf/compiler/T5631, which uses a lot of unsafeCoerces. (It's a happy-generated parser.) Metric Decrease: T5631
Showing
- compiler/GHC/Core.hs 1 addition, 1 deletioncompiler/GHC/Core.hs
- compiler/GHC/Core/Coercion.hs 3 additions, 0 deletionscompiler/GHC/Core/Coercion.hs
- compiler/GHC/Core/Coercion/Opt.hs 1 addition, 0 deletionscompiler/GHC/Core/Coercion/Opt.hs
- compiler/GHC/Core/FVs.hs 1 addition, 0 deletionscompiler/GHC/Core/FVs.hs
- compiler/GHC/Core/Lint.hs 10 additions, 1 deletioncompiler/GHC/Core/Lint.hs
- compiler/GHC/Core/Subst.hs 1 addition, 1 deletioncompiler/GHC/Core/Subst.hs
- compiler/GHC/Core/TyCo/FVs.hs 2 additions, 0 deletionscompiler/GHC/Core/TyCo/FVs.hs
- compiler/GHC/Core/TyCo/Rep.hs 5 additions, 0 deletionscompiler/GHC/Core/TyCo/Rep.hs
- compiler/GHC/Core/TyCo/Subst.hs 1 addition, 0 deletionscompiler/GHC/Core/TyCo/Subst.hs
- compiler/GHC/Core/TyCo/Tidy.hs 1 addition, 0 deletionscompiler/GHC/Core/TyCo/Tidy.hs
- compiler/GHC/Core/Type.hs 4 additions, 0 deletionscompiler/GHC/Core/Type.hs
- compiler/GHC/Core/Unfold.hs 1 addition, 1 deletioncompiler/GHC/Core/Unfold.hs
- compiler/GHC/CoreToIface.hs 2 additions, 0 deletionscompiler/GHC/CoreToIface.hs
- compiler/GHC/CoreToStg.hs 31 additions, 36 deletionscompiler/GHC/CoreToStg.hs
- compiler/GHC/CoreToStg/Prep.hs 341 additions, 157 deletionscompiler/GHC/CoreToStg/Prep.hs
- compiler/GHC/StgToByteCode.hs 1 addition, 1 deletioncompiler/GHC/StgToByteCode.hs
- compiler/GHC/Tc/TyCl/Utils.hs 1 addition, 0 deletionscompiler/GHC/Tc/TyCl/Utils.hs
- compiler/GHC/Tc/Utils/TcMType.hs 1 addition, 0 deletionscompiler/GHC/Tc/Utils/TcMType.hs
- compiler/GHC/Types/Id/Make.hs 1 addition, 1 deletioncompiler/GHC/Types/Id/Make.hs
- libraries/base/Unsafe/Coerce.hs 9 additions, 23 deletionslibraries/base/Unsafe/Coerce.hs
Loading
Please register or sign in to comment