[FIR2IR] Implement mapping of FIR & IR built-in class members
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+58
-8
@@ -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) {
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
// WITH_RUNTIME
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
interface B<T> {
|
||||
val bar: T
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
fun box(): String {
|
||||
var x = 0
|
||||
do x++ while (x < 5)
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
fun printlnMock(a: Any) {}
|
||||
|
||||
public fun testCoalesce() {
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
// DONT_RUN_GENERATED_CODE: JS
|
||||
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
// DONT_RUN_GENERATED_CODE: JS
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// KJS_WITH_FULL_RUNTIME
|
||||
fun box(): String {
|
||||
val list = ArrayList<String>()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
class Test {
|
||||
val a : String = "1"
|
||||
private val b : String get() = a
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JS_IR, JS, NATIVE
|
||||
// WITH_REFLECT
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
fun t1() : Boolean {
|
||||
val s1 : String? = "sff"
|
||||
val s2 : String? = null
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
fun Long.id() = this
|
||||
|
||||
fun String.drop2() = if (length >= 2) subSequence(2, length) else null
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
fun Long.id() = this
|
||||
|
||||
fun String.drop2() = if (length >= 2) subSequence(2, length) else null
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
fun Long.id() = this
|
||||
|
||||
fun String.drop2() = if (length >= 2) subSequence(2, length) else null
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
fun Long.id() = this
|
||||
|
||||
fun String.drop2() = if (length >= 2) subSequence(2, length) else null
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
fun baz(s: String?): Int {
|
||||
if (s == null) return 0
|
||||
return when(s) {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
fun box() : String {
|
||||
val s = "abc"
|
||||
val test1 = """$s"""
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// WITH_RUNTIME
|
||||
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
abstract class WaitFor {
|
||||
init {
|
||||
condition()
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
var subjectEvaluated = 0
|
||||
|
||||
fun String.foo() = length.also { ++subjectEvaluated }
|
||||
|
||||
Reference in New Issue
Block a user