Skip to content

Commit 8b62f3c

Browse files
doliogithub-actions[bot]
authored andcommitted
automatically run ormolu
1 parent 4b1515c commit 8b62f3c

File tree

9 files changed

+226
-204
lines changed

9 files changed

+226
-204
lines changed

parser-typechecker/src/Unison/Codebase/Runtime/Profile.hs

Lines changed: 56 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ module Unison.Codebase.Runtime.Profile
1111
aggregatePruned,
1212
fullProfile,
1313
miniProfile,
14-
foldedProfile
15-
) where
14+
foldedProfile,
15+
)
16+
where
1617

1718
import Data.Bifunctor (second)
1819
import Data.Functor.Identity (Identity (..))
@@ -21,9 +22,7 @@ import Data.Map.Strict qualified as M
2122
import Data.Set (Set)
2223
import Data.Set qualified as S
2324
import Data.String
24-
2525
import Numeric
26-
2726
import Unison.PrettyPrintEnv
2827
import Unison.Reference
2928
import Unison.Referent
@@ -43,7 +42,7 @@ newtype ProfTrie k a = ProfT (Map k (a, ProfTrie k a))
4342
data Profile k = Prof !Int !(ProfTrie k Int) !(Map k Reference)
4443

4544
-- Abstracts over the exact key type used in a profile.
46-
data SomeProfile = forall k. Ord k => SomeProf (Profile k)
45+
data SomeProfile = forall k. (Ord k) => SomeProf (Profile k)
4746

4847
data ProfileSpec = NoProf | MiniProf | FullProf String
4948
deriving (Eq, Ord, Show)
@@ -52,42 +51,42 @@ emptyProfile :: Profile k
5251
emptyProfile = Prof 0 (ProfT M.empty) M.empty
5352

5453
-- Creates a singleton profile trie from a path.
55-
singlePath :: Ord k => [k] -> (Int, ProfTrie k Int)
54+
singlePath :: (Ord k) => [k] -> (Int, ProfTrie k Int)
5655
singlePath [] = (1, ProfT M.empty)
57-
singlePath (i:is) = (0,) . ProfT $! M.singleton i (singlePath is)
56+
singlePath (i : is) = (0,) . ProfT $! M.singleton i (singlePath is)
5857

59-
addPath0 :: Ord k => [k] -> (Int, ProfTrie k Int) -> (Int, ProfTrie k Int)
60-
addPath0 [] (m, p) = (,p) $! m+1
61-
addPath0 (i:is) (m, ProfT p) = (m,) . ProfT $! M.alter f i p
58+
addPath0 :: (Ord k) => [k] -> (Int, ProfTrie k Int) -> (Int, ProfTrie k Int)
59+
addPath0 [] (m, p) = (,p) $! m + 1
60+
addPath0 (i : is) (m, ProfT p) = (m,) . ProfT $! M.alter f i p
6261
where
6362
f Nothing = Just $ singlePath is
6463
f (Just q) = Just $ addPath0 is q
6564

6665
-- Adds a path to a profile trie, incrementing the count for the given
6766
-- path.
68-
addPath :: Ord k => [k] -> ProfTrie k Int -> ProfTrie k Int
67+
addPath :: (Ord k) => [k] -> ProfTrie k Int -> ProfTrie k Int
6968
addPath [] p = p
70-
addPath (i:is) (ProfT m) = ProfT $ M.alter f i m
69+
addPath (i : is) (ProfT m) = ProfT $ M.alter f i m
7170
where
7271
f Nothing = Just $ singlePath is
7372
f (Just q) = Just $ addPath0 is q
7473

75-
data AggInfo k = Ag {
76-
-- inherited sample count
74+
data AggInfo k = Ag
75+
{ -- inherited sample count
7776
inherited :: Int,
7877
-- total sample for all occurrences of a key
7978
allOccs :: Map k Int
8079
}
8180

82-
instance Ord k => Semigroup (AggInfo k) where
81+
instance (Ord k) => Semigroup (AggInfo k) where
8382
Ag il al <> Ag ir ar =
8483
Ag (il + ir) (M.unionWith (+) al ar)
8584

86-
instance Ord k => Monoid (AggInfo k) where
85+
instance (Ord k) => Monoid (AggInfo k) where
8786
mempty = Ag 0 M.empty
8887

8988
aggregateWith ::
90-
Ord k =>
89+
(Ord k) =>
9190
(AggInfo k -> Int -> r) ->
9291
k ->
9392
(Int, ProfTrie k Int) ->
@@ -96,10 +95,10 @@ aggregateWith f k (m, ProfT t) =
9695
case M.traverseWithKey (aggregateWith f) t of
9796
(ag, t) -> (ag', (f ag' m, ProfT t))
9897
where
99-
ag' = ag <> Ag m (M.singleton k m)
98+
ag' = ag <> Ag m (M.singleton k m)
10099

101100
prune0 ::
102-
Ord k =>
101+
(Ord k) =>
103102
Set k ->
104103
k ->
105104
(a, ProfTrie k a) ->
@@ -110,22 +109,22 @@ prune0 keep k (a, ProfT sub) =
110109
| null sub, k `S.notMember` keep -> pure Nothing
111110
| otherwise -> pure $ Just (a, ProfT sub)
112111

113-
prune :: Ord k => Set k -> ProfTrie k a -> ProfTrie k a
112+
prune :: (Ord k) => Set k -> ProfTrie k a -> ProfTrie k a
114113
prune keep (ProfT m) = case M.traverseMaybeWithKey (prune0 keep) m of
115114
Identity sub -> ProfT sub
116115

117-
topN :: Ord k => Int -> Map k Int -> [(k, Int)]
116+
topN :: (Ord k) => Int -> Map k Int -> [(k, Int)]
118117
topN n0 = M.foldlWithKey (ins n0) []
119118
where
120119
ins 0 _ _ _ = []
121120
ins _ [] k i = [(k, i)]
122121
ins n pss@((k1, j) : ps) k0 i
123-
| i > j = (k0, i) : pop (n-1) pss
124-
| otherwise = (k1, j) : ins (n-1) ps k0 i
122+
| i > j = (k0, i) : pop (n - 1) pss
123+
| otherwise = (k1, j) : ins (n - 1) ps k0 i
125124

126125
pop 0 _ = []
127126
pop _ [] = []
128-
pop n (p:ps) = p : pop (n-1) ps
127+
pop n (p : ps) = p : pop (n - 1) ps
129128

130129
fraction :: Int -> Int -> Double
131130
fraction n d = fromIntegral n / fromIntegral d
@@ -141,15 +140,15 @@ topNum = 25
141140
-- cost fractions of the positions in the trie, and prunes it to the
142141
-- hottest spots.
143142
aggregatePruned ::
144-
Ord k => Int -> ProfTrie k Int -> ProfTrie k (Double, Double)
143+
(Ord k) => Int -> ProfTrie k Int -> ProfTrie k (Double, Double)
145144
aggregatePruned total (ProfT t) =
146145
case M.traverseWithKey (aggregateWith (fractions total)) t of
147146
(ag, t)
148147
| top <- topN topNum (allOccs ag) ->
149148
prune (S.fromList $ fst <$> top) $ ProfT t
150149

151150
aggregate ::
152-
Ord k =>
151+
(Ord k) =>
153152
Int ->
154153
ProfTrie k Int ->
155154
([(k, Double)], ProfTrie k (Double, Double))
@@ -163,12 +162,12 @@ aggregate total (ProfT t) =
163162
-- Folds over a profile trie. The mapping function receives a reversed
164163
-- path to the node, which can be used e.g. to see the node's key and to
165164
-- calculate the depth in the trie.
166-
foldMapTrie :: Monoid m => ((k,[k]) -> v -> m) -> ProfTrie k v -> m
165+
foldMapTrie :: (Monoid m) => ((k, [k]) -> v -> m) -> ProfTrie k v -> m
167166
foldMapTrie f = descend []
168167
where
169168
descend ks (ProfT m) =
170169
M.foldMapWithKey
171-
(\k (v, sub) -> f (k,ks) v <> descend (k:ks) sub)
170+
(\k (v, sub) -> f (k, ks) v <> descend (k : ks) sub)
172171
m
173172

174173
showPercent :: Double -> String
@@ -177,17 +176,17 @@ showPercent d = pad $ showFFloat (Just 2) (100 * d) "%"
177176
pad s = replicate (7 - length s) ' ' <> s
178177

179178
dispProfEntry ::
180-
Ord k =>
179+
(Ord k) =>
181180
PrettyPrintEnv ->
182181
Map k Reference ->
183-
(k,[k]) ->
182+
(k, [k]) ->
184183
(Double, Double) ->
185184
Pretty ColorText
186-
dispProfEntry ppe refs (k,ks) (inh, self) =
185+
dispProfEntry ppe refs (k, ks) (inh, self) =
187186
mconcat
188187
[ P.indentN 2 . fromString $ showPercent inh,
189188
P.indentN 4 . fromString $ showPercent self,
190-
P.indentN (2*ind + 4) $ dispKey ppe refs k,
189+
P.indentN (2 * ind + 4) $ dispKey ppe refs k,
191190
"\n"
192191
]
193192
where
@@ -198,21 +197,21 @@ dispFunc ppe =
198197
syntaxToColor . prettyHashQualified . termName ppe . Ref
199198

200199
dispKey ::
201-
Ord k => PrettyPrintEnv -> Map k Reference -> k -> Pretty ColorText
200+
(Ord k) => PrettyPrintEnv -> Map k Reference -> k -> Pretty ColorText
202201
dispKey ppe refs k
203202
| Just r <- M.lookup k refs = dispFunc ppe r
204203
| otherwise = "<unknown>"
205204

206205
dispProfTrie ::
207-
Ord k =>
206+
(Ord k) =>
208207
PrettyPrintEnv ->
209208
Map k Reference ->
210209
ProfTrie k (Double, Double) ->
211210
Pretty ColorText
212211
dispProfTrie ppe refs ag = foldMapTrie (dispProfEntry ppe refs) ag
213212

