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

Adding fields to a record can cause Agda to reject previous definitions #2500

Closed
identicalsnowflake opened this issue Mar 15, 2017 · 8 comments
Labels
records Record declarations, literals, constructors and updates status: duplicate Duplicate issue (not in changelog) type: bug Issues and pull requests about actual bugs
Milestone

Comments

@identicalsnowflake
Copy link
Contributor

data  : Set where
  tt :flip :  {t₁ t₂ t₃ : Set}  (t₁  t₂  t₃)  t₂  t₁  t₃
flip f x y = f y x

record R : Set₁ where
  field
    f :  {a b c : Set}  {{_ : ⊤}}  (a  b)  (b  c) g :  {a b c : Set}  (b  c)  (a  b)  ⊤
  g = flip (f {{tt}})

  -- field
  --   top :

Agda accepts the above code, but rejects it if you uncomment the final top : ⊤ field. Strangely, changing the definition of g to the following (adding a single {_} pattern) causes it to be accepted again:

  g :  {a b c : Set}  (b  c)  (a  b)  ⊤
  g {_} = flip (f {{tt}})
@identicalsnowflake identicalsnowflake changed the title Adding fields to a record can cause Agda to reject previous fields Adding fields to a record can cause Agda to reject previous definitions Mar 15, 2017
@nad nad added this to the 2.5.3 milestone Mar 16, 2017
@andreasabel
Copy link
Member

CONGRATS, YOU FILED ISSUE 2500! YOU WON 50 HOURS OF FREE AGDA BUG FIXING! START NOW! IT IS COMPLETELY FREE!!

@andreasabel
Copy link
Member

This is just good old #434. I had heroic plans to fix it at the last AIM. For various reasons I lacked the concentration to attack it. But the next AIM is coming up soon.

@andreasabel andreasabel added type: bug Issues and pull requests about actual bugs records Record declarations, literals, constructors and updates labels Mar 17, 2017
@identicalsnowflake
Copy link
Contributor Author

Did you ever hear the tragedy of Darth Abel the Wise? I thought not. It’s not a story the Haskellers would tell you. It’s an Agda legend. Darth Abel was a Dark Lord of the Types, so powerful and so wise he could use the Types to influence the terms to create... types. He had such a knowledge of the types that he could even keep the ones he cared about from bugs.

He became so powerful that the only thing he was afraid of was losing his types, which eventually, of course, he did.

Ironic. Agda could save others from bugs, but not itself.

@andreasabel
Copy link
Member

Alas, we are still far from being able to bootstrap Agda in Agda. For one, Agda is not efficient enough for feasible development of a 300 module piece of software. For two, we probably would need 60 very active developers instead of the 6 we have. Even developing a verified kernel would be a heroic effort. While this would prevent bugs like proving false, it would not weed out all the usability bugs (which are the great majority).

@identicalsnowflake
Copy link
Contributor Author

Oh I'm under no delusion that it's going to happen any time soon. But to the latter point, I think there's lots of untapped potential in formalizing (or at least stating basic properties of) "non-mathy" stuff: things like quote compose unquote should form the identity, case splitting should generate only valid syntax, etc..

An example I encountered: I wrote a JSONEncoding typeclass which entails ∀ (x : t) → fromJSON (toJSON x) ≡≡ Ok x. When I first wrote it, I just postulated this property away because it was annoying to have to prove it, but I quickly became overcome with guilt and went back to make the proof for all my types. And guess what? It turns out I'm much less skilled at writing JSON instances than I thought! I probably caught at least 3-4 latent bugs in my tiny codebase just from that simple theorem.

So while sure, it's not feasible to write Agda in Agda (for now!), I think you underestimate just how much benefit could be there. Even very simple guarantees can go a long way.

@andreasabel
Copy link
Member

I am totally on your side. Even doing a pen and paper proof for a significant fragment of Agda would be a revolution. Just documenting invariants of the code does make a huge difference. I think in the beginning, @nad put some effort into writing quick-check properties. I try to document invariants where I can. But of course, yes, trying to prove them would bring many issues to light.

I think in an open source project without formal responsibilities it is very difficult to retrofit correctness properties. Say I add some asserts to code I have not written myself and expose sleeping bugs in Agda, then I have to fix them myself, since I cannot force the author to fix them. And I cannot just add these assertions that let Agda crash with an internal error where it did not before.

@UlfNorell
Copy link
Member

Closing this as duplicate of #434.

@UlfNorell UlfNorell added the status: duplicate Duplicate issue (not in changelog) label Aug 9, 2017
andreasabel added a commit that referenced this issue Feb 26, 2018
An overhaul of record declaration checking (#434, #2500) would probably
fix this issue here: the termination checker for the definition inside
the record declaration runs too early, it would need the results of
positivity checking.

For now, just turn off the internal error.
@UlfNorell
Copy link
Member

Actually it's a combo of #434 and #1079. Here's the failing example without the record:

data  : Set where
  tt :flip :  {t₁ t₂ t₃ : Set}  (t₁  t₂  t₃)  t₂  t₁  t₃
flip f x y = f y x

R : Set₁
R = (f :  {a b c : Set}  {{_ : ⊤}}  (a  b)  (b  c)  ⊤)
    (let g :  {a b c : Set}  (b  c)  (a  b)  ⊤
         g = flip (f {{tt}})) 
    Set

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
records Record declarations, literals, constructors and updates status: duplicate Duplicate issue (not in changelog) type: bug Issues and pull requests about actual bugs
Projects
None yet
Development

No branches or pull requests

4 participants