From 232002c44942491759e44aa93a03a6bc68afbadf Mon Sep 17 00:00:00 2001
From: James Foster <ratherforky@gmail.com>
Date: Sat, 13 Jul 2019 01:23:30 +0100
Subject: [PATCH] Make HsInstances and DynFlags compile with -O0 for Stage0 to
 speed up Hadrian builds (fixes #16936)

---
 hadrian/src/Settings/Packages.hs | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/hadrian/src/Settings/Packages.hs b/hadrian/src/Settings/Packages.hs
index 4c5407186c34..e120e7993c5a 100644
--- a/hadrian/src/Settings/Packages.hs
+++ b/hadrian/src/Settings/Packages.hs
@@ -50,7 +50,12 @@ packageArgs = do
           , builder (Ghc CompileHs) ? mconcat
             [ inputs ["//GHC.hs", "//GhcMake.hs"] ? arg "-fprof-auto"
             , input "//Parser.hs" ?
-              pure ["-fno-ignore-interface-pragmas", "-fcmm-sink" ] ]
+              pure ["-fno-ignore-interface-pragmas", "-fcmm-sink"]
+            -- These files take a very long time to compile with -O1,
+            -- so we use -O0 for them just in Stage0 to speed up the
+            -- build but not affect Stage1+ executables
+            , inputs ["//HsInstances.hs", "//DynFlags.hs"] ? stage0 ?
+              pure ["-O0"] ]
 
           , builder (Cabal Setup) ? mconcat
             [ arg $ "--ghc-option=-DSTAGE=" ++ show (fromEnum stage + 1)
@@ -71,7 +76,7 @@ packageArgs = do
             , ghcProfiled <$> flavour ?
               notStage0 ? arg "--ghc-pkg-option=--force" ]
 
-         , builder (Cabal Flags) ? mconcat
+          , builder (Cabal Flags) ? mconcat
             [ ghcWithNativeCodeGen ? arg "ncg"
             , ghcWithInterpreter ? notStage0 ? arg "ghci"
             , notStage0 ? not windowsHost ? notM cross ? arg "ext-interp"
@@ -172,7 +177,7 @@ packageArgs = do
         -- in Stage1, and at that point the configuration is just wrong.
         , package text ?
           builder (Cabal Flags) ? notStage0 ? intLib == integerSimple ?
-          pure [ "+integer-simple", "-bytestring-builder"] ]
+          pure ["+integer-simple", "-bytestring-builder"] ]
 
 -- | RTS-specific command line arguments.
 rtsPackageArgs :: Args
-- 
GitLab