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

Commits:

9 changed files:

Changes:

  • compiler/GHC/Builtin/Names.hs
    ... ... @@ -129,7 +129,9 @@ import GHC.Unit.Types
    129 129
     import GHC.Types.Name.Occurrence
    
    130 130
     import GHC.Types.Name.Reader
    
    131 131
     import GHC.Types.Unique
    
    132
    +import GHC.Types.Unique.FM
    
    132 133
     import GHC.Builtin.Uniques
    
    134
    +import GHC.Builtin.Names.TH( thKnownKeyTable )
    
    133 135
     import GHC.Types.Name
    
    134 136
     import GHC.Types.SrcLoc
    
    135 137
     import GHC.Data.FastString
    
    ... ... @@ -156,7 +158,7 @@ allNameStringList = Inf.toList allNameStrings
    156 158
     
    
    157 159
     {-
    
    158 160
     ************************************************************************
    
    159
    -*                                                                      *
    
    161
    +o*                                                                      *
    
    160 162
     \subsection{Local Names}
    
    161 163
     *                                                                      *
    
    162 164
     ************************************************************************
    
    ... ... @@ -187,6 +189,14 @@ names with uniques. These ones are the *non* wired-in ones. The
    187 189
     wired in ones are defined in GHC.Builtin.Types etc.
    
    188 190
     -}
    
    189 191
     
    
    192
    +-- | `knownKeyOccMap` maps the OccName of a known-key to its Unique
    
    193
    +knownKeyOccMap :: OccEnv KnownKeyNameKey
    
    194
    +knownKeyOccMap = mkOccEnv (basicKnownKeyTable ++ thKnownKeyTable)
    
    195
    +
    
    196
    +knownKeyUniqMap :: UniqFM KnownKeyNameKey OccName
    
    197
    +knownKeyUniqMap = listToUFM [ (uniq, occ)
    
    198
    +                            | (occ, uniq) <- basicKnownKeyTable ++ thKnownKeyTable ]
    
    199
    +
    
    190 200
     basicKnownKeyTable :: [(OccName, KnownKeyNameKey)]
    
    191 201
     basicKnownKeyTable
    
    192 202
       = [ (mkTcOcc "Rational",     rationalTyConKey)
    
    ... ... @@ -1604,11 +1614,6 @@ tcQual modu str unique = mk_known_key_name tcName modu str unique
    1604 1614
     clsQual  modu str unique = mk_known_key_name clsName modu str unique
    
    1605 1615
     dcQual   modu str unique = mk_known_key_name dataName modu str unique
    
    1606 1616
     
    
    1607
    -mk_known_key_name :: NameSpace -> Module -> FastString -> KnownKeyNameKey -> Name
    
    1608
    -{-# INLINE mk_known_key_name #-}
    
    1609
    -mk_known_key_name space modu str unique
    
    1610
    -  = mkExternalName unique modu (mkOccNameFS space str) noSrcSpan
    
    1611
    -
    
    1612 1617
     
    
    1613 1618
     {-
    
    1614 1619
     ************************************************************************
    

  • compiler/GHC/Builtin/Names/TH.hs
    ... ... @@ -8,9 +8,8 @@ module GHC.Builtin.Names.TH where
    8 8
     
    
    9 9
     import GHC.Prelude ()
    
    10 10
     
    
    11
    -import GHC.Builtin.Names( mk_known_key_name )
    
    12 11
     import GHC.Unit.Types
    
    13
    -import GHC.Types.Name( Name )
    
    12
    +import GHC.Types.Name( Name, mk_known_key_name )
    
    14 13
     import GHC.Types.Name.Occurrence( OccName, tcName, clsName, dataName, varName, fieldName )
    
    15 14
     import GHC.Types.Name.Reader( RdrName, nameRdrName )
    
    16 15
     import GHC.Types.Unique ( Unique )
    

  • compiler/GHC/Builtin/Utils.hs
    ... ... @@ -19,16 +19,15 @@
    19 19
     --
    
    20 20
     module GHC.Builtin.Utils (
    
    21 21
             -- * Known-key names
    
    22
    -        isKnownKeyName,
    
    23
    -        lookupKnownKeyName,
    
    24
    -        lookupKnownNameInfo,
    
    22
    +        oldIsKnownKeyName,
    
    23
    +        oldLookupKnownKeyName,
    
    24
    +        oldLookupKnownNameInfo,
    
    25 25
     
    
    26 26
             -- ** Internal use
    
    27 27
             -- | 'knownKeyNames' is exported to seed the original name cache only;
    
    28 28
             -- if you find yourself wanting to look at it you might consider using
    
    29 29
             -- 'lookupKnownKeyName' or 'isKnownKeyName'.
    
    30 30
             knownKeyNames,
    
    31
    -        knownKeyOccMap, knownKeyUniqMap,
    
    32 31
     
    
    33 32
             -- * Miscellaneous
    
    34 33
             wiredInIds, ghcPrimIds,
    
    ... ... @@ -54,7 +53,7 @@ import GHC.Builtin.PrimOps.Ids
    54 53
     import GHC.Builtin.Types
    
    55 54
     import GHC.Builtin.Types.Literals ( typeNatTyCons )
    
    56 55
     import GHC.Builtin.Types.Prim
    
    57
    -import GHC.Builtin.Names.TH ( templateHaskellNames, thKnownKeyTable )
    
    56
    +import GHC.Builtin.Names.TH ( templateHaskellNames )
    
    58 57
     import GHC.Builtin.Names
    
    59 58
     
    
    60 59
     import GHC.Core.ConLike ( ConLike(..) )
    
    ... ... @@ -193,38 +192,34 @@ knownKeyNamesOkay all_names
    193 192
                                text ": " <>
    
    194 193
                                brackets (pprWithCommas (ppr . nameOccName) ns)
    
    195 194
     
    
    195
    +---------------  ToDo: get rid of these old-mechanism functions
    
    196
    +---------------        when we complete the known-key tranitition
    
    197
    +--------------   See #27013
    
    198
    +
    
    196 199
     -- | Given a 'Unique' lookup its associated 'Name' if it corresponds to a
    
    197 200
     -- known-key thing.
    
    198
    -lookupKnownKeyName :: Unique -> Maybe Name
    
    199
    -lookupKnownKeyName u =
    
    200
    -    knownUniqueName u <|> lookupUFM_Directly knownKeysMap u
    
    201
    +oldLookupKnownKeyName :: Unique -> Maybe Name
    
    202
    +oldLookupKnownKeyName u =
    
    203
    +    knownUniqueName u <|> lookupUFM_Directly oldKnownKeysMap u
    
    201 204
     
    
    202 205
     -- TODO: remove this once all knownkey names come from providers
    
    203 206
     -- | Is a 'Name' known-key?
    
    204
    -isKnownKeyName :: Name -> Bool
    
    205
    -isKnownKeyName n =
    
    206
    -    isJust (knownUniqueName $ nameUnique n) || elemUFM n knownKeysMap
    
    207
    -
    
    208
    --- | `knownKeyOccMap` maps the OccName of a known-key to its Unique
    
    209
    -knownKeyOccMap :: OccEnv Unique
    
    210
    -knownKeyOccMap = mkOccEnv (basicKnownKeyTable ++ thKnownKeyTable)
    
    211
    -
    
    212
    -knownKeyUniqMap :: UniqFM Unique OccName
    
    213
    -knownKeyUniqMap = listToUFM [ (uniq, occ)
    
    214
    -                            | (occ, uniq) <- basicKnownKeyTable ++ thKnownKeyTable ]
    
    207
    +oldIsKnownKeyName :: Name -> Bool
    
    208
    +oldIsKnownKeyName n =
    
    209
    +    isJust (knownUniqueName $ nameUnique n) || elemUFM n oldKnownKeysMap
    
    215 210
     
    
    216 211
     -- | Maps 'Unique's to known-key names.
    
    217 212
     --
    
    218 213
     -- The type is @UniqFM Name Name@ to denote that the 'Unique's used
    
    219 214
     -- in the domain are 'Unique's associated with 'Name's (as opposed
    
    220 215
     -- to some other namespace of 'Unique's).
    
    221
    -knownKeysMap :: UniqFM Name Name
    
    222
    -knownKeysMap = listToIdentityUFM knownKeyNames
    
    216
    +oldKnownKeysMap :: UniqFM Name Name
    
    217
    +oldKnownKeysMap = listToIdentityUFM knownKeyNames
    
    223 218
     
    
    224 219
     -- | Given a 'Unique' lookup any associated arbitrary SDoc's to be displayed by
    
    225 220
     -- GHCi's ':info' command.
    
    226
    -lookupKnownNameInfo :: Name -> SDoc
    
    227
    -lookupKnownNameInfo name = case lookupNameEnv knownNamesInfo name of
    
    221
    +oldLookupKnownNameInfo :: Name -> SDoc
    
    222
    +oldLookupKnownNameInfo name = case lookupNameEnv knownNamesInfo name of
    
    228 223
         -- If we do find a doc, we add comment delimiters to make the output
    
    229 224
         -- of ':info' valid Haskell.
    
    230 225
         Nothing  -> empty
    

  • compiler/GHC/Iface/Binary.hs
    ... ... @@ -32,8 +32,8 @@ module GHC.Iface.Binary (
    32 32
     
    
    33 33
     import GHC.Prelude
    
    34 34
     
    
    35
    -import GHC.Builtin.Utils   ( knownKeyOccMap, isKnownKeyName, lookupKnownKeyName )
    
    36
    -
    
    35
    +import GHC.Builtin.Utils   ( oldIsKnownKeyName, oldLookupKnownKeyName )
    
    36
    +import GHC.Builtin.Names   ( knownKeyOccMap )
    
    37 37
     import GHC.Utils.Panic
    
    38 38
     import GHC.Utils.Binary as Binary
    
    39 39
     import GHC.Utils.Outputable
    
    ... ... @@ -725,7 +725,7 @@ putName BinSymbolTable{
    725 725
                    bin_symtab_map = symtab_map_ref,
    
    726 726
                    bin_symtab_next = symtab_next }
    
    727 727
             bh name
    
    728
    -  | isKnownKeyName name
    
    728
    +  | oldIsKnownKeyName name
    
    729 729
       , let (c, u) = unpkUniqueGrimly (nameUnique name) -- INVARIANT: (ord c) fits in 8 bits
    
    730 730
       = -- assert (u < 2^(22 :: Int))
    
    731 731
         put_ bh (0x80000000
    
    ... ... @@ -758,7 +758,7 @@ getSymtabName symtab bh = do
    758 758
               ix  = fromIntegral i .&. 0x003FFFFF
    
    759 759
               u   = mkUniqueGrimilyWithTag tag ix
    
    760 760
             in
    
    761
    -          return $! case lookupKnownKeyName u of
    
    761
    +          return $! case oldLookupKnownKeyName u of
    
    762 762
                           Nothing -> pprPanic "getSymtabName:unknown known-key unique"
    
    763 763
                                               (ppr i $$ ppr u $$ char tag $$ ppr ix)
    
    764 764
                           Just n  -> n
    

  • compiler/GHC/Iface/Load.hs
    ... ... @@ -16,7 +16,8 @@ module GHC.Iface.Load (
    16 16
             -- Importing one thing
    
    17 17
             importDecl,
    
    18 18
             checkWiredInTyCon, ifCheckWiredInThing,
    
    19
    -        lookupKnownKeyThing, loadGlobalName,
    
    19
    +        lookupKnownKeyThing, lookupKnownKeyName,
    
    20
    +        loadGlobalName,
    
    20 21
     
    
    21 22
             -- RnM/TcM functions
    
    22 23
             loadModuleInterface, loadModuleInterfaces,
    
    ... ... @@ -63,6 +64,9 @@ import GHC.Iface.Rename
    63 64
     import GHC.Iface.Env
    
    64 65
     import GHC.Iface.Errors as Iface_Errors
    
    65 66
     
    
    67
    +import GHC.Rename.Env( addUsedGRE )
    
    68
    +import GHC.Rename.Utils( DeprecationWarnings(..) )
    
    69
    +
    
    66 70
     import GHC.Tc.Errors.Types
    
    67 71
     import GHC.Tc.Utils.Monad
    
    68 72
     
    
    ... ... @@ -134,9 +138,16 @@ import qualified GHC.Unit.Home.Graph as HUG
    134 138
     ********************************************************************* -}
    
    135 139
     
    
    136 140
     lookupKnownKeyThing :: HasDebugCallStack
    
    137
    -                    => Maybe GlobalRdrEnv -> Unique
    
    141
    +                    => Maybe GlobalRdrEnv -> KnownKeyNameKey
    
    138 142
                         -> IfM lcl (MaybeErr IfaceMessage TyThing)
    
    139
    -lookupKnownKeyThing Nothing uniq
    
    143
    +lookupKnownKeyThing mb_gbl_rdr_env key
    
    144
    +  = do { name <- lookupKnownKeyName mb_gbl_rdr_env key
    
    145
    +       ; lookupGlobalName name }
    
    146
    +
    
    147
    +lookupKnownKeyName :: HasDebugCallStack
    
    148
    +                   => Maybe GlobalRdrEnv -> KnownKeyNameKey
    
    149
    +                   -> IfM lcl Name
    
    150
    +lookupKnownKeyName Nothing uniq
    
    140 151
       = do { known_key_name_map <- loadKnownKeyOccMap
    
    141 152
            ; let name = lookupUFM known_key_name_map uniq
    
    142 153
                         `orElse` pprPanic "lookupKnownKeyThing 1"
    
    ... ... @@ -144,17 +155,23 @@ lookupKnownKeyThing Nothing uniq
    144 155
                                            , text "occ-map" <+> ppr known_key_name_map ])
    
    145 156
            ; traceIf $ hang (text "lookupKnownKeyThing ImplicitKnownKeyNames")
    
    146 157
                           2 (ppr name <+> ppr uniq)
    
    147
    -       ; lookupGlobalName name }
    
    158
    +       ; return name }
    
    148 159
     
    
    149
    -lookupKnownKeyThing (Just gbl_rdr_env) uniq
    
    150
    -  -- Look up the known-key OccName in the current top-level GlobalRdrEnv
    
    160
    +lookupKnownKeyName (Just gbl_rdr_env) uniq
    
    161
    +  -- Just gbl_rdr_env: we have -frebindable-known-key-names on, and
    
    162
    +  --                   here is the top-level GlobalRdrEnv
    
    163
    +  -- Look up the known-key OccName in the GlobalRdrEnv
    
    151 164
       -- If we get a unique hit, use it; if not, panic.
    
    152 165
       = case lookupGRE gbl_rdr_env (LookupOccName occ SameNameSpace) of
    
    153 166
            [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
    
    154 170
                        ; traceIf $ hang (text "lookupKnownKeyThing NoImplicitKnownKeyNames")
    
    155 171
                                       2 (ppr name <+> ppr uniq)
    
    156
    -                   ; lookupGlobalName name }
    
    157
    -       gres  -> pprPanic "lookupKnownKeyOcc" (ppr occ $$ ppr gres)
    
    172
    +                   ; 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)
    
    158 175
       where
    
    159 176
          occ = lookupUFM knownKeyUniqMap uniq
    
    160 177
                `orElse` pprPanic "lookupKnownKeyThing 2"
    

  • compiler/GHC/Tc/Module.hs
    ... ... @@ -2960,7 +2960,7 @@ tcRnGetInfo hsc_env name
    2960 2960
            ; thing  <- tcRnLookupName' name
    
    2961 2961
            ; fixity <- lookupFixityRn name
    
    2962 2962
            ; (cls_insts, fam_insts) <- lookupInsts thing
    
    2963
    -       ; let info = lookupKnownNameInfo name
    
    2963
    +       ; let info = oldLookupKnownNameInfo name
    
    2964 2964
            ; return (thing, fixity, cls_insts, fam_insts, info) }
    
    2965 2965
     
    
    2966 2966
     
    

  • compiler/GHC/Types/Name.hs
    ... ... @@ -50,6 +50,8 @@ module GHC.Types.Name (
    50 50
             mkFCallName,
    
    51 51
             mkExternalName, mkWiredInName, mkKnownKeyName,
    
    52 52
     
    
    53
    +        mk_known_key_name,   -- Temporary. ToDo: get rid of me #27013
    
    54
    +
    
    53 55
             -- ** Manipulating and deconstructing 'Name's
    
    54 56
             nameUnique, setNameUnique,
    
    55 57
             nameOccName, nameNameSpace, nameModule, nameModule_maybe, extNamePieces,
    
    ... ... @@ -161,15 +163,28 @@ To implement all this, here are the moving parts:
    161 163
            eqClassKey = mkPreludeClassUnique 3
    
    162 164
     
    
    163 165
     * All the known-key names are gathered in one table:
    
    164
    -     basicKnownKeyTable :: [(OccName, KnownKeyNameKey)]
    
    165
    -     basicKnownKeyTable
    
    166
    -       = [ (mkTcOcc "Rational",     rationalTyConKey)
    
    167
    -         , (mkTcOcc "Eq",           eqClassKey)
    
    168
    -         ... etc ...
    
    166
    +      basicKnownKeyTable :: [(OccName, KnownKeyNameKey)]
    
    167
    +      basicKnownKeyTable
    
    168
    +        = [ (mkTcOcc "Rational",     rationalTyConKey)
    
    169
    +          , (mkTcOcc "Eq",           eqClassKey)
    
    170
    +          ... etc ...
    
    171
    +
    
    172
    +  INVARIANT (KnownKeyInvariant): It is a requirement that all known-key names
    
    173
    +  have distinct OccNames. (We could have multiple name-spaces, but in practice
    
    174
    +  this is not an onerous restriction.)
    
    175
    +
    
    176
    +* Because of (KnownKeyInvariant) we can turn that table into two mappings:
    
    177
    +
    
    178
    +      knownKeyOccMap :: OccEnv KnownKeyNameKey
    
    179
    +      knownKeyOccMap = mkOccEnv (basicKnownKeyTable ++ thKnownKeyTable)
    
    169 180
     
    
    170
    -* INVARIANT: It is a requirement that all known-key names have distinct
    
    171
    -  OccNames. (We could have multiple name-spaces, but in practice this is not an
    
    172
    -  onerous restriction.)
    
    181
    +      knownKeyUniqMap :: UniqFM KnownKeyNameKey OccName
    
    182
    +
    
    183
    +* There are two flags that control the treatment of known-key names:
    
    184
    +    -frebindable-known-key-names
    
    185
    +    -fdefines-known-key-names
    
    186
    +
    
    187
    +* When processing source code, /without/ -frebindable
    
    173 188
     
    
    174 189
     Note [About the NameSorts]
    
    175 190
     ~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    ... ... @@ -360,6 +375,14 @@ hasKnownKey :: Uniquable a => a -> KnownKeyNameKey -> Bool
    360 375
     -- See if a thing has a particular known key
    
    361 376
     hasKnownKey = hasKey
    
    362 377
     
    
    378
    +-- ToDo: get rid of this function when we complete the known-key name transition
    
    379
    +--       see #27013
    
    380
    +mk_known_key_name :: NameSpace -> Module -> FastString -> KnownKeyNameKey -> Name
    
    381
    +{-# INLINE mk_known_key_name #-}
    
    382
    +mk_known_key_name space modu str unique
    
    383
    +  = mkExternalName unique modu (mkOccNameFS space str) noSrcSpan
    
    384
    +
    
    385
    +
    
    363 386
     
    
    364 387
     {- *********************************************************************
    
    365 388
     *                                                                      *
    

  • libraries/ghc-internal/src/GHC/Internal/Base.hs
    ... ... @@ -82,6 +82,9 @@ Other Prelude modules are much easier with fewer complex dependencies.
    82 82
     {-# LANGUAGE UnboxedTuples #-}
    
    83 83
     {-# LANGUAGE Unsafe #-}
    
    84 84
     
    
    85
    +{-# OPTIONS_GHC -fdefines-known-key-names #-}
    
    86
    +    -- Defines Monad
    
    87
    +
    
    85 88
     -- -Wno-orphans is needed for things like:
    
    86 89
     -- Orphan rule: "x# -# x#" ALWAYS forall x# :: Int# -# x# x# = 0
    
    87 90
     {-# OPTIONS_GHC -Wno-orphans #-}
    

  • libraries/ghc-internal/src/GHC/Internal/TH/Lift.hs
    ... ... @@ -31,7 +31,9 @@ module GHC.Internal.TH.Lift
    31 31
     
    
    32 32
     import GHC.Internal.TH.Syntax
    
    33 33
     import GHC.Internal.TH.Monad
    
    34
    -import qualified GHC.Internal.TH.Lib as Lib (litE)  -- See wrinkle (W4) of Note [Tracking dependencies on primitives]
    
    34
    +import qualified GHC.Internal.TH.Lib as Lib (litE)
    
    35
    +    -- See wrinkle (W4) of Note [Tracking dependencies on primitives]
    
    36
    +import GHC.Internal.Base( Monad ) -- Needed for known-key lookup
    
    35 37
     
    
    36 38
     import GHC.Internal.Data.Either
    
    37 39
     import GHC.Internal.Base (String, Void, map, mapM, ord, return, (.))