From f56bbd68d7f3015fbb9fed2558f06ac02742bb28 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 1 Jun 2023 17:39:21 +0200 Subject: [PATCH] Kapt+JVM_IR: generate stub bodies for property accessors Similarly to how stub bodies are generated for functions in the kapt mode (see `BodyGenerator.generateFunctionBody`). This is more useful then not generating bodies at all, because otherwise in the -Xjvm-default=all/all-compatibility modes it would be difficult to differentiate functions with default implementations from the ones without (because they all would lack body and thus be generated as abstract into the resulting Java stub). The effect of this change is pretty minor, so there's no YT issue. But it fixes light analysis tests run with JVM_IR in `codegen/box/jvm8/defaults`, because now there's no difference between full analysis and light analysis for interfaces with default methods in new modes. --- .../psi2ir/generators/FunctionGenerator.kt | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) 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 c9473a76f24..7eb94e41667 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 @@ -129,14 +129,12 @@ internal class FunctionGenerator(declarationGenerator: DeclarationGenerator) : D irAccessor, ktAccessor ?: ktProperty, ktProperty.receiverTypeReference, ktProperty.contextReceivers.mapNotNull { it.typeReference() } ) - if (context.configuration.generateBodies) { - val ktBodyExpression = ktAccessor?.bodyExpression - irAccessor.body = - if (ktBodyExpression != null) - createBodyGenerator(irAccessor.symbol).generateFunctionBody(ktBodyExpression) - else - generateDefaultAccessorBody(descriptor, irAccessor) - } + val ktBodyExpression = ktAccessor?.bodyExpression + irAccessor.body = + if (ktBodyExpression != null) + createBodyGenerator(irAccessor.symbol).generateFunctionBody(ktBodyExpression) + else + generateDefaultAccessorBody(descriptor, irAccessor) } fun generateDefaultAccessorForPrimaryConstructorParameter( @@ -154,7 +152,7 @@ internal class FunctionGenerator(declarationGenerator: DeclarationGenerator) : D accessor: PropertyAccessorDescriptor, irAccessor: IrSimpleFunction ): IrBlockBody? = - if (accessor.modality == Modality.ABSTRACT || accessor.correspondingProperty.isExpect) + if (accessor.modality == Modality.ABSTRACT || accessor.correspondingProperty.isExpect || context.configuration.skipBodies) null else when (accessor) {