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

Rename FeatureInEra to Eon #247

Merged
merged 7 commits into from
Sep 20, 2023
Merged

Rename FeatureInEra to Eon #247

merged 7 commits into from
Sep 20, 2023

Conversation

newhoggy
Copy link
Collaborator

@newhoggy newhoggy commented Sep 16, 2023

Changelog

- description: |
    - Rename `FeatureInEra` to `Eon`
    - Rename the following modules:
      - `Cardano.Api.Feature.AlonzoEraOnly -> Cardano.Api.Eon.AlonzoEraOnly`
      - `Cardano.Api.Feature.AlonzoEraOnwards -> Cardano.Api.Eon.AlonzoEraOnwards`
      - `Cardano.Api.Feature.BabbageEraOnwards -> Cardano.Api.Eon.BabbageEraOnwards`
      - `Cardano.Api.Feature.ConwayEraOnwards -> Cardano.Api.Eon.ConwayEraOnwards`
      - `Cardano.Api.Feature.ShelleyToAllegraEra -> Cardano.Api.Eon.ShelleyToAllegraEra`
      - `Cardano.Api.Feature.ShelleyToAlonzoEra -> Cardano.Api.Eon.ShelleyToAlonzoEra`
      - `Cardano.Api.Feature.ShelleyToBabbageEra -> Cardano.Api.Eon.ShelleyToBabbageEra`
      - `Cardano.Api.Feature.ShelleyToMaryEra -> Cardano.Api.Eon.ShelleyToMaryEra`
    - Rename the following functions:
      - `inEraFeature` to `inEonEra`
      - `inEraFeature` to `eraInEon`
    - Rename the following functions (conservatively replacing "feature" with "eon" until we have a better naming convention):
      - `inEraFeatureMaybe -> inEraEonMaybe`
      - `maybeFeatureInEra -> maybeEonInEra`
      - `featureInShelleyBasedEra -> eonInShelleyBasedEra`
      - `inShelleyBasedEraFeature -> inShelleyBasedEraEon`
      - `inShelleyBasedEraFeatureMaybe -> inShelleyBasedEraEonMaybe`
      - `maybeFeatureInShelleyBasedEra -> maybeEonInShelleyBasedEra`
  type:
  # - feature        # introduces a new feature
  - breaking       # the API has changed in a breaking way
  # - compatible     # the API has changed but is non-breaking
  # - optimisation   # measurable performance improvements
  - improvement    # QoL changes e.g. refactoring
  # - bugfix         # fixes a defect
  # - test           # fixes/modifies tests
  # - maintenance    # not directly related to the code
  # - release        # related to a new release preparation
  # - documentation  # change in code docs, haddocks...

Context

The types that we have so far called "features" do not seem like features at all. Rather they represent some set of eras that scope the applicability of certain functionality.

This PR renames them to be "eons" instead. An Eon is some subset of eras.

Checklist

  • Commit sequence broadly makes sense and commits have useful messages
  • The change log section in the PR description has been filled in
  • New tests are added if needed and existing tests are updated. These may include:
    • golden tests
    • property tests
    • round trip tests
    • integration tests
      See Running tests for more details
  • The version bounds in .cabal files are updated
  • CI passes. See note on CI. The following CI checks are required:
    • Code is linted with hlint. See .github/workflows/check-hlint.yml to get the hlint version
    • Code is formatted with stylish-haskell. See .github/workflows/stylish-haskell.yml to get the stylish-haskell version
    • Code builds on Linux, MacOS and Windows for ghc-8.10.7 and ghc-9.2.7
  • The changelog section in the PR is updated to describe the change
  • Self-reviewed the diff

@newhoggy newhoggy marked this pull request as ready for review September 16, 2023 06:28
-- | An Eon is a span of multiple eras. Eon's are used to scope functionality to
-- particular eras such that it isn't possible construct code that uses functionality
-- that is not available given eras.
class IsEon (eon :: Type -> Type) where
Copy link
Contributor

Choose a reason for hiding this comment

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

Clever name. 🙂 I guess we can rename era ranges into e.g. AlonzoOnwardsEon to highlight that those are eons.

Copy link
Collaborator Author

@newhoggy newhoggy Sep 18, 2023

Choose a reason for hiding this comment

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

I was thinking of dropping the suffix altogether so that it is just AlonzoOnwards but I would do it as a separate change.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is definitely a more appropriate name but instead of IsEon why not InEon and inEon?
The comment could read: Determine the value to use in a span of eras (eon)

Copy link
Collaborator Author

@newhoggy newhoggy Sep 18, 2023

Choose a reason for hiding this comment

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

Eon is unclaimed so it can be just that.

The instances would look like this:

instance Eon AlonzoOnwards where
  ...

@@ -1029,8 +1029,8 @@ data ProtocolUTxOCostPerWordFeature era where
deriving instance Eq (ProtocolUTxOCostPerWordFeature era)
deriving instance Show (ProtocolUTxOCostPerWordFeature era)

