Implement special desugaring for numeric comparisons in PSI2IR

This introduces the following IR built-in functions required for proper
implementation of the number comparisons:

- ieee754Equals(T, T): Boolean,
    for each T in {Float?, Double?}

- less(T, T): Boolean
  lessOrEqual(T, T): Boolean
  greater(T, T): Boolean
  greaterOrEqual(T, T): Boolean
    for each T in {Int, Long, Float, Double}
This commit is contained in:
Dmitry Petrov
2018-02-01 16:18:01 +03:00
parent f4ed4ec9d9
commit 9137e68d4e
33 changed files with 1566 additions and 233 deletions
+3 -4
View File
@@ -39,18 +39,17 @@ CONTENT
1 SET_VAR 'number: Int' type=kotlin.Unit origin=DIVEQ
2 GET_VAR 'number: Int' type=kotlin.Int origin=null
3 CONST Int type=kotlin.Int value=0
4 CALL 'compareTo(Int): Int' type=kotlin.Int origin=GT
OUTGOING -> BB 4, 5
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Int, Int): Boolean' type=kotlin.Boolean origin=GT
BB 4
INCOMING <- BB 3
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Int, Int): Boolean' type=kotlin.Boolean origin=GT
CONTENT
OUTGOING -> BB 1
Do..while entry: DO_WHILE label=null origin=DO_WHILE_LOOP
BB 5
INCOMING <- BB 3
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Int, Int): Boolean' type=kotlin.Boolean origin=GT
CONTENT
OUTGOING -> BB 6
Do..while exit: DO_WHILE label=null origin=DO_WHILE_LOOP
+6 -8
View File
@@ -34,37 +34,35 @@ CONTENT
6 GET_VAR 'm: Int' type=kotlin.Int origin=null
7 CALL 'rem(Int): Int' type=kotlin.Int origin=PERC
8 CONST Int type=kotlin.Int value=0
9 CALL 'compareTo(Int): Int' type=kotlin.Int origin=GT
OUTGOING -> BB 3, 4
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Int, Int): Boolean' type=kotlin.Boolean origin=GT
BB 3
INCOMING <- BB 2
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Int, Int): Boolean' type=kotlin.Boolean origin=GT
CONTENT
1 CONTINUE label=null loop.label=null
OUTGOING -> BB 1
While entry: WHILE label=null origin=FOR_LOOP_INNER_WHILE
BB 4
INCOMING <- BB 2
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Int, Int): Boolean' type=kotlin.Boolean origin=GT
CONTENT
1 SET_VAR 'sum: Int' type=kotlin.Unit origin=PLUSEQ
2 WHEN type=kotlin.Unit origin=null
3 GET_VAR 'sum: Int' type=kotlin.Int origin=null
4 GET_VAR 'value-parameter n: Int' type=kotlin.Int origin=null
5 CALL 'compareTo(Int): Int' type=kotlin.Int origin=GT
OUTGOING -> BB 5, 6
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Int, Int): Boolean' type=kotlin.Boolean origin=GT
BB 5
INCOMING <- BB 4
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Int, Int): Boolean' type=kotlin.Boolean origin=GT
CONTENT
1 BREAK label=null loop.label=null
OUTGOING -> BB 8
While exit: WHILE label=null origin=FOR_LOOP_INNER_WHILE
BB 6
INCOMING <- BB 4
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Int, Int): Boolean' type=kotlin.Boolean origin=GT
CONTENT
OUTGOING -> BB 1
While entry: WHILE label=null origin=FOR_LOOP_INNER_WHILE
+6 -8
View File
@@ -6,34 +6,32 @@ CONTENT
2 WHEN type=kotlin.Int origin=WHEN
3 GET_VAR 'value-parameter x: Int' type=kotlin.Int origin=null
4 GET_VAR 'value-parameter y: Int' type=kotlin.Int origin=null
5 CALL 'compareTo(Int): Int' type=kotlin.Int origin=GT
OUTGOING -> BB 1, 3
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Int, Int): Boolean' type=kotlin.Boolean origin=GT
BB 1
INCOMING <- BB 0
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Int, Int): Boolean' type=kotlin.Boolean origin=GT
CONTENT
1 GET_VAR 'value-parameter x: Int' type=kotlin.Int origin=null
2 GET_VAR 'value-parameter y: Int' type=kotlin.Int origin=null
3 CALL 'compareTo(Int): Int' type=kotlin.Int origin=LT
OUTGOING -> BB 2, 4
CALL 'LT0(Int): Boolean' type=kotlin.Boolean origin=LT
CALL 'less(Int, Int): Boolean' type=kotlin.Boolean origin=LT
BB 2
INCOMING <- BB 1
CALL 'LT0(Int): Boolean' type=kotlin.Boolean origin=LT
CALL 'less(Int, Int): Boolean' type=kotlin.Boolean origin=LT
CONTENT
OUTGOING -> BB 5
CONST Boolean type=kotlin.Boolean value=true
BB 3
INCOMING <- BB 0
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Int, Int): Boolean' type=kotlin.Boolean origin=GT
CONTENT
1 CONST Int type=kotlin.Int value=1
OUTGOING -> BB 6
When exit: WHEN type=kotlin.Int origin=WHEN
BB 4
INCOMING <- BB 1
CALL 'LT0(Int): Boolean' type=kotlin.Boolean origin=LT
CALL 'less(Int, Int): Boolean' type=kotlin.Boolean origin=LT
CONTENT
1 CONST Int type=kotlin.Int value=-1
OUTGOING -> BB 6
+3 -4
View File
@@ -6,18 +6,17 @@ CONTENT
2 WHEN type=kotlin.Int origin=null
3 GET_VAR 'value-parameter x: Int' type=kotlin.Int origin=null
4 GET_VAR 'value-parameter y: Int' type=kotlin.Int origin=null
5 CALL 'compareTo(Int): Int' type=kotlin.Int origin=GT
OUTGOING -> BB 1, 2
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Int, Int): Boolean' type=kotlin.Boolean origin=GT
BB 1
INCOMING <- BB 0
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Int, Int): Boolean' type=kotlin.Boolean origin=GT
CONTENT
OUTGOING -> BB 3
CONST Boolean type=kotlin.Boolean value=true
BB 2
INCOMING <- BB 0
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Int, Int): Boolean' type=kotlin.Boolean origin=GT
CONTENT
1 GET_VAR 'value-parameter x: Int' type=kotlin.Int origin=null
OUTGOING -> BB 4
+18 -22
View File
@@ -7,19 +7,19 @@ CONTENT
3 GET_VAR 'value-parameter a: Double' type=kotlin.Double origin=null
4 CONST Double type=kotlin.Double value=0.0
OUTGOING -> BB 1, 6
CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EQEQ
CALL 'ieee754equals(Double?, Double?): Boolean' type=kotlin.Boolean origin=EQEQ
BB 1
INCOMING <- BB 0
CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EQEQ
CALL 'ieee754equals(Double?, Double?): Boolean' type=kotlin.Boolean origin=EQEQ
CONTENT
1 WHEN type=kotlin.Unit origin=null
2 GET_VAR 'value-parameter b: Double' type=kotlin.Double origin=null
3 CONST Double type=kotlin.Double value=0.0
OUTGOING -> BB 2, 3
CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EQEQ
CALL 'ieee754equals(Double?, Double?): Boolean' type=kotlin.Boolean origin=EQEQ
BB 2
INCOMING <- BB 1
CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EQEQ
CALL 'ieee754equals(Double?, Double?): Boolean' type=kotlin.Boolean origin=EQEQ
CONTENT
1 CONST Double type=kotlin.Double value=1.0
2 RETURN type=kotlin.Nothing from='minBiRoot(Double, Double, Double): Double'
@@ -27,7 +27,7 @@ OUTGOING -> NONE
Function exit: FUN name:minBiRoot visibility:public modality:FINAL <> (a:kotlin.Double, b:kotlin.Double, c:kotlin.Double) returnType:Double flags:
BB 3
INCOMING <- BB 1
CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EQEQ
CALL 'ieee754equals(Double?, Double?): Boolean' type=kotlin.Boolean origin=EQEQ
CONTENT
1 GET_VAR 'value-parameter c: Double' type=kotlin.Double origin=null
2 CALL 'unaryMinus(): Double' type=kotlin.Double origin=UMINUS
@@ -37,12 +37,11 @@ CONTENT
6 WHEN type=kotlin.Unit origin=null
7 GET_VAR 'bc: Double' type=kotlin.Double origin=null
8 CONST Double type=kotlin.Double value=0.0
9 CALL 'compareTo(Double): Int' type=kotlin.Int origin=LT
OUTGOING -> BB 4, 5
CALL 'LT0(Int): Boolean' type=kotlin.Boolean origin=LT
CALL 'less(Double, Double): Boolean' type=kotlin.Boolean origin=LT
BB 4
INCOMING <- BB 3
CALL 'LT0(Int): Boolean' type=kotlin.Boolean origin=LT
CALL 'less(Double, Double): Boolean' type=kotlin.Boolean origin=LT
CONTENT
1 CONST Double type=kotlin.Double value=2.0
2 RETURN type=kotlin.Nothing from='minBiRoot(Double, Double, Double): Double'
@@ -50,7 +49,7 @@ OUTGOING -> NONE
Function exit: FUN name:minBiRoot visibility:public modality:FINAL <> (a:kotlin.Double, b:kotlin.Double, c:kotlin.Double) returnType:Double flags:
BB 5
INCOMING <- BB 3
CALL 'LT0(Int): Boolean' type=kotlin.Boolean origin=LT
CALL 'less(Double, Double): Boolean' type=kotlin.Boolean origin=LT
CONTENT
1 GET_VAR 'bc: Double' type=kotlin.Double origin=null
2 CALL 'unaryMinus(): Double' type=kotlin.Double origin=UMINUS
@@ -59,7 +58,7 @@ OUTGOING -> NONE
Function exit: FUN name:minBiRoot visibility:public modality:FINAL <> (a:kotlin.Double, b:kotlin.Double, c:kotlin.Double) returnType:Double flags:
BB 6
INCOMING <- BB 0
CALL 'EQEQ(Any?, Any?): Boolean' type=kotlin.Boolean origin=EQEQ
CALL 'ieee754equals(Double?, Double?): Boolean' type=kotlin.Boolean origin=EQEQ
CONTENT
1 GET_VAR 'value-parameter b: Double' type=kotlin.Double origin=null
2 GET_VAR 'value-parameter b: Double' type=kotlin.Double origin=null
@@ -74,12 +73,11 @@ CONTENT
11 WHEN type=kotlin.Unit origin=null
12 GET_VAR 'd: Double' type=kotlin.Double origin=null
13 CONST Double type=kotlin.Double value=0.0
14 CALL 'compareTo(Double): Int' type=kotlin.Int origin=LT
OUTGOING -> BB 7, 8
CALL 'LT0(Int): Boolean' type=kotlin.Boolean origin=LT
CALL 'less(Double, Double): Boolean' type=kotlin.Boolean origin=LT
BB 7
INCOMING <- BB 6
CALL 'LT0(Int): Boolean' type=kotlin.Boolean origin=LT
CALL 'less(Double, Double): Boolean' type=kotlin.Boolean origin=LT
CONTENT
1 CONST Double type=kotlin.Double value=3.0
2 RETURN type=kotlin.Nothing from='minBiRoot(Double, Double, Double): Double'
@@ -87,7 +85,7 @@ OUTGOING -> NONE
Function exit: FUN name:minBiRoot visibility:public modality:FINAL <> (a:kotlin.Double, b:kotlin.Double, c:kotlin.Double) returnType:Double flags:
BB 8
INCOMING <- BB 6
CALL 'LT0(Int): Boolean' type=kotlin.Boolean origin=LT
CALL 'less(Double, Double): Boolean' type=kotlin.Boolean origin=LT
CONTENT
1 GET_VAR 'value-parameter b: Double' type=kotlin.Double origin=null
2 CALL 'unaryMinus(): Double' type=kotlin.Double origin=UMINUS
@@ -110,18 +108,17 @@ CONTENT
19 WHEN type=kotlin.Double origin=null
20 GET_VAR 'y1: Double' type=kotlin.Double origin=null
21 GET_VAR 'y2: Double' type=kotlin.Double origin=null
22 CALL 'compareTo(Double): Int' type=kotlin.Int origin=GT
OUTGOING -> BB 9, 10
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Double, Double): Boolean' type=kotlin.Boolean origin=GT
BB 9
INCOMING <- BB 8
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Double, Double): Boolean' type=kotlin.Boolean origin=GT
CONTENT
OUTGOING -> BB 11
CONST Boolean type=kotlin.Boolean value=true
BB 10
INCOMING <- BB 8
CALL 'GT0(Int): Boolean' type=kotlin.Boolean origin=GT
CALL 'greater(Double, Double): Boolean' type=kotlin.Boolean origin=GT
CONTENT
1 GET_VAR 'y1: Double' type=kotlin.Double origin=null
OUTGOING -> BB 12
@@ -141,18 +138,17 @@ CONTENT
2 WHEN type=kotlin.Double origin=null
3 GET_VAR 'y3: Double' type=kotlin.Double origin=null
4 CONST Double type=kotlin.Double value=0.0
5 CALL 'compareTo(Double): Int' type=kotlin.Int origin=LT
OUTGOING -> BB 13, 14
CALL 'LT0(Int): Boolean' type=kotlin.Boolean origin=LT
CALL 'less(Double, Double): Boolean' type=kotlin.Boolean origin=LT
BB 13
INCOMING <- BB 12
CALL 'LT0(Int): Boolean' type=kotlin.Boolean origin=LT
CALL 'less(Double, Double): Boolean' type=kotlin.Boolean origin=LT
CONTENT
OUTGOING -> BB 15
CONST Boolean type=kotlin.Boolean value=true
BB 14
INCOMING <- BB 12
CALL 'LT0(Int): Boolean' type=kotlin.Boolean origin=LT
CALL 'less(Double, Double): Boolean' type=kotlin.Boolean origin=LT
CONTENT
1 CONST Double type=kotlin.Double value=4.0
OUTGOING -> BB 16