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

Port tests to Dotty #3552

Closed
wants to merge 14 commits into from
Closed

Port tests to Dotty #3552

wants to merge 14 commits into from

Conversation

LukaJCB
Copy link
Member

@LukaJCB LukaJCB commented Aug 6, 2020

No description provided.

@@ -10,3 +10,4 @@ docstrings = JavaDoc
newlines.afterCurlyLambda = preserve
docstrings.style = Asterisk
docstrings.oneline = unfold
project.excludeFilters = [ "core/src/main/scala-3.x" ]
Copy link
Member Author

Choose a reason for hiding this comment

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

scalafmt can't deal with dotty syntax yet.


import cats.{Monad, Alternative}

final class MonadOps[F[_], A](private val fa: F[A]) extends AnyVal {
Copy link
Member Author

Choose a reason for hiding this comment

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

Had to split this out due to scala/scala3#9480

Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this flip the order of parameters though? That could be moderately source-incompatible. More importantly, it's inconsistent with the other syntax classes.

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 actually don't know how dotty compiles this down. Is explicitly still a thing? Do you have a suggestion on how to fix this given the limitation above?

Copy link
Member

Choose a reason for hiding this comment

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

I would summon @smarter actually if I hit this. Probably worth looking at the bytecode quickly to see what the parameter order is. Can we simply put the using block second?

Copy link
Contributor

Choose a reason for hiding this comment

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

It's source-compatible (to explicitly pass parameters to a using block, you have to write using at use-site in front of the block too). I suggested putting the using block first because doing the implicit search requires instantiating type variables which in turns means that in increment.whileM_(inspect(i => i > 4)).run(3) we can figure out that i needs to be Int, see scala/scala3#9480 (comment) for the full explanation.

Copy link
Contributor

Choose a reason for hiding this comment

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

That would increase the maintenance burden though. But if you did want to rewrite all the ops classes for dotty, then you might as well use extension syntax which would look more natural:

extension [F[_], A](fa: F[A])(using M: Monad[F]) {
  def whileM_(p: F[Boolean]): F[Unit] = ???
  def untilM(...)
}

Copy link
Member

Choose a reason for hiding this comment

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

I'm just concerned that we're going to end up hitting something like this again in the future, but once we release on Dotty, we can't futz with the binary compatibility any further.

Copy link
Contributor

Choose a reason for hiding this comment

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

Well, you can break BC every time we break BC which is every six weeks until 3.0 is out probably, but afterwards it gets tricky yeah :) (though I guess you can always play trick with something like a package-protected overload to preserve BC?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Are we promising binary compatibility for dotty artifacts? Should we? (We certainly don't test it yet)

Copy link
Member

Choose a reason for hiding this comment

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

I don't think we're promising BC until Scala 3 goes final. Once it does though, we 100% should be promising it.

@@ -122,7 +122,6 @@ object Invariant extends ScalaVersionSpecificInvariantInstances with InvariantIn
implicit def catsFlatMapForSortedMap[K]: FlatMap[SortedMap[K, *]] =
cats.instances.sortedMap.catsStdInstancesForSortedMap[K]
implicit def catsBimonadForFunction0: Bimonad[Function0] = cats.instances.function.catsStdBimonadForFunction0
implicit def catsMonadForFunction1[I]: Monad[I => *] = cats.instances.function.catsStdMonadForFunction1[I]
Copy link
Member Author

Choose a reason for hiding this comment

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

Moved this down because dotty thinks Monad[List] and Monad[Function1[Int, *]] are ambiguous

implicit def catsCommutativeFlatMapForTuple2[X](implicit X: CommutativeSemigroup[X]): CommutativeFlatMap[(X, *)] =
cats.instances.tuple.catsStdCommutativeFlatMapForTuple2[X]

implicit def catsApplicativeForArrow[F[_, _], A](implicit F: Arrow[F]): Applicative[F[A, *]] =
Copy link
Member Author

Choose a reason for hiding this comment

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

Same with this one

@@ -10,6 +10,7 @@ import cats.syntax.parallel._
import cats.syntax.traverse._
import cats.syntax.eq._
import org.scalacheck.Prop._
import cats.catsInstancesForId
Copy link
Member Author

Choose a reason for hiding this comment

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

Id instances are no longer automatically in scope in dotty.

@@ -506,7 +509,7 @@ class IndexedStateTSuite extends CatsSuite {
Alternative[IndexedStateT[ListWrapper, Int, Int, *]]
Applicative[IndexedStateT[ListWrapper, Int, Int, *]]
Apply[IndexedStateT[ListWrapper, Int, Int, *]]
Functor[IndexedStateT[ListWrapper, Int, Int, *]]
//Functor[IndexedStateT[ListWrapper, Int, Int, *]]
Copy link
Member Author

Choose a reason for hiding this comment

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

Ambiguous here because both G and F are Functors

@@ -536,7 +536,7 @@ class OptionTSuite extends CatsSuite {
Traverse[OptionT[List, *]]

implicit val T: Traverse[ListWrapper] = ListWrapper.traverse
implicit val M: Monad[ListWrapper] = ListWrapper.monad
//implicit val M: Monad[ListWrapper] = ListWrapper.monad
Copy link
Member Author

Choose a reason for hiding this comment

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

Same here

@@ -88,34 +83,37 @@ class ParallelSuite extends CatsSuite with ApplicativeErrorForEitherTest with Sc
}
}

type ListTuple2[A, B] = List[(A, B)]
case class ListTuple2[A, B](value: List[(A, B)])
Copy link
Member Author

Choose a reason for hiding this comment

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

Had to turn this into a case class for it to work

@@ -131,14 +131,14 @@ class ReducibleSuiteAdditional extends CatsSuite {
val n = 100000
val xs = NES(0, Stream.from(1))

assert(xs.reduceMapM(i => if (i < n) Right(i) else Left(i)) === Left(n))
assert(xs.reduceMapM(i => if (i < n) i.asRight[Int] else i.asLeft[Int]) === Left(n))
Copy link
Member Author

Choose a reason for hiding this comment

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

@djspiewak djspiewak self-requested a review August 17, 2020 19:49
@@ -61,7 +61,7 @@ class ApplicativeErrorSuite extends CatsSuite {
assert(compileErrors("e2.attemptNarrow[Num]").nonEmpty)

val e3: Either[List[T[String]], Unit] = List(Str).asLeft[Unit]
assert(compileErrors("e3.attemptNarrow[List[Str.type]]").nonEmpty)
//assertEquals(compileErrors("e3.attemptNarrow[List[Str.type]]"), "")
Copy link
Member Author

Choose a reason for hiding this comment

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

This is an odd one, because when I try it in the console it gives me an error but munit returns an empty string here

/**
* Placed here to work around scala/bug#6260 on scala 2.10
*/
test("#1802 duplicated method name") {
Copy link
Member Author

Choose a reason for hiding this comment

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

Deleted this for now, since it was giving me an error and seems like this is pretty old

@@ -103,7 +103,7 @@ class RegressionSuite extends CatsSuite with ScalaVersionSpecificRegressionSuite

test("#500: foldMap - traverse consistency") {
assert(
List(1, 2, 3).traverse(i => Const.of[List[Int]](List(i))).getConst == List(1, 2, 3).foldMap(List(_))
List(1, 2, 3).traverse(i => Const[List[Int], List[Int]](List(i))).getConst == List(1, 2, 3).foldMap(List(_))
Copy link
Member Author

Choose a reason for hiding this comment

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

Dotty was inferring Int => Int, I'll try to reach out to the dotty team on how to get this working

@codecov-commenter
Copy link

codecov-commenter commented Sep 8, 2020

Codecov Report

Merging #3552 into master will decrease coverage by 0.05%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #3552      +/-   ##
==========================================
- Coverage   91.33%   91.27%   -0.06%     
==========================================
  Files         386      386              
  Lines        8628     8611      -17     
  Branches      260      269       +9     
==========================================
- Hits         7880     7860      -20     
- Misses        748      751       +3     

@LukaJCB LukaJCB marked this pull request as ready for review September 8, 2020 15:46

import cats.{Monad, Alternative}

final class MonadOps[F[_], A](private val fa: F[A]) extends AnyVal {
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this flip the order of parameters though? That could be moderately source-incompatible. More importantly, it's inconsistent with the other syntax classes.

onFlatMapped: ((S[X], X => Free[S, A]) forSome { type X }) => B
onFlatMapped: ((S[Any], Any => Free[S, A])) => B
Copy link
Member

Choose a reason for hiding this comment

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

Isn't foldStep public? This would be a rather drastic change if so. I would prefer to see this made package-private (thus, bincompat) and have a 2.0-specific enrichment which uses forSome in this skolem rank, while a 3.0-specific enrichment uses a higher-rank universal to achieve the same thing.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is bincompat due to type erasure, but I believe having separate sources here is probably a good idea 👍

Copy link
Member

Choose a reason for hiding this comment

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

It's definitely bincompat, I was mostly just concerned about the loss of type safety in a public-facing API.

@LukaJCB LukaJCB requested a review from djspiewak September 14, 2020 17:29
@LukaJCB
Copy link
Member Author

LukaJCB commented Sep 14, 2020

Seeing a new failure now, opened a bug report at scala/scala3#9793

@larsrh
Copy link
Contributor

larsrh commented Oct 17, 2020

This appears to be fixed in scala/scala3#9937, which is scheduled for 3.0.0-M1, so I guess we'll have to wait for that.

@larsrh
Copy link
Contributor

larsrh commented Oct 17, 2020

I just realized that the milestone date is end of year 😬 Maybe let's try this instead: 300a9cd

@codecov-io
Copy link

Codecov Report

Merging #3552 into master will decrease coverage by 0.04%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #3552      +/-   ##
==========================================
- Coverage   91.33%   91.29%   -0.05%     
==========================================
  Files         386      386              
  Lines        8628     8611      -17     
  Branches      260      257       -3     
==========================================
- Hits         7880     7861      -19     
- Misses        748      750       +2     

@smarter
Copy link
Contributor

smarter commented Oct 17, 2020

M1 should be out next week, the milestone date hasn't been updated

@larsrh
Copy link
Contributor

larsrh commented Oct 17, 2020

I made a new PR that is up-to-date: #3636. Obviously we can continue the discussion there.

@larsrh larsrh closed this Oct 17, 2020
@larsrh larsrh deleted the dotty-tests branch October 17, 2020 10:32
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.

6 participants