Skip to content

Commit 3f3aa2e

Browse files
committed
format the whole codebase with ormolu/cabal format
1 parent 9b27ec8 commit 3f3aa2e

Some content is hidden

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

98 files changed

+6911
-5990
lines changed

.github/workflows/ci.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
- name: Build Nix dependencies
5454
run: nix-shell --pure --run "echo '=== Nix dependencies installed ==='"
5555
- name: check formatting
56-
run: nix-shell --pure --run 'stack build ormolu && { stack exec ormolu -- -m check $(find . -type f -name "*.hs-boot" -o -name "*.hs") || true; }'
56+
run: nix-shell --pure --run 'stack build ormolu && stack exec ormolu -- -m check $(find . -type f -name "*.hs-boot" -o -name "*.hs")'
5757

5858
stack-build:
5959
name: stack build

Setup.hs

+1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
import Distribution.Simple
2+
23
main = defaultMain

bench/Data/Mutable/Array.hs

+80-77
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
{-# LANGUAGE BangPatterns #-}
2-
{-# LANGUAGE TypeApplications #-}
32
{-# LANGUAGE LinearTypes #-}
43
{-# LANGUAGE NumericUnderscores #-}
4+
{-# LANGUAGE TypeApplications #-}
55

66
module Data.Mutable.Array (benchmarks) where
77

8-
import Gauge
9-
import Data.Function ((&))
10-
import qualified Data.Unrestricted.Linear as Linear
11-
import qualified Prelude.Linear as Linear
128
import Control.DeepSeq (rnf)
13-
149
import qualified Data.Array.Mutable.Linear as Array.Linear
10+
import Data.Function ((&))
11+
import qualified Data.Unrestricted.Linear as Linear
1512
import qualified Data.Vector
13+
import Gauge
14+
import qualified Prelude.Linear as Linear
1615

1716
dontFuse :: a -> a
1817
dontFuse a = a
@@ -22,99 +21,103 @@ arr_size :: Int
2221
arr_size = 10_000_000
2322

2423
benchmarks :: Benchmark
25-
benchmarks = bgroup "arrays"
26-
[ runImpls "toList" bToList arr_size
27-
, runImpls "map" bMap arr_size
28-
, runImpls "reads" bReads arr_size
29-
]
24+
benchmarks =
25+
bgroup
26+
"arrays"
27+
[ runImpls "toList" bToList arr_size,
28+
runImpls "map" bMap arr_size,
29+
runImpls "reads" bReads arr_size
30+
]
3031

3132
--------------------------------------------------------------------------------
3233

33-
data Impls =
34-
Impls
35-
(Array.Linear.Array Int %1-> ())
36-
(Data.Vector.Vector Int -> ())
34+
data Impls
35+
= Impls
36+
(Array.Linear.Array Int %1 -> ())
37+
(Data.Vector.Vector Int -> ())
3738

3839
runImpls :: String -> Impls -> Int -> Benchmark
3940
runImpls name impls size =
4041
let Impls linear dataVector = impls
41-
in bgroup name
42-
[ bench "Data.Array.Mutable.Linear" $ whnf (runLinear linear) size
43-
, bench "Data.Vector" $ whnf (runDataVector dataVector) size
44-
]
45-
where
46-
runLinear :: (Array.Linear.Array Int %1-> ()) -> Int -> ()
47-
runLinear cb sz = Linear.unur (Array.Linear.alloc sz 0 (\a -> Linear.move (cb a)))
42+
in bgroup
43+
name
44+
[ bench "Data.Array.Mutable.Linear" $ whnf (runLinear linear) size,
45+
bench "Data.Vector" $ whnf (runDataVector dataVector) size
46+
]
47+
where
48+
runLinear :: (Array.Linear.Array Int %1 -> ()) -> Int -> ()
49+
runLinear cb sz = Linear.unur (Array.Linear.alloc sz 0 (\a -> Linear.move (cb a)))
4850

49-
runDataVector :: (Data.Vector.Vector Int -> ()) -> Int -> ()
50-
runDataVector cb sz = cb (Data.Vector.replicate sz 0)
51+
runDataVector :: (Data.Vector.Vector Int -> ()) -> Int -> ()
52+
runDataVector cb sz = cb (Data.Vector.replicate sz 0)
5153

5254
--------------------------------------------------------------------------------
5355

5456
bToList :: Impls
5557
bToList = Impls linear dataVector
5658
where
57-
linear :: Array.Linear.Array Int %1-> ()
58-
linear hm =
59-
hm
60-
Linear.& Array.Linear.toList
61-
Linear.& Linear.lift rnf
62-
Linear.& Linear.unur
63-
64-
dataVector :: Data.Vector.Vector Int -> ()
65-
dataVector hm =
66-
hm
67-
& Data.Vector.toList
68-
& rnf
59+
linear :: Array.Linear.Array Int %1 -> ()
60+
linear hm =
61+
hm
62+
Linear.& Array.Linear.toList
63+
Linear.& Linear.lift rnf
64+
Linear.& Linear.unur
65+
66+
dataVector :: Data.Vector.Vector Int -> ()
67+
dataVector hm =
68+
hm
69+
& Data.Vector.toList
70+
& rnf
6971
{-# NOINLINE bToList #-}
7072

7173
bMap :: Impls
7274
bMap = Impls linear dataVector
7375
where
74-
linear :: Array.Linear.Array Int %1-> ()
75-
linear hm =
76-
hm
77-
Linear.& Array.Linear.map (+1)
78-
Linear.& Array.Linear.unsafeGet 5
79-
Linear.& (`Linear.lseq` ())
80-
81-
dataVector :: Data.Vector.Vector Int -> ()
82-
dataVector hm =
83-
hm
84-
& Data.Vector.map (+1)
85-
& dontFuse -- This looks like cheating, I know. But we're trying to measure
86-
-- the speed of `map`, and without this, `vector` fuses the `map`
87-
-- with the subsequent `index` to skip writing to the rest of the
88-
-- vector.
89-
& (`Data.Vector.unsafeIndex` 5)
90-
& (`seq` ())
76+
linear :: Array.Linear.Array Int %1 -> ()
77+
linear hm =
78+
hm
79+
Linear.& Array.Linear.map (+ 1)
80+
Linear.& Array.Linear.unsafeGet 5
81+
Linear.& (`Linear.lseq` ())
82+
83+
dataVector :: Data.Vector.Vector Int -> ()
84+
dataVector hm =
85+
hm
86+
& Data.Vector.map (+ 1)
87+
& dontFuse -- This looks like cheating, I know. But we're trying to measure
88+
-- the speed of `map`, and without this, `vector` fuses the `map`
89+
-- with the subsequent `index` to skip writing to the rest of the
90+
-- vector.
91+
& (`Data.Vector.unsafeIndex` 5)
92+
& (`seq` ())
9193
{-# NOINLINE bMap #-}
9294

9395
bReads :: Impls
9496
bReads = Impls linear dataVector
9597
where
96-
linear :: Array.Linear.Array Int %1-> ()
97-
linear hm =
98-
hm
99-
Linear.& Array.Linear.size
100-
Linear.& \(Linear.Ur sz, arr) -> arr
101-
Linear.& go 0 sz
102-
where
103-
go :: Int -> Int -> Array.Linear.Array Int %1-> ()
104-
go start end arr
105-
| start < end =
106-
Array.Linear.unsafeGet start arr
107-
Linear.& \(Linear.Ur i, arr') -> i `Linear.seq` go (start + 1) end arr'
108-
| otherwise = arr `Linear.lseq` ()
109-
110-
dataVector :: Data.Vector.Vector Int -> ()
111-
dataVector v =
112-
let sz = Data.Vector.length v
113-
in go 0 sz
114-
where
115-
go :: Int -> Int -> ()
116-
go start end
117-
| start < end =
118-
(v Data.Vector.! start) `seq` go (start + 1) end
119-
| otherwise = ()
98+
linear :: Array.Linear.Array Int %1 -> ()
99+
linear hm =
100+
hm
101+
Linear.& Array.Linear.size
102+
Linear.& \(Linear.Ur sz, arr) ->
103+
arr
104+
Linear.& go 0 sz
105+
where
106+
go :: Int -> Int -> Array.Linear.Array Int %1 -> ()
107+
go start end arr
108+
| start < end =
109+
Array.Linear.unsafeGet start arr
110+
Linear.& \(Linear.Ur i, arr') -> i `Linear.seq` go (start + 1) end arr'
111+
| otherwise = arr `Linear.lseq` ()
112+
113+
dataVector :: Data.Vector.Vector Int -> ()
114+
dataVector v =
115+
let sz = Data.Vector.length v
116+
in go 0 sz
117+
where
118+
go :: Int -> Int -> ()
119+
go start end
120+
| start < end =
121+
(v Data.Vector.! start) `seq` go (start + 1) end
122+
| otherwise = ()
120123
{-# NOINLINE bReads #-}

0 commit comments

Comments
 (0)