Make CLASS default class kind in binary metadata
Don't write the kind to the class file if it's CLASS to save some bytes
This commit is contained in:
@@ -239,13 +239,20 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
kind = KotlinClass.Kind.ANONYMOUS_OBJECT;
|
kind = KotlinClass.Kind.ANONYMOUS_OBJECT;
|
||||||
}
|
}
|
||||||
else if (isTopLevelOrInnerClass(descriptor)) {
|
else if (isTopLevelOrInnerClass(descriptor)) {
|
||||||
kind = KotlinClass.Kind.CLASS;
|
// Default value is Kind.CLASS
|
||||||
|
kind = null;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// LOCAL_CLASS is also written to inner classes of local classes
|
// LOCAL_CLASS is also written to inner classes of local classes
|
||||||
kind = KotlinClass.Kind.LOCAL_CLASS;
|
kind = KotlinClass.Kind.LOCAL_CLASS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Temporarily write class kind anyway because old compiler may not expect its absence
|
||||||
|
// TODO: remove after M13
|
||||||
|
if (kind == null) {
|
||||||
|
kind = KotlinClass.Kind.CLASS;
|
||||||
|
}
|
||||||
|
|
||||||
DescriptorSerializer serializer =
|
DescriptorSerializer serializer =
|
||||||
DescriptorSerializer.create(descriptor, new JvmSerializerExtension(v.getSerializationBindings(), typeMapper));
|
DescriptorSerializer.create(descriptor, new JvmSerializerExtension(v.getSerializationBindings(), typeMapper));
|
||||||
|
|
||||||
@@ -257,11 +264,14 @@ public class ImplementationBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
AnnotationVisitor av = v.getVisitor().visitAnnotation(asmDescByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_CLASS), true);
|
AnnotationVisitor av = v.getVisitor().visitAnnotation(asmDescByFqNameWithoutInnerClasses(JvmAnnotationNames.KOTLIN_CLASS), true);
|
||||||
av.visit(JvmAnnotationNames.ABI_VERSION_FIELD_NAME, JvmAbi.VERSION);
|
av.visit(JvmAnnotationNames.ABI_VERSION_FIELD_NAME, JvmAbi.VERSION);
|
||||||
av.visitEnum(
|
//noinspection ConstantConditions
|
||||||
JvmAnnotationNames.KIND_FIELD_NAME,
|
if (kind != null) {
|
||||||
Type.getObjectType(KotlinClass.KIND_INTERNAL_NAME).getDescriptor(),
|
av.visitEnum(
|
||||||
kind.toString()
|
JvmAnnotationNames.KIND_FIELD_NAME,
|
||||||
);
|
Type.getObjectType(KotlinClass.KIND_INTERNAL_NAME).getDescriptor(),
|
||||||
|
kind.toString()
|
||||||
|
);
|
||||||
|
}
|
||||||
AnnotationVisitor array = av.visitArray(JvmAnnotationNames.DATA_FIELD_NAME);
|
AnnotationVisitor array = av.visitArray(JvmAnnotationNames.DATA_FIELD_NAME);
|
||||||
for (String string : BitEncoding.encodeBytes(SerializationUtil.serializeClassData(data))) {
|
for (String string : BitEncoding.encodeBytes(SerializationUtil.serializeClassData(data))) {
|
||||||
array.visit(null, string);
|
array.visit(null, string);
|
||||||
|
|||||||
+5
@@ -68,6 +68,11 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (headerKind == CLASS && classKind == null) {
|
||||||
|
// Default class kind is Kind.CLASS
|
||||||
|
classKind = KotlinClass.Kind.CLASS;
|
||||||
|
}
|
||||||
|
|
||||||
if (!AbiVersionUtil.isAbiVersionCompatible(version)) {
|
if (!AbiVersionUtil.isAbiVersionCompatible(version)) {
|
||||||
return new KotlinClassHeader(headerKind, version, null, classKind, syntheticClassKind);
|
return new KotlinClassHeader(headerKind, version, null, classKind, syntheticClassKind);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import java.lang.annotation.RetentionPolicy;
|
|||||||
public @interface KotlinClass {
|
public @interface KotlinClass {
|
||||||
int abiVersion();
|
int abiVersion();
|
||||||
|
|
||||||
Kind kind();
|
Kind kind() default Kind.CLASS;
|
||||||
|
|
||||||
String[] data();
|
String[] data();
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ public @interface KotlinClass {
|
|||||||
CLASS,
|
CLASS,
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A class has this kind if and only if its first non-class container is not a package.
|
* A class has kind LOCAL_CLASS if and only if it's not an anonymous object and its first non-class container is not a package.
|
||||||
*/
|
*/
|
||||||
LOCAL_CLASS,
|
LOCAL_CLASS,
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user