-
Notifications
You must be signed in to change notification settings - Fork 509
Remove the deriving-aeson dependency
#7871
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
Open
Unisay
wants to merge
2
commits into
master
Choose a base branch
from
yura/issue-7870-remove-deriving-aeson
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
.../changelog.d/20260728_100010_yuriy.lazaryev_issue_7870_remove_deriving_aeson.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| ### Removed | ||
|
|
||
| - `LowerInitialCharacter` is no longer exported from `PlutusCore.Evaluation.Machine.ExBudget`; it existed solely to support `deriving-aeson`, which `plutus-core` no longer depends on. | ||
|
|
||
| ### Changed | ||
|
|
||
| - Replaced the `deriving-aeson`-based JSON instances of the cost model types with plain `aeson` generic instances. The JSON format is unchanged. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| -- editorconfig-checker-disable-file | ||
| {-# LANGUAGE ConstraintKinds #-} | ||
| {-# LANGUAGE DataKinds #-} | ||
| {-# LANGUAGE DeriveAnyClass #-} | ||
| {-# LANGUAGE FlexibleInstances #-} | ||
| {-# LANGUAGE StrictData #-} | ||
|
|
@@ -57,13 +56,12 @@ import PlutusPrelude hiding (toList) | |
|
|
||
| import PlutusCore.Evaluation.Machine.CostingFun.Core | ||
| import PlutusCore.Evaluation.Machine.CostingFun.JSON () | ||
| import PlutusCore.Evaluation.Machine.ExBudget | ||
|
|
||
| import Barbies | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe qualify this so we can see what we're using? I tried Not sure what's going on there. |
||
| import Data.Aeson | ||
| import Data.Kind qualified as Kind | ||
| import Data.List (stripPrefix) | ||
| import Data.Monoid | ||
| import Deriving.Aeson | ||
| import Language.Haskell.TH.Syntax hiding (Name, newName) | ||
|
|
||
| type BuiltinCostModel = BuiltinCostModelBase CostingFun | ||
|
|
@@ -203,18 +201,21 @@ data BuiltinCostModelBase f | |
| deriving stock (Generic) | ||
| deriving anyclass (FunctorB, TraversableB, ConstraintsB) | ||
|
|
||
| deriving via | ||
| CustomJSON | ||
| '[FieldLabelModifier (StripPrefix "param", LowerInitialCharacter)] | ||
| (BuiltinCostModelBase CostingFun) | ||
| instance | ||
| ToJSON (BuiltinCostModelBase CostingFun) | ||
| deriving via | ||
| CustomJSON | ||
| '[FieldLabelModifier (StripPrefix "param", LowerInitialCharacter)] | ||
| (BuiltinCostModelBase CostingFun) | ||
| instance | ||
| FromJSON (BuiltinCostModelBase CostingFun) | ||
| {-| JSON options for 'BuiltinCostModelBase': drop the @param@ prefix and lower the initial | ||
| character, so that the names of the JSON fields are exactly the same as the names of the | ||
| builtins. -} | ||
| builtinCostModelOptions :: Options | ||
| builtinCostModelOptions = | ||
| defaultOptions {fieldLabelModifier = lowerInitialChar . dropPrefix "param"} | ||
| where | ||
| dropPrefix prefix s = fromMaybe s (stripPrefix prefix s) | ||
|
|
||
| instance ToJSON (BuiltinCostModelBase CostingFun) where | ||
| toJSON = genericToJSON builtinCostModelOptions | ||
| toEncoding = genericToEncoding builtinCostModelOptions | ||
|
|
||
| instance FromJSON (BuiltinCostModelBase CostingFun) where | ||
| parseJSON = genericParseJSON builtinCostModelOptions | ||
|
|
||
| {-| Same as 'CostingFun' but maybe missing. | ||
| We could use 'Compose Maybe CostinFun' instead but we would then need an orphan ToJSON instance. -} | ||
|
|
@@ -223,12 +224,12 @@ newtype MCostingFun a = MCostingFun (Maybe (CostingFun a)) | |
| deriving (Semigroup, Monoid) via (Alt Maybe (CostingFun a)) -- for mempty == MCostingFun Nothing | ||
|
|
||
| -- Omit generating JSON for any costing functions that have not been set (are missing). | ||
| deriving via | ||
| CustomJSON | ||
| '[OmitNothingFields, FieldLabelModifier (StripPrefix "param", LowerInitialCharacter)] | ||
| (BuiltinCostModelBase MCostingFun) | ||
| instance | ||
| ToJSON (BuiltinCostModelBase MCostingFun) | ||
| instance ToJSON (BuiltinCostModelBase MCostingFun) where | ||
| toJSON = genericToJSON mBuiltinCostModelOptions | ||
| toEncoding = genericToEncoding mBuiltinCostModelOptions | ||
|
|
||
| mBuiltinCostModelOptions :: Options | ||
| mBuiltinCostModelOptions = builtinCostModelOptions {omitNothingFields = True} | ||
|
|
||
| -- Needed to help derive various instances for BuiltinCostModelBase | ||
| type AllArgumentModels (constraint :: Kind.Type -> Kind.Constraint) f = | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 was a bit worried that these might give different results, but if you look at the implementation in
deriving-aesonit hasso the previous code was secretly using
camelTo2anyway.It does look as if you have to be a bit careful about what conversion functions like this do in general. For example we have a constructor called
LinearInMaxYZand there's a question of what happens if you have a sequence of multiple uppercase letters. In this casecamelTo2 '_'giveslinear_in_max_yz, butlinear_in_max_y_zmight be justifiable as well (and it looks as if there are functions in other libraries that would do that).