Add a field in SimplMode to turn off built-in rules
<!--
READ THIS FIRST: If the feature you are proposing changes the language that GHC accepts
or adds any warnings to `-Wall`, it should be written as a [GHC Proposal](https://github.com/ghc-proposals/ghc-proposals/).
Other features, appropriate for a GitLab feature request, include GHC API/plugin
innovations, new low-impact compiler flags, or other similar additions to GHC.
-->
## Motivation
Currently, built-in rules simply cannot be turned off during simplification:
```haskell
-- GHC.Core.Rules
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
```
This poses a problem for what we are trying to do: we are developing a Core plugin that converts certain `CoreExpr`s of type `a -> b` into `CoreExprs` of type `M a -> M b` for some `M`. Our plugin needs to call `simplExpr` on various parts of the expression, for purposes like inlining, case-of-case transformation, beta reduction etc. The one thing we do _not_ want `simplExpr` to do is specialization - it is much easier and more efficient to directly convert `== $fEqFoo ...` than `$fEqFoo5 ...`. The latter (1) has a strange name (2) has a different name for each `Foo` (3) may contain primops which are difficult to deal with.
I don't think our use case is the only one that would benefit from a `simplExpr` that allows turning off built-in rules. This would allow one to precisely control its behavior, e.g., only performing case-of-case and inlining, but nothing else, which seems useful in general.
## Proposal
I think this can be easily achieved by adding a new field to `SimplMode`, say `sm_builtin_rules`, and then modifying the above code snippet to check this field. Its value would normally be `True`, but can be set to `False` if one knows what they are doing.
issue