Skip to content

matchRule function doesn't respect `-fno-enable-rewrite-rules`

{-# OPTIONS_GHC -ddump-rule-firings -fno-enable-rewrite-rules #-}
module T20021 where

foo :: Int -> Int
foo n = length ([0..(10^n)] :: [Int])

BUILTIN rules still fire, despite passing -fno-enable-rewrite-rules.

[nix-shell:~/ghc-lazyget/r-test]$ ghc T20021.hs -O -fforce-recomp 
[1 of 1] Compiling T20021           ( T20021.hs, T20021.o )
Rule fired: Class op length (BUILTIN)
Rule fired: Class op enumFromTo (BUILTIN)

Is this expected behaviour? There is a comment on matchRule which also asks this question:

matchRule opts rule_env _is_active fn args _rough_args
          (BuiltinRule { ru_try = match_fn })
-- Built-in rules can't be switched off, it seems
  = case match_fn opts rule_env fn args of
        Nothing   -> Nothing
        Just expr -> Just expr

matchRule _ in_scope is_active _ args rough_args
          (Rule { ru_name = rule_name, ru_act = act, ru_rough = tpl_tops
                , ru_bndrs = tpl_vars, ru_args = tpl_args, ru_rhs = rhs })
  | not (is_active act)               = Nothing
  | ruleCantMatch tpl_tops rough_args = Nothing
  | otherwise = matchN in_scope rule_name tpl_vars tpl_args args rhs

cc @simonpj @RolandSenn

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information