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

Automatically add getters/setters to class fields #16

Open VladUreche opened 11 years ago

VladUreche commented 11 years ago

Citing spire compilation:

core/src/main/scala/spire/math/Rational.scala:412: error: The program is accessing field integral of miniboxed class (or trait) Rationals, a pattern which becomes invalid after the miniboxing transformation. Please allow Scala to generate getters (and possibly setters) by using val (or var) without the "private[this]" qualifier: val integral: spire#29.math#7202.Integral#7636[A#7667]".
    override def signum: Int = scala.math.signum(integral.compare(num, zero))
                                                 ^
core/src/main/scala/spire/math/Rational.scala:412: error: The program is accessing field integral of miniboxed class (or trait) Rationals, a pattern which becomes invalid after the miniboxing transformation. Please allow Scala to generate getters (and possibly setters) by using val (or var) without the "private[this]" qualifier: val integral: spire#29.math#7202.Integral#7636[A#7667]".
    override def signum: Int = scala.math.signum(integral.compare(num, zero))
                                                                       ^
core/src/main/scala/spire/math/Rational.scala:414: error: The program is accessing field integral of miniboxed class (or trait) Rationals, a pattern which becomes invalid after the miniboxing transformation. Please allow Scala to generate getters (and possibly setters) by using val (or var) without the "private[this]" qualifier: val integral: spire#29.math#7202.Integral#7636[A#7667]".
    def isWhole: Boolean = den == one
                                  ^
core/src/main/scala/spire/math/Rational.scala:418: error: The program is accessing field integral of miniboxed class (or trait) Rationals, a pattern which becomes invalid after the miniboxing transformation. Please allow Scala to generate getters (and possibly setters) by using val (or var) without the "private[this]" qualifier: val integral: spire#29.math#7202.Integral#7636[A#7667]".
    def toBigInt: BigInt = (integral.toBigInt(num) / integral.toBigInt(den))
                            ^
core/src/main/scala/spire/math/Rational.scala:418: error: The program is accessing field integral of miniboxed class (or trait) Rationals, a pattern which becomes invalid after the miniboxing transformation. Please allow Scala to generate getters (and possibly setters) by using val (or var) without the "private[this]" qualifier: val integral: spire#29.math#7202.Integral#7636[A#7667]".
    def toBigInt: BigInt = (integral.toBigInt(num) / integral.toBigInt(den))
                                                     ^
core/src/main/scala/spire/math/Rational.scala:419: error: The program is accessing field integral of miniboxed class (or trait) Rationals, a pattern which becomes invalid after the miniboxing transformation. Please allow Scala to generate getters (and possibly setters) by using val (or var) without the "private[this]" qualifier: val integral: spire#29.math#7202.Integral#7636[A#7667]".
    def toBigDecimal: BigDecimal = integral.toBigDecimal(num) / integral.toBigDecimal(den)
                                   ^
core/src/main/scala/spire/math/Rational.scala:419: error: The program is accessing field integral of miniboxed class (or trait) Rationals, a pattern which becomes invalid after the miniboxing transformation. Please allow Scala to generate getters (and possibly setters) by using val (or var) without the "private[this]" qualifier: val integral: spire#29.math#7202.Integral#7636[A#7667]".
    def toBigDecimal: BigDecimal = integral.toBigDecimal(num) / integral.toBigDecimal(den)
                                                                ^
core/src/main/scala/spire/math/Rational.scala:426: error: The program is accessing field integral of miniboxed class (or trait) Rationals, a pattern which becomes invalid after the miniboxing transformation. Please allow Scala to generate getters (and possibly setters) by using val (or var) without the "private[this]" qualifier: val integral: spire#29.math#7202.Integral#7636[A#7667]".
    def doubleValue: Double = if (num == zero) {
                                         ^
core/src/main/scala/spire/math/Rational.scala:428: error: The program is accessing field integral of miniboxed class (or trait) Rationals, a pattern which becomes invalid after the miniboxing transformation. Please allow Scala to generate getters (and possibly setters) by using val (or var) without the "private[this]" qualifier: val integral: spire#29.math#7202.Integral#7636[A#7667]".
    } else if (integral.lt(num, zero)) {
               ^
core/src/main/scala/spire/math/Rational.scala:428: error: The program is accessing field integral of miniboxed class (or trait) Rationals, a pattern which becomes invalid after the miniboxing transformation. Please allow Scala to generate getters (and possibly setters) by using val (or var) without the "private[this]" qualifier: val integral: spire#29.math#7202.Integral#7636[A#7667]".
    } else if (integral.lt(num, zero)) {
                                ^
core/src/main/scala/spire/math/Rational.scala:435: error: The program is accessing field integral of miniboxed class (or trait) Rationals, a pattern which becomes invalid after the miniboxing transformation. Please allow Scala to generate getters (and possibly setters) by using val (or var) without the "private[this]" qualifier: val integral: spire#29.math#7202.Integral#7636[A#7667]".
      val n = integral.toBigInt(num)
              ^
core/src/main/scala/spire/math/Rational.scala:436: error: The program is accessing field integral of miniboxed class (or trait) Rationals, a pattern which becomes invalid after the miniboxing transformation. Please allow Scala to generate getters (and possibly setters) by using val (or var) without the "private[this]" qualifier: val integral: spire#29.math#7202.Integral#7636[A#7667]".
      val d = integral.toBigInt(den)
              ^
VladUreche commented 11 years ago

Turning integer into a val will fix all errors: before: private[math] abstract class Rationals[@specialized(Long) A](implicit integral: Integral[A]) after: private[math] abstract class Rationals[@specialized(Long) A](implicit val integral: Integral[A])