Remove extra copyOf calls during filtering in collectRealOverrides (#3916)

This commit is contained in:
LepilkinaElena
2020-11-19 09:53:25 +03:00
committed by GitHub
parent 7b5544ebd3
commit b0c74c841e
@@ -30,14 +30,17 @@ val IrFunction.target: IrFunction get() = when (this) {
else -> error(this) else -> error(this)
} }
fun IrSimpleFunction.collectRealOverrides(toSkip: (IrSimpleFunction) -> Boolean = { false }): Set<IrSimpleFunction> { fun IrSimpleFunction.collectRealOverrides(
toSkip: (IrSimpleFunction) -> Boolean = { false },
filter: (IrOverridableMember) -> Boolean = { false }
): Set<IrSimpleFunction> {
if (isReal && !toSkip(this)) return setOf(this) if (isReal && !toSkip(this)) return setOf(this)
return this.overriddenSymbols return this.overriddenSymbols
.map { it.owner } .map { it.owner }
.collectAndFilterRealOverrides { .collectAndFilterRealOverrides {
require(it is IrSimpleFunction) { "Expected IrSimpleFunction: ${it.render()}" } require(it is IrSimpleFunction) { "Expected IrSimpleFunction: ${it.render()}" }
toSkip(it) toSkip(it) || filter(it)
} }
.map { it as IrSimpleFunction } .map { it as IrSimpleFunction }
.toSet() .toSet()
@@ -85,13 +88,12 @@ fun Collection<IrOverridableMember>.collectAndFilterRealOverrides(toSkip: (IrOve
// TODO: use this implementation instead of any other // TODO: use this implementation instead of any other
fun IrSimpleFunction.resolveFakeOverride(allowAbstract: Boolean = false, toSkip: (IrSimpleFunction) -> Boolean = { false }): IrSimpleFunction? { fun IrSimpleFunction.resolveFakeOverride(allowAbstract: Boolean = false, toSkip: (IrSimpleFunction) -> Boolean = { false }): IrSimpleFunction? {
val reals = collectRealOverrides(toSkip)
return if (allowAbstract) { return if (allowAbstract) {
val reals = collectRealOverrides(toSkip)
if (reals.isEmpty()) error("No real overrides for ${this.render()}") if (reals.isEmpty()) error("No real overrides for ${this.render()}")
reals.first() reals.first()
} else { } else {
reals collectRealOverrides(toSkip, { it.modality == Modality.ABSTRACT })
.filter { it.modality != Modality.ABSTRACT }
.let { realOverrides -> .let { realOverrides ->
// Kotlin forbids conflicts between overrides, but they may trickle down from Java. // Kotlin forbids conflicts between overrides, but they may trickle down from Java.
realOverrides.singleOrNull { it.parent.safeAs<IrClass>()?.isInterface != true } realOverrides.singleOrNull { it.parent.safeAs<IrClass>()?.isInterface != true }