From 00fd411c5c5388d58de08ef8ad9ee7f01a3c9e33 Mon Sep 17 00:00:00 2001 From: Matthew Haughton <3flex@users.noreply.github.com> Date: Sat, 21 Sep 2024 21:46:22 +1000 Subject: [PATCH] Add missing opt-in annotations --- .../dev/drewhamilton/poko/ir/PokoMembersTransformer.kt | 3 +++ .../kotlin/dev/drewhamilton/poko/ir/equalsGeneration.kt | 2 ++ .../kotlin/dev/drewhamilton/poko/ir/functionGeneration.kt | 2 ++ .../kotlin/dev/drewhamilton/poko/ir/hashCodeGeneration.kt | 6 ++++++ .../kotlin/dev/drewhamilton/poko/ir/toStringGeneration.kt | 3 +++ 5 files changed, 16 insertions(+) diff --git a/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/PokoMembersTransformer.kt b/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/PokoMembersTransformer.kt index b38e73de..3cac1af3 100644 --- a/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/PokoMembersTransformer.kt +++ b/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/PokoMembersTransformer.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.ir.declarations.IrFunction import org.jetbrains.kotlin.ir.declarations.IrProperty import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl +import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl import org.jetbrains.kotlin.ir.types.createType import org.jetbrains.kotlin.ir.util.IdSignature @@ -73,6 +74,7 @@ internal class PokoMembersTransformer( return super.visitFunctionNew(declaration) } + @OptIn(UnsafeDuringIrConstructionAPI::class) private fun IrClass.isPokoClass(): Boolean = when { !hasAnnotation(pokoAnnotationName.asSingleFqName()) -> { messageCollector.log("Not Poko class") @@ -106,6 +108,7 @@ internal class PokoMembersTransformer( } } + @OptIn(UnsafeDuringIrConstructionAPI::class) private inline fun IrFunction.convertToGenerated( generateFunctionBody: IrBlockBodyBuilder.(List) -> Unit ) { diff --git a/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/equalsGeneration.kt b/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/equalsGeneration.kt index 26685670..2965fa5b 100644 --- a/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/equalsGeneration.kt +++ b/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/equalsGeneration.kt @@ -33,6 +33,7 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol +import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI import org.jetbrains.kotlin.ir.types.classifierOrFail import org.jetbrains.kotlin.ir.types.classifierOrNull import org.jetbrains.kotlin.ir.types.isNullable @@ -214,6 +215,7 @@ private fun IrBuilderWithScope.irCallContentDeepEquals( * function if it represents a primitive array. */ context(IrPluginContext) +@OptIn(UnsafeDuringIrConstructionAPI::class) private fun IrBuilderWithScope.findContentDeepEqualsFunctionSymbol( classifier: IrClassifierSymbol, ): IrSimpleFunctionSymbol { diff --git a/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/functionGeneration.kt b/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/functionGeneration.kt index dfa3931e..91de36f1 100644 --- a/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/functionGeneration.kt +++ b/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/functionGeneration.kt @@ -15,6 +15,7 @@ import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol import org.jetbrains.kotlin.ir.symbols.IrValueSymbol +import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI import org.jetbrains.kotlin.ir.types.IrSimpleType import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.classOrNull @@ -133,6 +134,7 @@ private val IrTypeParameterSymbol.hasArrayOrPrimitiveArrayUpperBound: Boolean return false } +@OptIn(UnsafeDuringIrConstructionAPI::class) internal val IrTypeParameter.erasedUpperBound: IrClass get() { // Pick the (necessarily unique) non-interface upper bound if it exists diff --git a/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/hashCodeGeneration.kt b/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/hashCodeGeneration.kt index e60ab38c..f324f3e7 100644 --- a/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/hashCodeGeneration.kt +++ b/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/hashCodeGeneration.kt @@ -31,6 +31,7 @@ import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol +import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI import org.jetbrains.kotlin.ir.symbols.impl.IrVariableSymbolImpl import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.types.classifierOrFail @@ -140,6 +141,7 @@ private fun IrBlockBodyBuilder.getHashCodeOfProperty( * [org.jetbrains.kotlin.fir.backend.generators.DataClassMembersGenerator]. */ context(IrPluginContext) +@OptIn(UnsafeDuringIrConstructionAPI::class) private fun IrBlockBodyBuilder.getHashCodeOf( property: IrProperty, value: IrExpression, @@ -264,6 +266,7 @@ private fun IrBlockBodyBuilder.maybeFindArrayContentHashCodeFunction( } context(IrPluginContext) +@OptIn(UnsafeDuringIrConstructionAPI::class) private fun IrBlockBodyBuilder.findArrayContentDeepHashCodeFunction( propertyClassifier: IrClassifierSymbol, ): IrSimpleFunctionSymbol { @@ -285,6 +288,7 @@ private fun IrBlockBodyBuilder.findArrayContentDeepHashCodeFunction( } } +@OptIn(UnsafeDuringIrConstructionAPI::class) private fun IrBlockBodyBuilder.getStandardHashCodeFunctionSymbol( classifier: IrClassifierSymbol?, ): IrSimpleFunctionSymbol = when { @@ -298,6 +302,7 @@ private fun IrBlockBodyBuilder.getStandardHashCodeFunctionSymbol( error("Unknown classifier kind $classifier") } +@OptIn(UnsafeDuringIrConstructionAPI::class) private fun IrBlockBodyBuilder.getHashCodeFunctionForClass( irClass: IrClass ): IrSimpleFunctionSymbol { @@ -310,6 +315,7 @@ private fun IrBlockBodyBuilder.getHashCodeFunctionForClass( ?: context.irBuiltIns.anyClass.functions.single { it.owner.name.asString() == "hashCode" } } +@OptIn(UnsafeDuringIrConstructionAPI::class) private fun IrBlockBodyBuilder.irCallHashCodeFunction( hashCodeFunctionSymbol: IrSimpleFunctionSymbol, value: IrExpression, diff --git a/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/toStringGeneration.kt b/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/toStringGeneration.kt index d31c0607..6891fdd8 100644 --- a/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/toStringGeneration.kt +++ b/poko-compiler-plugin/src/main/kotlin/dev/drewhamilton/poko/ir/toStringGeneration.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.ir.expressions.addArgument import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol +import org.jetbrains.kotlin.ir.symbols.UnsafeDuringIrConstructionAPI import org.jetbrains.kotlin.ir.types.classifierOrFail import org.jetbrains.kotlin.ir.types.classifierOrNull import org.jetbrains.kotlin.ir.types.isNullable @@ -186,6 +187,7 @@ private fun IrBlockBodyBuilder.irArrayTypeCheckAndContentDeepToStringBranch( * `contentToString` function if it is a primitive array. */ context(IrPluginContext) +@OptIn(UnsafeDuringIrConstructionAPI::class) private fun IrBuilderWithScope.findContentDeepToStringFunctionSymbol( propertyClassifier: IrClassifierSymbol, ): IrSimpleFunctionSymbol { @@ -208,6 +210,7 @@ private fun IrBuilderWithScope.findContentDeepToStringFunctionSymbol( } } +@OptIn(UnsafeDuringIrConstructionAPI::class) private fun IrBlockBodyBuilder.irCallToStringFunction( toStringFunctionSymbol: IrSimpleFunctionSymbol, value: IrExpression,