Scala Macro Libraries · Scala 3 Migration guide (original) (raw)

While being experimental, the Scala community has largely adopted the Scala 2 Def Macro feature in multiple of ways: code generation, optimizations, ergonomic DSLs...

A large part of the ecosystem now depends on Scala 2.13 macros defined in external libraries. Identifying those library dependencies is key to establish that a project is ready to be migrated to Scala 3.

The Scala 3 compiler cannot execute Scala 2.13 macro definitions.

However, the handy -Xignore-scala2-macros option can be used to ignore them and type check the rest of the code.

[error] -- Error: /src/main/scala/foo/Foo.scala:10:45 
[error] 10 |  implicit val foo: Foo[List[Int]] = Foo.make
[error]    |                                             ^
[error]    |Scala 2 macro cannot be used in Scala 3. See https://dotty.epfl.ch/docs/reference/dropped-features/macros.html
[error]    |To turn this error into a warning, pass -Xignore-scala2-macros to the compiler

Beware that -Xignore-scala2-macros will produce bytecode that will fail at runtime.

Macro Libraries

The following table contains an incomplete list of macro libraries and their migration status.

Project Status Comments
adamw/scala-macro-debug
ajozwik/quill-generic
argonaut-io/argonaut Since version 6.3.2
backuity/ansi-interpolator
typelevel/log4cats Since version 1.3.1
circe/circe Since version 0.14.0
dmytromitin/auxify
fthomas/refined refined macros not yet available
jokade/slogging
getquill/quill Since version 3.13.0
giiita/refuel Since version 2.0.2
lightbend/scala-logging Since version 3.9.4
lihaoyi/autowire
lihaoyi/fastparse Since version 3.0.0
lihaoyi/mill
lihaoyi/pprint Since version 0.6.0
lihaoyi/sourcecode Since version 0.1.8
lihaoyi/upickle Since version 1.2.0
lihaoyi/utest Since version 0.7.3
lloydmeta/enumeratum Since version 1.7.1
log4s/log4s Since version 1.10.0-M1
macro-peg/macro_peg
milessabin/shapeless Being rewritten into Shapeless 3 Since version 3.0.0 (typelevel/shapeless-3)
monix/minitest Since 2.9.0
mpollmeier/gremlin-scala macros module not available for Scala 3.0
nevillelyh/parquet-avro-extra
non/imp
optics-dev/Monocle Since 3.0.0
payalabs/scalajs-react-bridge
playframework/play-json Since version 2.10.0-RC5
plokhotnyuk/expression-evaluator No replacement for Evals.eval
plokhotnyuk/fast-string-interpolator Since version 0.6.2
plokhotnyuk/jsoniter-scala Since version 2.12.1
softwaremill/magnolia Since version 1.0.0
pureconfig/pureconfig Since version 0.17.2
sangria-graphql/sangria Since version 3.3.0
scalalandio/chimney Since version 0.8.0
scalameta/munit Since 0.3.0
scalatest/scalatest Since version 3.1.0
scalatest/scalatestplus-junit Since version 3.1.0
scalikejdbc/scalikejdbc Since 4.0.0
scodec/scodec-bits Since version 1.1.18
sirthias/parboiled2 Since version 2.4.0
sirthias/borer Since version 1.10.0
slick/slick Since version 3.5.0-M4
softwaremill/macwire Since version 2.4.0
thoughtworksinc/each
tersesystems/blindsight Since version 1.5.2
typelevel/claimant No longer maintained
typelevel/spire Since version 0.18.0
wix/accord No longer maintained
wvlet/airframe Since version 20.12.1
zio/izumi-reflect Does not yet support path-dependent type
zio/zio Since version 1.0.4
zero-deps/proto Since version 2.1.0

If you find any macro library that is not listed here you are invited to open an issue.

Macro Annotations Libraries

Macro annotations are not supported in Scala 3. The following table contains a incomplete list of Scala 2.13 libraries that provide macro annotations. Scala 3 compatible alternatives are proposed when available.

Project Alternative Solutions
dmytromitin/auxify
julianpeeters/avro-scala-macro-annotations
manatki/derevo
typelevel/simulacrum Source generation using simulacrum-scalafix

Contributors welcome!