8000 Merge pull request #2 from lrytz/pr5834 · scala/scala@af1c05a · GitHub
[go: up one dir, main page]

Skip to content

Commit af1c05a

Browse files
authored
Merge pull request #2 from lrytz/pr5834
Some formatting and minor cleanups
2 parents 3a0023a + c99553f commit af1c05a

File tree

4 files changed

+51
-77
lines changed

4 files changed

+51
-77
lines changed

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1579,20 +1579,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter)
15791579
}
15801580
}
15811581

1582-
def getFile(source: AbstractFile, segments: Array[String], suffix: String): File = {
1583-
val outDir = Path(
1584-
settings.outputDirs.outputDirFor(source).path match {
1585-
case "" => "."
1586-
case path => path
1587-
}
1588-
)
1589-
val dir = segments.init.foldLeft(outDir)(_ / _).createDirectory()
1590-
new File(dir.path, segments.last + suffix)
1591-
}
1592-
1593-
/** Returns the file with the given suffix for the given class. Used for icode writing. */
1594-
def getFile(clazz: Symbol, suffix: String): File = getFile(clazz.sourceFile, clazz.fullName split '.', suffix)
1595-
15961582
def createJavadoc = false
15971583
}
15981584

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,12 @@ abstract class BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
231231
val originalReporter = global.reporter
232232
val storeReporter = new reporters.StoreReporter()
233233
global.reporter = storeReporter
234-
try {
235-
sym.info
236-
} finally {
237-
global.reporter = originalReporter
238-
}
234+
try sym.info
235+
finally global.reporter = originalReporter
239236
sym.isErroneous
240237
}
241238

242-
var pickledBytes = 0 // statistics
239+
var pickledBytes = 0 // statistics
243240

244241
// -----------------------------------------------------------------------------------------
245242
// finding the least upper bound in agreement with the bytecode verifier (given two internal names handed by ASM)

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

Lines changed: 31 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -6,94 +6,85 @@
66
package scala.tools.nsc
77
package backend.jvm
88

9-
import java.io.{DataOutputStream, FileOutputStream, IOException, File => JFile}
9+
import java.io.{DataOutputStream, FileOutputStream, File => JFile}
1010
import java.nio.ByteBuffer
1111
import java.nio.file.{StandardOpenOption, Files => JNFiles, Path => JNPath}
12-
import java.nio.file.attribute.{FileAttribute => JNFileAttribute}
1312
import java.util
1413

1514
import scala.tools.nsc.io._
1615
import java.util.jar.Attributes.Name
1716
import scala.language.postfixOps
1817

