Simon Peyton Jones pushed to branch wip/spj-reinstallable-base at Glasgow Haskell Compiler / GHC
Commits:
-
6f8e976b
by Simon Peyton Jones at 2026-03-20T11:00:39+00:00
-
742099ce
by Simon Peyton Jones at 2026-03-20T12:46:27+00:00
22 changed files:
- compiler/GHC/Builtin/Names.hs
- compiler/GHC/Driver/Backpack.hs
- compiler/GHC/Driver/Downsweep.hs
- compiler/GHC/Driver/Pipeline/Execute.hs
- compiler/GHC/Parser/Header.hs
- compiler/GHC/Rename/Names.hs
- compiler/GHC/Tc/Utils/Env.hs
- compiler/GHC/Unit/Module/ModSummary.hs
- libraries/base/src/Control/Applicative.hs
- libraries/base/src/Data/Bool.hs
- libraries/base/src/Data/Enum.hs
- libraries/base/src/Data/List.hs
- libraries/base/src/Data/List/NubOrdSet.hs
- libraries/base/src/GHC/KnownKeyNames.hs
- libraries/base/src/GHC/RTS/Flags.hs
- libraries/base/src/GHC/Stats.hs
- libraries/base/src/System/Exit.hs
- libraries/base/src/System/IO/OS.hs
- libraries/ghc-internal/src/GHC/Internal/Data/String.hs
- libraries/ghc-prim/ghc-prim.cabal
- testsuite/tests/ghc-api/downsweep/PartialDownsweep.hs
- testsuite/tests/parser/should_fail/T16270h.hs
Changes:
| ... | ... | @@ -1637,8 +1637,8 @@ integralClassKey = mkPreludeClassUnique 7 |
| 1637 | 1637 | monadClassKey = mkPreludeClassUnique 8
|
| 1638 | 1638 | dataClassKey = mkPreludeClassUnique 9
|
| 1639 | 1639 | functorClassKey = mkPreludeClassUnique 10
|
| 1640 | -numClassKey = mkPreludeClassUnique 11
|
|
| 1641 | -ordClassKey = mkPreludeClassUnique 12
|
|
| 1640 | +numClassKey = mkPreludeClassUnique 11 -- 2b
|
|
| 1641 | +ordClassKey = mkPreludeClassUnique 12 -- 2c
|
|
| 1642 | 1642 | readClassKey = mkPreludeClassUnique 13
|
| 1643 | 1643 | realClassKey = mkPreludeClassUnique 14
|
| 1644 | 1644 | realFloatClassKey = mkPreludeClassUnique 15
|
| ... | ... | @@ -879,7 +879,7 @@ hsModuleToModSummary home_keys pn hsc_src modname |
| 879 | 879 | hi_timestamp <- liftIO $ modificationTimeIfExists (ml_hi_file_ospath location)
|
| 880 | 880 | hie_timestamp <- liftIO $ modificationTimeIfExists (ml_hie_file_ospath location)
|
| 881 | 881 | |
| 882 | - -- Also copied from 'getImports'
|
|
| 882 | + -- Also copied from 'getImportEdges'
|
|
| 883 | 883 | let (src_idecls, ord_idecls) = partition ((== IsBoot) . ideclSource . unLoc) imps
|
| 884 | 884 | |
| 885 | 885 | implicit_prelude = xopt LangExt.ImplicitPrelude dflags
|
| ... | ... | @@ -1536,10 +1536,7 @@ getPreprocessedImports hsc_env src_fn mb_phase maybe_buf = do |
| 1536 | 1536 | pi_hspp_buf <- liftIO $ hGetStringBuffer pi_hspp_fn
|
| 1537 | 1537 | (pi_srcimps', pi_theimps', L pi_mod_name_loc pi_mod_name)
|
| 1538 | 1538 | <- ExceptT $ do
|
| 1539 | - let imp_prelude = xopt LangExt.ImplicitPrelude pi_local_dflags
|
|
| 1540 | - popts = initParserOpts pi_local_dflags
|
|
| 1541 | - sec = initSourceErrorContext pi_local_dflags
|
|
| 1542 | - mimps <- getImports popts sec imp_prelude pi_hspp_buf pi_hspp_fn src_fn
|
|
| 1539 | + mimps <- getImportEdges pi_local_dflags pi_hspp_buf pi_hspp_fn src_fn
|
|
| 1543 | 1540 | return (first (mkMessages . fmap mkDriverPsHeaderMessage . getMessages) mimps)
|
| 1544 | 1541 | let rn_pkg_qual = renameRawPkgQual (hsc_unit_env hsc_env)
|
| 1545 | 1542 | let rn_imps = fmap (\(sp, pk, lmn@(L _ mn)) -> (sp, rn_pkg_qual mn pk, lmn))
|
| ... | ... | @@ -672,12 +672,10 @@ runHscPhase pipe_env hsc_env0 input_fn src_flavour = do |
| 672 | 672 | (hspp_buf,mod_name,imps,src_imps) <- do
|
| 673 | 673 | buf <- hGetStringBuffer input_fn
|
| 674 | 674 | -- TODO: handle implicit knownkey names here?
|
| 675 | - let imp_prelude = xopt LangExt.ImplicitPrelude dflags
|
|
| 676 | - popts = initParserOpts dflags
|
|
| 677 | - rn_pkg_qual = renameRawPkgQual (hsc_unit_env hsc_env)
|
|
| 675 | + let rn_pkg_qual = renameRawPkgQual (hsc_unit_env hsc_env)
|
|
| 678 | 676 | rn_imps = fmap (\(s, rpk, lmn@(L _ mn)) -> (s, rn_pkg_qual mn rpk, lmn))
|
| 679 | 677 | sec = initSourceErrorContext dflags
|
| 680 | - eimps <- getImports popts sec imp_prelude buf input_fn (basename <.> suff)
|
|
| 678 | + eimps <- getImportEdges dflags buf input_fn (basename <.> suff)
|
|
| 681 | 679 | case eimps of
|
| 682 | 680 | Left errs -> throwErrors sec (GhcPsMessage <$> errs)
|
| 683 | 681 | Right (src_imps,imps, L _ mod_name) -> return
|
| ... | ... | @@ -11,7 +11,7 @@ |
| 11 | 11 | -----------------------------------------------------------------------------
|
| 12 | 12 | |
| 13 | 13 | module GHC.Parser.Header
|
| 14 | - ( getImports
|
|
| 14 | + ( getImportEdges
|
|
| 15 | 15 | , mkPrelImports -- used by the renamer too
|
| 16 | 16 | , getOptionsFromFile
|
| 17 | 17 | , getOptions
|
| ... | ... | @@ -24,7 +24,8 @@ import GHC.Prelude |
| 24 | 24 | |
| 25 | 25 | import GHC.Data.Bag
|
| 26 | 26 | |
| 27 | -import GHC.Driver.DynFlags (DynFlags)
|
|
| 27 | +import GHC.Driver.DynFlags
|
|
| 28 | +import GHC.Driver.Config.Parser( initParserOpts )
|
|
| 28 | 29 | import GHC.Driver.Errors.Types -- Unfortunate, needed due to the fact we throw exceptions!
|
| 29 | 30 | |
| 30 | 31 | import GHC.Parser.Errors.Types
|
| ... | ... | @@ -47,6 +48,8 @@ import GHC.Utils.Monad |
| 47 | 48 | import GHC.Utils.Error
|
| 48 | 49 | import GHC.Utils.Exception as Exception
|
| 49 | 50 | |
| 51 | +import qualified GHC.LanguageExtensions as LangExt
|
|
| 52 | + |
|
| 50 | 53 | import GHC.Data.StringBuffer
|
| 51 | 54 | import GHC.Data.Maybe
|
| 52 | 55 | import GHC.Data.FastString
|
| ... | ... | @@ -63,26 +66,31 @@ import Text.Read (readPrec) |
| 63 | 66 | |
| 64 | 67 | ------------------------------------------------------------------------------
|
| 65 | 68 | |
| 66 | --- | Parse the imports of a source file.
|
|
| 69 | +-- | Returns the dependency edges of the module graph, by
|
|
| 70 | +-- * parsing the module and looking for `import` declarations
|
|
| 71 | +-- * adding edges for Prelude and GHC.KnownKeyNames as required
|
|
| 67 | 72 | --
|
| 68 | 73 | -- Throws a 'SourceError' if parsing fails.
|
| 69 | -getImports :: ParserOpts -- ^ Parser options
|
|
| 70 | - -> SourceErrorContext
|
|
| 71 | - -> Bool -- ^ Implicit Prelude?
|
|
| 72 | - -> StringBuffer -- ^ Parse this.
|
|
| 73 | - -> FilePath -- ^ Filename the buffer came from. Used for
|
|
| 74 | - -- reporting parse error locations.
|
|
| 75 | - -> FilePath -- ^ The original source filename (used for locations
|
|
| 76 | - -- in the function result)
|
|
| 77 | - -> IO (Either
|
|
| 78 | - (Messages PsMessage)
|
|
| 79 | - ([Located ModuleName],
|
|
| 80 | - [(ImportLevel, RawPkgQual, Located ModuleName)],
|
|
| 81 | - Located ModuleName))
|
|
| 82 | - -- ^ The source imports and normal imports (with optional package
|
|
| 83 | - -- names from -XPackageImports), and the module name.
|
|
| 84 | -getImports popts sec implicit_prelude buf filename source_filename = do
|
|
| 74 | +getImportEdges
|
|
| 75 | + :: DynFlags
|
|
| 76 | + -> StringBuffer -- ^ Parse this.
|
|
| 77 | + -> FilePath -- ^ Filename the buffer came from. Used for
|
|
| 78 | + -- reporting parse error locations.
|
|
| 79 | + -> FilePath -- ^ The original source filename (used for locations
|
|
| 80 | + -- in the function result)
|
|
| 81 | + -> IO (Either
|
|
| 82 | + (Messages PsMessage)
|
|
| 83 | + ([Located ModuleName], -- {-# SOURCE #-} imports
|
|
| 84 | + [(ImportLevel, RawPkgQual, Located ModuleName)], -- Normal imports
|
|
| 85 | + Located ModuleName)) -- Name of current module
|
|
| 86 | + -- ^ The source imports and normal imports (with optional package
|
|
| 87 | + -- names from -XPackageImports), and the module name.
|
|
| 88 | +getImportEdges dflags buf filename source_filename = do
|
|
| 85 | 89 | let loc = mkRealSrcLoc (mkFastString filename) 1 1
|
| 90 | + imp_prelude = xopt LangExt.ImplicitPrelude dflags
|
|
| 91 | + rebindable_kn = gopt Opt_RebindableKnownKeyNames dflags
|
|
| 92 | + popts = initParserOpts dflags
|
|
| 93 | + sec = initSourceErrorContext dflags
|
|
| 86 | 94 | case unP parseHeader (initParserState popts buf loc) of
|
| 87 | 95 | PFailed pst ->
|
| 88 | 96 | -- assuming we're not logging warnings here as per below
|
| ... | ... | @@ -102,16 +110,19 @@ getImports popts sec implicit_prelude buf filename source_filename = do |
| 102 | 110 | mod = mb_mod `orElse` L (noAnnSrcSpan main_loc) mAIN_NAME
|
| 103 | 111 | (src_idecls, ord_idecls) = partition ((== IsBoot) . ideclSource . unLoc) imps
|
| 104 | 112 | |
| 105 | - generated_imports = mkPrelImports (unLoc mod) implicit_prelude imps
|
|
| 106 | - convImport (L _ (i :: ImportDecl GhcPs)) = (convImportLevel (ideclLevelSpec i), ideclPkgQual i, reLoc $ ideclName i)
|
|
| 113 | + generated_imports = mkPrelImports (unLoc mod) imp_prelude imps
|
|
| 114 | + convImport (L _ (i :: ImportDecl GhcPs)) = (convImportLevel (ideclLevelSpec i), ideclPkgQual i, reLoc $ ideclName i)
|
|
| 107 | 115 | convImport_src (L _ (i :: ImportDecl GhcPs)) = (reLoc $ ideclName i)
|
| 116 | + |
|
| 117 | + known_key_name_edges -- Add an edge to GHC.KnownKeyNames, unless -frebindable-known-key-names is on
|
|
| 118 | + | rebindable_kn = []
|
|
| 119 | + | otherwise = [(NormalLevel, NoRawPkgQual, noLoc kNOWN_KEY_NAMES)]
|
|
| 108 | 120 | in
|
| 109 | - return (map convImport_src src_idecls
|
|
| 110 | - , map convImport (generated_imports ++ ord_idecls)
|
|
| 121 | + return ( map convImport_src src_idecls
|
|
| 122 | + , known_key_name_edges ++
|
|
| 123 | + map convImport (generated_imports ++ ord_idecls)
|
|
| 111 | 124 | , reLoc mod)
|
| 112 | 125 | |
| 113 | - |
|
| 114 | - |
|
| 115 | 126 | mkPrelImports :: ModuleName
|
| 116 | 127 | -> Bool -> [LImportDecl GhcPs]
|
| 117 | 128 | -> [LImportDecl GhcPs]
|
| ... | ... | @@ -261,7 +272,7 @@ getOptions opts sec supported buf filename |
| 261 | 272 | -- The token parser is written manually because Happy can't
|
| 262 | 273 | -- return a partial result when it encounters a lexer error.
|
| 263 | 274 | -- We want to extract options before the buffer is passed through
|
| 264 | --- CPP, so we can't use the same trick as 'getImports'.
|
|
| 275 | +-- CPP, so we can't use the same trick as 'getImportEdges'.
|
|
| 265 | 276 | getOptions' :: ParserOpts
|
| 266 | 277 | -> SourceErrorContext
|
| 267 | 278 | -> [String]
|
| ... | ... | @@ -2203,7 +2203,8 @@ warnUnusedImport :: GlobalRdrEnv -> ImportDeclUsage -> RnM () |
| 2203 | 2203 | warnUnusedImport rdr_env (L loc decl, used, unused, unused_wcs)
|
| 2204 | 2204 | |
| 2205 | 2205 | -- Do not warn for 'import M()'
|
| 2206 | - | Just (Exactly, L _ []) <- ideclImportList decl
|
|
| 2206 | + | Just (Exactly, _) <- ideclImportList decl
|
|
| 2207 | + , null unused
|
|
| 2207 | 2208 | = return ()
|
| 2208 | 2209 | |
| 2209 | 2210 | -- Note [Do not warn about Prelude hiding]
|
| ... | ... | @@ -1083,11 +1083,14 @@ tcGetDefaultTys |
| 1083 | 1083 | ; checkWiredInTyCon doubleTyCon
|
| 1084 | 1084 | ; numDef <- case lookupDefaultEnv_Directly user_defaults numClassKey of
|
| 1085 | 1085 | Nothing -> do { integer_ty <- tcMetaTy integerTyConName
|
| 1086 | - ; numClass <- tcLookupKnownKeyClass numClassKey
|
|
| 1087 | - ; pure $ unitDefaultEnv $ builtinDefaults numClass [integer_ty, doubleTy]
|
|
| 1088 | - }
|
|
| 1089 | - -- The Num class is already user-defaulted, no need to construct the builtin default
|
|
| 1090 | - _ -> pure emptyDefaultEnv
|
|
| 1086 | + ; numClass <- tcLookupKnownKeyClass numClassKey
|
|
| 1087 | + ; pure $ unitDefaultEnv $
|
|
| 1088 | + builtinDefaults numClass [integer_ty, doubleTy] }
|
|
| 1089 | + |
|
| 1090 | + _ -> -- The Num class is already user-defaulted, so
|
|
| 1091 | + -- no need to construct the builtin default
|
|
| 1092 | + pure emptyDefaultEnv
|
|
| 1093 | + |
|
| 1091 | 1094 | -- Supply the built-in defaults, but make the user-supplied defaults
|
| 1092 | 1095 | -- override them. We put the user-supplied ones last because in `mconcat`
|
| 1093 | 1096 | -- on `DefaultEnv` the rightmost wins.
|
| ... | ... | @@ -86,6 +86,7 @@ data ModSummary |
| 86 | 86 | -- ^ Source imports of the module
|
| 87 | 87 | ms_textual_imps :: [(ImportLevel, PkgQual, Located ModuleName)],
|
| 88 | 88 | -- ^ Non-source imports of the module from the module *text*
|
| 89 | + -- Includes 'import Prelude' if -XImplicitPrelude
|
|
| 89 | 90 | ms_parsed_mod :: Maybe HsParsedModule,
|
| 90 | 91 | -- ^ The parsed, nonrenamed source, if we have it. This is also
|
| 91 | 92 | -- used to support "inline module syntax" in Backpack files.
|
| ... | ... | @@ -69,6 +69,7 @@ import GHC.Internal.Base ( |
| 69 | 69 | import GHC.Internal.Functor.ZipList (ZipList(..))
|
| 70 | 70 | import GHC.Internal.Types
|
| 71 | 71 | import GHC.Generics
|
| 72 | +import GHC.Internal.Num( Num ) -- For -frebindable-known-key-names (defaulting)
|
|
| 72 | 73 | |
| 73 | 74 | -- $setup
|
| 74 | 75 | -- >>> import Prelude
|
| ... | ... | @@ -24,7 +24,8 @@ module Data.Bool |
| 24 | 24 | bool
|
| 25 | 25 | ) where
|
| 26 | 26 | |
| 27 | -import Prelude (Bool(..), (&&), (||), not, otherwise)
|
|
| 27 | +import Prelude ( Bool(..), (&&), (||), not, otherwise )
|
|
| 28 | +import Prelude( Num ) -- For -frebindable-known-key-names (defaulting)
|
|
| 28 | 29 | |
| 29 | 30 | -- $setup
|
| 30 | 31 | -- >>> import Prelude
|
| ... | ... | @@ -25,7 +25,7 @@ module Data.Enum |
| 25 | 25 | ) where
|
| 26 | 26 | |
| 27 | 27 | import GHC.Internal.Enum
|
| 28 | -import GHC.Internal.Num( Num ) -- For -frebindable-known-key-names
|
|
| 28 | +import GHC.Internal.Num( Num ) -- For -frebindable-known-key-names (defaulting)
|
|
| 29 | 29 | |
| 30 | 30 | -- | Returns a list of all values of an enum type
|
| 31 | 31 | --
|
| ... | ... | @@ -193,6 +193,7 @@ import GHC.Internal.Int (Int) |
| 193 | 193 | import GHC.Internal.Num ((-))
|
| 194 | 194 | import GHC.List (build)
|
| 195 | 195 | import qualified Data.List.NubOrdSet as NubOrdSet
|
| 196 | +import GHC.Internal.Num( Num ) -- For -frebindable-known-key-names (defaulting)
|
|
| 196 | 197 | |
| 197 | 198 | inits1, tails1 :: [a] -> [NonEmpty a]
|
| 198 | 199 |
| ... | ... | @@ -14,6 +14,7 @@ module Data.List.NubOrdSet ( |
| 14 | 14 | import Data.Bool (Bool(..))
|
| 15 | 15 | import GHC.Internal.Data.Function ((.))
|
| 16 | 16 | import GHC.Internal.Data.Ord (Ordering(..))
|
| 17 | +import GHC.Internal.Num( Num ) -- For -frebindable-known-key-names (defaulting)
|
|
| 17 | 18 | |
| 18 | 19 | -- | Implemented as a red-black tree, a la Okasaki.
|
| 19 | 20 | data NubOrdSet a
|
| ... | ... | @@ -7,12 +7,11 @@ |
| 7 | 7 | -- Stability : internal
|
| 8 | 8 | -- Portability : non-portable (GHC Extensions)
|
| 9 | 9 | --
|
| 10 | --- TODO: Note on KnownKeyNames by export
|
|
| 11 | ---
|
|
| 12 | 10 | |
| 13 | 11 | module GHC.KnownKeyNames
|
| 14 | 12 | ( Rational
|
| 15 | - , Eq, Ord, Show, Num, Bounded
|
|
| 13 | + , Eq, Ord, Show, Num
|
|
| 14 | + , Enum, Bounded
|
|
| 16 | 15 | , Foldable, Traversable
|
| 17 | 16 | , IsString
|
| 18 | 17 | , Functor, Monad
|
| ... | ... | @@ -62,6 +62,7 @@ import qualified GHC.Internal.RTS.Flags as Internal |
| 62 | 62 | import GHC.Internal.IO.SubSystem (IoSubSystem(..))
|
| 63 | 63 | |
| 64 | 64 | import Data.Word (Word32,Word64,Word)
|
| 65 | +import Prelude( Num ) -- For -frebindable-known-key-names (used when defaulting)
|
|
| 65 | 66 | |
| 66 | 67 | -- | 'RtsTime' is defined as a @StgWord64@ in @stg/Types.h@
|
| 67 | 68 | --
|
| ... | ... | @@ -37,6 +37,7 @@ module GHC.Stats |
| 37 | 37 | |
| 38 | 38 | |
| 39 | 39 | import Prelude (Bool,IO,Read,Show,(<$>))
|
| 40 | +import Prelude (Num) -- For -frebindable-known-key-names (defaulting)
|
|
| 40 | 41 | |
| 41 | 42 | import qualified GHC.Internal.Stats as Internal
|
| 42 | 43 | import GHC.Generics (Generic)
|
| ... | ... | @@ -34,6 +34,7 @@ import Data.Maybe (Maybe (Nothing)) |
| 34 | 34 | import Data.String (String)
|
| 35 | 35 | import Data.Eq ((/=))
|
| 36 | 36 | import System.IO (IO, hPutStrLn, stderr)
|
| 37 | +import GHC.Internal.Num( Num ) -- For -frebindable-known-key-names (defaulting)
|
|
| 37 | 38 | |
| 38 | 39 | -- ---------------------------------------------------------------------------
|
| 39 | 40 | -- exitWith
|
| ... | ... | @@ -61,6 +61,7 @@ import GHC.IO.Exception |
| 61 | 61 | )
|
| 62 | 62 | import Foreign.Ptr (Ptr)
|
| 63 | 63 | import Foreign.C.Types (CInt)
|
| 64 | +import GHC.Internal.Num( Num ) -- For -frebindable-known-key-names (defaulting)
|
|
| 64 | 65 | |
| 65 | 66 | -- * Obtaining POSIX file descriptors and Windows handles
|
| 66 | 67 |
| ... | ... | @@ -7,6 +7,9 @@ |
| 7 | 7 | {-# LANGUAGE TypeFamilies #-}
|
| 8 | 8 | {-# LANGUAGE TypeOperators #-}
|
| 9 | 9 | |
| 10 | +{-# OPTIONS_GHC -fdefines-known-key-names #-}
|
|
| 11 | + -- Defines IsString
|
|
| 12 | + |
|
| 10 | 13 | -----------------------------------------------------------------------------
|
| 11 | 14 | -- |
|
| 12 | 15 | -- Module : GHC.Internal.Data.String
|
| ... | ... | @@ -26,6 +26,10 @@ Library |
| 26 | 26 | |
| 27 | 27 | build-depends: ghc-internal
|
| 28 | 28 | |
| 29 | + ghc-options: -frebindable-known-key-names
|
|
| 30 | + -- Do not create dependencies on GHC.KnownKeyNames!
|
|
| 31 | + -- It doesn't exist yet.
|
|
| 32 | + |
|
| 29 | 33 | other-modules:
|
| 30 | 34 | -- dummy module to make Hadrian/GHC build a valid library...
|
| 31 | 35 | Dummy
|
| ... | ... | @@ -61,7 +61,7 @@ main = do |
| 61 | 61 | , "import B"
|
| 62 | 62 | ]
|
| 63 | 63 | , [ "module B !parse_error where"
|
| 64 | - -- ^ this used to cause getImports to throw an exception instead
|
|
| 64 | + -- ^ this used to cause getImportEdges to throw an exception instead
|
|
| 65 | 65 | -- of having downsweep return an error for just this module
|
| 66 | 66 | , "import C"
|
| 67 | 67 | ]
|
| ... | ... | @@ -95,7 +95,7 @@ main = do |
| 95 | 95 | ]
|
| 96 | 96 | , [ "module B where"
|
| 97 | 97 | , "!parse_error"
|
| 98 | - -- ^ this is silently ignored, getImports assumes the import
|
|
| 98 | + -- ^ this is silently ignored, getImportEdges assumes the import
|
|
| 99 | 99 | -- list is just empty. This smells like a parser bug to me but
|
| 100 | 100 | -- I'm still documenting this behaviour here.
|
| 101 | 101 | , "import C"
|
| 1 | 1 | -- We can't test module header parsing errors using the same file as other
|
| 2 | --- parsing errors (in ../T16270.hs) because HeaderInfo.getImports fails fast
|
|
| 2 | +-- parsing errors (in ../T16270.hs) because HeaderInfo.getImportEdges fails fast
|
|
| 3 | 3 | -- on parsing imports:
|
| 4 | 4 | --
|
| 5 | 5 | -- if errorsFound dflags ms
|