FIR: serialize HAS_CONSTANT at least for const properties
Non-const properties may need them too with if the 1.4 feature NoConstantValueAttributeForNonConstVals is disabled.
This commit is contained in:
@@ -40,6 +40,6 @@ public final const val s: R|kotlin/Short| = Short(20000)
|
|||||||
public final const val s1: R|kotlin/Short| = Short(1)
|
public final const val s1: R|kotlin/Short| = Short(1)
|
||||||
public get(): R|kotlin/Short|
|
public get(): R|kotlin/Short|
|
||||||
|
|
||||||
public final const val str: R|kotlin/String|
|
public final const val str: R|kotlin/String| = String(:))
|
||||||
public get(): R|kotlin/String|
|
public get(): R|kotlin/String|
|
||||||
|
|
||||||
|
|||||||
+8
-11
@@ -20,24 +20,21 @@ import org.jetbrains.kotlin.serialization.deserialization.builtins.BuiltInSerial
|
|||||||
|
|
||||||
class FirConstDeserializer(
|
class FirConstDeserializer(
|
||||||
val session: FirSession,
|
val session: FirSession,
|
||||||
private val partSource: KotlinJvmBinaryClass? = null,
|
private val binaryClass: KotlinJvmBinaryClass? = null
|
||||||
private val facadeSource: KotlinJvmBinaryClass? = null
|
|
||||||
) {
|
) {
|
||||||
companion object {
|
private val constantCache = mutableMapOf<CallableId, FirExpression>()
|
||||||
private val constantCache = mutableMapOf<CallableId, FirExpression>()
|
|
||||||
}
|
|
||||||
|
|
||||||
fun loadConstant(propertyProto: ProtoBuf.Property, callableId: CallableId, nameResolver: NameResolver): FirExpression? {
|
fun loadConstant(propertyProto: ProtoBuf.Property, callableId: CallableId, nameResolver: NameResolver): FirExpression? {
|
||||||
if (!Flags.HAS_CONSTANT.get(propertyProto.flags)) return null
|
if (!Flags.HAS_CONSTANT.get(propertyProto.flags)) return null
|
||||||
|
|
||||||
constantCache[callableId]?.let { return it }
|
constantCache[callableId]?.let { return it }
|
||||||
|
|
||||||
if (facadeSource == null && partSource == null) {
|
if (binaryClass == null) {
|
||||||
val value = propertyProto.getExtensionOrNull(BuiltInSerializerProtocol.compileTimeValue) ?: return null
|
val value = propertyProto.getExtensionOrNull(BuiltInSerializerProtocol.compileTimeValue) ?: return null
|
||||||
return buildFirConstant(value, null, value.type.name, nameResolver)?.apply { constantCache[callableId] = this }
|
return buildFirConstant(value, null, value.type.name, nameResolver)?.apply { constantCache[callableId] = this }
|
||||||
}
|
}
|
||||||
|
|
||||||
(facadeSource ?: partSource)!!.visitMembers(object : KotlinJvmBinaryClass.MemberVisitor {
|
binaryClass.visitMembers(object : KotlinJvmBinaryClass.MemberVisitor {
|
||||||
override fun visitMethod(name: Name, desc: String): KotlinJvmBinaryClass.MethodAnnotationVisitor? = null
|
override fun visitMethod(name: Name, desc: String): KotlinJvmBinaryClass.MethodAnnotationVisitor? = null
|
||||||
|
|
||||||
override fun visitField(name: Name, desc: String, initializer: Any?): KotlinJvmBinaryClass.AnnotationVisitor? {
|
override fun visitField(name: Name, desc: String, initializer: Any?): KotlinJvmBinaryClass.AnnotationVisitor? {
|
||||||
@@ -60,11 +57,11 @@ class FirConstDeserializer(
|
|||||||
"CHAR", "C" -> buildConstExpression(null, FirConstKind.Char, ((protoValue?.intValue ?: sourceValue) as Number).toChar())
|
"CHAR", "C" -> buildConstExpression(null, FirConstKind.Char, ((protoValue?.intValue ?: sourceValue) as Number).toChar())
|
||||||
"SHORT", "S" -> buildConstExpression(null, FirConstKind.Short, ((protoValue?.intValue ?: sourceValue) as Number).toShort())
|
"SHORT", "S" -> buildConstExpression(null, FirConstKind.Short, ((protoValue?.intValue ?: sourceValue) as Number).toShort())
|
||||||
"INT", "I" -> buildConstExpression(null, FirConstKind.Int, protoValue?.intValue?.toInt() ?: sourceValue as Int)
|
"INT", "I" -> buildConstExpression(null, FirConstKind.Int, protoValue?.intValue?.toInt() ?: sourceValue as Int)
|
||||||
"LONG", "J" -> buildConstExpression(null, FirConstKind.Long, (protoValue?.intValue ?: sourceValue) as Long)
|
"LONG", "J" -> buildConstExpression(null, FirConstKind.Long, protoValue?.intValue ?: sourceValue as Long)
|
||||||
"FLOAT", "F" -> buildConstExpression(null, FirConstKind.Float, (protoValue?.floatValue ?: sourceValue) as Float)
|
"FLOAT", "F" -> buildConstExpression(null, FirConstKind.Float, protoValue?.floatValue ?: sourceValue as Float)
|
||||||
"DOUBLE", "D" -> buildConstExpression(null, FirConstKind.Double, (protoValue?.doubleValue ?: sourceValue) as Double)
|
"DOUBLE", "D" -> buildConstExpression(null, FirConstKind.Double, protoValue?.doubleValue ?: sourceValue as Double)
|
||||||
"BOOLEAN", "Z" -> buildConstExpression(null, FirConstKind.Boolean, (protoValue?.intValue?.toInt() ?: sourceValue) != 0)
|
"BOOLEAN", "Z" -> buildConstExpression(null, FirConstKind.Boolean, (protoValue?.intValue?.toInt() ?: sourceValue) != 0)
|
||||||
"STRING", "Ljava/lang/String" -> buildConstExpression(
|
"STRING", "Ljava/lang/String;" -> buildConstExpression(
|
||||||
null, FirConstKind.String, protoValue?.stringValue?.let { nameResolver.getString(it) } ?: sourceValue as String
|
null, FirConstKind.String, protoValue?.stringValue?.let { nameResolver.getString(it) } ?: sourceValue as String
|
||||||
)
|
)
|
||||||
else -> null
|
else -> null
|
||||||
|
|||||||
+1
-3
@@ -205,9 +205,6 @@ class FirElementSerializer private constructor(
|
|||||||
var hasGetter = false
|
var hasGetter = false
|
||||||
var hasSetter = false
|
var hasSetter = false
|
||||||
|
|
||||||
//val compileTimeConstant = property.compileTimeInitializer
|
|
||||||
val hasConstant = false // TODO: compileTimeConstant != null && compileTimeConstant !is NullValue
|
|
||||||
|
|
||||||
val hasAnnotations = property.nonSourceAnnotations(session).isNotEmpty()
|
val hasAnnotations = property.nonSourceAnnotations(session).isNotEmpty()
|
||||||
// TODO: hasAnnotations(descriptor) || hasAnnotations(descriptor.backingField) || hasAnnotations(descriptor.delegateField)
|
// TODO: hasAnnotations(descriptor) || hasAnnotations(descriptor.backingField) || hasAnnotations(descriptor.delegateField)
|
||||||
|
|
||||||
@@ -247,6 +244,7 @@ class FirElementSerializer private constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val hasConstant = property.isConst // TODO: this is only correct with LanguageFeature.NoConstantValueAttributeForNonConstVals
|
||||||
val flags = Flags.getPropertyFlags(
|
val flags = Flags.getPropertyFlags(
|
||||||
hasAnnotations,
|
hasAnnotations,
|
||||||
ProtoEnumFlags.visibility(normalizeVisibility(property)),
|
ProtoEnumFlags.visibility(normalizeVisibility(property)),
|
||||||
|
|||||||
+1
-1
@@ -126,7 +126,7 @@ class KotlinDeserializedJvmSymbolsProvider(
|
|||||||
FirDeserializationContext.createForPackage(
|
FirDeserializationContext.createForPackage(
|
||||||
packageFqName, packageProto, nameResolver, session,
|
packageFqName, packageProto, nameResolver, session,
|
||||||
JvmBinaryAnnotationDeserializer(session, kotlinJvmBinaryClass, byteContent),
|
JvmBinaryAnnotationDeserializer(session, kotlinJvmBinaryClass, byteContent),
|
||||||
FirConstDeserializer(session, kotlinJvmBinaryClass, facadeBinaryClass),
|
FirConstDeserializer(session, facadeBinaryClass ?: kotlinJvmBinaryClass),
|
||||||
source
|
source
|
||||||
),
|
),
|
||||||
source,
|
source,
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// FILE: A.kt
|
// FILE: A.kt
|
||||||
|
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// FILE: A.kt
|
// FILE: A.kt
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// FILE: A.kt
|
// FILE: A.kt
|
||||||
|
|
||||||
|
|||||||
-1
@@ -1,4 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: JVM_IR
|
|
||||||
// TARGET_BACKEND: JVM
|
// TARGET_BACKEND: JVM
|
||||||
// FILE: A.kt
|
// FILE: A.kt
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user