com-lihaoyi / scalasql

Scala ORM to query SQL databases from Scala via concise, type-safe, and familiar case classes and collection operations. Connects to Postgres, MySql, H2, and Sqlite out of the box
194 stars 22 forks source link

Scala 3 Support (1000USD Bounty) #2

Closed lihaoyi closed 6 months ago

lihaoyi commented 10 months ago

Currently ScalaSql only supports Scala 2.13. Getting it working on Scala 3 would involve porting the table macros, which is one ~100 line file https://github.com/com-lihaoyi/scalasql/blob/main/scalasql/query/src-2/TableMacro.scala. I don't have the knowledge of Scala 3 macros to do it myself, but it shouldn't be hard to port, and the rest of the ScalaSql library should "just work".

To incentivize contribution, I'm putting a 1000USD bounty on resolving this ticket to the first person who can get all the ScalaSql tests passing on Scala 3. This is payable via bank transfer, and at my discretion in case of ambiguity.

lihaoyi commented 10 months ago

@KuceraMartin said he wanted to look into this, but if anyone else wants to try their hand at this feel free to do so

ghik commented 10 months ago

Sounds like a fun thing to do

ghik commented 10 months ago

I tried doing this and discovered https://github.com/lampepfl/dotty/issues/19480

KuceraMartin commented 10 months ago

I discovered https://github.com/lampepfl/dotty/issues/19436 in https://github.com/com-lihaoyi/scalasql/pull/3. I also tried a different approach with mirrors and ran into another compiler crash https://github.com/lampepfl/dotty/issues/19493.

It seems there are many different ways to approach this. @ghik would you be interested in discussing our thoughts? Maybe together we could find another approach that doesn't break the compiler :D

ghik commented 10 months ago

Sure, but I haven't even gotten to porting the macro itself. I just tried to compile tests on Scala 3...

KuceraMartin commented 10 months ago

Actually I never tried compiling all the tests. Now that I did, I see I'm getting the same compiler crash as you.

I started by removing most tests and trying to write a macro that would generate something similar to what the Scala 2 TableMacros does, as per @lihaoyi's advice. You could try the same thing if you want. If you do so, you can cherry-pick this commit https://github.com/com-lihaoyi/scalasql/pull/3/commits/a96df75c0d56046dcc2ad5172b366b4526fd5af4 which fixes some trivial Scala 3 incompatibilities outside of macros. Then, delete all tests except for e.g. Main.scala. Then, if you just replace TableMacros with

trait TableMacros:
   given metadata[V[_[_]]]: Table.Metadata[V] = ???

it will at least compile. Later on, you can start adding some tests back. I tried multiple and never ran into that compiler crash. For instance SqliteExample.scala should work.

If you're interested in discussing it further, let's connect on Discord (mine is martin.kucera)

ghik commented 10 months ago

@KuceraMartin FYI https://github.com/lampepfl/dotty/issues/19480 already has a working fix on the way, I compiled the tests successfully with it

I'm going to take a break from this for now, but I'll be happy to discuss details if I come back to it.

vvidlearn commented 6 months ago

Hi this sounds like an interesting exercise. I am new to macros but consider this as an opportunity to learn them. So would like to work on it if its ok. If this will be too much of an effort for a macro newbie I am happy for someone else to work on this.Thank you.

lihaoyi commented 6 months ago

Hi this sounds like an interesting exercise. I am new to macros but consider this as an opportunity to learn them. So would like to work on it if its ok. Thank you.

Please go ahead! No need to ask me for permission

mrdziuban commented 6 months ago

Hey @vvidlearn, are you still looking into this? I'm curious to look as well but don't want to step on your toes

vvidlearn commented 6 months ago

hi @mrdziuban sorry for the late reply, I am just a macro beginner. So it was beyond me. glad you completed it.