1918
object OutputDirectories {
20-
21-
def apply(file:AbstractFile) :OutputDirectories = {
22-
require (file.isDirectory)
19+
def apply(file: AbstractFile): OutputDirectories = {
20+
require(file.isDirectory)
2321
if (file.file ne null) new PathDirInfo(file.file.toPath)
2422
else new AbstractFileDirInfo(file)
2523
}
2624

27-
private class PathDirInfo (val base:JNPath) extends OutputDirectories {
28-
//should be strict, when we fix duplicate file names
29-
val optsStrict = util.EnumSet.of(StandardOpenOption.CREATE_NEW, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)
30-
val optsLax = util.EnumSet.of(StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)
31-
val noAttr = Array[JNFileAttribute[_]]()
25+
private val openOpts = util.EnumSet.of(StandardOpenOption.CREATE, StandardOpenOption.WRITE, StandardOpenOption.TRUNCATE_EXISTING)
3226

33-
class PathFile(path:JNPath) extends OutputFile{
27+
private class PathDirInfo(base: JNPath) extends OutputDirectories {
28+
class PathFile(path: JNPath) extends OutputFile {
3429
override def writeFile(bytes: Array[Byte]): Unit = {
35-
36-
val channel = path.getFileSystem.provider.newByteChannel(path, optsLax, noAttr: _*)
30+
val channel = path.getFileSystem.provider.newByteChannel(path, openOpts)
3731
val bb = ByteBuffer.wrap(bytes)
38-
3932
try do channel.write(bb) while (bb.remaining() > 0)
4033
finally channel.close()
41-
4234
}
4335
}
44-
class PathDir(path:String) extends OutputDirectory{
36+
37+
class PathDir(path: String) extends OutputDirectory {
4538
private lazy val dir = JNFiles.createDirectories(base.resolve(path))
4639
override def file(name: String): OutputFile = new PathFile(dir.resolve(name))
4740
}
41+
4842
private val dirs = new collection.concurrent.TrieMap[String, PathDir]()
49-
def directory(path:String): OutputDirectory = {
43+
44+
def directory(path: String): OutputDirectory = {
5045
dirs.getOrElseUpdate(path, new PathDir(path))
5146
}
52-
lazy val root:OutputDirectory = new PathDir(".")
53-
val caseInsensitive = base.resolve("a") == base.resolve("A")
47+
48+
lazy val root: OutputDirectory = new PathDir(".")
5449
}
55-
private class AbstractFileDirInfo (val base:AbstractFile) extends OutputDirectories {
56-
private class SimpleFile(outfile:AbstractFile) extends OutputFile{
50+
51+
private class AbstractFileDirInfo(val base: AbstractFile) extends OutputDirectories {
52+
private class SimpleFile(outfile: AbstractFile) extends OutputFile {
5753
override def writeFile(bytes: Array[Byte]): Unit = {
5854
val outstream = outfile.output
5955
try outstream.write(bytes, 0, bytes.length)
6056
finally outstream.close()
6157
}
6258
}
63-
private class SimpleDir(file:AbstractFile) extends OutputDirectory {
59+
60+
private class SimpleDir(file: AbstractFile) extends OutputDirectory {
6461
override def file(name: String): OutputFile = new SimpleFile(file.fileNamed(name))
6562
}
66-
val root:OutputDirectory = new SimpleDir(base)
67-
def directory(path:String): OutputDirectory = {
63+
64+
def directory(path: String): OutputDirectory = {
6865
val file = path.split("/").foldLeft(base) {
6966
case (parentDir, child) => parentDir.subdirectoryNamed(child)
7067
}
7168
new SimpleDir(file)
7269
}
73-
val caseInsensitive = {
74-
if (base.file == null) false
75-
else {
76-
val path = base.file.toPath
77-
path.resolve("a") == path.resolve("A")
78-
}
79-
}
70+
71+
val root: OutputDirectory = new SimpleDir(base)
8072
}
8173
}
8274

8375
trait OutputDirectories {
84-
def directory(path:String): OutputDirectory
76+
def directory(path: String): OutputDirectory
8577
def root: OutputDirectory
86-
val caseInsensitive : Boolean
8778
}
79+
8880
trait OutputDirectory {
89-
def file(name:String):OutputFile
81+
def file(name: String): OutputFile
9082
}
83+
9184
trait OutputFile {
92-
def writeFile(bytes:Array[Byte])
85+
def writeFile(bytes: Array[Byte])
9386
}
9487

95-
96-
9788
/** For the last mile: turning generated bytecode in memory into
9889
* something you can use. Has implementations for writing to class
9990
* files, jars, and disassembled/javap output.
@@ -102,20 +93,17 @@ trait BytecodeWriters {
10293
val global: Global
10394
import global._
10495

105-
def outputDirectory(sym: Symbol): AbstractFile =
106-
settings.outputDirs outputDirFor enteringFlatten(sym.sourceFile)
107-
10896
/**
10997
* @param clsName cls.getName
11098
*/
111-
def getFile(known: OutputDirectories, clsName: String, suffix: String): OutputFile = {
99+
def getFile(outDirs: OutputDirectories, clsName: String, suffix: String): OutputFile = {
112100
val pathAndName = clsName.replace('.', '/')
113101
val split = pathAndName.lastIndexOf('/')
114-
if (split == -1) known.root.file(clsName + suffix)
102+
if (split == -1) outDirs.root.file(clsName + suffix)
115103
else {
116104
val dirPath = pathAndName.substring(0, split)
117105
val filename = pathAndName.substring(split + 1) + suffix
118-
known.directory(dirPath).file(filename)
106+
outDirs.directory(dirPath).file(filename)
119107
}
120108
}
121109

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

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import scala.collection.mutable
1515
import scala.reflect.internal.util.Statistics
1616
import scala.tools.asm
1717
import scala.tools.asm.tree.ClassNode
18-
import scala.tools.nsc.backend.jvm.opt.ByteCodeRepository
1918
import scala.tools.nsc.io.AbstractFile
2019

2120
/*
@@ -127,6 +126,7 @@ abstract class GenBCode extends BCodeSyncAndTry {
127126
* Pipeline that takes ClassDefs from queue-1, lowers them into an intermediate form, placing them on queue-2
128127
*/
129128
abstract class Worker1 {
129+
protected def getOutFolder(csym: Symbol, cName: String, cunit: CompilationUnit): OutputDirectories
130130

131131
val caseInsensitively = mutable.Map.empty[String, Symbol]
132132

@@ -147,7 +147,8 @@ abstract class GenBCode extends BCodeSyncAndTry {
147147
}
148148
}
149149
}
150-
protected def getOutFolder(csym: Symbol, cName: String, cunit: CompilationUnit): OutputDirectories /*
150+
151+
/*
151152
* Checks for duplicate internal names case-insensitively,
152153
* builds ASM ClassNodes for mirror, plain, and bean classes;
153154
* enqueues them in queue-2.
@@ -215,21 +216,27 @@ abstract class GenBCode extends BCodeSyncAndTry {
215216
} // end of method visit(Item1)
216217

217218
} // end of class BCodePhase.Worker1
218-
def newWorker1(needsOutputFile:Boolean): Worker1 = {
219-
if (!needsOutputFile)
220-
new SingleOutputWorker1(null)
219+
220+
def newWorker1(needsOutputFile: Boolean): Worker1 = {
221+
// Item2.outFolder will be `null` if `needsOutputFile` is false
222+
if (!needsOutputFile) new SingleOutputWorker1(null)
221223
else settings.outputDirs.getSingleOutput match {
222224
case Some(dir) =>
223-
new SingleOutputWorker1(OutputDirectories (dir))
224-
case _ => new MultiOutputWorker1()
225+
new SingleOutputWorker1(OutputDirectories(dir))
226+
case _ =>
227+
new MultiOutputWorker1()
225228 F438
}
226229
}
227-
class SingleOutputWorker1(val folder : OutputDirectories) extends Worker1 {
228230

231+
class SingleOutputWorker1(folder: OutputDirectories) extends Worker1 {
229232
override protected def getOutFolder(csym: global.Symbol, cName: String, cunit: global.CompilationUnit) = folder
230233
}
234+
231235
class MultiOutputWorker1() extends Worker1 {
232-
val knownDirectories = mutable.Map[AbstractFile, OutputDirectories]()
236+
private def outputDirectory(sym: Symbol): AbstractFile =
237+
settings.outputDirs outputDirFor enteringFlatten(sym.sourceFile)
238+
239+
private val knownDirectories = mutable.Map[AbstractFile, OutputDirectories]()
233240

234241
override protected def getOutFolder(csym: global.Symbol, cName: String, cunit: global.CompilationUnit): OutputDirectories =
235242
try {
@@ -402,8 +409,8 @@ abstract class GenBCode extends BCodeSyncAndTry {
402409
* (d) serialize to disk by draining queue-3.
403410
*/
404411
private def buildAndSendToDisk(needsOutFolder: Boolean) {
405-
406412
feedPipeline1()
413+
407414
val genStart = Statistics.startTimer(BackendStats.bcodeGenStat)
408415
newWorker1(needsOutFolder).run()
409416
Statistics.stopTimer(BackendStats.bcodeGenStat, genStart)
@@ -413,7 +420,6 @@ abstract class GenBCode extends BCodeSyncAndTry {
413420
val writeStart = Statistics.startTimer(BackendStats.bcodeWriteTimer)
414421
drainQ3()
415422
Statistics.stopTimer(BackendStats.bcodeWriteTimer, writeStart)
416-
417423
}
418424

419425
/* Feed pipeline-1: place all ClassDefs on q1, recording their arrival position. */
@@ -424,7 +430,6 @@ abstract class GenBCode extends BCodeSyncAndTry {
424430

425431
/* Pipeline that writes classfile representations to disk. */
426432
private def drainQ3() {
427-
428433
def sendToDisk(cfr: SubItem3, outFolder: OutputDirectories) {
429434
if (cfr != null){
430435
val SubItem3(jclassName, jclassBytes) = cfr
@@ -462,11 +467,9 @@ abstract class GenBCode extends BCodeSyncAndTry {
462467
assert(q1.isEmpty, s"Some ClassDefs remained in the first queue: $q1")
463468
assert(q2.isEmpty, s"Some classfiles remained in the second queue: $q2")
464469
assert(q3.isEmpty, s"Some classfiles weren't written to disk: $q3")
465-
466470
}
467471

468472
override def apply(cunit: CompilationUnit): Unit = {
469-
470473
def gen(tree: Tree) {
471474
tree match {
472475
case EmptyTree => ()

0 commit comments

Comments
 (0)
0