Skip to content

Commit fded2f3

Browse files
committed
Remove prefixes from field names of various types
lh/LoadHelper, rr/ResolveResult, pi/PathInfo, so/ScriptOpts, sdopts/SDistOpts, hs/HaskellStackOrg, sco/SetupCmdOpts, upopts/UnpackOpts, _bo/BinaryOpts, _uo/UpgradeOpts, uo/UploadOpts, hc/HackageCreds.
1 parent de666a7 commit fded2f3

File tree

11 files changed

+259
-247
lines changed

11 files changed

+259
-247
lines changed

src/Stack/Build/Installed.hs

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ loadDatabase installMap db lhs0 = do
132132
pkgexe <- getGhcPkgExe
133133
(lhs1', dps) <- ghcPkgDump pkgexe pkgDb $ conduitDumpPackage .| sink
134134
lhs1 <- mapMaybeM processLoadResult lhs1'
135-
let lhs = pruneDeps id (.lhId) (.lhDeps) const (lhs0 ++ lhs1)
136-
pure (map (\lh -> lh { lhDeps = [] }) $ Map.elems lhs, dps)
135+
let lhs = pruneDeps id (.ghcPkgId) (.depsGhcPkgId) const (lhs0 ++ lhs1)
136+
pure (map (\lh -> lh { depsGhcPkgId = [] }) $ Map.elems lhs, dps)
137137
where
138138
pkgDb = case db of
139139
GlobalPkgDb -> []
@@ -152,7 +152,7 @@ loadDatabase installMap db lhs0 = do
152152
processLoadResult (reason, lh) = do
153153
logDebug $
154154
"Ignoring package "
155-
<> fromPackageName (fst lh.lhPair)
155+
<> fromPackageName (fst lh.pair)
156156
<> case db of
157157
GlobalPkgDb -> mempty
158158
UserPkgDb loc fp -> ", from " <> displayShow (loc, fp) <> ","
@@ -241,13 +241,13 @@ isAllowed installMap pkgDb dp = case Map.lookup name installMap of
241241

242242
-- | Type representing certain information about an installed package.
243243
data LoadHelper = LoadHelper
244-
{ lhId :: !GhcPkgId
244+
{ ghcPkgId :: !GhcPkgId
245245
-- ^ The package's id.
246-
, lhSublibrary :: !(Maybe SublibDump)
247-
, lhDeps :: ![GhcPkgId]
246+
, subLibDump :: !(Maybe SublibDump)
247+
, depsGhcPkgId :: ![GhcPkgId]
248248
-- ^ Unless the package's name is that of a 'wired-in' package, a list of
249249
-- the ids of the installed packages that are the package's dependencies.
250-
, lhPair :: !(PackageName, (InstallLocation, Installed))
250+
, pair :: !(PackageName, (InstallLocation, Installed))
251251
-- ^ A pair of (a) the package's name and (b) a pair of the relevant
252252
-- database (write-only or mutable) and information about the library
253253
-- installed.
@@ -256,33 +256,33 @@ data LoadHelper = LoadHelper
256256

257257
toLoadHelper :: PackageDbVariety -> DumpPackage -> LoadHelper
258258
toLoadHelper pkgDb dp = LoadHelper
259-
{ lhId = gid
260-
, lhDeps =
261-
-- We always want to consider the wired in packages as having all of their
262-
-- dependencies installed, since we have no ability to reinstall them.
263-
-- This is especially important for using different minor versions of GHC,
264-
-- where the dependencies of wired-in packages may change slightly and
265-
-- therefore not match the snapshot.
266-
if name `Set.member` wiredInPackages
267-
then []
268-
else dp.depends
269-
, lhSublibrary = dp.sublib
270-
, lhPair =
271-
( name
272-
, (toInstallLocation pkgDb, Library ident installedLibInfo)
273-
)
259+
{ ghcPkgId
260+
, depsGhcPkgId
261+
, subLibDump = dp.sublib
262+
, pair
274263
}
275264
where
276-
installedLibInfo = InstalledLibraryInfo gid (Right <$> dp.license) mempty
277-
gid = dp.ghcPkgId
265+
ghcPkgId = dp.ghcPkgId
278266
ident@(PackageIdentifier name _) = dp.packageIdent
267+
depsGhcPkgId =
268+
-- We always want to consider the wired in packages as having all of their
269+
-- dependencies installed, since we have no ability to reinstall them. This
270+
-- is especially important for using different minor versions of GHC, where
271+
-- the dependencies of wired-in packages may change slightly and therefore
272+
-- not match the snapshot.
273+
if name `Set.member` wiredInPackages
274+
then []
275+
else dp.depends
276+
installedLibInfo = InstalledLibraryInfo ghcPkgId (Right <$> dp.license) mempty
279277

280278
toInstallLocation :: PackageDbVariety -> InstallLocation
281279
toInstallLocation GlobalDb = Snap
282280
toInstallLocation ExtraDb = Snap
283281
toInstallLocation WriteOnlyDb = Snap
284282
toInstallLocation MutableDb = Local
285283

284+
pair = (name, (toInstallLocation pkgDb, Library ident installedLibInfo))
285+
286286
-- | This is where sublibraries and main libraries are assembled into a single
287287
-- entity Installed package, where all ghcPkgId live.
288288
gatherAndTransformSubLoadHelper ::
@@ -302,16 +302,16 @@ gatherAndTransformSubLoadHelper lh =
302302
{ subLib = Map.union
303303
incomingLibInfo.subLib
304304
existingLibInfo.subLib
305-
, ghcPkgId = if isJust lh.lhSublibrary
305+
, ghcPkgId = if isJust lh.subLibDump
306306
then existingLibInfo.ghcPkgId
307307
else incomingLibInfo.ghcPkgId
308308
}
309309
)
310310
onPreviousLoadHelper newVal _oldVal = newVal
311-
(key, value) = case lh.lhSublibrary of
311+
(key, value) = case lh.subLibDump of
312312
Nothing -> (rawPackageName, rawValue)
313313
Just sd -> (sd.packageName, updateAsSublib sd <$> rawValue)
314-
(rawPackageName, rawValue) = lh.lhPair
314+
(rawPackageName, rawValue) = lh.pair
315315
updateAsSublib
316316
sd
317317
(Library (PackageIdentifier _sublibMungedPackageName version) libInfo)

src/Stack/Build/Target.hs

Lines changed: 66 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{-# LANGUAGE DuplicateRecordFields #-}
44
{-# LANGUAGE GADTs #-}
55
{-# LANGUAGE MultiWayIf #-}
6+
{-# LANGUAGE NoFieldSelectors #-}
67
{-# LANGUAGE OverloadedRecordDot #-}
78
{-# LANGUAGE OverloadedStrings #-}
89
{-# LANGUAGE ViewPatterns #-}
@@ -101,7 +102,7 @@ data NeedTargets
101102
--------------------------------------------------------------------------------
102103

103104
-- | Raw target information passed on the command line.
104-
newtype RawInput = RawInput { unRawInput :: Text }
105+
newtype RawInput = RawInput { rawInput :: Text }
105106

106107
getRawInput ::
107108
BuildOptsCLI
@@ -235,13 +236,13 @@ parseRawTarget t =
235236
--------------------------------------------------------------------------------
236237

237238
data ResolveResult = ResolveResult
238-
{ rrName :: !PackageName
239-
, rrRaw :: !RawInput
240-
, rrComponent :: !(Maybe NamedComponent)
239+
{ name :: !PackageName
240+
, rawInput :: !RawInput
241+
, component :: !(Maybe NamedComponent)
241242
-- ^ Was a concrete component specified?
242-
, rrAddedDep :: !(Maybe PackageLocationImmutable)
243+
, addedDep :: !(Maybe PackageLocationImmutable)
243244
-- ^ Only if we're adding this as a dependency
244-
, rrPackageType :: !PackageType
245+
, packageType :: !PackageType
245246
}
246247

247248
-- | Convert a 'RawTarget' into a 'ResolveResult' (see description on the
@@ -252,7 +253,7 @@ resolveRawTarget ::
252253
-> Map PackageName PackageLocation
253254
-> (RawInput, RawTarget)
254255
-> RIO env (Either StyleDoc ResolveResult)
255-
resolveRawTarget sma allLocs (ri, rt) =
256+
resolveRawTarget sma allLocs (rawInput, rt) =
256257
go rt
257258
where
258259
locals = sma.project
@@ -283,12 +284,12 @@ resolveRawTarget sma allLocs (ri, rt) =
283284
, style Shell $ flow "stack ide targets"
284285
, flow "for a list of available targets."
285286
]
286-
[(name, comp)] -> Right ResolveResult
287-
{ rrName = name
288-
, rrRaw = ri
289-
, rrComponent = Just comp
290-
, rrAddedDep = Nothing
291-
, rrPackageType = PTProject
287+
[(name, component)] -> Right ResolveResult
288+
{ name
289+
, rawInput
290+
, component = Just component
291+
, addedDep = Nothing
292+
, packageType = PTProject
292293
}
293294
matches -> Left $
294295
fillSep
@@ -321,41 +322,43 @@ resolveRawTarget sma allLocs (ri, rt) =
321322
Just pp -> do
322323
comps <- ppComponents pp
323324
pure $ case ucomp of
324-
ResolvedComponent comp
325-
| comp `Set.member` comps -> Right ResolveResult
326-
{ rrName = name
327-
, rrRaw = ri
328-
, rrComponent = Just comp
329-
, rrAddedDep = Nothing
330-
, rrPackageType = PTProject
325+
ResolvedComponent component
326+
| component `Set.member` comps -> Right ResolveResult
327+
{ name
328+
, rawInput
329+
, component = Just component
330+
, addedDep = Nothing
331+
, packageType = PTProject
331332
}
332333
| otherwise -> Left $
333334
fillSep
334335
[ "Component"
335-
, style Target (fromString $ T.unpack $ renderComponent comp)
336+
, style
337+
Target
338+
(fromString $ T.unpack $ renderComponent component)
336339
, flow "does not exist in package"
337340
, style Target (fromPackageName name) <> "."
338341
]
339-
UnresolvedComponent comp ->
340-
case filter (isCompNamed comp) $ Set.toList comps of
342+
UnresolvedComponent comp' ->
343+
case filter (isCompNamed comp') $ Set.toList comps of
341344
[] -> Left $
342345
fillSep
343346
[ "Component"
344-
, style Target (fromString $ T.unpack comp)
347+
, style Target (fromString $ T.unpack comp')
345348
, flow "does not exist in package"
346349
, style Target (fromPackageName name) <> "."
347350
]
348-
[x] -> Right ResolveResult
349-
{ rrName = name
350-
, rrRaw = ri
351-
, rrComponent = Just x
352-
, rrAddedDep = Nothing
353-
, rrPackageType = PTProject
351+
[component] -> Right ResolveResult
352+
{ name
353+
, rawInput
354+
, component = Just component
355+
, addedDep = Nothing
356+
, packageType = PTProject
354357
}
355358
matches -> Left $
356359
fillSep
357360
[ flow "Ambiguous component name"
358-
, style Target (fromString $ T.unpack comp)
361+
, style Target (fromString $ T.unpack comp')
359362
, flow "for package"
360363
, style Target (fromPackageName name)
361364
, flow "matches components:"
@@ -369,11 +372,11 @@ resolveRawTarget sma allLocs (ri, rt) =
369372

370373
go (RTPackage name)
371374
| Map.member name locals = pure $ Right ResolveResult
372-
{ rrName = name
373-
, rrRaw = ri
374-
, rrComponent = Nothing
375-
, rrAddedDep = Nothing
376-
, rrPackageType = PTProject
375+
{ name
376+
, rawInput
377+
, component = Nothing
378+
, addedDep = Nothing
379+
, packageType = PTProject
377380
}
378381
| Map.member name deps =
379382
pure $ deferToConstructPlan name
@@ -428,12 +431,12 @@ resolveRawTarget sma allLocs (ri, rt) =
428431
pure $ case mrev of
429432
Nothing -> deferToConstructPlan name
430433
Just (_rev, cfKey, treeKey) -> Right ResolveResult
431-
{ rrName = name
432-
, rrRaw = ri
433-
, rrComponent = Nothing
434-
, rrAddedDep = Just $
434+
{ name
435+
, rawInput
436+
, component = Nothing
437+
, addedDep = Just $
435438
PLIHackage (PackageIdentifier name version) cfKey treeKey
436-
, rrPackageType = PTDependency
439+
, packageType = PTDependency
437440
}
438441

439442
hackageLatest name = do
@@ -443,36 +446,36 @@ resolveRawTarget sma allLocs (ri, rt) =
443446
Nothing -> deferToConstructPlan name
444447
Just loc ->
445448
Right ResolveResult
446-
{ rrName = name
447-
, rrRaw = ri
448-
, rrComponent = Nothing
449-
, rrAddedDep = Just loc
450-
, rrPackageType = PTDependency
449+
{ name
450+
, rawInput
451+
, component = Nothing
452+
, addedDep = Just loc
453+
, packageType = PTDependency
451454
}
452455

453456
hackageLatestRevision name version = do
454457
mrev <- getLatestHackageRevision YesRequireHackageIndex name version
455458
pure $ case mrev of
456459
Nothing -> deferToConstructPlan name
457460
Just (_rev, cfKey, treeKey) -> Right ResolveResult
458-
{ rrName = name
459-
, rrRaw = ri
460-
, rrComponent = Nothing
461-
, rrAddedDep =
461+
{ name
462+
, rawInput
463+
, component = Nothing
464+
, addedDep =
462465
Just $ PLIHackage (PackageIdentifier name version) cfKey treeKey
463-
, rrPackageType = PTDependency
466+
, packageType = PTDependency
464467
}
465468

466469
-- This is actually an error case. We _could_ pure a Left value here, but it
467470
-- turns out to be better to defer this until the ConstructPlan phase, and let
468471
-- it complain about the missing package so that we get more errors together,
469472
-- plus the fancy colored output from that module.
470473
deferToConstructPlan name = Right ResolveResult
471-
{ rrName = name
472-
, rrRaw = ri
473-
, rrComponent = Nothing
474-
, rrAddedDep = Nothing
475-
, rrPackageType = PTDependency
474+
{ name
475+
, rawInput
476+
, component = Nothing
477+
, addedDep = Nothing
478+
, packageType = PTDependency
476479
}
477480
--------------------------------------------------------------------------------
478481
-- Combine the ResolveResults
@@ -489,23 +492,23 @@ combineResolveResults ::
489492
)
490493
combineResolveResults results = do
491494
addedDeps <- fmap Map.unions $ forM results $ \result ->
492-
case result.rrAddedDep of
495+
case result.addedDep of
493496
Nothing -> pure Map.empty
494-
Just pl -> pure $ Map.singleton result.rrName pl
497+
Just pl -> pure $ Map.singleton result.name pl
495498

496499
let m0 = Map.unionsWith (++) $
497-
map (\rr -> Map.singleton rr.rrName [rr]) results
500+
map (\rr -> Map.singleton rr.name [rr]) results
498501
(errs, ms) = partitionEithers $ flip map (Map.toList m0) $
499502
\(name, rrs) ->
500-
let mcomps = map (.rrComponent) rrs in
503+
let mcomps = map (.component) rrs in
501504
-- Confirm that there is either exactly 1 with no component, or that
502505
-- all rrs are components
503506
case rrs of
504507
[] -> assert False $
505508
Left $
506509
flow "Somehow got no rrComponent values, that can't happen."
507-
[rr] | isNothing rr.rrComponent ->
508-
Right $ Map.singleton name $ TargetAll rr.rrPackageType
510+
[rr] | isNothing rr.component ->
511+
Right $ Map.singleton name $ TargetAll rr.packageType
509512
_
510513
| all isJust mcomps ->
511514
Right $ Map.singleton name $ TargetComps $ Set.fromList $
@@ -521,7 +524,7 @@ combineResolveResults results = do
521524
pure (errs, Map.unions ms, addedDeps)
522525
where
523526
rrToStyleDoc :: ResolveResult -> StyleDoc
524-
rrToStyleDoc = fromString . T.unpack . (.rrRaw.unRawInput)
527+
rrToStyleDoc = fromString . T.unpack . (.rawInput.rawInput)
525528

526529
--------------------------------------------------------------------------------
527530
-- OK, let's do it!

src/Stack/CLI.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ commandLineHandler currentDir progName isInterpreter =
454454
"Run a Stack script."
455455
globalFooter
456456
scriptCmd
457-
(\so gom -> gom { resolverRoot = First $ Just $ takeDirectory so.soFile })
457+
(\so gom -> gom { resolverRoot = First $ Just $ takeDirectory so.file })
458458
(globalOpts OtherCmdGlobalOpts)
459459
scriptOptsParser
460460

0 commit comments

Comments
 (0)