Revert "JVM_IR. Support compile time constants"

This reverts commit 055215c54f.
This commit is contained in:
Georgy Bronnikov
2018-09-25 05:24:48 +03:00
parent 055215c54f
commit 487f500f85
39 changed files with 42 additions and 35 deletions
@@ -13,9 +13,7 @@ import org.jetbrains.kotlin.descriptors.PropertyGetterDescriptor
import org.jetbrains.kotlin.ir.IrStatement
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.declarations.IrProperty
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.expressions.IrCall
import org.jetbrains.kotlin.ir.expressions.IrConst
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.expressions.impl.IrGetFieldImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrSetFieldImpl
@@ -24,7 +22,6 @@ import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
import org.jetbrains.kotlin.synthetic.SyntheticJavaPropertyDescriptor
class ConstAndJvmFieldPropertiesLowering(val context: JvmBackendContext) : IrElementTransformerVoid(), FileLoweringPass {
override fun lower(irFile: IrFile) {
irFile.transformChildrenVoid(this)
}
@@ -39,12 +36,6 @@ class ConstAndJvmFieldPropertiesLowering(val context: JvmBackendContext) : IrEle
}
override fun visitCall(expression: IrCall): IrExpression {
val irProperty = (expression.symbol.owner as? IrSimpleFunction)?.correspondingProperty ?: return super.visitCall(expression)
if (irProperty.isConst) {
(irProperty.backingField?.initializer?.expression as? IrConst<*>)?.let { return it }
}
val descriptor = expression.descriptor as? PropertyAccessorDescriptor ?: return super.visitCall(expression)
val property = descriptor.correspondingProperty
@@ -74,7 +65,7 @@ class ConstAndJvmFieldPropertiesLowering(val context: JvmBackendContext) : IrEle
)
}
private fun substituteGetter(descriptor: PropertyGetterDescriptor, expression: IrCall): IrExpression {
private fun substituteGetter(descriptor: PropertyGetterDescriptor, expression: IrCall): IrGetFieldImpl {
return IrGetFieldImpl(
expression.startOffset,
expression.endOffset,
@@ -79,21 +79,14 @@ class DeclarationStubGenerator(
throw AssertionError("Unexpected member descriptor: $descriptor")
}
internal fun generatePropertyStub(
descriptor: PropertyDescriptor,
bindingContext: BindingContext? = null
): IrProperty =
internal fun generatePropertyStub(descriptor: PropertyDescriptor, bindingContext: BindingContext? = null): IrProperty =
IrPropertyImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor).also { irProperty ->
if (descriptor.hasBackingField(bindingContext)) {
irProperty.backingField = generateFieldStub(descriptor)
}
irProperty.getter = descriptor.getter?.let { generateFunctionStub(it, createPropertyIfNeeded = false) }?.apply {
correspondingProperty = irProperty
}
irProperty.setter = descriptor.setter?.let { generateFunctionStub(it, createPropertyIfNeeded = false) }?.apply {
correspondingProperty = irProperty
}
irProperty.getter = descriptor.getter?.let { generateFunctionStub(it) }
irProperty.setter = descriptor.setter?.let { generateFunctionStub(it) }
}
private fun generateFieldStub(descriptor: PropertyDescriptor): IrField {
@@ -124,19 +117,12 @@ class DeclarationStubGenerator(
}
}
fun generateFunctionStub(descriptor: FunctionDescriptor, createPropertyIfNeeded: Boolean = true): IrSimpleFunction {
fun generateFunctionStub(descriptor: FunctionDescriptor): IrSimpleFunction {
val referenced = symbolTable.referenceSimpleFunction(descriptor)
if (referenced.isBound) {
return referenced.owner
}
if (createPropertyIfNeeded && descriptor is PropertyGetterDescriptor) {
return generatePropertyStub(descriptor.correspondingProperty).getter!!
}
if (createPropertyIfNeeded && descriptor is PropertySetterDescriptor) {
return generatePropertyStub(descriptor.correspondingProperty).setter!!
}
val origin =
if (descriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE)
IrDeclarationOrigin.FAKE_OVERRIDE