diff --git a/compiler/backend-common/build.gradle.kts b/compiler/backend-common/build.gradle.kts index 56c375ee0ce..7f2a9d68a90 100644 --- a/compiler/backend-common/build.gradle.kts +++ b/compiler/backend-common/build.gradle.kts @@ -6,7 +6,6 @@ plugins { dependencies { compile(project(":core:descriptors")) - compile(project(":core:descriptors.jvm")) compile(project(":compiler:util")) compile(project(":compiler:frontend")) compile(project(":compiler:ir.tree")) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/PropertiesLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/PropertiesLowering.kt index d39336512c3..1996d6bea79 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/PropertiesLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/PropertiesLowering.kt @@ -8,7 +8,6 @@ package org.jetbrains.kotlin.backend.common.lower import org.jetbrains.kotlin.backend.common.BackendContext import org.jetbrains.kotlin.backend.common.FileLoweringPass import org.jetbrains.kotlin.backend.common.descriptors.WrappedSimpleFunctionDescriptor -import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase import org.jetbrains.kotlin.descriptors.ClassKind import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Visibilities @@ -20,36 +19,15 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl import org.jetbrains.kotlin.ir.expressions.impl.IrBlockImpl import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl import org.jetbrains.kotlin.ir.util.transformDeclarationsFlat -import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid -import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid -import org.jetbrains.kotlin.load.java.JvmAbi -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.ir.visitors.* +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.utils.addIfNotNull import java.util.* -fun makePropertiesPhase(originOfSyntheticMethodForAnnotations: IrDeclarationOrigin?) = makeIrFilePhase( - { context -> PropertiesLowering(context, originOfSyntheticMethodForAnnotations) }, - name = "Properties", - description = "Move fields and accessors for properties to their classes", - stickyPostconditions = setOf(::checkNoProperties) -) - -fun checkNoProperties(irFile: IrFile) { - irFile.acceptVoid(object : IrElementVisitorVoid { - override fun visitElement(element: IrElement) { - element.acceptChildrenVoid(this) - } - - override fun visitProperty(declaration: IrProperty) { - error("No properties should remain at this stage") - } - }) -} - class PropertiesLowering( private val context: BackendContext, - private val originOfSyntheticMethodForAnnotations: IrDeclarationOrigin? + private val originOfSyntheticMethodForAnnotations: IrDeclarationOrigin? = null, + private val computeSyntheticMethodName: ((Name) -> String)? = null ) : IrElementTransformerVoid(), FileLoweringPass { override fun lower(irFile: IrFile) { irFile.accept(this, null) @@ -78,20 +56,22 @@ class PropertiesLowering( addIfNotNull(declaration.getter) addIfNotNull(declaration.setter) - if (declaration.annotations.isNotEmpty() && originOfSyntheticMethodForAnnotations != null) { - add(createSyntheticMethodForAnnotations(declaration, originOfSyntheticMethodForAnnotations)) + if (declaration.annotations.isNotEmpty() && originOfSyntheticMethodForAnnotations != null + && computeSyntheticMethodName != null + ) { + val methodName = computeSyntheticMethodName.invoke(declaration.name) // Workaround KT-4113 + add(createSyntheticMethodForAnnotations(declaration, originOfSyntheticMethodForAnnotations, methodName)) } } else null - private fun createSyntheticMethodForAnnotations(declaration: IrProperty, origin: IrDeclarationOrigin): IrFunctionImpl { + private fun createSyntheticMethodForAnnotations(declaration: IrProperty, origin: IrDeclarationOrigin, name: String): IrFunctionImpl { val descriptor = WrappedSimpleFunctionDescriptor(declaration.descriptor.annotations) val symbol = IrSimpleFunctionSymbolImpl(descriptor) // TODO: ACC_DEPRECATED return IrFunctionImpl( - -1, -1, origin, - symbol, Name.identifier(JvmAbi.getSyntheticMethodNameForAnnotatedProperty(declaration.name)), + -1, -1, origin, symbol, Name.identifier(name), Visibilities.PUBLIC, Modality.OPEN, context.irBuiltIns.unitType, isInline = false, isExternal = false, isTailrec = false, isSuspend = false ).apply { @@ -107,6 +87,20 @@ class PropertiesLowering( metadata = declaration.metadata } } + + companion object { + fun checkNoProperties(irFile: IrFile) { + irFile.acceptVoid(object : IrElementVisitorVoid { + override fun visitElement(element: IrElement) { + element.acceptChildrenVoid(this) + } + + override fun visitProperty(declaration: IrProperty) { + error("No properties should remain at this stage") + } + }) + } + } } class LocalDelegatedPropertiesLowering : IrElementTransformerVoid(), FileLoweringPass { diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt index 8ffeacd85be..17456d85bbb 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/JsLoweringPhases.kt @@ -244,7 +244,7 @@ private val varargLoweringPhase = makeJsModulePhase( ) private val propertiesLoweringPhase = makeJsModulePhase( - { context -> PropertiesLowering(context, null) }, + { context -> PropertiesLowering(context) }, name = "PropertiesLowering", description = "Move fields and accessors out from its property" ) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt index 5fd498df549..14a8c999d86 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.backend.jvm.lower.* import org.jetbrains.kotlin.ir.declarations.IrFile import org.jetbrains.kotlin.ir.util.PatchDeclarationParentsVisitor import org.jetbrains.kotlin.ir.visitors.acceptVoid +import org.jetbrains.kotlin.load.java.JvmAbi private fun makePatchParentsPhase(number: Int) = namedIrFilePhase( lower = object : SameTypeCompilerPhase { @@ -36,6 +37,17 @@ private fun makePatchParentsPhase(number: Int) = namedIrFilePhase( nlevels = 0 ) +private val propertiesPhase = makeIrFilePhase( + { context -> + PropertiesLowering(context, JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_ANNOTATIONS) { propertyName -> + JvmAbi.getSyntheticMethodNameForAnnotatedProperty(propertyName) + } + }, + name = "Properties", + description = "Move fields and accessors for properties to their classes", + stickyPostconditions = setOf((PropertiesLowering)::checkNoProperties) +) + internal val jvmPhases = namedIrFilePhase( name = "IrLowering", description = "IR lowering", @@ -48,7 +60,7 @@ internal val jvmPhases = namedIrFilePhase( moveCompanionObjectFieldsPhase then constPhase then propertiesToFieldsPhase then - makePropertiesPhase(JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_PROPERTY_ANNOTATIONS) then + propertiesPhase then renameFieldsPhase then annotationPhase then