From 5cc242e87835537cc231d86b13c0c16ec8e4aedc Mon Sep 17 00:00:00 2001 From: Denis Zharkov Date: Fri, 14 Dec 2018 13:11:14 +0300 Subject: [PATCH] Refactor FunctionHandle::isInterfaceDeclaration - Give it more clear name mayBeUsedAsSuperImplementation because defining if it can be used as super-implementation this is what it used for - The meaning is negated, so it's needed to negate its usages and impls - Also, reuse it in findSuperImplementationForStubDelegation --- .../kotlin/backend/common/bridges/bridges.kt | 4 ++-- .../kotlin/backend/common/bridges/impl.kt | 4 ++-- .../kotlin/codegen/builtinSpecialBridges.kt | 8 +++---- .../backend/js/lower/BridgesConstruction.kt | 4 ++-- .../jetbrains/kotlin/codegen/BridgeTest.kt | 22 +++++++++---------- 5 files changed, 21 insertions(+), 21 deletions(-) diff --git a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/bridges/bridges.kt b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/bridges/bridges.kt index b35cb24f502..49123d24cd6 100644 --- a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/bridges/bridges.kt +++ b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/bridges/bridges.kt @@ -27,7 +27,7 @@ interface FunctionHandle { * class ones (see [findConcreteSuperDeclaration] method in bridges.kt). * Note that interface methods with body compiled to jvm 8 target are assumed to be non-abstract in bridges method calculation * (more details in [DescriptorBasedFunctionHandle.isBodyOwner] comment).*/ - val isInterfaceDeclaration: Boolean + val mayBeUsedAsSuperImplementation: Boolean fun getOverridden(): Iterable } @@ -114,7 +114,7 @@ fun findConcreteSuperDeclaration(function: Function) } result.removeAll(toRemove) - val concreteRelevantDeclarations = result.filter { !it.isAbstract && !it.isInterfaceDeclaration } + val concreteRelevantDeclarations = result.filter { !it.isAbstract && it.mayBeUsedAsSuperImplementation } if (concreteRelevantDeclarations.size != 1) { error("Concrete fake override $function should have exactly one concrete super-declaration: $concreteRelevantDeclarations") } diff --git a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/bridges/impl.kt b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/bridges/impl.kt index bbe3f5e03ca..a137103715a 100644 --- a/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/bridges/impl.kt +++ b/compiler/backend-common/src/org/jetbrains/kotlin/backend/common/bridges/impl.kt @@ -72,8 +72,8 @@ class DescriptorBasedFunctionHandle( override val isAbstract: Boolean = descriptor.modality == Modality.ABSTRACT || !areDeclarationAndDefinitionSame(descriptor) - override val isInterfaceDeclaration: Boolean - get() = DescriptorUtils.isInterface(descriptor.containingDeclaration) + override val mayBeUsedAsSuperImplementation: Boolean = + !DescriptorUtils.isInterface(descriptor.containingDeclaration) override fun getOverridden() = overridden diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/builtinSpecialBridges.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/builtinSpecialBridges.kt index c9d6e342418..ae917c35cd7 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/builtinSpecialBridges.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/builtinSpecialBridges.kt @@ -153,19 +153,19 @@ private fun findSuperImplementationForStubDelegation( areDeclarationAndDefinitionSame: (CallableMemberDescriptor) -> Boolean, signatureByDescriptor: (FunctionDescriptor) -> Signature ): FunctionDescriptor? { - val implementation = findConcreteSuperDeclaration(DescriptorBasedFunctionHandle(function, areDeclarationAndDefinitionSame)).descriptor + val implementation = findConcreteSuperDeclaration(DescriptorBasedFunctionHandle(function, areDeclarationAndDefinitionSame)) // Implementation from interface will be generated by common mechanism - if (DescriptorUtils.isInterface(implementation.containingDeclaration)) return null + if (!implementation.mayBeUsedAsSuperImplementation) return null // Implementation in super-class already has proper signature - if (signatureByDescriptor(function) == signatureByDescriptor(implementation)) return null + if (signatureByDescriptor(function) == signatureByDescriptor(implementation.descriptor)) return null assert(function.modality == Modality.OPEN) { "Should generate stubs only for non-abstract built-ins, but ${function.name} is ${function.modality}" } - return implementation + return implementation.descriptor } private fun findAllReachableDeclarations( diff --git a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BridgesConstruction.kt b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BridgesConstruction.kt index 57a76106e61..02ec22fbb43 100644 --- a/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BridgesConstruction.kt +++ b/compiler/ir/backend.js/src/org/jetbrains/kotlin/ir/backend/js/lower/BridgesConstruction.kt @@ -171,8 +171,8 @@ data class IrBasedFunctionHandle(val function: IrSimpleFunction) : FunctionHandl override val isAbstract: Boolean = function.modality == Modality.ABSTRACT - override val isInterfaceDeclaration = - function.parentAsClass.isInterface + override val mayBeUsedAsSuperImplementation = + !function.parentAsClass.isInterface override fun getOverridden() = function.overriddenSymbols.map { IrBasedFunctionHandle(it.owner) } diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BridgeTest.kt b/compiler/tests/org/jetbrains/kotlin/codegen/BridgeTest.kt index ed07b7cf06c..3be51f26292 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BridgeTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BridgeTest.kt @@ -28,7 +28,7 @@ class BridgeTest : TestCase() { private class Fun(val text: String) : FunctionHandle { override val isDeclaration: Boolean get() = text[1] == 'D' override val isAbstract: Boolean get() = text[0] == '-' - override val isInterfaceDeclaration: Boolean get() = false + override val mayBeUsedAsSuperImplementation: Boolean get() = true val signature: Char get() = text[2] val overriddenFunctions: MutableList = arrayListOf() @@ -150,7 +150,7 @@ class BridgeTest : TestCase() { graph() doTest(a, setOf()) } - + fun testSimpleFakeOverrideSameSignature() { val a = v("+D1") val b = v("+F1") @@ -190,7 +190,7 @@ class BridgeTest : TestCase() { doTest(a, setOf()) doTest(b, setOf()) } - + // Simple tests where declaration "a" is inherited by declaration "b" with a different signature. // Note that we don't generate bridges near abstract declarations in contrast to javac @@ -200,7 +200,7 @@ class BridgeTest : TestCase() { graph(b to a) doTest(b, setOf(bridge(a, b))) } - + fun testSimpleAbstractDeclarationDifferentSignature() { val a = v("-D1") val b = v("-D2") @@ -221,7 +221,7 @@ class BridgeTest : TestCase() { graph(b to a) doTest(b, setOf(bridge(a, b))) } - + // Simple tests where declaration overrides declaration through a fake override in the super class, with a different signature fun testSimpleConcreteDeclarationOverridesConcreteThroughFakeOverride() { @@ -263,7 +263,7 @@ class BridgeTest : TestCase() { doTest(b, setOf()) doTest(c, setOf()) } - + // Declaration "c" overrides two declarations "a" and "b" fun testAbstractDeclarationOverridesTwoAbstractDeclarations() { @@ -320,7 +320,7 @@ class BridgeTest : TestCase() { doTest(b, setOf()) doTest(c, setOf(bridge(a, c), bridge(b, c))) } - + // Diamonds where the sink (vertex "d") is a declaration: bridges from all super-declarations to "d" should be present fun testDiamondAbstractDeclarations() { @@ -334,7 +334,7 @@ class BridgeTest : TestCase() { doTest(c, setOf()) doTest(d, setOf()) } - + fun testDiamondMixedDeclarations() { val a = v("-D1") val b = v("+D2") @@ -346,7 +346,7 @@ class BridgeTest : TestCase() { doTest(c, setOf()) doTest(d, setOf(bridge(a, d), bridge(b, d), bridge(c, d))) } - + fun testDiamondAbstractFakeOverridesInTheMiddle() { val a = v("-D1") val b = v("-F2") @@ -360,7 +360,7 @@ class BridgeTest : TestCase() { } // Fake override "c" overrides declarations "a" and "b": a bridge is needed if signatures are different and there's an implementation - + fun testAbstractFakeOverride() { val a = v("-D1") val b = v("-D2") @@ -384,7 +384,7 @@ class BridgeTest : TestCase() { graph(c to a, c to b) doTest(c, setOf(bridge(a, b))) } - + fun testFakeOverrideInheritingDeclarations() { val a = v("-D1") val b = v("+D2")