instance FeatureInEra ProtocolUTxOCostPerWordFeature where
featureInEra no yes = \case
instance IsEon ProtocolUTxOCostPerWordFeature where
Copy link
Contributor

@carbolymer carbolymer Sep 18, 2023

Choose a reason for hiding this comment

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

From the naming point of view, I think this is confusing. Feature isn't an eon. If we want to use the same class for that, I'd suggest using more universal name e.g. IsAvailableInEra or IsPresentInEra or HasWitnessInEra.

Copy link
Collaborator Author

@newhoggy newhoggy Sep 18, 2023

Choose a reason for hiding this comment

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

ProtocolUTxOCostPerWordFeature could actually be replaced with AlonzoEraOnly because they are isomorphic to each other:

data ProtocolUTxOCostPerWordFeature era where
  ProtocolUpdateUTxOCostPerWordInAlonzoEra :: ProtocolUTxOCostPerWordFeature AlonzoEra

vs

data AlonzoEraOnly era where
  AlonzoEraOnlyAlonzo  :: AlonzoEraOnly AlonzoEra

and the latter has good integration with era feature switching functions and constraints summoning whereas the former is just the datatype.

All the feature GADTs can actually be replaced in this manner so the overloaded use of the name should not arise.

Copy link
Contributor

Choose a reason for hiding this comment

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

Makes sense. If we won't have to use this class for features I'm all for this change.

Copy link
Contributor

@carbolymer carbolymer left a comment

Choose a reason for hiding this comment

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

Nice name, but I don't think it fits our case in 100% https://github.com/input-output-hk/cardano-api/pull/247/files#r1328491918
@Jimbo4350 what do you think?

@newhoggy newhoggy force-pushed the newhoggy/rename-feature-to-eon branch from cba294a to 3264c3a Compare September 18, 2023 12:13
-- | An Eon is a span of multiple eras. Eon's are used to scope functionality to
-- particular eras such that it isn't possible construct code that uses functionality
-- that is not available given eras.
class IsEon (eon :: Type -> Type) where
Copy link
Contributor

Choose a reason for hiding this comment

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

This is definitely a more appropriate name but instead of IsEon why not InEon and inEon?
The comment could read: Determine the value to use in a span of eras (eon)

cardano-api/internal/Cardano/Api/Eras/Core.hs Outdated Show resolved Hide resolved
@newhoggy newhoggy force-pushed the newhoggy/rename-feature-to-eon branch 5 times, most recently from a44dc7e to a563862 Compare September 18, 2023 23:51
@newhoggy newhoggy force-pushed the newhoggy/rename-feature-to-eon branch 2 times, most recently from ce64aad to 412242a Compare September 19, 2023 01:54
cardano-api/gen/Test/Gen/Cardano/Api/Typed.hs Outdated Show resolved Hide resolved
@newhoggy newhoggy force-pushed the newhoggy/rename-feature-to-eon branch 2 times, most recently from 9853461 to 822425f Compare September 20, 2023 07:18
@newhoggy newhoggy requested a review from Jimbo4350 September 20, 2023 09:41
@newhoggy newhoggy dismissed Jimbo4350’s stale review September 20, 2023 09:42

Comments addressed

import Cardano.Api.Eras.Core

-- | A value only if the eon includes era
data Featured eon era a where
Copy link
Contributor

Choose a reason for hiding this comment

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

currentEra or targetEra instead of era?

Copy link
Collaborator Author

@newhoggy newhoggy Sep 20, 2023

Choose a reason for hiding this comment

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

It's the same sort of era as as the era in ShelleyBasedEra era in that we don't say ShelleyBasedEra currentEra. The qualification seems unnecessary.

-- but not others.
class FeatureInEra (feature :: Type -> Type) where
-- | Determine the value to use for a feature in a given 'CardanoEra'.
-- | An Eon is a span of multiple eras. Eon's are used to scope functionality to
Copy link
Contributor

Choose a reason for hiding this comment

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

💯

-- | Determine the value to use for a feature in a given 'ShelleyBasedEra'.
featureInShelleyBasedEra :: ()
=> FeatureInEra feature
inEonEra :: ()
Copy link
Contributor

Choose a reason for hiding this comment

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

inEonForEra? inEonEra is shorter but it's confusing to me

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I adopted inEonForEra and also forEraInEon for the other function where CardanoEra era is the first argument.

Copy link
Contributor

@carbolymer carbolymer left a comment

Choose a reason for hiding this comment

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

I think current naming is confusing, but If you prefer the current state, feel free to merge as it is now.

