From 17c8ac5440aa27fae0831dd7e1d9ef308b723cd2 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 27 Jan 2022 14:34:25 +0100 Subject: [PATCH] IR: make IrLazyValueParameter.type/varargElementType lazy This makes it a bit more apparent, in profiler snapshots, where parameter types are really needed. Also, hopefully it will improve performance somewhat in cases where types are not needed. For example, before this change about 1/3 of the time of `DefaultArgumentStubGenerator.lower` on JVM was actually computing types of parameters from dependencies, even though the actual types were not needed, only the presence of defaultValue was used. This made it the most time-consuming lowering phase on JVM. After this change, default argument lowering is thus 50% faster, however this time is in part distributed among other lowerings that visit the whole override hierarchy for all methods and really need the types of parameters, e.g. BridgeLowering, SyntheticAccessorLowering. So the profiler snapshots are now more "honest". --- .../ir/declarations/lazy/IrLazyValueParameter.kt | 13 +++++++++++-- .../kotlin/ir/util/DeclarationStubGenerator.kt | 2 +- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyValueParameter.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyValueParameter.kt index f094fd53974..540fe49dc78 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyValueParameter.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/declarations/lazy/IrLazyValueParameter.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.ir.types.IrType import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator import org.jetbrains.kotlin.ir.util.TypeTranslator import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.types.KotlinType @OptIn(ObsoleteDescriptorBasedAPI::class) class IrLazyValueParameter( @@ -27,8 +28,8 @@ class IrLazyValueParameter( override val descriptor: ValueParameterDescriptor, override val name: Name, override val index: Int, - override var type: IrType, - override var varargElementType: IrType?, + kotlinType: KotlinType, + varargElementKotlinType: KotlinType?, override val isCrossinline: Boolean, override val isNoinline: Boolean, override val isHidden: Boolean, @@ -42,6 +43,14 @@ class IrLazyValueParameter( override var annotations: List by createLazyAnnotations() + override var type: IrType by lazyVar(stubGenerator.lock) { + kotlinType.toIrType() + } + + override var varargElementType: IrType? by lazyVar(stubGenerator.lock) { + varargElementKotlinType?.toIrType() + } + init { symbol.bind(this) } diff --git a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt index 307cb0f5a66..4f22b67cffc 100644 --- a/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt +++ b/compiler/ir/ir.tree/src/org/jetbrains/kotlin/ir/util/DeclarationStubGenerator.kt @@ -236,7 +236,7 @@ abstract class DeclarationStubGenerator( internal fun generateValueParameterStub(descriptor: ValueParameterDescriptor, index: Int): IrValueParameter = with(descriptor) { IrLazyValueParameter( UNDEFINED_OFFSET, UNDEFINED_OFFSET, computeOrigin(this), IrValueParameterSymbolImpl(this), this, name, index, - type.toIrType(), varargElementType?.toIrType(), + type, varargElementType, isCrossinline = isCrossinline, isNoinline = isNoinline, isHidden = false, isAssignable = false, stubGenerator = this@DeclarationStubGenerator, typeTranslator = typeTranslator ).also { irValueParameter ->