Fix over-eager inlining in SimpleOpt
In GHC.Core.SimpleOpt, I found that its inlining could duplicate an arbitary redex inside a lambda! Consider (\xyz. x+y). The occurrence-analysis treats the lamdda as a group, and says that both x and y occur once, even though the occur under the lambda-z. See Note [Occurrence analysis for lambda binders] in OccurAnal. When the lambda is under-applied in a call, the Simplifier is careful to zap the occ-info on x,y, because they appear under the \z. (See the call to zapLamBndrs in simplExprF1.) But SimpleOpt missed this test, resulting in #19347. So this patch * commons up the binder-zapping in GHC.Core.Utils.zapLamBndrs. * Calls this new function from GHC.Core.Opt.Simplify * Adds a call to zapLamBndrs to GHC.Core.SimpleOpt.simple_app This change makes test T12990 regress somewhat, but it was always very delicate, so I'm going to put up with that. In this voyage I also discovered a small, rather unrelated infelicity in the Simplifier: * In GHC.Core.Opt.Simplify.simplNonRecX we should apply isStrictId to the OutId not the InId. See Note [Dark corner with levity polymorphism] It may never "bite", because SimpleOpt should have inlined all the levity-polymorphic compulsory inlnings already, but somehow it bit me at one point and it's generally a more solid thing to do. Fixing the main bug increases runtime allocation in test perf/should_run/T12990, for (acceptable) reasons explained in a comement on Metric Increase: T12990
Showing
- compiler/GHC/Core/Opt/OccurAnal.hs 17 additions, 9 deletionscompiler/GHC/Core/Opt/OccurAnal.hs
- compiler/GHC/Core/Opt/Simplify.hs 41 additions, 23 deletionscompiler/GHC/Core/Opt/Simplify.hs
- compiler/GHC/Core/SimpleOpt.hs 14 additions, 3 deletionscompiler/GHC/Core/SimpleOpt.hs
- compiler/GHC/Core/Utils.hs 29 additions, 4 deletionscompiler/GHC/Core/Utils.hs
- compiler/GHC/Driver/Main.hs 2 additions, 0 deletionscompiler/GHC/Driver/Main.hs
- compiler/GHC/Types/Basic.hs 6 additions, 1 deletioncompiler/GHC/Types/Basic.hs
- testsuite/tests/perf/should_run/T19347.hs 30 additions, 0 deletionstestsuite/tests/perf/should_run/T19347.hs
- testsuite/tests/perf/should_run/T19347.stdout 1 addition, 0 deletionstestsuite/tests/perf/should_run/T19347.stdout
- testsuite/tests/perf/should_run/all.T 5 additions, 0 deletionstestsuite/tests/perf/should_run/all.T
Loading
Please register or sign in to comment