diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt index 0c7ad46e61f..cd60f4a813b 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrClassifierStorage.kt @@ -53,7 +53,7 @@ class Fir2IrClassifierStorage( val irClass = irBuiltinSymbol.owner classCache[firClass] = irClass processClassHeader(firClass, irClass) - declarationStorage.preCacheBuiltinClassConstructorIfAny(firClass, irClass) + declarationStorage.preCacheBuiltinClassMembers(firClass, irClass) } for ((primitiveClassId, primitiveArrayId) in StandardClassIds.primitiveArrayTypeByElementType) { val firClass = ConeClassLikeLookupTagImpl(primitiveArrayId).toSymbol(session)!!.fir as FirRegularClass @@ -61,7 +61,7 @@ class Fir2IrClassifierStorage( val irClass = irBuiltIns.primitiveArrayForType[irType]!!.owner classCache[firClass] = irClass processClassHeader(firClass, irClass) - declarationStorage.preCacheBuiltinClassConstructorIfAny(firClass, irClass) + declarationStorage.preCacheBuiltinClassMembers(firClass, irClass) } } 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 66729a2cee3..30ccd221e15 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 @@ -25,10 +25,7 @@ import org.jetbrains.kotlin.fir.resolve.* import org.jetbrains.kotlin.fir.scopes.impl.FirClassSubstitutionScope import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.* -import org.jetbrains.kotlin.fir.types.ConeKotlinType -import org.jetbrains.kotlin.fir.types.FirTypeRef -import org.jetbrains.kotlin.fir.types.arrayElementType -import org.jetbrains.kotlin.fir.types.coneTypeSafe +import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET import org.jetbrains.kotlin.ir.declarations.* import org.jetbrains.kotlin.ir.declarations.impl.* @@ -38,8 +35,11 @@ import org.jetbrains.kotlin.ir.expressions.IrSyntheticBodyKind import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl import org.jetbrains.kotlin.ir.symbols.* +import org.jetbrains.kotlin.ir.types.IrSimpleType import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.util.constructors +import org.jetbrains.kotlin.ir.util.functions +import org.jetbrains.kotlin.ir.util.properties import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.name.Name @@ -72,10 +72,60 @@ class Fir2IrDeclarationStorage( private val localStorage = Fir2IrLocalStorage() - internal fun preCacheBuiltinClassConstructorIfAny(firClass: FirRegularClass, irClass: IrClass) { - val primaryConstructor = firClass.getPrimaryConstructorIfAny() ?: return - val irConstructor = irClass.constructors.firstOrNull() ?: return - constructorCache[primaryConstructor] = irConstructor + private fun areCompatible(firFunction: FirFunction<*>, irFunction: IrFunction): Boolean { + if (firFunction is FirSimpleFunction && irFunction is IrSimpleFunction) { + if (irFunction.name != firFunction.name) return false + } + return irFunction.valueParameters.size == firFunction.valueParameters.size && + irFunction.valueParameters.zip(firFunction.valueParameters).all { (irParameter, firParameter) -> + val irType = irParameter.type + val firType = (firParameter.returnTypeRef as FirResolvedTypeRef).type + if (irType is IrSimpleType) { + when (val irClassifierSymbol = irType.classifier) { + is IrTypeParameterSymbol -> { + firType is ConeTypeParameterType + } + is IrClassSymbol -> { + val irClass = irClassifierSymbol.owner + firType is ConeClassLikeType && irClass.name == firType.lookupTag.name + } + else -> { + false + } + } + } else { + false + } + } + } + + internal fun preCacheBuiltinClassMembers(firClass: FirRegularClass, irClass: IrClass) { + for (declaration in firClass.declarations) { + when (declaration) { + is FirProperty -> { + val irProperty = irClass.properties.find { it.name == declaration.name } + if (irProperty != null) { + propertyCache[declaration] = irProperty + } + } + is FirSimpleFunction -> { + val irFunction = irClass.functions.find { + areCompatible(declaration, it) + } + if (irFunction != null) { + functionCache[declaration] = irFunction + } + } + is FirConstructor -> { + val irConstructor = irClass.constructors.find { + areCompatible(declaration, it) + } + if (irConstructor != null) { + constructorCache[declaration] = irConstructor + } + } + } + } } fun registerFile(firFile: FirFile, irFile: IrFile) { diff --git a/compiler/testData/codegen/box/callableReference/property/listOfStringsMapLength.kt b/compiler/testData/codegen/box/callableReference/property/listOfStringsMapLength.kt index c698e4d64d4..a3e3522f66d 100644 --- a/compiler/testData/codegen/box/callableReference/property/listOfStringsMapLength.kt +++ b/compiler/testData/codegen/box/callableReference/property/listOfStringsMapLength.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // KJS_WITH_FULL_RUNTIME // WITH_RUNTIME diff --git a/compiler/testData/codegen/box/closures/captureExtensionReceiver.kt b/compiler/testData/codegen/box/closures/captureExtensionReceiver.kt index 88ba3fa67af..bd78f48b9ef 100644 --- a/compiler/testData/codegen/box/closures/captureExtensionReceiver.kt +++ b/compiler/testData/codegen/box/closures/captureExtensionReceiver.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR interface B { val bar: T } diff --git a/compiler/testData/codegen/box/controlStructures/doWhile.kt b/compiler/testData/codegen/box/controlStructures/doWhile.kt index 9ef1349d642..f9b776c736c 100644 --- a/compiler/testData/codegen/box/controlStructures/doWhile.kt +++ b/compiler/testData/codegen/box/controlStructures/doWhile.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box(): String { var x = 0 do x++ while (x < 5) diff --git a/compiler/testData/codegen/box/controlStructures/kt3273.kt b/compiler/testData/codegen/box/controlStructures/kt3273.kt index 516b437f460..187dc50ecf8 100644 --- a/compiler/testData/codegen/box/controlStructures/kt3273.kt +++ b/compiler/testData/codegen/box/controlStructures/kt3273.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun printlnMock(a: Any) {} public fun testCoalesce() { diff --git a/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/realStringEscape.kt b/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/realStringEscape.kt index 4f514e71a02..958549b3308 100644 --- a/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/realStringEscape.kt +++ b/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/realStringEscape.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // KJS_WITH_FULL_RUNTIME // DONT_RUN_GENERATED_CODE: JS diff --git a/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/realStringRepeat.kt b/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/realStringRepeat.kt index 58eefe89238..9b58c22110c 100644 --- a/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/realStringRepeat.kt +++ b/compiler/testData/codegen/box/diagnostics/functions/tailRecursion/realStringRepeat.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // KJS_WITH_FULL_RUNTIME // DONT_RUN_GENERATED_CODE: JS diff --git a/compiler/testData/codegen/box/intrinsics/stringFromCollection.kt b/compiler/testData/codegen/box/intrinsics/stringFromCollection.kt index 785b0ce95ea..a889f52b9c7 100644 --- a/compiler/testData/codegen/box/intrinsics/stringFromCollection.kt +++ b/compiler/testData/codegen/box/intrinsics/stringFromCollection.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // KJS_WITH_FULL_RUNTIME fun box(): String { val list = ArrayList() diff --git a/compiler/testData/codegen/box/primitiveTypes/kt684.kt b/compiler/testData/codegen/box/primitiveTypes/kt684.kt index 6f2ab7f0296..34be34ea676 100644 --- a/compiler/testData/codegen/box/primitiveTypes/kt684.kt +++ b/compiler/testData/codegen/box/primitiveTypes/kt684.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/properties/kt3556.kt b/compiler/testData/codegen/box/properties/kt3556.kt index adec8d759fe..adce0368131 100644 --- a/compiler/testData/codegen/box/properties/kt3556.kt +++ b/compiler/testData/codegen/box/properties/kt3556.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR class Test { val a : String = "1" private val b : String get() = a diff --git a/compiler/testData/codegen/box/reflection/builtins/stringLength.kt b/compiler/testData/codegen/box/reflection/builtins/stringLength.kt index 21ae1251998..3644a4c104c 100644 --- a/compiler/testData/codegen/box/reflection/builtins/stringLength.kt +++ b/compiler/testData/codegen/box/reflection/builtins/stringLength.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // IGNORE_BACKEND: JS_IR, JS, NATIVE // WITH_REFLECT diff --git a/compiler/testData/codegen/box/safeCall/kt247.kt b/compiler/testData/codegen/box/safeCall/kt247.kt index c490038cafc..55a7fbe74f8 100644 --- a/compiler/testData/codegen/box/safeCall/kt247.kt +++ b/compiler/testData/codegen/box/safeCall/kt247.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun t1() : Boolean { val s1 : String? = "sff" val s2 : String? = null diff --git a/compiler/testData/codegen/box/safeCall/primitiveEqSafeCall.kt b/compiler/testData/codegen/box/safeCall/primitiveEqSafeCall.kt index ddc733b25a7..6cfb10708e8 100644 --- a/compiler/testData/codegen/box/safeCall/primitiveEqSafeCall.kt +++ b/compiler/testData/codegen/box/safeCall/primitiveEqSafeCall.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun Long.id() = this fun String.drop2() = if (length >= 2) subSequence(2, length) else null diff --git a/compiler/testData/codegen/box/safeCall/primitiveNotEqSafeCall.kt b/compiler/testData/codegen/box/safeCall/primitiveNotEqSafeCall.kt index 6ef217185cd..1485dea2135 100644 --- a/compiler/testData/codegen/box/safeCall/primitiveNotEqSafeCall.kt +++ b/compiler/testData/codegen/box/safeCall/primitiveNotEqSafeCall.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun Long.id() = this fun String.drop2() = if (length >= 2) subSequence(2, length) else null diff --git a/compiler/testData/codegen/box/safeCall/safeCallEqPrimitive.kt b/compiler/testData/codegen/box/safeCall/safeCallEqPrimitive.kt index fb1e7a238c6..fe8438abca6 100644 --- a/compiler/testData/codegen/box/safeCall/safeCallEqPrimitive.kt +++ b/compiler/testData/codegen/box/safeCall/safeCallEqPrimitive.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun Long.id() = this fun String.drop2() = if (length >= 2) subSequence(2, length) else null diff --git a/compiler/testData/codegen/box/safeCall/safeCallNotEqPrimitive.kt b/compiler/testData/codegen/box/safeCall/safeCallNotEqPrimitive.kt index 1270127a089..8cac0043470 100644 --- a/compiler/testData/codegen/box/safeCall/safeCallNotEqPrimitive.kt +++ b/compiler/testData/codegen/box/safeCall/safeCallNotEqPrimitive.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun Long.id() = this fun String.drop2() = if (length >= 2) subSequence(2, length) else null diff --git a/compiler/testData/codegen/box/smartCasts/whenSmartCast.kt b/compiler/testData/codegen/box/smartCasts/whenSmartCast.kt index c1f5c2155d5..8069048ce00 100644 --- a/compiler/testData/codegen/box/smartCasts/whenSmartCast.kt +++ b/compiler/testData/codegen/box/smartCasts/whenSmartCast.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun baz(s: String?): Int { if (s == null) return 0 return when(s) { diff --git a/compiler/testData/codegen/box/strings/multilineStringsWithTemplates.kt b/compiler/testData/codegen/box/strings/multilineStringsWithTemplates.kt index daa216647a5..38e661755cd 100644 --- a/compiler/testData/codegen/box/strings/multilineStringsWithTemplates.kt +++ b/compiler/testData/codegen/box/strings/multilineStringsWithTemplates.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR fun box() : String { val s = "abc" val test1 = """$s""" diff --git a/compiler/testData/codegen/box/strings/nestedConcat.kt b/compiler/testData/codegen/box/strings/nestedConcat.kt index 955110f2931..34b2d423c8d 100644 --- a/compiler/testData/codegen/box/strings/nestedConcat.kt +++ b/compiler/testData/codegen/box/strings/nestedConcat.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR // WITH_RUNTIME import kotlin.test.assertEquals diff --git a/compiler/testData/codegen/box/super/kt4982.kt b/compiler/testData/codegen/box/super/kt4982.kt index 76da76cab8e..8c01d8f2212 100644 --- a/compiler/testData/codegen/box/super/kt4982.kt +++ b/compiler/testData/codegen/box/super/kt4982.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR abstract class WaitFor { init { condition() diff --git a/compiler/testData/codegen/box/when/whenSafeCallSubjectEvaluatedOnce.kt b/compiler/testData/codegen/box/when/whenSafeCallSubjectEvaluatedOnce.kt index ac6febeb900..18ec8a99651 100644 --- a/compiler/testData/codegen/box/when/whenSafeCallSubjectEvaluatedOnce.kt +++ b/compiler/testData/codegen/box/when/whenSafeCallSubjectEvaluatedOnce.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND_FIR: JVM_IR var subjectEvaluated = 0 fun String.foo() = length.also { ++subjectEvaluated }