Reformat coroutineContext related code

This commit is contained in:
Ilmir Usmanov
2018-01-25 19:26:27 +03:00
parent 18c03f94f8
commit 8ffb205f1c
3 changed files with 181 additions and 179 deletions
@@ -65,7 +65,8 @@ val COROUTINES_JVM_INTERNAL_PACKAGE_FQ_NAME =
val CONTINUATION_ASM_TYPE = DescriptorUtils.CONTINUATION_INTERFACE_FQ_NAME.topLevelClassAsmType() val CONTINUATION_ASM_TYPE = DescriptorUtils.CONTINUATION_INTERFACE_FQ_NAME.topLevelClassAsmType()
@JvmField @JvmField
val COROUTINE_CONTEXT_ASM_TYPE = DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME.child(Name.identifier("CoroutineContext")).topLevelClassAsmType() val COROUTINE_CONTEXT_ASM_TYPE =
DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME.child(Name.identifier("CoroutineContext")).topLevelClassAsmType()
@JvmField @JvmField
val COROUTINE_IMPL_ASM_TYPE = COROUTINES_JVM_INTERNAL_PACKAGE_FQ_NAME.child(Name.identifier("CoroutineImpl")).topLevelClassAsmType() val COROUTINE_IMPL_ASM_TYPE = COROUTINES_JVM_INTERNAL_PACKAGE_FQ_NAME.child(Name.identifier("CoroutineImpl")).topLevelClassAsmType()
@@ -128,7 +129,8 @@ fun ResolvedCall<*>.replaceSuspensionFunctionWithRealDescriptor(
newCandidateDescriptor, newCandidateDescriptor,
dispatchReceiver, extensionReceiver, explicitReceiverKind, dispatchReceiver, extensionReceiver, explicitReceiverKind,
null, DelegatingBindingTrace(BindingTraceContext().bindingContext, "Temporary trace for unwrapped suspension function"), null, DelegatingBindingTrace(BindingTraceContext().bindingContext, "Temporary trace for unwrapped suspension function"),
TracingStrategy.EMPTY, MutableDataFlowInfoForArguments.WithoutArgumentsCheck(DataFlowInfo.EMPTY)) TracingStrategy.EMPTY, MutableDataFlowInfoForArguments.WithoutArgumentsCheck(DataFlowInfo.EMPTY)
)
this.valueArguments.forEach { this.valueArguments.forEach {
newCall.recordValueArgument(newCandidateDescriptor.valueParameters[it.key.index], it.value) newCall.recordValueArgument(newCandidateDescriptor.valueParameters[it.key.index], it.value)
@@ -139,14 +141,16 @@ fun ResolvedCall<*>.replaceSuspensionFunctionWithRealDescriptor(
val thisExpression = arguments.getArgumentExpression()!! val thisExpression = arguments.getArgumentExpression()!!
newCall.recordValueArgument( newCall.recordValueArgument(
newCandidateDescriptor.valueParameters.last(), newCandidateDescriptor.valueParameters.last(),
ExpressionValueArgument(arguments)) ExpressionValueArgument(arguments)
)
val newTypeArguments = newCandidateDescriptor.typeParameters.map { val newTypeArguments = newCandidateDescriptor.typeParameters.map {
Pair(it, typeArguments[candidateDescriptor.typeParameters[it.index]]!!.asTypeProjection()) Pair(it, typeArguments[candidateDescriptor.typeParameters[it.index]]!!.asTypeProjection())
}.toMap() }.toMap()
newCall.setResultingSubstitutor( newCall.setResultingSubstitutor(
TypeConstructorSubstitution.createByParametersMap(newTypeArguments).buildSubstitutor()) TypeConstructorSubstitution.createByParametersMap(newTypeArguments).buildSubstitutor()
)
return ResolvedCallWithRealDescriptor(newCall, thisExpression) return ResolvedCallWithRealDescriptor(newCall, thisExpression)
} }
@@ -53,8 +53,7 @@ fun generateDelegateCall(
fun FunctionDescriptor.getNameForFunctionWithPossibleDefaultParam() = fun FunctionDescriptor.getNameForFunctionWithPossibleDefaultParam() =
if (detectDefaultParameters && hasOrInheritsParametersWithDefaultValue()) { if (detectDefaultParameters && hasOrInheritsParametersWithDefaultValue()) {
context.scope().declareName(context.getNameForDescriptor(this).ident + Namer.DEFAULT_PARAMETER_IMPLEMENTOR_SUFFIX) context.scope().declareName(context.getNameForDescriptor(this).ident + Namer.DEFAULT_PARAMETER_IMPLEMENTOR_SUFFIX)
} } else {
else {
context.getNameForDescriptor(this) context.getNameForDescriptor(this)
} }
@@ -80,8 +79,7 @@ fun generateDelegateCall(
val intrinsic = context.intrinsics().getFunctionIntrinsic(toDescriptor) val intrinsic = context.intrinsics().getFunctionIntrinsic(toDescriptor)
val invocation = if (intrinsic.exists() && intrinsic is FunctionIntrinsicWithReceiverComputed) { val invocation = if (intrinsic.exists() && intrinsic is FunctionIntrinsicWithReceiverComputed) {
intrinsic.apply(thisObject, args, context) intrinsic.apply(thisObject, args, context)
} } else {
else {
JsInvocation(overriddenMemberFunctionRef, args) JsInvocation(overriddenMemberFunctionRef, args)
} }
@@ -130,8 +128,8 @@ fun getReferenceToJsClass(type: KotlinType, context: TranslationContext): JsExpr
context.usageTracker()?.used(classifierDescriptor) context.usageTracker()?.used(classifierDescriptor)
context.captureTypeIfNeedAndGetCapturedName(classifierDescriptor) ?: context.captureTypeIfNeedAndGetCapturedName(classifierDescriptor)
context.getNameForDescriptor(classifierDescriptor).makeRef() ?: context.getNameForDescriptor(classifierDescriptor).makeRef()
} }
else -> { else -> {
throw IllegalStateException("Can't get reference for $type") throw IllegalStateException("Can't get reference for $type")