Skip to content
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

Make package names more similar to the rule name. #246

Merged
merged 4 commits into from
May 16, 2018
Merged

Conversation

judah
Copy link
Collaborator

@judah judah commented May 15, 2018

As of #222, both the package name and ID are z-encoded. However,
GHC only needs the package ID to be unique, as long as you
call -package-id instead of -package. As a result we can
simplify how package-names are encoded: we can keep them the same
as the rule name, other than fixing underscores.

In addition to (I think) making error messages nicer, this paves the way for
some improvements in Hazel (or similar tools), now that the rule and package
names can be identical:

  • It helps support the PackageImports extension.
  • GHC >= 8.0 generates the Cabal macros (e.g., MIN_VERSION_*) automatically.

Prebuilt dependencies are still passed with -package since their IDs are internal details of GHC.

@judah judah force-pushed the package-imports branch from b79ca92 to e480182 Compare May 15, 2018 02:14
As of #222, both the package name and ID are z-encoded.  However,
GHC only needs the package *ID* to be unique, as long as you
call `-package-id` instead of `-package`.  As a result we can
simplify how package-names are encoded: we can keep them the same
as the rule name, other than fixing underscores.

In addition to (I think) making error messages nicer, this paves the way for
some improvements in Hazel (or similar tools), now that the rule and package
names can be identical:
- It helps support the PackageImports extension.
- GHC >= 8.0 generates the Cabal macros (e.g., `MIN_VERSION_*`) automatically.

Prebuilt dependencies are still passed with `-package` since their IDs
are internal details of GHC.
@judah judah force-pushed the package-imports branch from e480182 to fb6b7c4 Compare May 15, 2018 04:34
@judah judah requested review from mrkkrp and mboes May 15, 2018 04:34
judah added a commit to FormationAI/hazel that referenced this pull request May 15, 2018
It turns out they're generated automatically by GHC since version 8.0,
as long as we pass the right package name and version.  That's now possible
as of tweag/rules_haskell#246.

I'll hold off merging this PR until that one goes in, then I'll rebase to
`rules_haskell` master.
judah added a commit to FormationAI/hazel that referenced this pull request May 15, 2018
It turns out they're generated automatically by GHC since version 8.0,
as long as we pass the right package name and version.  That's now possible
as of tweag/rules_haskell#246.

I'll hold off merging this PR until that one goes in, then I'll rebase to
`rules_haskell` master.
judah added a commit to FormationAI/hazel that referenced this pull request May 15, 2018
It turns out they're generated automatically by GHC since version 8.0,
as long as we pass the right package name and version.  That's now possible
as of tweag/rules_haskell#246.

I'll hold off merging this PR until that one goes in, then I'll rebase to
`rules_haskell` master.
Copy link
Member

@mboes mboes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, LGTM. Only change I'd prefer to see is a nicer encoding for underscores given that this will appear in source code, or even no encoding at all.

As it stands, the current implementation of the package name encoding isn't injective anyways.

@@ -866,35 +862,41 @@ def _zencode(s):
return s.replace("Z", "ZZ").replace("_", "ZU").replace("/", "ZS")

def get_pkg_name(ctx):
"""Get package name. Package name includes Bazel package and name of the
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You point out that funny package names won't just be visible in documentation, but much worse, in source code too (if using -XPackageImports). Funny names in documentation is less bad because if the names change, nothing breaks. Fortunately, we can separate package-id from package-name, it's just that underscores are still illegal.

If so then I'd lean towards banning underscores outright. That way no encoding necessary, no funny names in package imports. Either that or s/_/-/, which yes, is technically a non-injective encoding, but since package names don't need to be unique (only package-id's), that should be ok. And it lets users keep to Bazel-conventional package naming style if desired (i.e. underscores everywhere, no hyphens).

Copy link
Member

@mrkkrp mrkkrp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a few minor issues.

"""Get package name.

The name is not required to be unique/injective; however it must be a valid
GHC package name (i.e., no underscores). This encoding is not aims to
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"does not aim"?

haskell/cc.bzl Outdated
@@ -187,6 +187,7 @@ def _cc_haskell_import(ctx):
if dbin != None:
set.mutable_insert(dyn_libs, dbin)

print(dyn_libs)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be removed?

@@ -15,7 +15,7 @@ HaskellBuildInfo = provider(
HaskellLibraryInfo = provider(
doc = "Library-specific information.",
fields = {
"package_name": "Package name, usually of the form name-version.",
"package_id": "Package name, usually of the form name-version.",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say "package id" here?

@mboes mboes merged commit 0340f38 into master May 16, 2018
@mboes mboes deleted the package-imports branch May 16, 2018 06:59
judah added a commit to FormationAI/hazel that referenced this pull request May 17, 2018
It turns out they're generated automatically by GHC since version 8.0,
as long as we pass the right package name and version.  That's now possible
as of tweag/rules_haskell#246.  (So bump `rules_haskell` accordingly.)

Also add network back since the new `rules_haskell` handles `cc_library` `defines` attributes better.
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.

3 participants