Skip to content

Commit d5dc00b

Browse files
authored
Merge pull request #6453 from commercialhaskell/other-prefix
Remove other prefixes from field names of types
2 parents d29cfee + 48595fd commit d5dc00b

File tree

8 files changed

+83
-79
lines changed

8 files changed

+83
-79
lines changed

src/Control/Concurrent/Execute.hs

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
{-# LANGUAGE NoImplicitPrelude #-}
2-
{-# LANGUAGE OverloadedRecordDot #-}
1+
{-# LANGUAGE NoImplicitPrelude #-}
2+
{-# LANGUAGE DuplicateRecordFields #-}
3+
{-# LANGUAGE NoFieldSelectors #-}
4+
{-# LANGUAGE OverloadedRecordDot #-}
35

46
-- Concurrent execution with dependencies. Types currently hard-coded for needs
57
-- of stack, but could be generalized easily.
@@ -55,9 +57,9 @@ data Action = Action
5557
-- ^ The action's unique id.
5658
, actionDeps :: !(Set ActionId)
5759
-- ^ Actions on which this action depends.
58-
, actionDo :: !(ActionContext -> IO ())
60+
, action :: !(ActionContext -> IO ())
5961
-- ^ The action's 'IO' action, given a context.
60-
, actionConcurrency :: !Concurrency
62+
, concurrency :: !Concurrency
6163
-- ^ Whether this action may be run concurrently with others.
6264
}
6365

@@ -69,20 +71,20 @@ data Concurrency
6971
deriving Eq
7072

7173
data ActionContext = ActionContext
72-
{ acRemaining :: !(Set ActionId)
74+
{ remaining :: !(Set ActionId)
7375
-- ^ Does not include the current action.
74-
, acDownstream :: [Action]
76+
, downstream :: [Action]
7577
-- ^ Actions which depend on the current action.
76-
, acConcurrency :: !Concurrency
78+
, concurrency :: !Concurrency
7779
-- ^ Whether this action may be run concurrently with others.
7880
}
7981

8082
data ExecuteState = ExecuteState
81-
{ esActions :: TVar [Action]
82-
, esExceptions :: TVar [SomeException]
83-
, esInAction :: TVar (Set ActionId)
84-
, esCompleted :: TVar Int
85-
, esKeepGoing :: Bool
83+
{ actions :: TVar [Action]
84+
, exceptions :: TVar [SomeException]
85+
, inAction :: TVar (Set ActionId)
86+
, completed :: TVar Int
87+
, keepGoing :: Bool
8688
}
8789

8890
runActions ::
@@ -98,16 +100,16 @@ runActions threads keepGoing actions withProgress = do
98100
<*> newTVarIO Set.empty -- esInAction
99101
<*> newTVarIO 0 -- esCompleted
100102
<*> pure keepGoing -- esKeepGoing
101-
_ <- async $ withProgress es.esCompleted es.esInAction
103+
_ <- async $ withProgress es.completed es.inAction
102104
if threads <= 1
103105
then runActions' es
104106
else replicateConcurrently_ threads $ runActions' es
105-
readTVarIO es.esExceptions
107+
readTVarIO es.exceptions
106108

107109
-- | Sort actions such that those that can't be run concurrently are at
108110
-- the end.
109111
sortActions :: [Action] -> [Action]
110-
sortActions = sortBy (compareConcurrency `on` (.actionConcurrency))
112+
sortActions = sortBy (compareConcurrency `on` (.concurrency))
111113
where
112114
-- NOTE: Could derive Ord. However, I like to make this explicit so
113115
-- that changes to the datatype must consider how it's affecting
@@ -124,53 +126,54 @@ runActions' es = loop
124126

125127
breakOnErrs :: STM (IO ()) -> STM (IO ())
126128
breakOnErrs inner = do
127-
errs <- readTVar es.esExceptions
128-
if null errs || es.esKeepGoing
129+
errs <- readTVar es.exceptions
130+
if null errs || es.keepGoing
129131
then inner
130132
else doNothing
131133

132134
withActions :: ([Action] -> STM (IO ())) -> STM (IO ())
133135
withActions inner = do
134-
actions <- readTVar es.esActions
136+
actions <- readTVar es.actions
135137
if null actions
136138
then doNothing
137139
else inner actions
138140

139141
processActions :: [Action] -> STM (IO ())
140142
processActions actions = do
141-
inAction <- readTVar es.esInAction
143+
inAction <- readTVar es.inAction
142144
case break (Set.null . (.actionDeps)) actions of
143145
(_, []) -> do
144146
check (Set.null inAction)
145-
unless es.esKeepGoing $
146-
modifyTVar es.esExceptions (toException InconsistentDependenciesBug:)
147+
unless es.keepGoing $
148+
modifyTVar es.exceptions (toException InconsistentDependenciesBug:)
147149
doNothing
148150
(xs, action:ys) -> processAction inAction (xs ++ ys) action
149151

150152
processAction :: Set ActionId -> [Action] -> Action -> STM (IO ())
151153
processAction inAction otherActions action = do
152-
let concurrency = action.actionConcurrency
154+
let concurrency = action.concurrency
153155
unless (concurrency == ConcurrencyAllowed) $
154156
check (Set.null inAction)
155157
let action' = action.actionId
156158
otherActions' = Set.fromList $ map (.actionId) otherActions
157159
remaining = Set.union otherActions' inAction
160+
downstream = downstreamActions action' otherActions
158161
actionContext = ActionContext
159-
{ acRemaining = remaining
160-
, acDownstream = downstreamActions action' otherActions
161-
, acConcurrency = concurrency
162+
{ remaining
163+
, downstream
164+
, concurrency
162165
}
163-
writeTVar es.esActions otherActions
164-
modifyTVar es.esInAction (Set.insert action')
166+
writeTVar es.actions otherActions
167+
modifyTVar es.inAction (Set.insert action')
165168
pure $ do
166169
mask $ \restore -> do
167-
eres <- try $ restore $ action.actionDo actionContext
170+
eres <- try $ restore $ action.action actionContext
168171
atomically $ do
169-
modifyTVar es.esInAction (Set.delete action')
170-
modifyTVar es.esCompleted (+1)
172+
modifyTVar es.inAction (Set.delete action')
173+
modifyTVar es.completed (+1)
171174
case eres of
172-
Left err -> modifyTVar es.esExceptions (err:)
173-
Right () -> modifyTVar es.esActions $ map (dropDep action')
175+
Left err -> modifyTVar es.exceptions (err:)
176+
Right () -> modifyTVar es.actions $ map (dropDep action')
174177
loop
175178

176179
-- | Filter a list of actions to include only those that depend on the given

src/Options/Applicative/Builder/Extra.hs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{-# LANGUAGE NoImplicitPrelude #-}
2+
{-# LANGUAGE NoFieldSelectors #-}
23
{-# LANGUAGE OverloadedRecordDot #-}
34

45
-- | Extra functions for optparse-applicative.
@@ -260,22 +261,22 @@ optionalFirstFalse = fmap FirstFalse . optional
260261
absFileOption :: Mod OptionFields (Path Abs File) -> Parser (Path Abs File)
261262
absFileOption mods = option (eitherReader' parseAbsFile) $
262263
completer
263-
(pathCompleterWith defaultPathCompleterOpts { pcoRelative = False })
264+
(pathCompleterWith defaultPathCompleterOpts { relative = False })
264265
<> mods
265266

266267
relFileOption :: Mod OptionFields (Path Rel File) -> Parser (Path Rel File)
267268
relFileOption mods = option (eitherReader' parseRelFile) $
268269
completer
269-
(pathCompleterWith defaultPathCompleterOpts { pcoAbsolute = False })
270+
(pathCompleterWith defaultPathCompleterOpts { absolute = False })
270271
<> mods
271272

272273
absDirOption :: Mod OptionFields (Path Abs Dir) -> Parser (Path Abs Dir)
273274
absDirOption mods = option (eitherReader' parseAbsDir) $
274275
completer
275276
( pathCompleterWith
276277
defaultPathCompleterOpts
277-
{ pcoRelative = False
278-
, pcoFileFilter = const False
278+
{ relative = False
279+
, fileFilter = const False
279280
}
280281
)
281282
<> mods
@@ -285,8 +286,8 @@ relDirOption mods = option (eitherReader' parseRelDir) $
285286
completer
286287
( pathCompleterWith
287288
defaultPathCompleterOpts
288-
{ pcoAbsolute = False
289-
, pcoFileFilter = const False
289+
{ absolute = False
290+
, fileFilter = const False
290291
}
291292
)
292293
<> mods
@@ -296,20 +297,20 @@ eitherReader' :: Show e => (String -> Either e a) -> ReadM a
296297
eitherReader' f = eitherReader (mapLeft show . f)
297298

298299
data PathCompleterOpts = PathCompleterOpts
299-
{ pcoAbsolute :: Bool
300-
, pcoRelative :: Bool
301-
, pcoRootDir :: Maybe FilePath
302-
, pcoFileFilter :: FilePath -> Bool
303-
, pcoDirFilter :: FilePath -> Bool
300+
{ absolute :: Bool
301+
, relative :: Bool
302+
, rootDir :: Maybe FilePath
303+
, fileFilter :: FilePath -> Bool
304+
, dirFilter :: FilePath -> Bool
304305
}
305306

306307
defaultPathCompleterOpts :: PathCompleterOpts
307308
defaultPathCompleterOpts = PathCompleterOpts
308-
{ pcoAbsolute = True
309-
, pcoRelative = True
310-
, pcoRootDir = Nothing
311-
, pcoFileFilter = const True
312-
, pcoDirFilter = const True
309+
{ absolute = True
310+
, relative = True
311+
, rootDir = Nothing
312+
, fileFilter = const True
313+
, dirFilter = const True
313314
}
314315

315316
fileCompleter :: Completer
@@ -318,11 +319,11 @@ fileCompleter = pathCompleterWith defaultPathCompleterOpts
318319
fileExtCompleter :: [String] -> Completer
319320
fileExtCompleter exts =
320321
pathCompleterWith
321-
defaultPathCompleterOpts { pcoFileFilter = (`elem` exts) . takeExtension }
322+
defaultPathCompleterOpts { fileFilter = (`elem` exts) . takeExtension }
322323

323324
dirCompleter :: Completer
324325
dirCompleter =
325-
pathCompleterWith defaultPathCompleterOpts { pcoFileFilter = const False }
326+
pathCompleterWith defaultPathCompleterOpts { fileFilter = const False }
326327

327328
pathCompleterWith :: PathCompleterOpts -> Completer
328329
pathCompleterWith pco = mkCompleter $ \inputRaw -> do
@@ -333,15 +334,15 @@ pathCompleterWith pco = mkCompleter $ \inputRaw -> do
333334
let (inputSearchDir0, searchPrefix) = splitFileName input
334335
inputSearchDir = if inputSearchDir0 == "./" then "" else inputSearchDir0
335336
msearchDir <-
336-
case (isRelative inputSearchDir, pco.pcoAbsolute, pco.pcoRelative) of
337+
case (isRelative inputSearchDir, pco.absolute, pco.relative) of
337338
(True, _, True) -> do
338-
rootDir <- maybe getCurrentDirectory pure pco.pcoRootDir
339+
rootDir <- maybe getCurrentDirectory pure pco.rootDir
339340
pure $ Just (rootDir </> inputSearchDir)
340341
(False, True, _) -> pure $ Just inputSearchDir
341342
_ -> pure Nothing
342343
case msearchDir of
343344
Nothing
344-
| input == "" && pco.pcoAbsolute -> pure ["/"]
345+
| input == "" && pco.absolute -> pure ["/"]
345346
| otherwise -> pure []
346347
Just searchDir -> do
347348
entries <-
@@ -354,7 +355,7 @@ pathCompleterWith pco = mkCompleter $ \inputRaw -> do
354355
if searchPrefix `isPrefixOf` entry
355356
then do
356357
let path = searchDir </> entry
357-
case (pco.pcoFileFilter path, pco.pcoDirFilter path) of
358+
case (pco.fileFilter path, pco.dirFilter path) of
358359
(True, True) -> pure $ Just (inputSearchDir </> entry)
359360
(fileAllowed, dirAllowed) -> do
360361
isDir <- doesDirectoryExist path

src/Stack/Build/Execute.hs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -522,9 +522,9 @@ toActions installedMap mtestLock runInBase ee (mbuild, mfinal) =
522522
{ actionId = ActionId (taskProvides task) ATBuild
523523
, actionDeps =
524524
Set.map (`ActionId` ATBuild) task.configOpts.missing
525-
, actionDo =
525+
, action =
526526
\ac -> runInBase $ singleBuild ac ee task installedMap False
527-
, actionConcurrency = ConcurrencyAllowed
527+
, concurrency = ConcurrencyAllowed
528528
}
529529
]
530530
afinal = case mfinal of
@@ -536,9 +536,9 @@ toActions installedMap mtestLock runInBase ee (mbuild, mfinal) =
536536
{ actionId = ActionId pkgId ATBuildFinal
537537
, actionDeps = addBuild
538538
(Set.map (`ActionId` ATBuild) task.configOpts.missing)
539-
, actionDo =
539+
, action =
540540
\ac -> runInBase $ singleBuild ac ee task installedMap True
541-
, actionConcurrency = ConcurrencyAllowed
541+
, concurrency = ConcurrencyAllowed
542542
}
543543
) $
544544
-- These are the "final" actions - running tests and benchmarks.
@@ -547,20 +547,20 @@ toActions installedMap mtestLock runInBase ee (mbuild, mfinal) =
547547
else (:) Action
548548
{ actionId = ActionId pkgId ATRunTests
549549
, actionDeps = finalDeps
550-
, actionDo = \ac -> withLock mtestLock $ runInBase $
550+
, action = \ac -> withLock mtestLock $ runInBase $
551551
singleTest topts (Set.toList tests) ac ee task installedMap
552552
-- Always allow tests tasks to run concurrently with other tasks,
553553
-- particularly build tasks. Note that 'mtestLock' can optionally
554554
-- make it so that only one test is run at a time.
555-
, actionConcurrency = ConcurrencyAllowed
555+
, concurrency = ConcurrencyAllowed
556556
}
557557
) $
558558
( if Set.null benches
559559
then id
560560
else (:) Action
561561
{ actionId = ActionId pkgId ATRunBenchmarks
562562
, actionDeps = finalDeps
563-
, actionDo = \ac -> runInBase $
563+
, action = \ac -> runInBase $
564564
singleBench
565565
beopts
566566
(Set.toList benches)
@@ -570,7 +570,7 @@ toActions installedMap mtestLock runInBase ee (mbuild, mfinal) =
570570
installedMap
571571
-- Never run benchmarks concurrently with any other task, see
572572
-- #3663
573-
, actionConcurrency = ConcurrencyDisallowed
573+
, concurrency = ConcurrencyDisallowed
574574
}
575575
)
576576
[]

src/Stack/Build/ExecuteEnv.hs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,10 +602,10 @@ withSingleContext
602602
( wanted
603603
&& all
604604
(\(ActionId ident _) -> ident == pkgId)
605-
(Set.toList ac.acRemaining)
605+
(Set.toList ac.remaining)
606606
&& ee.totalWanted == 1
607607
)
608-
|| ac.acConcurrency == ConcurrencyDisallowed
608+
|| ac.concurrency == ConcurrencyDisallowed
609609

610610
withPackage inner =
611611
case taskType of

src/Stack/Build/ExecutePackage.hs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -456,8 +456,8 @@ singleBuild
456456
-- because their configure step will require that this
457457
-- package is built. See
458458
-- https://github.com/commercialhaskell/stack/issues/2787
459-
(True, _) | null ac.acDownstream -> pure Nothing
460-
(_, True) | null ac.acDownstream || installedMapHasThisPkg -> do
459+
(True, _) | null ac.downstream -> pure Nothing
460+
(_, True) | null ac.downstream || installedMapHasThisPkg -> do
461461
initialBuildSteps executableBuildStatuses cabal announce
462462
pure Nothing
463463
_ -> fulfillCuratorBuildExpectations
@@ -700,7 +700,7 @@ singleBuild
700700
let remaining =
701701
filter
702702
(\(ActionId x _) -> x == pkgId)
703-
(Set.toList ac.acRemaining)
703+
(Set.toList ac.remaining)
704704
when (null remaining) $ removeDirRecur pkgDir
705705
TTLocalMutable{} -> pure ()
706706

0 commit comments

Comments
 (0)