diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIrFileSerializer.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIrFileSerializer.kt index 7ceeaa72329..8e58c5b9e1f 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIrFileSerializer.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIrFileSerializer.kt @@ -29,5 +29,5 @@ class KonanIrFileSerializer( return node.annotations.hasAnnotation(fqn) } - override fun backendSpecificSerializeAllMembers(irClass: IrClass) = !KonanFakeOverrideClassFilter.constructFakeOverrides(irClass) + override fun backendSpecificSerializeAllMembers(irClass: IrClass) = !KonanFakeOverrideClassFilter.needToConstructFakeOverrides(irClass) } \ No newline at end of file diff --git a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIrlinker.kt b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIrlinker.kt index 1a720ef24a9..8ad31de04c1 100644 --- a/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIrlinker.kt +++ b/backend.native/compiler/ir/backend.native/src/org/jetbrains/kotlin/backend/konan/serialization/KonanIrlinker.kt @@ -18,7 +18,7 @@ package org.jetbrains.kotlin.backend.konan.serialization import org.jetbrains.kotlin.backend.common.LoggingContext import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideBuilder -import org.jetbrains.kotlin.backend.common.overrides.PlatformFakeOverrideClassFilter +import org.jetbrains.kotlin.backend.common.overrides.FakeOverrideClassFilter import org.jetbrains.kotlin.backend.common.serialization.* import org.jetbrains.kotlin.backend.common.serialization.encodings.BinarySymbolData import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureSerializer @@ -48,7 +48,7 @@ import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.descriptorUtil.module -object KonanFakeOverrideClassFilter : PlatformFakeOverrideClassFilter { +object KonanFakeOverrideClassFilter : FakeOverrideClassFilter { private fun IdSignature.isInteropSignature(): Boolean = with(this) { IdSignature.Flags.IS_NATIVE_INTEROP_LIBRARY.test() } @@ -60,7 +60,7 @@ object KonanFakeOverrideClassFilter : PlatformFakeOverrideClassFilter { .filter { it is IrPublicSymbolBase<*> } .any { it.signature.isInteropSignature() } - override fun constructFakeOverrides(clazz: IrClass): Boolean { + override fun needToConstructFakeOverrides(clazz: IrClass): Boolean { return !clazz.hasInteropSuperClass() } } @@ -91,9 +91,8 @@ internal class KonanIrLinker( override fun isBuiltInModule(moduleDescriptor: ModuleDescriptor): Boolean = moduleDescriptor.isNativeStdlib() - override val fakeOverrideBuilder = FakeOverrideBuilder(symbolTable, IdSignatureSerializer(KonanManglerIr), builtIns, KonanFakeOverrideClassFilter) - private val forwardDeclarationDeserializer = forwardModuleDescriptor?.let { KonanForwardDeclarationModuleDeserializer(it) } + override val fakeOverrideBuilder = FakeOverrideBuilder(this, symbolTable, IdSignatureSerializer(KonanManglerIr), builtIns, KonanFakeOverrideClassFilter) override fun createModuleDeserializer(moduleDescriptor: ModuleDescriptor, klib: IrLibrary?, strategy: DeserializationStrategy): IrModuleDeserializer { if (moduleDescriptor === forwardModuleDescriptor) { diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index 0f268e0e964..fa035b5ba89 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -4395,6 +4395,18 @@ standaloneTest("fake_override_0") { goldValue = "Moved\nMoved\nChild\nSuper\n" } +linkTest("private_fake_overrides_0") { + source = "link/private_fake_overrides/inherit_main.kt" + lib = "link/private_fake_overrides/inherit_lib.kt" + goldValue = "PASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\n" +} + +linkTest("private_fake_overrides_1") { + source = "link/private_fake_overrides/override_main.kt" + lib = "link/private_fake_overrides/override_lib.kt" + goldValue = "PASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\nPASS\n" +} + Task frameworkTest(String name, Closure configurator) { return KotlinNativeTestKt.createTest(project, name, FrameworkTest) { task -> configurator.delegate = task diff --git a/backend.native/tests/link/private_fake_overrides/inherit_lib.kt b/backend.native/tests/link/private_fake_overrides/inherit_lib.kt new file mode 100644 index 00000000000..79d005ea442 --- /dev/null +++ b/backend.native/tests/link/private_fake_overrides/inherit_lib.kt @@ -0,0 +1,53 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +// Private classes +private open class A { + public fun foo1() = println("PASS") + internal fun foo2() = println("PASS") + protected fun foo3() = println("PASS") +} + +private class B:A() { + fun foo4() = foo3() +} + +// Private interfaces +private interface C { + fun foo() = println("PASS") +} + +private class D: C + +fun runner() { + B().foo1() + B().foo2() + B().foo4() + + D().foo() + + // Objects + object : A(){ + fun foo4() = foo3() + }.apply { + foo1() + foo2() + foo4() + } + + // Function local classes + abstract class E { + public open fun foo1() = println("PASS") + internal open fun foo2() = println("PASS") + protected open fun foo3() = println("PASS") + } + class F : E() { + fun foo4() = foo3() + } + F().foo1() + F().foo2() + F().foo4() +} + diff --git a/backend.native/tests/link/private_fake_overrides/inherit_main.kt b/backend.native/tests/link/private_fake_overrides/inherit_main.kt new file mode 100644 index 00000000000..46b1d2d0bd2 --- /dev/null +++ b/backend.native/tests/link/private_fake_overrides/inherit_main.kt @@ -0,0 +1,9 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +fun main() { + runner() +} + diff --git a/backend.native/tests/link/private_fake_overrides/override_lib.kt b/backend.native/tests/link/private_fake_overrides/override_lib.kt new file mode 100644 index 00000000000..6af4bca65ab --- /dev/null +++ b/backend.native/tests/link/private_fake_overrides/override_lib.kt @@ -0,0 +1,97 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +// Private classes +private open class A { + public open fun foo1() = println("FAIL") + internal open fun foo2() = println("FAIL") + protected open fun foo3() = println("FAIL") + private fun foo4() = println("FAIL") +} + +private class B:A() { + override public fun foo1() = println("PASS") + override internal fun foo2() = println("PASS") + override protected fun foo3() = println("PASS") + private fun foo4() = println("PASS") + fun foo5() = foo3() + fun foo6() = foo4() +} + +private abstract class G { + public abstract fun foo1() + internal abstract fun foo2() + protected abstract fun foo3() + private fun foo4() = println("FAIL") +} + +private class H:A() { + override public fun foo1() = println("PASS") + override internal fun foo2() = println("PASS") + override protected fun foo3() = println("PASS") + private fun foo4() = println("PASS") + fun foo5() = foo3() + fun foo6() = foo4() +} + + +// Private interfaces +private interface C { + fun foo() = println("FAIL") +} + +private class D: C { + override fun foo() = println("PASS") +} + +fun runner() { + B().foo1() + B().foo2() + B().foo5() + B().foo6() + + H().foo1() + H().foo2() + H().foo5() + H().foo6() + + D().foo() + + // Objects + object : A(){ + override public fun foo1() = println("PASS") + override internal fun foo2() = println("PASS") + override protected fun foo3() = println("PASS") + private fun foo4() = println("PASS") + fun foo5() = foo3() + fun foo6() = foo4() + }.apply { + foo1() + foo2() + foo5() + foo6() + } + + // Function local classes + open class E { + public open fun foo1() = println("FAIL") + internal open fun foo2() = println("FAIL") + protected open fun foo3() = println("FAIL") + private fun foo4() = println("FAIL") + } + class F : E() { + public override fun foo1() = println("PASS") + internal override fun foo2() = println("PASS") + protected override fun foo3() = println("PASS") + private fun foo4() = println("PASS") + fun foo5() = foo3() + fun foo6() = foo4() + } + F().foo1() + F().foo2() + F().foo5() + F().foo6() +} + diff --git a/backend.native/tests/link/private_fake_overrides/override_main.kt b/backend.native/tests/link/private_fake_overrides/override_main.kt new file mode 100644 index 00000000000..281b809b23b --- /dev/null +++ b/backend.native/tests/link/private_fake_overrides/override_main.kt @@ -0,0 +1,8 @@ +/* + * Copyright 2010-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license + * that can be found in the LICENSE file. + */ + +fun main() { + runner() +}