From 157db778fd15d5a2cb8143910493c3fcfbae6ed6 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 25 Feb 2022 23:24:35 +0100 Subject: [PATCH] Rework support of `Iterator.iterator` optimization in ForLoopsLowering - Fix the predicate used for finding the member function `next`: check that there's no extension receiver parameter, don't filter out abstract functions. - Do not copy iterator expression, instead change the type in all references to the iterator variable. - Fix some style issues. #KT-47171 Fixed --- .../FirBlackBoxCodegenTestGenerated.java | 50 ++++++++---- .../common/lower/loops/ForLoopsLowering.kt | 81 +++++++++---------- .../jetbrains/kotlin/ir/types/IrTypeUtils.kt | 3 + .../forInIterator/abstractNext.kt | 24 ++++++ .../forInIterator/primitiveIterator.kt | 24 ++++++ .../forInIterator/uintIterator.kt} | 3 +- .../unrelatedExtensionFunctionNext.kt | 22 +++++ .../codegen/box/forLoop/forInIterator.txt | 17 ---- .../codegen/BlackBoxCodegenTestGenerated.java | 50 ++++++++---- .../IrBlackBoxCodegenTestGenerated.java | 50 ++++++++---- .../LightAnalysisModeTestGenerated.java | 51 +++++++----- .../js/test/JsCodegenBoxTestGenerated.java | 20 ++--- .../test/ir/IrJsCodegenBoxTestGenerated.java | 20 ++--- .../IrCodegenBoxWasmTestGenerated.java | 26 +++--- .../NativeCodegenBoxTestGenerated.java | 24 +++--- 15 files changed, 293 insertions(+), 172 deletions(-) create mode 100644 compiler/testData/codegen/box/controlStructures/forInIterator/abstractNext.kt create mode 100644 compiler/testData/codegen/box/controlStructures/forInIterator/primitiveIterator.kt rename compiler/testData/codegen/box/{forLoop/forInIterator.kt => controlStructures/forInIterator/uintIterator.kt} (90%) create mode 100644 compiler/testData/codegen/box/controlStructures/forInIterator/unrelatedExtensionFunctionNext.kt delete mode 100644 compiler/testData/codegen/box/forLoop/forInIterator.txt diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 80d07799bab..ab2beb4c133 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -9335,6 +9335,40 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT } } + @Nested + @TestMetadata("compiler/testData/codegen/box/controlStructures/forInIterator") + @TestDataPath("$PROJECT_ROOT") + public class ForInIterator { + @Test + @TestMetadata("abstractNext.kt") + public void testAbstractNext() throws Exception { + runTest("compiler/testData/codegen/box/controlStructures/forInIterator/abstractNext.kt"); + } + + @Test + public void testAllFilesPresentInForInIterator() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInIterator"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("primitiveIterator.kt") + public void testPrimitiveIterator() throws Exception { + runTest("compiler/testData/codegen/box/controlStructures/forInIterator/primitiveIterator.kt"); + } + + @Test + @TestMetadata("uintIterator.kt") + public void testUintIterator() throws Exception { + runTest("compiler/testData/codegen/box/controlStructures/forInIterator/uintIterator.kt"); + } + + @Test + @TestMetadata("unrelatedExtensionFunctionNext.kt") + public void testUnrelatedExtensionFunctionNext() throws Exception { + runTest("compiler/testData/codegen/box/controlStructures/forInIterator/unrelatedExtensionFunctionNext.kt"); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex") @TestDataPath("$PROJECT_ROOT") @@ -17266,22 +17300,6 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT } } - @Nested - @TestMetadata("compiler/testData/codegen/box/forLoop") - @TestDataPath("$PROJECT_ROOT") - public class ForLoop { - @Test - public void testAllFilesPresentInForLoop() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/forLoop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); - } - - @Test - @TestMetadata("forInIterator.kt") - public void testForInIterator() throws Exception { - runTest("compiler/testData/codegen/box/forLoop/forInIterator.kt"); - } - } - @Nested @TestMetadata("compiler/testData/codegen/box/fullJdk") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ForLoopsLowering.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ForLoopsLowering.kt index 0835820ca88..48e3a08bcdc 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ForLoopsLowering.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/lower/loops/ForLoopsLowering.kt @@ -10,20 +10,21 @@ import org.jetbrains.kotlin.backend.common.CommonBackendContext import org.jetbrains.kotlin.backend.common.IrElementTransformerVoidWithContext import org.jetbrains.kotlin.backend.common.lower.createIrBuilder import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase -import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.ir.IrElement import org.jetbrains.kotlin.ir.IrStatement -import org.jetbrains.kotlin.ir.builders.irCall -import org.jetbrains.kotlin.ir.declarations.* +import org.jetbrains.kotlin.ir.declarations.IrDeclaration +import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin +import org.jetbrains.kotlin.ir.declarations.IrSymbolOwner +import org.jetbrains.kotlin.ir.declarations.IrVariable import org.jetbrains.kotlin.ir.expressions.* +import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl import org.jetbrains.kotlin.ir.expressions.impl.IrCompositeImpl -import org.jetbrains.kotlin.ir.types.classFqName -import org.jetbrains.kotlin.ir.types.classifierOrFail +import org.jetbrains.kotlin.ir.types.getClass +import org.jetbrains.kotlin.ir.types.isStrictSubtypeOfClass import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.ir.visitors.* import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.utils.addToStdlib.cast -import org.jetbrains.kotlin.utils.addToStdlib.safeAs +import org.jetbrains.kotlin.util.OperatorNameConventions val forLoopsPhase = makeIrFilePhase( ::ForLoopsLowering, @@ -305,52 +306,44 @@ private class RangeLoopTransformer( * for (x in iterator) * println(x) * ``` - * Without this optimization, receiver type of call of `next` would be Iterator instead of MyIterator, which - * is an unnecessary boxing can be optimized out. + * Without this optimization, receiver type of call of `next` would be Iterator instead of MyIterator, which means that + * a less specific method would be called, which could lead to unnecessary boxing of primitives or inline classes. */ private fun specializeIteratorIfPossible(irForLoopBlock: IrContainerExpression) { val statements = irForLoopBlock.statements - val iterator = statements[0] as IrVariable - val loop = statements[1] as IrWhileLoop - // do optimization iff the initializer is call of `kotlin.collections.CollectionsKt.iterator` - val initializer = iterator.initializer.safeAs().takeIf { - it != null && it.symbol.owner.fqNameWhenAvailable == FqName("kotlin.collections.CollectionsKt.iterator") + val initializer = iterator.initializer as? IrCall ?: return + if (!initializer.symbol.owner.hasEqualFqName(STDLIB_ITERATOR_FUNCTION_FQ_NAME)) return + + val receiverType = initializer.extensionReceiver?.type ?: return + if (!receiverType.isStrictSubtypeOfClass(context.irBuiltIns.iteratorClass)) return + + val receiverClass = receiverType.getClass() ?: return + val next = receiverClass.functions.singleOrNull { + it.name == OperatorNameConventions.NEXT && + it.dispatchReceiverParameter != null && + it.extensionReceiverParameter == null && + it.valueParameters.isEmpty() } ?: return - // for now, we only optimize for the case where extension receiver is a direct subclass of `kotlin.collections.Iterator` - // we can expand the scope later, if it considered to be necessary - val receiverType = initializer.extensionReceiver!!.type.takeIf { - it.superTypes().any { superType -> - superType.classFqName == FqName("kotlin.collections.Iterator") - } - } ?: return - - fun IrClass.findNextFunction(): IrFunction? = - this.functions.find { - it.nameForIrSerialization.asString() == "next" - && it.valueParameters.isEmpty() - && it.modality != Modality.ABSTRACT - } - - val next = receiverType.classifierOrFail.owner.cast().findNextFunction() ?: return - - val loopVariable = (loop.body as IrBlock).statements[0] as IrVariable - val loopCondition = loop.condition as IrCall - iterator.apply { - type = receiverType + this.type = receiverType this.initializer = initializer.extensionReceiver } - loopCondition.apply { - dispatchReceiver = initializer.extensionReceiver!!.shallowCopy() - } + val loop = statements[1] as IrWhileLoop + val loopVariable = (loop.body as? IrBlock)?.statements?.firstOrNull() as? IrVariable ?: return + val loopCondition = loop.condition as? IrCall ?: return + loopCondition.dispatchReceiver?.type = receiverType - loopVariable.initializer = with(next) { - context.createIrBuilder(symbol, startOffset, endOffset).irCall(this).apply { - dispatchReceiver = initializer.extensionReceiver!!.shallowCopy() + val nextCall = loopVariable.initializer as? IrCall ?: return + loopVariable.initializer = with(nextCall) { + IrCallImpl( + startOffset, endOffset, type, next.symbol, typeArgumentsCount, valueArgumentsCount, origin, superQualifierSymbol + ).apply { + copyTypeAndValueArgumentsFrom(nextCall) + dispatchReceiver?.type = receiverType } } } @@ -471,4 +464,8 @@ private class RangeLoopTransformer( return LoopVariableInfo(mainLoopVariable, mainLoopVariableIndex, loopVariableComponents, loopVariableComponentIndices) } -} \ No newline at end of file + + companion object { + val STDLIB_ITERATOR_FUNCTION_FQ_NAME = FqName("kotlin.collections.CollectionsKt.iterator") + } +} diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeUtils.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeUtils.kt index 9916e8ae419..d788f6ca945 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeUtils.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/types/IrTypeUtils.kt @@ -29,6 +29,9 @@ fun IrClassifierSymbol.isStrictSubtypeOfClass(superClass: IrClassSymbol): Boolea fun IrType.isSubtypeOfClass(superClass: IrClassSymbol): Boolean = this is IrSimpleType && classifier.isSubtypeOfClass(superClass) +fun IrType.isStrictSubtypeOfClass(superClass: IrClassSymbol): Boolean = + this is IrSimpleType && classifier.isStrictSubtypeOfClass(superClass) + fun IrType.isSubtypeOf(superType: IrType, typeSystem: IrTypeSystemContext): Boolean = AbstractTypeChecker.isSubtypeOf(createIrTypeCheckerState(typeSystem), this, superType) diff --git a/compiler/testData/codegen/box/controlStructures/forInIterator/abstractNext.kt b/compiler/testData/codegen/box/controlStructures/forInIterator/abstractNext.kt new file mode 100644 index 00000000000..184ea3c048c --- /dev/null +++ b/compiler/testData/codegen/box/controlStructures/forInIterator/abstractNext.kt @@ -0,0 +1,24 @@ +// TARGET_BACKEND: JVM +// WITH_STDLIB + +fun iterate(iterator: MyIterator): String { + for (x in iterator) return x + return "Fail" +} + +abstract class MyIterator : Iterator { + override fun hasNext(): Boolean = true + abstract override fun next(): String +} + +class MyIteratorImpl : MyIterator() { + override fun next(): String = "OK" +} + +fun box(): String = iterate(MyIteratorImpl()) + +// CHECK_BYTECODE_TEXT +// JVM_IR_TEMPLATES +// 0 java/util/Iterator.next +// 1 MyIterator.next +// 1 MyIteratorImpl.next diff --git a/compiler/testData/codegen/box/controlStructures/forInIterator/primitiveIterator.kt b/compiler/testData/codegen/box/controlStructures/forInIterator/primitiveIterator.kt new file mode 100644 index 00000000000..a7b957d4ae7 --- /dev/null +++ b/compiler/testData/codegen/box/controlStructures/forInIterator/primitiveIterator.kt @@ -0,0 +1,24 @@ +// TARGET_BACKEND: JVM +// WITH_STDLIB + +fun myFun(iterator: MyLongIterator) { + for (x in iterator) { + assert(x == 42L) + } +} + +class MyLongIterator : Iterator { + private var count = 1 + override fun hasNext(): Boolean = count-- > 0 + override fun next(): Long = 42L +} + +fun box(): String { + myFun(MyLongIterator()) + return "OK" +} + +// CHECK_BYTECODE_TEXT +// JVM_IR_TEMPLATES +// 0 java/util/Iterator.next +// 2 MyLongIterator.next diff --git a/compiler/testData/codegen/box/forLoop/forInIterator.kt b/compiler/testData/codegen/box/controlStructures/forInIterator/uintIterator.kt similarity index 90% rename from compiler/testData/codegen/box/forLoop/forInIterator.kt rename to compiler/testData/codegen/box/controlStructures/forInIterator/uintIterator.kt index 75f1f6bfe98..e22953b4698 100644 --- a/compiler/testData/codegen/box/forLoop/forInIterator.kt +++ b/compiler/testData/codegen/box/controlStructures/forInIterator/uintIterator.kt @@ -1,6 +1,5 @@ // TARGET_BACKEND: JVM // WITH_STDLIB -// CHECK_BYTECODE_LISTING fun myFun(iterator: MyUIntIterator) { for (x in iterator) { @@ -25,4 +24,4 @@ fun box(): String { // 0 java/util/Iterator.next \(\)Ljava/lang/Object; // 1 MyUIntIterator.hasNext \(\)Z // 1 public synthetic bridge next\(\)Ljava/lang/Object; -// 2 MyUIntIterator.next-pVg5ArA \(\)I \ No newline at end of file +// 2 MyUIntIterator.next-pVg5ArA \(\)I diff --git a/compiler/testData/codegen/box/controlStructures/forInIterator/unrelatedExtensionFunctionNext.kt b/compiler/testData/codegen/box/controlStructures/forInIterator/unrelatedExtensionFunctionNext.kt new file mode 100644 index 00000000000..c3ab4c726e4 --- /dev/null +++ b/compiler/testData/codegen/box/controlStructures/forInIterator/unrelatedExtensionFunctionNext.kt @@ -0,0 +1,22 @@ +// TARGET_BACKEND: JVM +// WITH_STDLIB + +fun iterate(iterator: MyIterator): String { + for (x in iterator) return x + return "Fail" +} + +class MyIterator : Iterator { + @JvmName("unrelated") + private fun String.next(): String = throw AssertionError("Should not be called") + + override fun hasNext(): Boolean = true + override fun next(): String = "OK" +} + +fun box(): String = iterate(MyIterator()) + +// CHECK_BYTECODE_TEXT +// JVM_IR_TEMPLATES +// 0 java/util/Iterator.next +// 2 MyIterator.next diff --git a/compiler/testData/codegen/box/forLoop/forInIterator.txt b/compiler/testData/codegen/box/forLoop/forInIterator.txt deleted file mode 100644 index c1d5c03ebd2..00000000000 --- a/compiler/testData/codegen/box/forLoop/forInIterator.txt +++ /dev/null @@ -1,17 +0,0 @@ -@kotlin.Metadata -public final class ForInIteratorKt { - // source: 'forInIterator.kt' - public final static @org.jetbrains.annotations.NotNull method box(): java.lang.String - public final static method myFun(@org.jetbrains.annotations.NotNull p0: MyUIntIterator): void -} - -@kotlin.Metadata -public final class MyUIntIterator { - // source: 'forInIterator.kt' - private field count: int - public method (): void - public method hasNext(): boolean - public synthetic bridge method next(): java.lang.Object - public method next-pVg5ArA(): int - public method remove(): void -} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index 1d4bd0a2397..ac1aa4928ba 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -9215,6 +9215,40 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } } + @Nested + @TestMetadata("compiler/testData/codegen/box/controlStructures/forInIterator") + @TestDataPath("$PROJECT_ROOT") + public class ForInIterator { + @Test + @TestMetadata("abstractNext.kt") + public void testAbstractNext() throws Exception { + runTest("compiler/testData/codegen/box/controlStructures/forInIterator/abstractNext.kt"); + } + + @Test + public void testAllFilesPresentInForInIterator() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInIterator"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @Test + @TestMetadata("primitiveIterator.kt") + public void testPrimitiveIterator() throws Exception { + runTest("compiler/testData/codegen/box/controlStructures/forInIterator/primitiveIterator.kt"); + } + + @Test + @TestMetadata("uintIterator.kt") + public void testUintIterator() throws Exception { + runTest("compiler/testData/codegen/box/controlStructures/forInIterator/uintIterator.kt"); + } + + @Test + @TestMetadata("unrelatedExtensionFunctionNext.kt") + public void testUnrelatedExtensionFunctionNext() throws Exception { + runTest("compiler/testData/codegen/box/controlStructures/forInIterator/unrelatedExtensionFunctionNext.kt"); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex") @TestDataPath("$PROJECT_ROOT") @@ -16846,22 +16880,6 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { } } - @Nested - @TestMetadata("compiler/testData/codegen/box/forLoop") - @TestDataPath("$PROJECT_ROOT") - public class ForLoop { - @Test - public void testAllFilesPresentInForLoop() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/forLoop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); - } - - @Test - @TestMetadata("forInIterator.kt") - public void testForInIterator() throws Exception { - runTest("compiler/testData/codegen/box/forLoop/forInIterator.kt"); - } - } - @Nested @TestMetadata("compiler/testData/codegen/box/fullJdk") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index bfc96faad76..87f15c13aa1 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -9335,6 +9335,40 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes } } + @Nested + @TestMetadata("compiler/testData/codegen/box/controlStructures/forInIterator") + @TestDataPath("$PROJECT_ROOT") + public class ForInIterator { + @Test + @TestMetadata("abstractNext.kt") + public void testAbstractNext() throws Exception { + runTest("compiler/testData/codegen/box/controlStructures/forInIterator/abstractNext.kt"); + } + + @Test + public void testAllFilesPresentInForInIterator() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInIterator"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("primitiveIterator.kt") + public void testPrimitiveIterator() throws Exception { + runTest("compiler/testData/codegen/box/controlStructures/forInIterator/primitiveIterator.kt"); + } + + @Test + @TestMetadata("uintIterator.kt") + public void testUintIterator() throws Exception { + runTest("compiler/testData/codegen/box/controlStructures/forInIterator/uintIterator.kt"); + } + + @Test + @TestMetadata("unrelatedExtensionFunctionNext.kt") + public void testUnrelatedExtensionFunctionNext() throws Exception { + runTest("compiler/testData/codegen/box/controlStructures/forInIterator/unrelatedExtensionFunctionNext.kt"); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex") @TestDataPath("$PROJECT_ROOT") @@ -17266,22 +17300,6 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes } } - @Nested - @TestMetadata("compiler/testData/codegen/box/forLoop") - @TestDataPath("$PROJECT_ROOT") - public class ForLoop { - @Test - public void testAllFilesPresentInForLoop() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/forLoop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); - } - - @Test - @TestMetadata("forInIterator.kt") - public void testForInIterator() throws Exception { - runTest("compiler/testData/codegen/box/forLoop/forInIterator.kt"); - } - } - @Nested @TestMetadata("compiler/testData/codegen/box/fullJdk") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index afde920f74e..fbe77ac8315 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -7173,6 +7173,39 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes } } + @TestMetadata("compiler/testData/codegen/box/controlStructures/forInIterator") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ForInIterator extends AbstractLightAnalysisModeTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + @TestMetadata("abstractNext.kt") + public void testAbstractNext() throws Exception { + runTest("compiler/testData/codegen/box/controlStructures/forInIterator/abstractNext.kt"); + } + + public void testAllFilesPresentInForInIterator() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInIterator"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @TestMetadata("primitiveIterator.kt") + public void testPrimitiveIterator() throws Exception { + runTest("compiler/testData/codegen/box/controlStructures/forInIterator/primitiveIterator.kt"); + } + + @TestMetadata("uintIterator.kt") + public void testUintIterator() throws Exception { + runTest("compiler/testData/codegen/box/controlStructures/forInIterator/uintIterator.kt"); + } + + @TestMetadata("unrelatedExtensionFunctionNext.kt") + public void testUnrelatedExtensionFunctionNext() throws Exception { + runTest("compiler/testData/codegen/box/controlStructures/forInIterator/unrelatedExtensionFunctionNext.kt"); + } + } + @TestMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -13929,24 +13962,6 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes } } - @TestMetadata("compiler/testData/codegen/box/forLoop") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class ForLoop extends AbstractLightAnalysisModeTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); - } - - public void testAllFilesPresentInForLoop() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/forLoop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); - } - - @TestMetadata("forInIterator.kt") - public void testForInIterator() throws Exception { - runTest("compiler/testData/codegen/box/forLoop/forInIterator.kt"); - } - } - @TestMetadata("compiler/testData/codegen/box/fullJdk") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java index 2cd8c1de76b..1971169c316 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/JsCodegenBoxTestGenerated.java @@ -6415,6 +6415,16 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { } } + @Nested + @TestMetadata("compiler/testData/codegen/box/controlStructures/forInIterator") + @TestDataPath("$PROJECT_ROOT") + public class ForInIterator { + @Test + public void testAllFilesPresentInForInIterator() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInIterator"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex") @TestDataPath("$PROJECT_ROOT") @@ -13014,16 +13024,6 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { } } - @Nested - @TestMetadata("compiler/testData/codegen/box/forLoop") - @TestDataPath("$PROJECT_ROOT") - public class ForLoop { - @Test - public void testAllFilesPresentInForLoop() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/forLoop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); - } - } - @Nested @TestMetadata("compiler/testData/codegen/box/fullJdk") @TestDataPath("$PROJECT_ROOT") diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java index 1ac57c08867..f6256bc27f8 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/IrJsCodegenBoxTestGenerated.java @@ -6457,6 +6457,16 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { } } + @Nested + @TestMetadata("compiler/testData/codegen/box/controlStructures/forInIterator") + @TestDataPath("$PROJECT_ROOT") + public class ForInIterator { + @Test + public void testAllFilesPresentInForInIterator() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInIterator"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex") @TestDataPath("$PROJECT_ROOT") @@ -13056,16 +13066,6 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { } } - @Nested - @TestMetadata("compiler/testData/codegen/box/forLoop") - @TestDataPath("$PROJECT_ROOT") - public class ForLoop { - @Test - public void testAllFilesPresentInForLoop() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/forLoop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); - } - } - @Nested @TestMetadata("compiler/testData/codegen/box/fullJdk") @TestDataPath("$PROJECT_ROOT") diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index f691beba5f2..cbea39f61c4 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testOld/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -5590,6 +5590,19 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest } } + @TestMetadata("compiler/testData/codegen/box/controlStructures/forInIterator") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class ForInIterator extends AbstractIrCodegenBoxWasmTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath); + } + + public void testAllFilesPresentInForInIterator() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInIterator"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); + } + } + @TestMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) @@ -10891,19 +10904,6 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest } } - @TestMetadata("compiler/testData/codegen/box/forLoop") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class ForLoop extends AbstractIrCodegenBoxWasmTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest0(this::doTest, TargetBackend.WASM, testDataFilePath); - } - - public void testAllFilesPresentInForLoop() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/forLoop"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.WASM, true); - } - } - @TestMetadata("compiler/testData/codegen/box/fullJdk") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java index a87266e7f7a..c6a2838bef0 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/blackboxtest/NativeCodegenBoxTestGenerated.java @@ -7261,6 +7261,18 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest } } + @Nested + @TestMetadata("compiler/testData/codegen/box/controlStructures/forInIterator") + @TestDataPath("$PROJECT_ROOT") + @Tag("codegen") + @UseExtTestCaseGroupProvider() + public class ForInIterator { + @Test + public void testAllFilesPresentInForInIterator() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/controlStructures/forInIterator"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); + } + } + @Nested @TestMetadata("compiler/testData/codegen/box/controlStructures/forInSequenceWithIndex") @TestDataPath("$PROJECT_ROOT") @@ -14030,18 +14042,6 @@ public class NativeCodegenBoxTestGenerated extends AbstractNativeCodegenBoxTest } } - @Nested - @TestMetadata("compiler/testData/codegen/box/forLoop") - @TestDataPath("$PROJECT_ROOT") - @Tag("codegen") - @UseExtTestCaseGroupProvider() - public class ForLoop { - @Test - public void testAllFilesPresentInForLoop() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/forLoop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.NATIVE, true); - } - } - @Nested @TestMetadata("compiler/testData/codegen/box/fullJdk") @TestDataPath("$PROJECT_ROOT")