214213
dispTopEntry ::
215-
Ord k =>
214+
(Ord k) =>
216215
PrettyPrintEnv ->
217216
Map k Reference ->
218217
(k, Double) ->
@@ -225,11 +224,12 @@ dispTopEntry ppe refs (k, frac) =
225224
]
226225
where
227226
dr :: Pretty ColorText
228-
dr | Just r <- M.lookup k refs = dispFunc ppe r
229-
| otherwise = "<unknown>"
227+
dr
228+
| Just r <- M.lookup k refs = dispFunc ppe r
229+
| otherwise = "<unknown>"
230230

231231
dispTop ::
232-
Ord k =>
232+
(Ord k) =>
233233
PrettyPrintEnv ->
234234
Map k Reference ->
235235
[(k, Double)] ->
@@ -243,34 +243,34 @@ profileTopHeader =
243243
profileTreeHeader :: Pretty ColorText
244244
profileTreeHeader =
245245
P.lines
246-
[ P.indentN 9 "Costs"
247-
, "Inherited Local Function Call Tree"
248-
, ""
246+
[ P.indentN 9 "Costs",
247+
"Inherited Local Function Call Tree",
248+
""
249249
]
250250

251-
miniProfile :: Ord k => PrettyPrintEnv -> Profile k -> Pretty ColorText
251+
miniProfile :: (Ord k) => PrettyPrintEnv -> Profile k -> Pretty ColorText
252252
miniProfile ppe (Prof total tr refs) =
253-
profileTreeHeader <>
254-
dispProfTrie ppe refs ag
253+
profileTreeHeader
254+
<> dispProfTrie ppe refs ag
255255
where
256256
ag = aggregatePruned total tr
257257

258258
fullProfile ::
259-
Ord k =>
259+
(Ord k) =>
260260
PrettyPrintEnv ->
261261
Profile k ->
262262
Pretty ColorText
263263
fullProfile ppe (Prof total tr refs) =
264-
profileTopHeader <>
265-
dispTop ppe refs top <>
266-
"\n\n" <>
267-
profileTreeHeader <>
268-
dispProfTrie ppe refs ag
264+
profileTopHeader
265+
<> dispTop ppe refs top
266+
<> "\n\n"
267+
<> profileTreeHeader
268+
<> dispProfTrie ppe refs ag
269269
where
270270
(top, ag) = aggregate total tr
271271

272272
foldedProfile ::
273-
Ord k =>
273+
(Ord k) =>
274274
PrettyPrintEnv ->
275275
Profile k ->
276276
String
@@ -279,10 +279,10 @@ foldedProfile ppe (Prof _ tr refs) =
279279
where
280280
dk = dispKey ppe refs
281281

282-
f (k,ks) n =
282+
f (k, ks) n =
283283
mconcat
284-
[ foldl (\tx k -> dk k <> ";" <> tx) (dk k) ks
285-
, " "
286-
, fromString $ show n
287-
, "\n"
284+
[ foldl (\tx k -> dk k <> ";" <> tx) (dk k) ks,
285+
" ",
286+
fromString $ show n,
287+
"\n"
288288
]

unison-cli/src/Unison/Codebase/Editor/HandleInput/Load.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ import Unison.Codebase qualified as Codebase
3030
import Unison.Codebase.Branch qualified as Branch
3131
import Unison.Codebase.Branch.Names qualified as Branch
3232
import Unison.Codebase.Editor.HandleInput.RuntimeUtils
33-
(EvalMode (..), modeProfSpec)
33+
( EvalMode (..),
34+
modeProfSpec,
35+
)
3436
import Unison.Codebase.Editor.HandleInput.RuntimeUtils qualified as RuntimeUtils
3537
import Unison.Codebase.Editor.Output qualified as Output
3638
import Unison.Codebase.Editor.SlurpResult (SlurpEntry (..), TermSlurp (..))

unison-cli/src/Unison/Codebase/Editor/HandleInput/RuntimeUtils.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module Unison.Codebase.Editor.HandleInput.RuntimeUtils
66
displayResponse,
77
selectRuntime,
88
EvalMode (..),
9-
modeProfSpec
9+
modeProfSpec,
1010
)
1111
where
1212

unison-cli/src/Unison/Codebase/Editor/Input.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ import Unison.Codebase.Path qualified as Path
4040
import Unison.Codebase.Path.Parse qualified as Path
4141
import Unison.Codebase.ProjectPath (ProjectPath)
4242
import Unison.Codebase.PushBehavior (PushBehavior)
43+
import Unison.Codebase.Runtime.Profile (ProfileSpec)
4344
import Unison.Codebase.ShortCausalHash (ShortCausalHash)
4445
import Unison.Codebase.ShortCausalHash qualified as SCH
45-
import Unison.Codebase.Runtime.Profile (ProfileSpec)
4646
import Unison.CommandLine.BranchRelativePath (BranchRelativePath, parseBranchRelativePath)
4747
import Unison.HashQualified qualified as HQ
4848
import Unison.HashQualifiedPrime qualified as HQ'

0 commit comments

Comments
 (0)