Skip to content

Commit

Permalink
Completely remove logic to set Main-Class
Browse files Browse the repository at this point in the history
It never actually worked (see previous commit), we have no tests for it,
and it's only useful for a marginal feature (when the compiler outputs a
jar), better to remove dead code and wait for a usecase to appear.
  • Loading branch information
smarter committed Sep 11, 2019
1 parent e89516a commit 3ebf919
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 146 deletions.
23 changes: 4 additions & 19 deletions compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,27 +77,12 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
/*
* must-single-thread
*/
def initBytecodeWriter(entryPoints: List[Symbol]): BytecodeWriter = {
def initBytecodeWriter(): BytecodeWriter = {
getSingleOutput match {
case Some(f) if f hasExtension "jar" =>
// If no main class was specified, see if there's only one
// entry point among the classes going into the jar.
if (mainClass.isEmpty) {
entryPoints map (_.fullName('.')) match {
case Nil =>
log("No Main-Class designated or discovered.")
case name :: Nil =>
log(s"Unique entry point: setting Main-Class to $name")
setMainClass(name)
case names =>
log(s"No Main-Class due to multiple entry points:\n ${names.mkString("\n ")}")
}
}
else log(s"Main-Class was specified: ${mainClass.get}")

case Some(f) if f.hasExtension("jar") =>
new DirectToJarfileWriter(f.file)

case _ => factoryNonJarBytecodeWriter()
case _ =>
factoryNonJarBytecodeWriter()
}
}

Expand Down
3 changes: 0 additions & 3 deletions compiler/src/dotty/tools/backend/jvm/BackendInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,11 @@ abstract class BackendInterface extends BackendInterfaceDefinitions {
/* various configuration options used by backend */
def emitAsmp: Option[String]
def dumpClasses: Option[String]
def mainClass: Option[String]
def noForwarders: Boolean
def debuglevel: Int
def settings_debug: Boolean
def targetPlatform: String
def sourceFileFor(cu: CompilationUnit): String
def setMainClass(name: String): Unit
def informProgress(msg: String): Unit
def hasLabelDefs: Boolean // whether this compiler uses LabelDefs (i.e., scalac)

Expand Down Expand Up @@ -508,7 +506,6 @@ abstract class BackendInterface extends BackendInterfaceDefinitions {
def isNonBottomSubClass(sym: Symbol): Boolean
def hasAnnotation(sym: Symbol): Boolean
def shouldEmitForwarders: Boolean
def isJavaEntryPoint: Boolean
def isJavaDefaultMethod: Boolean
def isClassConstructor: Boolean
def isSerializable: Boolean
Expand Down
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/backend/jvm/BytecodeWriters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ trait BytecodeWriters {
}

class DirectToJarfileWriter(jfile: JFile) extends BytecodeWriter {
val jarMainAttrs = mainClass.map(nm => List(Name.MAIN_CLASS -> nm)).getOrElse(Nil)

val writer = new Jar(jfile).jarWriter(jarMainAttrs: _*)
val writer = new Jar(jfile).jarWriter()

def writeClass(label: String, jclassName: String, jclassBytes: Array[Byte], outfile: AbstractFile): Unit = {
assert(outfile == null,
Expand Down
104 changes: 0 additions & 104 deletions compiler/src/dotty/tools/backend/jvm/CollectEntryPoints.scala

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -400,12 +400,6 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
if (ctx.settings.Ydumpclasses.isDefault) None
else Some(ctx.settings.Ydumpclasses.value)

def mainClass: Option[String] =
if (ctx.settings.XmainClass.isDefault) None
else Some(ctx.settings.XmainClass.value)
def setMainClass(name: String): Unit = ctx.settings.XmainClass.update(name)


def noForwarders: Boolean = ctx.settings.XnoForwarders.value
def debuglevel: Int = 3 // 0 -> no debug info; 1-> filename; 2-> lines; 3-> varnames
def settings_debug: Boolean = ctx.settings.Ydebug.value
Expand Down Expand Up @@ -700,7 +694,6 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
def hasAnnotation(ann: Symbol): Boolean = toDenot(sym).hasAnnotation(ann)
def shouldEmitForwarders: Boolean =
(sym.is(Flags.Module)) && sym.isStatic
def isJavaEntryPoint: Boolean = CollectEntryPoints.isJavaEntryPoint(sym)
def isEnum = sym.is(Flags.Enum)

def isClassConstructor: Boolean = toDenot(sym).isClassConstructor
Expand Down
11 changes: 4 additions & 7 deletions compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ import dotty.tools.io._

class GenBCode extends Phase {
def phaseName: String = GenBCode.name
private val entryPoints = new mutable.HashSet[Symbol]()
def registerEntryPoint(sym: Symbol): Unit = entryPoints += sym

private val superCallsMap = newMutableSymbolMap[Set[ClassSymbol]]
def registerSuperCall(sym: Symbol, calls: ClassSymbol): Unit = {
Expand All @@ -50,9 +48,8 @@ class GenBCode extends Phase {
}

def run(implicit ctx: Context): Unit = {
new GenBCodePipeline(entryPoints.toList,
new DottyBackendInterface(outputDir, superCallsMap.toMap)(ctx))(ctx).run(ctx.compilationUnit.tpdTree)
entryPoints.clear()
new GenBCodePipeline(new DottyBackendInterface(
outputDir, superCallsMap.toMap)(ctx))(ctx).run(ctx.compilationUnit.tpdTree)
}

override def runOn(units: List[CompilationUnit])(implicit ctx: Context): List[CompilationUnit] = {
Expand All @@ -69,7 +66,7 @@ object GenBCode {
val name: String = "genBCode"
}

class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInterface)(implicit val ctx: Context) extends BCodeSyncAndTry {
class GenBCodePipeline(val int: DottyBackendInterface)(implicit val ctx: Context) extends BCodeSyncAndTry {

private[this] var tree: Tree = _

Expand Down Expand Up @@ -474,7 +471,7 @@ class GenBCodePipeline(val entryPoints: List[Symbol], val int: DottyBackendInter
// Statistics.stopTimer(BackendStats.bcodeInitTimer, initStart)

// initBytecodeWriter invokes fullName, thus we have to run it before the typer-dependent thread is activated.
bytecodeWriter = initBytecodeWriter(entryPoints)
bytecodeWriter = initBytecodeWriter()
mirrorCodeGen = new JMirrorBuilder

val needsOutfileForSymbol = bytecodeWriter.isInstanceOf[ClassBytecodeWriter]
Expand Down
2 changes: 0 additions & 2 deletions compiler/src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,6 @@ class Compiler {
new RestoreScopes, // Repair scopes rendered invalid by moving definitions in prior phases of the group
new SelectStatic, // get rid of selects that would be compiled into GetStatic
new sjs.JUnitBootstrappers, // Generate JUnit-specific bootstrapper classes for Scala.js (not enabled by default)
// FIXME: See comment in CollectEntryPoints
// new CollectEntryPoints, // Find classes with main methods
new CollectSuperCalls) :: // Find classes that are called with super
Nil

Expand Down
1 change: 0 additions & 1 deletion compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@ class ScalaSettings extends Settings.SettingGroup {
val XprintDiffDel: Setting[Boolean] = BooleanSetting("-Xprint-diff-del", "Print changed parts of the tree since last print including deleted parts.")
val XprintInline: Setting[Boolean] = BooleanSetting("-Xprint-inline", "Show where inlined code comes from")
val Xprompt: Setting[Boolean] = BooleanSetting("-Xprompt", "Display a prompt after each error (debugging option).")
val XmainClass: Setting[String] = StringSetting("-Xmain-class", "path", "Class for manifest's Main-Class entry (only useful with -d <jar>)", "")
val XnoValueClasses: Setting[Boolean] = BooleanSetting("-Xno-value-classes", "Do not use value classes. Helps debugging.")
val XreplLineWidth: Setting[Int] = IntSetting("-Xrepl-line-width", "Maximal number of columns per line for REPL output", 390)
val XfatalWarnings: Setting[Boolean] = BooleanSetting("-Xfatal-warnings", "Fail the compilation if there are any warnings.")
Expand Down

0 comments on commit 3ebf919

Please sign in to comment.