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
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:
| ... | ... | @@ -86,7 +86,7 @@ This is accomplished through a combination of mechanisms: |
| 86 | 86 | Note [Infinite families of known-key names]
|
| 87 | 87 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| 88 | 88 | Infinite families of known-key things (e.g. tuples and sums) pose a tricky
|
| 89 | -problem: we can't add them to the knownKeyNames finite map which we use to
|
|
| 89 | +problem: we can't add them to the wiredInNames finite map which we use to
|
|
| 90 | 90 | ensure that, e.g., a reference to (,) gets assigned the right unique (if this
|
| 91 | 91 | doesn't sound familiar see Note [Known-key names] above).
|
| 92 | 92 |
| ... | ... | @@ -284,7 +284,7 @@ names in GHC.Builtin.Names, so they use wTcQual, wDataQual, etc |
| 284 | 284 | -}
|
| 285 | 285 | |
| 286 | 286 | |
| 287 | --- This list is used only to define GHC.Builtin.Utils.knownKeyNames. That in turn
|
|
| 287 | +-- This list is used only to define GHC.Builtin.Utils.wiredInNames. That in turn
|
|
| 288 | 288 | -- is used to initialise the name environment carried around by the renamer.
|
| 289 | 289 | -- This means that if we look up the name of a TyCon (or its implicit binders)
|
| 290 | 290 | -- that occurs in this list that name will be assigned the wired-in key we
|
| ... | ... | @@ -23,14 +23,9 @@ module GHC.Builtin.Utils ( |
| 23 | 23 | oldLookupKnownKeyName,
|
| 24 | 24 | oldLookupKnownNameInfo,
|
| 25 | 25 | |
| 26 | - -- ** Internal use
|
|
| 27 | - -- | 'knownKeyNames' is exported to seed the original name cache only;
|
|
| 28 | - -- if you find yourself wanting to look at it you might consider using
|
|
| 29 | - -- 'lookupKnownKeyName' or 'isKnownKeyName'.
|
|
| 30 | - knownKeyNames,
|
|
| 31 | 26 | |
| 32 | 27 | -- * Miscellaneous
|
| 33 | - wiredInIds, ghcPrimIds,
|
|
| 28 | + wiredInNames, wiredInIds, ghcPrimIds,
|
|
| 34 | 29 | |
| 35 | 30 | ghcPrimExports,
|
| 36 | 31 | ghcPrimDeclDocs,
|
| ... | ... | @@ -118,9 +113,9 @@ Note [About wired-in things] |
| 118 | 113 | -- | This list is used to ensure that when you say "Prelude.map" in your source
|
| 119 | 114 | -- code, or in an interface file, you get a Name with the correct known key (See
|
| 120 | 115 | -- Note [Known-key names] in "GHC.Builtin.Names")
|
| 121 | -knownKeyNames :: [Name]
|
|
| 116 | +wiredInNames :: [Name]
|
|
| 122 | 117 | -- ToDo: rename to wiredInNames
|
| 123 | -knownKeyNames
|
|
| 118 | +wiredInNames
|
|
| 124 | 119 | | debugIsOn
|
| 125 | 120 | , Just badNamesDoc <- knownKeyNamesOkay all_names
|
| 126 | 121 | = pprPanic "badAllKnownKeyNames" badNamesDoc
|
| ... | ... | @@ -214,7 +209,7 @@ oldIsKnownKeyName n = |
| 214 | 209 | -- in the domain are 'Unique's associated with 'Name's (as opposed
|
| 215 | 210 | -- to some other namespace of 'Unique's).
|
| 216 | 211 | oldKnownKeysMap :: UniqFM Name Name
|
| 217 | -oldKnownKeysMap = listToIdentityUFM knownKeyNames
|
|
| 212 | +oldKnownKeysMap = listToIdentityUFM wiredInNames
|
|
| 218 | 213 | |
| 219 | 214 | -- | Given a 'Unique' lookup any associated arbitrary SDoc's to be displayed by
|
| 220 | 215 | -- GHCi's ':info' command.
|
| ... | ... | @@ -714,7 +714,7 @@ serialiseName bh name _ |
| 714 | 714 | -- all known-key uniques fit in this space. This is asserted by
|
| 715 | 715 | -- GHC.Builtin.Utils.knownKeyNamesOkay.
|
| 716 | 716 | --
|
| 717 | --- During serialization we check for known-key things using isKnownKeyName.
|
|
| 717 | +-- During serialization we check for known-key things using oldIsKnownKeyName.
|
|
| 718 | 718 | -- During deserialization we use lookupKnownKeyName to get from the unique back
|
| 719 | 719 | -- to its corresponding Name.
|
| 720 | 720 |
| ... | ... | @@ -64,7 +64,7 @@ import GHC.Iface.Binary |
| 64 | 64 | import GHC.Iface.Rename
|
| 65 | 65 | import GHC.Iface.Env
|
| 66 | 66 | import GHC.Iface.Errors as Iface_Errors
|
| 67 | -import GHC.Iface.Errors.Ppr( defaultIfaceMessageOpts )
|
|
| 67 | +import GHC.Iface.Errors.Ppr( defaultIfaceMessageOpts, missingInterfaceErrorDiagnostic )
|
|
| 68 | 68 | import GHC.Tc.Errors.Types
|
| 69 | 69 | import GHC.Tc.Utils.Monad
|
| 70 | 70 | |
| ... | ... | @@ -190,7 +190,7 @@ loadKnownKeyOccMap |
| 190 | 190 | ; mb_res <- liftIO $ findImportedModule hsc_env kNOWN_KEY_NAMES NoPkgQual
|
| 191 | 191 | ; iface <- case mb_res of
|
| 192 | 192 | Found _ mod -> loadInterfaceWithException doc mod ImportBySystem
|
| 193 | - fr -> do { hsc_env <- getHscEnv
|
|
| 193 | + fr -> do { hsc_env <- getTopEnv
|
|
| 194 | 194 | ; pprPanic "loadKnownKeyOccMap" $
|
| 195 | 195 | missingInterfaceErrorDiagnostic defaultIfaceMessageOpts $
|
| 196 | 196 | cannotFindModule hsc_env kNOWN_KEY_NAMES fr }
|
| ... | ... | @@ -1951,8 +1951,9 @@ warnUnusedImportDecls gbl_env hsc_src |
| 1951 | 1951 | |
| 1952 | 1952 | -- We should only warn for unnecessary *user* imports, but deciding
|
| 1953 | 1953 | -- minimal imports should take generated imports into account
|
| 1954 | - ; let usageUserImports = findImportUsage (excludeGenerated imports) uses
|
|
| 1955 | - usageAllImports = findImportUsage imports uses
|
|
| 1954 | + ; rb <- goptM Opt_RebindableKnownKeyNames
|
|
| 1955 | + ; let usageUserImports = findImportUsage rb (excludeGenerated imports) uses
|
|
| 1956 | + usageAllImports = findImportUsage rb imports uses
|
|
| 1956 | 1957 | |
| 1957 | 1958 | ; traceRn "warnUnusedImportDecls" $
|
| 1958 | 1959 | (vcat [ text "Uses:" <+> ppr uses
|
| ... | ... | @@ -1968,11 +1969,12 @@ warnUnusedImportDecls gbl_env hsc_src |
| 1968 | 1969 | excludeGenerated :: [LImportDecl GhcRn] -> [LImportDecl GhcRn]
|
| 1969 | 1970 | excludeGenerated = filterOut (ideclGenerated . ideclExt . unLoc)
|
| 1970 | 1971 | |
| 1971 | -findImportUsage :: [LImportDecl GhcRn]
|
|
| 1972 | +findImportUsage :: Bool -- True <=> Opt_RebindableKnownKeyNames is on
|
|
| 1973 | + -> [LImportDecl GhcRn]
|
|
| 1972 | 1974 | -> [GlobalRdrElt]
|
| 1973 | 1975 | -> [ImportDeclUsage]
|
| 1974 | 1976 | |
| 1975 | -findImportUsage imports used_gres
|
|
| 1977 | +findImportUsage rebindable_known_key_names imports used_gres
|
|
| 1976 | 1978 | = map unused_decl imports
|
| 1977 | 1979 | where
|
| 1978 | 1980 | import_usage :: ImportMap
|
| ... | ... | @@ -2021,6 +2023,13 @@ findImportUsage imports used_gres |
| 2021 | 2023 | in UnusedNames acc_ns acc_wcs acc_fs'
|
| 2022 | 2024 | | used
|
| 2023 | 2025 | = acc
|
| 2026 | + |
|
| 2027 | + -- -frebindable-known-key-names is on, and `n` is a known-key name
|
|
| 2028 | + -- Then don't warn about an unused imports.
|
|
| 2029 | + | rebindable_known_key_names
|
|
| 2030 | + , isKnownKeyName n
|
|
| 2031 | + = acc
|
|
| 2032 | + |
|
| 2024 | 2033 | | otherwise
|
| 2025 | 2034 | = UnusedNames (acc_ns `extendNameSet` n) acc_wcs acc_fs
|
| 2026 | 2035 | where
|
| ... | ... | @@ -681,7 +681,7 @@ findValidHoleFits tidy_env implics simples h@(Hole { hole_sort = ExprHole _ |
| 681 | 681 | |
| 682 | 682 | -- BuiltInSyntax names like (:) and []
|
| 683 | 683 | builtIns :: EnumSet LangExt.Extension -> [Name]
|
| 684 | - builtIns exts = filter isBuiltInSyntax (knownKeyNames ++ infFamNames)
|
|
| 684 | + builtIns exts = filter isBuiltInSyntax (wiredInNames ++ infFamNames)
|
|
| 685 | 685 | where
|
| 686 | 686 | -- Tuples and sums of are not included in knownKeyName as there are infinitely many of them.
|
| 687 | 687 | -- See Note [Infinite families of known-key names] in GHC.Builtin.Names.
|
| ... | ... | @@ -69,7 +69,7 @@ module GHC.Types.Name ( |
| 69 | 69 | isTyVarName, isTyConName, isDataConName,
|
| 70 | 70 | isValName, isVarName, isDynLinkName, isFieldName,
|
| 71 | 71 | isWiredInName, isWiredIn, isBuiltInSyntax, isTupleTyConName,
|
| 72 | - isKnownKeyName', isKnownKey,
|
|
| 72 | + isKnownKeyName, isKnownKey,
|
|
| 73 | 73 | isSumTyConName,
|
| 74 | 74 | isUnboxedTupleDataConLikeName,
|
| 75 | 75 | isHoleName,
|
| ... | ... | @@ -135,7 +135,7 @@ There are several reasons that GHC might want to refer to a known-key Name: |
| 135 | 135 | |
| 136 | 136 | * When desugaring, the desugarer wants to refer to a particular
|
| 137 | 137 | class, type, or function. It does this via (e.g.)
|
| 138 | - dsLookupTyKnownKeyTyCon :: Unique -> DsM TyCon
|
|
| 138 | + dsLookupKnownKeyTyCon :: Unique -> DsM TyCon
|
|
| 139 | 139 | |
| 140 | 140 | * In a very similar way, for type-class defauting GHC has built-in defaulting behaviour
|
| 141 | 141 | 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: |
| 184 | 184 | -frebindable-known-key-names
|
| 185 | 185 | -fdefines-known-key-names
|
| 186 | 186 | |
| 187 | -* When processing source code, /without/ -frebindable
|
|
| 187 | +* Suppose the desugarer calls `dsLookupKnownKeyTyCon` on `rationalTyConKey`.
|
|
| 188 | + * In client source code, that is, /without/ -frebindable-known-key-names,
|
|
| 189 | + we try to import GHC.KnownKeyNames. Assuming this is succesful,
|
|
| 188 | 190 | |
| 189 | 191 | Note [About the NameSorts]
|
| 190 | 192 | ~~~~~~~~~~~~~~~~~~~~~~~~~~
|
| ... | ... | @@ -394,20 +396,19 @@ isInternalName :: Name -> Bool |
| 394 | 396 | isExternalName :: Name -> Bool
|
| 395 | 397 | isSystemName :: Name -> Bool
|
| 396 | 398 | isWiredInName :: Name -> Bool
|
| 397 | -isKnownKeyName' :: Name -> Bool
|
|
| 399 | +isKnownKeyName :: Name -> Bool
|
|
| 398 | 400 | |
| 399 | 401 | isWiredInName (Name {n_sort = WiredIn _ _ _}) = True
|
| 400 | 402 | isWiredInName _ = False
|
| 401 | 403 | |
| 402 | --- TODO: disambiguate with builtin utils
|
|
| 403 | -isKnownKeyName' (Name {n_sort = KnownKey _}) = True
|
|
| 404 | -isKnownKeyName' _ = False
|
|
| 404 | +isKnownKeyName (Name {n_sort = KnownKey _}) = True
|
|
| 405 | +isKnownKeyName _ = False
|
|
| 405 | 406 | |
| 406 | 407 | isWiredIn :: NamedThing thing => thing -> Bool
|
| 407 | 408 | isWiredIn = isWiredInName . getName
|
| 408 | 409 | |
| 409 | 410 | isKnownKey :: NamedThing thing => thing -> Bool
|
| 410 | -isKnownKey = isKnownKeyName' . getName
|
|
| 411 | +isKnownKey = isKnownKeyName . getName
|
|
| 411 | 412 | |
| 412 | 413 | wiredInNameTyThing_maybe :: Name -> Maybe TyThing
|
| 413 | 414 | wiredInNameTyThing_maybe (Name {n_sort = WiredIn _ thing _}) = Just thing
|
| ... | ... | @@ -91,7 +91,7 @@ So we deal with them in lookupOrigNameCache by means of isInfiniteFamilyOrigName |
| 91 | 91 | |
| 92 | 92 | At the same time, simple finite built-in names (`[]`, `:`, `->`) can be put in
|
| 93 | 93 | the OrigNameCache without any issues (they end up there because they're
|
| 94 | -knownKeyNames). It doesn't matter that they're built-in syntax.
|
|
| 94 | +wiredInNames). It doesn't matter that they're built-in syntax.
|
|
| 95 | 95 | |
| 96 | 96 | One might wonder: what's the point of having any built-in syntax in the
|
| 97 | 97 | OrigNameCache at all? Good question; after all,
|
| ... | ... | @@ -200,7 +200,7 @@ updateNameCache name_cache !_mod !_occ upd_fn |
| 200 | 200 | |
| 201 | 201 | {-# NOINLINE knownKeysOrigNameCache #-}
|
| 202 | 202 | knownKeysOrigNameCache :: OrigNameCache
|
| 203 | -knownKeysOrigNameCache = initOrigNames knownKeyNames
|
|
| 203 | +knownKeysOrigNameCache = initOrigNames wiredInNames
|
|
| 204 | 204 | |
| 205 | 205 | isKnownOrigName_maybe :: Module -> OccName -> Maybe Name
|
| 206 | 206 | isKnownOrigName_maybe = lookupOrigNameCache knownKeysOrigNameCache |
| ... | ... | @@ -21,6 +21,7 @@ import GHC.Internal.IO.Handle.Types (Handle) |
| 21 | 21 | import GHC.Internal.IO.Handle.Text (hPutStrLn)
|
| 22 | 22 | import GHC.Internal.Prim (Array#, State#, RealWorld)
|
| 23 | 23 | import GHC.Internal.Types (Int, IO)
|
| 24 | +import GHC.Internal.Num( Num ) -- A necessary known-key name
|
|
| 24 | 25 | |
| 25 | 26 | |
| 26 | 27 | {-# DEPRECATED runFinalizerBatch
|