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 Document in commit message cycle with unpack - GHC.Internal.CString defines a known-key name unpackCString# (unpackCStringIdKey) - IIUC, this known-key is looked up essentially for all modules, as long as there’s some literal string in it (coreStringLit uses unpackCStringIdKey) - GHC.Internal.Types has literal strings, so it needs to lookup unpackCString. It fails with this error: libraries/ghc-internal/src/GHC/Internal/Types.hs:653:1: error: [GHC-99040] • Could not find known-key entity ‘unpackCString#’ in the top-level environment (unqualified, or qualified as Rebindable) Consider importing it Call stack: lookupKnownGRE, called at compiler/GHC/Iface/Load.hs:196:10 in ghc-10.1-inplace:GHC.Iface.Load […] tcLookupKnownKeyId, called at compiler/GHC/Tc/Solver/Monad.hs:1192:36 in ghc-10.1-inplace:GHC.Tc.Solver.Monad • In the kind ‘k’ In the class declaration for ‘Coercible’ | 653 | class Coercible (a :: k) (b :: k) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - This makes sense, unpackCString must be in scope (this is GHC.Internal.Types, i.e. ghc-internal, i.e. compiled with -frebindable-known-names) - For GHC.Internal.Types, unpackCString is looked up to later construct a string expression in `evCallStack` - Thus, GHC.Internal.Types MUST import unpackCString from GHC.Internal.String - BUT! GHC.Internal.CString imports GHC.Internal.Types… - - - - - 61d6b31d by Rodrigo Mesquita at 2026-05-06T14:20:35+01:00 ptrTyConName, funPtrTyConName - - - - - 6decd81e by Rodrigo Mesquita at 2026-05-06T14:24:17+01:00 word8TyConName is wired in - - - - - 9dec147e by Rodrigo Mesquita at 2026-05-06T17:29:51+01:00 pluginTyConName, frontendPluginTyConName - - - - - 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: ===================================== compiler/GHC/Builtin/KnownKeys.hs ===================================== @@ -163,6 +163,8 @@ knownKeyRdrName key = knownOccRdrName (knownKeyOccName key) This section tells what the compiler knows about the association of names with uniques. These ones are the *non* wired-in ones. The wired in ones are defined in GHC.Builtin.Types etc. + +See Note [Overview of known entities] in GHC.Builtin -} knownKeyTable :: [(OccName, KnownKey)] @@ -269,6 +271,10 @@ knownKeyTable , (mkDataOcc ":$$:", typeErrorVAppendDataConKey) , (mkDataOcc "ShowType", typeErrorShowTypeDataConKey) + -- Plugins + , (mkTcOcc "Plugin", pluginTyConKey) + , (mkTcOcc "FrontendPlugin", frontendPluginTyConKey) + -- Base strings Strings , (mkVarOcc "unpackCString#", unpackCStringIdKey) , (mkVarOcc "unpackCStringUtf8#", unpackCStringUtf8IdKey) @@ -367,16 +373,9 @@ basicKnownKeyNames starArrStarKindRepName, starArrStarArrStarKindRepName, constraintKindRepName, - -- FFI primitive types that are not wired-in. - ptrTyConName, funPtrTyConName, - word8TyConName, - - -- Plugins - pluginTyConName - , frontendPluginTyConName -- Unsafe coercion proofs - , unsafeCoercePrimName + unsafeCoercePrimName ] @@ -445,23 +444,6 @@ unsafeCoercePrimName = varQual gHC_INTERNAL_UNSAFE_COERCE (fsLit "unsafeCoerc genericClassKeys :: [KnownKey] genericClassKeys = [genClassKey, gen1ClassKey] --- Word module -word8TyConName :: Name -word8TyConName = tcQual gHC_INTERNAL_WORD (fsLit "Word8") word8TyConKey - --- PrelPtr module -ptrTyConName, funPtrTyConName :: Name -ptrTyConName = tcQual gHC_INTERNAL_PTR (fsLit "Ptr") ptrTyConKey -funPtrTyConName = tcQual gHC_INTERNAL_PTR (fsLit "FunPtr") funPtrTyConKey - --- plugins -pLUGINS :: Module -pLUGINS = mkThisGhcModule (fsLit "GHC.Driver.Plugins") -pluginTyConName :: Name -pluginTyConName = tcQual pLUGINS (fsLit "Plugin") pluginTyConKey -frontendPluginTyConName :: Name -frontendPluginTyConName = tcQual pLUGINS (fsLit "FrontendPlugin") frontendPluginTyConKey - {- ************************************************************************ * * ===================================== compiler/GHC/Builtin/WiredIn/Types.hs ===================================== @@ -58,7 +58,7 @@ module GHC.Builtin.WiredIn.Types ( wordTyCon, wordDataCon, wordTyConName, wordTy, -- * Word8 - word8TyCon, word8DataCon, word8Ty, + word8TyCon, word8DataCon, word8TyConName, word8Ty, -- * List listTyCon, listTyConName, listTyConKey, @@ -395,10 +395,11 @@ nothingDataConName = mkWiredInDataConName UserSyntax gHC_INTERNAL_MAYBE (fsLit " justDataConName = mkWiredInDataConName UserSyntax gHC_INTERNAL_MAYBE (fsLit "Just") justDataConKey justDataCon -wordTyConName, wordDataConName, word8DataConName :: Name -wordTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Word") wordTyConKey wordTyCon -wordDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "W#") wordDataConKey wordDataCon -word8DataConName = mkWiredInDataConName UserSyntax gHC_INTERNAL_WORD (fsLit "W8#") word8DataConKey word8DataCon +wordTyConName, wordDataConName, word8TyConName, word8DataConName :: Name +wordTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Word") wordTyConKey wordTyCon +wordDataConName = mkWiredInDataConName UserSyntax gHC_TYPES (fsLit "W#") wordDataConKey wordDataCon +word8TyConName = mkWiredInTyConName UserSyntax gHC_INTERNAL_WORD (fsLit "Word8") word8TyConKey word8TyCon +word8DataConName = mkWiredInDataConName UserSyntax gHC_INTERNAL_WORD (fsLit "W8#") word8DataConKey word8DataCon floatTyConName, floatDataConName, doubleTyConName, doubleDataConName :: Name floatTyConName = mkWiredInTyConName UserSyntax gHC_TYPES (fsLit "Float") floatTyConKey floatTyCon ===================================== compiler/GHC/Driver/Plugins.hs ===================================== @@ -5,6 +5,12 @@ {-# LANGUAGE UnboxedTuples #-} #endif +#if __GLASGOW_HASKELL__ > 1000 +{-# OPTIONS_GHC -fdefines-known-key-names #-} + -- 'Plugin' and 'FrontendPlugin' are known-key names + -- (they have a fixed known unique) (from GHC 10.2) + -- See Note [Overview of known entities] in GHC.Builtin +#endif -- | Definitions for writing /plugins/ for GHC. Plugins can hook into -- several areas of the compiler. See the 'Plugin' type. These plugins ===================================== compiler/GHC/HsToCore/Foreign/C.hs ===================================== @@ -365,7 +365,7 @@ toCType t = case f False t of -- If the inner type is void-based, we collapse the pointer -- chain to just "void*". See Note [Collapsing void pointer chains]. | Just (ptr, [t']) <- splitTyConApp_maybe t - , tyConName ptr `elem` [ptrTyConName, funPtrTyConName] + , tyConUnique ptr `elem` [ptrTyConKey, funPtrTyConKey] = case f True t' of (mh, True, _) -> (mh, True, text "void*") ===================================== compiler/GHC/Runtime/Loader.hs ===================================== @@ -37,7 +37,7 @@ import GHC.Rename.Names ( gresFromAvails ) import GHC.Tc.Utils.Monad ( initTcInteractive, initIfaceTcRn ) import GHC.Iface.Load ( loadPluginInterface, cannotFindModule ) -import GHC.Builtin.KnownKeys ( pluginTyConName, frontendPluginTyConName ) +import GHC.Builtin.KnownKeys ( pluginTyConKey, frontendPluginTyConKey ) import GHC.Driver.Env import GHCi.RemoteTypes ( HValue ) @@ -47,7 +47,7 @@ import GHC.Core.TyCon ( TyCon(tyConName) ) import GHC.Types.SrcLoc ( noSrcSpan ) -import GHC.Types.Name ( Name, nameModule, nameModule_maybe ) +import GHC.Types.Name ( Name, nameModule, nameModule_maybe, KnownKey, mkKnownKeyName, mkTcOcc ) import GHC.Types.Id ( idType ) import GHC.Types.PkgQual import GHC.Types.TyThing @@ -75,6 +75,7 @@ import GHC.Linker.Types import Data.List (unzip4) import GHC.Iface.Errors.Ppr import GHC.Driver.Monad +import GHC.Builtin.Modules {- Note [Timing of plugin initialization] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -170,12 +171,13 @@ loadPlugins hsc_env where options = [ option | (opt_mod_nm, option) <- pluginModNameOpts dflags , opt_mod_nm == mod_nm ] + pluginTyConName = mkKnownKeyGhcPluginsName (mkTcOcc "Plugin") pluginTyConKey loadPlugin = loadPlugin' (mkVarOccFS (fsLit "plugin")) pluginTyConName hsc_env - loadFrontendPlugin :: HscEnv -> ModuleName -> IO (FrontendPlugin, [LinkableUsage], PkgsLoaded) loadFrontendPlugin hsc_env mod_name = do checkExternalInterpreter hsc_env + let frontendPluginTyConName = mkKnownKeyGhcPluginsName (mkTcOcc "FrontendPlugin") frontendPluginTyConKey (plugin, _iface, links, pkgs) <- loadPlugin' (mkVarOccFS (fsLit "frontendPlugin")) frontendPluginTyConName hsc_env mod_name @@ -188,6 +190,10 @@ checkExternalInterpreter hsc_env = case interpInstance <$> hsc_interp hsc_env of -> throwIO (InstallationError "Plugins require -fno-external-interpreter") _ -> pure () +mkKnownKeyGhcPluginsName :: OccName -> KnownKey -> Name +mkKnownKeyGhcPluginsName occ kk = + mkKnownKeyName kk (mkThisGhcModule (fsLit "GHC.Driver.Plugins")) occ noSrcSpan + loadPlugin' :: OccName -> Name -> HscEnv -> ModuleName -> IO (a, ModIface, [LinkableUsage], PkgsLoaded) loadPlugin' occ_name plugin_name hsc_env mod_name = do { let plugin_rdr_name = mkRdrQual mod_name occ_name ===================================== libraries/base/src/GHC/Essentials.hs ===================================== @@ -76,6 +76,7 @@ module GHC.Essentials , Void -- FFI + , Ptr, FunPtr , ConstPtr -- Show internals @@ -302,6 +303,7 @@ import GHC.Internal.GHCi import GHC.Internal.Desugar (toAnnotationWrapper) import GHC.Internal.Stack.Types import GHC.Internal.Exception.Context +import GHC.Internal.Ptr import GHC.Internal.Foreign.C.ConstPtr #if defined(javascript_HOST_ARCH) import GHC.Internal.JS.Prim (unsafeUnpackJSStringUtf8##) ===================================== libraries/ghc-internal/src/GHC/Internal/Ptr.hs ===================================== @@ -2,6 +2,7 @@ {-# LANGUAGE CPP, NoImplicitPrelude, MagicHash, RoleAnnotations #-} {-# LANGUAGE UnboxedTuples #-} {-# OPTIONS_HADDOCK not-home #-} +{-# OPTIONS_GHC -fdefines-known-key-names #-} ----------------------------------------------------------------------------- -- | View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/64ed2f412343e5cdc5c0694b79f61eb... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/64ed2f412343e5cdc5c0694b79f61eb... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Rodrigo Mesquita (@alt-romes)