Rodrigo Mesquita pushed to branch wip/spj-reinstallable-base2 at Glasgow Haskell Compiler / GHC
Commits:
-
ede44664
by Rodrigo Mesquita at 2026-05-06T14:06:59+01:00
-
61d6b31d
by Rodrigo Mesquita at 2026-05-06T14:20:35+01:00
-
6decd81e
by Rodrigo Mesquita at 2026-05-06T14:24:17+01:00
-
9dec147e
by Rodrigo Mesquita at 2026-05-06T17:29:51+01:00
7 changed files:
- compiler/GHC/Builtin/KnownKeys.hs
- compiler/GHC/Builtin/WiredIn/Types.hs
- compiler/GHC/Driver/Plugins.hs
- compiler/GHC/HsToCore/Foreign/C.hs
- compiler/GHC/Runtime/Loader.hs
- libraries/base/src/GHC/Essentials.hs
- libraries/ghc-internal/src/GHC/Internal/Ptr.hs
Changes:
| ... | ... | @@ -163,6 +163,8 @@ knownKeyRdrName key = knownOccRdrName (knownKeyOccName key) |
| 163 | 163 | This section tells what the compiler knows about the association of
|
| 164 | 164 | names with uniques. These ones are the *non* wired-in ones. The
|
| 165 | 165 | wired in ones are defined in GHC.Builtin.Types etc.
|
| 166 | + |
|
| 167 | +See Note [Overview of known entities] in GHC.Builtin
|
|
| 166 | 168 | -}
|
| 167 | 169 | |
| 168 | 170 | knownKeyTable :: [(OccName, KnownKey)]
|
| ... | ... | @@ -269,6 +271,10 @@ knownKeyTable |
| 269 | 271 | , (mkDataOcc ":$$:", typeErrorVAppendDataConKey)
|
| 270 | 272 | , (mkDataOcc "ShowType", typeErrorShowTypeDataConKey)
|
| 271 | 273 | |
| 274 | + -- Plugins
|
|
| 275 | + , (mkTcOcc "Plugin", pluginTyConKey)
|
|
| 276 | + , (mkTcOcc "FrontendPlugin", frontendPluginTyConKey)
|
|
| 277 | + |
|
| 272 | 278 | -- Base strings Strings
|
| 273 | 279 | , (mkVarOcc "unpackCString#", unpackCStringIdKey)
|
| 274 | 280 | , (mkVarOcc "unpackCStringUtf8#", unpackCStringUtf8IdKey)
|
| ... | ... | @@ -367,16 +373,9 @@ basicKnownKeyNames |
| 367 | 373 | starArrStarKindRepName,
|
| 368 | 374 | starArrStarArrStarKindRepName,
|
| 369 | 375 | constraintKindRepName,
|
| 370 | - -- FFI primitive types that are not wired-in.
|
|
| 371 | - ptrTyConName, funPtrTyConName,
|
|
| 372 | - word8TyConName,
|
|
| 373 | - |
|
| 374 | - -- Plugins
|
|
| 375 | - pluginTyConName
|
|
| 376 | - , frontendPluginTyConName
|
|
| 377 | 376 | |
| 378 | 377 | -- Unsafe coercion proofs
|
| 379 | - , unsafeCoercePrimName
|
|
| 378 | + unsafeCoercePrimName
|
|
| 380 | 379 | ]
|
| 381 | 380 | |
| 382 | 381 | |
| ... | ... | @@ -445,23 +444,6 @@ unsafeCoercePrimName = varQual gHC_INTERNAL_UNSAFE_COERCE (fsLit "unsafeCoerc |
| 445 | 444 | genericClassKeys :: [KnownKey]
|
| 446 | 445 | genericClassKeys = [genClassKey, gen1ClassKey]
|
| 447 | 446 | |
| 448 | --- Word module
|
|
| 449 | -word8TyConName :: Name
|
|
| 450 | -word8TyConName = tcQual gHC_INTERNAL_WORD (fsLit "Word8") word8TyConKey
|
|
| 451 | - |
|
| 452 | --- PrelPtr module
|
|
| 453 | -ptrTyConName, funPtrTyConName :: Name
|
|
| 454 | -ptrTyConName = tcQual gHC_INTERNAL_PTR (fsLit "Ptr") ptrTyConKey
|
|
| 455 | -funPtrTyConName = tcQual gHC_INTERNAL_PTR (fsLit "FunPtr") funPtrTyConKey
|
|
| 456 | - |
|
| 457 | --- plugins
|
|
| 458 | -pLUGINS :: Module
|
|
| 459 | -pLUGINS = mkThisGhcModule (fsLit "GHC.Driver.Plugins")
|
|
| 460 | -pluginTyConName :: Name
|
|
| 461 | -pluginTyConName = tcQual pLUGINS (fsLit "Plugin") pluginTyConKey
|
|
| 462 | -frontendPluginTyConName :: Name
|
|
| 463 | -frontendPluginTyConName = tcQual pLUGINS (fsLit "FrontendPlugin") frontendPluginTyConKey
|
|
| 464 | - |
|
| 465 | 447 | {-
|
| 466 | 448 | ************************************************************************
|
| 467 | 449 | * *
|
| ... | ... | @@ -58,7 +58,7 @@ module GHC.Builtin.WiredIn.Types ( |
| 58 | 58 | wordTyCon, wordDataCon, wordTyConName, wordTy,
|
| 59 | 59 | |
| 60 | 60 | -- * Word8
|
| 61 | - word8TyCon, word8DataCon, word8Ty,
|
|
| 61 | + word8TyCon, word8DataCon, word8TyConName, word8Ty,
|
|
| 62 | 62 | |
| 63 | 63 | -- * List
|
| 64 | 64 | listTyCon, listTyConName, listTyConKey,
|
| ... | ... | @@ -395,10 +395,11 @@ nothingDataConName = mkWiredInDataConName UserSyntax gHC_INTERNAL_MAYBE (fsLit " |
| 395 | 395 | justDataConName = mkWiredInDataConName UserSyntax gHC_INTERNAL_MAYBE (fsLit "Just")
|
| 396 | 396 | justDataConKey justDataCon
|
| 397 | 397 | |
| 398 | -wordTyConName, wordDataConName, word8DataConName :: Name
|
|
| 399 | -wordTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Word") wordTyConKey wordTyCon
|
|
| 400 | -wordDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "W#") wordDataConKey wordDataCon
|
|
| 401 | -word8DataConName = mkWiredInDataConName UserSyntax gHC_INTERNAL_WORD (fsLit "W8#") word8DataConKey word8DataCon
|
|
| 398 | +wordTyConName, wordDataConName, word8TyConName, word8DataConName :: Name
|
|
| 399 | +wordTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Word") wordTyConKey wordTyCon
|
|
| 400 | +wordDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "W#") wordDataConKey wordDataCon
|
|
| 401 | +word8TyConName = mkWiredInTyConName UserSyntax gHC_INTERNAL_WORD (fsLit "Word8") word8TyConKey word8TyCon
|
|
| 402 | +word8DataConName = mkWiredInDataConName UserSyntax gHC_INTERNAL_WORD (fsLit "W8#") word8DataConKey word8DataCon
|
|
| 402 | 403 | |
| 403 | 404 | floatTyConName, floatDataConName, doubleTyConName, doubleDataConName :: Name
|
| 404 | 405 | floatTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Float") floatTyConKey floatTyCon
|
| ... | ... | @@ -5,6 +5,12 @@ |
| 5 | 5 | {-# LANGUAGE UnboxedTuples #-}
|
| 6 | 6 | #endif
|
| 7 | 7 | |
| 8 | +#if __GLASGOW_HASKELL__ > 1000
|
|
| 9 | +{-# OPTIONS_GHC -fdefines-known-key-names #-}
|
|
| 10 | + -- 'Plugin' and 'FrontendPlugin' are known-key names
|
|
| 11 | + -- (they have a fixed known unique) (from GHC 10.2)
|
|
| 12 | + -- See Note [Overview of known entities] in GHC.Builtin
|
|
| 13 | +#endif
|
|
| 8 | 14 | |
| 9 | 15 | -- | Definitions for writing /plugins/ for GHC. Plugins can hook into
|
| 10 | 16 | -- several areas of the compiler. See the 'Plugin' type. These plugins
|
| ... | ... | @@ -365,7 +365,7 @@ toCType t = case f False t of |
| 365 | 365 | -- If the inner type is void-based, we collapse the pointer
|
| 366 | 366 | -- chain to just "void*". See Note [Collapsing void pointer chains].
|
| 367 | 367 | | Just (ptr, [t']) <- splitTyConApp_maybe t
|
| 368 | - , tyConName ptr `elem` [ptrTyConName, funPtrTyConName]
|
|
| 368 | + , tyConUnique ptr `elem` [ptrTyConKey, funPtrTyConKey]
|
|
| 369 | 369 | = case f True t' of
|
| 370 | 370 | (mh, True, _) ->
|
| 371 | 371 | (mh, True, text "void*")
|
| ... | ... | @@ -37,7 +37,7 @@ import GHC.Rename.Names ( gresFromAvails ) |
| 37 | 37 | |
| 38 | 38 | import GHC.Tc.Utils.Monad ( initTcInteractive, initIfaceTcRn )
|
| 39 | 39 | import GHC.Iface.Load ( loadPluginInterface, cannotFindModule )
|
| 40 | -import GHC.Builtin.KnownKeys ( pluginTyConName, frontendPluginTyConName )
|
|
| 40 | +import GHC.Builtin.KnownKeys ( pluginTyConKey, frontendPluginTyConKey )
|
|
| 41 | 41 | |
| 42 | 42 | import GHC.Driver.Env
|
| 43 | 43 | import GHCi.RemoteTypes ( HValue )
|
| ... | ... | @@ -47,7 +47,7 @@ import GHC.Core.TyCon ( TyCon(tyConName) ) |
| 47 | 47 | |
| 48 | 48 | |
| 49 | 49 | import GHC.Types.SrcLoc ( noSrcSpan )
|
| 50 | -import GHC.Types.Name ( Name, nameModule, nameModule_maybe )
|
|
| 50 | +import GHC.Types.Name ( Name, nameModule, nameModule_maybe, KnownKey, mkKnownKeyName, mkTcOcc )
|
|
| 51 | 51 | import GHC.Types.Id ( idType )
|
| 52 | 52 | import GHC.Types.PkgQual
|
| 53 | 53 | import GHC.Types.TyThing
|
| ... | ... | @@ -75,6 +75,7 @@ import GHC.Linker.Types |
| 75 | 75 | import Data.List (unzip4)
|
| 76 | 76 | import GHC.Iface.Errors.Ppr
|
| 77 | 77 | import GHC.Driver.Monad
|
| 78 | +import GHC.Builtin.Modules
|
|
| 78 | 79 | |
| 79 | 80 | {- Note [Timing of plugin initialization]
|
| 80 | 81 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -170,12 +171,13 @@ loadPlugins hsc_env |
| 170 | 171 | where
|
| 171 | 172 | options = [ option | (opt_mod_nm, option) <- pluginModNameOpts dflags
|
| 172 | 173 | , opt_mod_nm == mod_nm ]
|
| 174 | + pluginTyConName = mkKnownKeyGhcPluginsName (mkTcOcc "Plugin") pluginTyConKey
|
|
| 173 | 175 | loadPlugin = loadPlugin' (mkVarOccFS (fsLit "plugin")) pluginTyConName hsc_env
|
| 174 | 176 | |
| 175 | - |
|
| 176 | 177 | loadFrontendPlugin :: HscEnv -> ModuleName -> IO (FrontendPlugin, [LinkableUsage], PkgsLoaded)
|
| 177 | 178 | loadFrontendPlugin hsc_env mod_name = do
|
| 178 | 179 | checkExternalInterpreter hsc_env
|
| 180 | + let frontendPluginTyConName = mkKnownKeyGhcPluginsName (mkTcOcc "FrontendPlugin") frontendPluginTyConKey
|
|
| 179 | 181 | (plugin, _iface, links, pkgs)
|
| 180 | 182 | <- loadPlugin' (mkVarOccFS (fsLit "frontendPlugin")) frontendPluginTyConName
|
| 181 | 183 | hsc_env mod_name
|
| ... | ... | @@ -188,6 +190,10 @@ checkExternalInterpreter hsc_env = case interpInstance <$> hsc_interp hsc_env of |
| 188 | 190 | -> throwIO (InstallationError "Plugins require -fno-external-interpreter")
|
| 189 | 191 | _ -> pure ()
|
| 190 | 192 | |
| 193 | +mkKnownKeyGhcPluginsName :: OccName -> KnownKey -> Name
|
|
| 194 | +mkKnownKeyGhcPluginsName occ kk =
|
|
| 195 | + mkKnownKeyName kk (mkThisGhcModule (fsLit "GHC.Driver.Plugins")) occ noSrcSpan
|
|
| 196 | + |
|
| 191 | 197 | loadPlugin' :: OccName -> Name -> HscEnv -> ModuleName -> IO (a, ModIface, [LinkableUsage], PkgsLoaded)
|
| 192 | 198 | loadPlugin' occ_name plugin_name hsc_env mod_name
|
| 193 | 199 | = do { let plugin_rdr_name = mkRdrQual mod_name occ_name
|
| ... | ... | @@ -76,6 +76,7 @@ module GHC.Essentials |
| 76 | 76 | , Void
|
| 77 | 77 | |
| 78 | 78 | -- FFI
|
| 79 | + , Ptr, FunPtr
|
|
| 79 | 80 | , ConstPtr
|
| 80 | 81 | |
| 81 | 82 | -- Show internals
|
| ... | ... | @@ -302,6 +303,7 @@ import GHC.Internal.GHCi |
| 302 | 303 | import GHC.Internal.Desugar (toAnnotationWrapper)
|
| 303 | 304 | import GHC.Internal.Stack.Types
|
| 304 | 305 | import GHC.Internal.Exception.Context
|
| 306 | +import GHC.Internal.Ptr
|
|
| 305 | 307 | import GHC.Internal.Foreign.C.ConstPtr
|
| 306 | 308 | #if defined(javascript_HOST_ARCH)
|
| 307 | 309 | import GHC.Internal.JS.Prim (unsafeUnpackJSStringUtf8##)
|
| ... | ... | @@ -2,6 +2,7 @@ |
| 2 | 2 | {-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, RoleAnnotations #-}
|
| 3 | 3 | {-# LANGUAGE UnboxedTuples #-}
|
| 4 | 4 | {-# OPTIONS_HADDOCK not-home #-}
|
| 5 | +{-# OPTIONS_GHC -fdefines-known-key-names #-}
|
|
| 5 | 6 | |
| 6 | 7 | -----------------------------------------------------------------------------
|
| 7 | 8 | -- |
|