JVM IR: rename JvmDeclarationFactory -> JvmCachedDeclarations

This commit is contained in:
Alexander Udalov
2020-07-08 19:00:02 +02:00
parent c7f9dc1c40
commit 71730696b2
11 changed files with 30 additions and 36 deletions
@@ -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.IrTypeMapper
import org.jetbrains.kotlin.backend.jvm.codegen.MethodSignatureMapper import org.jetbrains.kotlin.backend.jvm.codegen.MethodSignatureMapper
import org.jetbrains.kotlin.backend.jvm.codegen.createFakeContinuation 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.descriptors.JvmSharedVariablesManager
import org.jetbrains.kotlin.backend.jvm.intrinsics.IrIntrinsicMethods import org.jetbrains.kotlin.backend.jvm.intrinsics.IrIntrinsicMethods
import org.jetbrains.kotlin.backend.jvm.lower.CollectionStubComputer import org.jetbrains.kotlin.backend.jvm.lower.CollectionStubComputer
@@ -69,7 +68,7 @@ class JvmBackendContext(
val methodSignatureMapper = MethodSignatureMapper(this) val methodSignatureMapper = MethodSignatureMapper(this)
internal val innerClassesSupport = JvmInnerClassesSupport() 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() override val mapping: Mapping = DefaultMapping()
@@ -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. * 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.copyParameterDeclarationsFrom
import org.jetbrains.kotlin.backend.common.ir.createImplicitParameterDeclarationWithWrappedDescriptor import org.jetbrains.kotlin.backend.common.ir.createImplicitParameterDeclarationWithWrappedDescriptor
import org.jetbrains.kotlin.backend.common.ir.createStaticFunctionWithReceivers import org.jetbrains.kotlin.backend.common.ir.createStaticFunctionWithReceivers
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder 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.MethodSignatureMapper
import org.jetbrains.kotlin.backend.jvm.codegen.isJvmInterface import org.jetbrains.kotlin.backend.jvm.codegen.isJvmInterface
import org.jetbrains.kotlin.backend.jvm.ir.copyCorrespondingPropertyFrom 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.name.Name
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
class JvmDeclarationFactory( class JvmCachedDeclarations(
private val context: JvmBackendContext, private val context: JvmBackendContext,
private val methodSignatureMapper: MethodSignatureMapper, private val methodSignatureMapper: MethodSignatureMapper,
private val languageVersionSettings: LanguageVersionSettings private val languageVersionSettings: LanguageVersionSettings
@@ -125,7 +123,7 @@ class JvmDeclarationFactory(
oldParent oldParent
annotations += oldField.annotations annotations += oldField.annotations
initializer = oldField.initializer initializer = oldField.initializer
?.replaceThisByStaticReference(this@JvmDeclarationFactory, oldParent, oldParent.thisReceiver!!) ?.replaceThisByStaticReference(this@JvmCachedDeclarations, oldParent, oldParent.thisReceiver!!)
?.patchDeclarationParents(this) as IrExpressionBody? ?.patchDeclarationParents(this) as IrExpressionBody?
origin = if (irProperty.parentAsClass.isCompanion) JvmLoweredDeclarationOrigin.COMPANION_PROPERTY_BACKING_FIELD else origin 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 && if (it.origin == JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE_FOR_COMPATIBILITY &&
!it.annotations.hasAnnotation(DeprecationResolver.JAVA_DEPRECATED) !it.annotations.hasAnnotation(DeprecationResolver.JAVA_DEPRECATED)
) { ) {
this@JvmDeclarationFactory.context.createIrBuilder(it.symbol).run { this@JvmCachedDeclarations.context.createIrBuilder(it.symbol).run {
it.annotations += irCall(this@JvmDeclarationFactory.context.ir.symbols.javaLangDeprecatedConstructor) 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.ir.ir2string
import org.jetbrains.kotlin.backend.common.lower.IrLoweringContext import org.jetbrains.kotlin.backend.common.lower.IrLoweringContext
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext 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.JvmLoweredDeclarationOrigin
import org.jetbrains.kotlin.backend.jvm.JvmSymbols import org.jetbrains.kotlin.backend.jvm.JvmSymbols
import org.jetbrains.kotlin.backend.jvm.codegen.isInlineOnly import org.jetbrains.kotlin.backend.jvm.codegen.isInlineOnly
import org.jetbrains.kotlin.backend.jvm.codegen.isJvmInterface 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.backend.jvm.lower.inlineclasses.unboxInlineClass
import org.jetbrains.kotlin.codegen.inline.coroutines.FOR_INLINE_SUFFIX import org.jetbrains.kotlin.codegen.inline.coroutines.FOR_INLINE_SUFFIX
import org.jetbrains.kotlin.config.JvmDefaultMode import org.jetbrains.kotlin.config.JvmDefaultMode
@@ -228,14 +228,14 @@ fun IrExpression.isSmartcastFromHigherThanNullable(context: JvmBackendContext):
} }
fun IrBody.replaceThisByStaticReference( fun IrBody.replaceThisByStaticReference(
declarationFactory: JvmDeclarationFactory, cachedDeclarations: JvmCachedDeclarations,
irClass: IrClass, irClass: IrClass,
oldThisReceiverParameter: IrValueParameter oldThisReceiverParameter: IrValueParameter
): IrBody = ): IrBody =
transform(object : IrElementTransformerVoid() { transform(object : IrElementTransformerVoid() {
override fun visitGetValue(expression: IrGetValue): IrExpression { override fun visitGetValue(expression: IrGetValue): IrExpression {
if (expression.symbol == oldThisReceiverParameter.symbol) { if (expression.symbol == oldThisReceiverParameter.symbol) {
val instanceField = declarationFactory.getPrivateFieldForObjectInstance(irClass) val instanceField = cachedDeclarations.getPrivateFieldForObjectInstance(irClass)
return IrGetFieldImpl( return IrGetFieldImpl(
expression.startOffset, expression.startOffset,
expression.endOffset, expression.endOffset,
@@ -348,7 +348,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
private fun IrBlockBodyBuilder.callInvokeSuspend(invokeSuspend: IrSimpleFunction, lambda: IrExpression): IrExpression { private fun IrBlockBodyBuilder.callInvokeSuspend(invokeSuspend: IrSimpleFunction, lambda: IrExpression): IrExpression {
// SingletonReferencesLowering has finished a while ago, so `irUnit()` won't work anymore. // SingletonReferencesLowering has finished a while ago, so `irUnit()` won't work anymore.
val unitClass = context.irBuiltIns.unitClass 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)) return irCallOp(invokeSuspend.symbol, invokeSuspend.returnType, lambda, irGetField(null, unitField))
} }
@@ -79,7 +79,7 @@ private class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringP
} }
private fun buildEnumEntryField(enumEntry: IrEnumEntry): IrField = private fun buildEnumEntryField(enumEntry: IrEnumEntry): IrField =
context.declarationFactory.getFieldForEnumEntry(enumEntry).apply { context.cachedDeclarations.getFieldForEnumEntry(enumEntry).apply {
initializer = IrExpressionBodyImpl(enumEntry.initializerExpression!!.expression.patchDeclarationParents(this)) initializer = IrExpressionBodyImpl(enumEntry.initializerExpression!!.expression.patchDeclarationParents(this))
annotations += enumEntry.annotations annotations += enumEntry.annotations
} }
@@ -74,7 +74,7 @@ private class InheritedDefaultMethodsOnClassesLowering(val context: JvmBackendCo
override fun visitSimpleFunction(declaration: IrSimpleFunction) { override fun visitSimpleFunction(declaration: IrSimpleFunction) {
declaration.overriddenSymbols = declaration.overriddenSymbols.map { symbol -> declaration.overriddenSymbols = declaration.overriddenSymbols.map { symbol ->
if (symbol.owner.findInterfaceImplementation(context.state.jvmDefaultMode) != null) if (symbol.owner.findInterfaceImplementation(context.state.jvmDefaultMode) != null)
context.declarationFactory.getDefaultImplsRedirection(symbol.owner).symbol context.cachedDeclarations.getDefaultImplsRedirection(symbol.owner).symbol
else symbol else symbol
} }
super.visitSimpleFunction(declaration) super.visitSimpleFunction(declaration)
@@ -84,10 +84,10 @@ private class InheritedDefaultMethodsOnClassesLowering(val context: JvmBackendCo
interfaceImplementation: IrSimpleFunction, interfaceImplementation: IrSimpleFunction,
classOverride: IrSimpleFunction classOverride: IrSimpleFunction
): IrSimpleFunction { ): IrSimpleFunction {
val irFunction = context.declarationFactory.getDefaultImplsRedirection(classOverride) val irFunction = context.cachedDeclarations.getDefaultImplsRedirection(classOverride)
val superMethod = firstSuperMethodFromKotlin(irFunction, interfaceImplementation).owner 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 { context.createIrBuilder(irFunction.symbol, UNDEFINED_OFFSET, UNDEFINED_OFFSET).apply {
irFunction.body = irBlockBody { irFunction.body = irBlockBody {
+irReturn( +irReturn(
@@ -130,7 +130,7 @@ private class InterfaceSuperCallsLowering(val context: JvmBackendContext) : IrEl
val superCallee = expression.symbol.owner as IrSimpleFunction val superCallee = expression.symbol.owner as IrSimpleFunction
if (superCallee.isDefinitelyNotDefaultImplsMethod(context.state.jvmDefaultMode)) return super.visitCall(expression) 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) val newCall = createDelegatingCallWithPlaceholderTypeArguments(expression, redirectTarget, context.irBuiltIns)
return super.visitCall(newCall) return super.visitCall(newCall)
} }
@@ -158,7 +158,7 @@ private class InterfaceDefaultCallsLowering(val context: JvmBackendContext) : Ir
return super.visitCall(expression) 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, // 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 // this phase will inadvertently cause a recursive loop as the bridge on the DefaultImpls
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.backend.jvm.lower
import org.jetbrains.kotlin.backend.common.ClassLoweringPass import org.jetbrains.kotlin.backend.common.ClassLoweringPass
import org.jetbrains.kotlin.backend.common.ir.isMethodOfAny import org.jetbrains.kotlin.backend.common.ir.isMethodOfAny
import org.jetbrains.kotlin.backend.common.ir.moveBodyTo 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.JvmBackendContext
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
import org.jetbrains.kotlin.backend.jvm.codegen.isJvmInterface 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.ClassKind
import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.descriptors.Visibilities
import org.jetbrains.kotlin.ir.builders.irCall
import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrCall import org.jetbrains.kotlin.ir.expressions.IrCall
import org.jetbrains.kotlin.ir.expressions.IrExpression 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.util.*
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
/** /**
* This phase moves interface members with default implementations to the * 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) it is IrFunction && removedFunctions.containsKey(it.symbol)
} }
val defaultImplsIrClass = context.declarationFactory.getDefaultImplsClass(irClass) val defaultImplsIrClass = context.cachedDeclarations.getDefaultImplsClass(irClass)
if (defaultImplsIrClass.declarations.isNotEmpty()) { if (defaultImplsIrClass.declarations.isNotEmpty()) {
irClass.declarations.add(defaultImplsIrClass) irClass.declarations.add(defaultImplsIrClass)
} }
@@ -112,7 +109,7 @@ internal class InterfaceLowering(val context: JvmBackendContext) : IrElementTran
!function.isDefinitelyNotDefaultImplsMethod(jvmDefaultMode, implementation) -> { !function.isDefinitelyNotDefaultImplsMethod(jvmDefaultMode, implementation) -> {
val defaultImpl = createDefaultImpl(function) val defaultImpl = createDefaultImpl(function)
val superImpl = firstSuperMethodFromKotlin(function, implementation) val superImpl = firstSuperMethodFromKotlin(function, implementation)
context.declarationFactory.getDefaultImplsFunction(superImpl.owner).also { context.cachedDeclarations.getDefaultImplsFunction(superImpl.owner).also {
defaultImpl.bridgeToStatic(it) 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. // 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] 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 = 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) newFunction.parentAsClass.declarations.add(newFunction)
} }
@@ -114,7 +114,7 @@ private class CompanionObjectJvmStaticLowering(val context: JvmBackendContext) :
annotations = target.annotations.map { it.deepCopyWithSymbols() } annotations = target.annotations.map { it.deepCopyWithSymbols() }
val proxy = this val proxy = this
val companionInstanceField = context.declarationFactory.getFieldForObjectInstance(companion) val companionInstanceField = context.cachedDeclarations.getFieldForObjectInstance(companion)
body = context.createIrBuilder(symbol).run { body = context.createIrBuilder(symbol).run {
irExprBody(irCall(target).apply { irExprBody(irCall(target).apply {
passTypeArgumentsFrom(proxy) passTypeArgumentsFrom(proxy)
@@ -142,7 +142,7 @@ private class SingletonObjectJvmStaticLowering(
jvmStaticFunction.dispatchReceiverParameter?.let { oldDispatchReceiverParameter -> jvmStaticFunction.dispatchReceiverParameter?.let { oldDispatchReceiverParameter ->
jvmStaticFunction.dispatchReceiverParameter = null jvmStaticFunction.dispatchReceiverParameter = null
jvmStaticFunction.body = jvmStaticFunction.body?.replaceThisByStaticReference( jvmStaticFunction.body = jvmStaticFunction.body?.replaceThisByStaticReference(
context.declarationFactory, context.cachedDeclarations,
irClass, irClass,
oldDispatchReceiverParameter oldDispatchReceiverParameter
) )
@@ -51,7 +51,7 @@ private class MoveOrCopyCompanionObjectFieldsLowering(val context: JvmBackendCon
private fun IrClass.handle() { private fun IrClass.handle() {
val newDeclarations = declarations.map { val newDeclarations = declarations.map {
when (it) { when (it) {
is IrProperty -> context.declarationFactory.getStaticBackingField(it)?.also { newField -> is IrProperty -> context.cachedDeclarations.getStaticBackingField(it)?.also { newField ->
it.backingField = newField it.backingField = newField
newField.correspondingPropertySymbol = it.symbol newField.correspondingPropertySymbol = it.symbol
} }
@@ -101,7 +101,7 @@ private class MoveOrCopyCompanionObjectFieldsLowering(val context: JvmBackendCon
IrAnonymousInitializerImpl(startOffset, endOffset, origin, newSymbol, isStatic = true).apply { IrAnonymousInitializerImpl(startOffset, endOffset, origin, newSymbol, isStatic = true).apply {
parent = newParent parent = newParent
body = this@with.body body = this@with.body
.replaceThisByStaticReference(context.declarationFactory, oldParent, oldParent.thisReceiver!!) .replaceThisByStaticReference(context.cachedDeclarations, oldParent, oldParent.thisReceiver!!)
.patchDeclarationParents(newParent) as IrBlockBody .patchDeclarationParents(newParent) as IrBlockBody
} }
} }
@@ -132,7 +132,7 @@ private class RemapObjectFieldAccesses(val context: JvmBackendContext) : FileLow
override fun lower(irFile: IrFile) = irFile.transformChildrenVoid() override fun lower(irFile: IrFile) = irFile.transformChildrenVoid()
private fun IrField.remap(): IrField? = private fun IrField.remap(): IrField? =
correspondingPropertySymbol?.owner?.let(context.declarationFactory::getStaticBackingField) correspondingPropertySymbol?.owner?.let(context.cachedDeclarations::getStaticBackingField)
override fun visitGetField(expression: IrGetField): IrExpression = override fun visitGetField(expression: IrGetField): IrExpression =
expression.symbol.owner.remap()?.let { expression.symbol.owner.remap()?.let {
@@ -44,8 +44,8 @@ private class ObjectClassLowering(val context: JvmBackendContext) : IrElementTra
private fun process(irClass: IrClass) { private fun process(irClass: IrClass) {
if (!irClass.isObject) return if (!irClass.isObject) return
val publicInstanceField = context.declarationFactory.getFieldForObjectInstance(irClass) val publicInstanceField = context.cachedDeclarations.getFieldForObjectInstance(irClass)
val privateInstanceField = context.declarationFactory.getPrivateFieldForObjectInstance(irClass) val privateInstanceField = context.cachedDeclarations.getPrivateFieldForObjectInstance(irClass)
val constructor = irClass.constructors.find { it.isPrimary } val constructor = irClass.constructors.find { it.isPrimary }
?: throw AssertionError("Object should have a primary constructor: ${irClass.name}") ?: throw AssertionError("Object should have a primary constructor: ${irClass.name}")
@@ -46,7 +46,7 @@ private class SingletonReferencesLowering(val context: JvmBackendContext) : File
// must be replaced with `SomeEnumEntry.this`. // must be replaced with `SomeEnumEntry.this`.
IrGetValueImpl(expression.startOffset, expression.endOffset, expression.type, appropriateThis.symbol) IrGetValueImpl(expression.startOffset, expression.endOffset, expression.type, appropriateThis.symbol)
} else { } 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) 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) return IrGetValueImpl(expression.startOffset, expression.endOffset, it.symbol)
} }
val instanceField = if (allScopes.any { it.irElement == expression.symbol.owner }) 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 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) return IrGetFieldImpl(expression.startOffset, expression.endOffset, instanceField.symbol, expression.type)
} }