Skip to content
Snippets Groups Projects
Commit 37472a10 authored by Sebastian Graf's avatar Sebastian Graf Committed by Marge Bot
Browse files

WorkWrap: Make mkWWstr and mkWWcpr generate fewer let bindings

In ghc/ghc!5814 (comment 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.
parent eee498bf
No related branches found
No related tags found
No related merge requests found
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment