Skip to content

Commit cb66ab7

Browse files
committed
Remove SimpleShow, add non-record Show instances
1 parent 5141f3e commit cb66ab7

File tree

28 files changed

+172
-400
lines changed

28 files changed

+172
-400
lines changed

plutus-core/executables/plutus/AnyProgram/Compile.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import Control.Monad.Reader
3535
import Data.Singletons.Decide
3636
import Data.Text
3737
import PlutusPrelude hiding ((%~))
38-
import Text.SimpleShow
3938

4039
-- Note that we use for erroring the original term's annotation
4140
compileProgram :: (?opts :: Opts, e ~ PIR.Provenance (FromAnn (US_ann s1)),
@@ -76,7 +75,7 @@ compileProgram = curry $ \case
7675

7776
-- pir to plc
7877
----------------------------------------
79-
(SPir n1@SName a1, SPlc n2 SUnit) -> withA @Ord a1 $ withA @Pretty a1 $ withA @SimpleShow a1 $
78+
(SPir n1@SName a1, SPlc n2 SUnit) -> withA @Ord a1 $ withA @Pretty a1 $ withA @Show a1 $
8079
-- Note: PIR.compileProgram subsumes pir typechecking
8180
(PLC.runQuoteT . flip runReaderT compCtx . PIR.compileProgram (const (return ())))
8281
>=> plcToOutName n1 n2

plutus-core/plutus-core.cabal

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,6 @@ library
190190
PlutusCore.Version
191191
PlutusPrelude
192192
Prettyprinter.Custom
193-
Text.SimpleShow
194193
Universe
195194
UntypedPlutusCore
196195
UntypedPlutusCore.Check.Scope

plutus-core/plutus-core/src/PlutusCore/Annotation.hs

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,10 @@ import Data.MonoTraversable
2323
import Data.Semigroup (Any (..))
2424
import Data.Set (Set)
2525
import Data.Set qualified as Set
26-
import Data.Text qualified as T
2726
import Flat (Flat (..))
2827
import GHC.Generics
2928
import Prettyprinter
3029
import Text.Megaparsec.Pos as Megaparsec
31-
import Text.SimpleShow
3230

3331
newtype InlineHints name a = InlineHints { shouldInline :: a -> name -> Bool }
3432
deriving (Semigroup, Monoid) via (a -> name -> Any)
@@ -42,7 +40,7 @@ data Ann = Ann
4240
, annSrcSpans :: SrcSpans
4341
}
4442
deriving stock (Eq, Ord, Generic, Show)
45-
deriving anyclass (Hashable, SimpleShow)
43+
deriving anyclass (Hashable)
4644

4745
data Inline
4846
= -- | When calling @PlutusIR.Compiler.Definitions.defineTerm@ to add a new term definition,
@@ -57,7 +55,6 @@ data Inline
5755
| MayInline
5856
deriving stock (Eq, Ord, Generic, Show)
5957
deriving anyclass (Hashable)
60-
deriving anyclass (SimpleShow)
6158

6259
instance Pretty Ann where
6360
pretty = viaShow
@@ -90,13 +87,6 @@ data SrcSpan = SrcSpan
9087
deriving stock (Eq, Ord, Generic)
9188
deriving anyclass (Flat, Hashable, NFData)
9289

93-
-- Cannot directly derive SimpleShow using Generic, since an instance of SimpleShow FilePath
94-
-- ( = String) results in overlapping instances, which do not work well with
95-
-- QuantifiedConstraints (needed for instances of uni)
96-
-- Workaround: print as tuple and use Text instance
97-
instance SimpleShow SrcSpan where
98-
simpleShow (SrcSpan f l c l' c') = simpleShow (T.pack f, l, c, l', c')
99-
10090
instance Show SrcSpan where
10191
showsPrec _ s =
10292
showString (srcSpanFile s)
@@ -115,7 +105,7 @@ instance Pretty SrcSpan where
115105
newtype SrcSpans = SrcSpans {unSrcSpans :: Set SrcSpan}
116106
deriving newtype (Eq, Ord, Hashable, Semigroup, Monoid, MonoFoldable, NFData)
117107
deriving stock (Generic)
118-
deriving anyclass (Flat, SimpleShow)
108+
deriving anyclass (Flat)
119109

120110
type instance Element SrcSpans = SrcSpan
121111

