Skip to content

Commit 9bbca2e

Browse files
committed
Include strict-stm, strict-mvar and si-timers into io-classes
`strict-mvar:test` is left in `test-strict-mvar` as it introduces a cycle between `io-sim` and `io-classes` which cabal cannot resolve.
1 parent 29daad4 commit 9bbca2e

File tree

43 files changed

+204
-747
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+204
-747
lines changed

.github/workflows/cabal.project.local

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,6 @@ package io-classes
66
ghc-options: -Werror
77
flags: +asserts
88

9-
package io-classes-mtl
10-
ghc-options: -Werror
11-
12-
package strict-mvar
13-
ghc-options: -Werror
14-
15-
package strict-stm
16-
ghc-options: -Werror
17-
flags: +asserts
18-
199
package io-sim
2010
ghc-options: -Werror
2111
flags: +asserts
22-
23-
package si-timers
24-
ghc-options: -Werror
25-
flags: +asserts

.github/workflows/haskell.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ jobs:
8585

8686
- name: Build dependencies
8787
run: |
88-
cabal build --only-dependencies all
88+
cabal build --only-dependencies io-classes
89+
cabal build --only-dependencies io-sim
90+
cabal build --only-dependencies test-strict-mvar
8991
9092
- uses: actions/cache/save@v4
9193
name: "Save cabal store"
@@ -103,8 +105,8 @@ jobs:
103105
- name: io-sim [test]
104106
run: cabal run io-sim:test
105107

106-
- name: si-timers [test]
107-
run: cabal run si-timers:test
108+
- name: io-classes:si-timers [test]
109+
run: cabal run io-classes:test-si-timers
108110

109-
- name: strict-mvar [test]
110-
run: cabal run strict-mvar:test
111+
- name: test-strict-mvar [test]
112+
run: cabal run test-strict-mvar

README.md

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,23 @@
1818
* tracing committed changes to `TVar`, `TMVar`s, etc.
1919
* labeling of threads, `TVar`'s, etc.
2020

21-
[`io-classes`] provides an interface, which allows writing code that can be run
22-
in both real `IO` and [`IOSim`]. It is a drop-in replacement for `IO`, and
23-
supports interfaces commonly known from `base`, `exceptions`, `stm`, `async`,
24-
or `time` packages.
25-
26-
One of the principles of `io-classes` was to stay as close to `IO` as possible,
27-
thus most of the `IO` instances are directly referring to `base` or `async`
28-
API. However, we made some distinctions, which are reported below.
29-
30-
[`io-classes`] supports a novel hierarchy for error-handling monads as well as
31-
more familiar `exception` style. The new hierarchy provides `bracket` and
32-
`finally` functions in the `MonadThrow` class, while `catch` style operators
33-
are provided by a super-class `MonadCatch`. Both `bracket` and `finally` are
34-
the most common functions used to write code with robust exception handling,
35-
exposing them through the more basic `MonadThrow` class informs the reader
36-
/ reviewer that no tricky error handling is done in that section of the code
37-
base.
21+
[`io-classes:io-classes`] provides an interface, which allows writing code that
22+
can be run in both real `IO` and [`IOSim`]. It is a drop-in replacement for
23+
`IO`, and supports interfaces commonly known from `base`, `exceptions`, `stm`,
24+
`async`, or `time` packages.
25+
26+
One of the principles of `io-classes:io-classes` was to stay as close to `IO`
27+
as possible, thus most of the `IO` instances are directly referring to `base`
28+
or `async` API. However, we made some distinctions, which are reported below.
29+
30+
[`io-classes:io-classes`] supports a novel hierarchy for error-handling monads
31+
as well as more familiar `exception` style. The new hierarchy provides
32+
`bracket` and `finally` functions in the `MonadThrow` class, while `catch`
33+
style operators are provided by a super-class `MonadCatch`. Both `bracket` and
34+
`finally` are the most common functions used to write code with robust
35+
exception handling, exposing them through the more basic `MonadThrow` class
36+
informs the reader / reviewer that no tricky error handling is done in that
37+
section of the code base.
3838

