JVM IR: link via descriptors instead of signatures by default

Doing so speeds up psi2ir ~2 times, and thus improves total compiler
performance by about 6-8%.

Unless JVM IR is in the mode where linking via signatures is the only
way (-Xserialize-ir, -Xklib), signatures are actually not needed at all,
SymbolTable can use the frontend representation (descriptors for FE1.0,
and hopefully FIR elements for K2) as hash table keys. The only catch is
that since other backends still need to work with signatures, all the
common IR utilities, such as irTypePredicates.kt, need to work correctly
for IR elements both with signatures and without.

Also, introduce a fallback compiler flag -Xlink-via-signatures, in case
something goes wrong, to be able to troubleshoot and workaround any
issues.

 #KT-48233
This commit is contained in:
Alexander Udalov
2022-01-24 14:26:28 +01:00
parent 6e4131de8e
commit 6379fe4c4c
18 changed files with 290 additions and 70 deletions
@@ -0,0 +1,50 @@
/*
* Copyright 2010-2022 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.backend.jvm.serialization
import org.jetbrains.kotlin.backend.common.serialization.mangle.SpecialDeclarationType
import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.ir.util.IdSignature
import org.jetbrains.kotlin.ir.util.KotlinMangler
object DisabledDescriptorMangler : KotlinMangler.DescriptorMangler {
override val String.hashMangle: Long
get() = error("Should not be called")
override fun DeclarationDescriptor.isExported(compatibleMode: Boolean): Boolean =
error("Should not be called")
override fun DeclarationDescriptor.mangleString(compatibleMode: Boolean): String =
error("Should not be called")
override fun DeclarationDescriptor.signatureString(compatibleMode: Boolean): String =
error("Should not be called")
override fun DeclarationDescriptor.fqnString(compatibleMode: Boolean): String =
error("Should not be called")
override fun ClassDescriptor.mangleEnumEntryString(compatibleMode: Boolean): String =
error("Should not be called")
override fun PropertyDescriptor.mangleFieldString(compatibleMode: Boolean): String =
error("Should not be called")
}
object DisabledIdSignatureDescriptor : IdSignatureDescriptor(DisabledDescriptorMangler) {
override fun composeSignature(descriptor: DeclarationDescriptor): IdSignature? = null
override fun composeEnumEntrySignature(descriptor: ClassDescriptor): IdSignature? = null
override fun composeFieldSignature(descriptor: PropertyDescriptor): IdSignature? = null
override fun composeAnonInitSignature(descriptor: ClassDescriptor): IdSignature? = null
override fun createSignatureBuilder(type: SpecialDeclarationType): DescriptorBasedSignatureBuilder =
error("Should not be called")
}
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.konan.KlibModuleOrigin
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.builders.TranslationPluginContext
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrField
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl
@@ -38,7 +39,8 @@ class JvmIrLinker(
symbolTable: SymbolTable,
override val translationPluginContext: TranslationPluginContext?,
private val stubGenerator: DeclarationStubGenerator,
private val manglerDesc: JvmDescriptorMangler
private val manglerDesc: JvmDescriptorMangler,
private val enableIdSignatures: Boolean,
) : KotlinIrLinker(currentModule, messageLogger, typeSystem.irBuiltIns, symbolTable, emptyList()) {
// TODO: provide friend modules
@@ -91,6 +93,8 @@ class JvmIrLinker(
}
}
override fun getDeclaration(symbol: IrSymbol): IrDeclaration? =
deserializeOrResolveDeclaration(symbol, !enableIdSignatures)
override fun createCurrentModuleDeserializer(moduleFragment: IrModuleFragment, dependencies: Collection<IrModuleDeserializer>): IrModuleDeserializer =
JvmCurrentModuleDeserializer(moduleFragment, dependencies)