From b6142d276fd3b625764e4e93e699aafb309c4093 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 27 Jul 2017 17:18:59 +0200 Subject: [PATCH 01/24] Implement value classes with phantom parameters In this implementation the first parameter of the value class must be a subtype of scala.Any. Every other parameter must be phantom. --- .../src/dotty/tools/dotc/ast/Desugar.scala | 2 +- .../dotc/reporting/diagnostic/messages.scala | 4 ++-- .../tools/dotc/transform/Constructors.scala | 2 +- .../dotty/tools/dotc/transform/Erasure.scala | 3 ++- .../dotc/transform/SyntheticMethods.scala | 7 +++--- .../src/dotty/tools/dotc/typer/Checking.scala | 12 ++++++---- .../dotc/reporting/ErrorMessagesTests.scala | 6 ++--- tests/neg/phantom-in-value-class.scala | 11 ++++++++++ tests/run/phantom-in-value-class.scala | 22 +++++++++++++++++++ 9 files changed, 54 insertions(+), 15 deletions(-) create mode 100644 tests/neg/phantom-in-value-class.scala create mode 100644 tests/run/phantom-in-value-class.scala diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index d311ac834450..8a86b26cdf1e 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -503,7 +503,7 @@ object desugar { companionDefs(anyRef, companionMeths) else if (isValueClass) { constr0.vparamss match { - case List(_ :: Nil) => companionDefs(anyRef, Nil) + case (_ :: Nil) :: _ => companionDefs(anyRef, Nil) case _ => Nil // error will be emitted in typer } } diff --git a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala index 3b398d23661c..c0da98fa8946 100644 --- a/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala +++ b/compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala @@ -1620,9 +1620,9 @@ object messages { |""" } - case class ValueClassNeedsExactlyOneValParam(valueClass: Symbol)(implicit ctx: Context) + case class ValueClassNeedsOneValParam(valueClass: Symbol)(implicit ctx: Context) extends Message(ValueClassNeedsExactlyOneValParamID) { - val msg = hl"""value class needs to have exactly one ${"val"} parameter""" + val msg = hl"""value class needs one ${"val"} parameter""" val kind = "Syntax" val explanation = "" } diff --git a/compiler/src/dotty/tools/dotc/transform/Constructors.scala b/compiler/src/dotty/tools/dotc/transform/Constructors.scala index 4698930691e2..969f4f548a07 100644 --- a/compiler/src/dotty/tools/dotc/transform/Constructors.scala +++ b/compiler/src/dotty/tools/dotc/transform/Constructors.scala @@ -129,7 +129,7 @@ class Constructors extends MiniPhaseTransform with IdentityDenotTransformer { th // Produce aligned accessors and constructor parameters. We have to adjust // for any outer parameters, which are last in the sequence of original // parameter accessors but come first in the constructor parameter list. - val accessors = cls.paramAccessors.filterNot(_.isSetter) + val accessors = cls.paramAccessors.filterNot(x => x.isSetter || x.info.resultType.classSymbol == defn.ErasedPhantomClass) val vparamsWithOuterLast = vparams match { case vparam :: rest if vparam.name == nme.OUTER => rest ::: vparam :: Nil case _ => vparams diff --git a/compiler/src/dotty/tools/dotc/transform/Erasure.scala b/compiler/src/dotty/tools/dotc/transform/Erasure.scala index 5837b2b6904a..9f3b603ac66f 100644 --- a/compiler/src/dotty/tools/dotc/transform/Erasure.scala +++ b/compiler/src/dotty/tools/dotc/transform/Erasure.scala @@ -414,7 +414,8 @@ object Erasure { } } - if (tree.symbol eq defn.Phantom_assume) PhantomErasure.erasedAssume + if ((origSym eq defn.Phantom_assume) || (origSym.is(Flags.ParamAccessor) && wasPhantom(pt))) + PhantomErasure.erasedAssume else recur(typed(tree.qualifier, AnySelectionProto)) } diff --git a/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala b/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala index c8bef28dcd66..20a8a08b40d3 100644 --- a/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala +++ b/compiler/src/dotty/tools/dotc/transform/SyntheticMethods.scala @@ -159,8 +159,8 @@ class SyntheticMethods(thisTransformer: DenotTransformer) { val thatAsClazz = ctx.newSymbol(ctx.owner, nme.x_0, Synthetic, clazzType, coord = ctx.owner.pos) // x$0 def wildcardAscription(tp: Type) = Typed(Underscore(tp), TypeTree(tp)) val pattern = Bind(thatAsClazz, wildcardAscription(clazzType)) // x$0 @ (_: C) - val comparisons = accessors map (accessor => - This(clazz).select(accessor).select(defn.Any_==).appliedTo(ref(thatAsClazz).select(accessor))) + val comparisons = accessors collect { case accessor if !accessor.info.isPhantom => + This(clazz).select(accessor).select(defn.Any_==).appliedTo(ref(thatAsClazz).select(accessor)) } val rhs = // this.x == this$0.x && this.y == x$0.y if (comparisons.isEmpty) Literal(Constant(true)) else comparisons.reduceLeft(_ and _) 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) { * ``` */ def valueHashCodeBody(implicit ctx: Context): Tree = { - assert(accessors.length == 1) + assert(accessors.nonEmpty) + assert(accessors.tail.forall(_.info.isPhantom)) ref(accessors.head).select(nme.hashCode_).ensureApplied } diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 72ce89a33942..4156fbd16fd7 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -489,13 +489,17 @@ object Checking { param.isTerm && !param.is(Flags.Accessor) } clParamAccessors match { - case List(param) => + case param :: params => if (param.is(Mutable)) ctx.error(ValueClassParameterMayNotBeAVar(clazz, param), param.pos) if (param.info.isPhantom) - ctx.error("value class parameter must not be phantom", param.pos) - case _ => - ctx.error(ValueClassNeedsExactlyOneValParam(clazz), clazz.pos) + ctx.error("value class first parameter must not be phantom.", param.pos) + else { + for (p <- params if !p.info.isPhantom) + ctx.error("value class can only have one non phantom parameter", p.pos) + } + case Nil => + ctx.error(ValueClassNeedsOneValParam(clazz), clazz.pos) } } stats.foreach(checkValueClassMember) diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala index a597ef498b07..c51151331fa7 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala @@ -772,14 +772,14 @@ class ErrorMessagesTests extends ErrorMessagesTest { assertEquals("variable i", param.show) } - @Test def valueClassNeedsExactlyOneVal = + @Test def valueClassNeedsOneVal = checkMessagesAfter("refchecks") { - """class MyValue(var i: Int, j: Int) extends AnyVal""" + """class MyValue() extends AnyVal""" } .expect { (ictx, messages) => implicit val ctx: Context = ictx assertMessageCount(1, messages) - val ValueClassNeedsExactlyOneValParam(valueClass) :: Nil = messages + val ValueClassNeedsOneValParam(valueClass) :: Nil = messages assertEquals("class MyValue", valueClass.show) } diff --git a/tests/neg/phantom-in-value-class.scala b/tests/neg/phantom-in-value-class.scala new file mode 100644 index 000000000000..23f225767f41 --- /dev/null +++ b/tests/neg/phantom-in-value-class.scala @@ -0,0 +1,11 @@ +import MyPhantom._ + + +class Cursed1(val p: Boo) extends AnyVal // error + +class Cursed2(val n: Int)(val a: Int) extends AnyVal // error + +object MyPhantom extends Phantom { + type Boo <: super[MyPhantom].Any + def boo: Boo = assume +} diff --git a/tests/run/phantom-in-value-class.scala b/tests/run/phantom-in-value-class.scala new file mode 100644 index 000000000000..daa93a5b31a5 --- /dev/null +++ b/tests/run/phantom-in-value-class.scala @@ -0,0 +1,22 @@ +import MyPhantom._ + +object Test { + def main(args: Array[String]): Unit = { + val cursed = new Cursed(7)(boo) + val cursed2 = new Cursed(7)(boo) + cursed.p + cursed2.p + } +} + + +class Cursed(val n: Int)(val p: Boo) extends AnyVal + +class Cursed2[B <: Boo](val n: Int)(val p: B) extends AnyVal + +class Cursed3[B <: Boo](val n: Int)(val p1: Boo, val p2: B) extends AnyVal + +object MyPhantom extends Phantom { + type Boo <: super[MyPhantom].Any + def boo: Boo = assume +} From e2db2923a5ab8150b59ba712fa493cd989d369e7 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 24 Aug 2017 12:00:14 +0200 Subject: [PATCH 02/24] Remove extra `.` --- compiler/src/dotty/tools/dotc/typer/Checking.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 4156fbd16fd7..6c03582a16a4 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -493,7 +493,7 @@ object Checking { if (param.is(Mutable)) ctx.error(ValueClassParameterMayNotBeAVar(clazz, param), param.pos) if (param.info.isPhantom) - ctx.error("value class first parameter must not be phantom.", param.pos) + ctx.error("value class first parameter must not be phantom", param.pos) else { for (p <- params if !p.info.isPhantom) ctx.error("value class can only have one non phantom parameter", p.pos) From 9304f3be9190184b419953e9631920d557fc76a8 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 31 Aug 2017 16:37:20 +0200 Subject: [PATCH 03/24] Remove dead code --- .../dotty/tools/dotc/CompilationTests.scala | 21 ------------------- 1 file changed, 21 deletions(-) diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 436958683fb1..d8cfee48c423 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -292,27 +292,6 @@ class CompilationTests extends ParallelTesting { tests.foreach(_.delete()) } - - private val (compilerSources, backendSources, backendJvmSources) = { - val compilerDir = Paths.get("../compiler/src") - val compilerSources0 = sources(Files.walk(compilerDir)) - - val backendDir = Paths.get("../scala-backend/src/compiler/scala/tools/nsc/backend") - val backendJvmDir = Paths.get("../scala-backend/src/compiler/scala/tools/nsc/backend/jvm") - - // NOTE: Keep these exclusions synchronized with the ones in the sbt build (Build.scala) - val backendExcluded = - List("JavaPlatform.scala", "Platform.scala", "ScalaPrimitives.scala") - val backendJvmExcluded = - List("BCodeICodeCommon.scala", "GenASM.scala", "GenBCode.scala", "ScalacBackendInterface.scala", "BackendStats.scala") - - val backendSources0 = - sources(Files.list(backendDir), excludedFiles = backendExcluded) - val backendJvmSources0 = - sources(Files.list(backendJvmDir), excludedFiles = backendJvmExcluded) - - (compilerSources0, backendSources0, backendJvmSources0) - } } object CompilationTests { From 796bcf8f7e267b467dc9b1208d9a29e8368dffa5 Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Wed, 30 Aug 2017 17:53:23 +0200 Subject: [PATCH 04/24] Upgrade Drone to 0.8 --- .drone.yml | 38 ++++++++++++++++++++------------------ .drone.yml.sig | 1 - 2 files changed, 20 insertions(+), 19 deletions(-) delete mode 100644 .drone.yml.sig diff --git a/.drone.yml b/.drone.yml index c6198f67f795..39091f6009a6 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,50 +1,48 @@ -# After updating this file, you need to re-sign it: -# -# - Install [drone-cli](http://readme.drone.io/usage/getting-started-cli/) -# - Copy your token from http://dotty-ci.epfl.ch/account (Click SHOW TOKEN) -# - DRONE_TOKEN=your-token DRONE_SERVER=http://dotty-ci.epfl.ch drone sign lampepfl/dotty -# -# Please note that the signing can only be done by collaborators. - pipeline: test: image: lampepfl/dotty:2017-08-30 commands: - ./project/scripts/sbt "${CI_TEST}" - when: - branch: - exclude: gh-pages publish_nightly: image: lampepfl/dotty:2017-08-30 + environment: + - NIGHTLYBUILD=yes commands: - ./project/scripts/sbt ";clean ;publishLocal" "${CI_PUBLISH}" - ./project/scripts/sbt "sbt-dotty/scripted source-dependencies/*" "${CI_PUBLISH}" - - NIGHTLYBUILD="yes" ./project/scripts/sbtPublish ${CI_PUBLISH} $SONATYPE_USER $SONATYPE_PW $PGP_PW ";dotty-bootstrapped/publishSigned ;sonatypeRelease" + - ./project/scripts/sbtPublish "${CI_PUBLISH}" "$SONATYPE_USER" "$SONATYPE_PW" "$PGP_PW" ";dotty-bootstrapped/publishSigned ;sonatypeRelease" volumes: - /home/drone/keys:/keys + secrets: [ sonatype_user, sonatype_pw, pgp_pw ] when: event: deployment environment: nightly publish_release: image: lampepfl/dotty:2017-08-30 + environment: + - RELEASEBUILD=yes commands: - ./project/scripts/sbt ";clean ;publishLocal" "${CI_PUBLISH}" - ./project/scripts/sbt "sbt-dotty/scripted source-dependencies/*" "${CI_PUBLISH}" - - RELEASEBUILD="yes" ./project/scripts/sbtPublish ${CI_PUBLISH} $SONATYPE_USER $SONATYPE_PW $PGP_PW ";dotty-bootstrapped/publishSigned ;sonatypeRelease" + - ./project/scripts/sbtPublish "${CI_PUBLISH}" "$SONATYPE_USER" "$SONATYPE_PW" "$PGP_PW" ";dotty-bootstrapped/publishSigned ;sonatypeRelease" volumes: - /home/drone/keys:/keys + secrets: [ sonatype_user, sonatype_pw, pgp_pw ] when: event: deployment environment: release publish_sbt_release: image: lampepfl/dotty:2017-08-30 + environment: + - RELEASEBUILD=yes commands: - - RELEASEBUILD="yes" ./project/scripts/sbtPublish ${CI_PUBLISH} $SONATYPE_USER $SONATYPE_PW $PGP_PW ";sbt-dotty/publishSigned ;sonatypeRelease" + - ./project/scripts/sbtPublish "${CI_PUBLISH}" "$SONATYPE_USER" "$SONATYPE_PW" "$PGP_PW" ";sbt-dotty/publishSigned ;sonatypeRelease" volumes: - /home/drone/keys:/keys + secrets: [ sonatype_user, sonatype_pw, pgp_pw ] when: event: deployment environment: sbt_release @@ -52,16 +50,20 @@ pipeline: documentation: image: lampepfl/dotty:2017-08-30 commands: - - ./project/scripts/genDocs "${CI_PUBLISH}" $BOT_PASS + - ./project/scripts/genDocs "${CI_PUBLISH}" "$BOT_PASS" + secrets: [ bot_pass ] when: - branch: master + event: push slack: image: plugins/slack channel: dotty + secrets: [ slack_webhook ] when: - branch: master - status: changed + status: [ success, failure ] + event: [ push, deployment ] + +branches: master matrix: include: diff --git a/.drone.yml.sig b/.drone.yml.sig deleted file mode 100644 index 31bbee0fd421..000000000000 --- a/.drone.yml.sig +++ /dev/null @@ -1 +0,0 @@ -eyJhbGciOiJIUzI1NiJ9.IyBBZnRlciB1cGRhdGluZyB0aGlzIGZpbGUsIHlvdSBuZWVkIHRvIHJlLXNpZ24gaXQ6CiMKIyAtIEluc3RhbGwgW2Ryb25lLWNsaV0oaHR0cDovL3JlYWRtZS5kcm9uZS5pby91c2FnZS9nZXR0aW5nLXN0YXJ0ZWQtY2xpLykKIyAtIENvcHkgeW91ciB0b2tlbiBmcm9tIGh0dHA6Ly9kb3R0eS1jaS5lcGZsLmNoL2FjY291bnQgKENsaWNrIFNIT1cgVE9LRU4pCiMgLSBEUk9ORV9UT0tFTj15b3VyLXRva2VuIERST05FX1NFUlZFUj1odHRwOi8vZG90dHktY2kuZXBmbC5jaCBkcm9uZSBzaWduIGxhbXBlcGZsL2RvdHR5CiMKIyBQbGVhc2Ugbm90ZSB0aGF0IHRoZSBzaWduaW5nIGNhbiBvbmx5IGJlIGRvbmUgYnkgY29sbGFib3JhdG9ycy4KCnBpcGVsaW5lOgogIHRlc3Q6CiAgICBpbWFnZTogbGFtcGVwZmwvZG90dHk6MjAxNy0wOC0zMAogICAgY29tbWFuZHM6CiAgICAgIC0gLi9wcm9qZWN0L3NjcmlwdHMvc2J0ICIke0NJX1RFU1R9IgogICAgd2hlbjoKICAgICAgYnJhbmNoOgogICAgICAgIGV4Y2x1ZGU6IGdoLXBhZ2VzCgogIHB1Ymxpc2hfbmlnaHRseToKICAgIGltYWdlOiBsYW1wZXBmbC9kb3R0eToyMDE3LTA4LTMwCiAgICBjb21tYW5kczoKICAgICAgLSAuL3Byb2plY3Qvc2NyaXB0cy9zYnQgIjtjbGVhbiA7cHVibGlzaExvY2FsIiAiJHtDSV9QVUJMSVNIfSIKICAgICAgLSAuL3Byb2plY3Qvc2NyaXB0cy9zYnQgInNidC1kb3R0eS9zY3JpcHRlZCBzb3VyY2UtZGVwZW5kZW5jaWVzLyoiICIke0NJX1BVQkxJU0h9IgogICAgICAtIE5JR0hUTFlCVUlMRD0ieWVzIiAuL3Byb2plY3Qvc2NyaXB0cy9zYnRQdWJsaXNoICR7Q0lfUFVCTElTSH0gJFNPTkFUWVBFX1VTRVIgJFNPTkFUWVBFX1BXICRQR1BfUFcgIjtkb3R0eS1ib290c3RyYXBwZWQvcHVibGlzaFNpZ25lZCA7c29uYXR5cGVSZWxlYXNlIgogICAgdm9sdW1lczoKICAgICAgLSAvaG9tZS9kcm9uZS9rZXlzOi9rZXlzCiAgICB3aGVuOgogICAgICBldmVudDogZGVwbG95bWVudAogICAgICBlbnZpcm9ubWVudDogbmlnaHRseQoKICBwdWJsaXNoX3JlbGVhc2U6CiAgICBpbWFnZTogbGFtcGVwZmwvZG90dHk6MjAxNy0wOC0zMAogICAgY29tbWFuZHM6CiAgICAgIC0gLi9wcm9qZWN0L3NjcmlwdHMvc2J0ICI7Y2xlYW4gO3B1Ymxpc2hMb2NhbCIgIiR7Q0lfUFVCTElTSH0iCiAgICAgIC0gLi9wcm9qZWN0L3NjcmlwdHMvc2J0ICJzYnQtZG90dHkvc2NyaXB0ZWQgc291cmNlLWRlcGVuZGVuY2llcy8qIiAiJHtDSV9QVUJMSVNIfSIKICAgICAgLSBSRUxFQVNFQlVJTEQ9InllcyIgLi9wcm9qZWN0L3NjcmlwdHMvc2J0UHVibGlzaCAke0NJX1BVQkxJU0h9ICRTT05BVFlQRV9VU0VSICRTT05BVFlQRV9QVyAkUEdQX1BXICI7ZG90dHktYm9vdHN0cmFwcGVkL3B1Ymxpc2hTaWduZWQgO3NvbmF0eXBlUmVsZWFzZSIKICAgIHZvbHVtZXM6CiAgICAgIC0gL2hvbWUvZHJvbmUva2V5czova2V5cwogICAgd2hlbjoKICAgICAgZXZlbnQ6IGRlcGxveW1lbnQKICAgICAgZW52aXJvbm1lbnQ6IHJlbGVhc2UKCiAgcHVibGlzaF9zYnRfcmVsZWFzZToKICAgIGltYWdlOiBsYW1wZXBmbC9kb3R0eToyMDE3LTA4LTMwCiAgICBjb21tYW5kczoKICAgICAgLSBSRUxFQVNFQlVJTEQ9InllcyIgLi9wcm9qZWN0L3NjcmlwdHMvc2J0UHVibGlzaCAke0NJX1BVQkxJU0h9ICRTT05BVFlQRV9VU0VSICRTT05BVFlQRV9QVyAkUEdQX1BXICI7c2J0LWRvdHR5L3B1Ymxpc2hTaWduZWQgO3NvbmF0eXBlUmVsZWFzZSIKICAgIHZvbHVtZXM6CiAgICAgIC0gL2hvbWUvZHJvbmUva2V5czova2V5cwogICAgd2hlbjoKICAgICAgZXZlbnQ6IGRlcGxveW1lbnQKICAgICAgZW52aXJvbm1lbnQ6IHNidF9yZWxlYXNlCgogIGRvY3VtZW50YXRpb246CiAgICBpbWFnZTogbGFtcGVwZmwvZG90dHk6MjAxNy0wOC0zMAogICAgY29tbWFuZHM6CiAgICAgIC0gLi9wcm9qZWN0L3NjcmlwdHMvZ2VuRG9jcyAiJHtDSV9QVUJMSVNIfSIgJEJPVF9QQVNTCiAgICB3aGVuOgogICAgICBicmFuY2g6IG1hc3RlcgoKICBzbGFjazoKICAgIGltYWdlOiBwbHVnaW5zL3NsYWNrCiAgICBjaGFubmVsOiBkb3R0eQogICAgd2hlbjoKICAgICAgYnJhbmNoOiBtYXN0ZXIKICAgICAgc3RhdHVzOiBjaGFuZ2VkCgptYXRyaXg6CiAgaW5jbHVkZToKICAgIC0gQ0lfVEVTVDogbGVnYWN5VGVzdHMKICAgICAgQ0lfUFVCTElTSDogdHJ1ZQogICAgLSBDSV9URVNUOiA7dGVzdDtzYnQtZG90dHkvc2NyaXB0ZWQgY29tcGlsZXJSZXBvcnRlci8qO3NidC1kb3R0eS9zY3JpcHRlZCBkaXNjb3ZlcnkvKjtzYnQtZG90dHkvc2NyaXB0ZWQgc2J0LWRvdHR5LyoKICAgICAgQ0lfUFVCTElTSDogZmFsc2UKICAgIC0gQ0lfVEVTVDogZG90dHktYm9vdHN0cmFwcGVkL3Rlc3QKICAgICAgQ0lfUFVCTElTSDogZmFsc2UKICAgIC0gQ0lfVEVTVDogO3NldCBib290c3RyYXBPcHRpbWlzZWQgaW4gVGhpc0J1aWxkIDo9IHRydWUgO2RvdHR5LWJvb3RzdHJhcHBlZC90ZXN0CiAgICAgIENJX1BVQkxJU0g6IGZhbHNlCg.ZcgLhxT5IhcxKM--uKEpNgQEsCoMG7aNMZq5APv8ypI \ No newline at end of file From b06b27b0edca69133307f31545a847c846c25b8e Mon Sep 17 00:00:00 2001 From: Raymond Tay Date: Sun, 3 Sep 2017 10:43:11 +0800 Subject: [PATCH 05/24] corrected a small typo --- docs/docs/reference/changed/structural-types.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/reference/changed/structural-types.md b/docs/docs/reference/changed/structural-types.md index ea7311258896..022cf61016e9 100644 --- a/docs/docs/reference/changed/structural-types.md +++ b/docs/docs/reference/changed/structural-types.md @@ -66,7 +66,7 @@ current implementation of structural types. The main difference is that to get reflection-based structural access one now has to add an import: - import scala.relect.Selectable.reflectiveSelectable + import scala.reflect.Selectable.reflectiveSelectable On the other hand, the previously required language feature import of `reflectiveCalls` is now redundant and is therefore dropped. @@ -130,4 +130,4 @@ differences. ### Reference -For more info, see [Issue #1886](https://github.com/lampepfl/dotty/issues/1886). \ No newline at end of file +For more info, see [Issue #1886](https://github.com/lampepfl/dotty/issues/1886). From 91dcd184238c421f28da34d434b763631bba271e Mon Sep 17 00:00:00 2001 From: Raymond Tay Date: Sun, 3 Sep 2017 10:58:54 +0800 Subject: [PATCH 06/24] Removed extra pair of parens --- docs/docs/reference/changed/structural-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/reference/changed/structural-types.md b/docs/docs/reference/changed/structural-types.md index 022cf61016e9..d51f73c20ed0 100644 --- a/docs/docs/reference/changed/structural-types.md +++ b/docs/docs/reference/changed/structural-types.md @@ -92,7 +92,7 @@ For illustration, let's define a record value and cast it to a structural type `Person`: type Person = Record { val name: String; val age: Int } - val person = Record(("name" -> "Emma", "age" -> 42)).asInstanceOf[Person] + val person = Record("name" -> "Emma", "age" -> 42).asInstanceOf[Person] Then `person.name` will have static type `String`, and will produce `"Emma"` as result. From 9bf9998fee392c9930211cb20e68281a4c2a1c2b Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 21 Aug 2017 13:50:40 +0200 Subject: [PATCH 07/24] Fix #2964: Refresh names for anonymous classes --- compiler/src/dotty/tools/dotc/Compiler.scala | 3 +- .../tools/dotc/transform/LiftedClasses.scala | 47 +++++++++++++++++++ .../dotc/transform/TransformWildcards.scala | 3 ++ tests/run/i2738.check | 4 +- tests/run/i2964.check | 4 ++ tests/run/i2964.scala | 27 +++++++++++ tests/run/i2964b.check | 4 ++ tests/run/i2964b.scala | 27 +++++++++++ tests/run/i2964c.check | 4 ++ tests/run/i2964c.scala | 41 ++++++++++++++++ tests/run/i2964d.check | 4 ++ tests/run/i2964d.scala | 41 ++++++++++++++++ 12 files changed, 206 insertions(+), 3 deletions(-) create mode 100644 compiler/src/dotty/tools/dotc/transform/LiftedClasses.scala create mode 100644 tests/run/i2964.check create mode 100644 tests/run/i2964.scala create mode 100644 tests/run/i2964b.check create mode 100644 tests/run/i2964b.scala create mode 100644 tests/run/i2964c.check create mode 100644 tests/run/i2964c.scala create mode 100644 tests/run/i2964d.check create mode 100644 tests/run/i2964d.scala diff --git a/compiler/src/dotty/tools/dotc/Compiler.scala b/compiler/src/dotty/tools/dotc/Compiler.scala index a6555cdcd50e..b0f588874bb3 100644 --- a/compiler/src/dotty/tools/dotc/Compiler.scala +++ b/compiler/src/dotty/tools/dotc/Compiler.scala @@ -100,7 +100,8 @@ class Compiler { new ElimStaticThis, // Replace `this` references to static objects by global identifiers new Flatten, // Lift all inner classes to package scope new RestoreScopes), // Repair scopes rendered invalid by moving definitions in prior phases of the group - List(new TransformWildcards, // Replace wildcards with default values + List(new LiftedClasses, // Renames lifted classes to local numbering scheme + new TransformWildcards, // Replace wildcards with default values new MoveStatics, // Move static methods to companion classes new ExpandPrivate, // Widen private definitions accessed from nested classes new SelectStatic, // get rid of selects that would be compiled into GetStatic diff --git a/compiler/src/dotty/tools/dotc/transform/LiftedClasses.scala b/compiler/src/dotty/tools/dotc/transform/LiftedClasses.scala new file mode 100644 index 000000000000..4ac899f2902b --- /dev/null +++ b/compiler/src/dotty/tools/dotc/transform/LiftedClasses.scala @@ -0,0 +1,47 @@ +package dotty.tools.dotc.transform + +import dotty.tools.dotc.ast.tpd +import dotty.tools.dotc.core.Contexts.Context +import dotty.tools.dotc.core.Decorators._ +import dotty.tools.dotc.core.DenotTransformers.SymTransformer +import dotty.tools.dotc.core.Flags._ +import dotty.tools.dotc.core.NameKinds._ +import dotty.tools.dotc.core.Names._ +import dotty.tools.dotc.core.Phases +import dotty.tools.dotc.core.StdNames._ +import dotty.tools.dotc.core.SymDenotations.SymDenotation +import dotty.tools.dotc.core.Symbols._ +import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo} + +/** Renames lifted classes to local numbering scheme */ +class LiftedClasses extends MiniPhaseTransform with SymTransformer { thisTransformer => + + override def phaseName = "liftedClasses" + + override def runsAfterGroupsOf: Set[Class[_ <: Phases.Phase]] = Set(classOf[Flatten]) + + def transformSym(ref: SymDenotation)(implicit ctx: Context): SymDenotation = + if (needsRefresh(ref.symbol)) ref.copySymDenotation(name = refreshedName(ref.symbol)) + else ref + + override def transformTypeDef(tree: tpd.TypeDef)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = + if (needsRefresh(tree.symbol)) cpy.TypeDef(tree)(name = tree.symbol.name.asTypeName) + else tree + + private def needsRefresh(sym: Symbol)(implicit ctx: Context): Boolean = + sym.isClass && !sym.is(Package) && sym.name.is(UniqueName) + + /* Makes a new unique name based on a unique name that was flatten */ + private def refreshedName(sym: Symbol)(implicit ctx: Context): TypeName = { + // TODO: Refresh names not only based on their full name? + // Include package to distinguish $anon from .$anon + val name = sym.name + val newName = (name.firstPart.toString + str.NAME_JOIN + name.lastPart).toTermName + + var freshName = UniqueName.fresh(newName).toTypeName + if (name.toSimpleName.endsWith(str.MODULE_SUFFIX)) + freshName = (freshName + str.MODULE_SUFFIX).toTypeName + + freshName + } +} diff --git a/compiler/src/dotty/tools/dotc/transform/TransformWildcards.scala b/compiler/src/dotty/tools/dotc/transform/TransformWildcards.scala index 946722227af9..a2bcede2a38d 100644 --- a/compiler/src/dotty/tools/dotc/transform/TransformWildcards.scala +++ b/compiler/src/dotty/tools/dotc/transform/TransformWildcards.scala @@ -5,6 +5,7 @@ import TreeTransforms._ import core.DenotTransformers._ import core.Contexts._ import ast.tpd +import dotty.tools.dotc.core.Phases /** This phase transforms wildcards in valdefs with their default value. * In particular for every valdef that is declared: @@ -16,6 +17,8 @@ class TransformWildcards extends MiniPhaseTransform with IdentityDenotTransforme override def phaseName = "transformWildcards" + override def runsAfter: Set[Class[_ <: Phases.Phase]] = Set(classOf[LiftedClasses]) + override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = { tree match { case vDef: ValDef => assert(!tpd.isWildcardArg(vDef.rhs)) diff --git a/tests/run/i2738.check b/tests/run/i2738.check index 1261ac914586..0521c21711ed 100644 --- a/tests/run/i2738.check +++ b/tests/run/i2738.check @@ -3,6 +3,6 @@ bar$1 foo bar$2 baz -Test$qux$2$ +Test$qux$1$ baz -Test$qux$4$ +Test$qux$2$ diff --git a/tests/run/i2964.check b/tests/run/i2964.check new file mode 100644 index 000000000000..748b2a47faf1 --- /dev/null +++ b/tests/run/i2964.check @@ -0,0 +1,4 @@ +class Foo$$anon$1 +class Bar$$anon$1 +class Bar$$anon$2 +class Baz$$anon$1 diff --git a/tests/run/i2964.scala b/tests/run/i2964.scala new file mode 100644 index 000000000000..8b76c5e05da2 --- /dev/null +++ b/tests/run/i2964.scala @@ -0,0 +1,27 @@ + +object Test { + def main(args: Array[String]): Unit = { + new Foo + new Bar + new Baz + } +} + +class Foo { + new Object { + println(this.getClass) // Foo$$anon$1 + } +} +class Bar { + new Object { + println(this.getClass) // Bar$$anon$1 + } + new Object { + println(this.getClass) // Bar$$anon$2 + } +} +class Baz { + new Object { + println(this.getClass) // Baz$$anon$1 + } +} diff --git a/tests/run/i2964b.check b/tests/run/i2964b.check new file mode 100644 index 000000000000..748b2a47faf1 --- /dev/null +++ b/tests/run/i2964b.check @@ -0,0 +1,4 @@ +class Foo$$anon$1 +class Bar$$anon$1 +class Bar$$anon$2 +class Baz$$anon$1 diff --git a/tests/run/i2964b.scala b/tests/run/i2964b.scala new file mode 100644 index 000000000000..26177b85d993 --- /dev/null +++ b/tests/run/i2964b.scala @@ -0,0 +1,27 @@ + +object Test { + def main(args: Array[String]): Unit = { + Foo + Bar + Baz + } +} + +object Foo { + new Object { + println(this.getClass) // Foo$$anon$1 + } +} +object Bar { + new Object { + println(this.getClass) // Bar$$anon$1 + } + new Object { + println(this.getClass) // Bar$$anon$2 + } +} +object Baz { + new Object { + println(this.getClass) // Baz$$anon$1 + } +} diff --git a/tests/run/i2964c.check b/tests/run/i2964c.check new file mode 100644 index 000000000000..f7cc0f12df69 --- /dev/null +++ b/tests/run/i2964c.check @@ -0,0 +1,4 @@ +class Foo$Inner$1 +class Bar$Inner$1 +class Bar$Inner$2 +class Baz$Inner$1 diff --git a/tests/run/i2964c.scala b/tests/run/i2964c.scala new file mode 100644 index 000000000000..3683823764c6 --- /dev/null +++ b/tests/run/i2964c.scala @@ -0,0 +1,41 @@ + +object Test { + def main(args: Array[String]): Unit = { + new Foo().foo + new Bar().bar + new Bar().bar2 + new Baz().baz + } +} + +class Foo { + def foo: Unit = { + class Inner { + println(this.getClass) + } + new Inner + } +} +class Bar { + def bar: Unit = { + class Inner { + println(this.getClass) + } + new Inner + } + + def bar2: Unit = { + class Inner { + println(this.getClass) + } + new Inner + } +} +class Baz { + def baz: Unit = { + class Inner { + println(this.getClass) + } + new Inner + } +} diff --git a/tests/run/i2964d.check b/tests/run/i2964d.check new file mode 100644 index 000000000000..f1a0e8bb51c4 --- /dev/null +++ b/tests/run/i2964d.check @@ -0,0 +1,4 @@ +class Foo$Inner$1$ +class Bar$Inner$1$ +class Bar$Inner$2$ +class Baz$Inner$1$ diff --git a/tests/run/i2964d.scala b/tests/run/i2964d.scala new file mode 100644 index 000000000000..4090bfc084f7 --- /dev/null +++ b/tests/run/i2964d.scala @@ -0,0 +1,41 @@ + +object Test { + def main(args: Array[String]): Unit = { + new Foo().foo + new Bar().bar + new Bar().bar2 + new Baz().baz + } +} + +class Foo { + def foo: Unit = { + object Inner { + println(this.getClass) + } + Inner + } +} +class Bar { + def bar: Unit = { + object Inner { + println(this.getClass) + } + Inner + } + + def bar2: Unit = { + object Inner { + println(this.getClass) + } + Inner + } +} +class Baz { + def baz: Unit = { + object Inner { + println(this.getClass) + } + Inner + } +} From b1bcbde345459099206c30390017f751ce5df470 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 22 Aug 2017 08:06:32 +0200 Subject: [PATCH 08/24] Use local fresh indices for lifted classes in diferent packages --- .../tools/dotc/transform/LiftedClasses.scala | 7 ++-- tests/run/i2964e.check | 4 +++ tests/run/i2964e.scala | 32 +++++++++++++++++++ tests/run/i3000b.check | 2 +- 4 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 tests/run/i2964e.check create mode 100644 tests/run/i2964e.scala diff --git a/compiler/src/dotty/tools/dotc/transform/LiftedClasses.scala b/compiler/src/dotty/tools/dotc/transform/LiftedClasses.scala index 4ac899f2902b..fef9dce0ca2e 100644 --- a/compiler/src/dotty/tools/dotc/transform/LiftedClasses.scala +++ b/compiler/src/dotty/tools/dotc/transform/LiftedClasses.scala @@ -33,12 +33,13 @@ class LiftedClasses extends MiniPhaseTransform with SymTransformer { thisTransfo /* Makes a new unique name based on a unique name that was flatten */ private def refreshedName(sym: Symbol)(implicit ctx: Context): TypeName = { - // TODO: Refresh names not only based on their full name? - // Include package to distinguish $anon from .$anon + val packName = sym.owner.fullName.toString val name = sym.name - val newName = (name.firstPart.toString + str.NAME_JOIN + name.lastPart).toTermName + val newName = (packName + name.firstPart + str.NAME_JOIN + name.lastPart).toTermName var freshName = UniqueName.fresh(newName).toTypeName + val prefix = if (sym.owner.isEmptyPackage) "$empty$" else packName + freshName = freshName.toString.substring(prefix.length).toTypeName if (name.toSimpleName.endsWith(str.MODULE_SUFFIX)) freshName = (freshName + str.MODULE_SUFFIX).toTypeName diff --git a/tests/run/i2964e.check b/tests/run/i2964e.check new file mode 100644 index 000000000000..a42348b97b00 --- /dev/null +++ b/tests/run/i2964e.check @@ -0,0 +1,4 @@ +class foo.bar.Foo$$anon$1 +class foo.bar.Foo$$anon$2 +class foo.Foo$$anon$1 +class Foo$$anon$1 diff --git a/tests/run/i2964e.scala b/tests/run/i2964e.scala new file mode 100644 index 000000000000..2c6b0d1d4542 --- /dev/null +++ b/tests/run/i2964e.scala @@ -0,0 +1,32 @@ + +object Test { + def main(args: Array[String]): Unit = { + new foo.bar.Foo + new foo.Foo + new Foo + } +} + +package foo { + package bar { + class Foo { + new Object { + println(this.getClass) // Foo$$anon$1 + } + new Object { + println(this.getClass) // Foo$$anon$2 + } + } + } + class Foo { + new Object { + println(this.getClass) // Foo$$anon$1 + } + } +} + +class Foo { + new Object { + println(this.getClass) // Foo$$anon$1 + } +} diff --git a/tests/run/i3000b.check b/tests/run/i3000b.check index 605021c9b2c0..c5980c545f33 100644 --- a/tests/run/i3000b.check +++ b/tests/run/i3000b.check @@ -1,2 +1,2 @@ Foo$$anon$1 -bar.Bar$$anon$2 +bar.Bar$$anon$1 From 10672c04eebcc37858a9543c5e3255f6616e97ca Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 22 Aug 2017 10:03:50 +0200 Subject: [PATCH 09/24] Rename transform --- compiler/src/dotty/tools/dotc/Compiler.scala | 2 +- .../transform/{LiftedClasses.scala => RenameLifted.scala} | 4 ++-- .../src/dotty/tools/dotc/transform/TransformWildcards.scala | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) rename compiler/src/dotty/tools/dotc/transform/{LiftedClasses.scala => RenameLifted.scala} (93%) diff --git a/compiler/src/dotty/tools/dotc/Compiler.scala b/compiler/src/dotty/tools/dotc/Compiler.scala index b0f588874bb3..d31035f83a25 100644 --- a/compiler/src/dotty/tools/dotc/Compiler.scala +++ b/compiler/src/dotty/tools/dotc/Compiler.scala @@ -100,7 +100,7 @@ class Compiler { new ElimStaticThis, // Replace `this` references to static objects by global identifiers new Flatten, // Lift all inner classes to package scope new RestoreScopes), // Repair scopes rendered invalid by moving definitions in prior phases of the group - List(new LiftedClasses, // Renames lifted classes to local numbering scheme + List(new RenameLifted, // Renames lifted classes to local numbering scheme new TransformWildcards, // Replace wildcards with default values new MoveStatics, // Move static methods to companion classes new ExpandPrivate, // Widen private definitions accessed from nested classes diff --git a/compiler/src/dotty/tools/dotc/transform/LiftedClasses.scala b/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala similarity index 93% rename from compiler/src/dotty/tools/dotc/transform/LiftedClasses.scala rename to compiler/src/dotty/tools/dotc/transform/RenameLifted.scala index fef9dce0ca2e..2ca315c6c13e 100644 --- a/compiler/src/dotty/tools/dotc/transform/LiftedClasses.scala +++ b/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala @@ -14,9 +14,9 @@ import dotty.tools.dotc.core.Symbols._ import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo} /** Renames lifted classes to local numbering scheme */ -class LiftedClasses extends MiniPhaseTransform with SymTransformer { thisTransformer => +class RenameLifted extends MiniPhaseTransform with SymTransformer { thisTransformer => - override def phaseName = "liftedClasses" + override def phaseName = "renameLifted" override def runsAfterGroupsOf: Set[Class[_ <: Phases.Phase]] = Set(classOf[Flatten]) diff --git a/compiler/src/dotty/tools/dotc/transform/TransformWildcards.scala b/compiler/src/dotty/tools/dotc/transform/TransformWildcards.scala index a2bcede2a38d..b273e440d045 100644 --- a/compiler/src/dotty/tools/dotc/transform/TransformWildcards.scala +++ b/compiler/src/dotty/tools/dotc/transform/TransformWildcards.scala @@ -17,7 +17,7 @@ class TransformWildcards extends MiniPhaseTransform with IdentityDenotTransforme override def phaseName = "transformWildcards" - override def runsAfter: Set[Class[_ <: Phases.Phase]] = Set(classOf[LiftedClasses]) + override def runsAfter: Set[Class[_ <: Phases.Phase]] = Set(classOf[RenameLifted]) override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = { tree match { From 2dd41c34e24425ff3db1f2b711e37011e00a6a8a Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 22 Aug 2017 10:07:53 +0200 Subject: [PATCH 10/24] Remove uneccesary condition --- compiler/src/dotty/tools/dotc/transform/RenameLifted.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala b/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala index 2ca315c6c13e..ae6c44f9ec17 100644 --- a/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala +++ b/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala @@ -18,7 +18,7 @@ class RenameLifted extends MiniPhaseTransform with SymTransformer { thisTransfor override def phaseName = "renameLifted" - override def runsAfterGroupsOf: Set[Class[_ <: Phases.Phase]] = Set(classOf[Flatten]) + override def runsAfterGroupsOf: Set[Class[_ <: Phases.Phase]] = Set(classOf[RestoreScopes]) def transformSym(ref: SymDenotation)(implicit ctx: Context): SymDenotation = if (needsRefresh(ref.symbol)) ref.copySymDenotation(name = refreshedName(ref.symbol)) @@ -29,7 +29,7 @@ class RenameLifted extends MiniPhaseTransform with SymTransformer { thisTransfor else tree private def needsRefresh(sym: Symbol)(implicit ctx: Context): Boolean = - sym.isClass && !sym.is(Package) && sym.name.is(UniqueName) + sym.isClass && sym.name.is(UniqueName) /* Makes a new unique name based on a unique name that was flatten */ private def refreshedName(sym: Symbol)(implicit ctx: Context): TypeName = { From 54d610a97e474fb46da6446bbfdc4d00e4c57c21 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 29 Aug 2017 14:22:29 +0200 Subject: [PATCH 11/24] Fix #3006: Refresh names for lifted methods --- .../tools/dotc/transform/RenameLifted.scala | 38 ++++++++----------- .../dotc/transform/TransformWildcards.scala | 3 -- tests/run/i2738.check | 4 +- tests/run/i3006.check | 5 +++ tests/run/i3006.scala | 35 +++++++++++++++++ tests/run/i3006b.check | 3 ++ tests/run/i3006b.scala | 35 +++++++++++++++++ 7 files changed, 96 insertions(+), 27 deletions(-) create mode 100644 tests/run/i3006.check create mode 100644 tests/run/i3006.scala create mode 100644 tests/run/i3006b.check create mode 100644 tests/run/i3006b.scala diff --git a/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala b/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala index ae6c44f9ec17..ae5654ca735c 100644 --- a/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala +++ b/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala @@ -1,6 +1,5 @@ package dotty.tools.dotc.transform -import dotty.tools.dotc.ast.tpd import dotty.tools.dotc.core.Contexts.Context import dotty.tools.dotc.core.Decorators._ import dotty.tools.dotc.core.DenotTransformers.SymTransformer @@ -8,10 +7,9 @@ import dotty.tools.dotc.core.Flags._ import dotty.tools.dotc.core.NameKinds._ import dotty.tools.dotc.core.Names._ import dotty.tools.dotc.core.Phases -import dotty.tools.dotc.core.StdNames._ import dotty.tools.dotc.core.SymDenotations.SymDenotation import dotty.tools.dotc.core.Symbols._ -import dotty.tools.dotc.transform.TreeTransforms.{MiniPhaseTransform, TransformerInfo} +import dotty.tools.dotc.transform.TreeTransforms.MiniPhaseTransform /** Renames lifted classes to local numbering scheme */ class RenameLifted extends MiniPhaseTransform with SymTransformer { thisTransformer => @@ -24,25 +22,21 @@ class RenameLifted extends MiniPhaseTransform with SymTransformer { thisTransfor if (needsRefresh(ref.symbol)) ref.copySymDenotation(name = refreshedName(ref.symbol)) else ref - override def transformTypeDef(tree: tpd.TypeDef)(implicit ctx: Context, info: TransformerInfo): tpd.Tree = - if (needsRefresh(tree.symbol)) cpy.TypeDef(tree)(name = tree.symbol.name.asTypeName) - else tree - + /** If the name of the symbol with a unique name needs to be refreshed + * - if it is a lifted class + * - if it is a lifted method + */ private def needsRefresh(sym: Symbol)(implicit ctx: Context): Boolean = - sym.isClass && sym.name.is(UniqueName) - - /* Makes a new unique name based on a unique name that was flatten */ - private def refreshedName(sym: Symbol)(implicit ctx: Context): TypeName = { - val packName = sym.owner.fullName.toString - val name = sym.name - val newName = (packName + name.firstPart + str.NAME_JOIN + name.lastPart).toTermName - - var freshName = UniqueName.fresh(newName).toTypeName - val prefix = if (sym.owner.isEmptyPackage) "$empty$" else packName - freshName = freshName.toString.substring(prefix.length).toTypeName - if (name.toSimpleName.endsWith(str.MODULE_SUFFIX)) - freshName = (freshName + str.MODULE_SUFFIX).toTypeName - - freshName + (sym.isClass || sym.is(Private | Method | JavaStatic)) && sym.name.is(UniqueName) + + /** Refreshes the number of the name based on the full name of the symbol */ + private def refreshedName(sym: Symbol)(implicit ctx: Context): Name = { + sym.name.rewrite { + case name: DerivedName if name.info.kind == UniqueName => + val fullName = (sym.owner.fullName.toString + name.underlying).toTermName + val freshName = UniqueName.fresh(fullName) + val info = freshName.asInstanceOf[DerivedName].info + DerivedName(name.underlying, info) + } } } diff --git a/compiler/src/dotty/tools/dotc/transform/TransformWildcards.scala b/compiler/src/dotty/tools/dotc/transform/TransformWildcards.scala index b273e440d045..946722227af9 100644 --- a/compiler/src/dotty/tools/dotc/transform/TransformWildcards.scala +++ b/compiler/src/dotty/tools/dotc/transform/TransformWildcards.scala @@ -5,7 +5,6 @@ import TreeTransforms._ import core.DenotTransformers._ import core.Contexts._ import ast.tpd -import dotty.tools.dotc.core.Phases /** This phase transforms wildcards in valdefs with their default value. * In particular for every valdef that is declared: @@ -17,8 +16,6 @@ class TransformWildcards extends MiniPhaseTransform with IdentityDenotTransforme override def phaseName = "transformWildcards" - override def runsAfter: Set[Class[_ <: Phases.Phase]] = Set(classOf[RenameLifted]) - override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = { tree match { case vDef: ValDef => assert(!tpd.isWildcardArg(vDef.rhs)) diff --git a/tests/run/i2738.check b/tests/run/i2738.check index 0521c21711ed..e4d27e3fc332 100644 --- a/tests/run/i2738.check +++ b/tests/run/i2738.check @@ -1,7 +1,7 @@ foo -bar$1 -foo bar$2 +foo +bar$1 baz Test$qux$1$ baz diff --git a/tests/run/i3006.check b/tests/run/i3006.check new file mode 100644 index 000000000000..4fc525c0d632 --- /dev/null +++ b/tests/run/i3006.check @@ -0,0 +1,5 @@ +f$3 +f$2 +f$1 +f$2 +f$1 diff --git a/tests/run/i3006.scala b/tests/run/i3006.scala new file mode 100644 index 000000000000..199fd29194d8 --- /dev/null +++ b/tests/run/i3006.scala @@ -0,0 +1,35 @@ +class Foo { + def foo() = { + def f() = println(Thread.currentThread.getStackTrace.apply(1).getMethodName) + f() + } + def bar() = { + def f() = println(Thread.currentThread.getStackTrace.apply(1).getMethodName) + f() + } + def baz() = { + def f() = println(Thread.currentThread.getStackTrace.apply(1).getMethodName) + f() + } +} + +class Bar { + def foo() = { + def f() = println(Thread.currentThread.getStackTrace.apply(1).getMethodName) + f() + } + def bar() = { + def f() = println(Thread.currentThread.getStackTrace.apply(1).getMethodName) + f() + } +} + +object Test { + def main(args: Array[String]): Unit = { + new Foo().foo() + new Foo().bar() + new Foo().baz() + new Bar().foo() + new Bar().bar() + } +} diff --git a/tests/run/i3006b.check b/tests/run/i3006b.check new file mode 100644 index 000000000000..e0e763177e0c --- /dev/null +++ b/tests/run/i3006b.check @@ -0,0 +1,3 @@ +Foo$$init$$$bar$2 +Foo$$init$$$bar$1 +Bar$$init$$$bar$1 diff --git a/tests/run/i3006b.scala b/tests/run/i3006b.scala new file mode 100644 index 000000000000..051a06f266c8 --- /dev/null +++ b/tests/run/i3006b.scala @@ -0,0 +1,35 @@ +class Foo(i: Int) { + def this() = this({ + def bar() = { + println(Thread.currentThread.getStackTrace.apply(1).getMethodName) + 5 + } + bar() + }) + + def this(i: String) = this({ + def bar() = { + println(Thread.currentThread.getStackTrace.apply(1).getMethodName) + 5 + } + bar() + }) +} + +class Bar(i: Int) { + def this() = this({ + def bar() = { + println(Thread.currentThread.getStackTrace.apply(1).getMethodName) + 5 + } + bar() + }) +} + +object Test { + def main(args: Array[String]): Unit = { + new Foo() + new Foo("") + new Bar() + } +} From da14d0d4e0e76eb79d423f9dec4459714c8f433c Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 29 Aug 2017 15:58:39 +0200 Subject: [PATCH 12/24] Rewrite nested unique names --- .../src/dotty/tools/dotc/transform/RenameLifted.scala | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala b/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala index ae5654ca735c..97e05bd4ef09 100644 --- a/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala +++ b/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala @@ -31,12 +31,16 @@ class RenameLifted extends MiniPhaseTransform with SymTransformer { thisTransfor /** Refreshes the number of the name based on the full name of the symbol */ private def refreshedName(sym: Symbol)(implicit ctx: Context): Name = { - sym.name.rewrite { + lazy val rewriteUnique: PartialFunction[Name, Name] = { case name: DerivedName if name.info.kind == UniqueName => val fullName = (sym.owner.fullName.toString + name.underlying).toTermName val freshName = UniqueName.fresh(fullName) val info = freshName.asInstanceOf[DerivedName].info - DerivedName(name.underlying, info) + DerivedName(name.underlying.rewrite(rewriteUnique), info) + case DerivedName(underlying, info: QualifiedInfo) => + underlying.rewrite(rewriteUnique).derived(info) } + + sym.name.rewrite(rewriteUnique) } } From fe7ac0a5718fdbedf614b8269a65400b95f7e10e Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 4 Sep 2017 13:12:29 +0200 Subject: [PATCH 13/24] Use def for recursive partial function --- compiler/src/dotty/tools/dotc/transform/RenameLifted.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala b/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala index 97e05bd4ef09..fca24d71b8cf 100644 --- a/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala +++ b/compiler/src/dotty/tools/dotc/transform/RenameLifted.scala @@ -31,7 +31,7 @@ class RenameLifted extends MiniPhaseTransform with SymTransformer { thisTransfor /** Refreshes the number of the name based on the full name of the symbol */ private def refreshedName(sym: Symbol)(implicit ctx: Context): Name = { - lazy val rewriteUnique: PartialFunction[Name, Name] = { + def rewriteUnique: PartialFunction[Name, Name] = { case name: DerivedName if name.info.kind == UniqueName => val fullName = (sym.owner.fullName.toString + name.underlying).toTermName val freshName = UniqueName.fresh(fullName) From 1b06643a04b1de422fa95755e5136c2b3f8ef20a Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Mon, 4 Sep 2017 16:00:37 +0200 Subject: [PATCH 14/24] fix #2996: remove useless Makefile in distributed archive --- project/Build.scala | 6 ++++-- project/plugins.sbt | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/project/Build.scala b/project/Build.scala index 608546300c1a..648a1ee61263 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -8,7 +8,8 @@ import java.util.Calendar import scala.reflect.io.Path import sbtassembly.AssemblyKeys.assembly -import xerial.sbt.Pack._ +import xerial.sbt.pack.PackPlugin._ +import autoImport._ import sbt.Package.ManifestAttributes @@ -1142,6 +1143,7 @@ object Build { settings( publishArtifact := false, // packMain := Map("dummy" -> "dotty.tools.dotc.Main"), + packGenerateMakefile := false, packExpandedClasspath := true, packResourceDir += (baseDirectory.value / "bin" -> "bin"), packArchiveName := "dotty-" + dottyVersion @@ -1160,7 +1162,7 @@ object Build { publishArtifact := false, // packMain := Map("dummy" -> "dotty.tools.dotc.Main"), packExpandedClasspath := true, - // packExcludeJars := Seq("scala-library-.*\\.jar"), + packGenerateMakefile := false, packResourceDir += (baseDirectory.value / "bin" -> "bin"), packArchiveName := "dotty-" + dottyVersion ) diff --git a/project/plugins.sbt b/project/plugins.sbt index 6b24922932e3..0a7c99b64aea 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -13,7 +13,7 @@ addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "1.1") addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.0.0") -addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.8.2") +addSbtPlugin("org.xerial.sbt" % "sbt-pack" % "0.9.1") addSbtPlugin("pl.project13.scala" % "sbt-jmh" % "0.2.24") From c2572e0b3ea2fdb9a8c165c9ea9cba540f251236 Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Mon, 4 Sep 2017 18:12:04 +0200 Subject: [PATCH 15/24] Fix failing test case `InterfaceEntryPointTest.runCompilerFromInterface` used to fail when the output directory did not exist. --- .../test/dotty/tools/dotc/InterfaceEntryPointTest.scala | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/test/dotty/tools/dotc/InterfaceEntryPointTest.scala b/compiler/test/dotty/tools/dotc/InterfaceEntryPointTest.scala index e27b0f7b8ed9..907b733f5484 100644 --- a/compiler/test/dotty/tools/dotc/InterfaceEntryPointTest.scala +++ b/compiler/test/dotty/tools/dotc/InterfaceEntryPointTest.scala @@ -5,6 +5,7 @@ import org.junit.Test import org.junit.Assert._ import interfaces._ import scala.collection.mutable.ListBuffer +import java.nio.file._ /** Test that demonstrates how to use dotty-interfaces * @@ -20,8 +21,12 @@ import scala.collection.mutable.ListBuffer class InterfaceEntryPointTest { @Test def runCompilerFromInterface = { val sources = - List("../tests/pos/HelloWorld.scala").map(p => new java.io.File(p).getPath()) - val args = sources ++ List("-d", "../out/", "-usejavacp") + List("../tests/pos/HelloWorld.scala").map(p => Paths.get(p).toAbsolutePath().toString) + val out = Paths.get("../out/").toAbsolutePath() + if (Files.notExists(out)) + Files.createDirectory(out) + + val args = sources ++ List("-d", out.toString, "-usejavacp") val mainClass = Class.forName("dotty.tools.dotc.Main") val process = mainClass.getMethod("process", From 8fe0f04581be2c0d03dff0d8dabffdb00041f8c9 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 31 Aug 2017 17:39:59 +0200 Subject: [PATCH 16/24] Fix #2395: Check if the scala or dotty libraries are missing --- .../dotty/tools/dotc/MissingCoreLibraryException.scala | 9 +++++++++ compiler/src/dotty/tools/dotc/core/Definitions.scala | 2 +- compiler/src/dotty/tools/dotc/core/Denotations.scala | 5 ++++- compiler/src/dotty/tools/dotc/core/StdNames.scala | 1 + 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 compiler/src/dotty/tools/dotc/MissingCoreLibraryException.scala diff --git a/compiler/src/dotty/tools/dotc/MissingCoreLibraryException.scala b/compiler/src/dotty/tools/dotc/MissingCoreLibraryException.scala new file mode 100644 index 000000000000..ae20d81226c9 --- /dev/null +++ b/compiler/src/dotty/tools/dotc/MissingCoreLibraryException.scala @@ -0,0 +1,9 @@ +package dotty.tools.dotc + +import dotty.tools.FatalError + +class MissingCoreLibraryException(rootPackage: String) extends FatalError( + s"""Could not find package $rootPackage from compiler core libraries. + |Make sure the compiler core libraries are on the classpath. + """.stripMargin +) diff --git a/compiler/src/dotty/tools/dotc/core/Definitions.scala b/compiler/src/dotty/tools/dotc/core/Definitions.scala index 561ee6a00746..ce2ce247060c 100644 --- a/compiler/src/dotty/tools/dotc/core/Definitions.scala +++ b/compiler/src/dotty/tools/dotc/core/Definitions.scala @@ -212,7 +212,7 @@ class Definitions { * in `scalaShadowing` so they don't clash with the same-named `scala` * members at runtime. */ - lazy val ScalaShadowingPackageVal = ctx.requiredPackage("scalaShadowing") + lazy val ScalaShadowingPackageVal = ctx.requiredPackage(nme.scalaShadowing) lazy val ScalaShadowingPackageClass = ScalaShadowingPackageVal.moduleClass.asClass /** Note: We cannot have same named methods defined in Object and Any (and AnyVal, for that matter) diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 75d1261c3d44..85f64f144cdf 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -1199,7 +1199,10 @@ object Denotations { val alt = if (generateStubs) missingHook(owner.symbol.moduleClass, selector) else NoSymbol - if (alt.exists) alt.denot else MissingRef(owner, selector) + if (alt.exists) alt.denot + else if (owner.symbol == defn.RootClass && (selector == nme.scala_ || selector == nme.scalaShadowing)) + throw new MissingCoreLibraryException(selector.toString) + else MissingRef(owner, selector) } } else owner diff --git a/compiler/src/dotty/tools/dotc/core/StdNames.scala b/compiler/src/dotty/tools/dotc/core/StdNames.scala index 312ebcf1b5f7..b4fd1efa745a 100644 --- a/compiler/src/dotty/tools/dotc/core/StdNames.scala +++ b/compiler/src/dotty/tools/dotc/core/StdNames.scala @@ -491,6 +491,7 @@ object StdNames { val runtimeMirror: N = "runtimeMirror" val sameElements: N = "sameElements" val scala_ : N = "scala" + val scalaShadowing : N = "scalaShadowing" val selectDynamic: N = "selectDynamic" val selectDynamicMethod: N = "selectDynamicMethod" val selectOverloadedMethod: N = "selectOverloadedMethod" From 3e5009d95b89a20749f92fd9998466b06ded87db Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 31 Aug 2017 18:21:58 +0200 Subject: [PATCH 17/24] Add test for #2395 --- .../tools/dotc/MissingCoreLibTests.scala | 34 +++++++++++++++++++ .../tools/vulpix/TestConfiguration.scala | 8 +++-- tests/neg/nolib/Foo.scala | 2 ++ 3 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 compiler/test/dotty/tools/dotc/MissingCoreLibTests.scala create mode 100644 tests/neg/nolib/Foo.scala diff --git a/compiler/test/dotty/tools/dotc/MissingCoreLibTests.scala b/compiler/test/dotty/tools/dotc/MissingCoreLibTests.scala new file mode 100644 index 000000000000..593121c6b0d4 --- /dev/null +++ b/compiler/test/dotty/tools/dotc/MissingCoreLibTests.scala @@ -0,0 +1,34 @@ +package dotty +package tools +package dotc + +import org.junit.{ Test, AfterClass } + +import vulpix.{ ParallelTesting, SummaryReport, SummaryReporting, TestConfiguration } + +import scala.concurrent.duration._ + +class MissingCoreLibTests extends ParallelTesting { + import MissingCoreLibTests._ + import TestConfiguration._ + + // Test suite configuration -------------------------------------------------- + + def maxDuration = 30.seconds + def numberOfSlaves = 5 + def safeMode = Properties.testsSafeMode + def isInteractive = SummaryReport.isInteractive + def testFilter = Properties.testsFilter + + @Test def missingDottyLib: Unit = { + val classPath = mkClassPath(Jars.dottyCompiler :: Jars.dottyInterfaces :: Jars.dottyExtras) // missing Jars.dottyLib + val options = noCheckOptions ++ checkOptions ++ yCheckOptions ++ classPath + compileFile("../tests/neg/nolib/Foo.scala", options).checkExpectedErrors() + } + +} + +object MissingCoreLibTests { + implicit val summaryReport: SummaryReporting = new SummaryReport + @AfterClass def cleanup(): Unit = summaryReport.echoSummary() +} diff --git a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala index 44dabbabc93f..816221a0a13d 100644 --- a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala +++ b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala @@ -23,8 +23,10 @@ object TestConfiguration { "-Yforce-sbt-phases" ) - val classPath = { - val paths = Jars.dottyTestDeps map { p => + val classPath = mkClassPath(Jars.dottyTestDeps) + + def mkClassPath(deps: List[String]) = { + val paths = deps map { p => val file = new java.io.File(p) assert( file.exists, @@ -50,7 +52,7 @@ object TestConfiguration { Array("-classpath", paths) } - private val yCheckOptions = Array("-Ycheck:tailrec,resolveSuper,erasure,mixin,getClass,restoreScopes,labelDef") + val yCheckOptions = Array("-Ycheck:tailrec,resolveSuper,erasure,mixin,getClass,restoreScopes,labelDef") val defaultUnoptimised = noCheckOptions ++ checkOptions ++ yCheckOptions ++ classPath val defaultOptimised = defaultUnoptimised :+ "-optimise" diff --git a/tests/neg/nolib/Foo.scala b/tests/neg/nolib/Foo.scala new file mode 100644 index 000000000000..ef4e4e70d01d --- /dev/null +++ b/tests/neg/nolib/Foo.scala @@ -0,0 +1,2 @@ +// nopos-error +class Foo From 4d6c29fc89f5641acfd9aec7620e070ad5a10b58 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 4 Sep 2017 11:08:57 +0200 Subject: [PATCH 18/24] Add documentation --- compiler/src/dotty/tools/dotc/core/Denotations.scala | 10 ++++++++-- .../test/dotty/tools/vulpix/TestConfiguration.scala | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 85f64f144cdf..4724e68f2cb7 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -1192,6 +1192,13 @@ object Denotations { def staticRef(path: Name, generateStubs: Boolean = true, isPackage: Boolean = false)(implicit ctx: Context): Denotation = { def select(prefix: Denotation, selector: Name): Denotation = { val owner = prefix.disambiguate(_.info.isParameterless) + def isPackageFromCoreLibMissing: Boolean = { + owner.symbol == defn.RootClass && + { + selector == nme.scala_ || // if the scala package is missing, the stdlib must be missing + selector == nme.scalaShadowing // if the scalaShadowing package is missing, the dotty library must be missing + } + } if (owner.exists) { val result = if (isPackage) owner.info.decl(selector) else owner.info.member(selector) if (result.exists) result @@ -1200,8 +1207,7 @@ object Denotations { if (generateStubs) missingHook(owner.symbol.moduleClass, selector) else NoSymbol if (alt.exists) alt.denot - else if (owner.symbol == defn.RootClass && (selector == nme.scala_ || selector == nme.scalaShadowing)) - throw new MissingCoreLibraryException(selector.toString) + else if (isPackageFromCoreLibMissing) throw new MissingCoreLibraryException(selector.toString) else MissingRef(owner, selector) } } diff --git a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala index 816221a0a13d..06022833dbb8 100644 --- a/compiler/test/dotty/tools/vulpix/TestConfiguration.scala +++ b/compiler/test/dotty/tools/vulpix/TestConfiguration.scala @@ -25,7 +25,7 @@ object TestConfiguration { val classPath = mkClassPath(Jars.dottyTestDeps) - def mkClassPath(deps: List[String]) = { + def mkClassPath(deps: List[String]): Array[String] = { val paths = deps map { p => val file = new java.io.File(p) assert( From 025885905d178607f8629a2d0deedd0df8b5fcf9 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 4 Sep 2017 19:21:32 +0200 Subject: [PATCH 19/24] Small format fix --- compiler/src/dotty/tools/dotc/core/Denotations.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/Denotations.scala b/compiler/src/dotty/tools/dotc/core/Denotations.scala index 4724e68f2cb7..14a93191e4a6 100644 --- a/compiler/src/dotty/tools/dotc/core/Denotations.scala +++ b/compiler/src/dotty/tools/dotc/core/Denotations.scala @@ -1194,10 +1194,10 @@ object Denotations { val owner = prefix.disambiguate(_.info.isParameterless) def isPackageFromCoreLibMissing: Boolean = { owner.symbol == defn.RootClass && - { + ( selector == nme.scala_ || // if the scala package is missing, the stdlib must be missing selector == nme.scalaShadowing // if the scalaShadowing package is missing, the dotty library must be missing - } + ) } if (owner.exists) { val result = if (isPackage) owner.info.decl(selector) else owner.info.member(selector) From 9a6c7590cf37dc3da2401fb05261283a317fac6b Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Tue, 5 Sep 2017 18:38:05 +0200 Subject: [PATCH 20/24] Update Docker image following #3059 --- .drone.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.drone.yml b/.drone.yml index 39091f6009a6..519f56566323 100644 --- a/.drone.yml +++ b/.drone.yml @@ -1,11 +1,11 @@ pipeline: test: - image: lampepfl/dotty:2017-08-30 + image: lampepfl/dotty:2017-09-05 commands: - ./project/scripts/sbt "${CI_TEST}" publish_nightly: - image: lampepfl/dotty:2017-08-30 + image: lampepfl/dotty:2017-09-05 environment: - NIGHTLYBUILD=yes commands: @@ -20,7 +20,7 @@ pipeline: environment: nightly publish_release: - image: lampepfl/dotty:2017-08-30 + image: lampepfl/dotty:2017-09-05 environment: - RELEASEBUILD=yes commands: @@ -35,7 +35,7 @@ pipeline: environment: release publish_sbt_release: - image: lampepfl/dotty:2017-08-30 + image: lampepfl/dotty:2017-09-05 environment: - RELEASEBUILD=yes commands: @@ -48,7 +48,7 @@ pipeline: environment: sbt_release documentation: - image: lampepfl/dotty:2017-08-30 + image: lampepfl/dotty:2017-09-05 commands: - ./project/scripts/genDocs "${CI_PUBLISH}" "$BOT_PASS" secrets: [ bot_pass ] From 865e8f076a562919448d6651f29a4068363799ee Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Tue, 5 Sep 2017 18:37:30 +0200 Subject: [PATCH 21/24] Fix initialization vulnerability in Scanner When bootstrapping with -Yno-inline, Tokens failied to initialize because the length `maxToken` in `tokenString` was still 0. Changing a `val` to a `def` fixes that. This is a nice demonstration that the initialization rules are non-intuitive - we get bitten by them ourselves! --- compiler/src/dotty/tools/dotc/parsing/JavaTokens.scala | 2 +- compiler/src/dotty/tools/dotc/parsing/Tokens.scala | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/parsing/JavaTokens.scala b/compiler/src/dotty/tools/dotc/parsing/JavaTokens.scala index 9530e0516196..5412481f07bf 100644 --- a/compiler/src/dotty/tools/dotc/parsing/JavaTokens.scala +++ b/compiler/src/dotty/tools/dotc/parsing/JavaTokens.scala @@ -6,7 +6,7 @@ import collection.immutable.BitSet object JavaTokens extends TokensCommon { final val minToken = EMPTY - final val maxToken = DOUBLE + final def maxToken = DOUBLE final val javaOnlyKeywords = tokenRange(INSTANCEOF, ASSERT) final val sharedKeywords = BitSet( IF, FOR, ELSE, THIS, NULL, NEW, SUPER, ABSTRACT, FINAL, PRIVATE, PROTECTED, diff --git a/compiler/src/dotty/tools/dotc/parsing/Tokens.scala b/compiler/src/dotty/tools/dotc/parsing/Tokens.scala index 770b826fd9f2..ae447a22c7b1 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Tokens.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Tokens.scala @@ -6,7 +6,7 @@ import collection.immutable.BitSet import core.Decorators._ abstract class TokensCommon { - val maxToken: Int + def maxToken: Int type Token = Int type TokenSet = BitSet @@ -145,7 +145,7 @@ abstract class TokensCommon { object Tokens extends TokensCommon { final val minToken = EMPTY - final val maxToken = XMLSTART + final def maxToken = XMLSTART final val INTERPOLATIONID = 10; enter(INTERPOLATIONID, "string interpolator") final val SYMBOLLIT = 11; enter(SYMBOLLIT, "symbol literal") // TODO: deprecate From fe4ba25a9f65d4a075e7a78393c2f7b9ee55e504 Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Tue, 5 Sep 2017 19:38:37 +0200 Subject: [PATCH 22/24] Simplify dist project definitions --- project/Build.scala | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/project/Build.scala b/project/Build.scala index 648a1ee61263..71b60f334666 100644 --- a/project/Build.scala +++ b/project/Build.scala @@ -1133,21 +1133,21 @@ object Build { state } + lazy val commonDistSettings = packSettings ++ Seq( + publishArtifact := false, + packGenerateMakefile := false, + packExpandedClasspath := true, + packResourceDir += (baseDirectory.value / "bin" -> "bin"), + packArchiveName := "dotty-" + dottyVersion + ) + lazy val dist = project. dependsOn(`dotty-interfaces`). dependsOn(`dotty-compiler`). dependsOn(`dotty-library`). dependsOn(`dotty-doc`). settings(commonNonBootstrappedSettings). - settings(packSettings). - settings( - publishArtifact := false, - // packMain := Map("dummy" -> "dotty.tools.dotc.Main"), - packGenerateMakefile := false, - packExpandedClasspath := true, - packResourceDir += (baseDirectory.value / "bin" -> "bin"), - packArchiveName := "dotty-" + dottyVersion - ) + settings(commonDistSettings) // Same as `dist` but using bootstrapped projects. lazy val `dist-bootstrapped` = project. @@ -1156,14 +1156,8 @@ object Build { dependsOn(`dotty-compiler-bootstrapped`). dependsOn(`dotty-doc-bootstrapped`). settings(commonBootstrappedSettings). - settings(packSettings). + settings(commonDistSettings). settings( - target := baseDirectory.value / "target", // override setting in commonBootstrappedSettings - publishArtifact := false, - // packMain := Map("dummy" -> "dotty.tools.dotc.Main"), - packExpandedClasspath := true, - packGenerateMakefile := false, - packResourceDir += (baseDirectory.value / "bin" -> "bin"), - packArchiveName := "dotty-" + dottyVersion + target := baseDirectory.value / "target" // override setting in commonBootstrappedSettings ) } From 165a60ee69fb5187c6959d00a30c96475b484f8a Mon Sep 17 00:00:00 2001 From: Raymond Tay Date: Sun, 3 Sep 2017 10:43:11 +0800 Subject: [PATCH 23/24] corrected a small typo --- docs/docs/reference/changed/structural-types.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/docs/reference/changed/structural-types.md b/docs/docs/reference/changed/structural-types.md index ea7311258896..022cf61016e9 100644 --- a/docs/docs/reference/changed/structural-types.md +++ b/docs/docs/reference/changed/structural-types.md @@ -66,7 +66,7 @@ current implementation of structural types. The main difference is that to get reflection-based structural access one now has to add an import: - import scala.relect.Selectable.reflectiveSelectable + import scala.reflect.Selectable.reflectiveSelectable On the other hand, the previously required language feature import of `reflectiveCalls` is now redundant and is therefore dropped. @@ -130,4 +130,4 @@ differences. ### Reference -For more info, see [Issue #1886](https://github.com/lampepfl/dotty/issues/1886). \ No newline at end of file +For more info, see [Issue #1886](https://github.com/lampepfl/dotty/issues/1886). From e5c930b684e97ddb1d8df3e07ccbab1b26c631ea Mon Sep 17 00:00:00 2001 From: Raymond Tay Date: Sun, 3 Sep 2017 10:58:54 +0800 Subject: [PATCH 24/24] Removed extra pair of parens --- docs/docs/reference/changed/structural-types.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/docs/reference/changed/structural-types.md b/docs/docs/reference/changed/structural-types.md index 022cf61016e9..d51f73c20ed0 100644 --- a/docs/docs/reference/changed/structural-types.md +++ b/docs/docs/reference/changed/structural-types.md @@ -92,7 +92,7 @@ For illustration, let's define a record value and cast it to a structural type `Person`: type Person = Record { val name: String; val age: Int } - val person = Record(("name" -> "Emma", "age" -> 42)).asInstanceOf[Person] + val person = Record("name" -> "Emma", "age" -> 42).asInstanceOf[Person] Then `person.name` will have static type `String`, and will produce `"Emma"` as result.