When matching functions in rewrite rules: ignore multiplicity
When matching a template variable to an expression, we check that it
has the same type as the matched expression. But if the variable f
has
type A -> B
while the expression e
has type A %1 -> B
, the match was
previously rejected.
A principled solution would have f
substituted by \(%Many x) -> e x
or some other appropriate coercion. But since linearity is not
properly checked in Core, we can be cheeky and simply ignore
multiplicity while matching. Much easier.
Fixes #24725.
Left to do
-
Add a test in the testsuite. I'm not quite sure what the right way to add a test on rewrite rules is. Failure to apply a rewrite rule. My best idea so far is to make a(n incorrect) rewrite rule that renders unequal things equal, and asserting the equality.
MR Checklist
-
if your MR may break existing programs (e.g. touches base
or causes the compiler to reject programs), please describe the expected breakage and add the user-facing label. This will run ghc/head.hackage> to characterise the effect of your change on Hackage. -
ensure that your commits are either individually buildable or squashed -
ensure that your commit messages describe what they do (referring to tickets using #NNNN
syntax when appropriate) -
have added source comments describing your change. For larger changes you likely should add a Note and cross-reference it from the relevant places. -
add a testcase to the testsuite. -
updates the users guide if applicable -
mentions new features in the release notes for the next release