Skip to content

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

Merged
merged 1 commit into from
Nov 1, 2016

Conversation

Ericson2314
Copy link
Collaborator

Working on #4055 led into this... 🎊

@mention-bot
Copy link

@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.

@Ericson2314
Copy link
Collaborator Author

Hmm this bitrots real quick

@Ericson2314 Ericson2314 force-pushed the unqual-component-name branch from 761abbf to 2cd5ac2 Compare October 30, 2016 00:29
@dcoutts
Copy link
Contributor

dcoutts commented Oct 30, 2016

Hmm this bitrots real quick

You were just unlucky, ezyang merged the huge foreign libraries patch. Those don't come along very often.

@dcoutts
Copy link
Contributor

dcoutts commented Oct 30, 2016

So I'm lacking some context. Why are we renaming component name to unqualified component name?

@ezyang
Copy link
Contributor

ezyang commented Oct 30, 2016

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.

@Ericson2314 Ericson2314 force-pushed the unqual-component-name branch 3 times, most recently from b93ccd3 to b008fcd Compare October 31, 2016 03:48
@ezyang
Copy link
Contributor

ezyang commented Oct 31, 2016

Appveyor failure is real. I guess some Windows specific code that is macro'd away?

Copy link
Contributor

@ezyang ezyang left a 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)
Copy link
Contributor

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.
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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)
Copy link
Contributor

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)])
Copy link
Contributor

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 :)

Copy link
Collaborator Author

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.

@Ericson2314 Ericson2314 force-pushed the unqual-component-name branch 2 times, most recently from 8271b2d to ac8ad4a Compare October 31, 2016 13:01
@Ericson2314
Copy link
Collaborator Author

No windows error seems spurious?

@ezyang
Copy link
Contributor

ezyang commented Oct 31, 2016

Yeah. For some reason Appveyor isn't letting me request a rebuild. Maybe rebase and force push to kick the build again.

@Ericson2314 Ericson2314 force-pushed the unqual-component-name branch from ac8ad4a to 63502b8 Compare October 31, 2016 18:38
@Ericson2314 Ericson2314 force-pushed the unqual-component-name branch from 63502b8 to be6a94a Compare October 31, 2016 19:16
@Ericson2314
Copy link
Collaborator Author

Hmm, for future reference it would be nice to avoid repeating the signatures of symlinkBinar{y,ies}, as only their implementations are platform-specific.

@ezyang
Copy link
Contributor

ezyang commented Oct 31, 2016

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.

@Ericson2314 Ericson2314 changed the title [WIP] Use UnqualComponentName instead of String for component names [WIP] Use UnqualComponentName newtype instead of String for component names Oct 31, 2016
@Ericson2314
Copy link
Collaborator Author

Ericson2314 commented Nov 1, 2016

Whew both passed! Cause this bitrots so quick I'm going to merge. I hope that's ok!

@Ericson2314 Ericson2314 merged commit acc460d into haskell:master Nov 1, 2016
@ezyang
Copy link
Contributor

ezyang commented Nov 1, 2016

Thank you, good work!

@ezyang ezyang added this to the 2.0 milestone Nov 1, 2016
@Ericson2314 Ericson2314 deleted the unqual-component-name branch November 1, 2016 13:07
@Ericson2314 Ericson2314 changed the title [WIP] Use UnqualComponentName newtype instead of String for component names Use UnqualComponentName newtype instead of String for component names Jan 18, 2017
@Ericson2314
Copy link
Collaborator Author

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
Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Copy link
Collaborator

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.

Copy link
Collaborator Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants