Skip to content

Commit 6051bf6

Browse files
mpickeringalt-romes
authored andcommitted
wip
1 parent f9187e2 commit 6051bf6

File tree

11 files changed

+103
-26
lines changed

11 files changed

+103
-26
lines changed

Cabal-syntax/src/Distribution/Types/Dependency.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,11 @@ instance Parsec PrivateDependency where
6868
instance Pretty PrivateDependency where
6969
pretty (PrivateDependency alias deps) = PP.hsep [pretty alias, PP.text "with", PP.parens (PP.hsep (PP.punctuate PP.comma (map pretty deps)))]
7070

71+
-- Footgun
7172
flattenPrivateDepends :: Dependencies -> [Dependency]
7273
flattenPrivateDepends (Dependencies _ priv) = concatMap private_depends priv
7374

75+
-- Footgun
7476
allDependencies :: Dependencies -> [Dependency]
7577
allDependencies (Dependencies pub priv) = pub ++ concatMap private_depends priv
7678

Cabal/src/Distribution/Simple/Setup/Config.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,6 @@ showProfDetailLevelFlag (Flag dl) = [showProfDetailLevel dl]
905905
parsecAliasDependency :: ParsecParser AliasDependency
906906
parsecAliasDependency = do
907907
pn <- parsec
908-
traceShowM pn
909908
_ <- P.char '='
910909
gc <- parsecGivenComponent
911910
return $ AliasDependency pn gc

