scala3
scala3 copied to clipboard
Implement SIP-61 `@unroll` annotation
~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
notEmptyTree
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 (viaSELECTin
), (invisible def are filtered out "before typer") so I intercept theSelect
trees to beTERMREFdirect
, and then restore them to Select after TASTY. perhaps someone has a better idea, or we could change the resolution rules forInvisible
? or invent a new TASTy node? (I also tried generating aIdent
tree rather than aSelect
, but this had a type error)~
fixes #21728