Scala 3 Migration guide

Scala 3 Migration guide

  • User Guide
  • Contribute
  • GitHub

›Macros

General

  • Compatibility Reference
  • Tour of the Migration Tools
  • Scala 3.0 Migration Mode
  • Scala 3 Syntax Rewriting

Tutorials

  • Porting an sbt Project
  • Porting the scalacOptions

Incompatibilities

  • Incompatibility Table
  • Syntactic Changes
  • Dropped Features
  • Contextual Abstractions
  • Other Changed Features

Macros

  • Scala Macro Libraries
  • Metaprogramming in Scala 3
  • Porting a Macro Library

External Resources

  • Moving from Scala 2 to Scala 3
Edit

Metaprogramming in Scala 3

The Scala 2.13 macros are compiler-dependent by design. A macro compiled by one version of the compiler cannot be used by another version of the compiler.

Scala 3.0 is overcoming this limitation by introducing a new principled approach of metaprogramming. While this is an uncontested improvement, it also means that previous macro implementations have to be rewritten from the ground up.

Before rewriting a macro

Before getting deep into reimplementing a macro your should check if it can be supported using Scala 3.0 new features.

  • Can I encode the logic of the macro using the new scala 3 features?
  • Can I use match types to reimplement the interface of my macro?
  • Can I use inline and the metaprogramming features in scala.compiletime to reimplement my logic?
  • Can I use the simpler and safer expression based macros to implement my macro?
  • Do I really need to have access to the raw AST trees?

You can find references to these concepts in the macro tutorial.

Macro turorial

  • Scala 3 Macro Tutorial
    • Inline
    • Compile-time operations
    • Macros
    • Quoted code
    • AST Reflection

Additional Resources

Documentation:

  • Scala 3.0 Documentation
  • Macros: The Plan For Scala 3
  • Examples - a repository with small, self-contained examples of various tasks done with Scala 3 macros.

Talks:

  • Scala Days - Metaprogramming in Dotty

Projects:

  • XML Interpolator
  • Shapeless 3

Contributors welcome!

← Scala Macro LibrariesPorting a Macro Library →
  • Before rewriting a macro
  • Macro turorial
  • Additional Resources
Scala 3 Migration guide
Docs
User GuideContribute
Community
Chat on GitterDiscuss on Scala Users
More
GitHub
Copyright © 2021 Scala Center