From 487e7f2a91191f11725317eebd4b7c330388988b Mon Sep 17 00:00:00 2001 From: Alexey Sedunov Date: Fri, 11 Jul 2014 13:34:54 +0400 Subject: [PATCH] Pseudocode: Replace {<: Any?} type predicate with * --- .../jet/lang/cfg/pseudocode/TypePredicate.kt | 11 +++++++++-- .../cfg-variables/basic/IfWithUninitialized.values | 2 +- .../basic/UsageInFunctionLiteral.values | 2 +- .../bugs/varInitializationInIfInCycle.values | 2 +- compiler/testData/cfg/basic/Basic.values | 4 ++-- .../cfg/controlStructures/FinallyTestCopy.values | 4 ++-- .../cfg/controlStructures/whenConditions.values | 2 +- compiler/testData/cfg/conventions/equals.values | 2 +- compiler/testData/cfg/conventions/notEqual.values | 2 +- .../backingFieldQualifiedWithThis.values | 14 +++++++------- compiler/testData/cfg/tailCalls/sum.values | 4 ++-- 11 files changed, 28 insertions(+), 21 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/TypePredicate.kt b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/TypePredicate.kt index da985950d5e..bd201338487 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/TypePredicate.kt +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/pseudocode/TypePredicate.kt @@ -20,6 +20,7 @@ import org.jetbrains.jet.lang.types.JetType import org.jetbrains.jet.lang.types.checker.JetTypeChecker import org.jetbrains.jet.renderer.DescriptorRenderer import com.intellij.util.SmartFMap +import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns import org.jetbrains.jet.lang.types.TypeUtils public trait TypePredicate: (JetType) -> Boolean { @@ -71,8 +72,14 @@ fun or(predicates: Collection): TypePredicate? = else -> ForSomeType(predicates.toList()) } -fun JetType.getSubtypesPredicate(): TypePredicate? = - if (TypeUtils.canHaveSubtypes(JetTypeChecker.DEFAULT, this)) AllSubtypes(this) else SingleType(this) +fun JetType.getSubtypesPredicate(): TypePredicate? { + return when { + KotlinBuiltIns.getInstance().isAnyOrNullableAny(this) && isNullable() -> AllTypes + TypeUtils.canHaveSubtypes(JetTypeChecker.DEFAULT, this) -> AllSubtypes(this) + else -> SingleType(this) + } +} + private fun JetType.render(): String = DescriptorRenderer.SHORT_NAMES_IN_TYPES.renderType(this) diff --git a/compiler/testData/cfg-variables/basic/IfWithUninitialized.values b/compiler/testData/cfg-variables/basic/IfWithUninitialized.values index e5dd9a40fe2..4c96c9f62f3 100644 --- a/compiler/testData/cfg-variables/basic/IfWithUninitialized.values +++ b/compiler/testData/cfg-variables/basic/IfWithUninitialized.values @@ -12,7 +12,7 @@ fun foo() { 1 : {<: Comparable} NEW: r(1) -> 2 : Int NEW: r(2) -> 1 < 2 : Boolean NEW: call(1 < 2, compareTo|, ) -> -b : {<: Any?} NEW: r(b) -> +b : * NEW: r(b) -> use(b) : * NEW: call(use(b), use|) -> { use(b) } : * COPY true : Boolean NEW: r(true) -> diff --git a/compiler/testData/cfg-variables/basic/UsageInFunctionLiteral.values b/compiler/testData/cfg-variables/basic/UsageInFunctionLiteral.values index ef53a6976f1..033d91cd500 100644 --- a/compiler/testData/cfg-variables/basic/UsageInFunctionLiteral.values +++ b/compiler/testData/cfg-variables/basic/UsageInFunctionLiteral.values @@ -20,7 +20,7 @@ fun foo() { x : Int NEW: r(x) -> a : Int NEW: r(a) -> x + a : Int NEW: call(x + a, plus|, ) -> -a : {<: Any?} NEW: r(a) -> +a : * NEW: r(a) -> use(a) : {<: Array} NEW: call(use(a), use|) -> val y = x + a use(a) : {<: Array} COPY ===================== diff --git a/compiler/testData/cfg-variables/bugs/varInitializationInIfInCycle.values b/compiler/testData/cfg-variables/bugs/varInitializationInIfInCycle.values index 122f89e1e5f..68ccdba7801 100644 --- a/compiler/testData/cfg-variables/bugs/varInitializationInIfInCycle.values +++ b/compiler/testData/cfg-variables/bugs/varInitializationInIfInCycle.values @@ -21,7 +21,7 @@ numbers : {<: Iterable} NEW: r(numbers) -> 1 < 2 : Boolean NEW: call(1 < 2, compareTo|, ) -> false : Boolean NEW: r(false) -> true : Boolean NEW: r(true) -> -b : {<: Any?} NEW: r(b) -> +b : * NEW: r(b) -> use(b) : * NEW: call(use(b), use|) -> ===================== == use == diff --git a/compiler/testData/cfg/basic/Basic.values b/compiler/testData/cfg/basic/Basic.values index 67357513ffa..72c6c290f7b 100644 --- a/compiler/testData/cfg/basic/Basic.values +++ b/compiler/testData/cfg/basic/Basic.values @@ -30,11 +30,11 @@ genfun() {1} : {<: () -> Any} NEW: r({1}) -> flfun {1} : * NEW: call(flfun {1}, flfun|) -> 3 : OR{{<: Any}, {<: Any}} NEW: r(3) -> -4 : {<: Any?} NEW: r(4) -> +4 : * NEW: r(4) -> equals(4) : * NEW: call(equals(4), equals|, ) -> 3.equals(4) : * COPY 3 : OR{{<: Any}, {<: Any}} NEW: r(3) -> -4 : {<: Any?} NEW: r(4) -> +4 : * NEW: r(4) -> 3 equals 4 : * NEW: call(3 equals 4, equals|, ) -> 1 : Int NEW: r(1) -> 2 : Int NEW: r(2) -> diff --git a/compiler/testData/cfg/controlStructures/FinallyTestCopy.values b/compiler/testData/cfg/controlStructures/FinallyTestCopy.values index a0a82bc8c68..b65a79dad80 100644 --- a/compiler/testData/cfg/controlStructures/FinallyTestCopy.values +++ b/compiler/testData/cfg/controlStructures/FinallyTestCopy.values @@ -116,8 +116,8 @@ fun doTestCopy4(list: List?) : Int { : {<: List?} NEW: magic[FAKE_INITIALIZER](list: List?) -> doSmth() : * NEW: call(doSmth(), doSmth) -> { doSmth() } : * COPY -list : {<: Any?} NEW: r(list) -> -null : {<: Any?} NEW: r(null) -> +list : * NEW: r(list) -> +null : * NEW: r(null) -> list != null : Boolean NEW: call(list != null, equals|, ) -> try { doSmth() } finally { if(list != null) { } } : * COPY { try { doSmth() } finally { if(list != null) { } } } : * COPY diff --git a/compiler/testData/cfg/controlStructures/whenConditions.values b/compiler/testData/cfg/controlStructures/whenConditions.values index b6f54cff4a3..f50dcb47443 100644 --- a/compiler/testData/cfg/controlStructures/whenConditions.values +++ b/compiler/testData/cfg/controlStructures/whenConditions.values @@ -11,7 +11,7 @@ fun foo(a: Number) { } --------------------- : {<: Number} NEW: magic[FAKE_INITIALIZER](a: Number) -> -a : AND{*, {<: Any?}} NEW: r(a) -> +a : * NEW: r(a) -> 1 : * NEW: r(1) -> 1 : * NEW: magic[EQUALS_IN_WHEN_CONDITION](1|, ) -> "1" : {<: String?} NEW: r("1") -> diff --git a/compiler/testData/cfg/conventions/equals.values b/compiler/testData/cfg/conventions/equals.values index edd38961247..8a51f921331 100644 --- a/compiler/testData/cfg/conventions/equals.values +++ b/compiler/testData/cfg/conventions/equals.values @@ -7,6 +7,6 @@ fun foo(a: Int, b: Int) { : Int NEW: magic[FAKE_INITIALIZER](a: Int) -> : Int NEW: magic[FAKE_INITIALIZER](b: Int) -> a : OR{{<: Any}, {<: Any}} NEW: r(a) -> -b : {<: Any?} NEW: r(b) -> +b : * NEW: r(b) -> a == b : Boolean NEW: call(a == b, equals|, ) -> ===================== diff --git a/compiler/testData/cfg/conventions/notEqual.values b/compiler/testData/cfg/conventions/notEqual.values index 4b26d518ded..c2890278034 100644 --- a/compiler/testData/cfg/conventions/notEqual.values +++ b/compiler/testData/cfg/conventions/notEqual.values @@ -6,6 +6,6 @@ fun neq(a: Int, b: Int) { : Int NEW: magic[FAKE_INITIALIZER](a: Int) -> : Int NEW: magic[FAKE_INITIALIZER](b: Int) -> a : OR{{<: Any}, {<: Any}} NEW: r(a) -> -b : {<: Any?} NEW: r(b) -> +b : * NEW: r(b) -> a != b : Boolean NEW: call(a != b, equals|, ) -> ===================== diff --git a/compiler/testData/cfg/declarations/properties/backingFieldQualifiedWithThis.values b/compiler/testData/cfg/declarations/properties/backingFieldQualifiedWithThis.values index 99c0a542f33..c6b6648fcd5 100644 --- a/compiler/testData/cfg/declarations/properties/backingFieldQualifiedWithThis.values +++ b/compiler/testData/cfg/declarations/properties/backingFieldQualifiedWithThis.values @@ -8,10 +8,10 @@ abstract class Bar { == foo == fun foo() = "foo" + this.$bar --------------------- -"foo" : String NEW: r("foo") -> -this : {<: Bar} COPY -this : {<: Bar} NEW: r(this) -> -$bar : {<: Any?} NEW: r($bar|) -> -this.$bar : {<: Any?} COPY -"foo" + this.$bar : String NEW: call("foo" + this.$bar, plus|, ) -> -===================== \ No newline at end of file +"foo" : String NEW: r("foo") -> +this : {<: Bar} COPY +this : {<: Bar} NEW: r(this) -> +$bar : * NEW: r($bar|) -> +this.$bar : * COPY +"foo" + this.$bar : String NEW: call("foo" + this.$bar, plus|, ) -> +===================== diff --git a/compiler/testData/cfg/tailCalls/sum.values b/compiler/testData/cfg/tailCalls/sum.values index 3af9727386a..ccfbb5d4aaa 100644 --- a/compiler/testData/cfg/tailCalls/sum.values +++ b/compiler/testData/cfg/tailCalls/sum.values @@ -8,8 +8,8 @@ tailRecursive fun sum(x: Long, sum: Long): Long { : Long NEW: magic[FAKE_INITIALIZER](sum: Long) -> x : OR{{<: Any}, {<: Any}} NEW: r(x) -> 0 : {<: Number} NEW: r(0) -> -toLong() : {<: Any?} NEW: call(toLong(), toLong|) -> -0.toLong() : {<: Any?} COPY +toLong() : * NEW: call(toLong(), toLong|) -> +0.toLong() : * COPY x == 0.toLong() : Boolean NEW: call(x == 0.toLong(), equals|, ) -> sum : Long NEW: r(sum) -> x : Long NEW: r(x) ->