[Wasm] Renovated Ir declarations dump by adding a type entry
This commit is contained in:
committed by
Space Team
parent
3b52b452a3
commit
bc0afc36a2
@@ -29,10 +29,12 @@ internal fun IrDeclaration.fqNameForDceDump(): String {
|
|||||||
return (fqn + signature + synthetic)
|
return (fqn + signature + synthetic)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private data class IrDeclarationDumpInfo(val fqName: String, val type: String, val size: Int)
|
||||||
|
|
||||||
fun dumpDeclarationIrSizesIfNeed(path: String?, allModules: List<IrModuleFragment>) {
|
fun dumpDeclarationIrSizesIfNeed(path: String?, allModules: List<IrModuleFragment>) {
|
||||||
if (path == null) return
|
if (path == null) return
|
||||||
|
|
||||||
val declarations = linkedSetOf<IrDeclaration>()
|
val declarations = linkedSetOf<IrDeclarationDumpInfo>()
|
||||||
|
|
||||||
allModules.forEach {
|
allModules.forEach {
|
||||||
it.acceptChildrenVoid(object : IrElementVisitorVoid {
|
it.acceptChildrenVoid(object : IrElementVisitorVoid {
|
||||||
@@ -41,15 +43,21 @@ fun dumpDeclarationIrSizesIfNeed(path: String?, allModules: List<IrModuleFragmen
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitDeclaration(declaration: IrDeclarationBase) {
|
override fun visitDeclaration(declaration: IrDeclarationBase) {
|
||||||
when (declaration) {
|
val type = when (declaration) {
|
||||||
is IrFunction,
|
is IrFunction -> "function"
|
||||||
is IrProperty,
|
is IrProperty -> "property"
|
||||||
is IrField,
|
is IrField -> "field"
|
||||||
is IrAnonymousInitializer,
|
is IrAnonymousInitializer -> "anonymous initializer"
|
||||||
is IrClass,
|
else -> null
|
||||||
-> {
|
}
|
||||||
declarations.add(declaration)
|
type?.let {
|
||||||
}
|
declarations.add(
|
||||||
|
IrDeclarationDumpInfo(
|
||||||
|
fqName = declaration.fqNameForDceDump().removeQuotes(),
|
||||||
|
type = it,
|
||||||
|
size = declaration.dumpKotlinLike().length
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
super.visitDeclaration(declaration)
|
super.visitDeclaration(declaration)
|
||||||
@@ -65,21 +73,17 @@ fun dumpDeclarationIrSizesIfNeed(path: String?, allModules: List<IrModuleFragmen
|
|||||||
}
|
}
|
||||||
|
|
||||||
val value = declarations
|
val value = declarations
|
||||||
.groupBy({ it.fqNameForDceDump() }, { it })
|
// TODO: introduce a way to assign unique names to each declaration and use it for both reachability and size infos
|
||||||
.map { (k, v) -> k to v.maxBy { it.dumpKotlinLike().length } }
|
.groupBy { it.fqName }
|
||||||
.joinToString(separator, prefix, postfix) { (fqn, element) ->
|
.flatMap { (_, v) ->
|
||||||
val size = element.dumpKotlinLike().length
|
v.mapIndexed { index: Int, declaration: IrDeclarationDumpInfo ->
|
||||||
val type = when (element) {
|
if (index == 0) declaration
|
||||||
is IrFunction -> "function"
|
else declaration.copy(fqName = "${declaration.fqName} ($index)")
|
||||||
is IrProperty -> "property"
|
|
||||||
is IrField -> "field"
|
|
||||||
is IrAnonymousInitializer -> "anonymousInitializer"
|
|
||||||
is IrClass -> "class"
|
|
||||||
else -> "unknown"
|
|
||||||
}
|
}
|
||||||
"""$indent"${fqn.removeQuotes()}": {
|
}.joinToString(separator, prefix, postfix) { declaration ->
|
||||||
|$indent$indent"size": $size,
|
"""$indent"${declaration.fqName}": {
|
||||||
|$indent$indent"type": "$type"
|
|$indent$indent"size": ${declaration.size},
|
||||||
|
|$indent$indent"type": "${declaration.type}"
|
||||||
|$indent}
|
|$indent}
|
||||||
""".trimMargin()
|
""".trimMargin()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user