diff options
author | John Ericson <git@JohnEricson.me> | 2019-07-13 22:58:42 -0400 |
---|---|---|
committer | John Ericson <git@JohnEricson.me> | 2019-07-13 22:58:42 -0400 |
commit | cf6c2b8023e843bf04d6c8b031e2ac1306658bf7 (patch) | |
tree | 6827165cee44216fe918744a2bd7f44c8666c52d | |
parent | 6ff5f24028f9d29e8c9f2c870ee6f2d7e9747da0 (diff) | |
parent | d63ab461a0419d028a3bcca2fafe43be78a14cde (diff) | |
download | haskell-cf6c2b8023e843bf04d6c8b031e2ac1306658bf7.tar.gz |
Merge branch 'always-enable-external-interpreter' into HEAD
28 files changed, 436 insertions, 387 deletions
diff --git a/aclocal.m4 b/aclocal.m4 index 0d564f3885..a378c4fcf9 100644 --- a/aclocal.m4 +++ b/aclocal.m4 @@ -372,12 +372,14 @@ AC_DEFUN([FPTOOLS_SET_HASKELL_PLATFORM_VARS], checkArch "$HostArch" "HaskellHostArch" checkVendor "$HostVendor" - checkOS "$HostOS" "" + checkOS "$HostOS" "HaskellHostOs" checkArch "$TargetArch" "HaskellTargetArch" checkVendor "$TargetVendor" checkOS "$TargetOS" "HaskellTargetOs" + AC_SUBST(HaskellHostArch) + AC_SUBST(HaskellHostOs) AC_SUBST(HaskellTargetArch) AC_SUBST(HaskellTargetOs) AC_SUBST(HaskellHaveSubsectionsViaSymbols) diff --git a/compiler/ghc.cabal.in b/compiler/ghc.cabal.in index 1a3d131af4..48b0c1c5d5 100644 --- a/compiler/ghc.cabal.in +++ b/compiler/ghc.cabal.in @@ -25,11 +25,6 @@ Flag ghci Default: False Manual: True -Flag ext-interp - Description: Support external interpreter - Default: True - Manual: True - Flag stage1 Description: Is this stage 1? Default: False @@ -98,12 +93,6 @@ Library CPP-Options: -DHAVE_INTERNAL_INTERPRETER Include-Dirs: ../rts/dist/build @FFIIncludeDir@ - if flag(ext-interp) - CPP-Options: -DHAVE_EXTERNAL_INTERPRETER - - if flag(ghci) || flag(ext-interp) - CPP-Options: -DHAVE_INTERPRETER - -- sanity-check to ensure not more than one integer flag is set if flag(integer-gmp) && flag(integer-simple) build-depends: invalid-cabal-flag-settings<0 @@ -419,6 +408,7 @@ Library SysTools.Info SysTools.Process SysTools.Tasks + SysTools.Settings Elf TidyPgm Ctype diff --git a/compiler/main/DynFlags.hs b/compiler/main/DynFlags.hs index 7d3e35e981..967cfd440d 100644 --- a/compiler/main/DynFlags.hs +++ b/compiler/main/DynFlags.hs @@ -1504,7 +1504,7 @@ versionedAppDir dflags = do return $ appdir </> versionedFilePath dflags versionedFilePath :: DynFlags -> FilePath -versionedFilePath dflags = uniqueSubdir $ targetPlatform dflags +versionedFilePath dflags = uniqueSubdir $ platformMini $ targetPlatform dflags -- | The target code type of the compilation (if any). -- @@ -4336,26 +4336,25 @@ supportedLanguages = map (flagSpecName . snd) languageFlagsDeps supportedLanguageOverlays :: [String] supportedLanguageOverlays = map (flagSpecName . snd) safeHaskellFlagsDeps -supportedExtensions :: [String] -supportedExtensions = concatMap toFlagSpecNamePair xFlags +supportedExtensions :: PlatformMini -> [String] +supportedExtensions targetPlatformMini = concatMap toFlagSpecNamePair xFlags where toFlagSpecNamePair flg -#if !defined(HAVE_INTERPRETER) -- IMPORTANT! Make sure that `ghc --supported-extensions` omits -- "TemplateHaskell"/"QuasiQuotes" when it's known not to work out of the -- box. See also GHC #11102 and #16331 for more details about -- the rationale - | flagSpecFlag flg == LangExt.TemplateHaskell = [noName] - | flagSpecFlag flg == LangExt.QuasiQuotes = [noName] -#endif + | isAIX, flagSpecFlag flg == LangExt.TemplateHaskell = [noName] + | isAIX, flagSpecFlag flg == LangExt.QuasiQuotes = [noName] | otherwise = [name, noName] where + isAIX = platformMini_os targetPlatformMini == OSAIX noName = "No" ++ name name = flagSpecName flg -supportedLanguagesAndExtensions :: [String] -supportedLanguagesAndExtensions = - supportedLanguages ++ supportedLanguageOverlays ++ supportedExtensions +supportedLanguagesAndExtensions :: PlatformMini -> [String] +supportedLanguagesAndExtensions targetPlatformMini = + supportedLanguages ++ supportedLanguageOverlays ++ supportedExtensions targetPlatformMini -- | These -X<blah> flags cannot be reversed with -XNo<blah> languageFlagsDeps :: [(Deprecation, FlagSpec Language)] diff --git a/compiler/main/DynamicLoading.hs b/compiler/main/DynamicLoading.hs index 64cc0a1216..ea09a8ceb5 100644 --- a/compiler/main/DynamicLoading.hs +++ b/compiler/main/DynamicLoading.hs @@ -3,7 +3,6 @@ -- | Dynamically lookup up values from modules and loading them. module DynamicLoading ( initializePlugins, -#if defined(HAVE_INTERPRETER) -- * Loading plugins loadFrontendPlugin, @@ -19,15 +18,11 @@ module DynamicLoading ( getValueSafely, getHValueSafely, lessUnsafeCoerce -#else - pluginError -#endif ) where import GhcPrelude import DynFlags -#if defined(HAVE_INTERPRETER) import Linker ( linkModule, getHValue ) import GHCi ( wormhole ) import SrcLoc ( noSrcSpan ) @@ -60,28 +55,11 @@ import Control.Monad ( when, unless ) import Data.Maybe ( mapMaybe ) import GHC.Exts ( unsafeCoerce# ) -#else - -import HscTypes ( HscEnv ) -import Module ( ModuleName, moduleNameString ) -import Panic - -import Data.List ( intercalate ) -import Control.Monad ( unless ) - -#endif - -- | Loads the plugins specified in the pluginModNames field of the dynamic -- flags. Should be called after command line arguments are parsed, but before -- actual compilation starts. Idempotent operation. Should be re-called if -- pluginModNames or pluginModNameOpts changes. initializePlugins :: HscEnv -> DynFlags -> IO DynFlags -#if !defined(HAVE_INTERPRETER) -initializePlugins _ df - = do let pluginMods = pluginModNames df - unless (null pluginMods) (pluginError pluginMods) - return df -#else initializePlugins hsc_env df | map lpModuleName (cachedPlugins df) == pluginModNames df -- plugins not changed @@ -93,10 +71,6 @@ initializePlugins hsc_env df = do loadedPlugins <- loadPlugins (hsc_env { hsc_dflags = df }) return $ df { cachedPlugins = loadedPlugins } where argumentsForPlugin p = map snd . filter ((== lpModuleName p) . fst) -#endif - - -#if defined(HAVE_INTERPRETER) loadPlugins :: HscEnv -> IO [LoadedPlugin] loadPlugins hsc_env @@ -302,15 +276,3 @@ throwCmdLineErrorS dflags = throwCmdLineError . showSDoc dflags throwCmdLineError :: String -> IO a throwCmdLineError = throwGhcExceptionIO . CmdLineError - -#else - -pluginError :: [ModuleName] -> a -pluginError modnames = throwGhcException (CmdLineError msg) - where - msg = "not built for interactive use - can't load plugins (" - -- module names are not z-encoded - ++ intercalate ", " (map moduleNameString modnames) - ++ ")" - -#endif diff --git a/compiler/main/HeaderInfo.hs b/compiler/main/HeaderInfo.hs index c7557922bc..25f6c38bd6 100644 --- a/compiler/main/HeaderInfo.hs +++ b/compiler/main/HeaderInfo.hs @@ -22,6 +22,7 @@ module HeaderInfo ( getImports import GhcPrelude +import GHC.Platform import HscTypes import Parser ( parseHeader ) import Lexer @@ -307,10 +308,12 @@ checkExtension :: DynFlags -> Located FastString -> Located String checkExtension dflags (dL->L l ext) -- Checks if a given extension is valid, and if so returns -- its corresponding flag. Otherwise it throws an exception. - = let ext' = unpackFS ext in - if ext' `elem` supportedLanguagesAndExtensions + = if ext' `elem` supported then cL l ("-X"++ext') else unsupportedExtnError dflags l ext' + where + ext' = unpackFS ext + supported = supportedLanguagesAndExtensions $ platformMini $ targetPlatform dflags languagePragParseError :: DynFlags -> SrcSpan -> a languagePragParseError dflags loc = @@ -326,7 +329,8 @@ unsupportedExtnError dflags loc unsup = text "Unsupported extension: " <> text unsup $$ if null suggestions then Outputable.empty else text "Perhaps you meant" <+> quotedListWithOr (map text suggestions) where - suggestions = fuzzyMatch unsup supportedLanguagesAndExtensions + supported = supportedLanguagesAndExtensions $ platformMini $ targetPlatform dflags + suggestions = fuzzyMatch unsup supported optionsErrorMsgs :: DynFlags -> [String] -> [Located String] -> FilePath -> Messages diff --git a/compiler/main/SysTools.hs b/compiler/main/SysTools.hs index 518d9fdb2f..fa339bbb87 100644 --- a/compiler/main/SysTools.hs +++ b/compiler/main/SysTools.hs @@ -44,22 +44,19 @@ import GHC.Settings import Module import Packages -import Config import Outputable import ErrUtils import GHC.Platform import DynFlags -import Fingerprint -import ToolSettings -import qualified Data.Map as Map +import Control.Monad.Trans.Except (runExceptT) import System.FilePath import System.IO -import System.Directory import SysTools.ExtraObj import SysTools.Info import SysTools.Tasks import SysTools.BaseDir +import SysTools.Settings {- Note [How GHC finds toolchain utilities] @@ -137,212 +134,12 @@ initSysTools :: String -- TopDir path -- (a) the system programs -- (b) the package-config file -- (c) the GHC usage message -initSysTools top_dir - = do -- see Note [topdir: How GHC finds its files] - -- NB: top_dir is assumed to be in standard Unix - -- format, '/' separated - mtool_dir <- findToolDir top_dir - -- see Note [tooldir: How GHC finds mingw on Windows] - - let installed :: FilePath -> FilePath - installed file = top_dir </> file - libexec :: FilePath -> FilePath - libexec file = top_dir </> "bin" </> file - settingsFile = installed "settings" - platformConstantsFile = installed "platformConstants" - - settingsStr <- readFile settingsFile - platformConstantsStr <- readFile platformConstantsFile - settingsList <- case maybeReadFuzzy settingsStr of - Just s -> - return s - Nothing -> - pgmError ("Can't parse " ++ show settingsFile) - let mySettings = Map.fromList settingsList - platformConstants <- case maybeReadFuzzy platformConstantsStr of - Just s -> - return s - Nothing -> - pgmError ("Can't parse " ++ - show platformConstantsFile) - -- See Note [Settings file] for a little more about this file. We're - -- just partially applying those functions and throwing 'Left's; they're - -- written in a very portable style to keep ghc-boot light. - let getSetting key = either pgmError pure $ - getFilePathSetting0 top_dir settingsFile mySettings key - getToolSetting :: String -> IO String - getToolSetting key = expandToolDir mtool_dir <$> getSetting key - getBooleanSetting :: String -> IO Bool - getBooleanSetting key = either pgmError pure $ - getBooleanSetting0 settingsFile mySettings key - targetPlatformString <- getSetting "target platform string" - tablesNextToCode <- getBooleanSetting "Tables next to code" - myExtraGccViaCFlags <- getSetting "GCC extra via C opts" - -- On Windows, mingw is distributed with GHC, - -- so we look in TopDir/../mingw/bin, - -- as well as TopDir/../../mingw/bin for hadrian. - -- It would perhaps be nice to be able to override this - -- with the settings file, but it would be a little fiddly - -- to make that possible, so for now you can't. - cc_prog <- getToolSetting "C compiler command" - cc_args_str <- getSetting "C compiler flags" - cxx_args_str <- getSetting "C++ compiler flags" - gccSupportsNoPie <- getBooleanSetting "C compiler supports -no-pie" - cpp_prog <- getToolSetting "Haskell CPP command" - cpp_args_str <- getSetting "Haskell CPP flags" - - platform <- either pgmError pure $ getTargetPlatform settingsFile mySettings - - let unreg_cc_args = if platformUnregisterised platform - then ["-DNO_REGS", "-DUSE_MINIINTERPRETER"] - else [] - cpp_args = map Option (words cpp_args_str) - cc_args = words cc_args_str ++ unreg_cc_args - cxx_args = words cxx_args_str - ldSupportsCompactUnwind <- getBooleanSetting "ld supports compact unwind" - ldSupportsBuildId <- getBooleanSetting "ld supports build-id" - ldSupportsFilelist <- getBooleanSetting "ld supports filelist" - ldIsGnuLd <- getBooleanSetting "ld is GNU ld" - - let pkgconfig_path = installed "package.conf.d" - ghc_usage_msg_path = installed "ghc-usage.txt" - ghci_usage_msg_path = installed "ghci-usage.txt" - - -- For all systems, unlit, split, mangle are GHC utilities - -- architecture-specific stuff is done when building Config.hs - unlit_path <- getToolSetting "unlit command" - - windres_path <- getToolSetting "windres command" - libtool_path <- getToolSetting "libtool command" - ar_path <- getToolSetting "ar command" - ranlib_path <- getToolSetting "ranlib command" - - tmpdir <- getTemporaryDirectory - - touch_path <- getToolSetting "touch command" - - mkdll_prog <- getToolSetting "dllwrap command" - let mkdll_args = [] - - -- cpp is derived from gcc on all platforms - -- HACK, see setPgmP below. We keep 'words' here to remember to fix - -- Config.hs one day. - - - -- Other things being equal, as and ld are simply gcc - cc_link_args_str <- getSetting "C compiler link flags" - let as_prog = cc_prog - as_args = map Option cc_args - ld_prog = cc_prog - ld_args = map Option (cc_args ++ words cc_link_args_str) - - -- We just assume on command line - lc_prog <- getSetting "LLVM llc command" - lo_prog <- getSetting "LLVM opt command" - lcc_prog <- getSetting "LLVM clang command" - - let iserv_prog = libexec "ghc-iserv" - - integerLibrary <- getSetting "integer library" - integerLibraryType <- case integerLibrary of - "integer-gmp" -> pure IntegerGMP - "integer-simple" -> pure IntegerSimple - _ -> pgmError $ unwords - [ "Entry for" - , show "integer library" - , "must be one of" - , show "integer-gmp" - , "or" - , show "integer-simple" - ] - - ghcWithInterpreter <- getBooleanSetting "Use interpreter" - ghcWithNativeCodeGen <- getBooleanSetting "Use native code generator" - ghcWithSMP <- getBooleanSetting "Support SMP" - ghcRTSWays <- getSetting "RTS ways" - leadingUnderscore <- getBooleanSetting "Leading underscore" - useLibFFI <- getBooleanSetting "Use LibFFI" - ghcThreaded <- getBooleanSetting "Use Threads" - ghcDebugged <- getBooleanSetting "Use Debugging" - ghcRtsWithLibdw <- getBooleanSetting "RTS expects libdw" - - return $ Settings - { sGhcNameVersion = GhcNameVersion - { ghcNameVersion_programName = "ghc" - , ghcNameVersion_projectVersion = cProjectVersion - } - - , sFileSettings = FileSettings - { fileSettings_tmpDir = normalise tmpdir - , fileSettings_ghcUsagePath = ghc_usage_msg_path - , fileSettings_ghciUsagePath = ghci_usage_msg_path - , fileSettings_toolDir = mtool_dir - , fileSettings_topDir = top_dir - , fileSettings_systemPackageConfig = pkgconfig_path - } - - , sToolSettings = ToolSettings - { toolSettings_ldSupportsCompactUnwind = ldSupportsCompactUnwind - , toolSettings_ldSupportsBuildId = ldSupportsBuildId - , toolSettings_ldSupportsFilelist = ldSupportsFilelist - , toolSettings_ldIsGnuLd = ldIsGnuLd - , toolSettings_ccSupportsNoPie = gccSupportsNoPie - - , toolSettings_pgm_L = unlit_path - , toolSettings_pgm_P = (cpp_prog, cpp_args) - , toolSettings_pgm_F = "" - , toolSettings_pgm_c = cc_prog - , toolSettings_pgm_a = (as_prog, as_args) - , toolSettings_pgm_l = (ld_prog, ld_args) - , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) - , toolSettings_pgm_T = touch_path - , toolSettings_pgm_windres = windres_path - , toolSettings_pgm_libtool = libtool_path - , toolSettings_pgm_ar = ar_path - , toolSettings_pgm_ranlib = ranlib_path - , toolSettings_pgm_lo = (lo_prog,[]) - , toolSettings_pgm_lc = (lc_prog,[]) - , toolSettings_pgm_lcc = (lcc_prog,[]) - , toolSettings_pgm_i = iserv_prog - , toolSettings_opt_L = [] - , toolSettings_opt_P = [] - , toolSettings_opt_P_fingerprint = fingerprint0 - , toolSettings_opt_F = [] - , toolSettings_opt_c = cc_args - , toolSettings_opt_cxx = cxx_args - , toolSettings_opt_a = [] - , toolSettings_opt_l = [] - , toolSettings_opt_windres = [] - , toolSettings_opt_lcc = [] - , toolSettings_opt_lo = [] - , toolSettings_opt_lc = [] - , toolSettings_opt_i = [] - - , toolSettings_extraGccViaCFlags = words myExtraGccViaCFlags - } - - , sTargetPlatform = platform - , sPlatformMisc = PlatformMisc - { platformMisc_targetPlatformString = targetPlatformString - , platformMisc_integerLibrary = integerLibrary - , platformMisc_integerLibraryType = integerLibraryType - , platformMisc_ghcWithInterpreter = ghcWithInterpreter - , platformMisc_ghcWithNativeCodeGen = ghcWithNativeCodeGen - , platformMisc_ghcWithSMP = ghcWithSMP - , platformMisc_ghcRTSWays = ghcRTSWays - , platformMisc_tablesNextToCode = tablesNextToCode - , platformMisc_leadingUnderscore = leadingUnderscore - , platformMisc_libFFI = useLibFFI - , platformMisc_ghcThreaded = ghcThreaded - , platformMisc_ghcDebugged = ghcDebugged - , platformMisc_ghcRtsWithLibdw = ghcRtsWithLibdw - } - - , sPlatformConstants = platformConstants - - , sRawSettings = settingsList - } - +initSysTools top_dir = do + res <- runExceptT $ initSettings top_dir + case res of + Right a -> pure a + Left (SettingsError_MissingData msg) -> pgmError msg + Left (SettingsError_BadData msg) -> pgmError msg {- Note [Windows stack usage] diff --git a/compiler/main/SysTools/BaseDir.hs b/compiler/main/SysTools/BaseDir.hs index f67d2def6d..c4fc71b502 100644 --- a/compiler/main/SysTools/BaseDir.hs +++ b/compiler/main/SysTools/BaseDir.hs @@ -14,6 +14,7 @@ module SysTools.BaseDir ( expandTopDir, expandToolDir , findTopDir, findToolDir + , tryFindTopDir ) where #include "HsVersions.h" @@ -88,23 +89,28 @@ expandToolDir _ s = s -- | Returns a Unix-format path pointing to TopDir. findTopDir :: Maybe String -- Maybe TopDir path (without the '-B' prefix). -> IO String -- TopDir (in Unix format '/' separated) -findTopDir (Just minusb) = return (normalise minusb) -findTopDir Nothing +findTopDir m_minusb = do + maybe_exec_dir <- tryFindTopDir m_minusb + case maybe_exec_dir of + -- "Just" on Windows, "Nothing" on unix + Nothing -> throwGhcExceptionIO $ + InstallationError "missing -B<dir> option" + Just dir -> return dir + +tryFindTopDir + :: Maybe String -- ^ Maybe TopDir path (without the '-B' prefix). + -> IO (Maybe String) -- ^ TopDir (in Unix format '/' separated) +tryFindTopDir (Just minusb) = return $ Just $ normalise minusb +tryFindTopDir Nothing = do -- The _GHC_TOP_DIR environment variable can be used to specify -- the top dir when the -B argument is not specified. It is not -- intended for use by users, it was added specifically for the -- purpose of running GHC within GHCi. maybe_env_top_dir <- lookupEnv "_GHC_TOP_DIR" case maybe_env_top_dir of - Just env_top_dir -> return env_top_dir - Nothing -> do - -- Get directory of executable - maybe_exec_dir <- getBaseDir - case maybe_exec_dir of - -- "Just" on Windows, "Nothing" on unix - Nothing -> throwGhcExceptionIO $ - InstallationError "missing -B<dir> option" - Just dir -> return dir + Just env_top_dir -> return $ Just env_top_dir + -- Try directory of executable + Nothing -> getBaseDir -- See Note [tooldir: How GHC finds mingw and perl on Windows] diff --git a/compiler/main/SysTools/Settings.hs b/compiler/main/SysTools/Settings.hs new file mode 100644 index 0000000000..e9b5381ebe --- /dev/null +++ b/compiler/main/SysTools/Settings.hs @@ -0,0 +1,250 @@ +{-# LANGUAGE CPP #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE ScopedTypeVariables #-} + +module SysTools.Settings + ( SettingsError (..) + , initSettings + ) where + +#include "HsVersions.h" + +import GhcPrelude + +import GHC.Settings + +import Config +import CliOption +import FileSettings +import Fingerprint +import GHC.Platform +import GhcNameVersion +import Outputable +import Settings +import SysTools.BaseDir +import ToolSettings + +import Control.Monad.Trans.Except +import Control.Monad.IO.Class +import qualified Data.Map as Map +import System.FilePath +import System.Directory + +data SettingsError + = SettingsError_MissingData String + | SettingsError_BadData String + +initSettings + :: forall m + . MonadIO m + => String -- ^ TopDir path + -> ExceptT SettingsError m Settings +initSettings top_dir = do + -- see Note [topdir: How GHC finds its files] + -- NB: top_dir is assumed to be in standard Unix + -- format, '/' separated + mtool_dir <- liftIO $ findToolDir top_dir + -- see Note [tooldir: How GHC finds mingw on Windows] + + let installed :: FilePath -> FilePath + installed file = top_dir </> file + libexec :: FilePath -> FilePath + libexec file = top_dir </> "bin" </> file + settingsFile = installed "settings" + platformConstantsFile = installed "platformConstants" + + readFileSafe :: FilePath -> ExceptT SettingsError m String + readFileSafe path = liftIO (doesFileExist path) >>= \case + True -> liftIO $ readFile path + False -> throwE $ SettingsError_MissingData $ "Missing file: " ++ path + + settingsStr <- readFileSafe settingsFile + platformConstantsStr <- readFileSafe platformConstantsFile + settingsList <- case maybeReadFuzzy settingsStr of + Just s -> pure s + Nothing -> throwE $ SettingsError_BadData $ + "Can't parse " ++ show settingsFile + let mySettings = Map.fromList settingsList + platformConstants <- case maybeReadFuzzy platformConstantsStr of + Just s -> pure s + Nothing -> throwE $ SettingsError_BadData $ + "Can't parse " ++ show platformConstantsFile + -- See Note [Settings file] for a little more about this file. We're + -- just partially applying those functions and throwing 'Left's; they're + -- written in a very portable style to keep ghc-boot light. + let getSetting key = either pgmError pure $ + getFilePathSetting0 top_dir settingsFile mySettings key + getToolSetting :: String -> ExceptT SettingsError m String + getToolSetting key = expandToolDir mtool_dir <$> getSetting key + getBooleanSetting :: String -> ExceptT SettingsError m Bool + getBooleanSetting key = either pgmError pure $ + getBooleanSetting0 settingsFile mySettings key + targetPlatformString <- getSetting "target platform string" + tablesNextToCode <- getBooleanSetting "Tables next to code" + myExtraGccViaCFlags <- getSetting "GCC extra via C opts" + -- On Windows, mingw is distributed with GHC, + -- so we look in TopDir/../mingw/bin, + -- as well as TopDir/../../mingw/bin for hadrian. + -- It would perhaps be nice to be able to override this + -- with the settings file, but it would be a little fiddly + -- to make that possible, so for now you can't. + cc_prog <- getToolSetting "C compiler command" + cc_args_str <- getSetting "C compiler flags" + cxx_args_str <- getSetting "C++ compiler flags" + gccSupportsNoPie <- getBooleanSetting "C compiler supports -no-pie" + cpp_prog <- getToolSetting "Haskell CPP command" + cpp_args_str <- getSetting "Haskell CPP flags" + + platform <- either pgmError pure $ getTargetPlatform settingsFile mySettings + + let unreg_cc_args = if platformUnregisterised platform + then ["-DNO_REGS", "-DUSE_MINIINTERPRETER"] + else [] + cpp_args = map Option (words cpp_args_str) + cc_args = words cc_args_str ++ unreg_cc_args + cxx_args = words cxx_args_str + ldSupportsCompactUnwind <- getBooleanSetting "ld supports compact unwind" + ldSupportsBuildId <- getBooleanSetting "ld supports build-id" + ldSupportsFilelist <- getBooleanSetting "ld supports filelist" + ldIsGnuLd <- getBooleanSetting "ld is GNU ld" + + let pkgconfig_path = installed "package.conf.d" + ghc_usage_msg_path = installed "ghc-usage.txt" + ghci_usage_msg_path = installed "ghci-usage.txt" + + -- For all systems, unlit, split, mangle are GHC utilities + -- architecture-specific stuff is done when building Config.hs + unlit_path <- getToolSetting "unlit command" + + windres_path <- getToolSetting "windres command" + libtool_path <- getToolSetting "libtool command" + ar_path <- getToolSetting "ar command" + ranlib_path <- getToolSetting "ranlib command" + + -- TODO this side-effect doesn't belong here. Reading and parsing the settings + -- should be idempotent and accumulate no resources. + tmpdir <- liftIO $ getTemporaryDirectory + + touch_path <- getToolSetting "touch command" + + mkdll_prog <- getToolSetting "dllwrap command" + let mkdll_args = [] + + -- cpp is derived from gcc on all platforms + -- HACK, see setPgmP below. We keep 'words' here to remember to fix + -- Config.hs one day. + + + -- Other things being equal, as and ld are simply gcc + cc_link_args_str <- getSetting "C compiler link flags" + let as_prog = cc_prog + as_args = map Option cc_args + ld_prog = cc_prog + ld_args = map Option (cc_args ++ words cc_link_args_str) + + -- We just assume on command line + lc_prog <- getSetting "LLVM llc command" + lo_prog <- getSetting "LLVM opt command" + lcc_prog <- getSetting "LLVM clang command" + + let iserv_prog = libexec "ghc-iserv" + + integerLibrary <- getSetting "integer library" + integerLibraryType <- case integerLibrary of + "integer-gmp" -> pure IntegerGMP + "integer-simple" -> pure IntegerSimple + _ -> pgmError $ unwords + [ "Entry for" + , show "integer library" + , "must be one of" + , show "integer-gmp" + , "or" + , show "integer-simple" + ] + + ghcWithInterpreter <- getBooleanSetting "Use interpreter" + ghcWithNativeCodeGen <- getBooleanSetting "Use native code generator" + ghcWithSMP <- getBooleanSetting "Support SMP" + ghcRTSWays <- getSetting "RTS ways" + leadingUnderscore <- getBooleanSetting "Leading underscore" + useLibFFI <- getBooleanSetting "Use LibFFI" + ghcThreaded <- getBooleanSetting "Use Threads" + ghcDebugged <- getBooleanSetting "Use Debugging" + ghcRtsWithLibdw <- getBooleanSetting "RTS expects libdw" + + return $ Settings + { sGhcNameVersion = GhcNameVersion + { ghcNameVersion_programName = "ghc" + , ghcNameVersion_projectVersion = cProjectVersion + } + + , sFileSettings = FileSettings + { fileSettings_tmpDir = normalise tmpdir + , fileSettings_ghcUsagePath = ghc_usage_msg_path + , fileSettings_ghciUsagePath = ghci_usage_msg_path + , fileSettings_toolDir = mtool_dir + , fileSettings_topDir = top_dir + , fileSettings_systemPackageConfig = pkgconfig_path + } + + , sToolSettings = ToolSettings + { toolSettings_ldSupportsCompactUnwind = ldSupportsCompactUnwind + , toolSettings_ldSupportsBuildId = ldSupportsBuildId + , toolSettings_ldSupportsFilelist = ldSupportsFilelist + , toolSettings_ldIsGnuLd = ldIsGnuLd + , toolSettings_ccSupportsNoPie = gccSupportsNoPie + + , toolSettings_pgm_L = unlit_path + , toolSettings_pgm_P = (cpp_prog, cpp_args) + , toolSettings_pgm_F = "" + , toolSettings_pgm_c = cc_prog + , toolSettings_pgm_a = (as_prog, as_args) + , toolSettings_pgm_l = (ld_prog, ld_args) + , toolSettings_pgm_dll = (mkdll_prog,mkdll_args) + , toolSettings_pgm_T = touch_path + , toolSettings_pgm_windres = windres_path + , toolSettings_pgm_libtool = libtool_path + , toolSettings_pgm_ar = ar_path + , toolSettings_pgm_ranlib = ranlib_path + , toolSettings_pgm_lo = (lo_prog,[]) + , toolSettings_pgm_lc = (lc_prog,[]) + , toolSettings_pgm_lcc = (lcc_prog,[]) + , toolSettings_pgm_i = iserv_prog + , toolSettings_opt_L = [] + , toolSettings_opt_P = [] + , toolSettings_opt_P_fingerprint = fingerprint0 + , toolSettings_opt_F = [] + , toolSettings_opt_c = cc_args + , toolSettings_opt_cxx = cxx_args + , toolSettings_opt_a = [] + , toolSettings_opt_l = [] + , toolSettings_opt_windres = [] + , toolSettings_opt_lcc = [] + , toolSettings_opt_lo = [] + , toolSettings_opt_lc = [] + , toolSettings_opt_i = [] + + , toolSettings_extraGccViaCFlags = words myExtraGccViaCFlags + } + + , sTargetPlatform = platform + , sPlatformMisc = PlatformMisc + { platformMisc_targetPlatformString = targetPlatformString + , platformMisc_integerLibrary = integerLibrary + , platformMisc_integerLibraryType = integerLibraryType + , platformMisc_ghcWithInterpreter = ghcWithInterpreter + , platformMisc_ghcWithNativeCodeGen = ghcWithNativeCodeGen + , platformMisc_ghcWithSMP = ghcWithSMP + , platformMisc_ghcRTSWays = ghcRTSWays + , platformMisc_tablesNextToCode = tablesNextToCode + , platformMisc_leadingUnderscore = leadingUnderscore + , platformMisc_libFFI = useLibFFI + , platformMisc_ghcThreaded = ghcThreaded + , platformMisc_ghcDebugged = ghcDebugged + , platformMisc_ghcRtsWithLibdw = ghcRtsWithLibdw + } + + , sPlatformConstants = platformConstants + + , sRawSettings = settingsList + } diff --git a/compiler/nativeGen/PIC.hs b/compiler/nativeGen/PIC.hs index 9c57a0292f..7ea68e1105 100644 --- a/compiler/nativeGen/PIC.hs +++ b/compiler/nativeGen/PIC.hs @@ -565,7 +565,7 @@ pprGotDeclaration _ _ _ -- pprImportedSymbol :: DynFlags -> Platform -> CLabel -> SDoc -pprImportedSymbol dflags (Platform { platformArch = ArchX86, platformOS = OSDarwin }) importedLbl +pprImportedSymbol dflags (Platform { platformMini = PlatformMini { platformMini_arch = ArchX86, platformMini_os = OSDarwin } }) importedLbl | Just (CodeStub, lbl) <- dynamicLinkerLabelInfo importedLbl = case positionIndependent dflags of False -> @@ -618,7 +618,7 @@ pprImportedSymbol dflags (Platform { platformArch = ArchX86, platformOS = OSDarw = empty -pprImportedSymbol _ (Platform { platformOS = OSDarwin }) _ +pprImportedSymbol _ (Platform { platformMini = PlatformMini { platformMini_os = OSDarwin } }) _ = empty -- XCOFF / AIX @@ -632,7 +632,7 @@ pprImportedSymbol _ (Platform { platformOS = OSDarwin }) _ -- -- NB: No DSO-support yet -pprImportedSymbol dflags (Platform { platformOS = OSAIX }) importedLbl +pprImportedSymbol dflags (Platform { platformMini = PlatformMini { platformMini_os = OSAIX } }) importedLbl = case dynamicLinkerLabelInfo importedLbl of Just (SymbolPtr, lbl) -> vcat [ @@ -669,7 +669,7 @@ pprImportedSymbol dflags (Platform { platformOS = OSAIX }) importedLbl -- the NCG will keep track of all DynamicLinkerLabels it uses -- and output each of them using pprImportedSymbol. -pprImportedSymbol dflags platform@(Platform { platformArch = ArchPPC_64 _ }) +pprImportedSymbol dflags platform@(Platform { platformMini = PlatformMini { platformMini_arch = ArchPPC_64 _ } }) importedLbl | osElfTarget (platformOS platform) = case dynamicLinkerLabelInfo importedLbl of diff --git a/compiler/rename/RnExpr.hs b/compiler/rename/RnExpr.hs index eadb4bca03..be7cb6ad71 100644 --- a/compiler/rename/RnExpr.hs +++ b/compiler/rename/RnExpr.hs @@ -208,8 +208,6 @@ rnExpr (NegApp _ e _) ------------------------------------------ -- Template Haskell extensions --- Don't ifdef-HAVE_INTERPRETER them because we want to fail gracefully --- (not with an rnExpr crash) in a stage-1 compiler. rnExpr e@(HsBracket _ br_body) = rnBracket e br_body rnExpr (HsSpliceE _ splice) = rnSpliceExpr splice diff --git a/compiler/simplCore/SimplCore.hs b/compiler/simplCore/SimplCore.hs index 572084c420..b3af87b2af 100644 --- a/compiler/simplCore/SimplCore.hs +++ b/compiler/simplCore/SimplCore.hs @@ -462,11 +462,7 @@ doCorePass (CoreDoRuleCheck phase pat) = ruleCheckPass phase pat doCorePass CoreDoNothing = return doCorePass (CoreDoPasses passes) = runCorePasses passes -#if defined(HAVE_INTERPRETER) doCorePass (CoreDoPluginPass _ pass) = {-# SCC "Plugin" #-} pass -#else -doCorePass pass@CoreDoPluginPass {} = pprPanic "doCorePass" (ppr pass) -#endif doCorePass pass@CoreDesugar = pprPanic "doCorePass" (ppr pass) doCorePass pass@CoreDesugarOpt = pprPanic "doCorePass" (ppr pass) diff --git a/compiler/typecheck/TcPluginM.hs b/compiler/typecheck/TcPluginM.hs index 3785a4aac5..f4fe3013a3 100644 --- a/compiler/typecheck/TcPluginM.hs +++ b/compiler/typecheck/TcPluginM.hs @@ -3,7 +3,6 @@ -- access select functions of the 'TcM', principally those to do with -- reading parts of the state. module TcPluginM ( -#if defined(HAVE_INTERPRETER) -- * Basic TcPluginM functionality TcPluginM, tcPluginIO, @@ -49,10 +48,8 @@ module TcPluginM ( newEvVar, setEvBind, getEvBindsTcPluginM -#endif ) where -#if defined(HAVE_INTERPRETER) import GhcPrelude import qualified TcRnMonad as TcM @@ -190,7 +187,3 @@ setEvBind :: EvBind -> TcPluginM () setEvBind ev_bind = do tc_evbinds <- getEvBindsTcPluginM unsafeTcPluginTcM $ TcM.addTcEvBind tc_evbinds ev_bind -#else --- this dummy import is needed as a consequence of NoImplicitPrelude -import GhcPrelude () -#endif diff --git a/ghc/Main.hs b/ghc/Main.hs index 614b45f277..1f8ccdb840 100644 --- a/ghc/Main.hs +++ b/ghc/Main.hs @@ -1,4 +1,7 @@ -{-# LANGUAGE CPP, NondecreasingIndentation, TupleSections #-} +{-# LANGUAGE CPP #-} +{-# LANGUAGE LambdaCase #-} +{-# LANGUAGE NondecreasingIndentation #-} +{-# LANGUAGE TupleSections #-} {-# OPTIONS -fno-warn-incomplete-patterns -optc-DNON_POSIX_SOURCE #-} ----------------------------------------------------------------------------- @@ -30,12 +33,8 @@ import GHCi.UI ( interactiveUI, ghciWelcomeMsg, defaultGhciSettings ) #endif -- Frontend plugins -#if defined(HAVE_INTERPRETER) import DynamicLoading ( loadFrontendPlugin ) import Plugins -#else -import DynamicLoading ( pluginError ) -#endif #if defined(HAVE_INTERNAL_INTERPRETER) import DynamicLoading ( initializePlugins ) #endif @@ -44,6 +43,8 @@ import Module ( ModuleName ) -- Various other random stuff that we need import GHC.HandleEncoding +import GHC.Platform +import GHC.Platform.Host import Config import Constants import HscTypes @@ -54,6 +55,8 @@ import DynFlags hiding (WarnReason(..)) import ErrUtils import FastString import Outputable +import SysTools.BaseDir +import SysTools.Settings import SrcLoc import Util import Panic @@ -74,6 +77,8 @@ import System.Environment import System.Exit import System.FilePath import Control.Monad +import Control.Monad.Trans.Class +import Control.Monad.Trans.Except (throwE, runExceptT) import Data.Char import Data.List import Data.Maybe @@ -122,7 +127,7 @@ main = do case mode of Left preStartupMode -> do case preStartupMode of - ShowSupportedExtensions -> showSupportedExtensions + ShowSupportedExtensions -> showSupportedExtensions mbMinusB ShowVersion -> showVersion ShowNumVersion -> putStrLn cProjectVersion ShowOptions isInteractive -> showOptions isInteractive @@ -776,8 +781,24 @@ showInfo dflags = do let sq x = " [" ++ x ++ "\n ]" putStrLn $ sq $ intercalate "\n ," $ map show $ compilerInfo dflags -showSupportedExtensions :: IO () -showSupportedExtensions = mapM_ putStrLn supportedLanguagesAndExtensions +-- TODO use ErrUtils once that is disentangled from all the other GhcMonad stuff? +showSupportedExtensions :: Maybe String -> IO () +showSupportedExtensions m_top_dir = do + res <- runExceptT $ do + top_dir <- lift (tryFindTopDir m_top_dir) >>= \case + Nothing -> throwE $ SettingsError_MissingData "Could not find the top directory, missing -B flag" + Just dir -> pure dir + initSettings top_dir + targetPlatformMini <- case res of + Right s -> pure $ platformMini $ sTargetPlatform s + Left (SettingsError_MissingData msg) -> do + hPutStrLn stderr $ "WARNING: " ++ show msg + hPutStrLn stderr $ "cannot know target platform so guessing target == host (native compiler)." + pure cHostPlatformMini + Left (SettingsError_BadData msg) -> do + hPutStrLn stderr msg + exitWith $ ExitFailure 1 + mapM_ putStrLn $ supportedLanguagesAndExtensions targetPlatformMini showVersion :: IO () showVersion = putStrLn (cProjectName ++ ", version " ++ cProjectVersion) @@ -847,15 +868,11 @@ dumpPackagesSimple dflags = putMsg dflags (pprPackagesSimple dflags) -- Frontend plugin support doFrontend :: ModuleName -> [(String, Maybe Phase)] -> Ghc () -#if !defined(HAVE_INTERPRETER) -doFrontend modname _ = pluginError [modname] -#else doFrontend modname srcs = do hsc_env <- getSession frontend_plugin <- liftIO $ loadFrontendPlugin hsc_env modname frontend frontend_plugin (reverse $ frontendPluginOpts (hsc_dflags hsc_env)) srcs -#endif -- ----------------------------------------------------------------------------- -- ABI hash support diff --git a/ghc/ghc-bin.cabal.in b/ghc/ghc-bin.cabal.in index cf5fde03e3..721df4ea62 100644 --- a/ghc/ghc-bin.cabal.in +++ b/ghc/ghc-bin.cabal.in @@ -24,11 +24,6 @@ Flag ghci Default: False Manual: True -Flag ext-interp - Description: Build external interpreter support - Default: True - Manual: True - Flag threaded Description: Link the ghc executable against the threaded RTS Default: True @@ -44,6 +39,7 @@ Executable ghc directory >= 1 && < 1.4, process >= 1 && < 1.7, filepath >= 1 && < 1.5, + transformers == 0.5.*, ghc-boot == @ProjectVersionMunged@, ghc == @ProjectVersionMunged@ @@ -66,8 +62,7 @@ Executable ghc ghc-prim >= 0.5.0 && < 0.7, ghci == @ProjectVersionMunged@, haskeline == 0.7.*, - time >= 1.8 && < 1.10, - transformers == 0.5.* + time >= 1.8 && < 1.10 CPP-Options: -DHAVE_INTERNAL_INTERPRETER GHC-Options: -fno-warn-name-shadowing Other-Modules: @@ -97,12 +92,6 @@ Executable ghc if flag(threaded) ghc-options: -threaded - if flag(ext-interp) - cpp-options: -DHAVE_EXTERNAL_INTERPRETER - - if flag(ghci) || flag(ext-interp) - cpp-options: -DHAVE_INTERPRETER - Other-Extensions: CPP NondecreasingIndentation diff --git a/hadrian/cfg/system.config.in b/hadrian/cfg/system.config.in index 2380baf9c0..13f695f076 100644 --- a/hadrian/cfg/system.config.in +++ b/hadrian/cfg/system.config.in @@ -59,12 +59,16 @@ host-platform = @HostPlatform@ host-arch = @HostArch_CPP@ host-os = @HostOS_CPP@ host-vendor = @HostVendor_CPP@ +host-os-haskell = @HaskellHostOs@ +host-arch-haskell = @HaskellHostArch@ target-platform = @TargetPlatform@ target-platform-full = @TargetPlatformFull@ target-arch = @TargetArch_CPP@ target-os = @TargetOS_CPP@ target-vendor = @TargetVendor_CPP@ +target-os-haskell = @HaskellTargetOs@ +target-arch-haskell = @HaskellTargetArch@ llvm-target = @LLVMTarget_CPP@ cross-compiling = @CrossCompiling@ @@ -142,8 +146,6 @@ settings-clang-command = @SettingsClangCommand@ settings-llc-command = @SettingsLlcCommand@ settings-opt-command = @SettingsOptCommand@ -haskell-target-os = @HaskellTargetOs@ -haskell-target-arch = @HaskellTargetArch@ target-word-size = @TargetWordSize@ haskell-have-gnu-nonexec-stack = @HaskellHaveGnuNonexecStack@ haskell-have-ident-directive = @HaskellHaveIdentDirective@ diff --git a/hadrian/src/Oracles/Setting.hs b/hadrian/src/Oracles/Setting.hs index 51ccc729a3..2a4f5d0572 100644 --- a/hadrian/src/Oracles/Setting.hs +++ b/hadrian/src/Oracles/Setting.hs @@ -42,6 +42,8 @@ data Setting = BuildArch | HostOs | HostPlatform | HostVendor + | HostArchHaskell + | HostOsHaskell | IconvIncludeDir | IconvLibDir | LlvmTarget @@ -58,6 +60,8 @@ data Setting = BuildArch | TargetPlatform | TargetPlatformFull | TargetVendor + | TargetArchHaskell + | TargetOsHaskell -- TODO: Reduce the variety of similar flags (e.g. CPP and non-CPP versions). -- | Each 'SettingList' comes from the file @hadrian/cfg/system.config@, @@ -126,6 +130,8 @@ setting key = lookupValueOrError configFile $ case key of HostOs -> "host-os" HostPlatform -> "host-platform" HostVendor -> "host-vendor" + HostArchHaskell -> "host-arch-haskell" + HostOsHaskell -> "host-os-haskell" IconvIncludeDir -> "iconv-include-dir" IconvLibDir -> "iconv-lib-dir" LlvmTarget -> "llvm-target" @@ -142,6 +148,8 @@ setting key = lookupValueOrError configFile $ case key of TargetPlatform -> "target-platform" TargetPlatformFull -> "target-platform-full" TargetVendor -> "target-vendor" + TargetArchHaskell -> "target-arch-haskell" + TargetOsHaskell -> "target-os-haskell" -- | Look up the value of a 'SettingList' in @cfg/system.config@, tracking the -- result. diff --git a/hadrian/src/Rules/Generate.hs b/hadrian/src/Rules/Generate.hs index 4bb3876999..a93ce1bb31 100644 --- a/hadrian/src/Rules/Generate.hs +++ b/hadrian/src/Rules/Generate.hs @@ -116,8 +116,9 @@ generatePackageCode context@(Context stage pkg _) = do when (pkg == ghcPrim) $ do root <//> dir -/- "GHC/Prim.hs" %> genPrimopCode context root <//> dir -/- "GHC/PrimopWrappers.hs" %> genPrimopCode context - when (pkg == ghcBoot) $ + when (pkg == ghcBoot) $ do root <//> dir -/- "GHC/Version.hs" %> go generateVersionHs + root <//> dir -/- "GHC/Platform/Host.hs" %> go generatePlatformHostHs when (pkg == compiler) $ do root -/- primopsTxt stage %> \file -> do @@ -299,8 +300,8 @@ generateSettings = do , ("unlit command", ("$topdir/bin/" <>) <$> expr (programName (ctx { Context.package = unlit }))) , ("cross compiling", expr $ yesNo <$> flag CrossCompiling) , ("target platform string", getSetting TargetPlatform) - , ("target os", expr $ lookupValueOrError configFile "haskell-target-os") - , ("target arch", expr $ lookupValueOrError configFile "haskell-target-arch") + , ("target os", getSetting TargetOsHaskell) + , ("target arch", getSetting TargetArchHaskell) , ("target word size", expr $ lookupValueOrError configFile "target-word-size") , ("target has GNU nonexec stack", expr $ lookupValueOrError configFile "haskell-have-gnu-nonexec-stack") , ("target has .ident directive", expr $ lookupValueOrError configFile "haskell-have-ident-directive") @@ -515,3 +516,27 @@ generateVersionHs = do , "cProjectPatchLevel2 :: String" , "cProjectPatchLevel2 = " ++ show cProjectPatchLevel2 ] + +-- | Generate @Platform/Host.hs@ files. +generatePlatformHostHs :: Expr String +generatePlatformHostHs = do + trackGenerateHs + cHostPlatformArch <- getSetting HostArchHaskell + cHostPlatformOS <- getSetting HostOsHaskell + return $ unlines + [ "module GHC.Platform.Host where" + , "" + , "import GHC.Platform" + , "" + , "cHostPlatformArch :: Arch" + , "cHostPlatformArch = " ++ cHostPlatformArch + , "" + , "cHostPlatformOS :: OS" + , "cHostPlatformOS = " ++ cHostPlatformOS + , "" + , "cHostPlatformMini :: PlatformMini" + , "cHostPlatformMini = PlatformMini" + , " { platformMini_arch = cHostPlatformArch" + , " , platformMini_os = cHostPlatformOS" + , " }" + ] diff --git a/hadrian/src/Settings/Packages.hs b/hadrian/src/Settings/Packages.hs index 614d76cb7b..22cc4f86f2 100644 --- a/hadrian/src/Settings/Packages.hs +++ b/hadrian/src/Settings/Packages.hs @@ -74,7 +74,6 @@ packageArgs = do , builder (Cabal Flags) ? mconcat [ ghcWithNativeCodeGen ? arg "ncg" , ghcWithInterpreter ? notStage0 ? arg "ghci" - , notStage0 ? not windowsHost ? notM cross ? arg "ext-interp" , cross ? arg "-terminfo" , notStage0 ? intLib == integerGmp ? arg "integer-gmp" @@ -89,7 +88,6 @@ packageArgs = do , builder (Cabal Flags) ? mconcat [ ghcWithInterpreter ? notStage0 ? arg "ghci" - , notStage0 ? not windowsHost ? notM cross ? arg "ext-interp" , cross ? arg "-terminfo" -- the 'threaded' flag is True by default, but -- let's record explicitly that we link all ghc @@ -123,8 +121,6 @@ packageArgs = do -- behind the @-fghci@ flag. , package ghci ? mconcat [ notStage0 ? builder (Cabal Flags) ? arg "ghci" - , notStage0 ? builder (Cabal Flags) ? not windowsHost ? notM cross - ? arg "ext-interp" , cross ? stage0 ? builder (Cabal Flags) ? arg "ghci" ] -------------------------------- haddock ------------------------------- diff --git a/libraries/ghc-boot/GHC/Platform.hs b/libraries/ghc-boot/GHC/Platform.hs index 5e309b993e..bff9582c26 100644 --- a/libraries/ghc-boot/GHC/Platform.hs +++ b/libraries/ghc-boot/GHC/Platform.hs @@ -3,7 +3,8 @@ -- | A description of the platform we're compiling for. -- module GHC.Platform ( - Platform(..), + PlatformMini(..), + Platform(..), platformArch, platformOS, Arch(..), OS(..), ArmISA(..), @@ -29,12 +30,21 @@ where import Prelude -- See Note [Why do we import Prelude here?] +-- | Contains the bare-bones arch and os information. This isn't enough for +-- code gen, but useful for tasks where we can fall back upon the host +-- platform, as this is all we know about the host platform. +data PlatformMini + = PlatformMini + { platformMini_arch :: Arch + , platformMini_os :: OS + } + deriving (Read, Show, Eq) + -- | Contains enough information for the native code generator to emit -- code for this platform. data Platform = Platform { - platformArch :: Arch, - platformOS :: OS, + platformMini :: PlatformMini, -- Word size in bytes (i.e. normally 4 or 8, -- for 32bit and 64bit platforms respectively) platformWordSize :: {-# UNPACK #-} !Int, @@ -46,6 +56,13 @@ data Platform } deriving (Read, Show, Eq) +-- | Legacy accessor +platformArch :: Platform -> Arch +platformArch = platformMini_arch . platformMini + +-- | Legacy accessor +platformOS :: Platform -> OS +platformOS = platformMini_os . platformMini -- | Architectures that the native code generator knows about. -- TODO: It might be nice to extend these constructors with information diff --git a/libraries/ghc-boot/GHC/Settings.hs b/libraries/ghc-boot/GHC/Settings.hs index fc9f95a586..0433e3e88f 100644 --- a/libraries/ghc-boot/GHC/Settings.hs +++ b/libraries/ghc-boot/GHC/Settings.hs @@ -43,8 +43,10 @@ getTargetPlatform settingsFile mySettings = do crossCompiling <- getBooleanSetting "cross compiling" pure $ Platform - { platformArch = targetArch - , platformOS = targetOS + { platformMini = PlatformMini + { platformMini_arch = targetArch + , platformMini_os = targetOS + } , platformWordSize = targetWordSize , platformUnregisterised = targetUnregisterised , platformHasGnuNonexecStack = targetHasGnuNonexecStack diff --git a/libraries/ghc-boot/GHC/UniqueSubdir.hs b/libraries/ghc-boot/GHC/UniqueSubdir.hs index 49ae05e526..b59fdc43ce 100644 --- a/libraries/ghc-boot/GHC/UniqueSubdir.hs +++ b/libraries/ghc-boot/GHC/UniqueSubdir.hs @@ -1,6 +1,5 @@ module GHC.UniqueSubdir ( uniqueSubdir - , uniqueSubdir0 ) where import Prelude -- See Note [Why do we import Prelude here?] @@ -13,18 +12,13 @@ import GHC.Version (cProjectVersion) -- | A filepath like @x86_64-linux-7.6.3@ with the platform string to use when -- constructing platform-version-dependent files that need to co-exist. -- -uniqueSubdir :: Platform -> FilePath -uniqueSubdir platform = uniqueSubdir0 - (stringEncodeArch $ platformArch platform) - (stringEncodeOS $ platformOS platform) - --- | 'ghc-pkg' falls back on the host platform if the settings file is missing, +-- 'ghc-pkg' falls back on the host platform if the settings file is missing, -- and so needs this since we don't have information about the host platform in --- as much detail as 'Platform'. -uniqueSubdir0 :: String -> String -> FilePath -uniqueSubdir0 arch os = intercalate "-" - [ arch - , os +-- as much detail as 'Platform', so we use 'PlatformMini' instead. +uniqueSubdir :: PlatformMini -> FilePath +uniqueSubdir archOs = intercalate "-" + [ stringEncodeArch $ platformMini_arch archOs + , stringEncodeOS $ platformMini_os archOs , cProjectVersion ] -- NB: This functionality is reimplemented in Cabal, so if you diff --git a/libraries/ghc-boot/ghc-boot.cabal.in b/libraries/ghc-boot/ghc-boot.cabal.in index aed75b0c8a..f986810b6b 100644 --- a/libraries/ghc-boot/ghc-boot.cabal.in +++ b/libraries/ghc-boot/ghc-boot.cabal.in @@ -44,6 +44,7 @@ Library GHC.ForeignSrcLang GHC.HandleEncoding GHC.Platform + GHC.Platform.Host GHC.Settings GHC.UniqueSubdir GHC.Version @@ -51,6 +52,7 @@ Library -- but done by Hadrian -- autogen-modules: -- GHC.Version + -- GHC.Platform.Host build-depends: base >= 4.7 && < 4.14, binary == 0.8.*, diff --git a/libraries/ghc-boot/ghc.mk b/libraries/ghc-boot/ghc.mk index 29c5376560..9c5d695d8c 100644 --- a/libraries/ghc-boot/ghc.mk +++ b/libraries/ghc-boot/ghc.mk @@ -34,3 +34,28 @@ libraries/ghc-boot/dist-boot/package-data.mk: \ libraries/ghc-boot/dist-boot/build/GHC/Version.hs libraries/ghc-boot/dist-install/package-data.mk: \ libraries/ghc-boot/dist-install/build/GHC/Version.hs + +libraries/ghc-boot/dist-boot/build/GHC/Platform/Host.hs \ +libraries/ghc-boot/dist-install/build/GHC/Platform/Host.hs: mk/project.mk | $$(dir $$@)/. + $(call removeFiles,$@) + @echo "module GHC.Platform.Host where" >> $@ + @echo >> $@ + @echo 'import GHC.Platform' >> $@ + @echo >> $@ + @echo 'cHostPlatformArch :: Arch' >> $@ + @echo 'cHostPlatformArch = $(HaskellHostArch)' >> $@ + @echo >> $@ + @echo 'cHostPlatformOS :: OS' >> $@ + @echo 'cHostPlatformOS = $(HaskellHostOs)' >> $@ + @echo >> $@ + @echo 'cHostPlatformMini :: PlatformMini' >> $@ + @echo 'cHostPlatformMini = PlatformMini' >> $@ + @echo ' { platformMini_arch = cHostPlatformArch' >> $@ + @echo ' , platformMini_os = cHostPlatformOS' >> $@ + @echo ' }' >> $@ + @echo done. + +libraries/ghc-boot/dist-boot/package-data.mk: \ + libraries/ghc-boot/dist-boot/build/GHC/Platform/Host.hs +libraries/ghc-boot/dist-install/package-data.mk: \ + libraries/ghc-boot/dist-install/build/GHC/Platform/Host.hs diff --git a/libraries/ghci/GHCi/BreakArray.hs b/libraries/ghci/GHCi/BreakArray.hs index 41a2ab498f..8ab813a5a7 100644 --- a/libraries/ghci/GHCi/BreakArray.hs +++ b/libraries/ghci/GHCi/BreakArray.hs @@ -19,17 +19,14 @@ module GHCi.BreakArray ( BreakArray -#if defined(HAVE_INTERPRETER) (BA) -- constructor is exported only for ByteCodeGen , newBreakArray , getBreak , setBreakOn , setBreakOff , showBreakArray -#endif ) where -#if defined(HAVE_INTERPRETER) import Prelude -- See note [Why do we import Prelude here?] import Control.Monad import Data.Word @@ -116,6 +113,3 @@ readBA# array i = IO $ \s -> readBreakArray :: BreakArray -> Int -> IO Word8 readBreakArray (BA array) (I# i) = readBA# array i -#else -data BreakArray -#endif diff --git a/libraries/ghci/GHCi/InfoTable.hsc b/libraries/ghci/GHCi/InfoTable.hsc index 826e3bc2fd..ab13485e28 100644 --- a/libraries/ghci/GHCi/InfoTable.hsc +++ b/libraries/ghci/GHCi/InfoTable.hsc @@ -10,13 +10,10 @@ -- module GHCi.InfoTable ( -#if defined(HAVE_INTERPRETER) mkConInfoTable -#endif ) where import Prelude -- See note [Why do we import Prelude here?] -#if defined(HAVE_INTERPRETER) import Foreign import Foreign.C import GHC.Ptr @@ -24,7 +21,6 @@ import GHC.Exts import GHC.Exts.Heap import Data.ByteString (ByteString) import qualified Data.ByteString as BS -#endif ghciTablesNextToCode :: Bool #if defined(TABLES_NEXT_TO_CODE) @@ -33,7 +29,6 @@ ghciTablesNextToCode = True ghciTablesNextToCode = False #endif -#if defined(HAVE_INTERPRETER) /* To end */ -- NOTE: Must return a pointer acceptable for use in the header of a closure. -- If tables_next_to_code is enabled, then it must point the the 'code' field. -- Otherwise, it should point to the start of the StgInfoTable. @@ -387,4 +382,3 @@ wORD_SIZE = (#const SIZEOF_HSINT) conInfoTableSizeB :: Int conInfoTableSizeB = wORD_SIZE + itblSize -#endif /* HAVE_INTERPRETER */ diff --git a/libraries/ghci/ghci.cabal.in b/libraries/ghci/ghci.cabal.in index 4da94b3549..849e2a147a 100644 --- a/libraries/ghci/ghci.cabal.in +++ b/libraries/ghci/ghci.cabal.in @@ -22,11 +22,6 @@ Flag ghci Default: False Manual: True -Flag ext-interp - Description: Build external interpreter support - Default: True - Manual: True - source-repository head type: git location: https://gitlab.haskell.org/ghc/ghc.git @@ -61,12 +56,6 @@ library GHCi.Signals GHCi.TH - if flag(ext-interp) - CPP-Options: -DHAVE_EXTERNAL_INTERPRETER - - if flag(ghci) || flag(ext-interp) - CPP-Options: -DHAVE_INTERPRETER - include-dirs: @FFIIncludeDir@ exposed-modules: diff --git a/mk/config.mk.in b/mk/config.mk.in index ca17e8689b..a7fff60a82 100644 --- a/mk/config.mk.in +++ b/mk/config.mk.in @@ -486,6 +486,8 @@ GHC_PACKAGE_DB_FLAG = @GHC_PACKAGE_DB_FLAG@ GccExtraViaCOpts = @GccExtraViaCOpts@ LdHasFilelist = @LdHasFilelist@ ArArgs = @ArArgs@ +HaskellHostOs = @HaskellHostOs@ +HaskellHostArch = @HaskellHostArch@ HaskellTargetOs = @HaskellTargetOs@ HaskellTargetArch = @HaskellTargetArch@ TargetWordSize = @TargetWordSize@ diff --git a/utils/ghc-pkg/Main.hs b/utils/ghc-pkg/Main.hs index bace7356cd..b5073662c7 100644 --- a/utils/ghc-pkg/Main.hs +++ b/utils/ghc-pkg/Main.hs @@ -35,13 +35,9 @@ import GHC.PackageDb (BinaryStringRep(..)) import GHC.HandleEncoding import GHC.BaseDir (getBaseDir) import GHC.Settings (getTargetPlatform, maybeReadFuzzy) -import GHC.Platform - ( platformArch, platformOS - , stringEncodeArch, stringEncodeOS - ) -import GHC.UniqueSubdir - ( uniqueSubdir0 - ) +import GHC.Platform (platformMini) +import GHC.Platform.Host (cHostPlatformMini) +import GHC.UniqueSubdir (uniqueSubdir) import GHC.Version ( cProjectVersion ) import qualified Distribution.Simple.PackageIndex as PackageIndex import qualified Data.Graph as Graph @@ -642,11 +638,11 @@ getPkgDatabases verbosity mode use_user use_cache expand_vars my_flags = do -- See Note [Settings File] about this file, and why we need GHC to share it with us. let settingsFile = top_dir </> "settings" exists_settings_file <- doesFileExist settingsFile - (arch, os) <- case exists_settings_file of + targetPlatformMini <- case exists_settings_file of False -> do warn $ "WARNING: settings file doesn't exist " ++ show settingsFile warn "cannot know target platform so guessing target == host (native compiler)." - pure (HOST_ARCH, HOST_OS) + pure cHostPlatformMini True -> do settingsStr <- readFile settingsFile mySettings <- case maybeReadFuzzy settingsStr of @@ -655,9 +651,9 @@ getPkgDatabases verbosity mode use_user use_cache expand_vars my_flags = do -- least) but completely inexcusable to have a malformed one. Nothing -> die $ "Can't parse settings file " ++ show settingsFile case getTargetPlatform settingsFile mySettings of - Right platform -> pure (stringEncodeArch $ platformArch platform, stringEncodeOS $ platformOS platform) + Right platform -> pure $ platformMini platform Left e -> die e - let subdir = uniqueSubdir0 arch os + let subdir = uniqueSubdir targetPlatformMini dir = appdir </> subdir r <- lookForPackageDBIn dir case r of |