-
Notifications
You must be signed in to change notification settings - Fork 502
Plinth: Add Bounded typeclass and deriveBounded #7482
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
base: master
Are you sure you want to change the base?
Conversation
0b3bd07 to
2129536
Compare
77d2cc9 to
d838673
Compare
zliu41
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what this buys us. It seems using Haskell's Bounded is sufficient?
I tried to use the Haskell one and I get the classic error of no available unfoldings |
|
There should be some plugin tests to verify that the plugin can compile the new |
d838673 to
14042f1
Compare
I have added some |
14042f1 to
5ed0817
Compare
5ed0817 to
231b376
Compare
| deriving stock (HS.Eq, HS.Enum, HS.Bounded, HS.Show) | ||
| deriveEnum ''SomeVeryLargeEnum | ||
|
|
||
| -- we lack Tx.Bounded so we use Haskell's for the tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
now as we have it, is it a good time to use Plinth's Bounded then?
| boundedTests = | ||
| let | ||
| in testGroup | ||
| "PlutusTx.Enum tests" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be "PlutusTx.Bounded tests"?
| deriving stock (HS.Eq, HS.Enum, HS.Bounded, HS.Show) | ||
| deriveEnum ''SomeVeryLargeEnum | ||
|
|
||
| -- we lack Tx.Bounded so we use Haskell's for the tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it make sense to use PlutusTx.Bounded in these tests now?
| {-# LANGUAGE TemplateHaskell #-} | ||
| {-# LANGUAGE TypeApplications #-} | ||
|
|
||
| module Bounded.Spec (boundedTests) where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried this one too:
data Stream = S Stream
deriveBounded ''Stream
Which results in
<no location info>: error:
GHC Core to PLC plugin: Error: Reference to a name which is not a local, a builtin, or an external INLINABLE function: Variable $cminBound
No unfolding
Context: Compiling expr: $cminBound
Context: Compiling expr: PlutusTx.Bounded.Class.C:Bounded
@Bounded.Spec.Stream $cminBound
Context: Compiling expr: PlutusTx.Bounded.Class.C:Bounded
@Bounded.Spec.Stream $cminBound $cmaxBound
Context: Compiling definition of: Bounded.Spec.$fBoundedStream, located at test/Bounded/Spec.hs:45:1-22
Context: Compiling expr: Bounded.Spec.$fBoundedStream
Context: Compiling expr: Bounded.Spec.minAndMax
@Bounded.Spec.Stream Bounded.Spec.$fBoundedStream
Context: Compiling expr at: test/Bounded/Spec.hs:57:38-46
Context: Compiling expr: src<test/Bounded/Spec.hs:57:38-46>
Bounded.Spec.minAndMax
@Bounded.Spec.Stream Bounded.Spec.$fBoundedStream
Context: Compiling expr at "compiledL"
But GHC's deriving mechanism accepts it. Perhaps this example is a bit silly because such a datatype doesn't make much sense in a strict plutus-tx? At least there is some small mismatch with GHC's deriving which we could document.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's strange. @bezirg please see if you can reproduce.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that is strange because I did test it in the plugin side. I will try to reproduce.
Typeclasses seem to be finicky in compilation.
zliu41
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You didn't include the golden file for the plugin tests.
Could you add another test verifying that the plugin can't compile Haskell's bounded? Use the defer-errors option so that the compilation error appears in the golden file.
| {-# LANGUAGE TemplateHaskell #-} | ||
| {-# LANGUAGE TypeApplications #-} | ||
|
|
||
| module Bounded.Spec (boundedTests) where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's strange. @bezirg please see if you can reproduce.
Pre-submit checklist: