KT-28456 generate index arguments per expression

In the desugaring for compound assignment to a collection element,
argument expression 'i' is mapped to value parameters 'iG' and 'iS' of
corresponding 'get' and 'set' operators.
In general, these value parameters can have different indices.

This requires extra machinery in argument generation - that is, to be
able to generate a particular expression argument using an arbitrary
callback. In the vast majority of the cases this callback will just use
the corresponding StatementGenerator to generate IR subtree for the
provided expression. In case of 'get' and 'set' operator calls for an
augmented assignment expression this will map corresponding argument
expressions to pregenerated temporary variables.

Thus, in the following context:
```
  class A

  operator fun A.get(vararg xs: Int) = 0
  operator fun A.set(i: Int, j: Int, v: Int) {}
```

statement `a[1, 2] += 3` will be desugared as (in a really pseudo
Kotlin):
```
  {
    val tmp_array = a
    val tmp_index0 = 1
    val tmp_index1 = 2
    tmp_array.set(
      i = tmp_index0,
      j = tmp_index1,
      v = tmp_array.get(xs = [tmp_index0, tmp_index1]).plus(3)
    )
  }
```
This commit is contained in:
Dmitry Petrov
2018-11-27 12:03:22 +03:00
parent 036b12f408
commit 42e253b5ff
10 changed files with 311 additions and 19 deletions
@@ -957,6 +957,21 @@ public class IrTextTestCaseGenerated extends AbstractIrTextTestCase {
runTest("compiler/testData/ir/irText/expressions/kt28006.kt");
}
@TestMetadata("kt28456.kt")
public void testKt28456() throws Exception {
runTest("compiler/testData/ir/irText/expressions/kt28456.kt");
}
@TestMetadata("kt28456a.kt")
public void testKt28456a() throws Exception {
runTest("compiler/testData/ir/irText/expressions/kt28456a.kt");
}
@TestMetadata("kt28456b.kt")
public void testKt28456b() throws Exception {
runTest("compiler/testData/ir/irText/expressions/kt28456b.kt");
}
@TestMetadata("lambdaInCAO.kt")
public void testLambdaInCAO() throws Exception {
runTest("compiler/testData/ir/irText/expressions/lambdaInCAO.kt");