Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.compiler.plugins.kotlin.analysis.ComposeWritableSlices
import androidx.compose.compiler.plugins.kotlin.hasComposableAnnotation
import androidx.compose.compiler.plugins.kotlin.irTrace
import androidx.compose.compiler.plugins.kotlin.isComposableCallable
import androidx.compose.compiler.plugins.kotlin.lower.decoys.copyWithNewTypeParams
import androidx.compose.compiler.plugins.kotlin.lower.decoys.isDecoy
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.backend.common.ir.copyTo
Expand Down Expand Up @@ -49,6 +50,7 @@ import org.jetbrains.kotlin.ir.descriptors.WrappedPropertyGetterDescriptor
import org.jetbrains.kotlin.ir.descriptors.WrappedPropertySetterDescriptor
import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor
import org.jetbrains.kotlin.ir.expressions.IrCall
import org.jetbrains.kotlin.ir.expressions.IrConstKind
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.IrGetValue
Expand All @@ -67,6 +69,7 @@ import org.jetbrains.kotlin.ir.types.IrSimpleType
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.types.classOrNull
import org.jetbrains.kotlin.ir.types.createType
import org.jetbrains.kotlin.ir.types.isMarkedNullable
import org.jetbrains.kotlin.ir.types.isPrimitiveType
import org.jetbrains.kotlin.ir.types.makeNullable
import org.jetbrains.kotlin.ir.util.DeepCopySymbolRemapper
Expand Down Expand Up @@ -267,8 +270,16 @@ class ComposerParamTransformer(
endOffset: Int = UNDEFINED_OFFSET
): IrExpression {
val classSymbol = classOrNull
if (this !is IrSimpleType || hasQuestionMark || classSymbol?.owner?.isInline != true)
if (this !is IrSimpleType || hasQuestionMark || classSymbol?.owner?.isInline != true) {
if (isMarkedNullable()) {
return IrConstImpl.constNull(
startOffset,
endOffset,
context.irBuiltIns.unitType
)
}
return IrConstImpl.defaultValueForType(startOffset, endOffset, this)
}

val klass = classSymbol.owner
val ctor = classSymbol.constructors.first()
Expand Down Expand Up @@ -415,7 +426,11 @@ class ComposerParamTransformer(
// case in composable lambdas. The synthetic name that kotlin generates for
// anonymous parameters has an issue where it is not safe to dex, so we sanitize
// the names here to ensure that dex is always safe.
p.copyTo(fn, name = dexSafeName(p.name))
p.copyTo(
irFunction = fn,
name = dexSafeName(p.name),
defaultValue = p.defaultValue?.copyWithNewTypeParams(this, fn)
)
}
fn.annotations = annotations.map { a -> a }
fn.metadata = metadata
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import androidx.compose.compiler.plugins.kotlin.lower.ModuleLoweringPass
import org.jetbrains.kotlin.backend.common.ir.addChild
import org.jetbrains.kotlin.backend.common.ir.copyParameterDeclarationsFrom
import org.jetbrains.kotlin.backend.common.ir.copyTo
import org.jetbrains.kotlin.backend.common.ir.copyTypeParametersFrom
import org.jetbrains.kotlin.backend.common.ir.moveBodyTo
import org.jetbrains.kotlin.backend.common.ir.remapTypeParameters
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
Expand Down Expand Up @@ -162,26 +163,30 @@ class CreateDecoysTransformer(
newFunction.origin = IrDeclarationOrigin.DEFINED

// here generic value parameters will be applied
newFunction.copyParameterDeclarationsFrom(original)
newFunction.copyTypeParametersFrom(original)

// ..but we need to remap the return type as well
newFunction.returnType = newFunction.returnType.remapTypeParameters(
source = original,
target = newFunction
)
// remove leading $ in params to avoid confusing other transforms
newFunction.valueParameters = newFunction.valueParameters.map {
newFunction.valueParameters = original.valueParameters.map {
val name = dexSafeName(it.name).asString()
if (name.startsWith('$')) {
it.copyTo(
newFunction,
name = Name.identifier(name.dropWhile { it == '$' })
)
} else {
it
}
it.copyTo(
newFunction,
name = Name.identifier(
if (name.startsWith('$')) name.dropWhile { it == '$' } else name
),
defaultValue = it.defaultValue?.copyWithNewTypeParams(original, newFunction)
)
}

newFunction.extensionReceiverParameter = original.extensionReceiverParameter
?.copyTo(newFunction)
newFunction.dispatchReceiverParameter = original.dispatchReceiverParameter
?.copyTo(newFunction)

newFunction.body = original.moveBodyTo(newFunction)
?.copyWithNewTypeParams(original, newFunction)

Expand Down