[Git][ghc/ghc][wip/spj-reinstallable-base2] 5 commits: misc fixes
Rodrigo Mesquita pushed to branch wip/spj-reinstallable-base2 at Glasgow Haskell Compiler / GHC Commits: c4f835f9 by Rodrigo Mesquita at 2026-05-06T11:35:55+01:00 misc fixes - - - - - 59c56053 by Rodrigo Mesquita at 2026-05-06T11:56:04+01:00 Undo 72c0e07869a4652399e669e529f1bfd456522ee0 Now KnownKey names like the ones we cared about for this previous fix must be compared explicitly by construction because we no longer have a Name! - - - - - 38033e26 by Rodrigo Mesquita at 2026-05-06T11:56:32+01:00 int8TyConName, int16TyConName, int32TyConName, int64TyConName - - - - - 5604ce26 by Rodrigo Mesquita at 2026-05-06T12:07:06+01:00 word16TyConName, word32TyConName, word64TyConName - - - - - db33d608 by Rodrigo Mesquita at 2026-05-06T12:11:31+01:00 constPtrConName - - - - - 7 changed files: - compiler/GHC/Builtin/KnownKeys.hs - compiler/GHC/Builtin/KnownOccs.hs - compiler/GHC/HsToCore/Foreign/C.hs - compiler/GHC/HsToCore/Match/Literal.hs - compiler/GHC/Types/Name.hs - libraries/base/src/GHC/Essentials.hs - libraries/ghc-internal/src/GHC/Internal/Foreign/C/ConstPtr.hs Changes: ===================================== compiler/GHC/Builtin/KnownKeys.hs ===================================== @@ -200,6 +200,9 @@ knownKeyTable , (mkVarOcc "toRational", toRationalClassOpKey) , (mkVarOcc "realToFrac", realToFracIdKey) + -- FFI things + , (mkTcOcc "ConstPtr", constPtrTyConKey) + -- Class Monad, MonadFix, MonadZip , (mkTcOcc "Monad", monadClassKey) , (thenMClassOpOcc, thenMClassOpKey) @@ -365,9 +368,8 @@ basicKnownKeyNames starArrStarArrStarKindRepName, constraintKindRepName, -- FFI primitive types that are not wired-in. - ptrTyConName, funPtrTyConName, constPtrConName, - int8TyConName, int16TyConName, int32TyConName, int64TyConName, - word8TyConName, word16TyConName, word32TyConName, word64TyConName, + ptrTyConName, funPtrTyConName, + word8TyConName, -- Plugins pluginTyConName @@ -443,19 +445,9 @@ unsafeCoercePrimName = varQual gHC_INTERNAL_UNSAFE_COERCE (fsLit "unsafeCoerc genericClassKeys :: [KnownKey] genericClassKeys = [genClassKey, gen1ClassKey] --- Int, Word, and Addr things -int8TyConName, int16TyConName, int32TyConName, int64TyConName :: Name -int8TyConName = tcQual gHC_INTERNAL_INT (fsLit "Int8") int8TyConKey -int16TyConName = tcQual gHC_INTERNAL_INT (fsLit "Int16") int16TyConKey -int32TyConName = tcQual gHC_INTERNAL_INT (fsLit "Int32") int32TyConKey -int64TyConName = tcQual gHC_INTERNAL_INT (fsLit "Int64") int64TyConKey - -- Word module -word8TyConName, word16TyConName, word32TyConName, word64TyConName :: Name -word8TyConName = tcQual gHC_INTERNAL_WORD (fsLit "Word8") word8TyConKey -word16TyConName = tcQual gHC_INTERNAL_WORD (fsLit "Word16") word16TyConKey -word32TyConName = tcQual gHC_INTERNAL_WORD (fsLit "Word32") word32TyConKey -word64TyConName = tcQual gHC_INTERNAL_WORD (fsLit "Word64") word64TyConKey +word8TyConName :: Name +word8TyConName = tcQual gHC_INTERNAL_WORD (fsLit "Word8") word8TyConKey -- PrelPtr module ptrTyConName, funPtrTyConName :: Name @@ -470,11 +462,6 @@ pluginTyConName = tcQual pLUGINS (fsLit "Plugin") pluginTyConKey frontendPluginTyConName :: Name frontendPluginTyConName = tcQual pLUGINS (fsLit "FrontendPlugin") frontendPluginTyConKey -constPtrConName :: Name -constPtrConName = - tcQual gHC_INTERNAL_FOREIGN_C_CONSTPTR (fsLit "ConstPtr") constPtrTyConKey - - {- ************************************************************************ * * ===================================== compiler/GHC/Builtin/KnownOccs.hs ===================================== @@ -204,9 +204,8 @@ fromStaticPtrClassOpOcc, newStablePtrIdOcc :: KnownOcc fromStaticPtrClassOpOcc = mkVarOcc "fromStaticPtr" newStablePtrIdOcc = mkVarOcc "newStablePtr" -staticPtrTyConOcc, staticPtrDataConOcc, staticPtrInfoDataConOcc :: KnownOcc +staticPtrTyConOcc, staticPtrInfoDataConOcc :: KnownOcc staticPtrTyConOcc = mkTcOcc "StaticPtr" -staticPtrDataConOcc = mkDataOcc "StaticPtr" staticPtrInfoDataConOcc = mkDataOcc "StaticPtrInfo" knownNatClassOcc, knownSymbolClassOcc, knownCharClassOcc :: KnownOcc ===================================== compiler/GHC/HsToCore/Foreign/C.hs ===================================== @@ -241,7 +241,7 @@ dsFCall fn_id co fcall mDeclHeader = do | (_, res_ty1) <- tcSplitFunTys ty1 , newty <- maybe res_ty1 snd (tcSplitIOType_maybe res_ty1) , Just (ptr, _) <- splitTyConApp_maybe newty - , tyConName ptr == constPtrConName + , tyConName ptr `hasKnownKey` constPtrTyConKey = text "const" | otherwise = empty ===================================== compiler/GHC/HsToCore/Match/Literal.hs ===================================== @@ -60,7 +60,6 @@ import GHC.Driver.DynFlags import GHC.Utils.Outputable as Outputable import GHC.Utils.Panic -import GHC.Utils.Unique (sameUnique) import GHC.Data.FastString import qualified GHC.Data.List.NonEmpty as NEL @@ -310,29 +309,29 @@ warnAboutOverflowedLiterals dflags lit , Just (i, tc) <- lit = if -- These only show up via the 'HsOverLit' route - | sameUnique tc intTyConName -> check i tc minInt maxInt - | sameUnique tc wordTyConName -> check i tc minWord maxWord - | sameUnique tc int8TyConName -> check i tc (min' @Int8) (max' @Int8) - | sameUnique tc int16TyConName -> check i tc (min' @Int16) (max' @Int16) - | sameUnique tc int32TyConName -> check i tc (min' @Int32) (max' @Int32) - | sameUnique tc int64TyConName -> check i tc (min' @Int64) (max' @Int64) - | sameUnique tc word8TyConName -> check i tc (min' @Word8) (max' @Word8) - | sameUnique tc word16TyConName -> check i tc (min' @Word16) (max' @Word16) - | sameUnique tc word32TyConName -> check i tc (min' @Word32) (max' @Word32) - | sameUnique tc word64TyConName -> check i tc (min' @Word64) (max' @Word64) - | sameUnique tc naturalTyConName -> checkPositive i tc + | tc `hasKnownKey` intTyConKey -> check i tc minInt maxInt + | tc `hasKnownKey` wordTyConKey -> check i tc minWord maxWord + | tc `hasKnownKey` int8TyConKey -> check i tc (min' @Int8) (max' @Int8) + | tc `hasKnownKey` int16TyConKey -> check i tc (min' @Int16) (max' @Int16) + | tc `hasKnownKey` int32TyConKey -> check i tc (min' @Int32) (max' @Int32) + | tc `hasKnownKey` int64TyConKey -> check i tc (min' @Int64) (max' @Int64) + | tc `hasKnownKey` word8TyConKey -> check i tc (min' @Word8) (max' @Word8) + | tc `hasKnownKey` word16TyConKey -> check i tc (min' @Word16) (max' @Word16) + | tc `hasKnownKey` word32TyConKey -> check i tc (min' @Word32) (max' @Word32) + | tc `hasKnownKey` word64TyConKey -> check i tc (min' @Word64) (max' @Word64) + | tc `hasKnownKey` naturalTyConKey -> checkPositive i tc -- These only show up via the 'HsLit' route - | sameUnique tc intPrimTyConName -> check i tc minInt maxInt - | sameUnique tc wordPrimTyConName -> check i tc minWord maxWord - | sameUnique tc int8PrimTyConName -> check i tc (min' @Int8) (max' @Int8) - | sameUnique tc int16PrimTyConName -> check i tc (min' @Int16) (max' @Int16) - | sameUnique tc int32PrimTyConName -> check i tc (min' @Int32) (max' @Int32) - | sameUnique tc int64PrimTyConName -> check i tc (min' @Int64) (max' @Int64) - | sameUnique tc word8PrimTyConName -> check i tc (min' @Word8) (max' @Word8) - | sameUnique tc word16PrimTyConName -> check i tc (min' @Word16) (max' @Word16) - | sameUnique tc word32PrimTyConName -> check i tc (min' @Word32) (max' @Word32) - | sameUnique tc word64PrimTyConName -> check i tc (min' @Word64) (max' @Word64) + | tc `hasKnownKey` intPrimTyConKey -> check i tc minInt maxInt + | tc `hasKnownKey` wordPrimTyConKey -> check i tc minWord maxWord + | tc `hasKnownKey` int8PrimTyConKey -> check i tc (min' @Int8) (max' @Int8) + | tc `hasKnownKey` int16PrimTyConKey -> check i tc (min' @Int16) (max' @Int16) + | tc `hasKnownKey` int32PrimTyConKey -> check i tc (min' @Int32) (max' @Int32) + | tc `hasKnownKey` int64PrimTyConKey -> check i tc (min' @Int64) (max' @Int64) + | tc `hasKnownKey` word8PrimTyConKey -> check i tc (min' @Word8) (max' @Word8) + | tc `hasKnownKey` word16PrimTyConKey -> check i tc (min' @Word16) (max' @Word16) + | tc `hasKnownKey` word32PrimTyConKey -> check i tc (min' @Word32) (max' @Word32) + | tc `hasKnownKey` word64PrimTyConKey -> check i tc (min' @Word64) (max' @Word64) | otherwise -> return () ===================================== compiler/GHC/Types/Name.hs ===================================== @@ -165,34 +165,6 @@ import GHC.Builtin.Uniques ( isTupleTyConUnique, isCTupleTyConUnique, The BuiltInSyntax flag => It's a syntactic form, not "in scope" (e.g. []) All built-in syntax things are WiredIn. - -Note [Fast comparison for built-in Names] -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Consider this wired-in Name in GHC.Builtin.KnownKeys: - - int8TyConName = tcQual gHC_INTERNAL_INT (fsLit "Int8") int8TyConKey - -Ultimately this turns into something like: - - int8TyConName = Name gHC_INTERNAL_INT (mkOccName ..."Int8") int8TyConKey - -So a comparison like `x == int8TyConName` will turn into `getUnique x == -int8TyConKey`, nice and efficient. But if the `n_occ` field is strict, that -definition will look like: - - int8TyConName = case (mkOccName..."Int8") of occ -> - Name gHC_INTERNAL_INT occ int8TyConKey - -and now the comparison will not optimise. This matters even more when there are -numerous comparisons (see #19386): - -if | tc == int8TyCon -> ... - | tc == int16TyCon -> ... - ...etc... - -when we would like to get a single multi-branched case. - -TL;DR: we make the `n_occ` field lazy. -} {- ******************************************************************* @@ -207,11 +179,8 @@ data Name = Name { n_sort :: NameSort -- ^ What sort of name it is - , n_occ :: OccName + , n_occ :: !OccName -- ^ Its occurrence name. - -- - -- NOTE: kept lazy to allow known names to be known constructor applications - -- and to inline better. See Note [Fast comparison for built-in Names] , n_uniq :: {-# UNPACK #-} !Unique -- ^ Its unique. ===================================== libraries/base/src/GHC/Essentials.hs ===================================== @@ -1,4 +1,4 @@ -{-# LANGUAGE MagicHash, Trustworthy, RankNTypes #-} +{-# LANGUAGE MagicHash, Trustworthy, RankNTypes, CPP #-} -- | -- @@ -75,6 +75,9 @@ module GHC.Essentials , Either(..) , Void + -- FFI + , ConstPtr + -- Show internals , showsPrec, shows, showString, showSpace, showCommaSpace, showParen @@ -138,7 +141,7 @@ module GHC.Essentials -- Static pointers , IsStatic( fromStaticPtr ), makeStatic - , StaticPtr( StaticPtr ), StaticPtrInfo( StaticPtrInfo ) + , StaticPtr, StaticPtrInfo( StaticPtrInfo ) -- Stable pointers , StablePtr, newStablePtr @@ -157,9 +160,6 @@ module GHC.Essentials , CS.unpackAppendCStringUtf8#, CS.cstringLength# , eqString, inline - -- JS primitives - , unsafeUnpackJSStringUtf8## - , UnsafeEquality( UnsafeRefl ), unsafeEqualityProof -- Typeable and type representations @@ -237,6 +237,11 @@ module GHC.Essentials , ExceptionContext, emptyExceptionContext , toAnnotationWrapper + +#if defined(javascript_HOST_ARCH) + -- JS primitives + , unsafeUnpackJSStringUtf8## +#endif ) where import GHC.Internal.Base hiding( foldr ) @@ -276,7 +281,7 @@ import GHC.Internal.Word( Word8(W8#), Word16(W16#), Word32(W32#), Word64(W64#) ) import GHC.Internal.Unsafe.Coerce( UnsafeEquality(..), unsafeEqualityProof ) -import GHC.Internal.StaticPtr( IsStatic(..), StaticPtr(..), StaticPtrInfo(..) ) +import GHC.Internal.StaticPtr( IsStatic(..), StaticPtr, StaticPtrInfo(..) ) import GHC.Internal.StaticPtr.Internal( makeStatic ) import GHC.Internal.Stable( StablePtr, newStablePtr ) @@ -297,4 +302,7 @@ import GHC.Internal.GHCi import GHC.Internal.Desugar (toAnnotationWrapper) import GHC.Internal.Stack.Types import GHC.Internal.Exception.Context +import GHC.Internal.Foreign.C.ConstPtr +#if defined(javascript_HOST_ARCH) import GHC.Internal.JS.Prim (unsafeUnpackJSStringUtf8##) +#endif ===================================== libraries/ghc-internal/src/GHC/Internal/Foreign/C/ConstPtr.hs ===================================== @@ -3,6 +3,7 @@ {-# LANGUAGE StandaloneKindSignatures #-} {-# LANGUAGE Trustworthy #-} +{-# OPTIONS_GHC -fdefine-known-key-names #-} ----------------------------------------------------------------------------- -- | -- Module : GHC.Internal.Foreign.C.ConstPtr View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a207cbcf5265d0a81d32ba744dccc6d... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/a207cbcf5265d0a81d32ba744dccc6d... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Rodrigo Mesquita (@alt-romes)