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
Crazy bug when defining Ord instances for Int #4967
Comments
My guess, based on looking at the generated Haskell code, is that Agda does some partial evaluation, and that there is a bug in the code that does this. |
If I eta-contract check : Int -> Bool
check = _<_ (pos 0) Using -- converted
Issue4967.check =
λ a →
(λ b c →
case b of
_ | b >= 0 →
case c of
_ | c >= 0 → b < c
_ → Agda.Builtin.Bool.Bool.false
_ → let d = -1 - b in
case c of
_ | c >= 0 → Agda.Builtin.Bool.Bool.true
_ → let e = -1 - c in e < d)
(Agda.Builtin.Int.Int.pos 0) a
-- simplification
Issue4967.check =
λ a →
let b = Agda.Builtin.Int.Int.pos 0
c = -1 - b in
case a of
_ | a >= 0 → Agda.Builtin.Bool.Bool.true
_ → let d = -1 - a in d < c The wrong branch is taken. |
Haha, what a fool I have been, to think I could fix this issue. agda/src/full/Agda/Compiler/Treeless/Simplify.hs Lines 73 to 449 in 08191e6
@UlfNorell : If you want someone to help you with maintenance, you need to apply at least the most basic technique of software engineering: documentation. Not speaking of assertions or unit tests... |
The problem was that the instance gets inlined and the simplifier can't handle partially builtin-translated code. In this case the pattern matching in the instance implementation had been translated to Haskell integers instead of |
In the program below, I define an Ord class and create an instance for Int. The check n function basically does 0 < n. When I call check 0 and print it out, I erroneously get True. If I change the Ord instance to the commented out one, the program prints out False (which is correct). The code for both instances is exactly the same though!
I am using Agda 2.6.1 on macOS Mojave.
The text was updated successfully, but these errors were encountered: