JVM IR: rename JvmDeclarationFactory -> JvmCachedDeclarations
This commit is contained in:
@@ -15,7 +15,6 @@ import org.jetbrains.kotlin.backend.jvm.codegen.ClassCodegen
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.IrTypeMapper
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.MethodSignatureMapper
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.createFakeContinuation
|
||||
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmDeclarationFactory
|
||||
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmSharedVariablesManager
|
||||
import org.jetbrains.kotlin.backend.jvm.intrinsics.IrIntrinsicMethods
|
||||
import org.jetbrains.kotlin.backend.jvm.lower.CollectionStubComputer
|
||||
@@ -69,7 +68,7 @@ class JvmBackendContext(
|
||||
val methodSignatureMapper = MethodSignatureMapper(this)
|
||||
|
||||
internal val innerClassesSupport = JvmInnerClassesSupport()
|
||||
internal val declarationFactory = JvmDeclarationFactory(this, methodSignatureMapper, state.languageVersionSettings)
|
||||
internal val cachedDeclarations = JvmCachedDeclarations(this, methodSignatureMapper, state.languageVersionSettings)
|
||||
|
||||
override val mapping: Mapping = DefaultMapping()
|
||||
|
||||
|
||||
+5
-7
@@ -3,14 +3,12 @@
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm.descriptors
|
||||
package org.jetbrains.kotlin.backend.jvm
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.ir.copyParameterDeclarationsFrom
|
||||
import org.jetbrains.kotlin.backend.common.ir.createImplicitParameterDeclarationWithWrappedDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.ir.createStaticFunctionWithReceivers
|
||||
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.MethodSignatureMapper
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.isJvmInterface
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.copyCorrespondingPropertyFrom
|
||||
@@ -33,7 +31,7 @@ import org.jetbrains.kotlin.load.java.JvmAbi
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||
|
||||
class JvmDeclarationFactory(
|
||||
class JvmCachedDeclarations(
|
||||
private val context: JvmBackendContext,
|
||||
private val methodSignatureMapper: MethodSignatureMapper,
|
||||
private val languageVersionSettings: LanguageVersionSettings
|
||||
@@ -125,7 +123,7 @@ class JvmDeclarationFactory(
|
||||
oldParent
|
||||
annotations += oldField.annotations
|
||||
initializer = oldField.initializer
|
||||
?.replaceThisByStaticReference(this@JvmDeclarationFactory, oldParent, oldParent.thisReceiver!!)
|
||||
?.replaceThisByStaticReference(this@JvmCachedDeclarations, oldParent, oldParent.thisReceiver!!)
|
||||
?.patchDeclarationParents(this) as IrExpressionBody?
|
||||
origin = if (irProperty.parentAsClass.isCompanion) JvmLoweredDeclarationOrigin.COMPANION_PROPERTY_BACKING_FIELD else origin
|
||||
}
|
||||
@@ -174,8 +172,8 @@ class JvmDeclarationFactory(
|
||||
if (it.origin == JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE_FOR_COMPATIBILITY &&
|
||||
!it.annotations.hasAnnotation(DeprecationResolver.JAVA_DEPRECATED)
|
||||
) {
|
||||
this@JvmDeclarationFactory.context.createIrBuilder(it.symbol).run {
|
||||
it.annotations += irCall(this@JvmDeclarationFactory.context.ir.symbols.javaLangDeprecatedConstructor)
|
||||
this@JvmCachedDeclarations.context.createIrBuilder(it.symbol).run {
|
||||
it.annotations += irCall(this@JvmCachedDeclarations.context.ir.symbols.javaLangDeprecatedConstructor)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,11 +8,11 @@ package org.jetbrains.kotlin.backend.jvm.ir
|
||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||
import org.jetbrains.kotlin.backend.common.lower.IrLoweringContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmCachedDeclarations
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmSymbols
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.isInlineOnly
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.isJvmInterface
|
||||
import org.jetbrains.kotlin.backend.jvm.descriptors.JvmDeclarationFactory
|
||||
import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.unboxInlineClass
|
||||
import org.jetbrains.kotlin.codegen.inline.coroutines.FOR_INLINE_SUFFIX
|
||||
import org.jetbrains.kotlin.config.JvmDefaultMode
|
||||
@@ -228,14 +228,14 @@ fun IrExpression.isSmartcastFromHigherThanNullable(context: JvmBackendContext):
|
||||
}
|
||||
|
||||
fun IrBody.replaceThisByStaticReference(
|
||||
declarationFactory: JvmDeclarationFactory,
|
||||
cachedDeclarations: JvmCachedDeclarations,
|
||||
irClass: IrClass,
|
||||
oldThisReceiverParameter: IrValueParameter
|
||||
): IrBody =
|
||||
transform(object : IrElementTransformerVoid() {
|
||||
override fun visitGetValue(expression: IrGetValue): IrExpression {
|
||||
if (expression.symbol == oldThisReceiverParameter.symbol) {
|
||||
val instanceField = declarationFactory.getPrivateFieldForObjectInstance(irClass)
|
||||
val instanceField = cachedDeclarations.getPrivateFieldForObjectInstance(irClass)
|
||||
return IrGetFieldImpl(
|
||||
expression.startOffset,
|
||||
expression.endOffset,
|
||||
|
||||
+1
-1
@@ -348,7 +348,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
|
||||
private fun IrBlockBodyBuilder.callInvokeSuspend(invokeSuspend: IrSimpleFunction, lambda: IrExpression): IrExpression {
|
||||
// SingletonReferencesLowering has finished a while ago, so `irUnit()` won't work anymore.
|
||||
val unitClass = context.irBuiltIns.unitClass
|
||||
val unitField = this@AddContinuationLowering.context.declarationFactory.getFieldForObjectInstance(unitClass.owner)
|
||||
val unitField = this@AddContinuationLowering.context.cachedDeclarations.getFieldForObjectInstance(unitClass.owner)
|
||||
return irCallOp(invokeSuspend.symbol, invokeSuspend.returnType, lambda, irGetField(null, unitField))
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -79,7 +79,7 @@ private class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringP
|
||||
}
|
||||
|
||||
private fun buildEnumEntryField(enumEntry: IrEnumEntry): IrField =
|
||||
context.declarationFactory.getFieldForEnumEntry(enumEntry).apply {
|
||||
context.cachedDeclarations.getFieldForEnumEntry(enumEntry).apply {
|
||||
initializer = IrExpressionBodyImpl(enumEntry.initializerExpression!!.expression.patchDeclarationParents(this))
|
||||
annotations += enumEntry.annotations
|
||||
}
|
||||
|
||||
+5
-5
@@ -74,7 +74,7 @@ private class InheritedDefaultMethodsOnClassesLowering(val context: JvmBackendCo
|
||||
override fun visitSimpleFunction(declaration: IrSimpleFunction) {
|
||||
declaration.overriddenSymbols = declaration.overriddenSymbols.map { symbol ->
|
||||
if (symbol.owner.findInterfaceImplementation(context.state.jvmDefaultMode) != null)
|
||||
context.declarationFactory.getDefaultImplsRedirection(symbol.owner).symbol
|
||||
context.cachedDeclarations.getDefaultImplsRedirection(symbol.owner).symbol
|
||||
else symbol
|
||||
}
|
||||
super.visitSimpleFunction(declaration)
|
||||
@@ -84,10 +84,10 @@ private class InheritedDefaultMethodsOnClassesLowering(val context: JvmBackendCo
|
||||
interfaceImplementation: IrSimpleFunction,
|
||||
classOverride: IrSimpleFunction
|
||||
): IrSimpleFunction {
|
||||
val irFunction = context.declarationFactory.getDefaultImplsRedirection(classOverride)
|
||||
val irFunction = context.cachedDeclarations.getDefaultImplsRedirection(classOverride)
|
||||
|
||||
val superMethod = firstSuperMethodFromKotlin(irFunction, interfaceImplementation).owner
|
||||
val defaultImplFun = context.declarationFactory.getDefaultImplsFunction(superMethod)
|
||||
val defaultImplFun = context.cachedDeclarations.getDefaultImplsFunction(superMethod)
|
||||
context.createIrBuilder(irFunction.symbol, UNDEFINED_OFFSET, UNDEFINED_OFFSET).apply {
|
||||
irFunction.body = irBlockBody {
|
||||
+irReturn(
|
||||
@@ -130,7 +130,7 @@ private class InterfaceSuperCallsLowering(val context: JvmBackendContext) : IrEl
|
||||
val superCallee = expression.symbol.owner as IrSimpleFunction
|
||||
if (superCallee.isDefinitelyNotDefaultImplsMethod(context.state.jvmDefaultMode)) return super.visitCall(expression)
|
||||
|
||||
val redirectTarget = context.declarationFactory.getDefaultImplsFunction(superCallee)
|
||||
val redirectTarget = context.cachedDeclarations.getDefaultImplsFunction(superCallee)
|
||||
val newCall = createDelegatingCallWithPlaceholderTypeArguments(expression, redirectTarget, context.irBuiltIns)
|
||||
return super.visitCall(newCall)
|
||||
}
|
||||
@@ -158,7 +158,7 @@ private class InterfaceDefaultCallsLowering(val context: JvmBackendContext) : Ir
|
||||
return super.visitCall(expression)
|
||||
}
|
||||
|
||||
val redirectTarget = context.declarationFactory.getDefaultImplsFunction(callee as IrSimpleFunction)
|
||||
val redirectTarget = context.cachedDeclarations.getDefaultImplsFunction(callee as IrSimpleFunction)
|
||||
|
||||
// InterfaceLowering bridges from DefaultImpls in compatibility mode -- if that's the case,
|
||||
// this phase will inadvertently cause a recursive loop as the bridge on the DefaultImpls
|
||||
|
||||
+4
-7
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.backend.jvm.lower
|
||||
import org.jetbrains.kotlin.backend.common.ClassLoweringPass
|
||||
import org.jetbrains.kotlin.backend.common.ir.isMethodOfAny
|
||||
import org.jetbrains.kotlin.backend.common.ir.moveBodyTo
|
||||
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.codegen.isJvmInterface
|
||||
@@ -16,7 +15,6 @@ import org.jetbrains.kotlin.backend.jvm.ir.*
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.ir.builders.irCall
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
@@ -29,7 +27,6 @@ import org.jetbrains.kotlin.ir.types.defaultType
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||
|
||||
/**
|
||||
* This phase moves interface members with default implementations to the
|
||||
@@ -54,7 +51,7 @@ internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTran
|
||||
it is IrFunction && removedFunctions.containsKey(it.symbol)
|
||||
}
|
||||
|
||||
val defaultImplsIrClass = context.declarationFactory.getDefaultImplsClass(irClass)
|
||||
val defaultImplsIrClass = context.cachedDeclarations.getDefaultImplsClass(irClass)
|
||||
if (defaultImplsIrClass.declarations.isNotEmpty()) {
|
||||
irClass.declarations.add(defaultImplsIrClass)
|
||||
}
|
||||
@@ -112,7 +109,7 @@ internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTran
|
||||
!function.isDefinitelyNotDefaultImplsMethod(jvmDefaultMode, implementation) -> {
|
||||
val defaultImpl = createDefaultImpl(function)
|
||||
val superImpl = firstSuperMethodFromKotlin(function, implementation)
|
||||
context.declarationFactory.getDefaultImplsFunction(superImpl.owner).also {
|
||||
context.cachedDeclarations.getDefaultImplsFunction(superImpl.owner).also {
|
||||
defaultImpl.bridgeToStatic(it)
|
||||
}
|
||||
}
|
||||
@@ -156,7 +153,7 @@ internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTran
|
||||
}
|
||||
}
|
||||
|
||||
val defaultImplsIrClass = context.declarationFactory.getDefaultImplsClass(irClass)
|
||||
val defaultImplsIrClass = context.cachedDeclarations.getDefaultImplsClass(irClass)
|
||||
|
||||
// Move metadata for local delegated properties from the interface to DefaultImpls, since this is where kotlin-reflect looks for it.
|
||||
val localDelegatedProperties = context.localDelegatedProperties[irClass.attributeOwnerId as IrClass]
|
||||
@@ -196,7 +193,7 @@ internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTran
|
||||
}
|
||||
|
||||
private fun createDefaultImpl(function: IrSimpleFunction, forCompatibility: Boolean = false): IrSimpleFunction =
|
||||
context.declarationFactory.getDefaultImplsFunction(function, forCompatibility).also { newFunction ->
|
||||
context.cachedDeclarations.getDefaultImplsFunction(function, forCompatibility).also { newFunction ->
|
||||
newFunction.parentAsClass.declarations.add(newFunction)
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -114,7 +114,7 @@ private class CompanionObjectJvmStaticLowering(val context: JvmBackendContext) :
|
||||
annotations = target.annotations.map { it.deepCopyWithSymbols() }
|
||||
|
||||
val proxy = this
|
||||
val companionInstanceField = context.declarationFactory.getFieldForObjectInstance(companion)
|
||||
val companionInstanceField = context.cachedDeclarations.getFieldForObjectInstance(companion)
|
||||
body = context.createIrBuilder(symbol).run {
|
||||
irExprBody(irCall(target).apply {
|
||||
passTypeArgumentsFrom(proxy)
|
||||
@@ -142,7 +142,7 @@ private class SingletonObjectJvmStaticLowering(
|
||||
jvmStaticFunction.dispatchReceiverParameter?.let { oldDispatchReceiverParameter ->
|
||||
jvmStaticFunction.dispatchReceiverParameter = null
|
||||
jvmStaticFunction.body = jvmStaticFunction.body?.replaceThisByStaticReference(
|
||||
context.declarationFactory,
|
||||
context.cachedDeclarations,
|
||||
irClass,
|
||||
oldDispatchReceiverParameter
|
||||
)
|
||||
|
||||
+3
-3
@@ -51,7 +51,7 @@ private class MoveOrCopyCompanionObjectFieldsLowering(val context: JvmBackendCon
|
||||
private fun IrClass.handle() {
|
||||
val newDeclarations = declarations.map {
|
||||
when (it) {
|
||||
is IrProperty -> context.declarationFactory.getStaticBackingField(it)?.also { newField ->
|
||||
is IrProperty -> context.cachedDeclarations.getStaticBackingField(it)?.also { newField ->
|
||||
it.backingField = newField
|
||||
newField.correspondingPropertySymbol = it.symbol
|
||||
}
|
||||
@@ -101,7 +101,7 @@ private class MoveOrCopyCompanionObjectFieldsLowering(val context: JvmBackendCon
|
||||
IrAnonymousInitializerImpl(startOffset, endOffset, origin, newSymbol, isStatic = true).apply {
|
||||
parent = newParent
|
||||
body = this@with.body
|
||||
.replaceThisByStaticReference(context.declarationFactory, oldParent, oldParent.thisReceiver!!)
|
||||
.replaceThisByStaticReference(context.cachedDeclarations, oldParent, oldParent.thisReceiver!!)
|
||||
.patchDeclarationParents(newParent) as IrBlockBody
|
||||
}
|
||||
}
|
||||
@@ -132,7 +132,7 @@ private class RemapObjectFieldAccesses(val context: JvmBackendContext) : FileLow
|
||||
override fun lower(irFile: IrFile) = irFile.transformChildrenVoid()
|
||||
|
||||
private fun IrField.remap(): IrField? =
|
||||
correspondingPropertySymbol?.owner?.let(context.declarationFactory::getStaticBackingField)
|
||||
correspondingPropertySymbol?.owner?.let(context.cachedDeclarations::getStaticBackingField)
|
||||
|
||||
override fun visitGetField(expression: IrGetField): IrExpression =
|
||||
expression.symbol.owner.remap()?.let {
|
||||
|
||||
+2
-2
@@ -44,8 +44,8 @@ private class ObjectClassLowering(val context: JvmBackendContext) : IrElementTra
|
||||
private fun process(irClass: IrClass) {
|
||||
if (!irClass.isObject) return
|
||||
|
||||
val publicInstanceField = context.declarationFactory.getFieldForObjectInstance(irClass)
|
||||
val privateInstanceField = context.declarationFactory.getPrivateFieldForObjectInstance(irClass)
|
||||
val publicInstanceField = context.cachedDeclarations.getFieldForObjectInstance(irClass)
|
||||
val privateInstanceField = context.cachedDeclarations.getPrivateFieldForObjectInstance(irClass)
|
||||
|
||||
val constructor = irClass.constructors.find { it.isPrimary }
|
||||
?: throw AssertionError("Object should have a primary constructor: ${irClass.name}")
|
||||
|
||||
+3
-3
@@ -46,7 +46,7 @@ private class SingletonReferencesLowering(val context: JvmBackendContext) : File
|
||||
// must be replaced with `SomeEnumEntry.this`.
|
||||
IrGetValueImpl(expression.startOffset, expression.endOffset, expression.type, appropriateThis.symbol)
|
||||
} else {
|
||||
val entrySymbol = context.declarationFactory.getFieldForEnumEntry(expression.symbol.owner)
|
||||
val entrySymbol = context.cachedDeclarations.getFieldForEnumEntry(expression.symbol.owner)
|
||||
IrGetFieldImpl(expression.startOffset, expression.endOffset, entrySymbol.symbol, expression.type)
|
||||
}
|
||||
}
|
||||
@@ -60,9 +60,9 @@ private class SingletonReferencesLowering(val context: JvmBackendContext) : File
|
||||
return IrGetValueImpl(expression.startOffset, expression.endOffset, it.symbol)
|
||||
}
|
||||
val instanceField = if (allScopes.any { it.irElement == expression.symbol.owner })
|
||||
context.declarationFactory.getPrivateFieldForObjectInstance(expression.symbol.owner) // Constructor or static method.
|
||||
context.cachedDeclarations.getPrivateFieldForObjectInstance(expression.symbol.owner) // Constructor or static method.
|
||||
else
|
||||
context.declarationFactory.getFieldForObjectInstance(expression.symbol.owner) // Not in object scope at all.
|
||||
context.cachedDeclarations.getFieldForObjectInstance(expression.symbol.owner) // Not in object scope at all.
|
||||
return IrGetFieldImpl(expression.startOffset, expression.endOffset, instanceField.symbol, expression.type)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user