Skip to content

Commit 9a46803

Browse files
committed
Add run test for specialisation
Adds a simple run test which checks for an expected number of generated specialised methods, and correct parameter types instantiation.
1 parent 4b93cf5 commit 9a46803

File tree

4 files changed

+97
-58
lines changed

4 files changed

+97
-58
lines changed

src/dotty/tools/dotc/Compiler.scala

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ import dotty.tools.backend.jvm.{LabelDefs, GenBCode}
2020
class Compiler {
2121

2222
/** Meta-ordering constraint:
23-
*
24-
* DenotTransformers that change the signature of their denotation's info must go
25-
* after erasure. The reason is that denotations are permanently referred to by
26-
* TermRefs which contain a signature. If the signature of a symbol would change,
27-
* all refs to it would become outdated - they could not be dereferenced in the
28-
* new phase.
29-
*
30-
* After erasure, signature changing denot-transformers are OK because erasure
31-
* will make sure that only term refs with fixed SymDenotations survive beyond it. This
32-
* is possible because:
33-
*
34-
* - splitter has run, so every ident or select refers to a unique symbol
35-
* - after erasure, asSeenFrom is the identity, so every reference has a
36-
* plain SymDenotation, as opposed to a UniqueRefDenotation.
37-
*/
23+
*
24+
* DenotTransformers that change the signature of their denotation's info must go
25+
* after erasure. The reason is that denotations are permanently referred to by
26+
* TermRefs which contain a signature. If the signature of a symbol would change,
27+
* all refs to it would become outdated - they could not be dereferenced in the
28+
* new phase.
29+
*
30+
* After erasure, signature changing denot-transformers are OK because erasure
31+
* will make sure that only term refs with fixed SymDenotations survive beyond it. This
32+
* is possible because:
33+
*
34+
* - splitter has run, so every ident or select refers to a unique symbol
35+
* - after erasure, asSeenFrom is the identity, so every reference has a
36+
* plain SymDenotation, as opposed to a UniqueRefDenotation.
37+
*/
3838
def phases: List[List[Phase]] =
3939
List(
4040
List(new FrontEnd),
@@ -87,13 +87,13 @@ class Compiler {
8787
}
8888

8989
/** Produces the following contexts, from outermost to innermost
90-
*
91-
* bootStrap: A context with next available runId and a scope consisting of
92-
* the RootPackage _root_
93-
* start A context with RootClass as owner and the necessary initializations
94-
* for type checking.
95-
* imports For each element of RootImports, an import context
96-
*/
90+
*
91+
* bootStrap: A context with next available runId and a scope consisting of
92+
* the RootPackage _root_
93+
* start A context with RootClass as owner and the necessary initializations
94+
* for type checking.
95+
* imports For each element of RootImports, an import context
96+
*/
9797
def rootContext(implicit ctx: Context): Context = {
9898
ctx.definitions.init(ctx)
9999
ctx.setPhasePlan(phases)

test/dotc/tests.scala

Lines changed: 28 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,19 @@ import org.junit.experimental.categories._
99
class tests extends CompilerTest {
1010

1111
val noCheckOptions = List(
12-
// "-verbose",
13-
// "-Ylog:frontend",
14-
// "-Xprompt",
15-
// "-explaintypes",
16-
// "-Yshow-suppressed-errors",
12+
// "-verbose",
13+
// "-Ylog:frontend",
14+
// "-Xprompt",
15+
// "-explaintypes",
16+
// "-Yshow-suppressed-errors",
1717
)
1818

1919
val defaultOutputDir = "./out/"
2020

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

@@ -51,11 +50,10 @@ class tests extends CompilerTest {
5150
val dotcDir = toolsDir + "dotc/"
5251
val coreDir = dotcDir + "core/"
5352

54-
/*
5553

5654
@Test def pickle_pickleOK = compileDir(testsDir, "pickling", testPickling)
57-
// This directory doesn't exist anymore
58-
// @Test def pickle_pickling = compileDir(coreDir, "pickling", testPickling)
55+
// This directory doesn't exist anymore
56+
// @Test def pickle_pickling = compileDir(coreDir, "pickling", testPickling)
5957
@Test def pickle_ast = compileDir(dotcDir, "ast", testPickling)
6058

6159
//@Test def pickle_core = compileDir(dotcDir, "core", testPickling, xerrors = 2) // two spurious comparison errors in Types and TypeOps
@@ -95,7 +93,6 @@ class tests extends CompilerTest {
9593
@Test def pos_packageObj = compileFile(posDir, "i0239", twice)
9694
@Test def pos_anonClassSubtyping = compileFile(posDir, "anonClassSubtyping", twice)
9795
@Test def pos_extmethods = compileFile(posDir, "extmethods", twice)
98-
//@Test def pos_specialization = compileFile(posDir, "specialization")
9996

10097
@Test def pos_all = compileFiles(posDir) // twice omitted to make tests run faster
10198

@@ -148,8 +145,8 @@ class tests extends CompilerTest {
148145
@Test def neg_instantiateAbstract = compileFile(negDir, "instantiateAbstract", xerrors = 8)
149146
@Test def neg_selfInheritance = compileFile(negDir, "selfInheritance", xerrors = 5)
150147

151-
//@Test def run_all = runFiles(runDir)
152-
//@Test def run_spec = runFile(runDir, "specialization")
148+
149+
@Test def run_all = runFiles(runDir)
153150

154151

155152
@Test def dotty = compileDir(dottyDir, "tools", "-deep" :: allowDeepSubtypes ++ twice) // note the -deep argument
@@ -159,8 +156,8 @@ class tests extends CompilerTest {
159156
@Test def dotc_config = compileDir(dotcDir, "config")
160157
@Test def dotc_core = compileDir(dotcDir, "core")("-Yno-double-bindings" :: allowDeepSubtypes)// twice omitted to make tests run faster
161158

162-
// This directory doesn't exist anymore
163-
// @Test def dotc_core_pickling = compileDir(coreDir, "pickling")(allowDeepSubtypes)// twice omitted to make tests run faster
159+
// This directory doesn't exist anymore
160+
// @Test def dotc_core_pickling = compileDir(coreDir, "pickling")(allowDeepSubtypes)// twice omitted to make tests run faster
164161

165162
@Test def dotc_transform = compileDir(dotcDir, "transform")// twice omitted to make tests run faster
166163

@@ -171,9 +168,9 @@ class tests extends CompilerTest {
171168
@Test def dotc_reporting = compileDir(dotcDir, "reporting") // twice omitted to make tests run faster
172169

173170
@Test def dotc_typer = compileDir(dotcDir, "typer")// twice omitted to make tests run faster
174-
// error: error while loading Checking$$anon$2$,
175-
// class file 'target/scala-2.11/dotty_2.11-0.1-SNAPSHOT.jar(dotty/tools/dotc/typer/Checking$$anon$2.class)'
176-
// has location not matching its contents: contains class $anon
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
177174

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

@@ -184,19 +181,19 @@ class tests extends CompilerTest {
184181
//@Test def tools = compileDir(dottyDir, "tools", "-deep" :: Nil)(allowDeepSubtypes)
185182

186183
@Test def testNonCyclic = compileList("testNonCyclic", List(
187-
dotcDir + "CompilationUnit.scala",
188-
coreDir + "Types.scala",
189-
dotcDir + "ast/Trees.scala"
190-
), List("-Xprompt") ++ staleSymbolError ++ twice)
184+
dotcDir + "CompilationUnit.scala",
185+
coreDir + "Types.scala",
186+
dotcDir + "ast/Trees.scala"
187+
), List("-Xprompt") ++ staleSymbolError ++ twice)
191188

192189
@Test def testIssue_34 = compileList("testIssue_34", List(
193-
dotcDir + "config/Properties.scala",
194-
dotcDir + "config/PathResolver.scala"
195-
), List(/* "-Ylog:frontend", */ "-Xprompt") ++ staleSymbolError ++ twice)
190+
dotcDir + "config/Properties.scala",
191+
dotcDir + "config/PathResolver.scala"
192+
), List(/* "-Ylog:frontend", */ "-Xprompt") ++ staleSymbolError ++ twice)
196193

197194
val javaDir = "./tests/pos/java-interop/"
198195
@Test def java_all = compileFiles(javaDir, twice)
199-
*/
196+
200197
@Test def specialization = compileFile(specialDir, "specialization", List("-Xprint:specialize"))
201198
@Test def mutual_spec = compileFile(specialDir, "mutual_specialization", List("-Xprint:specialize"))
202199
@Test def return_spec = compileFile(specialDir, "return_specialization", List("-Xprint:specialize"))
@@ -209,12 +206,7 @@ class tests extends CompilerTest {
209206
@Test def pos_this_specialization = compileFile(specialDir, "this_specialization", List("-Xprint:specialize"))
210207
@Test def pos_spec_all = compileFiles(specialDir)
211208

212-
213-
//@Test def mini_method = compileFiles(miniMethodDir)//, List("-Xprint:all"))
214-
//@Test def mini_more = compileFiles(miniMoreDir)//, List("-Xprint:all"))
215-
//@Test def pos_all = compileFiles(posDir)//, List("-Xprint:all"))
216-
217-
//@Test def pos_si7638 = compileFile(posDir, "SI-7638", List("-Xprint:all"))
218-
//@Test def test = compileFile(posDir, "t247", List("-Xprint:all"))
209+
@Test def run_spec = runFile(runDir, "specialization")
210+
219211
//@Test def dotc_compilercommand = compileFile(dotcDir + "config/", "CompilerCommand")
220-
}
212+
}

