Simon Peyton Jones pushed to branch wip/spj-reinstallable-base at Glasgow Haskell Compiler / GHC Commits: 4058ad0b by Simon Peyton Jones at 2026-03-20T00:19:21+00:00 More.. [skip ci] - - - - - 10 changed files: - compiler/GHC/Builtin/Names.hs - compiler/GHC/Builtin/Types.hs - compiler/GHC/Builtin/Utils.hs - compiler/GHC/Iface/Binary.hs - compiler/GHC/Iface/Load.hs - compiler/GHC/Rename/Names.hs - compiler/GHC/Tc/Errors/Hole.hs - compiler/GHC/Types/Name.hs - compiler/GHC/Types/Name/Cache.hs - libraries/base/src/GHC/Weak/Finalize.hs Changes: ===================================== compiler/GHC/Builtin/Names.hs ===================================== @@ -86,7 +86,7 @@ This is accomplished through a combination of mechanisms: Note [Infinite families of known-key names] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Infinite families of known-key things (e.g. tuples and sums) pose a tricky -problem: we can't add them to the knownKeyNames finite map which we use to +problem: we can't add them to the wiredInNames finite map which we use to ensure that, e.g., a reference to (,) gets assigned the right unique (if this doesn't sound familiar see Note [Known-key names] above). ===================================== compiler/GHC/Builtin/Types.hs ===================================== @@ -284,7 +284,7 @@ names in GHC.Builtin.Names, so they use wTcQual, wDataQual, etc -} --- This list is used only to define GHC.Builtin.Utils.knownKeyNames. That in turn +-- This list is used only to define GHC.Builtin.Utils.wiredInNames. That in turn -- is used to initialise the name environment carried around by the renamer. -- This means that if we look up the name of a TyCon (or its implicit binders) -- that occurs in this list that name will be assigned the wired-in key we ===================================== compiler/GHC/Builtin/Utils.hs ===================================== @@ -23,14 +23,9 @@ module GHC.Builtin.Utils ( oldLookupKnownKeyName, oldLookupKnownNameInfo, - -- ** Internal use - -- | 'knownKeyNames' is exported to seed the original name cache only; - -- if you find yourself wanting to look at it you might consider using - -- 'lookupKnownKeyName' or 'isKnownKeyName'. - knownKeyNames, -- * Miscellaneous - wiredInIds, ghcPrimIds, + wiredInNames, wiredInIds, ghcPrimIds, ghcPrimExports, ghcPrimDeclDocs, @@ -118,9 +113,9 @@ Note [About wired-in things] -- | This list is used to ensure that when you say "Prelude.map" in your source -- code, or in an interface file, you get a Name with the correct known key (See -- Note [Known-key names] in "GHC.Builtin.Names") -knownKeyNames :: [Name] +wiredInNames :: [Name] -- ToDo: rename to wiredInNames -knownKeyNames +wiredInNames | debugIsOn , Just badNamesDoc <- knownKeyNamesOkay all_names = pprPanic "badAllKnownKeyNames" badNamesDoc @@ -214,7 +209,7 @@ oldIsKnownKeyName n = -- in the domain are 'Unique's associated with 'Name's (as opposed -- to some other namespace of 'Unique's). oldKnownKeysMap :: UniqFM Name Name -oldKnownKeysMap = listToIdentityUFM knownKeyNames +oldKnownKeysMap = listToIdentityUFM wiredInNames -- | Given a 'Unique' lookup any associated arbitrary SDoc's to be displayed by -- GHCi's ':info' command. ===================================== compiler/GHC/Iface/Binary.hs ===================================== @@ -714,7 +714,7 @@ serialiseName bh name _ -- all known-key uniques fit in this space. This is asserted by -- GHC.Builtin.Utils.knownKeyNamesOkay. -- --- During serialization we check for known-key things using isKnownKeyName. +-- During serialization we check for known-key things using oldIsKnownKeyName. -- During deserialization we use lookupKnownKeyName to get from the unique back -- to its corresponding Name. ===================================== compiler/GHC/Iface/Load.hs ===================================== @@ -64,7 +64,7 @@ import GHC.Iface.Binary import GHC.Iface.Rename import GHC.Iface.Env import GHC.Iface.Errors as Iface_Errors -import GHC.Iface.Errors.Ppr( defaultIfaceMessageOpts ) +import GHC.Iface.Errors.Ppr( defaultIfaceMessageOpts, missingInterfaceErrorDiagnostic ) import GHC.Tc.Errors.Types import GHC.Tc.Utils.Monad @@ -190,7 +190,7 @@ loadKnownKeyOccMap ; mb_res <- liftIO $ findImportedModule hsc_env kNOWN_KEY_NAMES NoPkgQual ; iface <- case mb_res of Found _ mod -> loadInterfaceWithException doc mod ImportBySystem - fr -> do { hsc_env <- getHscEnv + fr -> do { hsc_env <- getTopEnv ; pprPanic "loadKnownKeyOccMap" $ missingInterfaceErrorDiagnostic defaultIfaceMessageOpts $ cannotFindModule hsc_env kNOWN_KEY_NAMES fr } ===================================== compiler/GHC/Rename/Names.hs ===================================== @@ -1951,8 +1951,9 @@ warnUnusedImportDecls gbl_env hsc_src -- We should only warn for unnecessary *user* imports, but deciding -- minimal imports should take generated imports into account - ; let usageUserImports = findImportUsage (excludeGenerated imports) uses - usageAllImports = findImportUsage imports uses + ; rb <- goptM Opt_RebindableKnownKeyNames + ; let usageUserImports = findImportUsage rb (excludeGenerated imports) uses + usageAllImports = findImportUsage rb imports uses ; traceRn "warnUnusedImportDecls" $ (vcat [ text "Uses:" <+> ppr uses @@ -1968,11 +1969,12 @@ warnUnusedImportDecls gbl_env hsc_src excludeGenerated :: [LImportDecl GhcRn] -> [LImportDecl GhcRn] excludeGenerated = filterOut (ideclGenerated . ideclExt . unLoc) -findImportUsage :: [LImportDecl GhcRn] +findImportUsage :: Bool -- True <=> Opt_RebindableKnownKeyNames is on + -> [LImportDecl GhcRn] -> [GlobalRdrElt] -> [ImportDeclUsage] -findImportUsage imports used_gres +findImportUsage rebindable_known_key_names imports used_gres = map unused_decl imports where import_usage :: ImportMap @@ -2021,6 +2023,13 @@ findImportUsage imports used_gres in UnusedNames acc_ns acc_wcs acc_fs' | used = acc + + -- -frebindable-known-key-names is on, and `n` is a known-key name + -- Then don't warn about an unused imports. + | rebindable_known_key_names + , isKnownKeyName n + = acc + | otherwise = UnusedNames (acc_ns `extendNameSet` n) acc_wcs acc_fs where ===================================== compiler/GHC/Tc/Errors/Hole.hs ===================================== @@ -681,7 +681,7 @@ findValidHoleFits tidy_env implics simples h@(Hole { hole_sort = ExprHole _ -- BuiltInSyntax names like (:) and [] builtIns :: EnumSet LangExt.Extension -> [Name] - builtIns exts = filter isBuiltInSyntax (knownKeyNames ++ infFamNames) + builtIns exts = filter isBuiltInSyntax (wiredInNames ++ infFamNames) where -- Tuples and sums of are not included in knownKeyName as there are infinitely many of them. -- See Note [Infinite families of known-key names] in GHC.Builtin.Names. ===================================== compiler/GHC/Types/Name.hs ===================================== @@ -69,7 +69,7 @@ module GHC.Types.Name ( isTyVarName, isTyConName, isDataConName, isValName, isVarName, isDynLinkName, isFieldName, isWiredInName, isWiredIn, isBuiltInSyntax, isTupleTyConName, - isKnownKeyName', isKnownKey, + isKnownKeyName, isKnownKey, isSumTyConName, isUnboxedTupleDataConLikeName, isHoleName, @@ -135,7 +135,7 @@ There are several reasons that GHC might want to refer to a known-key Name: * When desugaring, the desugarer wants to refer to a particular class, type, or function. It does this via (e.g.) - dsLookupTyKnownKeyTyCon :: Unique -> DsM TyCon + dsLookupKnownKeyTyCon :: Unique -> DsM TyCon * In a very similar way, for type-class defauting GHC has built-in defaulting behaviour for Num, IsString, etc. It gets hold of these classes via their known key, via @@ -184,7 +184,9 @@ To implement all this, here are the moving parts: -frebindable-known-key-names -fdefines-known-key-names -* When processing source code, /without/ -frebindable +* Suppose the desugarer calls `dsLookupKnownKeyTyCon` on `rationalTyConKey`. + * In client source code, that is, /without/ -frebindable-known-key-names, + we try to import GHC.KnownKeyNames. Assuming this is succesful, Note [About the NameSorts] ~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -394,20 +396,19 @@ isInternalName :: Name -> Bool isExternalName :: Name -> Bool isSystemName :: Name -> Bool isWiredInName :: Name -> Bool -isKnownKeyName' :: Name -> Bool +isKnownKeyName :: Name -> Bool isWiredInName (Name {n_sort = WiredIn _ _ _}) = True isWiredInName _ = False --- TODO: disambiguate with builtin utils -isKnownKeyName' (Name {n_sort = KnownKey _}) = True -isKnownKeyName' _ = False +isKnownKeyName (Name {n_sort = KnownKey _}) = True +isKnownKeyName _ = False isWiredIn :: NamedThing thing => thing -> Bool isWiredIn = isWiredInName . getName isKnownKey :: NamedThing thing => thing -> Bool -isKnownKey = isKnownKeyName' . getName +isKnownKey = isKnownKeyName . getName wiredInNameTyThing_maybe :: Name -> Maybe TyThing wiredInNameTyThing_maybe (Name {n_sort = WiredIn _ thing _}) = Just thing ===================================== compiler/GHC/Types/Name/Cache.hs ===================================== @@ -91,7 +91,7 @@ So we deal with them in lookupOrigNameCache by means of isInfiniteFamilyOrigName At the same time, simple finite built-in names (`[]`, `:`, `->`) can be put in the OrigNameCache without any issues (they end up there because they're -knownKeyNames). It doesn't matter that they're built-in syntax. +wiredInNames). It doesn't matter that they're built-in syntax. One might wonder: what's the point of having any built-in syntax in the OrigNameCache at all? Good question; after all, @@ -200,7 +200,7 @@ updateNameCache name_cache !_mod !_occ upd_fn {-# NOINLINE knownKeysOrigNameCache #-} knownKeysOrigNameCache :: OrigNameCache -knownKeysOrigNameCache = initOrigNames knownKeyNames +knownKeysOrigNameCache = initOrigNames wiredInNames isKnownOrigName_maybe :: Module -> OccName -> Maybe Name isKnownOrigName_maybe = lookupOrigNameCache knownKeysOrigNameCache ===================================== libraries/base/src/GHC/Weak/Finalize.hs ===================================== @@ -21,6 +21,7 @@ import GHC.Internal.IO.Handle.Types (Handle) import GHC.Internal.IO.Handle.Text (hPutStrLn) import GHC.Internal.Prim (Array#, State#, RealWorld) import GHC.Internal.Types (Int, IO) +import GHC.Internal.Num( Num ) -- A necessary known-key name {-# DEPRECATED runFinalizerBatch View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4058ad0b6765f350dfe57bacef369d4a... -- View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/4058ad0b6765f350dfe57bacef369d4a... You're receiving this email because of your account on gitlab.haskell.org.