[Haskell-cafe] Imported rewrite rules are ignored

Alexander Vieth aovieth at gmail.com
Mon Dec 21 16:23:51 UTC 2015


Hi café,

I observe that rewrite rules from imported modules are ignored by GHC.
Given these two files, one module and one executable, the problem can be
demonstrated by switching between `rewrite_me` and `rewrite_me_local`. If
the rule fires, the program should run cleanly, as the `error` term should
be rewritten to `()`. The imported function rewrite_me is not rewritten;
but the same thing, rewrite_me_local, defined in the same program, will be
rewritten.

File RuleModule.hs

    module RuleModule where

    {-# NOINLINE rewrite_me #-}
    rewrite_me :: () -> ()
    rewrite_me = error "Should rewrite"

    {-# RULES
    "rewrite_me" forall input .
             rewrite_me input = ()
     #-}

File Rule.hs

    import RuleModule

    {-# NOINLINE rewrite_me_local #-}
    rewrite_me_local :: () -> ()
    rewrite_me_local = error "Should rewrite"

    {-# RULES
    "rewrite_local" forall input .
                    rewrite_me_local input = ()
     #-}

    -- Replace with rewrite_me_local and it's all good.
    main = case rewrite_me () of
        () -> return ()

This is GHC 7.10.2. I compile using -O -fenable-rewrite-rules.

Using -dverbose-core2core, the "Desugar (after optimization)" section shows
no rules when using rewrite_me, but shows the rule rewrite_local when using
the local variant. Maybe this is expected, but I thought it important to
mention.

Thanks for any advice,

Alex
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20151221/158f78ea/attachment.html>


More information about the Haskell-Cafe mailing list