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

Interaction between opaque and instance arguments #6941

Closed
jespercockx opened this issue Oct 25, 2023 · 4 comments · Fixed by #6942
Closed

Interaction between opaque and instance arguments #6941

jespercockx opened this issue Oct 25, 2023 · 4 comments · Fixed by #6942
Assignees
Labels
instance Instance resolution opaque Issues about `opaque` definitions type: bug Issues and pull requests about actual bugs
Milestone

Comments

@jespercockx
Copy link
Member

jespercockx commented Oct 25, 2023

I noticed a rather unfortunate interaction between opaque declarations and instance arguments. Consider the following example:

it : {X : Set}  {{X}}  X
it {{x}} = x

postulate
  A : Set
  a : A

opaque
  B : Set
  B = A

  instance
    b : B
    b = a

works : B
works = it

opaque
  unfolding B

  fails : B
  fails = it

works works, but fails fails:

No instance of type B was found in scope.
when checking that the expression it has type B

This is not really surprising given the current implementation of instance search: in this case the instance is attached to the opaque type B, but inside the body of fails the type reduces to A and there are no instances for type A in the instance table.

I'm not sure what's the best way to solve it, but it feels like we need some kind of unfolding-aware instance table. @plt-amy do you have an idea?

@jespercockx jespercockx added type: bug Issues and pull requests about actual bugs instance Instance resolution opaque Issues about `opaque` definitions labels Oct 25, 2023
@jespercockx jespercockx added this to the 2.6.5 milestone Oct 25, 2023
@plt-amy
Copy link
Member

plt-amy commented Oct 25, 2023

I think I ran into this same on Sunday, but I wrote it off since I was trying to do something stupid anyway.

The immediate solution that pops into my head is to fix up the instance canditates according to the following rule: if we have i : {∆} → f xs and f is an opaque symbol that's unfolded in the current block, then it's replaced with i : {∆} → reduce (f xs). But it's possible that this might reduce the instance head too far, and so it would be necessary to consider an exponential number of i' : {∆} → reduce (f xs) in which different subsets of the unfolding set are allowed to reduce, which wouldn't be viable.

@nad
Copy link
Contributor

nad commented Oct 25, 2023

Could one instead change instance search so that it never succeeds for opaque symbols?

@jespercockx
Copy link
Member Author

Well one could but that solves the problem by denying it exists. A better way might be to ignore all opaque flags in the construction of the instance table, and then filter our the instances that are not legal because of opaque statements as part of the regular instance filtering.

@jespercockx
Copy link
Member Author

The same bug also happens for abstract:

it : {X : Set}  {{X}}  X
it {{x}} = x

postulate
  A : Set
  a : A

abstract
  B : Set
  B = A

  instance
    b : B
    b = a

works : B
works = it

abstract
  fails : B
  fails = it

jespercockx added a commit to jespercockx/agda that referenced this issue Oct 25, 2023
@jespercockx jespercockx linked a pull request Oct 25, 2023 that will close this issue
@jespercockx jespercockx self-assigned this Oct 25, 2023
@jespercockx jespercockx modified the milestones: 2.6.5, 2.6.4.1 Oct 25, 2023
jespercockx added a commit to jespercockx/agda that referenced this issue Oct 26, 2023
jespercockx added a commit that referenced this issue Oct 26, 2023
* [ fix #6941 ] Ignore abstract mode in `getOutputTypeName`

* [ re #6941 ] Address comments by Andreas
JobPetrovcic pushed a commit to JobPetrovcic/agda that referenced this issue Apr 12, 2024
)

* [ fix agda#6941 ] Ignore abstract mode in `getOutputTypeName`

* [ re agda#6941 ] Address comments by Andreas
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
instance Instance resolution opaque Issues about `opaque` definitions type: bug Issues and pull requests about actual bugs
Projects
None yet
3 participants