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

can do sbt +lihua/publishLocal #876

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft

can do sbt +lihua/publishLocal #876

wants to merge 4 commits into from

Conversation

lofoyet
Copy link
Contributor

@lofoyet lofoyet commented Oct 19, 2023

Summary

This is a tentative change to make lihua cross compile to scala 3(.2.2). The compile was successful. The goal isn't to merge this code or might not have to develop upon this PR, but rather to spark conversations and learnings.

Line of thought

I tried to make the change minimal for this cross compile. The outcome seems satisfying.

  • kind projector and paradise are specified to use 2.13 for 3.
  • tagless is also version based.
  • commonSettings > scalacOptions is version based.
  • because in scala 3 package object is deprecated

There is another branch i tried something a bit different. mostly around the class EntityId.
EntityId is a wrapped string, with the help of newtype lib. In scala3, this can be achieved using opaque type.
In a separate toy project, I am able to separate scala2 and scala3 code, each defines EntityId in the way talked above and it worked.

Let's talk about if all this makes sense

@lofoyet
Copy link
Contributor Author

lofoyet commented Oct 19, 2023

The cmd result

➜  thomas git:(scala3-lihua-2) sbt +lihua/publishLocal                        
[info] welcome to sbt 1.9.3 (Homebrew Java 11.0.20)
[info] loading global plugins from /Users/tonyliu/.sbt/1.0/plugins
[info] loading settings for project thomas-build from build.sbt,plugins.sbt ...
[info] loading project definition from /Users/tonyliu/Work/proj/thomas/project
[info] loading settings for project thomas from build.sbt,version.sbt ...
[info] resolving key references (18193 settings) ...
[info] set current project to thomas (in build file:/Users/tonyliu/Work/proj/thomas/)
[info] Setting Scala version to 2.13.10 on 17 projects.
[info] Reapplying settings...
[info] set current project to thomas (in build file:/Users/tonyliu/Work/proj/thomas/)
[info] Wrote /Users/tonyliu/Work/proj/thomas/lihua/target/scala-2.13/thomas-lihua_2.13-1.4.5-SNAPSHOT.pom
[info] Main Scala API documentation to /Users/tonyliu/Work/proj/thomas/lihua/target/scala-2.13/api...
[info] Main Scala API documentation successful.
[info] :: delivering :: com.iheart#thomas-lihua_2.13;1.4.5-SNAPSHOT :: 1.4.5-SNAPSHOT :: integration :: Thu Oct 19 14:37:00 PDT 2023
[info]  delivering ivy file to /Users/tonyliu/Work/proj/thomas/lihua/target/scala-2.13/ivy-1.4.5-SNAPSHOT.xml
[info]  published thomas-lihua_2.13 to /Users/tonyliu/.ivy2/local/com.iheart/thomas-lihua_2.13/1.4.5-SNAPSHOT/poms/thomas-lihua_2.13.pom
[info]  published thomas-lihua_2.13 to /Users/tonyliu/.ivy2/local/com.iheart/thomas-lihua_2.13/1.4.5-SNAPSHOT/jars/thomas-lihua_2.13.jar
[info]  published thomas-lihua_2.13 to /Users/tonyliu/.ivy2/local/com.iheart/thomas-lihua_2.13/1.4.5-SNAPSHOT/srcs/thomas-lihua_2.13-sources.jar
[info]  published thomas-lihua_2.13 to /Users/tonyliu/.ivy2/local/com.iheart/thomas-lihua_2.13/1.4.5-SNAPSHOT/docs/thomas-lihua_2.13-javadoc.jar
[info]  published ivy to /Users/tonyliu/.ivy2/local/com.iheart/thomas-lihua_2.13/1.4.5-SNAPSHOT/ivys/ivy.xml
[success] Total time: 2 s, completed Oct 19, 2023, 2:37:00 PM
[info] Setting Scala version to 3.2.2 on 1 projects.
[info] Excluded 16 projects, run ++ 3.2.2 -v for more details.
[info] Reapplying settings...
[info] set current project to thomas (in build file:/Users/tonyliu/Work/proj/thomas/)
[info] Wrote /Users/tonyliu/Work/proj/thomas/lihua/target/scala-3.2.2/thomas-lihua_3-1.4.5-SNAPSHOT.pom
[info] Main Scala API documentation to /Users/tonyliu/Work/proj/thomas/lihua/target/scala-3.2.2/api...
[info] Skipping unused scalacOptions: -Werror, -Ykind-projector
[warn] scaladoc will ignore following non-existent paths: , 
[warn] one warning found
[info] Main Scala API documentation successful.
[info] :: delivering :: com.iheart#thomas-lihua_3;1.4.5-SNAPSHOT :: 1.4.5-SNAPSHOT :: integration :: Thu Oct 19 14:37:02 PDT 2023
[info]  delivering ivy file to /Users/tonyliu/Work/proj/thomas/lihua/target/scala-3.2.2/ivy-1.4.5-SNAPSHOT.xml
[info]  published thomas-lihua_3 to /Users/tonyliu/.ivy2/local/com.iheart/thomas-lihua_3/1.4.5-SNAPSHOT/poms/thomas-lihua_3.pom
[info]  published thomas-lihua_3 to /Users/tonyliu/.ivy2/local/com.iheart/thomas-lihua_3/1.4.5-SNAPSHOT/jars/thomas-lihua_3.jar
[info]  published thomas-lihua_3 to /Users/tonyliu/.ivy2/local/com.iheart/thomas-lihua_3/1.4.5-SNAPSHOT/srcs/thomas-lihua_3-sources.jar
[info]  published thomas-lihua_3 to /Users/tonyliu/.ivy2/local/com.iheart/thomas-lihua_3/1.4.5-SNAPSHOT/docs/thomas-lihua_3-javadoc.jar
[info]  published ivy to /Users/tonyliu/.ivy2/local/com.iheart/thomas-lihua_3/1.4.5-SNAPSHOT/ivys/ivy.xml
[success] Total time: 2 s, completed Oct 19, 2023, 2:37:02 PM
[info] Reapplying settings...
[info] set current project to thomas (in build file:/Users/tonyliu/Work/proj/thomas/)

