Use UnqualComponentName newtype instead of String for component names#4057
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? |
ezyang
left a comment
There was a problem hiding this comment.
Looks good. But the Appveyor build failure needs to be fixed. The rest of the comments can wait after merging, to help avoid bitrotting.
| CSubLibName str -> | ||
| Map.insert (mkPackageName str) | ||
| -- TODO roundtrip | ||
| Map.insert (mkPackageName $ unUnqualComponentName str) |
There was a problem hiding this comment.
Didn't you make a function to handle this conversion?
Cabal/Distribution/Package.hs
Outdated
|
|
||
| import Text.PrettyPrint ((<+>), text) | ||
|
|
||
| -- | A Component name, or other similarly-parsed identifier. |
There was a problem hiding this comment.
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.
Explanation that this was cribbed from PackageName would be nice.
Cabal/Distribution/Package.hs
Outdated
| deriving (Generic, Read, Show, Eq, Ord, Typeable, Data, | ||
| Binary, Text, NFData) | ||
|
|
||
| packageNameToUnqualComponentName :: PackageName -> UnqualComponentName |
There was a problem hiding this comment.
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."
Cabal/Distribution/Package.hs
Outdated
| -- @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.
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.)
| , check (not (null duplicateNames)) $ | ||
| PackageBuildImpossible $ "Duplicate sections: " ++ commaSep duplicateNames | ||
| PackageBuildImpossible $ "Duplicate sections: " | ||
| ++ commaSep (unUnqualComponentName <$> duplicateNames) |
There was a problem hiding this comment.
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.
Ah, someday we'll refactor this code. Not today though :)
There was a problem hiding this comment.
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! |
| pure "" | ||
|
|
||
| parseUnqualComponentName :: Position -> [SectionArg Position] -> ParseResult UnqualComponentName | ||
| parseUnqualComponentName pos args = mkUnqualComponentName <$> parseName pos args |
There was a problem hiding this comment.
I wonder if parseName is used anywhere else, otherwise we could inline it here.
There was a problem hiding this comment.
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.
Ah, it used multiple times. Then everything is ok, sorry for disturbance.
There was a problem hiding this comment.
No worries! I think it was being weird about rendering the diff.
Working on #4055 led into this... 🎊