summaryrefslogtreecommitdiff
path: root/compiler/GHC/Unit
diff options
context:
space:
mode:
authorSylvain Henry <sylvain@haskus.fr>2021-04-09 14:39:27 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2021-04-10 05:31:14 -0400
commitb699c4fb0d23616a20d160f04a893f514fc7e38c (patch)
treed26e8dd39d908ec1c35945c613c48b39eba84b09 /compiler/GHC/Unit
parent2cdc95f9c068421a55c634933ab2d8596eb992fb (diff)
downloadhaskell-b699c4fb0d23616a20d160f04a893f514fc7e38c.tar.gz
Constants: add a note and fix minor doc glitches
Diffstat (limited to 'compiler/GHC/Unit')
-rw-r--r--compiler/GHC/Unit/State.hs40
1 files changed, 16 insertions, 24 deletions
diff --git a/compiler/GHC/Unit/State.hs b/compiler/GHC/Unit/State.hs
index 4a1cd29b25..fe4796d1fc 100644
--- a/compiler/GHC/Unit/State.hs
+++ b/compiler/GHC/Unit/State.hs
@@ -77,7 +77,6 @@ import GHC.Driver.Session
import GHC.Platform
import GHC.Platform.Ways
-import GHC.Platform.Constants
import GHC.Unit.Database
import GHC.Unit.Info
@@ -596,29 +595,22 @@ initUnits logger dflags cached_dbs = do
(homeUnitInstanceOf_ dflags)
(homeUnitInstantiations_ dflags)
- -- try to find platform constants
- mconstants <- do
- let
- try_parse d = do
- let p = d </> "DerivedConstants.h"
- doesFileExist p >>= \case
- True -> Just <$> parseConstantsHeader p
- False -> return Nothing
-
- find_constants [] = return Nothing
- find_constants (x:xs) = try_parse x >>= \case
- Nothing -> find_constants xs
- Just c -> return (Just c)
-
- if homeUnitId_ dflags == rtsUnitId
- then do
- -- we're building the RTS! Try to find the header in its includes
- find_constants (includePathsGlobal (includePaths dflags))
- else
- -- try to find the platform constants in the RTS unit
- case lookupUnitId unit_state rtsUnitId of
- Nothing -> return Nothing
- Just info -> find_constants (fmap ST.unpack (unitIncludeDirs info))
+ -- Try to find platform constants
+ --
+ -- See Note [Platform constants] in GHC.Platform
+ mconstants <- if homeUnitId_ dflags == rtsUnitId
+ then do
+ -- we're building the RTS! Lookup DerivedConstants.h in the include paths
+ lookupPlatformConstants (includePathsGlobal (includePaths dflags))
+ else
+ -- lookup the DerivedConstants.h header bundled with the RTS unit. We
+ -- don't fail if we can't find the RTS unit as it can be a valid (but
+ -- uncommon) case, e.g. building a C utility program (not depending on the
+ -- RTS) before building the RTS. In any case, we will fail later on if we
+ -- really need to use the platform constants but they have not been loaded.
+ case lookupUnitId unit_state rtsUnitId of
+ Nothing -> return Nothing
+ Just info -> lookupPlatformConstants (fmap ST.unpack (unitIncludeDirs info))
return (dbs,unit_state,home_unit,mconstants)