Skip to content

Commit 1d8844e

Browse files
committed
1 parent 94a2046 commit 1d8844e

File tree

7 files changed

+30
-27
lines changed

7 files changed

+30
-27
lines changed

kmp-nativecoroutines-compiler/src/main/kotlin/com/rickclephas/kmp/nativecoroutines/compiler/ir/codegen/CoroutineScope.kt

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ internal fun IrBuilderWithScope.irCallCoroutineScope(
2323
?: return irCallViewModelScope(declaration, viewModelClass)
2424
?: irNull(context.coroutineScopeSymbol.defaultType.makeNullable())
2525
val getter = property.getter ?: error("CoroutineScope property doesn't have a getter")
26-
if (getter.extensionReceiverParameter != null) {
27-
error("CoroutineScope property shouldn't have an extension receiver")
26+
if (getter.parameters.any { it.kind != IrParameterKind.DispatchReceiver }) {
27+
error("CoroutineScope property shouldn't have parameters other than dispatch")
2828
}
2929
return irCall(getter).apply {
30-
if (getter.dispatchReceiverParameter != null) {
31-
dispatchReceiver = irGet(declaration.dispatchOrExtensionReceiverParameter)
30+
if (getter.parameters.firstOrNull()?.kind == IrParameterKind.DispatchReceiver) {
31+
arguments[0] = irGet(declaration.dispatchOrExtensionReceiverParameter)
3232
}
3333
}
3434
}
@@ -41,7 +41,7 @@ private fun IrSimpleFunction.getCoroutineScopeProperty(classPropertyOnly: Boolea
4141
if (classPropertyOnly) return null
4242
fileOrNull?.getCoroutineScopeProperty(true)?.let { return it }
4343
if (parentClass != null) return null
44-
val extensionClass = extensionReceiverParameter?.type?.getClass()
44+
val extensionClass = parameters.firstOrNull { it.kind == IrParameterKind.ExtensionReceiver }?.type?.getClass()
4545
val extensionClassProperty = extensionClass?.getCoroutineScopeProperty(false)
4646
if (extensionClassProperty != null) return extensionClassProperty
4747
return null
@@ -65,12 +65,14 @@ private fun IrDeclarationWithVisibility.isVisible(
6565
}
6666

6767
private val IrSimpleFunction.dispatchOrExtensionReceiverParameter: IrValueParameter
68-
get() = dispatchReceiverParameter ?: extensionReceiverParameter ?: error("Missing dispatch receiver parameter")
68+
get() = parameters.firstOrNull {
69+
it.kind == IrParameterKind.DispatchReceiver || it.kind == IrParameterKind.ExtensionReceiver
70+
} ?: error("Missing dispatch receiver parameter")
6971

7072
@UnsafeDuringIrConstructionAPI
7173
private fun GeneratorContext.getViewModelClass(declaration: IrSimpleFunction): IrClass? {
7274
val parentClass = declaration.parentClassOrNull
73-
?: declaration.extensionReceiverParameter?.type?.getClass()
75+
?: declaration.parameters.firstOrNull { it.kind == IrParameterKind.ExtensionReceiver }?.type?.getClass()
7476
?: return null
7577
val viewModelSymbols = listOf(observableViewModelSymbol, androidxViewModelSymbol)
7678
for (viewModelSymbol in viewModelSymbols) {
@@ -99,8 +101,8 @@ private fun IrBuilderWithScope.irCallObservableViewModelScope(declaration: IrSim
99101
error("Failed to find viewModelScope.coroutineScope getters")
100102
}
101103
return irCall(coroutineScopeGetter).apply {
102-
extensionReceiver = irCall(viewModelScopeGetter).apply {
103-
dispatchReceiver = irGet(declaration.dispatchOrExtensionReceiverParameter)
104+
arguments[0] = irCall(viewModelScopeGetter).apply {
105+
arguments[0] = irGet(declaration.dispatchOrExtensionReceiverParameter)
104106
}
105107
}
106108
}
@@ -111,6 +113,6 @@ private fun IrBuilderWithScope.irCallAndroidXViewModelScope(declaration: IrSimpl
111113
val viewModelScopeGetter = context.androidxViewModelScopeSymbol?.owner?.getter
112114
?: error("Failed to find viewModelScope getter")
113115
return irCall(viewModelScopeGetter).apply {
114-
extensionReceiver = irGet(declaration.dispatchOrExtensionReceiverParameter)
116+
arguments[0] = irGet(declaration.dispatchOrExtensionReceiverParameter)
115117
}
116118
}

kmp-nativecoroutines-compiler/src/main/kotlin/com/rickclephas/kmp/nativecoroutines/compiler/ir/codegen/NativeFlow.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ internal fun IrBuilderWithScope.irCallAsNativeFlow(
2626
return IrBlockBodyExpression(returnType) {
2727
val flow = irTemporary(irGet(flowExpression))
2828
var expression: IrExpression = irCall(context.asNativeFlowSymbol, nativeFlowType).apply {
29-
putTypeArgument(0, valueTypeArg.typeOrFail)
30-
extensionReceiver = irGet(flow)
31-
putValueArgument(0, irGet(coroutineScope))
29+
typeArguments[0] = valueTypeArg.typeOrFail
30+
arguments[0] = irGet(flow)
31+
arguments[1] = irGet(coroutineScope)
3232
}
3333
if (flowType.isNullable()) {
3434
expression = irIfNull(returnType, irGet(flow), irNull(returnType), expression)

kmp-nativecoroutines-compiler/src/main/kotlin/com/rickclephas/kmp/nativecoroutines/compiler/ir/codegen/NativeSuspend.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ internal fun IrBuilderWithScope.irCallNativeSuspend(
1919
val context = context as GeneratorContext
2020
val expressionType = blockExpression.type as IrSimpleType
2121
val lambdaType = context.nativeSuspendSymbol.owner.run {
22-
valueParameters[1].type.substitute(typeParameters, listOf(expressionType))
22+
parameters[1].type.substitute(typeParameters, listOf(expressionType))
2323
}
2424
val returnType = context.nativeSuspendSymbol.owner.run {
2525
returnType.substitute(typeParameters, listOf(expressionType))
@@ -29,9 +29,9 @@ internal fun IrBuilderWithScope.irCallNativeSuspend(
2929
+irReturn(irGet(blockExpression))
3030
}
3131
irCall(context.nativeSuspendSymbol, returnType).apply {
32-
putTypeArgument(0, expressionType)
33-
putValueArgument(0, irGet(coroutineScope))
34-
putValueArgument(1, lambda)
32+
typeArguments[0] = expressionType
33+
arguments[0] = irGet(coroutineScope)
34+
arguments[1] = lambda
3535
}
3636
}
3737
}

kmp-nativecoroutines-compiler/src/main/kotlin/com/rickclephas/kmp/nativecoroutines/compiler/ir/codegen/OriginalFunction.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,9 @@ internal fun irCallOriginalFunction(
1111
function: IrSimpleFunction
1212
) = IrBlockBodyExpression(originalFunction.returnType) {
1313
irCall(originalFunction).apply {
14-
dispatchReceiver = function.dispatchReceiverParameter?.let { irGet(it) }
15-
extensionReceiver = function.extensionReceiverParameter?.let { irGet(it) }
1614
passTypeArgumentsFrom(function)
17-
function.valueParameters.forEachIndexed { index, parameter ->
18-
putValueArgument(index, irGet(parameter))
15+
function.parameters.forEachIndexed { index, parameter ->
16+
arguments[index] = irGet(parameter)
1917
}
2018
}
2119
}

kmp-nativecoroutines-compiler/src/main/kotlin/com/rickclephas/kmp/nativecoroutines/compiler/ir/codegen/OriginalProperty.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.rickclephas.kmp.nativecoroutines.compiler.ir.codegen
33
import com.rickclephas.kmp.nativecoroutines.compiler.ir.utils.IrBlockBodyExpression
44
import org.jetbrains.kotlin.ir.builders.irCall
55
import org.jetbrains.kotlin.ir.builders.irGet
6+
import org.jetbrains.kotlin.ir.declarations.IrParameterKind
67
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
78
import org.jetbrains.kotlin.ir.util.passTypeArgumentsFrom
89

@@ -11,8 +12,9 @@ internal fun irCallOriginalPropertyGetter(
1112
propertyFunction: IrSimpleFunction
1213
): IrBlockBodyExpression = IrBlockBodyExpression(originalGetter.returnType) {
1314
irCall(originalGetter).apply {
14-
dispatchReceiver = propertyFunction.dispatchReceiverParameter?.let { irGet(it) }
15-
extensionReceiver = propertyFunction.extensionReceiverParameter?.let { irGet(it) }
15+
propertyFunction.parameters.filter { it.kind != IrParameterKind.Regular }.forEachIndexed { index, parameter ->
16+
arguments[index] = irGet(parameter)
17+
}
1618
passTypeArgumentsFrom(propertyFunction)
1719
}
1820
}

kmp-nativecoroutines-compiler/src/main/kotlin/com/rickclephas/kmp/nativecoroutines/compiler/ir/codegen/SharedFlowReplayCache.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ internal fun GeneratorContext.buildSharedFlowReplayCacheGetterBody(
3535
?: error("Failed to find SharedFlow.replayCache getter")
3636
val flow = irTemporary(expression)
3737
expression = irCall(replayCacheGetter, valueType).apply {
38-
dispatchReceiver = irGet(flow)
38+
arguments[0] = irGet(flow)
3939
}
4040
if (flowType.isNullable()) {
4141
expression = irIfNull(returnType, irGet(flow), irNull(returnType), expression)

kmp-nativecoroutines-compiler/src/main/kotlin/com/rickclephas/kmp/nativecoroutines/compiler/ir/codegen/StateFlowValue.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import com.rickclephas.kmp.nativecoroutines.compiler.ir.utils.IrBlockBodyExpress
44
import com.rickclephas.kmp.nativecoroutines.compiler.ir.utils.getFlowValueTypeArg
55
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
66
import org.jetbrains.kotlin.ir.builders.*
7+
import org.jetbrains.kotlin.ir.declarations.IrParameterKind
78
import org.jetbrains.kotlin.ir.declarations.IrProperty
89
import org.jetbrains.kotlin.ir.expressions.IrBlockBody
910
import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI
@@ -32,7 +33,7 @@ internal fun GeneratorContext.buildStateFlowValueGetterBody(
3233
?: error("Failed to find StateFlow.value getter")
3334
val flow = irTemporary(expression)
3435
expression = irCall(valueGetter, valueType).apply {
35-
dispatchReceiver = irGet(flow)
36+
arguments[0] = irGet(flow)
3637
}
3738
if (flowType.isNullable()) {
3839
expression = irIfNull(returnType, irGet(flow), irNull(returnType), expression)
@@ -58,8 +59,8 @@ internal fun GeneratorContext.buildStateFlowValueSetterBody(
5859
val valueSetter = mutableStateFlowValueSymbol.owner.setter?.symbol
5960
?: error("Failed to find MutableStateFlow.value setter")
6061
expression = irCall(valueSetter).apply {
61-
dispatchReceiver = expression
62-
putValueArgument(0, irGet(setter.valueParameters.first()))
62+
arguments[0] = expression
63+
arguments[1] = irGet(setter.parameters.first { it.kind == IrParameterKind.Regular })
6364
}
6465
+irReturn(expression)
6566
}

0 commit comments

Comments
 (0)