[Git][ghc/ghc][wip/T18078] A few improvements

Sebastian Graf gitlab at gitlab.haskell.org
Wed May 27 13:38:25 UTC 2020



Sebastian Graf pushed to branch wip/T18078 at Glasgow Haskell Compiler / GHC


Commits:
a36eb7d5 by Sebastian Graf at 2020-05-27T15:29:40+02:00
A few improvements

- Inline `finalPhase`
- Remove `isFinalPhase` and use `== FinalPhase` instead
- A few comment improvements

- - - - -


5 changed files:

- compiler/GHC/Core/Opt/Driver.hs
- compiler/GHC/Core/Opt/Simplify/Utils.hs
- compiler/GHC/Core/Opt/SpecConstr.hs
- compiler/GHC/Core/Opt/WorkWrap.hs
- compiler/GHC/Types/Basic.hs


Changes:

=====================================
compiler/GHC/Core/Opt/Driver.hs
=====================================
@@ -165,7 +165,7 @@ getCoreToDo dflags
 
     -- Run GHC's internal simplification phase, after all rules have run.
     -- See Note [Compiler phases] in GHC.Types.Basic
-    simplify name = simpl_phase finalPhase name max_iter
+    simplify name = simpl_phase FinalPhase name max_iter
 
     -- initial simplify: mk specialiser happy: minimum effort please
     simpl_gently = CoreDoSimplify max_iter
@@ -205,7 +205,7 @@ getCoreToDo dflags
      if opt_level == 0 then
        [ static_ptrs_float_outwards,
          CoreDoSimplify max_iter
-             (base_mode { sm_phase = finalPhase
+             (base_mode { sm_phase = FinalPhase
                         , sm_names = ["Non-opt simplification"] })
        ]
 
@@ -306,7 +306,7 @@ getCoreToDo dflags
 
         runWhen do_float_in CoreDoFloatInwards,
 
-        maybe_rule_check finalPhase,
+        maybe_rule_check FinalPhase,
 
                 -- Case-liberation for -O2.  This should be after
                 -- strictness analysis and the simplification which follows it.
@@ -319,7 +319,7 @@ getCoreToDo dflags
 
         runWhen spec_constr CoreDoSpecConstr,
 
-        maybe_rule_check finalPhase,
+        maybe_rule_check FinalPhase,
 
         runWhen late_specialise
           (CoreDoPasses [ CoreDoSpecialising
@@ -345,7 +345,7 @@ getCoreToDo dflags
         -- can become /exponentially/ more expensive. See #11731, #12996.
         runWhen (strictness || late_dmd_anal) CoreDoDemand,
 
-        maybe_rule_check finalPhase
+        maybe_rule_check FinalPhase
      ]
 
     -- Remove 'CoreDoNothing' and flatten 'CoreDoPasses' for clarity.


=====================================
compiler/GHC/Core/Opt/Simplify/Utils.hs
=====================================
@@ -1093,7 +1093,7 @@ seems to be to do a callSiteInline based on the fact that there is
 something interesting about the call site (it's strict).  Hmm.  That
 seems a bit fragile.
 
-Conclusion: inline top level things gaily until finalPhase (the last
+Conclusion: inline top level things gaily until FinalPhase (the last
 phase), at which point don't.
 
 Note [pre/postInlineUnconditionally in gentle mode]
@@ -1216,7 +1216,7 @@ preInlineUnconditionally env top_lvl bndr rhs rhs_env
       -- not ticks.  Counting ticks cannot be duplicated, and non-counting
       -- ticks around a Lam will disappear anyway.
 
-    early_phase = not (isFinalPhase (sm_phase mode))
+    early_phase = sm_phase mode /= FinalPhase
     -- If we don't have this early_phase test, consider
     --      x = length [1,2,3]
     -- The full laziness pass carefully floats all the cons cells to


=====================================
compiler/GHC/Core/Opt/SpecConstr.hs
=====================================
@@ -1760,8 +1760,8 @@ Note [Transfer activation]
 In which phase should the specialise-constructor rules be active?
 Originally I made them always-active, but Manuel found that this
 defeated some clever user-written rules.  Then I made them active only
-in finalPhase; after all, currently, the specConstr transformation is
-only run after the simplifier has reached finalPhase, but that meant
+in FinalPhase; after all, currently, the specConstr transformation is
+only run after the simplifier has reached FinalPhase, but that meant
 that specialisations didn't fire inside wrappers; see test
 simplCore/should_compile/spec-inline.
 


=====================================
compiler/GHC/Core/Opt/WorkWrap.hs
=====================================
@@ -435,9 +435,9 @@ Conclusion:
     phase 0, the last user-visible phase.  That means that all
     rules will have had a chance to fire.
 
-    What phase is after phase 0?  Answer: finalPhase, phase (-1).
-    That's the reason finalPhase exists. NB: user's can't write
-    INLINE[-1] f; it's syntactically illegal.
+    What phase is after phase 0?  Answer: FinalPhase, that's the reason it
+    exists. NB: Similar to InitialPhase, users can't write INLINE[Final] f;
+    it's syntactically illegal.
 
   - Otherwise inline wrapper in phase 2.  That allows the
     'gentle' simplification pass to apply specialisation rules


=====================================
compiler/GHC/Types/Basic.hs
=====================================
@@ -83,7 +83,6 @@ module GHC.Types.Basic (
         Activation(..), isActive, competesWith,
         isNeverActive, isAlwaysActive, activeInFinalPhase,
         activateAfterInitial, activateDuringFinal,
-        finalPhase, isFinalPhase,
 
         RuleMatchInfo(..), isConLike, isFunLike,
         InlineSpec(..), noUserInlineSpec,
@@ -1332,7 +1331,8 @@ type PhaseNum = Int  -- Compilation phase
 data CompilerPhase
   = InitialPhase    -- The first phase -- number = infinity!
   | Phase PhaseNum  -- User-specificable phases
-  | FinalPhase
+  | FinalPhase      -- The last phase  -- number = -infinity!
+  deriving Eq
 
 instance Outputable CompilerPhase where
    ppr (Phase n)    = int n
@@ -1360,13 +1360,6 @@ activateDuringFinal :: Activation
 -- Active in the final simplification phase (which is repeated)
 activateDuringFinal = FinalActive
 
-finalPhase :: CompilerPhase
-finalPhase = FinalPhase
-
-isFinalPhase :: CompilerPhase -> Bool
-isFinalPhase FinalPhase = True
-isFinalPhase _          = False
-
 isActive :: CompilerPhase -> Activation -> Bool
 isActive InitialPhase act = activeInInitialPhase act
 isActive (Phase p)    act = activeInPhase p act



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a36eb7d5e727b72d550adae7cb473c73947d6e13

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/a36eb7d5e727b72d550adae7cb473c73947d6e13
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20200527/409f29b4/attachment-0001.html>


More information about the ghc-commits mailing list