From 3dc58bc99518b15522bed110432dadaffb915e99 Mon Sep 17 00:00:00 2001 From: Juan Chen Date: Fri, 20 Dec 2019 10:39:38 -0800 Subject: [PATCH] [FIR2IR] Fix translating primitive array types This commit fixes two issues in the existing implementation of translating primitive array types: * IrType.getArrayElementType throws an exception when the receiver is a primitive array type, because IR expects primitive array types use symbols defined in IrBuiltIns, but fir2ir translation doesn't; * IteratorNext.toCallable assumes all element types are boxed. The first issue is fixed by changing the fir2ir type translation to use symbols in IrBuiltIns for primitive array types, and the second by not unboxing primitive types. --- .../kotlin/fir/backend/ConversionUtils.kt | 57 ++++++++++++++----- .../fir/backend/Fir2IrDeclarationStorage.kt | 7 ++- .../kotlin/fir/backend/Fir2IrVisitor.kt | 7 ++- .../backend/jvm/intrinsics/IteratorNext.kt | 4 +- .../codegen/box/arrays/forEachBooleanArray.kt | 1 - .../codegen/box/arrays/forEachByteArray.kt | 1 - .../codegen/box/arrays/forEachCharArray.kt | 1 - .../codegen/box/arrays/forEachDoubleArray.kt | 1 - .../codegen/box/arrays/forEachFloatArray.kt | 1 - .../codegen/box/arrays/forEachIntArray.kt | 1 - .../codegen/box/arrays/forEachLongArray.kt | 1 - .../codegen/box/arrays/forEachShortArray.kt | 1 - .../box/arrays/iteratorBooleanArray.kt | 1 - .../codegen/box/arrays/iteratorByteArray.kt | 1 - .../box/arrays/iteratorByteArrayNextByte.kt | 1 - .../codegen/box/arrays/iteratorCharArray.kt | 1 - .../codegen/box/arrays/iteratorDoubleArray.kt | 1 - .../codegen/box/arrays/iteratorFloatArray.kt | 1 - .../codegen/box/arrays/iteratorIntArray.kt | 1 - .../codegen/box/arrays/iteratorLongArray.kt | 1 - .../box/arrays/iteratorLongArrayNextLong.kt | 1 - .../codegen/box/arrays/iteratorShortArray.kt | 1 - .../breakContinueInExpressions/breakInExpr.kt | 1 - .../continueInExpr.kt | 1 - .../breakContinueInExpressions/tryFinally2.kt | 1 - .../forInArray/forPrimitiveIntArray.kt | 1 - .../codegen/box/controlStructures/kt772.kt | 1 - .../codegen/box/controlStructures/kt773.kt | 1 - .../box/controlStructures/longRange.kt | 1 - .../tryCatchInExpressions/tryAndContinue.kt | 1 - .../box/finally/breakAndOuterFinally.kt | 1 - .../box/finally/continueAndOuterFinally.kt | 1 - .../codegen/box/finally/kt31923_break.kt | 1 - .../codegen/box/finally/kt31923_continue.kt | 1 - .../testData/codegen/box/finally/kt3874.kt | 1 - .../codegen/box/intrinsics/tostring.kt | 1 - .../controlLabelClashesWithFuncitonName.kt | 1 - .../int/MultiDeclForComponentExtensions.kt | 1 - .../long/MultiDeclForComponentExtensions.kt | 1 - .../int/MultiDeclForComponentExtensions.kt | 1 - .../int/MultiDeclForComponentExtensions.kt | 1 - .../long/MultiDeclForComponentExtensions.kt | 1 - .../codegen/box/primitiveTypes/kt752.kt | 1 - .../codegen/box/ranges/contains/inIntRange.kt | 1 - .../box/ranges/expression/emptyRange.kt | 1 - .../forInRangeLiteralWithMixedTypeBounds.kt | 1 - .../codegen/box/ranges/literal/emptyRange.kt | 1 - .../progressionExpression.kt | 1 - .../nullableLoopParameter/rangeExpression.kt | 1 - .../nullableLoopParameter/rangeLiteral.kt | 1 - .../testData/codegen/box/strings/kt894.kt | 1 - .../tests/GenerateRangesCodegenTestData.java | 14 +++-- 52 files changed, 65 insertions(+), 71 deletions(-) diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt index aa4e3ebefb7..495b788ace4 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.* import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.ir.IrElement +import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns import org.jetbrains.kotlin.ir.symbols.* import org.jetbrains.kotlin.ir.types.IrErrorType import org.jetbrains.kotlin.ir.types.IrType @@ -25,6 +26,8 @@ import org.jetbrains.kotlin.ir.types.impl.IrErrorTypeImpl import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection +import org.jetbrains.kotlin.name.ClassId +import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffsetSkippingComments import org.jetbrains.kotlin.types.Variance @@ -40,56 +43,82 @@ internal fun FirElement.convertWithOffsets( internal fun createErrorType(): IrErrorType = IrErrorTypeImpl(null, emptyList(), Variance.INVARIANT) -fun FirTypeRef.toIrType(session: FirSession, declarationStorage: Fir2IrDeclarationStorage): IrType { +fun FirTypeRef.toIrType(session: FirSession, declarationStorage: Fir2IrDeclarationStorage, irBuiltIns: IrBuiltIns): IrType { if (this !is FirResolvedTypeRef) { return createErrorType() } - return type.toIrType(session, declarationStorage) + return type.toIrType(session, declarationStorage, irBuiltIns) } -fun ConeKotlinType.toIrType(session: FirSession, declarationStorage: Fir2IrDeclarationStorage, definitelyNotNull: Boolean = false): IrType { +fun ConeKotlinType.toIrType( + session: FirSession, + declarationStorage: Fir2IrDeclarationStorage, + irBuiltIns: IrBuiltIns, + definitelyNotNull: Boolean = false +): IrType { return when (this) { is ConeKotlinErrorType -> createErrorType() is ConeLookupTagBasedType -> { - val firSymbol = this.lookupTag.toSymbol(session) ?: return createErrorType() - val irSymbol = firSymbol.toIrSymbol(session, declarationStorage) + val irSymbol = getPrimitiveArrayType(this.classId, irBuiltIns) ?: run { + val firSymbol = this.lookupTag.toSymbol(session) ?: return createErrorType() + firSymbol.toIrSymbol(session, declarationStorage) + } // TODO: annotations IrSimpleTypeImpl( irSymbol, !definitelyNotNull && this.isMarkedNullable, - typeArguments.map { it.toIrTypeArgument(session, declarationStorage) }, + typeArguments.map { it.toIrTypeArgument(session, declarationStorage, irBuiltIns) }, emptyList() ) } is ConeFlexibleType -> { // TODO: yet we take more general type. Not quite sure it's Ok - upperBound.toIrType(session, declarationStorage, definitelyNotNull) + upperBound.toIrType(session, declarationStorage, irBuiltIns, definitelyNotNull) } is ConeCapturedType -> TODO() is ConeDefinitelyNotNullType -> { - original.toIrType(session, declarationStorage, definitelyNotNull = true) + original.toIrType(session, declarationStorage, irBuiltIns, definitelyNotNull = true) } is ConeIntersectionType -> { // TODO: add intersectionTypeApproximation - intersectedTypes.first().toIrType(session, declarationStorage, definitelyNotNull) + intersectedTypes.first().toIrType(session, declarationStorage, irBuiltIns, definitelyNotNull) } is ConeStubType -> createErrorType() - is ConeIntegerLiteralType -> getApproximatedType().toIrType(session, declarationStorage, definitelyNotNull) + is ConeIntegerLiteralType -> getApproximatedType().toIrType(session, declarationStorage, irBuiltIns, definitelyNotNull) } } -fun ConeKotlinTypeProjection.toIrTypeArgument(session: FirSession, declarationStorage: Fir2IrDeclarationStorage): IrTypeArgument { +private fun getPrimitiveArrayType(classId: ClassId?, irBuiltIns: IrBuiltIns): IrClassifierSymbol? { + val irType = when (classId) { + ClassId(FqName("kotlin"), FqName("BooleanArray"), false) -> irBuiltIns.booleanType + ClassId(FqName("kotlin"), FqName("ByteArray"), false) -> irBuiltIns.byteType + ClassId(FqName("kotlin"), FqName("CharArray"), false) -> irBuiltIns.charType + ClassId(FqName("kotlin"), FqName("DoubleArray"), false) -> irBuiltIns.doubleType + ClassId(FqName("kotlin"), FqName("FloatArray"), false) -> irBuiltIns.floatType + ClassId(FqName("kotlin"), FqName("IntArray"), false) -> irBuiltIns.intType + ClassId(FqName("kotlin"), FqName("LongArray"), false) -> irBuiltIns.longType + ClassId(FqName("kotlin"), FqName("ShortArray"), false) -> irBuiltIns.shortType + else -> null + } + return irType?.let { irBuiltIns.primitiveArrayForType.getValue(it) } +} + +fun ConeKotlinTypeProjection.toIrTypeArgument( + session: FirSession, + declarationStorage: Fir2IrDeclarationStorage, + irBuiltIns: IrBuiltIns +): IrTypeArgument { return when (this) { ConeStarProjection -> IrStarProjectionImpl is ConeKotlinTypeProjectionIn -> { - val irType = this.type.toIrType(session, declarationStorage) + val irType = this.type.toIrType(session, declarationStorage, irBuiltIns) makeTypeProjection(irType, Variance.IN_VARIANCE) } is ConeKotlinTypeProjectionOut -> { - val irType = this.type.toIrType(session, declarationStorage) + val irType = this.type.toIrType(session, declarationStorage, irBuiltIns) makeTypeProjection(irType, Variance.OUT_VARIANCE) } is ConeKotlinType -> { - val irType = toIrType(session, declarationStorage) + val irType = toIrType(session, declarationStorage, irBuiltIns) makeTypeProjection(irType, Variance.INVARIANT) } } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index a7358d67ae8..23fdc0ac0a0 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -23,6 +23,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol +import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.* import org.jetbrains.kotlin.ir.descriptors.* @@ -40,7 +41,8 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffsetSkippingComments class Fir2IrDeclarationStorage( private val session: FirSession, private val irSymbolTable: SymbolTable, - private val moduleDescriptor: FirModuleDescriptor + private val moduleDescriptor: FirModuleDescriptor, + private val irBuiltIns: IrBuiltIns ) { private val firSymbolProvider = session.firSymbolProvider @@ -90,6 +92,9 @@ class Fir2IrDeclarationStorage( irSymbolTable.leaveScope(descriptor) } + private fun FirTypeRef.toIrType(session: FirSession, declarationStorage: Fir2IrDeclarationStorage) = + toIrType(session, declarationStorage, irBuiltIns) + private fun getIrExternalPackageFragment(fqName: FqName): IrExternalPackageFragment { return fragmentCache.getOrPut(fqName) { // TODO: module descriptor is wrong here diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt index 95785bfbee3..50ac68fe3a9 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt @@ -75,7 +75,7 @@ class Fir2IrVisitor( private val typeContext = session.typeContext - private val declarationStorage = Fir2IrDeclarationStorage(session, symbolTable, moduleDescriptor) + private val declarationStorage = Fir2IrDeclarationStorage(session, symbolTable, moduleDescriptor, irBuiltIns) private val nothingType = session.builtinTypes.nothingType.toIrType(session, declarationStorage) @@ -138,6 +138,9 @@ class Fir2IrVisitor( return result } + private fun FirTypeRef.toIrType(session: FirSession, declarationStorage: Fir2IrDeclarationStorage) = + toIrType(session, declarationStorage, irBuiltIns) + override fun visitElement(element: FirElement, data: Any?): IrElement { TODO("Should not be here: ${element.render()}") } @@ -711,7 +714,7 @@ class Fir2IrVisitor( private fun FirAnnotationCall.toIrExpression(): IrExpression { val coneType = (annotationTypeRef as? FirResolvedTypeRef)?.type as? ConeLookupTagBasedType val firSymbol = coneType?.lookupTag?.toSymbol(session) as? FirClassSymbol - val type = coneType?.toIrType(this@Fir2IrVisitor.session, declarationStorage) + val type = coneType?.toIrType(session, declarationStorage, irBuiltIns) val symbol = type?.classifierOrNull return convertWithOffsets { startOffset, endOffset -> when (symbol) { diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/IteratorNext.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/IteratorNext.kt index 914c40aee2d..6a4f0f7f59e 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/IteratorNext.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/intrinsics/IteratorNext.kt @@ -22,6 +22,7 @@ import org.jetbrains.kotlin.codegen.AsmUtil import org.jetbrains.kotlin.fileClasses.internalNameWithoutInnerClasses import org.jetbrains.kotlin.ir.expressions.IrFunctionAccessExpression import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression +import org.jetbrains.kotlin.ir.types.isPrimitiveType import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.jvm.AsmTypes import org.jetbrains.kotlin.resolve.jvm.JvmPrimitiveType @@ -31,7 +32,8 @@ import org.jetbrains.org.objectweb.asm.Type object IteratorNext : IntrinsicMethod() { override fun toCallable(expression: IrFunctionAccessExpression, signature: JvmMethodSignature, context: JvmBackendContext): IrIntrinsicFunction { - val type = AsmUtil.unboxType(signature.returnType) + // If the array element type is unboxed primitive, do not unbox. Otherwise AsmUtil.unbox throws exception + val type = if (AsmUtil.isBoxedPrimitiveType(signature.returnType)) AsmUtil.unboxType(signature.returnType) else signature.returnType val newSignature = signature.newReturnType(type) return IrIntrinsicFunction.create(expression, newSignature, context, AsmTypes.OBJECT_TYPE) { val primitiveClassName = getKotlinPrimitiveClassName(type) diff --git a/compiler/testData/codegen/box/arrays/forEachBooleanArray.kt b/compiler/testData/codegen/box/arrays/forEachBooleanArray.kt index 1a1b971d61a..f0238410cc5 100644 --- a/compiler/testData/codegen/box/arrays/forEachBooleanArray.kt +++ b/compiler/testData/codegen/box/arrays/forEachBooleanArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { for (x in BooleanArray(5)) { if (x != false) return "Fail $x" diff --git a/compiler/testData/codegen/box/arrays/forEachByteArray.kt b/compiler/testData/codegen/box/arrays/forEachByteArray.kt index 72a9ed5980e..1ae8205531a 100644 --- a/compiler/testData/codegen/box/arrays/forEachByteArray.kt +++ b/compiler/testData/codegen/box/arrays/forEachByteArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { for (x in ByteArray(5)) { if (x != 0.toByte()) return "Fail $x" diff --git a/compiler/testData/codegen/box/arrays/forEachCharArray.kt b/compiler/testData/codegen/box/arrays/forEachCharArray.kt index fbc13c4be8b..4b797671175 100644 --- a/compiler/testData/codegen/box/arrays/forEachCharArray.kt +++ b/compiler/testData/codegen/box/arrays/forEachCharArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { for (x in CharArray(5)) { if (x != 0.toChar()) return "Fail $x" diff --git a/compiler/testData/codegen/box/arrays/forEachDoubleArray.kt b/compiler/testData/codegen/box/arrays/forEachDoubleArray.kt index 031804cb11d..c1a79f222a3 100644 --- a/compiler/testData/codegen/box/arrays/forEachDoubleArray.kt +++ b/compiler/testData/codegen/box/arrays/forEachDoubleArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { for (x in DoubleArray(5)) { if (x != 0.toDouble()) return "Fail $x" diff --git a/compiler/testData/codegen/box/arrays/forEachFloatArray.kt b/compiler/testData/codegen/box/arrays/forEachFloatArray.kt index 9a849175a6e..8245beab4ee 100644 --- a/compiler/testData/codegen/box/arrays/forEachFloatArray.kt +++ b/compiler/testData/codegen/box/arrays/forEachFloatArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { for (x in FloatArray(5)) { if (x != 0.toFloat()) return "Fail $x" diff --git a/compiler/testData/codegen/box/arrays/forEachIntArray.kt b/compiler/testData/codegen/box/arrays/forEachIntArray.kt index 9850aa41e53..53ce12dd393 100644 --- a/compiler/testData/codegen/box/arrays/forEachIntArray.kt +++ b/compiler/testData/codegen/box/arrays/forEachIntArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { for (x in IntArray(5)) { if (x != 0) return "Fail $x" diff --git a/compiler/testData/codegen/box/arrays/forEachLongArray.kt b/compiler/testData/codegen/box/arrays/forEachLongArray.kt index 7079101e2c8..6ed0259f765 100644 --- a/compiler/testData/codegen/box/arrays/forEachLongArray.kt +++ b/compiler/testData/codegen/box/arrays/forEachLongArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { for (x in LongArray(5)) { if (x != 0.toLong()) return "Fail $x" diff --git a/compiler/testData/codegen/box/arrays/forEachShortArray.kt b/compiler/testData/codegen/box/arrays/forEachShortArray.kt index f071b5f07f7..a9145d42422 100644 --- a/compiler/testData/codegen/box/arrays/forEachShortArray.kt +++ b/compiler/testData/codegen/box/arrays/forEachShortArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { for (x in ShortArray(5)) { if (x != 0.toShort()) return "Fail $x" diff --git a/compiler/testData/codegen/box/arrays/iteratorBooleanArray.kt b/compiler/testData/codegen/box/arrays/iteratorBooleanArray.kt index a3669cb524c..753381f34f4 100644 --- a/compiler/testData/codegen/box/arrays/iteratorBooleanArray.kt +++ b/compiler/testData/codegen/box/arrays/iteratorBooleanArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { val a = BooleanArray(5) val x = a.iterator() diff --git a/compiler/testData/codegen/box/arrays/iteratorByteArray.kt b/compiler/testData/codegen/box/arrays/iteratorByteArray.kt index 29dc89bbf62..259eb5f3200 100644 --- a/compiler/testData/codegen/box/arrays/iteratorByteArray.kt +++ b/compiler/testData/codegen/box/arrays/iteratorByteArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { val a = ByteArray(5) val x = a.iterator() diff --git a/compiler/testData/codegen/box/arrays/iteratorByteArrayNextByte.kt b/compiler/testData/codegen/box/arrays/iteratorByteArrayNextByte.kt index 14b191024a3..61c458433a7 100644 --- a/compiler/testData/codegen/box/arrays/iteratorByteArrayNextByte.kt +++ b/compiler/testData/codegen/box/arrays/iteratorByteArrayNextByte.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { val a = ByteArray(5) val x = a.iterator() diff --git a/compiler/testData/codegen/box/arrays/iteratorCharArray.kt b/compiler/testData/codegen/box/arrays/iteratorCharArray.kt index 597aa74749d..525910d31e3 100644 --- a/compiler/testData/codegen/box/arrays/iteratorCharArray.kt +++ b/compiler/testData/codegen/box/arrays/iteratorCharArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { val a = CharArray(5) val x = a.iterator() diff --git a/compiler/testData/codegen/box/arrays/iteratorDoubleArray.kt b/compiler/testData/codegen/box/arrays/iteratorDoubleArray.kt index 2bf03354743..192625f22c6 100644 --- a/compiler/testData/codegen/box/arrays/iteratorDoubleArray.kt +++ b/compiler/testData/codegen/box/arrays/iteratorDoubleArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { val a = DoubleArray(5) val x = a.iterator() diff --git a/compiler/testData/codegen/box/arrays/iteratorFloatArray.kt b/compiler/testData/codegen/box/arrays/iteratorFloatArray.kt index 92f45d20493..4a5b86e694f 100644 --- a/compiler/testData/codegen/box/arrays/iteratorFloatArray.kt +++ b/compiler/testData/codegen/box/arrays/iteratorFloatArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { val a = FloatArray(5) val x = a.iterator() diff --git a/compiler/testData/codegen/box/arrays/iteratorIntArray.kt b/compiler/testData/codegen/box/arrays/iteratorIntArray.kt index cb2ca15b24e..2dd09e3a59c 100644 --- a/compiler/testData/codegen/box/arrays/iteratorIntArray.kt +++ b/compiler/testData/codegen/box/arrays/iteratorIntArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { val a = IntArray(5) val x = a.iterator() diff --git a/compiler/testData/codegen/box/arrays/iteratorLongArray.kt b/compiler/testData/codegen/box/arrays/iteratorLongArray.kt index 8dc5655512b..b1033002764 100644 --- a/compiler/testData/codegen/box/arrays/iteratorLongArray.kt +++ b/compiler/testData/codegen/box/arrays/iteratorLongArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { val a = LongArray(5) val x = a.iterator() diff --git a/compiler/testData/codegen/box/arrays/iteratorLongArrayNextLong.kt b/compiler/testData/codegen/box/arrays/iteratorLongArrayNextLong.kt index c85a4e728df..cc9cec5d570 100644 --- a/compiler/testData/codegen/box/arrays/iteratorLongArrayNextLong.kt +++ b/compiler/testData/codegen/box/arrays/iteratorLongArrayNextLong.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { val a = LongArray(5) val x = a.iterator() diff --git a/compiler/testData/codegen/box/arrays/iteratorShortArray.kt b/compiler/testData/codegen/box/arrays/iteratorShortArray.kt index 9872493c9bb..49807e23720 100644 --- a/compiler/testData/codegen/box/arrays/iteratorShortArray.kt +++ b/compiler/testData/codegen/box/arrays/iteratorShortArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { val a = ShortArray(5) val x = a.iterator() diff --git a/compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/breakInExpr.kt b/compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/breakInExpr.kt index 2fdb8152bd1..203452b0a60 100644 --- a/compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/breakInExpr.kt +++ b/compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/breakInExpr.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun test(str: String): String { var s = "" for (i in 1..3) { diff --git a/compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/continueInExpr.kt b/compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/continueInExpr.kt index 899609aed85..667cd474bd0 100644 --- a/compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/continueInExpr.kt +++ b/compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/continueInExpr.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { var s = "OK" for (i in 1..3) { diff --git a/compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/tryFinally2.kt b/compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/tryFinally2.kt index 987cd76d892..147362a181c 100644 --- a/compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/tryFinally2.kt +++ b/compiler/testData/codegen/box/controlStructures/breakContinueInExpressions/tryFinally2.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { var r = "" for (i in 1..1) { diff --git a/compiler/testData/codegen/box/controlStructures/forInArray/forPrimitiveIntArray.kt b/compiler/testData/codegen/box/controlStructures/forInArray/forPrimitiveIntArray.kt index 0a013e46657..566894de73a 100644 --- a/compiler/testData/codegen/box/controlStructures/forInArray/forPrimitiveIntArray.kt +++ b/compiler/testData/codegen/box/controlStructures/forInArray/forPrimitiveIntArray.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box() : String { val a = IntArray (5) var i = 0 diff --git a/compiler/testData/codegen/box/controlStructures/kt772.kt b/compiler/testData/codegen/box/controlStructures/kt772.kt index 620e7cbbee5..6facb9ef23d 100644 --- a/compiler/testData/codegen/box/controlStructures/kt772.kt +++ b/compiler/testData/codegen/box/controlStructures/kt772.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR package demo2 fun print(o : Any?) {} diff --git a/compiler/testData/codegen/box/controlStructures/kt773.kt b/compiler/testData/codegen/box/controlStructures/kt773.kt index 620e7cbbee5..6facb9ef23d 100644 --- a/compiler/testData/codegen/box/controlStructures/kt773.kt +++ b/compiler/testData/codegen/box/controlStructures/kt773.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR package demo2 fun print(o : Any?) {} diff --git a/compiler/testData/codegen/box/controlStructures/longRange.kt b/compiler/testData/codegen/box/controlStructures/longRange.kt index 973bf7bbec0..b1ab17ee093 100644 --- a/compiler/testData/codegen/box/controlStructures/longRange.kt +++ b/compiler/testData/codegen/box/controlStructures/longRange.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { val r = 1.toLong()..2 var s = "" diff --git a/compiler/testData/codegen/box/controlStructures/tryCatchInExpressions/tryAndContinue.kt b/compiler/testData/codegen/box/controlStructures/tryCatchInExpressions/tryAndContinue.kt index 9bb0a30d771..120d463b00c 100644 --- a/compiler/testData/codegen/box/controlStructures/tryCatchInExpressions/tryAndContinue.kt +++ b/compiler/testData/codegen/box/controlStructures/tryCatchInExpressions/tryAndContinue.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun idiv(a: Int, b: Int): Int = if (b == 0) throw Exception("Division by zero") else a / b diff --git a/compiler/testData/codegen/box/finally/breakAndOuterFinally.kt b/compiler/testData/codegen/box/finally/breakAndOuterFinally.kt index 4002a0e9353..a39feee79b6 100644 --- a/compiler/testData/codegen/box/finally/breakAndOuterFinally.kt +++ b/compiler/testData/codegen/box/finally/breakAndOuterFinally.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR var result = "" fun test() { diff --git a/compiler/testData/codegen/box/finally/continueAndOuterFinally.kt b/compiler/testData/codegen/box/finally/continueAndOuterFinally.kt index cbe77f58f88..7665e525771 100644 --- a/compiler/testData/codegen/box/finally/continueAndOuterFinally.kt +++ b/compiler/testData/codegen/box/finally/continueAndOuterFinally.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR var result = "" fun test() { diff --git a/compiler/testData/codegen/box/finally/kt31923_break.kt b/compiler/testData/codegen/box/finally/kt31923_break.kt index c93431c6dad..175a02b8566 100644 --- a/compiler/testData/codegen/box/finally/kt31923_break.kt +++ b/compiler/testData/codegen/box/finally/kt31923_break.kt @@ -1,5 +1,4 @@ // !LANGUAGE: +ProperFinally -// IGNORE_BACKEND_FIR: JVM_IR var result = "" fun test() { diff --git a/compiler/testData/codegen/box/finally/kt31923_continue.kt b/compiler/testData/codegen/box/finally/kt31923_continue.kt index a8742e9a542..e31b48c675e 100644 --- a/compiler/testData/codegen/box/finally/kt31923_continue.kt +++ b/compiler/testData/codegen/box/finally/kt31923_continue.kt @@ -1,5 +1,4 @@ // !LANGUAGE: +ProperFinally -// IGNORE_BACKEND_FIR: JVM_IR var result = "" fun test() { diff --git a/compiler/testData/codegen/box/finally/kt3874.kt b/compiler/testData/codegen/box/finally/kt3874.kt index e652cc9183c..fa0a4259d12 100644 --- a/compiler/testData/codegen/box/finally/kt3874.kt +++ b/compiler/testData/codegen/box/finally/kt3874.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun test1(): String { var r = "" for (i in 1..2) { diff --git a/compiler/testData/codegen/box/intrinsics/tostring.kt b/compiler/testData/codegen/box/intrinsics/tostring.kt index 6c121a8f9d6..27f9f1a11a0 100644 --- a/compiler/testData/codegen/box/intrinsics/tostring.kt +++ b/compiler/testData/codegen/box/intrinsics/tostring.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // TODO: muted automatically, investigate should it be ran for JS or not // IGNORE_BACKEND: JS diff --git a/compiler/testData/codegen/box/labels/controlLabelClashesWithFuncitonName.kt b/compiler/testData/codegen/box/labels/controlLabelClashesWithFuncitonName.kt index f3fab91b6f5..ae2f251cc2c 100644 --- a/compiler/testData/codegen/box/labels/controlLabelClashesWithFuncitonName.kt +++ b/compiler/testData/codegen/box/labels/controlLabelClashesWithFuncitonName.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun test1(): Boolean { test1@ for(i in 1..2) { continue@test1 diff --git a/compiler/testData/codegen/box/multiDecl/forRange/explicitRangeTo/int/MultiDeclForComponentExtensions.kt b/compiler/testData/codegen/box/multiDecl/forRange/explicitRangeTo/int/MultiDeclForComponentExtensions.kt index ca13c509434..68454565301 100644 --- a/compiler/testData/codegen/box/multiDecl/forRange/explicitRangeTo/int/MultiDeclForComponentExtensions.kt +++ b/compiler/testData/codegen/box/multiDecl/forRange/explicitRangeTo/int/MultiDeclForComponentExtensions.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR operator fun Int.component1() = this + 1 operator fun Int.component2() = this + 2 diff --git a/compiler/testData/codegen/box/multiDecl/forRange/explicitRangeTo/long/MultiDeclForComponentExtensions.kt b/compiler/testData/codegen/box/multiDecl/forRange/explicitRangeTo/long/MultiDeclForComponentExtensions.kt index 268c949d024..132c532501f 100644 --- a/compiler/testData/codegen/box/multiDecl/forRange/explicitRangeTo/long/MultiDeclForComponentExtensions.kt +++ b/compiler/testData/codegen/box/multiDecl/forRange/explicitRangeTo/long/MultiDeclForComponentExtensions.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR operator fun Long.component1() = this + 1 operator fun Long.component2() = this + 2 diff --git a/compiler/testData/codegen/box/multiDecl/forRange/explicitRangeToWithDot/int/MultiDeclForComponentExtensions.kt b/compiler/testData/codegen/box/multiDecl/forRange/explicitRangeToWithDot/int/MultiDeclForComponentExtensions.kt index ca13c509434..68454565301 100644 --- a/compiler/testData/codegen/box/multiDecl/forRange/explicitRangeToWithDot/int/MultiDeclForComponentExtensions.kt +++ b/compiler/testData/codegen/box/multiDecl/forRange/explicitRangeToWithDot/int/MultiDeclForComponentExtensions.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR operator fun Int.component1() = this + 1 operator fun Int.component2() = this + 2 diff --git a/compiler/testData/codegen/box/multiDecl/forRange/int/MultiDeclForComponentExtensions.kt b/compiler/testData/codegen/box/multiDecl/forRange/int/MultiDeclForComponentExtensions.kt index 0929eef2433..5f60ba33287 100644 --- a/compiler/testData/codegen/box/multiDecl/forRange/int/MultiDeclForComponentExtensions.kt +++ b/compiler/testData/codegen/box/multiDecl/forRange/int/MultiDeclForComponentExtensions.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR operator fun Int.component1() = this + 1 operator fun Int.component2() = this + 2 diff --git a/compiler/testData/codegen/box/multiDecl/forRange/long/MultiDeclForComponentExtensions.kt b/compiler/testData/codegen/box/multiDecl/forRange/long/MultiDeclForComponentExtensions.kt index 4bf1e4a517a..85f78eabcdc 100644 --- a/compiler/testData/codegen/box/multiDecl/forRange/long/MultiDeclForComponentExtensions.kt +++ b/compiler/testData/codegen/box/multiDecl/forRange/long/MultiDeclForComponentExtensions.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR operator fun Long.component1() = this + 1 operator fun Long.component2() = this + 2 diff --git a/compiler/testData/codegen/box/primitiveTypes/kt752.kt b/compiler/testData/codegen/box/primitiveTypes/kt752.kt index 1b1c6fd9c62..3d0027e314e 100644 --- a/compiler/testData/codegen/box/primitiveTypes/kt752.kt +++ b/compiler/testData/codegen/box/primitiveTypes/kt752.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JS_IR // TODO: muted automatically, investigate should it be ran for JS or not // IGNORE_BACKEND: JS, NATIVE diff --git a/compiler/testData/codegen/box/ranges/contains/inIntRange.kt b/compiler/testData/codegen/box/ranges/contains/inIntRange.kt index af8a59d04b1..fb87d450d03 100644 --- a/compiler/testData/codegen/box/ranges/contains/inIntRange.kt +++ b/compiler/testData/codegen/box/ranges/contains/inIntRange.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JS_IR // TODO: muted automatically, investigate should it be ran for JS or not // IGNORE_BACKEND: JS diff --git a/compiler/testData/codegen/box/ranges/expression/emptyRange.kt b/compiler/testData/codegen/box/ranges/expression/emptyRange.kt index af9d004e288..a7c6fbee514 100644 --- a/compiler/testData/codegen/box/ranges/expression/emptyRange.kt +++ b/compiler/testData/codegen/box/ranges/expression/emptyRange.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // KJS_WITH_FULL_RUNTIME // Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT! // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/ranges/forInRangeLiteralWithMixedTypeBounds.kt b/compiler/testData/codegen/box/ranges/forInRangeLiteralWithMixedTypeBounds.kt index 8f3e208989e..0fdbe711937 100644 --- a/compiler/testData/codegen/box/ranges/forInRangeLiteralWithMixedTypeBounds.kt +++ b/compiler/testData/codegen/box/ranges/forInRangeLiteralWithMixedTypeBounds.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun test1(): Long { var s = 0L for (i in 1L..4) { diff --git a/compiler/testData/codegen/box/ranges/literal/emptyRange.kt b/compiler/testData/codegen/box/ranges/literal/emptyRange.kt index 002816c281d..73583591445 100644 --- a/compiler/testData/codegen/box/ranges/literal/emptyRange.kt +++ b/compiler/testData/codegen/box/ranges/literal/emptyRange.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // KJS_WITH_FULL_RUNTIME // Auto-generated by org.jetbrains.kotlin.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT! // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/ranges/nullableLoopParameter/progressionExpression.kt b/compiler/testData/codegen/box/ranges/nullableLoopParameter/progressionExpression.kt index 7b80555a90d..2caf1a33808 100644 --- a/compiler/testData/codegen/box/ranges/nullableLoopParameter/progressionExpression.kt +++ b/compiler/testData/codegen/box/ranges/nullableLoopParameter/progressionExpression.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { var result = 0 val intRange: IntProgression = 1..3 diff --git a/compiler/testData/codegen/box/ranges/nullableLoopParameter/rangeExpression.kt b/compiler/testData/codegen/box/ranges/nullableLoopParameter/rangeExpression.kt index 1a9fea5c558..7cc906c09d2 100644 --- a/compiler/testData/codegen/box/ranges/nullableLoopParameter/rangeExpression.kt +++ b/compiler/testData/codegen/box/ranges/nullableLoopParameter/rangeExpression.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { var result = 0 val intRange = 1..3 diff --git a/compiler/testData/codegen/box/ranges/nullableLoopParameter/rangeLiteral.kt b/compiler/testData/codegen/box/ranges/nullableLoopParameter/rangeLiteral.kt index 42c9513dd9c..52713ad8bf7 100644 --- a/compiler/testData/codegen/box/ranges/nullableLoopParameter/rangeLiteral.kt +++ b/compiler/testData/codegen/box/ranges/nullableLoopParameter/rangeLiteral.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { var result = 0 for (i: Int? in 1..3) { diff --git a/compiler/testData/codegen/box/strings/kt894.kt b/compiler/testData/codegen/box/strings/kt894.kt index a4b973b67cd..e2aeb1f5bab 100644 --- a/compiler/testData/codegen/box/strings/kt894.kt +++ b/compiler/testData/codegen/box/strings/kt894.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun stringConcat(n : Int) : String? { var string : String? = "" for (i in 0..(n - 1)) diff --git a/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateRangesCodegenTestData.java b/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateRangesCodegenTestData.java index e64018684e5..e713361ee47 100644 --- a/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateRangesCodegenTestData.java +++ b/compiler/tests/org/jetbrains/kotlin/generators/tests/GenerateRangesCodegenTestData.java @@ -135,7 +135,7 @@ public class GenerateRangesCodegenTestData { out.printf("// IGNORE_BACKEND: %s%n%n", backendName); } - private static void writeToFile(File file, String generatedBody, boolean isForUnsigned) { + private static void writeToFile(File file, String generatedBody, boolean isForUnsigned, boolean ignoreFrontendIR) { PrintWriter out; try { //noinspection IOResourceOpenedButNotSafelyClosed @@ -145,7 +145,9 @@ public class GenerateRangesCodegenTestData { throw new AssertionError(e); } - out.println("// IGNORE_BACKEND_FIR: JVM_IR"); + if (ignoreFrontendIR) { + out.println("// IGNORE_BACKEND_FIR: JVM_IR"); + } out.println("// KJS_WITH_FULL_RUNTIME"); out.println("// Auto-generated by " + GenerateRangesCodegenTestData.class.getName() + ". DO NOT EDIT!"); out.println("// WITH_RUNTIME"); @@ -225,10 +227,10 @@ public class GenerateRangesCodegenTestData { } String fileName = testFunName + ".kt"; - writeToFile(new File(AS_LITERAL_DIR, fileName), asLiteralBody.toString(), false); - writeToFile(new File(AS_EXPRESSION_DIR, fileName), asExpressionBody.toString(), false); - writeToFile(new File(UNSIGNED_AS_LITERAL_DIR, fileName), unsignedAsLiteralBody.toString(), true); - writeToFile(new File(UNSIGNED_AS_EXPRESSION_DIR, fileName), unsignedAsExpressionBody.toString(), true); + writeToFile(new File(AS_LITERAL_DIR, fileName), asLiteralBody.toString(), false, !fileName.equals("emptyRange.kt")); + writeToFile(new File(AS_EXPRESSION_DIR, fileName), asExpressionBody.toString(), false, !fileName.equals("emptyRange.kt")); + writeToFile(new File(UNSIGNED_AS_LITERAL_DIR, fileName), unsignedAsLiteralBody.toString(), true, true); + writeToFile(new File(UNSIGNED_AS_EXPRESSION_DIR, fileName), unsignedAsExpressionBody.toString(), true, true); } } }