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".
This commit is contained in:
Alexander Udalov
2022-01-27 14:34:25 +01:00
parent 7c172f5798
commit 17c8ac5440
2 changed files with 12 additions and 3 deletions
@@ -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<IrConstructorCall> 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)
}
@@ -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 ->