[FIR] Get module name for deserialized fir2ir classes
This commit is contained in:
committed by
teamcityserver
parent
dc8934ab22
commit
a121061df7
+4
-4
@@ -31,10 +31,8 @@ import org.jetbrains.kotlin.fir.types.impl.ConeClassLikeTypeImpl
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
||||
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.Flags
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.metadata.deserialization.TypeTable
|
||||
import org.jetbrains.kotlin.metadata.deserialization.supertypes
|
||||
import org.jetbrains.kotlin.metadata.deserialization.*
|
||||
import org.jetbrains.kotlin.metadata.jvm.JvmProtoBuf
|
||||
import org.jetbrains.kotlin.name.CallableId
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -216,6 +214,8 @@ fun deserializeClassToSymbol(
|
||||
it.versionRequirementsTable = context.versionRequirementTable
|
||||
|
||||
it.sourceElement = containerSource
|
||||
|
||||
it.proto = FirClassProto(classProto, nameResolver)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.isNullableAny
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.IrMaybeDeserializedClass
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.lazyVar
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
@@ -27,6 +28,8 @@ import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||
import org.jetbrains.kotlin.ir.util.isFakeOverride
|
||||
import org.jetbrains.kotlin.ir.util.render
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class Fir2IrLazyClass(
|
||||
@@ -36,7 +39,7 @@ class Fir2IrLazyClass(
|
||||
override var origin: IrDeclarationOrigin,
|
||||
override val fir: FirRegularClass,
|
||||
override val symbol: Fir2IrClassSymbol,
|
||||
) : IrClass(), AbstractFir2IrLazyDeclaration<FirRegularClass, IrClass>, Fir2IrComponents by components {
|
||||
) : IrClass(), AbstractFir2IrLazyDeclaration<FirRegularClass, IrClass>, IrMaybeDeserializedClass, Fir2IrComponents by components {
|
||||
init {
|
||||
symbol.bind(this)
|
||||
classifierStorage.preCacheTypeParameters(fir)
|
||||
@@ -201,6 +204,12 @@ class Fir2IrLazyClass(
|
||||
get() = null
|
||||
set(_) = error("We should never need to store metadata of external declarations.")
|
||||
|
||||
override val classProto: ProtoBuf.Class?
|
||||
get() = fir.proto?.classProto
|
||||
|
||||
override val nameResolver: NameResolver?
|
||||
get() = fir.proto?.nameResolver
|
||||
|
||||
private fun FirNamedFunctionSymbol.isAbstractMethodOfAny(): Boolean {
|
||||
val fir = fir
|
||||
if (fir.modality != Modality.ABSTRACT) return false
|
||||
|
||||
@@ -23,6 +23,8 @@ import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.ConeFlexibleType
|
||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
|
||||
fun FirTypeParameterBuilder.addDefaultBoundIfNecessary(isFlexible: Boolean = false) {
|
||||
if (bounds.isEmpty()) {
|
||||
@@ -182,6 +184,12 @@ private object SourceElementKey : FirDeclarationDataKey()
|
||||
|
||||
var FirRegularClass.sourceElement: SourceElement? by FirDeclarationDataRegistry.data(SourceElementKey)
|
||||
|
||||
private object ClassProtoKey : FirDeclarationDataKey()
|
||||
|
||||
class FirClassProto(val classProto: ProtoBuf.Class, val nameResolver: NameResolver)
|
||||
|
||||
var FirRegularClass.proto: FirClassProto? by FirDeclarationDataRegistry.data(ClassProtoKey)
|
||||
|
||||
var FirTypeAlias.sourceElement: SourceElement? by FirDeclarationDataRegistry.data(SourceElementKey)
|
||||
|
||||
val FirMemberDeclaration.containerSource: SourceElement?
|
||||
|
||||
+4
-3
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyClass
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyFunctionBase
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.IrMaybeDeserializedClass
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBasedSimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
@@ -149,7 +150,7 @@ class MethodSignatureMapper(private val context: JvmBackendContext) {
|
||||
} else null
|
||||
|
||||
private fun getModuleName(function: IrSimpleFunction): String =
|
||||
(if (function is IrLazyFunction)
|
||||
(if (function is IrLazyFunctionBase)
|
||||
getJvmModuleNameForDeserialized(function)
|
||||
else null) ?: context.state.moduleName
|
||||
|
||||
@@ -494,11 +495,11 @@ class MethodSignatureMapper(private val context: JvmBackendContext) {
|
||||
}
|
||||
|
||||
// From org.jetbrains.kotlin.load.kotlin.getJvmModuleNameForDeserializedDescriptor
|
||||
private fun getJvmModuleNameForDeserialized(function: IrLazyFunction): String? {
|
||||
private fun getJvmModuleNameForDeserialized(function: IrLazyFunctionBase): String? {
|
||||
var current: IrDeclarationParent? = function.parent
|
||||
while (current != null) {
|
||||
when (current) {
|
||||
is IrLazyClass -> {
|
||||
is IrMaybeDeserializedClass -> {
|
||||
val classProto = current.classProto ?: return null
|
||||
val nameResolver = current.nameResolver ?: return null
|
||||
return classProto.getExtensionOrNull(JvmProtoBuf.classModuleName)
|
||||
|
||||
@@ -40,7 +40,7 @@ class IrLazyClass(
|
||||
override val isFun: Boolean,
|
||||
override val stubGenerator: DeclarationStubGenerator,
|
||||
override val typeTranslator: TypeTranslator
|
||||
) : IrClass(), IrLazyDeclarationBase {
|
||||
) : IrClass(), IrLazyDeclarationBase, IrMaybeDeserializedClass {
|
||||
init {
|
||||
symbol.bind(this)
|
||||
}
|
||||
@@ -103,8 +103,8 @@ class IrLazyClass(
|
||||
|
||||
override var attributeOwnerId: IrAttributeContainer = this
|
||||
|
||||
val classProto: ProtoBuf.Class? get() = (descriptor as? DeserializedClassDescriptor)?.classProto
|
||||
val nameResolver: NameResolver? get() = (descriptor as? DeserializedClassDescriptor)?.c?.nameResolver
|
||||
override val classProto: ProtoBuf.Class? get() = (descriptor as? DeserializedClassDescriptor)?.classProto
|
||||
override val nameResolver: NameResolver? get() = (descriptor as? DeserializedClassDescriptor)?.c?.nameResolver
|
||||
override val source: SourceElement get() = descriptor.source
|
||||
|
||||
override var metadata: MetadataSource?
|
||||
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.ir.declarations.lazy
|
||||
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
|
||||
interface IrMaybeDeserializedClass : IrDeclaration {
|
||||
val classProto: ProtoBuf.Class?
|
||||
val nameResolver: NameResolver?
|
||||
}
|
||||
Vendored
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// MODULE: lib
|
||||
// FILE: A.kt
|
||||
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// MODULE: lib
|
||||
// FILE: A.kt
|
||||
|
||||
-1
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: NATIVE
|
||||
// MODULE: lib
|
||||
// FILE: A.kt
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// IGNORE_BACKEND: JS_IR
|
||||
// IGNORE_BACKEND: JS_IR_ES6
|
||||
// MODULE: lib
|
||||
|
||||
Reference in New Issue
Block a user