3939
[`IOSim`] exposes a detailed trace, which can be enhanced by labeling threads, or
4040
mutable variables, tracing `Dynamic` values (which can be recovered from the
@@ -58,16 +58,18 @@ a complex, highly concurrent, distributed system
5858
* [`io-sim`]: provides two simulator interpreters: [`IOSim`] and
5959
`IOSimPOR` - an enhanced [`IOSim`] version with schedule discovery
6060
capabilities.
61-
* [`io-classes`]: class bases interface, which allows to to abstract over the
61+
* [`io-classes:io-classes`]: class bases interface, which allows to to abstract over the
6262
monad
63-
* [`strict-stm`]: strict STM operations
64-
* [`si-timers`]: non-standard timers API
63+
* [`io-classes:strict-stm`]: strict STM operations
64+
* [`io-classes:si-timers`]: non-standard timers API
6565

6666
### Issues
6767

6868
New issues should be reported in [this][io-sim-issues] repository.
6969

70-
[`io-classes`]: https://hackage.haskell.org/package/io-classes
70+
[`io-classes:io-classes`]: https://hackage.haskell.org/package/io-classes
71+
[`io-classes:strict-stm`]: https://hackage.haskell.org/package/io-classes
72+
[`io-classes:si-timers`]: https://hackage.haskell.org/package/io-classes
7173
[`io-sim`]: https://hackage.haskell.org/package/io-sim
7274

7375
[contra-tracer]: https://hackage.haskell.org/package/contra-tracer

cabal.project

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,7 @@ index-state: hackage.haskell.org 2024-05-17T03:42:00Z
33
packages: ./io-sim
44
./io-classes
55
./io-classes-mtl
6-
./strict-mvar
7-
./strict-stm
8-
./si-timers
6+
./test-strict-mvar
97

108
package io-sim
119
flags: +asserts

io-classes-mtl/io-classes-mtl.cabal

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ library
4444
array,
4545
mtl,
4646

47-
io-classes ^>=1.5,
48-
si-timers,
47+
io-classes:{io-classes,si-timers} ^>= 1.5
4948

5049

5150
hs-source-dirs: src

io-classes/CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Revsion history of io-classes
22

3+
### Next version
4+
5+
### Breaking changes
6+
7+
* `strict-stm`, `strict-mvar` and `si-timers` are now public sublibraries of `io-classes` package.
8+
39
## 1.5.0.0
410

511
### Breaking changes
@@ -12,6 +18,19 @@
1218

1319
* Add `writeTMVar` to `MonadSTM`.
1420

21+
* `strict-stm`, `strict-mvar` and `si-timers` were moved to `io-classes` as
22+
**public sublibraries**. You can import then in `*.cabal` files with the
23+
following syntax `io-classes:strict-stm` or `io-classes:{strict-stm,
24+
si-timers}`. See the _Multiple public libraries_ subsection of [_Internal
25+
Libraries_][sublibs] section in the `cabal` documentation.
26+
27+
Note: some time in the future we will deprecate `Hackage` packages
28+
`strict-stm`, `strict-mvar` and `si-timers`. If one will want to use the
29+
namespace for a non `io-classes` related packages please contact the
30+
maintainer.
31+
32+
[sublibs]: https://cabal.readthedocs.io/en/stable/cabal-package.html#sublibs
33+
1534
## 1.4.1.0
1635

1736
### Non-breaking changes

io-classes/README.md

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,20 @@ constraints in mind:
1010
as timer API;
1111
* provide zero-cost abstractions.
1212

13-
We provide also non-standard extensions of this API:
13+
We provide also non-standard extensions of this API in **sublibraries**:
1414

15-
* [`strict-stm`]: strict `TVar`'s, and other mutable `STM` variables, with
15+
* [`io-classes:strict-stm`]: strict `TVar`'s, and other mutable `STM` variables, with
1616
support of the [`nothunks`] library;
17-
* [`si-timers`]: timers api:
17+
* [`io-classes:strict-mvar`]: strict `MVar`s
18+
* [`io-classes:si-timers`]: timers api:
1819
- 32-bit safe API using `DiffTime` measured in seconds (rather than time in
1920
microseconds represented as `Int` as in `base`)
2021
- cancellable timeouts.
22+
* [`io-classes-mtl`]: MTL instances.
2123

22-
[`strict-stm`] and [`nothunks`] were successfully used in a large code base to
23-
eliminate space leaks and keep that property over long development cycles.
24+
[`io-classes:strict-stm`] and [`nothunks`] were successfully used in a large
25+
code base to eliminate space leaks and keep that property over long development
26+
cycles.
2427

2528
## Exception Class Hierarchy
2629

@@ -61,15 +64,14 @@ delays & timers.
6164
## Software Transactional Memory API
6265

6366
We provide two interfaces to `stm` API: lazy, included in `io-classes`; and
64-
strict one provided by [`strict-stm`].
65-
67+
strict one provided by [`io-classes:strict-stm`].
6668

6769
## Threads API
6870

6971
We draw a line between `base` API and `async` API. The former is provided by
7072
[MonadFork](https://hackage.haskell.org/package/io-classes/docs/Control-Monad-Class-MonadFork.html#t:MonadFork)
7173
the latter by
72-
[MonadAsync](https://hackage.haskell.org/package/io-classes/docs/Control-Monad-Class-MonadFork.html#t:MonadAsync).
74+
[MonadAsync](https://hackage.haskell.org/package/io-classes/docs/Control-Monad-Class-MonadAsync.html#t:MonadAsync).
7375
Both are shallow abstractions around APIs exposed by the `base` and `async`
7476
packages.
7577

@@ -140,17 +142,21 @@ its limitations and so there might be some rough edges. PRs are welcomed,
140142
[`base`]: https://hackage.haskell.org/package/base
141143
[`exceptions`]: https://hackage.haskell.org/package/exceptions
142144
[`io-sim`]: https://hackage.haskell.org/package/io-sim
143-
[`si-timers`]: https://hackage.haskell.org/package/si-timers
145+
[`io-classes-mtl`]: https://hackage.haskell.org/package/io-classes-mtl
144146
[`stm`]: https://hackage.haskell.org/package/stm
145-
[`strict-stm`]: https://hackage.haskell.org/package/strict-stm
146-
[`threadDelay`]: https://hackage.haskell.org/package/io-classes/docs/Control-Monad-Class-MonadTimer.html#v:threadDela
147+
[`threadDelay`]: https://hackage.haskell.org/package/io-classes/docs/Control-Monad-Class-MonadTimer.html#v:threadDelay
147148
[`time`]: https://hackage.haskell.org/package/time
148149
[contributing]: https://www.github.com/input-output-hk/io-sim/tree/master/CONTRIBUTING.md
149150
[`nothunks`]: https://hackage.haskell.org/package/nothunks
150151
[labelThread-base]: https://hackage.haskell.org/package/base-4.17.0.0/docs/GHC-Conc-Sync.html#v:labelThread
151152
[io-deadlock]: https://hackage.haskell.org/package/base-4.19.0.0/docs/Control-Exception.html#t:Deadlock
152153

153-
[MonadEventlog]: https://hackage.haskell.org/package/io-sim-classes/docs/Control-Monad-Class-MonadEventlog.html#t:MonadEventlog
154+
<!-- these links need to be updated once haskell/hackage-server#1218 is done --!>
155+
[`io-classes:si-timers`]: https://hackage.haskell.org/package/io-classes
156+
[`io-classes:strict-stm`]: https://hackage.haskell.org/package/io-classes
157+
[`io-classes:strict-mvar`]: https://hackage.haskell.org/package/io-classes
158+
159+
[MonadEventlog]: https://hackage.haskell.org/package/io-classes/docs/Control-Monad-Class-MonadEventlog.html#t:MonadEventlog
154160
[Debug.Trace]: https://hackage.haskell.org/package/base/docs/Debug-Trace.html
155161
[MonadST]: https://hackage.haskell.org/package/io-classes/docs/Control-Monad-Class-MonadST.html#t:MonadST
156162
[MonadSay]: https://hackage.haskell.org/package/io-classes/docs/Control-Monad-Class-MonadSay.html#t:MonadSay

io-classes/io-classes.cabal

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ author: Alexander Vieth, Duncan Coutts, Marcin Szamotulski, Thomas
1717
maintainer: Duncan Coutts [email protected], Marcin Szamotulski [email protected]
1818
category: Control
1919
build-type: Simple
20-
extra-doc-files: CHANGELOG.md README.md
20+
extra-doc-files: CHANGELOG.md README.md strict-stm/README.md strict-mvar/README.md
2121
bug-reports: https://github.com/input-output-hk/io-sim/issues
2222
tested-with: GHC == { 8.10, 9.2, 9.4, 9.6, 9.8, 9.10 }
2323

@@ -106,3 +106,98 @@ library
106106

107107
if flag(asserts)
108108
ghc-options: -fno-ignore-asserts
109+
110+
library strict-stm
111+
visibility: public
112+
hs-source-dirs: strict-stm
113+
114+
exposed-modules: Control.Concurrent.Class.MonadSTM.Strict
115+
Control.Concurrent.Class.MonadSTM.Strict.TArray
116+
Control.Concurrent.Class.MonadSTM.Strict.TBQueue
117+
Control.Concurrent.Class.MonadSTM.Strict.TChan
118+
Control.Concurrent.Class.MonadSTM.Strict.TMVar
119+
Control.Concurrent.Class.MonadSTM.Strict.TQueue
120+
Control.Concurrent.Class.MonadSTM.Strict.TVar
121+
reexported-modules: Control.Concurrent.Class.MonadSTM.TSem as Control.Concurrent.Class.MonadSTM.Strict.TSem
122+
default-language: Haskell2010
123+
default-extensions: ImportQualifiedPost
124+
build-depends: base >= 4.9 && <4.21,
125+
array,
126+
stm >= 2.5 && <2.6,
127+
128+
io-classes:io-classes,
129+
ghc-options: -Wall
130+
-Wno-unticked-promoted-constructors
131+
-Wcompat
132+
-Wincomplete-uni-patterns
133+
-Wincomplete-record-updates
134+
-Wpartial-fields
135+
-Widentities
136+
137+
if flag(asserts)
138+
ghc-options: -fno-ignore-asserts
139+
140+
library strict-mvar
141+
visibility: public
142+
hs-source-dirs: strict-mvar/src
143+
144+
exposed-modules: Control.Concurrent.Class.MonadMVar.Strict
145+
default-language: Haskell2010
146+
default-extensions: ImportQualifiedPost
147+
build-depends: base >= 4.9 && <4.21,
148+
io-classes:io-classes,
149+
ghc-options: -Wall
150+
-Wno-unticked-promoted-constructors
151+
-Wcompat
152+
-Wincomplete-uni-patterns
153+
-Wincomplete-record-updates
154+
-Wpartial-fields
155+
-Widentities
156+
157+
library si-timers
158+
import: warnings
159+
visibility: public
160+
hs-source-dirs: si-timers/src
161+
exposed-modules: Control.Monad.Class.MonadTime.SI
162+
Control.Monad.Class.MonadTimer.SI
163+
other-modules: Control.Monad.Class.MonadTimer.NonStandard
164+
default-language: Haskell2010
165+
default-extensions: ImportQualifiedPost
166+
other-extensions: BangPatterns,
167+
CPP,
168+
ConstraintKinds,
169+
DefaultSignatures,
170+
DeriveGeneric,
171+
NumericUnderscores,
172+
ScopedTypeVariables,
173+
TypeFamilies
174+
build-depends: base >=4.9 && <4.21,
175+
deepseq,
176+
mtl,
177+
nothunks,
178+
stm,
179+
time >=1.9.1 && <1.13,
180+
181+
io-classes:io-classes
182+
^>=1.5
183+
if flag(asserts)
184+
ghc-options: -fno-ignore-asserts
185+
186+
-- Since `io-sim` depends on `si-times` (`io-sim` depends on `Time`) some tests of
187+
-- are in `io-sim:test`: this is a good enough reason to pull `io-sim:test`
188+
-- into a seprate package.
189+
test-suite test-si-timers
190+
import: warnings
191+
type: exitcode-stdio-1.0
192+
hs-source-dirs: si-timers/test
193+
main-is: Main.hs
194+
other-modules: Test.MonadTimer
195+
default-language: Haskell2010
196+
default-extensions: ImportQualifiedPost
197+
build-depends: base,
198+
199+
QuickCheck,
200+
tasty,
201+
tasty-quickcheck,
202+
203+
si-timers

io-classes/si-timers/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# [SI] Timers
2+
3+
The `io-classes:si-timers` package provides delays & timeouts which are safe on
4+
32-bit systems; cancellable timeouts (see `registerDelayCancellable`);
5+
a refined interface for monotonic `Time`. `Time` is given with left monoid
6+
action of `DiffTime` (which encodes the notion of time differences). The
7+
`MonadMonotonicTime`, `MonadDelay` type classes & `MonadTimers` (type synonym)
8+
API provide a consistent interface for working with delays and timeouts.
9+
10+
`io-classes:si-timers` package also defined a low level `MonadTimout` type
11+
class. On system with a native timer manager (e.g. `Linux`, `MacOS`,
12+
`FreeBSD`), it's very efficient but for other platforms (e.g. `Windows`), it
13+
might not be the right API for low latency timeouts needed for example for low
14+
level networking code, because it relies on `GHC`'s `RTS` thread scheduling.
15+
16+
`io-classes:si-timers` are compatible with `io-sim`.
17+
18+
The `SI` comes from the [International System of Units][SI].
19+
20+
[SI]: https://www.wikiwand.com/en/International_System_of_Units
21+
[`io-sim`]: https://hackage.haskell.org/package/io-sim

0 commit comments

Comments
 (0)