scala-dev
scala-dev copied to clipboard
Treat more constructors as pure in the optimizer
e.g. scala.Some
(https://github.com/scala/scala/compare/2.12.x...retronym:topic/pure-some?expand=1)
Perhaps also:
-
Left
/Right
/Success
@lrytz WDYT?
Sure - is there a specific use case?
Nothing very scientific, I just noticed the possibility when demoing call-site inline annotations on gitter:
scala> class Inline2 { def test = (Some(1).isEmpty : @inline) }
defined class Inline2
scala> :javap -c Inline2#test
public boolean test();
Code:
0: new #17 // class scala/Some
3: iconst_1
4: invokestatic #23 // Method scala/runtime/BoxesRunTime.boxToInteger:(I)Ljava/lang/Integer;
7: invokespecial #27 // Method scala/Some."<init>":(Ljava/lang/Object;)V
10: iconst_0
11: ireturn
Longer-term I'm hoping to get a more generic solution, probably by supporting @inline
on classes (Some
), or maybe some heuristics / class analysis