Skip to content

Commit d55ea54

Browse files
committed
Merge commit 'refs/pull/530/head'; commit 'refs/pull/531/head'; commit 'refs/pull/532/head'; commit 'refs/pull/533/head'; commit 'refs/pull/534/head' into develop
5 parents 3caf528 + 3fdc052 + 389a15b + 82f3e49 + 3a7a92b commit d55ea54

Some content is hidden

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

71 files changed

+632
-343
lines changed

project.SAMPLE

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,6 @@
55
<projects>
66
</projects>
77
<buildSpec>
8-
<buildCommand>
9-
<name>org.eclipse.pde.ManifestBuilder</name>
10-
<arguments>
11-
</arguments>
12-
</buildCommand>
13-
<buildCommand>
14-
<name>org.eclipse.pde.SchemaBuilder</name>
15-
<arguments>
16-
</arguments>
17-
</buildCommand>
188
<buildCommand>
199
<name>org.scala-ide.sdt.core.scalabuilder</name>
2010
<arguments>
@@ -23,7 +13,6 @@
2313
</buildSpec>
2414
<natures>
2515
<nature>org.scala-ide.sdt.core.scalanature</nature>
26-
<nature>org.eclipse.pde.PluginNature</nature>
2716
<nature>org.eclipse.jdt.core.javanature</nature>
2817
</natures>
2918
</projectDescription>