cabal-install-solver/src/Distribution/Solver/Modular/ConfiguredConversion.hs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@ convCP iidx sidx (CP qpi fa es ds) =
3434
Left pi -> PreExisting $
3535
InstSolverPackage {
3636
instSolverPkgIPI = fromJust $ SI.lookupUnitId iidx pi,
37-
instSolverPkgLibDeps = fmap (\(b, _) -> map fst b) ds',
38-
instSolverPkgExeDeps = fmap (\(_, c) -> c) ds'
37+
instSolverPkgLibDeps = fmap (\(b, _) -> map fst b) (ds' Nothing),
38+
instSolverPkgExeDeps = fmap (\(_, c) -> c) (ds' Nothing)
3939
}
4040
Right pi -> Configured $
4141
SolverPackage {
4242
solverPkgSource = srcpkg,
4343
solverPkgFlags = fa,
4444
solverPkgStanzas = es,
45-
solverPkgLibDeps = fmap (\(b, _) -> b) ds',
46-
solverPkgExeDeps = fmap (\(_, c) -> c) ds'
45+
solverPkgLibDeps = fmap (\(b, _) -> b) (ds' (Just (pkgName pi))),
46+
solverPkgExeDeps = fmap (\(_, c) -> c) (ds' (Just (pkgName pi)))
4747
}
4848
where
4949
srcpkg = fromMaybe (error "convCP: lookupPackageId failed") $ CI.lookupPackageId sidx pi
5050
where
5151

52-
ds' :: ComponentDeps (([(SolverId, Maybe PrivateAlias)] {- lib -}, [SolverId] {- exe -}))
53-
ds' = fmap (partitionDeps . map convConfId) ds
52+
ds' :: Maybe PackageName -> ComponentDeps (([(SolverId, Maybe PrivateAlias)] {- lib -}, [SolverId] {- exe -}))
53+
ds' pn = fmap (partitionDeps . map (convConfId pn)) ds
5454

5555
partitionDeps :: [Converted] -> (([(SolverId, Maybe PrivateAlias)], [SolverId]))
5656
partitionDeps [] = ([], [])
@@ -69,8 +69,8 @@ convPI (PI (Q _ pn) (I v _)) = Right (PackageIdentifier pn v)
6969

7070
data Converted = NormalPkg SolverId | NormalExe SolverId | AliasPkg SolverId PrivateAlias
7171

72-
convConfId :: PI QPN -> Converted
73-
convConfId (PI (Q (PackagePath ns qn) pn) (I v loc)) =
72+
convConfId :: Maybe PackageName -> PI QPN -> Converted
73+
convConfId parent (PI (Q (PackagePath ns qn) pn) (I v loc)) =
7474
case loc of
7575
Inst pi -> NormalPkg (PreExistingId sourceId pi)
7676
_otherwise
@@ -82,7 +82,10 @@ convConfId (PI (Q (PackagePath ns qn) pn) (I v loc)) =
8282
-- silly and didn't allow arbitrarily nested build-tools
8383
-- dependencies, so a shallow check works.
8484
, pn == pn' -> NormalExe (PlannedId sourceId)
85-
| QualAlias _ _ alias _ <- qn -> AliasPkg (PlannedId sourceId) alias
85+
-- Same reasoning as for exes, the "top" qualified goal is the one
86+
-- which is private and needs to be aliased, but there might be other goals underneath which
87+
-- are solved in the same scope (but are not private)
88+
| QualAlias pn' _ alias _ <- qn, parent == Just pn' -> AliasPkg (PlannedId sourceId) alias
8689
| otherwise -> NormalPkg (PlannedId sourceId)
8790
where
8891
sourceId = PackageIdentifier pn v

cabal-install-solver/src/Distribution/Solver/Modular/Dependency.hs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ qualifyDeps QO{..} (Q pp@(PackagePath ns q) pn) = go
207207
| Private (qpn, pkgs) <- is_private = Dep (Q (PackagePath ns (QualAlias pn comp qpn pkgs)) <$> dep) is_private ci
208208
| qBase qpn = Dep (Q (PackagePath ns (QualBase pn)) <$> dep) is_private ci
209209
| qSetup comp = Dep (Q (PackagePath (IndependentComponent pn ComponentSetup) QualToplevel) <$> dep) is_private ci
210-
| otherwise = Dep (Q (PackagePath ns inheritedQ ) <$> dep) is_private ci
210+
| otherwise = Dep (Q (PackagePath ns (inheritedQ qpn) ) <$> dep) is_private ci
211211

212212

213213
-- pkg:lib-foo depends on: a
@@ -230,12 +230,16 @@ qualifyDeps QO{..} (Q pp@(PackagePath ns q) pn) = go
230230
-- The inherited qualifier is only used for regular dependencies; for setup
231231
-- and base dependencies we override the existing qualifier. See #3160 for
232232
-- a detailed discussion.
233-
inheritedQ :: Qualifier
234-
inheritedQ = case q of
233+
inheritedQ :: PackageName -> Qualifier
234+
inheritedQ pn = case q of
235235
QualToplevel -> QualToplevel
236236
QualBase {} -> QualToplevel
237237
-- MP: TODO, check if package name is in same scope (if so, persist)
238-
QualAlias {} -> QualToplevel
238+
QualAlias _ _ _ pkgs ->
239+
if pn `elem` pkgs
240+
then traceShow ("INHERITED", pn, pkgs) q
241+
else QualToplevel
242+
-- traceShow (alias, pkgs) QualToplevel
239243

240244
-- Should we qualify this goal with the 'Base' package path?
241245
qBase :: PN -> Bool

cabal-install-solver/src/Distribution/Solver/Modular/Preference.hs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module Distribution.Solver.Modular.Preference
1515
, onlyConstrained
1616
, sortGoals
1717
, pruneAfterFirstSuccess
18+
, rewriteQPN
1819
) where
1920

2021
import Prelude ()
@@ -359,6 +360,14 @@ onlyConstrained p = go
359360
go x
360361
= x
361362

363+
364+
rewriteQPN :: Show d => EndoTreeTrav d QGoalReason
365+
rewriteQPN = go
366+
where
367+
go x = x
368+
369+
370+
362371
-- | Sort all goals using the provided function.
363372
sortGoals :: (Variable QPN -> Variable QPN -> Ordering) -> EndoTreeTrav d c
364373
sortGoals variableOrder = go

cabal-install-solver/src/Distribution/Solver/Modular/Solver.hs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ import Distribution.Simple.Setup (BooleanFlag(..))
4848
#ifdef DEBUG_TRACETREE
4949
import qualified Distribution.Solver.Modular.ConflictSet as CS
5050
import qualified Distribution.Solver.Modular.WeightedPSQ as W
51-
import qualified Distribution.Deprecated.Text as T
51+
--import qualified Distribution.Deprecated.Text as T
5252

5353
import Debug.Trace.Tree (gtraceJson)
5454
import Debug.Trace.Tree.Simple
@@ -143,7 +143,8 @@ solve sc cinfo idx pkgConfigDB userPrefs userConstraints userGoals =
143143
OnlyConstrainedAll ->
144144
P.onlyConstrained pkgIsExplicit
145145
OnlyConstrainedNone ->
146-
id)
146+
id) . prunePhase2
147+
prunePhase2 = P.rewriteQPN
147148
buildPhase = buildTree idx (independentGoals sc) (S.toList userGoals)
148149

149150
allExplicit = M.keysSet userConstraints `S.union` userGoals
@@ -201,7 +202,7 @@ instance GSimpleTree (Tree d c) where
201202

202203
-- Show package choice
203204
goP :: QPN -> POption -> Tree d c -> (String, SimpleTree)
204-
goP _ (POption (I ver _loc) Nothing) subtree = (T.display ver, go subtree)
205+
goP _ (POption (I ver _loc) Nothing) subtree = (show ver, go subtree)
205206
goP (Q _ pn) (POption _ (Just pp)) subtree = (showQPN (Q pp pn), go subtree)
206207

207208
-- Show flag or stanza choice

cabal-install-solver/src/Distribution/Solver/Modular/Tree.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ data Tree d c =
7979

8080
-- | We failed to find a solution in this path through the tree
8181
| Fail ConflictSet FailReason
82+
deriving (Show)
8283

8384
-- | A package option is a package instance with an optional linking annotation
8485
--
@@ -143,7 +144,7 @@ data TreeF d c a =
143144
| GoalChoiceF RevDepMap (PSQ (Goal QPN) a)
144145
| DoneF RevDepMap d
145146
| FailF ConflictSet FailReason
146-
deriving (Functor, Foldable, Traversable)
147+
deriving (Functor, Foldable, Traversable, Show)
147148

148149
out :: Tree d c -> TreeF d c (Tree d c)
149150
out (PChoice p s i ts) = PChoiceF p s i ts

cabal-install-solver/src/Distribution/Solver/Types/PackageConstraint.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ scopeToPackageName (ScopePrivate _ _ pn) = pn
7979

8080
-- TOOD: Crucial
8181
constraintScopeMatches :: ConstraintScope -> QPN -> Bool
82-
constraintScopeMatches cs qpn | traceShow (cs, qpn) False = undefined
82+
--constraintScopeMatches cs qpn | traceShow (cs, qpn) False = undefined
8383
constraintScopeMatches (ScopeTarget pn) (Q (PackagePath ns q) pn') =
8484
let namespaceMatches DefaultNamespace = True
8585
namespaceMatches (Independent namespacePn) = pn == namespacePn

cabal-install-solver/src/Distribution/Solver/Types/PackagePath.hs

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ data Namespace =
3232
DefaultNamespace
3333

3434
-- | A goal which is solved per-package
35+
-- `--independent-goals`
3536
| Independent PackageName
3637

3738

@@ -66,6 +67,67 @@ data Qualifier =
6667
-- A goal which is solved per-component
6768
| QualAlias PackageName Component PrivateAlias [PackageName]
6869

70+
71+
-- package: qux
72+
-- :build-depends: foo, baz
73+
--
74+
-- package: baz
75+
-- :build-depends: wurble
76+
--
77+
-- PackagePath DefaultNamespace QualToplevel "foo"
78+
-- => PackagePath DefaultNamespace QualToplevel "wurble"
79+
-- PackagePath DefaultNamespace QualToplevel "baz"
80+
-- PackagePath DefaultNamespace QualToplevel "wurble"
81+
--
82+
-- package: qux
83+
-- :private-build-depends: G0 with (foo == 0.3, baz == 0.5)
84+
-- :private-build-depends: G1 with (foo == 0.4, baz)
85+
--
86+
-- package: foo
87+
-- :build-depends: baz >= 0.5
88+
--
89+
-- PackagePath DefaultNamespace (QualAlias "qux" "MainLib" "G0" [foo, baz]) "foo" (== 0.3)
90+
---- => PackagePath DefaultNamespace (QualAlias "qux" "MainLib" "G0") "baz" (>= 0.5)
91+
-- => PackagePath DefaultNamespace QualTopLevel "baz" (>= 0.5)
92+
-- PackagePath DefaultNamespace (QualAlias "qux" "MainLib" "G0") "baz" == 0.5
93+
-- =>>> PackagePath DefaultNamespace (QualAlias "qux" "MainLib" "G0") "baz" =>> 0.5
94+
-- =>>> PackagePath DefaultNamespace QualTopLevel "baz" =>> 0.6
95+
--
96+
--
97+
-- package a
98+
-- :private-build-depends: G0 with (b, d)
99+
--
100+
-- package b-0.1
101+
-- :build-depends: x
102+
--
103+
-- package b-0.2
104+
-- :build-depends: x, d
105+
--
106+
-- package b-0.3
107+
-- :build-depends: x, c, d
108+
--
109+
-- package c-0.1
110+
-- :build-depends: x
111+
--
112+
-- package c-0.2
113+
-- :build-depends: x, d
114+
--
115+
--
116+
-- Closure property violated by `b == 0.3` and `c == 0.2` THEN closure property is violated.
117+
--
118+
-- Need to be able to implicitly introduce c into the private scope so that the closure property holds.
119+
--
120+
--
121+
--
122+
--
123+
--
124+
-- PackagePath DefaultNamespace (QualAlias "qux" "MainLib" "G1" ) "foo"
125+
-- PackagePath DefaultNamespace (QualAlias "qux" "MainLib" "G1") "baz"
126+
--
127+
-- package: baz
128+
-- :build-depends: wurble
129+
--
130+
69131
{-
70132
-- | Setup dependency
71133
--

cabal-install-solver/src/Distribution/Solver/Types/SolverId.hs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ import Distribution.Package (PackageId, Package(..), UnitId)
1717
--
1818
data SolverId = PreExistingId { solverSrcId :: PackageId, solverInstId :: UnitId }
1919
| PlannedId { solverSrcId :: PackageId }
20-
deriving (Eq, Ord, Generic)
20+
deriving (Eq, Ord, Generic, Show)
2121

2222
instance Binary SolverId
2323
instance Structured SolverId
2424

25-
instance Show SolverId where
26-
show = show . solverSrcId
27-
2825
instance Package SolverId where
2926
packageId = solverSrcId

cabal-install/src/Distribution/Client/ProjectPlanning.hs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1873,7 +1873,7 @@ elaborateInstallPlan
18731873
external_lib_dep_sids = CD.select (== compSolverName) deps0
18741874
external_exe_dep_sids = CD.select (== compSolverName) exe_deps0
18751875

1876-
external_lib_dep_pkgs = [ (d, alias) | (sid, alias) <- external_lib_dep_sids, d <- mapDep sid ]
1876+
external_lib_dep_pkgs = Debug.Trace.traceShow ("SIDS", external_lib_dep_sids) [ (d, alias) | (sid, alias) <- external_lib_dep_sids, d <- mapDep sid ]
18771877

18781878
external_exe_dep_pkgs_raw = [ (d, Nothing) | sid <- external_exe_dep_sids, d <- mapDep sid ]
18791879

@@ -1894,8 +1894,7 @@ elaborateInstallPlan
18941894
exe_map1 = Map.union external_exe_map $ fmap (\x -> [x]) exe_map
18951895

18961896
external_lib_cc_map =
1897-
Map.fromListWith Map.union $
1898-
map mkCCMapping external_lib_dep_pkgs
1897+
Map.fromListWith Map.union (map mkCCMapping external_lib_dep_pkgs)
18991898
external_exe_cc_map =
19001899
Map.fromListWith Map.union $
19011900
map mkCCMapping external_exe_dep_pkgs

0 commit comments

Comments
 (0)