scala-dev icon indicating copy to clipboard operation
scala-dev copied to clipboard

Treat more constructors as pure in the optimizer

Open retronym opened this issue 8 years ago • 3 comments

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?

retronym avatar Apr 22 '16 01:04 retronym

Sure - is there a specific use case?

lrytz avatar Apr 22 '16 06:04 lrytz

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

retronym avatar Apr 22 '16 06:04 retronym

Longer-term I'm hoping to get a more generic solution, probably by supporting @inline on classes (Some), or maybe some heuristics / class analysis

lrytz avatar Apr 22 '16 06:04 lrytz