Skip to content
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

Warnings Fail: Object does not trigger warning #229

Open
VladUreche opened this issue Jun 4, 2015 · 4 comments
Open

Warnings Fail: Object does not trigger warning #229

VladUreche opened this issue Jun 4, 2015 · 4 comments
Assignees
Milestone

Comments

@VladUreche
Copy link
Member

Why don't we get a warning that MyNumeric[T] should be miniboxed?

$ cat gh-bug-229.scala 
package streams

trait MyNumeric[T]
object LongIsMyNumeric extends MyNumeric[Long]
object IntIsMyNumeric extends MyNumeric[Int]

$ mb-scalac gh-bug-229.scala 

@biboudis: This is what you were seening.

@VladUreche VladUreche self-assigned this Jun 4, 2015
@VladUreche VladUreche added this to the 0.4 milestone Jun 4, 2015
@VladUreche VladUreche changed the title Warnings Fail Warnings Fail: Object does not trigger warning Jun 4, 2015
@VladUreche
Copy link
Member Author

Oh shit! There's more...

$ cat gh-bug-229-2.scala 
package streams

object Warns1 {
  class SpecializedArrayBuilder[@specialized(Long) A]
  implicit val longBuilder = new SpecializedArrayBuilder[Long] {}
}

object Warns2 {
  class SpecializedArrayBuilder[@specialized(Long) A]
  implicit val longBuilder = new SpecializedArrayBuilder[Long]
}

object Warns3 { // erm, doesn't warn. WTF?!?
  trait SpecializedArrayBuilder[@specialized(Long) A]
  implicit val longBuilder = new SpecializedArrayBuilder[Long] {}
}

$ mb-scalac gh-bug-229-2.scala 

gh-bug-229-2.scala:5: warning: Although the type parameter A of class streams.Warns1.SpecializedArrayBuilder is specialized, miniboxing and specialization communicate among themselves by boxing (thus, inefficiently) on all classes other than as FunctionX and TupleX. If you want to maximize performance, consider switching from specialization to miniboxing: '@miniboxed T':
  implicit val longBuilder = new SpecializedArrayBuilder[Long] {}
                                 ^
gh-bug-229-2.scala:10: warning: Although the type parameter A of class streams.Warns2.SpecializedArrayBuilder is specialized, miniboxing and specialization communicate among themselves by boxing (thus, inefficiently) on all classes other than as FunctionX and TupleX. If you want to maximize performance, consider switching from specialization to miniboxing: '@miniboxed T':
  implicit val longBuilder = new SpecializedArrayBuilder[Long]
                             ^
two warnings found

Ping @milosstojanovic, any idea why this occurs?

@milosstojanovic
Copy link
Contributor

So, something is wrong with traits. Maybe I messed up with my last refactoring, will check now

@VladUreche
Copy link
Member Author

Or maybe it was that way from the beginning -- either way, we need to investigate.

@VladUreche
Copy link
Member Author

We should really test all possible combinations:

  • anonymous class (new X[Int] { ... }) extends {trait, class}
  • trait extends {trait, class}
  • class extends {trait, class}
  • object extends {trait, class}
  • self types trait T { self: X[Int] => ... }

For trait extension, we should check both first position and second:

object O1 extends T[Int] with Serializable
object O2 extends Serializable with T[Int] 

This way, if we lose someone along the way, we know about it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants