Following the successful experiment in In multi-stage compilation, should we use a standard serialisation method to ship objects through stages? - #22 by tribbloid, I’d like to publish its outcome as an independent library.
This includes a new way to implement TypeTag
that is far more lightweight than izumi-reflect and with none of its limitations.
(see list of these limitations at GitHub - zio/izumi-reflect: TypeTag without scala-reflect. Supports Scala 2 and Scala 3.)
I still can’t decide how to represent the underlying types in serialized form, Type
on its own are not serializable in either Scala 2 or 3, I could only think of 2 ways to convert it:
-
use the compiler built-in pickler (
dotty.tools.dotc.quoted.PickledQuotes
andscala.quoted.runtime.QuoteUnpickler
) to convert it into string or BLOB.- Pros: can be easily reconstructed in multi-stage programming.
- Cons: almost impossible to be used elsewhere,
QuoteUnpickler
is only implemented within the context of a compiler.
-
use metaprogramming tools to convert it into TASTy type data.
- Pros: can live independently without a specific compiler instance, it is even compatible with Scala2 tools!
- Cons: I haven’t figure out how to do this yet, is there a reference library or metaprogramming tool I can look into? Not sure about the relevance of scalameta as it is quite old by now.
Once implemented it will be published regularly as an interop layer between Scala 2 (which already has TypeTag
) and 3, old capabilities of TypeTag
(e.g. convert to runtime class, pattern matching) can be gradually revived with little effort.
I expect this feature to marginally reduce upgrade difficulty for some frameworks that heavily rely on TypeTag
and JVM runtime reflection (Apache Spark, obviously), thanks in advance if you would like to add more use cases and feature suggestions.