Skip to content

Commit 7d1d454

Browse files
authored
Merge branch 'master' into fix-i3050
2 parents 00cf7f6 + c071dcf commit 7d1d454

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+470
-80
lines changed

.drone.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
pipeline:
22
test:
3-
image: lampepfl/dotty:2017-08-30
3+
image: lampepfl/dotty:2017-09-05
44
commands:
55
- ./project/scripts/sbt "${CI_TEST}"
66

77
publish_nightly:
8-
image: lampepfl/dotty:2017-08-30
8+
image: lampepfl/dotty:2017-09-05
99
environment:
1010
- NIGHTLYBUILD=yes
1111
commands:
@@ -20,7 +20,7 @@ pipeline:
2020
environment: nightly
2121

2222
publish_release:
23-
image: lampepfl/dotty:2017-08-30
23+
image: lampepfl/dotty:2017-09-05
2424
environment:
2525
- RELEASEBUILD=yes
2626
commands:
@@ -35,7 +35,7 @@ pipeline:
3535
environment: release
3636

3737
publish_sbt_release:
38-
image: lampepfl/dotty:2017-08-30
38+
image: lampepfl/dotty:2017-09-05
3939
environment:
4040
- RELEASEBUILD=yes
4141
commands:
@@ -48,7 +48,7 @@ pipeline:
4848
environment: sbt_release
4949

