FIR2IR: don't calculate signatures for callables when possible
This commit is contained in:
+30
-8
@@ -55,6 +55,7 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
import org.jetbrains.kotlin.name.SpecialNames
|
import org.jetbrains.kotlin.name.SpecialNames
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||||
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
import org.jetbrains.kotlin.utils.KotlinExceptionWithAttachments
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.runUnless
|
||||||
import org.jetbrains.kotlin.utils.threadLocal
|
import org.jetbrains.kotlin.utils.threadLocal
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
@@ -510,7 +511,22 @@ class Fir2IrDeclarationStorage(
|
|||||||
function.origin == FirDeclarationOrigin.Enhancement -> IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
|
function.origin == FirDeclarationOrigin.Enhancement -> IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
|
||||||
else -> function.computeIrOrigin(predefinedOrigin)
|
else -> function.computeIrOrigin(predefinedOrigin)
|
||||||
}
|
}
|
||||||
val signature = if (isLocal) null else signatureComposer.composeSignature(function, containingClass, forceTopLevelPrivate)
|
// We don't generate signatures for local classes
|
||||||
|
// We attempt to avoid signature generation for non-local classes, with the following exceptions:
|
||||||
|
// - special mode (generateSignatures) oriented on special backend modes
|
||||||
|
// - lazy classes (they still use signatures)
|
||||||
|
// - primitive types (they can be from built-ins and don't have FIR counterpart)
|
||||||
|
// - overrides and fake overrides (sometimes we perform "receiver replacement" in FIR2IR breaking FIR->IR relation,
|
||||||
|
// or FIR counterpart can be just created on the fly)
|
||||||
|
val signature =
|
||||||
|
runUnless(
|
||||||
|
isLocal ||
|
||||||
|
!generateSignatures && irParent !is Fir2IrLazyClass &&
|
||||||
|
function.dispatchReceiverType?.isPrimitive != true && function.containerSource == null &&
|
||||||
|
updatedOrigin != IrDeclarationOrigin.FAKE_OVERRIDE && !function.isOverride
|
||||||
|
) {
|
||||||
|
signatureComposer.composeSignature(function, containingClass, forceTopLevelPrivate)
|
||||||
|
}
|
||||||
if (irParent is Fir2IrLazyClass && signature != null) {
|
if (irParent is Fir2IrLazyClass && signature != null) {
|
||||||
// For private functions signature is null, fallback to non-lazy function
|
// For private functions signature is null, fallback to non-lazy function
|
||||||
return createIrLazyFunction(function as FirSimpleFunction, signature, irParent, updatedOrigin)
|
return createIrLazyFunction(function as FirSimpleFunction, signature, irParent, updatedOrigin)
|
||||||
@@ -743,7 +759,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
type: IrType? = null
|
type: IrType? = null
|
||||||
): IrField = convertCatching(property) {
|
): IrField = convertCatching(property) {
|
||||||
val inferredType = type ?: firInitializerExpression!!.typeRef.toIrType()
|
val inferredType = type ?: firInitializerExpression!!.typeRef.toIrType()
|
||||||
return declareIrField(null) { symbol ->
|
return declareIrField { symbol ->
|
||||||
irFactory.createField(
|
irFactory.createField(
|
||||||
startOffset, endOffset, origin, symbol,
|
startOffset, endOffset, origin, symbol,
|
||||||
name, inferredType,
|
name, inferredType,
|
||||||
@@ -778,11 +794,8 @@ class Fir2IrDeclarationStorage(
|
|||||||
else
|
else
|
||||||
symbolTable.declareProperty(signature, { Fir2IrPropertySymbol(signature, containerSource) }, factory)
|
symbolTable.declareProperty(signature, { Fir2IrPropertySymbol(signature, containerSource) }, factory)
|
||||||
|
|
||||||
private fun declareIrField(signature: IdSignature?, factory: (IrFieldSymbol) -> IrField): IrField =
|
private fun declareIrField(factory: (IrFieldSymbol) -> IrField): IrField =
|
||||||
if (signature == null)
|
factory(IrFieldSymbolImpl())
|
||||||
factory(IrFieldSymbolImpl())
|
|
||||||
else
|
|
||||||
symbolTable.declareField(signature, { IrFieldPublicSymbolImpl(signature) }, factory)
|
|
||||||
|
|
||||||
fun getOrCreateIrProperty(
|
fun getOrCreateIrProperty(
|
||||||
property: FirProperty,
|
property: FirProperty,
|
||||||
@@ -835,7 +848,16 @@ class Fir2IrDeclarationStorage(
|
|||||||
forceTopLevelPrivate: Boolean = false,
|
forceTopLevelPrivate: Boolean = false,
|
||||||
): IrProperty = convertCatching(property) {
|
): IrProperty = convertCatching(property) {
|
||||||
val origin = property.computeIrOrigin(predefinedOrigin)
|
val origin = property.computeIrOrigin(predefinedOrigin)
|
||||||
val signature = if (isLocal) null else signatureComposer.composeSignature(property, containingClass, forceTopLevelPrivate)
|
// See similar comments in createIrFunction above
|
||||||
|
val signature =
|
||||||
|
runUnless(
|
||||||
|
isLocal ||
|
||||||
|
!generateSignatures && irParent !is Fir2IrLazyClass &&
|
||||||
|
property.dispatchReceiverType?.isPrimitive != true && property.containerSource == null &&
|
||||||
|
origin != IrDeclarationOrigin.FAKE_OVERRIDE && !property.isOverride
|
||||||
|
) {
|
||||||
|
signatureComposer.composeSignature(property, containingClass, forceTopLevelPrivate)
|
||||||
|
}
|
||||||
if (irParent is Fir2IrLazyClass && signature != null) {
|
if (irParent is Fir2IrLazyClass && signature != null) {
|
||||||
// For private functions signature is null, fallback to non-lazy property
|
// For private functions signature is null, fallback to non-lazy property
|
||||||
return createIrLazyProperty(property, signature, irParent, origin)
|
return createIrLazyProperty(property, signature, irParent, origin)
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
// IGNORE_BACKEND_FIR: ANY
|
|
||||||
|
|
||||||
val <T : CharSequence> T.gk: () -> T
|
val <T : CharSequence> T.gk: () -> T
|
||||||
get() = { -> this }
|
get() = { -> this }
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user