Turned conext.log("text") into context.log{"text"} so that the argument

evaluated lazily. This is especially useful when the text is constructed from
large IR pieces using ir2stringWhole().
This commit is contained in:
Alexander Gorshenev
2017-04-18 15:57:17 +03:00
committed by alexander-gorshenev
parent 3bdc7f6514
commit 4cf27e44ec
11 changed files with 58 additions and 58 deletions
@@ -410,9 +410,9 @@ internal class Context(config: KonanConfig) : KonanBackendContext(config) {
return config.configuration.getBoolean(KonanConfigKeys.DEBUG)
}
fun log(message: String) {
fun log(message: () -> String) {
if (phase?.verbose ?: false) {
println(message)
println(message())
}
}
@@ -279,8 +279,8 @@ internal class LinkStage(val context: Context) {
fun executeCommand(vararg command: String): Int {
context.log("")
context.log(command.asList<String>().joinToString(" "))
context.log{""}
context.log{command.asList<String>().joinToString(" ")}
val builder = ProcessBuilder(command.asList())
@@ -300,7 +300,7 @@ internal class LinkStage(val context: Context) {
}
fun linkStage() {
context.log("# Compiler root: ${distribution.konanHome}")
context.log{"# Compiler root: ${distribution.konanHome}"}
val bitcodeFiles = listOf<BitcodeFile>(emitted, distribution.start,
distribution.runtime, distribution.launcher) + libraries
@@ -101,4 +101,4 @@ internal fun Context.createArrayOfExpression(arrayElementType: KotlinType,
return IrCallImpl(startOffset, endOffset, substitutedArrayOfFun, typeArguments).apply {
putValueArgument(0, arg0)
}
}
}
@@ -273,7 +273,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
override fun visitModuleFragment(module: IrModuleFragment) {
context.log("visitModule : ${ir2string(module)}")
context.log{"visitModule : ${ir2string(module)}"}
// computeLifetimes(module, this.codegen, resultLifetimes)
@@ -389,7 +389,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
override fun visitConstructor(constructorDeclaration: IrConstructor) {
context.log("visitConstructor : ${ir2string(constructorDeclaration)}")
context.log{"visitConstructor : ${ir2string(constructorDeclaration)}"}
if (constructorDeclaration.descriptor.containingDeclaration.isIntrinsic) {
// Do not generate any ctors for intrinsic classes.
return
@@ -413,7 +413,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
override fun visitAnonymousInitializer(declaration: IrAnonymousInitializer) {
context.log("visitAnonymousInitializer : ${ir2string(declaration)}")
context.log{"visitAnonymousInitializer : ${ir2string(declaration)}"}
}
//-------------------------------------------------------------------------//
@@ -522,7 +522,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
}
override fun visitFunction(declaration: IrFunction) {
context.log("visitFunction : ${ir2string(declaration)}")
context.log{"visitFunction : ${ir2string(declaration)}"}
val body = declaration.body
if (declaration.descriptor.modality == Modality.ABSTRACT) return
@@ -563,7 +563,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
override fun visitClass(declaration: IrClass) {
context.log("visitClass : ${ir2string(declaration)}")
context.log{"visitClass : ${ir2string(declaration)}"}
if (declaration.descriptor.kind == ClassKind.ANNOTATION_CLASS) {
// do not generate any code for annotation classes as a workaround for NotImplementedError
return
@@ -587,7 +587,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
override fun visitField(expression: IrField) {
context.log("visitField : ${ir2string(expression)}")
context.log{"visitField : ${ir2string(expression)}"}
val descriptor = expression.descriptor
if (descriptor.containingDeclaration is PackageFragmentDescriptor) {
val type = codegen.getLLVMType(descriptor.type)
@@ -1051,7 +1051,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
* we cannot determine if the result of when is assigned or not.
*/
private fun evaluateWhen(expression: IrWhen): LLVMValueRef {
context.log("evaluateWhen : ${ir2string(expression)}")
context.log{"evaluateWhen : ${ir2string(expression)}"}
var bbExit: LLVMBasicBlockRef? = null // By default "when" does not have "exit".
val isUnit = KotlinBuiltIns.isUnit(expression.type)
val isNothing = KotlinBuiltIns.isNothing(expression.type)
@@ -1140,7 +1140,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
private fun evaluateGetValue(value: IrGetValue): LLVMValueRef {
context.log("evaluateGetValue : ${ir2string(value)}")
context.log{"evaluateGetValue : ${ir2string(value)}"}
return debugInfo(value) {
currentCodeContext.genGetValue(value.descriptor)
}
@@ -1149,7 +1149,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
private fun evaluateSetVariable(value: IrSetVariable): LLVMValueRef {
context.log("evaluateSetVariable : ${ir2string(value)}")
context.log{"evaluateSetVariable : ${ir2string(value)}"}
val result = evaluateExpression(value.value)
val variable = currentCodeContext.getDeclaredVariable(value.descriptor)
debugInfo(value) {
@@ -1163,7 +1163,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
private fun generateVariable(value: IrVariable) {
context.log("generateVariable : ${ir2string(value)}")
context.log{"generateVariable : ${ir2string(value)}"}
val result = value.initializer?.let { evaluateExpression(it) }
val variableDescriptor = value.descriptor
val index = currentCodeContext.genDeclareVariable(variableDescriptor, result)
@@ -1214,7 +1214,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
}
private fun evaluateIntegerCoercion(value: IrTypeOperatorCall): LLVMValueRef {
context.log("evaluateIntegerCoercion : ${ir2string(value)}")
context.log{"evaluateIntegerCoercion : ${ir2string(value)}"}
val type = value.typeOperand
assert(type.isPrimitiveInteger())
val result = evaluateExpression(value.argument)
@@ -1245,7 +1245,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
// double | fptosi fptosi fptosi fptosi fptrunc x
private fun evaluateCast(value: IrTypeOperatorCall): LLVMValueRef {
context.log("evaluateCast : ${ir2string(value)}")
context.log{"evaluateCast : ${ir2string(value)}"}
val type = value.typeOperand
assert(!KotlinBuiltIns.isPrimitiveType(type) && !KotlinBuiltIns.isPrimitiveType(value.argument.type))
assert(!type.isTypeParameter())
@@ -1261,7 +1261,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
private fun evaluateInstanceOf(value: IrTypeOperatorCall): LLVMValueRef {
context.log("evaluateInstanceOf : ${ir2string(value)}")
context.log{"evaluateInstanceOf : ${ir2string(value)}"}
val type = value.typeOperand
val srcArg = evaluateExpression(value.argument) // Evaluate src expression.
@@ -1313,7 +1313,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
private fun evaluateGetField(value: IrGetField): LLVMValueRef {
context.log("evaluateGetField : ${ir2string(value)}")
context.log{"evaluateGetField : ${ir2string(value)}"}
if (value.descriptor.dispatchReceiverParameter != null) {
val thisPtr = evaluateExpression(value.receiver!!)
return debugInfo(value) {
@@ -1346,7 +1346,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
private fun evaluateSetField(value: IrSetField): LLVMValueRef {
context.log("evaluateSetField : ${ir2string(value)}")
context.log{"evaluateSetField : ${ir2string(value)}"}
val valueToAssign = evaluateExpression(value.value)
if (value.descriptor.dispatchReceiverParameter != null) {
@@ -1414,7 +1414,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
private fun evaluateConst(value: IrConst<*>): LLVMValueRef {
context.log("evaluateConst : ${ir2string(value)}")
context.log{"evaluateConst : ${ir2string(value)}"}
debugLocation(value)
when (value.kind) {
IrConstKind.Null -> return codegen.kNullObjHeaderPtr
@@ -1438,7 +1438,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
private fun evaluateReturn(expression: IrReturn): LLVMValueRef {
context.log("evaluateReturn : ${ir2string(expression)}")
context.log{"evaluateReturn : ${ir2string(expression)}"}
val value = expression.value
val evaluated = evaluateExpression(value)
@@ -1500,7 +1500,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
private fun evaluateInlineFunction(value: IrInlineFunctionBody): LLVMValueRef {
context.log("evaluateInlineFunction : ${value.statements.forEach { ir2string(it) }}")
context.log{"evaluateInlineFunction : ${value.statements.forEach { ir2string(it) }}"}
val inlinedFunctionScope = InlinedFunctionScope(value)
using(inlinedFunctionScope) {
@@ -1529,7 +1529,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
private fun evaluateContainerExpression(value: IrContainerExpression): LLVMValueRef {
context.log("evaluateContainerExpression : ${value.statements.forEach { ir2string(it) }}")
context.log{"evaluateContainerExpression : ${value.statements.forEach { ir2string(it) }}"}
val scope = if (value is IrContainerExpression && value.isTransparentScope) {
null
@@ -1604,7 +1604,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
//-------------------------------------------------------------------------//
private fun evaluateCall(value: IrMemberAccessExpression): LLVMValueRef {
context.log("evaluateCall : ${ir2string(value)}")
context.log{"evaluateCall : ${ir2string(value)}"}
val args = evaluateExplicitArgs(value)
@@ -1826,7 +1826,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
private fun evaluateSimpleFunctionCall(
descriptor: FunctionDescriptor, args: List<LLVMValueRef>,
resultLifetime: Lifetime, superClass: ClassDescriptor? = null): LLVMValueRef {
//context.log("evaluateSimpleFunctionCall : $tmpVariableName = ${ir2string(value)}")
//context.log{"evaluateSimpleFunctionCall : $tmpVariableName = ${ir2string(value)}"}
if (descriptor.isOverridable && superClass == null)
return callVirtual(descriptor, args, resultLifetime)
else
@@ -1839,7 +1839,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
}
private fun evaluateConstructorCall(callee: IrCall, args: List<LLVMValueRef>): LLVMValueRef {
context.log("evaluateConstructorCall : ${ir2string(callee)}")
context.log{"evaluateConstructorCall : ${ir2string(callee)}"}
memScoped {
val constructedClass = (callee.descriptor as ConstructorDescriptor).constructedClass
val thisValue = if (constructedClass.isArray) {
@@ -1926,7 +1926,7 @@ internal class CodeGeneratorVisitor(val context: Context) : IrElementVisitorVoid
private fun evaluateOperatorCall(callee: IrCall, args: List<LLVMValueRef>): LLVMValueRef {
context.log("evaluateCall : origin:${ir2string(callee)}")
context.log{"evaluateCall : origin:${ir2string(callee)}"}
val descriptor = callee.descriptor
val ib = context.irModule!!.irBuiltins
when (descriptor) {
@@ -81,7 +81,7 @@ class DefaultArgumentStubGenerator internal constructor(val context: Context): D
log("detected ${functionDescriptor.name.asString()} has got #${bodies.size} default expressions")
functionDescriptor.overriddenDescriptors.forEach { context.log("DEFAULT-REPLACER: $it") }
functionDescriptor.overriddenDescriptors.forEach { context.log{"DEFAULT-REPLACER: $it"} }
if (bodies.isNotEmpty()) {
val descriptor = functionDescriptor.generateDefaultsDescription(context)
log("$functionDescriptor -> $descriptor")
@@ -190,7 +190,7 @@ class DefaultArgumentStubGenerator internal constructor(val context: Context): D
}
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: ValueParameterDescriptor?): VariableDescriptor =
@@ -338,7 +338,7 @@ class DefaultParameterInjector internal constructor(val context: Context): BodyL
})
}
private fun log(msg: String) = context.log("DEFAULT-INJECTOR: $msg")
private fun log(msg: String) = context.log{"DEFAULT-INJECTOR: $msg"}
}
private val CallableMemberDescriptor.needsDefaultArgumentsLowering
@@ -410,7 +410,7 @@ private fun FunctionDescriptor.generateDefaultsDescription(context: Context): Fu
/* unsubstitutedReturnType = */ returnType,
/* modality = */ Modality.FINAL,
/* visibility = */ this.visibility)
context.log("adds to cache[$this] = $descriptor")
context.log{"adds to cache[$this] = $descriptor"}
descriptor
}
}
@@ -233,7 +233,7 @@ class VarargInjectionLowering internal constructor(val context: Context): Declar
private fun hasSpreadElement(expression: IrVararg?) = expression?.elements?.any { it is IrSpreadElement }?:false
private fun log(msg:String) {
context.log("VARARG-INJECTOR: $msg")
context.log{"VARARG-INJECTOR: $msg"}
}
data class ArrayHandle(val arrayDescriptor:ClassDescriptor,
@@ -140,7 +140,7 @@ internal class IrDescriptorDeserializer(val context: Context,
} else
type
context.log("### deserialized Kotlin Type index=$index, text=$text:\t$realType")
context.log{"### deserialized Kotlin Type index=$index, text=$text:\t$realType"}
return realType
}
fun deserializeLocalDeclaration(proto: KonanLinkData.Descriptor): DeclarationDescriptor {
@@ -196,7 +196,7 @@ internal class IrDescriptorDeserializer(val context: Context,
fun deserializeDescriptor(proto: KonanIr.KotlinDescriptor): DeclarationDescriptor {
context.log("### deserializeDescriptor ${proto.kind} ${proto.index}")
context.log{"### deserializeDescriptor ${proto.kind} ${proto.index}"}
val descriptor = if (proto.hasIrLocalDeclaration()) {
val realDescriptor = proto.irLocalDeclaration.descriptor
@@ -206,7 +206,7 @@ internal class IrDescriptorDeserializer(val context: Context,
descriptorIndex.put(proto.index, descriptor)
context.log("### descriptor ${proto.kind} ${proto.index} -> $descriptor")
context.log{"### descriptor ${proto.kind} ${proto.index} -> $descriptor"}
// Now there are several descriptors that automatically
// recreated in addition to this one. Register them
@@ -141,9 +141,9 @@ internal class IrDescriptorSerializer(
descriptorTable.indexByValue(descriptor.original)
}
context.log("index = $index")
context.log("originalIndex = $originalIndex")
context.log("")
context.log{"index = $index"}
context.log{"originalIndex = $originalIndex"}
context.log{""}
val proto = KonanIr.KotlinDescriptor.newBuilder()
.setName(descriptor.name.asString())
@@ -299,7 +299,7 @@ internal class KonanSerializationUtil(val context: Context) {
val proto = KonanLinkData.Descriptor.newBuilder()
context.log("### serializeLocalDeclaration: $descriptor")
context.log{"### serializeLocalDeclaration: $descriptor"}
when (descriptor) {
is FunctionDescriptor ->
@@ -61,17 +61,17 @@ internal class IrSerializer(val context: Context,
fun serializeInlineBody(): String {
val declaration = context.ir.originalModuleIndex.functions[rootFunction]!!
context.log("INLINE: ${ir2stringWhole(declaration)}")
context.log{"INLINE: ${ir2stringWhole(declaration)}"}
return encodeDeclaration(declaration)
}
fun serializeKotlinType(type: KotlinType): KonanIr.KotlinType {
context.log("### serializing KotlinType: " + type)
context.log{"### serializing KotlinType: " + type}
return irDescriptorSerializer.serializeKotlinType(type)
}
fun serializeDescriptor(descriptor: DeclarationDescriptor): KonanIr.KotlinDescriptor {
context.log("### serializeDescriptor $descriptor")
context.log{"### serializeDescriptor $descriptor"}
// Behind this call starts a large world of
// descriptor serialization for IR.
@@ -398,7 +398,7 @@ internal class IrSerializer(val context: Context,
}
fun serializeExpression(expression: IrExpression): KonanIr.IrExpression {
context.log("### serializing Expression: ${ir2string(expression)}")
context.log{"### serializing Expression: ${ir2string(expression)}"}
val coordinates = serializeCoordinates(expression.startOffset, expression.endOffset)
val proto = KonanIr.IrExpression.newBuilder()
@@ -445,7 +445,7 @@ internal class IrSerializer(val context: Context,
}
fun serializeStatement(statement: IrElement): KonanIr.IrStatement {
context.log("### serializing Statement: ${ir2string(statement)}")
context.log{"### serializing Statement: ${ir2string(statement)}"}
val coordinates = serializeCoordinates(statement.startOffset, statement.endOffset)
val proto = KonanIr.IrStatement.newBuilder()
@@ -512,7 +512,7 @@ internal class IrSerializer(val context: Context,
}
fun serializeDeclaration(declaration: IrDeclaration): KonanIr.IrDeclaration {
context.log("### serializing Declaration: ${ir2string(declaration)}")
context.log{"### serializing Declaration: ${ir2string(declaration)}"}
val descriptor = declaration.descriptor
var kotlinDescriptor = serializeDescriptor(descriptor)
@@ -528,7 +528,7 @@ internal class IrSerializer(val context: Context,
.build()
} else if (descriptor is ClassDescriptor) {
// TODO
context.log("Can't serialize local class declarations in inline functions yet")
context.log{"Can't serialize local class declarations in inline functions yet"}
}
val coordinates = serializeCoordinates(declaration.startOffset, declaration.endOffset)
@@ -598,7 +598,7 @@ internal class IrDeserializer(val context: Context,
typeMap.put(typeParameter,
deserializeKotlinType(pair.getType()))
}
context.log("### deserialized typeMap = $typeMap")
context.log{"### deserialized typeMap = $typeMap"}
return typeMap
}
@@ -649,7 +649,7 @@ internal class IrDeserializer(val context: Context,
}
}
context.log("Deserialized statement: ${ir2string(element)}")
context.log{"Deserialized statement: ${ir2string(element)}"}
return element
}
@@ -959,7 +959,7 @@ internal class IrDeserializer(val context: Context,
val operation = proto.getOperation()
val expression = deserializeOperation(operation, start, end, type)
context.log("Deserialized expression: ${ir2string(expression)}")
context.log{"Deserialized expression: ${ir2string(expression)}"}
return expression
}
@@ -1040,7 +1040,7 @@ internal class IrDeserializer(val context: Context,
TODO("Declaration deserialization not implemented")
}
}
context.log("Deserialized declaration: ${ir2string(declaration)}")
context.log{"Deserialized declaration: ${ir2string(declaration)}"}
return declaration
}
@@ -50,14 +50,14 @@ internal class DeserializerDriver(val context: Context) {
var deserializedIr: IrDeclaration? = null
PhaseManager(context).phase(KonanPhase.DESERIALIZER) {
context.log("### IR deserialization attempt:\t$descriptor")
context.log{"### IR deserialization attempt:\t$descriptor"}
try {
deserializedIr = IrDeserializer(context, descriptor).decodeDeclaration()
context.log("${deserializedIr!!.descriptor}")
context.log(ir2stringWhole(deserializedIr!!))
context.log("IR deserialization SUCCESS:\t$descriptor")
context.log{"${deserializedIr!!.descriptor}"}
context.log{ir2stringWhole(deserializedIr!!)}
context.log{"IR deserialization SUCCESS:\t$descriptor"}
} catch(e: Throwable) {
context.log("IR deserialization FAILURE:\t$descriptor")
context.log{"IR deserialization FAILURE:\t$descriptor"}
e.printStackTrace()
}
}
@@ -66,7 +66,7 @@ internal class DeserializerDriver(val context: Context) {
internal fun dumpAllInlineBodies() {
if (! context.phase!!.verbose) return
context.log("Now deserializing all inlines for debugging purpose.")
context.log{"Now deserializing all inlines for debugging purpose."}
context.moduleDescriptor.accept(
InlineBodiesPrinterVisitor(InlineBodyPrinter()), Unit)
}