diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalFunctionsLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalFunctionsLowering.kt index b6b504774e4..119792e4ed5 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalFunctionsLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/LocalFunctionsLowering.kt @@ -38,7 +38,6 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.resolve.descriptorUtil.parents import org.jetbrains.kotlin.resolve.descriptorUtil.parentsWithSelf import org.jetbrains.kotlin.types.KotlinType import java.util.* @@ -154,14 +153,14 @@ class LocalFunctionsLowering(val context: BackendContext): DeclarationContainerL return this } - override fun visitCallableReference(expression: IrCallableReference): IrExpression { + override fun visitFunctionReference(expression: IrFunctionReference): IrExpression { expression.transformChildrenVoid(this) val oldCallee = expression.descriptor.original val localFunctionData = localFunctions[oldCallee] ?: return expression val newCallee = localFunctionData.transformedDescriptor - val newCallableReference = IrCallableReferenceImpl( + val newCallableReference = IrFunctionReferenceImpl( expression.startOffset, expression.endOffset, expression.type, // TODO functional type for transformed descriptor newCallee, @@ -179,7 +178,9 @@ class LocalFunctionsLowering(val context: BackendContext): DeclarationContainerL val localFunctionData = localFunctions[oldReturnTarget] ?: return expression val newReturnTarget = localFunctionData.transformedDescriptor - return IrReturnImpl(expression.startOffset, expression.endOffset, newReturnTarget, expression.value) + return IrReturnImpl(expression.startOffset, expression.endOffset, + newReturnTarget, + expression.value) } } @@ -196,15 +197,17 @@ class LocalFunctionsLowering(val context: BackendContext): DeclarationContainerL } private fun createNewCall(oldCall: IrCall, newCallee: FunctionDescriptor) = - if (oldCall is IrCallWithShallowCopy) - oldCall.shallowCopy(oldCall.origin, newCallee, oldCall.superQualifier) - else - IrCallImpl( - oldCall.startOffset, oldCall.endOffset, - newCallee, - remapTypeArguments(oldCall, newCallee), - oldCall.origin, oldCall.superQualifier - ) + when (oldCall) { + is IrCallWithShallowCopy -> + oldCall.shallowCopy(oldCall.origin, newCallee, oldCall.superQualifier) + else -> + IrCallImpl( + oldCall.startOffset, oldCall.endOffset, + newCallee, + remapTypeArguments(oldCall, newCallee), + oldCall.origin, oldCall.superQualifier + ) + } private fun remapTypeArguments(oldExpression: IrMemberAccessExpression, newCallee: FunctionDescriptor): Map? { val oldCallee = oldExpression.descriptor diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt index d4d97a08b82..33200c66126 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt @@ -193,12 +193,14 @@ class BridgeLowering(val state: GenerationState) : ClassLoweringPass { //TODO: rewrite //here some 'isSpecialBridge' magic (see type special descriptor processing in KotlinTypeMapper) val implementation = if (isSpecialBridge) delegateTo.descriptor.copyAsDeclaration() else delegateTo.descriptor - val call = IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, implementation.returnType!!, implementation, null, JvmLoweredStatementOrigin.BRIDGE_DELEGATION, null) + val call = IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, + implementation, + null, JvmLoweredStatementOrigin.BRIDGE_DELEGATION, null) call.dispatchReceiver = IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, containingClass.thisAsReceiverParameter, JvmLoweredStatementOrigin.BRIDGE_DELEGATION) newDescriptor.valueParameters.mapIndexed { i, valueParameterDescriptor -> call.putValueArgument(i, IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, valueParameterDescriptor, JvmLoweredStatementOrigin.BRIDGE_DELEGATION)) } - irBody.statements.add(IrReturnImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, newDescriptor.returnType!!, newDescriptor, call)) + irBody.statements.add(IrReturnImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, newDescriptor, call)) return irFunction } diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt index 3cff76917ad..3fc2b6efeda 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/EnumClassLowering.kt @@ -26,7 +26,6 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.impl.ClassConstructorDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl -import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.declarations.* diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InitializersLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InitializersLowering.kt index 1e583ef1d8d..8c0edc3f082 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InitializersLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InitializersLowering.kt @@ -37,7 +37,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl import org.jetbrains.kotlin.ir.expressions.impl.IrBlockImpl import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl import org.jetbrains.kotlin.ir.expressions.impl.IrSetFieldImpl -import org.jetbrains.kotlin.ir.util.DeepCopyIrTree +import org.jetbrains.kotlin.ir.util.deepCopy import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid @@ -127,9 +127,7 @@ class InitializersLowering(val context: JvmBackendContext) : ClassLoweringPass { companion object { val clinitName = Name.special("") - val deepCopyVisitor = DeepCopyIrTree() - - fun IrStatement.copy() = transform(deepCopyVisitor, null) - fun IrExpression.copy() = transform(deepCopyVisitor, null) + fun IrStatement.copy() = deepCopy() + fun IrExpression.copy() = deepCopy() } } \ No newline at end of file diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceDelegationLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceDelegationLowering.kt index f7b682aefa9..37c4ccbf231 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceDelegationLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InterfaceDelegationLowering.kt @@ -18,11 +18,9 @@ package org.jetbrains.kotlin.backend.jvm.lower import org.jetbrains.kotlin.backend.common.ClassLoweringPass import org.jetbrains.kotlin.backend.common.CodegenUtil -import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin import org.jetbrains.kotlin.backend.jvm.JvmLoweredStatementOrigin import org.jetbrains.kotlin.backend.jvm.descriptors.DefaultImplsClassDescriptor import org.jetbrains.kotlin.backend.jvm.descriptors.DefaultImplsClassDescriptorImpl -import org.jetbrains.kotlin.codegen.JvmCodegenUtil import org.jetbrains.kotlin.codegen.isDefinitelyNotDefaultImplsMethod import org.jetbrains.kotlin.codegen.state.GenerationState import org.jetbrains.kotlin.descriptors.ClassDescriptor @@ -31,7 +29,10 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl -import org.jetbrains.kotlin.ir.expressions.impl.* +import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid import org.jetbrains.kotlin.resolve.DescriptorUtils @@ -76,8 +77,8 @@ class InterfaceDelegationLowering(val state: GenerationState) : IrElementTransfo val defaultImpls = InterfaceLowering.createDefaultImplsClassDescriptor(interfaceDescriptor) val defaultImplFun = InterfaceLowering.createDefaultImplFunDescriptor(defaultImpls, interfaceFun.original, interfaceDescriptor, state.typeMapper) val returnType = inheritedFun.returnType!! - val irCallImpl = IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, returnType, defaultImplFun, null, JvmLoweredStatementOrigin.DEFAULT_IMPLS_DELEGATION) - irBody.statements.add(IrReturnImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, returnType, inheritedFun, irCallImpl)) + val irCallImpl = IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, defaultImplFun, null, JvmLoweredStatementOrigin.DEFAULT_IMPLS_DELEGATION) + irBody.statements.add(IrReturnImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, inheritedFun, irCallImpl)) var shift = 0 if (inheritedFun.dispatchReceiverParameter != null) { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt index 4fd837b93f6..9afd026d399 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/SyntheticAccessorLowering.kt @@ -140,7 +140,7 @@ class SyntheticAccessorLowering(val state: GenerationState) : FileLoweringPass, accessorDescriptor, body ) val calleeDescriptor = accessor.calleeDescriptor - val returnExpr = IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, calleeDescriptor.returnType!!, calleeDescriptor, emptyMap()) + val returnExpr = IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, calleeDescriptor) copyAllArgsToValueParams(returnExpr, accessorDescriptor) body.statements.add(IrReturnImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, accessor, returnExpr)) data.irClass.declarations.add(syntheticFunction) @@ -158,8 +158,7 @@ class SyntheticAccessorLowering(val state: GenerationState) : FileLoweringPass, if (accessor is AccessorForCallableDescriptor<*> && descriptor !is AccessorForCallableDescriptor<*>) { val accessorOwner = accessor.containingDeclaration as ClassOrPackageFragmentDescriptor val staticAccessor = descriptor.toStatic(accessorOwner, Name.identifier(state.typeMapper.mapAsmMethod(accessor as FunctionDescriptor).name)) //TODO change call - val call = IrCallImpl(expression.startOffset, expression.endOffset, expression.descriptor.returnType!!, staticAccessor, emptyMap(), - expression.origin/*TODO super*/) + val call = IrCallImpl(expression.startOffset, expression.endOffset, staticAccessor, emptyMap(), expression.origin/*TODO super*/) //copyAllArgsToValueParams(call, expression) expression.receiverAndArgs().forEachIndexed { i, irExpression -> call.putValueArgument(i, irExpression) diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/IrUtils.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/IrUtils.kt index 30bf3d91d4c..70050272233 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/IrUtils.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/IrUtils.kt @@ -21,5 +21,5 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl fun IrVariable.defaultLoad(): IrExpression = - IrGetValueImpl(startOffset, endOffset, descriptor) + IrGetValueImpl(startOffset, endOffset, symbol) diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt index 39d6a7fbf9f..92bdf3a12a1 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt @@ -56,7 +56,8 @@ fun StatementGenerator.generateReceiver(startOffset: Int, endOffset: Int, receiv if (shouldGenerateReceiverAsSingletonReference(receiverClassDescriptor)) generateSingletonReference(receiverClassDescriptor, startOffset, endOffset, receiver.type) else - IrGetValueImpl(startOffset, endOffset, receiverClassDescriptor.thisAsReceiverParameter) + IrGetValueImpl(startOffset, endOffset, + context.symbolTable.referenceValueParameter(receiverClassDescriptor.thisAsReceiverParameter)) } is ThisClassReceiver -> generateThisOrSuperReceiver(receiver, receiver.classDescriptor) @@ -66,9 +67,10 @@ fun StatementGenerator.generateReceiver(startOffset: Int, endOffset: Int, receiv generateExpression(receiver.expression) is ClassValueReceiver -> IrGetObjectValueImpl(receiver.expression.startOffset, receiver.expression.endOffset, receiver.type, - receiver.classQualifier.descriptor as ClassDescriptor) + context.symbolTable.referenceClass(receiver.classQualifier.descriptor as ClassDescriptor)) is ExtensionReceiver -> - IrGetValueImpl(startOffset, startOffset, receiver.declarationDescriptor.extensionReceiverParameter!!) + IrGetValueImpl(startOffset, startOffset, + context.symbolTable.referenceValueParameter(receiver.declarationDescriptor.extensionReceiverParameter!!)) else -> TODO("Receiver: ${receiver::class.java.simpleName}") } @@ -79,16 +81,19 @@ fun StatementGenerator.generateReceiver(startOffset: Int, endOffset: Int, receiv OnceExpressionValue(receiverExpression) } -fun generateSingletonReference(descriptor: ClassDescriptor, startOffset: Int, endOffset: Int, type: KotlinType): IrDeclarationReference = +fun StatementGenerator.generateSingletonReference(descriptor: ClassDescriptor, startOffset: Int, endOffset: Int, type: KotlinType): IrDeclarationReference = when { DescriptorUtils.isObject(descriptor) -> - IrGetObjectValueImpl(startOffset, endOffset, type, descriptor) + IrGetObjectValueImpl(startOffset, endOffset, type, + context.symbolTable.referenceClass(descriptor)) DescriptorUtils.isEnumEntry(descriptor) -> - IrGetEnumValueImpl(startOffset, endOffset, type, descriptor) + IrGetEnumValueImpl(startOffset, endOffset, type, + context.symbolTable.referenceEnumEntry(descriptor)) else -> { val companionObjectDescriptor = descriptor.companionObjectDescriptor ?: throw java.lang.AssertionError("Class value without companion object: $descriptor") - IrGetObjectValueImpl(startOffset, endOffset, type, companionObjectDescriptor) + IrGetObjectValueImpl(startOffset, endOffset, type, + context.symbolTable.referenceClass(companionObjectDescriptor)) } } @@ -98,11 +103,12 @@ private fun StatementGenerator.shouldGenerateReceiverAsSingletonReference(receiv this.scopeOwner.containingDeclaration != receiverClassDescriptor } -private fun generateThisOrSuperReceiver(receiver: ReceiverValue, classDescriptor: ClassDescriptor): IrExpression { +private fun StatementGenerator.generateThisOrSuperReceiver(receiver: ReceiverValue, classDescriptor: ClassDescriptor): IrExpression { val expressionReceiver = receiver as? ExpressionReceiver ?: throw AssertionError("'this' or 'super' receiver should be an expression receiver") val ktReceiver = expressionReceiver.expression - return IrGetValueImpl(ktReceiver.startOffset, ktReceiver.endOffset, classDescriptor.thisAsReceiverParameter) + return IrGetValueImpl(ktReceiver.startOffset, ktReceiver.endOffset, + context.symbolTable.referenceValueParameter(classDescriptor.thisAsReceiverParameter)) } fun StatementGenerator.generateBackingFieldReceiver( @@ -158,7 +164,7 @@ fun StatementGenerator.generateCallReceiver( } } -private fun generateReceiverForCalleeImportedFromObject( +private fun StatementGenerator.generateReceiverForCalleeImportedFromObject( startOffset: Int, endOffset: Int, calleeDescriptor: ImportedFromObjectCallableDescriptor<*> @@ -166,7 +172,8 @@ private fun generateReceiverForCalleeImportedFromObject( val objectDescriptor = calleeDescriptor.containingObject val objectType = objectDescriptor.defaultType return generateExpressionValue(objectType) { - IrGetObjectValueImpl(startOffset, endOffset, objectType, objectDescriptor) + IrGetObjectValueImpl(startOffset, endOffset, objectType, + context.symbolTable.referenceClass(objectDescriptor)) } } diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/AssignmentGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/AssignmentGenerator.kt index 4885061fec9..78d973556f3 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/AssignmentGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/AssignmentGenerator.kt @@ -19,8 +19,8 @@ package org.jetbrains.kotlin.psi2ir.generators import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor -import org.jetbrains.kotlin.ir.builders.defineTemporary import org.jetbrains.kotlin.ir.builders.irGet +import org.jetbrains.kotlin.ir.builders.irTemporary import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl @@ -32,6 +32,7 @@ import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.callUtil.isSafeCall import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.scopes.receivers.ThisClassReceiver +import org.jetbrains.kotlin.types.KotlinType class AssignmentGenerator(statementGenerator: StatementGenerator) : StatementGeneratorExtension(statementGenerator) { fun generateAssignment(expression: KtBinaryExpression): IrExpression { @@ -88,12 +89,12 @@ class AssignmentGenerator(statementGenerator: StatementGenerator) : StatementGen return irAssignmentReceiver.assign { irLValue -> irBlock(expression, origin, irLValue.type) { - val temporary = defineTemporary(irLValue.load()) + val temporary = irTemporary(irLValue.load()) val opCall = statementGenerator.pregenerateCall(opResolvedCall) - opCall.setExplicitReceiverValue(VariableLValue(startOffset, endOffset, temporary)) + opCall.setExplicitReceiverValue(VariableLValue(startOffset, endOffset, temporary.symbol)) val irOpCall = CallGenerator(statementGenerator).generateCall(expression, opCall, origin) +irLValue.store(irOpCall) - +irGet(temporary) + +irGet(temporary.symbol) } } } @@ -109,23 +110,50 @@ class AssignmentGenerator(statementGenerator: StatementGenerator) : StatementGen return when (descriptor) { is SyntheticFieldDescriptor -> { val receiverValue = statementGenerator.generateBackingFieldReceiver(ktLeft.startOffset, ktLeft.endOffset, resolvedCall, descriptor) - BackingFieldLValue(ktLeft.startOffset, ktLeft.endOffset, descriptor.propertyDescriptor, receiverValue, origin) + createBackingFieldLValue(ktLeft, descriptor.propertyDescriptor, receiverValue, origin) } is LocalVariableDescriptor -> @Suppress("DEPRECATION") if (descriptor.isDelegated) - DelegatedLocalPropertyLValue(ktLeft.startOffset, ktLeft.endOffset, descriptor, origin) + DelegatedLocalPropertyLValue( + ktLeft.startOffset, ktLeft.endOffset, + descriptor.type, + descriptor.getter?.let { context.symbolTable.referenceDeclaredFunction(it) }, + descriptor.setter?.let { context.symbolTable.referenceDeclaredFunction(it) }, + origin + ) else - VariableLValue(ktLeft.startOffset, ktLeft.endOffset, descriptor, origin) + VariableLValue( + ktLeft.startOffset, ktLeft.endOffset, + context.symbolTable.referenceVariable(descriptor), + origin + ) is PropertyDescriptor -> generateAssignmentReceiverForProperty(descriptor, origin, ktLeft, resolvedCall) - is VariableDescriptor -> - VariableLValue(ktLeft.startOffset, ktLeft.endOffset, descriptor, origin) + is ValueDescriptor -> + VariableLValue( + ktLeft.startOffset, ktLeft.endOffset, + context.symbolTable.referenceValue(descriptor), + origin + ) else -> OnceExpressionValue(statementGenerator.generateExpression(ktLeft)) } } + private fun createBackingFieldLValue( + ktExpression: KtExpression, + descriptor: PropertyDescriptor, + receiverValue: IntermediateValue?, + origin: IrStatementOrigin? + ): BackingFieldLValue = + BackingFieldLValue( + ktExpression.startOffset, ktExpression.endOffset, + descriptor.type, + context.symbolTable.referenceField(descriptor), + receiverValue, origin + ) + private fun generateAssignmentReceiverForProperty( descriptor: PropertyDescriptor, origin: IrStatementOrigin, @@ -134,10 +162,11 @@ class AssignmentGenerator(statementGenerator: StatementGenerator) : StatementGen ): AssignmentReceiver = if (isValInitializationInConstructor(descriptor, resolvedCall)) { val thisClass = getThisClass() - val irThis = IrGetValueImpl(ktLeft.startOffset, ktLeft.endOffset, thisClass.thisAsReceiverParameter) - - BackingFieldLValue(ktLeft.startOffset, ktLeft.endOffset, descriptor, - RematerializableValue(irThis), null) + val irThis = IrGetValueImpl( + ktLeft.startOffset, ktLeft.endOffset, + context.symbolTable.referenceValueParameter(thisClass.thisAsReceiverParameter) + ) + createBackingFieldLValue(ktLeft, descriptor, RematerializableValue(irThis), null) } else { val propertyReceiver = statementGenerator.generateCallReceiver( @@ -147,10 +176,43 @@ class AssignmentGenerator(statementGenerator: StatementGenerator) : StatementGen val superQualifier = getSuperQualifier(resolvedCall) - SimplePropertyLValue(context, scope, ktLeft.startOffset, ktLeft.endOffset, origin, descriptor, - getTypeArguments(resolvedCall), propertyReceiver, superQualifier) + createPropertyLValue(ktLeft, descriptor, propertyReceiver, getTypeArguments(resolvedCall), origin, superQualifier) } + private fun createPropertyLValue( + ktExpression: KtExpression, + descriptor: PropertyDescriptor, + propertyReceiver: CallReceiver, + typeArguments: Map?, + origin: IrStatementOrigin?, + superQualifier: ClassDescriptor? + ): PropertyLValueBase { + val superQualifierSymbol = superQualifier?.let { context.symbolTable.referenceClass(it) } + + val getterSymbol = descriptor.getter?.let { context.symbolTable.referenceFunction(it) } + val setterSymbol = descriptor.setter?.let { context.symbolTable.referenceFunction(it) } + return if (getterSymbol != null || setterSymbol != null) { + AccessorPropertyLValue( + scope, + ktExpression.startOffset, ktExpression.endOffset, origin, + descriptor.type, + getterSymbol, + setterSymbol, + typeArguments, + propertyReceiver, + superQualifierSymbol + ) + } + else + FieldPropertyLValue( + scope, + ktExpression.startOffset, ktExpression.endOffset, origin, + context.symbolTable.referenceField(descriptor), + propertyReceiver, + superQualifierSymbol + ) + } + private fun isValInitializationInConstructor(descriptor: PropertyDescriptor, resolvedCall: ResolvedCall<*>): Boolean = !descriptor.isVar && descriptor.kind != CallableMemberDescriptor.Kind.FAKE_OVERRIDE && diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BodyGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BodyGenerator.kt index eaac1f16973..1eb5920776a 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BodyGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BodyGenerator.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.builders.Scope import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* +import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset @@ -28,11 +29,17 @@ import org.jetbrains.kotlin.psi2ir.intermediate.VariableLValue import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.descriptorUtil.getSuperClassOrAny +import org.jetbrains.kotlin.resolve.descriptorUtil.hasDefaultValue import java.lang.AssertionError import java.util.* -class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context: GeneratorContext) : GeneratorWithScope { - override val scope = Scope(scopeOwner) +class BodyGenerator( + val scopeOwnerSymbol: IrSymbol, + override val context: GeneratorContext +) : GeneratorWithScope { + val scopeOwner: DeclarationDescriptor get() = scopeOwnerSymbol.descriptor + + override val scope = Scope(scopeOwnerSymbol) private val loopTable = HashMap() fun generateFunctionBody(ktBody: KtExpression): IrBody { @@ -62,7 +69,8 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context: val ktDestructuringDeclaration = ktParameter.destructuringDeclaration ?: continue val valueParameter = getOrFail(BindingContext.VALUE_PARAMETER, ktParameter) val parameterValue = VariableLValue(ktDestructuringDeclaration.startOffset, ktDestructuringDeclaration.endOffset, - valueParameter, IrStatementOrigin.DESTRUCTURING_DECLARATION) + context.symbolTable.referenceValue(valueParameter), + IrStatementOrigin.DESTRUCTURING_DECLARATION) statementGenerator.declareComponentVariablesInBlock(ktDestructuringDeclaration, irBlockBody, parameterValue) } @@ -78,7 +86,8 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context: else { irBlockBody.statements.add(generateReturnExpression( ktBody.startOffset, ktBody.endOffset, - IrGetObjectValueImpl(ktBody.startOffset, ktBody.endOffset, context.builtIns.unitType, context.builtIns.unit))) + IrGetObjectValueImpl(ktBody.startOffset, ktBody.endOffset, context.builtIns.unitType, + context.symbolTable.referenceClass(context.builtIns.unit)))) } } @@ -111,7 +120,9 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context: private fun generateReturnExpression(startOffset: Int, endOffset: Int, returnValue: IrExpression): IrReturnImpl { val returnTarget = (scopeOwner as? CallableDescriptor) ?: throw AssertionError("'return' in a non-callable: $scopeOwner") - return IrReturnImpl(startOffset, endOffset, context.builtIns.nothingType, returnTarget, returnValue) + return IrReturnImpl(startOffset, endOffset, context.builtIns.nothingType, + context.symbolTable.referenceFunction(returnTarget), + returnValue) } @@ -166,7 +177,8 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context: generateSuperConstructorCall(irBlockBody, ktClassOrObject) val classDescriptor = (scopeOwner as ClassConstructorDescriptor).containingDeclaration - irBlockBody.statements.add(IrInstanceInitializerCallImpl(ktClassOrObject.startOffset, ktClassOrObject.endOffset, classDescriptor)) + irBlockBody.statements.add(IrInstanceInitializerCallImpl(ktClassOrObject.startOffset, ktClassOrObject.endOffset, + context.symbolTable.referenceClass(classDescriptor))) return irBlockBody } @@ -177,7 +189,8 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context: generateDelegatingConstructorCall(irBlockBody, ktConstructor) val classDescriptor = getOrFail(BindingContext.CONSTRUCTOR, ktConstructor).containingDeclaration as ClassDescriptor - irBlockBody.statements.add(IrInstanceInitializerCallImpl(ktConstructor.startOffset, ktConstructor.endOffset, classDescriptor)) + irBlockBody.statements.add(IrInstanceInitializerCallImpl(ktConstructor.startOffset, ktConstructor.endOffset, + context.symbolTable.referenceClass(classDescriptor))) ktConstructor.bodyExpression?.let { ktBody -> createStatementGenerator().generateBlockBodyStatements(irBlockBody, ktBody) @@ -222,12 +235,23 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context: private fun generateAnySuperConstructorCall(irBlockBody: IrBlockBodyImpl, ktElement: KtElement) { val anyConstructor = context.builtIns.any.constructors.single() - irBlockBody.statements.add(IrDelegatingConstructorCallImpl(ktElement.startOffset, ktElement.endOffset, anyConstructor, null)) + irBlockBody.statements.add( + IrDelegatingConstructorCallImpl( + ktElement.startOffset, ktElement.endOffset, + context.symbolTable.referenceConstructor(anyConstructor), + null + ) + ) } private fun generateEnumSuperConstructorCall(irBlockBody: IrBlockBodyImpl, ktElement: KtElement) { val enumConstructor = context.builtIns.enum.constructors.single() - irBlockBody.statements.add(IrEnumConstructorCallImpl(ktElement.startOffset, ktElement.endOffset, enumConstructor)) + irBlockBody.statements.add( + IrEnumConstructorCallImpl( + ktElement.startOffset, ktElement.endOffset, + context.symbolTable.referenceConstructor(enumConstructor) + ) + ) } private fun generateEnumEntrySuperConstructorCall(ktEnumEntry: KtEnumEntry, enumEntryDescriptor: ClassDescriptor): IrExpression { @@ -249,7 +273,10 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context: fun generateEnumEntryInitializer(ktEnumEntry: KtEnumEntry, enumEntryDescriptor: ClassDescriptor): IrExpression { if (ktEnumEntry.declarations.isNotEmpty()) { val enumEntryConstructor = enumEntryDescriptor.unsubstitutedPrimaryConstructor!! - return IrEnumConstructorCallImpl(ktEnumEntry.startOffset, ktEnumEntry.endOffset, enumEntryConstructor) + return IrEnumConstructorCallImpl( + ktEnumEntry.startOffset, ktEnumEntry.endOffset, + context.symbolTable.referenceConstructor(enumEntryConstructor) + ) } return generateEnumConstructorCallOrSuperCall(ktEnumEntry, enumEntryDescriptor.containingDeclaration as ClassDescriptor) @@ -265,7 +292,6 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context: val ktSuperCallElement = ktEnumEntry.superTypeListEntries.firstOrNull() if (ktSuperCallElement != null) { return statementGenerator.generateEnumConstructorCall(getResolvedCall(ktSuperCallElement)!!, ktEnumEntry) - } val enumDefaultConstructorCall = getResolvedCall(ktEnumEntry) @@ -273,9 +299,16 @@ class BodyGenerator(val scopeOwner: DeclarationDescriptor, override val context: return statementGenerator.generateEnumConstructorCall(enumDefaultConstructorCall, ktEnumEntry) } - // No-argument enum entry constructor - val enumClassConstructor = enumClassDescriptor.constructors.find { it.valueParameters.isEmpty() }!! - return IrEnumConstructorCallImpl(ktEnumEntry.startOffset, ktEnumEntry.endOffset, enumClassConstructor) + // Default enum entry constructor + val enumClassConstructor = + enumClassDescriptor.constructors.singleOrNull { + it.valueParameters.isEmpty() || + it.valueParameters.all { it.hasDefaultValue() } + } ?: throw AssertionError("Enum class $enumClassDescriptor should have a default constructor") + return IrEnumConstructorCallImpl( + ktEnumEntry.startOffset, ktEnumEntry.endOffset, + context.symbolTable.referenceConstructor(enumClassConstructor) + ) } private fun StatementGenerator.generateEnumConstructorCall(constructorCall: ResolvedCall, ktEnumEntry: KtEnumEntry) = diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BranchingExpressionGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BranchingExpressionGenerator.kt index 498c39f7399..6970bc7c773 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BranchingExpressionGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/BranchingExpressionGenerator.kt @@ -128,7 +128,7 @@ class BranchingExpressionGenerator(statementGenerator: StatementGenerator) : Sta java.lang.Boolean.TRUE == bindingContext.get(BindingContext.EXHAUSTIVE_WHEN, whenExpression) if (isExhaustive) { - val call = IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, context.irBuiltIns.noWhenBranchMatchedException) + val call = IrCallImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, context.irBuiltIns.noWhenBranchMatchedExceptionSymbol) irWhen.branches.add(IrBranchImpl.elseBranch(call)) } } @@ -186,9 +186,14 @@ class BranchingExpressionGenerator(statementGenerator: StatementGenerator) : Sta val inOperator = getInfixOperator(ktCondition.operationReference.getReferencedNameElementType()) val irInCall = CallGenerator(statementGenerator).generateCall(ktCondition, inCall, inOperator) return when (inOperator) { - IrStatementOrigin.IN -> irInCall + IrStatementOrigin.IN -> + irInCall IrStatementOrigin.NOT_IN -> - IrUnaryPrimitiveImpl(ktCondition.startOffset, ktCondition.endOffset, IrStatementOrigin.EXCL, context.irBuiltIns.booleanNot, irInCall) + IrUnaryPrimitiveImpl( + ktCondition.startOffset, ktCondition.endOffset, + IrStatementOrigin.EXCL, context.irBuiltIns.booleanNotSymbol, + irInCall + ) else -> throw AssertionError("Expected 'in' or '!in', got $inOperator") } } @@ -196,7 +201,7 @@ class BranchingExpressionGenerator(statementGenerator: StatementGenerator) : Sta private fun generateEqualsCondition(irSubject: IrVariable, ktCondition: KtWhenConditionWithExpression): IrBinaryPrimitiveImpl = IrBinaryPrimitiveImpl( ktCondition.startOffset, ktCondition.endOffset, - IrStatementOrigin.EQEQ, context.irBuiltIns.eqeq, + IrStatementOrigin.EQEQ, context.irBuiltIns.eqeqSymbol, irSubject.defaultLoad(), statementGenerator.generateExpression(ktCondition.expression!!) ) } \ No newline at end of file diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/CallGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/CallGenerator.kt index 7cc709f519d..2baaee697ea 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/CallGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/CallGenerator.kt @@ -20,14 +20,13 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor import org.jetbrains.kotlin.ir.expressions.IrExpression -import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression +import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin import org.jetbrains.kotlin.ir.expressions.impl.* import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.psi2ir.intermediate.* -import org.jetbrains.kotlin.resolve.DescriptorUtils import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall import org.jetbrains.kotlin.resolve.calls.model.ResolvedValueArgument import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject @@ -66,14 +65,15 @@ class CallGenerator(statementGenerator: StatementGenerator): StatementGeneratorE generateValueReference(startOffset, endOffset, descriptor.classDescriptor!!, null, origin) is ClassDescriptor -> { val classValueType = descriptor.classValueType!! - generateSingletonReference(descriptor, startOffset, endOffset, classValueType) + statementGenerator.generateSingletonReference(descriptor, startOffset, endOffset, classValueType) } is PropertyDescriptor -> { generateCall(startOffset, endOffset, statementGenerator.pregenerateCall(resolvedCall!!)) } is SyntheticFieldDescriptor -> { val receiver = statementGenerator.generateBackingFieldReceiver(startOffset, endOffset, resolvedCall, descriptor) - IrGetFieldImpl(startOffset, endOffset, descriptor.propertyDescriptor, receiver?.load()) + val field = statementGenerator.context.symbolTable.referenceField(descriptor.propertyDescriptor) + IrGetFieldImpl(startOffset, endOffset, field, receiver?.load()) } is VariableDescriptor -> generateGetVariable(startOffset, endOffset, descriptor, getTypeArguments(resolvedCall), origin) @@ -89,22 +89,23 @@ class CallGenerator(statementGenerator: StatementGenerator): StatementGeneratorE origin: IrStatementOrigin? = null ) = @Suppress("DEPRECATION") - if (descriptor is LocalVariableDescriptor && descriptor.isDelegated) - IrCallImpl(startOffset, endOffset, descriptor.type, descriptor.getter!!, typeArguments, origin ?: IrStatementOrigin.GET_LOCAL_PROPERTY) + if (descriptor is LocalVariableDescriptor && descriptor.isDelegated) { + val getter = context.symbolTable.referenceFunction(descriptor.getter!!) + IrCallImpl(startOffset, endOffset, descriptor.type, getter, typeArguments, origin ?: IrStatementOrigin.GET_LOCAL_PROPERTY) + } else - IrGetValueImpl(startOffset, endOffset, descriptor, origin) + IrGetValueImpl(startOffset, endOffset, context.symbolTable.referenceValue(descriptor), origin) - fun generateDelegatingConstructorCall(startOffset: Int, endOffset: Int, call: CallBuilder) : IrExpression { - val descriptor = call.descriptor as? ClassConstructorDescriptor - ?: throw AssertionError("Class constructor expected: ${call.descriptor}") - - return call.callReceiver.call { dispatchReceiver, extensionReceiver -> - val irCall = IrDelegatingConstructorCallImpl(startOffset, endOffset, descriptor, getTypeArguments(call.original)) - irCall.dispatchReceiver = dispatchReceiver?.load() - irCall.extensionReceiver = extensionReceiver?.load() - addParametersToCall(startOffset, endOffset, call, irCall, descriptor.builtIns.unitType) - } - } + fun generateDelegatingConstructorCall(startOffset: Int, endOffset: Int, call: CallBuilder) : IrExpression = + call.callReceiver.call { dispatchReceiver, extensionReceiver -> + val descriptor = call.descriptor as? ClassConstructorDescriptor + ?: throw AssertionError("Class constructor expected: ${call.descriptor}") + val constructorSymbol = context.symbolTable.referenceConstructor(descriptor) + val irCall = IrDelegatingConstructorCallImpl(startOffset, endOffset, constructorSymbol, getTypeArguments(call.original)) + irCall.dispatchReceiver = dispatchReceiver?.load() + irCall.extensionReceiver = extensionReceiver?.load() + addParametersToCall(startOffset, endOffset, call, irCall, descriptor.builtIns.unitType) + } fun generateEnumConstructorSuperCall(startOffset: Int, endOffset: Int, call: CallBuilder) : IrExpression { val constructorDescriptor = call.descriptor @@ -115,7 +116,8 @@ class CallGenerator(statementGenerator: StatementGenerator): StatementGeneratorE return call.callReceiver.call { dispatchReceiver, extensionReceiver -> if (dispatchReceiver != null) throw AssertionError("Dispatch receiver should be null: $dispatchReceiver") if (extensionReceiver != null) throw AssertionError("Extension receiver should be null: $extensionReceiver") - val irCall = IrEnumConstructorCallImpl(startOffset, endOffset, constructorDescriptor) + val constructorSymbol = context.symbolTable.referenceConstructor(constructorDescriptor) + val irCall = IrEnumConstructorCallImpl(startOffset, endOffset, constructorSymbol) addParametersToCall(startOffset, endOffset, call, irCall, constructorDescriptor.returnType) } } @@ -127,16 +129,31 @@ class CallGenerator(statementGenerator: StatementGenerator): StatementGeneratorE call: CallBuilder ): IrExpression { return call.callReceiver.call { dispatchReceiverValue, extensionReceiverValue -> - descriptor.getter?.let { getter -> - IrGetterCallImpl(startOffset, endOffset, getter, - getTypeArguments(call.original), - dispatchReceiverValue?.load(), - extensionReceiverValue?.load(), - IrStatementOrigin.GET_PROPERTY, - call.superQualifier) - } ?: IrGetFieldImpl(startOffset, endOffset, descriptor, - dispatchReceiverValue?.load(), - IrStatementOrigin.GET_PROPERTY, call.superQualifier) + val superQualifierSymbol = call.superQualifier?.let { context.symbolTable.referenceClass(it) } + + val getterDescriptor = descriptor.getter + if (getterDescriptor != null) { + val getterSymbol = context.symbolTable.referenceFunction(getterDescriptor) + IrGetterCallImpl( + startOffset, endOffset, + getterSymbol, + getTypeArguments(call.original), + dispatchReceiverValue?.load(), + extensionReceiverValue?.load(), + IrStatementOrigin.GET_PROPERTY, + superQualifierSymbol + ) + } + else { + val fieldSymbol = context.symbolTable.referenceField(descriptor) + IrGetFieldImpl( + startOffset, endOffset, + fieldSymbol, + dispatchReceiverValue?.load(), + IrStatementOrigin.GET_PROPERTY, + superQualifierSymbol + ) + } } } @@ -146,19 +163,26 @@ class CallGenerator(statementGenerator: StatementGenerator): StatementGeneratorE endOffset: Int, origin: IrStatementOrigin?, call: CallBuilder - ): IrExpression { - val returnType = descriptor.returnType!! + ): IrExpression = + call.callReceiver.call { dispatchReceiverValue, extensionReceiverValue -> + val returnType = descriptor.returnType!! + val functionSymbol = context.symbolTable.referenceFunction(descriptor) + val superQualifierSymbol = call.superQualifier?.let { context.symbolTable.referenceClass(it) } + val irCall = IrCallImpl( + startOffset, endOffset, + returnType, + functionSymbol, + getTypeArguments(call.original), + origin, + superQualifierSymbol + ) + irCall.dispatchReceiver = dispatchReceiverValue?.load() + irCall.extensionReceiver = extensionReceiverValue?.load() - return call.callReceiver.call { dispatchReceiverValue, extensionReceiverValue -> - val irCall = IrCallImpl(startOffset, endOffset, returnType, descriptor, getTypeArguments(call.original), origin, call.superQualifier) - irCall.dispatchReceiver = dispatchReceiverValue?.load() - irCall.extensionReceiver = extensionReceiverValue?.load() + addParametersToCall(startOffset, endOffset, call, irCall, returnType) + } - addParametersToCall(startOffset, endOffset, call, irCall, returnType) - } - } - - private fun addParametersToCall(startOffset: Int, endOffset: Int, call: CallBuilder, irCall: IrCallWithIndexedArgumentsBase, returnType: KotlinType): IrExpression = + private fun addParametersToCall(startOffset: Int, endOffset: Int, call: CallBuilder, irCall: IrFunctionAccessExpression, returnType: KotlinType): IrExpression = if (call.isValueArgumentReorderingRequired()) { generateCallWithArgumentReordering(irCall, startOffset, endOffset, call, returnType) } @@ -171,7 +195,7 @@ class CallGenerator(statementGenerator: StatementGenerator): StatementGeneratorE } private fun generateCallWithArgumentReordering( - irCall: IrMemberAccessExpression, + irCall: IrFunctionAccessExpression, startOffset: Int, endOffset: Int, call: CallBuilder, diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt index e738d1862a6..f5298d4d7c7 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ClassGenerator.kt @@ -48,11 +48,20 @@ class ClassGenerator(declarationGenerator: DeclarationGenerator) : DeclarationGe IrDeclarationOrigin.DEFINED, descriptor ).buildWithScope { irClass -> + if (irClass.descriptor.canHaveInitializersWithInstanceReference()) { + irClass.newInstanceReceiver = context.symbolTable.declareValueParameter( + ktClassOrObject.startOffset, ktClassOrObject.endOffset, + IrDeclarationOrigin.NEW_INSTANCE_RECEIVER, + irClass.descriptor.thisAsReceiverParameter + ) + } + declarationGenerator.generateTypeParameterDeclarations(irClass, descriptor.declaredTypeParameters) - generatePrimaryConstructor(irClass, ktClassOrObject) - - generatePropertiesDeclaredInPrimaryConstructor(irClass, ktClassOrObject) + val irPrimaryConstructor = generatePrimaryConstructor(irClass, ktClassOrObject) + if (irPrimaryConstructor != null) { + generatePropertiesDeclaredInPrimaryConstructor(irClass, irPrimaryConstructor, ktClassOrObject) + } generateMembersDeclaredInSupertypeList(irClass, ktClassOrObject) @@ -70,6 +79,9 @@ class ClassGenerator(declarationGenerator: DeclarationGenerator) : DeclarationGe } } + private fun ClassDescriptor.canHaveInitializersWithInstanceReference(): Boolean = + kind != ClassKind.INTERFACE + private fun generateFakeOverrideMemberDeclarations(irClass: IrClass) { irClass.descriptor.unsubstitutedMemberScope.getContributedDescriptors() .mapNotNull { @@ -137,7 +149,7 @@ class ClassGenerator(declarationGenerator: DeclarationGenerator) : DeclarationGe ktDelegateExpression.startOffset, ktDelegateExpression.endOffset, IrDeclarationOrigin.DELEGATE, delegateDescriptor, - createBodyGenerator(irClass.descriptor).generateExpressionBody(ktDelegateExpression) + createBodyGenerator(irClass.symbol).generateExpressionBody(ktDelegateExpression) ) irClass.addMember(irDelegateField) @@ -189,33 +201,35 @@ class ClassGenerator(declarationGenerator: DeclarationGenerator) : DeclarationGe delegated ).buildWithScope { irFunction -> FunctionGenerator(declarationGenerator).generateSyntheticFunctionParameterDeclarations(irFunction) - irFunction.body = generateDelegateFunctionBody(irDelegate, delegated, overridden) + irFunction.body = generateDelegateFunctionBody(irDelegate, delegated, overridden, irFunction) } - private fun generateDelegateFunctionBody(irDelegate: IrField, delegated: FunctionDescriptor, overridden: FunctionDescriptor): IrBlockBodyImpl { + private fun generateDelegateFunctionBody(irDelegate: IrField, delegated: FunctionDescriptor, overridden: FunctionDescriptor, + irDelegatedFunction: IrSimpleFunction): IrBlockBodyImpl { val startOffset = irDelegate.startOffset val endOffset = irDelegate.endOffset - val dispatchReceiver = delegated.dispatchReceiverParameter ?: - throw AssertionError("Delegated member should have a dispatch receiver: $delegated") - val irBlockBody = IrBlockBodyImpl(startOffset, endOffset) val returnType = overridden.returnType!! - val irCall = IrCallImpl(startOffset, endOffset, returnType, overridden, null) - irCall.dispatchReceiver = IrGetFieldImpl(startOffset, endOffset, irDelegate.descriptor, - IrGetValueImpl(startOffset, endOffset, dispatchReceiver) - ) - irCall.extensionReceiver = delegated.extensionReceiverParameter?.let { extensionReceiver -> - IrGetValueImpl(startOffset, endOffset, extensionReceiver) - } + val irCall = IrCallImpl(startOffset, endOffset, returnType, context.symbolTable.referenceFunction(overridden), null) + irCall.dispatchReceiver = + IrGetFieldImpl( + startOffset, endOffset, irDelegate.symbol, + IrGetValueImpl(startOffset, endOffset, irDelegatedFunction.dispatchReceiverParameter!!.symbol) + ) + irCall.extensionReceiver = + irDelegatedFunction.extensionReceiverParameter?.let { extensionReceiver -> + IrGetValueImpl(startOffset, endOffset, extensionReceiver.symbol) + } irCall.mapValueParameters { overriddenValueParameter -> val delegatedValueParameter = delegated.valueParameters[overriddenValueParameter.index] - IrGetValueImpl(startOffset, endOffset, delegatedValueParameter) + val irDelegatedValueParameter = irDelegatedFunction.getIrValueParameter(delegatedValueParameter) + IrGetValueImpl(startOffset, endOffset, irDelegatedValueParameter.symbol) } if (KotlinBuiltIns.isUnit(returnType) || KotlinBuiltIns.isNothing(returnType)) { irBlockBody.statements.add(irCall) } else { - val irReturn = IrReturnImpl(startOffset, endOffset, context.builtIns.nothingType, delegated, irCall) + val irReturn = IrReturnImpl(startOffset, endOffset, context.builtIns.nothingType, irDelegatedFunction.symbol, irCall) irBlockBody.statements.add(irReturn) } return irBlockBody @@ -229,22 +243,31 @@ class ClassGenerator(declarationGenerator: DeclarationGenerator) : DeclarationGe EnumClassMembersGenerator(context).generateSpecialMembers(irClass) } - private fun generatePrimaryConstructor(irClass: IrClass, ktClassOrObject: KtClassOrObject) { + private fun generatePrimaryConstructor(irClass: IrClass, ktClassOrObject: KtClassOrObject): IrConstructor? { val classDescriptor = irClass.descriptor - if (DescriptorUtils.isAnnotationClass(classDescriptor)) return + if (DescriptorUtils.isAnnotationClass(classDescriptor)) return null - val primaryConstructorDescriptor = classDescriptor.unsubstitutedPrimaryConstructor ?: return + val primaryConstructorDescriptor = classDescriptor.unsubstitutedPrimaryConstructor ?: return null val irPrimaryConstructor = FunctionGenerator(declarationGenerator).generatePrimaryConstructor(primaryConstructorDescriptor, ktClassOrObject) irClass.addMember(irPrimaryConstructor) + + return irPrimaryConstructor } - private fun generatePropertiesDeclaredInPrimaryConstructor(irClass: IrClass, ktClassOrObject: KtClassOrObject) { + private fun generatePropertiesDeclaredInPrimaryConstructor( + irClass: IrClass, + irPrimaryConstructor: IrConstructor, + ktClassOrObject: KtClassOrObject + ) { ktClassOrObject.primaryConstructor?.let { ktPrimaryConstructor -> - for (ktParameter in ktPrimaryConstructor.valueParameters) { + ktPrimaryConstructor.valueParameters.forEachIndexed { i, ktParameter -> + val irValueParameter = irPrimaryConstructor.valueParameters[i] if (ktParameter.hasValOrVar()) { - irClass.addMember(PropertyGenerator(declarationGenerator).generatePropertyForPrimaryConstructorParameter(ktParameter)) + val irProperty = PropertyGenerator(declarationGenerator) + .generatePropertyForPrimaryConstructorParameter(ktParameter, irValueParameter) + irClass.addMember(irProperty) } } } @@ -267,7 +290,7 @@ class ClassGenerator(declarationGenerator: DeclarationGenerator) : DeclarationGe enumEntryDescriptor ).buildWithScope { irEnumEntry -> irEnumEntry.initializerExpression = - BodyGenerator(enumEntryDescriptor.containingDeclaration, context) + createBodyGenerator(irEnumEntry.symbol) .generateEnumEntryInitializer(ktEnumEntry, enumEntryDescriptor) if (ktEnumEntry.declarations.isNotEmpty()) { diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DataClassMembersGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DataClassMembersGenerator.kt index 16832f12815..beaebbcdd62 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DataClassMembersGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DataClassMembersGenerator.kt @@ -26,7 +26,9 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrFunction import org.jetbrains.kotlin.ir.declarations.putDefault import org.jetbrains.kotlin.ir.expressions.IrExpression +import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl import org.jetbrains.kotlin.ir.expressions.mapValueParameters +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.psi.KtClassOrObject import org.jetbrains.kotlin.psi.KtParameter import org.jetbrains.kotlin.psi2ir.containsNull @@ -46,21 +48,23 @@ class DataClassMembersGenerator( MyDataClassMethodGenerator(ktClassOrObject, irClass).generate() } + private fun declareSimpleFunction(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, function: FunctionDescriptor) = + context.symbolTable.declareSimpleFunction(startOffset, endOffset, origin, function) + private inner class MemberFunctionBuilder( val irClass: IrClass, val function: FunctionDescriptor, val origin: IrDeclarationOrigin, startOffset: Int = UNDEFINED_OFFSET, - endOffset: Int = UNDEFINED_OFFSET - ) : IrBlockBodyBuilder(context, Scope(function), startOffset, endOffset) { - lateinit var irFunction: IrFunction + endOffset: Int = UNDEFINED_OFFSET, + val irFunction: IrFunction = declareSimpleFunction(startOffset, endOffset, origin, function) + ) : IrBlockBodyBuilder(context, Scope(irFunction.symbol), startOffset, endOffset) { + inline fun addToClass(builder: MemberFunctionBuilder.(IrFunction) -> Unit): IrFunction { + irFunction.buildWithScope { + builder(irFunction) + irFunction.body = doBuild() + } - inline fun addToClass(body: MemberFunctionBuilder.(IrFunction) -> Unit): IrFunction { - irFunction = this@DataClassMembersGenerator.context.symbolTable - .declareSimpleFunction(startOffset, endOffset, origin, function) - - body(irFunction) - irFunction.body = doBuild() irClass.declarations.add(irFunction) return irFunction } @@ -68,6 +72,12 @@ class DataClassMembersGenerator( fun putDefault(parameter: ValueParameterDescriptor, value: IrExpression) { irFunction.putDefault(parameter, irExprBody(value)) } + + fun irThis(): IrExpression = + IrGetValueImpl(startOffset, endOffset, irFunction.dispatchReceiverParameter!!.symbol) + + fun irOther(): IrExpression = + IrGetValueImpl(startOffset, endOffset, irFunction.valueParameters[0].symbol) } private inner class MyDataClassMethodGenerator( @@ -94,23 +104,31 @@ class DataClassMembersGenerator( val ktParameter = DescriptorToSourceUtils.descriptorToDeclaration(parameter) ?: throw AssertionError("No definition for data class constructor parameter $parameter") - val property = getOrFail(BindingContext.VALUE_PARAMETER_AS_PROPERTY, parameter) - buildMember(function, ktParameter) { - +irReturn(irGet(irThis(), property)) + +irReturn(irGet(irThis(), getPropertyGetterSymbol(parameter))) } } + private fun getPropertyGetterSymbol(parameter: ValueParameterDescriptor): IrFunctionSymbol { + val property = getOrFail(BindingContext.VALUE_PARAMETER_AS_PROPERTY, parameter) + return getPropertyGetterSymbol(property) + } + + private fun getPropertyGetterSymbol(property: PropertyDescriptor) = + context.symbolTable.referenceFunction(property.getter!!) + override fun generateCopyFunction(function: FunctionDescriptor, constructorParameters: List) { val dataClassConstructor = classDescriptor.unsubstitutedPrimaryConstructor ?: throw AssertionError("Data class should have a primary constructor: $classDescriptor") + val constructorSymbol = context.symbolTable.referenceConstructor(dataClassConstructor) - buildMember(function) { + buildMember(function) { irFunction -> function.valueParameters.forEach { parameter -> - val property = getOrFail(BindingContext.VALUE_PARAMETER_AS_PROPERTY, parameter) - putDefault(parameter, irGet(irThis(), property)) + putDefault(parameter, irGet(irThis(), getPropertyGetterSymbol(parameter))) } - +irReturn(irCall(dataClassConstructor).mapValueParameters { irGet(function.valueParameters[it.index]) }) + +irReturn(irCall(constructorSymbol, dataClassConstructor.returnType).mapValueParameters { + irGet(irFunction.valueParameters[it.index].symbol) + }) } } @@ -118,43 +136,52 @@ class DataClassMembersGenerator( buildMember(function) { +irIfThenReturnTrue(irEqeqeq(irThis(), irOther())) +irIfThenReturnFalse(irNotIs(irOther(), classDescriptor.defaultType)) - val otherWithCast = defineTemporary(irAs(irOther(), classDescriptor.defaultType), "other_with_cast") + val otherWithCast = irTemporary(irAs(irOther(), classDescriptor.defaultType), "other_with_cast") for (property in properties) { +irIfThenReturnFalse( - irNotEquals(irGet(irThis(), property), - irGet(irGet(otherWithCast), property))) + irNotEquals(irGet(irThis(), getPropertyGetterSymbol(property)), + irGet(irGet(otherWithCast.symbol), getPropertyGetterSymbol(property)))) } +irReturnTrue() } } - private val INT = context.builtIns.int - private val INT_TYPE = context.builtIns.intType + private val intClass = context.builtIns.int + private val intType = context.builtIns.intType - private val IMUL = INT.findFirstFunction("times") { KotlinTypeChecker.DEFAULT.equalTypes(it.valueParameters[0].type, INT_TYPE) } - private val IADD = INT.findFirstFunction("plus") { KotlinTypeChecker.DEFAULT.equalTypes(it.valueParameters[0].type, INT_TYPE) } + private val intTimes = + intClass.findFirstFunction("times") { KotlinTypeChecker.DEFAULT.equalTypes(it.valueParameters[0].type, intType) } + .let { context.symbolTable.referenceFunction(it) } - private fun getHashCodeFunction(type: KotlinType): CallableDescriptor { + private val intPlus = + intClass.findFirstFunction("plus") { KotlinTypeChecker.DEFAULT.equalTypes(it.valueParameters[0].type, intType) } + .let { context.symbolTable.referenceFunction(it) } + + + private fun getHashCodeFunction(type: KotlinType): IrFunctionSymbol { val typeConstructorDescriptor = type.constructor.declarationDescriptor - when (typeConstructorDescriptor) { - is ClassDescriptor -> - return typeConstructorDescriptor.findFirstFunction("hashCode") { it.valueParameters.isEmpty() } + return when (typeConstructorDescriptor) { + is ClassDescriptor -> { + val hashCodeDescriptor: CallableDescriptor = typeConstructorDescriptor.findFirstFunction("hashCode") { it.valueParameters.isEmpty() } + context.symbolTable.referenceFunction(hashCodeDescriptor) + } is TypeParameterDescriptor -> - return getHashCodeFunction(context.builtIns.anyType) // TODO + getHashCodeFunction(context.builtIns.anyType) // TODO else -> throw AssertionError("Unexpected type: $type") } + } override fun generateHashCodeMethod(function: FunctionDescriptor, properties: List) { buildMember(function) { - val result = defineTemporaryVar(irInt(0), "result") + val result = irTemporaryVar(irInt(0), "result").symbol var first = true for (property in properties) { val hashCodeOfProperty = getHashCodeOfProperty(irThis(), property) val irNewValue = if (first) hashCodeOfProperty - else irCallOp(IADD, irCallOp(IMUL, irGet(result), irInt(31)), hashCodeOfProperty) + else irCallOp(intPlus, irCallOp(intTimes, irGet(result), irInt(31)), hashCodeOfProperty) +irSetVar(result, irNewValue) first = false } @@ -162,18 +189,20 @@ class DataClassMembersGenerator( } } - private fun MemberFunctionBuilder.getHashCodeOfProperty(receiver: IrExpression, property: PropertyDescriptor): IrExpression = - when { - property.type.containsNull() -> - irLet(irGet(receiver, property)) { variable -> - irIfNull(context.builtIns.intType, irGet(variable), irInt(0), getHashCodeOf(irGet(variable))) - } - else -> - getHashCodeOf(irGet(receiver, property)) - } + private fun MemberFunctionBuilder.getHashCodeOfProperty(receiver: IrExpression, property: PropertyDescriptor): IrExpression { + val getterSymbol = getPropertyGetterSymbol(property) + return when { + property.type.containsNull() -> + irLetS(irGet(receiver, getterSymbol)) { variable -> + irIfNull(context.builtIns.intType, irGet(variable), irInt(0), getHashCodeOf(irGet(variable))) + } + else -> + getHashCodeOf(irGet(receiver, getterSymbol)) + } + } private fun MemberFunctionBuilder.getHashCodeOf(irValue: IrExpression): IrExpression = - irCall(getHashCodeFunction(irValue.type)).apply { dispatchReceiver = irValue } + irCall(getHashCodeFunction(irValue.type), intType).apply { dispatchReceiver = irValue } override fun generateToStringMethod(function: FunctionDescriptor, properties: List) { buildMember(function) { @@ -183,7 +212,7 @@ class DataClassMembersGenerator( for (property in properties) { if (!first) irConcat.addArgument(irString(", ")) irConcat.addArgument(irString(property.name.asString() + "=")) - irConcat.addArgument(irGet(irThis(), property)) + irConcat.addArgument(irGet(irThis(), getPropertyGetterSymbol(property))) first = false } irConcat.addArgument(irString(")")) diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DeclarationGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DeclarationGenerator.kt index f7d10845b9e..a671448e4b0 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DeclarationGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DeclarationGenerator.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrErrorDeclarationImpl import org.jetbrains.kotlin.ir.declarations.impl.IrPropertyImpl import org.jetbrains.kotlin.ir.declarations.impl.IrTypeAliasImpl import org.jetbrains.kotlin.ir.expressions.IrExpressionBody +import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset @@ -74,7 +75,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator { context.symbolTable.declareAnonymousInitializer( ktAnonymousInitializer.startOffset, ktAnonymousInitializer.endOffset, IrDeclarationOrigin.DEFINED, classDescriptor ).apply { - body = createBodyGenerator(classDescriptor).generateAnonymousInitializerBody(ktAnonymousInitializer) + body = createBodyGenerator(symbol).generateAnonymousInitializerBody(ktAnonymousInitializer) } @@ -90,8 +91,8 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator { } } - fun generateInitializerBody(scopeOwner: CallableDescriptor, ktBody: KtExpression): IrExpressionBody = - createBodyGenerator(scopeOwner).generateExpressionBody(ktBody) + fun generateInitializerBody(scopeOwnerSymbol: IrSymbol, ktBody: KtExpression): IrExpressionBody = + createBodyGenerator(scopeOwnerSymbol).generateExpressionBody(ktBody) fun generateFakeOverrideDeclaration(memberDescriptor: CallableMemberDescriptor, ktElement: KtElement? = null): IrDeclaration { assert(memberDescriptor.kind == CallableMemberDescriptor.Kind.FAKE_OVERRIDE) { @@ -137,5 +138,5 @@ abstract class DeclarationGeneratorExtension(val declarationGenerator: Declarati } } -fun Generator.createBodyGenerator(scopeOwnerDescriptor: DeclarationDescriptor) = - BodyGenerator(scopeOwnerDescriptor, context) \ No newline at end of file +fun Generator.createBodyGenerator(scopeOwnerSymbol: IrSymbol) = + BodyGenerator(scopeOwnerSymbol, context) \ No newline at end of file diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DelegatedPropertyGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DelegatedPropertyGenerator.kt index 921111adef4..949f5e32a65 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DelegatedPropertyGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/DelegatedPropertyGenerator.kt @@ -28,9 +28,11 @@ import org.jetbrains.kotlin.ir.descriptors.IrLocalDelegatedPropertyDelegateDescr import org.jetbrains.kotlin.ir.descriptors.IrPropertyDelegateDescriptor import org.jetbrains.kotlin.ir.descriptors.IrPropertyDelegateDescriptorImpl import org.jetbrains.kotlin.ir.expressions.* -import org.jetbrains.kotlin.ir.expressions.impl.IrCallableReferenceImpl import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl +import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol +import org.jetbrains.kotlin.ir.symbols.IrSymbol +import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol import org.jetbrains.kotlin.psi.KtElement import org.jetbrains.kotlin.psi.KtProperty import org.jetbrains.kotlin.psi.KtPropertyDelegate @@ -46,33 +48,38 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D fun generateDelegatedProperty( ktProperty: KtProperty, ktDelegate: KtPropertyDelegate, - propertyDescriptor: PropertyDescriptor, - irDelegateInitializer: IrExpressionBody + propertyDescriptor: PropertyDescriptor ): IrProperty { - val kPropertyType = getKPropertyTypeForDelegatedProperty(propertyDescriptor) - val irDelegate = generateDelegateFieldForProperty(propertyDescriptor, kPropertyType, irDelegateInitializer, ktDelegate) - val delegateDescriptor = irDelegate.descriptor as IrPropertyDelegateDescriptor + val kPropertyType = getKPropertyTypeForDelegatedProperty(propertyDescriptor) val irProperty = IrPropertyImpl( ktProperty.startOffset, ktProperty.endOffset, IrDeclarationOrigin.DEFINED, true, - propertyDescriptor, irDelegate) + propertyDescriptor + ).apply { + backingField = generateDelegateFieldForProperty(propertyDescriptor, kPropertyType, ktDelegate) + } - val delegateReceiverValue = createBackingFieldValueForDelegate(delegateDescriptor, ktDelegate) + val irDelegate = irProperty.backingField!! + + val thisClass = propertyDescriptor.containingDeclaration as? ClassDescriptor + val delegateReceiverValue = createBackingFieldValueForDelegate(irDelegate.symbol, thisClass, ktDelegate) val getterDescriptor = propertyDescriptor.getter!! - irProperty.getter = generateDelegatedPropertyAccessorExceptBody(ktProperty, ktDelegate, getterDescriptor).also { irGetter -> - irGetter.body = generateDelegatedPropertyGetterBody( + irProperty.getter = generateDelegatedPropertyAccessor(ktProperty, ktDelegate, getterDescriptor) { irGetter -> + generateDelegatedPropertyGetterBody( + irGetter, ktDelegate, getterDescriptor, delegateReceiverValue, - createCallableReference(ktDelegate, kPropertyType, propertyDescriptor) + createCallableReference(ktDelegate, kPropertyType, propertyDescriptor, irGetter.symbol) ) } if (propertyDescriptor.isVar) { val setterDescriptor = propertyDescriptor.setter!! - irProperty.setter = generateDelegatedPropertyAccessorExceptBody(ktProperty, ktDelegate, setterDescriptor).also { irSetter -> - irSetter.body = generateDelegatedPropertySetterBody( + irProperty.setter = generateDelegatedPropertyAccessor(ktProperty, ktDelegate, setterDescriptor) { irSetter -> + generateDelegatedPropertySetterBody( + irSetter, ktDelegate, setterDescriptor, delegateReceiverValue, - createCallableReference(ktDelegate, kPropertyType, propertyDescriptor) + createCallableReference(ktDelegate, kPropertyType, propertyDescriptor, irSetter.symbol) ) } } @@ -80,10 +87,11 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D return irProperty } - private fun generateDelegatedPropertyAccessorExceptBody( + private inline fun generateDelegatedPropertyAccessor( ktProperty: KtProperty, ktDelegate: KtPropertyDelegate, - accessorDescriptor: PropertyAccessorDescriptor + accessorDescriptor: PropertyAccessorDescriptor, + generateBody: (IrFunction) -> IrBody ): IrFunction = context.symbolTable.declareSimpleFunction( ktDelegate.startOffset, ktDelegate.endOffset, @@ -91,6 +99,7 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D accessorDescriptor ).buildWithScope { irGetter -> FunctionGenerator(declarationGenerator).generateFunctionParameterDeclarations(irGetter, ktProperty, null) + irGetter.body = generateBody(irGetter) } @@ -102,10 +111,12 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D private fun generateDelegateFieldForProperty( propertyDescriptor: PropertyDescriptor, kPropertyType: KotlinType, - irDelegateInitializer: IrExpressionBody, ktDelegate: KtPropertyDelegate ): IrField { - val irActualDelegateInitializer = generateInitializerBodyForPropertyDelegate(propertyDescriptor, kPropertyType, irDelegateInitializer, ktDelegate) + val irActualDelegateInitializer = generateInitializerBodyForPropertyDelegate( + propertyDescriptor, kPropertyType, ktDelegate, + context.symbolTable.referenceField(propertyDescriptor) + ) val delegateType = irActualDelegateInitializer.expression.type val delegateDescriptor = createPropertyDelegateDescriptor(propertyDescriptor, delegateType, kPropertyType) @@ -119,44 +130,78 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D private fun generateInitializerBodyForPropertyDelegate( property: VariableDescriptorWithAccessors, kPropertyType: KotlinType, - irDelegateInitializer: IrExpressionBody, - ktDelegate: KtPropertyDelegate + ktDelegate: KtPropertyDelegate, + scopeOwner: IrSymbol ): IrExpressionBody { + val ktDelegateExpression = ktDelegate.expression!! + val irDelegateInitializer = declarationGenerator.generateInitializerBody(scopeOwner, ktDelegateExpression) + val provideDelegateResolvedCall = get(BindingContext.PROVIDE_DELEGATE_RESOLVED_CALL, property) ?: return irDelegateInitializer - val statementGenerator = BodyGenerator(property, context).createStatementGenerator() + val statementGenerator = createBodyGenerator(scopeOwner).createStatementGenerator() val provideDelegateCall = statementGenerator.pregenerateCall(provideDelegateResolvedCall) provideDelegateCall.setExplicitReceiverValue(OnceExpressionValue(irDelegateInitializer.expression)) - provideDelegateCall.irValueArgumentsByIndex[1] = createCallableReference(ktDelegate, kPropertyType, property) + provideDelegateCall.irValueArgumentsByIndex[1] = createCallableReference(ktDelegate, kPropertyType, property, scopeOwner) val irProvideDelegate = CallGenerator(statementGenerator).generateCall(ktDelegate.startOffset, ktDelegate.endOffset, provideDelegateCall) return IrExpressionBodyImpl(irProvideDelegate) } - private fun createBackingFieldValueForDelegate(delegateDescriptor: IrPropertyDelegateDescriptor, ktDelegate: KtPropertyDelegate): IntermediateValue { - val thisClass = delegateDescriptor.correspondingProperty.containingDeclaration as? ClassDescriptor - val thisValue = thisClass?.let { - RematerializableValue(IrGetValueImpl(ktDelegate.startOffset, ktDelegate.endOffset, thisClass.thisAsReceiverParameter)) - } - return BackingFieldLValue(ktDelegate.startOffset, ktDelegate.endOffset, delegateDescriptor, thisValue, null) + private fun createBackingFieldValueForDelegate(irDelegateField: IrFieldSymbol, thisClass: ClassDescriptor?, ktDelegate: KtPropertyDelegate): IntermediateValue { + val thisValue = createThisValueForDelegate(thisClass, ktDelegate) + return BackingFieldLValue(ktDelegate.startOffset, ktDelegate.endOffset, + irDelegateField.descriptor.type, + irDelegateField, + thisValue, + null) } - private fun createCallableReference(ktElement: KtElement, type: KotlinType, referencedDescriptor: CallableDescriptor): IrCallableReference = - IrCallableReferenceImpl(ktElement.startOffset, ktElement.endOffset, type, - referencedDescriptor, null, IrStatementOrigin.PROPERTY_REFERENCE_FOR_DELEGATE) + private fun createThisValueForDelegate(thisClass: ClassDescriptor?, ktDelegate: KtPropertyDelegate): IntermediateValue? = + thisClass?.let { + generateExpressionValue(it.thisAsReceiverParameter.type) { + IrGetValueImpl( + ktDelegate.startOffset, ktDelegate.endOffset, + context.symbolTable.referenceValueParameter(thisClass.thisAsReceiverParameter) + ) + } + } + + private fun createCallableReference( + ktElement: KtElement, + type: KotlinType, + referencedDescriptor: CallableDescriptor, + statementGenerator: StatementGenerator + ): IrCallableReference = + ReflectionReferencesGenerator(statementGenerator).generateCallableReference( + ktElement.startOffset, ktElement.endOffset, type, + referencedDescriptor, + null, IrStatementOrigin.PROPERTY_REFERENCE_FOR_DELEGATE + ) + + private fun createCallableReference( + ktElement: KtElement, + type: KotlinType, + referencedDescriptor: CallableDescriptor, + scopeOwner: IrSymbol + ): IrCallableReference = + createCallableReference( + ktElement, type, referencedDescriptor, + createBodyGenerator(scopeOwner).createStatementGenerator() + ) fun generateLocalDelegatedProperty( ktProperty: KtProperty, ktDelegate: KtPropertyDelegate, variableDescriptor: VariableDescriptorWithAccessors, - irDelegateInitializer: IrExpression + scopeOwnerSymbol: IrSymbol ): IrLocalDelegatedProperty { val kPropertyType = getKPropertyTypeForLocalDelegatedProperty(variableDescriptor) val irActualDelegateInitializer = generateInitializerBodyForPropertyDelegate( variableDescriptor, kPropertyType, - IrExpressionBodyImpl(irDelegateInitializer), ktDelegate + ktDelegate, + scopeOwnerSymbol ).expression val delegateType = irActualDelegateInitializer.type @@ -171,40 +216,53 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D ktProperty.startOffset, ktProperty.endOffset, IrDeclarationOrigin.DEFINED, variableDescriptor, irDelegate) + val getterDescriptor = variableDescriptor.getter!! - val delegateReceiverValue = createVariableValueForDelegate(delegateDescriptor, ktDelegate) - irLocalDelegatedProperty.getter = createLocalPropertyAccessor( - getterDescriptor, ktDelegate, - generateDelegatedPropertyGetterBody( - ktDelegate, getterDescriptor, delegateReceiverValue, - createCallableReference(ktDelegate, delegateDescriptor.kPropertyType, delegateDescriptor.correspondingLocalProperty) - ) - ) + val delegateReceiverValue = createVariableValueForDelegate(irDelegate.symbol, ktDelegate) + irLocalDelegatedProperty.getter = + createLocalPropertyAccessor(getterDescriptor, ktDelegate) { irGetter -> + generateDelegatedPropertyGetterBody( + irGetter, + ktDelegate, getterDescriptor, delegateReceiverValue, + createCallableReference( + ktDelegate, delegateDescriptor.kPropertyType, + delegateDescriptor.correspondingLocalProperty, + irGetter.symbol + ) + ) + } if (variableDescriptor.isVar) { val setterDescriptor = variableDescriptor.setter!! - irLocalDelegatedProperty.setter = createLocalPropertyAccessor( - setterDescriptor, ktDelegate, - generateDelegatedPropertySetterBody( - ktDelegate, setterDescriptor, delegateReceiverValue, - createCallableReference(ktDelegate, delegateDescriptor.kPropertyType, delegateDescriptor.correspondingLocalProperty) - ) - ) + irLocalDelegatedProperty.setter = + createLocalPropertyAccessor(setterDescriptor, ktDelegate) { irSetter -> + generateDelegatedPropertySetterBody( + irSetter, ktDelegate, setterDescriptor, delegateReceiverValue, + createCallableReference( + ktDelegate, delegateDescriptor.kPropertyType, + delegateDescriptor.correspondingLocalProperty, + irSetter.symbol + ) + ) + } } return irLocalDelegatedProperty } - private fun createVariableValueForDelegate(delegateDescriptor: IrLocalDelegatedPropertyDelegateDescriptor, ktDelegate: KtPropertyDelegate) = - VariableLValue(ktDelegate.startOffset, ktDelegate.endOffset, delegateDescriptor) + private fun createVariableValueForDelegate(irDelegate: IrVariableSymbol, ktDelegate: KtPropertyDelegate) = + VariableLValue(ktDelegate.startOffset, ktDelegate.endOffset, irDelegate) - private fun createLocalPropertyAccessor(getterDescriptor: VariableAccessorDescriptor, ktDelegate: KtPropertyDelegate, irBody: IrBody) = + private fun createLocalPropertyAccessor( + getterDescriptor: VariableAccessorDescriptor, ktDelegate: KtPropertyDelegate, + generateBody: (IrFunction) -> IrBody + ) = context.symbolTable.declareSimpleFunction( ktDelegate.startOffset, ktDelegate.endOffset, IrDeclarationOrigin.DELEGATED_PROPERTY_ACCESSOR, getterDescriptor - ).apply { - body = irBody + ).buildWithScope { + it.body = generateBody(it) } private fun createLocalPropertyDelegatedDescriptor( @@ -225,35 +283,38 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D ): IrPropertyDelegateDescriptor = IrPropertyDelegateDescriptorImpl(propertyDescriptor, delegateType, kPropertyType) - fun generateDelegatedPropertyGetterBody( + private fun generateDelegatedPropertyGetterBody( + irGetter: IrFunction, ktDelegate: KtPropertyDelegate, getterDescriptor: VariableAccessorDescriptor, delegateReceiverValue: IntermediateValue, irPropertyReference: IrCallableReference - ): IrBody = with(BodyGenerator(getterDescriptor, context)) { - irBlockBody(ktDelegate) { - val statementGenerator = createStatementGenerator() - val conventionMethodResolvedCall = getOrFail(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, getterDescriptor) - val conventionMethodCall = statementGenerator.pregenerateCall(conventionMethodResolvedCall) - conventionMethodCall.setExplicitReceiverValue(delegateReceiverValue) - conventionMethodCall.irValueArgumentsByIndex[1] = irPropertyReference - +irReturn(CallGenerator(statementGenerator).generateCall(ktDelegate.startOffset, ktDelegate.endOffset, conventionMethodCall)) - } - } + ): IrBody = + with(createBodyGenerator(irGetter.symbol)) { + irBlockBody(ktDelegate) { + val statementGenerator = createStatementGenerator() + val conventionMethodResolvedCall = getOrFail(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, getterDescriptor) + val conventionMethodCall = statementGenerator.pregenerateCall(conventionMethodResolvedCall) + conventionMethodCall.setExplicitReceiverValue(delegateReceiverValue) + conventionMethodCall.irValueArgumentsByIndex[1] = irPropertyReference + +irReturn(CallGenerator(statementGenerator).generateCall(ktDelegate.startOffset, ktDelegate.endOffset, conventionMethodCall)) + } + } - fun generateDelegatedPropertySetterBody( + private fun generateDelegatedPropertySetterBody( + irSetter: IrFunction, ktDelegate: KtPropertyDelegate, setterDescriptor: VariableAccessorDescriptor, delegateReceiverValue: IntermediateValue, irPropertyReference: IrCallableReference - ): IrBody = with(BodyGenerator(setterDescriptor, context)) { + ): IrBody = with(createBodyGenerator(irSetter.symbol)) { irBlockBody(ktDelegate) { val statementGenerator = createStatementGenerator() val conventionMethodResolvedCall = getOrFail(BindingContext.DELEGATED_PROPERTY_RESOLVED_CALL, setterDescriptor) val conventionMethodCall = statementGenerator.pregenerateCall(conventionMethodResolvedCall) conventionMethodCall.setExplicitReceiverValue(delegateReceiverValue) conventionMethodCall.irValueArgumentsByIndex[1] = irPropertyReference - conventionMethodCall.irValueArgumentsByIndex[2] = irGet(setterDescriptor.valueParameters[0]) + conventionMethodCall.irValueArgumentsByIndex[2] = irGet(irSetter.valueParameters[0].symbol) +irReturn(CallGenerator(statementGenerator).generateCall(ktDelegate.startOffset, ktDelegate.endOffset, conventionMethodCall)) } } diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/FunctionGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/FunctionGenerator.kt index f546e2b92dc..3958981dd41 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/FunctionGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/FunctionGenerator.kt @@ -66,7 +66,7 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio ktFunction.startOffset, ktFunction.endOffset, origin, descriptor ).buildWithScope { irFunction -> generateFunctionParameterDeclarations(irFunction, ktFunction, ktReceiver) - irFunction.body = createBodyGenerator(descriptor).generateBody() + irFunction.body = createBodyGenerator(irFunction.symbol).generateBody() } fun generateFunctionParameterDeclarations( @@ -93,15 +93,14 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio val ktBodyExpression = ktAccessor?.bodyExpression irAccessor.body = if (ktBodyExpression != null) - createBodyGenerator(descriptor).generateFunctionBody(ktBodyExpression) + createBodyGenerator(irAccessor.symbol).generateFunctionBody(ktBodyExpression) else - generateDefaultAccessorBody(ktProperty, descriptor) + generateDefaultAccessorBody(ktProperty, descriptor, irAccessor) } fun generateDefaultAccessorForPrimaryConstructorParameter( descriptor: PropertyAccessorDescriptor, - ktParameter: KtParameter, - isGetter: Boolean + ktParameter: KtParameter ): IrFunction = context.symbolTable.declareSimpleFunction( ktParameter.startOffsetOrUndefined, @@ -109,43 +108,55 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio IrDeclarationOrigin.DEFAULT_PROPERTY_ACCESSOR, descriptor ).buildWithScope { irAccessor -> - val accessorDescriptor = irAccessor.descriptor - declarationGenerator.generateTypeParameterDeclarations(irAccessor, accessorDescriptor.typeParameters) + declarationGenerator.generateTypeParameterDeclarations(irAccessor, descriptor.typeParameters) FunctionGenerator(declarationGenerator).generateSyntheticFunctionParameterDeclarations(irAccessor) - irAccessor.body = - if (isGetter) generateDefaultGetterBody(ktParameter, descriptor as PropertyGetterDescriptor) - else generateDefaultSetterBody(ktParameter, descriptor as PropertySetterDescriptor) + irAccessor.body = generateDefaultAccessorBody(ktParameter, descriptor, irAccessor) } - private fun generateDefaultAccessorBody(ktProperty: KtElement, accessor: PropertyAccessorDescriptor) = + private fun generateDefaultAccessorBody(ktProperty: KtElement, accessor: PropertyAccessorDescriptor, irAccessor: IrSimpleFunction) = when (accessor) { - is PropertyGetterDescriptor -> generateDefaultGetterBody(ktProperty, accessor) - is PropertySetterDescriptor -> generateDefaultSetterBody(ktProperty, accessor) + is PropertyGetterDescriptor -> generateDefaultGetterBody(ktProperty, accessor, irAccessor) + is PropertySetterDescriptor -> generateDefaultSetterBody(ktProperty, accessor, irAccessor) else -> throw AssertionError("Should be getter or setter: $accessor") } - private fun generateDefaultGetterBody(ktProperty: KtElement, getter: PropertyGetterDescriptor): IrBlockBody { + private fun generateDefaultGetterBody(ktProperty: KtElement, getter: PropertyGetterDescriptor, irAccessor: IrSimpleFunction): IrBlockBody { val property = getter.correspondingProperty val irBody = IrBlockBodyImpl(ktProperty.startOffset, ktProperty.endOffset) val receiver = generateReceiverExpressionForDefaultPropertyAccessor(ktProperty, property) - irBody.statements.add(IrReturnImpl(ktProperty.startOffset, ktProperty.endOffset, context.builtIns.nothingType, getter, - IrGetFieldImpl(ktProperty.startOffset, ktProperty.endOffset, property, receiver))) + irBody.statements.add( + IrReturnImpl( + ktProperty.startOffset, ktProperty.endOffset, context.builtIns.nothingType, + irAccessor.symbol, + IrGetFieldImpl( + ktProperty.startOffset, ktProperty.endOffset, + context.symbolTable.referenceField(property), + receiver + ) + ) + ) return irBody } - private fun generateDefaultSetterBody(ktProperty: KtElement, setter: PropertySetterDescriptor): IrBlockBody { + private fun generateDefaultSetterBody(ktProperty: KtElement, setter: PropertySetterDescriptor, irAccessor: IrSimpleFunction): IrBlockBody { val property = setter.correspondingProperty val irBody = IrBlockBodyImpl(ktProperty.startOffset, ktProperty.endOffset) val receiver = generateReceiverExpressionForDefaultPropertyAccessor(ktProperty, property) - val setterParameter = setter.valueParameters.single() - irBody.statements.add(IrSetFieldImpl(ktProperty.startOffset, ktProperty.endOffset, property, receiver, - IrGetValueImpl(ktProperty.startOffset, ktProperty.endOffset, setterParameter))) + val setterParameter = irAccessor.valueParameters.single().symbol + irBody.statements.add( + IrSetFieldImpl( + ktProperty.startOffset, ktProperty.endOffset, + context.symbolTable.referenceField(property), + receiver, + IrGetValueImpl(ktProperty.startOffset, ktProperty.endOffset, setterParameter) + ) + ) return irBody } @@ -153,7 +164,8 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio val containingDeclaration = property.containingDeclaration val receiver = when (containingDeclaration) { is ClassDescriptor -> - IrGetValueImpl(ktProperty.startOffset, ktProperty.endOffset, containingDeclaration.thisAsReceiverParameter) + IrGetValueImpl(ktProperty.startOffset, ktProperty.endOffset, + context.symbolTable.referenceValue(containingDeclaration.thisAsReceiverParameter)) else -> null } return receiver @@ -189,7 +201,7 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio ktConstructorElement.startOffset, ktConstructorElement.endOffset, IrDeclarationOrigin.DEFINED, constructorDescriptor ).buildWithScope { irConstructor -> generateFunctionParameterDeclarations(irConstructor, ktParametersElement, null) - irConstructor.body = createBodyGenerator(constructorDescriptor).generateBody() + irConstructor.body = createBodyGenerator(irConstructor.symbol).generateBody() } fun generateSyntheticFunctionParameterDeclarations(irFunction: IrFunction) { @@ -212,7 +224,7 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio generateReceiverParameterDeclaration(it, ktReceiverParameterElement ?: ktParameterOwner) } - val bodyGenerator = createBodyGenerator(functionDescriptor) + val bodyGenerator = createBodyGenerator(irFunction.symbol) functionDescriptor.valueParameters.mapTo(irFunction.valueParameters) { valueParameterDescriptor -> val ktParameter = DescriptorToSourceUtils.getSourceFromDescriptor(valueParameterDescriptor) as? KtParameter generateValueParameterDeclaration(valueParameterDescriptor, ktParameter, bodyGenerator) diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/LocalClassGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/LocalClassGenerator.kt index 3a00e4d53c0..2a236fbc161 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/LocalClassGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/LocalClassGenerator.kt @@ -45,8 +45,13 @@ class LocalClassGenerator(statementGenerator: StatementGenerator): StatementGene "Object literal constructor should have no value parameters: $objectConstructor" } - irBlock.statements.add(IrCallImpl(ktObjectLiteral.startOffset, ktObjectLiteral.endOffset, objectLiteralType, - objectConstructor, null, IrStatementOrigin.OBJECT_LITERAL)) + irBlock.statements.add( + IrCallImpl( + ktObjectLiteral.startOffset, ktObjectLiteral.endOffset, objectLiteralType, + context.symbolTable.referenceConstructor(objectConstructor), + null, IrStatementOrigin.OBJECT_LITERAL + ) + ) return irBlock } diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/LocalFunctionGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/LocalFunctionGenerator.kt index 59db352f65b..2544e6cd8bd 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/LocalFunctionGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/LocalFunctionGenerator.kt @@ -20,7 +20,7 @@ import org.jetbrains.kotlin.ir.IrStatement import org.jetbrains.kotlin.ir.declarations.IrFunction import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin import org.jetbrains.kotlin.ir.expressions.impl.IrBlockImpl -import org.jetbrains.kotlin.ir.expressions.impl.IrCallableReferenceImpl +import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionReferenceImpl import org.jetbrains.kotlin.psi.KtLambdaExpression import org.jetbrains.kotlin.psi.KtNamedFunction import org.jetbrains.kotlin.psi.psiUtil.endOffset @@ -35,9 +35,10 @@ class LocalFunctionGenerator(statementGenerator: StatementGenerator) : Statement val irBlock = IrBlockImpl(ktLambda.startOffset, ktLambda.endOffset, lambdaExpressionType, IrStatementOrigin.LAMBDA) irBlock.statements.add(irLambdaFunction) irBlock.statements.add( - IrCallableReferenceImpl( + IrFunctionReferenceImpl( ktLambda.startOffset, ktLambda.endOffset, lambdaExpressionType, - irLambdaFunction.descriptor, null, IrStatementOrigin.LAMBDA + irLambdaFunction.symbol, + null, IrStatementOrigin.LAMBDA ) ) return irBlock @@ -56,9 +57,10 @@ class LocalFunctionGenerator(statementGenerator: StatementGenerator) : Statement irBlock.statements.add(irFun) irBlock.statements.add( - IrCallableReferenceImpl( + IrFunctionReferenceImpl( ktFun.startOffset, ktFun.endOffset, funExpressionType, - irFun.descriptor, null, IrStatementOrigin.ANONYMOUS_FUNCTION + irFun.symbol, + null, IrStatementOrigin.ANONYMOUS_FUNCTION ) ) diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/OperatorExpressionGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/OperatorExpressionGenerator.kt index 749d4fc3ea2..bf2de8fb737 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/OperatorExpressionGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/OperatorExpressionGenerator.kt @@ -119,8 +119,8 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : Stat val irArgument1 = statementGenerator.generateExpression(expression.right!!) return irBlock(expression, IrStatementOrigin.ELVIS, resultType) { - val temporary = defineTemporary(irArgument0, "elvis_lhs") - +irIfNull(resultType, irGet(temporary), irArgument1, irGet(temporary)) + val temporary = irTemporary(irArgument0, "elvis_lhs") + +irIfNull(resultType, irGet(temporary.symbol), irArgument1, irGet(temporary.symbol)) } } @@ -146,7 +146,8 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : Stat IrStatementOrigin.IN -> irContainsCall IrStatementOrigin.NOT_IN -> - IrUnaryPrimitiveImpl(expression.startOffset, expression.endOffset, IrStatementOrigin.NOT_IN, context.irBuiltIns.booleanNot, + IrUnaryPrimitiveImpl(expression.startOffset, expression.endOffset, IrStatementOrigin.NOT_IN, + context.irBuiltIns.booleanNotSymbol, irContainsCall) else -> throw AssertionError("Unexpected in-operator $irOperator") @@ -159,14 +160,16 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : Stat val irArgument1 = statementGenerator.generateExpression(expression.right!!) - val irIdentityEquals = IrBinaryPrimitiveImpl(expression.startOffset, expression.endOffset, irOperator, context.irBuiltIns.eqeqeq, + val irIdentityEquals = IrBinaryPrimitiveImpl(expression.startOffset, expression.endOffset, irOperator, + context.irBuiltIns.eqeqeqSymbol, irArgument0, irArgument1) return when (irOperator) { IrStatementOrigin.EQEQEQ -> irIdentityEquals IrStatementOrigin.EXCLEQEQ -> - IrUnaryPrimitiveImpl(expression.startOffset, expression.endOffset, IrStatementOrigin.EXCLEQEQ, context.irBuiltIns.booleanNot, + IrUnaryPrimitiveImpl(expression.startOffset, expression.endOffset, IrStatementOrigin.EXCLEQEQ, + context.irBuiltIns.booleanNotSymbol, irIdentityEquals) else -> throw AssertionError("Unexpected identity operator $irOperator") @@ -179,14 +182,17 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : Stat val irArgument1 = statementGenerator.generateExpression(expression.right!!) val irEquals = IrBinaryPrimitiveImpl(expression.startOffset, expression.endOffset, - irOperator, context.irBuiltIns.eqeq, irArgument0, irArgument1) + irOperator, + context.irBuiltIns.eqeqSymbol, + irArgument0, irArgument1) return when (irOperator) { IrStatementOrigin.EQEQ -> irEquals IrStatementOrigin.EXCLEQ -> IrUnaryPrimitiveImpl(expression.startOffset, expression.endOffset, IrStatementOrigin.EXCLEQ, - context.irBuiltIns.booleanNot, irEquals) + context.irBuiltIns.booleanNotSymbol, + irEquals) else -> throw AssertionError("Unexpected equality operator $irOperator") } @@ -198,15 +204,15 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : Stat val irCompareToCall = CallGenerator(statementGenerator).generateCall(expression, statementGenerator.pregenerateCall(compareToCall), origin) - val compareToZeroDescriptor = when (origin) { - IrStatementOrigin.LT -> context.irBuiltIns.lt0 - IrStatementOrigin.LTEQ -> context.irBuiltIns.lteq0 - IrStatementOrigin.GT -> context.irBuiltIns.gt0 - IrStatementOrigin.GTEQ -> context.irBuiltIns.gteq0 + val compareToZeroSymbol = when (origin) { + IrStatementOrigin.LT -> context.irBuiltIns.lt0Symbol + IrStatementOrigin.LTEQ -> context.irBuiltIns.lteq0Symbol + IrStatementOrigin.GT -> context.irBuiltIns.gt0Symbol + IrStatementOrigin.GTEQ -> context.irBuiltIns.gteq0Symbol else -> throw AssertionError("Unexpected comparison operator: $origin") } - return IrUnaryPrimitiveImpl(expression.startOffset, expression.endOffset, origin, compareToZeroDescriptor, irCompareToCall) + return IrUnaryPrimitiveImpl(expression.startOffset, expression.endOffset, origin, compareToZeroSymbol, irCompareToCall) } private fun generateExclExclOperator(expression: KtPostfixExpression, origin: IrStatementOrigin): IrExpression { @@ -217,8 +223,8 @@ class OperatorExpressionGenerator(statementGenerator: StatementGenerator) : Stat val resultType = irArgument.type.makeNotNullable() return irBlock(ktOperator, origin, resultType) { - val temporary = defineTemporary(irArgument, "notnull") - +irIfNull(resultType, irGet(temporary), irThrowNpe(origin), irGet(temporary)) + val temporary = irTemporary(irArgument, "notnull") + +irIfNull(resultType, irGet(temporary.symbol), irThrowNpe(origin), irGet(temporary.symbol)) } } diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/PropertyGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/PropertyGenerator.kt index 76e541f4b12..deedca17b8d 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/PropertyGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/PropertyGenerator.kt @@ -41,8 +41,7 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio generateSimpleProperty(ktProperty, propertyDescriptor) } - fun generatePropertyForPrimaryConstructorParameter(ktParameter: KtParameter): IrDeclaration { - val valueParameterDescriptor = getOrFail(BindingContext.VALUE_PARAMETER, ktParameter) + fun generatePropertyForPrimaryConstructorParameter(ktParameter: KtParameter, irValueParameter: IrValueParameter): IrDeclaration { val propertyDescriptor = getOrFail(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, ktParameter) return IrPropertyImpl( @@ -54,18 +53,19 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio generatePropertyBackingField(ktParameter, propertyDescriptor) { IrExpressionBodyImpl(IrGetValueImpl( ktParameter.startOffset, ktParameter.endOffset, - valueParameterDescriptor, IrStatementOrigin.INITIALIZE_PROPERTY_FROM_PARAMETER + irValueParameter.symbol, + IrStatementOrigin.INITIALIZE_PROPERTY_FROM_PARAMETER )) } val getter = propertyDescriptor.getter ?: throw AssertionError("Property declared in primary constructor has no getter: $propertyDescriptor") - irProperty.getter = FunctionGenerator(declarationGenerator).generateDefaultAccessorForPrimaryConstructorParameter(getter, ktParameter, isGetter = true) + irProperty.getter = FunctionGenerator(declarationGenerator).generateDefaultAccessorForPrimaryConstructorParameter(getter, ktParameter) if (propertyDescriptor.isVar) { val setter = propertyDescriptor.setter ?: throw AssertionError("Property declared in primary constructor has no setter: $propertyDescriptor") - irProperty.setter = FunctionGenerator(declarationGenerator).generateDefaultAccessorForPrimaryConstructorParameter(setter, ktParameter, isGetter = false) + irProperty.setter = FunctionGenerator(declarationGenerator).generateDefaultAccessorForPrimaryConstructorParameter(setter, ktParameter) } } } @@ -73,21 +73,24 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio private inline fun generatePropertyBackingField( ktPropertyElement: KtElement, propertyDescriptor: PropertyDescriptor, - generateInitializer: () -> IrExpressionBody? + generateInitializer: (IrField) -> IrExpressionBody? ) : IrField = context.symbolTable.declareField( ktPropertyElement.startOffset, ktPropertyElement.endOffset, IrDeclarationOrigin.PROPERTY_BACKING_FIELD, - propertyDescriptor, - generateInitializer() - ) + propertyDescriptor + ).also { + it.initializer = generateInitializer(it) + } - private fun generateDelegatedProperty(ktProperty: KtProperty, ktDelegate: KtPropertyDelegate, propertyDescriptor: PropertyDescriptor): IrProperty { - val ktDelegateExpression = ktDelegate.expression!! - val irDelegateInitializer = declarationGenerator.generateInitializerBody(propertyDescriptor, ktDelegateExpression) - return DelegatedPropertyGenerator(declarationGenerator).generateDelegatedProperty(ktProperty, ktDelegate, propertyDescriptor, irDelegateInitializer) - } + private fun generateDelegatedProperty( + ktProperty: KtProperty, + ktDelegate: KtPropertyDelegate, + propertyDescriptor: PropertyDescriptor + ): IrProperty = + DelegatedPropertyGenerator(declarationGenerator) + .generateDelegatedProperty(ktProperty, ktDelegate, propertyDescriptor) private fun generateSimpleProperty(ktProperty: KtProperty, propertyDescriptor: PropertyDescriptor): IrProperty = IrPropertyImpl( @@ -97,8 +100,10 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio ).apply { backingField = if (propertyDescriptor.hasBackingField()) - generatePropertyBackingField(ktProperty, propertyDescriptor) { - ktProperty.initializer?.let { declarationGenerator.generateInitializerBody(propertyDescriptor, it) } + generatePropertyBackingField(ktProperty, propertyDescriptor) { irField -> + ktProperty.initializer?.let { ktInitializer -> + declarationGenerator.generateInitializerBody(irField.symbol, ktInitializer) + } } else null diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt index 64400d21218..101d2529c5a 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ReflectionReferencesGenerator.kt @@ -16,17 +16,17 @@ package org.jetbrains.kotlin.psi2ir.generators -import org.jetbrains.kotlin.descriptors.ClassifierDescriptor -import org.jetbrains.kotlin.ir.expressions.IrExpression -import org.jetbrains.kotlin.ir.expressions.impl.IrCallableReferenceImpl -import org.jetbrains.kotlin.ir.expressions.impl.IrClassReferenceImpl -import org.jetbrains.kotlin.ir.expressions.impl.IrGetClassImpl +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.ir.expressions.* +import org.jetbrains.kotlin.ir.expressions.impl.* +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.psi.KtCallableReferenceExpression import org.jetbrains.kotlin.psi.KtClassLiteralExpression import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.scopes.receivers.TransientReceiver +import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.expressions.DoubleColonLHS class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : StatementGeneratorExtension(statementGenerator) { @@ -43,15 +43,19 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St val typeConstructorDeclaration = lhs.type.constructor.declarationDescriptor val typeClass = typeConstructorDeclaration as? ClassifierDescriptor ?: throw AssertionError("Unexpected type constructor for ${lhs.type}: $typeConstructorDeclaration") - IrClassReferenceImpl(ktClassLiteral.startOffset, ktClassLiteral.endOffset, resultType, typeClass) + IrClassReferenceImpl(ktClassLiteral.startOffset, ktClassLiteral.endOffset, resultType, + context.symbolTable.referenceClassifier(typeClass)) } } fun generateCallableReference(ktCallableReference: KtCallableReferenceExpression): IrExpression { val resolvedCall = getResolvedCall(ktCallableReference.callableReference)!! - val irCallableRef = IrCallableReferenceImpl(ktCallableReference.startOffset, ktCallableReference.endOffset, - getInferredTypeWithImplicitCastsOrFail(ktCallableReference), - resolvedCall.resultingDescriptor, null) + val irCallableRef = generateCallableReference( + ktCallableReference.startOffset, ktCallableReference.endOffset, + getInferredTypeWithImplicitCastsOrFail(ktCallableReference), + resolvedCall.resultingDescriptor, + typeArguments = null + ) resolvedCall.dispatchReceiver?.let { dispatchReceiver -> if (dispatchReceiver !is TransientReceiver) { irCallableRef.dispatchReceiver = statementGenerator.generateReceiver(ktCallableReference, dispatchReceiver).load() @@ -66,5 +70,64 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St return irCallableRef } + fun generateCallableReference( + startOffset: Int, + endOffset: Int, + type: KotlinType, + callableDescriptor: CallableDescriptor, + typeArguments: Map?, + origin: IrStatementOrigin? = null + ): IrCallableReference = + when (callableDescriptor) { + is FunctionDescriptor -> + generateFunctionReference( + startOffset, endOffset, type, + context.symbolTable.referenceFunction(callableDescriptor), + typeArguments, + origin + ) + is PropertyDescriptor -> + generatePropertyReference(startOffset, endOffset, type, callableDescriptor, typeArguments, origin) + else -> + throw AssertionError("Unexpected callable reference: $callableDescriptor") + } + private fun generatePropertyReference( + startOffset: Int, + endOffset: Int, + type: KotlinType, + propertyDescriptor: PropertyDescriptor, + typeArguments: Map?, + origin: IrStatementOrigin? + ): IrPropertyReference { + val getterDescriptor = propertyDescriptor.getter + val setterDescriptor = propertyDescriptor.setter + + val fieldSymbol = if (getterDescriptor == null) context.symbolTable.referenceField(propertyDescriptor) else null + val getterSymbol = getterDescriptor?.let { context.symbolTable.referenceFunction(it) } + val setterSymbol = setterDescriptor?.let { context.symbolTable.referenceFunction(it) } + + return IrPropertyReferenceImpl( + startOffset, endOffset, type, + propertyDescriptor, + fieldSymbol, getterSymbol, setterSymbol, + typeArguments, + origin + ) + } + + fun generateFunctionReference( + startOffset: Int, + endOffset: Int, + type: KotlinType, + symbol: IrFunctionSymbol, + typeArguments: Map?, + origin: IrStatementOrigin? + ): IrFunctionReference = + IrFunctionReferenceImpl( + startOffset, endOffset, type, + symbol, + typeArguments, + origin + ) } \ No newline at end of file diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/StatementGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/StatementGenerator.kt index f2a3bbf9cd9..ae637bbc9e1 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/StatementGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/StatementGenerator.kt @@ -27,6 +27,7 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.impl.IrTypeAliasImpl import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* +import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.psi.* import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffset @@ -74,7 +75,8 @@ class StatementGenerator( val variableDescriptor = getOrFail(BindingContext.VARIABLE, property) property.delegate?.let { ktDelegate -> - return generateLocalDelegatedProperty(property, ktDelegate, variableDescriptor as VariableDescriptorWithAccessors) + return generateLocalDelegatedProperty(property, ktDelegate, variableDescriptor as VariableDescriptorWithAccessors, + bodyGenerator.scopeOwnerSymbol) } return context.symbolTable.declareVariable( @@ -86,12 +88,11 @@ class StatementGenerator( private fun generateLocalDelegatedProperty( ktProperty: KtProperty, ktDelegate: KtPropertyDelegate, - variableDescriptor: VariableDescriptorWithAccessors + variableDescriptor: VariableDescriptorWithAccessors, + scopeOwnerSymbol: IrSymbol ): IrStatement = - DelegatedPropertyGenerator(context).generateLocalDelegatedProperty( - ktProperty, ktDelegate, variableDescriptor, - ktDelegate.expression!!.genExpr() - ) + DelegatedPropertyGenerator(context) + .generateLocalDelegatedProperty(ktProperty, ktDelegate, variableDescriptor, scopeOwnerSymbol) override fun visitDestructuringDeclaration(multiDeclaration: KtDestructuringDeclaration, data: Nothing?): IrStatement { val irBlock = IrCompositeImpl(multiDeclaration.startOffset, multiDeclaration.endOffset, @@ -144,8 +145,10 @@ class StatementGenerator( override fun visitReturnExpression(expression: KtReturnExpression, data: Nothing?): IrStatement { val returnTarget = getReturnExpressionTarget(expression) val irReturnedExpression = expression.returnedExpression?.genExpr() ?: - IrGetObjectValueImpl(expression.startOffset, expression.endOffset, context.builtIns.unitType, context.builtIns.unit) - return IrReturnImpl(expression.startOffset, expression.endOffset, context.builtIns.nothingType, returnTarget, irReturnedExpression) + IrGetObjectValueImpl(expression.startOffset, expression.endOffset, context.builtIns.unitType, + context.symbolTable.referenceClass(context.builtIns.unit)) + return IrReturnImpl(expression.startOffset, expression.endOffset, context.builtIns.nothingType, + context.symbolTable.referenceFunction(returnTarget), irReturnedExpression) } private fun scopeOwnerAsCallable() = @@ -297,10 +300,12 @@ class StatementGenerator( val referenceTarget = getOrFail(BindingContext.REFERENCE_TARGET, expression.instanceReference) { "No reference target for this" } return when (referenceTarget) { is ClassDescriptor -> - IrGetValueImpl(expression.startOffset, expression.endOffset, referenceTarget.thisAsReceiverParameter) + IrGetValueImpl(expression.startOffset, expression.endOffset, + context.symbolTable.referenceValueParameter(referenceTarget.thisAsReceiverParameter)) is CallableDescriptor -> { val extensionReceiver = referenceTarget.extensionReceiverParameter ?: TODO("No extension receiver: $referenceTarget") - IrGetValueImpl(expression.startOffset, expression.endOffset, extensionReceiver) + IrGetValueImpl(expression.startOffset, expression.endOffset, + context.symbolTable.referenceValueParameter(extensionReceiver)) } else -> error("Expected this or receiver: $referenceTarget") diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/SymbolTable.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/SymbolTable.kt index a7eb63987ad..7cff5c60aaa 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/SymbolTable.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/SymbolTable.kt @@ -98,6 +98,18 @@ class SymbolTable { operator fun set(d: D, s: S) { descriptorToSymbol[d] = s } + + fun dumpTo(stringBuilder: StringBuilder): StringBuilder = + stringBuilder.also { + it.append("owner=") + it.append(owner) + it.append("; ") + descriptorToSymbol.keys.joinTo(prefix = "[", postfix = "]", buffer = it) + it.append('\n') + parent?.dumpTo(it) + } + + fun dump(): String = dumpTo(StringBuilder()).toString() } private var currentScope: Scope? = null @@ -131,9 +143,12 @@ class SymbolTable { currentScope = currentScope?.parent if (currentScope != null && unboundSymbols.isNotEmpty()) { - throw AssertionError("") + throw AssertionError("Local scope contains unbound symbols: ${unboundSymbols.joinToString { it.descriptor.toString() }}") } } + + fun dump(): String = + currentScope?.dump() ?: "" } private val classSymbolTable = FlatSymbolTable() @@ -148,14 +163,11 @@ class SymbolTable { private val scopedSymbolTables = listOf(typeParameterSymbolTable, valueParameterSymbolTable, variableSymbolTable) fun declareFile(fileEntry: SourceManager.FileEntry, packageFragmentDescriptor: PackageFragmentDescriptor): IrFile = - IrFileImpl( - fileEntry, packageFragmentDescriptor, - IrFileSymbolImpl(packageFragmentDescriptor) - ) + IrFileImpl(fileEntry, IrFileSymbolImpl(packageFragmentDescriptor)) fun declareAnonymousInitializer(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassDescriptor): IrAnonymousInitializer = IrAnonymousInitializerImpl( - startOffset, endOffset, origin, descriptor, + startOffset, endOffset, origin, IrAnonymousInitializerSymbolImpl(descriptor) ) @@ -163,7 +175,7 @@ class SymbolTable { classSymbolTable.declare( descriptor, { IrClassSymbolImpl(descriptor) }, - { IrClassImpl(startOffset, endOffset, origin, descriptor, it) } + { IrClassImpl(startOffset, endOffset, origin, it) } ) @@ -176,7 +188,7 @@ class SymbolTable { constructorSymbolTable.declare( descriptor, { IrConstructorSymbolImpl(descriptor) }, - { IrConstructorImpl(startOffset, endOffset, origin, descriptor, it) } + { IrConstructorImpl(startOffset, endOffset, origin, it) } ) fun referenceConstructor(descriptor: ClassConstructorDescriptor) = @@ -188,7 +200,7 @@ class SymbolTable { enumEntrySymbolTable.declare( descriptor, { IrEnumEntrySymbolImpl(descriptor) }, - { IrEnumEntryImpl(startOffset, endOffset, origin, descriptor, it) } + { IrEnumEntryImpl(startOffset, endOffset, origin, it) } ) fun referenceEnumEntry(descriptor: ClassDescriptor) = @@ -200,7 +212,7 @@ class SymbolTable { fieldSymbolTable.declare( descriptor, { IrFieldSymbolImpl(descriptor) }, - { IrFieldImpl(startOffset, endOffset, origin, descriptor, it) } + { IrFieldImpl(startOffset, endOffset, origin, it) } ) fun declareField(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: PropertyDescriptor, @@ -216,23 +228,26 @@ class SymbolTable { simpleFunctionSymbolTable.declare( descriptor, { IrSimpleFunctionSymbolImpl(descriptor) }, - { IrFunctionImpl(startOffset, endOffset, origin, descriptor, it) } + { IrFunctionImpl(startOffset, endOffset, origin, it) } ) fun referenceSimpleFunction(descriptor: FunctionDescriptor) = simpleFunctionSymbolTable.referenced(descriptor) { IrSimpleFunctionSymbolImpl(descriptor) } + fun referenceDeclaredFunction(descriptor: FunctionDescriptor) = + simpleFunctionSymbolTable.referenced(descriptor) { throw AssertionError("Function is not declared: $descriptor") } + val unboundSimpleFunctions: Set get() = simpleFunctionSymbolTable.unboundSymbols fun declareTypeParameter(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: TypeParameterDescriptor) : IrTypeParameter = typeParameterSymbolTable.declareLocal( descriptor, { IrTypeParameterSymbolImpl(descriptor) }, - { IrTypeParameterImpl(startOffset, endOffset, origin, descriptor, it) } + { IrTypeParameterImpl(startOffset, endOffset, origin, it) } ) fun referenceTypeParameter(descriptor: TypeParameterDescriptor) = - typeParameterSymbolTable.referenced(descriptor) { IrTypeParameterSymbolImpl(descriptor) } + typeParameterSymbolTable.referenced(descriptor) { throw AssertionError("Undefined type parameter referenced: $descriptor") } val unboundTypeParameters: Set get() = typeParameterSymbolTable.unboundSymbols @@ -240,11 +255,13 @@ class SymbolTable { valueParameterSymbolTable.declareLocal( descriptor, { IrValueParameterSymbolImpl(descriptor) }, - { IrValueParameterImpl(startOffset, endOffset, origin, descriptor, it) } + { IrValueParameterImpl(startOffset, endOffset, origin, it) } ) fun referenceValueParameter(descriptor: ParameterDescriptor) = - valueParameterSymbolTable.referenced(descriptor) { IrValueParameterSymbolImpl(descriptor) } + valueParameterSymbolTable.referenced(descriptor) { + throw AssertionError("Undefined parameter referenced: $descriptor\n${valueParameterSymbolTable.dump()}") + } val unboundValueParameters: Set get() = valueParameterSymbolTable.unboundSymbols @@ -252,18 +269,20 @@ class SymbolTable { variableSymbolTable.declareLocal( descriptor, { IrVariableSymbolImpl(descriptor) }, - { IrVariableImpl(startOffset, endOffset, origin, descriptor, it) } + { IrVariableImpl(startOffset, endOffset, origin, it) } ) - fun declareVariable(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: VariableDescriptor, - irInitializerExpression: IrExpression? + fun declareVariable( + startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, + descriptor: VariableDescriptor, + irInitializerExpression: IrExpression? ): IrVariable = declareVariable(startOffset, endOffset, origin, descriptor).apply { initializer = irInitializerExpression } fun referenceVariable(descriptor: VariableDescriptor) = - variableSymbolTable.referenced(descriptor) { IrVariableSymbolImpl(descriptor) } + variableSymbolTable.referenced(descriptor) { throw AssertionError("Undefined variable referenced: $descriptor") } val unboundVariables: Set get() = variableSymbolTable.unboundSymbols @@ -274,6 +293,36 @@ class SymbolTable { fun leaveScope(owner: DeclarationDescriptor) { scopedSymbolTables.forEach { it.leaveScope(owner) } } + + fun referenceFunction(callable: CallableDescriptor): IrFunctionSymbol = + when (callable) { + is ClassConstructorDescriptor -> + constructorSymbolTable.referenced(callable) { IrConstructorSymbolImpl(callable) } + is FunctionDescriptor -> + simpleFunctionSymbolTable.referenced(callable) { IrSimpleFunctionSymbolImpl(callable) } + else -> + throw IllegalArgumentException("Unexpected callable descriptor: $callable") + } + + fun referenceValue(value: ValueDescriptor): IrValueSymbol = + when (value) { + is ParameterDescriptor -> + valueParameterSymbolTable.referenced(value) { throw AssertionError("Undefined parameter referenced: $value") } + is VariableDescriptor -> + variableSymbolTable.referenced(value) { throw AssertionError("Undefined variable referenced: $value") } + else -> + throw IllegalArgumentException("Unexpected value descriptor: $value") + } + + fun referenceClassifier(classifier: ClassifierDescriptor): IrClassifierSymbol = + when (classifier) { + is TypeParameterDescriptor -> + typeParameterSymbolTable.referenced(classifier) { throw AssertionError("Undefined type parameter referenced: $classifier") } + is ClassDescriptor -> + classSymbolTable.referenced(classifier) { IrClassSymbolImpl(classifier) } + else -> + throw IllegalArgumentException("Unexpected classifier descriptor: $classifier") + } } inline fun SymbolTable.withScope(owner: DeclarationDescriptor, block: () -> T): T { diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/TryCatchExpressionGenerator.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/TryCatchExpressionGenerator.kt index e260e1e5b0f..eea7e023844 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/TryCatchExpressionGenerator.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/TryCatchExpressionGenerator.kt @@ -16,6 +16,8 @@ package org.jetbrains.kotlin.psi2ir.generators +import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin +import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.impl.IrCatchImpl import org.jetbrains.kotlin.ir.expressions.impl.IrTryImpl @@ -36,8 +38,16 @@ class TryCatchExpressionGenerator(statementGenerator: StatementGenerator) : Stat val ktCatchBody = ktCatchClause.catchBody!! val catchParameterDescriptor = getOrFail(BindingContext.VALUE_PARAMETER, ktCatchParameter) val irCatchResult = statementGenerator.generateExpression(ktCatchBody) - val irCatch = IrCatchImpl(ktCatchClause.startOffset, ktCatchClause.endOffset, - catchParameterDescriptor, irCatchResult) + + val irCatch = IrCatchImpl( + ktCatchClause.startOffset, ktCatchClause.endOffset, + context.symbolTable.declareVariable( + ktCatchParameter.startOffset, ktCatchParameter.endOffset, + IrDeclarationOrigin.CATCH_PARAMETER, + catchParameterDescriptor + ), + irCatchResult + ) irTryCatch.catches.add(irCatch) } diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/BackingFieldLValue.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/BackingFieldLValue.kt index 80bb9dec4f9..1159a3578c0 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/BackingFieldLValue.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/BackingFieldLValue.kt @@ -16,27 +16,26 @@ package org.jetbrains.kotlin.psi2ir.intermediate -import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin import org.jetbrains.kotlin.ir.expressions.impl.IrGetFieldImpl import org.jetbrains.kotlin.ir.expressions.impl.IrSetFieldImpl +import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol import org.jetbrains.kotlin.types.KotlinType class BackingFieldLValue( val startOffset: Int, val endOffset: Int, - val descriptor: PropertyDescriptor, + override val type: KotlinType, + val symbol: IrFieldSymbol, val receiver: IntermediateValue?, val origin: IrStatementOrigin? ) : LValue, AssignmentReceiver { - override val type: KotlinType get() = descriptor.type - override fun store(irExpression: IrExpression): IrExpression = - IrSetFieldImpl(startOffset, endOffset, descriptor, receiver?.load(), irExpression, origin) + IrSetFieldImpl(startOffset, endOffset, symbol, receiver?.load(), irExpression, origin) override fun load(): IrExpression = - IrGetFieldImpl(startOffset, endOffset, descriptor, receiver?.load(), origin) + IrGetFieldImpl(startOffset, endOffset, symbol, receiver?.load(), origin) override fun assign(withLValue: (LValue) -> IrExpression): IrExpression = withLValue(this) diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/DelegatedLocalPropertyLValue.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/DelegatedLocalPropertyLValue.kt index 20dab0f9d30..23f0b80a812 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/DelegatedLocalPropertyLValue.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/DelegatedLocalPropertyLValue.kt @@ -16,25 +16,25 @@ package org.jetbrains.kotlin.psi2ir.intermediate -import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl +import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol import org.jetbrains.kotlin.types.KotlinType class DelegatedLocalPropertyLValue( val startOffset: Int, val endOffset: Int, - val descriptor: VariableDescriptorWithAccessors, + override val type: KotlinType, + val getterSymbol: IrSimpleFunctionSymbol?, + val setterSymbol: IrSimpleFunctionSymbol?, val origin: IrStatementOrigin? = null ) : LValue, AssignmentReceiver { - override val type: KotlinType get() = descriptor.type - override fun load(): IrExpression = - IrCallImpl(startOffset, endOffset, descriptor.type, descriptor.getter!!, null, origin) + IrCallImpl(startOffset, endOffset, type, getterSymbol!!, null, origin) override fun store(irExpression: IrExpression): IrExpression = - IrCallImpl(startOffset, endOffset, descriptor.type, descriptor.setter!!, null, origin).apply { + IrCallImpl(startOffset, endOffset, type, setterSymbol!!, null, origin).apply { putValueArgument(0, irExpression) } diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/LValueWithGetterAndSetterCalls.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/LValueWithGetterAndSetterCalls.kt index 47a916b0eaa..43ae0e6bd22 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/LValueWithGetterAndSetterCalls.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/LValueWithGetterAndSetterCalls.kt @@ -32,7 +32,8 @@ class LValueWithGetterAndSetterCalls( val origin: IrStatementOrigin? = null ) : LValue { private val descriptor: CallableDescriptor = - getterCall?.descriptor ?: setterCall?.descriptor ?: + getterCall?.descriptor ?: + setterCall?.descriptor ?: throw AssertionError("Call-based LValue should have either a getter or a setter call") override fun load(): IrExpression { diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/PropertyLValue.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/PropertyLValue.kt new file mode 100644 index 00000000000..4fb3d8633b0 --- /dev/null +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/PropertyLValue.kt @@ -0,0 +1,155 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.psi2ir.intermediate + +import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor +import org.jetbrains.kotlin.ir.builders.Scope +import org.jetbrains.kotlin.ir.expressions.IrExpression +import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin +import org.jetbrains.kotlin.ir.expressions.impl.* +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol +import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol +import org.jetbrains.kotlin.types.KotlinType + +abstract class PropertyLValueBase( + val scope: Scope, + val startOffset: Int, + val endOffset: Int, + val origin: IrStatementOrigin?, + override val type: KotlinType, + val callReceiver: CallReceiver, + val superQualifier: IrClassSymbol? +) : LValue, AssignmentReceiver { + override fun assign(withLValue: (LValue) -> IrExpression) = + callReceiver.call { dispatchReceiverValue, extensionReceiverValue -> + val dispatchReceiverVariable2 = dispatchReceiverValue?.let { + scope.createTemporaryVariable(dispatchReceiverValue.load(), "this") + } + val dispatchReceiverValue2 = dispatchReceiverVariable2?.let { VariableLValue(it) } + + val extensionReceiverVariable2 = extensionReceiverValue?.let { + scope.createTemporaryVariable(extensionReceiverValue.load(), "receiver") + } + val extensionReceiverValue2 = extensionReceiverVariable2?.let { VariableLValue(it) } + + val irResultExpression = withLValue(withReceiver(dispatchReceiverValue2, extensionReceiverValue2)) + + val irBlock = IrBlockImpl(startOffset, endOffset, irResultExpression.type, origin) + irBlock.addIfNotNull(dispatchReceiverVariable2) + irBlock.addIfNotNull(extensionReceiverVariable2) + irBlock.statements.add(irResultExpression) + irBlock + } + + override fun assign(value: IrExpression): IrExpression = + store(value) + + protected abstract fun withReceiver(dispatchReceiver: VariableLValue?, extensionReceiver: VariableLValue?): PropertyLValueBase +} + +class FieldPropertyLValue( + scope: Scope, + startOffset: Int, + endOffset: Int, + origin: IrStatementOrigin?, + val field: IrFieldSymbol, + callReceiver: CallReceiver, + superQualifier: IrClassSymbol? +) : PropertyLValueBase(scope, startOffset, endOffset, origin, field.descriptor.type, callReceiver, superQualifier) { + override fun load(): IrExpression = + callReceiver.call { dispatchReceiverValue, extensionReceiverValue -> + assert(extensionReceiverValue == null) { "Field can't have an extension receiver: ${field.descriptor}" } + IrGetFieldImpl( + startOffset, endOffset, + field, + dispatchReceiverValue?.load(), + origin, + superQualifier + ) + } + + override fun store(irExpression: IrExpression) = + callReceiver.call { dispatchReceiverValue, extensionReceiverValue -> + assert(extensionReceiverValue == null) { "Field can't have an extension receiver: ${field.descriptor}" } + IrSetFieldImpl( + startOffset, endOffset, + field, + dispatchReceiverValue?.load(), + irExpression, + origin, + superQualifier + ) + } + + override fun withReceiver(dispatchReceiver: VariableLValue?, extensionReceiver: VariableLValue?): PropertyLValueBase = + FieldPropertyLValue( + scope, startOffset, endOffset, origin, + field, + SimpleCallReceiver(dispatchReceiver, extensionReceiver), + superQualifier + ) +} + +class AccessorPropertyLValue( + scope: Scope, + startOffset: Int, + endOffset: Int, + origin: IrStatementOrigin?, + type: KotlinType, + val getter: IrFunctionSymbol?, + val setter: IrFunctionSymbol?, + val typeArguments: Map?, + callReceiver: CallReceiver, + superQualifier: IrClassSymbol? +) : PropertyLValueBase(scope, startOffset, endOffset, origin, type, callReceiver, superQualifier) { + override fun load(): IrExpression = + callReceiver.call { dispatchReceiverValue, extensionReceiverValue -> + IrGetterCallImpl( + startOffset, endOffset, + getter!!, + typeArguments, + dispatchReceiverValue?.load(), + extensionReceiverValue?.load(), + origin, + superQualifier + ) + } + + override fun store(irExpression: IrExpression) = + callReceiver.call { dispatchReceiverValue, extensionReceiverValue -> + IrSetterCallImpl( + startOffset, endOffset, + setter!!, + typeArguments, + dispatchReceiverValue?.load(), + extensionReceiverValue?.load(), + irExpression, + origin, + superQualifier + ) + } + + override fun withReceiver(dispatchReceiver: VariableLValue?, extensionReceiver: VariableLValue?): PropertyLValueBase = + AccessorPropertyLValue( + scope, startOffset, endOffset, origin, + type, getter, setter, + typeArguments, + SimpleCallReceiver(dispatchReceiver, extensionReceiver), + superQualifier + ) +} \ No newline at end of file diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/SimplePropertyLValue.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/SimplePropertyLValue.kt deleted file mode 100644 index 4d1639207f4..00000000000 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/SimplePropertyLValue.kt +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.psi2ir.intermediate - -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.PropertyDescriptor -import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor -import org.jetbrains.kotlin.ir.builders.Scope -import org.jetbrains.kotlin.ir.expressions.IrExpression -import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin -import org.jetbrains.kotlin.ir.expressions.impl.* -import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext -import org.jetbrains.kotlin.types.KotlinType - -class SimplePropertyLValue( - val context: GeneratorContext, - val scope: Scope, - val startOffset: Int, - val endOffset: Int, - val origin: IrStatementOrigin?, - val descriptor: PropertyDescriptor, - val typeArguments: Map?, - val callReceiver: CallReceiver, - val superQualifier: ClassDescriptor? -) : LValue, AssignmentReceiver { - override val type: KotlinType get() = descriptor.type - - override fun load(): IrExpression = - callReceiver.call { dispatchReceiverValue, extensionReceiverValue -> - descriptor.getter?.let { getter -> - IrGetterCallImpl(startOffset, endOffset, getter, typeArguments, - dispatchReceiverValue?.load(), - extensionReceiverValue?.load(), - origin, - superQualifier) - } ?: IrGetFieldImpl(startOffset, endOffset, descriptor, - dispatchReceiverValue?.load(), origin, superQualifier) - } - - override fun store(irExpression: IrExpression) = - callReceiver.call { dispatchReceiverValue, extensionReceiverValue -> - descriptor.setter?.let { setter -> - IrSetterCallImpl(startOffset, endOffset, setter, typeArguments, - dispatchReceiverValue?.load(), - extensionReceiverValue?.load(), - irExpression, - origin, - superQualifier) - } ?: IrSetFieldImpl(startOffset, endOffset, descriptor, - dispatchReceiverValue?.load(), irExpression, origin, superQualifier) - } - - override fun assign(withLValue: (LValue) -> IrExpression) = - callReceiver.call { dispatchReceiverValue, extensionReceiverValue -> - val dispatchReceiverTmp = dispatchReceiverValue?.let { - scope.createTemporaryVariable(dispatchReceiverValue.load(), "this") - } - val dispatchReceiverValue2 = dispatchReceiverTmp?.let { VariableLValue(it) } - - val extensionReceiverTmp = extensionReceiverValue?.let { - scope.createTemporaryVariable(extensionReceiverValue.load(), "receiver") - } - val extensionReceiverValue2 = extensionReceiverTmp?.let { VariableLValue(it) } - - val irResultExpression = withLValue( - SimplePropertyLValue(context, scope, startOffset, endOffset, origin, descriptor, typeArguments, - SimpleCallReceiver(dispatchReceiverValue2, extensionReceiverValue2), - superQualifier) - ) - - val irBlock = IrBlockImpl(startOffset, endOffset, irResultExpression.type, origin) - irBlock.addIfNotNull(dispatchReceiverTmp) - irBlock.addIfNotNull(extensionReceiverTmp) - irBlock.statements.add(irResultExpression) - irBlock - } - - override fun assign(value: IrExpression): IrExpression = - store(value) -} \ No newline at end of file diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/VariableLValue.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/VariableLValue.kt index 3a5e2dc38fb..4d4cc5a6eb0 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/VariableLValue.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/intermediate/VariableLValue.kt @@ -16,30 +16,36 @@ package org.jetbrains.kotlin.psi2ir.intermediate -import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.ir.declarations.IrVariable import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl import org.jetbrains.kotlin.ir.expressions.impl.IrSetVariableImpl +import org.jetbrains.kotlin.ir.symbols.IrValueSymbol +import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol import org.jetbrains.kotlin.types.KotlinType +import org.jetbrains.kotlin.utils.addToStdlib.assertedCast class VariableLValue( val startOffset: Int, val endOffset: Int, - val descriptor: VariableDescriptor, + val symbol: IrValueSymbol, val origin: IrStatementOrigin? = null ) : LValue, AssignmentReceiver { constructor(irVariable: IrVariable, origin: IrStatementOrigin? = null) : this( - irVariable.startOffset, irVariable.endOffset, irVariable.descriptor, origin) + irVariable.startOffset, irVariable.endOffset, irVariable.symbol, origin) - override val type: KotlinType get() = descriptor.type + override val type: KotlinType get() = symbol.descriptor.type override fun load(): IrExpression = - IrGetValueImpl(startOffset, endOffset, descriptor, origin) + IrGetValueImpl(startOffset, endOffset, symbol, origin) override fun store(irExpression: IrExpression): IrExpression = - IrSetVariableImpl(startOffset, endOffset, descriptor, irExpression, origin) + IrSetVariableImpl( + startOffset, endOffset, + symbol.assertedCast { "Not a variable: ${symbol.descriptor}" }, + irExpression, origin + ) override fun assign(withLValue: (LValue) -> IrExpression): IrExpression = withLValue(this) diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/transformations/InsertImplicitCasts.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/transformations/InsertImplicitCasts.kt index 2e0c9d8dd7a..5aa0349c9c6 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/transformations/InsertImplicitCasts.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/transformations/InsertImplicitCasts.kt @@ -50,10 +50,19 @@ class InsertImplicitCasts(val builtIns: KotlinBuiltIns): IrElementTransformerVoi return element } + override fun visitCallableReference(expression: IrCallableReference): IrExpression = + expression.transformPostfix { + transformReceiverArguments() + } + + private fun IrMemberAccessExpression.transformReceiverArguments() { + dispatchReceiver = dispatchReceiver?.cast(descriptor.dispatchReceiverParameter?.type) + extensionReceiver = extensionReceiver?.cast(descriptor.extensionReceiverParameter?.type) + } + override fun visitMemberAccess(expression: IrMemberAccessExpression): IrExpression = expression.transformPostfix { - dispatchReceiver = dispatchReceiver?.cast(descriptor.dispatchReceiverParameter?.type) - extensionReceiver = extensionReceiver?.cast(descriptor.extensionReceiverParameter?.type) + transformReceiverArguments() for (index in descriptor.valueParameters.indices) { val argument = getValueArgument(index) ?: continue val parameterType = descriptor.valueParameters[index].type diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/ExpressionHelpers.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/ExpressionHelpers.kt index 443dced3974..8dc570aabc8 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/ExpressionHelpers.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/ExpressionHelpers.kt @@ -16,16 +16,16 @@ package org.jetbrains.kotlin.ir.builders -import org.jetbrains.kotlin.descriptors.CallableDescriptor -import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.ir.IrElement -import org.jetbrains.kotlin.ir.expressions.IrConstKind -import org.jetbrains.kotlin.ir.expressions.IrExpression -import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin -import org.jetbrains.kotlin.ir.expressions.IrTypeOperator +import org.jetbrains.kotlin.ir.declarations.IrVariable +import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol +import org.jetbrains.kotlin.ir.symbols.IrValueSymbol +import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol import org.jetbrains.kotlin.types.KotlinType +import org.jetbrains.kotlin.utils.addToStdlib.assertedCast inline fun IrBuilderWithScope.irLet( @@ -42,12 +42,40 @@ inline fun IrBuilderWithScope.irLet( return irBlock } +inline fun IrBuilderWithScope.irLetS( + value: IrExpression, + origin: IrStatementOrigin? = null, + nameHint: String? = null, + body: (IrValueSymbol) -> IrExpression +): IrExpression { + val irTemporary = scope.createTemporaryVariable(value, nameHint) + val irResult = body(irTemporary.symbol) + val irBlock = IrBlockImpl(startOffset, endOffset, irResult.type, origin) + irBlock.statements.add(irTemporary) + irBlock.statements.add(irResult) + return irBlock +} + + +fun IrStatementsBuilder.irTemporary(value: IrExpression, nameHint: String? = null): IrVariable { + val temporary = scope.createTemporaryVariable(value, nameHint) + +temporary + return temporary +} + fun IrStatementsBuilder.defineTemporary(value: IrExpression, nameHint: String? = null): VariableDescriptor { val temporary = scope.createTemporaryVariable(value, nameHint) +temporary return temporary.descriptor } +fun IrStatementsBuilder.irTemporaryVar(value: IrExpression, nameHint: String? = null): IrVariable { + val temporary = scope.createTemporaryVariable(value, nameHint, isMutable = true) + +temporary + return temporary +} + + fun IrStatementsBuilder.defineTemporaryVar(value: IrExpression, nameHint: String? = null): VariableDescriptor { val temporary = scope.createTemporaryVariable(value, nameHint, isMutable = true) +temporary @@ -58,7 +86,11 @@ fun IrBuilderWithScope.irExprBody(value: IrExpression) = IrExpressionBodyImpl(startOffset, endOffset, value) fun IrBuilderWithScope.irReturn(value: IrExpression) = - IrReturnImpl(startOffset, endOffset, context.builtIns.nothingType, scope.assertCastOwner(), value) + IrReturnImpl(startOffset, endOffset, context.builtIns.nothingType, + scope.scopeOwnerSymbol.assertedCast { + "Function scope expected: ${scope.scopeOwner}" + }, + value) fun IrBuilderWithScope.irReturnTrue() = irReturn(IrConstImpl(startOffset, endOffset, context.builtIns.booleanType, IrConstKind.Boolean, true)) @@ -73,7 +105,7 @@ fun IrBuilderWithScope.irIfNull(type: KotlinType, subject: IrExpression, thenPar irIfThenElse(type, irEqualsNull(subject), thenPart, elsePart) fun IrBuilderWithScope.irThrowNpe(origin: IrStatementOrigin) = - IrNullaryPrimitiveImpl(startOffset, endOffset, origin, context.irBuiltIns.throwNpe) + IrNullaryPrimitiveImpl(startOffset, endOffset, origin, context.irBuiltIns.throwNpeSymbol) fun IrBuilderWithScope.irIfThenReturnTrue(condition: IrExpression) = IrIfThenElseImpl(startOffset, endOffset, context.builtIns.unitType, condition, irReturnTrue()) @@ -81,20 +113,12 @@ fun IrBuilderWithScope.irIfThenReturnTrue(condition: IrExpression) = fun IrBuilderWithScope.irIfThenReturnFalse(condition: IrExpression) = IrIfThenElseImpl(startOffset, endOffset, context.builtIns.unitType, condition, irReturnFalse()) -fun IrBuilderWithScope.irThis() = - scope.classOwner().let { classOwner -> - IrGetValueImpl(startOffset, endOffset, classOwner.thisAsReceiverParameter) - } - -fun IrBuilderWithScope.irGet(variable: VariableDescriptor) = +fun IrBuilderWithScope.irGet(variable: IrValueSymbol) = IrGetValueImpl(startOffset, endOffset, variable) -fun IrBuilderWithScope.irSetVar(variable: VariableDescriptor, value: IrExpression) = +fun IrBuilderWithScope.irSetVar(variable: IrVariableSymbol, value: IrExpression) = IrSetVariableImpl(startOffset, endOffset, variable, value, IrStatementOrigin.EQ) -fun IrBuilderWithScope.irOther() = - irGet(scope.functionOwner().valueParameters.single()) - fun IrBuilderWithScope.irEqeqeq(arg1: IrExpression, arg2: IrExpression) = context.eqeqeq(startOffset, endOffset, arg1, arg2) @@ -102,22 +126,28 @@ fun IrBuilderWithScope.irNull() = IrConstImpl.constNull(startOffset, endOffset, context.builtIns.nullableNothingType) fun IrBuilderWithScope.irEqualsNull(argument: IrExpression) = - primitiveOp2(startOffset, endOffset, context.irBuiltIns.eqeq, IrStatementOrigin.EQEQ, + primitiveOp2(startOffset, endOffset, context.irBuiltIns.eqeqSymbol, IrStatementOrigin.EQEQ, argument, irNull()) fun IrBuilderWithScope.irNotEquals(arg1: IrExpression, arg2: IrExpression) = - primitiveOp1(startOffset, endOffset, context.irBuiltIns.booleanNot, IrStatementOrigin.EXCLEQ, - primitiveOp2(startOffset, endOffset, context.irBuiltIns.eqeq, IrStatementOrigin.EXCLEQ, + primitiveOp1(startOffset, endOffset, context.irBuiltIns.booleanNotSymbol, IrStatementOrigin.EXCLEQ, + primitiveOp2(startOffset, endOffset, context.irBuiltIns.eqeqSymbol, IrStatementOrigin.EXCLEQ, arg1, arg2)) -fun IrBuilderWithScope.irGet(receiver: IrExpression, property: PropertyDescriptor): IrExpression = - IrGetterCallImpl(startOffset, endOffset, property.getter!!, null, receiver, null, IrStatementOrigin.GET_PROPERTY) +fun IrBuilderWithScope.irGet(receiver: IrExpression, getterSymbol: IrFunctionSymbol): IrCall = + IrGetterCallImpl(startOffset, endOffset, getterSymbol, null, receiver, null, IrStatementOrigin.GET_PROPERTY) -fun IrBuilderWithScope.irCall(callee: CallableDescriptor) = - IrCallImpl(startOffset, endOffset, callee.returnType!!, callee, null) +fun IrBuilderWithScope.irCall(callee: IrFunctionSymbol, type: KotlinType): IrCall = + IrCallImpl(startOffset, endOffset, type, callee, null) -fun IrBuilderWithScope.irCallOp(callee: CallableDescriptor, dispatchReceiver: IrExpression, argument: IrExpression) = - IrCallImpl(startOffset, endOffset, callee.returnType!!, callee, null).apply { +fun IrBuilderWithScope.irCallOp(callee: IrFunctionSymbol, dispatchReceiver: IrExpression, argument: IrExpression): IrCall = + irCall(callee, callee.descriptor.returnType!!).apply { + this.dispatchReceiver = dispatchReceiver + putValueArgument(0, argument) + } + +fun IrBuilderWithScope.irCallOp(callee: IrFunctionSymbol, type: KotlinType, dispatchReceiver: IrExpression, argument: IrExpression): IrCall = + irCall(callee, type).apply { this.dispatchReceiver = dispatchReceiver putValueArgument(0, argument) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/Primitives.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/Primitives.kt index d18b6c7091a..1957eac625b 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/Primitives.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/Primitives.kt @@ -16,32 +16,38 @@ package org.jetbrains.kotlin.ir.builders -import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin import org.jetbrains.kotlin.ir.expressions.IrWhen import org.jetbrains.kotlin.ir.expressions.impl.* +import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol -fun primitiveOp1(startOffset: Int, endOffset: Int, primitiveOpDescriptor: CallableDescriptor, origin: IrStatementOrigin, - argument: IrExpression): IrExpression = - IrUnaryPrimitiveImpl(startOffset, endOffset, origin, primitiveOpDescriptor, argument) +fun primitiveOp1(startOffset: Int, endOffset: Int, + primitiveOpSymbol: IrSimpleFunctionSymbol, + origin: IrStatementOrigin, + argument: IrExpression +): IrExpression = + IrUnaryPrimitiveImpl(startOffset, endOffset, origin, primitiveOpSymbol, argument) -fun primitiveOp2(startOffset: Int, endOffset: Int, primitiveOpDescriptor: CallableDescriptor, origin: IrStatementOrigin, - argument1: IrExpression, argument2: IrExpression): IrExpression = - IrBinaryPrimitiveImpl(startOffset, endOffset, origin, primitiveOpDescriptor, argument1, argument2) +fun primitiveOp2(startOffset: Int, endOffset: Int, + primitiveOpSymbol: IrSimpleFunctionSymbol, + origin: IrStatementOrigin, + argument1: IrExpression, argument2: IrExpression +): IrExpression = + IrBinaryPrimitiveImpl(startOffset, endOffset, origin, primitiveOpSymbol, argument1, argument2) fun IrGeneratorContext.constNull(startOffset: Int, endOffset: Int): IrExpression = IrConstImpl.constNull(startOffset, endOffset, builtIns.nullableNothingType) fun IrGeneratorContext.equalsNull(startOffset: Int, endOffset: Int, argument: IrExpression): IrExpression = - primitiveOp2(startOffset, endOffset, irBuiltIns.eqeq, IrStatementOrigin.EQEQ, + primitiveOp2(startOffset, endOffset, irBuiltIns.eqeqSymbol, IrStatementOrigin.EQEQ, argument, constNull(startOffset, endOffset)) fun IrGeneratorContext.eqeqeq(startOffset: Int, endOffset: Int, argument1: IrExpression, argument2: IrExpression): IrExpression = - primitiveOp2(startOffset, endOffset, irBuiltIns.eqeqeq, IrStatementOrigin.EQEQEQ, argument1, argument2) + primitiveOp2(startOffset, endOffset, irBuiltIns.eqeqeqSymbol, IrStatementOrigin.EQEQEQ, argument1, argument2) fun IrGeneratorContext.throwNpe(startOffset: Int, endOffset: Int, origin: IrStatementOrigin): IrExpression = - IrNullaryPrimitiveImpl(startOffset, endOffset, origin, irBuiltIns.throwNpe) + IrNullaryPrimitiveImpl(startOffset, endOffset, origin, irBuiltIns.throwNpeSymbol) // a || b == if (a) true else b fun IrGeneratorContext.oror(startOffset: Int, endOffset: Int, a: IrExpression, b: IrExpression, origin: IrStatementOrigin = IrStatementOrigin.OROR): IrWhen = diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/Scope.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/Scope.kt index 6b12392c193..88d71946b32 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/Scope.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/Scope.kt @@ -16,21 +16,35 @@ package org.jetbrains.kotlin.ir.builders +import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrVariable import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl import org.jetbrains.kotlin.ir.descriptors.IrTemporaryVariableDescriptor import org.jetbrains.kotlin.ir.descriptors.IrTemporaryVariableDescriptorImpl import org.jetbrains.kotlin.ir.expressions.IrExpression +import org.jetbrains.kotlin.ir.symbols.IrSymbol +import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl +import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl +import org.jetbrains.kotlin.ir.symbols.impl.createFunctionSymbol import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.KotlinType -class Scope(val scopeOwner: DeclarationDescriptor) { +class Scope(val scopeOwnerSymbol: IrSymbol) { + val scopeOwner: DeclarationDescriptor get() = scopeOwnerSymbol.descriptor + + @Deprecated("Creates unbound symbol") + constructor(scopeOwner: ClassDescriptor) : this(IrClassSymbolImpl(scopeOwner)) + + @Deprecated("C") + private var lastTemporaryIndex: Int = 0 private fun nextTemporaryIndex(): Int = lastTemporaryIndex++ - private fun createDescriptorForTemporaryVariable(type: KotlinType, nameHint: String? = null, isMutable: Boolean = false): IrTemporaryVariableDescriptor = + fun createDescriptorForTemporaryVariable(type: KotlinType, nameHint: String? = null, isMutable: Boolean = false): IrTemporaryVariableDescriptor = IrTemporaryVariableDescriptorImpl(scopeOwner, Name.identifier(getNameForTemporary(nameHint)), type, isMutable) private fun getNameForTemporary(nameHint: String?): String { @@ -45,3 +59,12 @@ class Scope(val scopeOwner: DeclarationDescriptor) { irExpression ) } + +@Deprecated("Creates unbound symbol") +fun Scope(descriptor: DeclarationDescriptor) = + when (descriptor) { + is ClassDescriptor -> Scope(IrClassSymbolImpl(descriptor)) + is FunctionDescriptor -> Scope(createFunctionSymbol(descriptor)) + is PropertyDescriptor -> Scope(IrFieldSymbolImpl(descriptor)) + else -> throw AssertionError("Unexpected scopeOwner descriptor: $descriptor") + } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/ScopeHelpers.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/ScopeHelpers.kt index bb48d32a97d..368c60528a5 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/ScopeHelpers.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/builders/ScopeHelpers.kt @@ -28,8 +28,10 @@ fun Scope.functionOwner(): FunctionDescriptor = assertCastOwner() fun Scope.classOwner(): ClassDescriptor = - when (scopeOwner) { - is ClassDescriptor -> scopeOwner - is MemberDescriptor -> scopeOwner.containingDeclaration as ClassDescriptor - else -> throw AssertionError("Unexpected scopeOwner: $scopeOwner") + scopeOwner.let { + when (it) { + is ClassDescriptor -> it + is MemberDescriptor -> it.containingDeclaration as ClassDescriptor + else -> throw AssertionError("Unexpected scopeOwner: $scopeOwner") + } } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrClass.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrClass.kt index c56aa3bc79a..ff8a2305531 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrClass.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrClass.kt @@ -24,6 +24,8 @@ interface IrClass : IrSymbolDeclaration, IrDeclarationContainer, get() = IrDeclarationKind.CLASS override val descriptor: ClassDescriptor + + var newInstanceReceiver: IrValueParameter? } fun IrClass.addMember(member: IrDeclaration) { diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrDeclarationOrigin.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrDeclarationOrigin.kt index 0b134ffec4b..309472fb88b 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrDeclarationOrigin.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrDeclarationOrigin.kt @@ -27,6 +27,8 @@ interface IrDeclarationOrigin { object ENUM_CLASS_SPECIAL_MEMBER : IrDeclarationOriginImpl("ENUM_CLASS_SPECIAL_MEMBER") object GENERATED_DATA_CLASS_MEMBER : IrDeclarationOriginImpl("GENERATED_DATA_CLASS_MEMBER") object LOCAL_FUNCTION_FOR_LAMBDA : IrDeclarationOriginImpl("LOCAL_FUNCTION_FOR_LAMBDA") + object CATCH_PARAMETER : IrDeclarationOriginImpl("CATCH_PARAMETER") + object NEW_INSTANCE_RECEIVER : IrDeclarationOriginImpl("NEW_INSTANCE_RECEIVER") object IR_TEMPORARY_VARIABLE : IrDeclarationOriginImpl("IR_TEMPORARY_VARIABLE") } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFile.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFile.kt index 7e574d3ea14..370aa0e8c27 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFile.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFile.kt @@ -21,16 +21,27 @@ import org.jetbrains.kotlin.descriptors.annotations.AnnotationDescriptor import org.jetbrains.kotlin.descriptors.annotations.checkAnnotationName import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.SourceManager +import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol import org.jetbrains.kotlin.ir.symbols.IrFileSymbol +import org.jetbrains.kotlin.ir.symbols.IrPackageFragmentSymbol +import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.name.FqName -interface IrFile : IrElement, IrDeclarationContainer, IrSymbolOwner { +interface IrPackageFragment : IrElement, IrDeclarationContainer, IrSymbolOwner { + val packageFragmentDescriptor: PackageFragmentDescriptor + override val symbol: IrPackageFragmentSymbol +} + +interface IrExternalPackageFragment : IrPackageFragment { + override val symbol: IrExternalPackageFragmentSymbol +} + +interface IrFile : IrPackageFragment { override val symbol: IrFileSymbol val fileEntry: SourceManager.FileEntry val fileAnnotations: MutableList - val packageFragmentDescriptor: PackageFragmentDescriptor override fun transform(transformer: IrElementTransformer, data: D): IrFile = accept(transformer, data) as IrFile diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFunction.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFunction.kt index 73bfd45f5cc..c6923071ebb 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFunction.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/IrFunction.kt @@ -20,10 +20,12 @@ import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.expressions.IrExpressionBody +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol -interface IrFunction : IrDeclaration, IrTypeParametersContainer { +interface IrFunction : IrDeclaration, IrTypeParametersContainer, IrSymbolOwner { override val descriptor: FunctionDescriptor + override val symbol : IrFunctionSymbol var dispatchReceiverParameter: IrValueParameter? var extensionReceiverParameter: IrValueParameter? @@ -38,7 +40,6 @@ interface IrSimpleFunction : IrFunction, IrSymbolDeclaration accept(visitor: IrElementVisitor, data: D): R { diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrClassImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrClassImpl.kt index 9d377a00efa..bcf1388f303 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrClassImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrClassImpl.kt @@ -30,12 +30,10 @@ class IrClassImpl( startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, - override val descriptor: ClassDescriptor, override val symbol: IrClassSymbol ) : IrDeclarationBase(startOffset, endOffset, origin), IrClass { constructor(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassDescriptor) : - this(startOffset, endOffset, origin, descriptor, - IrClassSymbolImpl(descriptor)) + this(startOffset, endOffset, origin, IrClassSymbolImpl(descriptor)) constructor( startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassDescriptor, @@ -44,6 +42,10 @@ class IrClassImpl( addAll(members) } + override val descriptor: ClassDescriptor get() = symbol.descriptor + + override var newInstanceReceiver: IrValueParameter? = null + override val declarations: MutableList = ArrayList() override val typeParameters: MutableList = SmartList() @@ -52,11 +54,13 @@ class IrClassImpl( visitor.visitClass(this, data) override fun acceptChildren(visitor: IrElementVisitor, data: D) { + newInstanceReceiver?.accept(visitor, data) typeParameters.forEach { it.accept(visitor, data) } declarations.forEach { it.accept(visitor, data) } } override fun transformChildren(transformer: IrElementTransformer, data: D) { + newInstanceReceiver = newInstanceReceiver?.transform(transformer, data) typeParameters.transform { it.transform(transformer, data) } declarations.transform { it.transform(transformer, data) as IrDeclaration } } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrConstructorImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrConstructorImpl.kt index e1f49e2fbb9..125d2f33fbe 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrConstructorImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrConstructorImpl.kt @@ -19,19 +19,21 @@ package org.jetbrains.kotlin.ir.declarations.impl import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor import org.jetbrains.kotlin.ir.declarations.IrConstructor import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin +import org.jetbrains.kotlin.ir.declarations.IrValueParameter import org.jetbrains.kotlin.ir.expressions.IrBody import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl +import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementVisitor class IrConstructorImpl( - startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, - override val descriptor: ClassConstructorDescriptor, + startOffset: Int, + endOffset: Int, + origin: IrDeclarationOrigin, override val symbol: IrConstructorSymbol ) : IrFunctionBase(startOffset, endOffset, origin), IrConstructor { constructor(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassConstructorDescriptor) : - this(startOffset, endOffset, origin, descriptor, - IrConstructorSymbolImpl(descriptor)) + this(startOffset, endOffset, origin, IrConstructorSymbolImpl(descriptor)) constructor( startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassConstructorDescriptor, @@ -40,6 +42,8 @@ class IrConstructorImpl( this.body = body } + override val descriptor: ClassConstructorDescriptor get() = symbol.descriptor + override fun accept(visitor: IrElementVisitor, data: D): R { return visitor.visitConstructor(this, data) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrEnumEntryImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrEnumEntryImpl.kt index 8efb0910388..50ddc4b57fd 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrEnumEntryImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrEnumEntryImpl.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.ir.declarations.impl import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrEnumEntry @@ -30,12 +31,10 @@ class IrEnumEntryImpl( startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, - override val descriptor: ClassDescriptor, override val symbol: IrEnumEntrySymbol ) : IrDeclarationBase(startOffset, endOffset, origin), IrEnumEntry { constructor(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassDescriptor) : - this(startOffset, endOffset, origin, descriptor, - IrEnumEntrySymbolImpl(descriptor)) + this(startOffset, endOffset, origin, IrEnumEntrySymbolImpl(descriptor)) constructor( startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ClassDescriptor, @@ -45,6 +44,7 @@ class IrEnumEntryImpl( this.initializerExpression = initializerExpression } + override val descriptor: ClassDescriptor get() = symbol.descriptor override var correspondingClass: IrClass? = null override lateinit var initializerExpression: IrExpression diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrExternalPackageFragmentImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrExternalPackageFragmentImpl.kt new file mode 100644 index 00000000000..2d14609630e --- /dev/null +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrExternalPackageFragmentImpl.kt @@ -0,0 +1,47 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.declarations.impl + +import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor +import org.jetbrains.kotlin.ir.IrElementBase +import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET +import org.jetbrains.kotlin.ir.declarations.IrDeclaration +import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment +import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol +import org.jetbrains.kotlin.ir.visitors.IrElementTransformer +import org.jetbrains.kotlin.ir.visitors.IrElementVisitor + +class IrExternalPackageFragmentImpl( + override val symbol: IrExternalPackageFragmentSymbol +) : IrExternalPackageFragment, IrElementBase(UNDEFINED_OFFSET, UNDEFINED_OFFSET) { + override val packageFragmentDescriptor: PackageFragmentDescriptor get() = symbol.descriptor + + override val declarations: MutableList = ArrayList() + + override fun accept(visitor: IrElementVisitor, data: D): R = + visitor.visitExternalPackageFragment(this, data) + + override fun acceptChildren(visitor: IrElementVisitor, data: D) { + declarations.forEach { it.accept(visitor, data) } + } + + override fun transformChildren(transformer: IrElementTransformer, data: D) { + declarations.forEachIndexed { i, irDeclaration -> + declarations[i] = irDeclaration.transform(transformer, data) as IrDeclaration + } + } +} \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFieldImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFieldImpl.kt index b82f2ac47c1..777a9567f8c 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFieldImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFieldImpl.kt @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.ir.declarations.impl import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin import org.jetbrains.kotlin.ir.declarations.IrField +import org.jetbrains.kotlin.ir.declarations.IrValueParameter import org.jetbrains.kotlin.ir.expressions.IrExpressionBody import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl @@ -30,12 +31,10 @@ class IrFieldImpl( startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, - override val descriptor: PropertyDescriptor, override val symbol: IrFieldSymbol ): IrDeclarationBase(startOffset, endOffset, origin), IrField { constructor(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: PropertyDescriptor) : - this(startOffset, endOffset, origin, descriptor, - IrFieldSymbolImpl(descriptor)) + this(startOffset, endOffset, origin, IrFieldSymbolImpl(descriptor)) constructor(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: PropertyDescriptor, initializer: IrExpressionBody? @@ -43,6 +42,8 @@ class IrFieldImpl( this.initializer = initializer } + override val descriptor: PropertyDescriptor = symbol.descriptor + override var initializer: IrExpressionBody? = null override fun accept(visitor: IrElementVisitor, data: D): R { diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFileImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFileImpl.kt index 2b5dd1b77ac..b353e4f9b4b 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFileImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFileImpl.kt @@ -31,12 +31,10 @@ import java.util.* class IrFileImpl( override val fileEntry: SourceManager.FileEntry, - override val packageFragmentDescriptor: PackageFragmentDescriptor, override val symbol: IrFileSymbol ) : IrElementBase(0, fileEntry.maxOffset), IrFile { constructor(fileEntry: SourceManager.FileEntry, packageFragmentDescriptor: PackageFragmentDescriptor) - : this(fileEntry, packageFragmentDescriptor, - IrFileSymbolImpl(packageFragmentDescriptor)) + : this(fileEntry, IrFileSymbolImpl(packageFragmentDescriptor)) constructor( fileEntry: SourceManager.FileEntry, @@ -48,6 +46,8 @@ class IrFileImpl( this.declarations.addAll(declarations) } + override val packageFragmentDescriptor: PackageFragmentDescriptor get() = symbol.descriptor + override val fileAnnotations: MutableList = SmartList() override val declarations: MutableList = ArrayList() diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionImpl.kt index 588611d5f5f..118c2c0fcb2 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrFunctionImpl.kt @@ -28,12 +28,12 @@ class IrFunctionImpl( startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, - override val descriptor: FunctionDescriptor, override val symbol: IrSimpleFunctionSymbol ) : IrFunctionBase(startOffset, endOffset, origin), IrSimpleFunction { + override val descriptor: FunctionDescriptor = symbol.descriptor + constructor(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: FunctionDescriptor) : - this(startOffset, endOffset, origin, descriptor, - IrSimpleFunctionSymbolImpl(descriptor)) + this(startOffset, endOffset, origin, IrSimpleFunctionSymbolImpl(descriptor)) constructor( startOffset: Int, diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrTypeParameterImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrTypeParameterImpl.kt index 5816f13c0ef..5d9c15d784d 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrTypeParameterImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrTypeParameterImpl.kt @@ -28,12 +28,12 @@ class IrTypeParameterImpl( startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, - override val descriptor: TypeParameterDescriptor, override val symbol: IrTypeParameterSymbol ) : IrDeclarationBase(startOffset, endOffset, origin), IrTypeParameter { + override val descriptor: TypeParameterDescriptor get() = symbol.descriptor + constructor(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: TypeParameterDescriptor) : - this(startOffset, endOffset, origin, descriptor, - IrTypeParameterSymbolImpl(descriptor)) + this(startOffset, endOffset, origin, IrTypeParameterSymbolImpl(descriptor)) override fun accept(visitor: IrElementVisitor, data: D): R = visitor.visitTypeParameter(this, data) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrValueParameterImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrValueParameterImpl.kt index df5828f7c97..a11ef9f5bb2 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrValueParameterImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrValueParameterImpl.kt @@ -29,12 +29,12 @@ class IrValueParameterImpl( startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, - override val descriptor: ParameterDescriptor, override val symbol: IrValueParameterSymbol ) : IrDeclarationBase(startOffset, endOffset, origin), IrValueParameter { + override val descriptor: ParameterDescriptor = symbol.descriptor + constructor(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: ParameterDescriptor) : - this(startOffset, endOffset, origin, descriptor, - IrValueParameterSymbolImpl(descriptor)) + this(startOffset, endOffset, origin, IrValueParameterSymbolImpl(descriptor)) constructor( startOffset: Int, diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrVariableImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrVariableImpl.kt index 34760195d5f..74aa5bd7cbb 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrVariableImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/impl/IrVariableImpl.kt @@ -29,12 +29,10 @@ class IrVariableImpl( startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, - override val descriptor: VariableDescriptor, override val symbol: IrVariableSymbol ) : IrDeclarationBase(startOffset, endOffset, origin), IrVariable { constructor(startOffset: Int, endOffset: Int, origin: IrDeclarationOrigin, descriptor: VariableDescriptor) : - this(startOffset, endOffset, origin, descriptor, - IrVariableSymbolImpl(descriptor)) + this(startOffset, endOffset, origin, IrVariableSymbolImpl(descriptor)) constructor( startOffset: Int, @@ -46,6 +44,8 @@ class IrVariableImpl( this.initializer = initializer } + override val descriptor: VariableDescriptor get() = symbol.descriptor + override var initializer: IrExpression? = null override fun accept(visitor: IrElementVisitor, data: D): R { diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/BuiltinsOperatorsBuilder.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/BuiltinsOperatorsBuilder.kt new file mode 100644 index 00000000000..3e18b8de912 --- /dev/null +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/BuiltinsOperatorsBuilder.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.descriptors + +import org.jetbrains.kotlin.builtins.KotlinBuiltIns +import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor +import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.types.KotlinType + diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltIns.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltIns.kt index a2acfd15227..6c5179a08da 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltIns.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltIns.kt @@ -22,13 +22,44 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl +import org.jetbrains.kotlin.ir.declarations.IrDeclarationOriginImpl +import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction +import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl +import org.jetbrains.kotlin.ir.symbols.impl.IrExternalPackageFragmentSymbolImpl +import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.KotlinTypeFactory import org.jetbrains.kotlin.types.Variance -class BuiltinsOperatorsBuilder(val packageFragment: PackageFragmentDescriptor, val builtIns: KotlinBuiltIns) { +class IrBuiltIns(val builtIns: KotlinBuiltIns) { + private val packageFragment = IrBuiltinsPackageFragmentDescriptorImpl(builtIns.builtInsModule, KOTLIN_INTERNAL_IR_FQN) + val irBuiltInsExternalPackageFragment = IrExternalPackageFragmentImpl(IrExternalPackageFragmentSymbolImpl(packageFragment)) + + object IR_BUILTINS_STUB : IrDeclarationOriginImpl("IR_BUILTINS_STUB") + + private val stubBuilder = IrDeclarationStubBuilder(IR_BUILTINS_STUB) + + private fun defineOperator(name: String, returnType: KotlinType, valueParameterTypes: List): IrSimpleFunction { + val operatorDescriptor = IrSimpleBuiltinOperatorDescriptorImpl(packageFragment, Name.identifier(name), returnType) + for ((i, valueParameterType) in valueParameterTypes.withIndex()) { + operatorDescriptor.addValueParameter( + IrBuiltinValueParameterDescriptorImpl(operatorDescriptor, Name.identifier("arg$i"), i, valueParameterType) + ) + } + return addStubToPackageFragment(operatorDescriptor) + } + + private fun addStubToPackageFragment(descriptor: SimpleFunctionDescriptor): IrSimpleFunction { + val irSimpleFunction = stubBuilder.buildSimpleFunctionStub(IrSimpleFunctionSymbolImpl(descriptor)) + irBuiltInsExternalPackageFragment.declarations.add(irSimpleFunction) + return irSimpleFunction + } + + private fun T.addStub(): IrSimpleFunction = + addStubToPackageFragment(this) + val bool = builtIns.booleanType val any = builtIns.anyType val anyN = builtIns.nullableAnyType @@ -36,32 +67,37 @@ class BuiltinsOperatorsBuilder(val packageFragment: PackageFragmentDescriptor, v val nothing = builtIns.nothingType val unit = builtIns.unitType - fun defineOperator(name: String, returnType: KotlinType, valueParameterTypes: List): IrBuiltinOperatorDescriptor { - val operatorDescriptor = IrSimpleBuiltinOperatorDescriptorImpl(packageFragment, Name.identifier(name), returnType) - for ((i, valueParameterType) in valueParameterTypes.withIndex()) { - operatorDescriptor.addValueParameter( - IrBuiltinValueParameterDescriptorImpl(operatorDescriptor, Name.identifier("arg$i"), i, valueParameterType)) - } - return operatorDescriptor - } -} + val eqeqeqFun = defineOperator("EQEQEQ", bool, listOf(anyN, anyN)) + val eqeqFun = defineOperator("EQEQ", bool, listOf(anyN, anyN)) + val lt0Fun = defineOperator("LT0", bool, listOf(int)) + val lteq0Fun = defineOperator("LTEQ0", bool, listOf(int)) + val gt0Fun = defineOperator("GT0", bool, listOf(int)) + val gteq0Fun = defineOperator("GTEQ0", bool, listOf(int)) + val throwNpeFun = defineOperator("THROW_NPE", nothing, listOf()) + val booleanNotFun = defineOperator("NOT", bool, listOf(bool)) + val noWhenBranchMatchedExceptionFun = defineOperator("noWhenBranchMatchedException", unit, listOf()) -class IrBuiltIns(val builtIns: KotlinBuiltIns) { - private val packageFragment = IrBuiltinsPackageFragmentDescriptorImpl(builtIns.builtInsModule, KOTLIN_INTERNAL_IR_FQN) - private val builder = BuiltinsOperatorsBuilder(packageFragment, builtIns) + val eqeqeq = eqeqeqFun.descriptor + val eqeq = eqeqFun.descriptor + val lt0 = lt0Fun.descriptor + val lteq0 = lteq0Fun.descriptor + val gt0 = gt0Fun.descriptor + val gteq0 = gteq0Fun.descriptor + val throwNpe = throwNpeFun.descriptor + val booleanNot = booleanNotFun.descriptor + val noWhenBranchMatchedException = noWhenBranchMatchedExceptionFun.descriptor - val eqeqeq: FunctionDescriptor = builder.run { defineOperator("EQEQEQ", bool, listOf(anyN, anyN)) } - val eqeq: FunctionDescriptor = builder.run { defineOperator("EQEQ", bool, listOf(anyN, anyN)) } - val lt0: FunctionDescriptor = builder.run { defineOperator("LT0", bool, listOf(int)) } - val lteq0: FunctionDescriptor = builder.run { defineOperator("LTEQ0", bool, listOf(int)) } - val gt0: FunctionDescriptor = builder.run { defineOperator("GT0", bool, listOf(int)) } - val gteq0: FunctionDescriptor = builder.run { defineOperator("GTEQ0", bool, listOf(int)) } - val throwNpe: FunctionDescriptor = builder.run { defineOperator("THROW_NPE", nothing, listOf()) } - val booleanNot: FunctionDescriptor = builder.run { defineOperator("NOT", bool, listOf(bool)) } + val eqeqeqSymbol = eqeqeqFun.symbol + val eqeqSymbol = eqeqFun.symbol + val lt0Symbol = lt0Fun.symbol + val lteq0Symbol = lteq0Fun.symbol + val gt0Symbol = gt0Fun.symbol + val gteq0Symbol = gteq0Fun.symbol + val throwNpeSymbol = throwNpeFun.symbol + val booleanNotSymbol = booleanNotFun.symbol + val noWhenBranchMatchedExceptionSymbol = noWhenBranchMatchedExceptionFun.symbol - val noWhenBranchMatchedException: FunctionDescriptor = builder.run { defineOperator("noWhenBranchMatchedException", unit, listOf()) } - - val enumValueOf: FunctionDescriptor = + val enumValueOfFun = SimpleFunctionDescriptorImpl.create( packageFragment, Annotations.EMPTY, @@ -81,7 +117,9 @@ class IrBuiltIns(val builtIns: KotlinBuiltIns) { val returnType = KotlinTypeFactory.simpleType(Annotations.EMPTY, typeParameterT.typeConstructor, listOf(), false) initialize(null, null, listOf(typeParameterT), listOf(valueParameterName), returnType, Modality.FINAL, Visibilities.PUBLIC) - } + }.addStub() + val enumValueOf = enumValueOfFun.descriptor + val enumValueOfSymbol = enumValueOfFun.symbol companion object { val KOTLIN_INTERNAL_IR_FQN = FqName("kotlin.internal.ir") diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltinFunctionDescriptor.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltinFunctionDescriptor.kt index 4a319fd7c4d..34199ca1419 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltinFunctionDescriptor.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrBuiltinFunctionDescriptor.kt @@ -26,7 +26,7 @@ import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.TypeSubstitutor import java.util.* -interface IrBuiltinOperatorDescriptor : FunctionDescriptor +interface IrBuiltinOperatorDescriptor : SimpleFunctionDescriptor interface IrBuiltinValueParameterDescriptor : ValueParameterDescriptor @@ -36,7 +36,7 @@ abstract class IrBuiltinOperatorDescriptorBase(containingDeclaration: Declaratio { override fun getDispatchReceiverParameter(): ReceiverParameterDescriptor? = null override fun getExtensionReceiverParameter(): ReceiverParameterDescriptor? = null - override fun getOriginal(): FunctionDescriptor = this + override fun getOriginal(): SimpleFunctionDescriptor = this override fun substitute(substitutor: TypeSubstitutor): FunctionDescriptor = throw UnsupportedOperationException() override fun getOverriddenDescriptors(): Collection = emptyList() override fun setOverriddenDescriptors(overriddenDescriptors: Collection) = throw UnsupportedOperationException() @@ -59,10 +59,10 @@ abstract class IrBuiltinOperatorDescriptorBase(containingDeclaration: Declaratio override fun hasStableParameterNames(): Boolean = true override fun hasSynthesizedParameterNames(): Boolean = false - override fun copy(newOwner: DeclarationDescriptor?, modality: Modality?, visibility: Visibility?, kind: CallableMemberDescriptor.Kind?, copyOverrides: Boolean): FunctionDescriptor = + override fun copy(newOwner: DeclarationDescriptor?, modality: Modality?, visibility: Visibility?, + kind: CallableMemberDescriptor.Kind?, copyOverrides: Boolean) = throw UnsupportedOperationException() - - override fun newCopyBuilder(): FunctionDescriptor.CopyBuilder = + override fun newCopyBuilder() = throw UnsupportedOperationException() override fun accept(visitor: DeclarationDescriptorVisitor, data: D): R { diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrDeclarationStubBuilder.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrDeclarationStubBuilder.kt new file mode 100644 index 00000000000..f2937348bf6 --- /dev/null +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/descriptors/IrDeclarationStubBuilder.kt @@ -0,0 +1,84 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.descriptors + +import com.intellij.psi.PsiElement +import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.descriptors.ParameterDescriptor +import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor +import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET +import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl +import org.jetbrains.kotlin.ir.declarations.impl.IrTypeParameterImpl +import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl +import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol +import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol +import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol +import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl +import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl +import org.jetbrains.kotlin.psi.psiUtil.startOffset +import org.jetbrains.kotlin.resolve.source.PsiSourceElement +import org.jetbrains.kotlin.utils.addIfNotNull +import org.jetbrains.kotlin.utils.addToStdlib.safeAs + +class IrDeclarationStubBuilder(val defaultOrigin: IrDeclarationOrigin) { + fun buildSimpleFunctionStub(symbol: IrSimpleFunctionSymbol, origin: IrDeclarationOrigin = defaultOrigin): IrSimpleFunction = + IrFunctionImpl(symbol.descriptor.startOffset, symbol.descriptor.endOffset, origin, symbol) + .buildTypeParameterStubs(symbol.descriptor.typeParameters, origin) + .buildValueParameterStubs(symbol.descriptor, origin) + + fun buildTypeParameterStub(symbol: IrTypeParameterSymbol, origin: IrDeclarationOrigin = defaultOrigin): IrTypeParameter = + IrTypeParameterImpl(symbol.descriptor.startOffset, symbol.descriptor.endOffset, origin, symbol) + + fun buildValueParameterStub(symbol: IrValueParameterSymbol, origin: IrDeclarationOrigin = defaultOrigin): IrValueParameter = + IrValueParameterImpl(symbol.descriptor.startOffset, symbol.descriptor.endOffset, origin, symbol) + + private fun + T.buildTypeParameterStubs(typeParameterDescriptors: List, origin: IrDeclarationOrigin): T = + apply { + typeParameterDescriptors.forEach { typeParameterDescriptor -> + typeParameters.add( + buildTypeParameterStub(IrTypeParameterSymbolImpl(typeParameterDescriptor), origin) + ) + } + } + + private fun + T.buildValueParameterStubs(functionDescriptor: FunctionDescriptor, origin: IrDeclarationOrigin): T = + apply { + val valueParameterDescriptors = ArrayList(functionDescriptor.valueParameters.size + 2).apply { + addIfNotNull(functionDescriptor.dispatchReceiverParameter) + addIfNotNull(functionDescriptor.extensionReceiverParameter) + addAll(functionDescriptor.valueParameters) + } + valueParameterDescriptors.forEach { valueParameterDescriptor -> + valueParameters.add( + buildValueParameterStub(IrValueParameterSymbolImpl(valueParameterDescriptor), origin) + ) + } + } + + private val DeclarationDescriptorWithSource.startOffset + get() = psiElement?.startOffset ?: UNDEFINED_OFFSET + + private val DeclarationDescriptorWithSource.endOffset + get() = psiElement?.startOffset ?: UNDEFINED_OFFSET + + private val DeclarationDescriptorWithSource.psiElement: PsiElement? + get() = source.safeAs()?.psi +} \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrCall.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrCall.kt index e9ec27a2260..2e3766e983b 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrCall.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrCall.kt @@ -16,14 +16,20 @@ package org.jetbrains.kotlin.ir.expressions -import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol -interface IrCall : IrMemberAccessExpression { +interface IrCall : IrFunctionAccessExpression { val superQualifier: ClassDescriptor? + val superQualifierSymbol: IrClassSymbol? } interface IrCallWithShallowCopy : IrCall { - fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: CallableDescriptor, newSuperQualifier: ClassDescriptor?): IrCall + fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: IrFunctionSymbol, newSuperQualifier: IrClassSymbol?): IrCall + + @Deprecated("Creates unbound symbols") + fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: FunctionDescriptor, newSuperQualifier: ClassDescriptor?): IrCall } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrCallableReference.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrCallableReference.kt index 42c8b2efdc1..e1ce659455a 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrCallableReference.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrCallableReference.kt @@ -16,5 +16,24 @@ package org.jetbrains.kotlin.ir.expressions -interface IrCallableReference : IrMemberAccessExpression +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol +interface IrCallableReference : IrMemberAccessExpression { + override val descriptor: CallableMemberDescriptor +} + +interface IrFunctionReference : IrCallableReference { + override val descriptor: FunctionDescriptor + val symbol: IrFunctionSymbol +} + +interface IrPropertyReference : IrCallableReference { + override val descriptor: PropertyDescriptor + val field: IrFieldSymbol? + val getter: IrFunctionSymbol? + val setter: IrFunctionSymbol? +} diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrClassReference.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrClassReference.kt index 4c61efc9ccc..14213b88316 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrClassReference.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrClassReference.kt @@ -17,9 +17,11 @@ package org.jetbrains.kotlin.ir.expressions import org.jetbrains.kotlin.descriptors.ClassifierDescriptor +import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol interface IrClassReference : IrDeclarationReference { override val descriptor: ClassifierDescriptor + override val symbol: IrClassifierSymbol } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrDeclarationReference.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrDeclarationReference.kt index 0122c111ba5..e483d10e184 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrDeclarationReference.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrDeclarationReference.kt @@ -18,17 +18,25 @@ package org.jetbrains.kotlin.ir.expressions import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol +import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol +import org.jetbrains.kotlin.ir.symbols.IrSymbol interface IrDeclarationReference : IrExpression { val descriptor: DeclarationDescriptor + val symbol: IrSymbol } interface IrGetSingletonValue : IrDeclarationReference { override val descriptor: ClassDescriptor } -interface IrGetObjectValue : IrGetSingletonValue +interface IrGetObjectValue : IrGetSingletonValue { + override val symbol: IrClassSymbol +} -interface IrGetEnumValue : IrGetSingletonValue +interface IrGetEnumValue : IrGetSingletonValue { + override val symbol: IrEnumEntrySymbol +} diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrDelegatingConstructorCall.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrDelegatingConstructorCall.kt index 707dea7ffcb..66dacc6131e 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrDelegatingConstructorCall.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrDelegatingConstructorCall.kt @@ -17,8 +17,10 @@ package org.jetbrains.kotlin.ir.expressions import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor +import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol -interface IrDelegatingConstructorCall : IrMemberAccessExpression { +interface IrDelegatingConstructorCall : IrFunctionAccessExpression { override val descriptor: ClassConstructorDescriptor + override val symbol: IrConstructorSymbol } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrEnumConstructorCall.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrEnumConstructorCall.kt index 3e4d7bd43ae..b9a7d3d55e9 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrEnumConstructorCall.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrEnumConstructorCall.kt @@ -17,8 +17,10 @@ package org.jetbrains.kotlin.ir.expressions import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor +import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol -interface IrEnumConstructorCall : IrMemberAccessExpression { +interface IrEnumConstructorCall : IrFunctionAccessExpression { override val descriptor: ClassConstructorDescriptor + override val symbol: IrConstructorSymbol } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrFieldAccessExpression.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrFieldAccessExpression.kt index faa54667a3e..d5c85e05f1e 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrFieldAccessExpression.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrFieldAccessExpression.kt @@ -18,10 +18,16 @@ package org.jetbrains.kotlin.ir.expressions import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol +import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol interface IrFieldAccessExpression : IrDeclarationReference { override val descriptor: PropertyDescriptor + override val symbol: IrFieldSymbol + val superQualifier: ClassDescriptor? + val superQualifierSymbol: IrClassSymbol? + var receiver: IrExpression? val origin: IrStatementOrigin? } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrInstanceInitializerCall.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrInstanceInitializerCall.kt index 9e5d3dedf27..02c1d4b0fbb 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrInstanceInitializerCall.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrInstanceInitializerCall.kt @@ -17,8 +17,10 @@ package org.jetbrains.kotlin.ir.expressions import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol interface IrInstanceInitializerCall : IrExpression { val classDescriptor: ClassDescriptor + val classSymbol: IrClassSymbol } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrMemberAccessExpression.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrMemberAccessExpression.kt index c8279900ecf..494ea644da5 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrMemberAccessExpression.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrMemberAccessExpression.kt @@ -16,17 +16,16 @@ package org.jetbrains.kotlin.ir.expressions -import org.jetbrains.kotlin.descriptors.CallableDescriptor -import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor -import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol import org.jetbrains.kotlin.types.KotlinType -interface IrMemberAccessExpression : IrDeclarationReference { +interface IrMemberAccessExpression : IrExpression { var dispatchReceiver: IrExpression? var extensionReceiver: IrExpression? + val descriptor: CallableMemberDescriptor val origin: IrStatementOrigin? - override val descriptor: CallableDescriptor // NB `typeParameterDescriptor` should be taken from `descriptor.original` fun getTypeArgument(typeParameterDescriptor: TypeParameterDescriptor): KotlinType? @@ -36,6 +35,11 @@ interface IrMemberAccessExpression : IrDeclarationReference { fun removeValueArgument(index: Int) } +interface IrFunctionAccessExpression : IrMemberAccessExpression, IrDeclarationReference { + override val descriptor: FunctionDescriptor + override val symbol: IrFunctionSymbol +} + fun IrMemberAccessExpression.getValueArgument(valueParameterDescriptor: ValueParameterDescriptor) = getValueArgument(valueParameterDescriptor.index) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrReturn.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrReturn.kt index 8ff4f835d8f..006d656bed2 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrReturn.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrReturn.kt @@ -17,10 +17,12 @@ package org.jetbrains.kotlin.ir.expressions import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol interface IrReturn : IrExpression { var value: IrExpression val returnTarget: CallableDescriptor + val returnTargetSymbol: IrFunctionSymbol } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrTry.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrTry.kt index 65a8583d6b0..5547c15dac6 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrTry.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrTry.kt @@ -18,6 +18,10 @@ package org.jetbrains.kotlin.ir.expressions import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.ir.IrElement +import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner +import org.jetbrains.kotlin.ir.declarations.IrVariable +import org.jetbrains.kotlin.ir.symbols.IrSymbol +import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol import org.jetbrains.kotlin.ir.visitors.IrElementTransformer interface IrTry : IrExpression { @@ -30,6 +34,7 @@ interface IrTry : IrExpression { interface IrCatch : IrElement { val parameter: VariableDescriptor + var catchParameter: IrVariable var result: IrExpression override fun transform(transformer: IrElementTransformer, data: D): IrCatch = diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrValueAccessExpression.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrValueAccessExpression.kt index 8bc60e947af..6cc37c73fca 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrValueAccessExpression.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/IrValueAccessExpression.kt @@ -18,9 +18,12 @@ package org.jetbrains.kotlin.ir.expressions import org.jetbrains.kotlin.descriptors.ValueDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor +import org.jetbrains.kotlin.ir.symbols.IrValueSymbol +import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol interface IrValueAccessExpression : IrDeclarationReference { override val descriptor: ValueDescriptor + override val symbol: IrValueSymbol val origin: IrStatementOrigin? } @@ -30,6 +33,7 @@ interface IrGetValue : IrValueAccessExpression, IrExpressionWithCopy { interface IrSetVariable : IrValueAccessExpression { override val descriptor: VariableDescriptor + override val symbol: IrVariableSymbol var value: IrExpression } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallImpl.kt index a08684d999d..5704999e4ed 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallImpl.kt @@ -16,12 +16,14 @@ package org.jetbrains.kotlin.ir.expressions.impl -import org.jetbrains.kotlin.descriptors.CallableDescriptor -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor +import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.expressions.IrCall import org.jetbrains.kotlin.ir.expressions.IrCallWithShallowCopy import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol +import org.jetbrains.kotlin.ir.symbols.impl.createClassSymbolOrNull +import org.jetbrains.kotlin.ir.symbols.impl.createFunctionSymbol import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.types.KotlinType @@ -29,21 +31,40 @@ class IrCallImpl( startOffset: Int, endOffset: Int, type: KotlinType, - override val descriptor: CallableDescriptor, + override val symbol: IrFunctionSymbol, typeArguments: Map?, override val origin: IrStatementOrigin? = null, - override val superQualifier: ClassDescriptor? = null -) : IrCallWithIndexedArgumentsBase(startOffset, endOffset, type, descriptor.valueParameters.size, typeArguments), IrCallWithShallowCopy { + override val superQualifierSymbol: IrClassSymbol? = null +) : IrCall, + IrCallWithIndexedArgumentsBase(startOffset, endOffset, type, symbol.descriptor.valueParameters.size, typeArguments) +{ + @Deprecated("Creates unbound symbols") constructor( - startOffset: Int, endOffset: Int, descriptor: CallableDescriptor, + startOffset: Int, + endOffset: Int, + calleeDescriptor: CallableMemberDescriptor, typeArguments: Map? = null, origin: IrStatementOrigin? = null, - superQualifier: ClassDescriptor? = null - ) : this(startOffset, endOffset, descriptor.returnType!!, descriptor, typeArguments, origin, superQualifier) + superQualifierDescriptor: ClassDescriptor? = null + ) : this( + startOffset, endOffset, + calleeDescriptor.returnType!!, + createFunctionSymbol(calleeDescriptor), + typeArguments, origin, + createClassSymbolOrNull(superQualifierDescriptor) + ) + + constructor( + startOffset: Int, endOffset: Int, + symbol: IrFunctionSymbol, + typeArguments: Map? = null, + origin: IrStatementOrigin? = null, + superQualifierSymbol: IrClassSymbol? = null + ) : this(startOffset, endOffset, symbol.descriptor.returnType!!, symbol, typeArguments, origin, superQualifierSymbol) + + override val descriptor: FunctionDescriptor = symbol.descriptor + override val superQualifier: ClassDescriptor? = superQualifierSymbol?.descriptor override fun accept(visitor: IrElementVisitor, data: D): R = visitor.visitCall(this, data) - - override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: CallableDescriptor, newSuperQualifier: ClassDescriptor?): IrCall = - IrCallImpl(startOffset, endOffset, type, newCallee, typeArguments, newOrigin, newSuperQualifier) } \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallWithIndexedArgumentsBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallWithIndexedArgumentsBase.kt index dfebeab7a78..1018d69b06d 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallWithIndexedArgumentsBase.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallWithIndexedArgumentsBase.kt @@ -17,6 +17,7 @@ package org.jetbrains.kotlin.ir.expressions.impl import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor +import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin import org.jetbrains.kotlin.ir.visitors.IrElementTransformer diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallableReferenceBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallableReferenceBase.kt new file mode 100644 index 00000000000..6630ed21390 --- /dev/null +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallableReferenceBase.kt @@ -0,0 +1,100 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.expressions.impl + +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.descriptors.PropertyDescriptor +import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor +import org.jetbrains.kotlin.ir.expressions.* +import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol +import org.jetbrains.kotlin.ir.symbols.impl.createFunctionSymbol +import org.jetbrains.kotlin.ir.visitors.IrElementVisitor +import org.jetbrains.kotlin.types.KotlinType + +abstract class IrCallableReferenceBase( + startOffset: Int, + endOffset: Int, + type: KotlinType, + typeArguments: Map?, + numValueArguments: Int, + override val origin: IrStatementOrigin? = null +) : IrCallableReference, + IrCallWithIndexedArgumentsBase( + startOffset, endOffset, + type, + numValueArguments, + typeArguments, + origin + ) + +class IrFunctionReferenceImpl( + startOffset: Int, + endOffset: Int, + type: KotlinType, + override val symbol: IrFunctionSymbol, + typeArguments: Map?, + origin: IrStatementOrigin? = null +) : IrFunctionReference, + IrCallableReferenceBase( + startOffset, endOffset, type, typeArguments, + symbol.descriptor.valueParameters.size, + origin + ) +{ + @Deprecated("Creates unbound symbol") + constructor( + startOffset: Int, + endOffset: Int, + type: KotlinType, + descriptor: FunctionDescriptor, + typeArguments: Map?, + origin: IrStatementOrigin? = null + ) : this(startOffset, endOffset, type, createFunctionSymbol(descriptor), typeArguments, origin) + + override val descriptor: FunctionDescriptor get() = symbol.descriptor + + override fun accept(visitor: IrElementVisitor, data: D): R = + visitor.visitFunctionReference(this, data) +} + +class IrPropertyReferenceImpl( + startOffset: Int, + endOffset: Int, + type: KotlinType, + override val descriptor: PropertyDescriptor, + override val field: IrFieldSymbol?, + override val getter: IrFunctionSymbol?, + override val setter: IrFunctionSymbol?, + typeArguments: Map?, + override val origin: IrStatementOrigin? = null +) : IrPropertyReference, + IrMemberAccessExpressionBase(startOffset, endOffset, type, typeArguments) +{ + override fun accept(visitor: IrElementVisitor, data: D): R = + visitor.visitPropertyReference(this, data) + + private fun throwNoValueArguments(): Nothing { + throw UnsupportedOperationException("Property reference $descriptor has no value arguments") + } + + override fun getValueArgument(index: Int): IrExpression? = throwNoValueArguments() + + override fun putValueArgument(index: Int, valueArgument: IrExpression?) = throwNoValueArguments() + + override fun removeValueArgument(index: Int) = throwNoValueArguments() +} \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallableReferenceImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallableReferenceImpl.kt deleted file mode 100644 index 0d8bcabbaba..00000000000 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrCallableReferenceImpl.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2010-2016 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jetbrains.kotlin.ir.expressions.impl - -import org.jetbrains.kotlin.descriptors.CallableDescriptor -import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor -import org.jetbrains.kotlin.ir.expressions.IrCallableReference -import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin -import org.jetbrains.kotlin.ir.visitors.IrElementVisitor -import org.jetbrains.kotlin.types.KotlinType - -class IrCallableReferenceImpl( - startOffset: Int, - endOffset: Int, - type: KotlinType, - override val descriptor: CallableDescriptor, - typeArguments: Map?, - override val origin: IrStatementOrigin? = null -) : IrCallWithIndexedArgumentsBase(startOffset, endOffset, type, descriptor.valueParameters.size, typeArguments, origin), - IrCallableReference { - override fun accept(visitor: IrElementVisitor, data: D): R { - return visitor.visitCallableReference(this, data) - } -} \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrClassReferenceImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrClassReferenceImpl.kt index afd337c02d8..dd38ef056c9 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrClassReferenceImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrClassReferenceImpl.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.ir.expressions.impl import org.jetbrains.kotlin.descriptors.ClassifierDescriptor import org.jetbrains.kotlin.ir.expressions.IrClassReference +import org.jetbrains.kotlin.ir.symbols.IrClassifierSymbol import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.types.KotlinType @@ -25,9 +26,15 @@ class IrClassReferenceImpl( startOffset: Int, endOffset: Int, type: KotlinType, - descriptor: ClassifierDescriptor -) : IrTerminalDeclarationReferenceBase(startOffset, endOffset, type, descriptor), IrClassReference { - override fun accept(visitor: IrElementVisitor, data: D): R { - return visitor.visitClassReference(this, data) - } + symbol: IrClassifierSymbol +) : IrClassReference, + IrTerminalDeclarationReferenceBase( + startOffset, endOffset, type, + symbol, symbol.descriptor + ) +{ + override val descriptor: ClassifierDescriptor get() = symbol.descriptor + + override fun accept(visitor: IrElementVisitor, data: D): R = + visitor.visitClassReference(this, data) } \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrDeclarationReferenceBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrDeclarationReferenceBase.kt index 640bccbe835..8c38ff66d52 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrDeclarationReferenceBase.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrDeclarationReferenceBase.kt @@ -18,11 +18,13 @@ package org.jetbrains.kotlin.ir.expressions.impl import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.ir.expressions.IrDeclarationReference +import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.types.KotlinType -abstract class IrDeclarationReferenceBase( +abstract class IrDeclarationReferenceBase( startOffset: Int, endOffset: Int, type: KotlinType, + override val symbol: S, override val descriptor: D ) : IrExpressionBase(startOffset, endOffset, type), IrDeclarationReference \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrDelegatingConstructorCallImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrDelegatingConstructorCallImpl.kt index 24c0339eb28..50ad044255c 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrDelegatingConstructorCallImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrDelegatingConstructorCallImpl.kt @@ -19,6 +19,8 @@ package org.jetbrains.kotlin.ir.expressions.impl import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.ir.expressions.IrDelegatingConstructorCall +import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol +import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.types.KotlinType @@ -26,10 +28,28 @@ import org.jetbrains.kotlin.types.KotlinType class IrDelegatingConstructorCallImpl( startOffset: Int, endOffset: Int, - override val descriptor: ClassConstructorDescriptor, + override val symbol: IrConstructorSymbol, typeArguments: Map? = null -) : IrCallWithIndexedArgumentsBase(startOffset, endOffset, descriptor.builtIns.unitType, descriptor.valueParameters.size, typeArguments), - IrDelegatingConstructorCall { +) : IrDelegatingConstructorCall, + IrCallWithIndexedArgumentsBase( + startOffset, endOffset, + symbol.descriptor.builtIns.unitType, + symbol.descriptor.valueParameters.size, + typeArguments + ) +{ + @Deprecated("Creates unbound symbol") + constructor( + startOffset: Int, + endOffset: Int, + constructorDescriptor: ClassConstructorDescriptor, + typeArguments: Map? = null + ) : this(startOffset, endOffset, + IrConstructorSymbolImpl(constructorDescriptor), + typeArguments) + + override val descriptor: ClassConstructorDescriptor get() = symbol.descriptor + override fun accept(visitor: IrElementVisitor, data: D): R { return visitor.visitDelegatingConstructorCall(this, data) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrEnumConstructorCallImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrEnumConstructorCallImpl.kt index 0b01063a39f..6eb965e3647 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrEnumConstructorCallImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrEnumConstructorCallImpl.kt @@ -18,15 +18,23 @@ package org.jetbrains.kotlin.ir.expressions.impl import org.jetbrains.kotlin.descriptors.ClassConstructorDescriptor import org.jetbrains.kotlin.ir.expressions.IrEnumConstructorCall +import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns class IrEnumConstructorCallImpl( startOffset: Int, endOffset: Int, - override val descriptor: ClassConstructorDescriptor -) : IrCallWithIndexedArgumentsBase(startOffset, endOffset, descriptor.builtIns.unitType, descriptor.valueParameters.size, null), - IrEnumConstructorCall { + override val symbol: IrConstructorSymbol +) : IrEnumConstructorCall, + IrCallWithIndexedArgumentsBase( + startOffset, endOffset, + symbol.descriptor.builtIns.unitType, + symbol.descriptor.valueParameters.size, + null + ) { + override val descriptor: ClassConstructorDescriptor get() = symbol.descriptor + override fun accept(visitor: IrElementVisitor, data: D): R { return visitor.visitEnumConstructorCall(this, data) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrFieldExpressionBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrFieldExpressionBase.kt index 1de22721f67..44d59dacc77 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrFieldExpressionBase.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrFieldExpressionBase.kt @@ -21,12 +21,20 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrFieldAccessExpression import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol +import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol +import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.types.KotlinType abstract class IrFieldExpressionBase( - startOffset: Int, endOffset: Int, descriptor: PropertyDescriptor, type: KotlinType, + startOffset: Int, endOffset: Int, + override val symbol: IrFieldSymbol, + type: KotlinType, override val origin: IrStatementOrigin? = null, - override val superQualifier: ClassDescriptor? = null -) : IrDeclarationReferenceBase(startOffset, endOffset, type, descriptor), IrFieldAccessExpression { + override val superQualifierSymbol: IrClassSymbol? +) : IrExpressionBase(startOffset, endOffset, type), IrFieldAccessExpression { + override val descriptor: PropertyDescriptor get() = symbol.descriptor + override val superQualifier: ClassDescriptor? get() = superQualifierSymbol?.descriptor + override final var receiver: IrExpression? = null } \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrGetEnumValueImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrGetEnumValueImpl.kt index 86857263360..1e5ed87dc50 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrGetEnumValueImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrGetEnumValueImpl.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.ir.expressions.impl import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.ir.expressions.IrGetEnumValue +import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.types.KotlinType @@ -25,8 +26,10 @@ class IrGetEnumValueImpl( startOffset: Int, endOffset: Int, type: KotlinType, - descriptor: ClassDescriptor -) : IrTerminalDeclarationReferenceBase(startOffset, endOffset, type, descriptor), IrGetEnumValue { + symbol: IrEnumEntrySymbol +) : IrGetEnumValue, + IrTerminalDeclarationReferenceBase(startOffset, endOffset, type, symbol, symbol.descriptor) +{ override fun accept(visitor: IrElementVisitor, data: D): R { return visitor.visitGetEnumValue(this, data) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrGetFieldImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrGetFieldImpl.kt index 9b0770cee69..c56a50d780f 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrGetFieldImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrGetFieldImpl.kt @@ -21,19 +21,56 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrGetField import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol +import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol +import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl +import org.jetbrains.kotlin.ir.symbols.impl.createClassSymbolOrNull import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementVisitor class IrGetFieldImpl( - startOffset: Int, endOffset: Int, descriptor: PropertyDescriptor, + startOffset: Int, endOffset: Int, + symbol: IrFieldSymbol, origin: IrStatementOrigin? = null, - superQualifier: ClassDescriptor? = null -) : IrFieldExpressionBase(startOffset, endOffset, descriptor, descriptor.type, origin, superQualifier), IrGetField { + superQualifierSymbol: IrClassSymbol? = null +) : IrGetField, + IrFieldExpressionBase(startOffset, endOffset, symbol, symbol.descriptor.type, origin, superQualifierSymbol) +{ + @Deprecated("Creates unbound symbol") constructor( - startOffset: Int, endOffset: Int, descriptor: PropertyDescriptor, receiver: IrExpression?, + startOffset: Int, endOffset: Int, + propertyDescriptor: PropertyDescriptor, origin: IrStatementOrigin? = null, superQualifier: ClassDescriptor? = null - ) : this(startOffset, endOffset, descriptor, origin, superQualifier) { + ) : this( + startOffset, endOffset, + IrFieldSymbolImpl(propertyDescriptor), + origin, + createClassSymbolOrNull(superQualifier) + ) + + @Deprecated("Creates unbound symbol") + constructor( + startOffset: Int, endOffset: Int, + propertyDescriptor: PropertyDescriptor, + receiver: IrExpression?, + origin: IrStatementOrigin? = null, + superQualifier: ClassDescriptor? = null + ) : this( + startOffset, endOffset, + IrFieldSymbolImpl(propertyDescriptor), + receiver, origin, + createClassSymbolOrNull(superQualifier) + ) + + + constructor( + startOffset: Int, endOffset: Int, + symbol: IrFieldSymbol, + receiver: IrExpression?, + origin: IrStatementOrigin? = null, + superQualifierSymbol: IrClassSymbol? = null + ) : this(startOffset, endOffset, symbol, origin, superQualifierSymbol) { this.receiver = receiver } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrGetObjectValueImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrGetObjectValueImpl.kt index 6ac9d2130f8..040e578183d 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrGetObjectValueImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrGetObjectValueImpl.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.ir.expressions.impl import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.ir.expressions.IrGetObjectValue +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.types.KotlinType @@ -25,8 +26,10 @@ class IrGetObjectValueImpl( startOffset: Int, endOffset: Int, type: KotlinType, - descriptor: ClassDescriptor -) : IrTerminalDeclarationReferenceBase(startOffset, endOffset, type, descriptor), IrGetObjectValue { + symbol: IrClassSymbol +) : IrGetObjectValue, + IrTerminalDeclarationReferenceBase(startOffset, endOffset, type, symbol, symbol.descriptor) +{ override fun accept(visitor: IrElementVisitor, data: D): R = visitor.visitGetObjectValue(this, data) } \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrGetValueImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrGetValueImpl.kt index 27b4421fff9..55705f79d7c 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrGetValueImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrGetValueImpl.kt @@ -19,15 +19,27 @@ package org.jetbrains.kotlin.ir.expressions.impl import org.jetbrains.kotlin.descriptors.ValueDescriptor import org.jetbrains.kotlin.ir.expressions.IrGetValue import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin +import org.jetbrains.kotlin.ir.symbols.IrValueSymbol +import org.jetbrains.kotlin.ir.symbols.impl.createValueSymbol import org.jetbrains.kotlin.ir.visitors.IrElementVisitor class IrGetValueImpl( - startOffset: Int, endOffset: Int, descriptor: ValueDescriptor, + startOffset: Int, endOffset: Int, + symbol: IrValueSymbol, override val origin: IrStatementOrigin? = null -) : IrTerminalDeclarationReferenceBase(startOffset, endOffset, descriptor.type, descriptor), IrGetValue { +) : IrGetValue, + IrTerminalDeclarationReferenceBase(startOffset, endOffset, symbol.descriptor.type, symbol, symbol.descriptor) +{ + @Deprecated("Creates unbound reference") + constructor( + startOffset: Int, endOffset: Int, + descriptor: ValueDescriptor, + origin: IrStatementOrigin? = null + ) : this(startOffset, endOffset, createValueSymbol(descriptor), origin) + override fun accept(visitor: IrElementVisitor, data: D): R = visitor.visitGetValue(this, data) override fun copy(): IrGetValue = - IrGetValueImpl(startOffset, endOffset, descriptor, origin) + IrGetValueImpl(startOffset, endOffset, symbol, origin) } \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrInstanceInitializerCallImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrInstanceInitializerCallImpl.kt index 1e38cd5f4b5..4b2a95a8812 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrInstanceInitializerCallImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrInstanceInitializerCallImpl.kt @@ -18,14 +18,17 @@ package org.jetbrains.kotlin.ir.expressions.impl import org.jetbrains.kotlin.descriptors.ClassDescriptor import org.jetbrains.kotlin.ir.expressions.IrInstanceInitializerCall +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns class IrInstanceInitializerCallImpl( startOffset: Int, endOffset: Int, - override val classDescriptor: ClassDescriptor -) : IrTerminalExpressionBase(startOffset, endOffset, classDescriptor.builtIns.unitType), IrInstanceInitializerCall { + override val classSymbol: IrClassSymbol +) : IrTerminalExpressionBase(startOffset, endOffset, classSymbol.descriptor.builtIns.unitType), IrInstanceInitializerCall { + override val classDescriptor: ClassDescriptor get() = classSymbol.descriptor + override fun accept(visitor: IrElementVisitor, data: D): R { return visitor.visitInstanceInitializerCall(this, data) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrPrimitiveCall.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrPrimitiveCall.kt index f84aa66f516..72bf545f574 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrPrimitiveCall.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrPrimitiveCall.kt @@ -16,13 +16,14 @@ package org.jetbrains.kotlin.ir.expressions.impl -import org.jetbrains.kotlin.descriptors.CallableDescriptor -import org.jetbrains.kotlin.descriptors.ClassDescriptor -import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor +import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.expressions.IrCall import org.jetbrains.kotlin.ir.expressions.IrCallWithShallowCopy import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol +import org.jetbrains.kotlin.ir.symbols.impl.createFunctionSymbol import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.types.KotlinType @@ -32,9 +33,12 @@ abstract class IrPrimitiveCallBase( startOffset: Int, endOffset: Int, override val origin: IrStatementOrigin?, - override val descriptor: CallableDescriptor -) : IrExpressionBase(startOffset, endOffset, descriptor.returnType!!), IrCall { + override val symbol: IrFunctionSymbol +) : IrExpressionBase(startOffset, endOffset, symbol.descriptor.returnType!!), IrCall { + override val descriptor: FunctionDescriptor get() = symbol.descriptor override val superQualifier: ClassDescriptor? get() = null + override val superQualifierSymbol: IrClassSymbol? get() = null + override var dispatchReceiver: IrExpression? get() = null set(value) { @@ -66,8 +70,8 @@ abstract class IrPrimitiveCallBase( } } -class IrNullaryPrimitiveImpl(startOffset: Int, endOffset: Int, origin: IrStatementOrigin?, descriptor: CallableDescriptor) : - IrPrimitiveCallBase(startOffset, endOffset, origin, descriptor), IrCallWithShallowCopy { +class IrNullaryPrimitiveImpl(startOffset: Int, endOffset: Int, origin: IrStatementOrigin?, symbol: IrFunctionSymbol) : + IrPrimitiveCallBase(startOffset, endOffset, origin, symbol), IrCallWithShallowCopy { override fun getValueArgument(index: Int): IrExpression? = null override fun putValueArgument(index: Int, valueArgument: IrExpression?) { @@ -82,16 +86,44 @@ class IrNullaryPrimitiveImpl(startOffset: Int, endOffset: Int, origin: IrStateme // no children } - override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: CallableDescriptor, newSuperQualifier: ClassDescriptor?) = + override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: IrFunctionSymbol, newSuperQualifier: IrClassSymbol?): IrCall = IrNullaryPrimitiveImpl(startOffset, endOffset, newOrigin, newCallee) + + override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: FunctionDescriptor, newSuperQualifier: ClassDescriptor?): IrCall = + IrNullaryPrimitiveImpl(startOffset, endOffset, newOrigin, createFunctionSymbol(newCallee)) } -class IrUnaryPrimitiveImpl(startOffset: Int, endOffset: Int, origin: IrStatementOrigin?, descriptor: CallableDescriptor) : - IrPrimitiveCallBase(startOffset, endOffset, origin, descriptor), IrCallWithShallowCopy { +class IrUnaryPrimitiveImpl(startOffset: Int, endOffset: Int, origin: IrStatementOrigin?, symbol: IrFunctionSymbol) : + IrPrimitiveCallBase(startOffset, endOffset, origin, symbol), IrCallWithShallowCopy { + @Deprecated("Creates unbound symbol") constructor( - startOffset: Int, endOffset: Int, origin: IrStatementOrigin?, descriptor: CallableDescriptor, + startOffset: Int, endOffset: Int, + origin: IrStatementOrigin?, + functionDescriptor: FunctionDescriptor + ) : this( + startOffset, endOffset, origin, + createFunctionSymbol(functionDescriptor) + ) + + + @Deprecated("Creates unbound symbol") + constructor( + startOffset: Int, endOffset: Int, + origin: IrStatementOrigin?, + functionDescriptor: FunctionDescriptor, argument: IrExpression - ) : this(startOffset, endOffset, origin, descriptor) { + ) : this( + startOffset, endOffset, origin, + createFunctionSymbol(functionDescriptor), + argument + ) + + constructor( + startOffset: Int, endOffset: Int, + origin: IrStatementOrigin?, + symbol: IrFunctionSymbol, + argument: IrExpression + ) : this(startOffset, endOffset, origin, symbol) { this.argument = argument } @@ -119,16 +151,38 @@ class IrUnaryPrimitiveImpl(startOffset: Int, endOffset: Int, origin: IrStatement argument = argument.transform(transformer, data) } - override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: CallableDescriptor, newSuperQualifier: ClassDescriptor?) = - IrUnaryPrimitiveImpl(startOffset, endOffset, newOrigin, newCallee) + override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: IrFunctionSymbol, newSuperQualifier: IrClassSymbol?): IrCall = + IrUnaryPrimitiveImpl(startOffset, endOffset, newOrigin, newCallee) + + override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: FunctionDescriptor, newSuperQualifier: ClassDescriptor?): IrCall = + IrUnaryPrimitiveImpl(startOffset, endOffset, newOrigin, newCallee) } -class IrBinaryPrimitiveImpl(startOffset: Int, endOffset: Int, origin: IrStatementOrigin?, descriptor: CallableDescriptor) : - IrPrimitiveCallBase(startOffset, endOffset, origin, descriptor), IrCallWithShallowCopy { +class IrBinaryPrimitiveImpl(startOffset: Int, endOffset: Int, origin: IrStatementOrigin?, symbol: IrFunctionSymbol) : + IrPrimitiveCallBase(startOffset, endOffset, origin, symbol), IrCallWithShallowCopy { + @Deprecated("Creates unbound symbol") constructor( - startOffset: Int, endOffset: Int, origin: IrStatementOrigin?, descriptor: CallableDescriptor, + startOffset: Int, endOffset: Int, origin: IrStatementOrigin?, + descriptor: FunctionDescriptor + ) : this(startOffset, endOffset, origin, + createFunctionSymbol(descriptor)) + + @Deprecated("Creates unbound symbol") + constructor( + startOffset: Int, endOffset: Int, origin: IrStatementOrigin?, + descriptor: FunctionDescriptor, argument0: IrExpression, argument1: IrExpression - ) : this(startOffset, endOffset, origin, descriptor) { + ) : this( + startOffset, endOffset, origin, + createFunctionSymbol(descriptor), + argument0, argument1 + ) + + constructor( + startOffset: Int, endOffset: Int, origin: IrStatementOrigin?, + symbol: IrFunctionSymbol, + argument0: IrExpression, argument1: IrExpression + ) : this(startOffset, endOffset, origin, symbol) { this.argument0 = argument0 this.argument1 = argument1 } @@ -163,6 +217,9 @@ class IrBinaryPrimitiveImpl(startOffset: Int, endOffset: Int, origin: IrStatemen argument1 = argument1.transform(transformer, data) } - override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: CallableDescriptor, newSuperQualifier: ClassDescriptor?) = + override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: IrFunctionSymbol, newSuperQualifier: IrClassSymbol?): IrCall = + IrBinaryPrimitiveImpl(startOffset, endOffset, newOrigin, newCallee) + + override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: FunctionDescriptor, newSuperQualifier: ClassDescriptor?): IrCall = IrBinaryPrimitiveImpl(startOffset, endOffset, newOrigin, newCallee) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrPropertyAccessorCall.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrPropertyAccessorCall.kt index e08eb6d9886..a9ad71c90d2 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrPropertyAccessorCall.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrPropertyAccessorCall.kt @@ -16,13 +16,17 @@ package org.jetbrains.kotlin.ir.expressions.impl -import org.jetbrains.kotlin.descriptors.CallableDescriptor import org.jetbrains.kotlin.descriptors.ClassDescriptor +import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.ir.expressions.IrCall import org.jetbrains.kotlin.ir.expressions.IrCallWithShallowCopy import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol +import org.jetbrains.kotlin.ir.symbols.impl.createClassSymbolOrNull +import org.jetbrains.kotlin.ir.symbols.impl.createFunctionSymbol import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.types.KotlinType @@ -31,11 +35,14 @@ import java.lang.UnsupportedOperationException abstract class IrPropertyAccessorCallBase( startOffset: Int, endOffset: Int, - override val descriptor: CallableDescriptor, + override val symbol: IrFunctionSymbol, typeArguments: Map?, override val origin: IrStatementOrigin? = null, - override val superQualifier: ClassDescriptor? = null -) : IrMemberAccessExpressionBase(startOffset, endOffset, descriptor.returnType!!, typeArguments), IrCall { + override val superQualifierSymbol: IrClassSymbol? = null +) : IrMemberAccessExpressionBase(startOffset, endOffset, symbol.descriptor.returnType!!, typeArguments), IrCall { + override val descriptor: FunctionDescriptor get() = symbol.descriptor + override val superQualifier: ClassDescriptor? get() = superQualifierSymbol?.descriptor + override fun accept(visitor: IrElementVisitor, data: D): R { return visitor.visitCall(this, data) } @@ -47,19 +54,19 @@ abstract class IrPropertyAccessorCallBase( class IrGetterCallImpl( startOffset: Int, endOffset: Int, - descriptor: CallableDescriptor, + symbol: IrFunctionSymbol, typeArguments: Map?, origin: IrStatementOrigin? = null, - superQualifier: ClassDescriptor? = null -) : IrPropertyAccessorCallBase(startOffset, endOffset, descriptor, typeArguments, origin, superQualifier), IrCallWithShallowCopy { + superQualifierSymbol: IrClassSymbol? = null +) : IrPropertyAccessorCallBase(startOffset, endOffset, symbol, typeArguments, origin, superQualifierSymbol), IrCallWithShallowCopy { constructor(startOffset: Int, endOffset: Int, - descriptor: CallableDescriptor, + symbol: IrFunctionSymbol, typeArguments: Map?, dispatchReceiver: IrExpression?, extensionReceiver: IrExpression?, origin: IrStatementOrigin? = null, - superQualifier: ClassDescriptor? = null - ) : this(startOffset, endOffset, descriptor, typeArguments, origin, superQualifier) { + superQualifierSymbol: IrClassSymbol? = null + ) : this(startOffset, endOffset, symbol, typeArguments, origin, superQualifierSymbol) { this.dispatchReceiver = dispatchReceiver this.extensionReceiver = extensionReceiver } @@ -74,26 +81,35 @@ class IrGetterCallImpl( throw UnsupportedOperationException("Property getter call has no arguments") } - override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: CallableDescriptor, newSuperQualifier: ClassDescriptor?) = - IrGetterCallImpl(startOffset, endOffset, newCallee, typeArguments, newOrigin, newSuperQualifier) + override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: IrFunctionSymbol, newSuperQualifier: IrClassSymbol?): IrCall = + IrGetterCallImpl(startOffset, endOffset, newCallee, typeArguments, dispatchReceiver, extensionReceiver, newOrigin, newSuperQualifier) + + override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: FunctionDescriptor, newSuperQualifier: ClassDescriptor?): IrCall = + IrGetterCallImpl( + startOffset, endOffset, + createFunctionSymbol(newCallee), + typeArguments, dispatchReceiver, extensionReceiver, + newOrigin, + createClassSymbolOrNull(newSuperQualifier) + ) } class IrSetterCallImpl( startOffset: Int, endOffset: Int, - descriptor: CallableDescriptor, + symbol: IrFunctionSymbol, typeArguments: Map?, origin: IrStatementOrigin? = null, - superQualifier: ClassDescriptor? = null -) : IrPropertyAccessorCallBase(startOffset, endOffset, descriptor, typeArguments, origin, superQualifier), IrCallWithShallowCopy { + superQualifierSymbol: IrClassSymbol? = null +) : IrPropertyAccessorCallBase(startOffset, endOffset, symbol, typeArguments, origin, superQualifierSymbol), IrCallWithShallowCopy { constructor(startOffset: Int, endOffset: Int, - descriptor: CallableDescriptor, + symbol: IrFunctionSymbol, typeArguments: Map?, dispatchReceiver: IrExpression?, extensionReceiver: IrExpression?, argument: IrExpression, origin: IrStatementOrigin? = null, - superQualifier: ClassDescriptor? = null - ) : this(startOffset, endOffset, descriptor, typeArguments, origin, superQualifier) { + superQualifierSymbol: IrClassSymbol? = null + ) : this(startOffset, endOffset, symbol, typeArguments, origin, superQualifierSymbol) { this.dispatchReceiver = dispatchReceiver this.extensionReceiver = extensionReceiver putValueArgument(SETTER_ARGUMENT_INDEX, argument) @@ -114,9 +130,18 @@ class IrSetterCallImpl( argumentImpl = null } - override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: CallableDescriptor, newSuperQualifier: ClassDescriptor?) = + override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: IrFunctionSymbol, newSuperQualifier: IrClassSymbol?): IrCall = IrSetterCallImpl(startOffset, endOffset, newCallee, typeArguments, newOrigin, newSuperQualifier) + override fun shallowCopy(newOrigin: IrStatementOrigin?, newCallee: FunctionDescriptor, newSuperQualifier: ClassDescriptor?): IrCall = + IrSetterCallImpl( + startOffset, endOffset, + createFunctionSymbol(newCallee), + typeArguments, + newOrigin, + createClassSymbolOrNull(newSuperQualifier) + ) + override fun transformChildren(transformer: IrElementTransformer, data: D) { super.transformChildren(transformer, data) argumentImpl = argumentImpl?.transform(transformer, data) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrReturnImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrReturnImpl.kt index 4f79e8f89f3..47314f5bb13 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrReturnImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrReturnImpl.kt @@ -17,8 +17,11 @@ package org.jetbrains.kotlin.ir.expressions.impl import org.jetbrains.kotlin.descriptors.CallableDescriptor +import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrReturn +import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol +import org.jetbrains.kotlin.ir.symbols.impl.createFunctionSymbol import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns @@ -28,11 +31,19 @@ class IrReturnImpl( startOffset: Int, endOffset: Int, type: KotlinType, - override val returnTarget: CallableDescriptor, + override val returnTargetSymbol: IrFunctionSymbol, override var value: IrExpression ) : IrExpressionBase(startOffset, endOffset, type), IrReturn { - constructor(startOffset: Int, endOffset: Int, returnTarget: CallableDescriptor, value: IrExpression) : - this(startOffset, endOffset, returnTarget.builtIns.nothingType, returnTarget, value) + constructor(startOffset: Int, endOffset: Int, returnTargetSymbol: IrFunctionSymbol, value: IrExpression) : + this(startOffset, endOffset, returnTargetSymbol.descriptor.builtIns.nothingType, returnTargetSymbol, value) + + @Deprecated("Creates unbound symbol") + constructor(startOffset: Int, endOffset: Int, returnTargetDescriptor: FunctionDescriptor, value: IrExpression) : + this(startOffset, endOffset, returnTargetDescriptor.builtIns.nothingType, + createFunctionSymbol(returnTargetDescriptor), + value) + + override val returnTarget: CallableDescriptor get() = returnTargetSymbol.descriptor override fun accept(visitor: IrElementVisitor, data: D): R = visitor.visitReturn(this, data) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrSetFieldImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrSetFieldImpl.kt index 70329a993cc..fa65e87323d 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrSetFieldImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrSetFieldImpl.kt @@ -21,23 +21,64 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrSetField import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin +import org.jetbrains.kotlin.ir.symbols.IrClassSymbol +import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol +import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl +import org.jetbrains.kotlin.ir.symbols.impl.createClassSymbolOrNull import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.types.typeUtil.builtIns class IrSetFieldImpl( startOffset: Int, endOffset: Int, - descriptor: PropertyDescriptor, + symbol: IrFieldSymbol, origin: IrStatementOrigin? = null, - superQualifier: ClassDescriptor? = null -) : IrFieldExpressionBase(startOffset, endOffset, descriptor, descriptor.type.builtIns.unitType, origin, superQualifier), IrSetField { + superQualifierSymbol: IrClassSymbol? = null +) : IrSetField, + IrFieldExpressionBase( + startOffset, endOffset, + symbol, + symbol.descriptor.type.builtIns.unitType, + origin, + superQualifierSymbol + ) +{ + @Deprecated("Creates unbound symbol") constructor( - startOffset: Int, endOffset: Int, descriptor: PropertyDescriptor, + startOffset: Int, endOffset: Int, + propertyDescriptor: PropertyDescriptor, + origin: IrStatementOrigin? = null, + superQualifier: ClassDescriptor? = null + ) : this( + startOffset, endOffset, + IrFieldSymbolImpl(propertyDescriptor), + origin, + createClassSymbolOrNull(superQualifier) + ) + + @Deprecated("Creates unbound symbol") + constructor( + startOffset: Int, endOffset: Int, + propertyDescriptor: PropertyDescriptor, receiver: IrExpression?, value: IrExpression, origin: IrStatementOrigin? = null, superQualifier: ClassDescriptor? = null - ) : this(startOffset, endOffset, descriptor, origin, superQualifier) { + ) : this( + startOffset, endOffset, + IrFieldSymbolImpl(propertyDescriptor), + receiver, value, origin, + createClassSymbolOrNull(superQualifier) + ) + + constructor( + startOffset: Int, endOffset: Int, + symbol: IrFieldSymbol, + receiver: IrExpression?, + value: IrExpression, + origin: IrStatementOrigin? = null, + superQualifierSymbol: IrClassSymbol? = null + ) : this(startOffset, endOffset, symbol, origin, superQualifierSymbol) { this.receiver = receiver this.value = value } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrSetVariableImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrSetVariableImpl.kt index d46ae0151b2..59fcb9e204e 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrSetVariableImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrSetVariableImpl.kt @@ -20,23 +20,27 @@ import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrSetVariable import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin +import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns class IrSetVariableImpl( startOffset: Int, endOffset: Int, - override val descriptor: VariableDescriptor, + override val symbol: IrVariableSymbol, override val origin: IrStatementOrigin? -) : IrExpressionBase(startOffset, endOffset, descriptor.builtIns.unitType), IrSetVariable { +) : IrExpressionBase(startOffset, endOffset, symbol.descriptor.builtIns.unitType), IrSetVariable { constructor( - startOffset: Int, endOffset: Int, descriptor: VariableDescriptor, + startOffset: Int, endOffset: Int, + symbol: IrVariableSymbol, value: IrExpression, origin: IrStatementOrigin? - ) : this(startOffset, endOffset, descriptor, origin) { + ) : this(startOffset, endOffset, symbol, origin) { this.value = value } + override val descriptor: VariableDescriptor get() = symbol.descriptor + override lateinit var value: IrExpression override fun accept(visitor: IrElementVisitor, data: D): R { diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrTerminalDeclarationReferenceBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrTerminalDeclarationReferenceBase.kt index 70b65a72374..2ce3d5f1784 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrTerminalDeclarationReferenceBase.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrTerminalDeclarationReferenceBase.kt @@ -17,16 +17,19 @@ package org.jetbrains.kotlin.ir.expressions.impl import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.ir.expressions.IrDeclarationReference +import org.jetbrains.kotlin.ir.symbols.IrSymbol import org.jetbrains.kotlin.ir.visitors.IrElementTransformer import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.types.KotlinType -abstract class IrTerminalDeclarationReferenceBase( +abstract class IrTerminalDeclarationReferenceBase( startOffset: Int, endOffset: Int, type: KotlinType, + symbol: S, descriptor: D -) : IrDeclarationReferenceBase(startOffset, endOffset, type, descriptor) { +) : IrDeclarationReferenceBase(startOffset, endOffset, type, symbol, descriptor), IrDeclarationReference { override fun acceptChildren(visitor: IrElementVisitor, data: D) { // No children } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrTryImpl.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrTryImpl.kt index 87dbc8eba10..69c217190d5 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrTryImpl.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/expressions/impl/IrTryImpl.kt @@ -18,6 +18,7 @@ package org.jetbrains.kotlin.ir.expressions.impl import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.ir.IrElementBase +import org.jetbrains.kotlin.ir.declarations.IrVariable import org.jetbrains.kotlin.ir.expressions.IrCatch import org.jetbrains.kotlin.ir.expressions.IrExpression import org.jetbrains.kotlin.ir.expressions.IrTry @@ -62,19 +63,24 @@ class IrTryImpl(startOffset: Int, endOffset: Int, type: KotlinType) : } } -class IrCatchImpl(startOffset: Int, endOffset: Int, - override val parameter: VariableDescriptor, - override var result: IrExpression +class IrCatchImpl( + startOffset: Int, endOffset: Int, + override var catchParameter: IrVariable, + override var result: IrExpression ) : IrCatch, IrElementBase(startOffset, endOffset) { + override val parameter: VariableDescriptor get() = catchParameter.descriptor + override fun accept(visitor: IrElementVisitor, data: D): R { return visitor.visitCatch(this, data) } override fun acceptChildren(visitor: IrElementVisitor, data: D) { + catchParameter.accept(visitor, data) result.accept(visitor, data) } override fun transformChildren(transformer: IrElementTransformer, data: D) { + catchParameter = catchParameter.transform(transformer, data) as IrVariable result = result.transform(transformer, data) } } \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrSymbol.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrSymbol.kt index d1ec3986300..796810deda9 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrSymbol.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/IrSymbol.kt @@ -24,26 +24,38 @@ interface IrSymbol { val descriptor: DeclarationDescriptor } -interface IrBindableSymbol : IrSymbol{ +interface IrBindableSymbol : IrSymbol { override val owner: B override val descriptor: D fun bind(owner: B) } +interface IrPackageFragmentSymbol : IrSymbol { + override val descriptor: PackageFragmentDescriptor +} +interface IrFileSymbol : IrPackageFragmentSymbol, IrBindableSymbol +interface IrExternalPackageFragmentSymbol : IrPackageFragmentSymbol, IrBindableSymbol + interface IrAnonymousInitializerSymbol : IrBindableSymbol -interface IrClassSymbol : IrBindableSymbol interface IrEnumEntrySymbol : IrBindableSymbol -interface IrFileSymbol : IrBindableSymbol + interface IrFieldSymbol : IrBindableSymbol -interface IrTypeParameterSymbol : IrBindableSymbol -interface IrValueParameterSymbol : IrBindableSymbol -interface IrVariableSymbol : IrBindableSymbol +interface IrClassifierSymbol : IrSymbol { + override val descriptor: ClassifierDescriptor +} +interface IrClassSymbol : IrClassifierSymbol, IrBindableSymbol +interface IrTypeParameterSymbol : IrClassifierSymbol, IrBindableSymbol + +interface IrValueSymbol : IrSymbol { + override val descriptor: ValueDescriptor +} +interface IrValueParameterSymbol : IrValueSymbol, IrBindableSymbol +interface IrVariableSymbol : IrValueSymbol, IrBindableSymbol interface IrFunctionSymbol : IrSymbol { override val descriptor: FunctionDescriptor } - interface IrConstructorSymbol : IrFunctionSymbol, IrBindableSymbol interface IrSimpleFunctionSymbol : IrFunctionSymbol, IrBindableSymbol \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrBindableSymbolBase.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrSymbolBase.kt similarity index 69% rename from compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrBindableSymbolBase.kt rename to compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrSymbolBase.kt index f7f3edbd1c2..bb6b800875f 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrBindableSymbolBase.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/symbols/impl/IrSymbolBase.kt @@ -20,9 +20,10 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.symbols.* -abstract class IrBindableSymbolBase( - override val descriptor: D -) : IrBindableSymbol { +abstract class IrSymbolBase(override val descriptor: D) : IrSymbol + +abstract class IrBindableSymbolBase(descriptor: D) : + IrBindableSymbol, IrSymbolBase(descriptor) { private var _owner: B? = null override val owner: B get() = _owner ?: throw IllegalStateException("Symbol for $descriptor is unbound") @@ -35,6 +36,14 @@ abstract class IrBindableSymbolBase(descriptor), + IrFileSymbol + +class IrExternalPackageFragmentSymbolImpl(descriptor: PackageFragmentDescriptor) : + IrBindableSymbolBase(descriptor), + IrExternalPackageFragmentSymbol + class IrAnonymousInitializerSymbolImpl(descriptor: ClassDescriptor) : IrBindableSymbolBase(descriptor), IrAnonymousInitializerSymbol @@ -43,14 +52,13 @@ class IrClassSymbolImpl(descriptor: ClassDescriptor) : IrBindableSymbolBase(descriptor), IrClassSymbol +fun createClassSymbolOrNull(descriptor: ClassDescriptor?) = + descriptor?.let { IrClassSymbolImpl(it) } + class IrEnumEntrySymbolImpl(descriptor: ClassDescriptor) : IrBindableSymbolBase(descriptor), IrEnumEntrySymbol -class IrFileSymbolImpl(descriptor: PackageFragmentDescriptor) : - IrBindableSymbolBase(descriptor), - IrFileSymbol - class IrFieldSymbolImpl(descriptor: PropertyDescriptor) : IrBindableSymbolBase(descriptor), IrFieldSymbol @@ -67,10 +75,24 @@ class IrVariableSymbolImpl(descriptor: VariableDescriptor) : IrBindableSymbolBase(descriptor), IrVariableSymbol +fun createValueSymbol(descriptor: ValueDescriptor): IrValueSymbol = + when (descriptor) { + is ParameterDescriptor -> IrValueParameterSymbolImpl(descriptor) + is VariableDescriptor -> IrVariableSymbolImpl(descriptor) + else -> throw IllegalArgumentException("Unexpected descriptor kind: $descriptor") + } + class IrSimpleFunctionSymbolImpl(descriptor: FunctionDescriptor) : IrBindableSymbolBase(descriptor), IrSimpleFunctionSymbol class IrConstructorSymbolImpl(descriptor: ClassConstructorDescriptor) : IrBindableSymbolBase(descriptor), - IrConstructorSymbol \ No newline at end of file + IrConstructorSymbol + +fun createFunctionSymbol(descriptor: CallableMemberDescriptor): IrFunctionSymbol = + when (descriptor) { + is ClassConstructorDescriptor -> IrConstructorSymbolImpl(descriptor) + is FunctionDescriptor -> IrSimpleFunctionSymbolImpl(descriptor) + else -> throw IllegalArgumentException("Unexpected descriptor kind: $descriptor") + } \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTree.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTree.kt index dfa3c72f3fc..d617f1e7542 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTree.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopyIrTree.kt @@ -16,65 +16,67 @@ package org.jetbrains.kotlin.ir.util -import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrStatement -import org.jetbrains.kotlin.ir.SourceManager import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.* import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.expressions.impl.* +import org.jetbrains.kotlin.ir.symbols.impl.IrAnonymousInitializerSymbolImpl import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid +import org.jetbrains.kotlin.ir.visitors.acceptVoid import org.jetbrains.kotlin.types.KotlinType import java.util.* -open class DeepCopyIrTree : IrElementTransformerVoid() { - protected open fun mapDeclarationOrigin(declarationOrigin: IrDeclarationOrigin) = declarationOrigin - protected open fun mapStatementOrigin(statementOrigin: IrStatementOrigin?) = statementOrigin - protected open fun mapFileEntry(fileEntry: SourceManager.FileEntry) = fileEntry +inline fun T.deepCopy(): T { + val remapper = DeepCopySymbolsRemapper() + acceptVoid(remapper) + return transform(DeepCopyIrTree(remapper), null) as T +} - protected open fun mapModuleDescriptor(descriptor: ModuleDescriptor) = descriptor - protected open fun mapPackageFragmentDescriptor(descriptor: PackageFragmentDescriptor) = descriptor - protected open fun mapClassDeclaration(descriptor: ClassDescriptor) = descriptor - protected open fun mapTypeAliasDeclaration(descriptor: TypeAliasDescriptor) = descriptor - protected open fun mapFunctionDeclaration(descriptor: FunctionDescriptor) = descriptor - protected open fun mapConstructorDeclaration(descriptor: ClassConstructorDescriptor) = descriptor - protected open fun mapPropertyDeclaration(descriptor: PropertyDescriptor) = descriptor - protected open fun mapLocalPropertyDeclaration(descriptor: VariableDescriptorWithAccessors) = descriptor - protected open fun mapEnumEntryDeclaration(descriptor: ClassDescriptor) = descriptor - protected open fun mapVariableDeclaration(descriptor: VariableDescriptor) = descriptor - protected open fun mapCatchParameterDeclaration(descriptor: VariableDescriptor) = mapVariableDeclaration(descriptor) - protected open fun mapErrorDeclaration(descriptor: DeclarationDescriptor) = descriptor - protected open fun mapSuperQualifier(qualifier: ClassDescriptor?) = qualifier - protected open fun mapClassReference(descriptor: ClassDescriptor) = descriptor - protected open fun mapValueReference(descriptor: ValueDescriptor) = descriptor - protected open fun mapVariableReference(descriptor: VariableDescriptor) = descriptor - protected open fun mapPropertyReference(descriptor: PropertyDescriptor) = descriptor - protected open fun mapCallee(descriptor: CallableDescriptor) = descriptor - protected open fun mapDelegatedConstructorCallee(descriptor: ClassConstructorDescriptor) = descriptor - protected open fun mapEnumConstructorCallee(descriptor: ClassConstructorDescriptor) = descriptor - protected open fun mapCallableReference(descriptor: CallableDescriptor) = descriptor - protected open fun mapClassifierReference(descriptor: ClassifierDescriptor) = descriptor - protected open fun mapReturnTarget(descriptor: CallableDescriptor) = mapCallee(descriptor) +class DeepCopyIrTree(private val symbolsRemapper: DeepCopySymbolsRemapper) : IrElementTransformerVoid() { + private fun mapDeclarationOrigin(origin: IrDeclarationOrigin) = origin + private fun mapStatementOrigin(origin: IrStatementOrigin?) = origin + + private inline fun T.transform() = + transform(this@DeepCopyIrTree, null) as T + + private inline fun List.transform() = + map { it.transform() } + + private inline fun List.transformTo(destination: MutableList) = + mapTo(destination) { it.transform() } + + private fun T.transformDeclarationsTo(destination: T) = + declarations.transformTo(destination.declarations) override fun visitElement(element: IrElement): IrElement = throw IllegalArgumentException("Unsupported element type: $element") override fun visitModuleFragment(declaration: IrModuleFragment): IrModuleFragment = IrModuleFragmentImpl( - mapModuleDescriptor(declaration.descriptor), + declaration.descriptor, declaration.irBuiltins, - declaration.files.map { it.transform(this, null) } + declaration.files.transform() ) + override fun visitExternalPackageFragment(declaration: IrExternalPackageFragment, data: Nothing?): IrExternalPackageFragment = + IrExternalPackageFragmentImpl( + symbolsRemapper.getDeclaredExternalPackageFragment(declaration.symbol) + ).apply { + declaration.transformDeclarationsTo(this) + } + override fun visitFile(declaration: IrFile): IrFile = IrFileImpl( - mapFileEntry(declaration.fileEntry), - mapPackageFragmentDescriptor(declaration.packageFragmentDescriptor), - declaration.fileAnnotations.toMutableList(), - declaration.declarations.map { it.transform(this, null) as IrDeclaration } - ) + declaration.fileEntry, + symbolsRemapper.getDeclaredFile(declaration.symbol) + ).apply { + fileAnnotations.addAll(declaration.fileAnnotations) + declaration.transformDeclarationsTo(this) + } override fun visitDeclaration(declaration: IrDeclaration): IrStatement = throw IllegalArgumentException("Unsupported declaration type: $declaration") @@ -83,151 +85,127 @@ open class DeepCopyIrTree : IrElementTransformerVoid() { IrClassImpl( declaration.startOffset, declaration.endOffset, mapDeclarationOrigin(declaration.origin), - mapClassDeclaration(declaration.descriptor), - declaration.declarations.map { it.transform(this, null) as IrDeclaration } + symbolsRemapper.getDeclaredClass(declaration.symbol) ).apply { - transformTypeParameters(declaration, descriptor.declaredTypeParameters) + newInstanceReceiver = declaration.newInstanceReceiver?.transform() + declaration.typeParameters.transformTo(typeParameters) + declaration.transformDeclarationsTo(this) } override fun visitTypeAlias(declaration: IrTypeAlias): IrTypeAlias = IrTypeAliasImpl( declaration.startOffset, declaration.endOffset, mapDeclarationOrigin(declaration.origin), - mapTypeAliasDeclaration(declaration.descriptor) + declaration.descriptor ) override fun visitSimpleFunction(declaration: IrSimpleFunction): IrSimpleFunction = IrFunctionImpl( declaration.startOffset, declaration.endOffset, mapDeclarationOrigin(declaration.origin), - mapFunctionDeclaration(declaration.descriptor), - declaration.body?.transform(this, null) - ).transformParameters(declaration) + symbolsRemapper.getDeclaredFunction(declaration.symbol) + ).transformFunctionChildren(declaration) override fun visitConstructor(declaration: IrConstructor): IrConstructor = IrConstructorImpl( declaration.startOffset, declaration.endOffset, mapDeclarationOrigin(declaration.origin), - mapConstructorDeclaration(declaration.descriptor), - declaration.body!!.transform(this, null) - ).transformParameters(declaration) + symbolsRemapper.getDeclaredConstructor(declaration.symbol) + ).transformFunctionChildren(declaration) - private fun T.transformTypeParameters(original: T, myTypeParameters: List): T = + private fun T.transformFunctionChildren(declaration: T): T = apply { - original.typeParameters.mapTo(typeParameters) { originalTypeParameter -> - copyTypeParameter(originalTypeParameter, myTypeParameters[originalTypeParameter.descriptor.index]) - } + declaration.typeParameters.transformTo(typeParameters) + dispatchReceiverParameter = declaration.dispatchReceiverParameter?.transform() + extensionReceiverParameter = declaration.extensionReceiverParameter?.transform() + declaration.valueParameters.transformTo(valueParameters) + body = declaration.body?.transform() } - private fun T.transformParameters(original: T): T = - apply { - transformTypeParameters(original, descriptor.typeParameters) - transformValueParameters(original) - } - - private fun T.transformValueParameters(original: T) = - apply { - dispatchReceiverParameter = original.dispatchReceiverParameter?.let { - copyValueParameter(it, descriptor.dispatchReceiverParameter ?: throw AssertionError("No dispatch receiver in $descriptor")) - } - - extensionReceiverParameter = original.extensionReceiverParameter?.let { - copyValueParameter(it, descriptor.extensionReceiverParameter ?: throw AssertionError("No extension receiver in $descriptor")) - } - - original.valueParameters.mapIndexedTo(valueParameters) { i, originalValueParameter -> - copyValueParameter(originalValueParameter, descriptor.valueParameters[i]) - } - } - - private fun copyTypeParameter( - originalTypeParameter: IrTypeParameter, - newTypeParameterDescriptor: TypeParameterDescriptor - ): IrTypeParameterImpl = - IrTypeParameterImpl( - originalTypeParameter.startOffset, originalTypeParameter.endOffset, - mapDeclarationOrigin(originalTypeParameter.origin), - newTypeParameterDescriptor - ) - - private fun copyValueParameter( - originalValueParameter: IrValueParameter, - newParameterDescriptor: ParameterDescriptor - ): IrValueParameterImpl = - IrValueParameterImpl( - originalValueParameter.startOffset, originalValueParameter.endOffset, - mapDeclarationOrigin(originalValueParameter.origin), - newParameterDescriptor, - originalValueParameter.defaultValue?.transform(this@DeepCopyIrTree, null) - ) - - // TODO visitTypeParameter - // TODO visitValueParameter - override fun visitProperty(declaration: IrProperty): IrProperty = IrPropertyImpl( declaration.startOffset, declaration.endOffset, mapDeclarationOrigin(declaration.origin), declaration.isDelegated, - mapPropertyDeclaration(declaration.descriptor), - declaration.backingField?.transform(this, null) as? IrField, - declaration.getter?.transform(this, null) as? IrFunction, - declaration.setter?.transform(this, null) as? IrFunction + declaration.descriptor, + declaration.backingField?.transform(), + declaration.getter?.transform(), + declaration.setter?.transform() ) override fun visitField(declaration: IrField): IrField = IrFieldImpl( declaration.startOffset, declaration.endOffset, mapDeclarationOrigin(declaration.origin), - mapPropertyDeclaration(declaration.descriptor), - declaration.initializer?.transform(this, null) as? IrExpressionBody - ) + symbolsRemapper.getDeclaredField(declaration.symbol) + ).apply { + initializer = declaration.initializer?.transform() + } override fun visitLocalDelegatedProperty(declaration: IrLocalDelegatedProperty): IrLocalDelegatedProperty = IrLocalDelegatedPropertyImpl( declaration.startOffset, declaration.endOffset, mapDeclarationOrigin(declaration.origin), - mapLocalPropertyDeclaration(declaration.descriptor), - declaration.delegate.transform(this, null) as IrVariable, - declaration.getter.transform(this, null) as IrFunction, - declaration.setter?.transform(this, null) as IrFunction? + declaration.descriptor, + declaration.delegate.transform(), + declaration.getter.transform(), + declaration.setter?.transform() ) override fun visitEnumEntry(declaration: IrEnumEntry): IrEnumEntry = IrEnumEntryImpl( declaration.startOffset, declaration.endOffset, mapDeclarationOrigin(declaration.origin), - mapEnumEntryDeclaration(declaration.descriptor), - declaration.correspondingClass?.transform(this, null) as? IrClass, - declaration.initializerExpression.transform(this, null) - ) + symbolsRemapper.getDeclaredEnumEntry(declaration.symbol) + ).apply { + correspondingClass = declaration.correspondingClass?.transform() + initializerExpression = declaration.initializerExpression.transform() + } override fun visitAnonymousInitializer(declaration: IrAnonymousInitializer): IrAnonymousInitializer = IrAnonymousInitializerImpl( declaration.startOffset, declaration.endOffset, mapDeclarationOrigin(declaration.origin), - mapClassDeclaration(declaration.descriptor), - declaration.body.transform(this, null) as IrBlockBody - ) + IrAnonymousInitializerSymbolImpl(declaration.descriptor) + ).apply { + body = declaration.body.transform() + } override fun visitVariable(declaration: IrVariable): IrVariable = IrVariableImpl( declaration.startOffset, declaration.endOffset, mapDeclarationOrigin(declaration.origin), - mapVariableDeclaration(declaration.descriptor), - declaration.initializer?.transform(this, null) as? IrExpression + symbolsRemapper.getDeclaredVariable(declaration.symbol) + ).apply { + initializer = declaration.initializer?.transform() + } + + override fun visitTypeParameter(declaration: IrTypeParameter): IrTypeParameter = + IrTypeParameterImpl( + declaration.startOffset, declaration.endOffset, + mapDeclarationOrigin(declaration.origin), + symbolsRemapper.getDeclaredTypeParameter(declaration.symbol) ) + override fun visitValueParameter(declaration: IrValueParameter): IrValueParameter = + IrValueParameterImpl( + declaration.startOffset, declaration.endOffset, + mapDeclarationOrigin(declaration.origin), + symbolsRemapper.getDeclaredValueParameter(declaration.symbol) + ).apply { + defaultValue = declaration.defaultValue?.transform() + } + override fun visitBody(body: IrBody): IrBody = throw IllegalArgumentException("Unsupported body type: $body") override fun visitExpressionBody(body: IrExpressionBody): IrExpressionBody = - IrExpressionBodyImpl(body.expression.transform(this, null)) + IrExpressionBodyImpl(body.expression.transform()) override fun visitBlockBody(body: IrBlockBody): IrBlockBody = IrBlockBodyImpl( body.startOffset, body.endOffset, - body.statements.map { it.transform(this, null) } + body.statements.map { it.transform() } ) override fun visitSyntheticBody(body: IrSyntheticBody): IrSyntheticBody = @@ -243,13 +221,13 @@ open class DeepCopyIrTree : IrElementTransformerVoid() { IrVarargImpl( expression.startOffset, expression.endOffset, expression.type, expression.varargElementType, - expression.elements.map { it.transform(this, null) as IrVarargElement } + expression.elements.transform() ) override fun visitSpreadElement(spread: IrSpreadElement): IrSpreadElement = IrSpreadElementImpl( spread.startOffset, spread.endOffset, - spread.expression.transform(this, null) + spread.expression.transform() ) override fun visitBlock(expression: IrBlock): IrBlock = @@ -257,7 +235,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() { expression.startOffset, expression.endOffset, expression.type, mapStatementOrigin(expression.origin), - expression.statements.map { it.transform(this, null) } + expression.statements.map { it.transform() } ) override fun visitComposite(expression: IrComposite): IrComposite = @@ -265,97 +243,101 @@ open class DeepCopyIrTree : IrElementTransformerVoid() { expression.startOffset, expression.endOffset, expression.type, mapStatementOrigin(expression.origin), - expression.statements.map { it.transform(this, null) } + expression.statements.map { it.transform() } ) override fun visitStringConcatenation(expression: IrStringConcatenation): IrStringConcatenation = IrStringConcatenationImpl( expression.startOffset, expression.endOffset, expression.type, - expression.arguments.map { it.transform(this, null) } + expression.arguments.map { it.transform() } ) override fun visitGetObjectValue(expression: IrGetObjectValue): IrGetObjectValue = IrGetObjectValueImpl( expression.startOffset, expression.endOffset, expression.type, - mapClassReference(expression.descriptor) + symbolsRemapper.getReferencedClass(expression.symbol) ) override fun visitGetEnumValue(expression: IrGetEnumValue): IrGetEnumValue = IrGetEnumValueImpl( expression.startOffset, expression.endOffset, expression.type, - mapClassReference(expression.descriptor) + symbolsRemapper.getReferencedEnumEntry(expression.symbol) ) override fun visitGetValue(expression: IrGetValue): IrGetValue = IrGetValueImpl( expression.startOffset, expression.endOffset, - mapValueReference(expression.descriptor), + symbolsRemapper.getReferencedValue(expression.symbol), mapStatementOrigin(expression.origin) ) override fun visitSetVariable(expression: IrSetVariable): IrSetVariable = IrSetVariableImpl( expression.startOffset, expression.endOffset, - mapVariableReference(expression.descriptor), - expression.value.transform(this, null), + symbolsRemapper.getReferencedVariable(expression.symbol), + expression.value.transform(), mapStatementOrigin(expression.origin) ) override fun visitGetField(expression: IrGetField): IrGetField = IrGetFieldImpl( expression.startOffset, expression.endOffset, - mapPropertyReference(expression.descriptor), - expression.receiver?.transform(this, null), + symbolsRemapper.getReferencedField(expression.symbol), + expression.receiver?.transform(), mapStatementOrigin(expression.origin), - mapSuperQualifier(expression.superQualifier) + symbolsRemapper.getReferencedClassOrNull(expression.superQualifierSymbol) ) override fun visitSetField(expression: IrSetField): IrSetField = IrSetFieldImpl( expression.startOffset, expression.endOffset, - mapPropertyReference(expression.descriptor), - expression.receiver?.transform(this, null), - expression.value.transform(this, null), + symbolsRemapper.getReferencedField(expression.symbol), + expression.receiver?.transform(), + expression.value.transform(), mapStatementOrigin(expression.origin), - mapSuperQualifier(expression.superQualifier) + symbolsRemapper.getReferencedClassOrNull(expression.superQualifierSymbol) ) override fun visitCall(expression: IrCall): IrCall = shallowCopyCall(expression).transformValueArguments(expression) - protected fun shallowCopyCall(expression: IrCall) = + private fun shallowCopyCall(expression: IrCall) = when (expression) { is IrCallWithShallowCopy -> expression.shallowCopy( mapStatementOrigin(expression.origin), - mapCallee(expression.descriptor), - mapSuperQualifier(expression.superQualifier) + symbolsRemapper.getReferencedFunction(expression.symbol), + symbolsRemapper.getReferencedClassOrNull(expression.superQualifierSymbol) ) else -> IrCallImpl( expression.startOffset, expression.endOffset, expression.type, - mapCallee(expression.descriptor), + symbolsRemapper.getReferencedFunction(expression.symbol), expression.getTypeArgumentsMap(), mapStatementOrigin(expression.origin), - mapSuperQualifier(expression.superQualifier) + symbolsRemapper.getReferencedClassOrNull(expression.superQualifierSymbol) ) } - protected fun T.transformValueArguments(original: IrMemberAccessExpression): T = + private fun T.transformReceiverArguments(original: T): T = apply { - dispatchReceiver = original.dispatchReceiver?.transform(this@DeepCopyIrTree, null) - extensionReceiver = original.extensionReceiver?.transform(this@DeepCopyIrTree, null) - mapValueParameters { valueParameter -> - original.getValueArgument(valueParameter)?.transform(this@DeepCopyIrTree, null) - } - Unit + dispatchReceiver = original.dispatchReceiver?.transform() + extensionReceiver = original.extensionReceiver?.transform() } - protected fun IrMemberAccessExpression.getTypeArgumentsMap(): Map? { + private fun T.transformValueArguments(original: T): T = + apply { + transformReceiverArguments(original) + mapValueParameters { valueParameter -> + original.getValueArgument(valueParameter)?.transform() + } + } + + private fun IrMemberAccessExpression.getTypeArgumentsMap(): Map? { if (this is IrMemberAccessExpressionBase) return typeArguments val typeParameters = descriptor.original.typeParameters @@ -368,28 +350,40 @@ open class DeepCopyIrTree : IrElementTransformerVoid() { override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall): IrDelegatingConstructorCall = IrDelegatingConstructorCallImpl( expression.startOffset, expression.endOffset, - mapDelegatedConstructorCallee(expression.descriptor), + symbolsRemapper.getReferencedConstructor(expression.symbol), expression.getTypeArgumentsMap() ).transformValueArguments(expression) override fun visitEnumConstructorCall(expression: IrEnumConstructorCall): IrEnumConstructorCall = IrEnumConstructorCallImpl( expression.startOffset, expression.endOffset, - mapEnumConstructorCallee(expression.descriptor) + symbolsRemapper.getReferencedConstructor(expression.symbol) ).transformValueArguments(expression) override fun visitGetClass(expression: IrGetClass): IrGetClass = IrGetClassImpl( expression.startOffset, expression.endOffset, expression.type, - expression.argument.transform(this, null) + expression.argument.transform() ) - override fun visitCallableReference(expression: IrCallableReference): IrCallableReference = - IrCallableReferenceImpl( + override fun visitFunctionReference(expression: IrFunctionReference): IrFunctionReference = + IrFunctionReferenceImpl( expression.startOffset, expression.endOffset, expression.type, - mapCallableReference(expression.descriptor), + symbolsRemapper.getReferencedFunction(expression.symbol), + expression.getTypeArgumentsMap(), + mapStatementOrigin(expression.origin) + ).transformValueArguments(expression) + + override fun visitPropertyReference(expression: IrPropertyReference): IrExpression = + IrPropertyReferenceImpl( + expression.startOffset, expression.endOffset, + expression.type, + expression.descriptor, + expression.field?.let { symbolsRemapper.getReferencedField(it) }, + expression.getter?.let { symbolsRemapper.getReferencedFunction(it) }, + expression.setter?.let { symbolsRemapper.getReferencedFunction(it) }, expression.getTypeArgumentsMap(), mapStatementOrigin(expression.origin) ).transformValueArguments(expression) @@ -398,13 +392,13 @@ open class DeepCopyIrTree : IrElementTransformerVoid() { IrClassReferenceImpl( expression.startOffset, expression.endOffset, expression.type, - mapClassifierReference(expression.descriptor) + symbolsRemapper.getReferencedClassifier(expression.symbol) ) override fun visitInstanceInitializerCall(expression: IrInstanceInitializerCall): IrInstanceInitializerCall = IrInstanceInitializerCallImpl( expression.startOffset, expression.endOffset, - mapClassReference(expression.classDescriptor) + symbolsRemapper.getReferencedClass(expression.classSymbol) ) override fun visitTypeOperator(expression: IrTypeOperatorCall): IrTypeOperatorCall = @@ -413,7 +407,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() { expression.type, expression.operator, expression.typeOperand, - expression.argument.transform(this, null) + expression.argument.transform() ) override fun visitWhen(expression: IrWhen): IrWhen = @@ -421,21 +415,21 @@ open class DeepCopyIrTree : IrElementTransformerVoid() { expression.startOffset, expression.endOffset, expression.type, mapStatementOrigin(expression.origin), - expression.branches.map { it.transform(this, null) } + expression.branches.map { it.transform() } ) override fun visitBranch(branch: IrBranch): IrBranch = IrBranchImpl( branch.startOffset, branch.endOffset, - branch.condition.transform(this, null), - branch.result.transform(this, null) + branch.condition.transform(), + branch.result.transform() ) override fun visitElseBranch(branch: IrElseBranch): IrElseBranch = IrElseBranchImpl( branch.startOffset, branch.endOffset, - branch.condition.transform(this, null), - branch.result.transform(this, null) + branch.condition.transform(), + branch.result.transform() ) private val transformedLoops = HashMap() @@ -443,26 +437,24 @@ open class DeepCopyIrTree : IrElementTransformerVoid() { private fun getTransformedLoop(irLoop: IrLoop): IrLoop = transformedLoops.getOrElse(irLoop) { getNonTransformedLoop(irLoop) } - protected open fun getNonTransformedLoop(irLoop: IrLoop): IrLoop = + private fun getNonTransformedLoop(irLoop: IrLoop): IrLoop = throw AssertionError("Outer loop was not transformed: ${irLoop.render()}") - override fun visitWhileLoop(loop: IrWhileLoop): IrWhileLoop { - val newLoop = IrWhileLoopImpl(loop.startOffset, loop.endOffset, loop.type, mapStatementOrigin(loop.origin)) - transformedLoops[loop] = newLoop - newLoop.label = loop.label - newLoop.condition = loop.condition.transform(this, null) - newLoop.body = loop.body?.transform(this, null) - return newLoop - } + override fun visitWhileLoop(loop: IrWhileLoop): IrWhileLoop = + IrWhileLoopImpl(loop.startOffset, loop.endOffset, loop.type, mapStatementOrigin(loop.origin)).also { newLoop -> + transformedLoops[loop] = newLoop + newLoop.label = loop.label + newLoop.condition = loop.condition.transform() + newLoop.body = loop.body?.transform() + } - override fun visitDoWhileLoop(loop: IrDoWhileLoop): IrDoWhileLoop { - val newLoop = IrDoWhileLoopImpl(loop.startOffset, loop.endOffset, loop.type, mapStatementOrigin(loop.origin)) - transformedLoops[loop] = newLoop - newLoop.label = loop.label - newLoop.condition = loop.condition.transform(this, null) - newLoop.body = loop.body?.transform(this, null) - return newLoop - } + override fun visitDoWhileLoop(loop: IrDoWhileLoop): IrDoWhileLoop = + IrDoWhileLoopImpl(loop.startOffset, loop.endOffset, loop.type, mapStatementOrigin(loop.origin)).also { newLoop -> + transformedLoops[loop] = newLoop + newLoop.label = loop.label + newLoop.condition = loop.condition.transform() + newLoop.body = loop.body?.transform() + } override fun visitBreak(jump: IrBreak): IrBreak = IrBreakImpl( @@ -482,38 +474,35 @@ open class DeepCopyIrTree : IrElementTransformerVoid() { IrTryImpl( aTry.startOffset, aTry.endOffset, aTry.type, - aTry.tryResult.transform(this, null), - aTry.catches.map { it.transform(this, null) }, - aTry.finallyExpression?.transform(this, null) + aTry.tryResult.transform(), + aTry.catches.map { it.transform() }, + aTry.finallyExpression?.transform() ) override fun visitCatch(aCatch: IrCatch): IrCatch = IrCatchImpl( aCatch.startOffset, aCatch.endOffset, - mapCatchParameterDeclaration(aCatch.parameter), - aCatch.result.transform(this, null) + aCatch.catchParameter.transform(), + aCatch.result.transform() ) override fun visitReturn(expression: IrReturn): IrReturn = IrReturnImpl( expression.startOffset, expression.endOffset, expression.type, - mapReturnTarget(expression.returnTarget), - expression.value.transform(this, null) + symbolsRemapper.getReferencedFunction(expression.returnTargetSymbol), + expression.value.transform() ) override fun visitThrow(expression: IrThrow): IrThrow = IrThrowImpl( expression.startOffset, expression.endOffset, expression.type, - expression.value.transform(this, null) + expression.value.transform() ) override fun visitErrorDeclaration(declaration: IrErrorDeclaration): IrErrorDeclaration = - IrErrorDeclarationImpl( - declaration.startOffset, declaration.endOffset, - mapErrorDeclaration(declaration.descriptor) - ) + IrErrorDeclarationImpl(declaration.startOffset, declaration.endOffset, declaration.descriptor) override fun visitErrorExpression(expression: IrErrorExpression): IrErrorExpression = IrErrorExpressionImpl( @@ -528,7 +517,8 @@ open class DeepCopyIrTree : IrElementTransformerVoid() { expression.type, expression.description ).apply { - explicitReceiver = expression.explicitReceiver?.transform(this@DeepCopyIrTree, null) - expression.arguments.mapTo(arguments) { it.transform(this@DeepCopyIrTree, null) } + explicitReceiver = expression.explicitReceiver?.transform() + expression.arguments.transformTo(arguments) } -} \ No newline at end of file +} + diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopySymbolsRemapper.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopySymbolsRemapper.kt new file mode 100644 index 00000000000..b660f77e003 --- /dev/null +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeepCopySymbolsRemapper.kt @@ -0,0 +1,145 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.ir.util + +import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.ir.IrElement +import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.symbols.* +import org.jetbrains.kotlin.ir.symbols.impl.* +import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid +import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid + +class DeepCopySymbolsRemapper : IrElementVisitorVoid { + private val classes = hashMapOf() + private val constructors = hashMapOf() + private val enumEntries = hashMapOf() + private val externalPackageFragments = hashMapOf() + private val fields = hashMapOf() + private val files = hashMapOf() + private val functions = hashMapOf() + private val typeParameters = hashMapOf() + private val valueParameters = hashMapOf() + private val variables = hashMapOf() + + override fun visitElement(element: IrElement) { + element.acceptChildrenVoid(this) + } + + private inline fun > + remapSymbol(map: MutableMap, owner: B, createNewSymbol: (S) -> S) { + val symbol = owner.symbol as S + map[symbol] = createNewSymbol(symbol) + } + + override fun visitClass(declaration: IrClass) { + remapSymbol(classes, declaration) { IrClassSymbolImpl(it.descriptor) } + declaration.acceptChildrenVoid(this) + } + + override fun visitConstructor(declaration: IrConstructor) { + remapSymbol(constructors, declaration) { IrConstructorSymbolImpl(it.descriptor) } + declaration.acceptChildrenVoid(this) + } + + override fun visitEnumEntry(declaration: IrEnumEntry) { + remapSymbol(enumEntries, declaration) { IrEnumEntrySymbolImpl(it.descriptor) } + declaration.acceptChildrenVoid(this) + } + + override fun visitExternalPackageFragment(declaration: IrExternalPackageFragment) { + remapSymbol(externalPackageFragments, declaration) { IrExternalPackageFragmentSymbolImpl(it.descriptor) } + declaration.acceptChildrenVoid(this) + } + + override fun visitField(declaration: IrField) { + remapSymbol(fields, declaration) { IrFieldSymbolImpl(it.descriptor) } + declaration.acceptChildrenVoid(this) + } + + override fun visitFile(declaration: IrFile) { + remapSymbol(files, declaration) { IrFileSymbolImpl(it.descriptor) } + declaration.acceptChildrenVoid(this) + } + + override fun visitSimpleFunction(declaration: IrSimpleFunction) { + remapSymbol(functions, declaration) { IrSimpleFunctionSymbolImpl(it.descriptor) } + declaration.acceptChildrenVoid(this) + } + + override fun visitTypeParameter(declaration: IrTypeParameter) { + remapSymbol(typeParameters, declaration) { IrTypeParameterSymbolImpl(it.descriptor) } + declaration.acceptChildrenVoid(this) + } + + override fun visitValueParameter(declaration: IrValueParameter) { + remapSymbol(valueParameters, declaration) { IrValueParameterSymbolImpl(it.descriptor) } + declaration.acceptChildrenVoid(this) + } + + override fun visitVariable(declaration: IrVariable) { + remapSymbol(variables, declaration) { IrVariableSymbolImpl(it.descriptor) } + declaration.acceptChildrenVoid(this) + } + + private fun Map.getDeclared(symbol: T) = + getOrElse(symbol) { + throw IllegalArgumentException("Non-remapped symbol $symbol ${symbol.descriptor}") + } + + private fun Map.getReferenced(symbol: T) = + getOrElse(symbol) { symbol } + + fun getDeclaredClass(symbol: IrClassSymbol): IrClassSymbol = classes.getDeclared(symbol) + fun getDeclaredFunction(symbol: IrSimpleFunctionSymbol): IrSimpleFunctionSymbol = functions.getDeclared(symbol) + fun getDeclaredField(symbol: IrFieldSymbol): IrFieldSymbol = fields.getDeclared(symbol) + fun getDeclaredFile(symbol: IrFileSymbol): IrFileSymbol = files.getDeclared(symbol) + fun getDeclaredConstructor(symbol: IrConstructorSymbol): IrConstructorSymbol = constructors.getDeclared(symbol) + fun getDeclaredEnumEntry(symbol: IrEnumEntrySymbol): IrEnumEntrySymbol = enumEntries.getDeclared(symbol) + fun getDeclaredExternalPackageFragment(symbol: IrExternalPackageFragmentSymbol): IrExternalPackageFragmentSymbol = externalPackageFragments.getDeclared(symbol) + fun getDeclaredVariable(symbol: IrVariableSymbol): IrVariableSymbol = variables.getDeclared(symbol) + fun getDeclaredTypeParameter(symbol: IrTypeParameterSymbol): IrTypeParameterSymbol = typeParameters.getDeclared(symbol) + fun getDeclaredValueParameter(symbol: IrValueParameterSymbol): IrValueParameterSymbol = valueParameters.getDeclared(symbol) + + fun getReferencedClass(symbol: IrClassSymbol): IrClassSymbol = classes.getReferenced(symbol) + fun getReferencedClassOrNull(symbol: IrClassSymbol?): IrClassSymbol? = symbol?.let { classes.getReferenced(it) } + fun getReferencedEnumEntry(symbol: IrEnumEntrySymbol): IrEnumEntrySymbol = enumEntries.getReferenced(symbol) + fun getReferencedVariable(symbol: IrVariableSymbol): IrVariableSymbol = variables.getReferenced(symbol) + fun getReferencedField(symbol: IrFieldSymbol): IrFieldSymbol = fields.getReferenced(symbol) + fun getReferencedConstructor(symbol: IrConstructorSymbol): IrConstructorSymbol = constructors.getReferenced(symbol) + + fun getReferencedValue(symbol: IrValueSymbol): IrValueSymbol = + when (symbol) { + is IrValueParameterSymbol -> valueParameters.getReferenced(symbol) + is IrVariableSymbol -> variables.getReferenced(symbol) + else -> throw IllegalArgumentException("Unexpected symbol $symbol ${symbol.descriptor}") + } + + fun getReferencedFunction(symbol: IrFunctionSymbol): IrFunctionSymbol = + when (symbol) { + is IrSimpleFunctionSymbol -> functions.getReferenced(symbol) + is IrConstructorSymbol -> constructors.getReferenced(symbol) + else -> throw IllegalArgumentException("Unexpected symbol $symbol ${symbol.descriptor}") + } + + fun getReferencedClassifier(symbol: IrClassifierSymbol): IrClassifierSymbol = + when (symbol) { + is IrClassSymbol -> classes.getReferenced(symbol) + is IrTypeParameterSymbol -> typeParameters.getReferenced(symbol) + else -> throw IllegalArgumentException("Unexpected symbol $symbol ${symbol.descriptor}") + } +} \ No newline at end of file diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DumpIrTree.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DumpIrTree.kt index 07b4aeb2c88..296bbf0964a 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DumpIrTree.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DumpIrTree.kt @@ -18,10 +18,7 @@ package org.jetbrains.kotlin.ir.util import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.SourceManager -import org.jetbrains.kotlin.ir.declarations.IrEnumEntry -import org.jetbrains.kotlin.ir.declarations.IrFile -import org.jetbrains.kotlin.ir.declarations.IrFunction -import org.jetbrains.kotlin.ir.declarations.IrProperty +import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.* import org.jetbrains.kotlin.ir.visitors.IrElementVisitor import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid @@ -71,6 +68,14 @@ class DumpIrTreeVisitor(out: Appendable): IrElementVisitor { } } + override fun visitClass(declaration: IrClass, data: String) { + declaration.dumpLabeledElementWith(data) { + declaration.newInstanceReceiver?.accept(this, "\$new") + declaration.typeParameters.dumpElements() + declaration.declarations.dumpElements() + } + } + override fun visitFunction(declaration: IrFunction, data: String) { declaration.dumpLabeledElementWith(data) { declaration.typeParameters.dumpElements() @@ -81,6 +86,15 @@ class DumpIrTreeVisitor(out: Appendable): IrElementVisitor { } } + override fun visitConstructor(declaration: IrConstructor, data: String) { + declaration.dumpLabeledElementWith(data) { + declaration.typeParameters.dumpElements() + declaration.dispatchReceiverParameter?.accept(this, "\$outer") + declaration.valueParameters.dumpElements() + declaration.body?.accept(this, "") + } + } + override fun visitProperty(declaration: IrProperty, data: String) { declaration.dumpLabeledElementWith(data) { declaration.typeParameters.dumpElements() diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/RenderIrElement.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/RenderIrElement.kt index 8005f7369de..9fce080daea 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/RenderIrElement.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/RenderIrElement.kt @@ -40,6 +40,9 @@ class RenderIrElementVisitor : IrElementVisitor { override fun visitModuleFragment(declaration: IrModuleFragment, data: Nothing?): String = "MODULE_FRAGMENT ${declaration.descriptor.ref()}" + override fun visitExternalPackageFragment(declaration: IrExternalPackageFragment, data: Nothing?): String = + "EXTERNAL_PACKAGE_FRAGMENT ${declaration.packageFragmentDescriptor.fqName}" + override fun visitFile(declaration: IrFile, data: Nothing?): String = "FILE ${declaration.name}" @@ -170,8 +173,30 @@ class RenderIrElementVisitor : IrElementVisitor { override fun visitThrow(expression: IrThrow, data: Nothing?): String = "THROW type=${expression.type.render()}" - override fun visitCallableReference(expression: IrCallableReference, data: Nothing?): String = - "CALLABLE_REFERENCE '${expression.descriptor.ref()}' type=${expression.type.render()} origin=${expression.origin}" + override fun visitFunctionReference(expression: IrFunctionReference, data: Nothing?): String = + "FUNCTION_REFERENCE '${expression.descriptor.ref()}' type=${expression.type.render()} origin=${expression.origin}" + + override fun visitPropertyReference(expression: IrPropertyReference, data: Nothing?): String = + buildString { + append("PROPERTY_REFERENCE ") + append("'${expression.descriptor.ref()}' ") + appendNullableAttribute("field=", expression.field) { "'${it.descriptor.ref()}'" } + appendNullableAttribute("getter=", expression.getter) { "'${it.descriptor.ref()}'" } + appendNullableAttribute("setter=", expression.setter) { "'${it.descriptor.ref()}'" } + append("type=${expression.type.render()} ") + append("origin=${expression.origin}") + } + + private inline fun StringBuilder.appendNullableAttribute(prefix: String, value: T?, toString: (T) -> String) { + append(prefix) + if (value != null) { + append(toString(value)) + } + else { + append("null") + } + append(" ") + } override fun visitClassReference(expression: IrClassReference, data: Nothing?): String = "CLASS_REFERENCE '${expression.descriptor.ref()}' type=${expression.type.render()}" diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementTransformer.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementTransformer.kt index 6ed8842252d..640d6414dd0 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementTransformer.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementTransformer.kt @@ -23,16 +23,19 @@ import org.jetbrains.kotlin.ir.expressions.* interface IrElementTransformer : IrElementVisitor { override fun visitElement(element: IrElement, data: D): IrElement = - element.apply { transformChildren(this@IrElementTransformer, data) } + element.also { it.transformChildren(this, data) } override fun visitModuleFragment(declaration: IrModuleFragment, data: D): IrModuleFragment = - declaration.apply { transformChildren(this@IrElementTransformer, data) } + declaration.also { it.transformChildren(this, data) } override fun visitFile(declaration: IrFile, data: D): IrFile = - declaration.apply { transformChildren(this@IrElementTransformer, data) } + declaration.also { it.transformChildren(this, data) } + + override fun visitExternalPackageFragment(declaration: IrExternalPackageFragment, data: D): IrExternalPackageFragment = + declaration.also { it.transformChildren(this, data) } override fun visitDeclaration(declaration: IrDeclaration, data: D): IrStatement = - declaration.apply { transformChildren(this@IrElementTransformer, data) } + declaration.also { it.transformChildren(this, data) } override fun visitClass(declaration: IrClass, data: D) = visitDeclaration(declaration, data) override fun visitTypeAlias(declaration: IrTypeAlias, data: D) = visitDeclaration(declaration, data) @@ -49,20 +52,20 @@ interface IrElementTransformer : IrElementVisitor { override fun visitValueParameter(declaration: IrValueParameter, data: D) = visitDeclaration(declaration, data) override fun visitBody(body: IrBody, data: D): IrBody = - body.apply { transformChildren(this@IrElementTransformer, data) } + body.also { it.transformChildren(this, data) } override fun visitExpressionBody(body: IrExpressionBody, data: D) = visitBody(body, data) override fun visitBlockBody(body: IrBlockBody, data: D) = visitBody(body, data) override fun visitSyntheticBody(body: IrSyntheticBody, data: D) = visitBody(body, data) override fun visitExpression(expression: IrExpression, data: D): IrExpression = - expression.apply { transformChildren(this@IrElementTransformer, data) } + expression.also { it.transformChildren(this, data) } override fun visitConst(expression: IrConst, data: D) = visitExpression(expression, data) override fun visitVararg(expression: IrVararg, data: D) = visitExpression(expression, data) override fun visitSpreadElement(spread: IrSpreadElement, data: D): IrSpreadElement = - spread.apply { transformChildren(this@IrElementTransformer, data) } + spread.also { it.transformChildren(this, data) } override fun visitContainerExpression(expression: IrContainerExpression, data: D) = visitExpression(expression, data) override fun visitBlock(expression: IrBlock, data: D) = visitContainerExpression(expression, data) @@ -79,13 +82,17 @@ interface IrElementTransformer : IrElementVisitor { override fun visitFieldAccess(expression: IrFieldAccessExpression, data: D) = visitDeclarationReference(expression, data) override fun visitGetField(expression: IrGetField, data: D) = visitFieldAccess(expression, data) override fun visitSetField(expression: IrSetField, data: D) = visitFieldAccess(expression, data) - override fun visitMemberAccess(expression: IrMemberAccessExpression, data: D): IrElement = visitDeclarationReference(expression, data) - override fun visitCall(expression: IrCall, data: D) = visitMemberAccess(expression, data) - override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall, data: D) = visitMemberAccess(expression, data) - override fun visitEnumConstructorCall(expression: IrEnumConstructorCall, data: D) = visitMemberAccess(expression, data) + override fun visitMemberAccess(expression: IrMemberAccessExpression, data: D): IrElement = visitExpression(expression, data) + override fun visitFunctionAccess(expression: IrFunctionAccessExpression, data: D): IrElement = visitMemberAccess(expression, data) + override fun visitCall(expression: IrCall, data: D) = visitFunctionAccess(expression, data) + override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall, data: D) = visitFunctionAccess(expression, data) + override fun visitEnumConstructorCall(expression: IrEnumConstructorCall, data: D) = visitFunctionAccess(expression, data) override fun visitGetClass(expression: IrGetClass, data: D) = visitExpression(expression, data) override fun visitCallableReference(expression: IrCallableReference, data: D) = visitMemberAccess(expression, data) + override fun visitFunctionReference(expression: IrFunctionReference, data: D) = visitCallableReference(expression, data) + override fun visitPropertyReference(expression: IrPropertyReference, data: D) = visitCallableReference(expression, data) + override fun visitClassReference(expression: IrClassReference, data: D) = visitDeclarationReference(expression, data) override fun visitInstanceInitializerCall(expression: IrInstanceInitializerCall, data: D) = visitExpression(expression, data) @@ -95,15 +102,15 @@ interface IrElementTransformer : IrElementVisitor { override fun visitWhen(expression: IrWhen, data: D) = visitExpression(expression, data) override fun visitBranch(branch: IrBranch, data: D): IrBranch = - branch.apply { - condition = condition.transform(this@IrElementTransformer, data) - result = result.transform(this@IrElementTransformer, data) + branch.also { + it.condition = it.condition.transform(this, data) + it.result = it.result.transform(this, data) } override fun visitElseBranch(branch: IrElseBranch, data: D): IrElseBranch = - branch.apply { - condition = condition.transform(this@IrElementTransformer, data) - result = result.transform(this@IrElementTransformer, data) + branch.also { + it.condition = it.condition.transform(this, data) + it.result = it.result.transform(this, data) } override fun visitLoop(loop: IrLoop, data: D) = visitExpression(loop, data) @@ -112,7 +119,7 @@ interface IrElementTransformer : IrElementVisitor { override fun visitTry(aTry: IrTry, data: D) = visitExpression(aTry, data) override fun visitCatch(aCatch: IrCatch, data: D): IrCatch = - aCatch.apply { transformChildren(this@IrElementTransformer, data) } + aCatch.also { it.transformChildren(this, data) } override fun visitBreakContinue(jump: IrBreakContinue, data: D) = visitExpression(jump, data) override fun visitBreak(jump: IrBreak, data: D) = visitBreakContinue(jump, data) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementTransformerVoid.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementTransformerVoid.kt index c941b7d1bee..3143a433e5d 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementTransformerVoid.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementTransformerVoid.kt @@ -22,16 +22,25 @@ import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.expressions.* abstract class IrElementTransformerVoid : IrElementTransformer { - open fun visitElement(element: IrElement): IrElement = element.apply { transformChildrenVoid(this@IrElementTransformerVoid) } + private fun T.transformChildren() = apply { transformChildrenVoid(this@IrElementTransformerVoid) } + + open fun visitElement(element: IrElement): IrElement = element.transformChildren() override final fun visitElement(element: IrElement, data: Nothing?): IrElement = visitElement(element) - open fun visitModuleFragment(declaration: IrModuleFragment): IrModuleFragment = declaration.apply { transformChildrenVoid(this@IrElementTransformerVoid) } + open fun visitModuleFragment(declaration: IrModuleFragment): IrModuleFragment = declaration.transformChildren() override final fun visitModuleFragment(declaration: IrModuleFragment, data: Nothing?): IrModuleFragment = visitModuleFragment(declaration) - open fun visitFile(declaration: IrFile): IrFile = declaration.apply { transformChildrenVoid(this@IrElementTransformerVoid) } + open fun visitPackageFragment(declaration: IrPackageFragment): IrPackageFragment = declaration.transformChildren() + override fun visitPackageFragment(declaration: IrPackageFragment, data: Nothing?): IrElement = visitPackageFragment(declaration) + + open fun visitFile(declaration: IrFile): IrFile = visitPackageFragment(declaration) as IrFile override final fun visitFile(declaration: IrFile, data: Nothing?): IrFile = visitFile(declaration) - open fun visitDeclaration(declaration: IrDeclaration): IrStatement = declaration.apply { transformChildrenVoid(this@IrElementTransformerVoid) } + open fun visitExternalPackageFragment(declaration: IrExternalPackageFragment) = visitPackageFragment(declaration) as IrExternalPackageFragment + override fun visitExternalPackageFragment(declaration: IrExternalPackageFragment, data: Nothing?): IrExternalPackageFragment = + visitExternalPackageFragment(declaration) + + open fun visitDeclaration(declaration: IrDeclaration): IrStatement = declaration.transformChildren() override final fun visitDeclaration(declaration: IrDeclaration, data: Nothing?): IrStatement = visitDeclaration(declaration) open fun visitClass(declaration: IrClass) = visitDeclaration(declaration) @@ -73,8 +82,7 @@ abstract class IrElementTransformerVoid : IrElementTransformer { open fun visitVariable(declaration: IrVariable) = visitDeclaration(declaration) override final fun visitVariable(declaration: IrVariable, data: Nothing?) = visitVariable(declaration) - open fun visitBody(body: IrBody): IrBody = - body.apply { transformChildrenVoid(this@IrElementTransformerVoid) } + open fun visitBody(body: IrBody): IrBody = body.transformChildren() override final fun visitBody(body: IrBody, data: Nothing?): IrBody = visitBody(body) open fun visitExpressionBody(body: IrExpressionBody) = visitBody(body) @@ -86,7 +94,7 @@ abstract class IrElementTransformerVoid : IrElementTransformer { open fun visitSyntheticBody(body: IrSyntheticBody) = visitBody(body) override final fun visitSyntheticBody(body: IrSyntheticBody, data: Nothing?) = visitSyntheticBody(body) - open fun visitExpression(expression: IrExpression): IrExpression = expression.apply { transformChildrenVoid(this@IrElementTransformerVoid) } + open fun visitExpression(expression: IrExpression): IrExpression = expression.transformChildren() override final fun visitExpression(expression: IrExpression, data: Nothing?): IrExpression = visitExpression(expression) open fun visitConst(expression: IrConst) = visitExpression(expression) @@ -95,7 +103,7 @@ abstract class IrElementTransformerVoid : IrElementTransformer { open fun visitVararg(expression: IrVararg) = visitExpression(expression) override final fun visitVararg(expression: IrVararg, data: Nothing?) = visitVararg(expression) - open fun visitSpreadElement(spread: IrSpreadElement) = spread.apply { transformChildrenVoid(this@IrElementTransformerVoid) } + open fun visitSpreadElement(spread: IrSpreadElement) = spread.transformChildren() override final fun visitSpreadElement(spread: IrSpreadElement, data: Nothing?): IrSpreadElement = visitSpreadElement(spread) open fun visitContainerExpression(expression: IrContainerExpression) = visitExpression(expression) @@ -140,9 +148,12 @@ abstract class IrElementTransformerVoid : IrElementTransformer { open fun visitSetField(expression: IrSetField) = visitFieldAccess(expression) override final fun visitSetField(expression: IrSetField, data: Nothing?) = visitSetField(expression) - open fun visitMemberAccess(expression: IrMemberAccessExpression) = visitDeclarationReference(expression) + open fun visitMemberAccess(expression: IrMemberAccessExpression) = visitExpression(expression) override final fun visitMemberAccess(expression: IrMemberAccessExpression, data: Nothing?) = visitMemberAccess(expression) + open fun visitFunctionAccess(expression: IrFunctionAccessExpression) = visitMemberAccess(expression) + override fun visitFunctionAccess(expression: IrFunctionAccessExpression, data: Nothing?) = visitFunctionAccess(expression) + open fun visitCall(expression: IrCall) = visitMemberAccess(expression) override final fun visitCall(expression: IrCall, data: Nothing?) = visitCall(expression) @@ -158,6 +169,12 @@ abstract class IrElementTransformerVoid : IrElementTransformer { open fun visitCallableReference(expression: IrCallableReference) = visitMemberAccess(expression) override final fun visitCallableReference(expression: IrCallableReference, data: Nothing?) = visitCallableReference(expression) + open fun visitFunctionReference(expression: IrFunctionReference) = visitCallableReference(expression) + override final fun visitFunctionReference(expression: IrFunctionReference, data: Nothing?): IrElement = visitFunctionReference(expression) + + open fun visitPropertyReference(expression: IrPropertyReference) = visitCallableReference(expression) + override final fun visitPropertyReference(expression: IrPropertyReference, data: Nothing?): IrElement = visitPropertyReference(expression) + open fun visitClassReference(expression: IrClassReference) = visitDeclarationReference(expression) override final fun visitClassReference(expression: IrClassReference, data: Nothing?) = visitClassReference(expression) @@ -170,10 +187,10 @@ abstract class IrElementTransformerVoid : IrElementTransformer { open fun visitWhen(expression: IrWhen) = visitExpression(expression) override final fun visitWhen(expression: IrWhen, data: Nothing?) = visitWhen(expression) - open fun visitBranch(branch: IrBranch) = branch.apply { transformChildrenVoid(this@IrElementTransformerVoid) } + open fun visitBranch(branch: IrBranch) = branch.transformChildren() override final fun visitBranch(branch: IrBranch, data: Nothing?): IrBranch = visitBranch(branch) - open fun visitElseBranch(branch: IrElseBranch) = branch.apply { transformChildrenVoid(this@IrElementTransformerVoid) } + open fun visitElseBranch(branch: IrElseBranch) = branch.transformChildren() override final fun visitElseBranch(branch: IrElseBranch, data: Nothing?): IrElseBranch = visitElseBranch(branch) open fun visitLoop(loop: IrLoop) = visitExpression(loop) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementVisitor.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementVisitor.kt index d094e5e9589..b6c86563b48 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementVisitor.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementVisitor.kt @@ -23,7 +23,9 @@ import org.jetbrains.kotlin.ir.expressions.* interface IrElementVisitor { fun visitElement(element: IrElement, data: D): R fun visitModuleFragment(declaration: IrModuleFragment, data: D) = visitElement(declaration, data) - fun visitFile(declaration: IrFile, data: D) = visitElement(declaration, data) + fun visitPackageFragment(declaration: IrPackageFragment, data: D) = visitElement(declaration, data) + fun visitFile(declaration: IrFile, data: D) = visitPackageFragment(declaration, data) + fun visitExternalPackageFragment(declaration: IrExternalPackageFragment, data: D) = visitPackageFragment(declaration, data) fun visitDeclaration(declaration: IrDeclaration, data: D) = visitElement(declaration, data) fun visitClass(declaration: IrClass, data: D) = visitDeclaration(declaration, data) @@ -65,13 +67,18 @@ interface IrElementVisitor { fun visitFieldAccess(expression: IrFieldAccessExpression, data: D) = visitDeclarationReference(expression, data) fun visitGetField(expression: IrGetField, data: D) = visitFieldAccess(expression, data) fun visitSetField(expression: IrSetField, data: D) = visitFieldAccess(expression, data) - fun visitMemberAccess(expression: IrMemberAccessExpression, data: D) = visitDeclarationReference(expression, data) - fun visitCall(expression: IrCall, data: D) = visitMemberAccess(expression, data) - fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall, data: D) = visitMemberAccess(expression, data) - fun visitEnumConstructorCall(expression: IrEnumConstructorCall, data: D) = visitMemberAccess(expression, data) + + fun visitMemberAccess(expression: IrMemberAccessExpression, data: D) = visitExpression(expression, data) + fun visitFunctionAccess(expression: IrFunctionAccessExpression, data: D) = visitMemberAccess(expression, data) + fun visitCall(expression: IrCall, data: D) = visitFunctionAccess(expression, data) + fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall, data: D) = visitFunctionAccess(expression, data) + fun visitEnumConstructorCall(expression: IrEnumConstructorCall, data: D) = visitFunctionAccess(expression, data) fun visitGetClass(expression: IrGetClass, data: D) = visitExpression(expression, data) fun visitCallableReference(expression: IrCallableReference, data: D) = visitMemberAccess(expression, data) + fun visitFunctionReference(expression: IrFunctionReference, data: D) = visitCallableReference(expression, data) + fun visitPropertyReference(expression: IrPropertyReference, data: D) = visitCallableReference(expression, data) + fun visitClassReference(expression: IrClassReference, data: D) = visitDeclarationReference(expression, data) fun visitInstanceInitializerCall(expression: IrInstanceInitializerCall, data: D) = visitExpression(expression, data) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementVisitorVoid.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementVisitorVoid.kt index 2e660586ffc..f225d98b462 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementVisitorVoid.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/visitors/IrElementVisitorVoid.kt @@ -26,8 +26,14 @@ interface IrElementVisitorVoid : IrElementVisitor { fun visitModuleFragment(declaration: IrModuleFragment) = visitElement(declaration) override fun visitModuleFragment(declaration: IrModuleFragment, data: Nothing?) = visitModuleFragment(declaration) - - fun visitFile(declaration: IrFile) = visitElement(declaration) + + fun visitPackageFragment(declaration: IrPackageFragment) = visitElement(declaration) + override fun visitPackageFragment(declaration: IrPackageFragment, data: Nothing?) = visitPackageFragment(declaration) + + fun visitExternalPackageFragment(declaration: IrExternalPackageFragment) = visitPackageFragment(declaration) + override fun visitExternalPackageFragment(declaration: IrExternalPackageFragment, data: Nothing?) = visitExternalPackageFragment(declaration) + + fun visitFile(declaration: IrFile) = visitPackageFragment(declaration) override fun visitFile(declaration: IrFile, data: Nothing?) = visitFile(declaration) fun visitDeclaration(declaration: IrDeclaration) = visitElement(declaration) @@ -138,16 +144,19 @@ interface IrElementVisitorVoid : IrElementVisitor { fun visitSetField(expression: IrSetField) = visitFieldAccess(expression) override fun visitSetField(expression: IrSetField, data: Nothing?) = visitSetField(expression) - fun visitMemberAccess(expression: IrMemberAccessExpression) = visitDeclarationReference(expression) + fun visitMemberAccess(expression: IrMemberAccessExpression) = visitExpression(expression) override fun visitMemberAccess(expression: IrMemberAccessExpression, data: Nothing?) = visitMemberAccess(expression) - fun visitCall(expression: IrCall) = visitMemberAccess(expression) + fun visitFunctionAccess(expression: IrFunctionAccessExpression) = visitMemberAccess(expression) + override fun visitFunctionAccess(expression: IrFunctionAccessExpression, data: Nothing?) = visitFunctionAccess(expression) + + fun visitCall(expression: IrCall) = visitFunctionAccess(expression) override fun visitCall(expression: IrCall, data: Nothing?) = visitCall(expression) - fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall) = visitMemberAccess(expression) + fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall) = visitFunctionAccess(expression) override fun visitDelegatingConstructorCall(expression: IrDelegatingConstructorCall, data: Nothing?) = visitDelegatingConstructorCall(expression) - fun visitEnumConstructorCall(expression: IrEnumConstructorCall) = visitMemberAccess(expression) + fun visitEnumConstructorCall(expression: IrEnumConstructorCall) = visitFunctionAccess(expression) override fun visitEnumConstructorCall(expression: IrEnumConstructorCall, data: Nothing?) = visitEnumConstructorCall(expression) fun visitGetClass(expression: IrGetClass) = visitExpression(expression) @@ -156,6 +165,12 @@ interface IrElementVisitorVoid : IrElementVisitor { fun visitCallableReference(expression: IrCallableReference) = visitMemberAccess(expression) override fun visitCallableReference(expression: IrCallableReference, data: Nothing?) = visitCallableReference(expression) + fun visitFunctionReference(expression: IrFunctionReference) = visitCallableReference(expression) + override fun visitFunctionReference(expression: IrFunctionReference, data: Nothing?) = visitFunctionReference(expression) + + fun visitPropertyReference(expression: IrPropertyReference) = visitCallableReference(expression) + override fun visitPropertyReference(expression: IrPropertyReference, data: Nothing?) = visitPropertyReference(expression) + fun visitClassReference(expression: IrClassReference) = visitDeclarationReference(expression) override fun visitClassReference(expression: IrClassReference, data: Nothing?) = visitClassReference(expression) diff --git a/compiler/testData/ir/irText/classes/argumentReorderingInDelegatingConstructorCall.txt b/compiler/testData/ir/irText/classes/argumentReorderingInDelegatingConstructorCall.txt index e72ed1b82c8..016ddf56c1b 100644 --- a/compiler/testData/ir/irText/classes/argumentReorderingInDelegatingConstructorCall.txt +++ b/compiler/testData/ir/irText/classes/argumentReorderingInDelegatingConstructorCall.txt @@ -1,5 +1,6 @@ FILE /argumentReorderingInDelegatingConstructorCall.kt CLASS CLASS Base + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Base(x: kotlin.Int, y: kotlin.Int) VALUE_PARAMETER value-parameter x: kotlin.Int VALUE_PARAMETER value-parameter y: kotlin.Int @@ -30,6 +31,7 @@ FILE /argumentReorderingInDelegatingConstructorCall.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Test1 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test1(xx: kotlin.Int, yy: kotlin.Int) VALUE_PARAMETER value-parameter xx: kotlin.Int VALUE_PARAMETER value-parameter yy: kotlin.Int @@ -51,6 +53,7 @@ FILE /argumentReorderingInDelegatingConstructorCall.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Test2 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test2(xx: kotlin.Int, yy: kotlin.Int) VALUE_PARAMETER value-parameter xx: kotlin.Int VALUE_PARAMETER value-parameter yy: kotlin.Int diff --git a/compiler/testData/ir/irText/classes/classMembers.txt b/compiler/testData/ir/irText/classes/classMembers.txt index f371dc57f37..f356dab7655 100644 --- a/compiler/testData/ir/irText/classes/classMembers.txt +++ b/compiler/testData/ir/irText/classes/classMembers.txt @@ -1,5 +1,6 @@ FILE /classMembers.kt CLASS CLASS C + $new: VALUE_PARAMETER CONSTRUCTOR public constructor C(x: kotlin.Int, y: kotlin.Int, z: kotlin.Int = ...) VALUE_PARAMETER value-parameter x: kotlin.Int VALUE_PARAMETER value-parameter y: kotlin.Int @@ -84,6 +85,7 @@ FILE /classMembers.kt CALL 'println(Any?): Unit' type=kotlin.Unit origin=null message: CONST String type=kotlin.String value='2' CLASS CLASS NestedClass + $new: VALUE_PARAMETER CONSTRUCTOR public constructor NestedClass() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -115,6 +117,7 @@ FILE /classMembers.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS OBJECT companion object of C + $new: VALUE_PARAMETER CONSTRUCTOR private constructor Companion() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/classes/classes.txt b/compiler/testData/ir/irText/classes/classes.txt index 2ada50eb241..4deebbc2d62 100644 --- a/compiler/testData/ir/irText/classes/classes.txt +++ b/compiler/testData/ir/irText/classes/classes.txt @@ -1,5 +1,6 @@ FILE /classes.kt CLASS CLASS TestClass + $new: VALUE_PARAMETER CONSTRUCTOR public constructor TestClass() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -12,6 +13,7 @@ FILE /classes.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS OBJECT TestObject + $new: VALUE_PARAMETER CONSTRUCTOR private constructor TestObject() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -20,10 +22,12 @@ FILE /classes.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS ANNOTATION_CLASS TestAnnotationClass + $new: VALUE_PARAMETER FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS ENUM_CLASS TestEnumClass + $new: VALUE_PARAMETER CONSTRUCTOR private constructor TestEnumClass() BLOCK_BODY ENUM_CONSTRUCTOR_CALL 'constructor Enum(String, Int)' diff --git a/compiler/testData/ir/irText/classes/companionObject.txt b/compiler/testData/ir/irText/classes/companionObject.txt index 97513a1bec4..9462ac0ed09 100644 --- a/compiler/testData/ir/irText/classes/companionObject.txt +++ b/compiler/testData/ir/irText/classes/companionObject.txt @@ -1,10 +1,12 @@ FILE /companionObject.kt CLASS CLASS Test1 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test1() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='Test1' CLASS OBJECT companion object of Test1 + $new: VALUE_PARAMETER CONSTRUCTOR private constructor Companion() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -16,11 +18,13 @@ FILE /companionObject.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Test2 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test2() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='Test2' CLASS OBJECT companion object of Test2Named + $new: VALUE_PARAMETER CONSTRUCTOR private constructor Named() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/classes/dataClasses.txt b/compiler/testData/ir/irText/classes/dataClasses.txt index 33bd609c46f..ef2406f1de5 100644 --- a/compiler/testData/ir/irText/classes/dataClasses.txt +++ b/compiler/testData/ir/irText/classes/dataClasses.txt @@ -1,5 +1,6 @@ FILE /dataClasses.kt CLASS CLASS Test1 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test1(x: kotlin.Int, y: kotlin.String, z: kotlin.Any) VALUE_PARAMETER value-parameter x: kotlin.Int VALUE_PARAMETER value-parameter y: kotlin.String @@ -173,6 +174,7 @@ FILE /dataClasses.kt RETURN type=kotlin.Nothing from='equals(Any?): Boolean' CONST Boolean type=kotlin.Boolean value='true' CLASS CLASS Test2 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test2(x: kotlin.Any?) VALUE_PARAMETER value-parameter x: kotlin.Any? BLOCK_BODY diff --git a/compiler/testData/ir/irText/classes/dataClassesGeneric.txt b/compiler/testData/ir/irText/classes/dataClassesGeneric.txt index 38ae9c9b909..90f84adc878 100644 --- a/compiler/testData/ir/irText/classes/dataClassesGeneric.txt +++ b/compiler/testData/ir/irText/classes/dataClassesGeneric.txt @@ -1,5 +1,6 @@ FILE /dataClassesGeneric.kt CLASS CLASS Test1 + $new: VALUE_PARAMETER TYPE_PARAMETER CONSTRUCTOR public constructor Test1(x: T) TYPE_PARAMETER diff --git a/compiler/testData/ir/irText/classes/delegatedImplementation.txt b/compiler/testData/ir/irText/classes/delegatedImplementation.txt index 88b9ea1f6ea..78c29148d39 100644 --- a/compiler/testData/ir/irText/classes/delegatedImplementation.txt +++ b/compiler/testData/ir/irText/classes/delegatedImplementation.txt @@ -13,6 +13,7 @@ FILE /delegatedImplementation.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS OBJECT BaseImpl + $new: VALUE_PARAMETER CONSTRUCTOR private constructor BaseImpl() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -90,6 +91,7 @@ FILE /delegatedImplementation.kt RETURN type=kotlin.Nothing from='otherImpl(String, Int): IOther' BLOCK type=otherImpl. origin=OBJECT_LITERAL CLASS CLASS + $new: VALUE_PARAMETER > CONSTRUCTOR public constructor () BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -145,6 +147,7 @@ FILE /delegatedImplementation.kt FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CALL 'constructor ()' type=otherImpl. origin=OBJECT_LITERAL CLASS CLASS Test1 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test1() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -181,6 +184,7 @@ FILE /delegatedImplementation.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Test2 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test2() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/classes/delegatedImplementationWithExplicitOverride.txt b/compiler/testData/ir/irText/classes/delegatedImplementationWithExplicitOverride.txt index 32a2ee3428d..18b2c4df381 100644 --- a/compiler/testData/ir/irText/classes/delegatedImplementationWithExplicitOverride.txt +++ b/compiler/testData/ir/irText/classes/delegatedImplementationWithExplicitOverride.txt @@ -8,6 +8,7 @@ FILE /delegatedImplementationWithExplicitOverride.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS OBJECT FooBarImpl + $new: VALUE_PARAMETER CONSTRUCTOR private constructor FooBarImpl() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -22,6 +23,7 @@ FILE /delegatedImplementationWithExplicitOverride.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS C + $new: VALUE_PARAMETER CONSTRUCTOR public constructor C() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/classes/delegatingConstructorCallToTypeAliasConstructor.txt b/compiler/testData/ir/irText/classes/delegatingConstructorCallToTypeAliasConstructor.txt index 7cb972b351c..d839c2acb47 100644 --- a/compiler/testData/ir/irText/classes/delegatingConstructorCallToTypeAliasConstructor.txt +++ b/compiler/testData/ir/irText/classes/delegatingConstructorCallToTypeAliasConstructor.txt @@ -1,5 +1,6 @@ FILE /delegatingConstructorCallToTypeAliasConstructor.kt CLASS CLASS Cell + $new: VALUE_PARAMETER TYPE_PARAMETER CONSTRUCTOR public constructor Cell(value: T) TYPE_PARAMETER @@ -23,6 +24,7 @@ FILE /delegatingConstructorCallToTypeAliasConstructor.kt TYPEALIAS typealias CT = Cell type=Cell TYPEALIAS typealias CStr = Cell type=Cell CLASS CLASS C1 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor C1() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Cell(String)' @@ -34,6 +36,7 @@ FILE /delegatingConstructorCallToTypeAliasConstructor.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS C2 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor C2() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Cell(String)' diff --git a/compiler/testData/ir/irText/classes/delegatingConstructorCallsInSecondaryConstructors.txt b/compiler/testData/ir/irText/classes/delegatingConstructorCallsInSecondaryConstructors.txt index d27b8665b45..12227880dc9 100644 --- a/compiler/testData/ir/irText/classes/delegatingConstructorCallsInSecondaryConstructors.txt +++ b/compiler/testData/ir/irText/classes/delegatingConstructorCallsInSecondaryConstructors.txt @@ -1,5 +1,6 @@ FILE /delegatingConstructorCallsInSecondaryConstructors.kt CLASS CLASS Base + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Base() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -8,6 +9,7 @@ FILE /delegatingConstructorCallsInSecondaryConstructors.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Test + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Base()' diff --git a/compiler/testData/ir/irText/classes/enum.txt b/compiler/testData/ir/irText/classes/enum.txt index 66af35d54c3..c2dc546e681 100644 --- a/compiler/testData/ir/irText/classes/enum.txt +++ b/compiler/testData/ir/irText/classes/enum.txt @@ -1,5 +1,6 @@ FILE /enum.kt CLASS ENUM_CLASS TestEnum1 + $new: VALUE_PARAMETER CONSTRUCTOR private constructor TestEnum1() BLOCK_BODY ENUM_CONSTRUCTOR_CALL 'constructor Enum(String, Int)' @@ -24,6 +25,7 @@ FILE /enum.kt FUN ENUM_CLASS_SPECIAL_MEMBER public final fun valueOf(value: kotlin.String): TestEnum1 SYNTHETIC_BODY kind=ENUM_VALUEOF CLASS ENUM_CLASS TestEnum2 + $new: VALUE_PARAMETER CONSTRUCTOR private constructor TestEnum2(x: kotlin.Int) VALUE_PARAMETER value-parameter x: kotlin.Int BLOCK_BODY @@ -64,6 +66,7 @@ FILE /enum.kt FUN ENUM_CLASS_SPECIAL_MEMBER public final fun valueOf(value: kotlin.String): TestEnum2 SYNTHETIC_BODY kind=ENUM_VALUEOF CLASS ENUM_CLASS TestEnum3 + $new: VALUE_PARAMETER CONSTRUCTOR private constructor TestEnum3() BLOCK_BODY ENUM_CONSTRUCTOR_CALL 'constructor Enum(String, Int)' @@ -71,6 +74,7 @@ FILE /enum.kt ENUM_ENTRY enum entry TEST init: ENUM_CONSTRUCTOR_CALL 'constructor TEST()' class: CLASS ENUM_ENTRY TEST + $new: VALUE_PARAMETER CONSTRUCTOR private constructor TEST() BLOCK_BODY ENUM_CONSTRUCTOR_CALL 'constructor TestEnum3()' @@ -109,6 +113,7 @@ FILE /enum.kt FUN ENUM_CLASS_SPECIAL_MEMBER public final fun valueOf(value: kotlin.String): TestEnum3 SYNTHETIC_BODY kind=ENUM_VALUEOF CLASS ENUM_CLASS TestEnum4 + $new: VALUE_PARAMETER CONSTRUCTOR private constructor TestEnum4(x: kotlin.Int) VALUE_PARAMETER value-parameter x: kotlin.Int BLOCK_BODY @@ -127,6 +132,7 @@ FILE /enum.kt ENUM_ENTRY enum entry TEST1 init: ENUM_CONSTRUCTOR_CALL 'constructor TEST1()' class: CLASS ENUM_ENTRY TEST1 + $new: VALUE_PARAMETER CONSTRUCTOR private constructor TEST1() BLOCK_BODY ENUM_CONSTRUCTOR_CALL 'constructor TestEnum4(Int)' @@ -153,6 +159,7 @@ FILE /enum.kt ENUM_ENTRY enum entry TEST2 init: ENUM_CONSTRUCTOR_CALL 'constructor TEST2()' class: CLASS ENUM_ENTRY TEST2 + $new: VALUE_PARAMETER CONSTRUCTOR private constructor TEST2() BLOCK_BODY ENUM_CONSTRUCTOR_CALL 'constructor TestEnum4(Int)' @@ -208,6 +215,7 @@ FILE /enum.kt FUN ENUM_CLASS_SPECIAL_MEMBER public final fun valueOf(value: kotlin.String): TestEnum4 SYNTHETIC_BODY kind=ENUM_VALUEOF CLASS ENUM_CLASS TestEnum5 + $new: VALUE_PARAMETER CONSTRUCTOR private constructor TestEnum5(x: kotlin.Int = ...) VALUE_PARAMETER value-parameter x: kotlin.Int = ... EXPRESSION_BODY diff --git a/compiler/testData/ir/irText/classes/enumWithSecondaryCtor.txt b/compiler/testData/ir/irText/classes/enumWithSecondaryCtor.txt index c5308259ff1..a0b055b6bd6 100644 --- a/compiler/testData/ir/irText/classes/enumWithSecondaryCtor.txt +++ b/compiler/testData/ir/irText/classes/enumWithSecondaryCtor.txt @@ -1,5 +1,6 @@ FILE /enumWithSecondaryCtor.kt CLASS ENUM_CLASS Test0 + $new: VALUE_PARAMETER CONSTRUCTOR private constructor Test0(x: kotlin.Int) VALUE_PARAMETER value-parameter x: kotlin.Int BLOCK_BODY @@ -37,6 +38,7 @@ FILE /enumWithSecondaryCtor.kt FUN ENUM_CLASS_SPECIAL_MEMBER public final fun valueOf(value: kotlin.String): Test0 SYNTHETIC_BODY kind=ENUM_VALUEOF CLASS ENUM_CLASS Test1 + $new: VALUE_PARAMETER CONSTRUCTOR private constructor Test1(x: kotlin.Int) VALUE_PARAMETER value-parameter x: kotlin.Int BLOCK_BODY @@ -77,6 +79,7 @@ FILE /enumWithSecondaryCtor.kt FUN ENUM_CLASS_SPECIAL_MEMBER public final fun valueOf(value: kotlin.String): Test1 SYNTHETIC_BODY kind=ENUM_VALUEOF CLASS ENUM_CLASS Test2 + $new: VALUE_PARAMETER CONSTRUCTOR private constructor Test2(x: kotlin.Int) VALUE_PARAMETER value-parameter x: kotlin.Int BLOCK_BODY @@ -95,6 +98,7 @@ FILE /enumWithSecondaryCtor.kt ENUM_ENTRY enum entry ZERO init: ENUM_CONSTRUCTOR_CALL 'constructor ZERO()' class: CLASS ENUM_ENTRY ZERO + $new: VALUE_PARAMETER CONSTRUCTOR private constructor ZERO() BLOCK_BODY ENUM_CONSTRUCTOR_CALL 'constructor Test2()' @@ -120,6 +124,7 @@ FILE /enumWithSecondaryCtor.kt ENUM_ENTRY enum entry ONE init: ENUM_CONSTRUCTOR_CALL 'constructor ONE()' class: CLASS ENUM_ENTRY ONE + $new: VALUE_PARAMETER CONSTRUCTOR private constructor ONE() BLOCK_BODY ENUM_CONSTRUCTOR_CALL 'constructor Test2(Int)' diff --git a/compiler/testData/ir/irText/classes/initBlock.txt b/compiler/testData/ir/irText/classes/initBlock.txt index 21183368499..3a8120521e9 100644 --- a/compiler/testData/ir/irText/classes/initBlock.txt +++ b/compiler/testData/ir/irText/classes/initBlock.txt @@ -1,5 +1,6 @@ FILE /initBlock.kt CLASS CLASS Test1 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test1() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -11,6 +12,7 @@ FILE /initBlock.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Test2 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test2(x: kotlin.Int) VALUE_PARAMETER value-parameter x: kotlin.Int BLOCK_BODY @@ -33,6 +35,7 @@ FILE /initBlock.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Test3 + $new: VALUE_PARAMETER ANONYMOUS_INITIALIZER Test3 BLOCK_BODY CALL 'println(): Unit' type=kotlin.Unit origin=null @@ -44,6 +47,7 @@ FILE /initBlock.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Test4 + $new: VALUE_PARAMETER ANONYMOUS_INITIALIZER Test4 BLOCK_BODY CALL 'println(Any?): Unit' type=kotlin.Unit origin=null @@ -60,6 +64,7 @@ FILE /initBlock.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Test5 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test5() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -69,8 +74,9 @@ FILE /initBlock.kt CALL 'println(Any?): Unit' type=kotlin.Unit origin=null message: CONST String type=kotlin.String value='1' CLASS CLASS TestInner + $new: VALUE_PARAMETER CONSTRUCTOR public constructor TestInner() - $this: VALUE_PARAMETER + $outer: VALUE_PARAMETER BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='TestInner' diff --git a/compiler/testData/ir/irText/classes/initVal.txt b/compiler/testData/ir/irText/classes/initVal.txt index a133d855bef..80be31d760f 100644 --- a/compiler/testData/ir/irText/classes/initVal.txt +++ b/compiler/testData/ir/irText/classes/initVal.txt @@ -1,5 +1,6 @@ FILE /initVal.kt CLASS CLASS TestInitValFromParameter + $new: VALUE_PARAMETER CONSTRUCTOR public constructor TestInitValFromParameter(x: kotlin.Int) VALUE_PARAMETER value-parameter x: kotlin.Int BLOCK_BODY @@ -19,6 +20,7 @@ FILE /initVal.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS TestInitValInClass + $new: VALUE_PARAMETER CONSTRUCTOR public constructor TestInitValInClass() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -37,6 +39,7 @@ FILE /initVal.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS TestInitValInInitBlock + $new: VALUE_PARAMETER CONSTRUCTOR public constructor TestInitValInInitBlock() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/classes/initVar.txt b/compiler/testData/ir/irText/classes/initVar.txt index 150c9bf3a6e..0fdaeb1c572 100644 --- a/compiler/testData/ir/irText/classes/initVar.txt +++ b/compiler/testData/ir/irText/classes/initVar.txt @@ -1,5 +1,6 @@ FILE /initVar.kt CLASS CLASS TestInitVarFromParameter + $new: VALUE_PARAMETER CONSTRUCTOR public constructor TestInitVarFromParameter(x: kotlin.Int) VALUE_PARAMETER value-parameter x: kotlin.Int BLOCK_BODY @@ -26,6 +27,7 @@ FILE /initVar.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS TestInitVarInClass + $new: VALUE_PARAMETER CONSTRUCTOR public constructor TestInitVarInClass() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -51,6 +53,7 @@ FILE /initVar.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS TestInitVarInInitBlock + $new: VALUE_PARAMETER CONSTRUCTOR public constructor TestInitVarInInitBlock() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -79,6 +82,7 @@ FILE /initVar.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS TestInitVarWithCustomSetter + $new: VALUE_PARAMETER CONSTRUCTOR public constructor TestInitVarWithCustomSetter() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -104,6 +108,7 @@ FILE /initVar.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS TestInitVarWithCustomSetterWithExplicitCtor + $new: VALUE_PARAMETER PROPERTY public final var x: kotlin.Int FIELD PROPERTY_BACKING_FIELD public final var x: kotlin.Int FUN DEFAULT_PROPERTY_ACCESSOR public final fun (): kotlin.Int @@ -132,6 +137,7 @@ FILE /initVar.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS TestInitVarWithCustomSetterInCtor + $new: VALUE_PARAMETER PROPERTY public final var x: kotlin.Int FIELD PROPERTY_BACKING_FIELD public final var x: kotlin.Int FUN DEFAULT_PROPERTY_ACCESSOR public final fun (): kotlin.Int diff --git a/compiler/testData/ir/irText/classes/innerClass.txt b/compiler/testData/ir/irText/classes/innerClass.txt index 2221cf59b85..505dbc2f004 100644 --- a/compiler/testData/ir/irText/classes/innerClass.txt +++ b/compiler/testData/ir/irText/classes/innerClass.txt @@ -1,12 +1,14 @@ FILE /innerClass.kt CLASS CLASS Outer + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Outer() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='Outer' CLASS CLASS TestInnerClass + $new: VALUE_PARAMETER CONSTRUCTOR public constructor TestInnerClass() - $this: VALUE_PARAMETER + $outer: VALUE_PARAMETER BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='TestInnerClass' @@ -14,8 +16,9 @@ FILE /innerClass.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS DerivedInnerClass + $new: VALUE_PARAMETER CONSTRUCTOR public constructor DerivedInnerClass() - $this: VALUE_PARAMETER + $outer: VALUE_PARAMETER BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor TestInnerClass()' $this: GET_VAR '' type=Outer origin=null diff --git a/compiler/testData/ir/irText/classes/innerClassWithDelegatingConstructor.txt b/compiler/testData/ir/irText/classes/innerClassWithDelegatingConstructor.txt index 0f083659940..e57cd753e02 100644 --- a/compiler/testData/ir/irText/classes/innerClassWithDelegatingConstructor.txt +++ b/compiler/testData/ir/irText/classes/innerClassWithDelegatingConstructor.txt @@ -1,12 +1,14 @@ FILE /innerClassWithDelegatingConstructor.kt CLASS CLASS Outer + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Outer() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='Outer' CLASS CLASS Inner + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Inner(x: kotlin.Int) - $this: VALUE_PARAMETER + $outer: VALUE_PARAMETER VALUE_PARAMETER value-parameter x: kotlin.Int BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -22,7 +24,7 @@ FILE /innerClassWithDelegatingConstructor.kt GET_FIELD 'x: Int' type=kotlin.Int origin=null receiver: GET_VAR '' type=Outer.Inner origin=null CONSTRUCTOR public constructor Inner() - $this: VALUE_PARAMETER + $outer: VALUE_PARAMETER BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Inner(Int)' $this: GET_VAR '' type=Outer origin=null diff --git a/compiler/testData/ir/irText/classes/localClasses.txt b/compiler/testData/ir/irText/classes/localClasses.txt index 1e7a579026b..00b4920a5f4 100644 --- a/compiler/testData/ir/irText/classes/localClasses.txt +++ b/compiler/testData/ir/irText/classes/localClasses.txt @@ -2,6 +2,7 @@ FILE /localClasses.kt FUN public fun outer(): kotlin.Unit BLOCK_BODY CLASS CLASS LocalClass + $new: VALUE_PARAMETER CONSTRUCTOR public constructor LocalClass() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/classes/objectLiteralExpressions.txt b/compiler/testData/ir/irText/classes/objectLiteralExpressions.txt index fcd6f94af5d..35c707f865d 100644 --- a/compiler/testData/ir/irText/classes/objectLiteralExpressions.txt +++ b/compiler/testData/ir/irText/classes/objectLiteralExpressions.txt @@ -10,6 +10,7 @@ FILE /objectLiteralExpressions.kt EXPRESSION_BODY BLOCK type=test1. origin=OBJECT_LITERAL CLASS CLASS + $new: VALUE_PARAMETER > CONSTRUCTOR public constructor () BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -27,6 +28,7 @@ FILE /objectLiteralExpressions.kt EXPRESSION_BODY BLOCK type=test2. origin=OBJECT_LITERAL CLASS CLASS + $new: VALUE_PARAMETER > CONSTRUCTOR public constructor () BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -45,13 +47,15 @@ FILE /objectLiteralExpressions.kt RETURN type=kotlin.Nothing from='(): IFoo' GET_FIELD 'test2: IFoo' type=IFoo origin=null CLASS CLASS Outer + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Outer() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='Outer' CLASS CLASS Inner + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Inner() - $this: VALUE_PARAMETER + $outer: VALUE_PARAMETER BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='Inner' @@ -65,6 +69,7 @@ FILE /objectLiteralExpressions.kt RETURN type=kotlin.Nothing from='test3(): Outer.Inner' BLOCK type=Outer.test3. origin=OBJECT_LITERAL CLASS CLASS + $new: VALUE_PARAMETER > CONSTRUCTOR public constructor () BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Inner()' @@ -88,6 +93,7 @@ FILE /objectLiteralExpressions.kt RETURN type=kotlin.Nothing from='test4() on Outer: Outer.Inner' BLOCK type=test4. origin=OBJECT_LITERAL CLASS CLASS + $new: VALUE_PARAMETER > CONSTRUCTOR public constructor () BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Inner()' diff --git a/compiler/testData/ir/irText/classes/objectWithInitializers.txt b/compiler/testData/ir/irText/classes/objectWithInitializers.txt index bdada3428b0..d7f304a151f 100644 --- a/compiler/testData/ir/irText/classes/objectWithInitializers.txt +++ b/compiler/testData/ir/irText/classes/objectWithInitializers.txt @@ -1,5 +1,6 @@ FILE /objectWithInitializers.kt CLASS CLASS Base + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Base() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -8,6 +9,7 @@ FILE /objectWithInitializers.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS OBJECT Test + $new: VALUE_PARAMETER CONSTRUCTOR private constructor Test() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Base()' diff --git a/compiler/testData/ir/irText/classes/outerClassAccess.txt b/compiler/testData/ir/irText/classes/outerClassAccess.txt index 7da2e390905..3b9947f7202 100644 --- a/compiler/testData/ir/irText/classes/outerClassAccess.txt +++ b/compiler/testData/ir/irText/classes/outerClassAccess.txt @@ -1,5 +1,6 @@ FILE /outerClassAccess.kt CLASS CLASS Outer + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Outer() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -8,8 +9,9 @@ FILE /outerClassAccess.kt $this: VALUE_PARAMETER BLOCK_BODY CLASS CLASS Inner + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Inner() - $this: VALUE_PARAMETER + $outer: VALUE_PARAMETER BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='Inner' @@ -19,8 +21,9 @@ FILE /outerClassAccess.kt CALL 'foo(): Unit' type=kotlin.Unit origin=null $this: GET_VAR '' type=Outer origin=null CLASS CLASS Inner2 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Inner2() - $this: VALUE_PARAMETER + $outer: VALUE_PARAMETER BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='Inner2' diff --git a/compiler/testData/ir/irText/classes/primaryConstructorWithSuperConstructorCall.txt b/compiler/testData/ir/irText/classes/primaryConstructorWithSuperConstructorCall.txt index e23d387a430..e4e09735ebf 100644 --- a/compiler/testData/ir/irText/classes/primaryConstructorWithSuperConstructorCall.txt +++ b/compiler/testData/ir/irText/classes/primaryConstructorWithSuperConstructorCall.txt @@ -1,5 +1,6 @@ FILE /primaryConstructorWithSuperConstructorCall.kt CLASS CLASS Base + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Base() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -8,6 +9,7 @@ FILE /primaryConstructorWithSuperConstructorCall.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS TestImplicitPrimaryConstructor + $new: VALUE_PARAMETER CONSTRUCTOR public constructor TestImplicitPrimaryConstructor() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Base()' @@ -16,6 +18,7 @@ FILE /primaryConstructorWithSuperConstructorCall.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS TestExplicitPrimaryConstructor + $new: VALUE_PARAMETER CONSTRUCTOR public constructor TestExplicitPrimaryConstructor() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Base()' @@ -24,6 +27,7 @@ FILE /primaryConstructorWithSuperConstructorCall.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS TestWithDelegatingConstructor + $new: VALUE_PARAMETER CONSTRUCTOR public constructor TestWithDelegatingConstructor(x: kotlin.Int, y: kotlin.Int) VALUE_PARAMETER value-parameter x: kotlin.Int VALUE_PARAMETER value-parameter y: kotlin.Int diff --git a/compiler/testData/ir/irText/classes/qualifiedSuperCalls.txt b/compiler/testData/ir/irText/classes/qualifiedSuperCalls.txt index 58ab34f3794..1dd77ba700a 100644 --- a/compiler/testData/ir/irText/classes/qualifiedSuperCalls.txt +++ b/compiler/testData/ir/irText/classes/qualifiedSuperCalls.txt @@ -26,6 +26,7 @@ FILE /qualifiedSuperCalls.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS CBoth + $new: VALUE_PARAMETER CONSTRUCTOR public constructor CBoth() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/classes/sealedClasses.txt b/compiler/testData/ir/irText/classes/sealedClasses.txt index 71bb1c6aed7..a0a795e5327 100644 --- a/compiler/testData/ir/irText/classes/sealedClasses.txt +++ b/compiler/testData/ir/irText/classes/sealedClasses.txt @@ -1,10 +1,12 @@ FILE /sealedClasses.kt CLASS CLASS Expr + $new: VALUE_PARAMETER CONSTRUCTOR private constructor Expr() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='Expr' CLASS CLASS Const + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Const(number: kotlin.Double) VALUE_PARAMETER value-parameter number: kotlin.Double BLOCK_BODY @@ -24,6 +26,7 @@ FILE /sealedClasses.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Sum + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Sum(e1: Expr, e2: Expr) VALUE_PARAMETER value-parameter e1: Expr VALUE_PARAMETER value-parameter e2: Expr @@ -54,6 +57,7 @@ FILE /sealedClasses.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS OBJECT NotANumber + $new: VALUE_PARAMETER CONSTRUCTOR private constructor NotANumber() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Expr()' diff --git a/compiler/testData/ir/irText/classes/secondaryConstructorWithInitializersFromClassBody.txt b/compiler/testData/ir/irText/classes/secondaryConstructorWithInitializersFromClassBody.txt index a20dcfc4321..2e1707f44f5 100644 --- a/compiler/testData/ir/irText/classes/secondaryConstructorWithInitializersFromClassBody.txt +++ b/compiler/testData/ir/irText/classes/secondaryConstructorWithInitializersFromClassBody.txt @@ -1,5 +1,6 @@ FILE /secondaryConstructorWithInitializersFromClassBody.kt CLASS CLASS Base + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Base() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -8,6 +9,7 @@ FILE /secondaryConstructorWithInitializersFromClassBody.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS TestProperty + $new: VALUE_PARAMETER PROPERTY public final val x: kotlin.Int = 0 FIELD PROPERTY_BACKING_FIELD public final val x: kotlin.Int = 0 EXPRESSION_BODY @@ -26,6 +28,7 @@ FILE /secondaryConstructorWithInitializersFromClassBody.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS TestInitBlock + $new: VALUE_PARAMETER PROPERTY public final val x: kotlin.Int FIELD PROPERTY_BACKING_FIELD public final val x: kotlin.Int FUN DEFAULT_PROPERTY_ACCESSOR public final fun (): kotlin.Int diff --git a/compiler/testData/ir/irText/classes/secondaryConstructors.txt b/compiler/testData/ir/irText/classes/secondaryConstructors.txt index d64951a2d55..d83892a2ad6 100644 --- a/compiler/testData/ir/irText/classes/secondaryConstructors.txt +++ b/compiler/testData/ir/irText/classes/secondaryConstructors.txt @@ -1,5 +1,6 @@ FILE /secondaryConstructors.kt CLASS CLASS C + $new: VALUE_PARAMETER CONSTRUCTOR public constructor C() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor C(Int)' diff --git a/compiler/testData/ir/irText/classes/superCalls.txt b/compiler/testData/ir/irText/classes/superCalls.txt index 2252b9b9501..4b0d9c242bc 100644 --- a/compiler/testData/ir/irText/classes/superCalls.txt +++ b/compiler/testData/ir/irText/classes/superCalls.txt @@ -1,5 +1,6 @@ FILE /superCalls.kt CLASS CLASS Base + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Base() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -21,6 +22,7 @@ FILE /superCalls.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Derived + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Derived() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Base()' diff --git a/compiler/testData/ir/irText/declarations/classLevelProperties.txt b/compiler/testData/ir/irText/declarations/classLevelProperties.txt index a62ea79f61e..a27fed22493 100644 --- a/compiler/testData/ir/irText/declarations/classLevelProperties.txt +++ b/compiler/testData/ir/irText/declarations/classLevelProperties.txt @@ -1,5 +1,6 @@ FILE /classLevelProperties.kt CLASS CLASS C + $new: VALUE_PARAMETER CONSTRUCTOR public constructor C() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -91,7 +92,7 @@ FILE /classLevelProperties.kt BLOCK_BODY RETURN type=kotlin.Nothing from='(): Int' CONST Int type=kotlin.Int value='42' - CALLABLE_REFERENCE '(): Int' type=() -> kotlin.Int origin=LAMBDA + FUNCTION_REFERENCE '(): Int' type=() -> kotlin.Int origin=LAMBDA FUN DELEGATED_PROPERTY_ACCESSOR public final fun (): kotlin.Int $this: VALUE_PARAMETER BLOCK_BODY @@ -101,7 +102,7 @@ FILE /classLevelProperties.kt $receiver: GET_FIELD '`test7$delegate`: Lazy' type=kotlin.Lazy origin=null receiver: GET_VAR '' type=C origin=null thisRef: GET_VAR '' type=C origin=null - property: CALLABLE_REFERENCE 'test7: Int' type=kotlin.reflect.KProperty1 origin=PROPERTY_REFERENCE_FOR_DELEGATE + property: PROPERTY_REFERENCE 'test7: Int' field=null getter='(): Int' setter=null type=kotlin.reflect.KProperty1 origin=PROPERTY_REFERENCE_FOR_DELEGATE PROPERTY public final var test8: kotlin.Int FIELD DELEGATE val `test8$delegate`: kotlin.collections.HashMap /* = java.util.HashMap */ EXPRESSION_BODY @@ -117,7 +118,7 @@ FILE /classLevelProperties.kt $receiver: GET_FIELD '`test8$delegate`: HashMap /* = HashMap */' type=kotlin.collections.HashMap /* = java.util.HashMap */ origin=null receiver: GET_VAR '' type=C origin=null thisRef: GET_VAR '' type=C origin=null - property: CALLABLE_REFERENCE 'test8: Int' type=kotlin.reflect.KMutableProperty1 origin=PROPERTY_REFERENCE_FOR_DELEGATE + property: PROPERTY_REFERENCE 'test8: Int' field=null getter='(): Int' setter='(Int): Unit' type=kotlin.reflect.KMutableProperty1 origin=PROPERTY_REFERENCE_FOR_DELEGATE FUN DELEGATED_PROPERTY_ACCESSOR public final fun (: kotlin.Int): kotlin.Unit $this: VALUE_PARAMETER VALUE_PARAMETER value-parameter : kotlin.Int @@ -128,7 +129,7 @@ FILE /classLevelProperties.kt $receiver: GET_FIELD '`test8$delegate`: HashMap /* = HashMap */' type=kotlin.collections.HashMap /* = java.util.HashMap */ origin=null receiver: GET_VAR '' type=C origin=null thisRef: GET_VAR '' type=C origin=null - property: CALLABLE_REFERENCE 'test8: Int' type=kotlin.reflect.KMutableProperty1 origin=PROPERTY_REFERENCE_FOR_DELEGATE + property: PROPERTY_REFERENCE 'test8: Int' field=null getter='(): Int' setter='(Int): Unit' type=kotlin.reflect.KMutableProperty1 origin=PROPERTY_REFERENCE_FOR_DELEGATE value: GET_VAR 'value-parameter : Int' type=kotlin.Int origin=null FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int diff --git a/compiler/testData/ir/irText/declarations/delegatedProperties.txt b/compiler/testData/ir/irText/declarations/delegatedProperties.txt index d3d3d487ff1..a45bbca9105 100644 --- a/compiler/testData/ir/irText/declarations/delegatedProperties.txt +++ b/compiler/testData/ir/irText/declarations/delegatedProperties.txt @@ -9,7 +9,7 @@ FILE /delegatedProperties.kt BLOCK_BODY RETURN type=kotlin.Nothing from='(): Int' CONST Int type=kotlin.Int value='42' - CALLABLE_REFERENCE '(): Int' type=() -> kotlin.Int origin=LAMBDA + FUNCTION_REFERENCE '(): Int' type=() -> kotlin.Int origin=LAMBDA FUN DELEGATED_PROPERTY_ACCESSOR public fun (): kotlin.Int BLOCK_BODY RETURN type=kotlin.Nothing from='(): Int' @@ -17,8 +17,9 @@ FILE /delegatedProperties.kt : Int $receiver: GET_FIELD '`test1$delegate`: Lazy' type=kotlin.Lazy origin=null thisRef: CONST Null type=kotlin.Nothing? value='null' - property: CALLABLE_REFERENCE 'test1: Int' type=kotlin.reflect.KProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE + property: PROPERTY_REFERENCE 'test1: Int' field=null getter='(): Int' setter=null type=kotlin.reflect.KProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE CLASS CLASS C + $new: VALUE_PARAMETER CONSTRUCTOR public constructor C(map: kotlin.collections.MutableMap) VALUE_PARAMETER value-parameter map: kotlin.collections.MutableMap BLOCK_BODY @@ -44,7 +45,7 @@ FILE /delegatedProperties.kt BLOCK_BODY RETURN type=kotlin.Nothing from='(): Int' CONST Int type=kotlin.Int value='42' - CALLABLE_REFERENCE '(): Int' type=() -> kotlin.Int origin=LAMBDA + FUNCTION_REFERENCE '(): Int' type=() -> kotlin.Int origin=LAMBDA FUN DELEGATED_PROPERTY_ACCESSOR public final fun (): kotlin.Int $this: VALUE_PARAMETER BLOCK_BODY @@ -54,7 +55,7 @@ FILE /delegatedProperties.kt $receiver: GET_FIELD '`test2$delegate`: Lazy' type=kotlin.Lazy origin=null receiver: GET_VAR '' type=C origin=null thisRef: GET_VAR '' type=C origin=null - property: CALLABLE_REFERENCE 'test2: Int' type=kotlin.reflect.KProperty1 origin=PROPERTY_REFERENCE_FOR_DELEGATE + property: PROPERTY_REFERENCE 'test2: Int' field=null getter='(): Int' setter=null type=kotlin.reflect.KProperty1 origin=PROPERTY_REFERENCE_FOR_DELEGATE PROPERTY public final var test3: kotlin.Any FIELD DELEGATE val `test3$delegate`: kotlin.collections.MutableMap EXPRESSION_BODY @@ -69,7 +70,7 @@ FILE /delegatedProperties.kt $receiver: GET_FIELD '`test3$delegate`: MutableMap' type=kotlin.collections.MutableMap origin=null receiver: GET_VAR '' type=C origin=null thisRef: GET_VAR '' type=C origin=null - property: CALLABLE_REFERENCE 'test3: Any' type=kotlin.reflect.KMutableProperty1 origin=PROPERTY_REFERENCE_FOR_DELEGATE + property: PROPERTY_REFERENCE 'test3: Any' field=null getter='(): Any' setter='(Any): Unit' type=kotlin.reflect.KMutableProperty1 origin=PROPERTY_REFERENCE_FOR_DELEGATE FUN DELEGATED_PROPERTY_ACCESSOR public final fun (: kotlin.Any): kotlin.Unit $this: VALUE_PARAMETER VALUE_PARAMETER value-parameter : kotlin.Any @@ -80,7 +81,7 @@ FILE /delegatedProperties.kt $receiver: GET_FIELD '`test3$delegate`: MutableMap' type=kotlin.collections.MutableMap origin=null receiver: GET_VAR '' type=C origin=null thisRef: GET_VAR '' type=C origin=null - property: CALLABLE_REFERENCE 'test3: Any' type=kotlin.reflect.KMutableProperty1 origin=PROPERTY_REFERENCE_FOR_DELEGATE + property: PROPERTY_REFERENCE 'test3: Any' field=null getter='(): Any' setter='(Any): Unit' type=kotlin.reflect.KMutableProperty1 origin=PROPERTY_REFERENCE_FOR_DELEGATE value: GET_VAR 'value-parameter : Any' type=kotlin.Any origin=null FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int @@ -98,7 +99,7 @@ FILE /delegatedProperties.kt : Any $receiver: GET_FIELD '`test4$delegate`: HashMap /* = HashMap */' type=kotlin.collections.HashMap /* = java.util.HashMap */ origin=null thisRef: CONST Null type=kotlin.Nothing? value='null' - property: CALLABLE_REFERENCE 'test4: Any' type=kotlin.reflect.KMutableProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE + property: PROPERTY_REFERENCE 'test4: Any' field=null getter='(): Any' setter='(Any): Unit' type=kotlin.reflect.KMutableProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE FUN DELEGATED_PROPERTY_ACCESSOR public fun (: kotlin.Any): kotlin.Unit VALUE_PARAMETER value-parameter : kotlin.Any BLOCK_BODY @@ -107,5 +108,5 @@ FILE /delegatedProperties.kt : Any $receiver: GET_FIELD '`test4$delegate`: HashMap /* = HashMap */' type=kotlin.collections.HashMap /* = java.util.HashMap */ origin=null thisRef: CONST Null type=kotlin.Nothing? value='null' - property: CALLABLE_REFERENCE 'test4: Any' type=kotlin.reflect.KMutableProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE + property: PROPERTY_REFERENCE 'test4: Any' field=null getter='(): Any' setter='(Any): Unit' type=kotlin.reflect.KMutableProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE value: GET_VAR 'value-parameter : Any' type=kotlin.Any origin=null diff --git a/compiler/testData/ir/irText/declarations/fakeOverrides.txt b/compiler/testData/ir/irText/declarations/fakeOverrides.txt index d2c5575c164..7d37f0cdad7 100644 --- a/compiler/testData/ir/irText/declarations/fakeOverrides.txt +++ b/compiler/testData/ir/irText/declarations/fakeOverrides.txt @@ -18,6 +18,7 @@ FILE /fakeOverrides.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS CFoo + $new: VALUE_PARAMETER TYPE_PARAMETER CONSTRUCTOR public constructor CFoo() TYPE_PARAMETER @@ -32,6 +33,7 @@ FILE /fakeOverrides.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Test1 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test1() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor CFoo()' diff --git a/compiler/testData/ir/irText/declarations/packageLevelProperties.txt b/compiler/testData/ir/irText/declarations/packageLevelProperties.txt index 22fa4dc30aa..d4719faa015 100644 --- a/compiler/testData/ir/irText/declarations/packageLevelProperties.txt +++ b/compiler/testData/ir/irText/declarations/packageLevelProperties.txt @@ -69,7 +69,7 @@ FILE /packageLevelProperties.kt BLOCK_BODY RETURN type=kotlin.Nothing from='(): Int' CONST Int type=kotlin.Int value='42' - CALLABLE_REFERENCE '(): Int' type=() -> kotlin.Int origin=LAMBDA + FUNCTION_REFERENCE '(): Int' type=() -> kotlin.Int origin=LAMBDA FUN DELEGATED_PROPERTY_ACCESSOR public fun (): kotlin.Int BLOCK_BODY RETURN type=kotlin.Nothing from='(): Int' @@ -77,7 +77,7 @@ FILE /packageLevelProperties.kt : Int $receiver: GET_FIELD '`test7$delegate`: Lazy' type=kotlin.Lazy origin=null thisRef: CONST Null type=kotlin.Nothing? value='null' - property: CALLABLE_REFERENCE 'test7: Int' type=kotlin.reflect.KProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE + property: PROPERTY_REFERENCE 'test7: Int' field=null getter='(): Int' setter=null type=kotlin.reflect.KProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE PROPERTY public var test8: kotlin.Int FIELD DELEGATE val `test8$delegate`: kotlin.collections.HashMap /* = java.util.HashMap */ EXPRESSION_BODY @@ -91,7 +91,7 @@ FILE /packageLevelProperties.kt : Int $receiver: GET_FIELD '`test8$delegate`: HashMap /* = HashMap */' type=kotlin.collections.HashMap /* = java.util.HashMap */ origin=null thisRef: CONST Null type=kotlin.Nothing? value='null' - property: CALLABLE_REFERENCE 'test8: Int' type=kotlin.reflect.KMutableProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE + property: PROPERTY_REFERENCE 'test8: Int' field=null getter='(): Int' setter='(Int): Unit' type=kotlin.reflect.KMutableProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE FUN DELEGATED_PROPERTY_ACCESSOR public fun (: kotlin.Int): kotlin.Unit VALUE_PARAMETER value-parameter : kotlin.Int BLOCK_BODY @@ -100,5 +100,5 @@ FILE /packageLevelProperties.kt : Int $receiver: GET_FIELD '`test8$delegate`: HashMap /* = HashMap */' type=kotlin.collections.HashMap /* = java.util.HashMap */ origin=null thisRef: CONST Null type=kotlin.Nothing? value='null' - property: CALLABLE_REFERENCE 'test8: Int' type=kotlin.reflect.KMutableProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE + property: PROPERTY_REFERENCE 'test8: Int' field=null getter='(): Int' setter='(Int): Unit' type=kotlin.reflect.KMutableProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE value: GET_VAR 'value-parameter : Int' type=kotlin.Int origin=null diff --git a/compiler/testData/ir/irText/declarations/parameters/class.txt b/compiler/testData/ir/irText/declarations/parameters/class.txt index 8a562ab9a94..6f23dd1f22b 100644 --- a/compiler/testData/ir/irText/declarations/parameters/class.txt +++ b/compiler/testData/ir/irText/declarations/parameters/class.txt @@ -10,6 +10,7 @@ FILE /class.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Test + $new: VALUE_PARAMETER TYPE_PARAMETER CONSTRUCTOR public constructor Test() TYPE_PARAMETER @@ -17,6 +18,7 @@ FILE /class.kt DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='Test' CLASS CLASS TestNested + $new: VALUE_PARAMETER TYPE_PARAMETER CONSTRUCTOR public constructor TestNested() TYPE_PARAMETER @@ -27,10 +29,11 @@ FILE /class.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS TestInner + $new: VALUE_PARAMETER TYPE_PARAMETER CONSTRUCTOR public constructor TestInner() TYPE_PARAMETER - $this: VALUE_PARAMETER + $outer: VALUE_PARAMETER BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='TestInner' diff --git a/compiler/testData/ir/irText/declarations/parameters/constructor.txt b/compiler/testData/ir/irText/declarations/parameters/constructor.txt index 08fa083ccad..7712c365105 100644 --- a/compiler/testData/ir/irText/declarations/parameters/constructor.txt +++ b/compiler/testData/ir/irText/declarations/parameters/constructor.txt @@ -1,5 +1,6 @@ FILE /constructor.kt CLASS CLASS Test1 + $new: VALUE_PARAMETER TYPE_PARAMETER TYPE_PARAMETER CONSTRUCTOR public constructor Test1(x: T1, y: T2) @@ -34,6 +35,7 @@ FILE /constructor.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Test2 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test2(x: kotlin.Int, y: kotlin.String) VALUE_PARAMETER value-parameter x: kotlin.Int VALUE_PARAMETER value-parameter y: kotlin.String @@ -51,10 +53,11 @@ FILE /constructor.kt GET_FIELD 'y: String' type=kotlin.String origin=null receiver: GET_VAR '' type=Test2 origin=null CLASS CLASS TestInner + $new: VALUE_PARAMETER TYPE_PARAMETER CONSTRUCTOR public constructor TestInner(z: Z) TYPE_PARAMETER - $this: VALUE_PARAMETER + $outer: VALUE_PARAMETER VALUE_PARAMETER value-parameter z: Z BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -71,7 +74,7 @@ FILE /constructor.kt receiver: GET_VAR '' type=Test2.TestInner origin=null CONSTRUCTOR public constructor TestInner(z: Z, i: kotlin.Int) TYPE_PARAMETER - $this: VALUE_PARAMETER + $outer: VALUE_PARAMETER VALUE_PARAMETER value-parameter z: Z VALUE_PARAMETER value-parameter i: kotlin.Int BLOCK_BODY @@ -86,6 +89,7 @@ FILE /constructor.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Test3 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test3(x: kotlin.Int, y: kotlin.String = ...) VALUE_PARAMETER value-parameter x: kotlin.Int VALUE_PARAMETER value-parameter y: kotlin.String = ... @@ -118,6 +122,7 @@ FILE /constructor.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Test4 + $new: VALUE_PARAMETER TYPE_PARAMETER CONSTRUCTOR public constructor Test4(x: kotlin.Int) TYPE_PARAMETER diff --git a/compiler/testData/ir/irText/declarations/parameters/dataClassMembers.txt b/compiler/testData/ir/irText/declarations/parameters/dataClassMembers.txt index 6852e979193..56aa07a0316 100644 --- a/compiler/testData/ir/irText/declarations/parameters/dataClassMembers.txt +++ b/compiler/testData/ir/irText/declarations/parameters/dataClassMembers.txt @@ -1,5 +1,6 @@ FILE /dataClassMembers.kt CLASS CLASS Test + $new: VALUE_PARAMETER TYPE_PARAMETER CONSTRUCTOR public constructor Test(x: T, y: kotlin.String = ...) TYPE_PARAMETER diff --git a/compiler/testData/ir/irText/declarations/parameters/defaultPropertyAccessors.txt b/compiler/testData/ir/irText/declarations/parameters/defaultPropertyAccessors.txt index 03bfcbf6b7f..8c41310fb35 100644 --- a/compiler/testData/ir/irText/declarations/parameters/defaultPropertyAccessors.txt +++ b/compiler/testData/ir/irText/declarations/parameters/defaultPropertyAccessors.txt @@ -21,6 +21,7 @@ FILE /defaultPropertyAccessors.kt SET_FIELD 'test2: Int' type=kotlin.Unit origin=null value: GET_VAR 'value-parameter : Int' type=kotlin.Int origin=null CLASS CLASS Host + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Host() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -56,6 +57,7 @@ FILE /defaultPropertyAccessors.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS InPrimaryCtor + $new: VALUE_PARAMETER TYPE_PARAMETER CONSTRUCTOR public constructor InPrimaryCtor(testInPrimaryCtor1: T, testInPrimaryCtor2: kotlin.Int = ...) TYPE_PARAMETER diff --git a/compiler/testData/ir/irText/declarations/parameters/fun.txt b/compiler/testData/ir/irText/declarations/parameters/fun.txt index 74f942bf7e0..77e31a18f2a 100644 --- a/compiler/testData/ir/irText/declarations/parameters/fun.txt +++ b/compiler/testData/ir/irText/declarations/parameters/fun.txt @@ -21,6 +21,7 @@ FILE /fun.kt VALUE_PARAMETER value-parameter j: kotlin.String BLOCK_BODY CLASS CLASS Host + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Host() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/declarations/parameters/lambdas.txt b/compiler/testData/ir/irText/declarations/parameters/lambdas.txt index 147c849b4a4..71b779ab384 100644 --- a/compiler/testData/ir/irText/declarations/parameters/lambdas.txt +++ b/compiler/testData/ir/irText/declarations/parameters/lambdas.txt @@ -8,7 +8,7 @@ FILE /lambdas.kt BLOCK_BODY RETURN type=kotlin.Nothing from='(String): String' GET_VAR 'value-parameter it: String' type=kotlin.String origin=null - CALLABLE_REFERENCE '(String): String' type=(kotlin.String) -> kotlin.String origin=LAMBDA + FUNCTION_REFERENCE '(String): String' type=(kotlin.String) -> kotlin.String origin=LAMBDA FUN DEFAULT_PROPERTY_ACCESSOR public fun (): (kotlin.String) -> kotlin.String BLOCK_BODY RETURN type=kotlin.Nothing from='(): (String) -> String' @@ -24,7 +24,7 @@ FILE /lambdas.kt RETURN type=kotlin.Nothing from='(Any) on Any: Int' CALL 'hashCode(): Int' type=kotlin.Int origin=null $this: GET_VAR 'value-parameter it: Any' type=kotlin.Any origin=null - CALLABLE_REFERENCE '(Any) on Any: Int' type=kotlin.Any.(kotlin.Any) -> kotlin.Int origin=LAMBDA + FUNCTION_REFERENCE '(Any) on Any: Int' type=kotlin.Any.(kotlin.Any) -> kotlin.Int origin=LAMBDA FUN DEFAULT_PROPERTY_ACCESSOR public fun (): kotlin.Any.(kotlin.Any) -> kotlin.Any BLOCK_BODY RETURN type=kotlin.Nothing from='(): Any.(Any) -> Any' @@ -39,7 +39,7 @@ FILE /lambdas.kt BLOCK_BODY RETURN type=kotlin.Nothing from='(Int, Int): Unit' GET_OBJECT 'Unit' type=kotlin.Unit - CALLABLE_REFERENCE '(Int, Int): Unit' type=(kotlin.Int, kotlin.Int) -> kotlin.Unit origin=LAMBDA + FUNCTION_REFERENCE '(Int, Int): Unit' type=(kotlin.Int, kotlin.Int) -> kotlin.Unit origin=LAMBDA FUN DEFAULT_PROPERTY_ACCESSOR public fun (): (kotlin.Int, kotlin.Int) -> kotlin.Unit BLOCK_BODY RETURN type=kotlin.Nothing from='(): (Int, Int) -> Unit' @@ -52,7 +52,7 @@ FILE /lambdas.kt VALUE_PARAMETER value-parameter i: kotlin.Int VALUE_PARAMETER value-parameter j: kotlin.Int BLOCK_BODY - CALLABLE_REFERENCE '(Int, Int): Unit' type=(kotlin.Int, kotlin.Int) -> kotlin.Unit origin=ANONYMOUS_FUNCTION + FUNCTION_REFERENCE '(Int, Int): Unit' type=(kotlin.Int, kotlin.Int) -> kotlin.Unit origin=ANONYMOUS_FUNCTION FUN DEFAULT_PROPERTY_ACCESSOR public fun (): (kotlin.Int, kotlin.Int) -> kotlin.Unit BLOCK_BODY RETURN type=kotlin.Nothing from='(): (Int, Int) -> Unit' diff --git a/compiler/testData/ir/irText/declarations/parameters/propertyAccessors.txt b/compiler/testData/ir/irText/declarations/parameters/propertyAccessors.txt index 2276ac20587..6dccd4877ec 100644 --- a/compiler/testData/ir/irText/declarations/parameters/propertyAccessors.txt +++ b/compiler/testData/ir/irText/declarations/parameters/propertyAccessors.txt @@ -45,6 +45,7 @@ FILE /propertyAccessors.kt VALUE_PARAMETER value-parameter value: kotlin.Int BLOCK_BODY CLASS CLASS Host + $new: VALUE_PARAMETER TYPE_PARAMETER CONSTRUCTOR public constructor Host() TYPE_PARAMETER diff --git a/compiler/testData/ir/irText/declarations/primaryCtorDefaultArguments.txt b/compiler/testData/ir/irText/declarations/primaryCtorDefaultArguments.txt index d21359e505c..46f29824a9f 100644 --- a/compiler/testData/ir/irText/declarations/primaryCtorDefaultArguments.txt +++ b/compiler/testData/ir/irText/declarations/primaryCtorDefaultArguments.txt @@ -1,5 +1,6 @@ FILE /primaryCtorDefaultArguments.kt CLASS CLASS Test + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test(x: kotlin.Int = ...) VALUE_PARAMETER value-parameter x: kotlin.Int = ... EXPRESSION_BODY diff --git a/compiler/testData/ir/irText/declarations/primaryCtorProperties.txt b/compiler/testData/ir/irText/declarations/primaryCtorProperties.txt index 5b697dfdca9..73b3cef30ee 100644 --- a/compiler/testData/ir/irText/declarations/primaryCtorProperties.txt +++ b/compiler/testData/ir/irText/declarations/primaryCtorProperties.txt @@ -1,5 +1,6 @@ FILE /primaryCtorProperties.kt CLASS CLASS C + $new: VALUE_PARAMETER CONSTRUCTOR public constructor C(test1: kotlin.Int, test2: kotlin.Int) VALUE_PARAMETER value-parameter test1: kotlin.Int VALUE_PARAMETER value-parameter test2: kotlin.Int diff --git a/compiler/testData/ir/irText/declarations/provideDelegate/differentReceivers.txt b/compiler/testData/ir/irText/declarations/provideDelegate/differentReceivers.txt index f7c3e6a8580..27f7614ff71 100644 --- a/compiler/testData/ir/irText/declarations/provideDelegate/differentReceivers.txt +++ b/compiler/testData/ir/irText/declarations/provideDelegate/differentReceivers.txt @@ -1,5 +1,6 @@ FILE /differentReceivers.kt CLASS CLASS MyClass + $new: VALUE_PARAMETER CONSTRUCTOR public constructor MyClass(value: kotlin.String) VALUE_PARAMETER value-parameter value: kotlin.String BLOCK_BODY @@ -40,14 +41,14 @@ FILE /differentReceivers.kt $receiver: CALL 'constructor MyClass(String)' type=MyClass origin=null value: CONST String type=kotlin.String value='O' host: CONST Null type=kotlin.Nothing? value='null' - p: CALLABLE_REFERENCE 'testO: String' type=kotlin.reflect.KProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE + p: PROPERTY_REFERENCE 'testO: String' field=null getter='(): String' setter=null type=kotlin.reflect.KProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE FUN DELEGATED_PROPERTY_ACCESSOR public fun (): kotlin.String BLOCK_BODY RETURN type=kotlin.Nothing from='(): String' CALL 'getValue(Any?, Any) on String: String' type=kotlin.String origin=null $receiver: GET_FIELD '`testO$delegate`: String' type=kotlin.String origin=null receiver: CONST Null type=kotlin.Nothing? value='null' - p: CALLABLE_REFERENCE 'testO: String' type=kotlin.reflect.KProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE + p: PROPERTY_REFERENCE 'testO: String' field=null getter='(): String' setter=null type=kotlin.reflect.KProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE PROPERTY public val testK: kotlin.String FIELD DELEGATE val `testK$delegate`: kotlin.String EXPRESSION_BODY @@ -58,7 +59,7 @@ FILE /differentReceivers.kt CALL 'getValue(Any?, Any) on String: String' type=kotlin.String origin=null $receiver: GET_FIELD '`testK$delegate`: String' type=kotlin.String origin=null receiver: CONST Null type=kotlin.Nothing? value='null' - p: CALLABLE_REFERENCE 'testK: String' type=kotlin.reflect.KProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE + p: PROPERTY_REFERENCE 'testK: String' field=null getter='(): String' setter=null type=kotlin.reflect.KProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE PROPERTY public val testOK: kotlin.String FIELD PROPERTY_BACKING_FIELD public val testOK: kotlin.String EXPRESSION_BODY diff --git a/compiler/testData/ir/irText/declarations/provideDelegate/member.txt b/compiler/testData/ir/irText/declarations/provideDelegate/member.txt index 5adcd41e40e..a8b17b24977 100644 --- a/compiler/testData/ir/irText/declarations/provideDelegate/member.txt +++ b/compiler/testData/ir/irText/declarations/provideDelegate/member.txt @@ -1,5 +1,6 @@ FILE /member.kt CLASS CLASS Delegate + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Delegate(value: kotlin.String) VALUE_PARAMETER value-parameter value: kotlin.String BLOCK_BODY @@ -27,6 +28,7 @@ FILE /member.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS DelegateProvider + $new: VALUE_PARAMETER CONSTRUCTOR public constructor DelegateProvider(value: kotlin.String) VALUE_PARAMETER value-parameter value: kotlin.String BLOCK_BODY @@ -55,6 +57,7 @@ FILE /member.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Host + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Host() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -66,7 +69,7 @@ FILE /member.kt $this: CALL 'constructor DelegateProvider(String)' type=DelegateProvider origin=null value: CONST String type=kotlin.String value='OK' thisRef: GET_VAR '' type=Host origin=null - property: CALLABLE_REFERENCE 'testMember: String' type=kotlin.reflect.KProperty1 origin=PROPERTY_REFERENCE_FOR_DELEGATE + property: PROPERTY_REFERENCE 'testMember: String' field=null getter='(): String' setter=null type=kotlin.reflect.KProperty1 origin=PROPERTY_REFERENCE_FOR_DELEGATE FUN DELEGATED_PROPERTY_ACCESSOR public final fun (): kotlin.String $this: VALUE_PARAMETER BLOCK_BODY @@ -75,7 +78,7 @@ FILE /member.kt $this: GET_FIELD '`testMember$delegate`: Delegate' type=Delegate origin=null receiver: GET_VAR '' type=Host origin=null thisRef: GET_VAR '' type=Host origin=null - property: CALLABLE_REFERENCE 'testMember: String' type=kotlin.reflect.KProperty1 origin=PROPERTY_REFERENCE_FOR_DELEGATE + property: PROPERTY_REFERENCE 'testMember: String' field=null getter='(): String' setter=null type=kotlin.reflect.KProperty1 origin=PROPERTY_REFERENCE_FOR_DELEGATE FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String diff --git a/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.txt b/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.txt index 1ac80087297..448c481883a 100644 --- a/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.txt +++ b/compiler/testData/ir/irText/declarations/provideDelegate/memberExtension.txt @@ -1,10 +1,12 @@ FILE /memberExtension.kt CLASS OBJECT Host + $new: VALUE_PARAMETER CONSTRUCTOR private constructor Host() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='Host' CLASS CLASS StringDelegate + $new: VALUE_PARAMETER CONSTRUCTOR public constructor StringDelegate(s: kotlin.String) VALUE_PARAMETER value-parameter s: kotlin.String BLOCK_BODY @@ -49,7 +51,7 @@ FILE /memberExtension.kt $this: GET_VAR '' type=Host origin=null $receiver: CONST String type=kotlin.String value='K' host: GET_VAR '' type=Host origin=null - p: CALLABLE_REFERENCE 'plusK: String on String' type=kotlin.reflect.KProperty2 origin=PROPERTY_REFERENCE_FOR_DELEGATE + p: PROPERTY_REFERENCE 'plusK: String on String' field=null getter='() on String: String' setter=null type=kotlin.reflect.KProperty2 origin=PROPERTY_REFERENCE_FOR_DELEGATE FUN DELEGATED_PROPERTY_ACCESSOR public final fun kotlin.String.(): kotlin.String $this: VALUE_PARAMETER $receiver: VALUE_PARAMETER @@ -59,7 +61,7 @@ FILE /memberExtension.kt $this: GET_FIELD '`plusK$delegate`: Host.StringDelegate' type=Host.StringDelegate origin=null receiver: GET_VAR '' type=Host origin=null receiver: GET_VAR '' type=kotlin.String origin=null - p: CALLABLE_REFERENCE 'plusK: String on String' type=kotlin.reflect.KProperty2 origin=PROPERTY_REFERENCE_FOR_DELEGATE + p: PROPERTY_REFERENCE 'plusK: String on String' field=null getter='() on String: String' setter=null type=kotlin.reflect.KProperty2 origin=PROPERTY_REFERENCE_FOR_DELEGATE PROPERTY public final val ok: kotlin.String FIELD PROPERTY_BACKING_FIELD public final val ok: kotlin.String EXPRESSION_BODY diff --git a/compiler/testData/ir/irText/declarations/provideDelegate/topLevel.txt b/compiler/testData/ir/irText/declarations/provideDelegate/topLevel.txt index 2f95d806f77..1ff77156deb 100644 --- a/compiler/testData/ir/irText/declarations/provideDelegate/topLevel.txt +++ b/compiler/testData/ir/irText/declarations/provideDelegate/topLevel.txt @@ -1,5 +1,6 @@ FILE /topLevel.kt CLASS CLASS Delegate + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Delegate(value: kotlin.String) VALUE_PARAMETER value-parameter value: kotlin.String BLOCK_BODY @@ -27,6 +28,7 @@ FILE /topLevel.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS DelegateProvider + $new: VALUE_PARAMETER CONSTRUCTOR public constructor DelegateProvider(value: kotlin.String) VALUE_PARAMETER value-parameter value: kotlin.String BLOCK_BODY @@ -61,11 +63,11 @@ FILE /topLevel.kt $this: CALL 'constructor DelegateProvider(String)' type=DelegateProvider origin=null value: CONST String type=kotlin.String value='OK' thisRef: CONST Null type=kotlin.Nothing? value='null' - property: CALLABLE_REFERENCE 'testTopLevel: String' type=kotlin.reflect.KProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE + property: PROPERTY_REFERENCE 'testTopLevel: String' field=null getter='(): String' setter=null type=kotlin.reflect.KProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE FUN DELEGATED_PROPERTY_ACCESSOR public fun (): kotlin.String BLOCK_BODY RETURN type=kotlin.Nothing from='(): String' CALL 'getValue(Any?, Any?): String' type=kotlin.String origin=null $this: GET_FIELD '`testTopLevel$delegate`: Delegate' type=Delegate origin=null thisRef: CONST Null type=kotlin.Nothing? value='null' - property: CALLABLE_REFERENCE 'testTopLevel: String' type=kotlin.reflect.KProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE + property: PROPERTY_REFERENCE 'testTopLevel: String' field=null getter='(): String' setter=null type=kotlin.reflect.KProperty0 origin=PROPERTY_REFERENCE_FOR_DELEGATE diff --git a/compiler/testData/ir/irText/declarations/typeAlias.txt b/compiler/testData/ir/irText/declarations/typeAlias.txt index 8a1a38c1497..6bd85e536e4 100644 --- a/compiler/testData/ir/irText/declarations/typeAlias.txt +++ b/compiler/testData/ir/irText/declarations/typeAlias.txt @@ -4,6 +4,7 @@ FILE /typeAlias.kt BLOCK_BODY TYPEALIAS typealias TestLocal = String type=kotlin.String CLASS CLASS C + $new: VALUE_PARAMETER CONSTRUCTOR public constructor C() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/errors/suppressedNonPublicCall.txt b/compiler/testData/ir/irText/errors/suppressedNonPublicCall.txt index 8635bbac61a..75a7fccb0ae 100644 --- a/compiler/testData/ir/irText/errors/suppressedNonPublicCall.txt +++ b/compiler/testData/ir/irText/errors/suppressedNonPublicCall.txt @@ -1,5 +1,6 @@ FILE /suppressedNonPublicCall.kt CLASS CLASS C + $new: VALUE_PARAMETER CONSTRUCTOR public constructor C() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/expressions/arrayAugmentedAssignment1.txt b/compiler/testData/ir/irText/expressions/arrayAugmentedAssignment1.txt index b5809d63fae..858ad74e063 100644 --- a/compiler/testData/ir/irText/expressions/arrayAugmentedAssignment1.txt +++ b/compiler/testData/ir/irText/expressions/arrayAugmentedAssignment1.txt @@ -12,6 +12,7 @@ FILE /arrayAugmentedAssignment1.kt RETURN type=kotlin.Nothing from='bar(): Int' CONST Int type=kotlin.Int value='42' CLASS CLASS C + $new: VALUE_PARAMETER CONSTRUCTOR public constructor C(x: kotlin.IntArray) VALUE_PARAMETER value-parameter x: kotlin.IntArray BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/assignments.txt b/compiler/testData/ir/irText/expressions/assignments.txt index 6667e517853..8b63deda760 100644 --- a/compiler/testData/ir/irText/expressions/assignments.txt +++ b/compiler/testData/ir/irText/expressions/assignments.txt @@ -1,5 +1,6 @@ FILE /assignments.kt CLASS CLASS Ref + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Ref(x: kotlin.Int) VALUE_PARAMETER value-parameter x: kotlin.Int BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/augmentedAssignment2.txt b/compiler/testData/ir/irText/expressions/augmentedAssignment2.txt index db41c39a582..3315e19fef8 100644 --- a/compiler/testData/ir/irText/expressions/augmentedAssignment2.txt +++ b/compiler/testData/ir/irText/expressions/augmentedAssignment2.txt @@ -1,5 +1,6 @@ FILE /augmentedAssignment2.kt CLASS CLASS A + $new: VALUE_PARAMETER CONSTRUCTOR public constructor A() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/expressions/augmentedAssignmentWithExpression.txt b/compiler/testData/ir/irText/expressions/augmentedAssignmentWithExpression.txt index 4b34f8d6e7f..377a1ef84ea 100644 --- a/compiler/testData/ir/irText/expressions/augmentedAssignmentWithExpression.txt +++ b/compiler/testData/ir/irText/expressions/augmentedAssignmentWithExpression.txt @@ -1,5 +1,6 @@ FILE /augmentedAssignmentWithExpression.kt CLASS CLASS Host + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Host() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -12,7 +13,7 @@ FILE /augmentedAssignmentWithExpression.kt $this: VALUE_PARAMETER BLOCK_BODY CALL 'plusAssign(Int): Unit' type=kotlin.Unit origin=PLUSEQ - $this: GET_VAR '' type=Host origin=null + $this: GET_VAR '' type=Host origin=PLUSEQ x: CONST Int type=kotlin.Int value='1' FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int @@ -25,7 +26,7 @@ FILE /augmentedAssignmentWithExpression.kt $receiver: VALUE_PARAMETER BLOCK_BODY CALL 'plusAssign(Int): Unit' type=kotlin.Unit origin=PLUSEQ - $this: GET_VAR '' type=Host origin=null + $this: GET_VAR '' type=Host origin=PLUSEQ x: CONST Int type=kotlin.Int value='1' FUN public fun test3(): kotlin.Unit BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/badBreakContinue.txt b/compiler/testData/ir/irText/expressions/badBreakContinue.txt index 6f59ae86642..1ace5f45be8 100644 --- a/compiler/testData/ir/irText/expressions/badBreakContinue.txt +++ b/compiler/testData/ir/irText/expressions/badBreakContinue.txt @@ -21,7 +21,7 @@ FILE /badBreakContinue.kt BLOCK_BODY ERROR_EXPR 'Loop not found for break expression: break@L1' type=kotlin.Nothing ERROR_EXPR 'Loop not found for continue expression: continue@L1' type=kotlin.Nothing - CALLABLE_REFERENCE '(): Nothing' type=() -> kotlin.Nothing origin=LAMBDA + FUNCTION_REFERENCE '(): Nothing' type=() -> kotlin.Nothing origin=LAMBDA FUN public fun test4(): kotlin.Unit BLOCK_BODY WHILE label=null origin=WHILE_LOOP diff --git a/compiler/testData/ir/irText/expressions/boundCallableReferences.txt b/compiler/testData/ir/irText/expressions/boundCallableReferences.txt index 1bc231026ff..6ccb2ed776c 100644 --- a/compiler/testData/ir/irText/expressions/boundCallableReferences.txt +++ b/compiler/testData/ir/irText/expressions/boundCallableReferences.txt @@ -1,5 +1,6 @@ FILE /boundCallableReferences.kt CLASS CLASS A + $new: VALUE_PARAMETER CONSTRUCTOR public constructor A() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -26,7 +27,7 @@ FILE /boundCallableReferences.kt PROPERTY public val test1: kotlin.reflect.KFunction0 FIELD PROPERTY_BACKING_FIELD public val test1: kotlin.reflect.KFunction0 EXPRESSION_BODY - CALLABLE_REFERENCE 'foo(): Unit' type=kotlin.reflect.KFunction0 origin=null + FUNCTION_REFERENCE 'foo(): Unit' type=kotlin.reflect.KFunction0 origin=null $this: CALL 'constructor A()' type=A origin=null FUN DEFAULT_PROPERTY_ACCESSOR public fun (): kotlin.reflect.KFunction0 BLOCK_BODY @@ -35,7 +36,7 @@ FILE /boundCallableReferences.kt PROPERTY public val test2: kotlin.reflect.KProperty0 FIELD PROPERTY_BACKING_FIELD public val test2: kotlin.reflect.KProperty0 EXPRESSION_BODY - CALLABLE_REFERENCE 'bar: Int' type=kotlin.reflect.KProperty0 origin=null + PROPERTY_REFERENCE 'bar: Int' field=null getter='(): Int' setter=null type=kotlin.reflect.KProperty0 origin=null $this: CALL 'constructor A()' type=A origin=null FUN DEFAULT_PROPERTY_ACCESSOR public fun (): kotlin.reflect.KProperty0 BLOCK_BODY @@ -44,7 +45,7 @@ FILE /boundCallableReferences.kt PROPERTY public val test3: kotlin.reflect.KFunction0 FIELD PROPERTY_BACKING_FIELD public val test3: kotlin.reflect.KFunction0 EXPRESSION_BODY - CALLABLE_REFERENCE 'qux() on A: Unit' type=kotlin.reflect.KFunction0 origin=null + FUNCTION_REFERENCE 'qux() on A: Unit' type=kotlin.reflect.KFunction0 origin=null $receiver: CALL 'constructor A()' type=A origin=null FUN DEFAULT_PROPERTY_ACCESSOR public fun (): kotlin.reflect.KFunction0 BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/chainOfSafeCalls.txt b/compiler/testData/ir/irText/expressions/chainOfSafeCalls.txt index e03968605bb..21066216ea3 100644 --- a/compiler/testData/ir/irText/expressions/chainOfSafeCalls.txt +++ b/compiler/testData/ir/irText/expressions/chainOfSafeCalls.txt @@ -1,5 +1,6 @@ FILE /chainOfSafeCalls.kt CLASS CLASS C + $new: VALUE_PARAMETER CONSTRUCTOR public constructor C() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/expressions/classReference.txt b/compiler/testData/ir/irText/expressions/classReference.txt index fb421409ec1..0843b8ee9a4 100644 --- a/compiler/testData/ir/irText/expressions/classReference.txt +++ b/compiler/testData/ir/irText/expressions/classReference.txt @@ -1,5 +1,6 @@ FILE /classReference.kt CLASS CLASS A + $new: VALUE_PARAMETER CONSTRUCTOR public constructor A() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/expressions/coercionToUnit.txt b/compiler/testData/ir/irText/expressions/coercionToUnit.txt index fb7cd5db2a6..93ba3d0267b 100644 --- a/compiler/testData/ir/irText/expressions/coercionToUnit.txt +++ b/compiler/testData/ir/irText/expressions/coercionToUnit.txt @@ -8,7 +8,7 @@ FILE /coercionToUnit.kt RETURN type=kotlin.Nothing from='(): Unit' TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CONST Int type=kotlin.Int value='42' - CALLABLE_REFERENCE '(): Unit' type=() -> kotlin.Unit origin=LAMBDA + FUNCTION_REFERENCE '(): Unit' type=() -> kotlin.Unit origin=LAMBDA FUN DEFAULT_PROPERTY_ACCESSOR public fun (): () -> kotlin.Unit BLOCK_BODY RETURN type=kotlin.Nothing from='(): () -> Unit' diff --git a/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.txt b/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.txt index ee6009b46a8..36099f901b6 100644 --- a/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.txt +++ b/compiler/testData/ir/irText/expressions/complexAugmentedAssignment.txt @@ -1,5 +1,6 @@ FILE /complexAugmentedAssignment.kt CLASS OBJECT X1 + $new: VALUE_PARAMETER CONSTRUCTOR private constructor X1() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -22,6 +23,7 @@ FILE /complexAugmentedAssignment.kt receiver: GET_VAR '' type=X1 origin=null value: GET_VAR 'value-parameter : Int' type=kotlin.Int origin=null CLASS OBJECT X2 + $new: VALUE_PARAMETER CONSTRUCTOR private constructor X2() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -44,6 +46,7 @@ FILE /complexAugmentedAssignment.kt receiver: GET_VAR '' type=X1.X2 origin=null value: GET_VAR 'value-parameter : Int' type=kotlin.Int origin=null CLASS OBJECT X3 + $new: VALUE_PARAMETER CONSTRUCTOR private constructor X3() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -143,6 +146,7 @@ FILE /complexAugmentedAssignment.kt $this: GET_VAR 'tmp5: Int' type=kotlin.Int origin=null GET_VAR 'tmp5: Int' type=kotlin.Int origin=null CLASS CLASS B + $new: VALUE_PARAMETER CONSTRUCTOR public constructor B(s: kotlin.Int = ...) VALUE_PARAMETER value-parameter s: kotlin.Int = ... EXPRESSION_BODY @@ -171,6 +175,7 @@ FILE /complexAugmentedAssignment.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS OBJECT Host + $new: VALUE_PARAMETER CONSTRUCTOR private constructor Host() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/expressions/contructorCall.txt b/compiler/testData/ir/irText/expressions/contructorCall.txt index 954e3c6d845..700abb94265 100644 --- a/compiler/testData/ir/irText/expressions/contructorCall.txt +++ b/compiler/testData/ir/irText/expressions/contructorCall.txt @@ -1,5 +1,6 @@ FILE /contructorCall.kt CLASS CLASS A + $new: VALUE_PARAMETER CONSTRUCTOR public constructor A() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/expressions/destructuring1.txt b/compiler/testData/ir/irText/expressions/destructuring1.txt index cd1fc57942a..dd14766f166 100644 --- a/compiler/testData/ir/irText/expressions/destructuring1.txt +++ b/compiler/testData/ir/irText/expressions/destructuring1.txt @@ -1,5 +1,6 @@ FILE /destructuring1.kt CLASS OBJECT A + $new: VALUE_PARAMETER CONSTRUCTOR private constructor A() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -8,6 +9,7 @@ FILE /destructuring1.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS OBJECT B + $new: VALUE_PARAMETER CONSTRUCTOR private constructor B() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/expressions/destructuringWithUnderscore.txt b/compiler/testData/ir/irText/expressions/destructuringWithUnderscore.txt index e003c78e26f..963f12951c5 100644 --- a/compiler/testData/ir/irText/expressions/destructuringWithUnderscore.txt +++ b/compiler/testData/ir/irText/expressions/destructuringWithUnderscore.txt @@ -1,5 +1,6 @@ FILE /destructuringWithUnderscore.kt CLASS OBJECT A + $new: VALUE_PARAMETER CONSTRUCTOR private constructor A() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -8,6 +9,7 @@ FILE /destructuringWithUnderscore.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS OBJECT B + $new: VALUE_PARAMETER CONSTRUCTOR private constructor B() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/expressions/enumEntryAsReceiver.txt b/compiler/testData/ir/irText/expressions/enumEntryAsReceiver.txt index fdf7fcac547..50a4dedfbca 100644 --- a/compiler/testData/ir/irText/expressions/enumEntryAsReceiver.txt +++ b/compiler/testData/ir/irText/expressions/enumEntryAsReceiver.txt @@ -1,5 +1,6 @@ FILE /enumEntryAsReceiver.kt CLASS ENUM_CLASS X + $new: VALUE_PARAMETER CONSTRUCTOR private constructor X() BLOCK_BODY ENUM_CONSTRUCTOR_CALL 'constructor Enum(String, Int)' @@ -7,6 +8,7 @@ FILE /enumEntryAsReceiver.kt ENUM_ENTRY enum entry B init: ENUM_CONSTRUCTOR_CALL 'constructor B()' class: CLASS ENUM_ENTRY B + $new: VALUE_PARAMETER CONSTRUCTOR private constructor B() BLOCK_BODY ENUM_CONSTRUCTOR_CALL 'constructor X()' @@ -16,6 +18,7 @@ FILE /enumEntryAsReceiver.kt EXPRESSION_BODY CONST String type=kotlin.String value='OK' FUN DEFAULT_PROPERTY_ACCESSOR public final fun (): kotlin.String + $this: VALUE_PARAMETER BLOCK_BODY RETURN type=kotlin.Nothing from='(): String' GET_FIELD 'value2: String' type=kotlin.String origin=null @@ -29,18 +32,42 @@ FILE /enumEntryAsReceiver.kt RETURN type=kotlin.Nothing from='(): String' CALL '(): String' type=kotlin.String origin=GET_PROPERTY $this: GET_ENUM 'B' type=X.B - CALLABLE_REFERENCE '(): String' type=() -> kotlin.String origin=LAMBDA + FUNCTION_REFERENCE '(): String' type=() -> kotlin.String origin=LAMBDA FUN DEFAULT_PROPERTY_ACCESSOR public open override fun (): () -> kotlin.String + $this: VALUE_PARAMETER BLOCK_BODY RETURN type=kotlin.Nothing from='(): () -> String' GET_FIELD 'value: () -> String' type=() -> kotlin.String origin=null receiver: GET_VAR '' type=X.B origin=null + FUN FAKE_OVERRIDE protected final override fun clone(): kotlin.Any + FUN FAKE_OVERRIDE protected/*protected and package*/ final override fun finalize(): kotlin.Unit + FUN FAKE_OVERRIDE public final override fun getDeclaringClass(): java.lang.Class! + FUN FAKE_OVERRIDE public final override fun compareTo(other: X): kotlin.Int + FUN FAKE_OVERRIDE public final override fun equals(other: kotlin.Any?): kotlin.Boolean + FUN FAKE_OVERRIDE public final override fun hashCode(): kotlin.Int + PROPERTY FAKE_OVERRIDE public final override val name: kotlin.String + FUN FAKE_OVERRIDE public final override fun (): kotlin.String + PROPERTY FAKE_OVERRIDE public final override val ordinal: kotlin.Int + FUN FAKE_OVERRIDE public final override fun (): kotlin.Int + FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String PROPERTY public abstract val value: () -> kotlin.String FUN DEFAULT_PROPERTY_ACCESSOR public abstract fun (): () -> kotlin.String + $this: VALUE_PARAMETER BLOCK_BODY RETURN type=kotlin.Nothing from='(): () -> String' GET_FIELD 'value: () -> String' type=() -> kotlin.String origin=null receiver: GET_VAR '' type=X origin=null + FUN FAKE_OVERRIDE protected final override fun clone(): kotlin.Any + FUN FAKE_OVERRIDE protected/*protected and package*/ final override fun finalize(): kotlin.Unit + FUN FAKE_OVERRIDE public final override fun getDeclaringClass(): java.lang.Class! + FUN FAKE_OVERRIDE public final override fun compareTo(other: X): kotlin.Int + FUN FAKE_OVERRIDE public final override fun equals(other: kotlin.Any?): kotlin.Boolean + FUN FAKE_OVERRIDE public final override fun hashCode(): kotlin.Int + PROPERTY FAKE_OVERRIDE public final override val name: kotlin.String + FUN FAKE_OVERRIDE public final override fun (): kotlin.String + PROPERTY FAKE_OVERRIDE public final override val ordinal: kotlin.Int + FUN FAKE_OVERRIDE public final override fun (): kotlin.Int + FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String FUN ENUM_CLASS_SPECIAL_MEMBER public final fun values(): kotlin.Array SYNTHETIC_BODY kind=ENUM_VALUES FUN ENUM_CLASS_SPECIAL_MEMBER public final fun valueOf(value: kotlin.String): X diff --git a/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.txt b/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.txt index 3dc9f9aa42a..99617854eb7 100644 --- a/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.txt +++ b/compiler/testData/ir/irText/expressions/forWithImplicitReceivers.txt @@ -1,5 +1,6 @@ FILE /forWithImplicitReceivers.kt CLASS OBJECT FiveTimes + $new: VALUE_PARAMETER CONSTRUCTOR private constructor FiveTimes() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -8,6 +9,7 @@ FILE /forWithImplicitReceivers.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS IntCell + $new: VALUE_PARAMETER CONSTRUCTOR public constructor IntCell(value: kotlin.Int) VALUE_PARAMETER value-parameter value: kotlin.Int BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.txt b/compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.txt index 6fef6efc9b4..02572383928 100644 --- a/compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.txt +++ b/compiler/testData/ir/irText/expressions/jvmInstanceFieldReference.txt @@ -1,5 +1,6 @@ FILE /Derived.kt CLASS CLASS Derived + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Derived() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Base()' diff --git a/compiler/testData/ir/irText/expressions/jvmStaticFieldReference.txt b/compiler/testData/ir/irText/expressions/jvmStaticFieldReference.txt index 7ea34c12c73..46faddf1076 100644 --- a/compiler/testData/ir/irText/expressions/jvmStaticFieldReference.txt +++ b/compiler/testData/ir/irText/expressions/jvmStaticFieldReference.txt @@ -22,6 +22,7 @@ FILE /jvmStaticFieldReference.kt GET_FIELD 'out: PrintStream!' type=java.io.PrintStream! origin=GET_PROPERTY p0: CONST String type=kotlin.String value='testProp/set' CLASS CLASS TestClass + $new: VALUE_PARAMETER CONSTRUCTOR public constructor TestClass() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/expressions/kt16904.txt b/compiler/testData/ir/irText/expressions/kt16904.txt index 879594cb6f6..8e29c6415b1 100644 --- a/compiler/testData/ir/irText/expressions/kt16904.txt +++ b/compiler/testData/ir/irText/expressions/kt16904.txt @@ -1,5 +1,6 @@ FILE /kt16904.kt CLASS CLASS A + $new: VALUE_PARAMETER CONSTRUCTOR public constructor A() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -9,6 +10,7 @@ FILE /kt16904.kt EXPRESSION_BODY CALL 'constructor B()' type=B origin=null FUN DEFAULT_PROPERTY_ACCESSOR public final fun (): B + $this: VALUE_PARAMETER BLOCK_BODY RETURN type=kotlin.Nothing from='(): B' GET_FIELD 'x: B' type=B origin=null @@ -18,23 +20,36 @@ FILE /kt16904.kt EXPRESSION_BODY CONST Int type=kotlin.Int value='0' FUN DEFAULT_PROPERTY_ACCESSOR public final fun (): kotlin.Int + $this: VALUE_PARAMETER BLOCK_BODY RETURN type=kotlin.Nothing from='(): Int' GET_FIELD 'y: Int' type=kotlin.Int origin=null receiver: GET_VAR '' type=A origin=null FUN DEFAULT_PROPERTY_ACCESSOR public final fun (: kotlin.Int): kotlin.Unit + $this: VALUE_PARAMETER + VALUE_PARAMETER value-parameter : kotlin.Int BLOCK_BODY SET_FIELD 'y: Int' type=kotlin.Unit origin=null receiver: GET_VAR '' type=A origin=null value: GET_VAR 'value-parameter : Int' type=kotlin.Int origin=null + FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean + FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int + FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS B + $new: VALUE_PARAMETER CONSTRUCTOR public constructor B() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='B' FUN public final operator fun plusAssign(x: kotlin.Int): kotlin.Unit + $this: VALUE_PARAMETER + VALUE_PARAMETER value-parameter x: kotlin.Int BLOCK_BODY + FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean + FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int + FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Test1 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test1() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor A()' @@ -55,7 +70,16 @@ FILE /kt16904.kt $this: CALL '(): Int' type=kotlin.Int origin=PLUSEQ $this: GET_VAR 'tmp1_this: Test1' type=Test1 origin=null other: CONST Int type=kotlin.Int value='42' + PROPERTY FAKE_OVERRIDE public final override val x: B + FUN FAKE_OVERRIDE public final override fun (): B + PROPERTY FAKE_OVERRIDE public final override var y: kotlin.Int + FUN FAKE_OVERRIDE public final override fun (): kotlin.Int + FUN FAKE_OVERRIDE public final override fun (: kotlin.Int): kotlin.Unit + FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean + FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int + FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS Test2 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Test2() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor J()' @@ -65,3 +89,7 @@ FILE /kt16904.kt SET_FIELD 'field: Int' type=kotlin.Unit origin=EQ receiver: GET_VAR '' type=Test2 origin=null value: CONST Int type=kotlin.Int value='42' + PROPERTY FAKE_OVERRIDE public final override var field: kotlin.Int + FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean + FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int + FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String diff --git a/compiler/testData/ir/irText/expressions/kt16905.txt b/compiler/testData/ir/irText/expressions/kt16905.txt index c048790e639..7831e5b750d 100644 --- a/compiler/testData/ir/irText/expressions/kt16905.txt +++ b/compiler/testData/ir/irText/expressions/kt16905.txt @@ -1,26 +1,45 @@ FILE /kt16905.kt CLASS CLASS Outer + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Outer() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='Outer' CLASS CLASS Inner + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Inner() + $outer: VALUE_PARAMETER BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='Inner' + FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean + FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int + FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS InnerDerived0 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor InnerDerived0() + $outer: VALUE_PARAMETER BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Inner()' $this: GET_VAR '' type=Outer origin=null INSTANCE_INITIALIZER_CALL classDescriptor='InnerDerived0' + FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean + FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int + FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS CLASS InnerDerived1 + $new: VALUE_PARAMETER CONSTRUCTOR public constructor InnerDerived1() + $outer: VALUE_PARAMETER BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Inner()' $this: GET_VAR '' type=Outer origin=null INSTANCE_INITIALIZER_CALL classDescriptor='InnerDerived1' + FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean + FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int + FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String + FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean + FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int + FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String TYPEALIAS typealias OI = Outer.Inner type=Outer.Inner FUN public fun test(): Outer.Inner BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/membersImportedFromObject.txt b/compiler/testData/ir/irText/expressions/membersImportedFromObject.txt index c5efb795c9c..8cd96d79ff7 100644 --- a/compiler/testData/ir/irText/expressions/membersImportedFromObject.txt +++ b/compiler/testData/ir/irText/expressions/membersImportedFromObject.txt @@ -1,5 +1,6 @@ FILE /membersImportedFromObject.kt CLASS OBJECT A + $new: VALUE_PARAMETER CONSTRUCTOR private constructor A() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/expressions/objectAsCallable.txt b/compiler/testData/ir/irText/expressions/objectAsCallable.txt index e8856ec380b..9556ecf546f 100644 --- a/compiler/testData/ir/irText/expressions/objectAsCallable.txt +++ b/compiler/testData/ir/irText/expressions/objectAsCallable.txt @@ -1,5 +1,6 @@ FILE /objectAsCallable.kt CLASS OBJECT A + $new: VALUE_PARAMETER CONSTRUCTOR private constructor A() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -8,6 +9,7 @@ FILE /objectAsCallable.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS ENUM_CLASS En + $new: VALUE_PARAMETER CONSTRUCTOR private constructor En() BLOCK_BODY ENUM_CONSTRUCTOR_CALL 'constructor Enum(String, Int)' diff --git a/compiler/testData/ir/irText/expressions/objectClassReference.txt b/compiler/testData/ir/irText/expressions/objectClassReference.txt index 2fa0b2b76da..24c1beb47ba 100644 --- a/compiler/testData/ir/irText/expressions/objectClassReference.txt +++ b/compiler/testData/ir/irText/expressions/objectClassReference.txt @@ -1,5 +1,6 @@ FILE /objectClassReference.kt CLASS OBJECT A + $new: VALUE_PARAMETER CONSTRUCTOR private constructor A() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/expressions/primitivesImplicitConversions.txt b/compiler/testData/ir/irText/expressions/primitivesImplicitConversions.txt index 552965f1ceb..cb15c438d3a 100644 --- a/compiler/testData/ir/irText/expressions/primitivesImplicitConversions.txt +++ b/compiler/testData/ir/irText/expressions/primitivesImplicitConversions.txt @@ -83,6 +83,7 @@ FILE /primitivesImplicitConversions.kt $this: CONST Int type=kotlin.Int value='1' BLOCK_BODY CLASS CLASS TestImplicitArguments + $new: VALUE_PARAMETER CONSTRUCTOR public constructor TestImplicitArguments(x: kotlin.Long = ...) VALUE_PARAMETER value-parameter x: kotlin.Long = ... EXPRESSION_BODY diff --git a/compiler/testData/ir/irText/expressions/reflectionLiterals.txt b/compiler/testData/ir/irText/expressions/reflectionLiterals.txt index bee45099bde..dbdf1181df4 100644 --- a/compiler/testData/ir/irText/expressions/reflectionLiterals.txt +++ b/compiler/testData/ir/irText/expressions/reflectionLiterals.txt @@ -1,5 +1,6 @@ FILE /reflectionLiterals.kt CLASS CLASS A + $new: VALUE_PARAMETER CONSTRUCTOR public constructor A() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -40,7 +41,7 @@ FILE /reflectionLiterals.kt PROPERTY public val test3: kotlin.reflect.KFunction1 FIELD PROPERTY_BACKING_FIELD public val test3: kotlin.reflect.KFunction1 EXPRESSION_BODY - CALLABLE_REFERENCE 'foo(): Unit' type=kotlin.reflect.KFunction1 origin=null + FUNCTION_REFERENCE 'foo(): Unit' type=kotlin.reflect.KFunction1 origin=null FUN DEFAULT_PROPERTY_ACCESSOR public fun (): kotlin.reflect.KFunction1 BLOCK_BODY RETURN type=kotlin.Nothing from='(): KFunction1' @@ -48,7 +49,7 @@ FILE /reflectionLiterals.kt PROPERTY public val test4: kotlin.reflect.KFunction0 FIELD PROPERTY_BACKING_FIELD public val test4: kotlin.reflect.KFunction0 EXPRESSION_BODY - CALLABLE_REFERENCE 'constructor A()' type=kotlin.reflect.KFunction0 origin=null + FUNCTION_REFERENCE 'constructor A()' type=kotlin.reflect.KFunction0 origin=null FUN DEFAULT_PROPERTY_ACCESSOR public fun (): kotlin.reflect.KFunction0 BLOCK_BODY RETURN type=kotlin.Nothing from='(): KFunction0' @@ -56,7 +57,7 @@ FILE /reflectionLiterals.kt PROPERTY public val test5: kotlin.reflect.KFunction0 FIELD PROPERTY_BACKING_FIELD public val test5: kotlin.reflect.KFunction0 EXPRESSION_BODY - CALLABLE_REFERENCE 'foo(): Unit' type=kotlin.reflect.KFunction0 origin=null + FUNCTION_REFERENCE 'foo(): Unit' type=kotlin.reflect.KFunction0 origin=null $this: CALL 'constructor A()' type=A origin=null FUN DEFAULT_PROPERTY_ACCESSOR public fun (): kotlin.reflect.KFunction0 BLOCK_BODY @@ -65,7 +66,7 @@ FILE /reflectionLiterals.kt PROPERTY public val test6: kotlin.reflect.KFunction0 FIELD PROPERTY_BACKING_FIELD public val test6: kotlin.reflect.KFunction0 EXPRESSION_BODY - CALLABLE_REFERENCE 'bar(): Unit' type=kotlin.reflect.KFunction0 origin=null + FUNCTION_REFERENCE 'bar(): Unit' type=kotlin.reflect.KFunction0 origin=null FUN DEFAULT_PROPERTY_ACCESSOR public fun (): kotlin.reflect.KFunction0 BLOCK_BODY RETURN type=kotlin.Nothing from='(): KFunction0' @@ -73,7 +74,7 @@ FILE /reflectionLiterals.kt PROPERTY public val test7: kotlin.reflect.KProperty0 FIELD PROPERTY_BACKING_FIELD public val test7: kotlin.reflect.KProperty0 EXPRESSION_BODY - CALLABLE_REFERENCE 'qux: Int' type=kotlin.reflect.KProperty0 origin=null + PROPERTY_REFERENCE 'qux: Int' field=null getter='(): Int' setter=null type=kotlin.reflect.KProperty0 origin=null FUN DEFAULT_PROPERTY_ACCESSOR public fun (): kotlin.reflect.KProperty0 BLOCK_BODY RETURN type=kotlin.Nothing from='(): KProperty0' diff --git a/compiler/testData/ir/irText/expressions/safeAssignment.txt b/compiler/testData/ir/irText/expressions/safeAssignment.txt index 8f5433fb889..59f58423c9f 100644 --- a/compiler/testData/ir/irText/expressions/safeAssignment.txt +++ b/compiler/testData/ir/irText/expressions/safeAssignment.txt @@ -1,5 +1,6 @@ FILE /safeAssignment.kt CLASS CLASS C + $new: VALUE_PARAMETER CONSTRUCTOR public constructor C(x: kotlin.Int) VALUE_PARAMETER value-parameter x: kotlin.Int BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/safeCallWithIncrementDecrement.txt b/compiler/testData/ir/irText/expressions/safeCallWithIncrementDecrement.txt index 8da75d3e3fd..e6cdbb11b8f 100644 --- a/compiler/testData/ir/irText/expressions/safeCallWithIncrementDecrement.txt +++ b/compiler/testData/ir/irText/expressions/safeCallWithIncrementDecrement.txt @@ -1,5 +1,6 @@ FILE /safeCallWithIncrementDecrement.kt CLASS CLASS C + $new: VALUE_PARAMETER CONSTRUCTOR public constructor C() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/expressions/safeCalls.txt b/compiler/testData/ir/irText/expressions/safeCalls.txt index 0a3ade7cf52..3be29c66dde 100644 --- a/compiler/testData/ir/irText/expressions/safeCalls.txt +++ b/compiler/testData/ir/irText/expressions/safeCalls.txt @@ -1,5 +1,6 @@ FILE /safeCalls.kt CLASS CLASS Ref + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Ref(value: kotlin.Int) VALUE_PARAMETER value-parameter value: kotlin.Int BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/setFieldWithImplicitCast.txt b/compiler/testData/ir/irText/expressions/setFieldWithImplicitCast.txt index cf7e0f7c217..fd30deadf15 100644 --- a/compiler/testData/ir/irText/expressions/setFieldWithImplicitCast.txt +++ b/compiler/testData/ir/irText/expressions/setFieldWithImplicitCast.txt @@ -1,5 +1,6 @@ FILE /Derived.kt CLASS CLASS Derived + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Derived() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Base()' diff --git a/compiler/testData/ir/irText/expressions/tryCatch.txt b/compiler/testData/ir/irText/expressions/tryCatch.txt index a68c436cda0..8f86a194c8a 100644 --- a/compiler/testData/ir/irText/expressions/tryCatch.txt +++ b/compiler/testData/ir/irText/expressions/tryCatch.txt @@ -5,6 +5,7 @@ FILE /tryCatch.kt try: BLOCK type=kotlin.Unit origin=null CALL 'println(): Unit' type=kotlin.Unit origin=null CATCH parameter=e: Throwable + VAR CATCH_PARAMETER val e: kotlin.Throwable BLOCK type=kotlin.Unit origin=null CALL 'println(): Unit' type=kotlin.Unit origin=null finally: BLOCK type=kotlin.Unit origin=null @@ -17,6 +18,7 @@ FILE /tryCatch.kt CALL 'println(): Unit' type=kotlin.Unit origin=null CONST Int type=kotlin.Int value='42' CATCH parameter=e: Throwable + VAR CATCH_PARAMETER val e: kotlin.Throwable BLOCK type=kotlin.Int origin=null CALL 'println(): Unit' type=kotlin.Unit origin=null CONST Int type=kotlin.Int value='24' diff --git a/compiler/testData/ir/irText/expressions/tryCatchWithImplicitCast.txt b/compiler/testData/ir/irText/expressions/tryCatchWithImplicitCast.txt index 6f34e838fba..866493a8544 100644 --- a/compiler/testData/ir/irText/expressions/tryCatchWithImplicitCast.txt +++ b/compiler/testData/ir/irText/expressions/tryCatchWithImplicitCast.txt @@ -14,5 +14,6 @@ FILE /tryCatchWithImplicitCast.kt TYPE_OP type=kotlin.String origin=IMPLICIT_CAST typeOperand=kotlin.String GET_VAR 'value-parameter a: Any' type=kotlin.Any origin=null CATCH parameter=e: Throwable + VAR CATCH_PARAMETER val e: kotlin.Throwable BLOCK type=kotlin.String origin=null CONST String type=kotlin.String value='' diff --git a/compiler/testData/ir/irText/expressions/values.txt b/compiler/testData/ir/irText/expressions/values.txt index 3861173415f..fb740fdf83d 100644 --- a/compiler/testData/ir/irText/expressions/values.txt +++ b/compiler/testData/ir/irText/expressions/values.txt @@ -1,5 +1,6 @@ FILE /values.kt CLASS ENUM_CLASS Enum + $new: VALUE_PARAMETER CONSTRUCTOR private constructor Enum() BLOCK_BODY ENUM_CONSTRUCTOR_CALL 'constructor Enum(String, Int)' @@ -22,6 +23,7 @@ FILE /values.kt FUN ENUM_CLASS_SPECIAL_MEMBER public final fun valueOf(value: kotlin.String): Enum SYNTHETIC_BODY kind=ENUM_VALUEOF CLASS OBJECT A + $new: VALUE_PARAMETER CONSTRUCTOR private constructor A() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -38,11 +40,13 @@ FILE /values.kt RETURN type=kotlin.Nothing from='(): Int' GET_FIELD 'a: Int' type=kotlin.Int origin=null CLASS CLASS Z + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Z() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' INSTANCE_INITIALIZER_CALL classDescriptor='Z' CLASS OBJECT companion object of Z + $new: VALUE_PARAMETER CONSTRUCTOR private constructor Companion() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/expressions/variableAsFunctionCall.txt b/compiler/testData/ir/irText/expressions/variableAsFunctionCall.txt index 9f5130c78e5..f014e2be00e 100644 --- a/compiler/testData/ir/irText/expressions/variableAsFunctionCall.txt +++ b/compiler/testData/ir/irText/expressions/variableAsFunctionCall.txt @@ -8,7 +8,7 @@ FILE /variableAsFunctionCall.kt BLOCK_BODY RETURN type=kotlin.Nothing from='(): String' GET_VAR ' String>' type=kotlin.String origin=null - CALLABLE_REFERENCE '(): String' type=() -> kotlin.String origin=LAMBDA + FUNCTION_REFERENCE '(): String' type=() -> kotlin.String origin=LAMBDA FUN public fun test1(f: () -> kotlin.Unit): kotlin.Unit VALUE_PARAMETER value-parameter f: () -> kotlin.Unit BLOCK_BODY diff --git a/compiler/testData/ir/irText/expressions/when.txt b/compiler/testData/ir/irText/expressions/when.txt index 9bfb1cb4373..72c61058ac9 100644 --- a/compiler/testData/ir/irText/expressions/when.txt +++ b/compiler/testData/ir/irText/expressions/when.txt @@ -1,5 +1,6 @@ FILE /when.kt CLASS OBJECT A + $new: VALUE_PARAMETER CONSTRUCTOR private constructor A() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/lambdas/anonymousFunction.txt b/compiler/testData/ir/irText/lambdas/anonymousFunction.txt index 1ce8cc0551d..c4f0e07547b 100644 --- a/compiler/testData/ir/irText/lambdas/anonymousFunction.txt +++ b/compiler/testData/ir/irText/lambdas/anonymousFunction.txt @@ -6,7 +6,7 @@ FILE /anonymousFunction.kt FUN local final fun (): kotlin.Unit BLOCK_BODY CALL 'println(): Unit' type=kotlin.Unit origin=null - CALLABLE_REFERENCE '(): Unit' type=() -> kotlin.Unit origin=ANONYMOUS_FUNCTION + FUNCTION_REFERENCE '(): Unit' type=() -> kotlin.Unit origin=ANONYMOUS_FUNCTION FUN DEFAULT_PROPERTY_ACCESSOR public fun (): () -> kotlin.Unit BLOCK_BODY RETURN type=kotlin.Nothing from='(): () -> Unit' diff --git a/compiler/testData/ir/irText/lambdas/destructuringInLambda.txt b/compiler/testData/ir/irText/lambdas/destructuringInLambda.txt index 42f9e25c155..8dc3a12df85 100644 --- a/compiler/testData/ir/irText/lambdas/destructuringInLambda.txt +++ b/compiler/testData/ir/irText/lambdas/destructuringInLambda.txt @@ -1,5 +1,6 @@ FILE /destructuringInLambda.kt CLASS CLASS A + $new: VALUE_PARAMETER CONSTRUCTOR public constructor A(x: kotlin.Int, y: kotlin.Int) VALUE_PARAMETER value-parameter x: kotlin.Int VALUE_PARAMETER value-parameter y: kotlin.Int @@ -142,7 +143,7 @@ FILE /destructuringInLambda.kt CALL 'plus(Int): Int' type=kotlin.Int origin=PLUS $this: CONST Int type=kotlin.Int value='42' other: GET_VAR 'y: Int' type=kotlin.Int origin=null - CALLABLE_REFERENCE '(A): Int' type=(A) -> kotlin.Int origin=LAMBDA + FUNCTION_REFERENCE '(A): Int' type=(A) -> kotlin.Int origin=LAMBDA FUN DEFAULT_PROPERTY_ACCESSOR public fun (): (A) -> kotlin.Int BLOCK_BODY RETURN type=kotlin.Nothing from='(): (A) -> Int' diff --git a/compiler/testData/ir/irText/lambdas/extensionLambda.txt b/compiler/testData/ir/irText/lambdas/extensionLambda.txt index 36878a07493..c50b322b47a 100644 --- a/compiler/testData/ir/irText/lambdas/extensionLambda.txt +++ b/compiler/testData/ir/irText/lambdas/extensionLambda.txt @@ -13,4 +13,4 @@ FILE /extensionLambda.kt RETURN type=kotlin.Nothing from='() on String: Int' CALL '(): Int' type=kotlin.Int origin=GET_PROPERTY $this: GET_VAR '() on String: Int>' type=kotlin.String origin=null - CALLABLE_REFERENCE '() on String: Int' type=kotlin.String.() -> kotlin.Int origin=LAMBDA + FUNCTION_REFERENCE '() on String: Int' type=kotlin.String.() -> kotlin.Int origin=LAMBDA diff --git a/compiler/testData/ir/irText/lambdas/justLambda.txt b/compiler/testData/ir/irText/lambdas/justLambda.txt index 69fd6d6b588..76e838cf598 100644 --- a/compiler/testData/ir/irText/lambdas/justLambda.txt +++ b/compiler/testData/ir/irText/lambdas/justLambda.txt @@ -7,7 +7,7 @@ FILE /justLambda.kt BLOCK_BODY RETURN type=kotlin.Nothing from='(): Int' CONST Int type=kotlin.Int value='42' - CALLABLE_REFERENCE '(): Int' type=() -> kotlin.Int origin=LAMBDA + FUNCTION_REFERENCE '(): Int' type=() -> kotlin.Int origin=LAMBDA FUN DEFAULT_PROPERTY_ACCESSOR public fun (): () -> kotlin.Int BLOCK_BODY RETURN type=kotlin.Nothing from='(): () -> Int' @@ -20,7 +20,7 @@ FILE /justLambda.kt BLOCK_BODY RETURN type=kotlin.Nothing from='(): Unit' GET_OBJECT 'Unit' type=kotlin.Unit - CALLABLE_REFERENCE '(): Unit' type=() -> kotlin.Unit origin=LAMBDA + FUNCTION_REFERENCE '(): Unit' type=() -> kotlin.Unit origin=LAMBDA FUN DEFAULT_PROPERTY_ACCESSOR public fun (): () -> kotlin.Unit BLOCK_BODY RETURN type=kotlin.Nothing from='(): () -> Unit' diff --git a/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.txt b/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.txt index 3b445662b76..e08769e1cc8 100644 --- a/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.txt +++ b/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.txt @@ -1,5 +1,6 @@ FILE /multipleImplicitReceivers.kt CLASS OBJECT A + $new: VALUE_PARAMETER CONSTRUCTOR private constructor A() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -8,6 +9,7 @@ FILE /multipleImplicitReceivers.kt FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String CLASS OBJECT B + $new: VALUE_PARAMETER CONSTRUCTOR private constructor B() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -73,6 +75,6 @@ FILE /multipleImplicitReceivers.kt $receiver: CALL '() on A: B' type=B origin=GET_PROPERTY $this: GET_VAR '() on IFoo: Int>' type=IFoo origin=null $receiver: GET_VAR '() on A: Int>' type=A origin=null - CALLABLE_REFERENCE '() on IInvoke: Int' type=IInvoke.() -> kotlin.Int origin=LAMBDA - CALLABLE_REFERENCE '() on IFoo: Int' type=IFoo.() -> kotlin.Int origin=LAMBDA - CALLABLE_REFERENCE '() on A: Int' type=A.() -> kotlin.Int origin=LAMBDA + FUNCTION_REFERENCE '() on IInvoke: Int' type=IInvoke.() -> kotlin.Int origin=LAMBDA + FUNCTION_REFERENCE '() on IFoo: Int' type=IFoo.() -> kotlin.Int origin=LAMBDA + FUNCTION_REFERENCE '() on A: Int' type=A.() -> kotlin.Int origin=LAMBDA diff --git a/compiler/testData/ir/irText/lambdas/nonLocalReturn.txt b/compiler/testData/ir/irText/lambdas/nonLocalReturn.txt index 4dae5eac662..a8cacf6ea57 100644 --- a/compiler/testData/ir/irText/lambdas/nonLocalReturn.txt +++ b/compiler/testData/ir/irText/lambdas/nonLocalReturn.txt @@ -8,7 +8,7 @@ FILE /nonLocalReturn.kt BLOCK_BODY RETURN type=kotlin.Nothing from='test0(): Unit' GET_OBJECT 'Unit' type=kotlin.Unit - CALLABLE_REFERENCE '(): Nothing' type=() -> kotlin.Nothing origin=LAMBDA + FUNCTION_REFERENCE '(): Nothing' type=() -> kotlin.Nothing origin=LAMBDA FUN public fun test1(): kotlin.Unit BLOCK_BODY CALL 'run(() -> Unit): Unit' type=kotlin.Unit origin=null @@ -18,7 +18,7 @@ FILE /nonLocalReturn.kt BLOCK_BODY RETURN type=kotlin.Nothing from='(): Unit' GET_OBJECT 'Unit' type=kotlin.Unit - CALLABLE_REFERENCE '(): Unit' type=() -> kotlin.Unit origin=LAMBDA + FUNCTION_REFERENCE '(): Unit' type=() -> kotlin.Unit origin=LAMBDA FUN public fun test2(): kotlin.Unit BLOCK_BODY CALL 'run(() -> Unit): Unit' type=kotlin.Unit origin=null @@ -28,7 +28,7 @@ FILE /nonLocalReturn.kt BLOCK_BODY RETURN type=kotlin.Nothing from='(): Unit' GET_OBJECT 'Unit' type=kotlin.Unit - CALLABLE_REFERENCE '(): Unit' type=() -> kotlin.Unit origin=LAMBDA + FUNCTION_REFERENCE '(): Unit' type=() -> kotlin.Unit origin=LAMBDA FUN public fun testLrmFoo1(ints: kotlin.collections.List): kotlin.Unit VALUE_PARAMETER value-parameter ints: kotlin.collections.List BLOCK_BODY @@ -49,7 +49,7 @@ FILE /nonLocalReturn.kt RETURN type=kotlin.Nothing from='(Int): Unit' CALL 'print(Int): Unit' type=kotlin.Unit origin=null message: GET_VAR 'value-parameter it: Int' type=kotlin.Int origin=null - CALLABLE_REFERENCE '(Int): Unit' type=(kotlin.Int) -> kotlin.Unit origin=LAMBDA + FUNCTION_REFERENCE '(Int): Unit' type=(kotlin.Int) -> kotlin.Unit origin=LAMBDA FUN public fun testLrmFoo2(ints: kotlin.collections.List): kotlin.Unit VALUE_PARAMETER value-parameter ints: kotlin.collections.List BLOCK_BODY @@ -70,4 +70,4 @@ FILE /nonLocalReturn.kt RETURN type=kotlin.Nothing from='(Int): Unit' CALL 'print(Int): Unit' type=kotlin.Unit origin=null message: GET_VAR 'value-parameter it: Int' type=kotlin.Int origin=null - CALLABLE_REFERENCE '(Int): Unit' type=(kotlin.Int) -> kotlin.Unit origin=LAMBDA + FUNCTION_REFERENCE '(Int): Unit' type=(kotlin.Int) -> kotlin.Unit origin=LAMBDA diff --git a/compiler/testData/ir/irText/lambdas/samAdapter.txt b/compiler/testData/ir/irText/lambdas/samAdapter.txt index 4aba26e966d..28550aa3f3a 100644 --- a/compiler/testData/ir/irText/lambdas/samAdapter.txt +++ b/compiler/testData/ir/irText/lambdas/samAdapter.txt @@ -9,6 +9,6 @@ FILE /samAdapter.kt RETURN type=kotlin.Nothing from='(): Unit' CALL 'println(Any?): Unit' type=kotlin.Unit origin=null message: CONST String type=kotlin.String value='Hello, world!' - CALLABLE_REFERENCE '(): Unit' type=() -> kotlin.Unit origin=LAMBDA + FUNCTION_REFERENCE '(): Unit' type=() -> kotlin.Unit origin=LAMBDA CALL 'run(): Unit' type=kotlin.Unit origin=null $this: GET_VAR 'hello: Runnable' type=java.lang.Runnable origin=null diff --git a/compiler/testData/ir/irText/regressions/integerCoercionToT.txt b/compiler/testData/ir/irText/regressions/integerCoercionToT.txt index e69acee1a58..cfcb6a0728b 100644 --- a/compiler/testData/ir/irText/regressions/integerCoercionToT.txt +++ b/compiler/testData/ir/irText/regressions/integerCoercionToT.txt @@ -10,6 +10,7 @@ FILE /integerCoercionToT.kt RETURN type=kotlin.Nothing from='reinterpret() on CPointed: T' CALL 'TODO(): Nothing' type=kotlin.Nothing origin=null CLASS CLASS CInt32VarX + $new: VALUE_PARAMETER TYPE_PARAMETER CONSTRUCTOR public constructor CInt32VarX() TYPE_PARAMETER @@ -31,6 +32,7 @@ FILE /integerCoercionToT.kt VALUE_PARAMETER value-parameter value: T_INT BLOCK_BODY CLASS CLASS IdType + $new: VALUE_PARAMETER CONSTRUCTOR public constructor IdType(value: kotlin.Int) VALUE_PARAMETER value-parameter value: kotlin.Int BLOCK_BODY diff --git a/compiler/testData/ir/irText/singletons/companion.txt b/compiler/testData/ir/irText/singletons/companion.txt index 8542efbf6de..e8907a9f181 100644 --- a/compiler/testData/ir/irText/singletons/companion.txt +++ b/compiler/testData/ir/irText/singletons/companion.txt @@ -1,5 +1,6 @@ FILE /companion.kt CLASS CLASS Z + $new: VALUE_PARAMETER CONSTRUCTOR public constructor Z() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -10,6 +11,7 @@ FILE /companion.kt CALL 'test(): Unit' type=kotlin.Unit origin=null $this: GET_OBJECT 'companion object of Z' type=Z.Companion CLASS OBJECT companion object of Z + $new: VALUE_PARAMETER CONSTRUCTOR private constructor Companion() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/testData/ir/irText/singletons/enumEntry.txt b/compiler/testData/ir/irText/singletons/enumEntry.txt index 53e2911531c..a475e9d12c1 100644 --- a/compiler/testData/ir/irText/singletons/enumEntry.txt +++ b/compiler/testData/ir/irText/singletons/enumEntry.txt @@ -1,5 +1,6 @@ FILE /enumEntry.kt CLASS ENUM_CLASS Z + $new: VALUE_PARAMETER CONSTRUCTOR private constructor Z() BLOCK_BODY ENUM_CONSTRUCTOR_CALL 'constructor Enum(String, Int)' @@ -7,6 +8,7 @@ FILE /enumEntry.kt ENUM_ENTRY enum entry ENTRY init: ENUM_CONSTRUCTOR_CALL 'constructor ENTRY()' class: CLASS ENUM_ENTRY ENTRY + $new: VALUE_PARAMETER CONSTRUCTOR private constructor ENTRY() BLOCK_BODY ENUM_CONSTRUCTOR_CALL 'constructor Z()' @@ -15,6 +17,7 @@ FILE /enumEntry.kt $this: VALUE_PARAMETER BLOCK_BODY CLASS CLASS A + $new: VALUE_PARAMETER CONSTRUCTOR public constructor A() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -24,6 +27,31 @@ FILE /enumEntry.kt BLOCK_BODY CALL 'test(): Unit' type=kotlin.Unit origin=null $this: GET_ENUM 'ENTRY' type=Z.ENTRY + FUN FAKE_OVERRIDE public open override fun equals(other: kotlin.Any?): kotlin.Boolean + FUN FAKE_OVERRIDE public open override fun hashCode(): kotlin.Int + FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String + FUN FAKE_OVERRIDE protected final override fun clone(): kotlin.Any + FUN FAKE_OVERRIDE protected/*protected and package*/ final override fun finalize(): kotlin.Unit + FUN FAKE_OVERRIDE public final override fun getDeclaringClass(): java.lang.Class! + FUN FAKE_OVERRIDE public final override fun compareTo(other: Z): kotlin.Int + FUN FAKE_OVERRIDE public final override fun equals(other: kotlin.Any?): kotlin.Boolean + FUN FAKE_OVERRIDE public final override fun hashCode(): kotlin.Int + PROPERTY FAKE_OVERRIDE public final override val name: kotlin.String + FUN FAKE_OVERRIDE public final override fun (): kotlin.String + PROPERTY FAKE_OVERRIDE public final override val ordinal: kotlin.Int + FUN FAKE_OVERRIDE public final override fun (): kotlin.Int + FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String + FUN FAKE_OVERRIDE protected final override fun clone(): kotlin.Any + FUN FAKE_OVERRIDE protected/*protected and package*/ final override fun finalize(): kotlin.Unit + FUN FAKE_OVERRIDE public final override fun getDeclaringClass(): java.lang.Class! + FUN FAKE_OVERRIDE public final override fun compareTo(other: Z): kotlin.Int + FUN FAKE_OVERRIDE public final override fun equals(other: kotlin.Any?): kotlin.Boolean + FUN FAKE_OVERRIDE public final override fun hashCode(): kotlin.Int + PROPERTY FAKE_OVERRIDE public final override val name: kotlin.String + FUN FAKE_OVERRIDE public final override fun (): kotlin.String + PROPERTY FAKE_OVERRIDE public final override val ordinal: kotlin.Int + FUN FAKE_OVERRIDE public final override fun (): kotlin.Int + FUN FAKE_OVERRIDE public open override fun toString(): kotlin.String FUN ENUM_CLASS_SPECIAL_MEMBER public final fun values(): kotlin.Array SYNTHETIC_BODY kind=ENUM_VALUES FUN ENUM_CLASS_SPECIAL_MEMBER public final fun valueOf(value: kotlin.String): Z diff --git a/compiler/testData/ir/irText/singletons/object.txt b/compiler/testData/ir/irText/singletons/object.txt index 07135d348c6..c0415dd5def 100644 --- a/compiler/testData/ir/irText/singletons/object.txt +++ b/compiler/testData/ir/irText/singletons/object.txt @@ -1,5 +1,6 @@ FILE /object.kt CLASS OBJECT Z + $new: VALUE_PARAMETER CONSTRUCTOR private constructor Z() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' @@ -8,6 +9,7 @@ FILE /object.kt $this: VALUE_PARAMETER BLOCK_BODY CLASS CLASS A + $new: VALUE_PARAMETER CONSTRUCTOR public constructor A() BLOCK_BODY DELEGATING_CONSTRUCTOR_CALL 'constructor Any()' diff --git a/compiler/tests/org/jetbrains/kotlin/ir/AbstractIrTextTestCase.kt b/compiler/tests/org/jetbrains/kotlin/ir/AbstractIrTextTestCase.kt index fbda1f4c7f6..6bd40ecef8b 100644 --- a/compiler/tests/org/jetbrains/kotlin/ir/AbstractIrTextTestCase.kt +++ b/compiler/tests/org/jetbrains/kotlin/ir/AbstractIrTextTestCase.kt @@ -24,7 +24,7 @@ import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.IrFile import org.jetbrains.kotlin.ir.declarations.IrFunction import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer -import org.jetbrains.kotlin.ir.util.DeepCopyIrTree +import org.jetbrains.kotlin.ir.util.deepCopy import org.jetbrains.kotlin.ir.util.dump import org.jetbrains.kotlin.ir.util.dumpTreesFromLineNumber import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid @@ -61,7 +61,7 @@ abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() { verify(irFile, irFileDump) // Check that deep copy produces an equivalent result - val irFileCopy = irFile.transform(DeepCopyIrTree(), null) + val irFileCopy = irFile.deepCopy() val copiedTrees = irFileCopy.dumpTreesFromLineNumber(irTreeFileLabel.lineNumber) TestCase.assertEquals("IR dump mismatch after deep copy", actualTrees, copiedTrees) verify(irFileCopy, irFileCopy.dump())