[Git][ghc/ghc][wip/spj-reinstallable-base2] 2 commits: kill basicknownkeynames
Rodrigo Mesquita pushed to branch wip/spj-reinstallable-base2 at Glasgow Haskell Compiler / GHC Commits: d068471a by Rodrigo Mesquita at 2026-05-12T16:00:01+01:00 kill basicknownkeynames - - - - - 261d1946 by Rodrigo Mesquita at 2026-05-12T16:49:58+01:00 deletions, notes fixups, improv - - - - - 10 changed files: - compiler/GHC/Builtin.hs - compiler/GHC/Builtin/KnownKeys.hs - compiler/GHC/Builtin/KnownOccs.hs - compiler/GHC/Builtin/TH.hs - compiler/GHC/HsToCore.hs - compiler/GHC/Iface/Binary.hs - compiler/GHC/Tc/Utils/Env.hs - compiler/GHC/Unit.hs - compiler/GHC/Unit/Types.hs - libraries/ghc-internal/src/GHC/Internal/Classes/IP.hs Changes: ===================================== compiler/GHC/Builtin.hs ===================================== @@ -22,7 +22,7 @@ module GHC.Builtin ( -- * Main exports - wiredInNames, wiredInIds, ghcPrimIds, allKnownOccs, + wiredInNames, wiredInIds, ghcPrimIds, knownKeyTable, knownKeyOccMap, knownKeyUniqMap, knownKeyOccName, knownKeyOccName_maybe, @@ -53,9 +53,7 @@ import GHC.Builtin.WiredIn.Types import GHC.Builtin.WiredIn.TypeLits ( typeNatTyCons ) import GHC.Builtin.WiredIn.Ids ( wiredInIds, ghcPrimIds ) import GHC.Builtin.WiredIn.Prim -import GHC.Builtin.TH ( templateHaskellNames, thKnownOccs ) import GHC.Builtin.KnownKeys -import GHC.Builtin.KnownOccs( knownOccs, knownOccRdrNames ) import GHC.Core.ConLike ( ConLike(..) ) import GHC.Core.DataCon @@ -64,7 +62,6 @@ import GHC.Core.TyCon import GHC.Types.Id import GHC.Types.Name -import GHC.Types.Name.Reader( rdrNameOcc ) import GHC.Types.Name.Env import GHC.Types.Unique import GHC.Types.Unique.FM @@ -419,15 +416,6 @@ To make `wombat` into a known-key name, do the following. in scope by saying `import M( wombat )`. -} -allKnownOccs :: OccSet --- Used only for --- (a) sanity checks --- (b) suppressing unused-import warnings in `ghc-internal` and `base` -allKnownOccs - = mkOccSet thKnownOccs `unionOccSets` - mkOccSet knownOccs `unionOccSets` - mkOccSet (map rdrNameOcc knownOccRdrNames) - {- ************************************************************************ * * @@ -565,10 +553,6 @@ wiredInNames , map (idName . primOpWrapperId) allThePrimOps -- Actually the primop wrapper Ids have External Names, not WiredIn, -- but we still want to populate the OrigNameCache with them - - -- ToDo: get rid of these - , basicKnownKeyNames - , templateHaskellNames ] -- All of the names associated with a wired-in TyCon. -- This includes the TyCon itself, its DataCons and promoted TyCons. ===================================== compiler/GHC/Builtin/KnownKeys.hs ===================================== @@ -24,52 +24,6 @@ the big-num package or (for plugins) the ghc package. It's not necessary to know the uniques for these guys, only their names -Note [Known-key names] <---- LEGACY VERSION -~~~~~~~~~~~~~~~~~~~~~~ -It is *very* important that the compiler gives wired-in things and -things with "known-key" names the correct Uniques wherever they -occur. We have to be careful about this in exactly two places: - - 1. When we parse some source code, renaming the AST better yield an - AST whose Names have the correct uniques - - 2. When we read an interface file, the read-in gubbins better have - the right uniques - -This is accomplished through a combination of mechanisms: - - 1. When parsing source code, the RdrName-decorated AST has some - RdrNames which are Exact. These are wired-in RdrNames where - we could directly tell from the parsed syntax what Name to - use. For example, when we parse a [] in a type and ListTuplePuns - are enabled, we can just insert (Exact listTyConName :: RdrName). - - This is just an optimisation: it would be equally valid to output - Orig RdrNames that correctly record the module (and package) that - we expect the final Name to come from. The name would be looked up - in the OrigNameCache (see point 3). - - 2. The knownKeyNames (which consist of the basicKnownKeyNames from - the module, and those names reachable via the wired-in stuff from - GHC.Builtin.Types) are used to initialise the "OrigNameCache" in - GHC.Iface.Env. This initialization ensures that when the type checker - or renamer (both of which use GHC.Iface.Env) look up an original name - (i.e. a pair of a Module and an OccName) for a known-key name - they get the correct Unique. - - This is the most important mechanism for ensuring that known-key - stuff gets the right Unique, and is why it is so important to - place your known-key names in the appropriate lists. - - 3. For "infinite families" of known-key names (i.e. tuples and sums), we - have to be extra careful. Because there are an infinite number of - these things, we cannot add them to the list of known-key names - used to initialise the OrigNameCache. Instead, lookupOrigNameCache pretends - that these names are in the cache by using isInfiniteFamilyOrigName_maybe - before the actual lookup. - See Note [Infinite families of known-key names] for details. - - Note [Infinite families of known-key names] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Infinite families of known-key things (e.g. tuples and sums) pose a tricky @@ -109,7 +63,6 @@ import GHC.Prelude import GHC.Builtin.Modules import GHC.Builtin.Uniques -import GHC.Builtin.TH( thKnownKeyTable ) import GHC.Unit.Types @@ -169,8 +122,7 @@ See Note [Overview of known entities] in GHC.Builtin knownKeyTable :: [(OccName, KnownKey)] knownKeyTable - = thKnownKeyTable ++ - [ (mkTcOcc "IO", ioTyConKey) + = [ (mkTcOcc "IO", ioTyConKey) -- Classes , (mkTcOcc "Eq", eqClassKey) @@ -185,7 +137,8 @@ knownKeyTable , (mkTcOcc "Ix", ixClassKey) , (mkTcOcc "Alternative", alternativeClassKey) , (mkTcOcc "Typeable", typeableClassKey) - , (mkTcOcc "Functor", functorClassKey) + , (mkTcOcc "Functor", functorClassKey) + , (mkTcOcc "Lift", liftClassKey) -- Numeric classes , (mkTcOcc "Num", numClassKey) @@ -368,11 +321,6 @@ knownKeyTable , (mkVarOcc "integerShiftR#", integerShiftRIdKey) ] -basicKnownKeyNames :: [Name] -- See Note [Known-key names] -basicKnownKeyNames - = [ - ] - {- ************************************************************************ @@ -791,6 +739,9 @@ multMulTyConKey = mkPreludeTyConUnique 199 -- GHC.Builtin.TH: USES TyConUniques 200-299 ----------------------------------------------------- +liftClassKey :: Unique +liftClassKey = mkPreludeClassUnique 200 + ----------------------- SIMD ------------------------ -- USES TyConUniques 300-399 ----------------------------------------------------- ===================================== compiler/GHC/Builtin/KnownOccs.hs ===================================== @@ -122,31 +122,6 @@ primOpRdrName op = getRdrName (primOpId op) * * ********************************************************************* -} -knownOccs :: [KnownOcc] --- Used only for sanity-checks --- Sadly incomplete .. is it worth it? See fromEnum_REDR etc.... -knownOccs - = [ composeIdOcc - , rationalTyConOcc - - -- Enum class ops - , enumFromClassOpOcc, enumFromThenClassOpOcc - , enumFromToClassOpOcc, enumFromThenToClassOpOcc - - -- Static - , fromStaticPtrClassOpOcc - - -- Typeable stuff - , someTypeRepTyConOcc, someTypeRepDataConOcc, mkTrConOcc, mkTrAppCheckedOcc - , mkTrFunOcc, typeRepIdOcc, typeNatTypeRepOcc, typeSymbolTypeRepOcc - , typeCharTypeRepOcc, typeLitSymbolDataConOcc, typeLitNatDataConOcc - , typeLitCharDataConOcc - , trModuleTyConOcc, trModuleDataConOcc, trNameSDataConOcc, trTyConTyConOcc - , trTyConDataConOcc, kindRepTyConOcc, kindRepTyConAppDataConOcc, kindRepVarDataConOcc - , kindRepAppDataConOcc, kindRepFunDataConOcc, kindRepTypeDataConOcc - , kindRepTypeLitSDataConOcc - ] - eqClassOpOcc, negateClassOpOcc, minusClassOpOcc, geClassOpOcc, toListClassOpOcc, fromListNClassOpOcc, fromListClassOpOcc, fromLabelClassOpOcc, setFieldClassOpOcc, fromStringClassOpOcc :: KnownOcc @@ -355,18 +330,6 @@ emptyExceptionContextIdOcc = mkVarOcc "emptyExceptionContext" * * ********************************************************************* -} -knownOccRdrNames :: [RdrName] -knownOccRdrNames - = [ toDyn_RDR, compose_RDR - , appE_RDR, lift_RDR, liftTyped_RDR - , enumFrom_RDR, enumFromTo_RDR, enumFromThen_RDR, enumFromThenTo_RDR - , fromEnum_RDR, toEnum_RDR, toEnumError_RDR, succError_RDR - , predError_RDR, enumIntToWord_RDR, succ_RDR, pred_RDR - , minBound_RDR, maxBound_RDR - , times_RDR, plus_RDR, and_RDR, not_RDR, range_RDR, inRange_RDR, index_RDR - , unsafeIndex_RDR, unsafeRangeSize_RDR - ] - main_RDR_Unqual :: RdrName main_RDR_Unqual = mkUnqual varName (fsLit "main") -- We definitely don't want an Orig RdrName, because ===================================== compiler/GHC/Builtin/TH.hs ===================================== @@ -9,7 +9,7 @@ module GHC.Builtin.TH where import GHC.Prelude () import GHC.Unit.Types -import GHC.Types.Name( Name, KnownOcc, KnownKey, mk_known_key_name ) +import GHC.Types.Name( Name, KnownOcc, mk_known_key_name ) import GHC.Types.Name.Occurrence import GHC.Types.Unique ( Unique ) import GHC.Builtin.Uniques @@ -17,143 +17,6 @@ import GHC.Data.FastString import Language.Haskell.Syntax.Module.Name -thKnownKeyTable :: [(OccName, KnownKey)] -thKnownKeyTable - = [ (liftClassOcc, liftClassKey) - ] - -thKnownOccs :: [KnownOcc] -thKnownOccs - = [ qTyConOcc, nameTyConOcc, fieldExpTyConOcc, patTyConOcc - , fieldPatTyConOcc, expTyConOcc, decTyConOcc, typeTyConOcc - , matchTyConOcc, clauseTyConOcc, funDepTyConOcc, predTyConOcc - , codeTyConOcc, injAnnTyConOcc, overlapTyConOcc, decsTyConOcc - , modNameTyConOcc, quasiQuoterTyConOcc - , liftIdOcc, unsafeCodeCoerceOcc - , charLOcc, stringLOcc, integerLOcc, intPrimLOcc, wordPrimLOcc - , floatPrimLOcc, doublePrimLOcc, rationalLOcc, stringPrimLOcc - , charPrimLOcc - , litPOcc, varPOcc, tupPOcc, unboxedTupPOcc, unboxedSumPOcc, conPOcc - , infixPOcc, tildePOcc, bangPOcc, asPOcc, wildPOcc, recPOcc, listPOcc - , sigPOcc, viewPOcc, typePOcc, invisPOcc, orPOcc - , matchOcc, fieldPatOcc, clauseOcc - , varEOcc, conEOcc, litEOcc, appEOcc, appTypeEOcc, infixEOcc, infixAppOcc - , sectionLOcc, sectionROcc, lamEOcc, lamCaseEOcc, lamCasesEOcc, tupEOcc - , unboxedTupEOcc, unboxedSumEOcc, condEOcc, multiIfEOcc, letEOcc - , caseEOcc, doEOcc, mdoEOcc, compEOcc, staticEOcc, unboundVarEOcc - , labelEOcc, implicitParamVarEOcc, getFieldEOcc, projectionEOcc, typeEOcc - , forallEOcc, forallVisEOcc, constrainedEOcc - , fieldExpOcc - , funDOcc, valDOcc, dataDOcc, newtypeDOcc, typeDataDOcc, tySynDOcc, classDOcc - , instanceWithOverlapDOcc, sigDOcc, kiSigDOcc, forImpDOcc, pragInlDOcc - , pragSpecDOcc, pragSpecInlDOcc, pragSpecEDOcc, pragSpecInlEDOcc - , pragSpecInstDOcc, pragRuleDOcc - , pragAnnDOcc, pragSCCFunDOcc, pragSCCFunNamedDOcc - , standaloneDerivWithStrategyDOcc, defaultSigDOcc, defaultDOcc - , dataInstDOcc, newtypeInstDOcc, tySynInstDOcc, dataFamilyDOcc - , openTypeFamilyDOcc, closedTypeFamilyDOcc, infixLWithSpecDOcc - , infixRWithSpecDOcc, infixNWithSpecDOcc, roleAnnotDOcc, patSynDOcc - , patSynSigDOcc, pragCompleteDOcc, implicitParamBindDOcc, pragOpaqueDOcc - , patQTyConOcc, expQTyConOcc, stmtTyConOcc, conTyConOcc, bangTypeTyConOcc - , varBangTypeTyConOcc, typeQTyConOcc, decsQTyConOcc, ruleBndrTyConOcc - , tySynEqnTyConOcc, roleTyConOcc, derivClauseTyConOcc, kindTyConOcc - , tyVarBndrUnitTyConOcc, tyVarBndrSpecTyConOcc, tyVarBndrVisTyConOcc - , derivStrategyTyConOcc - , guardedBOcc, normalBOcc - , normalGEOcc, patGEOcc - , bindSOcc, letSOcc, noBindSOcc, parSOcc, recSOcc - ] - -templateHaskellNames :: [Name] --- The names that are implicitly mentioned by ``bracket'' --- Should stay in sync with the import list of GHC.HsToCore.Quote - -templateHaskellNames = [ - newNameName, - mkNameName, mkNameG_vName, mkNameG_dName, mkNameG_tcName, mkNameG_fldName, - mkNameLName, - mkNameSName, mkNameQName, - mkModNameName, - unTypeName, unTypeCodeName, - - -- Cxt - cxtName, - - -- SourceUnpackedness - noSourceUnpackednessName, sourceNoUnpackName, sourceUnpackName, - -- SourceStrictness - noSourceStrictnessName, sourceLazyName, sourceStrictName, - -- Con - normalCName, recCName, infixCName, forallCName, gadtCName, recGadtCName, - -- Bang - bangName, - -- BangType - bangTypeName, - -- VarBangType - varBangTypeName, - -- PatSynDir (for pattern synonyms) - unidirPatSynName, implBidirPatSynName, explBidirPatSynName, - -- PatSynArgs (for pattern synonyms) - prefixPatSynName, infixPatSynName, recordPatSynName, - -- Type - forallTName, forallVisTName, varTName, conTName, infixTName, appTName, - appKindTName, equalityTName, tupleTName, unboxedTupleTName, - unboxedSumTName, arrowTName, mulArrowTName, listTName, sigTName, litTName, - promotedTName, promotedTupleTName, promotedNilTName, promotedConsTName, - wildCardTName, implicitParamTName, - -- TyLit - numTyLitName, strTyLitName, charTyLitName, - -- TyVarBndr - plainTVName, kindedTVName, - plainInvisTVName, kindedInvisTVName, - plainBndrTVName, kindedBndrTVName, - -- Specificity - specifiedSpecName, inferredSpecName, - -- Visibility - bndrReqName, bndrInvisName, - -- Role - nominalRName, representationalRName, phantomRName, inferRName, - -- Kind - starKName, constraintKName, - -- FamilyResultSig - noSigName, kindSigName, tyVarSigName, - -- InjectivityAnn - injectivityAnnName, - -- Callconv - cCallName, stdCallName, cApiCallName, primCallName, javaScriptCallName, - -- Safety - unsafeName, - safeName, - interruptibleName, - -- Inline - noInlineDataConName, inlineDataConName, inlinableDataConName, - -- RuleMatch - conLikeDataConName, funLikeDataConName, - -- Phases - allPhasesDataConName, fromPhaseDataConName, beforePhaseDataConName, - -- Overlap - overlappableDataConName, overlappingDataConName, overlapsDataConName, - incoherentDataConName, - -- NamespaceSpecifier - noNamespaceSpecifierDataConName, typeNamespaceSpecifierDataConName, - dataNamespaceSpecifierDataConName, - -- DerivStrategy - stockStrategyName, anyclassStrategyName, - newtypeStrategyName, viaStrategyName, - -- RuleBndr - ruleVarName, typedRuleVarName, - -- FunDep - funDepName, - -- TySynEqn - tySynEqnName, - -- AnnTarget - valueAnnotationName, typeAnnotationName, moduleAnnotationName, - -- DerivClause - derivClauseName, - - -- Quasiquoting - quoteDecName, quoteTypeName, quoteExpName, quotePatName] - thSyn, thMonad, thLib, qqLib, liftLib :: Module thSyn = mkTHModule (fsLit "GHC.Internal.TH.Syntax") thMonad = mkTHModule (fsLit "GHC.Internal.TH.Monad") @@ -183,8 +46,7 @@ qqFld :: FastString -> Unique -> Name qqFld = mk_known_key_name (fieldName (fsLit "QuasiQuoter")) qqLib -------------------- TH.Syntax ----------------------- -liftClassOcc, quoteClassOcc :: KnownOcc -liftClassOcc = mkTcOcc "Lift" +quoteClassOcc :: KnownOcc quoteClassOcc = mkTcOcc "Quote" qTyConOcc, nameTyConOcc, fieldExpTyConOcc, patTyConOcc, @@ -664,9 +526,6 @@ dataNamespaceSpecifierDataConName = liftClassKey :: Unique liftClassKey = mkPreludeClassUnique 200 -quoteClassKey :: Unique -quoteClassKey = mkPreludeClassUnique 201 - {- ********************************************************************* * * TyCon keys ===================================== compiler/GHC/HsToCore.hs ===================================== @@ -719,21 +719,21 @@ moduleHasMagicDefn :: DsM Bool moduleHasMagicDefn = do env <- getGblEnv this_mod <- getModule - -- Look for the magic names in scope. If found, check if this is the defining - -- module. Otherwise, it definitely isn't the defining module. - let - kes = KES_InScope { ke_mod = ds_mod env - , ke_rdr_env = ds_gbl_rdr_env env - , ke_gbl_type_env = ds_type_env env - , ke_lcl_type_env = emptyNameEnv } - definesMagicName magicKey = do - mb_res <- lookupKnownKeyName magicKey kes - case mb_res of - Succeeded name -> return (nameModule name == this_mod) - Failed _ -> return False - dfns_magic <- setEnvs (ds_if_env env) $ - mapM (definesMagicName . fst) magicDefns - pure $ any id dfns_magic + -- If module -fdefines-known-key-names, look for the magic names in scope and + -- check if this module is the magic name's module. If module doesn't + -- -fdefines-known-key-names, it certainly doesn't define magic names. + kksource <- dsGetKnownKeySource + case kksource of + KES_FromModule -> return False + kes@KES_InScope{} -> do + let definesMagicName magicKey = do + mb_res <- lookupKnownKeyName magicKey kes + case mb_res of + Succeeded name -> return (nameModule name == this_mod) + Failed _ -> return False + dfns_magic <- setEnvs (ds_if_env env) $ + mapM (definesMagicName . fst) magicDefns + pure $ any id dfns_magic mkUnsafeCoercePrimPair :: Id -> CoreExpr -> DsM (Id, CoreExpr) -- See Note [Wiring in unsafeCoerce#] for the defn we are creating here ===================================== compiler/GHC/Iface/Binary.hs ===================================== @@ -703,6 +703,12 @@ getSymbolTable bh name_cache ; writeArray mut_arr (fromIntegral i) name ; return new_cache } +-- ROMES:TODO: KILL THIS from here to the end. +-- We no longer put uniques for known-occ names anymore, they'll be looked up +-- in the table. +-- No uniques in interface files! + + -- Note [Symbol table representation of names] -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -- An occurrence of a name in an interface file is serialized as a single 32-bit ===================================== compiler/GHC/Tc/Utils/Env.hs ===================================== @@ -1128,7 +1128,7 @@ tcGetDefaultTys ; user_defaults <- getDeclaredDefaultTys -- User-supplied defaults ; this_module <- tcg_mod <$> getGblEnv ; let this_unit = moduleUnit this_module - ; if this_unit == ghcInternalUnit + ; if this_unit == ghcInternalUnit -- if we wanted, this needn't be about ghc-internal -- see Remark [No built-in defaults in ghc-internal] -- in Note [Builtin class defaults] in GHC.Tc.Utils.Env then return (user_defaults, extended_defaults) ===================================== compiler/GHC/Unit.hs ===================================== @@ -59,16 +59,19 @@ UnitIds are important because they are used to generate internal names Wired-in units -------------- -Certain libraries (ghc-prim, base, etc.) are known to the compiler and to the -RTS as they provide some basic primitives. Hence UnitIds of wired-in libraries -are fixed. Instead of letting Cabal choose the UnitId for these libraries, their -.cabal file uses the following stanza to force it to a specific value: +Wired-in names have wired-in modules, which have a wired-in unit-id. +Wired-in unit-ids, such as ghc-internal and the RTS, must be known to the +compiler, as they provide some basic primitives. - ghc-options: -this-unit-id ghc-prim -- taken from ghc-prim.cabal +Hence wired-in unit-ids are fixed. Instead of letting Cabal choose +the UnitId for these libraries, their .cabal file uses the following stanza to +force it to a specific value: -The RTS also uses entities of wired-in units by directly referring to symbols -such as "base_GHCziIOziException_heapOverflow_closure" where the prefix is -the UnitId of "base" unit. + ghc-options: -this-unit-id ghc-internal -- taken from ghc-internal.cabal + +The RTS also uses entities of wired-in units by referring to symbols such as +"ghczminternal_GHCziInternalziTopHandler_runIO_closure" where the prefix is the +UnitId of "ghc-internal" unit (see Note [RTS/ghc-internal interface]). Unit databases -------------- ===================================== compiler/GHC/Unit/Types.hs ===================================== @@ -590,7 +590,7 @@ ghcInternalUnitId, rtsUnitId, ghcInternalUnit, rtsUnit, mainUnit, thisGhcUnit, interactiveUnit, interactiveGhciUnit, interactiveSessionUnit :: Unit -ghcInternalUnitId = UnitId (fsLit "ghc-internal") +ghcInternalUnitId = UnitId (fsLit "ghc-internal") -- See Note [About units], section "Wired-in units" rtsUnitId = UnitId (fsLit "rts") thisGhcUnitId = UnitId (fsLit cProjectUnitId) -- See Note [GHC's Unit Id] interactiveUnitId = UnitId (fsLit "interactive") ===================================== libraries/ghc-internal/src/GHC/Internal/Classes/IP.hs ===================================== @@ -25,7 +25,7 @@ -- ----------------------------------------------------------------------------- -module GHC.Internal.Classes.IP( IP(..)) where +module GHC.Internal.Classes.IP( IP(..) ) where import GHC.Internal.Types View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/6126f492574be3f452b82da20468e32... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/compare/6126f492574be3f452b82da20468e32... You're receiving this email because of your account on gitlab.haskell.org.
participants (1)
-
Rodrigo Mesquita (@alt-romes)