Skip to content

Commit 240a864

Browse files
authored
Merge pull request #9429 from dotty-staging/better-ctrl-c
Better handling of ctrl-c while the compiler is running
2 parents 8d5f56f + b8c1799 commit 240a864

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package backend
33
package jvm
44

55
import java.io.{ DataOutputStream, FileOutputStream, IOException, OutputStream, File => JFile }
6+
import java.nio.channels.ClosedByInterruptException
7+
import java.nio.file.Files
68
import dotty.tools.io._
79
import dotty.tools.dotc.report
810

@@ -112,6 +114,11 @@ trait BytecodeWriters {
112114
val outstream = new DataOutputStream(outfile.bufferedOutput)
113115

114116
try outstream.write(jclassBytes, 0, jclassBytes.length)
117+
catch case ex: ClosedByInterruptException =>
118+
try
119+
outfile.delete() // don't leave an empty or half-written classfile around after an interrupt
120+
catch case _: Throwable =>
121+
throw ex
115122
finally outstream.close()
116123
report.informProgress("wrote '" + label + "' to " + outfile)
117124
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import Symbols._
2222
import Decorators._
2323

2424
import java.io.DataOutputStream
25+
import java.nio.channels.ClosedByInterruptException
2526

2627
import dotty.tools.tasty.{ TastyBuffer, TastyHeaderUnpickler }
2728

@@ -190,6 +191,8 @@ class GenBCodePipeline(val int: DottyBackendInterface)(using Context) extends BC
190191
else {
191192
try { /*withCurrentUnit(item.cunit)*/(visit(item)) }
192193
catch {
194+
case ex: InterruptedException =>
195+
throw ex
193196
case ex: Throwable =>
194197
println(s"Error while emitting ${item.cunit.source.file.name}")
195198
throw ex
@@ -233,6 +236,11 @@ class GenBCodePipeline(val int: DottyBackendInterface)(using Context) extends BC
233236
val outTastyFile = getFileForClassfile(outF, store.name, ".tasty")
234237
val outstream = new DataOutputStream(outTastyFile.bufferedOutput)
235238
try outstream.write(binary)
239+
catch case ex: ClosedByInterruptException =>
240+
try
241+
outTastyFile.delete() // don't leave an empty or half-written tastyfile around after an interrupt
242+
catch case _: Throwable =>
243+
throw ex
236244
finally outstream.close()
237245

238246
val uuid = new TastyHeaderUnpickler(binary).readHeader()
@@ -424,6 +432,8 @@ class GenBCodePipeline(val int: DottyBackendInterface)(using Context) extends BC
424432
addLambdaDeserialize(plainNode, serializableLambdas)
425433
addToQ3(item)
426434
} catch {
435+
case ex: InterruptedException =>
436+
throw ex
427437
case ex: Throwable =>
428438
println(s"Error while emitting ${item.plain.classNode.name}")
429439
throw ex

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package dotc
33
package core
44

55
import java.io.{IOException, File}
6+
import java.nio.channels.ClosedByInterruptException
67
import scala.compat.Platform.currentTime
78
import dotty.tools.io.{ ClassPath, ClassRepresentation, AbstractFile }
89
import config.Config
@@ -343,6 +344,10 @@ abstract class SymbolLoader extends LazyType { self =>
343344
report.informTime("loaded " + description, start)
344345
}
345346
catch {
347+
case ex: InterruptedException =>
348+
throw ex
349+
case ex: ClosedByInterruptException =>
350+
throw new InterruptedException
346351
case ex: IOException =>
347352
signalError(ex)
348353
case NonFatal(ex: TypeError) =>

0 commit comments

Comments
 (0)