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:
@@ -12,9 +12,6 @@ dependencies {
|
|||||||
implementation(project(":compiler:psi"))
|
implementation(project(":compiler:psi"))
|
||||||
compileOnly(project(":kotlin-reflect-api"))
|
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") }
|
compileOnly(intellijCoreDep()) { includeJars("intellij-core") }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+5
-8
@@ -12,9 +12,7 @@ import org.jetbrains.kotlin.backend.common.serialization.mangle.collectForMangle
|
|||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrImplementingDelegateDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.IrImplementingDelegateDescriptor
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrPropertyDelegateDescriptor
|
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.*
|
||||||
import org.jetbrains.kotlin.types.checker.SimpleClassicTypeSystemContext
|
|
||||||
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
import org.jetbrains.kotlin.types.typeUtil.isUnit
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
|
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) {
|
if (mode.signature) {
|
||||||
append(s)
|
append(s)
|
||||||
}
|
}
|
||||||
@@ -195,10 +193,7 @@ abstract class DescriptorMangleComputer(protected val builder: StringBuilder, pr
|
|||||||
|
|
||||||
if (type.isMarkedNullable) tBuilder.appendSignature(MangleConstant.Q_MARK)
|
if (type.isMarkedNullable) tBuilder.appendSignature(MangleConstant.Q_MARK)
|
||||||
|
|
||||||
// Disambiguate between 'double' and '@NotNull java.lang.Double' types in mixed Java/Kotlin class hierarchies
|
mangleTypePlatformSpecific(type, tBuilder)
|
||||||
if (SimpleClassicTypeSystemContext.hasEnhancedNullability(type)) {
|
|
||||||
tBuilder.appendSignature(MangleConstant.ENHANCED_NULLABILITY_MARK)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
is DynamicType -> tBuilder.appendSignature(MangleConstant.DYNAMIC_MARK)
|
is DynamicType -> tBuilder.appendSignature(MangleConstant.DYNAMIC_MARK)
|
||||||
is FlexibleType -> {
|
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) {
|
private fun StringBuilder.mangleTypeParameterReference(typeParameter: TypeParameterDescriptor) {
|
||||||
val parent = typeParameter.containingDeclaration
|
val parent = typeParameter.containingDeclaration
|
||||||
val ci = typeParameterContainer.indexOf(parent)
|
val ci = typeParameterContainer.indexOf(parent)
|
||||||
@@ -315,4 +312,4 @@ abstract class DescriptorMangleComputer(protected val builder: StringBuilder, pr
|
|||||||
|
|
||||||
override fun visitReceiverParameterDescriptor(descriptor: ReceiverParameterDescriptor, data: Nothing?) =
|
override fun visitReceiverParameterDescriptor(descriptor: ReceiverParameterDescriptor, data: Nothing?) =
|
||||||
reportUnexpectedDescriptor(descriptor)
|
reportUnexpectedDescriptor(descriptor)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-5
@@ -14,13 +14,11 @@ import org.jetbrains.kotlin.ir.declarations.*
|
|||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.*
|
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.isVararg
|
||||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||||
import org.jetbrains.kotlin.ir.util.render
|
import org.jetbrains.kotlin.ir.util.render
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
|
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.hasQuestionMark) tBuilder.appendSignature(MangleConstant.Q_MARK)
|
||||||
|
|
||||||
if (type.hasAnnotation(JvmAnnotationNames.ENHANCED_NULLABILITY_ANNOTATION)) {
|
mangleTypePlatformSpecific(type, tBuilder)
|
||||||
tBuilder.append(MangleConstant.ENHANCED_NULLABILITY_MARK)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
is IrDynamicType -> tBuilder.appendSignature(MangleConstant.DYNAMIC_MARK)
|
is IrDynamicType -> tBuilder.appendSignature(MangleConstant.DYNAMIC_MARK)
|
||||||
is IrErrorType -> tBuilder.appendSignature(MangleConstant.ERROR_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) =
|
override fun visitElement(element: IrElement) =
|
||||||
error("unexpected element ${element.render()}")
|
error("unexpected element ${element.render()}")
|
||||||
|
|
||||||
|
|||||||
+19
@@ -22,9 +22,15 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
|||||||
import org.jetbrains.kotlin.idea.MainFunctionDetector
|
import org.jetbrains.kotlin.idea.MainFunctionDetector
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
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.ir.util.isFromJava
|
||||||
|
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||||
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
|
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
|
||||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.isJavaField
|
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() {
|
object JvmIrMangler : IrBasedKotlinManglerImpl() {
|
||||||
private class JvmIrExportChecker(compatibleMode: Boolean) : IrExportCheckerVisitor(compatibleMode) {
|
private class JvmIrExportChecker(compatibleMode: Boolean) : IrExportCheckerVisitor(compatibleMode) {
|
||||||
@@ -37,6 +43,12 @@ object JvmIrMangler : IrBasedKotlinManglerImpl() {
|
|||||||
|
|
||||||
override fun addReturnTypeSpecialCase(irFunction: IrFunction): Boolean =
|
override fun addReturnTypeSpecialCase(irFunction: IrFunction): Boolean =
|
||||||
irFunction.isFromJava()
|
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)
|
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
|
// because there should be `PackageFragmentDescriptor` in between
|
||||||
// but on JVM there is `SyntheticJavaPropertyDescriptor` whose parent is a module. So let just skip it.
|
// 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
|
override fun getExportChecker(compatibleMode: Boolean): KotlinExportChecker<DeclarationDescriptor> = ExportChecker
|
||||||
|
|||||||
Reference in New Issue
Block a user