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 kernel laws consistent with core laws #1922

Merged
merged 21 commits into from
Oct 6, 2017

Conversation

LukaJCB
Copy link
Member

@LukaJCB LukaJCB commented Sep 20, 2017

Should fix #1272, still a WIP, but compiles and runs so looking for some feedback on some of the decisions made when porting between styles :)

@LukaJCB LukaJCB force-pushed the make-kernel-laws-consistent branch 2 times, most recently from d66e8a7 to 29f9434 Compare September 21, 2017 07:25
@codecov-io
Copy link

codecov-io commented Sep 21, 2017

Codecov Report

Merging #1922 into master will increase coverage by 0.53%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1922      +/-   ##
==========================================
+ Coverage    95.6%   96.13%   +0.53%     
==========================================
  Files         252      273      +21     
  Lines        4570     4530      -40     
  Branches      124      116       -8     
==========================================
- Hits         4369     4355      -14     
+ Misses        201      175      -26
Impacted Files Coverage Δ
...main/scala/cats/kernel/laws/SerializableLaws.scala 93.75% <ø> (ø)
.../src/main/scala/cats/kernel/instances/option.scala 100% <ø> (ø) ⬆️
...ats/kernel/laws/discipline/SerializableTests.scala 100% <ø> (ø)
...ats/kernel/laws/discipline/SemigroupLawTests.scala 100% <100%> (ø)
.../scala/cats/kernel/laws/discipline/BandTests.scala 100% <100%> (ø)
...cats/kernel/laws/discipline/SemilatticeTests.scala 100% <100%> (ø)
...la/cats/kernel/laws/discipline/OrderLawTests.scala 100% <100%> (ø)
...ws/src/main/scala/cats/kernel/laws/OrderLaws.scala 100% <100%> (ø) ⬆️
laws/src/main/scala/cats/laws/package.scala 100% <100%> (ø) ⬆️
.../src/main/scala/cats/laws/discipline/package.scala 100% <100%> (ø) ⬆️
... and 54 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4ffd3a1...668c4e1. Read the comment docs.

@LukaJCB LukaJCB force-pushed the make-kernel-laws-consistent branch 3 times, most recently from 7785850 to 0616d9b Compare September 22, 2017 09:58
@LukaJCB
Copy link
Member Author

LukaJCB commented Sep 22, 2017

