<div dir="ltr"><div><div>Hi café,<br><br>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.<br><br>File RuleModule.hs<br><br>    module RuleModule where<br><br>    {-# NOINLINE rewrite_me #-}<br>    rewrite_me :: () -> ()<br>    rewrite_me = error "Should rewrite"<br><br>    {-# RULES<br>    "rewrite_me" forall input .<br>             rewrite_me input = ()<br>     #-}<br><br>File Rule.hs<br><br>    import RuleModule<br><br>    {-# NOINLINE rewrite_me_local #-}<br>    rewrite_me_local :: () -> ()<br>    rewrite_me_local = error "Should rewrite"<br><br>    {-# RULES<br>    "rewrite_local" forall input .<br>                    rewrite_me_local input = ()<br>     #-}<br><br>    -- Replace with rewrite_me_local and it's all good.<br>    main = case rewrite_me () of<br>        () -> return ()<br><br>This is GHC 7.10.2. I compile using -O -fenable-rewrite-rules.<br><br></div><div>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.<br></div><div><br></div>Thanks for any advice,<br><br></div>Alex<br></div>