[IR] Fix issue getting the length property from CharSequence bounded type parameter

Use the class of the subtype of CharSequence when available. When
it is not (for type parameters bounded by CharSequence) call the
CharSequence getter and 'get' method. Using the most specific type
posible fixes the forInStringSpecialized test that expects the
use of INVOKEVIRTUAL and not INVOKEINTERFACE.

Add tests for the type parameter use.
This commit is contained in:
Mads Ager
2019-09-03 13:39:27 +02:00
committed by max-kammerer
parent eb5e91d6bb
commit 3f28b71509
5 changed files with 79 additions and 11 deletions
@@ -0,0 +1,10 @@
fun <T: CharSequence> test(sequence: T) {
var s = ""
for (c in sequence) {
s += c
}
}
// 0 iterator
// 0 hasNext
// 0 nextChar
@@ -0,0 +1,27 @@
fun <T: CharSequence> test(s: T): Int {
var result = 0
for (i in s.indices) {
result = result * 10 + (i + 1)
}
return result
}
// JVM non-IR uses while.
// JVM IR uses if + do-while.
// 0 iterator
// 0 getStart
// 0 getEnd
// 0 getFirst
// 0 getLast
// JVM_TEMPLATES
// 0 IF_ICMPGT
// 0 IF_ICMPEQ
// 1 IF_ICMPGE
// 1 IF
// JVM_IR_TEMPLATES
// 1 IF_ICMPGT
// 1 IF_ICMPLE
// 2 IF