[Git][ghc/ghc][wip/tyconapp-opts] 7 commits: Shortcut mkTvSubstPrs on empty list

Ben Gamari gitlab at gitlab.haskell.org
Tue Apr 7 22:08:34 UTC 2020



Ben Gamari pushed to branch wip/tyconapp-opts at Glasgow Haskell Compiler / GHC


Commits:
bd3df703 by Ben Gamari at 2020-03-26T14:49:24-04:00
Shortcut mkTvSubstPrs on empty list

Surprisingly enough this reduces compilation time on Cabal by
nearly 1%.

- - - - -
854d9c44 by Ben Gamari at 2020-03-26T14:51:15-04:00
Shortcut coreView

- - - - -
0f03145f by Ömer Sinan Ağacan at 2020-03-29T10:37:40-04:00
Don't override proc CafInfos in ticky builds

Fixes #17947

Previously if we had a ticky label for a proc, IdLabels for the ticky
and proc would share the same Name. This caused overriding proc CafInfos
with the ticky CafInfos (i.e. NoCafRefs) during SRT analysis.

We now ignore the ticky labels when building SRTMaps. This makes sense
because:

- When building the current module they don't need to be in SRTMaps as
  they're initialized as non-CAFFY (see mkRednCountsLabel), so they
  don't take part in the dependency analysis and they're never added to
  SRTs.

  (Reminder: a "dependency" in the SRT analysis is a CAFFY dependency,
  non-CAFFY uses are not considered as dependencies for the algorithm)

- They don't appear in the interfaces as they're not exported, so it
  doesn't matter for cross-module concerns whether they're in the SRTMap
  or not.

- - - - -
21d40664 by Ben Gamari at 2020-04-07T15:01:05-04:00
expandSynTyCon_maybe: Special-case nullary tycons

This avoids both allocation and some instructions.

- - - - -
e04955eb by Ben Gamari at 2020-04-07T16:58:21-04:00
Don't allow isConstraintKindTyCon to inline

See #18026.

- - - - -
7f1928db by Ben Gamari at 2020-04-07T16:58:48-04:00
Optimise tcView

- - - - -
d620e8e4 by Ben Gamari at 2020-04-07T17:00:29-04:00
Inline expandSynTyCon_maybe

This is necessary to avoid some needless allocation since we currently
lack nested CPR on sums.

- - - - -


6 changed files:

- compiler/GHC/Cmm/CLabel.hs
- compiler/GHC/Cmm/Info/Build.hs
- compiler/GHC/Core/TyCo/Subst.hs
- compiler/GHC/Core/TyCon.hs
- compiler/GHC/Core/Type.hs
- compiler/GHC/StgToCmm/Utils.hs


Changes:

=====================================
compiler/GHC/Cmm/CLabel.hs
=====================================
@@ -108,7 +108,7 @@ module GHC.Cmm.CLabel (
         pprCLabel,
         isInfoTableLabel,
         isConInfoTableLabel,
-        isIdLabel
+        isIdLabel, isTickyLabel
     ) where
 
 #include "HsVersions.h"
@@ -268,6 +268,10 @@ isIdLabel :: CLabel -> Bool
 isIdLabel IdLabel{} = True
 isIdLabel _ = False
 
+isTickyLabel :: CLabel -> Bool
+isTickyLabel (IdLabel _ _ RednCounts) = True
+isTickyLabel _ = False
+
 -- This is laborious, but necessary. We can't derive Ord because
 -- Unique doesn't have an Ord instance. Note nonDetCmpUnique in the
 -- implementation. See Note [No Ord for Unique]
@@ -462,8 +466,7 @@ mkSRTLabel     :: Unique -> CLabel
 mkSRTLabel u = SRTLabel u
 
 mkRednCountsLabel :: Name -> CLabel
-mkRednCountsLabel       name    =
-  IdLabel name NoCafRefs RednCounts  -- Note [ticky for LNE]
+mkRednCountsLabel name = IdLabel name NoCafRefs RednCounts  -- Note [ticky for LNE]
 
 -- These have local & (possibly) external variants:
 mkLocalClosureLabel      :: Name -> CafInfo -> CLabel


=====================================
compiler/GHC/Cmm/Info/Build.hs
=====================================
@@ -818,8 +818,13 @@ doSRTs dflags moduleSRTInfo procs data_ = do
                       -- already updated by oneSRT
                       srtMap
                     CmmData _ (CmmStaticsRaw lbl _)
-                      | isIdLabel lbl ->
-                          -- not analysed by oneSRT, declare it non-CAFFY here
+                      | isIdLabel lbl && not (isTickyLabel lbl) ->
+                          -- Raw data are not analysed by oneSRT and they can't
+                          -- be CAFFY.
+                          -- Some ticky labels share the same Name with proc
+                          -- labels so we don't update the SRT map for ticky
+                          -- labels to avoid overriding CafInfos of procs.
+                          -- See #17947.
                           Map.insert (mkCAFLabel lbl) Nothing srtMap
                       | otherwise ->
                           -- Not an IdLabel, ignore


