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

Improve output of generrors #551

Merged
merged 8 commits into from
Aug 26, 2024
Merged

Conversation

williamdemeo
Copy link
Contributor

@williamdemeo williamdemeo commented Aug 21, 2024

Description

This will address issue #546.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • Code is formatted according to CONTRIBUTING.md
  • Self-reviewed the diff

@williamdemeo williamdemeo linked an issue Aug 21, 2024 that may be closed by this pull request
3 tasks
@williamdemeo williamdemeo force-pushed the 546-improve-output-of-generrors branch from 99e712a to aa785eb Compare August 22, 2024 12:45
@williamdemeo
Copy link
Contributor Author

williamdemeo commented Aug 23, 2024

Commit 4659a61 fails with the following type-check error:

HSTransactionStructure != ⊤ of type Type
when checking that the pattern KeyHashObj x has type
Ledger.Address.Credential
(Ledger.Types.Epoch.GlobalConstants.Network
 (TransactionStructure.globalConstants HSTransactionStructure))
(Ledger.Crypto.isHashableSet.THash
 (Ledger.Crypto.Crypto.khs
  (TransactionStructure.crypto HSTransactionStructure)))
(Ledger.Crypto.Crypto.ScriptHash
 (TransactionStructure.crypto HSTransactionStructure))

at the fourth line of the following code block from Ledger.Foreign.HSLedger.BaseTypes.agda:

  -- Since the foreign address is just a number, we do bad stuff here
  Convertible-Addr : Convertible Addr F.Addr
  Convertible-Addr = λ where
    .to  λ where (inj₁ record { pay = KeyHashObj x })  x
                  (inj₁ record { pay = ScriptObj  x })  x
                  (inj₂ record { pay = KeyHashObj x })  x
                  (inj₂ record { pay = ScriptObj  x })  x
    .from n  inj₁ record { net = _ ; pay = KeyHashObj n ; stake = KeyHashObj 0 }

Comment on lines 135 to 139
(inj₁ a) → sep + " ¬ ( filterˢ isKeyHash (mapˢ RwdAddr.stake (dom wdrls)) ⊆ dom voteDelegs ) "
+ sep + " filterˢ isKeyHash (mapˢ RwdAddr.stake (dom wdrls)): "
-- + show (filterˢ isKeyHash (mapˢ RwdAddr.stake (dom wdrls)))
+ show (dom wdrls)
(inj₂ b) → "¬ ( mapˢ (Bifunctor.map₁ Bifunctor-× (RwdAddr.stake)) (wdrls ˢ) ⊆ proj₁ rewards )"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This approach can go out of sync when somebody changes the order of predicates. I think it's fine to use genErrors and then just append all of the debug information regardless of which rule fails.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the error messages don't have to be all that readable, they're just for us. And not having to maintain them is a big plus. Just doing some super basic postprocessing of the generated strings to get rid of the fully qualified names also goes a long way in improving readability.

@Soupstraw
Copy link
Contributor

Commit 4659a61 fails with the following type-check error:

HSTransactionStructure != ⊤ of type Type
when checking that the pattern KeyHashObj x has type
Ledger.Address.Credential
(Ledger.Types.Epoch.GlobalConstants.Network
 (TransactionStructure.globalConstants HSTransactionStructure))
(Ledger.Crypto.isHashableSet.THash
 (Ledger.Crypto.Crypto.khs
  (TransactionStructure.crypto HSTransactionStructure)))
(Ledger.Crypto.Crypto.ScriptHash
 (TransactionStructure.crypto HSTransactionStructure))

at the fourth line of the following code block from Ledger.Foreign.HSLedger.BaseTypes.agda:

  -- Since the foreign address is just a number, we do bad stuff here
  Convertible-Addr : Convertible Addr F.Addr
  Convertible-Addr = λ where
    .to  λ where (inj₁ record { pay = KeyHashObj x })  x
                  (inj₁ record { pay = ScriptObj  x })  x
                  (inj₂ record { pay = KeyHashObj x })  x
                  (inj₂ record { pay = ScriptObj  x })  x
    .from n  inj₁ record { net = _ ; pay = KeyHashObj n ; stake = KeyHashObj 0 }

