Simon Peyton Jones pushed to branch wip/spj-reinstallable-base at Glasgow Haskell Compiler / GHC

Commits:

8 changed files:

Changes:

  • compiler/GHC/Builtin/Names.hs
    ... ... @@ -210,6 +210,7 @@ basicKnownKeyTable
    210 210
         , (mkTcOcc "Bounded",      boundedClassKey)
    
    211 211
         , (mkTcOcc "Enum",         enumClassKey)
    
    212 212
         , (mkTcOcc "Monad",        monadClassKey)
    
    213
    +    , (mkTcOcc "Functor",      functorClassKey)
    
    213 214
         ]
    
    214 215
     
    
    215 216
     basicKnownKeyNames :: [Name]  -- See Note [Known-key names]
    
    ... ... @@ -218,7 +219,6 @@ basicKnownKeyNames
    218 219
      ++ [   --  Classes.  *Must* include:
    
    219 220
             --      classes that are grabbed by key (e.g., eqClassKey)
    
    220 221
             --      classes in "Class.standardClassKeys" (quite a few)
    
    221
    -        functorClassName,
    
    222 222
             realClassName,                  -- numeric
    
    223 223
             integralClassName,              -- numeric
    
    224 224
             fractionalClassName,            -- numeric
    

  • compiler/GHC/HsToCore/Monad.hs
    ... ... @@ -563,7 +563,7 @@ mkNamePprCtxDs = ds_name_ppr_ctx <$> getGblEnv
    563 563
     instance MonadThings (IOEnv (Env DsGblEnv DsLclEnv)) where
    
    564 564
         lookupThing = dsLookupGlobal
    
    565 565
     
    
    566
    -dsLookupKnownKey :: Unique -> DsM TyThing
    
    566
    +dsLookupKnownKey :: KnownKeyNameKey -> DsM TyThing
    
    567 567
     dsLookupKnownKey uniq
    
    568 568
       = do { rebindable_path <- goptM Opt_RebindableKnownKeyNames
    
    569 569
            ; mb_rdr_env <- if rebindable_path
    
    ... ... @@ -575,7 +575,7 @@ dsLookupKnownKey uniq
    575 575
                      Succeeded thing -> return thing
    
    576 576
                      Failed msg -> failIfM (pprDiagnostic msg) } }
    
    577 577
     
    
    578
    -dsLookupKnownKeyTyCon :: Unique -> DsM TyCon
    
    578
    +dsLookupKnownKeyTyCon :: KnownKeyNameKey -> DsM TyCon
    
    579 579
     dsLookupKnownKeyTyCon uniq
    
    580 580
       = tyThingTyCon <$> dsLookupKnownKey uniq
    
    581 581
     
    

  • compiler/GHC/Iface/Errors/Ppr.hs
    ... ... @@ -13,6 +13,7 @@ module GHC.Iface.Errors.Ppr
    13 13
       , missingInterfaceErrorReason
    
    14 14
       , missingInterfaceErrorDiagnostic
    
    15 15
       , readInterfaceErrorDiagnostic
    
    16
    +  , defaultIfaceMessageOpts
    
    16 17
     
    
    17 18
       , lookingForHerald
    
    18 19
       , cantFindErrorX
    

  • compiler/GHC/Iface/Load.hs
    ... ... @@ -4,6 +4,7 @@
    4 4
     
    
    5 5
     -}
    
    6 6
     
    
    7
    +{-# LANGUAGE CPP #-}
    
    7 8
     {-# LANGUAGE NondecreasingIndentation #-}
    
    8 9
     {-# LANGUAGE TypeFamilies #-}
    
    9 10
     
    
    ... ... @@ -63,10 +64,7 @@ import GHC.Iface.Binary
    63 64
     import GHC.Iface.Rename
    
    64 65
     import GHC.Iface.Env
    
    65 66
     import GHC.Iface.Errors as Iface_Errors
    
    66
    -
    
    67
    -import GHC.Rename.Env( addUsedGRE )
    
    68
    -import GHC.Rename.Utils( DeprecationWarnings(..) )
    
    69
    -
    
    67
    +import GHC.Iface.Errors.Ppr( defaultIfaceMessageOpts )
    
    70 68
     import GHC.Tc.Errors.Types
    
    71 69
     import GHC.Tc.Utils.Monad
    
    72 70
     
    
    ... ... @@ -101,7 +99,7 @@ import GHC.Types.SourceFile
    101 99
     import GHC.Types.SafeHaskell
    
    102 100
     import GHC.Types.TypeEnv
    
    103 101
     import GHC.Types.Unique.DSet
    
    104
    -import GHC.Types.Unique.FM( listToUFM, lookupUFM )
    
    102
    +import GHC.Types.Unique.FM( UniqFM, listToUFM, lookupUFM )
    
    105 103
     import GHC.Types.SrcLoc
    
    106 104
     import GHC.Types.TyThing
    
    107 105
     import GHC.Types.PkgQual
    
    ... ... @@ -148,7 +146,7 @@ lookupKnownKeyName :: HasDebugCallStack
    148 146
                        => Maybe GlobalRdrEnv -> KnownKeyNameKey
    
    149 147
                        -> IfM lcl Name
    
    150 148
     lookupKnownKeyName Nothing uniq
    
    151
    -  = do { known_key_name_map <- loadKnownKeyOccMap
    
    149
    +  = do { known_key_name_map :: UniqFM KnownKeyNameKey Name <- loadKnownKeyOccMap
    
    152 150
            ; let name = lookupUFM known_key_name_map uniq
    
    153 151
                         `orElse` pprPanic "lookupKnownKeyThing 1"
    
    154 152
                                      (vcat [ text "unique:" <+> ppr uniq
    
    ... ... @@ -162,21 +160,22 @@ lookupKnownKeyName (Just gbl_rdr_env) uniq
    162 160
       --                   here is the top-level GlobalRdrEnv
    
    163 161
       -- Look up the known-key OccName in the GlobalRdrEnv
    
    164 162
       -- If we get a unique hit, use it; if not, panic.
    
    163
    +  | let occ :: OccName
    
    164
    +        occ = lookupUFM knownKeyUniqMap uniq
    
    165
    +               `orElse` pprPanic "lookupKnownKeyThing: missing key"
    
    166
    +                      (vcat [ text "unique:" <+> ppr uniq
    
    167
    +                            , text "uniq-map:" <+> ppr knownKeyUniqMap ])
    
    165 168
       = case lookupGRE gbl_rdr_env (LookupOccName occ SameNameSpace) of
    
    166 169
            [gre] -> do { let name = greName gre
    
    167
    -                   ; addUsedGRE NoDeprecationWarnings gre
    
    168
    -                        -- addUseGRE: don't complain about unused imports
    
    169
    -                        -- of known-key names when -frebindable-known-key-names
    
    170
    +--                   ; addUsedGRE NoDeprecationWarnings gre
    
    171
    +--                        -- addUseGRE: don't complain about unused imports
    
    172
    +--                        -- of known-key names when -frebindable-known-key-names
    
    170 173
                        ; traceIf $ hang (text "lookupKnownKeyThing NoImplicitKnownKeyNames")
    
    171 174
                                       2 (ppr name <+> ppr uniq)
    
    172 175
                        ; return name }
    
    173
    -       []    -> pprPanic "lookupKnownKeyOcc: known-key name is not in scope" (ppr occ)
    
    174
    -       gres  -> pprPanic "lookupKnownKeyOcc: known-key name is ambiguously in scope" (ppr gres)
    
    176
    +       []    -> pprPanic "lookupKnownKeyName: known-key name is not in scope" (ppr occ)
    
    177
    +       gres  -> pprPanic "lookupKnownKeyName: known-key name is ambiguously in scope" (ppr gres)
    
    175 178
       where
    
    176
    -     occ = lookupUFM knownKeyUniqMap uniq
    
    177
    -           `orElse` pprPanic "lookupKnownKeyThing 2"
    
    178
    -                      (vcat [ text "unique:" <+> ppr uniq
    
    179
    -                            , text "uniq-map:" <+> ppr knownKeyUniqMap ])
    
    180 179
     
    
    181 180
     loadKnownKeyOccMap :: IfM lcl KnownKeyNameMap
    
    182 181
     loadKnownKeyOccMap
    
    ... ... @@ -191,7 +190,10 @@ loadKnownKeyOccMap
    191 190
            ; mb_res <- liftIO $ findImportedModule hsc_env kNOWN_KEY_NAMES NoPkgQual
    
    192 191
            ; iface <- case mb_res of
    
    193 192
                Found _ mod -> loadInterfaceWithException doc mod ImportBySystem
    
    194
    -           _ -> panic "loadKnownKeyOccMap"   -- ToDo tidy up
    
    193
    +           fr -> do { hsc_env <- getHscEnv
    
    194
    +                    ; pprPanic "loadKnownKeyOccMap" $
    
    195
    +                      missingInterfaceErrorDiagnostic defaultIfaceMessageOpts $
    
    196
    +                      cannotFindModule hsc_env kNOWN_KEY_NAMES fr }
    
    195 197
     
    
    196 198
            ; let occ_map :: KnownKeyNameMap
    
    197 199
                  occ_map = listToUFM [ (getUnique nm, nm)
    
    ... ... @@ -201,10 +203,26 @@ loadKnownKeyOccMap
    201 203
            -- Record the KnownKeyOccMap in the EPS, so we will find it next time
    
    202 204
            ; updateEps_ (\eps -> eps { eps_known_keys = Just occ_map })
    
    203 205
     
    
    206
    +#ifdef DEBUG
    
    207
    +       ; case checkKnownKeyNamesIface occ_map of
    
    208
    +            Just msg -> pprPanic "Missing exports in KnownKeyNames" msg
    
    209
    +            Nothing  -> return ()
    
    210
    +#endif
    
    204 211
            ; return occ_map } } }
    
    205 212
       where
    
    206 213
         doc = text "Need interface for KnonwKeyNames"
    
    207 214
     
    
    215
    +checkKnownKeyNamesIface :: KnownKeyNameMap -> Maybe SDoc
    
    216
    +-- Check that KnownKeyNames exports all the things defined in `basicKnownKeyTable`
    
    217
    +-- and the the uniques and occ-names agree
    
    218
    +checkKnownKeyNamesIface known_key_names_occ_map
    
    219
    +  | null bad_ones = Nothing
    
    220
    +  | otherwise     = Just (ppr bad_ones)
    
    221
    +  where
    
    222
    +    bad_ones = filter is_bad basicKnownKeyTable
    
    223
    +    is_bad (occ, key) = case lookupUFM known_key_names_occ_map key of
    
    224
    +                           Nothing   -> True
    
    225
    +                           Just name -> getOccName name /= occ
    
    208 226
     
    
    209 227
     {- *********************************************************************
    
    210 228
     *                                                                      *
    

  • compiler/GHC/Rename/Env.hs
    ... ... @@ -70,8 +70,7 @@ import GHC.Tc.Utils.Monad
    70 70
     import GHC.Parser.PostProcess ( setRdrNameSpace )
    
    71 71
     
    
    72 72
     import GHC.Builtin.Types
    
    73
    -import GHC.Builtin.Utils( knownKeyOccMap )
    
    74
    -import GHC.Builtin.Names( rOOT_MAIN )
    
    73
    +import GHC.Builtin.Names
    
    75 74
     
    
    76 75
     import GHC.Types.Name
    
    77 76
     import GHC.Types.Name.Set
    
    ... ... @@ -87,7 +86,6 @@ import GHC.Types.Basic ( TupleSort(..), tupleSortBoxity )
    87 86
     import GHC.Types.TyThing ( tyThingGREInfo )
    
    88 87
     import GHC.Types.SrcLoc as SrcLoc
    
    89 88
     import GHC.Utils.Outputable as Outputable
    
    90
    -import GHC.Types.Unique
    
    91 89
     import GHC.Types.Unique.FM
    
    92 90
     import GHC.Types.Unique.DSet
    
    93 91
     import GHC.Types.Unique.Set
    

  • compiler/GHC/Tc/Deriv/Infer.hs
    ... ... @@ -346,7 +346,7 @@ inferConstraintsStock dit@(DerivInstTys { dit_cls_tys = cls_tys
    346 346
                -> assert (tyConTyVars rep_tc `lengthExceeds` 0) $
    
    347 347
                   -- Generic1 has a single kind variable
    
    348 348
                   assert (cls_tys `lengthIs` 1) $
    
    349
    -              do { functorClass <- lift $ tcLookupClass functorClassName
    
    349
    +              do { functorClass <- lift $ tcLookupKnownKeyClass functorClassKey
    
    350 350
                      ; pure $ con_arg_constraints
    
    351 351
                             $ get_gen1_constraints functorClass }
    
    352 352
     
    

  • compiler/GHC/Tc/Types.hs
    ... ... @@ -349,6 +349,7 @@ data IfGblEnv
    349 349
             -- Some information about where this environment came from;
    
    350 350
             -- useful for debugging.
    
    351 351
             if_doc :: SDoc,
    
    352
    +
    
    352 353
             -- The type environment for the module being compiled,
    
    353 354
             -- in case the interface refers back to it via a reference that
    
    354 355
             -- was originally a hi-boot file.
    

  • libraries/base/src/GHC/KnownKeyNames.hs
    ... ... @@ -11,7 +11,12 @@
    11 11
     --
    
    12 12
     
    
    13 13
     module GHC.KnownKeyNames
    
    14
    -    ( Rational -- TODO: add more than rational after smoke test
    
    15
    -     ) where
    
    14
    +    ( Rational
    
    15
    +    , Eq, Ord, Show, Num, Bounded
    
    16
    +    , Foldable, Traversable
    
    17
    +    , IsString
    
    18
    +    , Functor, Monad
    
    19
    +    ) where
    
    16 20
     
    
    17
    -import GHC.Internal.Real
    21
    +import Prelude
    
    22
    +import Data.String( IsString )