miniboxing / miniboxing-plugin

Miniboxing is a program transformation that improves the performance of Scala generics when used with primitive types. It can speed up generic collections by factors between 1.5x and 22x, while maintaining bytecode duplication to a minimum. You can easily add miniboxing to your sbt project:
http://scala-miniboxing.org
Other
121 stars 17 forks source link

No warning when instantiating Array[T] where T is miniboxed #214

Closed Roldak closed 9 years ago

Roldak commented 9 years ago
import scala.reflect._

object Test {
  def foo[@miniboxed T : ClassTag] = {
    new Array[T](42)
  }
}

This doesn't yield the warning "Use MbArray instead of Array and benefit from miniboxing specialization".

Btw, should this yield the warning too (it doesn't right now) ?

import scala.reflect._

object Test {
  def foo[T : ClassTag] = {
    new Array[T](42)
  }
}
VladUreche commented 9 years ago

Thanks @Roldak! First example should warn, the second one shouldn't. @milosstojanovic , can you please have a look? I might have broken the warnings in https://github.com/miniboxing/miniboxing-plugin/commit/d6b17854e3629abe721961707354b385ed9d2c57... :-1:

milosstojanovic commented 9 years ago

Yeah, I will have a look now.

VladUreche commented 9 years ago

Thanks Milos!

VladUreche commented 9 years ago
sun@sun-cpu:~/x$ cat i.scala 
class C[T: reflect.ClassTag](t: T) {
  new Array[T](4)
  Array[T](t,t,t,t,t)
}
sun@sun-cpu:~/x$ scalac -Xprint:typer i.scala
Picked up _JAVA_OPTIONS: -Xms2g -Xmx2g -Xss4m -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=512M -XX:ReservedCodeCacheSize=256m -XX:PermSize=256m -XX:+TieredCompilation -XX:+UseNUMA
[[syntax trees at end of                     typer]] // i.scala
package <empty> {
  class C[T] extends scala.AnyRef {
    <paramaccessor> private[this] val t: T = _;
    implicit <synthetic> <paramaccessor> private[this] val evidence$1: scala.reflect.ClassTag[T] = _;
    def <init>(t: T)(implicit evidence$1: scala.reflect.ClassTag[T]): C[T] = {
      C.super.<init>();
      ()
    };
    C.this.evidence$1.newArray(4);
    scala.Array.apply[T](C.this.t, C.this.t, C.this.t, C.this.t, C.this.t)(C.this.evidence$1)
  }
}