@lofoyet
Copy link
Contributor Author

lofoyet commented Oct 20, 2023

Following up:

I am trying to cross compile core. After making necessary changes to build.sbt, i got

[error] -- [E124] Cyclic Error: /Users/tonyliu/Work/proj/thomas/core/src/main/scala/com/iheart/thomas/abtest/AbtestAlg.scala:181:42 
[error] 181 |        implicit val nowF = utils.time.now[F]
[error]     |                                          ^
[error]     |value nowF needs result type because its right-hand side attempts implicit search
[error]     |
[error]     | longer explanation available when compiling with `-explain`
[error] -- Error: /Users/tonyliu/Work/proj/thomas/core/src/main/scala/com/iheart/thomas/abtest/AbtestAlg.scala:403:8 
[error] 403 |        feature
[error]     |        ^
[error]     |Scala 2 macro cannot be used in Dotty, this call will crash at runtime. See https://docs.scala-lang.org/scala3/reference/dropped-features/macros.html
[error] -- Error: /Users/tonyliu/Work/proj/thomas/core/src/main/scala/com/iheart/thomas/abtest/AbtestAlg.scala:425:8 
....

Looks like macros in scala2 and scala3 work pretty differently.

@kailuowang
Copy link
Contributor

kailuowang commented Oct 24, 2023

There is another branch i tried something a bit different. mostly around the class EntityId.
EntityId is a wrapped string, with the help of newtype lib. In scala3, this can be achieved using opaque type.
In a separate toy project, I am able to separate scala2 and scala3 code, each defines EntityId in the way talked above and it worked.

Both strategies worth trying. crossVersionUser213for3 might be a good intermediate step before we fully migrate to Scala3. cats-tagless will be more involved to be replaced. The effort to migrate that lib to support Scala 3 seems to be stalled. To replace it you will need to learn some rather advanced functional programming concepts such as FunctorK and Contravariant and basically what cats-tagless does for thomas.

@lofoyet
Copy link
Contributor Author

lofoyet commented Oct 25, 2023

There is another branch i tried something a bit different. mostly around the class EntityId.
EntityId is a wrapped string, with the help of newtype lib. In scala3, this can be achieved using opaque type.
In a separate toy project, I am able to separate scala2 and scala3 code, each defines EntityId in the way talked above and it worked.

Both strategies worth trying. crossVersionUser213for3 might be a good intermediate step before we fully migrate to Scala3. cats-tagless will be more involved to be replaced. The effort to migrate that lib to support Scala 3 seems to be stalled. To replace it you will need to learn some rather advanced functional programming concepts such as FunctorK and Contravariant and basically what cats-tagless does for thomas.

Good point. I have some basic understanding of Functor and Contravariant, I do need some more practice.

Ok, I will focus on tagless in the next sprints.

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