Skip to content

Commit d7e9107

Browse files
Work in progress
3 failing tests left: tests/run/t8933c.scala tests/pos/t348plus.scala dotty1 from idempotency1
1 parent ade4910 commit d7e9107

File tree

9 files changed

+234
-88
lines changed

9 files changed

+234
-88
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,10 @@ class Compiler {
8888
new NonLocalReturns, // Expand non-local returns
8989
new CapturedVars, // Represent vars captured by closures as heap objects
9090
new Constructors, // Collect initialization code in primary constructors
91-
// Note: constructors changes decls in transformTemplate, no InfoTransformers should be added after it
91+
// Note: constructors changes decls in transformTemplate, no InfoTransformers should be added after it
9292
new FunctionalInterfaces, // Rewrites closures to implement @specialized types of Functions.
93-
new GetClass), // Rewrites getClass calls on primitive types.
93+
new GetClass, // Rewrites getClass calls on primitive types.
94+
new Simplify), // Perform local optimizations, simplified versions of what linker does.
9495
List(new LambdaLift, // Lifts out nested functions to class scope, storing free variables in environments
9596
// Note: in this mini-phase block scopes are incorrect. No phases that rely on scopes should be here
9697
new ElimStaticThis, // Replace `this` references to static objects by global identifiers

compiler/src/dotty/tools/dotc/config/Printers.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,5 @@ object Printers {
3232
val pickling: Printer = noPrinter
3333
val inlining: Printer = noPrinter
3434
val exhaustivity: Printer = noPrinter
35+
val simplify: Printer = noPrinter
3536
}

compiler/src/dotty/tools/dotc/core/Scopes.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,10 @@ object Scopes {
9191
/** Is the scope empty? */
9292
def isEmpty: Boolean = lastEntry eq null
9393

94-
def foreach[U](p: Symbol => U)(implicit ctx: Context): Unit = toList foreach p
94+
/** Applies a function f to all Symbols of this Scope. */
95+
def foreach[U](f: Symbol => U)(implicit ctx: Context): Unit = toList.foreach(f)
9596

97+
/** Selects all Symbols of this Scope which satisfy a predicate. */
9698
def filter(p: Symbol => Boolean)(implicit ctx: Context): List[Symbol] = {
9799
ensureComplete()
98100
var syms: List[Symbol] = Nil
@@ -105,6 +107,10 @@ object Scopes {
105107
syms
106108
}
107109

110+
/** Tests whether a predicate holds for at least one Symbol of this Scope. */
111+
def exists(p: Symbol => Boolean)(implicit ctx: Context): Boolean = filter(p).isEmpty
112+
113+
/** Finds the first Symbol of this Scope satisfying a predicate, if any. */
108114
def find(p: Symbol => Boolean)(implicit ctx: Context): Symbol = filter(p) match {
109115
case sym :: _ => sym
110116
case _ => NoSymbol

compiler/src/dotty/tools/dotc/transform/linker/Simplify.scala

Lines changed: 113 additions & 80 deletions
Large diffs are not rendered by default.

compiler/test/dotc/tests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ class tests extends CompilerTest {
6868
}
6969

7070
implicit val defaultOptions: List[String] = noCheckOptions ++ {
71-
if (dotty.Properties.isRunByDrone) List("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef") // should be Ycheck:all, but #725
72-
else List("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef")
71+
if (dotty.Properties.isRunByDrone) List("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef,simplify") // should be Ycheck:all, but #725
72+
else List("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef,simplify")
7373
} ++ checkOptions ++ classPath
7474

7575
val testPickling = List("-Xprint-types", "-Ytest-pickler", "-Ystop-after:pickler", "-Yprintpos")

compiler/test/dotty/tools/dotc/CompilationTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@ class CompilationTests extends ParallelTesting {
3232
compileDir("../collection-strawman/src/main", defaultOptions) +
3333
compileDir("../compiler/src/dotty/tools/dotc/ast", defaultOptions) +
3434
compileDir("../compiler/src/dotty/tools/dotc/config", defaultOptions) +
35-
compileDir("../compiler/src/dotty/tools/dotc/core", allowDeepSubtypes) +
35+
compileDir("../compiler/src/dotty/tools/dotc/core", allowDeepSubtypes)
3636
compileDir("../compiler/src/dotty/tools/dotc/transform", allowDeepSubtypes) +
3737
compileDir("../compiler/src/dotty/tools/dotc/parsing", defaultOptions) +
3838
compileDir("../compiler/src/dotty/tools/dotc/printing", defaultOptions) +
3939
compileDir("../compiler/src/dotty/tools/dotc/reporting", defaultOptions) +
4040
compileDir("../compiler/src/dotty/tools/dotc/typer", defaultOptions) +
4141
compileDir("../compiler/src/dotty/tools/dotc/util", defaultOptions) +
4242
compileDir("../compiler/src/dotty/tools/io", defaultOptions) +
43-
compileDir("../compiler/src/dotty/tools/dotc/core", noCheckOptions ++ classPath) +
43+
compileDir("../compiler/src/dotty/tools/dotc/core", noCheckOptions ++ classPath)
4444
compileFile("../tests/pos/nullarify.scala", defaultOptions.and("-Ycheck:nullarify")) +
4545
compileFile("../tests/pos-scala2/rewrites.scala", scala2Mode.and("-rewrite")).copyToTarget() +
4646
compileFile("../tests/pos-special/t8146a.scala", allowDeepSubtypes) +

compiler/test/dotty/tools/vulpix/TestConfiguration.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ object TestConfiguration {
5050
Array("-classpath", paths)
5151
}
5252

53-
private val yCheckOptions = Array("-Ycheck:tailrec,resolveSuper,mixin,restoreScopes,labelDef")
53+
private val yCheckOptions = Array("-Ycheck:tailrec,resolveSuper,mixin,arrayConstructors,labelDef")
5454

5555
val defaultOptions = noCheckOptions ++ checkOptions ++ yCheckOptions ++ classPath :+ "-optimise"
5656
val allowDeepSubtypes = defaultOptions diff Array("-Yno-deep-subtypes")

tests/pos/bubbleUpNothing.scala

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
trait T {
2+
def apply(a1: String, a2: String, a3: String): String = a3
3+
}
4+
5+
object Test {
6+
def test1 =
7+
??? // Nothing.String.CharSequence.String.CharSequence.String
8+
.toString.subSequence(0, 1).toString.subSequence(0, 1).toString
9+
10+
def test2 =
11+
(new T {})
12+
.apply(???, "b", "c")
13+
.subSequence(0, 1).toString.subSequence(0, 1).toString
14+
15+
def test3 =
16+
(new T {})
17+
.apply("a", ???, "c")
18+
.subSequence(0, 1).toString.subSequence(0, 1).toString
19+
20+
def test4 =
21+
(new T {})
22+
.apply("a", "b", ???)
23+
.subSequence(0, 1).toString.subSequence(0, 1).toString
24+
25+
def test5 =
26+
(new T {})
27+
.apply("a", "b", ???)
28+
.subSequence(0, 1).toString.subSequence(0, 1).toString
29+
30+
def test6 =
31+
(if (???) "a" else "b")
32+
.subSequence(0, 1).toString.subSequence(0, 1).toString
33+
34+
def test7 =
35+
{ ???; "b"; "c" }
36+
.subSequence(0, 1).toString.subSequence(0, 1).toString
37+
38+
def test8 =
39+
{ "a"; ???; "c" }
40+
.subSequence(0, 1).toString.subSequence(0, 1).toString
41+
42+
def test9 =
43+
{ "a"; "b"; ??? }
44+
.toString.subSequence(0, 1).toString.subSequence(0, 1).toString
45+
46+
// run -optimise -Xprint:simplify
47+
// def test1(): String = ???(): String
48+
// def test2(): String = ???(): String
49+
// def test3(): String = ???(): String
50+
// def test4(): String = ???(): String
51+
// def test5(): String = ???(): String
52+
// def test6(): String = ???(): String
53+
// def test7(): String = ???(): String
54+
// def test8(): String = ???(): String
55+
// def test9(): String = ???(): String
56+
57+
def test10: Unit = {
58+
def fail = throw new IllegalArgumentException("")
59+
}
60+
61+
def test11: Unit = {
62+
trait Context
63+
trait Type
64+
trait Tree {
65+
def withType(tpe: Type)(implicit ctx: Context): Tree = this
66+
}
67+
68+
def readTree()(implicit ctx: Context): Any =
69+
(new Tree {}).withType(???)(ctx).withType(???)
70+
}
71+
}

tests/pos/devalify.scala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
object Test {
2+
def test0: Unit = {
3+
trait I {
4+
def foo: Any = null
5+
}
6+
val s: I = null
7+
s.foo
8+
}
9+
10+
def test1: Unit = {
11+
// `s1` is used once as a value, several times as a type. This tests shows
12+
// that Ycheck is happy despite devalify inlining (and removing) `s1`.
13+
val s1: String = "singleton"
14+
val s2: s1.type = s1
15+
16+
val t: Option[s1.type] = None
17+
18+
println(t)
19+
println((s2: s1.type))
20+
}
21+
22+
def test2: Unit = {
23+
class Foo {
24+
class Bar
25+
}
26+
27+
val foo = new Foo
28+
val subFoo = foo
29+
// Inlining `subFoo` changes the type of `subFooBar` from `subFoo.Bar` to `foo.Bar`
30+
val subFooBar = new subFoo.Bar
31+
32+
println(subFooBar)
33+
}
34+
}

0 commit comments

Comments
 (0)