From 0500a66f72ca79721576e2844b531760eccef78e Mon Sep 17 00:00:00 2001 From: Luite Stegeman Date: Sun, 22 Sep 2024 12:09:58 +0200 Subject: [PATCH 1/3] Disable speculative evaluation in coreprep in ghc 9.4, 9.6, 9.8 Speculative evaluation was found to cause a large increase in allocations in certain situations. We disable it for now. --- overlays/bootstrap.nix | 1 + ...ghc-9.4-9.6-9.8-disable-coreprep-spec-eval.patch | 13 +++++++++++++ 2 files changed, 14 insertions(+) create mode 100644 overlays/patches/ghc/ghc-9.4-9.6-9.8-disable-coreprep-spec-eval.patch diff --git a/overlays/bootstrap.nix b/overlays/bootstrap.nix index 84601b2b48..43759a3741 100644 --- a/overlays/bootstrap.nix +++ b/overlays/bootstrap.nix @@ -84,6 +84,7 @@ in { # will be applied to most versions of the GHC anyway (reordering the patches # results in rebuilds of GHC and reduces sharing in /nix/store). in always ./patches/ghc/dll-loader-8.4.2.patch # https://gitlab.haskell.org/ghc/ghc/merge_requests/949 -- open + ++ fromUntil "9.4" "9.10" ./patches/ghc/ghc-9.4-9.6-9.8-disable-coreprep-spec-eval.patch # causes more allocations ++ until "9.2" ./patches/ghc/ghc-8.4.3-Cabal2201-no-hackage-tests.patch # ? ++ until "9.2" ./patches/ghc/cabal-host.patch # https://github.com/haskell/cabal/issues/5887 ++ fromUntil "9.2" "9.4" ./patches/ghc/ghc-9.2-cabal-host.patch # https://github.com/haskell/cabal/issues/5887 diff --git a/overlays/patches/ghc/ghc-9.4-9.6-9.8-disable-coreprep-spec-eval.patch b/overlays/patches/ghc/ghc-9.4-9.6-9.8-disable-coreprep-spec-eval.patch new file mode 100644 index 0000000000..4f3ea2632d --- /dev/null +++ b/overlays/patches/ghc/ghc-9.4-9.6-9.8-disable-coreprep-spec-eval.patch @@ -0,0 +1,13 @@ +diff --git a/compiler/GHC/CoreToStg/Prep.hs b/compiler/GHC/CoreToStg/Prep.hs +index c463f41121..58b1d957c8 100644 +--- a/compiler/GHC/CoreToStg/Prep.hs ++++ b/compiler/GHC/CoreToStg/Prep.hs +@@ -1759,7 +1759,7 @@ data OkToSpec + + mkFloat :: CorePrepEnv -> Demand -> Bool -> Id -> CpeRhs -> FloatingBind + mkFloat env dmd is_unlifted bndr rhs +- | is_strict || ok_for_spec -- See Note [Speculative evaluation] ++ | is_strict {-|| ok_for_spec-} -- See Note [Speculative evaluation] + , not is_hnf = FloatCase rhs bndr DEFAULT [] ok_for_spec + -- Don't make a case for a HNF binding, even if it's strict + -- Otherwise we get case (\x -> e) of ...! From bc773fa03eba677b2cf390a182e080c1887ca2e3 Mon Sep 17 00:00:00 2001 From: Luite Stegeman Date: Tue, 24 Sep 2024 11:12:37 +0200 Subject: [PATCH 2/3] refine situations where speculation is allowed in coreprep --- ...4-9.6-9.8-disable-coreprep-spec-eval.patch | 25 ++++++++++++------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/overlays/patches/ghc/ghc-9.4-9.6-9.8-disable-coreprep-spec-eval.patch b/overlays/patches/ghc/ghc-9.4-9.6-9.8-disable-coreprep-spec-eval.patch index 4f3ea2632d..75abfd400d 100644 --- a/overlays/patches/ghc/ghc-9.4-9.6-9.8-disable-coreprep-spec-eval.patch +++ b/overlays/patches/ghc/ghc-9.4-9.6-9.8-disable-coreprep-spec-eval.patch @@ -1,13 +1,20 @@ diff --git a/compiler/GHC/CoreToStg/Prep.hs b/compiler/GHC/CoreToStg/Prep.hs -index c463f41121..58b1d957c8 100644 +index c463f41121..3673b94991 100644 --- a/compiler/GHC/CoreToStg/Prep.hs +++ b/compiler/GHC/CoreToStg/Prep.hs -@@ -1759,7 +1759,7 @@ data OkToSpec +@@ -1785,7 +1785,14 @@ mkFloat env dmd is_unlifted bndr rhs + where + is_hnf = exprIsHNF rhs + is_strict = isStrUsedDmd dmd +- ok_for_spec = exprOkForSpecEval (not . is_rec_call) rhs ++ ok_for_spec = exprOkForSpecEval fun_ok_for_spec rhs ++ fun_ok_for_spec i ++ | is_rec_call i = False ++ | otherwise = ++ case idDetails i of ++ DFunId {} -> False ++ DataConWorkId {} -> False ++ _ -> True + is_rec_call = (`elemUnVarSet` cpe_rec_ids env) - mkFloat :: CorePrepEnv -> Demand -> Bool -> Id -> CpeRhs -> FloatingBind - mkFloat env dmd is_unlifted bndr rhs -- | is_strict || ok_for_spec -- See Note [Speculative evaluation] -+ | is_strict {-|| ok_for_spec-} -- See Note [Speculative evaluation] - , not is_hnf = FloatCase rhs bndr DEFAULT [] ok_for_spec - -- Don't make a case for a HNF binding, even if it's strict - -- Otherwise we get case (\x -> e) of ...! + emptyFloats :: Floats From 82665f88d15e516b0c879de35250dbd2f5231728 Mon Sep 17 00:00:00 2001 From: Luite Stegeman Date: Tue, 24 Sep 2024 19:37:28 +0200 Subject: [PATCH 3/3] updated no-speculation patch applies to GHC 9.10 --- overlays/bootstrap.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/overlays/bootstrap.nix b/overlays/bootstrap.nix index 43759a3741..4b3a3d4bbd 100644 --- a/overlays/bootstrap.nix +++ b/overlays/bootstrap.nix @@ -84,7 +84,7 @@ in { # will be applied to most versions of the GHC anyway (reordering the patches # results in rebuilds of GHC and reduces sharing in /nix/store). in always ./patches/ghc/dll-loader-8.4.2.patch # https://gitlab.haskell.org/ghc/ghc/merge_requests/949 -- open - ++ fromUntil "9.4" "9.10" ./patches/ghc/ghc-9.4-9.6-9.8-disable-coreprep-spec-eval.patch # causes more allocations + ++ fromUntil "9.4" "9.12" ./patches/ghc/ghc-9.4-9.6-9.8-disable-coreprep-spec-eval.patch # causes more allocations ++ until "9.2" ./patches/ghc/ghc-8.4.3-Cabal2201-no-hackage-tests.patch # ? ++ until "9.2" ./patches/ghc/cabal-host.patch # https://github.com/haskell/cabal/issues/5887 ++ fromUntil "9.2" "9.4" ./patches/ghc/ghc-9.2-cabal-host.patch # https://github.com/haskell/cabal/issues/5887