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

Composing specialized traits in method argument does not lead to method specialization #4794

Closed
scabug opened this issue Jul 12, 2011 · 2 comments
Assignees

Comments

@scabug
Copy link

@scabug scabug commented Jul 12, 2011

Methods in specialized classes should have specialized versions if their type parameters require it. In particular, if you pass in a specialized class or trait of the same type, the method should be specialized. Unfortunately, this rule is lost if traits are composed, yielding unspecialized code.

Minimal example:

package spectest2 {
trait Mutable[@specialized A] { def a: A; def a_=(a0: A): Unit }
trait NotSpecialized { def not: String }
class Arr[@specialized A](val arr: Array[A]) {
def lode(m: Mutable[A]) { m.a = arr(0) }
def load(m: Mutable[A] with NotSpecialized) { m.a = arr(0) }
}
}

In this case, method "lode" is correctly specialized in, for example, the Int version of the class. However, method "load" is not. Even if the second trait is in fact specialized, the same behavior is observed.

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Jul 12, 2011

Imported From: https://issues.scala-lang.org/browse/SI-4794?orig=1
Reporter: @Ichoran
Affected Versions: 2.8.1, 2.9.0, 2.9.1

@scabug

This comment has been minimized.

Copy link
Author

@scabug scabug commented Sep 6, 2011

Commit Message Bot (anonymous) said:
(extempore in r25613) Intersection types made specializable.

Formerly a specializable type parameter would be missed if in
an intersection.

trait Trait[@specialized T] {
def f[T](x: Foo[T] with Bar) = x
}

Now that is specialized, as it already was in the "Foo[T]" case.
Closes #4794, no review.

@scabug scabug closed this Sep 6, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
2 participants
You can’t perform that action at this time.