Add serialization/deserialization of definitely-not-null types
^KT-26245 In Progress
This commit is contained in:
committed by
TeamCityServer
parent
6ca6bb2d45
commit
30eb9ad32f
Vendored
+1
@@ -0,0 +1 @@
|
||||
public final fun <T> foo(x: R|T!!|, y: R|kotlin/collections/List<T!!>|, z: R|(T!!) -> T!!|): R|T!!|
|
||||
+9
-2
@@ -132,9 +132,16 @@ class FirTypeDeserializer(
|
||||
fun FirClassLikeSymbol<*>.typeParameters(): List<FirTypeParameterSymbol> =
|
||||
(fir as? FirTypeParameterRefsOwner)?.typeParameters?.map { it.symbol }.orEmpty()
|
||||
|
||||
fun simpleType(proto: ProtoBuf.Type, attributes: ConeAttributes): ConeLookupTagBasedType? {
|
||||
fun simpleType(proto: ProtoBuf.Type, attributes: ConeAttributes): ConeSimpleKotlinType? {
|
||||
val constructor = typeSymbol(proto) ?: return null
|
||||
if (constructor is ConeTypeParameterLookupTag) return ConeTypeParameterTypeImpl(constructor, isNullable = proto.nullable)
|
||||
if (constructor is ConeTypeParameterLookupTag) {
|
||||
return ConeTypeParameterTypeImpl(constructor, isNullable = proto.nullable).let {
|
||||
if (Flags.DEFINITELY_NOT_NULL_TYPE.get(proto.flags))
|
||||
ConeDefinitelyNotNullType.create(it)
|
||||
else
|
||||
it
|
||||
}
|
||||
}
|
||||
if (constructor !is ConeClassLikeLookupTag) return null
|
||||
|
||||
fun ProtoBuf.Type.collectAllArguments(): List<ProtoBuf.Type.Argument> =
|
||||
|
||||
+12
-3
@@ -598,10 +598,16 @@ class FirElementSerializer private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
private fun typeProto(type: ConeKotlinType, toSuper: Boolean = false, correspondingTypeRef: FirTypeRef? = null): ProtoBuf.Type.Builder {
|
||||
private fun typeProto(
|
||||
type: ConeKotlinType,
|
||||
toSuper: Boolean = false,
|
||||
correspondingTypeRef: FirTypeRef? = null,
|
||||
isDefinitelyNotNullType: Boolean = false,
|
||||
): ProtoBuf.Type.Builder {
|
||||
val builder = ProtoBuf.Type.newBuilder()
|
||||
|
||||
when (type) {
|
||||
is ConeDefinitelyNotNullType -> return typeProto(type, toSuper, correspondingTypeRef, isDefinitelyNotNullType = true)
|
||||
is ConeKotlinErrorType -> {
|
||||
extension.serializeErrorType(type, builder)
|
||||
return builder
|
||||
@@ -623,7 +629,7 @@ class FirElementSerializer private constructor(
|
||||
session, CONTINUATION_INTERFACE_CLASS_ID
|
||||
)
|
||||
val functionType = typeProto(runtimeFunctionType)
|
||||
functionType.flags = Flags.getTypeFlags(true)
|
||||
functionType.flags = Flags.getTypeFlags(true, false)
|
||||
return functionType
|
||||
}
|
||||
fillFromPossiblyInnerType(builder, type)
|
||||
@@ -640,8 +646,11 @@ class FirElementSerializer private constructor(
|
||||
} else {
|
||||
builder.typeParameter = getTypeParameterId(typeParameter)
|
||||
}
|
||||
|
||||
if (isDefinitelyNotNullType) {
|
||||
builder.flags = Flags.getTypeFlags(false, isDefinitelyNotNullType)
|
||||
}
|
||||
}
|
||||
is ConeDefinitelyNotNullType,
|
||||
is ConeIntersectionType -> {
|
||||
val approximatedType = if (toSuper) {
|
||||
typeApproximator.approximateToSuperType(type, TypeApproximatorConfiguration.PublicDeclaration)
|
||||
|
||||
+3
-1
@@ -584,7 +584,7 @@ class DescriptorSerializer private constructor(
|
||||
|
||||
if (type.isSuspendFunctionType) {
|
||||
val functionType = type(transformSuspendFunctionToRuntimeFunctionType(type, extension.releaseCoroutines()))
|
||||
functionType.flags = Flags.getTypeFlags(true)
|
||||
functionType.flags = Flags.getTypeFlags(true, false)
|
||||
return functionType
|
||||
}
|
||||
|
||||
@@ -600,6 +600,8 @@ class DescriptorSerializer private constructor(
|
||||
builder.typeParameter = getTypeParameterId(descriptor)
|
||||
}
|
||||
|
||||
builder.flags = Flags.getTypeFlags(false, type is DefinitelyNotNullType)
|
||||
|
||||
assert(type.arguments.isEmpty()) { "Found arguments for type constructor build on type parameter: $descriptor" }
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
// !LANGUAGE: +DefinitelyNotNullTypeParameters
|
||||
// COMPILER_ARGUMENTS: -XXLanguage:+DefinitelyNotNullTypeParameters
|
||||
package test
|
||||
|
||||
fun <T> foo(x: T!!, y: List<T!!>, z: (T!!) -> T!!): T!! = x
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package test
|
||||
|
||||
public fun </*0*/ T> foo(/*0*/ x: T!!, /*1*/ y: kotlin.collections.List<T!!>, /*2*/ z: (T!!) -> T!!): T!!
|
||||
+5
@@ -2116,6 +2116,11 @@ public class LoadJavaTestGenerated extends AbstractLoadJavaTest {
|
||||
runTest("compiler/testData/loadJava/compiledKotlin/annotations/types/ClassLiteralArgument.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("DefinitelyNotNull.kt")
|
||||
public void testDefinitelyNotNull() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledKotlin/annotations/types/DefinitelyNotNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ReceiverParameter.kt")
|
||||
public void testReceiverParameter() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledKotlin/annotations/types/ReceiverParameter.kt");
|
||||
|
||||
Generated
+5
@@ -438,6 +438,11 @@ public class LoadKotlinWithTypeTableTestGenerated extends AbstractLoadKotlinWith
|
||||
runTest("compiler/testData/loadJava/compiledKotlin/annotations/types/ClassLiteralArgument.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("DefinitelyNotNull.kt")
|
||||
public void testDefinitelyNotNull() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledKotlin/annotations/types/DefinitelyNotNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ReceiverParameter.kt")
|
||||
public void testReceiverParameter() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledKotlin/annotations/types/ReceiverParameter.kt");
|
||||
|
||||
+5
@@ -2117,6 +2117,11 @@ public class IrLoadJavaTestGenerated extends AbstractIrLoadJavaTest {
|
||||
runTest("compiler/testData/loadJava/compiledKotlin/annotations/types/ClassLiteralArgument.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("DefinitelyNotNull.kt")
|
||||
public void testDefinitelyNotNull() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledKotlin/annotations/types/DefinitelyNotNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ReceiverParameter.kt")
|
||||
public void testReceiverParameter() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledKotlin/annotations/types/ReceiverParameter.kt");
|
||||
|
||||
Generated
+5
@@ -2116,6 +2116,11 @@ public class LoadJavaUsingJavacTestGenerated extends AbstractLoadJavaUsingJavacT
|
||||
runTest("compiler/testData/loadJava/compiledKotlin/annotations/types/ClassLiteralArgument.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("DefinitelyNotNull.kt")
|
||||
public void testDefinitelyNotNull() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledKotlin/annotations/types/DefinitelyNotNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("ReceiverParameter.kt")
|
||||
public void testReceiverParameter() throws Exception {
|
||||
runTest("compiler/testData/loadJava/compiledKotlin/annotations/types/ReceiverParameter.kt");
|
||||
|
||||
Reference in New Issue
Block a user