Skip to content

Commit 50486af

Browse files
committed
Refactor collecting entry points. Remove them from context and pass them via GenBCode callback
1 parent 418a84c commit 50486af

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

compiler/src/dotty/tools/backend/jvm/GenBCode.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,9 @@ class GenBCode extends Phase {
4242
superCallsMap.update(sym, old + calls)
4343
}
4444

45+
private val entryPoints = new mutable.HashSet[String]()
46+
def registerEntryPoint(s: String): Unit = entryPoints += s
47+
4548
private var myOutput: AbstractFile = _
4649

4750
private def outputDir(using Context): AbstractFile = {
@@ -63,7 +66,7 @@ class GenBCode extends Phase {
6366
override def runOn(units: List[CompilationUnit])(using Context): List[CompilationUnit] = {
6467
outputDir match
6568
case jar: JarArchive =>
66-
updateJarManifestWithMainClass(jar)
69+
updateJarManifestWithMainClass(jar, entryPoints.toList)
6770
case _ =>
6871
try super.runOn(units)
6972
finally outputDir match {
@@ -78,9 +81,9 @@ class GenBCode extends Phase {
7881
}
7982
}
8083

81-
private def updateJarManifestWithMainClass(jarArchive: JarArchive)(using Context): Unit =
84+
private def updateJarManifestWithMainClass(jarArchive: JarArchive, entryPoints: List[String])(using Context): Unit =
8285
val mainClass = Option.when(!ctx.settings.XmainClass.isDefault)(ctx.settings.XmainClass.value).orElse {
83-
ctx.entryPoints.toList.match
86+
entryPoints match
8487
case List(mainClass) =>
8588
Some(mainClass)
8689
case Nil =>

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,8 @@ object Contexts {
5252
private val (notNullInfosLoc, store8) = store7.newLocation[List[NotNullInfo]]()
5353
private val (importInfoLoc, store9) = store8.newLocation[ImportInfo]()
5454
private val (typeAssignerLoc, store10) = store9.newLocation[TypeAssigner](TypeAssigner)
55-
private val (entryPointsLoc, store11) = store10.newLocation[EntryPoints](new EntryPoints)
5655

57-
private val initialStore = store11
56+
private val initialStore = store10
5857

5958
/** The current context */
6059
inline def ctx(using ctx: Context): Context = ctx
@@ -240,9 +239,6 @@ object Contexts {
240239
/** The current type assigner or typer */
241240
def typeAssigner: TypeAssigner = store(typeAssignerLoc)
242241

243-
/** The current entry points */
244-
def entryPoints: EntryPoints = store(entryPointsLoc)
245-
246242
/** The new implicit references that are introduced by this scope */
247243
protected var implicitsCache: ContextualImplicits = null
248244
def implicits: ContextualImplicits = {

compiler/src/dotty/tools/dotc/core/EntryPoints.scala

Lines changed: 0 additions & 3 deletions
This file was deleted.

compiler/src/dotty/tools/dotc/transform/CollectEntryPoints.scala

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ import dotty.tools.dotc.ast.tpd
44
import dotty.tools.dotc.core.Contexts.Context
55
import dotty.tools.dotc.core.Types
66
import dotty.tools.dotc.transform.MegaPhase._
7-
import dotty.tools.dotc.ast.tpd
87
import java.io.{File => _}
98

109
import dotty.tools.dotc.core._
1110
import SymDenotations._
1211
import Contexts._
1312
import Types._
1413
import Symbols._
14+
import Phases._
1515
import dotty.tools.dotc.util.SourcePosition
1616
import Decorators._
1717
import StdNames.nme
1818
import dotty.tools.io.JarArchive
19+
import dotty.tools.backend.jvm.GenBCode
1920

2021
/**
2122
* Small phase to be run to collect main classes and store them in the context.
@@ -40,11 +41,19 @@ class CollectEntryPoints extends MiniPhase:
4041

4142

4243
override def transformTypeDef(tree: tpd.TypeDef)(using Context): tpd.Tree =
43-
ctx.entryPoints ++= getEntryPoint(tree)
44+
getEntryPoint(tree).map(registerEntryPoint)
4445
tree
4546

4647
private def getEntryPoint(tree: tpd.TypeDef)(using Context): Option[String] =
4748
val sym = tree.symbol
4849
import dotty.tools.dotc.core.NameOps.stripModuleClassSuffix
4950
val name = sym.fullName.stripModuleClassSuffix.toString
5051
Option.when(sym.isStatic && !sym.is(Flags.Trait) && ctx.platform.hasMainMethod(sym))(name)
52+
53+
private def registerEntryPoint(s: String)(using Context) = {
54+
genBCodePhase match {
55+
case genBCodePhase: GenBCode =>
56+
genBCodePhase.registerEntryPoint(s)
57+
case _ =>
58+
}
59+
}

0 commit comments

Comments
 (0)