diff options
author | Sebastian Graf <sebastian.graf@kit.edu> | 2021-05-28 20:01:34 +0200 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2021-06-27 14:57:39 -0400 |
commit | 37472a10da1ab39d22f1ab25b08fd6ef799cd0a7 (patch) | |
tree | 8cd4bc5355c6b2a7ce7686cc47cbe8d0ca007a91 /testsuite | |
parent | eee498bfce3cce03ba1017b65d559c79d5c2eb60 (diff) | |
download | haskell-37472a10da1ab39d22f1ab25b08fd6ef799cd0a7.tar.gz |
WorkWrap: Make mkWWstr and mkWWcpr generate fewer let bindings
In https://gitlab.haskell.org/ghc/ghc/-/merge_requests/5814#note_355144,
Simon noted that `mkWWstr` and `mkWWcpr` could generate fewer let bindings and
be implemented less indirectly by returning the rebuilt expressions directly, e.g. instead of
```
f :: (Int, Int) -> Int
f (x, y) = x+y
==>
f :: (Int, Int) -> Int
f p = case p of (x, y) ->
case x of I# x' ->
case y of I# y' ->
case $wf x' y' of r' ->
let r = I# r' -- immediately returned
in r
f :: Int# -> Int# -> Int#
$wf x' y' = let x = I# x' in -- only used in p
let y = I# y' in -- only used in p
let p = (x, y) in -- only used in the App below
case (\(x,y) -> x+y) p of I# r' ->
r'
```
we know generate
```
f :: (Int, Int) -> Int
f p = case p of (x, y) ->
case x of I# x' ->
case y of I# y' ->
case $wf x' y' of r' ->
I# r' -- 1 fewer let
f :: Int# -> Int# -> Int#
$wf x' y' = case (\(x,y) -> x+y) (I# x, I# y) of I# r' -> -- 3 fewer lets
r'
```
Which is much nicer and makes it easier to comprehend the output of
worker-wrapper pre-Simplification as well as puts less strain on the Simplifier.
I had to drop support for #18983, but we found that it's broken anyway.
Simon is working on a patch that provides a bit more justification.
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/tests/stranal/should_compile/T18982.stderr | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/testsuite/tests/stranal/should_compile/T18982.stderr b/testsuite/tests/stranal/should_compile/T18982.stderr index 19f25be15c..9b1f852dda 100644 --- a/testsuite/tests/stranal/should_compile/T18982.stderr +++ b/testsuite/tests/stranal/should_compile/T18982.stderr @@ -216,7 +216,7 @@ T18982.$wi = \ (@a) (@e) (ww :: a GHC.Prim.~# Int) (ww1 :: e) (ww2 :: GHC.Prim.I -- RHS size: {terms: 15, types: 22, coercions: 1, joins: 0/0} i :: forall a. ExGADT a -> Int -i = \ (@a) (w :: ExGADT a) -> case w of { ExGADT @e ww ww1 ww2 ww3 -> case ww3 of { GHC.Types.I# ww4 -> case T18982.$wi @a @e @~(ww :: a GHC.Prim.~# Int) ww2 ww4 of ww5 { __DEFAULT -> GHC.Types.I# ww5 } } } +i = \ (@a) (ds :: ExGADT a) -> case ds of { ExGADT @e ww ww1 ww2 ww3 -> case ww3 of { GHC.Types.I# ww4 -> case T18982.$wi @a @e @~(ww :: a GHC.Prim.~# Int) ww2 ww4 of ww5 { __DEFAULT -> GHC.Types.I# ww5 } } } -- RHS size: {terms: 6, types: 7, coercions: 0, joins: 0/0} T18982.$wh :: forall {a}. (a GHC.Prim.~# Int) -> GHC.Prim.Int# -> GHC.Prim.Int# @@ -224,7 +224,7 @@ T18982.$wh = \ (@a) (ww :: a GHC.Prim.~# Int) (ww1 :: GHC.Prim.Int#) -> GHC.Prim -- RHS size: {terms: 14, types: 15, coercions: 1, joins: 0/0} h :: forall a. GADT a -> Int -h = \ (@a) (w :: GADT a) -> case w of { GADT ww ww1 -> case ww1 of { GHC.Types.I# ww2 -> case T18982.$wh @a @~(ww :: a GHC.Prim.~# Int) ww2 of ww3 { __DEFAULT -> GHC.Types.I# ww3 } } } +h = \ (@a) (ds :: GADT a) -> case ds of { GADT ww ww1 -> case ww1 of { GHC.Types.I# ww2 -> case T18982.$wh @a @~(ww :: a GHC.Prim.~# Int) ww2 of ww3 { __DEFAULT -> GHC.Types.I# ww3 } } } -- RHS size: {terms: 9, types: 4, coercions: 0, joins: 0/0} T18982.$wg :: forall {e}. e -> GHC.Prim.Int# -> GHC.Prim.Int# @@ -232,7 +232,7 @@ T18982.$wg = \ (@e) (ww :: e) (ww1 :: GHC.Prim.Int#) -> case ww of { __DEFAULT - -- RHS size: {terms: 14, types: 11, coercions: 0, joins: 0/0} g :: Ex Int -> Int -g = \ (w :: Ex Int) -> case w of { Ex @e ww ww1 -> case ww1 of { GHC.Types.I# ww2 -> case T18982.$wg @e ww ww2 of ww3 { __DEFAULT -> GHC.Types.I# ww3 } } } +g = \ (ds :: Ex Int) -> case ds of { Ex @e ww ww1 -> case ww1 of { GHC.Types.I# ww2 -> case T18982.$wg @e ww ww2 of ww3 { __DEFAULT -> GHC.Types.I# ww3 } } } -- RHS size: {terms: 4, types: 1, coercions: 0, joins: 0/0} T18982.$wf :: GHC.Prim.Int# -> GHC.Prim.Int# @@ -240,7 +240,7 @@ T18982.$wf = \ (ww :: GHC.Prim.Int#) -> GHC.Prim.+# ww 1# -- RHS size: {terms: 13, types: 8, coercions: 0, joins: 0/0} f :: Box Int -> Int -f = \ (w :: Box Int) -> case w of { Box ww -> case ww of { GHC.Types.I# ww1 -> case T18982.$wf ww1 of ww2 { __DEFAULT -> GHC.Types.I# ww2 } } } +f = \ (ds :: Box Int) -> case ds of { Box ww -> case ww of { GHC.Types.I# ww1 -> case T18982.$wf ww1 of ww2 { __DEFAULT -> GHC.Types.I# ww2 } } } |