tests/run/specialization.check

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
10
2+
82
3+
3
4+
int
5+
int,double
6+
double,int

tests/run/specialization.scala

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
object Test extends dotty.runtime.LegacyApp {
2+
3+
class Foo {
4+
def foo[@specialized U](u: U) = u
5+
}
6+
class Bar {
7+
def bar[@specialized U, V](u: U, v: V) = v
8+
}
9+
class Baz {
10+
def baz[@specialized(Int, Char) V](v: V): V = v
11+
}
12+
13+
override def main(args: Array[String]): Unit = {
14+
/**
15+
* Expected output is:
16+
*
17+
* 10
18+
* 82
19+
* 3
20+
* int
21+
* double,int
22+
* int,double
23+
*/
24+
25+
val a = new Foo
26+
val b = new Bar
27+
val c = new Baz
28+
val foo_methods = a.getClass.getMethods
29+
val bar_methods = b.getClass.getMethods
30+
val baz_methods = c.getClass.getMethods
31+
println(foo_methods.filter(_.toString.contains("foo")).length)
32+
println(bar_methods.filter(_.toString.contains("bar")).length)
33+
println(baz_methods.filter(_.toString.contains("baz")).length)
34+
35+
val baz_int_param = baz_methods.filter(_.toString.contains("$mcI$sp")).head.getParameterTypes.mkString(",")
36+
val bar_int_double_params = bar_methods.filter(s => s.toString.contains("$mcDI$sp") || s.toString.contains("$mcID$sp"))
37+
println(baz_int_param)
38+
println(bar_int_double_params.head.getParameterTypes.mkString(","))
39+
println(bar_int_double_params.tail.head.getParameterTypes.mkString(","))
40+
}
41+
}

0 commit comments

Comments
 (0)