Skip to content

Commit 0cfd858

Browse files
author
Adriaan Moors
committed
Merge pull request #915 from gkossakowski/SI-6035-specialized-flag
SI-6035: Specialization and separate compilation.
2 parents d9629db + 7c42b5a commit 0cfd858

File tree

5 files changed

+32
-6
lines changed

5 files changed

+32
-6
lines changed

src/compiler/scala/tools/nsc/transform/UnCurry.scala

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -564,12 +564,6 @@ abstract class UnCurry extends InfoTransform
564564
}
565565

566566
val sym = tree.symbol
567-
// Take a pass looking for @specialize annotations and set all
568-
// their SPECIALIZE flags for cheaper recognition.
569-
if ((sym ne null) && (sym.isClass || sym.isMethod)) {
570-
for (tp <- sym.typeParams ; if tp hasAnnotation SpecializedClass)
571-
tp setFlag SPECIALIZED
572-
}
573567
val result = (
574568
// TODO - settings.noassertions.value temporarily retained to avoid
575569
// breakage until a reasonable interface is settled upon.

src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ import symtab.Flags._
1919
* of class-members which are private up to an enclosing non-package
2020
* class, in order to avoid overriding conflicts.
2121
*
22+
* This phase also sets SPECIALIZED flag on type parameters with
23+
* `@specialized` annotation. We put this logic here because the
24+
* flag must be set before pickling.
25+
*
2226
* @author Martin Odersky
2327
* @version 1.0
2428
*/
@@ -208,6 +212,15 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
208212
case TypeApply(sel @ Select(This(_), name), args) =>
209213
mayNeedProtectedAccessor(sel, args, false)
210214

215+
// set a flag for all type parameters with `@specialized` annotation so it can be pickled
216+
case typeDef: TypeDef if typeDef.symbol.deSkolemize.hasAnnotation(definitions.SpecializedClass) =>
217+
debuglog("setting SPECIALIZED flag on typeDef.symbol.deSkolemize where typeDef = " + typeDef)
218+
// we need to deSkolemize symbol so we get the same symbol as others would get when
219+
// inspecting type parameter from "outside"; see the discussion of skolems here:
220+
// https://groups.google.com/d/topic/scala-internals/0j8laVNTQsI/discussion
221+
typeDef.symbol.deSkolemize.setFlag(SPECIALIZED)
222+
typeDef
223+
211224
case sel @ Select(qual @ This(_), name) =>
212225
// warn if they are selecting a private[this] member which
213226
// also exists in a superclass, because they may be surprised

test/files/specialized/t6035.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
trait Foo[@specialized(Int) A] {
2+
def foo(x: A): A
3+
}
4+
5+
abstract class Inter extends Foo[Int]
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
class Baz extends Inter {
2+
def foo(x: Int) = x + 1
3+
}
4+
5+
object Test {
6+
def main(args: Array[String]) {
7+
// it's important that the type is Inter so we do not call Baz.foo(I)I directly!
8+
val baz: Inter = new Baz
9+
// here we should go through specialized version of foo and thus have zero boxing
10+
baz.foo(1)
11+
println(runtime.BoxesRunTime.integerBoxCount)
12+
}
13+
}

0 commit comments

Comments
 (0)