Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix lookup Div and Mod GHC >= 9.2 #52

Merged
merged 2 commits into from
Apr 16, 2024
Merged

Fix lookup Div and Mod GHC >= 9.2 #52

merged 2 commits into from
Apr 16, 2024

Conversation

rowanG077
Copy link
Member

@rowanG077 rowanG077 commented Apr 12, 2024

While implementing reduction Mod n p <= q -> p <= q + 1 I noticed that the lookups for Div and Mod were wrong post GHC 9.2.

I have fixed that and also added the reduction. If you want I can split this up into two PRs. One for the lookup fix and one for the reduction. But since the each change is so small I didn't feel like the overhead is worth it.

@rowanG077 rowanG077 force-pushed the modreduce branch 6 times, most recently from cc41b6e to beb409c Compare April 14, 2024 00:36
src-ghc-9.4/GHC/TypeLits/Extra/Solver.hs Outdated Show resolved Hide resolved
src-pre-ghc-9.4/GHC/TypeLits/Extra/Solver.hs Outdated Show resolved Hide resolved
@rowanG077 rowanG077 requested a review from christiaanb April 16, 2024 14:47
@rowanG077 rowanG077 force-pushed the modreduce branch 4 times, most recently from 5c74672 to 6bfd0ea Compare April 16, 2024 15:00
@leonschoorl
Copy link
Member

leonschoorl commented Apr 16, 2024

This maybe unavoidable with the way type checker plugins work, but I don't think this reduction is always a good thing to do.

While p <= q + 1 implies Mod n p <= q.
The opposite isn't necessarily true.

For example Mod 1 (a+3) <= 1 holds, but this now gets reduced to (a+3) <= 2, which does not hold.
If there happens to be some other (hypothetical) plugin that could have solved the original Mod 1 (a+2) <= 2, and this plugin happens gets called first by GHC then type checking will fail because we now reduced it to an unsolvable form.

error: [GHC-83865]
    • Couldn't match type ‘Data.Type.Ord.OrdCond
                             (CmpNat (a + 3) 2) True True False’
                     with ‘True’
      Expected: Proxy True
        Actual: Proxy (Mod 1 (a + 3) <=? 1)

@rowanG077
Copy link
Member Author

rowanG077 commented Apr 16, 2024

Yes. You ideally want to reduce Mod n p <= q to 1 <= p && (n <= q || p <= q + 1) but I don't think type level disjunction exists? Or could you simply write a || type family?

@rowanG077
Copy link
Member Author

Since it's more controversial then expected I have removed the reduction from this PR. If you are oke with doing the reduction I will open a seperate PR.

@christiaanb christiaanb merged commit 473f7d2 into master Apr 16, 2024
22 checks passed
@christiaanb christiaanb deleted the modreduce branch April 16, 2024 20:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants