Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/2.13.x' into topic/unsafe-undead
Browse files Browse the repository at this point in the history
  • Loading branch information
retronym committed Aug 9, 2018
2 parents 1825b6b + 0fd1b66 commit c40c26b
Show file tree
Hide file tree
Showing 400 changed files with 5,690 additions and 2,156 deletions.
6 changes: 5 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ lazy val commonSettings = instanceSettings ++ clearSourceAndResourceDirectories
// END: Copy/pasted from SBT
},
fork in run := true,
//scalacOptions += "-Xlint:-nullary-override,-inaccessible,_",
scalacOptions in Compile += "-Xlint:-nullary-override,-inaccessible,-nonlocal-return,_",
//scalacOptions ++= Seq("-Xmaxerrs", "5", "-Xmaxwarns", "5"),
scalacOptions in Compile in doc ++= Seq(
"-doc-footer", "epfl",
Expand Down Expand Up @@ -606,6 +606,7 @@ lazy val junit = project.in(file("test") / "junit")
.dependsOn(library, reflect, compiler, partest, scaladoc)
.settings(clearSourceAndResourceDirectories)
.settings(commonSettings)
.settings(scalacOptions in Compile += "-Xlint:-nullary-unit,-adapted-args")
.settings(disableDocs)
.settings(disablePublishing)
.settings(
Expand Down Expand Up @@ -713,6 +714,7 @@ lazy val test = project
.disablePlugins(plugins.JUnitXmlReportPlugin)
.configs(IntegrationTest)
.settings(commonSettings)
.settings(scalacOptions in Compile -= "-Xlint:-nullary-override,-inaccessible,-nonlocal-return,_") // as in common settings
.settings(disableDocs)
.settings(disablePublishing)
.settings(Defaults.itSettings)
Expand All @@ -724,6 +726,8 @@ lazy val test = project
// test sources are compiled in partest run, not here
sources in IntegrationTest := Seq.empty,
fork in IntegrationTest := true,
// enable this in 2.13, when tests pass
//scalacOptions in Compile += "-Yvalidate-pos:parser,typer",
javaOptions in IntegrationTest ++= List("-Xmx2G", "-Dpartest.exec.in.process=true", "-Dfile.encoding=UTF-8", "-Duser.language=en", "-Duser.country=US"),
testOptions in IntegrationTest += Tests.Argument("-Dfile.encoding=UTF-8", "-Duser.language=en", "-Duser.country=US"),
testFrameworks += new TestFramework("scala.tools.partest.sbt.Framework"),
Expand Down
2 changes: 1 addition & 1 deletion project/ScalaOptionParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ object ScalaOptionParser {
"-Ypresentation-log", "-Ypresentation-replay", "-Yrepl-outdir", "-d", "-dependencyfile", "-encoding", "-Xscript")
private def pathSettingNames = List("-bootclasspath", "-classpath", "-extdirs", "-javabootclasspath", "-javaextdirs", "-sourcepath", "-toolcp")
private val phases = List("all", "parser", "namer", "packageobjects", "typer", "patmat", "superaccessors", "extmethods", "pickler", "refchecks", "uncurry", "tailcalls", "specialize", "explicitouter", "erasure", "posterasure", "fields", "lambdalift", "constructors", "flatten", "mixin", "cleanup", "delambdafy", "icode", "jvm", "terminal")
private val phaseSettings = List("-Xprint-icode", "-Ystop-after", "-Yskip", "-Yshow", "-Ystop-before", "-Ybrowse", "-Ylog", "-Ycheck", "-Xprint")
private val phaseSettings = List("-Xprint-icode", "-Ystop-after", "-Yskip", "-Yshow", "-Ystop-before", "-Ybrowse", "-Ylog", "-Ycheck", "-Xprint", "-Yvalidate-pos")
private def multiStringSettingNames = List("-Xmacro-settings", "-Xplugin", "-Xplugin-disable", "-Xplugin-require", "-Ywarn-unused")
private def intSettingNames = List("-Xmax-classfile-name", "-Xelide-below", "-Ypatmat-exhaust-depth", "-Ypresentation-delay", "-Yrecursion")
private def choiceSettingNames = Map[String, List[String]](
Expand Down
42 changes: 22 additions & 20 deletions spec/11-annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,26 +149,28 @@ Java platform, the following annotations have a standard meaning.
Whenever the static type of an expression matches a specialized variant of
a definition, the compiler will instead use the specialized version.
See the [specialization sid](http://docs.scala-lang.org/sips/completed/scala-specialization.html) for more details of the implementation.


## User-defined Annotations

Other annotations may be interpreted by platform- or
application-dependent tools. Class `scala.Annotation` has two
sub-traits which are used to indicate how these annotations are
retained. Instances of an annotation class inheriting from trait
`scala.ClassfileAnnotation` will be stored in the generated class
files. Instances of an annotation class inheriting from trait
`scala.StaticAnnotation` will be visible to the Scala type-checker
in every compilation unit where the annotated symbol is accessed. An
annotation class can inherit from both `scala.ClassfileAnnotation`
and `scala.StaticAnnotation`. If an annotation class inherits from
neither `scala.ClassfileAnnotation` nor
`scala.StaticAnnotation`, its instances are visible only locally
during the compilation run that analyzes them.

Classes inheriting from `scala.ClassfileAnnotation` may be
subject to further restrictions in order to assure that they can be
mapped to the host environment. In particular, on both the Java and
the .NET platforms, such classes must be toplevel; i.e. they may not
be contained in another class or object. Additionally, on both
Java and .NET, all constructor arguments must be constant expressions.
Other annotations may be interpreted by platform- or application-dependent
tools. The class `scala.annotation.Annotation` is the base class for
user-defined annotations. It has two sub-traits:
- `scala.annotation.StaticAnnotation`: Instances of a subclass of this trait
will be stored in the generated class files, and therefore accessible to
runtime reflection and later compilation runs.
- `scala.annotation.ConstantAnnotation`: Instances of a subclass of this trait
may only have arguments which are
[constant expressions](06-expressions.html#constant-expressions), and are
also stored in the generated class files.
- If an annotation class inherits from neither `scala.ConstantAnnotation` nor
`scala.StaticAnnotation`, its instances are visible only locally during the
compilation run that analyzes them.

## Host-platform Annotations

The host platform may define its own annotation format. These annotations do not
extend any of the classes in the `scala.annotation` package, but can generally
be used in the same way as Scala annotations. The host platform may impose
additional restrictions on the expressions which are valid as annotation
arguments.
1 change: 0 additions & 1 deletion src/compiler/scala/reflect/reify/phases/Reify.scala
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ trait Reify extends GenSymbols
case mods: global.Modifiers => reifyModifiers(mods)
case xs: List[_] => reifyList(xs)
case s: String => Literal(Constant(s))
case s: scala.Symbol => Literal(Constant(s))
case v if isAnyVal(v) => Literal(Constant(v))
case null => Literal(Constant(null))
case _ =>
Expand Down
6 changes: 3 additions & 3 deletions src/compiler/scala/tools/nsc/GenericRunnerSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class GenericRunnerSettings(error: String => Unit) extends Settings(error) {
"how",
"how to run the specified code",
List("object", "script", "jar", "repl", "guess"),
"guess")
"guess") withAbbreviation "--how-to-run"

val loadfiles =
MultiStringSetting(
Expand All @@ -41,11 +41,11 @@ class GenericRunnerSettings(error: String => Unit) extends Settings(error) {
val save =
BooleanSetting(
"-save",
"save the compiled script (assumes the code is a script)") withAbbreviation "-savecompiled"
"save the compiled script (assumes the code is a script)") withAbbreviation "-savecompiled" withAbbreviation "--save"

val nc = BooleanSetting(
"-nc",
"do not use the legacy fsc compilation daemon").withAbbreviation("-nocompdaemon")
"do not use the legacy fsc compilation daemon").withAbbreviation("-nocompdaemon").withAbbreviation("--no-compilation-daemon")
.withDeprecationMessage("scripts use cold compilation by default; use -Yscriptrunner for custom behavior")
.withPostSetHook { x: BooleanSetting => Yscriptrunner.value = if (x) "default" else "resident" }
}
3 changes: 3 additions & 0 deletions src/compiler/scala/tools/nsc/Global.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,9 @@ class Global(var currentSettings: Settings, reporter0: LegacyReporter)
if (settings.browse containsPhase globalPhase)
treeBrowser browse (phase.name, units)

if ((settings.Yvalidatepos containsPhase globalPhase) && !reporter.hasErrors)
currentRun.units.foreach(unit => validatePositions(unit.body))

// move the pointer
globalPhase = globalPhase.next

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/ScriptRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

package scala.tools.nsc

import scala.reflect.io.{Directory, File, Path}
import scala.reflect.io.{Directory, File}
import scala.tools.nsc.classpath.DirectoryClassPath
import scala.tools.nsc.reporters.{Reporter,ConsoleReporter}
import scala.util.control.NonFatal
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/ast/TreeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL {
// Rewrite This(enclModuleClass) to Ident(enclModuleClass) to avoid unnecessary capture of the module
// class, which might hamper serializability.
//
// Analagous to this special case in ExplicitOuter: https://github.com/scala/scala/blob/d2d33ddf8c/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala#L410-L412
// Analogous to this special case in ExplicitOuter: https://github.com/scala/scala/blob/d2d33ddf8c/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala#L410-L412
// that understands that such references shouldn't give rise to outer params.
val enclosingStaticModules = owner.enclClassChain.filter(x => !x.hasPackageFlag && x.isModuleClass && x.isStatic)
enclosingStaticModules.foldLeft(tree)((tree, moduleClass) => tree.substituteThis(moduleClass, gen.mkAttributedIdent(moduleClass.sourceModule)) )
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/scala/tools/nsc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ trait Trees extends scala.reflect.internal.Trees { self: Global =>
transform(fn)
case EmptyTree =>
tree
// The typer does not accept UnApply. Replace it to Apply, which can be retyped.
case UnApply(Apply(Select(prefix, termNames.unapply | termNames.unapplySeq),
List(Ident(termNames.SELECTOR_DUMMY))), args) =>
Apply(prefix, transformTrees(args))
case _ =>
val dupl = tree.duplicate
// Typically the resetAttrs transformer cleans both symbols and types.
Expand Down
8 changes: 7 additions & 1 deletion src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1300,14 +1300,15 @@ self =>
def finish(value: Any): Tree = try newLiteral(value) finally in.nextToken()
if (in.token == INTERPOLATIONID)
interpolatedString(inPattern = inPattern)
else if (in.token == SYMBOLLIT)
Apply(scalaDot(nme.Symbol), List(finish(in.strVal)))
else finish(in.token match {
case CHARLIT => in.charVal
case INTLIT => in.intVal(isNegated).toInt
case LONGLIT => in.intVal(isNegated)
case FLOATLIT => in.floatVal(isNegated)
case DOUBLELIT => in.doubleVal(isNegated)
case STRINGLIT | STRINGPART => in.strVal.intern()
case SYMBOLLIT => Symbol(in.strVal.intern())
case TRUE => true
case FALSE => false
case NULL => null
Expand Down Expand Up @@ -3000,9 +3001,14 @@ self =>
def template(): (List[Tree], ValDef, List[Tree]) = {
newLineOptWhenFollowedBy(LBRACE)
if (in.token == LBRACE) {
val braceOffset = in.offset
// @S: pre template body cannot stub like post body can!
val (self, body) = templateBody(isPre = true)
if (in.token == WITH && (self eq noSelfType)) {
val advice =
if (settings.isScala214) "use trait parameters instead."
else "they will be replaced by trait parameters in 2.14, see the migration guide on avoiding var/val in traits."
deprecationWarning(braceOffset, s"early initializers are deprecated; $advice", "2.13.0")
val earlyDefs: List[Tree] = body.map(ensureEarlyDef).filter(_.nonEmpty)
in.nextToken()
val parents = templateParents()
Expand Down
3 changes: 0 additions & 3 deletions src/compiler/scala/tools/nsc/ast/parser/SyntaxAnalyzer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,6 @@ abstract class SyntaxAnalyzer extends SubComponent with Parsers with MarkupParse
if (unit.body == EmptyTree)
unit.body = initialUnitBody(unit)

if (settings.Yrangepos && !reporter.hasErrors)
validatePositions(unit.body)

if (settings.Ymemberpos.isSetByUser)
new MemberPosReporter(unit) show (style = settings.Ymemberpos.value)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -444,10 +444,6 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
assert(const.value != null, const) // TODO this invariant isn't documented in `case class Constant`
mnode.visitLdcInsn(const.stringValue) // `stringValue` special-cases null, but not for a const with StringTag

case SSymbolTag =>
mnode.visitLdcInsn(const.scalaSymbolValue.name)
genCallMethod(SSymbol_apply, InvokeStyle.Static, NoPosition)

case NullTag => emit(asm.Opcodes.ACONST_NULL)

case ClazzTag =>
Expand Down Expand Up @@ -572,7 +568,7 @@ abstract class BCodeBodyBuilder extends BCodeSkelBuilder {
}
}

// scala/bug#10290: qual can be `this.$outer()` (not just `this`), so we call genLoad (not jsut ALOAD_0)
// scala/bug#10290: qual can be `this.$outer()` (not just `this`), so we call genLoad (not just ALOAD_0)
genLoad(superQual)
genLoadArguments(args, paramTKs(app))
generatedType = genCallMethod(fun.symbol, InvokeStyle.Super, app.pos, sup.tpe.typeSymbol)
Expand Down
7 changes: 4 additions & 3 deletions src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ package backend.jvm

import scala.tools.asm
import BackendReporting._
import scala.reflect.internal.Flags
import scala.tools.asm.{ByteVector, ClassWriter}
import scala.tools.asm.ClassWriter
import scala.tools.nsc.backend.jvm.BCodeHelpers.ScalaSigBytes
import scala.tools.nsc.reporters.NoReporter

Expand All @@ -32,7 +31,9 @@ abstract class BCodeHelpers extends BCodeIdiomatic {
* True for classes generated by the Scala compiler that are considered top-level in terms of
* the InnerClass / EnclosingMethod classfile attributes. See comment in BTypes.
*/
def considerAsTopLevelImplementationArtifact(classSym: Symbol) = classSym.isSpecialized
def considerAsTopLevelImplementationArtifact(classSym: Symbol) =
classSym.isSpecialized ||
classSym.isSynthetic && classSym.name.containsName(nme.delayedInitArg.toTypeName)

/**
* Cache the value of delambdafy == "inline" for each run. We need to query this value many
Expand Down
2 changes: 0 additions & 2 deletions src/compiler/scala/tools/nsc/backend/jvm/BTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
package scala.tools.nsc
package backend.jvm

import scala.collection.generic.Clearable
import scala.collection.concurrent
import scala.tools.asm
import scala.tools.asm.Opcodes
import scala.tools.nsc.backend.jvm.BTypes.{InlineInfo, InternalName}
Expand Down
13 changes: 3 additions & 10 deletions src/compiler/scala/tools/nsc/backend/jvm/BTypesFromSymbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,9 @@ abstract class BTypesFromSymbols[G <: Global](val global: G) extends BTypes {

def implementedInterfaces(classSym: Symbol): List[Symbol] = {

// scala/bug#9393: java annotations are interfaces, but the classfile / java source parsers make them look like classes.
def isInterfaceOrTrait(sym: Symbol) = sym.isInterface || sym.isTrait || sym.hasJavaAnnotationFlag

val classParents = {
val parents = classSym.info.parents
// scala/bug#9393: the classfile / java source parsers add Annotation and StaticAnnotation to the
// parents of a java annotations. undo this for the backend (where we need classfile-level information).
if (classSym.hasJavaAnnotationFlag) parents.filterNot(c => c.typeSymbol == StaticAnnotationClass || c.typeSymbol == AnnotationClass)
else parents
}
def isInterfaceOrTrait(sym: Symbol) = sym.isInterface || sym.isTrait

val classParents = classSym.info.parents

val minimizedParents = if (classSym.isJavaDefined) classParents else erasure.minimizeParents(classSym, classParents)
// We keep the superClass when computing minimizeParents to eliminate more interfaces.
Expand Down
5 changes: 0 additions & 5 deletions src/compiler/scala/tools/nsc/backend/jvm/CoreBTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,6 @@ abstract class CoreBTypesFromSymbols[G <: Global] extends CoreBTypes {
})
}

def SSymbol_apply: Symbol = _SSymbol_apply.get
private[this] lazy val _SSymbol_apply: LazyVar[Symbol] = runLazy {
getMember(SymbolModule, nme.apply)
}

def lambdaMetaFactoryMetafactoryHandle: Handle = _lambdaMetaFactoryMetafactoryHandle.get
private[this] lazy val _lambdaMetaFactoryMetafactoryHandle: LazyVar[Handle] = runLazy {
new Handle(Opcodes.H_INVOKESTATIC,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import scala.tools.asm
import scala.tools.asm.Opcodes._
import scala.tools.asm.tree._
import scala.tools.asm.tree.analysis._
import scala.tools.asm.{Handle, Label, Type}
import scala.tools.asm.{Handle, Type}
import scala.tools.nsc.backend.jvm.BTypes._
import scala.tools.nsc.backend.jvm.GenBCode._
import scala.tools.nsc.backend.jvm.analysis.BackendUtils._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package opt

import scala.annotation.{tailrec, switch}

import scala.PartialFunction.cond
import scala.reflect.internal.util.Collections._
import scala.tools.asm.commons.CodeSizeEvaluator
import scala.tools.asm.tree.analysis._
Expand Down
14 changes: 7 additions & 7 deletions src/compiler/scala/tools/nsc/fsc/FscSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ class FscSettings(error: String => Unit) extends Settings(error) {
disable(resident)
}

val currentDir = StringSetting ("-current-dir", "path", "Base directory for resolving relative paths", "").internalOnly()
val reset = BooleanSetting("-reset", "Reset compile server caches")
val shutdown = BooleanSetting("-shutdown", "Shutdown compile server")
val server = StringSetting ("-server", "hostname:portnumber", "Specify compile server socket", "")
val currentDir = StringSetting ("-current-dir", "path", "Base directory for resolving relative paths", "").internalOnly() withAbbreviation "--current-directory"
val reset = BooleanSetting("-reset", "Reset compile server caches") withAbbreviation "--reset"
val shutdown = BooleanSetting("-shutdown", "Shutdown compile server") withAbbreviation "--shutdown"
val server = StringSetting ("-server", "hostname:portnumber", "Specify compile server socket", "") withAbbreviation "--server"
val port = IntSetting ("-port", "Search and start compile server in given port only",
0, Some((0, Int.MaxValue)), (_: String) => None)
val preferIPv4 = BooleanSetting("-ipv4", "Use IPv4 rather than IPv6 for the server socket")
0, Some((0, Int.MaxValue)), (_: String) => None) withAbbreviation "--port"
val preferIPv4 = BooleanSetting("-ipv4", "Use IPv4 rather than IPv6 for the server socket") withAbbreviation "--ipv4"
val idleMins = IntSetting ("-max-idle", "Set idle timeout in minutes for fsc (use 0 for no timeout)",
30, Some((0, Int.MaxValue)), (_: String) => None)
30, Some((0, Int.MaxValue)), (_: String) => None) withAbbreviation "--max-idle"

// For improved help output, separating fsc options from the others.
def fscSpecific = Set[Settings#Setting](
Expand Down
1 change: 1 addition & 0 deletions src/compiler/scala/tools/nsc/io/Jar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class Jar(file: File) extends AbstractIterable[JarEntry] {
Iterator continually in.getNextJarEntry() takeWhile (_ != null) foreach f
}
override def iterator: Iterator[JarEntry] = this.toList.iterator
override def isEmpty: Boolean = iterator.isEmpty
override def toString = "" + file
}

Expand Down
11 changes: 5 additions & 6 deletions src/compiler/scala/tools/nsc/javac/JavaParsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -770,11 +770,7 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
val idefs = members.toList ::: (sdefs flatMap forwarders)
(sdefs, idefs)
}
def annotationParents = List(
gen.scalaAnnotationDot(tpnme.Annotation),
Select(javaLangDot(nme.annotation), tpnme.Annotation),
gen.scalaAnnotationDot(tpnme.StaticAnnotation)
)
def annotationParents = Select(javaLangDot(nme.annotation), tpnme.Annotation) :: Nil
def annotationDecl(mods: Modifiers): List[Tree] = {
accept(AT)
accept(INTERFACE)
Expand All @@ -783,7 +779,10 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
val (statics, body) = typeBody(AT, name)
val templ = makeTemplate(annotationParents, body)
addCompanionObject(statics, atPos(pos) {
ClassDef(mods | Flags.JAVA_ANNOTATION, name, List(), templ)
import Flags._
ClassDef(
mods | JAVA_ANNOTATION | TRAIT | INTERFACE | ABSTRACT,
name, List(), templ)
})
}

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/scala/tools/nsc/profile/Profiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ private [profile] class RealProfiler(reporter : ProfileReporter, val settings: S
}
private def readHeapUsage() = RealProfiler.memoryMx.getHeapMemoryUsage.getUsed

private def doGC: Unit = {
private def doGC(): Unit = {
System.gc()
System.runFinalization()
}
Expand Down
Loading

0 comments on commit c40c26b

Please sign in to comment.