I think that when you try to use the KeyHashObj and ScriptObj constructors then Agda tries to resolve the instance parameters for Ledger.Address and then fails to find them. I think you're just missing some Show instances.

@@ -22,7 +23,8 @@ credential contains a hash, either of a verifying (public) key
ScriptHash
\end{code}
\begin{code}[hide]
: Type) ⦃ _ : DecEq Network ⦄ ⦃ _ : DecEq KeyHash ⦄ ⦃ _ : DecEq ScriptHash ⦄ where
: Type) ⦃ _ : DecEq Network ⦄ ⦃ _ : DecEq KeyHash ⦄ ⦃ _ : DecEq ScriptHash ⦄
⦃ _ : Show Network ⦄ ⦃ _ : Show KeyHash ⦄ ⦃ _ : Show ScriptHash ⦄ where
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't add the Show instances as module parameters since they're only needed for defining other Show instances. It'd be better to move these parameters to the Show instance definitions that are actually using them.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. Might be worth considering doing the same for DecEq, but there might be some stuff that requires it that isn't some other DecEq instance in which case I think this might be cleaner.

@WhatisRT
Copy link
Collaborator

I think that when you try to use the KeyHashObj and ScriptObj constructors then Agda tries to resolve the instance parameters for Ledger.Address and then fails to find them. I think you're just missing some Show instances.

No, it's something much weirder. This error message is in the pattern and the instances actually get fully resolved somewhere earlier, so KeyHashObj doesn't have instance arguments anymore.

Looks like it could be an Agda bug to me, especially because the first thing I tried when playing around with this triggered an IMPOSSIBLE error. I guess I'll go on the third code bisection this week...

@WhatisRT
Copy link
Collaborator

Oh, no, it's actually what you said. If you add ⦃ it ⦄ ⦃ it ⦄ ⦃ it ⦄ at the end of open Ledger.Address Network KeyHash ScriptHash ⦃ it ⦄ ⦃ it ⦄ ⦃ it ⦄ public in Ledger.Transaction it works just fine.

I still don't understand why this happens though. KeyHashObj has the instances fully applied, but maybe this breaks when used in a pattern?

@williamdemeo williamdemeo marked this pull request as ready for review August 23, 2024 21:24
Copy link

@TimSheard TimSheard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So there is a lot of work involved in making Show instances in Agda.
These will probably come in handy in the future as well.

Comment on lines +134 to +141
= KeyHashObj Integer
| ScriptObj Integer
deriving (Show, Eq, Generic)
#-}
data Credential : Type where
ScriptObj : Hash → Credential
KeyHashObj : Hash → Credential
{-# COMPILE GHC Credential = data Credential (ScriptObj | KeyHashObj) #-}
ScriptObj : Hash → Credential
{-# COMPILE GHC Credential = data Credential (KeyHashObj | ScriptObj) #-}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ... The culprit has been found!

@williamdemeo williamdemeo merged commit 1e297c4 into master Aug 26, 2024
3 checks passed
@williamdemeo williamdemeo deleted the 546-improve-output-of-generrors branch August 26, 2024 17:19
github-actions bot added a commit that referenced this pull request Aug 26, 2024
williamdemeo added a commit that referenced this pull request Aug 27, 2024
* experiment with manipulating a specific error string

* fix string add

* add Show instances for Credential and Set and ℙ

* add Show instances for more Ledger types

* fixed broken type class application

* incorporate suggestions from PR review and improve fail messages

* Fix order `KeyHashObj` and `ScriptHashObj` constructors in the FFI

---------

Co-authored-by: whatisRT <[email protected]>
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.

Improve output of genErrors
4 participants