Wolfgang Jeltsch pushed to branch wip/jeltsch/smaller-pit at Glasgow Haskell Compiler / GHC

Commits:

3 changed files:

Changes:

  • compiler/GHC/Iface/Binary.hs
    ... ... @@ -197,7 +197,7 @@ getIfaceWithExtFields name_cache bh = do
    197 197
       modIfaceBinData <- freezeBinHandle bh start
    
    198 198
       pure $ mod_iface
    
    199 199
         & set_mi_ext_fields extFields
    
    200
    -    & set_mi_hi_bytes (FullIfaceBinHandle $ Strict.Just modIfaceBinData)
    
    200
    +    & set_mi_hi_bytes (Strict.Just modIfaceBinData)
    
    201 201
     
    
    202 202
     -- | This performs a get action after reading the dictionary and symbol
    
    203 203
     -- table. It is necessary to run this before trying to deserialise any
    
    ... ... @@ -276,10 +276,10 @@ writeBinIface profile traceBinIface compressionLevel hi_path mod_iface = do
    276 276
     putIfaceWithExtFields :: TraceBinIFace -> CompressionIFace -> WriteBinHandle -> ModIface -> IO ()
    
    277 277
     putIfaceWithExtFields traceBinIface compressionLevel bh mod_iface =
    
    278 278
       case mi_hi_bytes mod_iface of
    
    279
    -    FullIfaceBinHandle Strict.Nothing -> do
    
    279
    +    Strict.Nothing -> do
    
    280 280
           forwardPutRel_ bh (\_ -> put_ bh (mi_ext_fields mod_iface)) $ do
    
    281 281
             putWithUserData traceBinIface compressionLevel bh mod_iface
    
    282
    -    FullIfaceBinHandle (Strict.Just binData) -> putFullBinData bh binData
    
    282
    +    Strict.Just binData -> putFullBinData bh binData
    
    283 283
     
    
    284 284
     -- | Put a piece of data with an initialised `UserData` field. This
    
    285 285
     -- is necessary if you want to serialise Names or FastStrings.
    

  • compiler/GHC/Iface/Make.hs
    ... ... @@ -77,6 +77,7 @@ import GHC.Iface.Binary
    77 77
     
    
    78 78
     import GHC.Data.FastString
    
    79 79
     import GHC.Data.Maybe
    
    80
    +import qualified GHC.Data.Strict as Strict
    
    80 81
     
    
    81 82
     import GHC.HsToCore.Docs
    
    82 83
     import GHC.HsToCore.Usage
    
    ... ... @@ -394,7 +395,7 @@ mkIface_ hsc_env
    394 395
               & set_mi_docs             docs
    
    395 396
               & set_mi_abi_hashes       ()
    
    396 397
               & set_mi_ext_fields       emptyExtensibleFields
    
    397
    -          & set_mi_hi_bytes         PartialIfaceBinHandle
    
    398
    +          & set_mi_hi_bytes         Strict.Nothing
    
    398 399
     
    
    399 400
       where
    
    400 401
          cmp_rule     = lexicalCompareFS `on` ifRuleName
    

  • compiler/GHC/Unit/Module/ModIface.hs
    ... ... @@ -70,7 +70,7 @@ module GHC.Unit.Module.ModIface
    70 70
        , set_mi_hash_fn
    
    71 71
        , completePartialModIface
    
    72 72
        , shrinkModIface
    
    73
    -   , IfaceBinHandle(..)
    
    73
    +   , IfaceBinHandle
    
    74 74
        , PartialModIface
    
    75 75
        , RetainedModIface
    
    76 76
        , IfaceAbiHashes (..)
    
    ... ... @@ -160,6 +160,7 @@ import GHC.Utils.Binary
    160 160
     
    
    161 161
     import Control.DeepSeq
    
    162 162
     import Control.Exception
    
    163
    +import Data.Void (Void)
    
    163 164
     
    
    164 165
     
    
    165 166
     {- Note [Interface file stages]
    
    ... ... @@ -236,15 +237,10 @@ data ModIfacePhase
    236 237
     -- | In-memory byte array representation of a 'ModIface'.
    
    237 238
     --
    
    238 239
     -- See Note [Sharing of ModIface] for why we need this.
    
    239
    -data IfaceBinHandle (phase :: ModIfacePhase) where
    
    240
    -  -- | A partial 'ModIface' cannot be serialised to disk.
    
    241
    -  PartialIfaceBinHandle :: IfaceBinHandle 'ModIfaceCore
    
    242
    -  -- | Optional 'FullBinData' that can be serialised to disk directly.
    
    243
    -  --
    
    244
    -  -- See Note [Private fields in ModIface] for when this fields needs to be cleared
    
    245
    -  -- (e.g., set to 'Nothing').
    
    246
    -  FullIfaceBinHandle :: !(Strict.Maybe FullBinData) -> IfaceBinHandle 'ModIfaceFinal
    
    247
    -  RetainedIfaceBinHandle :: IfaceBinHandle 'ModIfaceRetained
    
    240
    +type family IfaceBinHandle (phase :: ModIfacePhase) where
    
    241
    +  IfaceBinHandle 'ModIfaceCore     = Void
    
    242
    +  IfaceBinHandle 'ModIfaceFinal    = FullBinData
    
    243
    +  IfaceBinHandle 'ModIfaceRetained = Void
    
    248 244
     
    
    249 245
     type family IfaceSelfRecompData (phase :: ModIfacePhase) where
    
    250 246
       IfaceSelfRecompData 'ModIfaceCore     = Maybe IfaceSelfRecomp
    
    ... ... @@ -322,11 +318,22 @@ withSelfRecomp iface nk jk =
    322 318
     -- fields.
    
    323 319
     data ModIface_ (phase :: ModIfacePhase)
    
    324 320
       = PrivateModIface {
    
    325
    -        mi_hi_bytes_ :: !(IfaceBinHandle phase),
    
    326
    -                -- ^ A serialised in-memory buffer of this 'ModIface'.
    
    327
    -                -- If this handle is given, we can avoid serialising the 'ModIface'
    
    328
    -                -- when writing this 'ModIface' to disk, and write this buffer to disk instead.
    
    329
    -                -- See Note [Sharing of ModIface].
    
    321
    +        mi_hi_bytes_ :: !(Strict.Maybe (IfaceBinHandle phase)),
    
    322
    +                -- ^ Optionally an in-memory buffer that contains the
    
    323
    +                --   serialization of this 'ModIface'. If such a buffer is
    
    324
    +                --   present, we can avoid serialising the 'ModIface' when
    
    325
    +                --   writing it to disk and write this buffer instead. See
    
    326
    +                --   Note [Sharing of ModIface] and
    
    327
    +                --   Note [Private fields in ModIface].
    
    328
    +                --
    
    329
    +                --   Only in the 'ModIfaceFinal' phase, there can be a buffer
    
    330
    +                --   with the serialization. Both @IfaceBinHandle 'ModIfaceCore@
    
    331
    +                --   and @IfaceBinHandle 'ModIfaceRetained@ are defined to be
    
    332
    +                --   'Void', so that the 'mi_hi_bytes' field gets the type
    
    333
    +                --   @Strict.Maybe Void@. This type is isomorphic to '()', even
    
    334
    +                --   when taking partially defined values into account, because
    
    335
    +                --   @Strict.Just undefined@ is @undefined@ and so @Nothing@ and
    
    336
    +                --   @undefined@ are the only inhabitants of that type.
    
    330 337
             mi_iface_hash_  :: Fingerprint, -- A hash of the whole interface
    
    331 338
     
    
    332 339
             mi_mod_info_     :: IfaceModInfo,
    
    ... ... @@ -718,7 +725,7 @@ instance Binary ModIface where
    718 725
                      -- We can't populate this field here, as we are
    
    719 726
                      -- missing the 'mi_ext_fields_' field, which is
    
    720 727
                      -- handled in 'getIfaceWithExtFields'.
    
    721
    -                 mi_hi_bytes_    = FullIfaceBinHandle Strict.Nothing
    
    728
    +                 mi_hi_bytes_    = Strict.Nothing
    
    722 729
                      })
    
    723 730
     
    
    724 731
     instance Binary IfaceModInfo where
    
    ... ... @@ -833,7 +840,7 @@ emptyPartialModIface mod
    833 840
       = PrivateModIface
    
    834 841
           { mi_mod_info_    = emptyIfaceModInfo mod,
    
    835 842
             mi_iface_hash_  = fingerprint0,
    
    836
    -        mi_hi_bytes_    = PartialIfaceBinHandle,
    
    843
    +        mi_hi_bytes_    = Strict.Nothing,
    
    837 844
             mi_deps_        = noDependencies,
    
    838 845
             mi_public_      = emptyPublicModIface [] [] [] [] [] [] [] (),
    
    839 846
             mi_simplified_core_ = Nothing,
    
    ... ... @@ -907,7 +914,7 @@ emptyFullModIface :: Module -> ModIface
    907 914
     emptyFullModIface mod =
    
    908 915
         (emptyPartialModIface mod)
    
    909 916
           { mi_public_ = emptyPublicModIface [] [] [] [] [] [] [] emptyIfaceBackend
    
    910
    -      , mi_hi_bytes_ = FullIfaceBinHandle Strict.Nothing
    
    917
    +      , mi_hi_bytes_ = Strict.Nothing
    
    911 918
           }
    
    912 919
     
    
    913 920
     
    
    ... ... @@ -940,7 +947,7 @@ instance ( NFData (IfaceSelfRecompData phase)
    940 947
              , NFData (IfaceAbiHashesData phase)
    
    941 948
              ) => NFData (ModIface_ phase) where
    
    942 949
       rnf (PrivateModIface a1 a2 a3 a4 a5 a6 a7 a8 a9 a10)
    
    943
    -    = (a1 :: IfaceBinHandle phase)
    
    950
    +    = a1
    
    944 951
         `seq` rnf a2
    
    945 952
         `seq` rnf a3
    
    946 953
         `seq` rnf a4
    
    ... ... @@ -1051,7 +1058,7 @@ completePartialModIface :: PartialModIface
    1051 1058
     completePartialModIface partial iface_hash decls extra_decls final_exts cache = partial
    
    1052 1059
       { mi_public_ = completePublicModIface decls final_exts cache (mi_public_ partial)
    
    1053 1060
       , mi_simplified_core_ = extra_decls
    
    1054
    -  , mi_hi_bytes_ = FullIfaceBinHandle Strict.Nothing
    
    1061
    +  , mi_hi_bytes_ = Strict.Nothing
    
    1055 1062
       , mi_iface_hash_ = iface_hash
    
    1056 1063
       }
    
    1057 1064
     
    
    ... ... @@ -1072,7 +1079,7 @@ shrinkModIface :: ModIface -> RetainedModIface
    1072 1079
     shrinkModIface PrivateModIface {..}
    
    1073 1080
       = PrivateModIface
    
    1074 1081
         {
    
    1075
    -      mi_hi_bytes_        = RetainedIfaceBinHandle,
    
    1082
    +      mi_hi_bytes_        = Strict.Nothing,
    
    1076 1083
           mi_public_          = shrinkIfacePublic mi_public_,
    
    1077 1084
           mi_self_recomp_     = (),
    
    1078 1085
           mi_simplified_core_ = (),
    
    ... ... @@ -1100,7 +1107,7 @@ set_mi_mod_info val iface = clear_mi_hi_bytes $ iface { mi_mod_info_ = val }
    1100 1107
     set_mi_self_recomp :: IfaceSelfRecompData phase -> ModIface_ phase -> ModIface_ phase
    
    1101 1108
     set_mi_self_recomp val iface = clear_mi_hi_bytes $ iface { mi_self_recomp_ = val }
    
    1102 1109
     
    
    1103
    -set_mi_hi_bytes :: IfaceBinHandle phase -> ModIface_ phase -> ModIface_ phase
    
    1110
    +set_mi_hi_bytes :: Strict.Maybe (IfaceBinHandle phase) -> ModIface_ phase -> ModIface_ phase
    
    1104 1111
     set_mi_hi_bytes val iface = iface { mi_hi_bytes_ = val }
    
    1105 1112
     
    
    1106 1113
     set_mi_deps :: Dependencies -> ModIface_ phase -> ModIface_ phase
    
    ... ... @@ -1203,12 +1210,7 @@ set_mi_mod_info_field f iface = clear_mi_hi_bytes $ iface { mi_mod_info_ = f (mi
    1203 1210
     
    
    1204 1211
     -- | Invalidate any byte array buffer we might have.
    
    1205 1212
     clear_mi_hi_bytes :: ModIface_ phase -> ModIface_ phase
    
    1206
    -clear_mi_hi_bytes iface = iface
    
    1207
    -  { mi_hi_bytes_ = case mi_hi_bytes iface of
    
    1208
    -      PartialIfaceBinHandle  -> PartialIfaceBinHandle
    
    1209
    -      FullIfaceBinHandle _   -> FullIfaceBinHandle Strict.Nothing
    
    1210
    -      RetainedIfaceBinHandle -> RetainedIfaceBinHandle
    
    1211
    -  }
    
    1213
    +clear_mi_hi_bytes iface = iface { mi_hi_bytes_ = Strict.Nothing }
    
    1212 1214
     
    
    1213 1215
     -- ----------------------------------------------------------------------------
    
    1214 1216
     -- 'ModIface' pattern synonyms to keep breakage low.
    
    ... ... @@ -1319,7 +1321,7 @@ pattern ModIface ::
    1319 1321
       -> Maybe Docs
    
    1320 1322
       -> IfaceAbiHashesData phase
    
    1321 1323
       -> ExtensibleFieldsData phase
    
    1322
    -  -> IfaceBinHandle phase
    
    1324
    +  -> Strict.Maybe (IfaceBinHandle phase)
    
    1323 1325
       -> IfaceSelfRecompData phase
    
    1324 1326
       -> (OccName -> Maybe Fixity)
    
    1325 1327
       -> (OccName -> Maybe (OccName, Fingerprint))