Ticket #5344 (new feature request)

Opened 22 months ago

Last modified 19 months ago

CSE should look through coercions

Reported by: reinerp Owned by: simonpj
Priority: normal Milestone: _|_
Component: Compiler Version: 7.0.3
Keywords: cse Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Difficulty:
Test Case: Blocked By:
Blocking: Related Tickets:

Description

This is probably a known limitation of the CSE pass, but there doesn't appear to be a ticket so I'll make one.

Consider the module:

module M where

newtype Id a = Id a

f (a, b) = (Id a, b)

g (a, b) = (a, b)

Compiling this with ghc -ddump-simpl -dsuppress-all -O2, we get

g = \ (@ t_adf) (@ t1_adg) (ds_ddl :: (t_adf, t1_adg)) -> ds_ddl

f =
  \ (@ t_adi) (@ a_adj) (ds_ddn :: (a_adj, t_adi)) ->
    case ds_ddn of _ { (a_aaW, b_aaX) -> (a_aaW `cast` ..., b_aaX) }

We see that g shares its argument tuple, but f allocates a new copy of it. Ideally f would also share its argument tuple, and would look like this:

f = \ (@ t_adi) (@ a_adj) (ds_ddn :: (a_adj, t_adi)) -> ds_ddn `cast` ...

Change History

Changed 19 months ago by igloo

  • owner set to simonpj
  • milestone set to 7.6.1

Simon, does this seem feasible?

Changed 19 months ago by simonpj

  • milestone changed from 7.6.1 to _|_

You want to answer the question "Are these two expressions e1, e2 equal modulo a coercion, so that e1 = e2 |> co?" I'm sure it's possible to do that, but I don't see how to do it efficiently.

Nice idea, though!

I'll milestone for bottom unless someone comes up with a plausible implementation.

Simon

Note: See TracTickets for help on using tickets.