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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use explicit deriving strategies where it's ambiguous #3022

Merged
merged 1 commit into from Apr 4, 2022

Conversation

mitchellwrosen
Copy link
Member

Overview

This PR adds a few explicit stock / newtype deriving strategies where they were ambiguous before.

These clauses were previously causing warnings when loading more than one component into ghci (i.e. stack ghci), because:

  • With both DeriveAnyClass and GeneralizedNewtypeDeriving enabled, GHC emits a warning for some deriving clauses indicating that it's defaulting to DeriveAnyClass for some type classes, but you should be explicit about which strategy to use.
  • unison-parser-typechecker only has GeneralizedNewtypeDeriving enabled, but some other package(s) have DeriveAnyClass
  • When multiple components are loaded into ghci by stack ghci, it just combines all of the flags/extensions together.

With this PR, you should be able to stack ghci without warning. (Better would be to have the same set of extensions enabled in every package 馃槃)

@@ -180,3 +158,27 @@ executables:
- unison-util
- unison-util-relation
- unison-pretty-printer

Copy link
Member Author

Choose a reason for hiding this comment

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

Just moved this to the bottom because it's the most boring clause, I think. Also, I may have added an extension or two, for consistency with other packages.

Copy link
Contributor

Choose a reason for hiding this comment

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

We should consider a defaults.yaml for the monorepo for this in the future I think, you can then just import it into each package.yaml, we did it at Wire and it worked out well 馃槃

@@ -477,9 +477,13 @@ data ANormalF v e
-- Types representing components that will go into the runtime tag of
-- a data type value. RTags correspond to references, while CTags
-- correspond to constructors.
newtype RTag = RTag Word64 deriving (Eq, Ord, Show, Read, EC.EnumKey)
newtype RTag = RTag Word64
deriving stock (Eq, Ord, Show, Read)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hrmm, are you sure about the Read instance? The stock one would expect RTag 42 whereas the newtype instance would be 42; Same for CTag below;

I guess it depends on where and how this is used and whether it expects to read numbers or just requires a correct roundtrip through String.

Even if it was currently behaving as a stock instance that doesn't necessarily mean that's what Dan intended 馃

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, Read was stock-derived before and after this PR, so that'd be "RTag 42". Seems right to me, especially because of the (informal?) rule that Read should agree with Show.

Copy link
Contributor

Choose a reason for hiding this comment

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

I double-checked and these Read instances are unused (everything still compiles after removing them), I'm guessing someone just went a little derive-happy so I'd personally advocate for removing it haha.

I know the "expected" behaviour is for it to agree with Show, but in my experience using Read for anything other than primitive types is an anti-pattern, better to write a proper parser, or a String -> Either String a function IMO

Copy link
Member Author

Choose a reason for hiding this comment

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

Cool. Yeah, I don't use Read myself, but I didn't author this code originally. Let's maybe suggest removing it in another PR?

Copy link
Contributor

@ChrisPenner ChrisPenner left a comment

Choose a reason for hiding this comment

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

Double check the usage of those Read instances please, but otherwise looks good.

TBH I wish there was a "require-deriving-strategy" warning we could enable, could probably write a regex for it haha.

@mitchellwrosen
Copy link
Member Author

mitchellwrosen commented Mar 31, 2022

What do you mean check usage of the Read instances?

Edit: oh -- I see now, your other comment

@mitchellwrosen mitchellwrosen merged commit 548caae into trunk Apr 4, 2022
@mitchellwrosen mitchellwrosen deleted the 22-03-31-warning-free-ghci branch April 4, 2022 14:07
@mitchellwrosen mitchellwrosen restored the 22-03-31-warning-free-ghci branch April 4, 2022 14:07
@mitchellwrosen mitchellwrosen deleted the 22-03-31-warning-free-ghci branch April 4, 2022 14:07
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.

None yet

2 participants