Provide optimized code generation for for-in-withIndex for sequences

#KT-5177 In Progress
This commit is contained in:
Dmitry Petrov
2018-01-22 10:01:17 +03:00
parent 2399a39414
commit 40d1925e19
22 changed files with 531 additions and 25 deletions
@@ -70,22 +70,22 @@ fun getRangeOrProgressionElementType(rangeType: KotlinType): KotlinType? {
val builtIns = rangeTypeDescriptor.builtIns
return when {
isTopLevelInPackage(rangeTypeDescriptor, "CharRange", "kotlin.ranges") -> builtIns.charType
isTopLevelInPackage(rangeTypeDescriptor, "IntRange", "kotlin.ranges") -> builtIns.intType
isTopLevelInPackage(rangeTypeDescriptor, "LongRange", "kotlin.ranges") -> builtIns.longType
rangeTypeDescriptor.isTopLevelInPackage("CharRange", "kotlin.ranges") -> builtIns.charType
rangeTypeDescriptor.isTopLevelInPackage("IntRange", "kotlin.ranges") -> builtIns.intType
rangeTypeDescriptor.isTopLevelInPackage("LongRange", "kotlin.ranges") -> builtIns.longType
isTopLevelInPackage(rangeTypeDescriptor, "CharProgression", "kotlin.ranges") -> builtIns.charType
isTopLevelInPackage(rangeTypeDescriptor, "IntProgression", "kotlin.ranges") -> builtIns.intType
isTopLevelInPackage(rangeTypeDescriptor, "LongProgression", "kotlin.ranges") -> builtIns.longType
rangeTypeDescriptor.isTopLevelInPackage("CharProgression", "kotlin.ranges") -> builtIns.charType
rangeTypeDescriptor.isTopLevelInPackage("IntProgression", "kotlin.ranges") -> builtIns.intType
rangeTypeDescriptor.isTopLevelInPackage("LongProgression", "kotlin.ranges") -> builtIns.longType
isTopLevelInPackage(rangeTypeDescriptor, "ClosedFloatRange", "kotlin.ranges") -> builtIns.floatType
isTopLevelInPackage(rangeTypeDescriptor, "ClosedDoubleRange", "kotlin.ranges") -> builtIns.doubleType
rangeTypeDescriptor.isTopLevelInPackage("ClosedFloatRange", "kotlin.ranges") -> builtIns.floatType
rangeTypeDescriptor.isTopLevelInPackage("ClosedDoubleRange", "kotlin.ranges") -> builtIns.doubleType
isTopLevelInPackage(rangeTypeDescriptor, "ClosedRange", "kotlin.ranges") -> rangeType.arguments.singleOrNull()?.type
rangeTypeDescriptor.isTopLevelInPackage("ClosedRange", "kotlin.ranges") -> rangeType.arguments.singleOrNull()?.type
isTopLevelInPackage(rangeTypeDescriptor, "ClosedFloatingPointRange", "kotlin.ranges") -> rangeType.arguments.singleOrNull()?.type
rangeTypeDescriptor.isTopLevelInPackage("ClosedFloatingPointRange", "kotlin.ranges") -> rangeType.arguments.singleOrNull()?.type
isTopLevelInPackage(rangeTypeDescriptor, "ComparableRange", "kotlin.ranges") -> rangeType.arguments.singleOrNull()?.type
rangeTypeDescriptor.isTopLevelInPackage("ComparableRange", "kotlin.ranges") -> rangeType.arguments.singleOrNull()?.type
else -> null
}
@@ -113,7 +113,7 @@ private inline fun CallableDescriptor.isTopLevelExtensionOnType(
packageFQN: String,
receiverTypePredicate: (KotlinType) -> Boolean
): Boolean {
if (!isTopLevelInPackage(this, name, packageFQN)) return false
if (!this.isTopLevelInPackage(name, packageFQN)) return false
val extensionReceiverType = original.extensionReceiverParameter?.type ?: return false
return receiverTypePredicate(extensionReceiverType)
}
@@ -153,6 +153,12 @@ fun isIterableWithIndex(descriptor: CallableDescriptor) =
KotlinBuiltIns.isIterableOrNullableIterable(it)
}
fun isSequenceWithIndex(descriptor: CallableDescriptor) =
descriptor.isTopLevelExtensionOnType("withIndex", "kotlin.sequences") {
val typeDescriptor = it.constructor.declarationDescriptor ?: return false
typeDescriptor.isTopLevelInPackage("Sequence", "kotlin.sequences")
}
fun isCharSequenceIndices(descriptor: CallableDescriptor) =
descriptor.isTopLevelExtensionOnType("indices", "kotlin.text") {
KotlinBuiltIns.isCharSequenceOrNullableCharSequence(it)
@@ -168,13 +174,13 @@ fun isComparableRangeTo(descriptor: CallableDescriptor) =
val extensionReceiverTypeDescriptor = it.constructor.declarationDescriptor as? TypeParameterDescriptor ?: return false
val upperBoundType = extensionReceiverTypeDescriptor.upperBounds.singleOrNull() ?: return false
val upperBoundClassDescriptor = upperBoundType.constructor.declarationDescriptor as? ClassDescriptor ?: return false
isTopLevelInPackage(upperBoundClassDescriptor, "Comparable", "kotlin")
upperBoundClassDescriptor.isTopLevelInPackage("Comparable", "kotlin")
}
fun isClosedRangeContains(descriptor: CallableDescriptor): Boolean {
if (descriptor.name.asString() != "contains") return false
val containingClassDescriptor = descriptor.containingDeclaration as? ClassDescriptor ?: return false
if (!isTopLevelInPackage(containingClassDescriptor, "ClosedRange", "kotlin.ranges")) return false
if (!containingClassDescriptor.isTopLevelInPackage("ClosedRange", "kotlin.ranges")) return false
return true
}
@@ -218,21 +224,21 @@ private fun isPrimitiveNumberType(type: KotlinType) =
fun isClosedFloatingPointRangeContains(descriptor: CallableDescriptor): Boolean {
if (descriptor.name.asString() != "contains") return false
val containingClassDescriptor = descriptor.containingDeclaration as? ClassDescriptor ?: return false
if (!isTopLevelInPackage(containingClassDescriptor, "ClosedFloatingPointRange", "kotlin.ranges")) return false
if (!containingClassDescriptor.isTopLevelInPackage("ClosedFloatingPointRange", "kotlin.ranges")) return false
return true
}
fun getClosedFloatingPointRangeElementType(rangeType: KotlinType): KotlinType? {
val classDescriptor = rangeType.constructor.declarationDescriptor as? ClassDescriptor ?: return null
if (!isTopLevelInPackage(classDescriptor, "ClosedFloatingPointRange", "kotlin.ranges")) return null
if (!classDescriptor.isTopLevelInPackage("ClosedFloatingPointRange", "kotlin.ranges")) return null
return rangeType.arguments.singleOrNull()?.type
}
private fun isTopLevelInPackage(descriptor: DeclarationDescriptor, name: String, packageName: String): Boolean {
if (name != descriptor.name.asString()) return false
private fun DeclarationDescriptor.isTopLevelInPackage(name: String, packageName: String): Boolean {
if (name != this.name.asString()) return false
val containingDeclaration = descriptor.containingDeclaration as? PackageFragmentDescriptor ?: return false
val containingDeclaration = containingDeclaration as? PackageFragmentDescriptor ?: return false
val packageFqName = containingDeclaration.fqName.asString()
return packageName == packageFqName
}
@@ -7,11 +7,12 @@ package org.jetbrains.kotlin.codegen.range
import org.jetbrains.kotlin.codegen.ExpressionCodegen
import org.jetbrains.kotlin.codegen.range.forLoop.ForLoopGenerator
import org.jetbrains.kotlin.codegen.range.forLoop.IterableWithIndexForLoopGenerator
import org.jetbrains.kotlin.codegen.range.forLoop.IteratorWithIndexForLoopGenerator
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.psi.KtDestructuringDeclaration
import org.jetbrains.kotlin.psi.KtForExpression
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.org.objectweb.asm.Type
class IterableWithIndexRangeValue(rangeCall: ResolvedCall<out CallableDescriptor>) : AbstractDestructuredPairRangeValue(rangeCall) {
@@ -21,6 +22,9 @@ class IterableWithIndexRangeValue(rangeCall: ResolvedCall<out CallableDescriptor
loopParameter: KtDestructuringDeclaration,
rangeCall: ResolvedCall<out CallableDescriptor>
): ForLoopGenerator =
IterableWithIndexForLoopGenerator(codegen, forExpression, loopParameter, rangeCall)
IteratorWithIndexForLoopGenerator(
codegen, forExpression, loopParameter, rangeCall,
iteratorOwnerType = Type.getType(java.lang.Iterable::class.java)
)
}
@@ -130,6 +130,8 @@ private fun ExpressionCodegen.createIntrinsifiedRangeValueOrNull(rangeCall: Reso
ArrayWithIndexRangeValue(rangeCall)
isIterableWithIndex(rangeCallee) ->
IterableWithIndexRangeValue(rangeCall)
isSequenceWithIndex(rangeCallee) ->
SequenceWithIndexRangeValue(rangeCall)
isCharSequenceWithIndex(rangeCallee) ->
CharSequenceWithIndexRangeValue(rangeCall)
isComparableRangeTo(rangeCallee) ->
@@ -0,0 +1,30 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
* that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.codegen.range
import org.jetbrains.kotlin.codegen.ExpressionCodegen
import org.jetbrains.kotlin.codegen.range.forLoop.ForLoopGenerator
import org.jetbrains.kotlin.codegen.range.forLoop.IteratorWithIndexForLoopGenerator
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.psi.KtDestructuringDeclaration
import org.jetbrains.kotlin.psi.KtForExpression
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
import org.jetbrains.org.objectweb.asm.Type
class SequenceWithIndexRangeValue(rangeCall: ResolvedCall<out CallableDescriptor>) : AbstractDestructuredPairRangeValue(rangeCall) {
override fun createDestructuredPairForLoopGenerator(
codegen: ExpressionCodegen,
forExpression: KtForExpression,
loopParameter: KtDestructuringDeclaration,
rangeCall: ResolvedCall<out CallableDescriptor>
): ForLoopGenerator =
IteratorWithIndexForLoopGenerator(
codegen, forExpression, loopParameter, rangeCall,
iteratorOwnerType = Type.getType(Sequence::class.java)
)
}
@@ -16,11 +16,12 @@ import org.jetbrains.kotlin.resolve.jvm.AsmTypes
import org.jetbrains.org.objectweb.asm.Label
import org.jetbrains.org.objectweb.asm.Type
class IterableWithIndexForLoopGenerator(
class IteratorWithIndexForLoopGenerator(
codegen: ExpressionCodegen,
forExpression: KtForExpression,
loopParameter: KtDestructuringDeclaration,
rangeCall: ResolvedCall<out CallableDescriptor>
rangeCall: ResolvedCall<out CallableDescriptor>,
private val iteratorOwnerType: Type
) : AbstractWithIndexForLoopGenerator(codegen, forExpression, loopParameter, rangeCall) {
private var iteratorVar = -1
@@ -37,8 +38,8 @@ class IterableWithIndexForLoopGenerator(
.store(StackValue.constant(0, Type.INT_TYPE), v)
iteratorVar = createLoopTempVariable(asmTypeForIterator)
codegen.generateCallReceiver(rangeCall).put(Type.getType(Iterable::class.java), v)
v.invokeinterface("java/lang/Iterable", "iterator", "()Ljava/util/Iterator;")
codegen.generateCallReceiver(rangeCall).put(iteratorOwnerType, v)
v.invokeinterface(iteratorOwnerType.internalName, "iterator", "()Ljava/util/Iterator;")
StackValue.local(iteratorVar, asmTypeForIterator).store(StackValue.onStack(asmTypeForIterator), v)
}
@@ -0,0 +1,11 @@
// WITH_RUNTIME
val xs = listOf<Any>().asSequence()
fun box(): String {
val s = StringBuilder()
for ((index, x) in xs.withIndex()) {
return "Loop over empty list should not be executed"
}
return "OK"
}
@@ -0,0 +1,14 @@
// WITH_RUNTIME
val xs = listOf("a", "b", "c", "d").asSequence()
fun box(): String {
val s = StringBuilder()
for ((index, x) in xs.withIndex()) {
s.append("$index:$x;")
}
val ss = s.toString()
return if (ss == "0:a;1:b;2:c;3:d;") "OK" else "fail: '$ss'"
}
@@ -0,0 +1,14 @@
// WITH_RUNTIME
val xs = listOf("a", "b", "c", "d").asSequence()
fun box(): String {
val s = StringBuilder()
for ((i, _) in xs.withIndex()) {
s.append("$i;")
}
val ss = s.toString()
return if (ss == "0;1;2;3;") "OK" else "fail: '$ss'"
}
@@ -0,0 +1,14 @@
// WITH_RUNTIME
val xs = listOf("a", "b", "c", "d").asSequence()
fun box(): String {
val s = StringBuilder()
for ((_, x) in xs.withIndex()) {
s.append("$x;")
}
val ss = s.toString()
return if (ss == "a;b;c;d;") "OK" else "fail: '$ss'"
}
@@ -0,0 +1,25 @@
// IGNORE_BACKEND: JS, NATIVE
// FULL_JDK
// WITH_RUNTIME
val xsl = arrayListOf("a", "b", "c", "d")
val xs = xsl.asSequence()
fun box(): String {
val s = StringBuilder()
var cmeThrown = false
try {
for ((index, x) in xs.withIndex()) {
s.append("$index:$x;")
xsl.clear()
}
} catch (e: java.util.ConcurrentModificationException) {
cmeThrown = true
}
if (!cmeThrown) return "Fail: CME should be thrown"
val ss = s.toString()
return if (ss == "0:a;") "OK" else "fail: '$ss'"
}
@@ -0,0 +1,17 @@
// WITH_RUNTIME
val xs = listOf("a", "b", "c", "d").asSequence()
fun useAny(x: Any) {}
fun box(): String {
val s = StringBuilder()
for ((index: Any, x) in xs.withIndex()) {
useAny(index)
s.append("$index:$x;")
}
val ss = s.toString()
return if (ss == "0:a;1:b;2:c;3:d;") "OK" else "fail: '$ss'"
}
@@ -0,0 +1,18 @@
// WITH_RUNTIME
val xs = listOf<Any>().asSequence()
fun box(): String {
val s = StringBuilder()
for ((index, x) in xs.withIndex()) {
return "Loop over empty list should not be executed"
}
return "OK"
}
// 0 withIndex
// 1 iterator
// 1 hasNext
// 1 next
// 0 component1
// 0 component2
@@ -0,0 +1,21 @@
// WITH_RUNTIME
val xs = listOf("a", "b", "c", "d").asSequence()
fun box(): String {
val s = StringBuilder()
for ((index, x) in xs.withIndex()) {
s.append("$index:$x;")
}
val ss = s.toString()
return if (ss == "0:a;1:b;2:c;3:d;") "OK" else "fail: '$ss'"
}
// 0 withIndex
// 1 iterator
// 1 hasNext
// 1 next
// 0 component1
// 0 component2
@@ -0,0 +1,21 @@
// WITH_RUNTIME
val xs = listOf("a", "b", "c", "d").asSequence()
fun box(): String {
val s = StringBuilder()
for ((i, _) in xs.withIndex()) {
s.append("$i;")
}
val ss = s.toString()
return if (ss == "0;1;2;3;") "OK" else "fail: '$ss'"
}
// 0 withIndex
// 1 iterator
// 1 hasNext
// 1 next
// 0 component1
// 0 component2
@@ -0,0 +1,21 @@
// WITH_RUNTIME
val xs = listOf("a", "b", "c", "d").asSequence()
fun box(): String {
val s = StringBuilder()
for ((_, x) in xs.withIndex()) {
s.append("$x;")
}
val ss = s.toString()
return if (ss == "a;b;c;d;") "OK" else "fail: '$ss'"
}
// 0 withIndex
// 1 iterator
// 1 hasNext
// 1 next
// 0 component1
// 0 component2
@@ -0,0 +1,32 @@
// IGNORE_BACKEND: JS, NATIVE
// FULL_JDK
// WITH_RUNTIME
val xsl = arrayListOf("a", "b", "c", "d")
val xs = xsl.asSequence()
fun box(): String {
val s = StringBuilder()
var cmeThrown = false
try {
for ((index, x) in xs.withIndex()) {
s.append("$index:$x;")
xsl.clear()
}
} catch (e: java.util.ConcurrentModificationException) {
cmeThrown = true
}
if (!cmeThrown) return "Fail: CME should be thrown"
val ss = s.toString()
return if (ss == "0:a;") "OK" else "fail: '$ss'"
}
// 0 withIndex
// 1 iterator
// 1 hasNext
// 1 next
// 0 component1
// 0 component2
@@ -0,0 +1,24 @@
// WITH_RUNTIME
val xs = listOf("a", "b", "c", "d").asSequence()
fun useAny(x: Any) {}
fun box(): String {
val s = StringBuilder()
for ((index: Any, x) in xs.withIndex()) {
useAny(index)
s.append("$index:$x;")
}
val ss = s.toString()
return if (ss == "0:a;1:b;2:c;3:d;") "OK" else "fail: '$ss'"
}
// 0 withIndex
// 1 iterator
// 1 hasNext
// 1 next
// 0 component1
// 0 component2
@@ -5319,6 +5319,51 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
}
}
@TestMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ForInSequenceWithIndex extends AbstractIrBlackBoxCodegenTest {
public void testAllFilesPresentInForInSequenceWithIndex() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("forInEmptySequenceWithIndex.kt")
public void testForInEmptySequenceWithIndex() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInEmptySequenceWithIndex.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndex.kt")
public void testForInSequenceWithIndex() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndex.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexNoElementVar.kt")
public void testForInSequenceWithIndexNoElementVar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexNoElementVar.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexNoIndexVar.kt")
public void testForInSequenceWithIndexNoIndexVar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexNoIndexVar.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexThrowsCME.kt")
public void testForInSequenceWithIndexThrowsCME() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexThrowsCME.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexWithExplicitlyTypedIndexVariable.kt")
public void testForInSequenceWithIndexWithExplicitlyTypedIndexVariable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexWithExplicitlyTypedIndexVariable.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/controlStructures/returnsNothing")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -5319,6 +5319,51 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
}
}
@TestMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ForInSequenceWithIndex extends AbstractBlackBoxCodegenTest {
public void testAllFilesPresentInForInSequenceWithIndex() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("forInEmptySequenceWithIndex.kt")
public void testForInEmptySequenceWithIndex() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInEmptySequenceWithIndex.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndex.kt")
public void testForInSequenceWithIndex() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndex.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexNoElementVar.kt")
public void testForInSequenceWithIndexNoElementVar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexNoElementVar.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexNoIndexVar.kt")
public void testForInSequenceWithIndexNoIndexVar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexNoIndexVar.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexThrowsCME.kt")
public void testForInSequenceWithIndexThrowsCME() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexThrowsCME.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexWithExplicitlyTypedIndexVariable.kt")
public void testForInSequenceWithIndexWithExplicitlyTypedIndexVariable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexWithExplicitlyTypedIndexVariable.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/controlStructures/returnsNothing")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -1604,6 +1604,51 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ForInSequenceWithIndex extends AbstractBytecodeTextTest {
public void testAllFilesPresentInForInSequenceWithIndex() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.ANY, true);
}
@TestMetadata("forInEmptySequenceWithIndex.kt")
public void testForInEmptySequenceWithIndex() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInEmptySequenceWithIndex.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndex.kt")
public void testForInSequenceWithIndex() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndex.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexNoElementVar.kt")
public void testForInSequenceWithIndexNoElementVar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexNoElementVar.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexNoIndexVar.kt")
public void testForInSequenceWithIndexNoIndexVar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexNoIndexVar.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexThrowsCME.kt")
public void testForInSequenceWithIndexThrowsCME() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexThrowsCME.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexWithExplicitlyTypedIndexVariable.kt")
public void testForInSequenceWithIndexWithExplicitlyTypedIndexVariable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/forLoop/forInSequenceWithIndex/forInSequenceWithIndexWithExplicitlyTypedIndexVariable.kt");
doTest(fileName);
}
}
}
@TestMetadata("compiler/testData/codegen/bytecodeText/hashCode")
@@ -5319,6 +5319,51 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
}
}
@TestMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ForInSequenceWithIndex extends AbstractLightAnalysisModeTest {
public void testAllFilesPresentInForInSequenceWithIndex() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JVM, true);
}
@TestMetadata("forInEmptySequenceWithIndex.kt")
public void testForInEmptySequenceWithIndex() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInEmptySequenceWithIndex.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndex.kt")
public void testForInSequenceWithIndex() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndex.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexNoElementVar.kt")
public void testForInSequenceWithIndexNoElementVar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexNoElementVar.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexNoIndexVar.kt")
public void testForInSequenceWithIndexNoIndexVar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexNoIndexVar.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexThrowsCME.kt")
public void testForInSequenceWithIndexThrowsCME() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexThrowsCME.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexWithExplicitlyTypedIndexVariable.kt")
public void testForInSequenceWithIndexWithExplicitlyTypedIndexVariable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexWithExplicitlyTypedIndexVariable.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/controlStructures/returnsNothing")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -5913,6 +5913,57 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
}
}
@TestMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class ForInSequenceWithIndex extends AbstractJsCodegenBoxTest {
public void testAllFilesPresentInForInSequenceWithIndex() throws Exception {
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex"), Pattern.compile("^(.+)\\.kt$"), TargetBackend.JS, true);
}
@TestMetadata("forInEmptySequenceWithIndex.kt")
public void testForInEmptySequenceWithIndex() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInEmptySequenceWithIndex.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndex.kt")
public void testForInSequenceWithIndex() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndex.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexNoElementVar.kt")
public void testForInSequenceWithIndexNoElementVar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexNoElementVar.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexNoIndexVar.kt")
public void testForInSequenceWithIndexNoIndexVar() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexNoIndexVar.kt");
doTest(fileName);
}
@TestMetadata("forInSequenceWithIndexThrowsCME.kt")
public void testForInSequenceWithIndexThrowsCME() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexThrowsCME.kt");
try {
doTest(fileName);
}
catch (Throwable ignore) {
return;
}
throw new AssertionError("Looks like this test can be unmuted. Remove IGNORE_BACKEND directive for that.");
}
@TestMetadata("forInSequenceWithIndexWithExplicitlyTypedIndexVariable.kt")
public void testForInSequenceWithIndexWithExplicitlyTypedIndexVariable() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex/forInSequenceWithIndexWithExplicitlyTypedIndexVariable.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/controlStructures/returnsNothing")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)