5050
documentation:
51-
image: lampepfl/dotty:2017-08-30
51+
image: lampepfl/dotty:2017-09-05
5252
commands:
5353
- ./project/scripts/genDocs "${CI_PUBLISH}" "$BOT_PASS"
5454
secrets: [ bot_pass ]

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ class Compiler {
100100
new ElimStaticThis, // Replace `this` references to static objects by global identifiers
101101
new Flatten, // Lift all inner classes to package scope
102102
new RestoreScopes), // Repair scopes rendered invalid by moving definitions in prior phases of the group
103-
List(new TransformWildcards, // Replace wildcards with default values
103+
List(new RenameLifted, // Renames lifted classes to local numbering scheme
104+
new TransformWildcards, // Replace wildcards with default values
104105
new MoveStatics, // Move static methods to companion classes
105106
new ExpandPrivate, // Widen private definitions accessed from nested classes
106107
new SelectStatic, // get rid of selects that would be compiled into GetStatic
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package dotty.tools.dotc
2+
3+
import dotty.tools.FatalError
4+
5+
class MissingCoreLibraryException(rootPackage: String) extends FatalError(
6+
s"""Could not find package $rootPackage from compiler core libraries.
7+
|Make sure the compiler core libraries are on the classpath.
8+
""".stripMargin
9+
)

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ object desugar {
503503
companionDefs(anyRef, companionMeths)
504504
else if (isValueClass) {
505505
constr0.vparamss match {
506-
case List(_ :: Nil) => companionDefs(anyRef, Nil)
506+
case (_ :: Nil) :: _ => companionDefs(anyRef, Nil)
507507
case _ => Nil // error will be emitted in typer
508508
}
509509
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,12 @@ object Decorators {
112112
else x1 :: xs1
113113
}
114114

115-
def foldRightBN[U](z: => U)(op: (T, => U) => U): U = xs.reverse.foldLeftBN(z)(op)
116-
117-
@tailrec final def foldLeftBN[U](z: => U)(op: (T, => U) => U): U = xs match {
118-
case Nil => z
119-
case x :: xs1 => xs1.foldLeftBN(op(x, z))(op)
115+
def foldRightBN[U](z: => U)(op: (T, => U) => U): U = {
116+
@tailrec def foldLeftBN(xs: List[T], acc: => U): U = xs match {
117+
case x :: xs1 => foldLeftBN(xs1, op(x, acc))
118+
case Nil => acc
119+
}
120+
foldLeftBN(xs.reverse, z)
120121
}
121122

122123
final def hasSameLengthAs[U](ys: List[U]): Boolean = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ class Definitions {
212212
* in `scalaShadowing` so they don't clash with the same-named `scala`
213213
* members at runtime.
214214
*/
215-
lazy val ScalaShadowingPackageVal = ctx.requiredPackage("scalaShadowing")
215+
lazy val ScalaShadowingPackageVal = ctx.requiredPackage(nme.scalaShadowing)
216216
lazy val ScalaShadowingPackageClass = ScalaShadowingPackageVal.moduleClass.asClass
217217

218218
/** Note: We cannot have same named methods defined in Object and Any (and AnyVal, for that matter)

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,14 +1192,23 @@ object Denotations {
11921192
def staticRef(path: Name, generateStubs: Boolean = true, isPackage: Boolean = false)(implicit ctx: Context): Denotation = {
11931193
def select(prefix: Denotation, selector: Name): Denotation = {
11941194
val owner = prefix.disambiguate(_.info.isParameterless)
1195+
def isPackageFromCoreLibMissing: Boolean = {
1196+
owner.symbol == defn.RootClass &&
1197+
(
1198+
selector == nme.scala_ || // if the scala package is missing, the stdlib must be missing
1199+
selector == nme.scalaShadowing // if the scalaShadowing package is missing, the dotty library must be missing
1200+
)
1201+
}
11951202
if (owner.exists) {
11961203
val result = if (isPackage) owner.info.decl(selector) else owner.info.member(selector)
11971204
if (result.exists) result
11981205
else {
11991206
val alt =
12001207
if (generateStubs) missingHook(owner.symbol.moduleClass, selector)
12011208
else NoSymbol
1202-
if (alt.exists) alt.denot else MissingRef(owner, selector)
1209+
if (alt.exists) alt.denot
1210+
else if (isPackageFromCoreLibMissing) throw new MissingCoreLibraryException(selector.toString)
1211+
else MissingRef(owner, selector)
12031212
}
12041213
}
12051214
else owner

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,7 @@ object StdNames {
491491
val runtimeMirror: N = "runtimeMirror"
492492
val sameElements: N = "sameElements"
493493
val scala_ : N = "scala"
494+
val scalaShadowing : N = "scalaShadowing"
494495
val selectDynamic: N = "selectDynamic"
495496
val selectDynamicMethod: N = "selectDynamicMethod"
496497
val selectOverloadedMethod: N = "selectOverloadedMethod"

compiler/src/dotty/tools/dotc/parsing/JavaTokens.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import collection.immutable.BitSet
66

77
object JavaTokens extends TokensCommon {
88
final val minToken = EMPTY
9-
final val maxToken = DOUBLE
9+
final def maxToken = DOUBLE
1010

1111
final val javaOnlyKeywords = tokenRange(INSTANCEOF, ASSERT)
1212
final val sharedKeywords = BitSet( IF, FOR, ELSE, THIS, NULL, NEW, SUPER, ABSTRACT, FINAL, PRIVATE, PROTECTED,

compiler/src/dotty/tools/dotc/parsing/Tokens.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import collection.immutable.BitSet
66
import core.Decorators._
77

88
abstract class TokensCommon {
9-
val maxToken: Int
9+
def maxToken: Int
1010

1111
type Token = Int
1212
type TokenSet = BitSet
@@ -145,7 +145,7 @@ abstract class TokensCommon {
145145

146146
object Tokens extends TokensCommon {
147147
final val minToken = EMPTY
148-
final val maxToken = XMLSTART
148+
final def maxToken = XMLSTART
149149

150150
final val INTERPOLATIONID = 10; enter(INTERPOLATIONID, "string interpolator")
151151
final val SYMBOLLIT = 11; enter(SYMBOLLIT, "symbol literal") // TODO: deprecate

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1636,9 +1636,9 @@ object messages {
16361636
|"""
16371637
}
16381638

1639-
case class ValueClassNeedsExactlyOneValParam(valueClass: Symbol)(implicit ctx: Context)
1639+
case class ValueClassNeedsOneValParam(valueClass: Symbol)(implicit ctx: Context)
16401640
extends Message(ValueClassNeedsExactlyOneValParamID) {
1641-
val msg = hl"""value class needs to have exactly one ${"val"} parameter"""
1641+
val msg = hl"""value class needs one ${"val"} parameter"""
16421642
val kind = "Syntax"
16431643
val explanation = ""
16441644
}

compiler/src/dotty/tools/dotc/transform/Constructors.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class Constructors extends MiniPhaseTransform with IdentityDenotTransformer { th
129129
// Produce aligned accessors and constructor parameters. We have to adjust
130130
// for any outer parameters, which are last in the sequence of original
131131
// parameter accessors but come first in the constructor parameter list.
132-
val accessors = cls.paramAccessors.filterNot(_.isSetter)
132+
val accessors = cls.paramAccessors.filterNot(x => x.isSetter || x.info.resultType.classSymbol == defn.ErasedPhantomClass)
133133
val vparamsWithOuterLast = vparams match {
134134
case vparam :: rest if vparam.name == nme.OUTER => rest ::: vparam :: Nil
135135
case _ => vparams

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,8 @@ object Erasure {
432432
}
433433
}
434434

435-
if (tree.symbol eq defn.Phantom_assume) PhantomErasure.erasedAssume
435+
if ((origSym eq defn.Phantom_assume) || (origSym.is(Flags.ParamAccessor) && wasPhantom(pt)))
436+
PhantomErasure.erasedAssume
436437
else recur(typed(tree.qualifier, AnySelectionProto))
437438
}
438439

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package dotty.tools.dotc.transform
2+
3+
import dotty.tools.dotc.core.Contexts.Context
4+
import dotty.tools.dotc.core.Decorators._
5+
import dotty.tools.dotc.core.DenotTransformers.SymTransformer
6+
import dotty.tools.dotc.core.Flags._
7+
import dotty.tools.dotc.core.NameKinds._
8+
import dotty.tools.dotc.core.Names._
9+
import dotty.tools.dotc.core.Phases
10+
import dotty.tools.dotc.core.SymDenotations.SymDenotation
11+
import dotty.tools.dotc.core.Symbols._
12+
import dotty.tools.dotc.transform.TreeTransforms.MiniPhaseTransform
13+
14+
/** Renames lifted classes to local numbering scheme */
15+
class RenameLifted extends MiniPhaseTransform with SymTransformer { thisTransformer =>
16+
17+
override def phaseName = "renameLifted"
18+
19+
override def runsAfterGroupsOf: Set[Class[_ <: Phases.Phase]] = Set(classOf[RestoreScopes])
20+
21+
def transformSym(ref: SymDenotation)(implicit ctx: Context): SymDenotation =
22+
if (needsRefresh(ref.symbol)) ref.copySymDenotation(name = refreshedName(ref.symbol))
23+
else ref
24+
25+
/** If the name of the symbol with a unique name needs to be refreshed
26+
* - if it is a lifted class
27+
* - if it is a lifted method
28+
*/
29+
private def needsRefresh(sym: Symbol)(implicit ctx: Context): Boolean =
30+
(sym.isClass || sym.is(Private | Method | JavaStatic)) && sym.name.is(UniqueName)
31+
32+
/** Refreshes the number of the name based on the full name of the symbol */
33+
private def refreshedName(sym: Symbol)(implicit ctx: Context): Name = {
34+
def rewriteUnique: PartialFunction[Name, Name] = {
35+
case name: DerivedName if name.info.kind == UniqueName =>
36+
val fullName = (sym.owner.fullName.toString + name.underlying).toTermName
37+
val freshName = UniqueName.fresh(fullName)
38+
val info = freshName.asInstanceOf[DerivedName].info
39+
DerivedName(name.underlying.rewrite(rewriteUnique), info)
40+
case DerivedName(underlying, info: QualifiedInfo) =>
41+
underlying.rewrite(rewriteUnique).derived(info)
42+
}
43+
44+
sym.name.rewrite(rewriteUnique)
45+
}
46+
}

compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,8 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
159159
val thatAsClazz = ctx.newSymbol(ctx.owner, nme.x_0, Synthetic, clazzType, coord = ctx.owner.pos) // x$0
160160
def wildcardAscription(tp: Type) = Typed(Underscore(tp), TypeTree(tp))
161161
val pattern = Bind(thatAsClazz, wildcardAscription(clazzType)) // x$0 @ (_: C)
162-
val comparisons = accessors map (accessor =>
163-
This(clazz).select(accessor).select(defn.Any_==).appliedTo(ref(thatAsClazz).select(accessor)))
162+
val comparisons = accessors collect { case accessor if !accessor.info.isPhantom =>
163+
This(clazz).select(accessor).select(defn.Any_==).appliedTo(ref(thatAsClazz).select(accessor)) }
164164
val rhs = // this.x == this$0.x && this.y == x$0.y
165165
if (comparisons.isEmpty) Literal(Constant(true)) else comparisons.reduceLeft(_ and _)
166166
val matchingCase = CaseDef(pattern, EmptyTree, rhs) // case x$0 @ (_: C) => this.x == this$0.x && this.y == x$0.y
@@ -186,7 +186,8 @@ class SyntheticMethods(thisTransformer: DenotTransformer) {
186186
* ```
187187
*/
188188
def valueHashCodeBody(implicit ctx: Context): Tree = {
189-
assert(accessors.length == 1)
189+
assert(accessors.nonEmpty)
190+
assert(accessors.tail.forall(_.info.isPhantom))
190191
ref(accessors.head).select(nme.hashCode_).ensureApplied
191192
}
192193

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -490,13 +490,17 @@ object Checking {
490490
param.isTerm && !param.is(Flags.Accessor)
491491
}
492492
clParamAccessors match {
493-
case List(param) =>
493+
case param :: params =>
494494
if (param.is(Mutable))
495495
ctx.error(ValueClassParameterMayNotBeAVar(clazz, param), param.pos)
496496
if (param.info.isPhantom)
497-
ctx.error("value class parameter must not be phantom", param.pos)
498-
case _ =>
499-
ctx.error(ValueClassNeedsExactlyOneValParam(clazz), clazz.pos)
497+
ctx.error("value class first parameter must not be phantom", param.pos)
498+
else {
499+
for (p <- params if !p.info.isPhantom)
500+
ctx.error("value class can only have one non phantom parameter", p.pos)
501+
}
502+
case Nil =>
503+
ctx.error(ValueClassNeedsOneValParam(clazz), clazz.pos)
500504
}
501505
}
502506
stats.foreach(checkValueClassMember)

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -292,27 +292,6 @@ class CompilationTests extends ParallelTesting {
292292

293293
tests.foreach(_.delete())
294294
}
295-
296-
private val (compilerSources, backendSources, backendJvmSources) = {
297-
val compilerDir = Paths.get("../compiler/src")
298-
val compilerSources0 = sources(Files.walk(compilerDir))
299-
300-
val backendDir = Paths.get("../scala-backend/src/compiler/scala/tools/nsc/backend")
301-
val backendJvmDir = Paths.get("../scala-backend/src/compiler/scala/tools/nsc/backend/jvm")
302-
303-
// NOTE: Keep these exclusions synchronized with the ones in the sbt build (Build.scala)
304-
val backendExcluded =
305-
List("JavaPlatform.scala", "Platform.scala", "ScalaPrimitives.scala")
306-
val backendJvmExcluded =
307-
List("BCodeICodeCommon.scala", "GenASM.scala", "GenBCode.scala", "ScalacBackendInterface.scala", "BackendStats.scala")
308-
309-
val backendSources0 =
310-
sources(Files.list(backendDir), excludedFiles = backendExcluded)
311-
val backendJvmSources0 =
312-
sources(Files.list(backendJvmDir), excludedFiles = backendJvmExcluded)
313-
314-
(compilerSources0, backendSources0, backendJvmSources0)
315-
}
316295
}
317296

318297
object CompilationTests {

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import org.junit.Test
55
import org.junit.Assert._
66
import interfaces._
77
import scala.collection.mutable.ListBuffer
8+
import java.nio.file._
89

910
/** Test that demonstrates how to use dotty-interfaces
1011
*
@@ -20,8 +21,12 @@ import scala.collection.mutable.ListBuffer
2021
class InterfaceEntryPointTest {
2122
@Test def runCompilerFromInterface = {
2223
val sources =
23-
List("../tests/pos/HelloWorld.scala").map(p => new java.io.File(p).getPath())
24-
val args = sources ++ List("-d", "../out/", "-usejavacp")
24+
List("../tests/pos/HelloWorld.scala").map(p => Paths.get(p).toAbsolutePath().toString)
25+
val out = Paths.get("../out/").toAbsolutePath()
26+
if (Files.notExists(out))
27+
Files.createDirectory(out)
28+
29+
val args = sources ++ List("-d", out.toString, "-usejavacp")
2530

2631
val mainClass = Class.forName("dotty.tools.dotc.Main")
2732
val process = mainClass.getMethod("process",
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package dotty
2+
package tools
3+
package dotc
4+
5+
import org.junit.{ Test, AfterClass }
6+
7+
import vulpix.{ ParallelTesting, SummaryReport, SummaryReporting, TestConfiguration }
8+
9+
import scala.concurrent.duration._
10+
11+
class MissingCoreLibTests extends ParallelTesting {
12+
import MissingCoreLibTests._
13+
import TestConfiguration._
14+
15+
// Test suite configuration --------------------------------------------------
16+
17+
def maxDuration = 30.seconds
18+
def numberOfSlaves = 5
19+
def safeMode = Properties.testsSafeMode
20+
def isInteractive = SummaryReport.isInteractive
21+
def testFilter = Properties.testsFilter
22+
23+
@Test def missingDottyLib: Unit = {
24+
val classPath = mkClassPath(Jars.dottyCompiler :: Jars.dottyInterfaces :: Jars.dottyExtras) // missing Jars.dottyLib
25+
val options = noCheckOptions ++ checkOptions ++ yCheckOptions ++ classPath
26+
compileFile("../tests/neg/nolib/Foo.scala", options).checkExpectedErrors()
27+
}
28+
29+
}
30+
31+
object MissingCoreLibTests {
32+
implicit val summaryReport: SummaryReporting = new SummaryReport
33+
@AfterClass def cleanup(): Unit = summaryReport.echoSummary()
34+
}

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -787,14 +787,14 @@ class ErrorMessagesTests extends ErrorMessagesTest {
787787
assertEquals("variable i", param.show)
788788
}
789789

790-
@Test def valueClassNeedsExactlyOneVal =
790+
@Test def valueClassNeedsOneVal =
791791
checkMessagesAfter("refchecks") {
792-
"""class MyValue(var i: Int, j: Int) extends AnyVal"""
792+
"""class MyValue() extends AnyVal"""
793793
}
794794
.expect { (ictx, messages) =>
795795
implicit val ctx: Context = ictx
796796
assertMessageCount(1, messages)
797-
val ValueClassNeedsExactlyOneValParam(valueClass) :: Nil = messages
797+
val ValueClassNeedsOneValParam(valueClass) :: Nil = messages
798798
assertEquals("class MyValue", valueClass.show)
799799
}
800800

0 commit comments

Comments
 (0)