JVM_IR: compute classId on IR structures

This commit is contained in:
Georgy Bronnikov
2020-11-26 13:32:50 +03:00
parent ee1e05fedd
commit 6381d97aab
36 changed files with 17 additions and 40 deletions
@@ -56,6 +56,10 @@ fun classFileContainsMethod(descriptor: FunctionDescriptor, state: GenerationSta
}
}
return classFileContainsMethod(classId, state, method)
}
fun classFileContainsMethod(classId: ClassId, state: GenerationState, method: Method): Boolean? {
val bytes = VirtualFileFinder.getInstance(state.project, state.module).findVirtualFileWithHeader(classId)
?.contentsToByteArray() ?: return null
var found = false
@@ -21,10 +21,7 @@ import org.jetbrains.kotlin.codegen.SourceInfo
import org.jetbrains.kotlin.codegen.classFileContainsMethod
import org.jetbrains.kotlin.codegen.inline.SourceMapper
import org.jetbrains.kotlin.codegen.signature.BothSignatureWriter
import org.jetbrains.kotlin.descriptors.ClassKind
import org.jetbrains.kotlin.descriptors.DeclarationDescriptorWithSource
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.descriptors.Modality
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
@@ -36,6 +33,8 @@ import org.jetbrains.kotlin.ir.types.getClass
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.load.java.JavaDescriptorVisibilities
import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource
import org.jetbrains.kotlin.name.ClassId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.resolve.checkers.ExpectedActualDeclarationChecker
import org.jetbrains.kotlin.resolve.inline.INLINE_ONLY_ANNOTATION_FQ_NAME
@@ -379,12 +378,20 @@ val IrMemberAccessExpression<*>.psiElement: PsiElement?
fun IrSimpleType.isRawType(): Boolean =
hasAnnotation(JvmGeneratorExtensions.RAW_TYPE_ANNOTATION_FQ_NAME)
@OptIn(ObsoleteDescriptorBasedAPI::class)
internal fun classFileContainsMethod(function: IrFunction, context: JvmBackendContext, name: String): Boolean? {
val classId = (function.parent as? IrClass)?.classId ?: (function.containerSource as? JvmPackagePartSource)?.classId ?: return null
val originalDescriptor = context.methodSignatureMapper.mapSignatureWithGeneric(function).asmMethod.descriptor
val descriptor = if (function.isSuspend)
listOf(*Type.getArgumentTypes(originalDescriptor), Type.getObjectType("kotlin/coroutines/Continuation"))
.joinToString(prefix = "(", postfix = ")", separator = "") + AsmTypes.OBJECT_TYPE
else originalDescriptor
return classFileContainsMethod(function.descriptor, context.state, Method(name, descriptor))
return classFileContainsMethod(classId, context.state, Method(name, descriptor))
}
// Translated into IR-based terms from classifierDescriptor?.classId
val IrClass.classId: ClassId?
get() = when (val parent = parent) {
is IrExternalPackageFragment -> ClassId(parent.fqName, name)
is IrClass -> parent.classId?.createNestedClassId(name)
else -> null
}
@@ -3,7 +3,6 @@
// !LANGUAGE: +InlineClasses
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
class C<T>(val x: T, vararg ys: UInt) {
val y0 = ys[0]
@@ -1,7 +1,6 @@
// IGNORE_BACKEND: JVM
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
fun box(): String {
// These should all be empty progressions
@@ -1,6 +1,5 @@
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
fun ub_ub(x: UByte, a: UByte, b: UByte) = x in a..b
fun ub_us(x: UByte, a: UShort, b: UShort) = x in a..b
@@ -1,6 +1,5 @@
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
fun ULong.foobar() =
when (this) {
@@ -3,7 +3,6 @@
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
fun box(): String {
var result = 0u
@@ -3,7 +3,6 @@
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
fun box(): String {
var result = 0u
@@ -3,7 +3,6 @@
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
fun box(): String {
var result = 0u
@@ -1,6 +1,5 @@
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
fun testIn(x: ULong) =
x in UInt.MIN_VALUE..UInt.MAX_VALUE
@@ -1,6 +1,5 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
fun box(): String {
val good = 42.toUInt()
@@ -2,7 +2,6 @@
// WASM_MUTE_REASON: STDLIB_COLLECTIONS
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
const val MaxUI = UInt.MAX_VALUE
const val MinUI = UInt.MIN_VALUE
@@ -2,7 +2,6 @@
// WASM_MUTE_REASON: STDLIB_COLLECTIONS
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
const val MaxUI = UInt.MAX_VALUE
const val MinUI = UInt.MIN_VALUE
@@ -2,7 +2,6 @@
// WASM_MUTE_REASON: STDLIB_COLLECTIONS
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
const val MaxUI = UInt.MAX_VALUE
const val MinUI = UInt.MIN_VALUE
@@ -2,7 +2,6 @@
// WASM_MUTE_REASON: STDLIB_COLLECTIONS
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
const val MaxUI = UInt.MAX_VALUE
const val MinUI = UInt.MIN_VALUE
@@ -1,6 +1,5 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
val UB_MAX = UByte.MAX_VALUE
val UB_START = (UB_MAX - 10u).toUByte()
@@ -2,7 +2,6 @@
// WASM_MUTE_REASON: STDLIB_COLLECTIONS
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
const val MaxUI = UInt.MAX_VALUE
const val MinUI = UInt.MIN_VALUE
@@ -2,7 +2,6 @@
// WASM_MUTE_REASON: STDLIB_COLLECTIONS
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
const val MaxUI = UInt.MAX_VALUE
const val MinUI = UInt.MIN_VALUE
@@ -1,6 +1,5 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
const val MaxUI = UInt.MAX_VALUE
const val MinUI = UInt.MIN_VALUE
@@ -1,6 +1,5 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
const val MaxUI = UInt.MAX_VALUE
const val MinUI = UInt.MIN_VALUE
@@ -1,6 +1,5 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
const val MaxUI = UInt.MAX_VALUE
const val MinUI = UInt.MIN_VALUE
@@ -2,7 +2,6 @@
// WASM_MUTE_REASON: UNSIGNED_ARRAYS
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
fun box(): String {
var sum = 0u
@@ -1,6 +1,5 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
fun box(): String {
var sum = 0u
@@ -2,7 +2,6 @@
// WASM_MUTE_REASON: PROPERTY_REFERENCES
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
import kotlin.reflect.KProperty
import kotlin.reflect.KProperty0
@@ -1,7 +1,6 @@
// JVM_TARGET: 1.8
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
fun box(): String {
val x = 3UL % 2U
@@ -1,6 +1,5 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
val ua = 1234U
val ub = 5678U
@@ -1,6 +1,5 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
val ua = 1234U
val ub = 5678U
@@ -1,6 +1,5 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
val ua = 1234UL
val ub = 5678UL
@@ -1,6 +1,5 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
val ua = 1234UL
val ub = 5678UL
@@ -2,7 +2,6 @@
// WASM_MUTE_REASON: STDLIB_TEXT
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
const val MAX_BYTE: UByte = 0xFFu
const val HUNDRED: UByte = 100u
@@ -2,7 +2,6 @@
// WASM_MUTE_REASON: SPREAD_OPERATOR
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
fun uint(vararg us: UInt): UIntArray = us
@@ -1,6 +1,5 @@
// JVM_TARGET: 1.8
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
val ua = 1234U
val ub = 5678U
@@ -1,6 +1,5 @@
// JVM_TARGET: 1.8
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
val ua = 1234U
val ub = 5678U
@@ -1,6 +1,5 @@
// JVM_TARGET: 1.8
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
val ua = 1234UL
val ub = 5678UL
@@ -1,6 +1,5 @@
// JVM_TARGET: 1.8
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR
val ua = 1234UL
val ub = 5678UL
@@ -1,5 +1,4 @@
// !LANGUAGE: +InlineClasses
// IGNORE_BACKEND_FIR: JVM_IR
// FILE: 1.kt
// KOTLIN_CONFIGURATION_FLAGS: +JVM.USE_OLD_INLINE_CLASSES_MANGLING_SCHEME
package test