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

Bump scala 3.5.0 rc3 and adapt to new implicit resolution rules #15664

Merged
merged 15 commits into from
Jul 7, 2024

Conversation

lenguyenthanh
Copy link
Member

@lenguyenthanh lenguyenthanh commented Jul 6, 2024

Use -source:3.6-migration to make sure We're compatible with implicit resolution changes which will happen in 3.6 (in 3.5 compiler just emit (possibly false positive (ex: scala/scala3#21036) warnings.

There are some changes in db.Handlers that are required the snippet below will not compiled due to: scala/scala3#19300

//> using scala 3.5.0-RC3
//> using dep "org.reactivemongo::reactivemongo-bson-api:1.1.0-RC12"
//> using options -source:3.6-migration

import reactivemongo.api.bson.*


val x = summon[BSONHandler[Map[String, String]]]

required: lichess-org/scalalib#41

This is a draft version, I'll need to review and add more comment/context before merging.
Also please comment & review

There is a conflict between opaqueHandler and userIdOfWriter for UserId
Both are sastify for BSONWriter[UserId]. In this case of conflicting,
before 3.5 the compiler will pick the more specific type (in this case
opaqueHandler: BSONHandler[UserId] because it's more specific than
BSONWriter[UserId]). In 3.6 they will flip the priority, a.k.a pic the
most general. So, this specific case doesn't really affect us. But
removing implicit ambiguity is good anyway I guess.

More detail on the implicit resolution change here:
scala/scala3#19300
With Writer is limited by NoDbHandler[T] but Reader is always
available. This fixes situation like `UserName` which writer is
provider by userIdOfWrite and only need Reader from opaque reader.
@ornicar
Copy link
Collaborator

ornicar commented Jul 6, 2024

scalalib 11.2.3 published

@ornicar
Copy link
Collaborator

ornicar commented Jul 6, 2024

scalachess 16.0.9 is missing

@lenguyenthanh
Copy link
Member Author

oops, I'll publish 16.0.9

@lenguyenthanh lenguyenthanh force-pushed the 3.5.0-rc3 branch 3 times, most recently from 0460bc9 to 9162681 Compare July 7, 2024 09:51
@lenguyenthanh lenguyenthanh changed the title Bum scala 3.5.0 rc3 and fix a lot of implicit resolution Bum scala 3.5.0 rc3 and adapt to the new implicit resolution rules Jul 7, 2024
@@ -23,6 +25,12 @@ case class UserLine(

def isLichess = userId.is(UserId.lichess)

object UserLine:
private[chat] given BSONHandler[UserLine] = BSONStringHandler.as[UserLine](
Copy link
Member Author

Choose a reason for hiding this comment

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

Split this from Line object, otherwise it'll be BSONHandler[UserLine] and BSONHandler[Line] are ambiguous.


given listHandler[T: BSONHandler]: BSONHandler[List[T]] with
Copy link
Member Author

Choose a reason for hiding this comment

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

From scala/scala3#19300, compiler will pick the most general given instance: https://github.com/scala/scala3/pull/19300/files#diff-b961213fc5ea62f83ece999f7275ee195fed5a57e4f1c4e6b39dc9d7232a7a90R169. So listHandler will never be picked over reactivemongo collectionWriter. Similar for vectorHandler.

inline def writeTry(u: U) = writer.writeTry(u.id)

given noOpaqueUserId[A: lila.core.userId.OpaqueUserId]: NoDbHandler[A] with {}
given noUserIdOf[A: lila.core.userId.UserIdOf]: NoDbHandler[A] with {}
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 removing BSONWriter instance for an
OpaqueUserId is used to get BSONWriter instance from UserIdOf and as newtypes instance, which was fine before and should be fine in 3.6 as well but removing ambiguity is a good thing I guess.

@@ -108,18 +111,18 @@ trait Handlers:
leftHandler.readTry(bson).map(Left.apply).orElse(rightHandler.readTry(bson).map(Right.apply))
def writeTry(e: Either[L, R]) = e.fold(leftHandler.writeTry, rightHandler.writeTry)

def stringMapHandler[V](using
Copy link
Member Author

Choose a reason for hiding this comment

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

reactivemongo provides mapWriter/Reader and collectionWriter/Reader which are both valid instance for Map[String, V], and now it is illegal in 3.6.
With new implement of mapHandler We use mapWriter and mapReader directly which avoid the issue.

@@ -47,7 +47,7 @@ object BuildSettings {
"-Ybackend-parallelism:16", // https://github.com/scala/scala3/pull/15392
// "-nowarn", // during migration
// "-rewrite",
// "-source:3.4-migration",
"-source:3.6-migration",
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 to avoid false positive warning: scala/scala3#21036, and force me to fix implicit ambiguity issue.

@lenguyenthanh lenguyenthanh marked this pull request as ready for review July 7, 2024 10:29
@lenguyenthanh lenguyenthanh changed the title Bum scala 3.5.0 rc3 and adapt to the new implicit resolution rules Bum scala 3.5.0 rc3 and adapt to new implicit resolution rules Jul 7, 2024
@ornicar ornicar changed the title Bum scala 3.5.0 rc3 and adapt to new implicit resolution rules Bump scala 3.5.0 rc3 and adapt to new implicit resolution rules Jul 7, 2024
@ornicar ornicar merged commit 97daf06 into lichess-org:master Jul 7, 2024
4 checks passed
@lenguyenthanh lenguyenthanh deleted the 3.5.0-rc3 branch July 7, 2024 14:54
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.

2 participants