From 79c1f9882a31a833bb02ecbbdfdcb6ca61d2c522 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 31 Mar 2009 18:08:39 +0000 Subject: Moved static forwarder generation behind -Xforw... Moved static forwarder generation behind -Xforwarders option. Special cased main so #363 continues to work. Moved test case for #1745 into pending since it requires forwarders to work. --- src/compiler/scala/tools/nsc/Settings.scala | 1 + .../scala/tools/nsc/backend/jvm/GenJVM.scala | 22 ++++++++++++++++------ 2 files changed, 17 insertions(+), 6 deletions(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/Settings.scala b/src/compiler/scala/tools/nsc/Settings.scala index f13e1cfa21..6026186010 100644 --- a/src/compiler/scala/tools/nsc/Settings.scala +++ b/src/compiler/scala/tools/nsc/Settings.scala @@ -618,6 +618,7 @@ trait ScalacSettings val checkInit = BooleanSetting ("-Xcheckinit", "Add runtime checks on field accessors. Uninitialized accesses result in an exception being thrown.") val noassertions = BooleanSetting ("-Xdisable-assertions", "Generate no assertions and assumptions") val Xexperimental = BooleanSetting ("-Xexperimental", "Enable experimental extensions") + val forwarders = BooleanSetting ("-Xforwarders", "Generate static forwarders in mirror classes") val future = BooleanSetting ("-Xfuture", "Turn on future language features") val genPhaseGraph = StringSetting ("-Xgenerate-phase-graph", "file", "Generate the phase graphs (outputs .dot files) to fileX.dot", "") val XlogImplicits = BooleanSetting ("-Xlog-implicits", "Show more info on why some implicits are not applicable") diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala index cee270e555..e77333581b 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenJVM.scala @@ -209,10 +209,17 @@ abstract class GenJVM extends SubComponent { } } else { + val lmoc = c.symbol.linkedModuleOfClass // add static forwarders if there are no name conflicts; see bugs #363 and #1735 - if (c.symbol.linkedModuleOfClass != NoSymbol && !c.symbol.hasFlag(Flags.INTERFACE)) { - log("Adding forwarders to existing class " + c.symbol + " found in module " + c.symbol.linkedModuleOfClass) - addForwarders(jclass, c.symbol.linkedModuleOfClass.moduleClass) + if (lmoc != NoSymbol && !c.symbol.hasFlag(Flags.INTERFACE)) { + // forwarders were creating many issues, see #1795 for instance; so for now + // they are only enabled if -Xforwarders is supplied to scalac... + if (settings.forwarders.value) { + log("Adding forwarders to existing class " + c.symbol + " found in module " + lmoc) + addForwarders(jclass, lmoc.moduleClass) + } + // ...but we special case main so at least ticket #363 can continue to work. + else addForwarders(jclass, lmoc.moduleClass, _.name == nme.main) } } @@ -228,6 +235,7 @@ abstract class GenJVM extends SubComponent { genBeanInfoClass(c) } + /** * Generate a bean info class that describes the given class. * @@ -748,9 +756,11 @@ abstract class GenJVM extends SubComponent { /** Add forwarders for all methods defined in `module' that don't conflict with * methods in the companion class of `module'. A conflict arises when a method * with the same name is defined both in a class and its companion object (method - * signature is not taken into account). + * signature is not taken into account). If 3rd argument cond is supplied, only + * symbols for which cond(sym) is true are given forwarders. */ - def addForwarders(jclass: JClass, module: Symbol) { + def addForwarders(jclass: JClass, module: Symbol) { addForwarders(jclass, module, _ => true) } + def addForwarders(jclass: JClass, module: Symbol, cond: (Symbol) => Boolean) { def conflictsIn(cls: Symbol, name: Name) = cls.info.nonPrivateMembers.exists(_.name == name) @@ -784,7 +794,7 @@ abstract class GenJVM extends SubComponent { if (settings.debug.value) log("Dumping mirror class for object: " + module); - for (m <- module.info.nonPrivateMembers; if shouldForward(m)) + for (m <- module.info.nonPrivateMembers; if shouldForward(m) ; if cond(m)) addForwarder(jclass, module, m) } -- cgit v1.2.3