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

Specialization missing an opportunity to rewire parent from AbstractFunction1[Int, Unit] to AbstractFunction1$mcVI$sp #7343

Closed
scabug opened this issue Apr 8, 2013 · 6 comments
Assignees
Milestone

Comments

@scabug
Copy link

scabug commented Apr 8, 2013

$ cat spec-test.scala 
class Test[T](array: Array[T]) {
 
  def spec_mapper[@specialized(Int) U](array: Array[U]) {
    for(i <- 0 to 10) {
      array(i) = array(array.length - i - 1)
    }
  }
}

$ ../build/quick/bin/scalac -Xprint:specialize spec-test.scala
[[syntax trees at end of                specialize]] // spec-test.scala
package <empty> {
  class Test[T >: Nothing <: Any] extends Object {
    ...

    // generic spec_mapper:
    def spec_mapper[@specialized(scala.Int) U >: Nothing <: Any](array: Array[U]): Unit = scala.this.Predef.intWrapper(0).to(10).foreach$mVc$sp({
      // parent rewired correctly to AbstractFunction1$mcVI$sp
      @SerialVersionUID(0) final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1$mcVI$sp with Serializable {
        ...
      };
      (new anonymous class $anonfun(): Int => Unit)
    });

    // specialized spec_mapper for Int:
    <specialized> def spec_mapper$mIc$sp(array: Array[Int]): Unit = scala.this.Predef.intWrapper(0).to(10).foreach$mVc$sp({
      // parent not rewired: AbstractFunction1[Int, Unit] => Int boxed!
      final <synthetic> class $anonfun extends scala.runtime.AbstractFunction1[Int,Unit] with Serializable {
        ...
      };
      (new anonymous class $anonfun(): Int => Unit)
    })
  }
}

This bit us while working on https://github.com/nicolasstucki/specialized/

@scabug
Copy link
Author

scabug commented Apr 8, 2013

Imported From: https://issues.scala-lang.org/browse/SI-7343?orig=1
Reporter: @VladUreche
Affected Versions: 2.10.0

@scabug
Copy link
Author

scabug commented Apr 14, 2013

@VladUreche said:
A very simple test that doesn't fail is this:

class Target[@specialized(Int) T]{ def foo = 1 }

object Test {
  def spec_mapper[@specialized(Int) T](t: T) =
    new Target[T]().foo
}

I checked with and without separate compilation and it always works.
I will leave it for now, that's a pretty big time sink.

@scabug
Copy link
Author

scabug commented Apr 14, 2013

@VladUreche said:
This is a better reproduction:

class Target[@specialized(Int) T]{ def foo = 1 }

object Test {

  def spec_mapper[@specialized(Int) T](t: T) = {
    class X extends Target[T]() // <== never gets its parents updated
    (new X).foo
  }
}

@scabug
Copy link
Author

scabug commented Apr 15, 2013

@VladUreche said (edited on Apr 15, 2013 12:12:46 AM UTC):
Okay, found it. Explanation:

  1. Specialization relies on two steps:
  • info (type) transformation, which is triggered for all symbols coming from previous phases
  • tree transformation, which relies on the info transformation
  1. When duplicating class X above, the duplicate symbol is created during specialization, so it never has the chance to go through the info transformation. A beforeSpecialize() should fix this, but where to introduce it?

@scabug
Copy link
Author

scabug commented Apr 15, 2013

@VladUreche said:
The patch I have still fails two tests. I'll have to dig deeper into it...

@scabug
Copy link
Author

scabug commented Jun 12, 2013

@VladUreche said:
scala/scala#2651

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