Generate call of throwOnFailure instead of manual check
whether coroutine is resumed with exception. #KT-28015 Fixed
This commit is contained in:
+9
-12
@@ -828,23 +828,20 @@ internal fun InstructionAdapter.generateContinuationConstructorCall(
|
|||||||
|
|
||||||
private fun InstructionAdapter.generateResumeWithExceptionCheck(isReleaseCoroutines: Boolean, dataIndex: Int, exceptionIndex: Int) {
|
private fun InstructionAdapter.generateResumeWithExceptionCheck(isReleaseCoroutines: Boolean, dataIndex: Int, exceptionIndex: Int) {
|
||||||
// Check if resumeWithException has been called
|
// Check if resumeWithException has been called
|
||||||
load(if (isReleaseCoroutines) dataIndex else exceptionIndex, AsmTypes.OBJECT_TYPE)
|
|
||||||
dup()
|
|
||||||
val noExceptionLabel = Label()
|
|
||||||
|
|
||||||
if (isReleaseCoroutines) {
|
if (isReleaseCoroutines) {
|
||||||
instanceOf(AsmTypes.RESULT_FAILURE)
|
load(dataIndex, AsmTypes.OBJECT_TYPE)
|
||||||
ifeq(noExceptionLabel)
|
invokestatic("kotlin/ResultKt", "throwOnFailure", "(Ljava/lang/Object;)V", false)
|
||||||
// TODO: do we need this checkcast?
|
|
||||||
checkcast(AsmTypes.RESULT_FAILURE)
|
|
||||||
getfield(AsmTypes.RESULT_FAILURE.internalName, "exception", AsmTypes.JAVA_THROWABLE_TYPE.descriptor)
|
|
||||||
} else {
|
} else {
|
||||||
|
load(exceptionIndex, AsmTypes.OBJECT_TYPE)
|
||||||
|
dup()
|
||||||
|
val noExceptionLabel = Label()
|
||||||
ifnull(noExceptionLabel)
|
ifnull(noExceptionLabel)
|
||||||
}
|
athrow()
|
||||||
athrow()
|
|
||||||
|
|
||||||
mark(noExceptionLabel)
|
mark(noExceptionLabel)
|
||||||
pop()
|
pop()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun Type.fieldNameForVar(index: Int) = descriptor.first() + "$" + index
|
private fun Type.fieldNameForVar(index: Int) = descriptor.first() + "$" + index
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
// IGNORE_BACKEND: JVM_IR
|
||||||
|
// WITH_COROUTINES
|
||||||
|
// TREAT_AS_ONE_FILE
|
||||||
|
|
||||||
|
suspend fun foo() {}
|
||||||
|
|
||||||
|
suspend fun bar(): Int {
|
||||||
|
foo()
|
||||||
|
return 42
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2 INVOKESTATIC kotlin/ResultKt.throwOnFailure \(Ljava/lang/Object;\)V
|
||||||
@@ -1125,6 +1125,11 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/bytecodeText/coroutines/returnUnitInLambda.kt", "kotlin.coroutines");
|
runTestWithPackageReplacement("compiler/testData/codegen/bytecodeText/coroutines/returnUnitInLambda.kt", "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("throwOnFailure.kt")
|
||||||
|
public void testThrowOnFailure() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/bytecodeText/coroutines/throwOnFailure.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("varValueConflictsWithTable.kt")
|
@TestMetadata("varValueConflictsWithTable.kt")
|
||||||
public void testVarValueConflictsWithTable() throws Exception {
|
public void testVarValueConflictsWithTable() throws Exception {
|
||||||
runTest("compiler/testData/codegen/bytecodeText/coroutines/varValueConflictsWithTable.kt");
|
runTest("compiler/testData/codegen/bytecodeText/coroutines/varValueConflictsWithTable.kt");
|
||||||
|
|||||||
+5
@@ -1125,6 +1125,11 @@ public class IrBytecodeTextTestGenerated extends AbstractIrBytecodeTextTest {
|
|||||||
runTestWithPackageReplacement("compiler/testData/codegen/bytecodeText/coroutines/returnUnitInLambda.kt", "kotlin.coroutines");
|
runTestWithPackageReplacement("compiler/testData/codegen/bytecodeText/coroutines/returnUnitInLambda.kt", "kotlin.coroutines");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("throwOnFailure.kt")
|
||||||
|
public void testThrowOnFailure() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/bytecodeText/coroutines/throwOnFailure.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("varValueConflictsWithTable.kt")
|
@TestMetadata("varValueConflictsWithTable.kt")
|
||||||
public void testVarValueConflictsWithTable() throws Exception {
|
public void testVarValueConflictsWithTable() throws Exception {
|
||||||
runTest("compiler/testData/codegen/bytecodeText/coroutines/varValueConflictsWithTable.kt");
|
runTest("compiler/testData/codegen/bytecodeText/coroutines/varValueConflictsWithTable.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user