scala3 icon indicating copy to clipboard operation
scala3 copied to clipboard

Implement SIP-61 `@unroll` annotation

Open bishabosha opened this issue 4 months ago • 27 comments

~Still need to write documentation,~ Documentation is written also

I am doing this work on behalf of @lihaoyi

The main implementation follows com-lihaoyi/unroll but with some changes:

  • @unroll annotation is @experimental
  • run before pickling
  • increase validation checks for incorrect usage of @unroll
  • Underscore not EmptyTree in pattern match default case
  • ensure correct spans in TASTy
  • ensure symbols are correctly substituted in types

There is one main library addition: scala.annotation.unroll, i.e. the @unroll annotation that appears on parameters,

commits are a bit of a mess - a lot of churn

Edit: removed changes:

  • ~reuse the symbol when generating the "forwarder" of an abstract method.~
  • ~infer override when overriding trait methods that "appear" abstract in source code, but were actually implemented by the unroll annotation~
  • ~do not add the Invisible flag to abstract unrolled methods - this means they can actually still be visible in separately compiled compilation units (because unrolling runs before pickler now)~
  • ~Internal annotation scala.annotation.internal.AbstractUnroll - marker used to indicate that an unrolled abstract method was abstract in source code (unrolling phase actually provides a default implementation) - this enables downstream implementers to avoid the override flag. (Maybe we shouldn't allow this convenience?)~
  • ~Internal annotation scala.annotation.internal.UnrollForwarder - marker on any generated forwarder - which is used for special casing TASTy pickling of method calls to the forwarders~
  • ~because forwarders get the Invisible flag, this makes them impossible to select from TASTy normally (via SELECTin), (invisible def are filtered out "before typer") so I intercept the Select trees to be TERMREFdirect, and then restore them to Select after TASTY. perhaps someone has a better idea, or we could change the resolution rules for Invisible? or invent a new TASTy node? (I also tried generating a Ident tree rather than a Select, but this had a type error)~

fixes #21728

bishabosha avatar Oct 02 '24 17:10 bishabosha