summaryrefslogtreecommitdiff
path: root/src/Simplify.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Simplify.hs')
-rw-r--r--src/Simplify.hs11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/Simplify.hs b/src/Simplify.hs
index 62a3a9c..c44d965 100644
--- a/src/Simplify.hs
+++ b/src/Simplify.hs
@@ -2,6 +2,7 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ImplicitParams #-}
+{-# LANGUAGE MultiWayIf #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
@@ -24,14 +25,14 @@ simplify' :: (?accumInScope :: Bool) => Ex env t -> Ex env t
simplify' = \case
-- inlining
ELet _ rhs body
- | not ?accumInScope || not (hasAdds rhs) -- cannot discard effectful computations
- , Occ lexOcc runOcc <- occCount IZ body
- , lexOcc <= One -- prevent code size blowup
- , runOcc <= One -- prevent runtime increase
- -> simplify' (subst1 rhs body)
| cheapExpr rhs
-> simplify' (subst1 rhs body)
+ | Occ lexOcc runOcc <- occCount IZ body
+ , ((not ?accumInScope || not (hasAdds rhs)) && lexOcc <= One && runOcc <= One) -- without effects, normal rules apply
+ || (lexOcc == One && runOcc == One) -- with effects, linear inlining is still allowed, but weakening is not
+ -> simplify' (subst1 rhs body)
+
-- let splitting
ELet _ (EPair _ a b) body ->
simplify' $