[commit: ghc] wip/nfs-locking: Eliminate some uses of fromJust (8657341)

git at git.haskell.org git at git.haskell.org
Fri Oct 27 00:41:28 UTC 2017


Repository : ssh://git@git.haskell.org/ghc

On branch  : wip/nfs-locking
Link       : http://ghc.haskell.org/trac/ghc/changeset/8657341ded43e9671c48929627814e1e64b22ead/ghc

>---------------------------------------------------------------

commit 8657341ded43e9671c48929627814e1e64b22ead
Author: Ben Gamari <ben at smart-cactus.org>
Date:   Sat Oct 8 15:10:33 2016 -0400

    Eliminate some uses of fromJust


>---------------------------------------------------------------

8657341ded43e9671c48929627814e1e64b22ead
 src/Builder.hs | 7 +++++--
 src/Rules.hs   | 8 +++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/Builder.hs b/src/Builder.hs
index 55d561e..6f892f2 100644
--- a/src/Builder.hs
+++ b/src/Builder.hs
@@ -98,11 +98,14 @@ isOptional = \case
     Objdump  -> True
     _        -> False
 
--- TODO: Get rid of fromJust.
 -- | Determine the location of a 'Builder'.
 builderPath :: Builder -> Action FilePath
 builderPath builder = case builderProvenance builder of
-    Just context -> return . fromJust $ programPath context
+    Just context
+      | Just path <- programPath context -> return path
+      | otherwise                        ->
+        error $ "Cannot determine builderPath for " ++ show builder
+             ++ " in context " ++ show context
     Nothing -> case builder of
         Alex          -> fromKey "alex"
         Ar            -> fromKey "ar"
diff --git a/src/Rules.hs b/src/Rules.hs
index f69cc95..e62ecc7 100644
--- a/src/Rules.hs
+++ b/src/Rules.hs
@@ -49,7 +49,13 @@ topLevelTargets = do
                     docs <- interpretInContext context $ buildHaddock flavour
                     need $ libs ++ [ pkgHaddockFile context | docs && stage == Stage1 ]
                 else do -- otherwise build a program
-                    need [ fromJust $ programPath context ] -- TODO: drop fromJust
+                    need [ getProgramPath context ]
+  where
+    getProgramPath context =
+        case programPath context of
+          Nothing   -> error $ "topLevelTargets: Can't determine program path for context "
+                            ++ show context
+          Just path -> path
 
 packageRules :: Rules ()
 packageRules = do



More information about the ghc-commits mailing list