Skip to content

Commit

Permalink
priv deps: Drop ConstraintScope ScopePrivate
Browse files Browse the repository at this point in the history
Since we dropped the `Component` field of `ScopePrivate` in the previous
commit, we can now use `ScopeQualified` instead of having a specific
constructor `ScopePrivate`. This is mostly a clean up.
  • Loading branch information
alt-romes committed Apr 26, 2024
1 parent c334f41 commit f351097
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ data ConstraintScope
-- | The package with the specified name and qualifier.
| ScopeQualified Namespace Qualifier PackageName

-- Apply a constraint to a private-build-depends scope
-- It is not sufficient to have ScopeQualified because we don't have enough
-- information in the constraint syntax to fill in the `Component` field of
-- `QualAlias`
| ScopePrivate PackageName PrivateAlias PackageName
-- | The package with the specified name when it has a
-- setup qualifier.
| ScopeAnySetupQualifier PackageName
Expand All @@ -75,7 +70,6 @@ scopeToPackageName (ScopeTarget pn) = pn
scopeToPackageName (ScopeQualified _ _ pn) = pn
scopeToPackageName (ScopeAnySetupQualifier pn) = pn
scopeToPackageName (ScopeAnyQualifier pn) = pn
scopeToPackageName (ScopePrivate _ _ pn) = pn

-- | Whether a ConstraintScope matches a qualified package name, the crucial
-- function which determines the rules about when constraints apply.
Expand All @@ -86,12 +80,8 @@ constraintScopeMatches (ScopeTarget pn) (Q (PackagePath ns q) pn') =
namespaceMatches (IndependentComponent {}) = False
namespaceMatches (IndependentBuildTool {}) = False
in namespaceMatches ns && q == QualToplevel && pn == pn'
constraintScopeMatches (ScopePrivate spn alias c_pn) (Q (PackagePath _qual_ns q) c_pn') =
let qualMatches (QualAlias qual_pn qual_alias) = spn == qual_pn && alias == qual_alias
qualMatches _ = False
-- TODO: Check whether any ns should subsume qual_ns (if private constraint scopes grow namespaces...)
in qualMatches q && c_pn == c_pn'
constraintScopeMatches (ScopeQualified ns cq cpn) (Q (PackagePath qual_ns q) cpn') =
-- Should we check whether ns subsumes qual_ns rather than equality?
ns == qual_ns && cq == q && cpn == cpn'

constraintScopeMatches (ScopeAnySetupQualifier pn) (Q pp pn') =
Expand All @@ -103,8 +93,8 @@ constraintScopeMatches (ScopeAnyQualifier pn) (Q _ pn') = pn == pn'
-- | Pretty-prints a constraint scope.
dispConstraintScope :: ConstraintScope -> Disp.Doc
dispConstraintScope (ScopeTarget pn) = pretty pn <<>> Disp.text "." <<>> pretty pn
dispConstraintScope (ScopeQualified _ (QualAlias apn alias) p) = Disp.text "private." <<>> pretty apn <<>> Disp.text "." <<>> pretty @PrivateAlias alias <<>> Disp.text ":" <<>> pretty p
dispConstraintScope (ScopeQualified ns _q pn) = dispNamespace ns <<>> pretty pn
dispConstraintScope (ScopePrivate pn alias p) = Disp.text "private." <<>> pretty pn <<>> Disp.text "." <<>> pretty @PrivateAlias alias <<>> Disp.text ":" <<>> pretty p
dispConstraintScope (ScopeAnySetupQualifier pn) = Disp.text "setup." <<>> pretty pn
dispConstraintScope (ScopeAnyQualifier pn) = Disp.text "any." <<>> pretty pn

Expand Down
3 changes: 2 additions & 1 deletion cabal-install/src/Distribution/Client/Targets.hs
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,8 @@ fromUserQualifier (UserQualComp pn cn) = IndependentComponent pn (componentNameT
fromUserConstraintScope :: UserConstraintScope -> ConstraintScope
fromUserConstraintScope (UserQualified q pn) =
ScopeQualified (fromUserQualifier q) QualToplevel pn
fromUserConstraintScope (UserPrivateQualifier pn alias cpn) = ScopePrivate pn alias cpn
fromUserConstraintScope (UserPrivateQualifier pn alias cpn) =
ScopeQualified DefaultNamespace (QualAlias pn alias) cpn
fromUserConstraintScope (UserAnySetupQualifier pn) = ScopeAnySetupQualifier pn
fromUserConstraintScope (UserAnyQualifier pn) = ScopeAnyQualifier pn

Expand Down

0 comments on commit f351097

Please sign in to comment.