Skip to content

Commit fd8e564

Browse files
committed
feedback for PR #6173
1 parent 81627f9 commit fd8e564

File tree

4 files changed

+35
-40
lines changed

4 files changed

+35
-40
lines changed

bench/cardano-profile/src/Cardano/Benchmarking/Profile.hs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module Cardano.Benchmarking.Profile
1212

1313
import Prelude
1414
import Control.Monad (foldM)
15+
import Data.Maybe (catMaybes)
1516
import System.IO.Unsafe (unsafePerformIO)
1617
import GHC.Stack (HasCallStack)
1718
-- Package: aeson.
@@ -478,20 +479,7 @@ unionWithKey _ _ b = b
478479
addEras :: Map.Map String Types.Profile -> Map.Map String Types.Profile
479480
addEras = foldMap
480481
(\profile -> Map.fromList $
481-
let
482-
-- TODO: Profiles properties other than the "name" and "era" of
483-
-- type string are the only thing that change ??? Remove the
484-
-- concept of eras from the profile definitions and make it a
485-
-- workbench-level feature (???).
486-
addEra p era suffix
487-
| Just (major, _) <- Types.profileProtocolVersion p
488-
, era < Types.firstEraForMajorVersion major
489-
= mempty
490-
| otherwise
491-
= let name = Types.name p
492-
newName = name ++ "-" ++ suffix
493-
in [(newName, p {Types.name = newName, Types.era = era})]
494-
in mconcat
482+
catMaybes
495483
[ addEra profile Types.Shelley "shey"
496484
, addEra profile Types.Allegra "alra"
497485
, addEra profile Types.Mary "mary"
@@ -500,3 +488,13 @@ addEras = foldMap
500488
, addEra profile Types.Conway "coay"
501489
]
502490
)
491+
492+
addEra :: Types.Profile -> Types.Era -> String -> Maybe (String, Types.Profile)
493+
addEra p era suffix
494+
| Just (major, _) <- Types.profileProtocolVersion p
495+
, era < Types.firstEraForMajorVersion major
496+
= Nothing
497+
| otherwise
498+
= let name = Types.name p
499+
newName = name ++ "-" ++ suffix
500+
in Just (newName, p {Types.name = newName, Types.era = era})

