-
Notifications
You must be signed in to change notification settings - Fork 710
Use UnqualComponentName newtype instead of String for component names #4057
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
Conversation
@Ericson2314, thanks for your PR! By analyzing the history of the files in this pull request, we identified @ezyang, @dcoutts and @edsko to be potential reviewers. |
Hmm this bitrots real quick |
761abbf
to
2cd5ac2
Compare
You were just unlucky, ezyang merged the huge foreign libraries patch. Those don't come along very often. |
So I'm lacking some context. Why are we renaming component name to unqualified component name? |
We're not. ComponentName is still a library/executable/... tag + a string, and UnqualComponentName is just the string without the tag, which shows up in a number of places in Cabal source code. It's more type safe. |
b93ccd3
to
b008fcd
Compare
Appveyor failure is real. I guess some Windows specific code that is macro'd away? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. But the Appveyor build failure needs to be fixed. The rest of the comments can wait after merging, to help avoid bitrotting.
@@ -183,7 +183,8 @@ extendConfiguredComponentMap cc (lib_map, exe_map) = | |||
Map.insert (pkgName (cc_pkgid cc)) | |||
(cc_cid cc, cc_pkgid cc) lib_map | |||
CSubLibName str -> | |||
Map.insert (mkPackageName str) | |||
-- TODO roundtrip | |||
Map.insert (mkPackageName $ unUnqualComponentName str) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Didn't you make a function to handle this conversion?
@@ -69,6 +70,44 @@ import Distribution.ModuleName | |||
|
|||
import Text.PrettyPrint ((<+>), text) | |||
|
|||
-- | A Component name, or other similarly-parsed identifier. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Distinguished from a 'ComponentName', which also identifies whether or not the component in question is a library, executable, etc.
instance Binary UnqualComponentName | ||
|
||
instance Text UnqualComponentName where | ||
disp = Disp.text . unUnqualComponentName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explanation that this was cribbed from PackageName would be nice.
deriving (Generic, Read, Show, Eq, Ord, Typeable, Data, | ||
Binary, Text, NFData) | ||
|
||
packageNameToUnqualComponentName :: PackageName -> UnqualComponentName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs doc. Something like "Converts a package name to an unqualified component name; useful in legacy situations where a package name may refer to an internal component, if one is defined with that name."
@@ -77,12 +116,16 @@ import Text.PrettyPrint ((<+>), text) | |||
-- This type is opaque since @Cabal-2.0@ | |||
-- | |||
-- @since 2.0 | |||
newtype PackageName = PackageName ShortText | |||
deriving (Generic, Read, Show, Eq, Ord, Typeable, Data) | |||
newtype PackageName = PackageName UnqualComponentName |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm.... not sure setting it up this way makes sense? A package name isn't really a component name in any sense; they just happen to coincide in syntax due to some historical choices. Better to keep them disjoint? (If the duplication of the Text instance is troublesome, define a helper function.)
@@ -185,13 +185,15 @@ checkSanity pkg = | |||
++ "Only the non-internal library can have the same name as the package." | |||
|
|||
, check (not (null duplicateNames)) $ | |||
PackageBuildImpossible $ "Duplicate sections: " ++ commaSep duplicateNames | |||
PackageBuildImpossible $ "Duplicate sections: " | |||
++ commaSep (unUnqualComponentName <$> duplicateNames) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't say I'm the biggest fan of fmap here, when a map makes intent much clearer ;)
,[(UnqualComponentName, CondTree ConfVar [Dependency] ForeignLib)] | ||
,[(UnqualComponentName, CondTree ConfVar [Dependency] Executable)] | ||
,[(UnqualComponentName, CondTree ConfVar [Dependency] TestSuite)] | ||
,[(UnqualComponentName, CondTree ConfVar [Dependency] Benchmark)]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, someday we'll refactor this code. Not today though :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete I hope! Its the old parser.
8271b2d
to
ac8ad4a
Compare
No windows error seems spurious? |
Yeah. For some reason Appveyor isn't letting me request a rebuild. Maybe rebase and force push to kick the build again. |
ac8ad4a
to
63502b8
Compare
63502b8
to
be6a94a
Compare
Hmm, for future reference it would be nice to avoid repeating the signatures of |
Yes! My preference is to minimize the amount of code covered by CPP but there is a lot of code which doesn't follow this rule. |
Whew both passed! Cause this bitrots so quick I'm going to merge. I hope that's ok! |
Thank you, good work! |
I need to remember to move the WIP before the merge commit, lol! |
@@ -363,6 +364,10 @@ parseName pos args = case args of | |||
parseFailure pos $ "Invalid name " ++ show args | |||
pure "" | |||
|
|||
parseUnqualComponentName :: Position -> [SectionArg Position] -> ParseResult UnqualComponentName | |||
parseUnqualComponentName pos args = mkUnqualComponentName <$> parseName pos args |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if parseName
is used anywhere else, otherwise we could inline it here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean not expose it? It is used a couple time in that module if I am reading this right and it wasn't changed since this was merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, it used multiple times. Then everything is ok, sorry for disturbance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No worries! I think it was being weird about rendering the diff.
Working on #4055 led into this... 🎊