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

Serialization: Serializable meta annotation #4583

Merged

Conversation

rsinukov
Copy link
Contributor

https://youtrack.jetbrains.com/issue/KTOR-2704

Add handling for (not yet released) kotlinx.serialization @MetaSerializable

Copy link

@Repoman124 Repoman124 left a comment

Choose a reason for hiding this comment

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

Copy link

@Repoman124 Repoman124 left a comment

Choose a reason for hiding this comment

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

I'm attempting my first pull

@sandwwraith sandwwraith self-assigned this Sep 30, 2021
@rsinukov rsinukov force-pushed the rsinukov/serializable-meta-annotation branch 4 times, most recently from a517697 to af0b58b Compare October 11, 2021 18:00
@rsinukov rsinukov force-pushed the rsinukov/serializable-meta-annotation branch from f8a7d94 to 5eefc3a Compare December 1, 2021 00:22
@rsinukov rsinukov force-pushed the rsinukov/serializable-meta-annotation branch 2 times, most recently from 654ff1f to f4a378b Compare December 21, 2021 12:26
@@ -597,7 +604,9 @@ interface IrBuilderExtension {
irProperty.backingField?.symbol ?: error("Property expected to have backing field"),
property.type.toIrType(),
receiver
)
).let {
if (property.type.toIrType().isKClass()) kClassExprToJClassIfNeeded(startOffset, endOffset, it) else it
Copy link
Member

Choose a reason for hiding this comment

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

property.type.toIrType() is not very cheap operation, so IMO it's better to extract it to a separate variable beforehand

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

}

private val IrClass.isInternalSerializable: Boolean get() = kind == ClassKind.CLASS && hasSerializableAnnotationWithoutArgs()
private val IrClass.isInternalSerializable: Boolean get() = this.descriptor.isInternalSerializable
Copy link
Member

Choose a reason for hiding this comment

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

In general, it's better to avoid using descriptors in IR transformations because it's considered deprecated and dangerous API, which can sometimes lead to 'unbound symbol' bugs. I think it's possible to modify IrClass.hasSerializableAnnotationWithoutArgs(): Boolean function so it would take into account meta-annotations, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -38,6 +38,8 @@ object SerializationAnnotations {
internal val contextualOnPropertyFqName = FqName("kotlinx.serialization.Contextual")
internal val polymorphicFqName = FqName("kotlinx.serialization.Polymorphic")
internal val additionalSerializersFqName = FqName("kotlinx.serialization.UseSerializers")

internal val metaSerializableAnnotationFqName = FqName("kotlinx.serialization.MetaSerializable")
Copy link
Member

Choose a reason for hiding this comment

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

IMO better move it next to SerialInfo & InheritableSerialInfo

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@rsinukov rsinukov force-pushed the rsinukov/serializable-meta-annotation branch from f4a378b to 2d54606 Compare February 8, 2022 16:25
@rsinukov rsinukov requested a review from sandwwraith February 8, 2022 16:26
val annot = getAnnotation(SerializationAnnotations.serializableAnnotationFqName)
if (annot != null) {
for (i in 0 until annot.valueArgumentsCount) {
if (annot.getValueArgument(i) != null) return false
Copy link
Member

Choose a reason for hiding this comment

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

serializable annotation always have one argument so I think we may skip a loop here

@sandwwraith sandwwraith merged commit e09f30f into JetBrains:master Mar 25, 2022
sandwwraith pushed a commit that referenced this pull request Mar 27, 2022
This test is a leftover from the original implementation of #4583 which was updated. This test is redundant now.
maxim092001 pushed a commit to maxim092001/kotlin that referenced this pull request Apr 16, 2022
maxim092001 pushed a commit to maxim092001/kotlin that referenced this pull request Apr 16, 2022
This test is a leftover from the original implementation of JetBrains#4583 which was updated. This test is redundant now.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants