Skip to content

Commit b4deeff

Browse files
committed
Cleanup
1 parent 7451dca commit b4deeff

File tree

6 files changed

+40
-97
lines changed

6 files changed

+40
-97
lines changed

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class ClassfileWriter(frontendAccess: PostProcessorFrontendAccess) {
8888
}
8989
}
9090

91-
def write(className: InternalName, bytes: Array[Byte], sourceFile: AbstractFile): AbstractFile = try {
91+
def write(className: InternalName, bytes: Array[Byte], sourceFile: AbstractFile): AbstractFile | Null = try {
9292
// val writeStart = Statistics.startTimer(BackendStats.bcodeWriteTimer)
9393
val outFile = if (jarWriter == null) {
9494
val outFolder = compilerSettings.outputDirectory
@@ -120,13 +120,13 @@ class ClassfileWriter(frontendAccess: PostProcessorFrontendAccess) {
120120
}
121121

122122
def writeTasty(className: InternalName, bytes: Array[Byte]): Unit =
123-
val outFolder = compilerSettings.outputDirectory
124-
val outFile = getFile(outFolder, className, ".tasty")
125-
try writeBytes(outFile, bytes)
126-
catch case ex: ClosedByInterruptException =>
127-
try outFile.delete() // don't leave an empty or half-written tastyfile around after an interrupt
128-
catch case _: Throwable => ()
129-
finally throw ex
123+
val outFolder = compilerSettings.outputDirectory
124+
val outFile = getFile(outFolder, className, ".tasty")
125+
try writeBytes(outFile, bytes)
126+
catch case ex: ClosedByInterruptException =>
127+
try outFile.delete() // don't leave an empty or half-written tastyfile around after an interrupt
128+
catch case _: Throwable => ()
129+
finally throw ex
130130

131131
def close(): Unit = {
132132
if (jarWriter != null) jarWriter.close()

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

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,23 @@ import dotty.tools.dotc.transform.SymUtils._
1313
import dotty.tools.dotc.interfaces
1414
import dotty.tools.dotc.report
1515

16-
import dotty.tools.dotc.util.SourceFile
1716
import java.util.Optional
18-
19-
import dotty.tools.dotc.core._
2017
import dotty.tools.dotc.sbt.ExtractDependencies
18+
import dotty.tools.dotc.core._
2119
import Contexts._
2220
import Phases._
2321
import Symbols._
22+
import StdNames.nme
2423

2524
import java.io.DataOutputStream
2625
import java.nio.channels.ClosedByInterruptException
2726

2827
import dotty.tools.tasty.{ TastyBuffer, TastyHeaderUnpickler }
2928

3029
import scala.tools.asm
31-
import scala.tools.asm.Handle
3230
import scala.tools.asm.tree._
3331
import tpd._
34-
import StdNames._
35-
import dotty.tools.io._
36-
import scala.tools.asm.MethodTooLargeException
37-
import scala.tools.asm.ClassTooLargeException
32+
import dotty.tools.io.AbstractFile
3833
import dotty.tools.dotc.util.NoSourcePosition
3934

4035

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import StdNames.nme
2424
import NameKinds.LazyBitMapName
2525
import Names.Name
2626

27-
class DottyBackendInterface(val outputDirectory: AbstractFile, val superCallsMap: ReadOnlyMap[Symbol, Set[ClassSymbol]])(using var ctx: Context) {
27+
class DottyBackendInterface(val superCallsMap: ReadOnlyMap[Symbol, Set[ClassSymbol]])(using var ctx: Context) {
2828

2929
private val desugared = new java.util.IdentityHashMap[Type, tpd.Select]
3030

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

Lines changed: 15 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,13 @@
11
package dotty.tools.backend.jvm
22

3-
import scala.language.unsafeNulls
4-
53
import dotty.tools.dotc.CompilationUnit
6-
import dotty.tools.dotc.ast.Trees.{PackageDef, ValDef}
7-
import dotty.tools.dotc.ast.tpd
84
import dotty.tools.dotc.core.Phases.Phase
9-
10-
import scala.collection.mutable
11-
import scala.collection.JavaConverters._
12-
import dotty.tools.dotc.transform.SymUtils._
13-
import dotty.tools.dotc.interfaces
145
import dotty.tools.dotc.report
15-
16-
import dotty.tools.dotc.util.SourceFile
17-
import java.util.Optional
18-
196
import dotty.tools.dotc.core._
20-
import dotty.tools.dotc.sbt.ExtractDependencies
217
import Contexts._
22-
import Phases._
238
import Symbols._
24-
25-
import java.io.DataOutputStream
26-
import java.nio.channels.ClosedByInterruptException
27-
28-
import dotty.tools.tasty.{ TastyBuffer, TastyHeaderUnpickler }
29-
30-
import scala.tools.asm
31-
import scala.tools.asm.Handle
32-
import scala.tools.asm.tree._
33-
import tpd._
34-
import StdNames._
359
import dotty.tools.io._
36-
import scala.tools.asm.MethodTooLargeException
37-
import scala.tools.asm.ClassTooLargeException
38-
import dotty.tools.dotc.util.NoSourcePosition
10+
import scala.collection.mutable
3911

4012
class GenBCode extends Phase { self =>
4113

@@ -53,50 +25,37 @@ class GenBCode extends Phase { self =>
5325
def registerEntryPoint(s: String): Unit =
5426
entryPoints += s
5527

56-
private var _outputDir: AbstractFile = _
57-
private def outputDir(using Context): AbstractFile = {
58-
if (_outputDir eq null)
59-
_outputDir = ctx.settings.outputDir.value
60-
_outputDir
61-
}
62-
63-
private var _dottyPrimitives: DottyPrimitives = null
64-
private def dottyPrimitives(using Context): DottyPrimitives = {
65-
if _dottyPrimitives eq null then
66-
_dottyPrimitives = new DottyPrimitives(ctx)
67-
_dottyPrimitives
68-
}
69-
70-
private var _backendInterface: DottyBackendInterface = null
28+
private var _backendInterface: DottyBackendInterface = _
7129
def backendInterface(using Context): DottyBackendInterface = {
7230
if _backendInterface eq null then
73-
_backendInterface = DottyBackendInterface(outputDir, superCallsMap)
31+
_backendInterface = DottyBackendInterface(superCallsMap)
7432
_backendInterface
7533
}
7634

77-
private var _codeGen: CodeGen = null
35+
private var _codeGen: CodeGen = _
7836
def codeGen(using Context): CodeGen = {
7937
if _codeGen eq null then
8038
val int = backendInterface
39+
val dottyPrimitives = new DottyPrimitives(ctx)
8140
_codeGen = new CodeGen(int, dottyPrimitives)(bTypes.asInstanceOf[BTypesFromSymbols[int.type]])
8241
_codeGen
8342
}
8443

85-
private var _frontendAccess: PostProcessorFrontendAccess = null
86-
def frontendAccess(using Context): PostProcessorFrontendAccess = {
87-
if _frontendAccess eq null then
88-
_frontendAccess = PostProcessorFrontendAccess.Impl(backendInterface)
89-
_frontendAccess
90-
}
91-
92-
private var _bTypes: BTypesFromSymbols[DottyBackendInterface] = null
44+
private var _bTypes: BTypesFromSymbols[DottyBackendInterface] = _
9345
def bTypes(using Context): BTypesFromSymbols[DottyBackendInterface] = {
9446
if _bTypes eq null then
9547
_bTypes = BTypesFromSymbols(backendInterface, frontendAccess)
9648
_bTypes
9749
}
9850

99-
private var _postProcessor: PostProcessor = null
51+
private var _frontendAccess: PostProcessorFrontendAccess = _
52+
def frontendAccess(using Context): PostProcessorFrontendAccess = {
53+
if _frontendAccess eq null then
54+
_frontendAccess = PostProcessorFrontendAccess.Impl(backendInterface)
55+
_frontendAccess
56+
}
57+
58+
private var _postProcessor: PostProcessor = _
10059
def postProcessor(using Context): PostProcessor = {
10160
if _postProcessor eq null then
10261
_postProcessor = new PostProcessor(frontendAccess, bTypes)
@@ -113,7 +72,7 @@ class GenBCode extends Phase { self =>
11372
postProcessor.postProcessAndSendToDisk()
11473
result
11574
finally
116-
outputDir match {
75+
frontendAccess.compilerSettings.outputDirectory match {
11776
case jar: JarArchive =>
11877
if (ctx.run.nn.suspendedUnits.nonEmpty)
11978
// If we close the jar the next run will not be able to write on the jar.

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,11 @@
11
package dotty.tools.backend.jvm
22

33
import scala.collection.mutable.ListBuffer
4-
import dotty.tools.dotc.util.NoSourcePosition
5-
import scala.tools.asm.ClassWriter
6-
import scala.tools.asm.tree.ClassNode
7-
import dotty.tools.dotc.report
8-
import dotty.tools.dotc.util.SourcePosition
9-
import dotty.tools.dotc.interfaces
4+
import dotty.tools.dotc.util.{SourcePosition, NoSourcePosition}
105
import dotty.tools.io.AbstractFile
11-
import scala.collection.mutable.Clearable
126
import dotty.tools.dotc.core.Contexts.*
13-
import scala.language.unsafeNulls
14-
15-
16-
import java.util.Optional
7+
import scala.tools.asm.ClassWriter
8+
import scala.tools.asm.tree.ClassNode
179

1810
/**
1911
* Implements late stages of the backend that don't depend on a Global instance, i.e.,
@@ -38,7 +30,7 @@ class PostProcessor(val frontendAccess: PostProcessorFrontendAccess, val bTypes:
3830
setInnerClasses(classNode)
3931
serializeClass(classNode)
4032
catch
41-
case e: java.lang.RuntimeException if e.getMessage != null && e.getMessage.contains("too large!") =>
33+
case e: java.lang.RuntimeException if e.getMessage != null && e.getMessage.nn.contains("too large!") =>
4234
backendReporting.error(
4335
s"Could not write class ${classNode.name} because it exceeds JVM code size limits. ${e.getMessage}",
4436
NoSourcePosition

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

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,15 @@ sealed abstract class PostProcessorFrontendAccess {
1919
def backendReporting: BackendReporting
2020
def getEntryPoints: List[String]
2121

22-
final val frontendLock: AnyRef = new Object()
22+
private val frontendLock: AnyRef = new Object()
2323
@inline final def frontendSynch[T](x: => T): T = frontendLock.synchronized(x)
2424
}
2525

2626
object PostProcessorFrontendAccess {
2727
sealed trait CompilerSettings {
2828
def debug: Boolean
29-
3029
def target: String // javaOutputVersion
3130

32-
3331
def dumpClassesDirectory: Option[String]
3432
def outputDirectory: AbstractFile
3533

@@ -43,7 +41,7 @@ object PostProcessorFrontendAccess {
4341

4442
class Impl[I <: DottyBackendInterface](val int: I) extends PostProcessorFrontendAccess {
4543
import int.given
46-
def compilerSettings: CompilerSettings = buildCompilerSettings()
44+
lazy val compilerSettings: CompilerSettings = buildCompilerSettings()
4745

4846
private def buildCompilerSettings(): CompilerSettings = new CompilerSettings {
4947
extension [T](s: dotty.tools.dotc.config.Settings.Setting[T])
@@ -52,21 +50,20 @@ object PostProcessorFrontendAccess {
5250
def s = ctx.settings
5351

5452
lazy val target =
55-
val releaseValue = Option(ctx.settings.javaOutputVersion.value).filter(_.nonEmpty)
56-
val targetValue = Option(ctx.settings.XuncheckedJavaOutputVersion.value).filter(_.nonEmpty)
57-
val defaultTarget = "8"
53+
val releaseValue = Option(s.javaOutputVersion.value).filter(_.nonEmpty)
54+
val targetValue = Option(s.XuncheckedJavaOutputVersion.value).filter(_.nonEmpty)
5855
(releaseValue, targetValue) match
5956
case (Some(release), None) => release
6057
case (None, Some(target)) => target
6158
case (Some(release), Some(_)) =>
62-
report.warning(s"The value of ${ctx.settings.XuncheckedJavaOutputVersion.name} was overridden by ${ctx.settings.javaOutputVersion.name}")
59+
report.warning(s"The value of ${s.XuncheckedJavaOutputVersion.name} was overridden by ${ctx.settings.javaOutputVersion.name}")
6360
release
6461
case (None, None) => "8" // least supported version by default
6562

66-
val debug: Boolean = ctx.debug
67-
val dumpClassesDirectory: Option[String] = s.Ydumpclasses.valueSetByUser
68-
val outputDirectory: AbstractFile = s.outputDir.value
69-
val mainClass: Option[String] = s.XmainClass.valueSetByUser
63+
lazy val debug: Boolean = ctx.debug
64+
lazy val dumpClassesDirectory: Option[String] = s.Ydumpclasses.valueSetByUser
65+
lazy val outputDirectory: AbstractFile = s.outputDir.value
66+
lazy val mainClass: Option[String] = s.XmainClass.valueSetByUser
7067
}
7168

7269
object backendReporting extends BackendReporting {

0 commit comments

Comments
 (0)