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
Add Order/Hash/Show Instances For Uri And Related Types #3969
Conversation
@rossabaker so this commit breaks binary compatibility in two ways. For
It's simple enough to add that back in, though a bit gross. object Authority extends scala.runtime.AbstractFunction3[Option[UserInfo], Host, Option[Int], Authority] {
override def apply(userInfo: Option[UserInfo] = None, host: Host = RegName("localhost"), port: Option[Int] = None): Authority =
new Authority(userInfo, host, port) The binary change is the addition of the new My intuition would be to add the What are your thoughts? |
I did exactly that with an The arbitrary changes pass MiMa? Adding to traits was bad in 2.11, but I think is fine starting in 2.12 as long as there is a concrete implementation. |
@rossabaker I've updated the PR to include the
Yeah, that is my understanding as well. To be clear, MiMa does fail on them, but I don't think they are actually an issue unless http4s is still targeting 2.11.x. Thoughts? |
I usually end up regretting making MiMa exceptions. I think I understand, and then a week later, we get a bug. We already have a couple in the companion object. I think making them a trait was a mistake, and most people should be importing them. I'd be fine putting them in the companion, and we can reunify them somewhere in 1.0. |
@rossabaker sounds good. I've updated this with the new instances only in the companion object. |
4e7c6bf
to
78427b4
Compare
@rossabaker I had to make a few things |
@rossabaker as per other PRs, the failures here do not appear related to my change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree the test failures are unrelated. I did come up with a few more ideas.
@@ -82,4 +84,54 @@ package object http4s { | |||
type Http4sSyntax = syntax.AllSyntax | |||
@deprecated("Moved to org.http4s.syntax.all", "0.16") | |||
val Http4sSyntax = syntax.all | |||
|
|||
// Helper functions for writing Order instances // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We keep a lot of helpers in org.http4s.internals
, just to reduce clutter.
* and `SemigroupK[Option].combineK` have different semantics. We | ||
* ''always'' want the `SemigroupK[Option]` instance here. | ||
*/ | ||
private[http4s] def reduceComparisons( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This runs all the comparisons, right? Could we do a lazy one that only continues for as long as we get zeroes?
@@ -634,11 +638,12 @@ private[http4s] trait ArbitraryInstances { | |||
} yield Uri.Authority(maybeUserInfo, host, maybePort) | |||
} | |||
|
|||
val genPctEncoded: Gen[String] = | |||
lazy val genPctEncoded: Gen[String] = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A long, long time ago, I saw lazy arbitraries making a difference in a profile, which caused us to use eager vals. I don't know whether that's still a concern, but I think you could just by moving them above the new use.
Whether eager values are smart in a trait is a separate question.
I'm fine either way.
@rossabaker Updated. I moved the helpers into the |
This commit adds `Order`, `Hash`, and `Show` instances for the following types. * `org.http4s.Uri.Authority` * `org.http4s.Query` * `org.http4s.Uri.Host` * `org.http4s.Uri.RegName` * `org.http4s.Uri` The impetus for all of them was to support instances for `org.http4s.Uri`. In addition, two functions were added to the package object `org.http4s.internal` scoped to be private to `http4s`, `compareField`, `reduceComparisons_`, and `reduceComparisons`. These functions substantially reduce the amount of code required to write `Order` instances for Product types. In order to support testing the laws for these types, several new instances of `Arbitrary` and `Cogen` were added, as not all types had instances for each of these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rossabaker I saw this was missing an import after the merge with for the implicits <-> syntax change. I've updated the branch. |
I gambled and merged in the browser last night without compiling. Thanks for the mop-up! |
This commit adds
Order
,Hash
, andShow
instances for the following types.org.http4s.Uri.Authority
org.http4s.Query
org.http4s.Uri.Host
org.http4s.Uri.RegName
org.http4s.Uri
The impetus for all of them was to support instances for
org.http4s.Uri
.In addition, two functions were added to the package object
org.http4s.internal
scoped to be private tohttp4s
,compareField
,reduceComparisons_
, andreduceComparisons
.These functions substantially reduce the amount of code required to write
Order
instances for Product types.In order to support testing the laws for these types, several new instances of
Arbitrary
andCogen
were added, as not all types had instances for each of these.