Skip to content

Conversation

@bezirg
Copy link
Contributor

@bezirg bezirg commented Dec 9, 2025

Pre-submit checklist:

  • Branch
    • Tests are provided (if possible)
    • Commit sequence broadly makes sense
    • Key commits have useful messages
    • Changelog fragments have been written (if appropriate)
    • Relevant tickets are mentioned in commit messages
    • Formatting, PNG optimization, etc. are updated
  • PR
    • (For external contributions) Corresponding issue exists and is linked in the description
    • Targeting master unless this is a cherry-pick backport
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested

@bezirg bezirg self-assigned this Dec 9, 2025
@bezirg bezirg marked this pull request as draft December 9, 2025 13:40
@bezirg bezirg force-pushed the bezirg/derive-bounded branch from 0b3bd07 to 2129536 Compare December 9, 2025 13:42
@bezirg bezirg marked this pull request as ready for review December 9, 2025 13:51
@bezirg bezirg requested a review from zliu41 December 9, 2025 13:52
@bezirg bezirg force-pushed the bezirg/derive-bounded branch 2 times, most recently from 77d2cc9 to d838673 Compare December 15, 2025 14:11
@zliu41 zliu41 requested a review from a team December 15, 2025 18:11
Copy link
Member

@zliu41 zliu41 left a 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?

@bezirg
Copy link
Contributor Author

bezirg commented Dec 15, 2025

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

@zliu41
Copy link
Member

zliu41 commented Dec 15, 2025

There should be some plugin tests to verify that the plugin can compile the new Bounded.

@bezirg bezirg force-pushed the bezirg/derive-bounded branch from d838673 to 14042f1 Compare December 19, 2025 10:02
@bezirg
Copy link
Contributor Author

bezirg commented Dec 19, 2025

There should be some plugin tests to verify that the plugin can compile the new Bounded.

I have added some

@bezirg bezirg force-pushed the bezirg/derive-bounded branch from 14042f1 to 5ed0817 Compare December 19, 2025 16:44
@bezirg bezirg force-pushed the bezirg/derive-bounded branch from 5ed0817 to 231b376 Compare December 19, 2025 16:48
deriving stock (HS.Eq, HS.Enum, HS.Bounded, HS.Show)
deriveEnum ''SomeVeryLargeEnum

-- we lack Tx.Bounded so we use Haskell's for the tests
Copy link
Contributor

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"
Copy link
Collaborator

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
Copy link
Collaborator

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
Copy link
Collaborator

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.

Copy link
Member

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.

Copy link
Contributor Author

@bezirg bezirg Dec 24, 2025

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.

Copy link
Member

@zliu41 zliu41 left a 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
Copy link
Member

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.

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.

5 participants