Skip to content

Commit dffeda7

Browse files
authored
Fix main: revert "Regression: fix compilation performance on Windows" (#20355)
Reverts #20193 Cartoonishly failed right after I checked every other project for the existence of `create` and `delete` methods... except the compiler itself, where I personally added those a few weeks ago. I will remove those for the next release, so we can re-merge this performance PR.
2 parents 44c1e3a + c565993 commit dffeda7

File tree

6 files changed

+33
-2
lines changed

6 files changed

+33
-2
lines changed

compiler/src/dotty/tools/io/AbstractFile.scala

+6
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,12 @@ abstract class AbstractFile extends Iterable[AbstractFile] {
136136
/** Does this abstract file represent something which can contain classfiles? */
137137
def isClassContainer: Boolean = isDirectory || (jpath != null && ext.isJarOrZip)
138138

139+
/** Create a file on disk, if one does not exist already. */
140+
def create(): Unit
141+
142+
/** Delete the underlying file or directory (recursively). */
143+
def delete(): Unit
144+
139145
/** Is this abstract file a directory? */
140146
def isDirectory: Boolean
141147

compiler/src/dotty/tools/io/NoAbstractFile.scala

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import java.io.InputStream
1717
object NoAbstractFile extends AbstractFile {
1818
def absolute: AbstractFile = this
1919
def container: AbstractFile = this
20+
def create(): Unit = ???
21+
def delete(): Unit = ???
2022
def jpath: JPath = null
2123
def input: InputStream = null
2224
def isDirectory: Boolean = false

compiler/src/dotty/tools/io/PlainFile.scala

+11-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import java.nio.file.{InvalidPathException, Paths}
1313

1414
/** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */
1515
class PlainDirectory(givenPath: Directory) extends PlainFile(givenPath) {
16-
override val isDirectory: Boolean = true
16+
override def isDirectory: Boolean = true
1717
override def iterator(): Iterator[PlainFile] = givenPath.list.filter(_.exists).map(new PlainFile(_))
18+
override def delete(): Unit = givenPath.deleteRecursively()
1819
}
1920

2021
/** This class implements an abstract file backed by a File.
@@ -77,7 +78,7 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
7778
}
7879

7980
/** Is this abstract file a directory? */
80-
val isDirectory: Boolean = givenPath.isDirectory // cached for performance on Windows
81+
def isDirectory: Boolean = givenPath.isDirectory
8182

8283
/** Returns the time that this abstract file was last modified. */
8384
def lastModified: Long = givenPath.lastModified.toMillis
@@ -112,6 +113,14 @@ class PlainFile(val givenPath: Path) extends AbstractFile {
112113
null
113114
}
114115

116+
/** Does this abstract file denote an existing file? */
117+
def create(): Unit = if (!exists) givenPath.createFile()
118+
119+
/** Delete the underlying file or directory (recursively). */
120+
def delete(): Unit =
121+
if (givenPath.isFile) givenPath.delete()
122+
else if (givenPath.isDirectory) givenPath.toDirectory.deleteRecursively()
123+
115124
/** Returns a plain file with the given name. It does not
116125
* check that it exists.
117126
*/

compiler/src/dotty/tools/io/VirtualDirectory.scala

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ extends AbstractFile {
3434
override def input: InputStream = sys.error("directories cannot be read")
3535
override def output: OutputStream = sys.error("directories cannot be written")
3636

37+
/** Does this abstract file denote an existing file? */
38+
def create(): Unit = { unsupported() }
39+
40+
/** Delete the underlying file or directory (recursively). */
41+
def delete(): Unit = { unsupported() }
42+
3743
/** Returns an abstract file with the given name. It does not
3844
* check that it exists.
3945
*/

compiler/src/dotty/tools/io/VirtualFile.scala

+6
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,12 @@ class VirtualFile(val name: String, override val path: String) extends AbstractF
8282
Iterator.empty
8383
}
8484

85+
/** Does this abstract file denote an existing file? */
86+
def create(): Unit = unsupported()
87+
88+
/** Delete the underlying file or directory (recursively). */
89+
def delete(): Unit = unsupported()
90+
8591
/**
8692
* Returns the abstract file in this abstract directory with the
8793
* specified name. If there is no such file, returns null. The

compiler/src/dotty/tools/io/ZipArchive.scala

+2
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ abstract class ZipArchive(override val jpath: JPath, release: Option[String]) ex
6161
def isDirectory: Boolean = true
6262
def lookupName(name: String, directory: Boolean): AbstractFile = unsupported()
6363
def lookupNameUnchecked(name: String, directory: Boolean): AbstractFile = unsupported()
64+
def create(): Unit = unsupported()
65+
def delete(): Unit = unsupported()
6466
def output: OutputStream = unsupported()
6567
def container: AbstractFile = unsupported()
6668
def absolute: AbstractFile = unsupported()

0 commit comments

Comments
 (0)