-
Notifications
You must be signed in to change notification settings - Fork 37
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 for issue #305 + some related problems #307
Conversation
I ran into this while debugging agda#305, though I cannot reproduce a test case now. It seems like it's the right thing to do regardless.
c.f. the changes of 416234a, where I moved the cubical tests under |
I get that you changed it, but I don't understand why Also there apparently are internal errors here in CI that do not show up when I run the tests locally. Mysterious... Perhaps it's picking up the wrong version of |
This was a regression introduced by agda#304 that went unnoticed due to a lack of a (failing) test case
I think that was it: after manually deleting |
The old implementation using chaseDef was quite brittle and was causing problems with the fix of agda#305, so rather than fixing it I replaced it with a more direct (and hopefully more robust) implementation that inlines instances that are defined elsewhere
After exorcising the ghosts from my repository I managed to fix the remaining internal errors over the weekend. However, the issue still remains when a class function is used inside a pattern-matching lambda: module _ (@0 X : Set) where
record Class (a : Set) : Set where
field
foo : a → a
open Class {{...}} public
{-# COMPILE AGDA2HS Class class #-}
instance
ClassInt : Class Int
ClassInt .foo = _+ 1
{-# COMPILE AGDA2HS ClassInt #-}
yetAnotherTest : Int
yetAnotherTest = case Just True of λ where
Nothing → error "unreachable"
(Just y) → foo 5
{-# COMPILE AGDA2HS yetAnotherTest #-} still gives the error:
|
…r than the clause
I got one step further again: the checkpoint is now being set in the context of the module rather than the context of an individual clause, which means the example above now works. However, the problems are still not over as the check still fails when the instance is defined in a different module that is applied and opened in the current module: record Class (a : Set) : Set where
field
foo : a → a
open Class {{...}} public
{-# COMPILE AGDA2HS Class class #-}
module M1 (@0 X : Set) where
instance
ClassInt : Class Int
ClassInt .foo = _+ 1
{-# COMPILE AGDA2HS ClassInt #-}
module M2 (@0 X : Set) where
open M1 X
tester : Int
tester = foo 41
{-# COMPILE AGDA2HS tester #-} Error is the same as before:
I guess the problem is that we are using the instance table of the top-level module rather than the one that was used inside the module |
Let's see if we can use |
Here is a real-world example that triggered this error: https://github.com/jespercockx/agda-core/blob/20a4eac77466560730b5243faeed306a5aa98cf8/src/Agda/Core/Typechecker.agda#L41-L42 Here the call to |
Unfortunately this does not work: in Agda's internal syntax, calls to type class functions are represented as a (As an aside: Agda's pretty-printer seems to struggle with a similar problem, as it prints |
Since this PR constitutes a clear improvement to the status quo and I don't have a solution for the remaining problem, I believe it's best to merge this now and leave adding support for using instances coming from module applications as a separate issue. |
This fixes #305 by setting the right checkpoint for Agda so that when we call instance search for checking canonicity, the instances are correctly applied to the module parameters.
I also found and fixed a related regression introduced in my PR #304 that caused us to no longer check the canonicity of superclass instances when defining a subclass instance.
When I run the test suite locally on this branch, there is something weird that happens with the golden files for two modules:
NonCanonicalSuperclass.agda
produces an unexpected success despite producing the correct error when runningagda2hs
on it directlyStreamFusion.agda
I did not touch in any way, but suddenly appears in a different locationI feel like our test suite is getting increasingly flaky and hard to manage, so perhaps we should look into improving it soon (#153)