=====================================
compiler/GHC/Core/TyCo/Subst.hs
=====================================
@@ -423,6 +423,7 @@ zipTCvSubst tcvs tys
 -- | Generates the in-scope set for the 'TCvSubst' from the types in the
 -- incoming environment. No CoVars, please!
 mkTvSubstPrs :: [(TyVar, Type)] -> TCvSubst
+mkTvSubstPrs []  = emptyTCvSubst
 mkTvSubstPrs prs =
     ASSERT2( onlyTyVarsAndNoCoercionTy, text "prs" <+> ppr prs )
     mkTvSubst in_scope tenv


=====================================
compiler/GHC/Core/TyCon.hs
=====================================
@@ -2288,12 +2288,17 @@ expandSynTyCon_maybe
 -- ^ Expand a type synonym application, if any
 expandSynTyCon_maybe tc tys
   | SynonymTyCon { tyConTyVars = tvs, synTcRhs = rhs, tyConArity = arity } <- tc
-  = case tys `listLengthCmp` arity of
-        GT -> Just (tvs `zip` tys, rhs, drop arity tys)
-        EQ -> Just (tvs `zip` tys, rhs, [])
-        LT -> Nothing
+  = case tys of
+      [] -> Just ([], rhs, tys)
+      _  -> case tys `listLengthCmp` arity of
+              GT -> Just (tvs `zip` tys, rhs, drop arity tys)
+              EQ -> Just (tvs `zip` tys, rhs, [])
+              LT -> Nothing
    | otherwise
    = Nothing
+{-# INLINE expandSynTyCon_maybe #-}
+-- Inline to avoid allocation of tuples due to lack of nested CPR on sums.
+-- Particularly relevant to coreView and tcView, which are hammered.
 
 ----------------
 


=====================================
compiler/GHC/Core/Type.hs
=====================================
@@ -355,8 +355,11 @@ See also #11715, which tracks removing this inconsistency.
 -- See also Note [coreView vs tcView]
 {-# INLINE tcView #-}
 tcView :: Type -> Maybe Type
-tcView (TyConApp tc tys) | Just (tenv, rhs, tys') <- expandSynTyCon_maybe tc tys
-  = Just (mkAppTys (substTy (mkTvSubstPrs tenv) rhs) tys')
+tcView (TyConApp tc tys)
+  | Just (tenv, rhs, tys') <- expandSynTyCon_maybe tc tys
+  = Just $ case tenv of
+             [] -> mkAppTys rhs tys'
+             _  -> mkAppTys (substTy (mkTvSubstPrs tenv) rhs) tys'
                -- The free vars of 'rhs' should all be bound by 'tenv', so it's
                -- ok to use 'substTy' here.
                -- See also Note [The substitution invariant] in GHC.Core.TyCo.Subst.
@@ -376,7 +379,9 @@ coreView :: Type -> Maybe Type
 -- joined onto the case analysis that the caller is already doing
 coreView ty@(TyConApp tc tys)
   | Just (tenv, rhs, tys') <- expandSynTyCon_maybe tc tys
-  = Just (mkAppTys (substTy (mkTvSubstPrs tenv) rhs) tys')
+  = Just $ case tenv of
+            [] -> mkAppTys rhs tys'
+            _  -> mkAppTys (substTy (mkTvSubstPrs tenv) rhs) tys'
     -- This equation is exactly like tcView
 
   -- At the Core level, Constraint = Type
@@ -2936,6 +2941,7 @@ during type inference.
 
 isConstraintKindCon :: TyCon -> Bool
 isConstraintKindCon tc = tyConUnique tc == constraintKindTyConKey
+{-# NOINLINE isConstraintKindCon #-}
 
 -- | Tests whether the given kind (which should look like @TYPE x@)
 -- is something other than a constructor tree (that is, constructors at every node).


=====================================
compiler/GHC/StgToCmm/Utils.hs
=====================================
@@ -11,8 +11,8 @@
 
 module GHC.StgToCmm.Utils (
         cgLit, mkSimpleLit,
-        emitRawDataLits, mkRawDataLits,
-        emitRawRODataLits, mkRawRODataLits,
+        emitRawDataLits,
+        emitRawRODataLits,
         emitDataCon,
         emitRtsCall, emitRtsCallWithResult, emitRtsCallGen,
         assignTemp, newTemp,



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f25cda0c941a6643c635eaa21803d7c2e50892c2...d620e8e4e9bdb479391a50967eaaad0996a71d9d

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/f25cda0c941a6643c635eaa21803d7c2e50892c2...d620e8e4e9bdb479391a50967eaaad0996a71d9d
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/20200407/4964485d/attachment-0001.html>


More information about the ghc-commits mailing list