Skip to content

Remove functor instance from Dep #3167

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 3, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions cabal-install/Distribution/Client/Dependency/Modular/Dependency.hs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ data FlaggedDep comp qpn =
Flagged (FN qpn) FInfo (TrueFlaggedDeps qpn) (FalseFlaggedDeps qpn)
| Stanza (SN qpn) (TrueFlaggedDeps qpn)
| Simple (Dep qpn) comp
deriving (Eq, Show, Functor)
deriving (Eq, Show)

-- | Conversatively flatten out flagged dependencies
--
Expand All @@ -189,10 +189,15 @@ type FalseFlaggedDeps qpn = FlaggedDeps Component qpn

-- | A dependency (constraint) associates a package name with a
-- constrained instance.
--
-- 'Dep' intentionally has no 'Functor' instance because the type variable
-- is used both to record the dependencies as well as who's doing the
-- depending; having a 'Functor' instance makes bugs where we don't distinguish
-- these two far too likely. (By rights 'Dep' ought to have two type variables.)
data Dep qpn = Dep qpn (CI qpn) -- dependency on a package
| Ext Extension -- dependency on a language extension
| Lang Language -- dependency on a language version
deriving (Eq, Show, Functor)
deriving (Eq, Show)

showDep :: Dep QPN -> String
showDep (Dep qpn (Fixed i (Goal v _)) ) =
Expand Down Expand Up @@ -236,17 +241,25 @@ qualifyDeps QO{..} (Q pp' pn) = go
go1 (Stanza sn t) = Stanza (fmap (Q pp) sn) (go t)
go1 (Simple dep comp) = Simple (goD dep comp) comp

-- Suppose package B has a setup dependency on package A.
-- This will be recorded as something like
--
-- > Dep "A" (Constrained [(AnyVersion, Goal (P "B") reason])
--
-- Observe that when we qualify this dependency, we need to turn that
-- @"A"@ into @"B-setup.A"@, but we should not apply that same qualifier
-- to the goal or the goal reason chain.
goD :: Dep PN -> Component -> Dep QPN
goD dep comp
| qBase dep = fmap (Q (Base pn pp)) dep
| qSetup comp = fmap (Q (Setup pn pp)) dep
| otherwise = fmap (Q pp ) dep
goD (Ext ext) _ = Ext ext
goD (Lang lang) _ = Lang lang
goD (Dep dep ci) comp
| qBase dep = Dep (Q (Base pn pp) dep) (fmap (Q pp) ci)
| qSetup comp = Dep (Q (Setup pn pp) dep) (fmap (Q pp) ci)
| otherwise = Dep (Q pp dep) (fmap (Q pp) ci)

-- Should we qualify this goal with the 'Base' package path?
qBase :: Dep PN -> Bool
qBase (Dep dep _ci) = qoBaseShim && unPackageName dep == "base"
qBase (Ext _) = False
qBase (Lang _) = False
qBase :: PN -> Bool
qBase dep = qoBaseShim && unPackageName dep == "base"

-- Should we qualify this goal with the 'Setup' packaeg path?
qSetup :: Component -> Bool
Expand Down