Skip to content

Commit 7b75837

Browse files
committed
Handle @specialized(AnyRef)
1 parent 9a46803 commit 7b75837

File tree

6 files changed

+36
-28
lines changed

6 files changed

+36
-28
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,4 +122,4 @@ class Compiler {
122122
reset()
123123
new Run(this)(rootContext)
124124
}
125-
}
125+
}

src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ScalaSettings extends Settings.SettingGroup {
3333
val usejavacp = BooleanSetting("-usejavacp", "Utilize the java.class.path in classpath resolution.")
3434
val verbose = BooleanSetting("-verbose", "Output messages about what the compiler is doing.")
3535
val version = BooleanSetting("-version", "Print product version and exit.")
36-
val pageWidth = IntSetting("-pagewidth", "Set page width", 160)
36+
val pageWidth = IntSetting("-pagewidth", "Set page width", 80)
3737

3838
val jvmargs = PrefixSetting("-J<flag>", "-J", "Pass <flag> directly to the runtime system.")
3939
val defines = PrefixSetting("-Dproperty=value", "-D", "Pass -Dproperty=value directly to the runtime system.")

src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,10 @@ class Definitions {
317317
lazy val LanguageModuleClass = ctx.requiredModule("dotty.language").moduleClass.asClass
318318

319319
// Annotation base classes
320-
lazy val AnnotationClass = ctx.requiredClass("scala.annotation.Annotation")
321-
lazy val ClassfileAnnotationClass = ctx.requiredClass("scala.annotation.ClassfileAnnotation")
322-
lazy val StaticAnnotationClass = ctx.requiredClass("scala.annotation.StaticAnnotation")
323-
lazy val TailrecAnnotationClass = ctx.requiredClass("scala.annotation.tailrec")
320+
lazy val AnnotationClass = ctx.requiredClass("scala.annotation.Annotation")
321+
lazy val ClassfileAnnotationClass = ctx.requiredClass("scala.annotation.ClassfileAnnotation")
322+
lazy val StaticAnnotationClass = ctx.requiredClass("scala.annotation.StaticAnnotation")
323+
lazy val TailrecAnnotationClass = ctx.requiredClass("scala.annotation.tailrec")
324324
lazy val RemoteAnnot = ctx.requiredClass("scala.remote")
325325
lazy val SerialVersionUIDAnnot = ctx.requiredClass("scala.SerialVersionUID")
326326
lazy val TransientAnnot = ctx.requiredClass("scala.transient")

src/dotty/tools/dotc/transform/PreSpecializer.scala

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import dotty.tools.dotc.core.Contexts.Context
77
import dotty.tools.dotc.core.StdNames._
88
import dotty.tools.dotc.core.{Flags, Definitions}
99
import dotty.tools.dotc.core.Symbols.Symbol
10-
import dotty.tools.dotc.core.Types.Type
10+
import dotty.tools.dotc.core.Types.{TermRef, Type}
1111
import dotty.tools.dotc.transform.TreeTransforms.{TransformerInfo, MiniPhaseTransform}
1212

1313
/**
@@ -19,9 +19,14 @@ class PreSpecializer extends MiniPhaseTransform {
1919
override def phaseName: String = "prespecialize"
2020

2121
private final def primitiveCompanionToPrimitive(companion: Type)(implicit ctx: Context) = {
22-
val claz = companion.termSymbol.companionClass
23-
assert(ctx.definitions.ScalaValueClasses.contains(claz))
24-
claz.typeRef
22+
if (companion.asInstanceOf[TermRef].name.toString == "AnyRef") { // Handles `@specialized(AnyRef)` cases
23+
defn.AnyRefType
24+
}
25+
else {
26+
val claz = companion.termSymbol.companionClass
27+
assert(ctx.definitions.ScalaValueClasses.contains(claz))
28+
claz.typeRef
29+
}
2530
}
2631

2732
def defn(implicit ctx: Context): Definitions = ctx.definitions
@@ -55,8 +60,11 @@ class PreSpecializer extends MiniPhaseTransform {
5560
val args = annot.arguments
5661
if (args.isEmpty) primitiveTypes
5762
else args.head match {
58-
case a@Typed(SeqLiteral(types), _) => types.map(t => primitiveCompanionToPrimitive(t.tpe)) // Matches the expected `@specialized(...)` annotations
59-
case a@Select(Ident(_), _) => primitiveTypes // Matches `Select(Ident(Specializable), Primitives)` which is used in several instances
63+
case a@Typed(SeqLiteral(types), _) => // Matches the expected `@specialized(...)` annotations
64+
types.map(t => primitiveCompanionToPrimitive(t.tpe))
65+
66+
case a@Select(Ident(_), _) => primitiveTypes // Matches `Select(Ident(Specializable), Primitives)`
67+
// which is used in several instances in the compiler
6068
case _ => ctx.error("surprising match on specialized annotation"); Nil
6169
}
6270
case nil => Nil

src/dotty/tools/dotc/transform/TypeSpecializer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ class TypeSpecializer extends MiniPhaseTransform with InfoTransformer {
3030
defn.FloatType -> "F",
3131
defn.DoubleType -> "D",
3232
defn.CharType -> "C",
33-
defn.UnitType -> "V")
33+
defn.UnitType -> "V",
34+
defn.AnyRefType -> "A")
3435

3536
private def primitiveTypes(implicit ctx: Context) =
3637
List(defn.ByteType,

test/dotc/tests.scala

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ class tests extends CompilerTest {
1414
// "-Xprompt",
1515
// "-explaintypes",
1616
// "-Yshow-suppressed-errors",
17-
)
17+
"-pagewidth", "160")
1818

1919
val defaultOutputDir = "./out/"
2020

2121
implicit val defaultOptions = noCheckOptions ++ List(
22-
"-Yno-deep-subtypes", "-Yno-double-bindings",
23-
"-Ycheck:tailrec,resolveSuper,mixin,restoreScopes",
24-
"-d", defaultOutputDir
22+
"-Yno-deep-subtypes", "-Yno-double-bindings",
23+
"-Ycheck:tailrec,resolveSuper,mixin,restoreScopes",
24+
"-d", defaultOutputDir
2525
)
2626
val testPickling = List("-Xprint-types", "-Ytest-pickler", "-Ystop-after:pickler")
2727

@@ -50,7 +50,6 @@ class tests extends CompilerTest {
5050
val dotcDir = toolsDir + "dotc/"
5151
val coreDir = dotcDir + "core/"
5252

53-
5453
@Test def pickle_pickleOK = compileDir(testsDir, "pickling", testPickling)
5554
// This directory doesn't exist anymore
5655
// @Test def pickle_pickling = compileDir(coreDir, "pickling", testPickling)
@@ -168,9 +167,9 @@ class tests extends CompilerTest {
168167
@Test def dotc_reporting = compileDir(dotcDir, "reporting") // twice omitted to make tests run faster
169168

170169
@Test def dotc_typer = compileDir(dotcDir, "typer")// twice omitted to make tests run faster
171-
// error: error while loading Checking$$anon$2$,
172-
// class file 'target/scala-2.11/dotty_2.11-0.1-SNAPSHOT.jar(dotty/tools/dotc/typer/Checking$$anon$2.class)'
173-
// has location not matching its contents: contains class $anon
170+
// error: error while loading Checking$$anon$2$,
171+
// class file 'target/scala-2.11/dotty_2.11-0.1-SNAPSHOT.jar(dotty/tools/dotc/typer/Checking$$anon$2.class)'
172+
// has location not matching its contents: contains class $anon
174173

175174
@Test def dotc_util = compileDir(dotcDir, "util") // twice omitted to make tests run faster
176175

@@ -181,15 +180,15 @@ class tests extends CompilerTest {
181180
//@Test def tools = compileDir(dottyDir, "tools", "-deep" :: Nil)(allowDeepSubtypes)
182181

183182
@Test def testNonCyclic = compileList("testNonCyclic", List(
184-
dotcDir + "CompilationUnit.scala",
185-
coreDir + "Types.scala",
186-
dotcDir + "ast/Trees.scala"
187-
), List("-Xprompt") ++ staleSymbolError ++ twice)
183+
dotcDir + "CompilationUnit.scala",
184+
coreDir + "Types.scala",
185+
dotcDir + "ast/Trees.scala"
186+
), List("-Xprompt") ++ staleSymbolError ++ twice)
188187

189188
@Test def testIssue_34 = compileList("testIssue_34", List(
190-
dotcDir + "config/Properties.scala",
191-
dotcDir + "config/PathResolver.scala"
192-
), List(/* "-Ylog:frontend", */ "-Xprompt") ++ staleSymbolError ++ twice)
189+
dotcDir + "config/Properties.scala",
190+
dotcDir + "config/PathResolver.scala"
191+
), List(/* "-Ylog:frontend", */ "-Xprompt") ++ staleSymbolError ++ twice)
193192

194193
val javaDir = "./tests/pos/java-interop/"
195194
@Test def java_all = compileFiles(javaDir, twice)

0 commit comments

Comments
 (0)