Opened 3 years ago

Closed 3 years ago

#13040 closed feature request (fixed)

realToFrac into Complex Double has no specialization

Reported by: akio Owned by: akio
Priority: normal Milestone: 8.2.1
Component: libraries/base Version: 8.0.1
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Runtime performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s): Phab:D2901
Wiki Page:

Description

Example:

module Foo where
import Data.Complex

f :: Double -> Complex Double
f x = realToFrac x

ghc -O -ddump-simpl gives:

f =
  \ (w_s17v :: Double) ->
    case w_s17v of _ [Occ=Dead] { GHC.Types.D# ww1_s17y ->
    case GHC.Float.$w$ctoRational ww1_s17y
    of _ [Occ=Dead] { (# ww3_a152, ww4_a153 #) ->
    case GHC.Float.rationalToDouble ww3_a152 ww4_a153
    of dt_a15c { GHC.Types.D# ipv_a15g ->
    Data.Complex.:+ @ Double dt_a15c Data.Complex.$fFloatingComplex1
    }
    }
    }

This means the conversion goes through Rational. However, in this case, the conversion could be done much more efficiently with (:+0). It would be nice if this happened automatically.

Change History (3)

comment:1 Changed 3 years ago by akio

Differential Rev(s): Phab:D2901
Owner: set to akio

comment:2 Changed 3 years ago by Ben Gamari <ben@…>

In 5800b02a/ghc:

Add specialization rules for realToFrac on Complex

This patch implements RULES that specialize realToFrac at these 2 types:

`(Real a) => a -> Complex Double`
`(Real a) => a -> Complex Float`

Test Plan: ./validate

Reviewers: austin, hvr, bgamari

Reviewed By: bgamari

Subscribers: thomie

Differential Revision: https://phabricator.haskell.org/D2901

GHC Trac Issues: #13040

comment:3 Changed 3 years ago by bgamari

Milestone: 8.2.1
Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.