bench/cardano-profile/test/Main.hs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{-# LANGUAGE Trustworthy #-}
2-
{-# LANGUAGE OverloadedStrings #-}
32
{-# LANGUAGE ExistentialQuantification #-}
3+
{-# LANGUAGE OverloadedStrings #-}
44

55
--------------------------------------------------------------------------------
66
module Main (main) where
@@ -766,13 +766,19 @@ testGroupMap = Tasty.testGroup
766766
)
767767
, testCase "Profiles (Duplicate names)" $
768768
let
769-
go (set, duplicates) name
770-
| name `Set.member` set = (set, name:duplicates)
771-
| otherwise = (name `Set.insert` set, duplicates)
769+
go (T set duplicates) name
770+
| name `Set.member` set = T set (name:duplicates)
771+
| otherwise = T (name `Set.insert` set) duplicates
772772
in assertEqual "Duplicate definition(s) for profile(s)" []
773-
$ snd $ foldl' go (Set.empty, []) (map Types.name profilesRaw)
773+
$ sndT $ foldl' go (T Set.empty []) (map Types.name profilesRaw)
774774
]
775775

776+
-- little helper type for tuples strict in the first element
777+
data TupleStrictFirst a b = T !a b
778+
779+
sndT :: TupleStrictFirst a b -> b
780+
sndT (T _ b) = b
781+
776782
--------------------------------------------------------------------------------
777783

778784
-- The overlay to apply.

bench/tx-generator/src-calibrate/Cardano/TxGenerator/Calibrate/Utils.hs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import Data.Aeson (eitherDecodeFileStrict')
1717
import Data.Aeson.Encode.Pretty
1818
import Data.Bool (bool)
1919
import qualified Data.ByteString.Lazy.Char8 as BSL (ByteString, putStrLn)
20-
import Data.Functor ((<&>))
2120
import System.Directory (doesFileExist)
2221
import System.FilePath
2322

@@ -62,18 +61,18 @@ resolveRedeemerQuiet quiet = \case
6261
-- NB: while scripts-fallback/ content might be used in production, data/ should *NEVER* be - it's for tx-generator development and testing only
6362
Left n -> do
6463
let fallbackName = "data" </> n <.> "redeemer" <.> "json"
65-
fileExists <- maybe (pure False) doesFileExist plutusRedeemer
66-
fallbackFile <- try (getDataFileName fallbackName) <&> either (\SomeException{} -> "") id
67-
loader $ if fileExists then plutusRedeemer else Just fallbackFile
64+
fileExists <- or <$> forM plutusRedeemer doesFileExist
65+
fallbackFile <- either (\SomeException{} -> Nothing) Just <$> try (getDataFileName fallbackName)
66+
loader $ if fileExists then plutusRedeemer else fallbackFile
6867

6968
Right{} -> pure $ Left $ TxGenError "resolveRedeemer: no Plutus script defined"
7069

7170
where
7271
loader = \case
73-
Just f@(_:_) -> do
72+
Just f -> do
7473
unless quiet $ putStrLn $ "--> will read redeemer from: " ++ f
7574
readScriptData f
76-
_ -> pure $ Left $ TxGenError "resolveRedeemer: no redeemer file resolved"
75+
Nothing -> pure $ Left $ TxGenError "resolveRedeemer: no redeemer file resolved"
7776

7877
printScriptData :: ScriptData -> IO ()
7978
printScriptData =

bench/tx-generator/tx-generator.cabal

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ common project-config
2626
if os(windows)
2727
buildable: False
2828

29+
default-language: Haskell2010
30+
2931
common with-library
3032
-- This is the inverse to the "buildable" GHC version constraint in plutus-scripts-bench.
3133
-- It makes sure, we only depend on that package if it is buildable.
@@ -38,6 +40,7 @@ common maybe-unix
3840
if !os(windows)
3941
build-depends: unix
4042

43+
4144
library
4245
import: project-config, with-library, maybe-unix
4346

@@ -168,14 +171,12 @@ library
168171
, scientific
169172
, cardano-ledger-babbage
170173

171-
default-language: Haskell2010
172174
default-extensions: OverloadedStrings
173175

174176
executable tx-generator
175177
import: project-config
176178
hs-source-dirs: app
177179
main-is: tx-generator.hs
178-
default-language: Haskell2010
179180
ghc-options: -threaded
180181
-Wall
181182
-rtsopts
@@ -190,9 +191,8 @@ executable calibrate-script
190191
hs-source-dirs: app
191192
src-calibrate
192193
main-is: calibrate-script.hs
193-
default-language: Haskell2010
194-
ghc-options: -threaded
195-
-Wall
194+
195+
ghc-options: -Wall
196196
-rtsopts
197197
"-with-rtsopts=-T"
198198
-Wno-deprecations
@@ -207,9 +207,6 @@ executable calibrate-script
207207
, filepath
208208
, optparse-applicative-fork
209209
, cardano-api
210-
, cardano-cli
211-
, cardano-node
212-
, plutus-tx
213210
, text
214211
, transformers
215212
, transformers-except
@@ -228,9 +225,8 @@ test-suite tx-generator-apitest
228225
test
229226
main-is: ApiTest.hs
230227
type: exitcode-stdio-1.0
231-
default-language: Haskell2010
232-
ghc-options: -threaded
233-
-Wall
228+
229+
ghc-options: -Wall
234230
-rtsopts
235231
"-with-rtsopts=-T"
236232
-Wno-deprecations
@@ -266,8 +262,6 @@ test-suite tx-generator-test
266262
, tasty-hunit
267263
, tx-generator
268264

269-
default-language: Haskell2010
270-
271265
ghc-options: -Weverything
272266
-fno-warn-missing-import-lists
273267
-fno-warn-safe
@@ -285,8 +279,6 @@ benchmark tx-generator-bench
285279
, stm
286280
, tx-generator
287281

288-
default-language: Haskell2010
289-
290282
ghc-options: -Weverything
291283
-fno-warn-missing-import-lists
292284
-fno-warn-safe

0 commit comments

Comments
 (0)