Preserve extraInt in kotlin metadata remapper

The `extraInt` (`xs`, [1]) parameter of Kotlin's Metadata annotation does not become
part of the KmClass/KmLambda and must be preserved explicitly to not be lost
during remapping.

It does carry important information though, so we must not neglect it.
In particular, bit 7 indicates that the class is used in the scope of an inline
function and is therefore implicitly part of the public API. If this flag is
missing from a class which requires it, then it becomes impossible to use that
inline function because the Kotlin compiler will crash hitting an assertion
while trying to inline the required code [2].

Based on the descriptions in [1], it looks like none of this data should be
affected by our remapping in any way, so it seems safe to simply copy over the
value from the original annotation. And that's what this commit does.

[1]: https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-metadata/extra-int.html
[2]: https://i.johni0702.de/sOpA8.png

Co-authored-by: Jonas Herzig <jonas@spark-squared.com>
This commit is contained in:
modmuss50
2022-05-19 20:17:54 +01:00
parent c46100c76e
commit 1b6fa615c4

View File

@@ -61,7 +61,7 @@ class KotlinClassMetadataRemappingAnnotationVisitor(private val remapper: Remapp
val klass = metadata.toKmClass()
val writer = KotlinClassMetadata.Class.Writer()
klass.accept(RemappingKmVisitors(remapper).RemappingKmClassVisitor(writer))
val remapped = writer.write(header.metadataVersion).header
val remapped = writer.write(header.metadataVersion, header.extraInt).header
writeClassHeader(remapped)
validateKotlinClassHeader(remapped, header)
}
@@ -71,7 +71,7 @@ class KotlinClassMetadataRemappingAnnotationVisitor(private val remapper: Remapp
if (klambda != null) {
val writer = KotlinClassMetadata.SyntheticClass.Writer()
klambda.accept(RemappingKmVisitors(remapper).RemappingKmLambdaVisitor(writer))
val remapped = writer.write(header.metadataVersion).header
val remapped = writer.write(header.metadataVersion, header.extraInt).header
writeClassHeader(remapped)
validateKotlinClassHeader(remapped, header)
} else {
@@ -82,7 +82,7 @@ class KotlinClassMetadataRemappingAnnotationVisitor(private val remapper: Remapp
val kpackage = metadata.toKmPackage()
val writer = KotlinClassMetadata.FileFacade.Writer()
kpackage.accept(RemappingKmVisitors(remapper).RemappingKmPackageVisitor(writer))
val remapped = writer.write(header.metadataVersion).header
val remapped = writer.write(header.metadataVersion, header.extraInt).header
writeClassHeader(remapped)
validateKotlinClassHeader(remapped, header)
}