Skip to content

Commit 20de0bf

Browse files
authored
Merge pull request #4397 from ezyang/pr/omnibus-refactor
Resurrect MungedId patch, and a pile of bugfixes
2 parents a9131a5 + c7cd985 commit 20de0bf

Some content is hidden

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

57 files changed

+777
-695
lines changed

Cabal/Cabal.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ library
207207
Distribution.TestSuite
208208
Distribution.Text
209209
Distribution.Types.AbiHash
210+
Distribution.Types.AnnotatedId
210211
Distribution.Types.Benchmark
211212
Distribution.Types.BenchmarkInterface
212213
Distribution.Types.BenchmarkType

Cabal/Distribution/Backpack/Configure.hs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import Distribution.Backpack.ConfiguredComponent
2525
import Distribution.Backpack.LinkedComponent
2626
import Distribution.Backpack.ReadyComponent
2727
import Distribution.Backpack.ComponentsGraph
28+
import Distribution.Backpack.Id
2829

2930
import Distribution.Simple.Compiler hiding (Flag)
3031
import Distribution.Package
@@ -37,9 +38,9 @@ import Distribution.PackageDescription as PD hiding (Flag)
3738
import Distribution.ModuleName
3839
import Distribution.Simple.Setup as Setup
3940
import Distribution.Simple.LocalBuildInfo
41+
import Distribution.Types.AnnotatedId
4042
import Distribution.Types.ComponentRequestedSpec
4143
import Distribution.Types.ComponentInclude
42-
import Distribution.Types.MungedPackageId
4344
import Distribution.Verbosity
4445
import qualified Distribution.Compat.Graph as Graph
4546
import Distribution.Compat.Graph (Graph, IsNode(..))
@@ -82,7 +83,13 @@ configureComponentLocalBuildInfos
8283
(dispComponentsGraph graph0)
8384

