Skip to content
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

Remove unsafe perform io #130

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
ac17dd1
Remove uses of unsafePerformIO
exarkun Jan 13, 2023
9ffd704
Add an aggressive property test for encoding sanely
exarkun Jan 13, 2023
989f90f
Merge remote-tracking branch 'origin/master' into remove-unsafePerformIO
exarkun Jan 18, 2023
e452854
Adapt to switch to quickcheck-instances
exarkun Jan 18, 2023
eb47bfc
Adapt to enFEC and deFEC being in IO
exarkun Jan 18, 2023
ec5e1dd
let fourmolu do its thing
exarkun Jan 18, 2023
768fe4e
bump version to reflect incompatible change
exarkun Jan 18, 2023
390bfad
prefer where over let
exarkun Sep 13, 2023
b515dbf
remove redundant parens
exarkun Sep 13, 2023
3820caa
prefer where over let
exarkun Sep 13, 2023
1fa8a58
more frequent failure reproduction
exarkun Sep 13, 2023
e51db10
Merge from master
adrianmay Mar 17, 2025
31bbbaa
Merge from master
adrianmay Mar 17, 2025
28cc766
Merge from master
adrianmay Mar 17, 2025
3527617
Merge commit '14fc79b' into slowmerge
adrianmay Mar 17, 2025
923f11a
Merge commit '6de0374' into slowmerge
adrianmay Mar 17, 2025
a23f2a7
Fix errors and warnings
adrianmay Mar 17, 2025
882c5c9
Bump major version
adrianmay Mar 17, 2025
519b64b
Use a better lock
adrianmay Mar 18, 2025
bf0e50d
Reduce cabal version contraints to hackage rules
adrianmay Mar 18, 2025
2e9f5ac
Oops: reinstate uninitialised check
adrianmay Mar 18, 2025
7c8629a
Merge remote-tracking branch 'tahoe/127.pypi-trusted-publishing' into…
adrianmay Mar 19, 2025
8a4d067
Add workflow-dispatch trigger so I can manually start CI
adrianmay Mar 19, 2025
25ee0d9
Typo
adrianmay Mar 19, 2025
dd99b5f
Another typo
adrianmay Mar 19, 2025
31507fb
Merge branch 'master' into remove-unsafePerformIO
adrianmay Mar 20, 2025
0e782f7
Undoing workflow_dispatch cos it didn't do anything
adrianmay Mar 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog for fec

## 1.0 0 (2025-03-17)

* Haskell wrapper returns IO throughout to avoid unsafePerformIO

## 0.2.0 (2023-10-06)

* Application code must now execute the `Codec.FEC.initialize` action at least
Expand Down
18 changes: 7 additions & 11 deletions benchmark-zfec/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module Main where

import Codec.FEC (FECParams (paramK, paramN), decode, encode, fec, initialize)
import Control.Monad (replicateM)
import Criterion.Main (Benchmark, bench, bgroup, defaultMain, env, nf)
import Criterion.Main (Benchmark, bench, bgroup, defaultMain, env, nfAppIO)
import Data.Bifunctor (bimap)
import qualified Data.ByteString as B
import Data.List (unfoldr)
Expand All @@ -13,15 +13,11 @@ main =
defaultMain
-- Run against some somewhat arbitrarily chosen configurations. Notably,
-- though, 94/100 matches the numbers recorded in the readme.
[ env (setupFEC 2 3) makeFECBenchmarks
, env (setupFEC 16 31) makeFECBenchmarks
, env (setupFEC 94 100) makeFECBenchmarks
[ env (fec 2 3) makeFECBenchmarks
, env (fec 16 31) makeFECBenchmarks
, env (fec 94 100) makeFECBenchmarks
]
where
setupFEC :: Int -> Int -> IO FECParams
setupFEC k n = do
initialize
pure (fec k n)

makeFECBenchmarks = fecGroup [10 ^ 6]

Expand Down Expand Up @@ -53,20 +49,20 @@ main =
-- result is serialize use all of the bytes (eg, to write them to a
-- file or send them over the network) so they will certainly all be
-- used.
nf (uncurry encode) (params, blocks)
nfAppIO (uncurry encode) (params, blocks)

benchmarkPrimaryDecode params blocks =
bench ("decode [0..] blockSize=" <> showWithUnit (B.length $ head blocks)) $
-- normal form here for the same reason as in benchmarkEncode.
-- assign block numbers to use only primary blocks
nf (uncurry decode) (params, (zip [0 ..] blocks))
nfAppIO (uncurry decode) (params, (zip [0 ..] blocks))

benchmarkSecondaryDecode params blocks =
bench ("decode [" <> show n <> "..] blockSize=" <> showWithUnit (B.length $ head blocks)) $
-- normal form here for the same reason as in benchmarkEncode.
-- assign block numbers to use as many non-primary blocks as
-- possible
nf (uncurry decode) (params, (zip [n ..] blocks))
nfAppIO (uncurry decode) (params, (zip [n ..] blocks))
where
n = paramN params - paramK params

Expand Down
33 changes: 17 additions & 16 deletions fec.cabal
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cabal-version: 3.0
name: fec
version: 0.2.0
version: 1.0.0
license: GPL-2.0-or-later
license-file: README.rst
author: Adam Langley <agl@imperialviolet.org>
Expand Down Expand Up @@ -31,10 +31,11 @@ extra-doc-files: ChangeLog.md

library
build-depends:
, base >=4.9 && <5
, bytestring >=0.10 && <0.13
, deepseq >=1.4 && <1.6
, extra >=1.7 && <1.8
, base <5
, bytestring <0.13
, deepseq <1.7
, extra <2
, global-lock <1

exposed-modules: Codec.FEC
default-language: Haskell2010
Expand All @@ -49,11 +50,11 @@ executable benchmark-zfec
main-is: Main.hs
ghc-options: -threaded
build-depends:
, base >=4.9 && <5
, bytestring >=0.10 && <0.13
, criterion >=1.1 && <1.7
, base <5
, bytestring <0.13
, criterion <1.7
, fec
, random >=1.1 && <1.3
, random <2

hs-source-dirs: benchmark-zfec
default-language: Haskell2010
Expand All @@ -65,13 +66,13 @@ test-suite tests
hs-source-dirs: haskell/test
ghc-options: -Wall -threaded -rtsopts -with-rtsopts=-N
build-depends:
, base >=4.9 && <5
, bytestring >=0.10 && <0.13
, data-serializer >=0.3 && <0.4
, base <5
, bytestring <0.13
, data-serializer <1
, fec
, hspec >=2.7 && <2.12
, QuickCheck >=2.14 && <2.15
, quickcheck-instances >=0.3 && <0.4
, random >=1.1 && <1.3
, hspec <3
, QuickCheck <2.16
, quickcheck-instances <1
, random <2

default-language: Haskell2010
Loading
Loading