Skip to content

Commit

Permalink
Fix cancelation of Kotlin frontend.
Browse files Browse the repository at this point in the history
It looks like throwing our own exception causes Kotlin to wrap with its own and propagate like a failure. CL changes the mechanism to throw CompilationCanceledException which is properly handled by kotlinc and so it gracefully exits.

We didn't catch this earlier since existing tests are only testing the delay and prevent any exception to be thrown. I have some tests in the working so this might be partially covered by tests (though it is very difficult to fully repro this kind of problems in the integration tests).

PiperOrigin-RevId: 729227621
  • Loading branch information
gkdn authored and copybara-github committed Feb 20, 2025
1 parent a5ff87a commit 6c5c03c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion transpiler/java/com/google/j2cl/common/Problems.java
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public void abortIfCancelled() {
}
}

protected boolean isCancelled() {
public boolean isCancelled() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmMetadataVersion
import org.jetbrains.kotlin.metadata.jvm.deserialization.JvmProtoBufUtil
import org.jetbrains.kotlin.modules.TargetId
import org.jetbrains.kotlin.progress.CompilationCanceledException
import org.jetbrains.kotlin.progress.CompilationCanceledStatus
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus

Expand All @@ -102,7 +103,9 @@ class KotlinParser(private val problems: Problems) {
ProgressIndicatorAndCompilationCanceledStatus.setCompilationCanceledStatus(
object : CompilationCanceledStatus {
override fun checkCanceled() {
problems.abortIfCancelled()
// throw CompilationCanceledException instead of our own which is properly handled by
// kotlinc to gracefully exit from the compilation.
if (problems.isCancelled) throw CompilationCanceledException()
}
}
)
Expand Down

0 comments on commit 6c5c03c

Please sign in to comment.