Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing opt-in annotations #407

Merged
merged 1 commit into from
Sep 22, 2024
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 @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -106,6 +108,7 @@ internal class PokoMembersTransformer(
}
}

@OptIn(UnsafeDuringIrConstructionAPI::class)
private inline fun IrFunction.convertToGenerated(
generateFunctionBody: IrBlockBodyBuilder.(List<IrProperty>) -> Unit
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -214,6 +215,7 @@ private fun IrBuilderWithScope.irCallContentDeepEquals(
* function if it represents a primitive array.
*/
context(IrPluginContext)
@OptIn(UnsafeDuringIrConstructionAPI::class)
Comment on lines 217 to +218
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
context(IrPluginContext)
@OptIn(UnsafeDuringIrConstructionAPI::class)
@OptIn(UnsafeDuringIrConstructionAPI::class)
context(IrPluginContext)

In my brain the context is part of the signature

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense - I just tried though and there's a compiler error:

image

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let this awkward syntax be a reminder to remove context receivers from this project 😬

private fun IrBuilderWithScope.findContentDeepEqualsFunctionSymbol(
classifier: IrClassifierSymbol,
): IrSimpleFunctionSymbol {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -140,6 +141,7 @@ private fun IrBlockBodyBuilder.getHashCodeOfProperty(
* [org.jetbrains.kotlin.fir.backend.generators.DataClassMembersGenerator].
*/
context(IrPluginContext)
@OptIn(UnsafeDuringIrConstructionAPI::class)
Comment on lines 143 to +144
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
context(IrPluginContext)
@OptIn(UnsafeDuringIrConstructionAPI::class)
@OptIn(UnsafeDuringIrConstructionAPI::class)
context(IrPluginContext)

private fun IrBlockBodyBuilder.getHashCodeOf(
property: IrProperty,
value: IrExpression,
Expand Down Expand Up @@ -264,6 +266,7 @@ private fun IrBlockBodyBuilder.maybeFindArrayContentHashCodeFunction(
}

context(IrPluginContext)
@OptIn(UnsafeDuringIrConstructionAPI::class)
Comment on lines 268 to +269
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
context(IrPluginContext)
@OptIn(UnsafeDuringIrConstructionAPI::class)
@OptIn(UnsafeDuringIrConstructionAPI::class)
context(IrPluginContext)

private fun IrBlockBodyBuilder.findArrayContentDeepHashCodeFunction(
propertyClassifier: IrClassifierSymbol,
): IrSimpleFunctionSymbol {
Expand All @@ -285,6 +288,7 @@ private fun IrBlockBodyBuilder.findArrayContentDeepHashCodeFunction(
}
}

@OptIn(UnsafeDuringIrConstructionAPI::class)
private fun IrBlockBodyBuilder.getStandardHashCodeFunctionSymbol(
classifier: IrClassifierSymbol?,
): IrSimpleFunctionSymbol = when {
Expand All @@ -298,6 +302,7 @@ private fun IrBlockBodyBuilder.getStandardHashCodeFunctionSymbol(
error("Unknown classifier kind $classifier")
}

@OptIn(UnsafeDuringIrConstructionAPI::class)
private fun IrBlockBodyBuilder.getHashCodeFunctionForClass(
irClass: IrClass
): IrSimpleFunctionSymbol {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -186,6 +187,7 @@ private fun IrBlockBodyBuilder.irArrayTypeCheckAndContentDeepToStringBranch(
* `contentToString` function if it is a primitive array.
*/
context(IrPluginContext)
@OptIn(UnsafeDuringIrConstructionAPI::class)
Comment on lines 189 to +190
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
context(IrPluginContext)
@OptIn(UnsafeDuringIrConstructionAPI::class)
@OptIn(UnsafeDuringIrConstructionAPI::class)
context(IrPluginContext)

private fun IrBuilderWithScope.findContentDeepToStringFunctionSymbol(
propertyClassifier: IrClassifierSymbol,
): IrSimpleFunctionSymbol {
Expand All @@ -208,6 +210,7 @@ private fun IrBuilderWithScope.findContentDeepToStringFunctionSymbol(
}
}

@OptIn(UnsafeDuringIrConstructionAPI::class)
private fun IrBlockBodyBuilder.irCallToStringFunction(
toStringFunctionSymbol: IrSimpleFunctionSymbol,
value: IrExpression,
Expand Down