8485
let conf_pkg_map = Map.fromListWith Map.union
85-
[(pc_pkgname pkg, Map.singleton (pc_compname pkg) (pc_cid pkg, packageId pkg))
86+
[(pc_pkgname pkg,
87+
Map.singleton (pc_compname pkg)
88+
(AnnotatedId {
89+
ann_id = pc_cid pkg,
90+
ann_pid = packageId pkg,
91+
ann_cname = pc_compname pkg
92+
}))
8693
| pkg <- prePkgDeps]
8794
graph1 <- toConfiguredComponents use_external_internal_deps
8895
flagAssignment
@@ -110,7 +117,7 @@ configureComponentLocalBuildInfos
110117
let pid_map = Map.fromList $
111118
[ (pc_uid pkg, pc_munged_id pkg)
112119
| pkg <- prePkgDeps] ++
113-
[ (Installed.installedUnitId pkg, Installed.sourceMungedPackageId pkg)
120+
[ (Installed.installedUnitId pkg, mungedId pkg)
114121
| (_, Module uid _) <- instantiate_with
115122
, Just pkg <- [PackageIndex.lookupUnitId
116123
installedPackageSet (unDefUnitId uid)] ]
@@ -205,12 +212,10 @@ toComponentLocalBuildInfos
205212
-- TODO: This is probably wrong for Backpack
206213
let pseudoTopPkg :: InstalledPackageInfo
207214
pseudoTopPkg = emptyInstalledPackageInfo {
208-
Installed.installedUnitId = mkLegacyUnitId munged_id,
209-
Installed.sourceMungedPackageId = munged_id,
215+
Installed.installedUnitId = mkLegacyUnitId (packageId pkg_descr),
216+
Installed.sourcePackageId = packageId pkg_descr,
210217
Installed.depends = map pc_uid externalPkgDeps
211218
}
212-
where munged_id = computeCompatPackageId (packageId pkg_descr)
213-
CLibName
214219
case PackageIndex.dependencyInconsistencies
215220
. PackageIndex.insert pseudoTopPkg
216221
$ packageDependsIndex of
@@ -243,7 +248,7 @@ mkLinkedComponentsLocalBuildInfo comp rcs = map go rcs
243248
isInternal x = Set.member x internalUnits
244249
go rc =
245250
case rc_component rc of
246-
CLib _ ->
251+
CLib lib ->
247252
let convModuleExport (modname', (Module uid modname))
248253
| this_uid == unDefUnitId uid
249254
, modname' == modname
@@ -271,6 +276,10 @@ mkLinkedComponentsLocalBuildInfo comp rcs = map go rcs
271276
Left indefc -> [ (m, OpenModuleVar m) | m <- indefc_requires indefc ]
272277
Right instc -> [ (m, OpenModule (DefiniteUnitId uid') m')
273278
| (m, Module uid' m') <- instc_insts instc ]
279+
280+
compat_name = computeCompatPackageName (packageName rc) (libName lib)
281+
compat_key = computeCompatPackageKey comp compat_name (packageVersion rc) this_uid
282+
274283
in LibComponentLocalBuildInfo {
275284
componentPackageDeps = cpds,
276285
componentUnitId = this_uid,
@@ -283,8 +292,8 @@ mkLinkedComponentsLocalBuildInfo comp rcs = map go rcs
283292
componentIncludes = includes,
284293
componentExposedModules = exports,
285294
componentIsPublic = rc_public rc,
286-
componentCompatPackageKey = rc_compat_key rc comp,
287-
componentCompatPackageName = rc_compat_name rc
295+
componentCompatPackageKey = compat_key,
296+
componentCompatPackageName = compat_name
288297
}
289298
CFLib _ ->
290299
FLibComponentLocalBuildInfo {
@@ -332,7 +341,7 @@ mkLinkedComponentsLocalBuildInfo comp rcs = map go rcs
332341
this_cid = rc_cid rc
333342
cname = componentName (rc_component rc)
334343
cpds = rc_depends rc
335-
exe_deps = map fst $ rc_exe_deps rc
344+
exe_deps = map ann_id $ rc_exe_deps rc
336345
is_indefinite =
337346
case rc_i rc of
338347
Left _ -> True
@@ -343,6 +352,6 @@ mkLinkedComponentsLocalBuildInfo comp rcs = map go rcs
343352
Left indefc ->
344353
indefc_includes indefc
345354
Right instc ->
346-
map (\ci -> ci { ci_id = DefiniteUnitId (ci_id ci) })
355+
map (\ci -> ci { ci_ann_id = fmap DefiniteUnitId (ci_ann_id ci) })
347356
(instc_includes instc)
348357
internal_deps = filter isInternal (nodeNeighbors rc)

Cabal/Distribution/Backpack/ConfiguredComponent.hs

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
module Distribution.Backpack.ConfiguredComponent (
44
ConfiguredComponent(..),
55
cc_name,
6+
cc_cid,
7+
cc_pkgid,
68
toConfiguredComponent,
79
toConfiguredComponents,
810
dispConfiguredComponent,
@@ -19,6 +21,7 @@ import Distribution.Compat.Prelude hiding ((<>))
1921

2022
import Distribution.Backpack.Id
2123

24+
import Distribution.Types.AnnotatedId
2225
import Distribution.Types.Dependency
2326
import Distribution.Types.ExeDependency
2427
import Distribution.Types.IncludeRenaming
@@ -48,10 +51,8 @@ import Text.PrettyPrint
4851
-- and the 'ComponentId's of the things it depends on.
4952
data ConfiguredComponent
5053
= ConfiguredComponent {
51-
-- | Uniquely identifies a configured component.
52-
cc_cid :: ComponentId,
53-
-- | The package this component came from.
54-
cc_pkgid :: PackageId,
54+
-- | Unique identifier of component, plus extra useful info.
55+
cc_ann_id :: AnnotatedId ComponentId,
5556
-- | The fragment of syntax from the Cabal file describing this
5657
-- component.
5758
cc_component :: Component,
@@ -63,19 +64,28 @@ data ConfiguredComponent
6364
cc_public :: Bool,
6465
-- | Dependencies on executables from @build-tools@ and
6566
-- @build-tool-depends@.
66-
cc_exe_deps :: [(ComponentId, PackageId)],
67+
cc_exe_deps :: [AnnotatedId ComponentId],
6768
-- | The mixins of this package, including both explicit (from
6869
-- the @mixins@ field) and implicit (from @build-depends@). Not
6970
-- mix-in linked yet; component configuration only looks at
7071
-- 'ComponentId's.
7172
cc_includes :: [ComponentInclude ComponentId IncludeRenaming]
7273
}
7374

75+
76+
-- | Uniquely identifies a configured component.
77+
cc_cid :: ConfiguredComponent -> ComponentId
78+
cc_cid = ann_id . cc_ann_id
79+
80+
-- | The package this component came from.
81+
cc_pkgid :: ConfiguredComponent -> PackageId
82+
cc_pkgid = ann_pid . cc_ann_id
83+
7484
-- | The 'ComponentName' of a component; this uniquely identifies
7585
-- a fragment of syntax within a specified Cabal file describing the
7686
-- component.
7787
cc_name :: ConfiguredComponent -> ComponentName
78-
cc_name = componentName . cc_component
88+
cc_name = ann_cname . cc_ann_id
7989

8090
-- | Pretty-print a 'ConfiguredComponent'.
8191
dispConfiguredComponent :: ConfiguredComponent -> Doc
@@ -91,27 +101,24 @@ dispConfiguredComponent cc =
91101
mkConfiguredComponent
92102
:: PackageDescription
93103
-> ComponentId
94-
-> [((PackageName, ComponentName), (ComponentId, PackageId))]
95-
-> [(ComponentId, PackageId)]
104+
-> [AnnotatedId ComponentId] -- lib deps
105+
-> [AnnotatedId ComponentId] -- exe deps
96106
-> Component
97107
-> LogProgress ConfiguredComponent
98-
mkConfiguredComponent pkg_decr this_cid lib_deps exe_deps component = do
108+
mkConfiguredComponent pkg_descr this_cid lib_deps exe_deps component = do
99109
-- Resolve each @mixins@ into the actual dependency
100110
-- from @lib_deps@.
101111
explicit_includes <- forM (mixins bi) $ \(Mixin name rns) -> do
102-
let keys@(_, cname) = fixFakePkgName pkg_decr name
103-
(cid, pid) <-
104-
case Map.lookup keys deps_map of
112+
let keys = fixFakePkgName pkg_descr name
113+
aid <- case Map.lookup keys deps_map of
105114
Nothing ->
106115
dieProgress $
107116
text "Mix-in refers to non-existent package" <+>
108117
quotes (disp name) $$
109118
text "(did you forget to add the package to build-depends?)"
110119
Just r -> return r
111120
return ComponentInclude {
112-
ci_id = cid,
113-
ci_pkgid = pid,
114-
ci_compname = cname,
121+
ci_ann_id = aid,
115122
ci_renaming = rns,
116123
ci_implicit = False
117124
}
@@ -120,30 +127,32 @@ mkConfiguredComponent pkg_decr this_cid lib_deps exe_deps component = do
120127
-- @backpack-include@ is converted into an "implicit" include.
121128
let used_explicitly = Set.fromList (map ci_id explicit_includes)
122129
implicit_includes
123-
= map (\((_, cn), (cid, pid)) -> ComponentInclude {
124-
ci_id = cid,
125-
ci_pkgid = pid,
126-
ci_compname = cn,
127-
ci_renaming = defaultIncludeRenaming,
128-
ci_implicit = True
129-
})
130-
$ filter (flip Set.notMember used_explicitly . fst . snd) lib_deps
130+
= map (\aid -> ComponentInclude {
131+
ci_ann_id = aid,
132+
ci_renaming = defaultIncludeRenaming,
133+
ci_implicit = True
134+
})
135+
$ filter (flip Set.notMember used_explicitly . ann_id) lib_deps
131136

132137
return ConfiguredComponent {
133-
cc_cid = this_cid,
134-
cc_pkgid = package pkg_decr,
138+
cc_ann_id = AnnotatedId {
139+
ann_id = this_cid,
140+
ann_pid = package pkg_descr,
141+
ann_cname = componentName component
142+
},
135143
cc_component = component,
136144
cc_public = is_public,
137145
cc_exe_deps = exe_deps,
138146
cc_includes = explicit_includes ++ implicit_includes
139147
}
140148
where
141149
bi = componentBuildInfo component
142-
deps_map = Map.fromList lib_deps
150+
deps_map = Map.fromList [ ((packageName dep, ann_cname dep), dep)
151+
| dep <- lib_deps ]
143152
is_public = componentName component == CLibName
144153

145154
type ConfiguredComponentMap =
146-
Map PackageName (Map ComponentName (ComponentId, PackageId))
155+
Map PackageName (Map ComponentName (AnnotatedId ComponentId))
147156

148157
toConfiguredComponent
149158
:: PackageDescription
@@ -155,15 +164,15 @@ toConfiguredComponent pkg_descr this_cid dep_map component = do
155164
lib_deps <-
156165
if newPackageDepsBehaviour pkg_descr
157166
then forM (targetBuildDepends bi) $ \(Dependency name _) -> do
158-
let keys@(pn, cn) = fixFakePkgName pkg_descr name
167+
let (pn, cn) = fixFakePkgName pkg_descr name
159168
value <- case Map.lookup cn =<< Map.lookup pn dep_map of
160169
Nothing ->
161170
dieProgress $
162171
text "Dependency on unbuildable" <+>
163172
text (showComponentName cn) <+>
164173
text "from" <+> disp pn
165174
Just v -> return v
166-
return (keys, value)
175+
return value
167176
else return old_style_lib_deps
168177
mkConfiguredComponent
169178
pkg_descr this_cid
@@ -177,7 +186,7 @@ toConfiguredComponent pkg_descr this_cid dep_map component = do
177186
-- this is not supported by old-style deps behavior
178187
-- because it would imply a cyclic dependency for the
179188
-- library itself.
180-
old_style_lib_deps = [ ((pn, cn), e)
189+
old_style_lib_deps = [ e
181190
| (pn, comp_map) <- Map.toList dep_map
182191
, pn /= packageName pkg_descr
183192
, (cn, e) <- Map.toList comp_map
@@ -215,10 +224,11 @@ toConfiguredComponent' use_external_internal_deps flags
215224
then cc { cc_public = True }
216225
else cc
217226
where
227+
-- TODO: pass component names to it too!
218228
this_cid = computeComponentId deterministic ipid_flag cid_flag (package pkg_descr)
219229
(componentName component) (Just (deps, flags))
220-
deps = [ cid | m <- Map.elems dep_map
221-
, (cid, _) <- Map.elems m ]
230+
deps = [ ann_id aid | m <- Map.elems dep_map
231+
, aid <- Map.elems m ]
222232

223233
extendConfiguredComponentMap
224234
:: ConfiguredComponent
@@ -227,7 +237,7 @@ extendConfiguredComponentMap
227237
extendConfiguredComponentMap cc =
228238
Map.insertWith Map.union
229239
(pkgName (cc_pkgid cc))
230-
(Map.singleton (cc_name cc) (cc_cid cc, cc_pkgid cc))
240+
(Map.singleton (cc_name cc) (cc_ann_id cc))
231241

232242
-- Compute the 'ComponentId's for a graph of 'Component's. The
233243
-- list of internal components must be topologically sorted

0 commit comments

Comments
 (0)