Simon Peyton Jones pushed to branch wip/spj-reinstallable-base at Glasgow Haskell Compiler / GHC
Commits:
-
d5e3ac97
by Simon Peyton Jones at 2026-04-07T17:33:40+01:00
13 changed files:
- compiler/GHC/Builtin.hs
- compiler/GHC/Builtin/Names.hs
- compiler/GHC/Builtin/RdrNames.hs
- compiler/GHC/Builtin/Names/TH.hs → compiler/GHC/Builtin/TH.hs
- compiler/GHC/HsToCore/Quote.hs
- compiler/GHC/Iface/Errors/Ppr.hs
- compiler/GHC/Rename/Splice.hs
- compiler/GHC/Tc/Deriv/Generate.hs
- compiler/GHC/Tc/Deriv/Utils.hs
- compiler/GHC/Tc/Gen/Splice.hs
- compiler/ghc.cabal.in
- libraries/base/src/GHC/KnownKeyNames.hs
- libraries/ghc-internal/src/GHC/Internal/Base.hs
Changes:
| ... | ... | @@ -21,7 +21,8 @@ |
| 21 | 21 | module GHC.Builtin (
|
| 22 | 22 | -- * Main exports
|
| 23 | 23 | wiredInNames, wiredInIds, ghcPrimIds,
|
| 24 | - knownKeyTable, knownKeyOccMap, knownKeyUniqMap, knownKeyOccName,
|
|
| 24 | + knownKeyTable, knownKeyOccMap, knownKeyUniqMap,
|
|
| 25 | + knownKeyOccName, knownKeyOccName_maybe,
|
|
| 25 | 26 | knownKeyRdrName, knownOccRdrName, knownVarOccRdrName,
|
| 26 | 27 | |
| 27 | 28 | -- * Known-key names
|
| ... | ... | @@ -51,7 +52,7 @@ import GHC.Builtin.PrimOps.Ids |
| 51 | 52 | import GHC.Builtin.Types
|
| 52 | 53 | import GHC.Builtin.Types.Literals ( typeNatTyCons )
|
| 53 | 54 | import GHC.Builtin.Types.Prim
|
| 54 | -import GHC.Builtin.Names.TH ( templateHaskellNames, thKnownKeyTable )
|
|
| 55 | +import GHC.Builtin.TH ( templateHaskellNames, thKnownKeyTable )
|
|
| 55 | 56 | import GHC.Builtin.Names( basicKnownKeyTable, basicKnownKeyNames )
|
| 56 | 57 | import GHC.Builtin.Names( charDataConKey, intDataConKey, numericClassKeys, standardClassKeys )
|
| 57 | 58 | |
| ... | ... | @@ -84,6 +85,7 @@ import GHC.Unit.Module.ModIface (IfaceExport) |
| 84 | 85 | import GHC.Unit.Module.Warnings
|
| 85 | 86 | |
| 86 | 87 | import GHC.Data.List.SetOps
|
| 88 | +import GHC.Data.Maybe( orElse )
|
|
| 87 | 89 | |
| 88 | 90 | import Control.Applicative ((<|>))
|
| 89 | 91 | import Data.Maybe
|
| ... | ... | @@ -351,10 +353,14 @@ knownKeyTable = basicKnownKeyTable ++ |
| 351 | 353 | knownKeyOccName :: HasDebugCallStack => KnownKey -> OccName
|
| 352 | 354 | -- Find the OccName from the KnownKey,
|
| 353 | 355 | -- by looking in the knownKeyUniqMap
|
| 354 | -knownKeyOccName std_uniq
|
|
| 355 | - = case lookupUFM knownKeyUniqMap std_uniq of
|
|
| 356 | - Just occ -> occ
|
|
| 357 | - Nothing -> pprPanic "knownKeyOccName" (pprKnownKey std_uniq)
|
|
| 356 | +knownKeyOccName key
|
|
| 357 | + = knownKeyOccName_maybe key `orElse`
|
|
| 358 | + pprPanic "knownKeyOccName" (pprKnownKey key)
|
|
| 359 | + |
|
| 360 | +knownKeyOccName_maybe :: HasDebugCallStack
|
|
| 361 | + => KnownKey -> Maybe OccName
|
|
| 362 | +knownKeyOccName_maybe key
|
|
| 363 | + = lookupUFM knownKeyUniqMap key
|
|
| 358 | 364 | |
| 359 | 365 | knownKeyRdrName :: KnownKey -> RdrName
|
| 360 | 366 | knownKeyRdrName key = knownOccRdrName (knownKeyOccName key)
|
| ... | ... | @@ -1261,7 +1261,7 @@ hasFieldClassKey = mkPreludeClassUnique 50 |
| 1261 | 1261 | |
| 1262 | 1262 | |
| 1263 | 1263 | ---------------- Template Haskell -------------------
|
| 1264 | --- GHC.Builtin.Names.TH: USES ClassUniques 200-299
|
|
| 1264 | +-- GHC.Builtin.TH: USES ClassUniques 200-299
|
|
| 1265 | 1265 | -----------------------------------------------------
|
| 1266 | 1266 | |
| 1267 | 1267 | {-
|
| ... | ... | @@ -1507,7 +1507,7 @@ multMulTyConKey :: KnownKey |
| 1507 | 1507 | multMulTyConKey = mkPreludeTyConUnique 199
|
| 1508 | 1508 | |
| 1509 | 1509 | ---------------- Template Haskell -------------------
|
| 1510 | --- GHC.Builtin.Names.TH: USES TyConUniques 200-299
|
|
| 1510 | +-- GHC.Builtin.TH: USES TyConUniques 200-299
|
|
| 1511 | 1511 | -----------------------------------------------------
|
| 1512 | 1512 | |
| 1513 | 1513 | ----------------------- SIMD ------------------------
|
| ... | ... | @@ -1734,7 +1734,7 @@ naturalNBDataConKey = mkPreludeDataConUnique 124 |
| 1734 | 1734 | |
| 1735 | 1735 | |
| 1736 | 1736 | ---------------- Template Haskell -------------------
|
| 1737 | --- GHC.Builtin.Names.TH: USES DataUniques 200-250
|
|
| 1737 | +-- GHC.Builtin.TH: USES DataUniques 200-250
|
|
| 1738 | 1738 | -----------------------------------------------------
|
| 1739 | 1739 | |
| 1740 | 1740 | |
| ... | ... | @@ -1943,7 +1943,7 @@ proxyHashKey :: KnownKey |
| 1943 | 1943 | proxyHashKey = mkPreludeMiscIdUnique 502
|
| 1944 | 1944 | |
| 1945 | 1945 | ---------------- Template Haskell -------------------
|
| 1946 | --- GHC.Builtin.Names.TH: USES IdUniques 200-499
|
|
| 1946 | +-- GHC.Builtin.TH: USES IdUniques 200-499
|
|
| 1947 | 1947 | -----------------------------------------------------
|
| 1948 | 1948 | |
| 1949 | 1949 | -- Used to make `Typeable` dictionaries
|
| ... | ... | @@ -18,7 +18,7 @@ import GHC.Builtin |
| 18 | 18 | import GHC.Builtin.PrimOps
|
| 19 | 19 | import GHC.Builtin.Types -- A bunch of wired-in TyCons and DataCons
|
| 20 | 20 | import GHC.Builtin.PrimOps.Ids (primOpId)
|
| 21 | -import GHC.Builtin.Names.TH( unsafeCodeCoerceName, liftTypedName )
|
|
| 21 | +import GHC.Builtin.TH( unsafeCodeCoerceName, liftTypedName )
|
|
| 22 | 22 | import GHC.Builtin.Names
|
| 23 | 23 | |
| 24 | 24 | import GHC.Types.Name.Reader( RdrName, mkVarUnqual, getRdrName
|
| ... | ... | @@ -4,7 +4,7 @@ |
| 4 | 4 | -- %* *
|
| 5 | 5 | -- %************************************************************************
|
| 6 | 6 | |
| 7 | -module GHC.Builtin.Names.TH where
|
|
| 7 | +module GHC.Builtin.TH where
|
|
| 8 | 8 | |
| 9 | 9 | import GHC.Prelude ()
|
| 10 | 10 |
| ... | ... | @@ -53,7 +53,7 @@ import GHC.Core.Make |
| 53 | 53 | import GHC.Core.Utils
|
| 54 | 54 | |
| 55 | 55 | import GHC.Builtin.Names
|
| 56 | -import GHC.Builtin.Names.TH
|
|
| 56 | +import GHC.Builtin.TH
|
|
| 57 | 57 | import GHC.Builtin.Types
|
| 58 | 58 | import GHC.Builtin.Types.Prim
|
| 59 | 59 |
| ... | ... | @@ -24,6 +24,7 @@ module GHC.Iface.Errors.Ppr |
| 24 | 24 | |
| 25 | 25 | import GHC.Prelude
|
| 26 | 26 | |
| 27 | +import GHC.Builtin( knownKeyOccName_maybe )
|
|
| 27 | 28 | import GHC.Types.Error
|
| 28 | 29 | import GHC.Types.Hint.Ppr () -- Outputable GhcHint
|
| 29 | 30 | import GHC.Types.Error.Codes
|
| ... | ... | @@ -295,12 +296,20 @@ interfaceErrorDiagnostic opts = \ case |
| 295 | 296 | CircularImport mod ->
|
| 296 | 297 | text "Circular imports: module" <+> quotes (ppr mod)
|
| 297 | 298 | <+> text "depends on itself"
|
| 299 | + |
|
| 298 | 300 | MissingKnownKey1 key -> hang (text "Could not find known key" <+> quotes (pprKnownKey key))
|
| 299 | - 2 (text "in the exports of GHC.KnownKeys")
|
|
| 301 | + 2 (vcat [ text "in the exports of GHC.KnownKeys"
|
|
| 302 | + , text "occname:" <+> pp_occ (knownKeyOccName_maybe key) ])
|
|
| 303 | + where
|
|
| 304 | + pp_occ (Just occ) = ppr occ
|
|
| 305 | + pp_occ Nothing = text "Yikes: that key isn't in the known-key table"
|
|
| 306 | + |
|
| 300 | 307 | MissingKnownKey2 key -> hang (text "Could not find known key" <+> quotes (pprKnownKey key))
|
| 301 | 308 | 2 (text "in the static known-key table")
|
| 309 | + |
|
| 302 | 310 | MissingKnownKey3 occ -> hang (text "Could not find known occurrence" <+> quotes (ppr occ))
|
| 303 | 311 | 2 (text "in the exports of GHC.KnownKeys")
|
| 312 | + |
|
| 304 | 313 | KnownKeyScopeError occ gres
|
| 305 | 314 | | null gres
|
| 306 | 315 | -> hang (text "Could not find known-key entity" <+> quotes (ppr occ))
|
| ... | ... | @@ -51,7 +51,7 @@ import GHC.Data.FastString |
| 51 | 51 | import GHC.Utils.Logger
|
| 52 | 52 | import GHC.Utils.Panic
|
| 53 | 53 | import GHC.Driver.Hooks
|
| 54 | -import GHC.Builtin.Names.TH
|
|
| 54 | +import GHC.Builtin.TH
|
|
| 55 | 55 | |
| 56 | 56 | import {-# SOURCE #-} GHC.Tc.Gen.Expr ( tcCheckPolyExpr )
|
| 57 | 57 | import {-# SOURCE #-} GHC.Tc.Gen.Splice
|
| ... | ... | @@ -73,7 +73,7 @@ import GHC.Types.Var.Set |
| 73 | 73 | |
| 74 | 74 | import GHC.Builtin.Names
|
| 75 | 75 | import GHC.Builtin.RdrNames
|
| 76 | -import GHC.Builtin.Names.TH
|
|
| 76 | +import GHC.Builtin.TH
|
|
| 77 | 77 | import GHC.Builtin.Types.Prim
|
| 78 | 78 | import GHC.Builtin.Types
|
| 79 | 79 |
| ... | ... | @@ -66,7 +66,7 @@ import GHC.Types.SrcLoc |
| 66 | 66 | import GHC.Types.Var.Set
|
| 67 | 67 | |
| 68 | 68 | import GHC.Builtin.Names
|
| 69 | -import GHC.Builtin.Names.TH (liftClassKey)
|
|
| 69 | +import GHC.Builtin.TH (liftClassKey)
|
|
| 70 | 70 | |
| 71 | 71 | import GHC.Utils.Misc
|
| 72 | 72 | import GHC.Utils.Outputable
|
| ... | ... | @@ -68,7 +68,7 @@ import GHC.Core.TyCo.Rep as TyCoRep |
| 68 | 68 | import GHC.Core.FamInstEnv
|
| 69 | 69 | import GHC.Core.InstEnv as InstEnv
|
| 70 | 70 | |
| 71 | -import GHC.Builtin.Names.TH
|
|
| 71 | +import GHC.Builtin.TH
|
|
| 72 | 72 | import GHC.Builtin.Names
|
| 73 | 73 | import GHC.Builtin.Types
|
| 74 | 74 | |
| ... | ... | @@ -864,7 +864,7 @@ tcUntypedSplice q splice_name (XUntypedSplice ils) |
| 864 | 864 | -- lift :: Quote m' => a -> m' Exp
|
| 865 | 865 | ; lift <- setSrcSpan (getLocA id_name) $
|
| 866 | 866 | newKnownOccMethod (ImplicitLiftOrigin ils)
|
| 867 | - GHC.Builtin.Names.TH.liftIdOcc
|
|
| 867 | + GHC.Builtin.TH.liftIdOcc
|
|
| 868 | 868 | [getRuntimeRep id_ty, id_ty]
|
| 869 | 869 | ; let res = nlHsApp (mkLHsWrap (applyQuoteWrapper q) (noLocA lift)) v_expr'
|
| 870 | 870 | |
| ... | ... | @@ -890,7 +890,7 @@ tcPendingSpliceTyped q splice_name (XTypedSplice ils) res_ty |
| 890 | 890 | -- lift :: Quote m' => a -> m' Exp
|
| 891 | 891 | ; lift <- setSrcSpan (getLocA id_name) $
|
| 892 | 892 | newKnownOccMethod (ImplicitLiftOrigin ils)
|
| 893 | - GHC.Builtin.Names.TH.liftIdOcc
|
|
| 893 | + GHC.Builtin.TH.liftIdOcc
|
|
| 894 | 894 | [rep, res_ty]
|
| 895 | 895 | ; let res = nlHsApp (mkLHsWrap (applyQuoteWrapper q) (noLocA lift)) v_expr'
|
| 896 | 896 | ; return (PendingTcSplice splice_name res) }
|
| ... | ... | @@ -3108,7 +3108,7 @@ tcGetInterp = do |
| 3108 | 3108 | -- Note [Hard-wiring in-tree template-haskell for desugaring quotes]
|
| 3109 | 3109 | -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 3110 | 3110 | -- To desugar Template Haskell quotes, GHC needs to wire in a bunch of Names in the
|
| 3111 | --- `ghc-internal` library as Note [Known-key names], in GHC.Builtin.Names.TH.
|
|
| 3111 | +-- `ghc-internal` library as Note [Known-key names], in GHC.Builtin.TH.
|
|
| 3112 | 3112 | -- Consider
|
| 3113 | 3113 | -- > foo :: Q Exp
|
| 3114 | 3114 | -- > foo = [| unwords ["hello", "world"] |]
|
| ... | ... | @@ -201,11 +201,11 @@ Library |
| 201 | 201 | GHC
|
| 202 | 202 | GHC.Builtin
|
| 203 | 203 | GHC.Builtin.Names
|
| 204 | - GHC.Builtin.Names.TH
|
|
| 205 | 204 | GHC.Builtin.PrimOps
|
| 206 | 205 | GHC.Builtin.PrimOps.Casts
|
| 207 | 206 | GHC.Builtin.PrimOps.Ids
|
| 208 | 207 | GHC.Builtin.RdrNames
|
| 208 | + GHC.Builtin.TH
|
|
| 209 | 209 | GHC.Builtin.Types
|
| 210 | 210 | GHC.Builtin.Types.Literals
|
| 211 | 211 | GHC.Builtin.Types.Prim
|
| ... | ... | @@ -81,7 +81,7 @@ module GHC.KnownKeyNames |
| 81 | 81 | , arr, (>>>), first, app, (|||), loop
|
| 82 | 82 | |
| 83 | 83 | -- IO
|
| 84 | - , thenIO, bindIO, returnIO, print
|
|
| 84 | + , IO, thenIO, bindIO, returnIO, print
|
|
| 85 | 85 | |
| 86 | 86 | -- Unsatisfiable
|
| 87 | 87 | , Unsatisfiable, unsatisfiable
|
| ... | ... | @@ -112,8 +112,11 @@ module GHC.KnownKeyNames |
| 112 | 112 | , integerComplement, integerBit#, integerTestBit#, integerShiftL#, integerShiftR#
|
| 113 | 113 | |
| 114 | 114 | -- Template Haskell
|
| 115 | - , Q, Name, FieldExp, Decs, TH.Type, FunDep
|
|
| 115 | + , Q, DecsQ, ExpQ, TypeQ, PatQ
|
|
| 116 | + , Name, Decs, TH.Type, FunDep
|
|
| 116 | 117 | , Pred, Code, InjectivityAnn, Overlap, ModName, QuasiQuoter
|
| 118 | + , Stmt, Con, BangType, VarBangType, RuleBndr, TySynEqn, Role, DerivClause
|
|
| 119 | + , Kind, TyVarBndrUnit, TyVarBndrSpec, TyVarBndrVis, DerivStrategy
|
|
| 117 | 120 | , sequenceQ, newName, mkName, mkNameG_v, mkNameG_d, mkNameG_tc, mkNameG_fld, mkNameL
|
| 118 | 121 | , mkNameQ, mkNameS, mkModName, unType, unTypeCode, unsafeCodeCoerce
|
| 119 | 122 | , lift, liftString, liftTyped
|
| ... | ... | @@ -453,7 +453,7 @@ W6: |
| 453 | 453 | in GHC.HsToCore.Foreign.Wasm.
|
| 454 | 454 | |
| 455 | 455 | A complete list could probably be made by going through the known-key
|
| 456 | -names in GHC.Builtin.Names and GHC.Builtin.Names.TH. To test whether
|
|
| 456 | +names in GHC.Builtin.Names and GHC.Builtin.TH. To test whether
|
|
| 457 | 457 | the transitive imports are sufficient for any single module, instruct
|
| 458 | 458 | the build system to build /only/ that module in stage 2. For example,
|
| 459 | 459 | a command to check whether the transitive imports for GHC.Internal.Maybe
|