Psi2ir: support mode without generation of bodies
This is needed for kapt + JVM IR. #KT-49682
This commit is contained in:
@@ -53,12 +53,14 @@ interface CodegenFactory {
|
||||
val bindingContext: BindingContext,
|
||||
val languageVersionSettings: LanguageVersionSettings,
|
||||
val ignoreErrors: Boolean,
|
||||
val skipBodies: Boolean,
|
||||
) {
|
||||
companion object {
|
||||
fun fromGenerationState(state: GenerationState): IrConversionInput =
|
||||
with(state) {
|
||||
IrConversionInput(
|
||||
project, files, configuration, module, originalFrontendBindingContext, languageVersionSettings, ignoreErrors
|
||||
project, files, configuration, module, originalFrontendBindingContext, languageVersionSettings, ignoreErrors,
|
||||
skipBodies = !state.classBuilderMode.generateBodies
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -269,7 +269,8 @@ object KotlinToJVMBytecodeCompiler {
|
||||
result.moduleDescriptor,
|
||||
result.bindingContext,
|
||||
configuration.languageVersionSettings,
|
||||
false,
|
||||
ignoreErrors = false,
|
||||
skipBodies = false,
|
||||
)
|
||||
|
||||
val performanceManager = environment.configuration[CLIConfigurationKeys.PERF_MANAGER]
|
||||
|
||||
+8
-1
@@ -88,7 +88,14 @@ open class JvmIrCodegenFactory(
|
||||
val symbolTable = SymbolTable(signaturer, IrFactoryImpl)
|
||||
mangler to symbolTable
|
||||
}
|
||||
val psi2ir = Psi2IrTranslator(input.languageVersionSettings, Psi2IrConfiguration(input.ignoreErrors))
|
||||
val psi2ir = Psi2IrTranslator(
|
||||
input.languageVersionSettings,
|
||||
Psi2IrConfiguration(
|
||||
input.ignoreErrors,
|
||||
allowUnboundSymbols = false,
|
||||
input.skipBodies,
|
||||
)
|
||||
)
|
||||
val messageLogger = input.configuration[IrMessageLogger.IR_MESSAGE_LOGGER] ?: IrMessageLogger.None
|
||||
val psi2irContext = psi2ir.createGeneratorContext(
|
||||
input.module,
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ private class MoveOrCopyCompanionObjectFieldsLowering(val context: JvmBackendCon
|
||||
parent = newParent
|
||||
correspondingPropertySymbol = property.symbol
|
||||
annotations += oldField.annotations
|
||||
initializer = with(oldField.initializer!!) {
|
||||
initializer = oldField.initializer?.run {
|
||||
IrExpressionBodyImpl(startOffset, endOffset, (expression as IrConst<*>).shallowCopy())
|
||||
}
|
||||
|
||||
|
||||
@@ -18,5 +18,9 @@ package org.jetbrains.kotlin.psi2ir
|
||||
|
||||
class Psi2IrConfiguration(
|
||||
val ignoreErrors: Boolean = false,
|
||||
val allowUnboundSymbols: Boolean = false
|
||||
)
|
||||
val allowUnboundSymbols: Boolean = false,
|
||||
val skipBodies: Boolean = false,
|
||||
) {
|
||||
val generateBodies: Boolean
|
||||
get() = !skipBodies
|
||||
}
|
||||
|
||||
+3
-1
@@ -104,7 +104,9 @@ class DelegatedPropertyGenerator(declarationGenerator: DeclarationGenerator) : D
|
||||
accessorDescriptor
|
||||
).buildWithScope { irAccessor ->
|
||||
FunctionGenerator(declarationGenerator).generateFunctionParameterDeclarationsAndReturnType(irAccessor, ktProperty, null, emptyList())
|
||||
irAccessor.body = generateBody(irAccessor)
|
||||
if (context.configuration.generateBodies) {
|
||||
irAccessor.body = generateBody(irAccessor)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+10
-7
@@ -54,7 +54,8 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
|
||||
origin,
|
||||
getOrFail(BindingContext.FUNCTION, ktFunction)
|
||||
) {
|
||||
ktFunction.bodyExpression?.let { generateFunctionBody(it) }
|
||||
if (context.configuration.skipBodies) null
|
||||
else ktFunction.bodyExpression?.let { generateFunctionBody(it) }
|
||||
}
|
||||
|
||||
fun generateLambdaFunctionDeclaration(ktFunction: KtFunctionLiteral): IrSimpleFunction {
|
||||
@@ -131,12 +132,14 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
|
||||
irAccessor, ktAccessor ?: ktProperty, ktProperty.receiverTypeReference,
|
||||
ktProperty.contextReceivers.mapNotNull { it.typeReference() }
|
||||
)
|
||||
val ktBodyExpression = ktAccessor?.bodyExpression
|
||||
irAccessor.body =
|
||||
if (ktBodyExpression != null)
|
||||
createBodyGenerator(irAccessor.symbol).generateFunctionBody(ktBodyExpression)
|
||||
else
|
||||
generateDefaultAccessorBody(descriptor, irAccessor)
|
||||
if (context.configuration.generateBodies) {
|
||||
val ktBodyExpression = ktAccessor?.bodyExpression
|
||||
irAccessor.body =
|
||||
if (ktBodyExpression != null)
|
||||
createBodyGenerator(irAccessor.symbol).generateFunctionBody(ktBodyExpression)
|
||||
else
|
||||
generateDefaultAccessorBody(descriptor, irAccessor)
|
||||
}
|
||||
}
|
||||
|
||||
fun generateDefaultAccessorForPrimaryConstructorParameter(
|
||||
|
||||
+3
-2
@@ -76,7 +76,7 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
|
||||
): IrProperty {
|
||||
val irPropertyType = propertyDescriptor.type.toIrType()
|
||||
return generateSyntheticPropertyWithInitializer(ktDeclarationContainer, propertyDescriptor, generateSyntheticAccessors) {
|
||||
if (irValueParameter == null) null
|
||||
if (irValueParameter == null || context.configuration.skipBodies) null
|
||||
else {
|
||||
context.irFactory.createExpressionBody(
|
||||
IrGetValueImpl(
|
||||
@@ -205,7 +205,8 @@ class PropertyGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
|
||||
}
|
||||
}
|
||||
|
||||
declarationGenerator.generateInitializerBody(irField.symbol, ktInitializer)
|
||||
if (context.configuration.skipBodies) null
|
||||
else declarationGenerator.generateInitializerBody(irField.symbol, ktInitializer)
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user