JVM IR: do not depend on StubGeneratorExtensions in backend
Move most of the implementation from JvmGeneratorExtensions to JvmGeneratorExtensionsImpl. The latter implements StubGeneratorExtensions from psi2ir, and doing so helps to remove direct dependency on this part of psi2ir from backend.
This commit is contained in:
+16
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
|
||||
interface JvmGeneratorExtensions {
|
||||
val classNameOverride: MutableMap<IrClass, JvmClassName>
|
||||
|
||||
val rawTypeAnnotationConstructor: IrConstructor?
|
||||
}
|
||||
+9
-21
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
@@ -30,7 +30,6 @@ import org.jetbrains.kotlin.load.java.sam.JavaSingleAbstractMethodUtils
|
||||
import org.jetbrains.kotlin.load.java.typeEnhancement.hasEnhancedNullability
|
||||
import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtPureClassOrObject
|
||||
import org.jetbrains.kotlin.psi.psiUtil.pureEndOffset
|
||||
import org.jetbrains.kotlin.psi.psiUtil.pureStartOffset
|
||||
@@ -49,8 +48,8 @@ import org.jetbrains.kotlin.serialization.deserialization.descriptors.Deserializ
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.types.typeUtil.replaceAnnotations
|
||||
|
||||
class JvmGeneratorExtensions(private val generateFacades: Boolean = true) : GeneratorExtensions() {
|
||||
val classNameOverride = mutableMapOf<IrClass, JvmClassName>()
|
||||
class JvmGeneratorExtensionsImpl(private val generateFacades: Boolean = true) : GeneratorExtensions(), JvmGeneratorExtensions {
|
||||
override val classNameOverride: MutableMap<IrClass, JvmClassName> = mutableMapOf()
|
||||
|
||||
override val samConversion: SamConversion
|
||||
get() = JvmSamConversion
|
||||
@@ -162,32 +161,21 @@ class JvmGeneratorExtensions(private val generateFacades: Boolean = true) : Gene
|
||||
}
|
||||
|
||||
private val flexibleNullabilityAnnotationClass =
|
||||
createSpecialAnnotationClass(FLEXIBLE_NULLABILITY_ANNOTATION_FQ_NAME, kotlinIrInternalPackage)
|
||||
createSpecialAnnotationClass(JvmSymbols.FLEXIBLE_NULLABILITY_ANNOTATION_FQ_NAME, kotlinIrInternalPackage)
|
||||
|
||||
private val rawTypeAnnotationClass =
|
||||
createSpecialAnnotationClass(RAW_TYPE_ANNOTATION_FQ_NAME, kotlinIrInternalPackage)
|
||||
createSpecialAnnotationClass(JvmSymbols.RAW_TYPE_ANNOTATION_FQ_NAME, kotlinIrInternalPackage)
|
||||
|
||||
// NB Class 'kotlin.jvm.internal.EnhancedNullability' doesn't exist anywhere in descriptors or in bytecode
|
||||
private val enhancedNullabilityAnnotationClass =
|
||||
createSpecialAnnotationClass(ENHANCED_NULLABILITY_ANNOTATION_FQ_NAME, kotlinJvmInternalPackage)
|
||||
createSpecialAnnotationClass(JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION, kotlinJvmInternalPackage)
|
||||
|
||||
override val flexibleNullabilityAnnotationConstructor: IrConstructor? =
|
||||
override val flexibleNullabilityAnnotationConstructor: IrConstructor =
|
||||
flexibleNullabilityAnnotationClass.constructors.single()
|
||||
|
||||
override val enhancedNullabilityAnnotationConstructor: IrConstructor? =
|
||||
override val enhancedNullabilityAnnotationConstructor: IrConstructor =
|
||||
enhancedNullabilityAnnotationClass.constructors.single()
|
||||
|
||||
override val rawTypeAnnotationConstructor: IrConstructor? =
|
||||
override val rawTypeAnnotationConstructor: IrConstructor =
|
||||
rawTypeAnnotationClass.constructors.single()
|
||||
|
||||
companion object {
|
||||
val FLEXIBLE_NULLABILITY_ANNOTATION_FQ_NAME =
|
||||
IrBuiltIns.KOTLIN_INTERNAL_IR_FQN.child(Name.identifier("FlexibleNullability"))
|
||||
|
||||
val ENHANCED_NULLABILITY_ANNOTATION_FQ_NAME: FqName =
|
||||
JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION
|
||||
|
||||
val RAW_TYPE_ANNOTATION_FQ_NAME =
|
||||
IrBuiltIns.KOTLIN_INTERNAL_IR_FQN.child(Name.identifier("RawType"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ class JvmIrCodegenFactory(private val phaseConfig: PhaseConfig) : CodegenFactory
|
||||
|
||||
@JvmOverloads
|
||||
fun convertToIr(state: GenerationState, files: Collection<KtFile>, ignoreErrors: Boolean = false): JvmIrBackendInput {
|
||||
val extensions = JvmGeneratorExtensions()
|
||||
val extensions = JvmGeneratorExtensionsImpl()
|
||||
val mangler = JvmManglerDesc(MainFunctionDetector(state.bindingContext, state.languageVersionSettings))
|
||||
val psi2ir = Psi2IrTranslator(state.languageVersionSettings, Psi2IrConfiguration(ignoreErrors))
|
||||
val symbolTable = SymbolTable(JvmIdSignatureDescriptor(mangler), IrFactoryImpl, JvmNameProvider)
|
||||
@@ -217,7 +217,7 @@ class JvmIrCodegenFactory(private val phaseConfig: PhaseConfig) : CodegenFactory
|
||||
state: GenerationState,
|
||||
irModuleFragment: IrModuleFragment,
|
||||
symbolTable: SymbolTable,
|
||||
extensions: JvmGeneratorExtensions,
|
||||
extensions: JvmGeneratorExtensionsImpl,
|
||||
backendExtension: JvmBackendExtension,
|
||||
notifyCodegenStart: () -> Unit
|
||||
) {
|
||||
@@ -232,7 +232,7 @@ class JvmIrCodegenFactory(private val phaseConfig: PhaseConfig) : CodegenFactory
|
||||
fun configureBuiltInsAndGenerateIrProvidersInFrontendIRMode(
|
||||
irModuleFragment: IrModuleFragment,
|
||||
symbolTable: SymbolTable,
|
||||
extensions: JvmGeneratorExtensions
|
||||
extensions: JvmGeneratorExtensionsImpl,
|
||||
): List<IrProvider> {
|
||||
irModuleFragment.irBuiltins.functionFactory = IrFunctionFactory(irModuleFragment.irBuiltins, symbolTable)
|
||||
return generateTypicalIrProviderList(
|
||||
|
||||
@@ -24,9 +24,11 @@ import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
||||
import org.jetbrains.kotlin.ir.declarations.IrPackageFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.JVM_INLINE_ANNOTATION_FQ_NAME
|
||||
@@ -665,10 +667,6 @@ class JvmSymbols(
|
||||
returnType = irBuiltIns.anyType
|
||||
}.symbol
|
||||
|
||||
val flexibleNullabilityAnnotationFqName = JvmGeneratorExtensions.FLEXIBLE_NULLABILITY_ANNOTATION_FQ_NAME
|
||||
val enhancedNullabilityAnnotationFqName = JvmGeneratorExtensions.ENHANCED_NULLABILITY_ANNOTATION_FQ_NAME
|
||||
val rawTypeAnnotationFQN = JvmGeneratorExtensions.RAW_TYPE_ANNOTATION_FQ_NAME
|
||||
|
||||
private val collectionToArrayClass: IrClassSymbol = createClass(FqName("kotlin.jvm.internal.CollectionToArray")) { klass ->
|
||||
klass.origin = JvmLoweredDeclarationOrigin.TO_ARRAY
|
||||
|
||||
@@ -866,6 +864,14 @@ class JvmSymbols(
|
||||
|
||||
val runSuspendFunction: IrSimpleFunctionSymbol =
|
||||
kotlinCoroutinesJvmInternalRunSuspendKt.functionByName("runSuspend")
|
||||
|
||||
companion object {
|
||||
val FLEXIBLE_NULLABILITY_ANNOTATION_FQ_NAME =
|
||||
IrBuiltIns.KOTLIN_INTERNAL_IR_FQN.child(Name.identifier("FlexibleNullability"))
|
||||
|
||||
val RAW_TYPE_ANNOTATION_FQ_NAME =
|
||||
IrBuiltIns.KOTLIN_INTERNAL_IR_FQN.child(Name.identifier("RawType"))
|
||||
}
|
||||
}
|
||||
|
||||
private fun IrClassSymbol.functionByName(name: String): IrSimpleFunctionSymbol =
|
||||
|
||||
+6
-5
@@ -20,8 +20,8 @@ import org.jetbrains.annotations.NotNull
|
||||
import org.jetbrains.annotations.Nullable
|
||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmGeneratorExtensions
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmSymbols
|
||||
import org.jetbrains.kotlin.builtins.StandardNames
|
||||
import org.jetbrains.kotlin.codegen.AsmUtil
|
||||
import org.jetbrains.kotlin.codegen.TypeAnnotationCollector
|
||||
@@ -36,6 +36,7 @@ import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker
|
||||
@@ -303,9 +304,9 @@ abstract class AnnotationCodegen(
|
||||
)
|
||||
|
||||
internal val internalAnnotations = setOf(
|
||||
JvmGeneratorExtensions.FLEXIBLE_NULLABILITY_ANNOTATION_FQ_NAME,
|
||||
JvmGeneratorExtensions.ENHANCED_NULLABILITY_ANNOTATION_FQ_NAME,
|
||||
JvmGeneratorExtensions.RAW_TYPE_ANNOTATION_FQ_NAME
|
||||
JvmSymbols.FLEXIBLE_NULLABILITY_ANNOTATION_FQ_NAME,
|
||||
JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION,
|
||||
JvmSymbols.RAW_TYPE_ANNOTATION_FQ_NAME
|
||||
)
|
||||
|
||||
private fun getRetentionPolicy(irClass: IrClass): RetentionPolicy {
|
||||
@@ -393,7 +394,7 @@ private fun IrClass.getAnnotationRetention(): KotlinRetention? {
|
||||
}
|
||||
|
||||
private fun IrType.isNullabilityFlexible(): Boolean =
|
||||
hasAnnotation(JvmGeneratorExtensions.FLEXIBLE_NULLABILITY_ANNOTATION_FQ_NAME)
|
||||
hasAnnotation(JvmSymbols.FLEXIBLE_NULLABILITY_ANNOTATION_FQ_NAME)
|
||||
|
||||
// To be generalized to IrMemberAccessExpression as soon as properties get symbols.
|
||||
private fun IrConstructorCall.getValueArgument(name: Name): IrExpression? {
|
||||
|
||||
+2
-2
@@ -9,8 +9,8 @@ import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.backend.common.ir.allOverridden
|
||||
import org.jetbrains.kotlin.backend.common.ir.ir2string
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmGeneratorExtensions
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmSymbols
|
||||
import org.jetbrains.kotlin.backend.jvm.lower.MultifileFacadeFileEntry
|
||||
import org.jetbrains.kotlin.builtins.StandardNames.FqNames
|
||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
@@ -375,7 +375,7 @@ val IrMemberAccessExpression<*>.psiElement: PsiElement?
|
||||
get() = (symbol.descriptor.original as? DeclarationDescriptorWithSource)?.psiElement
|
||||
|
||||
fun IrSimpleType.isRawType(): Boolean =
|
||||
hasAnnotation(JvmGeneratorExtensions.RAW_TYPE_ANNOTATION_FQ_NAME)
|
||||
hasAnnotation(JvmSymbols.RAW_TYPE_ANNOTATION_FQ_NAME)
|
||||
|
||||
internal fun classFileContainsMethod(classId: ClassId, function: IrFunction, context: JvmBackendContext): Boolean? {
|
||||
val originalSignature = context.methodSignatureMapper.mapSignatureWithGeneric(function).asmMethod
|
||||
|
||||
@@ -386,7 +386,7 @@ fun collectVisibleTypeParameters(scopeOwner: IrTypeParametersContainer): Set<IrT
|
||||
private fun JvmBackendContext.makeRawTypeAnnotation() =
|
||||
IrConstructorCallImpl.fromSymbolOwner(
|
||||
generatorExtensions.rawTypeAnnotationConstructor!!.constructedClassType,
|
||||
generatorExtensions.rawTypeAnnotationConstructor.symbol
|
||||
generatorExtensions.rawTypeAnnotationConstructor!!.symbol
|
||||
)
|
||||
|
||||
fun IrClass.rawType(context: JvmBackendContext): IrType =
|
||||
|
||||
+8
-3
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.backend.common.lower.SamEqualsHashCodeMethodsGenerat
|
||||
import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmBackendContext
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
||||
import org.jetbrains.kotlin.backend.jvm.JvmSymbols
|
||||
import org.jetbrains.kotlin.backend.jvm.ir.*
|
||||
import org.jetbrains.kotlin.backend.jvm.lower.indy.LambdaMetafactoryArguments
|
||||
import org.jetbrains.kotlin.backend.jvm.lower.indy.LambdaMetafactoryArgumentsBuilder
|
||||
@@ -26,11 +27,15 @@ import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrClassReferenceImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrFunctionReferenceImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrGetObjectValueImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.name.SpecialNames
|
||||
|
||||
@@ -221,8 +226,8 @@ internal class FunctionReferenceLowering(private val context: JvmBackendContext)
|
||||
|
||||
private val specialNullabilityAnnotationsFqNames =
|
||||
setOf(
|
||||
context.ir.symbols.flexibleNullabilityAnnotationFqName,
|
||||
context.ir.symbols.enhancedNullabilityAnnotationFqName
|
||||
JvmSymbols.FLEXIBLE_NULLABILITY_ANNOTATION_FQ_NAME,
|
||||
JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION,
|
||||
)
|
||||
|
||||
private fun wrapWithIndySamConversion(
|
||||
|
||||
+2
-1
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.addIfNotNull
|
||||
|
||||
@@ -417,7 +418,7 @@ internal class LambdaMetafactoryArgumentsBuilder(
|
||||
if (adapteeType.isPrimitiveType()) {
|
||||
return if (
|
||||
expectedType.isPrimitiveType() &&
|
||||
!expectedType.hasAnnotation(context.ir.symbols.enhancedNullabilityAnnotationFqName)
|
||||
!expectedType.hasAnnotation(JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION)
|
||||
)
|
||||
TypeAdaptationConstraint.KEEP_UNBOXED
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user