Remove dependency of backend-common on descriptors.jvm

This commit is contained in:
Alexander Udalov
2019-03-01 17:02:59 +01:00
parent d7fd4987ae
commit 4b712bd14b
4 changed files with 38 additions and 33 deletions
-1
View File
@@ -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"))
@@ -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 {
@@ -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"
)
@@ -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<CommonBackendContext, IrFile> {
@@ -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