Comment on lines 155 to 161
inEraEonMaybe :: ()
=> Eon eon
=> CardanoEra era -- ^ Era to check
-> (eon era -> a) -- ^ Function to get the value to use if the eon includes the era
-> Maybe a -- ^ The value to use
inEraEonMaybe era yes =
eraInEon era Nothing (Just . yes)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
inEraEonMaybe :: ()
=> Eon eon
=> CardanoEra era -- ^ Era to check
-> (eon era -> a) -- ^ Function to get the value to use if the eon includes the era
-> Maybe a -- ^ The value to use
inEraEonMaybe era yes =
eraInEon era Nothing (Just . yes)
whenEraInEon :: ()
=> Eon eon
=> CardanoEra era -- ^ Era to check
-> (eon era -> a) -- ^ Function to get the value to use if the eon includes the era
-> Maybe a -- ^ The value to use
whenEraInEon era yes =
eraInEon era Nothing (Just . yes)

also Alternative f could be used instead of Maybe everywhere

Comment on lines +163 to +167
maybeEonInEra :: ()
=> Eon eon
=> CardanoEra era -- ^ Era to check
-> Maybe (eon era) -- ^ The eon if supported in the era
maybeEonInEra =
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
maybeEonInEra :: ()
=> Eon eon
=> CardanoEra era -- ^ Era to check
-> Maybe (eon era) -- ^ The eon if supported in the era
maybeEonInEra =
eonHasEraMaybe :: ()
=> Eon eon
=> CardanoEra era -- ^ Era to check
-> Maybe (eon era) -- ^ The eon if supported in the era
eonHasEraMaybe =


maybeFeatureInShelleyBasedEra :: ()
=> FeatureInEra feature
maybeEonInShelleyBasedEra :: ()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
maybeEonInShelleyBasedEra :: ()
whenShelleyBasedEraInEon :: ()


inShelleyBasedEraFeature :: ()
=> FeatureInEra feature
inShelleyBasedEraEon :: ()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
inShelleyBasedEraEon :: ()
shelleyBasedEraInEon :: ()

inEonEra Nothing Just

-- | Determine the value to use for a eon in a given 'ShelleyBasedEra'.
eonInShelleyBasedEra :: ()
Copy link
Contributor

Choose a reason for hiding this comment

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

this function is just inShelleyBasedEraEon with its arguments reordered. I think it is redundant and inShelleyBasedEraEon can be used everywhere instead.


inShelleyBasedEraFeatureMaybe :: ()
=> FeatureInEra feature
inShelleyBasedEraEonMaybe :: ()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
inShelleyBasedEraEonMaybe :: ()
whenShelleyBasedEraInEon :: ()

-- | Determine the value to use for a feature in a given 'ShelleyBasedEra'.
featureInShelleyBasedEra :: ()
=> FeatureInEra feature
inEonEra :: ()
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
inEonEra :: ()
hasEra :: ()

or hasEonEra or eraInEon

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I adopted this suggestion: #247 (comment)

cardano-api/internal/Cardano/Api/Eras/Core.hs Outdated Show resolved Hide resolved
-- | An Eon is a span of multiple eras. Eon's are used to scope functionality to
-- particular eras such that it isn't possible construct code that uses functionality
-- that is not available given eras.
class Eon (eon :: Type -> Type) where
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
class Eon (eon :: Type -> Type) where
class IsEon (eon :: Type -> Type) where

I feel that using IsEon instead of plain noun would be better suited here and represent the fact that something is an eon. I'd reserve plain nouns for concrete datatypes, just in case.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm okay with IsEon or Eon. I don't think there is a strong case for either. The standard library actually uses both.

For example the standard library uses Generic instead of IsGeneric whilst it uses IsString instead of String. I think the Is in IsString is necessary because the type String already exists, but we don't use IsGeneric and use Generic instead because there isn't a Generic type so the name is available for the type class.

@newhoggy newhoggy force-pushed the newhoggy/rename-feature-to-eon branch from 822425f to da43ac2 Compare September 20, 2023 15:32
@newhoggy newhoggy force-pushed the newhoggy/rename-feature-to-eon branch from da43ac2 to 9469db1 Compare September 20, 2023 15:55
@newhoggy
Copy link
Collaborator Author

newhoggy commented Sep 20, 2023

I think current naming is confusing, but If you prefer the current state, feel free to merge as it is now.

I don't actually prefer the current wording. I think the current wording is sub-optimal.

Nevertheless the goal of the PR isn't to optimise the naming of these functions. It's to remove the word "feature" because it isn't appropriate for the abstraction.

I'm merging this PR as it is to unblock other work.

We can have a separate PR to sort out the naming.

@newhoggy newhoggy requested a review from a team as a code owner September 20, 2023 16:02
@newhoggy newhoggy enabled auto-merge September 20, 2023 16:03
@newhoggy newhoggy added this pull request to the merge queue Sep 20, 2023
Merged via the queue into main with commit ee39ce5 Sep 20, 2023
20 checks passed
@newhoggy newhoggy deleted the newhoggy/rename-feature-to-eon branch September 20, 2023 19:10
newhoggy pushed a commit that referenced this pull request Mar 11, 2024
…ay-1.8

Update cardano-cli to newer cardano-ledger
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.

3 participants