Avoid creating SimpleType instances for default type

This commit is contained in:
Denis Zharkov
2017-05-24 13:54:31 +03:00
parent 8576054788
commit 59f2ba98a6
8 changed files with 95 additions and 81 deletions
@@ -9,7 +9,7 @@ fun test() {
"" <v0>: String NEW: r("") -> <v0> "" <v0>: String NEW: r("") -> <v0>
s = "" !<v1>: * s = "" !<v1>: *
{ val s: String s = "" } !<v1>: * COPY { val s: String s = "" } !<v1>: * COPY
s <v2>: OR{*, *} NEW: r(s) -> <v2> s <v2>: * NEW: r(s) -> <v2>
"" <v3>: * NEW: r("") -> <v3> "" <v3>: * NEW: r("") -> <v3>
s == "" <v4>: Boolean NEW: call(s == "", equals|<v2>, <v3>) -> <v4> s == "" <v4>: Boolean NEW: call(s == "", equals|<v2>, <v3>) -> <v4>
do { val s: String s = "" } while (s == "") !<v5>: * do { val s: String s = "" } while (s == "") !<v5>: *
@@ -27,7 +27,7 @@ fun test2() {
<v1>: * NEW: magic[VALUE_CONSUMER](true|<v0>) -> <v1> <v1>: * NEW: magic[VALUE_CONSUMER](true|<v0>) -> <v1>
true <v0>: Boolean NEW: r(true) -> <v0> true <v0>: Boolean NEW: r(true) -> <v0>
"" <v2>: String NEW: r("") -> <v2> "" <v2>: String NEW: r("") -> <v2>
s <v3>: OR{*, *} NEW: r(s) -> <v3> s <v3>: * NEW: r(s) -> <v3>
"" <v4>: * NEW: r("") -> <v4> "" <v4>: * NEW: r("") -> <v4>
s != "" <v5>: Boolean NEW: call(s != "", equals|<v3>, <v4>) -> <v5> s != "" <v5>: Boolean NEW: call(s != "", equals|<v3>, <v4>) -> <v5>
break !<v6>: * break !<v6>: *
+1 -1
View File
@@ -17,7 +17,7 @@ a = 3 !<v1>: *
a = 5 !<v3>: * a = 5 !<v3>: *
{ a = 5 } !<v3>: * COPY { a = 5 } !<v3>: * COPY
try { a = 3 } finally { a = 5 } <v4>: * NEW: merge(try { a = 3 } finally { a = 5 }|!<v1>) -> <v4> try { a = 3 } finally { a = 5 } <v4>: * NEW: merge(try { a = 3 } finally { a = 5 }|!<v1>) -> <v4>
a <v5>: OR{{<: Any}, {<: Any}} NEW: r(a) -> <v5> a <v5>: {<: Any} NEW: r(a) -> <v5>
hashCode() <v6>: * NEW: call(hashCode(), hashCode|<v5>) -> <v6> hashCode() <v6>: * NEW: call(hashCode(), hashCode|<v5>) -> <v6>
a.hashCode() <v6>: * COPY a.hashCode() <v6>: * COPY
{ var a: Int try { a = 3 } finally { a = 5 } a.hashCode() } <v6>: * COPY { var a: Int try { a = 3 } finally { a = 5 } a.hashCode() } <v6>: * COPY
+2 -2
View File
@@ -29,11 +29,11 @@ foo(a, 3)
genfun<Any>() <v8>: * NEW: call(genfun<Any>(), genfun) -> <v8> genfun<Any>() <v8>: * NEW: call(genfun<Any>(), genfun) -> <v8>
{1} <v9>: {<: () -> Any} NEW: r({1}) -> <v9> {1} <v9>: {<: () -> Any} NEW: r({1}) -> <v9>
flfun {1} <v10>: * NEW: call(flfun {1}, flfun|<v9>) -> <v10> flfun {1} <v10>: * NEW: call(flfun {1}, flfun|<v9>) -> <v10>
3 <v11>: OR{{<: Any}, {<: Any}} NEW: r(3) -> <v11> 3 <v11>: {<: Any} NEW: r(3) -> <v11>
4 <v12>: * NEW: r(4) -> <v12> 4 <v12>: * NEW: r(4) -> <v12>
equals(4) <v13>: * NEW: call(equals(4), equals|<v11>, <v12>) -> <v13> equals(4) <v13>: * NEW: call(equals(4), equals|<v11>, <v12>) -> <v13>
3.equals(4) <v13>: * COPY 3.equals(4) <v13>: * COPY
3 <v14>: OR{{<: Any}, {<: Any}} NEW: r(3) -> <v14> 3 <v14>: {<: Any} NEW: r(3) -> <v14>
4 <v15>: * NEW: r(4) -> <v15> 4 <v15>: * NEW: r(4) -> <v15>
3 equals 4 <v16>: * NEW: call(3 equals 4, equals|<v14>, <v15>) -> <v16> 3 equals 4 <v16>: * NEW: call(3 equals 4, equals|<v14>, <v15>) -> <v16>
1 <v17>: Int NEW: r(1) -> <v17> 1 <v17>: Int NEW: r(1) -> <v17>
+1 -1
View File
@@ -6,7 +6,7 @@ fun foo(a: Int, b: Int) {
--------------------- ---------------------
<v0>: Int NEW: magic[FAKE_INITIALIZER](a: Int) -> <v0> <v0>: Int NEW: magic[FAKE_INITIALIZER](a: Int) -> <v0>
<v1>: Int NEW: magic[FAKE_INITIALIZER](b: Int) -> <v1> <v1>: Int NEW: magic[FAKE_INITIALIZER](b: Int) -> <v1>
a <v2>: OR{*, *} NEW: r(a) -> <v2> a <v2>: * NEW: r(a) -> <v2>
b <v3>: * NEW: r(b) -> <v3> b <v3>: * NEW: r(b) -> <v3>
a == b <v4>: Boolean NEW: call(a == b, equals|<v2>, <v3>) -> <v4> a == b <v4>: Boolean NEW: call(a == b, equals|<v2>, <v3>) -> <v4>
{ } !<v5>: * { } !<v5>: *
+1 -1
View File
@@ -5,7 +5,7 @@ fun neq(a: Int, b: Int) {
--------------------- ---------------------
<v0>: Int NEW: magic[FAKE_INITIALIZER](a: Int) -> <v0> <v0>: Int NEW: magic[FAKE_INITIALIZER](a: Int) -> <v0>
<v1>: Int NEW: magic[FAKE_INITIALIZER](b: Int) -> <v1> <v1>: Int NEW: magic[FAKE_INITIALIZER](b: Int) -> <v1>
a <v2>: OR{*, *} NEW: r(a) -> <v2> a <v2>: * NEW: r(a) -> <v2>
b <v3>: * NEW: r(b) -> <v3> b <v3>: * NEW: r(b) -> <v3>
a != b <v4>: Boolean NEW: call(a != b, equals|<v2>, <v3>) -> <v4> a != b <v4>: Boolean NEW: call(a != b, equals|<v2>, <v3>) -> <v4>
{} !<v5>: * {} !<v5>: *
@@ -21,7 +21,7 @@ constructor() {
} }
--------------------- ---------------------
<v0>: * NEW: call(, <init>) -> <v0> <v0>: * NEW: call(, <init>) -> <v0>
1 <v1>: OR{*, *} NEW: r(1) -> <v1> 1 <v1>: * NEW: r(1) -> <v1>
1 <v2>: * NEW: r(1) -> <v2> 1 <v2>: * NEW: r(1) -> <v2>
1 == 1 <v3>: Boolean NEW: call(1 == 1, equals|<v1>, <v2>) -> <v3> 1 == 1 <v3>: Boolean NEW: call(1 == 1, equals|<v1>, <v2>) -> <v3>
return !<v4>: * return !<v4>: *
+1 -1
View File
@@ -6,7 +6,7 @@ tailrec fun sum(x: Long, sum: Long): Long {
--------------------- ---------------------
<v0>: Long NEW: magic[FAKE_INITIALIZER](x: Long) -> <v0> <v0>: Long NEW: magic[FAKE_INITIALIZER](x: Long) -> <v0>
<v1>: Long NEW: magic[FAKE_INITIALIZER](sum: Long) -> <v1> <v1>: Long NEW: magic[FAKE_INITIALIZER](sum: Long) -> <v1>
x <v2>: OR{*, *} NEW: r(x) -> <v2> x <v2>: * NEW: r(x) -> <v2>
0 <v3>: {<: Number} NEW: r(0) -> <v3> 0 <v3>: {<: Number} NEW: r(0) -> <v3>
toLong() <v4>: * NEW: call(toLong(), toLong|<v3>) -> <v4> toLong() <v4>: * NEW: call(toLong(), toLong|<v3>) -> <v4>
0.toLong() <v4>: * COPY 0.toLong() <v4>: * COPY
@@ -34,13 +34,27 @@ object KotlinTypeFactory {
} }
} }
@JvmStatic
fun simpleType(
annotations: Annotations,
constructor: TypeConstructor,
arguments: List<TypeProjection>,
nullable: Boolean
): SimpleType {
if (annotations.isEmpty() && arguments.isEmpty() && !nullable && constructor.declarationDescriptor != null) {
return constructor.declarationDescriptor!!.defaultType
}
return SimpleTypeImpl(annotations, constructor, arguments, nullable, computeMemberScope(constructor, arguments))
}
@JvmStatic @JvmStatic
fun simpleType( fun simpleType(
annotations: Annotations, annotations: Annotations,
constructor: TypeConstructor, constructor: TypeConstructor,
arguments: List<TypeProjection>, arguments: List<TypeProjection>,
nullable: Boolean, nullable: Boolean,
memberScope: MemberScope = computeMemberScope(constructor, arguments) memberScope: MemberScope
): SimpleType = SimpleTypeImpl(annotations, constructor, arguments, nullable, memberScope) ): SimpleType = SimpleTypeImpl(annotations, constructor, arguments, nullable, memberScope)
@JvmStatic @JvmStatic