Rodrigo Mesquita pushed to branch wip/spj-reinstallable-base2 at Glasgow Haskell Compiler / GHC
Commits:
-
b413547b
by Rodrigo Mesquita at 2026-04-30T11:23:22+01:00
-
2d7a3edb
by Rodrigo Mesquita at 2026-04-30T11:26:03+01:00
-
5ed1b76b
by Rodrigo Mesquita at 2026-04-30T11:30:19+01:00
-
3426681d
by Rodrigo Mesquita at 2026-04-30T13:33:04+01:00
-
a299f51e
by Rodrigo Mesquita at 2026-04-30T13:33:09+01:00
-
b2be111b
by Rodrigo Mesquita at 2026-04-30T13:35:30+01:00
-
31f947b9
by Rodrigo Mesquita at 2026-04-30T13:39:57+01:00
-
dbda1e30
by Rodrigo Mesquita at 2026-04-30T13:48:54+01:00
-
3b9dd300
by Rodrigo Mesquita at 2026-04-30T13:53:11+01:00
-
e3056af0
by Rodrigo Mesquita at 2026-04-30T14:05:47+01:00
10 changed files:
- compiler/GHC/Builtin/KnownKeys.hs
- compiler/GHC/Builtin/KnownOccs.hs
- compiler/GHC/HsToCore/Foreign/C.hs
- compiler/GHC/HsToCore/Foreign/JavaScript.hs
- compiler/GHC/HsToCore/Foreign/Wasm.hs
- compiler/GHC/HsToCore/Monad.hs
- compiler/GHC/Tc/Gen/Head.hs
- compiler/GHC/Tc/Module.hs
- libraries/base/src/GHC/Essentials.hs
- libraries/ghc-internal/src/GHC/Internal/Event/KQueue.hsc
Changes:
| ... | ... | @@ -240,6 +240,9 @@ knownKeyTable |
| 240 | 240 | -- Static pointers
|
| 241 | 241 | , (mkVarOcc "makeStatic", makeStaticKey)
|
| 242 | 242 | |
| 243 | + -- Stable pointers
|
|
| 244 | + , (mkTcOcc "StablePtr", stablePtrTyConKey)
|
|
| 245 | + |
|
| 243 | 246 | -- WithDict
|
| 244 | 247 | , (mkTcOcc "WithDict", withDictClassKey)
|
| 245 | 248 | |
| ... | ... | @@ -338,37 +341,24 @@ basicKnownKeyNames |
| 338 | 341 | -- classes in "Class.standardClassKeys" (quite a few)
|
| 339 | 342 | -- The IO type
|
| 340 | 343 | ioTyConName, ioDataConName,
|
| 341 | - runMainIOName,
|
|
| 342 | - runRWName,
|
|
| 343 | 344 | |
| 344 | 345 | -- KindReps for common cases
|
| 345 | - trGhcPrimModuleName,
|
|
| 346 | 346 | starKindRepName,
|
| 347 | 347 | starArrStarKindRepName,
|
| 348 | 348 | starArrStarArrStarKindRepName,
|
| 349 | 349 | constraintKindRepName,
|
| 350 | 350 | |
| 351 | - -- Monad stuff
|
|
| 352 | - bindMName,
|
|
| 353 | - |
|
| 354 | - -- GHC Extensions
|
|
| 355 | - considerAccessibleName,
|
|
| 356 | - |
|
| 357 | 351 | -- Strings and lists
|
| 358 | 352 | unpackCStringName, unpackCStringUtf8Name,
|
| 359 | 353 | |
| 360 | 354 | -- FFI primitive types that are not wired-in.
|
| 361 | - stablePtrTyConName, ptrTyConName, funPtrTyConName, constPtrConName,
|
|
| 355 | + ptrTyConName, funPtrTyConName, constPtrConName,
|
|
| 362 | 356 | int8TyConName, int16TyConName, int32TyConName, int64TyConName,
|
| 363 | 357 | word8TyConName, word16TyConName, word32TyConName, word64TyConName,
|
| 364 | 358 | jsvalTyConName,
|
| 365 | 359 | |
| 366 | 360 | -- Others
|
| 367 | - otherwiseIdName,
|
|
| 368 | - assertName,
|
|
| 369 | - assertErrorName, traceName,
|
|
| 370 | 361 | printName,
|
| 371 | - dollarName,
|
|
| 372 | 362 | |
| 373 | 363 | -- Type-level naturals
|
| 374 | 364 | knownNatClassName, knownSymbolClassName, knownCharClassName,
|
| ... | ... | @@ -436,10 +426,6 @@ and it's convenient to write them all down in one place. |
| 436 | 426 | wildCardName :: Name
|
| 437 | 427 | wildCardName = mkSystemVarName wildCardKey (fsLit "wild")
|
| 438 | 428 | |
| 439 | -runMainIOName, runRWName :: Name
|
|
| 440 | -runMainIOName = varQual gHC_INTERNAL_TOP_HANDLER (fsLit "runMainIO") runMainKey
|
|
| 441 | -runRWName = varQual gHC_MAGIC (fsLit "runRW#") runRWKey
|
|
| 442 | - |
|
| 443 | 429 | specTyConName :: Name
|
| 444 | 430 | specTyConName = tcQual gHC_TYPES (fsLit "SPEC") specTyConKey
|
| 445 | 431 | |
| ... | ... | @@ -448,10 +434,6 @@ unpackCStringName, unpackCStringUtf8Name :: Name |
| 448 | 434 | unpackCStringName = varQual gHC_CSTRING (fsLit "unpackCString#") unpackCStringIdKey
|
| 449 | 435 | unpackCStringUtf8Name = varQual gHC_CSTRING (fsLit "unpackCStringUtf8#") unpackCStringUtf8IdKey
|
| 450 | 436 | |
| 451 | --- Class Monad
|
|
| 452 | -bindMName :: Name
|
|
| 453 | -bindMName = varQual gHC_INTERNAL_BASE (fsLit ">>=") bindMClassOpKey
|
|
| 454 | - |
|
| 455 | 437 | -- Class MonadFail
|
| 456 | 438 | failMName :: Name
|
| 457 | 439 | failMName = varQual gHC_INTERNAL_MONAD_FAIL (fsLit "fail") failMClassOpKey
|
| ... | ... | @@ -469,19 +451,6 @@ pureAClassOpKey = mkPreludeMiscIdUnique 752 |
| 469 | 451 | thenAClassOpKey = mkPreludeMiscIdUnique 753
|
| 470 | 452 | alternativeClassKey = mkPreludeMiscIdUnique 754
|
| 471 | 453 | |
| 472 | - |
|
| 473 | --- Functions for GHC extensions
|
|
| 474 | -considerAccessibleName :: Name
|
|
| 475 | -considerAccessibleName = varQual gHC_MAGIC (fsLit "considerAccessible") considerAccessibleIdKey
|
|
| 476 | - |
|
| 477 | --- Random GHC.Internal.Base functions
|
|
| 478 | -otherwiseIdName,
|
|
| 479 | - assertName,
|
|
| 480 | - dollarName :: Name
|
|
| 481 | -dollarName = varQual gHC_INTERNAL_BASE (fsLit "$") dollarIdKey
|
|
| 482 | -otherwiseIdName = varQual gHC_INTERNAL_BASE (fsLit "otherwise") otherwiseIdKey
|
|
| 483 | -assertName = varQual gHC_INTERNAL_BASE (fsLit "assert") assertIdKey
|
|
| 484 | - |
|
| 485 | 454 | bnbVarQual, bnnVarQual, bniVarQual :: String -> Unique -> Name
|
| 486 | 455 | bnbVarQual str key = varQual gHC_INTERNAL_NUM_BIGNAT (fsLit str) key
|
| 487 | 456 | bnnVarQual str key = varQual gHC_INTERNAL_NUM_NATURAL (fsLit str) key
|
| ... | ... | @@ -495,11 +464,10 @@ bniVarQual str key = varQual gHC_INTERNAL_NUM_INTEGER (fsLit str) key |
| 495 | 464 | |
| 496 | 465 | |
| 497 | 466 | -- Class Typeable, and functions for constructing `Typeable` dictionaries
|
| 498 | -trGhcPrimModuleName, starKindRepName, starArrStarKindRepName,
|
|
| 467 | +starKindRepName, starArrStarKindRepName,
|
|
| 499 | 468 | starArrStarArrStarKindRepName, constraintKindRepName :: Name
|
| 500 | 469 | -- This is the Typeable 'Module' for GHC.Prim (which has no code, so we place in GHC.Types)
|
| 501 | 470 | -- See Note [Grand plan for Typeable] in GHC.Tc.Instance.Typeable.
|
| 502 | -trGhcPrimModuleName = varQual gHC_TYPES (fsLit "tr$ModuleGHCPrim") trGhcPrimModuleKey
|
|
| 503 | 471 | starKindRepName = varQual gHC_TYPES (fsLit "krep$*") starKindRepKey
|
| 504 | 472 | starArrStarKindRepName = varQual gHC_TYPES (fsLit "krep$*Arr*") starArrStarKindRepKey
|
| 505 | 473 | starArrStarArrStarKindRepName = varQual gHC_TYPES (fsLit "krep$*->*->*") starArrStarArrStarKindRepKey
|
| ... | ... | @@ -536,14 +504,6 @@ typeErrorShowTypeDataConName = |
| 536 | 504 | unsafeCoercePrimName:: Name
|
| 537 | 505 | unsafeCoercePrimName = varQual gHC_INTERNAL_UNSAFE_COERCE (fsLit "unsafeCoerce#") unsafeCoercePrimIdKey
|
| 538 | 506 | |
| 539 | --- Error module
|
|
| 540 | -assertErrorName :: Name
|
|
| 541 | -assertErrorName = varQual gHC_INTERNAL_IO_Exception (fsLit "assertError") assertErrorIdKey
|
|
| 542 | - |
|
| 543 | --- GHC.Internal.Debug.Trace
|
|
| 544 | -traceName :: Name
|
|
| 545 | -traceName = varQual gHC_INTERNAL_DEBUG_TRACE (fsLit "trace") traceKey
|
|
| 546 | - |
|
| 547 | 507 | genericClassKeys :: [KnownKey]
|
| 548 | 508 | genericClassKeys = [genClassKey, gen1ClassKey]
|
| 549 | 509 | |
| ... | ... | @@ -580,10 +540,6 @@ ptrTyConName, funPtrTyConName :: Name |
| 580 | 540 | ptrTyConName = tcQual gHC_INTERNAL_PTR (fsLit "Ptr") ptrTyConKey
|
| 581 | 541 | funPtrTyConName = tcQual gHC_INTERNAL_PTR (fsLit "FunPtr") funPtrTyConKey
|
| 582 | 542 | |
| 583 | --- Foreign objects and weak pointers
|
|
| 584 | -stablePtrTyConName :: Name
|
|
| 585 | -stablePtrTyConName = tcQual gHC_INTERNAL_STABLE (fsLit "StablePtr") stablePtrTyConKey
|
|
| 586 | - |
|
| 587 | 543 | -- Annotation type checking
|
| 588 | 544 | toAnnotationWrapperName :: Name
|
| 589 | 545 | toAnnotationWrapperName = varQual gHC_INTERNAL_DESUGAR (fsLit "toAnnotationWrapper") toAnnotationWrapperIdKey
|
| ... | ... | @@ -1145,12 +1101,10 @@ srcLocDataConKey :: KnownKey |
| 1145 | 1101 | srcLocDataConKey = mkPreludeDataConUnique 37
|
| 1146 | 1102 | |
| 1147 | 1103 | trTyConDataConKey, trModuleDataConKey,
|
| 1148 | - trNameSDataConKey,
|
|
| 1149 | - trGhcPrimModuleKey :: KnownKey
|
|
| 1104 | + trNameSDataConKey :: KnownKey
|
|
| 1150 | 1105 | trTyConDataConKey = mkPreludeDataConUnique 41
|
| 1151 | 1106 | trModuleDataConKey = mkPreludeDataConUnique 43
|
| 1152 | 1107 | trNameSDataConKey = mkPreludeDataConUnique 45
|
| 1153 | -trGhcPrimModuleKey = mkPreludeDataConUnique 47
|
|
| 1154 | 1108 | |
| 1155 | 1109 | typeErrorTextDataConKey,
|
| 1156 | 1110 | typeErrorAppendDataConKey,
|
| ... | ... | @@ -1337,10 +1291,9 @@ rootMainKey, runMainKey :: KnownKey |
| 1337 | 1291 | rootMainKey = mkPreludeMiscIdUnique 101
|
| 1338 | 1292 | runMainKey = mkPreludeMiscIdUnique 102
|
| 1339 | 1293 | |
| 1340 | -thenIOIdKey, lazyIdKey, assertErrorIdKey, oneShotKey, runRWKey :: KnownKey
|
|
| 1294 | +thenIOIdKey, lazyIdKey, oneShotKey, runRWKey :: KnownKey
|
|
| 1341 | 1295 | thenIOIdKey = mkPreludeMiscIdUnique 103
|
| 1342 | 1296 | lazyIdKey = mkPreludeMiscIdUnique 104
|
| 1343 | -assertErrorIdKey = mkPreludeMiscIdUnique 105
|
|
| 1344 | 1297 | oneShotKey = mkPreludeMiscIdUnique 106
|
| 1345 | 1298 | runRWKey = mkPreludeMiscIdUnique 107
|
| 1346 | 1299 |
| ... | ... | @@ -309,6 +309,15 @@ metaDataDataConOcc = mkDataOcc "MetaData" |
| 309 | 309 | metaConsDataConOcc = mkDataOcc "MetaCons"
|
| 310 | 310 | metaSelDataConOcc = mkDataOcc "MetaSel"
|
| 311 | 311 | |
| 312 | +runMainIOOcc :: KnownOcc
|
|
| 313 | +runMainIOOcc = mkVarOcc "runMainIO"
|
|
| 314 | + |
|
| 315 | +traceIdOcc :: KnownOcc
|
|
| 316 | +traceIdOcc = mkVarOcc "trace"
|
|
| 317 | + |
|
| 318 | +assertErrorIdOcc :: KnownOcc
|
|
| 319 | +assertErrorIdOcc = mkVarOcc "assertError"
|
|
| 320 | + |
|
| 312 | 321 | {- *********************************************************************
|
| 313 | 322 | * *
|
| 314 | 323 | Known-occ RdrNames
|
| ... | ... | @@ -178,7 +178,7 @@ dsCFExportDynamic id co0 cconv = do |
| 178 | 178 | -- depending on Unique. See #13807 and Note [Unique Determinism].
|
| 179 | 179 | cback <- newSysLocalDs scaled_arg_ty
|
| 180 | 180 | newStablePtrId <- dsLookupKnownOccId newStablePtrIdOcc
|
| 181 | - stable_ptr_tycon <- dsLookupTyCon stablePtrTyConName
|
|
| 181 | + stable_ptr_tycon <- dsLookupKnownKeyTyCon stablePtrTyConKey
|
|
| 182 | 182 | let
|
| 183 | 183 | stable_ptr_ty = mkTyConApp stable_ptr_tycon [arg_ty]
|
| 184 | 184 | export_ty = mkVisFunTyMany stable_ptr_ty arg_ty
|
| ... | ... | @@ -278,7 +278,7 @@ dsJsFExportDynamic id co0 cconv = do |
| 278 | 278 | -- depending on Unique. See #13807 and Note [Unique Determinism].
|
| 279 | 279 | cback <- newSysLocalDs scaled_arg_ty
|
| 280 | 280 | newStablePtrId <- dsLookupKnownOccId newStablePtrIdOcc
|
| 281 | - stable_ptr_tycon <- dsLookupTyCon stablePtrTyConName
|
|
| 281 | + stable_ptr_tycon <- dsLookupKnownKeyTyCon stablePtrTyConKey
|
|
| 282 | 282 | let
|
| 283 | 283 | stable_ptr_ty = mkTyConApp stable_ptr_tycon [arg_ty]
|
| 284 | 284 | export_ty = mkVisFunTyMany stable_ptr_ty arg_ty
|
| ... | ... | @@ -135,7 +135,7 @@ dsWasmJSDynamicExport :: |
| 135 | 135 | CCallStaticTargetUnit ->
|
| 136 | 136 | DsM ([Binding], CHeader, CStub, [Id])
|
| 137 | 137 | dsWasmJSDynamicExport sync fn_id co unitId = do
|
| 138 | - sp_tycon <- dsLookupTyCon stablePtrTyConName
|
|
| 138 | + sp_tycon <- dsLookupKnownKeyTyCon stablePtrTyConKey
|
|
| 139 | 139 | let ty = coercionLKind co
|
| 140 | 140 | (tv_bndrs, fun_ty) = tcSplitForAllTyVarBinders ty
|
| 141 | 141 | ([Scaled ManyTy arg_ty], io_jsval_ty) = tcSplitFunTys fun_ty
|
| ... | ... | @@ -87,6 +87,7 @@ import GHC.Iface.Load |
| 87 | 87 | |
| 88 | 88 | import GHC.Tc.Utils.Monad
|
| 89 | 89 | |
| 90 | +import GHC.Builtin.KnownOccs (traceIdOcc)
|
|
| 90 | 91 | import GHC.Builtin.KnownKeys
|
| 91 | 92 | |
| 92 | 93 | import GHC.Data.FastString
|
| ... | ... | @@ -730,7 +731,7 @@ pprRuntimeTrace :: String -- ^ header |
| 730 | 731 | -> CoreExpr -- ^ expression
|
| 731 | 732 | -> DsM CoreExpr
|
| 732 | 733 | pprRuntimeTrace str doc expr = do
|
| 733 | - traceId <- dsLookupGlobalId traceName
|
|
| 734 | + traceId <- dsLookupKnownOccId traceIdOcc
|
|
| 734 | 735 | unpackCStringId <- dsLookupGlobalId unpackCStringName
|
| 735 | 736 | dflags <- getDynFlags
|
| 736 | 737 | let message :: CoreExpr
|
| ... | ... | @@ -63,6 +63,7 @@ import GHC.Types.Name.Reader |
| 63 | 63 | import GHC.Types.SrcLoc
|
| 64 | 64 | import GHC.Types.Error
|
| 65 | 65 | |
| 66 | +import GHC.Builtin.KnownOccs
|
|
| 66 | 67 | import GHC.Builtin.KnownKeys
|
| 67 | 68 | |
| 68 | 69 | import GHC.Driver.DynFlags
|
| ... | ... | @@ -657,7 +658,8 @@ tcInferId lname@(L loc (WithUserRdr rdr id_name)) |
| 657 | 658 | do { dflags <- getDynFlags
|
| 658 | 659 | ; if gopt Opt_IgnoreAsserts dflags
|
| 659 | 660 | then tc_infer_id lname
|
| 660 | - else tc_infer_id (L loc $ WithUserRdr rdr assertErrorName) }
|
|
| 661 | + else do { assertErrorName <- idName <$> tcLookupKnownOccId assertErrorIdOcc
|
|
| 662 | + ; tc_infer_id (L loc $ WithUserRdr rdr assertErrorName) } }
|
|
| 661 | 663 | |
| 662 | 664 | | otherwise
|
| 663 | 665 | = tc_infer_id lname
|
| ... | ... | @@ -1948,7 +1948,7 @@ generateMainBinding tcg_env main_name = do |
| 1948 | 1948 | -- See Note [Root-main Id]
|
| 1949 | 1949 | -- Construct the binding
|
| 1950 | 1950 | -- :Main.main :: IO res_ty = runMainIO res_ty main
|
| 1951 | - ; run_main_id <- tcLookupId runMainIOName
|
|
| 1951 | + ; run_main_id <- tcLookupKnownOccId runMainIOOcc
|
|
| 1952 | 1952 | ; let { root_main_name = mkExternalName rootMainKey rOOT_MAIN
|
| 1953 | 1953 | (mkVarOccFS (fsLit "main"))
|
| 1954 | 1954 | (getSrcSpan main_name)
|
| ... | ... | @@ -90,6 +90,7 @@ module GHC.Essentials |
| 90 | 90 | |
| 91 | 91 | -- Error
|
| 92 | 92 | , error
|
| 93 | + , assertError
|
|
| 93 | 94 | |
| 94 | 95 | -- Numbers
|
| 95 | 96 | , Num, Integral, Real, Floating, Fractional, RealFloat, RealFrac
|
| ... | ... | @@ -129,11 +130,14 @@ module GHC.Essentials |
| 129 | 130 | , IsStatic( fromStaticPtr ), makeStatic
|
| 130 | 131 | |
| 131 | 132 | -- Stable pointers
|
| 132 | - , newStablePtr
|
|
| 133 | + , StablePtr, newStablePtr
|
|
| 133 | 134 | |
| 134 | 135 | -- Dynamic
|
| 135 | 136 | , toDyn
|
| 136 | 137 | |
| 138 | + -- Run Top Handler (Note [Dealing with main])
|
|
| 139 | + , runMainIO
|
|
| 140 | + |
|
| 137 | 141 | -- Names that have BuiltinRules
|
| 138 | 142 | , CS.unpackFoldrCString#, CS.unpackFoldrCStringUtf8#, CS.unpackAppendCString#
|
| 139 | 143 | , CS.unpackAppendCStringUtf8#, CS.cstringLength#
|
| ... | ... | @@ -236,6 +240,7 @@ import GHC.Internal.TypeError( Unsatisfiable, unsatisfiable ) |
| 236 | 240 | import GHC.Internal.System.IO( print )
|
| 237 | 241 | import qualified GHC.Internal.IsList as IL
|
| 238 | 242 | import GHC.Internal.Err( error )
|
| 243 | +import GHC.Internal.IO.Exception( assertError )
|
|
| 239 | 244 | import GHC.Internal.Int( Int8(I8#), Int16(I16#), Int32(I32#), Int64(I64#) )
|
| 240 | 245 | import GHC.Internal.Word( Word8(W8#), Word16(W16#), Word32(W32#), Word64(W64#) )
|
| 241 | 246 | |
| ... | ... | @@ -244,7 +249,7 @@ import GHC.Internal.Unsafe.Coerce( UnsafeEquality(..), unsafeEqualityProof ) |
| 244 | 249 | import GHC.Internal.StaticPtr( IsStatic(..) )
|
| 245 | 250 | import GHC.Internal.StaticPtr.Internal( makeStatic )
|
| 246 | 251 | |
| 247 | -import GHC.Internal.Stable( newStablePtr )
|
|
| 252 | +import GHC.Internal.Stable( StablePtr, newStablePtr )
|
|
| 248 | 253 | import GHC.Internal.Data.Typeable( gcast1, gcast2 )
|
| 249 | 254 | import GHC.Internal.Data.Typeable.Internal as TR
|
| 250 | 255 | import GHC.Internal.Generics hiding( Fixity(..), prec )
|
| ... | ... | @@ -257,3 +262,4 @@ import GHC.Internal.TH.Syntax as TH |
| 257 | 262 | import GHC.Internal.TH.Lib
|
| 258 | 263 | import GHC.Internal.TH.Lift
|
| 259 | 264 | import GHC.Internal.TH.Monad
|
| 265 | +import GHC.Internal.TopHandler |
| ... | ... | @@ -43,7 +43,7 @@ import GHC.Internal.Foreign.Storable (Storable(..)) |
| 43 | 43 | import GHC.Internal.Enum (toEnum)
|
| 44 | 44 | import GHC.Internal.Num (Num(..))
|
| 45 | 45 | import GHC.Internal.Real (quotRem, fromIntegral)
|
| 46 | -import GHC.Internal.Show (Show(show))
|
|
| 46 | +import GHC.Internal.Show
|
|
| 47 | 47 | import GHC.Internal.Event.Internal (Timeout(..))
|
| 48 | 48 | import GHC.Internal.System.Posix.Internals (c_close,c_getpid)
|
| 49 | 49 | import GHC.Internal.System.Posix.Types (Fd(..), CPid)
|