JS IR: simplify DCE root calculation
This commit is contained in:
committed by
TeamCityServer
parent
b27a109a1e
commit
387b84b37c
@@ -50,18 +50,41 @@ private fun IrField.isConstant(): Boolean {
|
|||||||
return correspondingPropertySymbol?.owner?.isConst ?: false
|
return correspondingPropertySymbol?.owner?.isConst ?: false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun buildRoots(modules: Iterable<IrModuleFragment>, context: JsIrBackendContext): Iterable<IrDeclaration> {
|
private fun IrDeclaration.addRootsTo(to: MutableCollection<IrDeclaration>, context: JsIrBackendContext) {
|
||||||
val rootDeclarations =
|
when {
|
||||||
(modules.flatMap { it.files } + context.packageLevelJsModules + context.externalPackageFragment.values).flatMapTo(mutableListOf()) { file ->
|
this is IrProperty -> {
|
||||||
file.declarations.flatMap { if (it is IrProperty) listOfNotNull(it.backingField, it.getter, it.setter) else listOf(it) }
|
backingField?.addRootsTo(to, context)
|
||||||
.filter {
|
getter?.addRootsTo(to, context)
|
||||||
it is IrField && it.initializer != null && !it.isKotlinPackage()
|
setter?.addRootsTo(to, context)
|
||||||
|| it.isExported(context)
|
|
||||||
|| it.isEffectivelyExternal()
|
|
||||||
|| it is IrField && it.correspondingPropertySymbol?.owner?.isExported(context) == true
|
|
||||||
|| it is IrSimpleFunction && it.correspondingPropertySymbol?.owner?.isExported(context) == true
|
|
||||||
}.filter { !(it is IrField && it.isConstant() && !it.isExported(context)) }
|
|
||||||
}
|
}
|
||||||
|
isEffectivelyExternal() -> {
|
||||||
|
to += this
|
||||||
|
}
|
||||||
|
isExported(context) -> {
|
||||||
|
to += this
|
||||||
|
}
|
||||||
|
this is IrField -> {
|
||||||
|
// TODO: simplify
|
||||||
|
if ((initializer != null && !isKotlinPackage() || correspondingPropertySymbol?.owner?.isExported(context) == true) && !isConstant()) {
|
||||||
|
to += this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this is IrSimpleFunction -> {
|
||||||
|
if (correspondingPropertySymbol?.owner?.isExported(context) == true) {
|
||||||
|
to += this
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildRoots(modules: Iterable<IrModuleFragment>, context: JsIrBackendContext): Iterable<IrDeclaration> {
|
||||||
|
val rootDeclarations = mutableListOf<IrDeclaration>()
|
||||||
|
val allFiles = (modules.flatMap { it.files } + context.packageLevelJsModules + context.externalPackageFragment.values)
|
||||||
|
allFiles.forEach {
|
||||||
|
it.declarations.forEach {
|
||||||
|
it.addRootsTo(rootDeclarations, context)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
rootDeclarations += context.testRoots.values
|
rootDeclarations += context.testRoots.values
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user