-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
Serialization: Serializable meta annotation #4583
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this 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
a517697
to
af0b58b
Compare
f8a7d94
to
5eefc3a
Compare
654ff1f
to
f4a378b
Compare
@@ -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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
plugins/kotlin-serialization/kotlin-serialization-compiler/testData/boxIr/metaSerializable.kt
Show resolved
Hide resolved
plugins/kotlin-serialization/kotlin-serialization-compiler/testData/boxIr/metaSerializable.kt
Show resolved
Hide resolved
f4a378b
to
2d54606
Compare
val annot = getAnnotation(SerializationAnnotations.serializableAnnotationFqName) | ||
if (annot != null) { | ||
for (i in 0 until annot.valueArgumentsCount) { | ||
if (annot.getValueArgument(i) != null) return false |
There was a problem hiding this comment.
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
This test is a leftover from the original implementation of #4583 which was updated. This test is redundant now.
This test is a leftover from the original implementation of JetBrains#4583 which was updated. This test is redundant now.
https://youtrack.jetbrains.com/issue/KTOR-2704
Add handling for (not yet released) kotlinx.serialization
@MetaSerializable