From 1b6fa615c48083b97afdda4fd350e43c67ae3a39 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Thu, 19 May 2022 20:17:54 +0100 Subject: [PATCH] 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 --- .../KotlinClassMetadataRemappingAnnotationVisitor.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassMetadataRemappingAnnotationVisitor.kt b/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassMetadataRemappingAnnotationVisitor.kt index 57fca33b..b8a10620 100644 --- a/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassMetadataRemappingAnnotationVisitor.kt +++ b/src/main/kotlin/net/fabricmc/loom/kotlin/remapping/KotlinClassMetadataRemappingAnnotationVisitor.kt @@ -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) }