src/compiler/scala/reflect/internal/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,7 +1207,7 @@ trait Definitions extends reflect.api.StandardDefinitions {
12071207
def isPrimitiveValueClass(sym: Symbol) = ScalaValueClasses contains sym
12081208
def isNonUnitValueClass(sym: Symbol) = isPrimitiveValueClass(sym) && (sym != UnitClass)
12091209
def isSpecializableClass(sym: Symbol) = isPrimitiveValueClass(sym) || (sym == AnyRefClass)
1210-
def isScalaValueType(tp: Type) = ScalaValueClasses contains tp.typeSymbol
1210+
def isPrimitiveValueType(tp: Type) = isPrimitiveValueClass(tp.typeSymbol)
12111211

12121212
/** Is symbol a boxed value class, e.g. java.lang.Integer? */
12131213
def isBoxedValueClass(sym: Symbol) = boxedValueClassesSet(sym)

src/compiler/scala/reflect/internal/StdNames.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,6 @@ trait StdNames {
766766
object fulltpnme extends TypeNames {
767767
val RuntimeNothing: NameType = "scala.runtime.Nothing$"
768768
val RuntimeNull: NameType = "scala.runtime.Null$"
769-
val JavaLangEnum: NameType = "java.lang.Enum"
770769
}
771770

772771
/** Java binary names, like scala/runtime/Nothing$.

src/compiler/scala/reflect/internal/Symbols.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2088,7 +2088,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
20882088
/** String representation of symbol's definition key word */
20892089
final def keyString: String =
20902090
if (isJavaInterface) "interface"
2091-
else if (isTrait) "trait"
2091+
else if (isTrait && !isImplClass) "trait"
20922092
else if (isClass) "class"
20932093
else if (isType && !isParameter) "type"
20942094
else if (isVariable) "var"
@@ -2116,6 +2116,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
21162116
else if (isSetter) ("setter", if (isSourceMethod) "method" else "value", "SET")
21172117
else if (isTerm && isLazy) ("lazy value", "lazy value", "LAZ")
21182118
else if (isVariable) ("field", "variable", "VAR")
2119+
else if (isImplClass) ("implementation class", "class", "IMPL")
21192120
else if (isTrait) ("trait", "trait", "TRT")
21202121
else if (isClass) ("class", "class", "CLS")
21212122
else if (isType) ("type", "type", "TPE")
@@ -2232,7 +2233,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
22322233
}
22332234

22342235
def infosString = infos.toString
2235-
def debugLocationString = fullLocationString + " " + debugFlagString
2236+
def debugLocationString = fullLocationString + " (flags: " + debugFlagString + ")"
22362237

22372238
private def defStringCompose(infoString: String) = compose(
22382239
flagString,

src/compiler/scala/reflect/internal/Trees.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,11 +145,12 @@ trait Trees extends api.Trees { self: SymbolTable =>
145145
*/
146146
def summaryString: String = tree match {
147147
case Literal(const) => "Literal(" + const + ")"
148-
case Select(qual, name) => qual.summaryString + "." + name.decode
148+
case Ident(name) => "Ident(%s)".format(name.decode)
149+
case Select(qual, name) => "Select(%s, %s)".format(qual.summaryString, name.decode)
149150
case t: NameTree => t.name.longString
150151
case t =>
151152
t.shortClass + (
152-
if (t.symbol != null && t.symbol != NoSymbol) " " + t.symbol
153+
if (t.symbol != null && t.symbol != NoSymbol) "(" + t.symbol + ")"
153154
else ""
154155
)
155156
}

src/compiler/scala/reflect/internal/Types.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2663,6 +2663,10 @@ trait Types extends api.Types { self: SymbolTable =>
26632663
override def kind = "OverloadedType"
26642664
}
26652665

2666+
def overloadedType(pre: Type, alternatives: List[Symbol]): Type =
2667+
if (alternatives.tail.isEmpty) pre memberType alternatives.head
2668+
else OverloadedType(pre, alternatives)
2669+
26662670
/** A class remembering a type instantiation for some a set of overloaded
26672671
* polymorphic symbols.
26682672
* Not used after phase `typer`.

src/compiler/scala/reflect/internal/transform/Erasure.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,14 @@ trait Erasure {
1717
* with primitive as well as class types)?.
1818
*/
1919
private def genericCore(tp: Type): Type = tp.normalize match {
20-
case TypeRef(_, sym, _) if sym.isAbstractType && !sym.owner.isJavaDefined =>
20+
/* A Java Array<T> is erased to Array[Object] (T can only be a reference type), where as a Scala Array[T] is
21+
* erased to Object. However, there is only symbol for the Array class. So to make the distinction between
22+
* a Java and a Scala array, we check if the owner of T comes from a Java class.
23+
* This however caused issue SI-5654. The additional test for EXSITENTIAL fixes it, see the ticket comments.
24+
* In short, members of an existential type (e.g. `T` in `forSome { type T }`) can have pretty arbitrary
25+
* owners (e.g. when computing lubs, <root> is used). All packageClass symbols have `isJavaDefined == true`.
26+
*/
27+
case TypeRef(_, sym, _) if sym.isAbstractType && (!sym.owner.isJavaDefined || sym.hasFlag(Flags.EXISTENTIAL)) =>
2128
tp
2229
case ExistentialType(tparams, restp) =>
2330
genericCore(restp)

src/compiler/scala/reflect/internal/util/TraceSymbolActivity.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ trait TraceSymbolActivity {
77
val global: SymbolTable
88
import global._
99

10-
if (traceSymbolActivity)
10+
if (traceSymbolActivity && !global.inReflexiveMirror)
1111
scala.sys addShutdownHook showAllSymbols()
1212

1313
private type Set[T] = scala.collection.immutable.Set[T]

src/compiler/scala/tools/nsc/Global.scala

Lines changed: 65 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
162162

163163
/** Register new context; called for every created context
164164
*/
165-
def registerContext(c: analyzer.Context) {}
165+
def registerContext(c: analyzer.Context) {
166+
lastSeenContext = c
167+
}
166168

167169
/** Register top level class (called on entering the class)
168170
*/
@@ -894,13 +896,22 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
894896
curRun = null
895897
}
896898

899+
object typeDeconstruct extends {
900+
val global: Global.this.type = Global.this
901+
} with interpreter.StructuredTypeStrings
902+
897903
/** There are common error conditions where when the exception hits
898904
* here, currentRun.currentUnit is null. This robs us of the knowledge
899905
* of what file was being compiled when it broke. Since I really
900906
* really want to know, this hack.
901907
*/
902908
private var lastSeenSourceFile: SourceFile = NoSourceFile
903909

910+
/** Let's share a lot more about why we crash all over the place.
911+
* People will be very grateful.
912+
*/
913+
private var lastSeenContext: analyzer.Context = null
914+
904915
/** The currently active run
905916
*/
906917
def currentRun: Run = curRun
@@ -929,25 +940,64 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
929940
@inline final def beforeTyper[T](op: => T): T = beforePhase(currentRun.typerPhase)(op)
930941
@inline final def beforeUncurry[T](op: => T): T = beforePhase(currentRun.uncurryPhase)(op)
931942

943+
def explainContext(c: analyzer.Context): String = (
944+
if (c == null) "" else (
945+
"""| context owners: %s
946+
|
947+
|Enclosing block or template:
948+
|%s""".format(
949+
c.owner.ownerChain.takeWhile(!_.isPackageClass).mkString(" -> "),
950+
nodePrinters.nodeToString(c.enclClassOrMethod.tree)
951+
)
952+
)
953+
)
954+
// Owners up to and including the first package class.
955+
private def ownerChainString(sym: Symbol): String = (
956+
if (sym == null) ""
957+
else sym.ownerChain.span(!_.isPackageClass) match {
958+
case (xs, pkg :: _) => (xs :+ pkg) mkString " -> "
959+
case _ => sym.ownerChain mkString " -> " // unlikely
960+
}
961+
)
962+
private def formatExplain(pairs: (String, Any)*): String = (
963+
pairs.toList collect { case (k, v) if v != null => "%20s: %s".format(k, v) } mkString "\n"
964+
)
965+
966+
def explainTree(t: Tree): String = formatExplain(
967+
)
968+
932969
/** Don't want to introduce new errors trying to report errors,
933970
* so swallow exceptions.
934971
*/
935972
override def supplementErrorMessage(errorMessage: String): String = try {
936-
"""|
937-
| while compiling: %s
938-
| current phase: %s
939-
| library version: %s
940-
| compiler version: %s
941-
| reconstructed args: %s
942-
|
943-
|%s""".stripMargin.format(
944-
currentSource.path,
945-
phase,
946-
scala.util.Properties.versionString,
947-
Properties.versionString,
948-
settings.recreateArgs.mkString(" "),
949-
if (opt.debug) "Current unit body:\n" + currentUnit.body + "\n" + errorMessage else errorMessage
973+
val tree = analyzer.lastTreeToTyper
974+
val sym = tree.symbol
975+
val tpe = tree.tpe
976+
val enclosing = lastSeenContext.enclClassOrMethod.tree
977+
978+
val info1 = formatExplain(
979+
"while compiling" -> currentSource.path,
980+
"during phase" -> phase,
981+
"library version" -> scala.util.Properties.versionString,
982+
"compiler version" -> Properties.versionString,
983+
"reconstructed args" -> settings.recreateArgs.mkString(" ")
984+
)
985+
val info2 = formatExplain(
986+
"last tree to typer" -> tree.summaryString,
987+
"symbol" -> Option(sym).fold("null")(_.debugLocationString),
988+
"symbol definition" -> Option(sym).fold("null")(_.defString),
989+
"tpe" -> tpe,
990+
"symbol owners" -> ownerChainString(sym),
991+
"context owners" -> ownerChainString(lastSeenContext.owner)
950992
)
993+
val info3: List[String] = (
994+
( List("== Enclosing template or block ==", nodePrinters.nodeToString(enclosing).trim) )
995+
++ ( if (tpe eq null) Nil else List("== Expanded type of tree ==", typeDeconstruct.show(tpe)) )
996+
++ ( if (!opt.debug) Nil else List("== Current unit body ==", nodePrinters.nodeToString(currentUnit.body)) )
997+
++ ( List(errorMessage) )
998+
)
999+
1000+
("\n" + info1) :: info2 :: info3 mkString "\n\n"
9511001
}
9521002
catch { case x: Exception => errorMessage }
9531003

src/compiler/scala/tools/nsc/ast/TreeGen.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ abstract class TreeGen extends reflect.internal.TreeGen with TreeDSL {
236236
mkMethodCall(
237237
PredefModule,
238238
wrapArrayMethodName(elemtp),
239-
if (isScalaValueType(elemtp)) Nil else List(elemtp),
239+
if (isPrimitiveValueType(elemtp)) Nil else List(elemtp),
240240
List(tree)
241241
)
242242
}
@@ -261,7 +261,7 @@ abstract class TreeGen extends reflect.internal.TreeGen with TreeDSL {
261261
* elem type elemtp to expected type pt.
262262
*/
263263
def mkCastArray(tree: Tree, elemtp: Type, pt: Type) =
264-
if (elemtp.typeSymbol == AnyClass && isScalaValueType(tree.tpe.typeArgs.head))
264+
if (elemtp.typeSymbol == AnyClass && isPrimitiveValueType(tree.tpe.typeArgs.head))
265265
mkCast(mkRuntimeCall(nme.toObjectArray, List(tree)), pt)
266266
else
267267
mkCast(tree, pt)

src/compiler/scala/tools/nsc/backend/icode/GenICode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1208,7 +1208,7 @@ abstract class GenICode extends SubComponent {
12081208
if (!tree.symbol.isPackageClass) tree.symbol
12091209
else tree.symbol.info.member(nme.PACKAGE) match {
12101210
case NoSymbol => assert(false, "Cannot use package as value: " + tree) ; NoSymbol
1211-
case s => Console.err.println("Bug: found package class where package object expected. Converting.") ; s.moduleClass
1211+
case s => debugwarn("Bug: found package class where package object expected. Converting.") ; s.moduleClass
12121212
}
12131213
)
12141214
debuglog("LOAD_MODULE from %s: %s".format(tree.shortClass, sym))

src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1159,6 +1159,27 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
11591159
*/
11601160
def generateMirrorClass(clasz: Symbol, sourceFile: SourceFile) {
11611161
import JAccessFlags._
1162+
/* We need to save inner classes buffer and create a new one to make sure
1163+
* that we do confuse inner classes of the class we mirror with inner
1164+
* classes of the class we are mirroring. These two sets can be different
1165+
* as seen in this case:
1166+
*
1167+
* class A {
1168+
* class B
1169+
* def b: B = new B
1170+
* }
1171+
* object C extends A
1172+
*
1173+
* Here mirror class of C has a static forwarder for (inherited) method `b`
1174+
* therefore it refers to class `B` and needs InnerClasses entry. However,
1175+
* the real class for `C` (named `C$`) is empty and does not refer to `B`
1176+
* thus does not need InnerClasses entry it.
1177+
*
1178+
* NOTE: This logic has been refactored in GenASM and everything is
1179+
* implemented in a much cleaner way by having two separate buffers.
1180+
*/
1181+
val savedInnerClasses = innerClassBuffer
1182+
innerClassBuffer = mutable.LinkedHashSet[Symbol]()
11621183
val moduleName = javaName(clasz) // + "$"
11631184
val mirrorName = moduleName.substring(0, moduleName.length() - 1)
11641185
val mirrorClass = fjbgContext.JClass(ACC_SUPER | ACC_PUBLIC | ACC_FINAL,
@@ -1172,6 +1193,7 @@ abstract class GenJVM extends SubComponent with GenJVMUtil with GenAndroid with
11721193
val ssa = scalaSignatureAddingMarker(mirrorClass, clasz.companionSymbol)
11731194
addAnnotations(mirrorClass, clasz.annotations ++ ssa)
11741195
emitClass(mirrorClass, clasz)
1196+
innerClassBuffer = savedInnerClasses
11751197
}
11761198

11771199
var linearization: List[BasicBlock] = Nil

src/compiler/scala/tools/nsc/doc/model/ModelFactoryImplicitSupport.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ trait ModelFactoryImplicitSupport {
179179
hardcoded.arraySkipConversions.contains(conv.conversionQualifiedName))
180180

181181
// Filter out non-sensical conversions from value types
182-
if (isScalaValueType(sym.tpe))
182+
if (isPrimitiveValueType(sym.tpe))
183183
conversions = conversions.filter((ic: ImplicitConversion) =>
184184
hardcoded.valueClassFilter(sym.nameString, ic.conversionQualifiedName))
185185

src/compiler/scala/tools/nsc/interactive/Global.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ class Global(settings: Settings, _reporter: Reporter, projectName: String = "")
930930
val implicitlyAdded = viaView != NoSymbol
931931
members.add(sym, pre, implicitlyAdded) { (s, st) =>
932932
new TypeMember(s, st,
933-
context.isAccessible(s, pre, superAccess && !implicitlyAdded),
933+
context.isAccessible(if (s.hasGetter) s.getter(s.owner) else s, pre, superAccess && !implicitlyAdded),
934934
inherited,
935935
viaView)
936936
}

src/compiler/scala/tools/nsc/javac/JavaParsers.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -872,7 +872,10 @@ trait JavaParsers extends ast.parser.ParsersCommon with JavaScanners {
872872
skipAhead()
873873
accept(RBRACE)
874874
}
875-
ValDef(Modifiers(Flags.JAVA | Flags.STATIC), name, enumType, blankExpr)
875+
// The STABLE flag is to signal to namer that this was read from a
876+
// java enum, and so should be given a Constant type (thereby making
877+
// it usable in annotations.)
878+
ValDef(Modifiers(Flags.STABLE | Flags.JAVA | Flags.STATIC), name, enumType, blankExpr)
876879
}
877880
}
878881

src/compiler/scala/tools/nsc/transform/Erasure.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ abstract class Erasure extends AddInterfaces
625625
tree.duplicate setType pt
626626
} else if (tree.tpe != null && tree.tpe.typeSymbol == ArrayClass && pt.typeSymbol == ArrayClass) {
627627
// See SI-2386 for one example of when this might be necessary.
628-
val needsExtraCast = isScalaValueType(tree.tpe.typeArgs.head) && !isScalaValueType(pt.typeArgs.head)
628+
val needsExtraCast = isPrimitiveValueType(tree.tpe.typeArgs.head) && !isPrimitiveValueType(pt.typeArgs.head)
629629
val tree1 = if (needsExtraCast) gen.mkRuntimeCall(nme.toObjectArray, List(tree)) else tree
630630
gen.mkAttributedCast(tree1, pt)
631631
} else gen.mkAttributedCast(tree, pt)

src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
6767

6868
import definitions.{
6969
RootClass, BooleanClass, UnitClass, ArrayClass,
70-
ScalaValueClasses, isPrimitiveValueClass, isScalaValueType,
70+
ScalaValueClasses, isPrimitiveValueClass, isPrimitiveValueType,
7171
SpecializedClass, UnspecializedClass, AnyRefClass, ObjectClass, AnyRefModule,
7272
GroupOfSpecializable, uncheckedVarianceClass, ScalaInlineClass
7373
}
@@ -145,7 +145,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
145145
def includes(t1: TypeEnv, t2: TypeEnv) = t1 forall {
146146
case (sym, tpe) =>
147147
t2 get sym exists { t2tp =>
148-
(tpe == t2tp) || !(isScalaValueType(tpe) || isScalaValueType(t2tp)) // u.t.b. (t2tp <:< AnyRefClass.tpe)
148+
(tpe == t2tp) || !(isPrimitiveValueType(tpe) || isPrimitiveValueType(t2tp)) // u.t.b. (t2tp <:< AnyRefClass.tpe)
149149
}
150150
}
151151

@@ -266,7 +266,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
266266
* specialized type.
267267
*/
268268
def survivingArgs(sym: Symbol, args: List[Type]): List[Type] =
269-
for ((tvar, tpe) <- sym.info.typeParams.zip(args) if !tvar.isSpecialized || !isScalaValueType(tpe))
269+
for ((tvar, tpe) <- sym.info.typeParams.zip(args) if !tvar.isSpecialized || !isPrimitiveValueType(tpe))
270270
yield tpe
271271

272272
val specializedType = new TypeMap {
@@ -448,7 +448,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
448448

449449
/** Type parameters that survive when specializing in the specified environment. */
450450
def survivingParams(params: List[Symbol], env: TypeEnv) =
451-
params.filter(p => !p.isSpecialized || !isScalaValueType(env(p)))
451+
params.filter(p => !p.isSpecialized || !isPrimitiveValueType(env(p)))
452452

453453
/** Produces the symbols from type parameters `syms` of the original owner,
454454
* in the given type environment `env`. The new owner is `nowner`.
@@ -1588,7 +1588,7 @@ abstract class SpecializeTypes extends InfoTransform with TypingTransformers {
15881588
// val (_, origtparams) = splitParams(source.typeParams)
15891589
val env = typeEnv(symbol)
15901590
val boundTvars = env.keySet
1591-
val origtparams = source.typeParams.filter(tparam => !boundTvars(tparam) || !isScalaValueType(env(tparam)))
1591+
val origtparams = source.typeParams.filter(tparam => !boundTvars(tparam) || !isPrimitiveValueType(env(tparam)))
15921592
if (origtparams.nonEmpty || symbol.typeParams.nonEmpty)
15931593
debuglog("substituting " + origtparams + " for " + symbol.typeParams)
15941594

src/compiler/scala/tools/nsc/typechecker/Namers.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,15 @@ trait Namers extends MethodSynthesis {
567567
assignAndEnterFinishedSymbol(tree)
568568
else
569569
enterGetterSetter(tree)
570+
571+
// When java enums are read from bytecode, they are known to have
572+
// constant types by the jvm flag and assigned accordingly. When
573+
// they are read from source, the java parser marks them with the
574+
// STABLE flag, and now we receive that signal.
575+
if (tree.symbol hasAllFlags STABLE | JAVA)
576+
tree.symbol setInfo ConstantType(Constant(tree.symbol))
570577
}
578+
571579
def enterLazyVal(tree: ValDef, lazyAccessor: Symbol): TermSymbol = {
572580
// If the owner is not a class, this is a lazy val from a method,
573581
// with no associated field. It has an accessor with $lzy appended to its name and

0 commit comments

Comments
 (0)