plutus-core/plutus-core/src/PlutusCore/Core/Type.hs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
{-# LANGUAGE MultiParamTypeClasses #-}
88
{-# LANGUAGE PatternSynonyms #-}
99
{-# LANGUAGE PolyKinds #-}
10-
{-# LANGUAGE QuantifiedConstraints #-}
1110
{-# LANGUAGE StandaloneKindSignatures #-}
1211
{-# LANGUAGE TemplateHaskell #-}
1312
{-# LANGUAGE TypeApplications #-}
@@ -70,14 +69,13 @@ import Data.List.NonEmpty qualified as NE
7069
import Data.Word
7170
import Instances.TH.Lift ()
7271
import Language.Haskell.TH.Lift
73-
import Text.SimpleShow
7472
import Universe
7573

7674
data Kind ann
7775
= Type ann
7876
| KindArrow ann (Kind ann) (Kind ann)
7977
deriving stock (Eq, Show, Functor, Generic, Lift)
80-
deriving anyclass (NFData, Hashable, SimpleShow)
78+
deriving anyclass (NFData, Hashable)
8179

8280
-- | The kind of a pattern functor (the first 'Type' argument of 'TyIFix') at a given kind (of the
8381
-- second 'Type' argument of 'TyIFix'):
@@ -111,14 +109,6 @@ data Type tyname uni ann
111109
deriving stock (Show, Functor, Generic)
112110
deriving anyclass (NFData)
113111

114-
deriving anyclass instance
115-
( SimpleShow tyname
116-
, forall t. SimpleShow (uni t)
117-
, Everywhere uni SimpleShow
118-
, SimpleShow a
119-
) =>
120-
SimpleShow (Type tyname uni a)
121-
122112
-- | Get recursively all the domains and codomains of a type.
123113
-- @splitFunTyParts (A->B->C) = [A, B, C]@
124114
-- @splitFunTyParts (X) = [X]@
@@ -195,30 +185,40 @@ data TyVarDecl tyname ann = TyVarDecl
195185
{ _tyVarDeclAnn :: ann
196186
, _tyVarDeclName :: tyname
197187
, _tyVarDeclKind :: Kind ann
198-
} deriving stock (Functor, Show, Generic)
199-
makeLenses ''TyVarDecl
188+
} deriving stock (Functor, Generic)
189+
190+
instance (Show tn, Show ann) => Show (TyVarDecl tn ann) where
191+
showsPrec p (TyVarDecl x y z) =
192+
showParen (p >= 11) $
193+
showString "TyVarDecl" .
194+
showString " " .
195+
showsPrec 11 x .
196+
showString " " .
197+
showsPrec 11 y .
198+
showString " " .
199+
showsPrec 11 z
200200

201-
deriving anyclass instance
202-
( SimpleShow tyname
203-
, SimpleShow a
204-
) => SimpleShow (TyVarDecl tyname a)
201+
makeLenses ''TyVarDecl
205202

206203
-- | A "variable declaration", i.e. a name and a type for a variable.
207204
data VarDecl tyname name uni ann = VarDecl
208205
{ _varDeclAnn :: ann
209206
, _varDeclName :: name
210207
, _varDeclType :: Type tyname uni ann
211-
} deriving stock (Functor, Show, Generic)
212-
makeLenses ''VarDecl
208+
} deriving stock (Functor, Generic)
209+
210+
instance (Show tn, Show ann, GShow uni, Show n) => Show (VarDecl tn n uni ann) where
211+
showsPrec p (VarDecl x y z) =
212+
showParen (p >= 11) $
213+
showString "VarDecl" .
214+
showString " " .
215+
showsPrec 11 x .
216+
showString " " .
217+
showsPrec 11 y .
218+
showString " " .
219+
showsPrec 11 z
213220

214-
deriving anyclass instance
215-
( SimpleShow tyname
216-
, SimpleShow name
217-
, forall t. SimpleShow (uni t)
218-
, Everywhere uni SimpleShow
219-
, SimpleShow a
220-
) =>
221-
SimpleShow (VarDecl tyname name uni a)
221+
makeLenses ''VarDecl
222222

223223
-- | A "type declaration", i.e. a kind for a type.
224224
data TyDecl tyname uni ann = TyDecl

plutus-core/plutus-core/src/PlutusCore/Crypto/BLS12_381/G1.hs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ import Data.ByteString (ByteString, length)
3131
import Data.Coerce (coerce)
3232
import Data.Hashable
3333
import Data.Proxy (Proxy (..))
34-
import Data.Text qualified as T
3534
import Flat
3635
import Prettyprinter
37-
import Text.SimpleShow
3836

3937
{- Note [Wrapping the BLS12-381 types in Plutus Core]. In the Haskell bindings
4038
to the `blst` library in cardano-crypto-class, points in G1 and G2 are
@@ -75,9 +73,6 @@ instance NFData Element where
7573
instance Hashable Element where
7674
hashWithSalt salt = hashWithSalt salt . compress
7775

78-
instance SimpleShow Element where
79-
simpleShow = T.pack . show
80-
8176
-- | Add two G1 group elements
8277
add :: Element -> Element -> Element
8378
add = coerce (BlstBindings.blsAddOrDouble @BlstBindings.Curve1)

plutus-core/plutus-core/src/PlutusCore/Crypto/BLS12_381/G2.hs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,8 @@ import Data.ByteString (ByteString, length)
3131
import Data.Coerce (coerce)
3232
import Data.Hashable
3333
import Data.Proxy (Proxy (..))
34-
import Data.Text qualified as T
3534
import Flat
3635
import Prettyprinter
37-
import Text.SimpleShow
3836

3937
{- | See Note [Wrapping the BLS12-381 types in Plutus Core]. -}
4038
newtype Element = Element { unElement :: BlstBindings.Point2 }
@@ -61,9 +59,6 @@ instance NFData Element where
6159
instance Hashable Element where
6260
hashWithSalt salt = hashWithSalt salt . compress
6361

64-
instance SimpleShow Element where
65-
simpleShow = T.pack . show
66-
6762
-- | Add two G2 group elements
6863
add :: Element -> Element -> Element
6964
add = coerce (BlstBindings.blsAddOrDouble @BlstBindings.Curve2)

plutus-core/plutus-core/src/PlutusCore/Crypto/BLS12_381/Pairing.hs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,8 @@ import Text.PrettyBy (PrettyBy, prettyBy)
2222
import Control.DeepSeq (NFData, rnf)
2323
import Data.Coerce (coerce)
2424
import Data.Hashable
25-
import Data.Text qualified as T
2625
import Flat
2726
import Prettyprinter
28-
import Text.SimpleShow
2927

3028
{- | This type represents the result of computing a pairing using the Miller
3129
loop. Values of this type are ephemeral, only created during script
@@ -55,9 +53,6 @@ instance NFData MlResult where
5553
instance Hashable MlResult where
5654
hashWithSalt salt = const salt
5755

58-
instance SimpleShow MlResult where
59-
simpleShow = T.pack . show
60-
6156
millerLoop :: G1.Element -> G2.Element -> MlResult
6257
millerLoop = coerce BlstBindings.millerLoop
6358

plutus-core/plutus-core/src/PlutusCore/Data.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import GHC.Generics
2929
import NoThunks.Class
3030
import Prelude
3131
import Prettyprinter
32-
import Text.SimpleShow
3332

3433
-- Attempting to make this strict made code slower by 2%,
3534
-- see https://github.com/IntersectMBO/plutus/pull/4622
@@ -59,8 +58,6 @@ instance Pretty Data where
5958
-- Base64 encode the ByteString since it may contain arbitrary bytes
6059
pretty (Text.decodeLatin1 (Base64.encode b))
6160

62-
deriving anyclass instance SimpleShow Data
63-
6461
{- Note [Encoding via Term]
6562
We want to write a custom encoder/decoder for Data (i.e. not use the Generic version), but actually
6663
doing this is a pain. So instead we go via the CBOR 'Term' representation, which lets us process a

plutus-core/plutus-core/src/PlutusCore/Default/Builtins.hs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import Flat.Decoder (Get, dBEBits8)
4848
import Flat.Encoder as Flat (Encoding, NumBits, eBits)
4949
import NoThunks.Class (NoThunks)
5050
import Prettyprinter (viaShow)
51-
import Text.SimpleShow
5251

5352
-- See Note [Pattern matching on built-in types].
5453
-- TODO: should we have the commonest built-in functions at the front to have more compact encoding?
@@ -175,7 +174,7 @@ data DefaultFun
175174
| Ripemd_160
176175
| ExpModInteger
177176
deriving stock (Show, Eq, Ord, Enum, Bounded, Generic, Ix)
178-
deriving anyclass (NFData, Hashable, PrettyBy PrettyConfigPlc, SimpleShow)
177+
deriving anyclass (NFData, Hashable, PrettyBy PrettyConfigPlc)
179178

180179
{- Note [Textual representation of names of built-in functions]. The plc parser
181180
parses builtin names by looking at an enumeration of all of the built-in

plutus-core/plutus-core/src/PlutusCore/Default/Universe.hs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ import Data.Typeable (typeRep)
6262
import Data.Word
6363
import GHC.Exts (inline, oneShot)
6464
import Text.PrettyBy.Fixity
65-
import Text.SimpleShow
6665
import Universe as Export
6766

6867
{- Note [PLC types and universes]
@@ -179,12 +178,6 @@ instance GEq DefaultUni where
179178
geqRec = geqStep
180179
{-# OPAQUE geqRec #-}
181180

182-
instance SimpleShow (DefaultUni a) where
183-
simpleShow x = parens True (Text.pack (show x))
184-
185-
instance SimpleShow (Some (ValueOf DefaultUni)) where
186-
simpleShow (Some x) = parens True (simpleShow x)
187-
188181
-- | For pleasing the coverage checker.
189182
noMoreTypeFunctions :: DefaultUni (Esc (f :: a -> b -> c -> d)) -> any
190183
noMoreTypeFunctions (f `DefaultUniApply` _) = noMoreTypeFunctions f

0 commit comments

Comments
 (0)