KT-43217 Encode @EnhancedNullability types in IdSignature

This commit is contained in:
Dmitry Petrov
2020-11-09 08:37:00 +03:00
parent f6df624c6b
commit b9c6267a63
21 changed files with 470 additions and 2 deletions
@@ -16,6 +16,7 @@ enum class MangleConstant(val prefix: Char, val separator: Char, val suffix: Cha
const val VAR_ARG_MARK = "..."
const val STAR_MARK = '*'
const val Q_MARK = '?'
const val ENHANCED_NULLABILITY_MARK = "{EnhancedNullability}"
const val EXPECT_MARK = "#expect"
const val UNKNOWN_MARK = "<unknown>"
const val DYNAMIC_MARK = "<dynamic>"
@@ -10,7 +10,9 @@ import org.jetbrains.kotlin.backend.common.serialization.mangle.MangleConstant
import org.jetbrains.kotlin.backend.common.serialization.mangle.MangleMode
import org.jetbrains.kotlin.backend.common.serialization.mangle.collectForMangler
import org.jetbrains.kotlin.descriptors.*
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
@@ -188,6 +190,11 @@ 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)
}
}
is DynamicType -> tBuilder.appendSignature(MangleConstant.DYNAMIC_MARK)
is FlexibleType -> {
@@ -12,9 +12,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.render
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
@@ -178,6 +180,10 @@ 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)
}
}
is IrDynamicType -> tBuilder.appendSignature(MangleConstant.DYNAMIC_MARK)
is IrErrorType -> tBuilder.appendSignature(MangleConstant.ERROR_MARK)
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.backend.common.serialization.signature
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor
import org.jetbrains.kotlin.ir.util.IdSignature
import org.jetbrains.kotlin.ir.util.IdSignatureComposer