[FIR] Fix enhancement of FlexibleNullability and EnhancedNullability

- Add utilities to add new attribute to ConeAttributes
- Get rid of FlexibleNullability attribute (it can be easily inferred
    for any flexible type at any moment)
- Fix determining of EnhancedNullability attribute
This commit is contained in:
Dmitriy Novozhilov
2021-03-09 14:51:19 +03:00
parent 0108f8a1b4
commit 65ea4e184a
290 changed files with 1395 additions and 2037 deletions
+1 -1
View File
@@ -1,7 +1,7 @@
fun <K1 : Any?, V1 : Any?> Map<out K1, V1>.plus(pair: Pair<K1, V1>): Map<K1, V1> {
return when {
<this>.isEmpty() -> mapOf<K1, V1>(pair = pair)
else -> LinkedHashMap<K1?, V1?>(p0 = <this>).apply<LinkedHashMap<K1?, V1?>>(block = local fun LinkedHashMap<K1?, V1?>.<anonymous>() {
else -> LinkedHashMap<@FlexibleNullability K1?, @FlexibleNullability V1?>(p0 = <this>).apply<LinkedHashMap<@FlexibleNullability K1?, @FlexibleNullability V1?>>(block = local fun LinkedHashMap<@FlexibleNullability K1?, @FlexibleNullability V1?>.<anonymous>() {
<this>.put(p0 = pair.<get-first>(), p1 = pair.<get-second>()) /*~> Unit */
}
)
+10 -10
View File
@@ -16,19 +16,19 @@ FILE fqName:<root> fileName:/builtinMap.kt
pair: GET_VAR 'pair: kotlin.Pair<K1 of <root>.plus, V1 of <root>.plus> declared in <root>.plus' type=kotlin.Pair<K1 of <root>.plus, V1 of <root>.plus> origin=null
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: CALL 'public final fun apply <T> (block: @[ExtensionFunctionType] kotlin.Function1<T of kotlin.StandardKt.apply, kotlin.Unit>): T of kotlin.StandardKt.apply [inline] declared in kotlin.StandardKt' type=java.util.LinkedHashMap<K1 of <root>.plus?, V1 of <root>.plus?> origin=null
<T>: java.util.LinkedHashMap<K1 of <root>.plus?, V1 of <root>.plus?>
$receiver: CONSTRUCTOR_CALL 'public constructor <init> (p0: kotlin.collections.Map<out K of java.util.LinkedHashMap?, out V of java.util.LinkedHashMap?>?) declared in java.util.LinkedHashMap' type=java.util.LinkedHashMap<K1 of <root>.plus?, V1 of <root>.plus?> origin=null
<class: K>: K1 of <root>.plus?
<class: V>: V1 of <root>.plus?
then: CALL 'public final fun apply <T> (block: @[ExtensionFunctionType] kotlin.Function1<T of kotlin.StandardKt.apply, kotlin.Unit>): T of kotlin.StandardKt.apply [inline] declared in kotlin.StandardKt' type=java.util.LinkedHashMap<@[FlexibleNullability] K1 of <root>.plus?, @[FlexibleNullability] V1 of <root>.plus?> origin=null
<T>: java.util.LinkedHashMap<@[FlexibleNullability] K1 of <root>.plus?, @[FlexibleNullability] V1 of <root>.plus?>
$receiver: CONSTRUCTOR_CALL 'public constructor <init> (p0: @[FlexibleNullability] kotlin.collections.Map<out @[FlexibleNullability] K of java.util.LinkedHashMap?, out @[FlexibleNullability] V of java.util.LinkedHashMap?>?) declared in java.util.LinkedHashMap' type=java.util.LinkedHashMap<@[FlexibleNullability] K1 of <root>.plus?, @[FlexibleNullability] V1 of <root>.plus?> origin=null
<class: K>: @[FlexibleNullability] K1 of <root>.plus?
<class: V>: @[FlexibleNullability] V1 of <root>.plus?
p0: GET_VAR '<this>: kotlin.collections.Map<out K1 of <root>.plus, V1 of <root>.plus> declared in <root>.plus' type=kotlin.collections.Map<out K1 of <root>.plus, V1 of <root>.plus> origin=null
block: FUN_EXPR type=kotlin.Function1<java.util.LinkedHashMap<K1 of <root>.plus?, V1 of <root>.plus?>, kotlin.Unit> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> ($receiver:java.util.LinkedHashMap<K1 of <root>.plus?, V1 of <root>.plus?>) returnType:kotlin.Unit
$receiver: VALUE_PARAMETER name:<this> type:java.util.LinkedHashMap<K1 of <root>.plus?, V1 of <root>.plus?>
block: FUN_EXPR type=kotlin.Function1<java.util.LinkedHashMap<@[FlexibleNullability] K1 of <root>.plus?, @[FlexibleNullability] V1 of <root>.plus?>, kotlin.Unit> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> ($receiver:java.util.LinkedHashMap<@[FlexibleNullability] K1 of <root>.plus?, @[FlexibleNullability] V1 of <root>.plus?>) returnType:kotlin.Unit
$receiver: VALUE_PARAMETER name:<this> type:java.util.LinkedHashMap<@[FlexibleNullability] K1 of <root>.plus?, @[FlexibleNullability] V1 of <root>.plus?>
BLOCK_BODY
TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit
CALL 'public open fun put (p0: @[FlexibleNullability] K of java.util.LinkedHashMap?, p1: @[FlexibleNullability] V of java.util.LinkedHashMap?): @[FlexibleNullability] V of java.util.LinkedHashMap? [fake_override] declared in java.util.LinkedHashMap' type=V1 of <root>.plus? origin=null
$this: GET_VAR '<this>: java.util.LinkedHashMap<K1 of <root>.plus?, V1 of <root>.plus?> declared in <root>.plus.<anonymous>' type=java.util.LinkedHashMap<K1 of <root>.plus?, V1 of <root>.plus?> origin=null
CALL 'public open fun put (p0: @[FlexibleNullability] K of java.util.LinkedHashMap?, p1: @[FlexibleNullability] V of java.util.LinkedHashMap?): V of java.util.LinkedHashMap? [fake_override] declared in java.util.LinkedHashMap' type=V1 of <root>.plus? origin=null
$this: GET_VAR '<this>: java.util.LinkedHashMap<@[FlexibleNullability] K1 of <root>.plus?, @[FlexibleNullability] V1 of <root>.plus?> declared in <root>.plus.<anonymous>' type=java.util.LinkedHashMap<@[FlexibleNullability] K1 of <root>.plus?, @[FlexibleNullability] V1 of <root>.plus?> origin=null
p0: CALL 'public final fun <get-first> (): A of kotlin.Pair declared in kotlin.Pair' type=K1 of <root>.plus origin=GET_PROPERTY
$this: GET_VAR 'pair: kotlin.Pair<K1 of <root>.plus, V1 of <root>.plus> declared in <root>.plus' type=kotlin.Pair<K1 of <root>.plus, V1 of <root>.plus> origin=null
p1: CALL 'public final fun <get-second> (): B of kotlin.Pair declared in kotlin.Pair' type=V1 of <root>.plus origin=GET_PROPERTY
@@ -1,15 +1,16 @@
fun test1(): J1<Int?> {
return J1<Int?>()
fun test1(): J1<@FlexibleNullability Int?> {
return J1<@FlexibleNullability Int?>()
}
fun test2(): J1<Int?> {
return J1<Int?, Int?>(x1 = 1)
fun test2(): J1<@FlexibleNullability Int?> {
return J1<@FlexibleNullability Int?, @FlexibleNullability Int?>(x1 = 1)
}
fun test3(j1: J1<Any>): J2<Int?, Any> {
return j1.J2<Int?>()
fun test3(j1: J1<Any>): J2<@FlexibleNullability Int?, Any> {
return j1.J2<@FlexibleNullability Int?>()
}
fun test4(j1: J1<Any>): J2<Int?, Any> {
return j1.J2<Int?, Int?>(x2 = 1)
fun test4(j1: J1<Any>): J2<@FlexibleNullability Int?, Any> {
return j1.J2<@FlexibleNullability Int?, @FlexibleNullability Int?>(x2 = 1)
}
@@ -1,29 +1,29 @@
FILE fqName:<root> fileName:/javaConstructorWithTypeParameters.kt
FUN name:test1 visibility:public modality:FINAL <> () returnType:<root>.J1<kotlin.Int?>
FUN name:test1 visibility:public modality:FINAL <> () returnType:<root>.J1<@[FlexibleNullability] kotlin.Int?>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test1 (): <root>.J1<kotlin.Int?> declared in <root>'
CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J1' type=<root>.J1<kotlin.Int?> origin=null
<class: T1>: kotlin.Int?
FUN name:test2 visibility:public modality:FINAL <> () returnType:<root>.J1<kotlin.Int?>
RETURN type=kotlin.Nothing from='public final fun test1 (): <root>.J1<@[FlexibleNullability] kotlin.Int?> declared in <root>'
CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J1' type=<root>.J1<@[FlexibleNullability] kotlin.Int?> origin=null
<class: T1>: @[FlexibleNullability] kotlin.Int?
FUN name:test2 visibility:public modality:FINAL <> () returnType:<root>.J1<@[FlexibleNullability] kotlin.Int?>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test2 (): <root>.J1<kotlin.Int?> declared in <root>'
CONSTRUCTOR_CALL 'public constructor <init> <X1> (x1: X1 of <root>.J1.<init>?) declared in <root>.J1' type=<root>.J1<kotlin.Int?> origin=null
<class: T1>: kotlin.Int?
<X1>: kotlin.Int?
RETURN type=kotlin.Nothing from='public final fun test2 (): <root>.J1<@[FlexibleNullability] kotlin.Int?> declared in <root>'
CONSTRUCTOR_CALL 'public constructor <init> <X1> (x1: @[FlexibleNullability] X1 of <root>.J1.<init>?) declared in <root>.J1' type=<root>.J1<@[FlexibleNullability] kotlin.Int?> origin=null
<class: T1>: @[FlexibleNullability] kotlin.Int?
<X1>: @[FlexibleNullability] kotlin.Int?
x1: CONST Int type=kotlin.Int value=1
FUN name:test3 visibility:public modality:FINAL <> (j1:<root>.J1<kotlin.Any>) returnType:<root>.J1.J2<kotlin.Int?, kotlin.Any>
FUN name:test3 visibility:public modality:FINAL <> (j1:<root>.J1<kotlin.Any>) returnType:<root>.J1.J2<@[FlexibleNullability] kotlin.Int?, kotlin.Any>
VALUE_PARAMETER name:j1 index:0 type:<root>.J1<kotlin.Any>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test3 (j1: <root>.J1<kotlin.Any>): <root>.J1.J2<kotlin.Int?, kotlin.Any> declared in <root>'
CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J1.J2' type=<root>.J1.J2<kotlin.Int?, kotlin.Any> origin=null
<class: T2>: kotlin.Int?
RETURN type=kotlin.Nothing from='public final fun test3 (j1: <root>.J1<kotlin.Any>): <root>.J1.J2<@[FlexibleNullability] kotlin.Int?, kotlin.Any> declared in <root>'
CONSTRUCTOR_CALL 'public constructor <init> () declared in <root>.J1.J2' type=<root>.J1.J2<@[FlexibleNullability] kotlin.Int?, kotlin.Any> origin=null
<class: T2>: @[FlexibleNullability] kotlin.Int?
$outer: GET_VAR 'j1: <root>.J1<kotlin.Any> declared in <root>.test3' type=<root>.J1<kotlin.Any> origin=null
FUN name:test4 visibility:public modality:FINAL <> (j1:<root>.J1<kotlin.Any>) returnType:<root>.J1.J2<kotlin.Int?, kotlin.Any>
FUN name:test4 visibility:public modality:FINAL <> (j1:<root>.J1<kotlin.Any>) returnType:<root>.J1.J2<@[FlexibleNullability] kotlin.Int?, kotlin.Any>
VALUE_PARAMETER name:j1 index:0 type:<root>.J1<kotlin.Any>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun test4 (j1: <root>.J1<kotlin.Any>): <root>.J1.J2<kotlin.Int?, kotlin.Any> declared in <root>'
CONSTRUCTOR_CALL 'public constructor <init> <X2> (x2: X2 of <root>.J1.J2.<init>?) declared in <root>.J1.J2' type=<root>.J1.J2<kotlin.Int?, kotlin.Any> origin=null
<class: T2>: kotlin.Int?
<X2>: kotlin.Int?
RETURN type=kotlin.Nothing from='public final fun test4 (j1: <root>.J1<kotlin.Any>): <root>.J1.J2<@[FlexibleNullability] kotlin.Int?, kotlin.Any> declared in <root>'
CONSTRUCTOR_CALL 'public constructor <init> <X2> (x2: @[FlexibleNullability] X2 of <root>.J1.J2.<init>?) declared in <root>.J1.J2' type=<root>.J1.J2<@[FlexibleNullability] kotlin.Int?, kotlin.Any> origin=null
<class: T2>: @[FlexibleNullability] kotlin.Int?
<X2>: @[FlexibleNullability] kotlin.Int?
$outer: GET_VAR 'j1: <root>.J1<kotlin.Any> declared in <root>.test4' type=<root>.J1<kotlin.Any> origin=null
x2: CONST Int type=kotlin.Int value=1
+1 -1
View File
@@ -1,3 +1,3 @@
val test: @FlexibleNullability JEnum
val test: JEnum
field = JEnum.ONE
get
+5 -5
View File
@@ -1,10 +1,10 @@
FILE fqName:<root> fileName:/javaEnum.kt
PROPERTY name:test visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:test type:@[FlexibleNullability] <root>.JEnum visibility:private [final,static]
FIELD PROPERTY_BACKING_FIELD name:test type:<root>.JEnum visibility:private [final,static]
EXPRESSION_BODY
GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_JAVA_DECLARATION_STUB name:ONE' type=@[FlexibleNullability] <root>.JEnum
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> visibility:public modality:FINAL <> () returnType:@[FlexibleNullability] <root>.JEnum
GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_JAVA_DECLARATION_STUB name:ONE' type=@[EnhancedNullability] <root>.JEnum
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> visibility:public modality:FINAL <> () returnType:<root>.JEnum
correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-test> (): @[FlexibleNullability] <root>.JEnum declared in <root>'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test type:@[FlexibleNullability] <root>.JEnum visibility:private [final,static]' type=@[FlexibleNullability] <root>.JEnum origin=null
RETURN type=kotlin.Nothing from='public final fun <get-test> (): <root>.JEnum declared in <root>'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test type:<root>.JEnum visibility:private [final,static]' type=<root>.JEnum origin=null
@@ -1,3 +0,0 @@
val test: String?
field = J().getFoo()
get
@@ -1,11 +0,0 @@
FILE fqName:<root> fileName:/javaSyntheticProperty.kt
PROPERTY name:test visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.String? visibility:private [final,static]
EXPRESSION_BODY
CALL 'public open fun getFoo (): kotlin.String? declared in <root>.J' type=kotlin.String? origin=GET_PROPERTY
$this: CONSTRUCTOR_CALL 'public/*package*/ constructor <init> () [primary] declared in <root>.J' type=<root>.J origin=null
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-test> visibility:public modality:FINAL <> () returnType:kotlin.String?
correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val]
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-test> (): kotlin.String? declared in <root>'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:test type:kotlin.String? visibility:private [final,static]' type=kotlin.String? origin=null
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DUMP_DEPENDENCIES
// FILE: javaSyntheticProperty.kt
val test = J().foo
@@ -1,4 +1,4 @@
val Class<*>.test: Array<out Field?>?
get(): Array<out Field?>? {
val Class<*>.test: @FlexibleNullability Array<out @FlexibleNullability Field?>?
get(): @FlexibleNullability Array<out @FlexibleNullability Field?>? {
return <this>.getDeclaredFields()
}
@@ -1,9 +1,9 @@
FILE fqName:<root> fileName:/jdkClassSyntheticProperty.kt
PROPERTY name:test visibility:public modality:FINAL [val]
FUN name:<get-test> visibility:public modality:FINAL <> ($receiver:java.lang.Class<*>) returnType:kotlin.Array<out java.lang.reflect.Field?>?
FUN name:<get-test> visibility:public modality:FINAL <> ($receiver:java.lang.Class<*>) returnType:@[FlexibleNullability] kotlin.Array<out @[FlexibleNullability] java.lang.reflect.Field?>?
correspondingProperty: PROPERTY name:test visibility:public modality:FINAL [val]
$receiver: VALUE_PARAMETER name:<this> type:java.lang.Class<*>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-test> (): kotlin.Array<out java.lang.reflect.Field?>? declared in <root>'
CALL 'public open fun getDeclaredFields (): kotlin.Array<out java.lang.reflect.Field?>? declared in java.lang.Class' type=kotlin.Array<out java.lang.reflect.Field?>? origin=GET_PROPERTY
RETURN type=kotlin.Nothing from='public final fun <get-test> (): @[FlexibleNullability] kotlin.Array<out @[FlexibleNullability] java.lang.reflect.Field?>? declared in <root>'
CALL 'public open fun getDeclaredFields (): @[FlexibleNullability] kotlin.Array<out @[FlexibleNullability] java.lang.reflect.Field?>? declared in java.lang.Class' type=@[FlexibleNullability] kotlin.Array<out @[FlexibleNullability] java.lang.reflect.Field?>? origin=GET_PROPERTY
$this: GET_VAR '<this>: java.lang.Class<*> declared in <root>.<get-test>' type=java.lang.Class<*> origin=null