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
-
59c56053
by Rodrigo Mesquita at 2026-05-06T11:56:04+01:00
-
38033e26
by Rodrigo Mesquita at 2026-05-06T11:56:32+01:00
-
5604ce26
by Rodrigo Mesquita at 2026-05-06T12:07:06+01:00
-
db33d608
by Rodrigo Mesquita at 2026-05-06T12:11:31+01:00
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:
| ... | ... | @@ -200,6 +200,9 @@ knownKeyTable |
| 200 | 200 | , (mkVarOcc "toRational", toRationalClassOpKey)
|
| 201 | 201 | , (mkVarOcc "realToFrac", realToFracIdKey)
|
| 202 | 202 | |
| 203 | + -- FFI things
|
|
| 204 | + , (mkTcOcc "ConstPtr", constPtrTyConKey)
|
|
| 205 | + |
|
| 203 | 206 | -- Class Monad, MonadFix, MonadZip
|
| 204 | 207 | , (mkTcOcc "Monad", monadClassKey)
|
| 205 | 208 | , (thenMClassOpOcc, thenMClassOpKey)
|
| ... | ... | @@ -365,9 +368,8 @@ basicKnownKeyNames |
| 365 | 368 | starArrStarArrStarKindRepName,
|
| 366 | 369 | constraintKindRepName,
|
| 367 | 370 | -- FFI primitive types that are not wired-in.
|
| 368 | - ptrTyConName, funPtrTyConName, constPtrConName,
|
|
| 369 | - int8TyConName, int16TyConName, int32TyConName, int64TyConName,
|
|
| 370 | - word8TyConName, word16TyConName, word32TyConName, word64TyConName,
|
|
| 371 | + ptrTyConName, funPtrTyConName,
|
|
| 372 | + word8TyConName,
|
|
| 371 | 373 | |
| 372 | 374 | -- Plugins
|
| 373 | 375 | pluginTyConName
|
| ... | ... | @@ -443,19 +445,9 @@ unsafeCoercePrimName = varQual gHC_INTERNAL_UNSAFE_COERCE (fsLit "unsafeCoerc |
| 443 | 445 | genericClassKeys :: [KnownKey]
|
| 444 | 446 | genericClassKeys = [genClassKey, gen1ClassKey]
|
| 445 | 447 | |
| 446 | --- Int, Word, and Addr things
|
|
| 447 | -int8TyConName, int16TyConName, int32TyConName, int64TyConName :: Name
|
|
| 448 | -int8TyConName = tcQual gHC_INTERNAL_INT (fsLit "Int8") int8TyConKey
|
|
| 449 | -int16TyConName = tcQual gHC_INTERNAL_INT (fsLit "Int16") int16TyConKey
|
|
| 450 | -int32TyConName = tcQual gHC_INTERNAL_INT (fsLit "Int32") int32TyConKey
|
|
| 451 | -int64TyConName = tcQual gHC_INTERNAL_INT (fsLit "Int64") int64TyConKey
|
|
| 452 | - |
|
| 453 | 448 | -- Word module
|
| 454 | -word8TyConName, word16TyConName, word32TyConName, word64TyConName :: Name
|
|
| 455 | -word8TyConName = tcQual gHC_INTERNAL_WORD (fsLit "Word8") word8TyConKey
|
|
| 456 | -word16TyConName = tcQual gHC_INTERNAL_WORD (fsLit "Word16") word16TyConKey
|
|
| 457 | -word32TyConName = tcQual gHC_INTERNAL_WORD (fsLit "Word32") word32TyConKey
|
|
| 458 | -word64TyConName = tcQual gHC_INTERNAL_WORD (fsLit "Word64") word64TyConKey
|
|
| 449 | +word8TyConName :: Name
|
|
| 450 | +word8TyConName = tcQual gHC_INTERNAL_WORD (fsLit "Word8") word8TyConKey
|
|
| 459 | 451 | |
| 460 | 452 | -- PrelPtr module
|
| 461 | 453 | ptrTyConName, funPtrTyConName :: Name
|
| ... | ... | @@ -470,11 +462,6 @@ pluginTyConName = tcQual pLUGINS (fsLit "Plugin") pluginTyConKey |
| 470 | 462 | frontendPluginTyConName :: Name
|
| 471 | 463 | frontendPluginTyConName = tcQual pLUGINS (fsLit "FrontendPlugin") frontendPluginTyConKey
|
| 472 | 464 | |
| 473 | -constPtrConName :: Name
|
|
| 474 | -constPtrConName =
|
|
| 475 | - tcQual gHC_INTERNAL_FOREIGN_C_CONSTPTR (fsLit "ConstPtr") constPtrTyConKey
|
|
| 476 | - |
|
| 477 | - |
|
| 478 | 465 | {-
|
| 479 | 466 | ************************************************************************
|
| 480 | 467 | * *
|
| ... | ... | @@ -204,9 +204,8 @@ fromStaticPtrClassOpOcc, newStablePtrIdOcc :: KnownOcc |
| 204 | 204 | fromStaticPtrClassOpOcc = mkVarOcc "fromStaticPtr"
|
| 205 | 205 | newStablePtrIdOcc = mkVarOcc "newStablePtr"
|
| 206 | 206 | |
| 207 | -staticPtrTyConOcc, staticPtrDataConOcc, staticPtrInfoDataConOcc :: KnownOcc
|
|
| 207 | +staticPtrTyConOcc, staticPtrInfoDataConOcc :: KnownOcc
|
|
| 208 | 208 | staticPtrTyConOcc = mkTcOcc "StaticPtr"
|
| 209 | -staticPtrDataConOcc = mkDataOcc "StaticPtr"
|
|
| 210 | 209 | staticPtrInfoDataConOcc = mkDataOcc "StaticPtrInfo"
|
| 211 | 210 | |
| 212 | 211 | knownNatClassOcc, knownSymbolClassOcc, knownCharClassOcc :: KnownOcc
|
| ... | ... | @@ -241,7 +241,7 @@ dsFCall fn_id co fcall mDeclHeader = do |
| 241 | 241 | | (_, res_ty1) <- tcSplitFunTys ty1
|
| 242 | 242 | , newty <- maybe res_ty1 snd (tcSplitIOType_maybe res_ty1)
|
| 243 | 243 | , Just (ptr, _) <- splitTyConApp_maybe newty
|
| 244 | - , tyConName ptr == constPtrConName
|
|
| 244 | + , tyConName ptr `hasKnownKey` constPtrTyConKey
|
|
| 245 | 245 | = text "const"
|
| 246 | 246 | | otherwise = empty
|
| 247 | 247 |
| ... | ... | @@ -60,7 +60,6 @@ import GHC.Driver.DynFlags |
| 60 | 60 | |
| 61 | 61 | import GHC.Utils.Outputable as Outputable
|
| 62 | 62 | import GHC.Utils.Panic
|
| 63 | -import GHC.Utils.Unique (sameUnique)
|
|
| 64 | 63 | |
| 65 | 64 | import GHC.Data.FastString
|
| 66 | 65 | import qualified GHC.Data.List.NonEmpty as NEL
|
| ... | ... | @@ -310,29 +309,29 @@ warnAboutOverflowedLiterals dflags lit |
| 310 | 309 | , Just (i, tc) <- lit
|
| 311 | 310 | = if
|
| 312 | 311 | -- These only show up via the 'HsOverLit' route
|
| 313 | - | sameUnique tc intTyConName -> check i tc minInt maxInt
|
|
| 314 | - | sameUnique tc wordTyConName -> check i tc minWord maxWord
|
|
| 315 | - | sameUnique tc int8TyConName -> check i tc (min' @Int8) (max' @Int8)
|
|
| 316 | - | sameUnique tc int16TyConName -> check i tc (min' @Int16) (max' @Int16)
|
|
| 317 | - | sameUnique tc int32TyConName -> check i tc (min' @Int32) (max' @Int32)
|
|
| 318 | - | sameUnique tc int64TyConName -> check i tc (min' @Int64) (max' @Int64)
|
|
| 319 | - | sameUnique tc word8TyConName -> check i tc (min' @Word8) (max' @Word8)
|
|
| 320 | - | sameUnique tc word16TyConName -> check i tc (min' @Word16) (max' @Word16)
|
|
| 321 | - | sameUnique tc word32TyConName -> check i tc (min' @Word32) (max' @Word32)
|
|
| 322 | - | sameUnique tc word64TyConName -> check i tc (min' @Word64) (max' @Word64)
|
|
| 323 | - | sameUnique tc naturalTyConName -> checkPositive i tc
|
|
| 312 | + | tc `hasKnownKey` intTyConKey -> check i tc minInt maxInt
|
|
| 313 | + | tc `hasKnownKey` wordTyConKey -> check i tc minWord maxWord
|
|
| 314 | + | tc `hasKnownKey` int8TyConKey -> check i tc (min' @Int8) (max' @Int8)
|
|
| 315 | + | tc `hasKnownKey` int16TyConKey -> check i tc (min' @Int16) (max' @Int16)
|
|
| 316 | + | tc `hasKnownKey` int32TyConKey -> check i tc (min' @Int32) (max' @Int32)
|
|
| 317 | + | tc `hasKnownKey` int64TyConKey -> check i tc (min' @Int64) (max' @Int64)
|
|
| 318 | + | tc `hasKnownKey` word8TyConKey -> check i tc (min' @Word8) (max' @Word8)
|
|
| 319 | + | tc `hasKnownKey` word16TyConKey -> check i tc (min' @Word16) (max' @Word16)
|
|
| 320 | + | tc `hasKnownKey` word32TyConKey -> check i tc (min' @Word32) (max' @Word32)
|
|
| 321 | + | tc `hasKnownKey` word64TyConKey -> check i tc (min' @Word64) (max' @Word64)
|
|
| 322 | + | tc `hasKnownKey` naturalTyConKey -> checkPositive i tc
|
|
| 324 | 323 | |
| 325 | 324 | -- These only show up via the 'HsLit' route
|
| 326 | - | sameUnique tc intPrimTyConName -> check i tc minInt maxInt
|
|
| 327 | - | sameUnique tc wordPrimTyConName -> check i tc minWord maxWord
|
|
| 328 | - | sameUnique tc int8PrimTyConName -> check i tc (min' @Int8) (max' @Int8)
|
|
| 329 | - | sameUnique tc int16PrimTyConName -> check i tc (min' @Int16) (max' @Int16)
|
|
| 330 | - | sameUnique tc int32PrimTyConName -> check i tc (min' @Int32) (max' @Int32)
|
|
| 331 | - | sameUnique tc int64PrimTyConName -> check i tc (min' @Int64) (max' @Int64)
|
|
| 332 | - | sameUnique tc word8PrimTyConName -> check i tc (min' @Word8) (max' @Word8)
|
|
| 333 | - | sameUnique tc word16PrimTyConName -> check i tc (min' @Word16) (max' @Word16)
|
|
| 334 | - | sameUnique tc word32PrimTyConName -> check i tc (min' @Word32) (max' @Word32)
|
|
| 335 | - | sameUnique tc word64PrimTyConName -> check i tc (min' @Word64) (max' @Word64)
|
|
| 325 | + | tc `hasKnownKey` intPrimTyConKey -> check i tc minInt maxInt
|
|
| 326 | + | tc `hasKnownKey` wordPrimTyConKey -> check i tc minWord maxWord
|
|
| 327 | + | tc `hasKnownKey` int8PrimTyConKey -> check i tc (min' @Int8) (max' @Int8)
|
|
| 328 | + | tc `hasKnownKey` int16PrimTyConKey -> check i tc (min' @Int16) (max' @Int16)
|
|
| 329 | + | tc `hasKnownKey` int32PrimTyConKey -> check i tc (min' @Int32) (max' @Int32)
|
|
| 330 | + | tc `hasKnownKey` int64PrimTyConKey -> check i tc (min' @Int64) (max' @Int64)
|
|
| 331 | + | tc `hasKnownKey` word8PrimTyConKey -> check i tc (min' @Word8) (max' @Word8)
|
|
| 332 | + | tc `hasKnownKey` word16PrimTyConKey -> check i tc (min' @Word16) (max' @Word16)
|
|
| 333 | + | tc `hasKnownKey` word32PrimTyConKey -> check i tc (min' @Word32) (max' @Word32)
|
|
| 334 | + | tc `hasKnownKey` word64PrimTyConKey -> check i tc (min' @Word64) (max' @Word64)
|
|
| 336 | 335 | |
| 337 | 336 | | otherwise -> return ()
|
| 338 | 337 |
| ... | ... | @@ -165,34 +165,6 @@ import GHC.Builtin.Uniques ( isTupleTyConUnique, isCTupleTyConUnique, |
| 165 | 165 | |
| 166 | 166 | The BuiltInSyntax flag => It's a syntactic form, not "in scope" (e.g. [])
|
| 167 | 167 | All built-in syntax things are WiredIn.
|
| 168 | - |
|
| 169 | -Note [Fast comparison for built-in Names]
|
|
| 170 | -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
| 171 | -Consider this wired-in Name in GHC.Builtin.KnownKeys:
|
|
| 172 | - |
|
| 173 | - int8TyConName = tcQual gHC_INTERNAL_INT (fsLit "Int8") int8TyConKey
|
|
| 174 | - |
|
| 175 | -Ultimately this turns into something like:
|
|
| 176 | - |
|
| 177 | - int8TyConName = Name gHC_INTERNAL_INT (mkOccName ..."Int8") int8TyConKey
|
|
| 178 | - |
|
| 179 | -So a comparison like `x == int8TyConName` will turn into `getUnique x ==
|
|
| 180 | -int8TyConKey`, nice and efficient. But if the `n_occ` field is strict, that
|
|
| 181 | -definition will look like:
|
|
| 182 | - |
|
| 183 | - int8TyConName = case (mkOccName..."Int8") of occ ->
|
|
| 184 | - Name gHC_INTERNAL_INT occ int8TyConKey
|
|
| 185 | - |
|
| 186 | -and now the comparison will not optimise. This matters even more when there are
|
|
| 187 | -numerous comparisons (see #19386):
|
|
| 188 | - |
|
| 189 | -if | tc == int8TyCon -> ...
|
|
| 190 | - | tc == int16TyCon -> ...
|
|
| 191 | - ...etc...
|
|
| 192 | - |
|
| 193 | -when we would like to get a single multi-branched case.
|
|
| 194 | - |
|
| 195 | -TL;DR: we make the `n_occ` field lazy.
|
|
| 196 | 168 | -}
|
| 197 | 169 | |
| 198 | 170 | {- *******************************************************************
|
| ... | ... | @@ -207,11 +179,8 @@ data Name = Name |
| 207 | 179 | { n_sort :: NameSort
|
| 208 | 180 | -- ^ What sort of name it is
|
| 209 | 181 | |
| 210 | - , n_occ :: OccName
|
|
| 182 | + , n_occ :: !OccName
|
|
| 211 | 183 | -- ^ Its occurrence name.
|
| 212 | - --
|
|
| 213 | - -- NOTE: kept lazy to allow known names to be known constructor applications
|
|
| 214 | - -- and to inline better. See Note [Fast comparison for built-in Names]
|
|
| 215 | 184 | |
| 216 | 185 | , n_uniq :: {-# UNPACK #-} !Unique
|
| 217 | 186 | -- ^ Its unique.
|
| 1 | -{-# LANGUAGE MagicHash, Trustworthy, RankNTypes #-}
|
|
| 1 | +{-# LANGUAGE MagicHash, Trustworthy, RankNTypes, CPP #-}
|
|
| 2 | 2 | |
| 3 | 3 | -- |
|
| 4 | 4 | --
|
| ... | ... | @@ -75,6 +75,9 @@ module GHC.Essentials |
| 75 | 75 | , Either(..)
|
| 76 | 76 | , Void
|
| 77 | 77 | |
| 78 | + -- FFI
|
|
| 79 | + , ConstPtr
|
|
| 80 | + |
|
| 78 | 81 | -- Show internals
|
| 79 | 82 | , showsPrec, shows, showString, showSpace, showCommaSpace, showParen
|
| 80 | 83 | |
| ... | ... | @@ -138,7 +141,7 @@ module GHC.Essentials |
| 138 | 141 | |
| 139 | 142 | -- Static pointers
|
| 140 | 143 | , IsStatic( fromStaticPtr ), makeStatic
|
| 141 | - , StaticPtr( StaticPtr ), StaticPtrInfo( StaticPtrInfo )
|
|
| 144 | + , StaticPtr, StaticPtrInfo( StaticPtrInfo )
|
|
| 142 | 145 | |
| 143 | 146 | -- Stable pointers
|
| 144 | 147 | , StablePtr, newStablePtr
|
| ... | ... | @@ -157,9 +160,6 @@ module GHC.Essentials |
| 157 | 160 | , CS.unpackAppendCStringUtf8#, CS.cstringLength#
|
| 158 | 161 | , eqString, inline
|
| 159 | 162 | |
| 160 | - -- JS primitives
|
|
| 161 | - , unsafeUnpackJSStringUtf8##
|
|
| 162 | - |
|
| 163 | 163 | , UnsafeEquality( UnsafeRefl ), unsafeEqualityProof
|
| 164 | 164 | |
| 165 | 165 | -- Typeable and type representations
|
| ... | ... | @@ -237,6 +237,11 @@ module GHC.Essentials |
| 237 | 237 | , ExceptionContext, emptyExceptionContext
|
| 238 | 238 | |
| 239 | 239 | , toAnnotationWrapper
|
| 240 | + |
|
| 241 | +#if defined(javascript_HOST_ARCH)
|
|
| 242 | + -- JS primitives
|
|
| 243 | + , unsafeUnpackJSStringUtf8##
|
|
| 244 | +#endif
|
|
| 240 | 245 | ) where
|
| 241 | 246 | |
| 242 | 247 | import GHC.Internal.Base hiding( foldr )
|
| ... | ... | @@ -276,7 +281,7 @@ import GHC.Internal.Word( Word8(W8#), Word16(W16#), Word32(W32#), Word64(W64#) ) |
| 276 | 281 | |
| 277 | 282 | import GHC.Internal.Unsafe.Coerce( UnsafeEquality(..), unsafeEqualityProof )
|
| 278 | 283 | |
| 279 | -import GHC.Internal.StaticPtr( IsStatic(..), StaticPtr(..), StaticPtrInfo(..) )
|
|
| 284 | +import GHC.Internal.StaticPtr( IsStatic(..), StaticPtr, StaticPtrInfo(..) )
|
|
| 280 | 285 | import GHC.Internal.StaticPtr.Internal( makeStatic )
|
| 281 | 286 | |
| 282 | 287 | import GHC.Internal.Stable( StablePtr, newStablePtr )
|
| ... | ... | @@ -297,4 +302,7 @@ import GHC.Internal.GHCi |
| 297 | 302 | import GHC.Internal.Desugar (toAnnotationWrapper)
|
| 298 | 303 | import GHC.Internal.Stack.Types
|
| 299 | 304 | import GHC.Internal.Exception.Context
|
| 305 | +import GHC.Internal.Foreign.C.ConstPtr
|
|
| 306 | +#if defined(javascript_HOST_ARCH)
|
|
| 300 | 307 | import GHC.Internal.JS.Prim (unsafeUnpackJSStringUtf8##)
|
| 308 | +#endif |
| ... | ... | @@ -3,6 +3,7 @@ |
| 3 | 3 | {-# LANGUAGE StandaloneKindSignatures #-}
|
| 4 | 4 | {-# LANGUAGE Trustworthy #-}
|
| 5 | 5 | |
| 6 | +{-# OPTIONS_GHC -fdefine-known-key-names #-}
|
|
| 6 | 7 | -----------------------------------------------------------------------------
|
| 7 | 8 | -- |
|
| 8 | 9 | -- Module : GHC.Internal.Foreign.C.ConstPtr
|