From d79bbf0800889f1f510459b56d3cf9b7d257d012 Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Thu, 16 May 2024 22:02:49 +0200 Subject: [PATCH 1/2] Revert "Revert "Regression: fix compilation performance on Windows"" This reverts commit c5659933ef58ddbb003ecc30694a9e3e77b20c57, which was sound, but originally reverted due to merge conflicts on main. --- compiler/src/dotty/tools/io/AbstractFile.scala | 6 ------ compiler/src/dotty/tools/io/NoAbstractFile.scala | 2 -- compiler/src/dotty/tools/io/PlainFile.scala | 13 ++----------- compiler/src/dotty/tools/io/VirtualDirectory.scala | 6 ------ compiler/src/dotty/tools/io/VirtualFile.scala | 6 ------ compiler/src/dotty/tools/io/ZipArchive.scala | 2 -- 6 files changed, 2 insertions(+), 33 deletions(-) diff --git a/compiler/src/dotty/tools/io/AbstractFile.scala b/compiler/src/dotty/tools/io/AbstractFile.scala index 233b1ca8fb62..ee72297c2a4f 100644 --- a/compiler/src/dotty/tools/io/AbstractFile.scala +++ b/compiler/src/dotty/tools/io/AbstractFile.scala @@ -136,12 +136,6 @@ abstract class AbstractFile extends Iterable[AbstractFile] { /** Does this abstract file represent something which can contain classfiles? */ def isClassContainer: Boolean = isDirectory || (jpath != null && ext.isJarOrZip) - /** Create a file on disk, if one does not exist already. */ - def create(): Unit - - /** Delete the underlying file or directory (recursively). */ - def delete(): Unit - /** Is this abstract file a directory? */ def isDirectory: Boolean diff --git a/compiler/src/dotty/tools/io/NoAbstractFile.scala b/compiler/src/dotty/tools/io/NoAbstractFile.scala index 13c2c6851d2b..bef045e290a5 100644 --- a/compiler/src/dotty/tools/io/NoAbstractFile.scala +++ b/compiler/src/dotty/tools/io/NoAbstractFile.scala @@ -17,8 +17,6 @@ import java.io.InputStream object NoAbstractFile extends AbstractFile { def absolute: AbstractFile = this def container: AbstractFile = this - def create(): Unit = ??? - def delete(): Unit = ??? def jpath: JPath = null def input: InputStream = null def isDirectory: Boolean = false diff --git a/compiler/src/dotty/tools/io/PlainFile.scala b/compiler/src/dotty/tools/io/PlainFile.scala index acef191d3072..a6a39d9ff3eb 100644 --- a/compiler/src/dotty/tools/io/PlainFile.scala +++ b/compiler/src/dotty/tools/io/PlainFile.scala @@ -13,9 +13,8 @@ import java.nio.file.{InvalidPathException, Paths} /** ''Note: This library is considered experimental and should not be used unless you know what you are doing.'' */ class PlainDirectory(givenPath: Directory) extends PlainFile(givenPath) { - override def isDirectory: Boolean = true + override val isDirectory: Boolean = true override def iterator(): Iterator[PlainFile] = givenPath.list.filter(_.exists).map(new PlainFile(_)) - override def delete(): Unit = givenPath.deleteRecursively() } /** This class implements an abstract file backed by a File. @@ -78,7 +77,7 @@ class PlainFile(val givenPath: Path) extends AbstractFile { } /** Is this abstract file a directory? */ - def isDirectory: Boolean = givenPath.isDirectory + val isDirectory: Boolean = givenPath.isDirectory // cached for performance on Windows /** Returns the time that this abstract file was last modified. */ def lastModified: Long = givenPath.lastModified.toMillis @@ -113,14 +112,6 @@ class PlainFile(val givenPath: Path) extends AbstractFile { null } - /** Does this abstract file denote an existing file? */ - def create(): Unit = if (!exists) givenPath.createFile() - - /** Delete the underlying file or directory (recursively). */ - def delete(): Unit = - if (givenPath.isFile) givenPath.delete() - else if (givenPath.isDirectory) givenPath.toDirectory.deleteRecursively() - /** Returns a plain file with the given name. It does not * check that it exists. */ diff --git a/compiler/src/dotty/tools/io/VirtualDirectory.scala b/compiler/src/dotty/tools/io/VirtualDirectory.scala index 157f63a2ac1a..949f2d0e61dd 100644 --- a/compiler/src/dotty/tools/io/VirtualDirectory.scala +++ b/compiler/src/dotty/tools/io/VirtualDirectory.scala @@ -34,12 +34,6 @@ extends AbstractFile { override def input: InputStream = sys.error("directories cannot be read") override def output: OutputStream = sys.error("directories cannot be written") - /** Does this abstract file denote an existing file? */ - def create(): Unit = { unsupported() } - - /** Delete the underlying file or directory (recursively). */ - def delete(): Unit = { unsupported() } - /** Returns an abstract file with the given name. It does not * check that it exists. */ diff --git a/compiler/src/dotty/tools/io/VirtualFile.scala b/compiler/src/dotty/tools/io/VirtualFile.scala index 9d290a9b0e6a..6fb9859503f2 100644 --- a/compiler/src/dotty/tools/io/VirtualFile.scala +++ b/compiler/src/dotty/tools/io/VirtualFile.scala @@ -82,12 +82,6 @@ class VirtualFile(val name: String, override val path: String) extends AbstractF Iterator.empty } - /** Does this abstract file denote an existing file? */ - def create(): Unit = unsupported() - - /** Delete the underlying file or directory (recursively). */ - def delete(): Unit = unsupported() - /** * Returns the abstract file in this abstract directory with the * specified name. If there is no such file, returns null. The diff --git a/compiler/src/dotty/tools/io/ZipArchive.scala b/compiler/src/dotty/tools/io/ZipArchive.scala index 9af935690ffc..a23bde8faaed 100644 --- a/compiler/src/dotty/tools/io/ZipArchive.scala +++ b/compiler/src/dotty/tools/io/ZipArchive.scala @@ -61,8 +61,6 @@ abstract class ZipArchive(override val jpath: JPath, release: Option[String]) ex def isDirectory: Boolean = true def lookupName(name: String, directory: Boolean): AbstractFile = unsupported() def lookupNameUnchecked(name: String, directory: Boolean): AbstractFile = unsupported() - def create(): Unit = unsupported() - def delete(): Unit = unsupported() def output: OutputStream = unsupported() def container: AbstractFile = unsupported() def absolute: AbstractFile = unsupported() From c6086f6724b64cfdaaa43071a3847b2dbab930c9 Mon Sep 17 00:00:00 2001 From: Jan Chyb Date: Thu, 16 May 2024 22:20:44 +0200 Subject: [PATCH 2/2] Replace removed `PlainFile.delete()` API method --- .../dotty/tools/dotc/core/tasty/BestEffortTastyWriter.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/tasty/BestEffortTastyWriter.scala b/compiler/src/dotty/tools/dotc/core/tasty/BestEffortTastyWriter.scala index 9cdfb042b8fb..13a6a274ed96 100644 --- a/compiler/src/dotty/tools/dotc/core/tasty/BestEffortTastyWriter.scala +++ b/compiler/src/dotty/tools/dotc/core/tasty/BestEffortTastyWriter.scala @@ -18,8 +18,8 @@ object BestEffortTastyWriter: unit.pickled.foreach { (clz, binary) => val parts = clz.fullName.mangledString.split('.') val outPath = outputPath(parts.toList, dir) - val outTastyFile = new PlainFile(new File(outPath)) - val outstream = new DataOutputStream(outTastyFile.bufferedOutput) + val outTastyFile = new File(outPath) + val outstream = new DataOutputStream(new PlainFile(outTastyFile).bufferedOutput) try outstream.write(binary()) catch case ex: ClosedByInterruptException => try