JVM IR: Add supertypes for PropertyReference classes in JvmSymbols

This is still missing overrides, but this change is enough to make
the code generated in PropertyReferenceLowering typecheck.
This commit is contained in:
Steven Schäfer
2019-11-11 11:45:41 +01:00
committed by Alexander Udalov
parent 2db8471dd7
commit 3d7d1022e4
@@ -328,21 +328,29 @@ class JvmSymbols(
val impl: Boolean val impl: Boolean
) )
private val propertyReferenceClasses = storageManager.createMemoizedFunction { key: PropertyReferenceKey -> private val propertyReferenceClassCache = mutableMapOf<PropertyReferenceKey, IrClassSymbol>()
val (mutable, n, impl) = key
fun getPropertyReferenceClass(mutable: Boolean, parameterCount: Int, impl: Boolean): IrClassSymbol {
val key = PropertyReferenceKey(mutable, parameterCount, impl)
return propertyReferenceClassCache.getOrPut(key) {
val className = buildString { val className = buildString {
if (mutable) append("Mutable") if (mutable) append("Mutable")
append("PropertyReference") append("PropertyReference")
append(n) append(parameterCount)
if (impl) append("Impl") if (impl) append("Impl")
} }
createClass(FqName("kotlin.jvm.internal.$className")) { klass ->
createClass(
FqName("kotlin.jvm.internal.$className"),
classModality = if (impl) Modality.FINAL else Modality.ABSTRACT
) { klass ->
if (impl) { if (impl) {
klass.addConstructor().apply { klass.addConstructor().apply {
addValueParameter("owner", irBuiltIns.kDeclarationContainerClass.owner.defaultType) addValueParameter("owner", irBuiltIns.kDeclarationContainerClass.owner.defaultType)
addValueParameter("name", irBuiltIns.stringType) addValueParameter("name", irBuiltIns.stringType)
addValueParameter("string", irBuiltIns.stringType) addValueParameter("string", irBuiltIns.stringType)
} }
klass.superTypes += getPropertyReferenceClass(mutable, parameterCount, false).owner.defaultType
} else { } else {
klass.addConstructor() klass.addConstructor()
@@ -369,21 +377,21 @@ class JvmSymbols(
// To avoid hassle with generic type parameters, we pretend that PropertyReferenceN.get takes and returns `Any?` // To avoid hassle with generic type parameters, we pretend that PropertyReferenceN.get takes and returns `Any?`
// (similarly with set). This should be enough for the JVM IR backend to generate correct calls and bridges. // (similarly with set). This should be enough for the JVM IR backend to generate correct calls and bridges.
klass.addFunction("get", irBuiltIns.anyNType, Modality.ABSTRACT).apply { klass.addFunction("get", irBuiltIns.anyNType, Modality.ABSTRACT).apply {
for (i in 0 until n) { for (i in 0 until parameterCount) {
addValueParameter("receiver$i", irBuiltIns.anyNType) addValueParameter("receiver$i", irBuiltIns.anyNType)
} }
} }
// invoke redirects to get // invoke redirects to get
klass.addFunction("invoke", irBuiltIns.anyNType, Modality.FINAL).apply { klass.addFunction("invoke", irBuiltIns.anyNType, Modality.FINAL).apply {
for (i in 0 until n) { for (i in 0 until parameterCount) {
addValueParameter("receiver$i", irBuiltIns.anyNType) addValueParameter("receiver$i", irBuiltIns.anyNType)
} }
} }
if (mutable) { if (mutable) {
klass.addFunction("set", irBuiltIns.unitType, Modality.ABSTRACT).apply { klass.addFunction("set", irBuiltIns.unitType, Modality.ABSTRACT).apply {
for (i in 0 until n) { for (i in 0 until parameterCount) {
addValueParameter("receiver$i", irBuiltIns.anyNType) addValueParameter("receiver$i", irBuiltIns.anyNType)
} }
addValueParameter("value", irBuiltIns.anyNType) addValueParameter("value", irBuiltIns.anyNType)
@@ -391,9 +399,7 @@ class JvmSymbols(
} }
} }
} }
}
fun getPropertyReferenceClass(mutable: Boolean, parameterCount: Int, impl: Boolean): IrClassSymbol =
propertyReferenceClasses(PropertyReferenceKey(mutable, parameterCount, impl))
val reflection: IrClassSymbol = createClass(FqName("kotlin.jvm.internal.Reflection")) { klass -> val reflection: IrClassSymbol = createClass(FqName("kotlin.jvm.internal.Reflection")) { klass ->
val javaLangClassType = javaLangClass.starProjectedType val javaLangClassType = javaLangClass.starProjectedType