Rename SuccessOrFailure to Result and hide Failure from ABI
* The members of Result are isSuccess, isFailure, exceptionOrNull, getOrNull * The rest of API is implemented via inline-only extensions * There are two internal functions to hide detailed mechanics of an internal Result.Failure class: createFailure and throwOnFailure * Result.toString is explicit: either Success(v) or Failure(x) See KT-26538
This commit is contained in:
@@ -64,7 +64,7 @@ abstract class AbstractCoroutineCodegen(
|
||||
if (languageVersionSettings.isReleaseCoroutines())
|
||||
createImplMethod(
|
||||
INVOKE_SUSPEND_METHOD_NAME,
|
||||
"result" to classDescriptor.module.getSuccessOrFailure(classDescriptor.builtIns.anyType)
|
||||
"result" to classDescriptor.module.getResult(classDescriptor.builtIns.anyType)
|
||||
)
|
||||
else
|
||||
createImplMethod(
|
||||
|
||||
+3
-3
@@ -759,11 +759,11 @@ private fun InstructionAdapter.generateResumeWithExceptionCheck(isReleaseCorouti
|
||||
val noExceptionLabel = Label()
|
||||
|
||||
if (isReleaseCoroutines) {
|
||||
instanceOf(AsmTypes.SUCCESS_OR_FAILURE_FAILURE)
|
||||
instanceOf(AsmTypes.RESULT_FAILURE)
|
||||
ifeq(noExceptionLabel)
|
||||
// TODO: do we need this checkcast?
|
||||
checkcast(AsmTypes.SUCCESS_OR_FAILURE_FAILURE)
|
||||
getfield(AsmTypes.SUCCESS_OR_FAILURE_FAILURE.internalName, "exception", AsmTypes.JAVA_THROWABLE_TYPE.descriptor)
|
||||
checkcast(AsmTypes.RESULT_FAILURE)
|
||||
getfield(AsmTypes.RESULT_FAILURE.internalName, "exception", AsmTypes.JAVA_THROWABLE_TYPE.descriptor)
|
||||
} else {
|
||||
ifnull(noExceptionLabel)
|
||||
}
|
||||
|
||||
+3
-3
@@ -303,16 +303,16 @@ fun <D : FunctionDescriptor> D.createCustomCopy(
|
||||
private fun FunctionDescriptor.getContinuationParameterTypeOfSuspendFunction(isReleaseCoroutines: Boolean) =
|
||||
module.getContinuationOfTypeOrAny(returnType!!, if (this.needsExperimentalCoroutinesWrapper()) false else isReleaseCoroutines)
|
||||
|
||||
fun ModuleDescriptor.getSuccessOrFailure(kotlinType: KotlinType) =
|
||||
fun ModuleDescriptor.getResult(kotlinType: KotlinType) =
|
||||
module.resolveTopLevelClass(
|
||||
DescriptorUtils.SUCCESS_OR_FAILURE_FQ_NAME,
|
||||
DescriptorUtils.RESULT_FQ_NAME,
|
||||
NoLookupLocation.FROM_BACKEND
|
||||
)?.defaultType?.let {
|
||||
KotlinTypeFactory.simpleType(
|
||||
it,
|
||||
arguments = listOf(kotlinType.asTypeProjection())
|
||||
)
|
||||
} ?: ErrorUtils.createErrorType("For SuccessOrFailure")
|
||||
} ?: ErrorUtils.createErrorType("For Result")
|
||||
|
||||
private fun MethodNode.invokeNormalizeContinuation(languageVersionSettings: LanguageVersionSettings) {
|
||||
visitMethodInsn(
|
||||
|
||||
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.codegen.state
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.load.kotlin.getRepresentativeUpperBound
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.RESULT_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils.SUCCESS_OR_FAILURE_FQ_NAME
|
||||
import org.jetbrains.kotlin.resolve.InlineClassDescriptorResolver
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
@@ -50,7 +49,7 @@ private fun KotlinType.isInlineClassThatRequiresMangling() =
|
||||
isInlineClassType() && !isDontMangleClass(this.constructor.declarationDescriptor as ClassDescriptor)
|
||||
|
||||
private fun isDontMangleClass(classDescriptor: ClassDescriptor) =
|
||||
classDescriptor.fqNameSafe == SUCCESS_OR_FAILURE_FQ_NAME || classDescriptor.fqNameSafe == RESULT_FQ_NAME
|
||||
classDescriptor.fqNameSafe == RESULT_FQ_NAME
|
||||
|
||||
private fun KotlinType.isTypeParameterWithUpperBoundThatRequiresMangling(): Boolean {
|
||||
val descriptor = constructor.declarationDescriptor as? TypeParameterDescriptor ?: return false
|
||||
|
||||
Reference in New Issue
Block a user