Skip to content

Corrected a typo in the online documentation for Programmatic Structural Types #3053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 37 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
820c92d
Merge pull request #1 from raygit/documentation-changes
raymondtay Dec 22, 2016
b6142d2
Implement value classes with phantom parameters
nicolasstucki Jul 27, 2017
e2db292
Remove extra `.`
nicolasstucki Aug 24, 2017
9304f3b
Remove dead code
nicolasstucki Aug 31, 2017
796bcf8
Upgrade Drone to 0.8
allanrenucci Aug 30, 2017
b06b27b
corrected a small typo
raymondtay Sep 3, 2017
ffaf401
Merge branch 'master' of https://github.com/raymondtay/dotty
raymondtay Sep 3, 2017
91dcd18
Removed extra pair of parens
raymondtay Sep 3, 2017
9bf9998
Fix #2964: Refresh names for anonymous classes
nicolasstucki Aug 21, 2017
b1bcbde
Use local fresh indices for lifted classes in diferent packages
nicolasstucki Aug 22, 2017
10672c0
Rename transform
nicolasstucki Aug 22, 2017
2dd41c3
Remove uneccesary condition
nicolasstucki Aug 22, 2017
54d610a
Fix #3006: Refresh names for lifted methods
nicolasstucki Aug 29, 2017
da14d0d
Rewrite nested unique names
nicolasstucki Aug 29, 2017
fe7ac0a
Use def for recursive partial function
nicolasstucki Sep 4, 2017
1b06643
fix #2996: remove useless Makefile in distributed archive
liufengyun Sep 4, 2017
a84bcf5
Merge pull request #3049 from allanrenucci/drone0.8
allanrenucci Sep 4, 2017
c2572e0
Fix failing test case
allanrenucci Sep 4, 2017
8276064
Merge pull request #3060 from allanrenucci/fix-missing-out-dir
allanrenucci Sep 4, 2017
8fe0f04
Fix #2395: Check if the scala or dotty libraries are missing
nicolasstucki Aug 31, 2017
3e5009d
Add test for #2395
nicolasstucki Aug 31, 2017
4d6c29f
Add documentation
nicolasstucki Sep 4, 2017
0258859
Small format fix
nicolasstucki Sep 4, 2017
8f15b2a
Merge pull request #3043 from dotty-staging/remove-dead-code
nicolasstucki Sep 4, 2017
717904b
Merge pull request #3045 from dotty-staging/fix-#2395
allanrenucci Sep 5, 2017
a0d703b
Merge pull request #2999 from dotty-staging/fix-#2964
allanrenucci Sep 5, 2017
b36c9be
Merge pull request #2926 from dotty-staging/phantoms-in-value-classes
allanrenucci Sep 5, 2017
9b29059
Merge pull request #3059 from dotty-staging/fix-2996
allanrenucci Sep 5, 2017
9a6c759
Update Docker image following #3059
allanrenucci Sep 5, 2017
865e8f0
Fix initialization vulnerability in Scanner
odersky Sep 5, 2017
8249cab
Merge pull request #3068 from allanrenucci/docker-image
allanrenucci Sep 5, 2017
fe4ba25
Simplify dist project definitions
allanrenucci Sep 5, 2017
1af3894
Merge pull request #3069 from dotty-staging/fix-noinline-bootstrap
smarter Sep 5, 2017
52cd082
Merge pull request #3072 from allanrenucci/dist
allanrenucci Sep 5, 2017
165a60e
corrected a small typo
raymondtay Sep 3, 2017
e5c930b
Removed extra pair of parens
raymondtay Sep 3, 2017
4a764b7
Merge branch 'master' of https://github.com/raymondtay/dotty
raymondtay Sep 6, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 25 additions & 23 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -1,67 +1,69 @@
# 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
image: lampepfl/dotty:2017-09-05
commands:
- ./project/scripts/sbt "${CI_TEST}"
when:
branch:
exclude: gh-pages

publish_nightly:
image: lampepfl/dotty:2017-08-30
image: lampepfl/dotty:2017-09-05
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
image: lampepfl/dotty:2017-09-05
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
image: lampepfl/dotty:2017-09-05
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

documentation:
image: lampepfl/dotty:2017-08-30
image: lampepfl/dotty:2017-09-05
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:
Expand Down
1 change: 0 additions & 1 deletion .drone.yml.sig

This file was deleted.

3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
new SelectStatic, // get rid of selects that would be compiled into GetStatic
Expand Down
Original file line number Diff line number Diff line change
@@ -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
)
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
11 changes: 10 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1192,14 +1192,23 @@ 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
else {
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 (isPackageFromCoreLibMissing) throw new MissingCoreLibraryException(selector.toString)
else MissingRef(owner, selector)
}
}
else owner
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/core/StdNames.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/parsing/JavaTokens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/parsing/Tokens.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1636,9 +1636,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 = ""
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/Constructors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,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))
}

Expand Down
46 changes: 46 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/RenameLifted.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package dotty.tools.dotc.transform

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.SymDenotations.SymDenotation
import dotty.tools.dotc.core.Symbols._
import dotty.tools.dotc.transform.TreeTransforms.MiniPhaseTransform

/** Renames lifted classes to local numbering scheme */
class RenameLifted extends MiniPhaseTransform with SymTransformer { thisTransformer =>

override def phaseName = "renameLifted"

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))
else ref

/** 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.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 = {
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)
val info = freshName.asInstanceOf[DerivedName].info
DerivedName(name.underlying.rewrite(rewriteUnique), info)
case DerivedName(underlying, info: QualifiedInfo) =>
underlying.rewrite(rewriteUnique).derived(info)
}

sym.name.rewrite(rewriteUnique)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

Expand Down
12 changes: 8 additions & 4 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,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)
Expand Down
21 changes: 0 additions & 21 deletions compiler/test/dotty/tools/dotc/CompilationTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 7 additions & 2 deletions compiler/test/dotty/tools/dotc/InterfaceEntryPointTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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",
Expand Down
Loading