From e203060fee41c970cd89b64fbf4dcea7dc8a7cc9 Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Wed, 21 May 2025 18:14:52 +0200 Subject: [PATCH 1/7] Removed not needed SRP --- cabal.project | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/cabal.project b/cabal.project index 20a5a27..6e1a548 100644 --- a/cabal.project +++ b/cabal.project @@ -1,4 +1,4 @@ -index-state: 2025-05-05T00:00:00Z +index-state: 2025-05-21T15:48:46Z packages: ./typed-protocols ./typed-protocols-doc @@ -13,11 +13,3 @@ if impl(ghc >= 9.12) if os(windows) package text flags: -simdutf - -source-repository-package - type: git - location: https://github.com/input-output-hk/io-sim - tag: aef112549bf85d51a03919008b6091af8933e9e2 - --sha256: sha256-yfhBeAYwWktqBAkvXUVdrgBzNvTwAqMKglcjwflMtM4= - subdir: io-classes - io-sim From bf213872a0c8a3e5aa2f3102a6437dbcc1335ad9 Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Thu, 22 May 2025 09:33:19 +0200 Subject: [PATCH 2/7] cleaned up the cabal file --- typed-protocols/typed-protocols.cabal | 241 +++++++++++--------------- 1 file changed, 105 insertions(+), 136 deletions(-) diff --git a/typed-protocols/typed-protocols.cabal b/typed-protocols/typed-protocols.cabal index 5232146..265bf84 100644 --- a/typed-protocols/typed-protocols.cabal +++ b/typed-protocols/typed-protocols.cabal @@ -16,60 +16,54 @@ tested-with: GHC == {9.6, 9.8, 9.10, 9.12} extra-doc-files: CHANGELOG.md README.md +common warnings + ghc-options: -Wall + -Wno-unticked-promoted-constructors + -Wcompat + -Wincomplete-uni-patterns + -Wincomplete-record-updates + -Wpartial-fields + -Widentities + -Wredundant-constraints + library - exposed-modules: Network.TypedProtocol - , Network.TypedProtocol.Core - , Network.TypedProtocol.Peer - , Network.TypedProtocol.Peer.Client - , Network.TypedProtocol.Peer.Server - , Network.TypedProtocol.Codec - , Network.TypedProtocol.Driver - , Network.TypedProtocol.Proofs - other-modules: Network.TypedProtocol.Lemmas - build-depends: base >=4.12 && <4.22, - io-classes:io-classes ^>= 1.8, - singletons ^>= 3.0 - - hs-source-dirs: src - default-language: GHC2021 + import: warnings + exposed-modules: Network.TypedProtocol + , Network.TypedProtocol.Core + , Network.TypedProtocol.Peer + , Network.TypedProtocol.Peer.Client + , Network.TypedProtocol.Peer.Server + , Network.TypedProtocol.Codec + , Network.TypedProtocol.Driver + , Network.TypedProtocol.Proofs + other-modules: Network.TypedProtocol.Lemmas + build-depends: base >=4.12 && <4.22, + io-classes:io-classes ^>= 1.8, + singletons ^>= 3.0 + hs-source-dirs: src + default-language: GHC2021 default-extensions: DataKinds GADTs LambdaCase - ghc-options: -Wall - -Wno-unticked-promoted-constructors - -Wcompat - -Wincomplete-uni-patterns - -Wincomplete-record-updates - -Wpartial-fields - -Widentities - -Wredundant-constraints library cborg - visibility: public - exposed-modules: Network.TypedProtocol.Codec.CBOR - - build-depends: base, - bytestring >=0.10 && <0.13, - cborg >=0.2.1 && <0.3, - singletons, - primitive, - - io-classes:io-classes, - typed-protocols:typed-protocols + import: warnings + visibility: public + exposed-modules: Network.TypedProtocol.Codec.CBOR + build-depends: base, + bytestring >=0.10 && <0.13, + cborg >=0.2.1 && <0.3, + singletons, + primitive, - hs-source-dirs: cborg - default-language: GHC2021 + io-classes:io-classes, + typed-protocols:typed-protocols + hs-source-dirs: cborg + default-language: GHC2021 default-extensions: LambdaCase - ghc-options: -Wall - -Wno-unticked-promoted-constructors - -Wcompat - -Wincomplete-uni-patterns - -Wincomplete-record-updates - -Wpartial-fields - -Widentities - -Wredundant-constraints library stateful + import: warnings visibility: public exposed-modules: Network.TypedProtocol.Stateful.Peer , Network.TypedProtocol.Stateful.Peer.Client @@ -81,117 +75,92 @@ library stateful singletons, io-classes:io-classes, typed-protocols:typed-protocols - hs-source-dirs: stateful default-language: GHC2021 default-extensions: DataKinds GADTs ImportQualifiedPost - ghc-options: -Wall - -Wno-unticked-promoted-constructors - -Wcompat - -Wincomplete-uni-patterns - -Wincomplete-record-updates - -Wpartial-fields - -Widentities - -Wredundant-constraints library stateful-cborg - visibility: public - exposed-modules: Network.TypedProtocol.Stateful.Codec.CBOR - - build-depends: base, - bytestring, - cborg, - singletons, + import: warnings + visibility: public + exposed-modules: Network.TypedProtocol.Stateful.Codec.CBOR - io-classes:io-classes, - typed-protocols:{typed-protocols,cborg,stateful} + build-depends: base, + bytestring, + cborg, + singletons, - hs-source-dirs: stateful-cborg - default-language: GHC2021 + io-classes:io-classes, + typed-protocols:{typed-protocols,cborg,stateful} + hs-source-dirs: stateful-cborg + default-language: GHC2021 default-extensions: ImportQualifiedPost - ghc-options: -Wall - -Wno-unticked-promoted-constructors - -Wcompat - -Wincomplete-uni-patterns - -Wincomplete-record-updates - -Wpartial-fields - -Widentities - -Wredundant-constraints library examples - visibility: public - exposed-modules: Network.TypedProtocol.Channel - , Network.TypedProtocol.Driver.Simple - - , Network.TypedProtocol.PingPong.Type - , Network.TypedProtocol.PingPong.Client - , Network.TypedProtocol.PingPong.Server - , Network.TypedProtocol.PingPong.Codec - , Network.TypedProtocol.PingPong.Codec.CBOR - , Network.TypedProtocol.PingPong.Examples - - , Network.TypedProtocol.ReqResp.Type - , Network.TypedProtocol.ReqResp.Client - , Network.TypedProtocol.ReqResp.Server - , Network.TypedProtocol.ReqResp.Codec - , Network.TypedProtocol.ReqResp.Codec.CBOR - , Network.TypedProtocol.ReqResp.Examples - - , Network.TypedProtocol.ReqResp2.Type - , Network.TypedProtocol.ReqResp2.Client - - , Network.TypedProtocol.Stateful.ReqResp.Type - , Network.TypedProtocol.Stateful.ReqResp.Client - , Network.TypedProtocol.Stateful.ReqResp.Server - , Network.TypedProtocol.Stateful.ReqResp.Codec - , Network.TypedProtocol.Stateful.ReqResp.Examples - - , Network.TypedProtocol.Trans.Wedge - build-depends: base, - bytestring, - cborg, - serialise, - singletons, - contra-tracer, - io-classes:{io-classes, si-timers}, - network, - time, - typed-protocols:{typed-protocols,cborg,stateful} - - hs-source-dirs: examples - default-language: GHC2021 + import: warnings + visibility: public + exposed-modules: Network.TypedProtocol.Channel + , Network.TypedProtocol.Driver.Simple + + , Network.TypedProtocol.PingPong.Type + , Network.TypedProtocol.PingPong.Client + , Network.TypedProtocol.PingPong.Server + , Network.TypedProtocol.PingPong.Codec + , Network.TypedProtocol.PingPong.Codec.CBOR + , Network.TypedProtocol.PingPong.Examples + + , Network.TypedProtocol.ReqResp.Type + , Network.TypedProtocol.ReqResp.Client + , Network.TypedProtocol.ReqResp.Server + , Network.TypedProtocol.ReqResp.Codec + , Network.TypedProtocol.ReqResp.Codec.CBOR + , Network.TypedProtocol.ReqResp.Examples + + , Network.TypedProtocol.ReqResp2.Type + , Network.TypedProtocol.ReqResp2.Client + + , Network.TypedProtocol.Stateful.ReqResp.Type + , Network.TypedProtocol.Stateful.ReqResp.Client + , Network.TypedProtocol.Stateful.ReqResp.Server + , Network.TypedProtocol.Stateful.ReqResp.Codec + , Network.TypedProtocol.Stateful.ReqResp.Examples + + , Network.TypedProtocol.Trans.Wedge + build-depends: base, + bytestring, + cborg, + serialise, + singletons, + contra-tracer, + io-classes:{io-classes, si-timers}, + network, + time, + typed-protocols:{typed-protocols,cborg,stateful} + hs-source-dirs: examples + default-language: GHC2021 default-extensions: DataKinds GADTs LambdaCase - ghc-options: -Wall - -Wno-unticked-promoted-constructors - -Wcompat - -Wincomplete-uni-patterns - -Wincomplete-record-updates - -Wpartial-fields - -Widentities - -Wredundant-constraints test-suite test - type: exitcode-stdio-1.0 - main-is: Main.hs - hs-source-dirs: test - default-language: GHC2021 + type: exitcode-stdio-1.0 + main-is: Main.hs + hs-source-dirs: test + default-language: GHC2021 default-extensions: GADTs LambdaCase - other-modules: Network.TypedProtocol.PingPong.Tests - , Network.TypedProtocol.ReqResp.Tests - build-depends: base - , bytestring - , contra-tracer - , typed-protocols:{typed-protocols,cborg,examples} - , io-classes:{io-classes,si-timers} - , io-sim - , QuickCheck - , tasty - , tasty-quickcheck + other-modules: Network.TypedProtocol.PingPong.Tests + , Network.TypedProtocol.ReqResp.Tests + build-depends: base + , bytestring + , contra-tracer + , typed-protocols:{typed-protocols,cborg,examples} + , io-classes:{io-classes,si-timers} + , io-sim + , QuickCheck + , tasty + , tasty-quickcheck if !os(windows) build-depends: directory From 13c29f9c93ea9dcae2d98268241c731e57d4767e Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Thu, 22 May 2025 09:38:36 +0200 Subject: [PATCH 3/7] Added -Wunused-packages to ghc-options --- typed-protocols/typed-protocols.cabal | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/typed-protocols/typed-protocols.cabal b/typed-protocols/typed-protocols.cabal index 265bf84..3879840 100644 --- a/typed-protocols/typed-protocols.cabal +++ b/typed-protocols/typed-protocols.cabal @@ -25,6 +25,7 @@ common warnings -Wpartial-fields -Widentities -Wredundant-constraints + -Wunused-packages library import: warnings @@ -53,8 +54,6 @@ library cborg build-depends: base, bytestring >=0.10 && <0.13, cborg >=0.2.1 && <0.3, - singletons, - primitive, io-classes:io-classes, typed-protocols:typed-protocols @@ -89,7 +88,6 @@ library stateful-cborg build-depends: base, bytestring, cborg, - singletons, io-classes:io-classes, typed-protocols:{typed-protocols,cborg,stateful} @@ -134,9 +132,9 @@ library examples singletons, contra-tracer, io-classes:{io-classes, si-timers}, - network, - time, typed-protocols:{typed-protocols,cborg,stateful} + if !os(windows) + build-depends: network hs-source-dirs: examples default-language: GHC2021 default-extensions: DataKinds From 5166f50e5b666d465dc1b3e0970586bfc0ad6e99 Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Thu, 22 May 2025 09:45:58 +0200 Subject: [PATCH 4/7] Added warnings to typed-protocols:test --- .../test/Network/TypedProtocol/ReqResp/Tests.hs | 3 +-- typed-protocols/typed-protocols.cabal | 12 ++++-------- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/typed-protocols/test/Network/TypedProtocol/ReqResp/Tests.hs b/typed-protocols/test/Network/TypedProtocol/ReqResp/Tests.hs index 6826e29..3916c69 100644 --- a/typed-protocols/test/Network/TypedProtocol/ReqResp/Tests.hs +++ b/typed-protocols/test/Network/TypedProtocol/ReqResp/Tests.hs @@ -21,7 +21,6 @@ import Control.Monad.Class.MonadAsync import Control.Monad.Class.MonadST import Control.Monad.Class.MonadSTM import Control.Monad.Class.MonadThrow -import Control.Monad.Class.MonadTimer.SI import Control.Monad.IOSim import Control.Monad.ST (runST) import Control.Tracer (nullTracer) @@ -193,7 +192,7 @@ prop_channel_ST f xs = prop_channelPipelined :: ( MonadLabelledSTM m, MonadAsync m, MonadCatch m - , MonadDelay m, MonadST m) + , MonadST m) => (Int -> Int -> (Int, Int)) -> [Int] -> m Bool prop_channelPipelined f xs = do diff --git a/typed-protocols/typed-protocols.cabal b/typed-protocols/typed-protocols.cabal index 3879840..e0604d6 100644 --- a/typed-protocols/typed-protocols.cabal +++ b/typed-protocols/typed-protocols.cabal @@ -142,6 +142,7 @@ library examples LambdaCase test-suite test + import: warnings type: exitcode-stdio-1.0 main-is: Main.hs hs-source-dirs: test @@ -153,19 +154,14 @@ test-suite test build-depends: base , bytestring , contra-tracer - , typed-protocols:{typed-protocols,cborg,examples} - , io-classes:{io-classes,si-timers} + , typed-protocols:{typed-protocols,examples} + , io-classes:io-classes , io-sim , QuickCheck , tasty , tasty-quickcheck - if !os(windows) build-depends: directory , network , unix - - ghc-options: -rtsopts - -Wall - -Wno-unticked-promoted-constructors - -Wno-orphans + ghc-options: -rtsopts From f3e080c1ad44c65934ed649f08199d552d34a704 Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Thu, 22 May 2025 10:41:14 +0200 Subject: [PATCH 5/7] typed-protocols description: include link to haddocks --- typed-protocols/typed-protocols.cabal | 1 + 1 file changed, 1 insertion(+) diff --git a/typed-protocols/typed-protocols.cabal b/typed-protocols/typed-protocols.cabal index e0604d6..058bd71 100644 --- a/typed-protocols/typed-protocols.cabal +++ b/typed-protocols/typed-protocols.cabal @@ -3,6 +3,7 @@ name: typed-protocols version: 1.0.0.0 synopsis: A framework for strongly typed protocols description: A robust session type framework which supports protocol pipelining. + Haddocks are published [here](https://input-output-hk.github.io/typed-protocols/) license: Apache-2.0 license-files: LICENSE From 264717fb3b7026af0133a0e1d17e59c0cd3e82fa Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Thu, 22 May 2025 11:17:33 +0200 Subject: [PATCH 6/7] cabal file: added common GHC setup --- typed-protocols/typed-protocols.cabal | 47 ++++++++++++--------------- 1 file changed, 21 insertions(+), 26 deletions(-) diff --git a/typed-protocols/typed-protocols.cabal b/typed-protocols/typed-protocols.cabal index 058bd71..5951b40 100644 --- a/typed-protocols/typed-protocols.cabal +++ b/typed-protocols/typed-protocols.cabal @@ -17,19 +17,24 @@ tested-with: GHC == {9.6, 9.8, 9.10, 9.12} extra-doc-files: CHANGELOG.md README.md -common warnings - ghc-options: -Wall - -Wno-unticked-promoted-constructors - -Wcompat - -Wincomplete-uni-patterns - -Wincomplete-record-updates - -Wpartial-fields - -Widentities - -Wredundant-constraints - -Wunused-packages +-- Minimal GHC setup, additional extensions are enabled per package (e.g. +-- pervasive type level extensions in the code base like `GADTs` or +-- `DataKinds`, etc), or per module (e.g. `CPP` or other more exotic ones). +common GHC + default-language: GHC2021 + default-extensions: LambdaCase + ghc-options: -Wall + -Wno-unticked-promoted-constructors + -Wcompat + -Wincomplete-uni-patterns + -Wincomplete-record-updates + -Wpartial-fields + -Widentities + -Wredundant-constraints + -Wunused-packages library - import: warnings + import: GHC exposed-modules: Network.TypedProtocol , Network.TypedProtocol.Core , Network.TypedProtocol.Peer @@ -43,13 +48,11 @@ library io-classes:io-classes ^>= 1.8, singletons ^>= 3.0 hs-source-dirs: src - default-language: GHC2021 default-extensions: DataKinds GADTs - LambdaCase library cborg - import: warnings + import: GHC visibility: public exposed-modules: Network.TypedProtocol.Codec.CBOR build-depends: base, @@ -59,11 +62,9 @@ library cborg io-classes:io-classes, typed-protocols:typed-protocols hs-source-dirs: cborg - default-language: GHC2021 - default-extensions: LambdaCase library stateful - import: warnings + import: GHC visibility: public exposed-modules: Network.TypedProtocol.Stateful.Peer , Network.TypedProtocol.Stateful.Peer.Client @@ -76,13 +77,12 @@ library stateful io-classes:io-classes, typed-protocols:typed-protocols hs-source-dirs: stateful - default-language: GHC2021 default-extensions: DataKinds GADTs ImportQualifiedPost library stateful-cborg - import: warnings + import: GHC visibility: public exposed-modules: Network.TypedProtocol.Stateful.Codec.CBOR @@ -93,11 +93,10 @@ library stateful-cborg io-classes:io-classes, typed-protocols:{typed-protocols,cborg,stateful} hs-source-dirs: stateful-cborg - default-language: GHC2021 default-extensions: ImportQualifiedPost library examples - import: warnings + import: GHC visibility: public exposed-modules: Network.TypedProtocol.Channel , Network.TypedProtocol.Driver.Simple @@ -137,19 +136,15 @@ library examples if !os(windows) build-depends: network hs-source-dirs: examples - default-language: GHC2021 default-extensions: DataKinds GADTs - LambdaCase test-suite test - import: warnings + import: GHC type: exitcode-stdio-1.0 main-is: Main.hs hs-source-dirs: test - default-language: GHC2021 default-extensions: GADTs - LambdaCase other-modules: Network.TypedProtocol.PingPong.Tests , Network.TypedProtocol.ReqResp.Tests build-depends: base From 0a31c02b61241afb5ff79ea1cbdce57c6c358bb2 Mon Sep 17 00:00:00 2001 From: Marcin Szamotulski Date: Tue, 17 Jun 2025 11:49:22 +0200 Subject: [PATCH 7/7] AnyMessage: show instance Show instance which shows parens if needed. --- typed-protocols/src/Network/TypedProtocol/Codec.hs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/typed-protocols/src/Network/TypedProtocol/Codec.hs b/typed-protocols/src/Network/TypedProtocol/Codec.hs index 8c259ee..7fdf440 100644 --- a/typed-protocols/src/Network/TypedProtocol/Codec.hs +++ b/typed-protocols/src/Network/TypedProtocol/Codec.hs @@ -322,8 +322,10 @@ data AnyMessage ps where -- requires @UndecidableInstances@ and @QuantifiedConstraints@. instance (forall (st :: ps) (st' :: ps). Show (Message ps st st')) => Show (AnyMessage ps) where - show (AnyMessage (msg :: Message ps st st')) = - "AnyMessage " ++ show msg + showsPrec d (AnyMessage (msg :: Message ps st st')) = + showParen (d > app_prec) (showString "AnyMessage " . showsPrec (app_prec + 1) msg) + where + app_prec = 10 -- | A convenient pattern synonym which unwrap 'AnyMessage' giving both the