JVM IR: load fields for JvmField properties from dependencies

This is needed to properly lower JvmField property calls to field
accesses.
This commit is contained in:
Alexander Udalov
2019-11-18 16:33:11 +01:00
parent 608449f41d
commit a485a5ffd6
8 changed files with 14 additions and 9 deletions
@@ -87,4 +87,7 @@ class JvmStubGeneratorExtensions : StubGeneratorExtensions() {
classNameOverride[it] = facadeName
}
}
override fun isPropertyWithPlatformField(descriptor: PropertyDescriptor): Boolean =
descriptor.hasJvmFieldAnnotation()
}
@@ -39,7 +39,7 @@ class IrLazyProperty(
override val isFakeOverride: Boolean,
stubGenerator: DeclarationStubGenerator,
typeTranslator: TypeTranslator,
private val bindingContext: BindingContext? = null
bindingContext: BindingContext? = null
) :
IrLazyDeclarationBase(startOffset, endOffset, origin, stubGenerator, typeTranslator),
IrProperty {
@@ -72,11 +72,14 @@ class IrLazyProperty(
symbol.bind(this)
}
private val hasBackingField: Boolean =
descriptor.hasBackingField(bindingContext) || stubGenerator.extensions.isPropertyWithPlatformField(descriptor)
override val descriptor: PropertyDescriptor
get() = symbol.descriptor
override var backingField: IrField? by lazyVar {
if (descriptor.hasBackingField(bindingContext)) {
if (hasBackingField) {
stubGenerator.generateFieldStub(descriptor).apply {
correspondingPropertySymbol = this@IrLazyProperty.symbol
}
@@ -37,7 +37,7 @@ class DeclarationStubGenerator(
val symbolTable: SymbolTable,
languageVersionSettings: LanguageVersionSettings,
private val irProviders: List<IrProvider> = emptyList(),
private val extensions: StubGeneratorExtensions = StubGeneratorExtensions.EMPTY
val extensions: StubGeneratorExtensions = StubGeneratorExtensions.EMPTY
) {
private val lazyTable = symbolTable.lazyWrapper
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.ir.util
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
@@ -15,6 +16,8 @@ open class StubGeneratorExtensions {
open fun generateFacadeClass(source: DeserializedContainerSource): IrClass? = null
open fun isPropertyWithPlatformField(descriptor: PropertyDescriptor): Boolean = false
companion object {
@JvmField
val EMPTY = StubGeneratorExtensions()
@@ -1,5 +1,4 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_MULTI_MODULE: JVM_IR
// WITH_RUNTIME
// FILE: 1.kt
@@ -17,4 +16,4 @@ import test.*
fun box(): String {
return test(Foo("OK")::a)
}
}
@@ -1,5 +1,4 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_MULTI_MODULE: JVM_IR
// WITH_RUNTIME
// FILE: 1.kt
@@ -17,4 +16,4 @@ import test.*
fun box(): String {
return test(Foo::a)
}
}
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// TARGET_BACKEND: JVM
// FILE: A.kt
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JVM_IR
// TARGET_BACKEND: JVM
// FILE: A.kt