diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/dce/utils.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/dce/utils.kt index bd930f2fb7b..4203c49a0ba 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/dce/utils.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/dce/utils.kt @@ -29,10 +29,12 @@ internal fun IrDeclaration.fqNameForDceDump(): String { return (fqn + signature + synthetic) } +private data class IrDeclarationDumpInfo(val fqName: String, val type: String, val size: Int) + fun dumpDeclarationIrSizesIfNeed(path: String?, allModules: List) { if (path == null) return - val declarations = linkedSetOf() + val declarations = linkedSetOf() allModules.forEach { it.acceptChildrenVoid(object : IrElementVisitorVoid { @@ -41,15 +43,21 @@ fun dumpDeclarationIrSizesIfNeed(path: String?, allModules: List { - declarations.add(declaration) - } + val type = when (declaration) { + is IrFunction -> "function" + is IrProperty -> "property" + is IrField -> "field" + is IrAnonymousInitializer -> "anonymous initializer" + else -> null + } + type?.let { + declarations.add( + IrDeclarationDumpInfo( + fqName = declaration.fqNameForDceDump().removeQuotes(), + type = it, + size = declaration.dumpKotlinLike().length + ) + ) } super.visitDeclaration(declaration) @@ -65,21 +73,17 @@ fun dumpDeclarationIrSizesIfNeed(path: String?, allModules: List k to v.maxBy { it.dumpKotlinLike().length } } - .joinToString(separator, prefix, postfix) { (fqn, element) -> - val size = element.dumpKotlinLike().length - val type = when (element) { - is IrFunction -> "function" - is IrProperty -> "property" - is IrField -> "field" - is IrAnonymousInitializer -> "anonymousInitializer" - is IrClass -> "class" - else -> "unknown" + // TODO: introduce a way to assign unique names to each declaration and use it for both reachability and size infos + .groupBy { it.fqName } + .flatMap { (_, v) -> + v.mapIndexed { index: Int, declaration: IrDeclarationDumpInfo -> + if (index == 0) declaration + else declaration.copy(fqName = "${declaration.fqName} ($index)") } - """$indent"${fqn.removeQuotes()}": { - |$indent$indent"size": $size, - |$indent$indent"type": "$type" + }.joinToString(separator, prefix, postfix) { declaration -> + """$indent"${declaration.fqName}": { + |$indent$indent"size": ${declaration.size}, + |$indent$indent"type": "${declaration.type}" |$indent} """.trimMargin() }