Remove dependency on JVM specifics in serialization.common

Move handling of EnhancedNullability to JVM subclasses in
serialization.jvm. Looks like this was possible because of accidental
dependency of frontend on compiler.common.jvm introduced in 564d382b9d.

Also fix a minor typo in the file name typeEnhancementUtils.kt.
This commit is contained in:
Alexander Udalov
2021-05-05 19:20:03 +02:00
parent 7a42f603f2
commit 173e194dac
5 changed files with 27 additions and 16 deletions
@@ -12,9 +12,6 @@ dependencies {
implementation(project(":compiler:psi"))
compileOnly(project(":kotlin-reflect-api"))
// TODO: move usages of JvmAnnotationNames and hasEnhancedNullability to ir.serialization.jvm and remove this dependency.
implementation(project(":core:compiler.common.jvm"))
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
}
@@ -12,9 +12,7 @@ import org.jetbrains.kotlin.backend.common.serialization.mangle.collectForMangle
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.descriptors.IrImplementingDelegateDescriptor
import org.jetbrains.kotlin.ir.descriptors.IrPropertyDelegateDescriptor
import org.jetbrains.kotlin.load.java.typeEnhancement.hasEnhancedNullability
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext
import org.jetbrains.kotlin.types.typeUtil.isUnit
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
@@ -40,7 +38,7 @@ abstract class DescriptorMangleComputer(protected val builder: StringBuilder, pr
}
}
private fun StringBuilder.appendSignature(s: String) {
protected fun StringBuilder.appendSignature(s: String) {
if (mode.signature) {
append(s)
}
@@ -195,10 +193,7 @@ abstract class DescriptorMangleComputer(protected val builder: StringBuilder, pr
if (type.isMarkedNullable) tBuilder.appendSignature(MangleConstant.Q_MARK)
// Disambiguate between 'double' and '@NotNull java.lang.Double' types in mixed Java/Kotlin class hierarchies
if (SimpleClassicTypeSystemContext.hasEnhancedNullability(type)) {
tBuilder.appendSignature(MangleConstant.ENHANCED_NULLABILITY_MARK)
}
mangleTypePlatformSpecific(type, tBuilder)
}
is DynamicType -> tBuilder.appendSignature(MangleConstant.DYNAMIC_MARK)
is FlexibleType -> {
@@ -215,6 +210,8 @@ abstract class DescriptorMangleComputer(protected val builder: StringBuilder, pr
}
}
protected open fun mangleTypePlatformSpecific(type: UnwrappedType, tBuilder: StringBuilder) {}
private fun StringBuilder.mangleTypeParameterReference(typeParameter: TypeParameterDescriptor) {
val parent = typeParameter.containingDeclaration
val ci = typeParameterContainer.indexOf(parent)
@@ -315,4 +312,4 @@ abstract class DescriptorMangleComputer(protected val builder: StringBuilder, pr
override fun visitReceiverParameterDescriptor(descriptor: ReceiverParameterDescriptor, data: Nothing?) =
reportUnexpectedDescriptor(descriptor)
}
}
@@ -14,13 +14,11 @@ import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
import org.jetbrains.kotlin.ir.types.*
import org.jetbrains.kotlin.ir.util.hasAnnotation
import org.jetbrains.kotlin.ir.util.isVararg
import org.jetbrains.kotlin.ir.util.parentAsClass
import org.jetbrains.kotlin.ir.util.render
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptVoid
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
@@ -192,9 +190,7 @@ abstract class IrMangleComputer(protected val builder: StringBuilder, private va
if (type.hasQuestionMark) tBuilder.appendSignature(MangleConstant.Q_MARK)
if (type.hasAnnotation(JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION)) {
tBuilder.append(MangleConstant.ENHANCED_NULLABILITY_MARK)
}
mangleTypePlatformSpecific(type, tBuilder)
}
is IrDynamicType -> tBuilder.appendSignature(MangleConstant.DYNAMIC_MARK)
is IrErrorType -> tBuilder.appendSignature(MangleConstant.ERROR_MARK)
@@ -202,6 +198,8 @@ abstract class IrMangleComputer(protected val builder: StringBuilder, private va
}
}
protected open fun mangleTypePlatformSpecific(type: IrType, tBuilder: StringBuilder) {}
override fun visitElement(element: IrElement) =
error("unexpected element ${element.render()}")
@@ -22,9 +22,15 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.idea.MainFunctionDetector
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.types.IrType
import org.jetbrains.kotlin.ir.util.hasAnnotation
import org.jetbrains.kotlin.ir.util.isFromJava
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
import org.jetbrains.kotlin.load.java.lazy.descriptors.isJavaField
import org.jetbrains.kotlin.load.java.typeEnhancement.hasEnhancedNullability
import org.jetbrains.kotlin.types.UnwrappedType
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext
object JvmIrMangler : IrBasedKotlinManglerImpl() {
private class JvmIrExportChecker(compatibleMode: Boolean) : IrExportCheckerVisitor(compatibleMode) {
@@ -37,6 +43,12 @@ object JvmIrMangler : IrBasedKotlinManglerImpl() {
override fun addReturnTypeSpecialCase(irFunction: IrFunction): Boolean =
irFunction.isFromJava()
override fun mangleTypePlatformSpecific(type: IrType, tBuilder: StringBuilder) {
if (type.hasAnnotation(JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION)) {
tBuilder.append(MangleConstant.ENHANCED_NULLABILITY_MARK)
}
}
}
override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<IrDeclaration> = JvmIrExportChecker(compatibleMode)
@@ -78,6 +90,13 @@ class JvmDescriptorMangler(private val mainDetector: MainFunctionDetector?) : De
// because there should be `PackageFragmentDescriptor` in between
// but on JVM there is `SyntheticJavaPropertyDescriptor` whose parent is a module. So let just skip it.
}
override fun mangleTypePlatformSpecific(type: UnwrappedType, tBuilder: StringBuilder) {
// Disambiguate between 'double' and '@NotNull java.lang.Double' types in mixed Java/Kotlin class hierarchies
if (SimpleClassicTypeSystemContext.hasEnhancedNullability(type)) {
tBuilder.appendSignature(MangleConstant.ENHANCED_NULLABILITY_MARK)
}
}
}
override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<DeclarationDescriptor> = ExportChecker