Scala 2 Roadmap Update: the Road to Scala 3

Likely not. My understanding is that Tasty reflection is a compile-time thing (true?). That might help but doesn’t solve the problem. Let’s say I have a reflection-based function that accepts a trait Pet. At runtime a user hands me a Dog. How would I detect that? How would I understand the runtime properties of Dog? Let’s say further that Dog is parameterized with some type [T]. What’s the actual type for T at runtime? I need all this information to serialize/deserialize things. Can’t do it without.

Not to drift off-topic of reflection, but you’ve hit the nail on the head of the problem ScalaJack was intended to solve: allow for a friction-less, type-safe serialization to formats like JSON, YAML, etc. Type information is encoded into the JSON (i.e. for traits), so that upon deserialization the precise, typed object can be reconstituted. That’s why I need robust runtime reflection.

So what’s the deal with DelayedInit? Seems like there are valid use-cases for it but it’s still being dropped completely?

I don’t know how Tasty is stored, but if it’s put into an annotation as nsc’s pickles are, you could get it out of an object’s runtime class.

I know that @bishabosha did something to make Tasty semi-independent of the compiler itself, so that could be a starting point.

1 Like

Typically with the current way of doing things, there is a class file annotation (not accessible with reflection), which contains a UUID for a matching .tasty file which actually contains the serialised trees.

What we’ve done so far is to separate just the classes necessary to buffer bytes and standardise the names given to tree node tags, there would be more work required to abstract the traversal of TASTy and to generate it from concrete tree types.

1 Like

My understanding is that Tasty reflection is a compile-time thing (true?)

Not quite, you can invoke it at runtime by obtaining a QuoteContext from dotty compiler. AFAIU the difference wrt previous scala-reflect is that instead of being a standalone ripped out piece of the compiler, runtime tasty-reflect just requires the entire compiler, so the JAR size will be bigger, might work slower, but should be more stable than scala-reflect.

1 Like