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

Fix #4986, and extra refactoring #4991

Merged
merged 5 commits into from
Jan 3, 2018
Merged

Fix #4986, and extra refactoring #4991

merged 5 commits into from
Jan 3, 2018

Conversation

ezyang
Copy link
Contributor

@ezyang ezyang commented Jan 1, 2018

Please include the following checklist in your PR:

  • Patches conform to the coding conventions.
  • Any changes that could be relevant to users have been recorded in the changelog.
  • The documentation has been updated, if necessary.
  • If the change is docs-only, [ci skip] is used to avoid triggering the build bots.

Please also shortly describe how you tested your change. Bonus points for added tests!

Added test for the bugfix

@phadej
Copy link
Collaborator

phadej commented Jan 2, 2018

I have uneasy feeling about re-using Pretty for this. The idea is to use Pretty to display data to user. For debugging we could use Show but it's not pretty. I propose adding PShow class, and define show = pshow. I can make a PR soon. This can go in as is, but I will revert Pretty related commits

@ezyang
Copy link
Contributor Author

ezyang commented Jan 2, 2018

@phadej Show is not all that appropriate either, because conventionally the Show instance of a datatype is intended to be valid Haskell, and I don't necessarily want to force Pretty-printed variants of types to be valid Haskell; a very simple case where this would be extremely annoying are newtypes of Text, where barfing out the constructor name would be a big problem for readability. So I'm 👎 on PShow, but 👍 for Outputable. I guess I'll add that class...

@phadej
Copy link
Collaborator

phadej commented Jan 2, 2018 via email

@phadej
Copy link
Collaborator

phadej commented Jan 2, 2018

FWIW PShow can have Generic implementation, taking into account newtypes and records!

A note about composability: parens!

@BardurArantsson
Copy link
Collaborator

Seems like outputting somethink S-expression-like would be pretty trivial and sufficient for debugging?

@ezyang
Copy link
Contributor Author

ezyang commented Jan 3, 2018

I force-pushed the reduced patch set, without updated asserts or pretty-printing.

Given IsString, PShow could be a little "reality twister".

I don't know what you mean by this. Are you suggesting that a PackageName can acceptably render as "pkgname", because -XOverloadedStrings can interpret this as a PackageName?

But there are still situations where Haskell syntax is unacceptably verbose, and there is no way to "hack" it with OverloadedStrings. One example that came up in the patchset:

-- | A ConfiguredId is a package ID for a configured package.
--
-- Once we configure a source package we know its UnitId. It is still
-- however useful in lots of places to also know the source ID for the package.
-- We therefore bundle the two.
--
-- An already installed package of course is also "configured" (all its
-- configuration parameters and dependencies have been specified).
data ConfiguredId = ConfiguredId {
    confSrcId  :: PackageId
  , confCompName :: Maybe ComponentName
  , confInstId :: ComponentId
  }
  deriving (Eq, Ord, Generic)

By default, I'd like ConfiguredId to render as just its ComponentId, since that canonically identifies a ConfiguredId. However, if I am debugging corrupt ConfiguredId metadata, I might also like to display the confSrcId, confCompName. In GHC, the way we do this is we render x by default, but x{some metadata} if you turn on -dppr-debug. I think this behavior is quite useful and I'd like it to apply to Cabal too.

Cabal-like syntax is compact, but it doesn't compose well.

With pretty-printing, this is not true; indentation is all you need. To take your example of [PackageDescription], with pretty-printing it with the default list renderer will cause it to look something like this:

[name: foo
 field: 1
 field: 2,
 name: bar
 field: 3
 field: 4]

Which is basically as good as you're going to get with Haskell-style list syntax with multi-line elements. Or you be a bit more clever and have a different format:

- name: foo
  field: 1
  field: 2
- name: bar
  field: 3
  field: 4

Indentation is great! And it is much easier to parse than parentheses.

P.S. Also, why do I care so much about conciseness? Because if I'm debugging I'm going to have to read all of this information, and it is far easier to understand what is going on if a single ElaboratedConfiguredPackage can fit in a few lines, rather than multiple pages.

ezyang added 5 commits January 2, 2018 21:54
Previously, if you had:

  build-tool-depends: happy:happy
  build-tools: happy

This would cause an executable dependency to show up twice in exe_deps.
It turns out that this made its way all the way to cabal-install's
InstallPlan, and then broke an invariant in the install plan execution
engine.  This is the "correct" fix but the whole arrangement is a little
brittle.

Signed-off-by: Edward Z. Yang <[email protected]>
Signed-off-by: Edward Z. Yang <[email protected]>
…isplay.

Before:
    In order, the following would be built (use -v for more details):
     - Cabal-2.1.0.0 (lib) --enable-library-profiling (first run)

After:
    In order, the following would be built (use -v for more details):
     - Cabal-2.1.0.0 (lib) (first run)

Signed-off-by: Edward Z. Yang <[email protected]>
Before: pkgStanzasEnabled is initialized to an empty list and
filled in on the first pruning pass.

After: pkgStanzasEnabled is initialized to the set of explicitly
requested stanzas, and then we add more enabled stanzas as we
do "pruning" passes (a bit of a misnomer).

Why is it good?  Now we always satisfy the invariant that
the set of enabled stanzas is a superset of the set of requested
stanzas; previously, the invariant was broken up until the point
you ran pruning (which, in the case of new-configure, meant that
the invariant was always broken!)  and we were tripping over this
when attempting to render the set of configure flags for plan
display.

Signed-off-by: Edward Z. Yang <[email protected]>
@ezyang ezyang force-pushed the pr/T4986 branch 2 times, most recently from d0e6daf to 1f00ad8 Compare January 3, 2018 02:54
@ezyang ezyang mentioned this pull request Jan 3, 2018
4 tasks
Copy link
Member

@23Skidoo 23Skidoo left a comment

Choose a reason for hiding this comment

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

LGTM.

@23Skidoo 23Skidoo merged commit 6e42aa2 into haskell:master Jan 3, 2018
@23Skidoo
Copy link
Member

23Skidoo commented Jan 3, 2018

Merged, thanks!

@23Skidoo 23Skidoo mentioned this pull request Feb 7, 2018
@23Skidoo
Copy link
Member

23Skidoo commented Feb 8, 2018

Cherry-picked the first four commits into 2.0.

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.

4 participants