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

Scala 3 support #677

Merged
merged 15 commits into from
Dec 17, 2023
Merged

Scala 3 support #677

merged 15 commits into from
Dec 17, 2023

Conversation

hughsimpson
Copy link
Contributor

@hughsimpson hughsimpson commented Nov 28, 2023

Builds on #676 and #668 to fix compilation for scala 3.

Couple of issues (although I'm not sure if I personally consider them blockers..):

  • geom support: This makes makeBox/makeBox3d/makeLine slightly less general, although I've never used this and don't know if it's a real issue
  • bumps play-json major version reverted. Not sure why I thought I needed to do that
  • does not implement Composite support for scala 3 (I had a crack at implementing that with scala 3 inline, but ran into a wall. Probably needs full-fat macros. Personally I don't use this functionality of slick-pg at all, so I believe it's still worth merging without) Now implements composite (Struct) support for scala 3. It's a different mechanism -- requires some implicits, uses scala 3 inline -- but passes the test suite

@hughsimpson hughsimpson reopened this Nov 28, 2023
@nafg
Copy link
Contributor

nafg commented Dec 4, 2023

Is my understanding correct that scala 2 functionality remains the same and this successfully adds scala 3 support for almost everything?

@hughsimpson
Copy link
Contributor Author

hughsimpson commented Dec 4, 2023

Pretty much, the differences are clearer if you compare to #676 (which I opened to separate the bulk of the noise from the 'real' changes) but there are some differences:

  • I had to remove the DateTimeImplicits alias traits, so that'd probably break some code, but is a very quick fix.
  • There are some changes the type signature of 3 methods in the geom package, and I'm not sure whether that could impact a real-world use-case
  • Some array support has been moved from using type tags to using izumi. I believe this is fine and causes no conflict with the unmigrated Struct support however.
  • Stuff that extends Struct isn't magic any more. I didn't even know slick-pg did this. It's so cool. Anyway I think it might be encodable with inline but I haven't done it yet. Have an implementation for this now that seems to work well

It would be possible to denormalise the code further, as it were, and retain completely identical scala 2 support,. however I felt like that'd be making a rod for our own back and it was probably better to do a more sweeping change

@hughsimpson
Copy link
Contributor Author

hughsimpson commented Dec 6, 2023

Probably also worth noting that some cool fun syntax doesn't work in scala 3, so there are definitely regressions on that front too, but for the most part they're regexable.

Edit: this only applies to scala 3 but it could make upgrading some stuff more painful

@nafg
Copy link
Contributor

nafg commented Dec 6, 2023

@tminglei can you please review, merge and get this released?

@hughsimpson
Copy link
Contributor Author

What I should do is remove the Struct entirely from scala 3 to push the breaking change up to the type level

@hughsimpson
Copy link
Contributor Author

hughsimpson commented Dec 6, 2023

There we go, removed a mine hopefully

Edit: actually I'm now certain that the Struct functionality can indeed be implemented with inline and hope to push that up in the next couple of hours

implicit val RangeToString: RegisteredTypeConverter[Range[LocalDateTime], String] =
RegisteredTypeConverter(PgRangeSupportUtils.toStringFn[LocalDateTime](_.toString))
implicit val MapToString: RegisteredTypeConverter[Map[String, String], String] = RegisteredTypeConverter(mapToString)
implicit val StringToMap: RegisteredTypeConverter[String, Map[String, String]] = RegisteredTypeConverter(stringToMap)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

So this is different to scala 2 usage -- rather than 'register'ing a typetag, we need to have an appropriate implicit 'registered converter' in scope. This all boils down to the composite type being constructed at compile time rather than runtime, and I think it's actually an improvement. Sadly it does mean some inconsistency between scala 2 and scala 3 APIs, because we can't use typetags in scala 3 and can't use inline in scala 2, but hey ho them's the breaks

@hughsimpson
Copy link
Contributor Author

@tminglei are you able to take a look at this please? Happy to make changes, but would love to start the process of migrating to scala 3 and this is the last significant dependency I have that's not yet crosspublished

@@ -53,12 +53,12 @@ trait PgPostGISExtensions extends JdbcTypesComponent { driver: PostgresProfile =
case Some(p) => om.column(GeomLibrary.LineFromEncodedPolyline, encodedPolyline.toNode, LiteralNode(p))
case None => om.column(GeomLibrary.LineFromEncodedPolyline, encodedPolyline.toNode)
}
def makeBox[G1 <: GEOMETRY, P1, G2 <: GEOMETRY, P2, R](lowLeftPoint: Rep[P1], upRightPoint: Rep[P2])(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't know why we needed a second geometry subtype here... Anyway scala 3 seemed to struggle with the type inference, and rather than specifying everything I decided to simplify the signature

Copy link
Owner

Choose a reason for hiding this comment

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

@hughsimpson can't remember it exactly.
I think your changes should be ok after double checked the official docs.

@tminglei tminglei merged commit 68324de into tminglei:master Dec 17, 2023
0 of 24 checks passed
@tminglei
Copy link
Owner

@hughsimpson merged. Thanks very much! 👍

@hughsimpson hughsimpson deleted the scala_3_support branch December 17, 2023 08:57
@nafg
Copy link
Contributor

nafg commented Dec 18, 2023

@tminglei thanks! BTW I see you published to maven central, but I didn't realize it at first because there isn't an M5 tag or release on GitHub.

@tminglei
Copy link
Owner

Published.
@nafg @hughsimpson sorry for forgot to make a release on Github.

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.

3 participants