Skip to content

avoid boxing #5303

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 11, 2016
Merged

avoid boxing #5303

merged 1 commit into from
Nov 11, 2016

Conversation

xuwei-k
Copy link
Contributor

@xuwei-k xuwei-k commented Jul 26, 2016

scala.runtime.Rich{Double, Float} has isNaN and these are value class.
Also java.lang.{Double, Float} has isNaN.

We can't call RichDouble#isNaN because
implicit def double2Double(x: Double): java.lang.Double
is higher priority than
implicit def doubleWrapper(x: Double): RichDouble

$ scala -version
Scala code runner version 2.11.8 -- Copyright 2002-2016, LAMP/EPFL

$ scala -Xprint:jvm -e "1.0.isNaN"
[[syntax trees at end of                       jvm]] // scalacmd616162202928036892.scala
package <empty> {
  object Main extends Object {
    def main(args: Array[String]): Unit = {
      new <$anon: Object>();
      ()
    };
    def <init>(): Main.type = {
      Main.super.<init>();
      ()
    }
  };
  final class anon$1 extends Object {
    def <init>(): <$anon: Object> = {
      anon$1.super.<init>();
      scala.this.Predef.double2Double(1.0).isNaN();
      ()
    }
  }
}

@adriaanm adriaanm modified the milestone: 2.12.1 Jul 26, 2016
scala.runtime.Rich{Double, Float} has `isNaN` and these are value class.
Also java.lang.{Double, Float} has `isNaN`.

- https://docs.oracle.com/javase/8/docs/api/java/lang/Double.html#isNaN--
- https://docs.oracle.com/javase/8/docs/api/java/lang/Float.html#isNaN--

We can't call `RichDouble#isNaN` because
`implicit def double2Double(x: Double): java.lang.Double`
is higher priority than
`implicit def doubleWrapper(x: Double): RichDouble`

```
$ scala -version
Scala code runner version 2.11.8 -- Copyright 2002-2016, LAMP/EPFL

$ scala -Xprint:jvm -e "1.0.isNaN"
[[syntax trees at end of                       jvm]] // scalacmd616162202928036892.scala
package <empty> {
  object Main extends Object {
    def main(args: Array[String]): Unit = {
      new <$anon: Object>();
      ()
    };
    def <init>(): Main.type = {
      Main.super.<init>();
      ()
    }
  };
  final class anon$1 extends Object {
    def <init>(): <$anon: Object> = {
      anon$1.super.<init>();
      scala.this.Predef.double2Double(1.0).isNaN();
      ()
    }
  }
}
```
@retronym
Copy link
Member

This implicit situation here is pretty unfortunate. Would be nice to train -opt to deal with this, but for now your patch looks like a pragmatic solution.

LGTM

@retronym retronym self-assigned this Nov 11, 2016
@retronym retronym merged commit 5c3f0fa into scala:2.12.x Nov 11, 2016
@xuwei-k xuwei-k deleted the isNaN-boxing branch November 11, 2016 04:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants