Simon Peyton Jones pushed to branch wip/spj-reinstallable-base2 at Glasgow Haskell Compiler / GHC
Commits:
-
3dc8d56d
by Simon Peyton Jones at 2026-04-14T00:35:11+01:00
18 changed files:
- compiler/GHC/Builtin.hs
- compiler/GHC/Builtin/KnownKeys.hs
- compiler/GHC/Builtin/KnownOccs.hs
- compiler/GHC/HsToCore/ListComp.hs
- compiler/GHC/Iface/Load.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/Tc/Deriv/Functor.hs
- compiler/GHC/Tc/Deriv/Generate.hs
- compiler/GHC/Tc/Deriv/Generics.hs
- libraries/base/src/Control/Applicative.hs
- libraries/base/src/Data/Fixed.hs
- libraries/base/src/Data/Semigroup.hs
- libraries/base/src/GHC/KnownKeyNames.hs
- libraries/ghc-internal/src/GHC/Internal/Base.hs
- libraries/ghc-internal/src/GHC/Internal/Heap/Closures.hs
- libraries/ghc-internal/src/GHC/Internal/TH/Lib.hs
- libraries/ghc-internal/src/GHC/Internal/TH/Lift.hs
- libraries/ghc-internal/src/GHC/Internal/TH/Syntax.hs
Changes:
| ... | ... | @@ -93,6 +93,18 @@ import Data.Maybe |
| 93 | 93 | |
| 94 | 94 | {- Note [Overview of known-key entities]
|
| 95 | 95 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 96 | +There are three kinds of entities that GHC knows something about.
|
|
| 97 | + * known-occ entities
|
|
| 98 | + * known-key entities
|
|
| 99 | + * wired-in entities
|
|
| 100 | +It is pretty easy, cheap, and robust to add a new known-occ entity; but GHC
|
|
| 101 | +does not know much about it. In contrast, it is expensive and relatively
|
|
| 102 | +fragile to add a new wired-in entity; but in exchange GHC knows a lot about
|
|
| 103 | +it. Known-key entities are in the middle. Use the cheapest one that does
|
|
| 104 | +what you need!
|
|
| 105 | + |
|
| 106 | +Here are more details.
|
|
| 107 | + |
|
| 96 | 108 | A "wired-in" entity:
|
| 97 | 109 | * Its Unique, OccName
|
| 98 | 110 | * Its defining module
|
| ... | ... | @@ -103,7 +115,7 @@ A "wired-in" entity: |
| 103 | 115 | knowledge precisely reflects the code in the library.
|
| 104 | 116 | |
| 105 | 117 | A "known-key" entity:
|
| 106 | - * Its Unique and OccName are baked into GHC
|
|
| 118 | + * Its Unique and OccName are baked into GHC. Its Unique is called a KnownKey.
|
|
| 107 | 119 | * It is exported by base:GHC.KnownKeyNames
|
| 108 | 120 | * But that's all that GHC knows about it
|
| 109 | 121 | In particular, GHC does /not/ know in which module the entity is defined.
|
| ... | ... | @@ -115,7 +127,7 @@ A "known-key" entity: |
| 115 | 127 | to GHC. It's not hard.
|
| 116 | 128 | |
| 117 | 129 | A "known-occ" entity:
|
| 118 | - * Its OccName is baked into GHC
|
|
| 130 | + * Its OccName is baked into GHC -- we call it a KnownOcc
|
|
| 119 | 131 | * It is exported by base:GHC.KnownKeyNames
|
| 120 | 132 | * But that's all that GHC knows about it
|
| 121 | 133 | In particular, GHC does /not/ know in which module the entity is defined,
|
| ... | ... | @@ -127,13 +139,15 @@ A "known-occ" entity: |
| 127 | 139 | It is significantly easier to add a known-occ entity to GHC than a known-key
|
| 128 | 140 | entity, so we use known-occ entities whenever we can.
|
| 129 | 141 | |
| 142 | + Every known-key entity is also a known-occ entity, but not vice versa.
|
|
| 143 | + |
|
| 130 | 144 | When do we use each of these?
|
| 131 | 145 | |
| 132 | -* We use a wired-in entity when we must. E.g. `boolTy` uses the wired-in TyCon
|
|
| 133 | - `boolTyCon`. We want a static `boolTy` so we can use it in `mkIfThenElse`,
|
|
| 134 | - which is a pure function with no monad in sight.
|
|
| 146 | +* WIRED-IN. We use a wired-in entity when we want a statically-defined Type or TyCon.
|
|
| 147 | + E.g. `boolTy` uses the wired-in TyCon `boolTyCon`. We want a static `boolTy` so
|
|
| 148 | + we can use it in `mkIfThenElse`, which is a pure function with no monad in sight.
|
|
| 135 | 149 | |
| 136 | -* We use a known-key entity when we want a fast test to say, for example,
|
|
| 150 | +* KNOWN-KEY. We use a known-key entity when we want a fast test to say, for example,
|
|
| 137 | 151 | "are you /the/ Typeable class?", not some other class that happens to be called
|
| 138 | 152 | "Typeable". It checks this using
|
| 139 | 153 | cls `hasKnownKey` typeableClassKey
|
| ... | ... | @@ -142,76 +156,73 @@ When do we use each of these? |
| 142 | 156 | where GHC.Builtin.KnownKeys.typeableClassKey is the statically chosen unique
|
| 143 | 157 | for `Typeable`. See `GHC.Tc.Instance.Class.matchGlobalInst`
|
| 144 | 158 | |
| 145 | -* We use a known-occ entity when we just want to refer to the thing in, say,
|
|
| 146 | - the code generated for a `deriving` clause.
|
|
| 147 | - |
|
| 148 | - |
|
| 149 | - |
|
| 150 | - |
|
| 151 | -* Very similarly, see `GHC.Tc.Deriv.Utils.stockSideConditions`, which checks if a
|
|
| 159 | + Very similarly, see `GHC.Tc.Deriv.Utils.stockSideConditions`, which checks if a
|
|
| 152 | 160 | class is suitable for stock deriving.
|
| 153 | 161 | |
| 154 | -Here is why GHC might want to refer to a known-occ entity:
|
|
| 155 | - |
|
| 156 | -* When desugaring a Template Haskell quotation, in GHC.HsToCore.Quote, GHC
|
|
| 157 | - must generate Core that mentions a myriad of functions defined in
|
|
| 158 | - ghc-internal:GHC.Internal.TH.Lib, such as `varE`, `conE`, `funD`, etc etc.
|
|
| 159 | - They don't need a fixed /unique/, but we still need to find them, so we use
|
|
| 160 | - their /OccName/. They are "known-occ" entities.
|
|
| 161 | - |
|
| 162 | - To do the lookup it uses
|
|
| 163 | - dsLookupKnownOccId :: KnownOcc -> DsM TyThing
|
|
| 164 | - |
|
| 165 | -* When dealing with `deriving` clauses, GHC generates (LHsBinds GhcPs) bindings,
|
|
| 166 | - and then renames and typechecks them. These bindings refer to a myriad of
|
|
| 167 | - identifiers, such as `(==)`, `(>)`, `inRange`, and so on. Again GHC does not
|
|
| 168 | - need to know a statically-known unique for them, but it does need to find them
|
|
| 169 | - so it uses known
|
|
| 170 | - |
|
| 171 | -* When desugaring, the desugarer wants to refer to a particular
|
|
| 172 | - class, type, or function. It does this via (e.g.)
|
|
| 173 | - dsLookupKnownOccTyCon :: KnownOcc -> DsM TyCon
|
|
| 174 | - or
|
|
| 175 | - dsLookupKnownKeyTyCon :: KnownKey -> DsM TyCon
|
|
| 176 | - It doesn't really matter which we use.
|
|
| 177 | - |
|
| 178 | -* In a very similar way, for type-class defauting GHC has built-in defaulting behaviour
|
|
| 179 | - for Num, IsString, etc. It gets hold of these classes via their known key, via
|
|
| 180 | - tcLookupKnownKeyClass :: KnownKey -> TcM Class
|
|
| 181 | - See GHC.Tc.Gen.Default.tcDefaultDecls
|
|
| 162 | + * For type-class defauting GHC has built-in defaulting behaviour
|
|
| 163 | + for Num, IsString, etc. It gets hold of these classes via their known key, via
|
|
| 164 | + tcLookupKnownKeyClass :: KnownKey -> TcM Class
|
|
| 165 | + See GHC.Tc.Gen.Default.tcDefaultDecls.
|
|
| 166 | + |
|
| 167 | +* KNOWN_OCC. We use a known-occ entity when we just want to /refer/ to the thing in,
|
|
| 168 | + say, the code generated for a `deriving` clause. Here is why GHC might want to
|
|
| 169 | + refer to a known-occ entity:
|
|
| 170 | + |
|
| 171 | + * When desugaring a Template Haskell quotation, in GHC.HsToCore.Quote, GHC
|
|
| 172 | + must generate Core that mentions a myriad of functions defined in
|
|
| 173 | + ghc-internal:GHC.Internal.TH.Lib, such as `varE`, `conE`, `funD`, etc etc.
|
|
| 174 | + They don't need a fixed /unique/, but we still need to find them, so we use
|
|
| 175 | + their /OccName/. They are "known-occ" entities.
|
|
| 176 | + |
|
| 177 | + To do the lookup it uses
|
|
| 178 | + dsLookupKnownOccId :: KnownOcc -> DsM TyThing
|
|
| 179 | + |
|
| 180 | + * When dealing with `deriving` clauses, GHC generates (LHsBinds GhcPs) bindings,
|
|
| 181 | + and then renames and typechecks them. These bindings refer to a myriad of
|
|
| 182 | + identifiers, such as `(==)`, `(>)`, `inRange`, and so on. Again GHC does not
|
|
| 183 | + need to know a statically-known unique for them, but it does need to find them
|
|
| 184 | + so it uses known
|
|
| 185 | + |
|
| 186 | + * When desugaring, the desugarer wants to refer to a particular
|
|
| 187 | + class, type, or function. It does this via (e.g.)
|
|
| 188 | + dsLookupKnownOccTyCon :: KnownOcc -> DsM TyCon
|
|
| 189 | + or
|
|
| 190 | + dsLookupKnownKeyTyCon :: KnownKey -> DsM TyCon
|
|
| 191 | + It doesn't really matter which we use.
|
|
| 182 | 192 | |
| 183 | 193 | To implement all this, here are the moving parts:
|
| 184 | 194 | |
| 195 | +* INVARIANT (KnownEntityInvariant): It is a requirement that all known-key and known-occ
|
|
| 196 | + entities have distinct OccNames. We could have multiple name-spaces, but in practice
|
|
| 197 | + this is not an onerous restriction. But see Note [Tricky known-occ cases] in
|
|
| 198 | + GHC.Builtin.KnownOccs for some awkward cases.
|
|
| 199 | + |
|
| 185 | 200 | * Each known-key name has a /statically-chosen/ unique, fixed in GHC.Builtin.KnownKeys.
|
| 186 | 201 | e.g. eqClassKey :: KnownKey
|
| 187 | 202 | eqClassKey = mkPreludeClassUnique 3
|
| 188 | 203 | |
| 189 | 204 | * All the known-key names are gathered in one table:
|
| 190 | - knownKeyTable :: [(OccName, KnownKey)]
|
|
| 205 | + knownKeyTable :: [(KnownOcc, KnownKey)]
|
|
| 191 | 206 | knownKeyTable
|
| 192 | 207 | = [ (mkTcOcc "Rational", rationalTyConKey)
|
| 193 | 208 | , (mkTcOcc "Eq", eqClassKey)
|
| 194 | 209 | ... etc ... ]
|
| 195 | 210 | |
| 196 | - INVARIANT (KnownKeyInvariant): It is a requirement that all known-key names
|
|
| 197 | - have distinct OccNames. (We could have multiple name-spaces, but in practice
|
|
| 198 | - this is not an onerous restriction.)
|
|
| 199 | - |
|
| 200 | -* Because of (KnownKeyInvariant) we can turn that table into two mappings:
|
|
| 211 | +* Because of (KnownEntityInvariant) we can turn that table into two mappings:
|
|
| 201 | 212 | |
| 202 | 213 | knownKeyOccMap :: OccEnv KnownKey
|
| 203 | 214 | knownKeyOccMap = mkOccEnv knownKeyTable
|
| 204 | 215 | |
| 205 | - knownKeyUniqMap :: UniqFM KnownKey OccName
|
|
| 216 | + knownKeyUniqMap :: UniqFM KnownKey KnownOcc
|
|
| 206 | 217 | |
| 207 | -* A new module `base:GHC.KnownKeyNames` exports all the known-key names.
|
|
| 218 | +* A special module `base:GHC.KnownKeyNames` exports all the known-key names.
|
|
| 208 | 219 | There is nothing special about this module except that GHC knows its
|
| 209 | 220 | name and can import it.
|
| 210 | 221 | |
| 211 | 222 | In effect, the `mi_exports` of `GHC/KnownKeyNames.hi` tells GHC where each
|
| 212 | 223 | known-key name is defined.
|
| 213 | 224 | |
| 214 | - This is one reason for (KnownKeyInvariant): an export list cannot have two
|
|
| 225 | + This is a big reason for (KnownEntityInvaroiant): an export list cannot have two
|
|
| 215 | 226 | entities with the same OccName.
|
| 216 | 227 | |
| 217 | 228 | * There are three flags that control the treatment of known-key names:
|
| ... | ... | @@ -220,17 +231,25 @@ To implement all this, here are the moving parts: |
| 220 | 231 | -fexclude-known-key-define=wombat See wrinkle (KKN2)
|
| 221 | 232 | Details in the following bullets.
|
| 222 | 233 | |
| 223 | -* Known-key name lookup (normal case: KKNS_FromModule)
|
|
| 224 | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 225 | - In normal client code, suppose the desugarer calls `dsLookupKnownKeyTyCon`
|
|
| 226 | - on `rationalTyConKey`. Then, in `loadKnownKeyOccMap`
|
|
| 234 | +* Known-key or known-occ lookup (normal case: KKNS_FromModule)
|
|
| 235 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 236 | + In normal client code, suppose the desugarer calls
|
|
| 237 | + dsLookupKnownKeyTyCon rationalTyConKey
|
|
| 238 | + or
|
|
| 239 | + dsLookupKnownOccTyCon rationalTyConOcc
|
|
| 240 | + |
|
| 241 | + Then, in `loadKnownKeyOccMaps`
|
|
| 227 | 242 | * GHC imports GHC.KnownKeyNames, i.e. looks for `GHC/KnownKeyNames.hi`
|
| 228 | - * Assuming this is successful, GHC usees its `mi_exports` to builds a mapping
|
|
| 229 | - `KnownKeyNameMap` from each known-key unique to the Name of the entity.
|
|
| 230 | - * It stashes this map in the `eps_known_keys` field of the ExternalPackageState
|
|
| 243 | + |
|
| 244 | + * Assuming this is successful, GHC uses its `mi_exports` to build `KnownKeyNameMaps`,
|
|
| 245 | + which has (a) a map from the KnownKey of each known-key entity to its Name
|
|
| 246 | + (b) a map from the KnownOcc of each known-occ entity to its Name
|
|
| 247 | + |
|
| 248 | + * It stashes these maps in the `eps_known_keys` field of the ExternalPackageState
|
|
| 231 | 249 | so that it doesn't need to repeat the exercise.
|
| 232 | - Now it can simplhy look up `rationalTyConKey` in the `eps_known_keys`. Easy!
|
|
| 233 | - See `dsLookupKnownKeyName`.
|
|
| 250 | + |
|
| 251 | + Now it can simply look up `rationalTyConKey` in the `eps_known_keys`. Easy!
|
|
| 252 | + See `GHC.Iface.Load.lookupKnownKeyThing` and `lookupKnownOccThing`.
|
|
| 234 | 253 | |
| 235 | 254 | * Known-key name lookup (base case: KKNS_InScope)
|
| 236 | 255 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -238,14 +257,26 @@ To implement all this, here are the moving parts: |
| 238 | 257 | GHC.KnownKeyNames has not yet been compiled! Instead, we use whatever is in scope with
|
| 239 | 258 | the desired `OccName`, rather like `-XRebindableSyntax`.
|
| 240 | 259 | |
| 241 | - See the `KnownKeyNameSource` argument to `lookupKnownKeyName`. When compiling modules
|
|
| 260 | + See the `KnownKeyNameSource` argument to `lookupKnownOccThing`. When compiling modules
|
|
| 242 | 261 | in `ghc-internal` or `base`:
|
| 262 | + |
|
| 243 | 263 | * We switch on -frebindable-known-key-names
|
| 244 | - * That ensures that we pass `KKNS_InScope` to `lookupKnownKeyName`
|
|
| 245 | - * The latter now looks in the GlobalRdrEnv it is passed.
|
|
| 246 | 264 | |
| 247 | - This does mean that in `base` and `ghc-internal` we occasionally need an extra import
|
|
| 248 | - to bring into scope some entities that are needed by `dsLookupKnownKeyTyCon` etc.
|
|
| 265 | + * That ensures that we pass `KKNS_InScope gbl_rdr_env` to `lookupKnownKeyThing`
|
|
| 266 | + |
|
| 267 | + * Suppose we are looking up the known-occ entity `wombat`. The key function is
|
|
| 268 | + `lookupKnownGRE`:
|
|
| 269 | + * First we look in the `gbl_rdr_env` for the qualified name `Rebindable.wombat`.
|
|
| 270 | + If we find a unique hit, choose it.
|
|
| 271 | + * Otherwise we look in `gbl_rdr_env` for the /unqualified/ name `wombat`.
|
|
| 272 | + If we find a unique hit, choose it.
|
|
| 273 | + |
|
| 274 | + This plan means that we can have an unrelated local binding for `wombat` and still
|
|
| 275 | + not get confused provided we import Rebindable.wombat.
|
|
| 276 | + |
|
| 277 | + This does mean that in `base` and `ghc-internal` we need quite a few extra imports that
|
|
| 278 | + look like import GHC.InternalNum as Rebindable
|
|
| 279 | + or import qualified GHC.Internal.Num as Rebindable
|
|
| 249 | 280 | See also wrinkle (KKN1)
|
| 250 | 281 | |
| 251 | 282 | * Defining known-key names
|
| ... | ... | @@ -267,8 +298,13 @@ To implement all this, here are the moving parts: |
| 267 | 298 | |
| 268 | 299 | Wrinkles
|
| 269 | 300 | |
| 270 | -(KKN1) We need some special treatment of unused-import warnings.
|
|
| 271 | - See (UI1) in Note [Unused imports] in GHC.Rename.Names
|
|
| 301 | +(KKN1) An import declaration may look entirely unused, if it is there solely to
|
|
| 302 | + bring a known-occ name into scope for the desugarer. Why? Becuase we only generate
|
|
| 303 | + usage information, to drive unused-import warnings, in the renamer and typechecker.
|
|
| 304 | + Not, currently, the desugarer.
|
|
| 305 | + |
|
| 306 | + So we simply suppress an unused-import-decl warning if it has a "as Rebindable"
|
|
| 307 | + qualifier. See (UI1) in Note [Unused imports] in GHC.Rename.Names
|
|
| 272 | 308 | |
| 273 | 309 | (KKN2) The flag `-fdefines-known-key-names` is module-wide. But what if that module
|
| 274 | 310 | happens to define an entity that /isn't/ a known-key entity, but /does/ share the
|
| ... | ... | @@ -284,7 +320,7 @@ Wrinkles |
| 284 | 320 | So we compile GHC.Internal.Data.Foldable with
|
| 285 | 321 | -fexclude-known-key-define=toList
|
| 286 | 322 | |
| 287 | -(KKN3) You don't need need to export the wired-in entities from GHC.KnownKeyNames
|
|
| 323 | +(KKN3) You don't need need to export wired-in entities from GHC.KnownKeyNames
|
|
| 288 | 324 | because we (should) never look up a wired-in name via its key. That is,
|
| 289 | 325 | `GHC.Iface.Load.lookupKnownKeyName` should never be called on the key of
|
| 290 | 326 | a wired-in name.
|
| ... | ... | @@ -292,8 +328,6 @@ Wrinkles |
| 292 | 328 | Alternative: export all wired-in entities from GHC.KnownKeyNames. But that
|
| 293 | 329 | would simply bloat the interface for no good reason.
|
| 294 | 330 | |
| 295 | -(KKN4) Typeable binds early in tc
|
|
| 296 | - |
|
| 297 | 331 | Note [Recipe for adding a known-occ name]
|
| 298 | 332 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 299 | 333 | To make `wombat` into a known-occ name, you must ensure that:
|
| ... | ... | @@ -302,12 +336,15 @@ To make `wombat` into a known-occ name, you must ensure that: |
| 302 | 336 | |
| 303 | 337 | * In any module in `base` or `ghc-internal` (which are compiled with
|
| 304 | 338 | -frebindable-known-key-names), in which `wombat` is needed, you must ensure
|
| 305 | - that `wombat` is in scope by saying `import M( wombat )`.
|
|
| 339 | + that `wombat` is in scope by saying `import M( wombat )`, or
|
|
| 340 | + import qualified M as Rebindable( wombat )
|
|
| 341 | + |
|
| 342 | + Using the `as Rebindable` qualifier will suppress any unused-import-decl warnings.
|
|
| 306 | 343 | |
| 307 | - You do not need to import the module in which `wombat` is /defined/, although
|
|
| 308 | - you may. It is enough simply to bring `wombat` in scope by importing a
|
|
| 309 | - module that re-exports. You can even import `GHC.KnownKeyNames`, if that does
|
|
| 310 | - not create a module loop!
|
|
| 344 | + You do not need to import the precise module in which `wombat` is /defined/,
|
|
| 345 | + although you may. It is enough simply to bring `wombat` in scope by importing a
|
|
| 346 | + module that re-exports it. You can even import `GHC.KnownKeyNames`, if doing so
|
|
| 347 | + does not create a module loop!
|
|
| 311 | 348 | |
| 312 | 349 | Note [Recipe for adding a known-key name]
|
| 313 | 350 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -329,17 +366,9 @@ To make `wombat` into a known-key name, you must ensure that: |
| 329 | 366 | entry for `wombat`
|
| 330 | 367 | (mkVarOcc "wombat", wombatKey)
|
| 331 | 368 | |
| 332 | -* In any module in `base` or `ghc-internal` (which are compiled with
|
|
| 333 | - -frebindable-known-key-names), you must ensure that `wombat` is in scope
|
|
| 334 | - by saying `import M( wombat )`.
|
|
| 335 | - |
|
| 336 | - If you just say `import M` you may get a "unused import" warning; that
|
|
| 337 | - warning is suppressed for known-key names if you import `wombat` by name.
|
|
| 338 | - |
|
| 339 | - You do not need to import the module in which `wombat` is /defined/, although
|
|
| 340 | - you may. It is enough simply to bring `wombat` in scope by importing a
|
|
| 341 | - module that re-exports. You can even import `GHC.KnownKeyNames`, if that does
|
|
| 342 | - not create a module loop!
|
|
| 369 | +* Just like known-occ names, above in any module in `base` or `ghc-internal` (which
|
|
| 370 | + are compiled with -frebindable-known-key-names), you must ensure that `wombat` is
|
|
| 371 | + in scope by saying `import M( wombat )`.
|
|
| 343 | 372 | -}
|
| 344 | 373 | |
| 345 | 374 | allKnownOccs :: OccSet
|
| ... | ... | @@ -219,7 +219,6 @@ knownKeyTable |
| 219 | 219 | -- Class Functor
|
| 220 | 220 | , (mkTcOcc "Functor", functorClassKey)
|
| 221 | 221 | , (mkVarOcc "fmap", fmapClassOpKey)
|
| 222 | - , (mkVarOcc "map", mapIdKey)
|
|
| 223 | 222 | |
| 224 | 223 | -- Class Monad, MonadFix, MonadZip
|
| 225 | 224 | , (mkTcOcc "Monad", monadClassKey)
|
| ... | ... | @@ -254,7 +253,6 @@ knownKeyTable |
| 254 | 253 | , (mkVarOcc "dataToTag#", dataToTagClassOpKey)
|
| 255 | 254 | |
| 256 | 255 | -- Lists
|
| 257 | - , (mkVarOcc "foldr", foldrIdKey)
|
|
| 258 | 256 | , (mkVarOcc "build", buildIdKey)
|
| 259 | 257 | |
| 260 | 258 | -- Records
|
| ... | ... | @@ -43,6 +43,49 @@ mechanisms: |
| 43 | 43 | to make an ExactOcc RdrName for the thing. We use the latter for
|
| 44 | 44 | known-key things, merely to avoid duplicating knowledge of the KnownOcc
|
| 45 | 45 | |
| 46 | +Note [Tricky known-occ cases]
|
|
| 47 | +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 48 | +A few known-occ entities are a bit tricky, because ghc-internal has distinct
|
|
| 49 | +entities that share the same occ-name. For these, we must be careful to
|
|
| 50 | +have the correct one in scope when looking up a known-occ name.
|
|
| 51 | + |
|
| 52 | +* Data types involving Fixity. We have
|
|
| 53 | + module GHC.Internal.Data.Data where
|
|
| 54 | + data Fixity = Infix | Prefix
|
|
| 55 | + module GHC.Internal.Generics where
|
|
| 56 | + data Fixity = Prefix | Infix Associativity Int
|
|
| 57 | + module GHC.Internal.TH.Syntax where
|
|
| 58 | + data Fixity = Fixity Int FixityDirection
|
|
| 59 | + |
|
| 60 | + Of these, Fixity(Infix,Prefix) from GHC.Internal.Data.Data are the
|
|
| 61 | + known-occ entities, used in derived Data instances; the other are not.
|
|
| 62 | + |
|
| 63 | +* `prec`: we have
|
|
| 64 | + module GHC.Internal.Text.ParserCombinators.ReadPrec where
|
|
| 65 | + prec :: Prec -> ReadPrec a -> ReadPrec a
|
|
| 66 | + module GHC.Internal.Generics where
|
|
| 67 | + prec :: Fixity -> Int
|
|
| 68 | + |
|
| 69 | + Of these, the former is the known-occ entity, used in the derived instances
|
|
| 70 | + for Read. The latter is not.
|
|
| 71 | + |
|
| 72 | +* `foldr`: we have
|
|
| 73 | + module GHC.Internal.Data.Foldable where
|
|
| 74 | + class Foldable t where
|
|
| 75 | + foldr :: (a -> b -> b) -> b -> t a -> b
|
|
| 76 | + module GHC.Internal.Base where
|
|
| 77 | + foldr :: (a -> b -> b) -> b -> [a] -> b
|
|
| 78 | + |
|
| 79 | + This one is particularly annoying because
|
|
| 80 | + * We need the Foldable `foldr` to be known-occ so we can refer to it in
|
|
| 81 | + derived Foldable instances
|
|
| 82 | + * We need the list `foldr` to be known-occ so we can refer to it when
|
|
| 83 | + desugaring list comprehensions.
|
|
| 84 | + |
|
| 85 | + So we define an alias
|
|
| 86 | + module GHC.Internal.Base where
|
|
| 87 | + foldrList = foldr
|
|
| 88 | + make `foldrList` known-occ, and refer to that in desugaring list comprehensions.
|
|
| 46 | 89 | -}
|
| 47 | 90 | |
| 48 | 91 | |
| ... | ... | @@ -107,8 +150,10 @@ rightDataConOcc = mkDataOcc "Right" |
| 107 | 150 | voidTyConOcc = mkTcOcc "Void"
|
| 108 | 151 | rationalTyConOcc = mkTcOcc "Rational"
|
| 109 | 152 | |
| 110 | -composeIdOcc :: KnownOcc
|
|
| 111 | -composeIdOcc = mkVarOcc "."
|
|
| 153 | +composeIdOcc, mapIdOcc, foldrListIdOcc :: KnownOcc
|
|
| 154 | +composeIdOcc = mkVarOcc "."
|
|
| 155 | +mapIdOcc = mkVarOcc "map"
|
|
| 156 | +foldrListIdOcc = mkVarOcc "foldrList"
|
|
| 112 | 157 | |
| 113 | 158 | fromStaticPtrClassOpOcc :: KnownOcc
|
| 114 | 159 | fromStaticPtrClassOpOcc = mkVarOcc "fromStaticPtr"
|
| ... | ... | @@ -128,16 +173,9 @@ enumFromToClassOpOcc = mkVarOcc "enumFromTo" |
| 128 | 173 | enumFromThenToClassOpOcc = mkVarOcc "enumFromThenTo"
|
| 129 | 174 | |
| 130 | 175 | -- Class Typeable, and functions for constructing `Typeable` dictionaries
|
| 131 | -someTypeRepTyConOcc
|
|
| 132 | - , someTypeRepDataConOcc
|
|
| 133 | - , mkTrConOcc
|
|
| 134 | - , mkTrAppCheckedOcc
|
|
| 135 | - , mkTrFunOcc
|
|
| 136 | - , typeRepIdOcc
|
|
| 137 | - , typeNatTypeRepOcc
|
|
| 138 | - , typeSymbolTypeRepOcc
|
|
| 139 | - , typeCharTypeRepOcc
|
|
| 140 | - :: KnownOcc
|
|
| 176 | +someTypeRepTyConOcc, someTypeRepDataConOcc, mkTrConOcc, mkTrAppCheckedOcc
|
|
| 177 | + , mkTrFunOcc, typeRepIdOcc, typeNatTypeRepOcc, typeSymbolTypeRepOcc
|
|
| 178 | + , typeCharTypeRepOcc :: KnownOcc
|
|
| 141 | 179 | someTypeRepTyConOcc = mkTcOcc "SomeTypeRep"
|
| 142 | 180 | someTypeRepDataConOcc = mkDataOcc "SomeTypeRep"
|
| 143 | 181 | typeRepIdOcc = mkVarOcc "typeRep#"
|
| ... | ... | @@ -148,21 +186,14 @@ typeNatTypeRepOcc = mkVarOcc "typeNatTypeRep" |
| 148 | 186 | typeSymbolTypeRepOcc = mkVarOcc "typeSymbolTypeRep"
|
| 149 | 187 | typeCharTypeRepOcc = mkVarOcc "typeCharTypeRep"
|
| 150 | 188 | |
| 151 | -typeLitSymbolDataConOcc
|
|
| 152 | - , typeLitNatDataConOcc
|
|
| 153 | - , typeLitCharDataConOcc
|
|
| 154 | - :: KnownOcc
|
|
| 189 | +typeLitSymbolDataConOcc, typeLitNatDataConOcc, typeLitCharDataConOcc :: KnownOcc
|
|
| 155 | 190 | typeLitSymbolDataConOcc = mkDataOcc "TypeLitSymbol"
|
| 156 | 191 | typeLitNatDataConOcc = mkDataOcc "TypeLitNat"
|
| 157 | 192 | typeLitCharDataConOcc = mkDataOcc "TypeLitChar"
|
| 158 | 193 | |
| 159 | 194 | |
| 160 | -trModuleTyConOcc
|
|
| 161 | - , trModuleDataConOcc
|
|
| 162 | - , trNameSDataConOcc
|
|
| 163 | - , trTyConTyConOcc
|
|
| 164 | - , trTyConDataConOcc
|
|
| 165 | - :: KnownOcc
|
|
| 195 | +trModuleTyConOcc, trModuleDataConOcc, trNameSDataConOcc
|
|
| 196 | + , trTyConTyConOcc, trTyConDataConOcc :: KnownOcc
|
|
| 166 | 197 | trModuleTyConOcc = mkTcOcc "Module"
|
| 167 | 198 | trModuleDataConOcc = mkDataOcc "Module"
|
| 168 | 199 | trNameSDataConOcc = mkDataOcc "TrNameS"
|
| ... | ... | @@ -170,14 +201,8 @@ trTyConTyConOcc = mkTcOcc "TyCon" |
| 170 | 201 | trTyConDataConOcc = mkDataOcc "TyCon"
|
| 171 | 202 | |
| 172 | 203 | -- Typeable representation types
|
| 173 | -kindRepTyConOcc
|
|
| 174 | - , kindRepTyConAppDataConOcc
|
|
| 175 | - , kindRepVarDataConOcc
|
|
| 176 | - , kindRepAppDataConOcc
|
|
| 177 | - , kindRepFunDataConOcc
|
|
| 178 | - , kindRepTYPEDataConOcc
|
|
| 179 | - , kindRepTypeLitSDataConOcc
|
|
| 180 | - :: KnownOcc
|
|
| 204 | +kindRepTyConOcc, kindRepTyConAppDataConOcc, kindRepVarDataConOcc, kindRepAppDataConOcc
|
|
| 205 | + , kindRepFunDataConOcc, kindRepTYPEDataConOcc, kindRepTypeLitSDataConOcc :: KnownOcc
|
|
| 181 | 206 | kindRepTyConOcc = mkTcOcc "KindRep"
|
| 182 | 207 | kindRepTyConAppDataConOcc = mkDataOcc "KindRepTyConApp"
|
| 183 | 208 | kindRepVarDataConOcc = mkDataOcc "KindRepVar"
|
| ... | ... | @@ -210,20 +235,20 @@ main_RDR_Unqual = mkUnqual varName (fsLit "main") |
| 210 | 235 | -- We definitely don't want an Orig RdrName, because
|
| 211 | 236 | -- main might, in principle, be imported into module Main
|
| 212 | 237 | |
| 213 | - |
|
| 214 | 238 | error_RDR :: RdrName
|
| 215 | 239 | error_RDR = knownVarOccRdrName "error"
|
| 216 | 240 | |
| 217 | 241 | toDyn_RDR :: RdrName
|
| 218 | 242 | toDyn_RDR = knownVarOccRdrName "toDyn"
|
| 219 | 243 | |
| 220 | -compose_RDR :: RdrName
|
|
| 244 | +compose_RDR, map_RDR :: RdrName
|
|
| 221 | 245 | compose_RDR = knownOccRdrName composeIdOcc
|
| 246 | +map_RDR = knownOccRdrName mapIdOcc
|
|
| 222 | 247 | |
| 223 | 248 | appE_RDR, lift_RDR, liftTyped_RDR :: RdrName
|
| 224 | -appE_RDR = knownVarOccRdrName "appE"
|
|
| 225 | -lift_RDR = knownVarOccRdrName "lift"
|
|
| 226 | -liftTyped_RDR = knownVarOccRdrName "liftTyped"
|
|
| 249 | +appE_RDR = knownVarOccRdrName "appE"
|
|
| 250 | +lift_RDR = knownVarOccRdrName "lift"
|
|
| 251 | +liftTyped_RDR = knownVarOccRdrName "liftTyped"
|
|
| 227 | 252 | |
| 228 | 253 | enumFrom_RDR, enumFromTo_RDR, enumFromThen_RDR, enumFromThenTo_RDR :: RdrName
|
| 229 | 254 | enumFrom_RDR = knownOccRdrName enumFromClassOpOcc
|
| ... | ... | @@ -420,10 +445,9 @@ ltTag_RDR = nameRdrName ordLTDataConName |
| 420 | 445 | eqTag_RDR = nameRdrName ordEQDataConName
|
| 421 | 446 | gtTag_RDR = nameRdrName ordGTDataConName
|
| 422 | 447 | |
| 423 | -map_RDR, fmap_RDR, replace_RDR, pure_RDR, ap_RDR, liftA2_RDR, foldable_foldr_RDR,
|
|
| 448 | +fmap_RDR, replace_RDR, pure_RDR, ap_RDR, liftA2_RDR, foldable_foldr_RDR,
|
|
| 424 | 449 | foldMap_RDR, null_RDR, all_RDR, traverse_RDR, mempty_RDR,
|
| 425 | 450 | mappend_RDR :: RdrName
|
| 426 | -map_RDR = knownKeyRdrName mapIdKey
|
|
| 427 | 451 | fmap_RDR = knownKeyRdrName fmapClassOpKey
|
| 428 | 452 | pure_RDR = knownKeyRdrName pureAClassOpKey
|
| 429 | 453 | ap_RDR = knownKeyRdrName apAClassOpKey
|
| ... | ... | @@ -37,6 +37,7 @@ import GHC.Driver.DynFlags |
| 37 | 37 | import GHC.Tc.Utils.TcType
|
| 38 | 38 | |
| 39 | 39 | import GHC.Builtin.KnownKeys
|
| 40 | +import GHC.Builtin.KnownOccs
|
|
| 40 | 41 | import GHC.Builtin.Types
|
| 41 | 42 | import GHC.Builtin.Types.Prim( alphaTyVar )
|
| 42 | 43 | |
| ... | ... | @@ -129,7 +130,7 @@ dsTransStmt (TransStmt { trS_form = form, trS_stmts = stmts, trS_bndrs = binderM |
| 129 | 130 | |
| 130 | 131 | -- Create an unzip function for the appropriate arity and element types and find "map"
|
| 131 | 132 | unzip_stuff' <- mkUnzipBind form from_bndrs_tys
|
| 132 | - map_id <- dsLookupKnownKeyId mapIdKey
|
|
| 133 | + map_id <- dsLookupKnownOccId mapIdOcc
|
|
| 133 | 134 | |
| 134 | 135 | -- Generate the expressions to build the grouped list
|
| 135 | 136 | let -- First we apply the grouping function to the inner list
|
| ... | ... | @@ -682,7 +683,7 @@ mkFoldrExpr :: Type -- ^ Element type of the list |
| 682 | 683 | -> CoreExpr -- ^ List expression being folded acress
|
| 683 | 684 | -> DsM CoreExpr
|
| 684 | 685 | mkFoldrExpr elt_ty result_ty c n list = do
|
| 685 | - foldr_id <- dsLookupKnownKeyId foldrIdKey
|
|
| 686 | + foldr_id <- dsLookupKnownOccId foldrListIdOcc
|
|
| 686 | 687 | return (Var foldr_id `App` Type elt_ty
|
| 687 | 688 | `App` Type result_ty
|
| 688 | 689 | `App` c
|
| ... | ... | @@ -116,7 +116,7 @@ import GHC.Types.SafeHaskell |
| 116 | 116 | import GHC.Types.TypeEnv
|
| 117 | 117 | import GHC.Types.Unique.DSet
|
| 118 | 118 | import GHC.Types.Unique.Map( listToUniqMap )
|
| 119 | -import GHC.Types.Unique.FM( UniqFM, listToUFM, lookupUFM )
|
|
| 119 | +import GHC.Types.Unique.FM( UniqFM, listToUFM, lookupUFM, elemUFM )
|
|
| 120 | 120 | import GHC.Types.SrcLoc
|
| 121 | 121 | import GHC.Types.TyThing
|
| 122 | 122 | import GHC.Types.PkgQual
|
| ... | ... | @@ -284,9 +284,12 @@ loadKnownKeyOccMaps |
| 284 | 284 | cannotFindModule hsc_env kNOWN_KEY_NAMES fr }
|
| 285 | 285 | |
| 286 | 286 | ; let kk_map :: UniqFM KnownKey Name
|
| 287 | + -- Domain is just the KnownKeys in the knownKeyTable
|
|
| 287 | 288 | kk_map = listToUFM [ (getUnique nm, nm)
|
| 288 | 289 | | avail <- mi_exports iface
|
| 289 | - , nm <- availNames avail ]
|
|
| 290 | + , nm <- availNames avail
|
|
| 291 | + , let uniq = getUnique nm
|
|
| 292 | + , uniq `elemUFM` knownKeyUniqMap ]
|
|
| 290 | 293 | occ_map :: OccEnv Name
|
| 291 | 294 | occ_map = mkOccEnv [ (nameOccName nm, nm)
|
| 292 | 295 | | avail <- mi_exports iface
|
| ... | ... | @@ -2029,14 +2029,6 @@ findImportUsage imports used_gres |
| 2029 | 2029 | | used
|
| 2030 | 2030 | = acc
|
| 2031 | 2031 | |
| 2032 | -{- ToDo: delete this
|
|
| 2033 | - -- -frebindable-known-key-names is on, and `n` is a known-key name
|
|
| 2034 | - -- Then don't warn about an unused import.
|
|
| 2035 | - -- See (UI2) in Note [Unused imports]
|
|
| 2036 | - | rebindable_known_key_names
|
|
| 2037 | - , isKnownKeyName n || nameOccName n `elemOccSet` allKnownOccs
|
|
| 2038 | - = acc
|
|
| 2039 | --}
|
|
| 2040 | 2032 | | otherwise
|
| 2041 | 2033 | = UnusedNames (acc_ns `extendNameSet` n) acc_wcs acc_fs
|
| 2042 | 2034 | where
|
| ... | ... | @@ -2210,6 +2202,7 @@ warnUnusedImport :: GlobalRdrEnv -> ImportDeclUsage -> RnM () |
| 2210 | 2202 | warnUnusedImport rdr_env (L loc decl, used, unused, unused_wcs)
|
| 2211 | 2203 | |
| 2212 | 2204 | -- Do not warn for 'import M()'
|
| 2205 | + -- See (UI1) in Note [Unused imports]
|
|
| 2213 | 2206 | | Just (Exactly, _) <- ideclImportList decl
|
| 2214 | 2207 | , null unused
|
| 2215 | 2208 | = return ()
|
| ... | ... | @@ -2221,8 +2214,7 @@ warnUnusedImport rdr_env (L loc decl, used, unused, unused_wcs) |
| 2221 | 2214 | = return ()
|
| 2222 | 2215 | |
| 2223 | 2216 | -- Do not warn about import X as Rebindable
|
| 2224 | - -- See Note [Overview of known-key entities]
|
|
| 2225 | - -- ToDo: write wrinkle
|
|
| 2217 | + -- See (UI2) in Note [Unused imports]
|
|
| 2226 | 2218 | | Just (L _ mod) <- ideclAs decl
|
| 2227 | 2219 | , mod == rEBINDABLE_MOD_NAME
|
| 2228 | 2220 | = return ()
|
| ... | ... | @@ -2405,21 +2397,13 @@ and neither `a` nor `b` is used, we report the entire import decl as unused. We |
| 2405 | 2397 | check this by looking at the names that it brings into scope scope; if there are
|
| 2406 | 2398 | no ununused names, don't report.
|
| 2407 | 2399 | |
| 2408 | -This neatly takes into account two things:
|
|
| 2409 | - |
|
| 2410 | 2400 | (UI1) We don't want to complain about `import M()`, because that is often used to bring
|
| 2411 | - M's /instances/ into scope.
|
|
| 2412 | - |
|
| 2413 | -(UI2) In base:Data.Enum we see
|
|
| 2414 | - import GHC.Internal.Num( Num ) -- For -frebindable-known-key-names (defaulting)
|
|
| 2415 | - 'Num' is not mentioned explicity but the import is still required; see KKNS_InScope
|
|
| 2416 | - in Note [Overview of known-key entities] in GHC.Builtin
|
|
| 2417 | - |
|
| 2418 | - We don't want this import reported at an unused. So `findImportUsage`, when looking
|
|
| 2419 | - at `import M( x )`, we do /not/ record `x` as "unused" (regardless of whether it is
|
|
| 2420 | - mentioned in M if
|
|
| 2421 | - (a) -frebindable-known-key-names is on, and
|
|
| 2422 | - (b) `x` is a known-key name
|
|
| 2401 | + M's /instances/ into scope. That is neatly dealt with by the "no unused names"
|
|
| 2402 | + criterion.
|
|
| 2403 | + |
|
| 2404 | +(UI2) We don't report a decl as unused if it has an `as Rebindable` qualifier.
|
|
| 2405 | + See (KKN1) in Note [Overview of known-key entities] in GHC.Builtin
|
|
| 2406 | + |
|
| 2423 | 2407 | |
| 2424 | 2408 | Note [Printing minimal imports]
|
| 2425 | 2409 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -1066,7 +1066,7 @@ gen_Traversable_binds loc dit@(DerivInstTys{ dit_rep_tc = tycon |
| 1066 | 1066 | where
|
| 1067 | 1067 | data_cons = getPossibleDataCons tycon tycon_args
|
| 1068 | 1068 | |
| 1069 | - traverse_name = L (noAnnSrcSpan loc) traverse_RDR
|
|
| 1069 | + traverse_name = mkMethBinder loc traverse_RDR
|
|
| 1070 | 1070 | |
| 1071 | 1071 | -- See Note [EmptyDataDecls with Functor, Foldable, and Traversable]
|
| 1072 | 1072 | traverse_bind = mkRdrFunBindEC 2 (nlHsApp pure_Expr)
|
| ... | ... | @@ -2152,14 +2152,11 @@ nlHsCompose :: LHsExpr GhcPs -> LHsExpr GhcPs -> LHsExpr GhcPs |
| 2152 | 2152 | nlHsCompose x y = compose_RDR `nlHsApps` [x, y]
|
| 2153 | 2153 | |
| 2154 | 2154 | mkMethBinder :: SrcSpan -> RdrName -> LocatedN RdrName
|
| 2155 | --- The binder for a class method `op` in in an instance decl
|
|
| 2156 | --- can be /unqualified/, thus
|
|
| 2157 | --- instance C Int where
|
|
| 2158 | --- op = ... -- The "op" can be unqualied
|
|
| 2159 | --- because the renamer looks in the class to find it. Having it
|
|
| 2160 | --- unqualified reduces the need for it to be in scope
|
|
| 2161 | -mkMethBinder loc op_rdr
|
|
| 2162 | - = L (noAnnSrcSpan loc ) (mkRdrUnqual (rdrNameOcc op_rdr))
|
|
| 2155 | +-- The binder for a class method `op` in in an `derived` instance decl
|
|
| 2156 | +-- should be an Exact RdrName, so that the derived instance works even when
|
|
| 2157 | +-- that method name is not in scope in this module. (Usually, a method must
|
|
| 2158 | +-- be in scope for you to define it in an instance decl.)
|
|
| 2159 | +mkMethBinder loc op_rdr = L (noAnnSrcSpan loc ) op_rdr
|
|
| 2163 | 2160 | |
| 2164 | 2161 | -- | Make a function binding. If no equations are given, produce a function
|
| 2165 | 2162 | -- with the given arity that produces a stock error.
|
| ... | ... | @@ -352,14 +352,14 @@ gk2gkDC Gen1 dc tc_args = Gen1_DC $ assert (isTyVarTy last_dc_inst_univ) |
| 352 | 352 | mkBindsRep :: DynFlags -> GenericKind -> SrcSpan -> DerivInstTys -> (LHsBinds GhcPs, [LSig GhcPs])
|
| 353 | 353 | mkBindsRep dflags gk loc dit@(DerivInstTys{dit_rep_tc = tycon}) = (binds, sigs)
|
| 354 | 354 | where
|
| 355 | - binds = [mkRdrFunBind (mkMethBinder loc' from01_RDR) [from_eqn]]
|
|
| 355 | + binds = [mkRdrFunBind from01_bndr [from_eqn]]
|
|
| 356 | 356 | ++
|
| 357 | - [mkRdrFunBind (mkMethBinder loc' to01_RDR) [to_eqn]]
|
|
| 357 | + [mkRdrFunBind to01_bndr [to_eqn]]
|
|
| 358 | 358 | |
| 359 | 359 | -- See Note [Generics performance tricks]
|
| 360 | 360 | sigs = if gopt Opt_InlineGenericsAggressively dflags
|
| 361 | 361 | || (gopt Opt_InlineGenerics dflags && inlining_useful)
|
| 362 | - then [inline1 from01_RDR, inline1 to01_RDR]
|
|
| 362 | + then [inline1 from01_bndr, inline1 to01_bndr]
|
|
| 363 | 363 | else []
|
| 364 | 364 | where
|
| 365 | 365 | inlining_useful
|
| ... | ... | @@ -373,7 +373,7 @@ mkBindsRep dflags gk loc dit@(DerivInstTys{dit_rep_tc = tycon}) = (binds, sigs) |
| 373 | 373 | cons = length datacons
|
| 374 | 374 | max_fields = maximum $ 0 :| map dataConSourceArity datacons
|
| 375 | 375 | |
| 376 | - inline1 f = L loc'' . InlineSig noAnn (L loc' f)
|
|
| 376 | + inline1 f = L loc'' . InlineSig noAnn f
|
|
| 377 | 377 | $ alwaysInlinePragma `setInlinePragmaActivation` activeAfter (Phase 1)
|
| 378 | 378 | |
| 379 | 379 | -- The topmost M1 (the datatype metadata) has the exact same type
|
| ... | ... | @@ -386,10 +386,11 @@ mkBindsRep dflags gk loc dit@(DerivInstTys{dit_rep_tc = tycon}) = (binds, sigs) |
| 386 | 386 | |
| 387 | 387 | from_matches = [mkHsCaseAlt pat rhs | (pat,rhs) <- from_alts]
|
| 388 | 388 | to_matches = [mkHsCaseAlt pat rhs | (pat,rhs) <- to_alts ]
|
| 389 | - loc' = noAnnSrcSpan loc
|
|
| 390 | 389 | loc'' = noAnnSrcSpan loc
|
| 391 | 390 | datacons = tyConDataCons tycon
|
| 392 | 391 | |
| 392 | + from01_bndr = mkMethBinder loc from01_RDR
|
|
| 393 | + to01_bndr = mkMethBinder loc to01_RDR
|
|
| 393 | 394 | (from01_RDR, to01_RDR) = case gk of
|
| 394 | 395 | Gen0 -> (from_RDR, to_RDR)
|
| 395 | 396 | Gen1 -> (from1_RDR, to1_RDR)
|
| ... | ... | @@ -63,10 +63,13 @@ import GHC.Internal.Data.Functor ((<$>)) |
| 63 | 63 | import GHC.Internal.Data.Functor.Const (Const(..))
|
| 64 | 64 | import GHC.Internal.Data.Typeable (Typeable)
|
| 65 | 65 | import GHC.Internal.Data.Data (Data)
|
| 66 | - |
|
| 66 | +import GHC.Generics( Generic, Generic1 )
|
|
| 67 | 67 | import GHC.Internal.Functor.ZipList (ZipList(..))
|
| 68 | -import GHC.Generics
|
|
| 69 | -import qualified GHC.KnownKeyNames as Rebindable
|
|
| 68 | + |
|
| 69 | +import qualified GHC.Internal.Data.Data as Rebindable
|
|
| 70 | +import qualified GHC.Internal.Data.Typeable.Internal as Rebindable
|
|
| 71 | +import qualified GHC.Num as Rebindable
|
|
| 72 | +import qualified GHC.Generics as Rebindable hiding( Fixity(..) )
|
|
| 70 | 73 | |
| 71 | 74 | -- $setup
|
| 72 | 75 | -- >>> import Prelude
|
| ... | ... | @@ -93,7 +93,7 @@ import Prelude |
| 93 | 93 | import GHC.Internal.Data.Data
|
| 94 | 94 | import GHC.Internal.TypeLits (KnownNat, natVal)
|
| 95 | 95 | import GHC.Internal.Read
|
| 96 | -import GHC.Internal.Text.ParserCombinators.ReadPrec( ReadPrec, pfail )
|
|
| 96 | +import GHC.Internal.Text.ParserCombinators.ReadPrec( ReadPrec )
|
|
| 97 | 97 | import GHC.Internal.Text.Read.Lex
|
| 98 | 98 | import qualified GHC.Internal.TH.Monad as TH
|
| 99 | 99 | import qualified GHC.Internal.TH.Lift as TH
|
| ... | ... | @@ -121,7 +121,8 @@ import GHC.Internal.Data.Traversable |
| 121 | 121 | import GHC.Internal.Data.Semigroup.Internal
|
| 122 | 122 | import GHC.Internal.Control.Monad.Fix
|
| 123 | 123 | import GHC.Internal.Data.Data
|
| 124 | -import GHC.Generics
|
|
| 124 | +import GHC.Generics( Generic, Generic1 )
|
|
| 125 | +import qualified GHC.Generics as Rebindable hiding( Fixity(..) )
|
|
| 125 | 126 | import qualified GHC.Internal.List as List
|
| 126 | 127 | import qualified GHC.KnownKeyNames as Rebindable
|
| 127 | 128 |
| ... | ... | @@ -14,16 +14,16 @@ module GHC.KnownKeyNames |
| 14 | 14 | ( Eq(..), Ord(..) -- With their methods
|
| 15 | 15 | , Show, Read
|
| 16 | 16 | |
| 17 | - -- Foldable/Traversable with their methods
|
|
| 18 | - , Foldable, foldMap, null, all
|
|
| 19 | - , Traversable, traverse
|
|
| 17 | + -- Foldable/Traversable with those methods need for deriving
|
|
| 18 | + , Foldable(foldr, foldMap, null), all
|
|
| 19 | + , Traversable(traverse)
|
|
| 20 | 20 | |
| 21 | 21 | , Functor, fmap, (<$)
|
| 22 | 22 | , Monad, (>>), (>>=), return, fail, guard, mfix, join
|
| 23 | 23 | , Alternative
|
| 24 | 24 | |
| 25 | 25 | -- Misc
|
| 26 | - , (.), (&&), not, map, foldr, build
|
|
| 26 | + , (.), (&&), not, foldrList, build, map
|
|
| 27 | 27 | , seq#
|
| 28 | 28 | |
| 29 | 29 | -- Applicative
|
| ... | ... | @@ -47,7 +47,7 @@ module GHC.KnownKeyNames |
| 47 | 47 | , Ix, range, inRange, index, unsafeIndex, unsafeRangeSize
|
| 48 | 48 | |
| 49 | 49 | -- Data
|
| 50 | - , Data
|
|
| 50 | + , Data, Fixity(Prefix,Infix)
|
|
| 51 | 51 | , gfoldl, gunfold, toConstr, dataTypeOf, dataCast1, dataCast2
|
| 52 | 52 | , mkConstrTag, Constr, mkDataType, DataType, constrIndex
|
| 53 | 53 | |
| ... | ... | @@ -59,9 +59,8 @@ module GHC.KnownKeyNames |
| 59 | 59 | , Generic(..), Generic1(..)
|
| 60 | 60 | , Datatype(..), Constructor(..), Selector(..)
|
| 61 | 61 | , U1(..), Par1(..), Rec1(..), K1(..), M1(..)
|
| 62 | - , (:+:)(L1, R1), (:*:)((:*:))
|
|
| 63 | - , Comp1(..)
|
|
| 64 | - , UAddr(..), UChar(..), UDouble(..), UFloat(..), UInt(..), UWord(..)
|
|
| 62 | + , (:+:)(L1, R1), (:*:)((:*:)), (:.:)(Comp1, unComp1)
|
|
| 63 | + , UAddr, UChar, UDouble, UFloat, UInt, UWord
|
|
| 65 | 64 | |
| 66 | 65 | -- DataToTag
|
| 67 | 66 | , DataToTag
|
| ... | ... | @@ -196,7 +195,7 @@ module GHC.KnownKeyNames |
| 196 | 195 | , Clause, clause
|
| 197 | 196 | ) where
|
| 198 | 197 | |
| 199 | -import GHC.Internal.Base
|
|
| 198 | +import GHC.Internal.Base hiding( foldr )
|
|
| 200 | 199 | import GHC.Internal.Show
|
| 201 | 200 | import GHC.Internal.Read
|
| 202 | 201 | import GHC.Internal.Num
|
| ... | ... | @@ -209,7 +208,7 @@ import GHC.Internal.Data.Dynamic( toDyn ) |
| 209 | 208 | import GHC.Internal.Data.Data
|
| 210 | 209 | import GHC.Internal.Data.String( fromString )
|
| 211 | 210 | import GHC.Internal.Data.Either( Either(..) )
|
| 212 | -import GHC.Internal.Data.Foldable( Foldable, foldMap, null, all )
|
|
| 211 | +import GHC.Internal.Data.Foldable( Foldable(..), null, all )
|
|
| 213 | 212 | import GHC.Internal.Data.Traversable( Traversable, traverse )
|
| 214 | 213 | import GHC.Internal.Float( RealFloat )
|
| 215 | 214 | import GHC.Internal.IO( seq# )
|
| ... | ... | @@ -226,8 +225,6 @@ import qualified GHC.Internal.IsList as IL |
| 226 | 225 | import GHC.Internal.Err( error )
|
| 227 | 226 | import GHC.Internal.Int( Int8(I8#), Int16(I16#), Int32(I32#), Int64(I64#) )
|
| 228 | 227 | import GHC.Internal.Word( Word8(W8#), Word16(W16#), Word32(W32#), Word64(W64#) )
|
| 229 | -import GHC.Internal.Text.ParserCombinators.ReadPrec( step, reset, prec, pfail, (+++) )
|
|
| 230 | -import GHC.Internal.Text.Read.Lex( Lexeme(Punc, Ident, Symbol) )
|
|
| 231 | 228 | |
| 232 | 229 | import GHC.Internal.Unsafe.Coerce( UnsafeEquality(..), unsafeEqualityProof )
|
| 233 | 230 | |
| ... | ... | @@ -236,11 +233,18 @@ import GHC.Internal.StaticPtr.Internal( makeStatic ) |
| 236 | 233 | |
| 237 | 234 | import GHC.Internal.Data.Typeable( gcast1, gcast2 )
|
| 238 | 235 | import GHC.Internal.Data.Typeable.Internal as TR
|
| 239 | -import GHC.Internal.Generics
|
|
| 236 | +import GHC.Internal.Generics( Generic(..), Generic1(..), Datatype(..)
|
|
| 237 | + , Constructor(..), Selector(..)
|
|
| 238 | + , U1(..), Par1(..), Rec1(..), K1(..), M1(..)
|
|
| 239 | + , (:+:)(..), (:*:)(..), (:.:)(..)
|
|
| 240 | + , UAddr, UChar, UDouble
|
|
| 241 | + , UFloat, UInt, UWord
|
|
| 242 | + )
|
|
| 240 | 243 | |
| 241 | 244 | import GHC.Internal.Bignum.BigNat
|
| 242 | 245 | |
| 243 | -import GHC.Internal.TH.Syntax as TH
|
|
| 244 | -import GHC.Internal.TH.Lib hiding( InjectivityAnn, Role )
|
|
| 246 | +import GHC.Internal.TH.Syntax as TH hiding( Fixity(..) )
|
|
| 247 | + -- hiding(Fixity) see Note [Tricky known-occ cases] in GHC.Builtin.KnownOccs
|
|
| 248 | +import GHC.Internal.TH.Lib
|
|
| 245 | 249 | import GHC.Internal.TH.Lift
|
| 246 | 250 | import GHC.Internal.TH.Monad |
| ... | ... | @@ -1819,6 +1819,12 @@ foldr k z = go |
| 1819 | 1819 | go [] = z
|
| 1820 | 1820 | go (y:ys) = y `k` go ys
|
| 1821 | 1821 | |
| 1822 | + |
|
| 1823 | +foldrList :: (a -> b -> b) -> b -> [a] -> b
|
|
| 1824 | +-- An alias for `foldr`, used only internally
|
|
| 1825 | +-- See Note [Tricky known-occ cases] in GHC.Builtin.KnownOccs
|
|
| 1826 | +foldrList = foldr
|
|
| 1827 | + |
|
| 1822 | 1828 | -- | A list producer that can be fused with 'foldr'.
|
| 1823 | 1829 | -- This function is merely
|
| 1824 | 1830 | --
|
| ... | ... | @@ -83,7 +83,8 @@ import GHC.Internal.Numeric |
| 83 | 83 | import GHC.Internal.Ptr
|
| 84 | 84 | import GHC.Internal.Unsafe.Coerce
|
| 85 | 85 | import GHC.Internal.Stack (HasCallStack)
|
| 86 | -import qualified GHC.Internal.Data.Foldable as Rebindable
|
|
| 86 | +import qualified GHC.Internal.Data.Foldable as Rebindable
|
|
| 87 | +import qualified GHC.Internal.Data.Traversable as Rebindable
|
|
| 87 | 88 | |
| 88 | 89 | ------------------------------------------------------------------------
|
| 89 | 90 | -- Boxes
|
| ... | ... | @@ -19,10 +19,8 @@ |
| 19 | 19 | -- is safe to break things.
|
| 20 | 20 | |
| 21 | 21 | module GHC.Internal.TH.Lib where
|
| 22 | - |
|
| 23 | -import GHC.Internal.TH.Syntax hiding (Role, InjectivityAnn)
|
|
| 22 | +import GHC.Internal.TH.Syntax
|
|
| 24 | 23 | import GHC.Internal.TH.Monad
|
| 25 | -import qualified GHC.Internal.TH.Syntax as TH
|
|
| 26 | 24 | |
| 27 | 25 | #ifdef BOOTSTRAP_TH
|
| 28 | 26 | import Control.Applicative(liftA, Applicative(..))
|
| ... | ... | @@ -94,10 +92,6 @@ type PatSynArgsQ = Q PatSynArgs |
| 94 | 92 | type FamilyResultSigQ = Q FamilyResultSig
|
| 95 | 93 | type DerivStrategyQ = Q DerivStrategy
|
| 96 | 94 | |
| 97 | --- must be defined here for DsMeta to find it
|
|
| 98 | -type Role = TH.Role
|
|
| 99 | -type InjectivityAnn = TH.InjectivityAnn
|
|
| 100 | - |
|
| 101 | 95 | type TyVarBndrUnit = TyVarBndr ()
|
| 102 | 96 | type TyVarBndrSpec = TyVarBndr Specificity
|
| 103 | 97 | type TyVarBndrVis = TyVarBndr BndrVis
|
| ... | ... | @@ -974,7 +968,7 @@ tyVarSig = fmap TyVarSig |
| 974 | 968 | -- * Injectivity annotation
|
| 975 | 969 | |
| 976 | 970 | injectivityAnn :: Name -> [Name] -> InjectivityAnn
|
| 977 | -injectivityAnn = TH.InjectivityAnn
|
|
| 971 | +injectivityAnn = InjectivityAnn
|
|
| 978 | 972 | |
| 979 | 973 | -------------------------------------------------------------------------------
|
| 980 | 974 | -- * Role
|
| ... | ... | @@ -33,7 +33,7 @@ import GHC.Internal.Base as Rebindable hiding( Type ) |
| 33 | 33 | import GHC.Internal.TH.Syntax
|
| 34 | 34 | import GHC.Internal.TH.Monad
|
| 35 | 35 | import qualified GHC.Internal.TH.Lib as Lib (litE)
|
| 36 | -import GHC.Internal.TH.Lib hiding( InjectivityAnn, Role )
|
|
| 36 | +import GHC.Internal.TH.Lib
|
|
| 37 | 37 | -- For known-key names
|
| 38 | 38 | -- See wrinkle (W4) of Note [Tracking dependencies on primitives]
|
| 39 | 39 |
| ... | ... | @@ -42,7 +42,6 @@ import GHC.Ptr ( Ptr, plusPtr ) |
| 42 | 42 | import GHC.Generics ( Generic )
|
| 43 | 43 | #else
|
| 44 | 44 | -- Compiling with stage1 compiler
|
| 45 | -import qualified GHC.Internal.Base as Rebindable
|
|
| 46 | 45 | import GHC.Internal.Base hiding( Type, Module )
|
| 47 | 46 | import GHC.Internal.Data.Traversable
|
| 48 | 47 | import GHC.Internal.Err (error)
|
| ... | ... | @@ -61,7 +60,9 @@ import GHC.Internal.Num |
| 61 | 60 | import GHC.Internal.IO.Unsafe
|
| 62 | 61 | import GHC.Internal.List (dropWhile, break, replicate, reverse, last)
|
| 63 | 62 | import GHC.Internal.Unicode
|
| 64 | -import qualified GHC.Internal.Generics as Rebindable hiding( prec )
|
|
| 63 | +import qualified GHC.Internal.Base as Rebindable hiding( foldr )
|
|
| 64 | +import qualified GHC.Internal.Data.Foldable as Rebindable
|
|
| 65 | +import qualified GHC.Internal.Generics as Rebindable hiding( prec )
|
|
| 65 | 66 | #endif
|
| 66 | 67 | import GHC.Internal.ForeignSrcLang
|
| 67 | 68 | import GHC.Internal.LanguageExtensions
|