I moved most of the machinery from cats.laws.* to cats.kernel.laws.*, including IsEq, SerializableLaws and SerializableTests. By doing so, I removed the seperate IsSerializable object, as I considered the test inside to be equivalent to the one inside SerializableLaws (Please correct me here if I'm wrong)

Otherwise I'm pretty much done with this :)

@johnynek
Copy link
Contributor

note algebra-laws do depend on this, so we will need to fix algebra before it can be updated after this is published:

https://github.com/typelevel/algebra/blob/master/build.sbt#L143

@LukaJCB
Copy link
Member Author

LukaJCB commented Sep 23, 2017

I'll create a PR :)

def laws: BoundedSemilatticeLaws[A]

def boundedSemilattice(implicit arbA: Arbitrary[A], eqA: Eq[A]): RuleSet =
new RuleSet {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: most of these new RuleSet { where bases is empty could be just new DefaultRuleSet( right like the one you used in BandTests? No big deal though, just that it could be slightly more concise.

Copy link
Member Author

Choose a reason for hiding this comment

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

That doesn't work for Typeclasses with more than one parent though, no?

Copy link
Contributor

Choose a reason for hiding this comment

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

I didn't realize that. disregard my comment then. Maybe we can create one that does in discipline later.

import org.scalacheck.{Arbitrary, Prop}
import cats.kernel.instances.boolean._

object Rules {
Copy link
Contributor

Choose a reason for hiding this comment

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

This setup is indeed less readable than the cats.core way.

@@ -1,7 +1,7 @@
package cats
package tests

import cats.kernel.laws.GroupLaws
import cats.kernel.laws.discipline.{MonoidTests => MonoidTypeclassTests}
Copy link
Contributor

Choose a reason for hiding this comment

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

Another nit: Maybe we can call these MonoidLawTests, because the other MonoidTest is also testing the Type Class.


import cats.kernel.Monoid

trait MonoidLaws[A] extends SemigroupLaws[A] {
Copy link
Contributor

Choose a reason for hiding this comment

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

I couldn't find the replacement for Rules.isId("isEmpty", A.empty)(A.isEmpty)?

new RuleSet {
val name: String = "boundedSemilattice"
val bases: Seq[(String, RuleSet)] = Nil
val parents: Seq[RuleSet] = Seq(commutativeSemigroup, band)
Copy link
Contributor

Choose a reason for hiding this comment

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

should this be communtativeMonoid, semilattice instead?

override implicit def E: PartialOrder[A]

def reflexitivity(x: A): IsEq[Boolean] =
E.gteqv(x, x) <-> true
Copy link
Contributor

Choose a reason for hiding this comment

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

the original test uses ?<=, i.e. E.lteqv, I am not sure if it matters. (mabye we can have both lteqv and gteqv?)

kailuowang
kailuowang previously approved these changes Oct 4, 2017
@@ -45,7 +44,6 @@ class FunctionTests extends CatsSuite {
checkAll("Function0[Eqed]", EqLawTests[Function0[Eqed]].eqv)
checkAll("Function0[POrd]", PartialOrderLawTests[Function0[POrd]].partialOrder)
checkAll("Function0[Ord]", OrderLawTests[Function0[Ord]].order)
checkAll("Function0[Hsh]", HashLaws[Function0[Hsh]].hash)
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, was this test removed intentionally?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch, I removed it initially for erroring for erroring out, as with the new setup, all the laws are tested and you can't single out one specific law to run. I wanted to replace it with a manual test, but forgot, will fix :)

@LukaJCB LukaJCB force-pushed the make-kernel-laws-consistent branch from d3464b1 to 8dbbb81 Compare October 4, 2017 15:58
@LukaJCB
Copy link
Member Author

LukaJCB commented Oct 4, 2017

I added another MiMa exception as I had to reshuffle the option instances :)

@@ -54,6 +55,13 @@ class FunctionTests extends CatsSuite {
checkAll("Function0[Grp]", GroupLawTests[Function0[Grp]].group)
checkAll("Function0[CGrp]", CommutativeGroupTests[Function0[CGrp]].commutativeGroup)

test("Function0[Hsh]") {
Copy link
Contributor

Choose a reason for hiding this comment

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

just curious why not just test the hash law? won't pass?

checkAll("Function0[Grp]", GroupLawTests[Function0[Grp]].group)
checkAll("Function0[CGrp]", CommutativeGroupTests[Function0[CGrp]].commutativeGroup)

test("Function0[Hsh]") {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just curious, why not just test the full HashLaw? won't pass?

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, it's not the same as universal hash and not the same as scala.util.Hashing

@@ -3,17 +3,19 @@ package instances

package object option extends OptionInstances

trait OptionInstances extends OptionInstances1 {
trait OptionInstances extends OptionInstances2 {
Copy link
Contributor

Choose a reason for hiding this comment

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

since we are reshuffling the number here, how about the we fix the priority number in one go? should be in the ascending order. BTW, @johnynek is this break okay?

Copy link
Member Author

Choose a reason for hiding this comment

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

I renamed the numbers :) Btw, I think this break is an oversight from the Hash PR, as PartialOrder and Hash instances had the same priority and both extend Eq, so it led to ambiguous implicits when requiring Eq for Option

@kailuowang
Copy link
Contributor

kailuowang commented Oct 5, 2017

filter with: ProblemFilters.exclude[UpdateForwarderBodyProblem]("cats.kernel.instances.OptionInstances0.catsKernelStdEqForOption")
filter with: ProblemFilters.exclude[ReversedMissingMethodProblem]("cats.kernel.instances.OptionInstances0.catsKernelStdPartialOrderForOption")
filter with: ProblemFilters.exclude[InheritedNewAbstractMethodProblem]("cats.kernel.instances.OptionInstances1.catsKernelStdHashForOption")
 filter with: ProblemFilters.exclude[MissingTypesProblem]("cats.kernel.instances.OptionInstances1")

@LukaJCB LukaJCB force-pushed the make-kernel-laws-consistent branch from 2a33438 to d82b447 Compare October 5, 2017 13:19
@LukaJCB
Copy link
Member Author

LukaJCB commented Oct 5, 2017

Thanks @kailuowang! Fixed it :)

@LukaJCB LukaJCB force-pushed the make-kernel-laws-consistent branch from d82b447 to fb163f3 Compare October 5, 2017 13:58
@LukaJCB LukaJCB force-pushed the make-kernel-laws-consistent branch from fb163f3 to 1ca0ecd Compare October 5, 2017 13:58
kailuowang
kailuowang previously approved these changes Oct 5, 2017
@kailuowang
Copy link
Contributor

sorry, more merge needed.

@LukaJCB
Copy link
Member Author

LukaJCB commented Oct 6, 2017

No worries, done :)

Copy link
Contributor

@johnynek johnynek left a comment

Choose a reason for hiding this comment

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

Thanks for doing this huge job. This is a great service to cats and I appreciate it.

* Object with a dynamic variable that allows users to skip the
* serialization tests for certain instances.
*/
private[laws] object IsSerializable {
Copy link
Contributor

Choose a reason for hiding this comment

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

did we lose this test entirely?

It is very important for spark and scalding (and others).

Copy link
Contributor

Choose a reason for hiding this comment

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

No, it's replaced by the SerializableLaws moved from cats.tests

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@kailuowang kailuowang merged commit 9ae4dc4 into typelevel:master Oct 6, 2017
@adelbertc
Copy link
Contributor

Oh damn just saw this @LukaJCB - you the man!

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

Successfully merging this pull request may close these issues.

Make cats-kernel law organization consistent with cats-core
6 participants