Skip to content

Fragile rewrite rules #3

@thomie

Description

@thomie

GHC panics on the following program:

module Test where

import Numeric.FastMath
import GHC.Exts

times4 :: Double -> Double
times4 (D# x) = D# ((x *## x) *## (x *## x))
ghc-7.10.1 Test.hs -cpp -XMagicHash -O -fforce-recomp
...
[5 of 5] Compiling Test             ( Test.hs, Test.o )
ghc: panic! (the 'impossible' happened)
  (GHC version 7.10.1 for x86_64-unknown-linux):
    Simplifier ticks exhausted
  When trying RuleFired double commute left *
  To increase the limit, use -fsimpl-tick-factor=N (default 100)
  If you need to do this, let GHC HQ know, and what factor you needed
  To see detailed counts use -ddump-simpl-stats
  Total ticks: 4564
Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

It is not a bug in GHC though. It happens because of the following rewrite rule in Numeric.FastMath.Approximation

"double commute left *"   [~2] forall x1 x2 x3. (*##) x1 ((*##) x2 x3)
    = (*##) ((*##) x2 x3) x1

This rewrites (x *## x) *## (x *## x) to (x *## x) *## (x *## x).

From the GHC user's guide [1]:

 GHC makes no attempt to make sure that the rules are confluent or terminating. For example:

 "loop"        forall x y.  f x y = f y x

This rule will cause the compiler to go into an infinite loop. 

The are similar fragile rewrite rules in this package. I don't know what to about this, other than to remove those rules. Or at least put a big warning in the README.

[1] https://downloads.haskell.org/~ghc/7.10.1/docs/html/users_guide/rewrite-rules.html#rule-semantics

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions