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
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
class Test {
|
||||
private val foo = Example.FOO
|
||||
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
public final class Test {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
private final Test.Companion.Example foo;
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final Test.Companion Companion = null;
|
||||
|
||||
public Test() {
|
||||
super();
|
||||
}
|
||||
|
||||
@kotlin.Metadata()
|
||||
public static final class Companion {
|
||||
|
||||
private Companion() {
|
||||
super();
|
||||
}
|
||||
|
||||
@kotlin.Metadata()
|
||||
public static enum Example {
|
||||
/*public static final*/ FOO /* = new Example() */;
|
||||
|
||||
Example() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
public final class Test2 {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
private final Test2.Amigo.Example foo;
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final Test2.Amigo Amigo = null;
|
||||
|
||||
public Test2() {
|
||||
super();
|
||||
}
|
||||
|
||||
@kotlin.Metadata()
|
||||
public static final class Amigo {
|
||||
|
||||
private Amigo() {
|
||||
super();
|
||||
}
|
||||
|
||||
@kotlin.Metadata()
|
||||
public static enum Example {
|
||||
/*public static final*/ FOO /* = new Example() */;
|
||||
|
||||
Example() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
public final class Test3 {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
private final Test3.Amigo.Example foo = null;
|
||||
|
||||
public Test3() {
|
||||
super();
|
||||
}
|
||||
|
||||
@kotlin.Metadata()
|
||||
public static final class Amigo {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final Test3.Amigo INSTANCE = null;
|
||||
|
||||
private Amigo() {
|
||||
super();
|
||||
}
|
||||
|
||||
@kotlin.Metadata()
|
||||
public static enum Example {
|
||||
/*public static final*/ FOO /* = new Example() */;
|
||||
|
||||
Example() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
public final class Test4 {
|
||||
private final int foo = 0;
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final Test4.Companion Companion = null;
|
||||
|
||||
public Test4() {
|
||||
super();
|
||||
}
|
||||
|
||||
@kotlin.Metadata()
|
||||
public static final class Companion {
|
||||
|
||||
private Companion() {
|
||||
super();
|
||||
}
|
||||
|
||||
@kotlin.Metadata()
|
||||
public static final class Foo {
|
||||
public static final int constProperty = 1;
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final Test4.Companion.Foo INSTANCE = null;
|
||||
|
||||
private Foo() {
|
||||
super();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////
|
||||
|
||||
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
public final class Test5 {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
private final Test5.Amigos.Companion.Goo.Example foo;
|
||||
|
||||
public Test5() {
|
||||
super();
|
||||
}
|
||||
|
||||
@kotlin.Metadata()
|
||||
public static final class Amigos {
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public static final Test5.Amigos.Companion Companion = null;
|
||||
|
||||
public Amigos() {
|
||||
super();
|
||||
}
|
||||
|
||||
@kotlin.Metadata()
|
||||
public static final class Companion {
|
||||
|
||||
private Companion() {
|
||||
super();
|
||||
}
|
||||
|
||||
@kotlin.Metadata()
|
||||
public static final class Goo {
|
||||
|
||||
public Goo() {
|
||||
super();
|
||||
}
|
||||
|
||||
@kotlin.Metadata()
|
||||
public static enum Example {
|
||||
/*public static final*/ FOO /* = new Example() */;
|
||||
|
||||
Example() {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
class GenericRawSignatures {
|
||||
fun <T> genericFun(): T? = null
|
||||
fun nonGenericFun(): String? = null
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
fun crashMe(values: List<String>): String {
|
||||
throw UnsupportedOperationException()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
import java.util.Date
|
||||
|
||||
fun Date(double: Double): Date = Date(double.times(1000).toLong())
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
interface Intf {
|
||||
fun foo(abc: String)
|
||||
|
||||
|
||||
-2
@@ -1,5 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
class CrashMe {
|
||||
val resources = 1
|
||||
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
class Test {
|
||||
class Nested {
|
||||
class NestedNested
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
open class Test {
|
||||
|
||||
open fun getTestNoSuspend(text: String): String {
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
import java.lang.System;
|
||||
|
||||
@kotlin.Metadata()
|
||||
public class Test {
|
||||
|
||||
public Test() {
|
||||
super();
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public java.lang.String getTestNoSuspend(@org.jetbrains.annotations.NotNull()
|
||||
java.lang.String text) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.Nullable()
|
||||
public java.lang.Object getTest(@org.jetbrains.annotations.NotNull()
|
||||
java.lang.String text, @org.jetbrains.annotations.NotNull()
|
||||
kotlin.coroutines.Continuation<? super java.lang.String> $completion) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.NotNull()
|
||||
public java.lang.String getTestNoSuspendInvalid(@org.jetbrains.annotations.NotNull()
|
||||
java.lang.String p0_55085957) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@org.jetbrains.annotations.Nullable()
|
||||
public java.lang.Object getTestInvalid(@org.jetbrains.annotations.NotNull()
|
||||
java.lang.String p0_55085957, @org.jetbrains.annotations.NotNull()
|
||||
kotlin.coroutines.Continuation<? super java.lang.String> $completion) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,3 @@
|
||||
// IGNORE_BACKEND: JVM_IR
|
||||
|
||||
package test
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user