Skip to content

Commit

Permalink
JVM_IR: compute classId on IR structures
Browse files Browse the repository at this point in the history
  • Loading branch information
Georgy Bronnikov committed Nov 27, 2020
1 parent ee1e05f commit 6381d97
Show file tree
Hide file tree
Showing 36 changed files with 17 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 0 additions & 1 deletion compiler/testData/codegen/box/ranges/forInUntil/kt42533.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 0 additions & 1 deletion compiler/testData/codegen/box/ranges/unsigned/kt35004.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR

fun ULong.foobar() =
when (this) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR

fun box(): String {
var result = 0u
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR

fun box(): String {
var result = 0u
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR

fun box(): String {
var result = 0u
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR

fun box(): String {
val good = 42.toUInt()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR

fun box(): String {
var sum = 0u
Expand Down
1 change: 0 additions & 1 deletion compiler/testData/codegen/box/unsignedTypes/kt25784.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion compiler/testData/codegen/box/unsignedTypes/kt43286a.kt
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR

val ua = 1234U
val ub = 5678U
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR

val ua = 1234U
val ub = 5678U
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR

val ua = 1234UL
val ub = 5678UL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// KJS_WITH_FULL_RUNTIME
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR

val ua = 1234UL
val ub = 5678UL
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// JVM_TARGET: 1.8
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR

val ua = 1234U
val ub = 5678U
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// JVM_TARGET: 1.8
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR

val ua = 1234U
val ub = 5678U
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// JVM_TARGET: 1.8
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR

val ua = 1234UL
val ub = 5678UL
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// JVM_TARGET: 1.8
// WITH_RUNTIME
// IGNORE_BACKEND_FIR: JVM_IR

val ua = 1234UL
val ub = 5678UL
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 6381d97

Please sign in to comment.