Use lazy logging in lowers
This commit is contained in:
+13
-13
@@ -72,12 +72,12 @@ open class DefaultArgumentStubGenerator constructor(val context: CommonBackendCo
|
||||
.mapNotNull{irFunction.getDefault(it)}
|
||||
|
||||
|
||||
log("detected ${functionDescriptor.name.asString()} has got #${bodies.size} default expressions")
|
||||
log { "detected ${functionDescriptor.name.asString()} has got #${bodies.size} default expressions" }
|
||||
functionDescriptor.overriddenDescriptors.forEach { context.log{"DEFAULT-REPLACER: $it"} }
|
||||
if (bodies.isNotEmpty()) {
|
||||
val newIrFunction = functionDescriptor.generateDefaultsFunction(context)
|
||||
val descriptor = newIrFunction.descriptor
|
||||
log("$functionDescriptor -> $descriptor")
|
||||
log { "$functionDescriptor -> $descriptor" }
|
||||
val builder = context.createIrBuilder(newIrFunction.symbol)
|
||||
val body = builder.irBlockBody(irFunction) {
|
||||
val params = mutableListOf<IrVariableSymbol>()
|
||||
@@ -104,7 +104,7 @@ open class DefaultArgumentStubGenerator constructor(val context: CommonBackendCo
|
||||
/* Use previously calculated values in next expression. */
|
||||
expressionBody.transformChildrenVoid(object:IrElementTransformerVoid() {
|
||||
override fun visitGetValue(expression: IrGetValue): IrExpression {
|
||||
log("GetValue: ${expression.descriptor}")
|
||||
log { "GetValue: ${expression.descriptor}" }
|
||||
val valueSymbol = variables[expression.descriptor] ?: return expression
|
||||
return irGet(valueSymbol)
|
||||
}
|
||||
@@ -174,7 +174,7 @@ open class DefaultArgumentStubGenerator constructor(val context: CommonBackendCo
|
||||
}
|
||||
|
||||
|
||||
private fun log(msg:String) = context.log{"DEFAULT-REPLACER: $msg"}
|
||||
private fun log(msg: () -> String) = context.log { "DEFAULT-REPLACER: ${msg()}" }
|
||||
}
|
||||
|
||||
private fun Scope.createTemporaryVariableDescriptor(parameterDescriptor: ParameterDescriptor?): VariableDescriptor =
|
||||
@@ -239,7 +239,7 @@ class DefaultParameterInjector constructor(val context: CommonBackendContext): B
|
||||
descriptor = symbolForCall.descriptor)
|
||||
.apply {
|
||||
params.forEach {
|
||||
log("call::params@${it.first.index}/${it.first.name.asString()}: ${ir2string(it.second)}")
|
||||
log { "call::params@${it.first.index}/${it.first.name.asString()}: ${ir2string(it.second)}" }
|
||||
putValueArgument(it.first.index, it.second)
|
||||
}
|
||||
dispatchReceiver = expression.dispatchReceiver
|
||||
@@ -259,8 +259,8 @@ class DefaultParameterInjector constructor(val context: CommonBackendContext): B
|
||||
return expression
|
||||
val (symbol, params) = parametersForCall(expression)
|
||||
val descriptor = symbol.descriptor
|
||||
descriptor.typeParameters.forEach { log("$descriptor [${it.index}]: $it") }
|
||||
descriptor.original.typeParameters.forEach { log("${descriptor.original}[${it.index}] : $it") }
|
||||
descriptor.typeParameters.forEach { log { "$descriptor [${it.index}]: $it" } }
|
||||
descriptor.original.typeParameters.forEach { log { "${descriptor.original}[${it.index}] : $it" } }
|
||||
return IrCallImpl(
|
||||
startOffset = expression.startOffset,
|
||||
endOffset = expression.endOffset,
|
||||
@@ -269,7 +269,7 @@ class DefaultParameterInjector constructor(val context: CommonBackendContext): B
|
||||
typeArguments = expression.descriptor.typeParameters.map{it to (expression.getTypeArgument(it) ?: it.defaultType) }.toMap())
|
||||
.apply {
|
||||
params.forEach {
|
||||
log("call::params@${it.first.index}/${it.first.name.asString()}: ${ir2string(it.second)}")
|
||||
log { "call::params@${it.first.index}/${it.first.name.asString()}: ${ir2string(it.second)}" }
|
||||
putValueArgument(it.first.index, it.second)
|
||||
}
|
||||
expression.extensionReceiver?.apply{
|
||||
@@ -278,8 +278,8 @@ class DefaultParameterInjector constructor(val context: CommonBackendContext): B
|
||||
expression.dispatchReceiver?.apply {
|
||||
dispatchReceiver = expression.dispatchReceiver
|
||||
}
|
||||
log("call::extension@: ${ir2string(expression.extensionReceiver)}")
|
||||
log("call::dispatch@: ${ir2string(expression.dispatchReceiver)}")
|
||||
log { "call::extension@: ${ir2string(expression.extensionReceiver)}" }
|
||||
log { "call::dispatch@: ${ir2string(expression.dispatchReceiver)}" }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -292,7 +292,7 @@ class DefaultParameterInjector constructor(val context: CommonBackendContext): B
|
||||
val realFunction = keyDescriptor.generateDefaultsFunction(context)
|
||||
val realDescriptor = realFunction.descriptor
|
||||
|
||||
log("$descriptor -> $realDescriptor")
|
||||
log { "$descriptor -> $realDescriptor" }
|
||||
val maskValues = Array(descriptor.valueParameters.size / 32 + 1, {0})
|
||||
val params = mutableListOf<Pair<ValueParameterDescriptor, IrExpression?>>()
|
||||
params.addAll(descriptor.valueParameters.mapIndexed { i, _ ->
|
||||
@@ -325,7 +325,7 @@ class DefaultParameterInjector constructor(val context: CommonBackendContext): B
|
||||
IrConstImpl.constNull(irBody.startOffset, irBody.endOffset, context.builtIns.any.defaultType)
|
||||
}
|
||||
params.forEach {
|
||||
log("descriptor::${realDescriptor.name.asString()}#${it.first.index}: ${it.first.name.asString()}")
|
||||
log { "descriptor::${realDescriptor.name.asString()}#${it.first.index}: ${it.first.name.asString()}" }
|
||||
}
|
||||
return Pair(realFunction.symbol, params)
|
||||
}
|
||||
@@ -335,7 +335,7 @@ class DefaultParameterInjector constructor(val context: CommonBackendContext): B
|
||||
})
|
||||
}
|
||||
|
||||
private fun log(msg: String) = context.log{"DEFAULT-INJECTOR: $msg"}
|
||||
private fun log(msg: () -> String) = context.log { "DEFAULT-INJECTOR: ${msg()}" }
|
||||
}
|
||||
|
||||
private val CallableMemberDescriptor.needsDefaultArgumentsLowering
|
||||
|
||||
+8
-9
@@ -39,7 +39,6 @@ import org.jetbrains.kotlin.ir.util.functions
|
||||
import org.jetbrains.kotlin.ir.util.getPropertyGetter
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
|
||||
@@ -70,10 +69,10 @@ class VarargInjectionLowering constructor(val context: CommonBackendContext): De
|
||||
val transformer = this
|
||||
|
||||
private fun replaceEmptyParameterWithEmptyArray(expression: IrMemberAccessExpression) {
|
||||
log("call of: ${expression.descriptor}")
|
||||
log { "call of: ${expression.descriptor}" }
|
||||
context.createIrBuilder(owner, expression.startOffset, expression.endOffset).apply {
|
||||
expression.descriptor.valueParameters.forEach {
|
||||
log("varargElementType: ${it.varargElementType} expr: ${ir2string(expression.getValueArgument(it))}")
|
||||
log { "varargElementType: ${it.varargElementType} expr: ${ir2string(expression.getValueArgument(it))}" }
|
||||
}
|
||||
expression.descriptor.valueParameters.filter { it.varargElementType != null && expression.getValueArgument(it) == null }.forEach {
|
||||
expression.putValueArgument(it.index,
|
||||
@@ -101,13 +100,13 @@ class VarargInjectionLowering constructor(val context: CommonBackendContext): De
|
||||
expression.transformChildrenVoid(transformer)
|
||||
val hasSpreadElement = hasSpreadElement(expression)
|
||||
if (!hasSpreadElement && expression.elements.all { it is IrConst<*> && KotlinBuiltIns.isString(it.type) }) {
|
||||
log("skipped vararg expression because it's string array literal")
|
||||
log { "skipped vararg expression because it's string array literal" }
|
||||
return expression
|
||||
}
|
||||
val irBuilder = context.createIrBuilder(owner, expression.startOffset, expression.endOffset)
|
||||
irBuilder.run {
|
||||
val type = expression.varargElementType
|
||||
log("$expression: array type:$type, is array of primitives ${!KotlinBuiltIns.isArray(expression.type)}")
|
||||
log { "$expression: array type:$type, is array of primitives ${!KotlinBuiltIns.isArray(expression.type)}" }
|
||||
val arrayHandle = arrayType(expression.type)
|
||||
val arrayConstructor = arrayHandle.arraySymbol.constructors.find { it.owner.valueParameters.size == 1 }!!
|
||||
val block = irBlock(arrayHandle.arraySymbol.owner.defaultType)
|
||||
@@ -136,7 +135,7 @@ class VarargInjectionLowering constructor(val context: CommonBackendContext): De
|
||||
irBuilder.startOffset = element.startOffset
|
||||
irBuilder.endOffset = element.endOffset
|
||||
irBuilder.apply {
|
||||
log("element:$i> ${ir2string(element)}")
|
||||
log { "element:$i> ${ir2string(element)}" }
|
||||
val dst = vars[element]!!
|
||||
if (element !is IrSpreadElement) {
|
||||
val setArrayElementCall = irCall(arrayHandle.setMethodSymbol)
|
||||
@@ -160,7 +159,7 @@ class VarargInjectionLowering constructor(val context: CommonBackendContext): De
|
||||
block.statements.add(copyCall)
|
||||
block.statements.add(incrementVariable(indexTmpVariable.symbol,
|
||||
irGet(arraySizeVariable.symbol)))
|
||||
log("element:$i:spread element> ${ir2string(element.expression)}")
|
||||
log { "element:$i:spread element> ${ir2string(element.expression)}" }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,8 +228,8 @@ class VarargInjectionLowering constructor(val context: CommonBackendContext): De
|
||||
|
||||
private fun hasSpreadElement(expression: IrVararg?) = expression?.elements?.any { it is IrSpreadElement }?:false
|
||||
|
||||
private fun log(msg:String) {
|
||||
context.log{"VARARG-INJECTOR: $msg"}
|
||||
private fun log(msg:() -> String) {
|
||||
context.log { "VARARG-INJECTOR: ${msg()}" }
|
||||
}
|
||||
|
||||
data class ArrayHandle(val arraySymbol: IrClassSymbol,
|
||||
|
||||
Reference in New Issue
Block a user