Skip to content

Better handling of ctrl-c while the compiler is running #9429

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compiler/src/dotty/tools/backend/jvm/BytecodeWriters.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package backend
package jvm

import java.io.{ DataOutputStream, FileOutputStream, IOException, OutputStream, File => JFile }
import java.nio.channels.ClosedByInterruptException
import java.nio.file.Files
import dotty.tools.io._
import dotty.tools.dotc.report

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

try outstream.write(jclassBytes, 0, jclassBytes.length)
catch case ex: ClosedByInterruptException =>
try
outfile.delete() // don't leave an empty or half-written classfile around after an interrupt
catch case _: Throwable =>
throw ex
finally outstream.close()
report.informProgress("wrote '" + label + "' to " + outfile)
}
Expand Down
10 changes: 10 additions & 0 deletions compiler/src/dotty/tools/backend/jvm/GenBCode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import Symbols._
import Decorators._

import java.io.DataOutputStream
import java.nio.channels.ClosedByInterruptException

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

Expand Down Expand Up @@ -190,6 +191,8 @@ class GenBCodePipeline(val int: DottyBackendInterface)(using Context) extends BC
else {
try { /*withCurrentUnit(item.cunit)*/(visit(item)) }
catch {
case ex: InterruptedException =>
throw ex
case ex: Throwable =>
println(s"Error while emitting ${item.cunit.source.file.name}")
throw ex
Expand Down Expand Up @@ -233,6 +236,11 @@ class GenBCodePipeline(val int: DottyBackendInterface)(using Context) extends BC
val outTastyFile = getFileForClassfile(outF, store.name, ".tasty")
val outstream = new DataOutputStream(outTastyFile.bufferedOutput)
try outstream.write(binary)
catch case ex: ClosedByInterruptException =>
try
outTastyFile.delete() // don't leave an empty or half-written tastyfile around after an interrupt
catch case _: Throwable =>
throw ex
finally outstream.close()

val uuid = new TastyHeaderUnpickler(binary).readHeader()
Expand Down Expand Up @@ -424,6 +432,8 @@ class GenBCodePipeline(val int: DottyBackendInterface)(using Context) extends BC
addLambdaDeserialize(plainNode, serializableLambdas)
addToQ3(item)
} catch {
case ex: InterruptedException =>
throw ex
case ex: Throwable =>
println(s"Error while emitting ${item.plain.classNode.name}")
throw ex
Expand Down
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/core/SymbolLoaders.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package dotc
package core

import java.io.{IOException, File}
import java.nio.channels.ClosedByInterruptException
import scala.compat.Platform.currentTime
import dotty.tools.io.{ ClassPath, ClassRepresentation, AbstractFile }
import config.Config
Expand Down Expand Up @@ -343,6 +344,10 @@ abstract class SymbolLoader extends LazyType { self =>
report.informTime("loaded " + description, start)
}
catch {
case ex: InterruptedException =>
throw ex
case ex: ClosedByInterruptException =>
throw new InterruptedException
case ex: IOException =>
signalError(ex)
case NonFatal(ex: TypeError) =>
Expand Down