From ee5edf4caa212a3c22700fca3cc2edaab6f7df34 Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Thu, 15 Oct 2020 16:43:48 +0300 Subject: [PATCH] JVM_IR fix 'remove' in inline class implementing MutableCollection --- .../ir/FirBlackBoxCodegenTestGenerated.java | 10 ++ .../jvm/codegen/MethodSignatureMapper.kt | 20 +++- .../kotlin/backend/jvm/ir/IrUtils.kt | 4 + .../backend/jvm/lower/BridgeLowering.kt | 35 +++++-- .../jvm/lower/CollectionStubMethodLowering.kt | 5 +- .../MemoizedInlineClassReplacements.kt | 4 + .../javaCollectionWithRemovePrimitiveInt.kt | 99 +++++++++++++++++++ ...oveInInlineCollectionOfInlineClassAsInt.kt | 48 +++++++++ .../noStubsForMapImplementations.kt | 5 - .../noStubsForMapImplementations_ir.txt | 46 +++++++++ .../inlineCollectionOfInlineClass/map_ir.txt | 1 + .../mutableCollection.kt | 2 - .../mutableCollection_ir.txt | 60 +++++++++++ .../mutableList_ir.txt | 2 +- .../mutableMap_ir.txt | 1 + .../mutableSet.kt | 2 - .../mutableSet2.kt | 19 ++++ .../mutableSet2.txt | 77 +++++++++++++++ .../mutableSet2_ir.txt | 77 +++++++++++++++ .../mutableSet_ir.txt | 60 +++++++++++ .../mutableCollectionOfPrimitive.kt | 27 +++++ .../mutableCollectionOfPrimitive.txt | 47 +++++++++ .../mutableCollectionOfPrimitive_ir.txt | 47 +++++++++ .../codegen/BlackBoxCodegenTestGenerated.java | 10 ++ .../codegen/BytecodeListingTestGenerated.java | 10 ++ .../LightAnalysisModeTestGenerated.java | 10 ++ .../ir/IrBlackBoxCodegenTestGenerated.java | 10 ++ .../ir/IrBytecodeListingTestGenerated.java | 10 ++ .../IrJsCodegenBoxES6TestGenerated.java | 5 + .../IrJsCodegenBoxTestGenerated.java | 5 + .../semantics/JsCodegenBoxTestGenerated.java | 5 + 31 files changed, 738 insertions(+), 25 deletions(-) create mode 100644 compiler/testData/codegen/box/collections/javaCollectionWithRemovePrimitiveInt.kt create mode 100644 compiler/testData/codegen/box/inlineClasses/removeInInlineCollectionOfInlineClassAsInt.kt create mode 100644 compiler/testData/codegen/bytecodeListing/collectionStubs/noStubsForMapImplementations_ir.txt create mode 100644 compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableCollection_ir.txt create mode 100644 compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet2.kt create mode 100644 compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet2.txt create mode 100644 compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet2_ir.txt create mode 100644 compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet_ir.txt create mode 100644 compiler/testData/codegen/bytecodeListing/specialBridges/mutableCollectionOfPrimitive.kt create mode 100644 compiler/testData/codegen/bytecodeListing/specialBridges/mutableCollectionOfPrimitive.txt create mode 100644 compiler/testData/codegen/bytecodeListing/specialBridges/mutableCollectionOfPrimitive_ir.txt diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index a2353f97afa..f311e6b71a2 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -5033,6 +5033,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/collections/irrelevantSizeOverrideInJava.kt"); } + @TestMetadata("javaCollectionWithRemovePrimitiveInt.kt") + public void testJavaCollectionWithRemovePrimitiveInt() throws Exception { + runTest("compiler/testData/codegen/box/collections/javaCollectionWithRemovePrimitiveInt.kt"); + } + @TestMetadata("kt41123.kt") public void testKt41123() throws Exception { runTest("compiler/testData/codegen/box/collections/kt41123.kt"); @@ -14042,6 +14047,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/inlineClasses/referToUnderlyingPropertyOfInlineClass.kt"); } + @TestMetadata("removeInInlineCollectionOfInlineClassAsInt.kt") + public void testRemoveInInlineCollectionOfInlineClassAsInt() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/removeInInlineCollectionOfInlineClassAsInt.kt"); + } + @TestMetadata("resultInlining.kt") public void testResultInlining() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/resultInlining.kt"); diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt index c2c11d12ccc..94edc2b5a5e 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/codegen/MethodSignatureMapper.kt @@ -11,10 +11,8 @@ import org.jetbrains.kotlin.backend.common.ir.isTopLevel import org.jetbrains.kotlin.backend.common.lower.parentsWithSelf import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin -import org.jetbrains.kotlin.backend.jvm.ir.getJvmNameFromAnnotation -import org.jetbrains.kotlin.backend.jvm.ir.isCompiledToJvmDefault -import org.jetbrains.kotlin.backend.jvm.ir.isStaticInlineClassReplacement -import org.jetbrains.kotlin.backend.jvm.ir.propertyIfAccessor +import org.jetbrains.kotlin.backend.jvm.ir.* +import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.unboxInlineClass import org.jetbrains.kotlin.backend.jvm.lower.suspendFunctionOriginal import org.jetbrains.kotlin.builtins.StandardNames import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap @@ -246,7 +244,7 @@ class MethodSignatureMapper(private val context: JvmBackendContext) { else -> JvmMethodParameterKind.VALUE } val type = - if (function.name.asString() == "remove" && forceSingleValueParameterBoxing(function.toIrBasedDescriptor())) + if (shouldBoxSingleValueParameterForSpecialCaseOfRemove(function)) parameter.type.makeNullable() else parameter.type writeParameter(sw, kind, type, function) @@ -274,6 +272,18 @@ class MethodSignatureMapper(private val context: JvmBackendContext) { return signature } + // Boxing is only necessary for 'remove(E): Boolean' of a MutableCollection implementation. + // Otherwise this method might clash with 'remove(I): E' defined in the java.util.List JDK interface (mapped to kotlin 'removeAt'). + internal fun shouldBoxSingleValueParameterForSpecialCaseOfRemove(irFunction: IrFunction): Boolean { + if (irFunction !is IrSimpleFunction) return false + if (irFunction.name.asString() != "remove" && !irFunction.name.asString().startsWith("remove-")) return false + if (irFunction.isFromJava()) return false + if (irFunction.valueParameters.size != 1) return false + val valueParameterType = irFunction.valueParameters[0].type + if (!valueParameterType.unboxInlineClass().isInt()) return false + return irFunction.allOverridden(false).any { it.parent.kotlinFqName == StandardNames.FqNames.mutableCollection } + } + private fun writeParameter(sw: JvmSignatureWriter, kind: JvmMethodParameterKind, type: IrType, function: IrFunction) { sw.writeParameterType(kind) writeParameterType(sw, type, function) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt index 726b131e5d2..e8c8a4cef50 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/ir/IrUtils.kt @@ -344,3 +344,7 @@ fun IrProperty.needsAccessor(accessor: IrSimpleFunction): Boolean = when { val IrDeclaration.isStaticInlineClassReplacement: Boolean get() = origin == JvmLoweredDeclarationOrigin.STATIC_INLINE_CLASS_REPLACEMENT || origin == JvmLoweredDeclarationOrigin.STATIC_INLINE_CLASS_CONSTRUCTOR + +fun IrDeclaration.isFromJava(): Boolean = + origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB || + parent is IrDeclaration && (parent as IrDeclaration).isFromJava() \ No newline at end of file diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt index 5f458a4a012..bbddfb696d4 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/BridgeLowering.kt @@ -17,6 +17,7 @@ import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin import org.jetbrains.kotlin.backend.jvm.codegen.isJvmInterface import org.jetbrains.kotlin.backend.jvm.ir.copyCorrespondingPropertyFrom import org.jetbrains.kotlin.backend.jvm.ir.eraseTypeParameters +import org.jetbrains.kotlin.backend.jvm.ir.isFromJava import org.jetbrains.kotlin.backend.jvm.ir.isJvmAbstract import org.jetbrains.kotlin.backend.jvm.lower.inlineclasses.unboxInlineClass import org.jetbrains.kotlin.codegen.AsmUtil @@ -118,7 +119,8 @@ import org.jetbrains.org.objectweb.asm.commons.Method internal val bridgePhase = makeIrFilePhase( ::BridgeLowering, name = "Bridge", - description = "Generate bridges" + description = "Generate bridges", + prerequisite = setOf(jvmInlineClassPhase) ) internal class BridgeLowering(val context: JvmBackendContext) : FileLoweringPass, IrElementTransformerVoid() { @@ -196,6 +198,24 @@ internal class BridgeLowering(val context: JvmBackendContext) : FileLoweringPass return !irFunction.isFakeOverride || irFunction.resolvesToClass() }) + if (declaration.isInline) { + // Inline class (implementing 'MutableCollection', where T is Int or an inline class mapped to Int) + // can contain a static replacement for a function 'remove', which forces value parameter boxing + // in order to avoid signature clash with 'remove(int)' method in 'java.util.List'. + // We should rewrite this static replacement as well ('remove' function itself is handled during special bridge processing). + for (irFunction in declaration.functions) { + val originalFunction = context.inlineClassReplacements.originalFunctionForStaticReplacement[irFunction] + ?: continue + if (context.methodSignatureMapper.shouldBoxSingleValueParameterForSpecialCaseOfRemove(originalFunction)) { + val oldValueParameter1 = irFunction.valueParameters[1] + val newValueParameter1 = oldValueParameter1.copyTo(irFunction, type = oldValueParameter1.type.makeNullable()) + irFunction.valueParameters = listOf(irFunction.valueParameters[0], newValueParameter1) + irFunction.body?.transform(VariableRemapper(mapOf(oldValueParameter1 to newValueParameter1)), null) + break + } + } + } + return super.visitClass(declaration) } @@ -351,7 +371,7 @@ internal class BridgeLowering(val context: JvmBackendContext) : FileLoweringPass // // This matches the behavior of the JVM backend, but it's probably a bad idea since this is an // opportunity for a Java and Kotlin implementation of the same interface to go out of sync. - if (it.parentAsClass.isInterface || it.comesFromJava()) + if (it.parentAsClass.isInterface || it.isFromJava()) null else it.specialBridgeOrNull?.signature?.takeIf { bridgeSignature -> bridgeSignature != it.jvmMethod } @@ -361,7 +381,7 @@ internal class BridgeLowering(val context: JvmBackendContext) : FileLoweringPass private fun IrSimpleFunction.overriddenSpecialBridges(): List { val targetJvmMethod = context.methodSignatureMapper.mapCalleeToAsmMethod(this) return allOverridden() - .filter { it.parentAsClass.isInterface || it.comesFromJava() } + .filter { it.parentAsClass.isInterface || it.isFromJava() } .mapNotNull { it.specialBridgeOrNull } .filter { it.signature != targetJvmMethod } .map { it.copy(isFinal = false, isSynthetic = true, methodInfo = null) } @@ -568,8 +588,11 @@ internal class BridgeLowering(val context: JvmBackendContext) : FileLoweringPass if (correspondingProperty != null) { if (correspondingProperty.owner.name !in specialBridgeMethods.specialPropertyNames) return null } else { - // 'removeAt' function can be mangled by inline class rules - if (function.name !in specialBridgeMethods.specialMethodNames && !function.name.asString().startsWith("removeAt-")) { + // 'remove' and 'removeAt' functions can be mangled by inline class rules + if (function.name !in specialBridgeMethods.specialMethodNames && + !function.name.asString().startsWith("removeAt-") && + !function.name.asString().startsWith("remove-") + ) { return null } } @@ -622,8 +645,6 @@ internal class BridgeLowering(val context: JvmBackendContext) : FileLoweringPass } } -private fun IrDeclaration.comesFromJava() = parentAsClass.origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB - // Check whether a fake override will resolve to an implementation in class, not an interface. private fun IrSimpleFunction.resolvesToClass(): Boolean { val overriddenFromClass = overriddenFromClass() ?: return false diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CollectionStubMethodLowering.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CollectionStubMethodLowering.kt index 9dc3c0d6c6f..0e95b83175f 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CollectionStubMethodLowering.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CollectionStubMethodLowering.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.backend.common.lower.createIrBuilder import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase import org.jetbrains.kotlin.backend.jvm.JvmBackendContext import org.jetbrains.kotlin.backend.jvm.codegen.isJvmInterface +import org.jetbrains.kotlin.backend.jvm.ir.isFromJava import org.jetbrains.kotlin.descriptors.Modality import org.jetbrains.kotlin.ir.builders.declarations.buildFun import org.jetbrains.kotlin.ir.builders.declarations.buildValueParameter @@ -420,12 +421,10 @@ internal class CollectionStubComputer(val context: JvmBackendContext) { fun stubsForCollectionClasses(irClass: IrClass): Collection = stubsCache.getOrPut(irClass) { - if (irClass.comesFromJava()) emptySet() + if (irClass.isFromJava()) emptySet() else preComputedStubs.filter { (readOnlyClass, mutableClass) -> !irClass.symbol.isSubtypeOfClass(mutableClass) && irClass.superTypes.any { it.isSubtypeOfClass(readOnlyClass) } } } - - private fun IrClass.comesFromJava() = origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB } \ No newline at end of file diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/MemoizedInlineClassReplacements.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/MemoizedInlineClassReplacements.kt index 6fa2d2a6103..469cf1e0994 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/MemoizedInlineClassReplacements.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/inlineclasses/MemoizedInlineClassReplacements.kt @@ -37,6 +37,8 @@ class MemoizedInlineClassReplacements(private val mangleReturnTypes: Boolean, pr private val storageManager = LockBasedStorageManager("inline-class-replacements") private val propertyMap = mutableMapOf() + internal val originalFunctionForStaticReplacement: MutableMap = HashMap() + /** * Get a replacement for a function or a constructor. */ @@ -166,6 +168,8 @@ class MemoizedInlineClassReplacements(private val mangleReturnTypes: Boolean, pr private fun createStaticReplacement(function: IrFunction): IrSimpleFunction = buildReplacement(function, JvmLoweredDeclarationOrigin.STATIC_INLINE_CLASS_REPLACEMENT, noFakeOverride = true) { + originalFunctionForStaticReplacement[this] = function + val newValueParameters = mutableListOf() if (function.dispatchReceiverParameter != null) { // FAKE_OVERRIDEs have broken dispatch receivers diff --git a/compiler/testData/codegen/box/collections/javaCollectionWithRemovePrimitiveInt.kt b/compiler/testData/codegen/box/collections/javaCollectionWithRemovePrimitiveInt.kt new file mode 100644 index 00000000000..7768bd068eb --- /dev/null +++ b/compiler/testData/codegen/box/collections/javaCollectionWithRemovePrimitiveInt.kt @@ -0,0 +1,99 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME +// FILE: javaCollectionWithRemovePrimitiveInt.kt + +fun box(): String { + val j = JIntCollection(arrayListOf(1, 2, 3)) + j.remove(1) // remove(int) + if (j.removed != 1) throw AssertionError("${j.removed}") + return "OK" +} + +// FILE: JIntCollection.java + +import org.jetbrains.annotations.NotNull; + +import java.util.Collection; +import java.util.Iterator; + +public class JIntCollection implements Collection { + private final Collection collection; + public int removed = 0; + + public JIntCollection(Collection collection) { + this.collection = collection; + } + + @Override + public int size() { + return collection.size(); + } + + @Override + public boolean isEmpty() { + return collection.isEmpty(); + } + + @Override + public boolean contains(Object o) { + return collection.contains(o); + } + + @NotNull + @Override + public Iterator iterator() { + return collection.iterator(); + } + + @NotNull + @Override + public Object[] toArray() { + return collection.toArray(); + } + + @NotNull + @Override + public T[] toArray(@NotNull T[] a) { + return collection.toArray(a); + } + + @Override + public boolean add(Integer integer) { + return collection.add(integer); + } + + @Override + public boolean remove(Object o) { + return collection.remove(o); + } + + public boolean remove(int x) { + removed = x; + return true; + } + + @Override + public boolean containsAll(@NotNull Collection c) { + return collection.containsAll(c); + } + + @Override + public boolean addAll(@NotNull Collection c) { + return collection.addAll(c); + } + + @Override + public boolean removeAll(@NotNull Collection c) { + return collection.removeAll(c); + } + + @Override + public boolean retainAll(@NotNull Collection c) { + return collection.retainAll(c); + } + + @Override + public void clear() { + collection.clear(); + } +} diff --git a/compiler/testData/codegen/box/inlineClasses/removeInInlineCollectionOfInlineClassAsInt.kt b/compiler/testData/codegen/box/inlineClasses/removeInInlineCollectionOfInlineClassAsInt.kt new file mode 100644 index 00000000000..1f60cdb2230 --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/removeInInlineCollectionOfInlineClassAsInt.kt @@ -0,0 +1,48 @@ +// WITH_RUNTIME +// KJS_WITH_FULL_RUNTIME + +inline class Z(val x: Int) + +inline class Z2(val x: Z) + +fun z2(x: Int) = Z2(Z(x)) + +inline class ZMutableCollection(private val ms: MutableCollection) : MutableCollection { + override fun add(element: Z): Boolean = ms.add(element) + override fun addAll(elements: Collection): Boolean = ms.addAll(elements) + override fun clear() { ms.clear() } + override fun iterator(): MutableIterator = ms.iterator() + override fun remove(element: Z): Boolean = ms.remove(element) + override fun removeAll(elements: Collection): Boolean = ms.removeAll(elements) + override fun retainAll(elements: Collection): Boolean = ms.retainAll(elements) + override val size: Int get() = ms.size + override fun contains(element: Z): Boolean = ms.contains(element) + override fun containsAll(elements: Collection): Boolean = ms.containsAll(elements) + override fun isEmpty(): Boolean = ms.isEmpty() +} + +inline class Z2MutableCollection(private val ms: MutableCollection) : MutableCollection { + override fun add(element: Z2): Boolean = ms.add(element) + override fun addAll(elements: Collection): Boolean = ms.addAll(elements) + override fun clear() { ms.clear() } + override fun iterator(): MutableIterator = ms.iterator() + override fun remove(element: Z2): Boolean = ms.remove(element) + override fun removeAll(elements: Collection): Boolean = ms.removeAll(elements) + override fun retainAll(elements: Collection): Boolean = ms.retainAll(elements) + override val size: Int get() = ms.size + override fun contains(element: Z2): Boolean = ms.contains(element) + override fun containsAll(elements: Collection): Boolean = ms.containsAll(elements) + override fun isEmpty(): Boolean = ms.isEmpty() +} + +fun box(): String { + val zc1 = ZMutableCollection(mutableListOf(Z(1), Z(2), Z(3))) + zc1.remove(Z(1)) + if (Z(1) in zc1) throw AssertionError("Z(1) in zc1") + + val zc2 = Z2MutableCollection(mutableListOf(z2(1), z2(2), z2(3))) + zc2.remove(z2(1)) + if (z2(1) in zc2) throw AssertionError("z2(1) in zc2") + + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/collectionStubs/noStubsForMapImplementations.kt b/compiler/testData/codegen/bytecodeListing/collectionStubs/noStubsForMapImplementations.kt index da2d6d8421a..4c1a8f832e0 100644 --- a/compiler/testData/codegen/bytecodeListing/collectionStubs/noStubsForMapImplementations.kt +++ b/compiler/testData/codegen/bytecodeListing/collectionStubs/noStubsForMapImplementations.kt @@ -1,11 +1,6 @@ // Ensure the proper collection stubs are added, in // particular *not* when specialized implementations are provided. -// IGNORE_BACKEND: JVM_IR -// TODO KT-42067 JVM_IR generates extra bridges: -// public bridge final method entrySet(): MyMap$MySet -// public bridge final method keySet(): MyMap$MySet -// public bridge final method values(): java.util.ArrayList class MyMap : Map { class MySet : Set { diff --git a/compiler/testData/codegen/bytecodeListing/collectionStubs/noStubsForMapImplementations_ir.txt b/compiler/testData/codegen/bytecodeListing/collectionStubs/noStubsForMapImplementations_ir.txt new file mode 100644 index 00000000000..0dff01a9c3e --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/collectionStubs/noStubsForMapImplementations_ir.txt @@ -0,0 +1,46 @@ +@kotlin.Metadata +public final class MyMap$MySet { + // source: 'noStubsForMapImplementations.kt' + public method (): void + public method add(p0: java.lang.Object): boolean + public method addAll(p0: java.util.Collection): boolean + public method clear(): void + public method contains(p0: java.lang.Object): boolean + public method containsAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public method getSize(): int + public method isEmpty(): boolean + public @org.jetbrains.annotations.NotNull method iterator(): java.util.Iterator + public method remove(p0: java.lang.Object): boolean + public method removeAll(p0: java.util.Collection): boolean + public method retainAll(p0: java.util.Collection): boolean + public bridge final method size(): int + public method toArray(): java.lang.Object[] + public method toArray(p0: java.lang.Object[]): java.lang.Object[] + public final inner class MyMap$MySet +} + +@kotlin.Metadata +public final class MyMap { + // source: 'noStubsForMapImplementations.kt' + public method (): void + public method clear(): void + public method containsKey(p0: java.lang.Object): boolean + public method containsValue(p0: java.lang.Object): boolean + public bridge final method entrySet(): MyMap$MySet + public synthetic bridge method entrySet(): java.util.Set + public method get(p0: java.lang.Object): java.lang.Object + public @org.jetbrains.annotations.NotNull method getEntries(): MyMap$MySet + public @org.jetbrains.annotations.NotNull method getKeys(): MyMap$MySet + public method getSize(): int + public @org.jetbrains.annotations.NotNull method getValues(): java.util.ArrayList + public method isEmpty(): boolean + public bridge final method keySet(): MyMap$MySet + public synthetic bridge method keySet(): java.util.Set + public method put(p0: java.lang.Object, p1: java.lang.Object): java.lang.Object + public method putAll(p0: java.util.Map): void + public method remove(p0: java.lang.Object): java.lang.Object + public bridge final method size(): int + public bridge final method values(): java.util.ArrayList + public synthetic bridge method values(): java.util.Collection + public final inner class MyMap$MySet +} diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/map_ir.txt b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/map_ir.txt index 3f15ccd5455..cb491d7ac80 100644 --- a/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/map_ir.txt +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/map_ir.txt @@ -68,6 +68,7 @@ public final class InlineMap { public synthetic bridge method put(p0: java.lang.Object, p1: java.lang.Object): java.lang.Object public method put-pjrbk2k(p0: int, p1: double): IV public method putAll(p0: java.util.Map): void + public bridge final method remove(p0: java.lang.Object): IV public synthetic bridge method remove(p0: java.lang.Object): java.lang.Object public method remove-i7hxwoc(p0: java.lang.Object): IV public synthetic bridge method size(): int diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableCollection.kt b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableCollection.kt index 44ae93542dd..54935b7bc19 100644 --- a/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableCollection.kt +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableCollection.kt @@ -1,6 +1,4 @@ // IGNORE_ANNOTATIONS -// IGNORE_BACKEND: JVM_IR -// ^ TODO: special bridges <-> inline classes interaction inline class IT(val x: Int) diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableCollection_ir.txt b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableCollection_ir.txt new file mode 100644 index 00000000000..73a1c6a8a28 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableCollection_ir.txt @@ -0,0 +1,60 @@ +public final class IT { + // source: 'mutableCollection.kt' + private final field x: int + private synthetic method (p0: int): void + public synthetic final static method box-impl(p0: int): IT + public static method constructor-impl(p0: int): int + public method equals(p0: java.lang.Object): boolean + public static method equals-impl(p0: int, p1: java.lang.Object): boolean + public final static method equals-impl0(p0: int, p1: int): boolean + public final method getX(): int + public method hashCode(): int + public static method hashCode-impl(p0: int): int + public method toString(): java.lang.String + public static method toString-impl(p0: int): java.lang.String + public synthetic final method unbox-impl(): int +} + +public final class InlineMutableCollection { + // source: 'mutableCollection.kt' + private final field mc: java.util.Collection + private synthetic method (p0: java.util.Collection): void + public synthetic bridge method add(p0: java.lang.Object): boolean + public method add-jHY5zpA(p0: int): boolean + public static method add-jHY5zpA(p0: java.util.Collection, p1: int): boolean + public method addAll(p0: java.util.Collection): boolean + public static method addAll-impl(p0: java.util.Collection, p1: java.util.Collection): boolean + public synthetic final static method box-impl(p0: java.util.Collection): InlineMutableCollection + public method clear(): void + public static method clear-impl(p0: java.util.Collection): void + public static method constructor-impl(p0: java.util.Collection): java.util.Collection + public synthetic bridge method contains(p0: java.lang.Object): boolean + public method contains-jHY5zpA(p0: int): boolean + public static method contains-jHY5zpA(p0: java.util.Collection, p1: int): boolean + public method containsAll(p0: java.util.Collection): boolean + public static method containsAll-impl(p0: java.util.Collection, p1: java.util.Collection): boolean + public method equals(p0: java.lang.Object): boolean + public static method equals-impl(p0: java.util.Collection, p1: java.lang.Object): boolean + public final static method equals-impl0(p0: java.util.Collection, p1: java.util.Collection): boolean + public method getSize(): int + public static method getSize-impl(p0: java.util.Collection): int + public method hashCode(): int + public static method hashCode-impl(p0: java.util.Collection): int + public method isEmpty(): boolean + public static method isEmpty-impl(p0: java.util.Collection): boolean + public method iterator(): java.util.Iterator + public static method iterator-impl(p0: java.util.Collection): java.util.Iterator + public bridge final method remove(p0: java.lang.Object): boolean + public method remove-jHY5zpA(p0: IT): boolean + public static method remove-jHY5zpA(p0: java.util.Collection, p1: IT): boolean + public method removeAll(p0: java.util.Collection): boolean + public static method removeAll-impl(p0: java.util.Collection, p1: java.util.Collection): boolean + public method retainAll(p0: java.util.Collection): boolean + public static method retainAll-impl(p0: java.util.Collection, p1: java.util.Collection): boolean + public synthetic bridge method size(): int + public method toArray(): java.lang.Object[] + public method toArray(p0: java.lang.Object[]): java.lang.Object[] + public method toString(): java.lang.String + public static method toString-impl(p0: java.util.Collection): java.lang.String + public synthetic final method unbox-impl(): java.util.Collection +} diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableList_ir.txt b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableList_ir.txt index f81489c18ba..c17c4e5d9c0 100644 --- a/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableList_ir.txt +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableList_ir.txt @@ -64,7 +64,7 @@ public final class InlineMutableList { public static method listIterator-impl(p0: java.util.List, p1: int): java.util.ListIterator public synthetic bridge method remove(p0: int): java.lang.Object public bridge final method remove(p0: int): long - public synthetic bridge method remove(p0: java.lang.Object): boolean + public bridge final method remove(p0: java.lang.Object): boolean public static method remove-jHY5zpA(p0: java.util.List, p1: long): boolean public method remove-jHY5zpA(p0: long): boolean public method removeAll(p0: java.util.Collection): boolean diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableMap_ir.txt b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableMap_ir.txt index d3e56f34382..657df961e74 100644 --- a/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableMap_ir.txt +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableMap_ir.txt @@ -71,6 +71,7 @@ public final class InlineMutableMap { public static method put-pjrbk2k(p0: java.util.Map, p1: int, p2: double): IV public method putAll(p0: java.util.Map): void public static method putAll-impl(p0: java.util.Map, p1: java.util.Map): void + public bridge final method remove(p0: java.lang.Object): IV public synthetic bridge method remove(p0: java.lang.Object): java.lang.Object public method remove-FSIWiWE(p0: int): IV public static method remove-FSIWiWE(p0: java.util.Map, p1: int): IV diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet.kt b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet.kt index 41cd80ca3a2..af454fdbd24 100644 --- a/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet.kt +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet.kt @@ -1,6 +1,4 @@ // IGNORE_ANNOTATIONS -// IGNORE_BACKEND: JVM_IR -// ^ TODO: special bridges <-> inline classes interaction inline class IT(val x: Int) diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet2.kt b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet2.kt new file mode 100644 index 00000000000..ab69ff8f670 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet2.kt @@ -0,0 +1,19 @@ +// IGNORE_ANNOTATIONS + +inline class IT(val x: Int) + +inline class IT2(val x: IT) + +inline class InlineMutableSet2(private val ms: MutableSet) : MutableSet { + override val size: Int get() = ms.size + override fun contains(element: IT2): Boolean = ms.contains(element) + override fun containsAll(elements: Collection): Boolean = ms.containsAll(elements) + override fun isEmpty(): Boolean = ms.isEmpty() + override fun add(element: IT2): Boolean = ms.add(element) + override fun addAll(elements: Collection): Boolean = ms.addAll(elements) + override fun clear() { ms.clear() } + override fun iterator(): MutableIterator = ms.iterator() + override fun remove(element: IT2): Boolean = ms.remove(element) + override fun removeAll(elements: Collection): Boolean = ms.removeAll(elements) + override fun retainAll(elements: Collection): Boolean = ms.retainAll(elements) +} diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet2.txt b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet2.txt new file mode 100644 index 00000000000..098c3b21857 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet2.txt @@ -0,0 +1,77 @@ +public final class IT { + // source: 'mutableSet2.kt' + private final field x: int + private synthetic method (p0: int): void + public synthetic final static method box-impl(p0: int): IT + public static method constructor-impl(p0: int): int + public method equals(p0: java.lang.Object): boolean + public static method equals-impl(p0: int, p1: java.lang.Object): boolean + public final static method equals-impl0(p0: int, p1: int): boolean + public final method getX(): int + public method hashCode(): int + public static method hashCode-impl(p0: int): int + public method toString(): java.lang.String + public static method toString-impl(p0: int): java.lang.String + public synthetic final method unbox-impl(): int +} + +public final class IT2 { + // source: 'mutableSet2.kt' + private final field x: int + private synthetic method (p0: int): void + public synthetic final static method box-impl(p0: int): IT2 + public static method constructor-impl(p0: int): int + public method equals(p0: java.lang.Object): boolean + public static method equals-impl(p0: int, p1: java.lang.Object): boolean + public final static method equals-impl0(p0: int, p1: int): boolean + public final method getX-XAcLw3A(): int + public method hashCode(): int + public static method hashCode-impl(p0: int): int + public method toString(): java.lang.String + public static method toString-impl(p0: int): java.lang.String + public synthetic final method unbox-impl(): int +} + +public final class InlineMutableSet2 { + // source: 'mutableSet2.kt' + private final field ms: java.util.Set + private synthetic method (p0: java.util.Set): void + public synthetic bridge method add(p0: java.lang.Object): boolean + public method add-C2ZI6mw(p0: int): boolean + public static method add-C2ZI6mw(p0: java.util.Set, p1: int): boolean + public method addAll(p0: java.util.Collection): boolean + public static method addAll-impl(p0: java.util.Set, p1: java.util.Collection): boolean + public synthetic final static method box-impl(p0: java.util.Set): InlineMutableSet2 + public method clear(): void + public static method clear-impl(p0: java.util.Set): void + public static method constructor-impl(p0: java.util.Set): java.util.Set + public bridge final method contains(p0: java.lang.Object): boolean + public method contains-C2ZI6mw(p0: int): boolean + public static method contains-C2ZI6mw(p0: java.util.Set, p1: int): boolean + public method containsAll(p0: java.util.Collection): boolean + public static method containsAll-impl(p0: java.util.Set, p1: java.util.Collection): boolean + public method equals(p0: java.lang.Object): boolean + public static method equals-impl(p0: java.util.Set, p1: java.lang.Object): boolean + public final static method equals-impl0(p0: java.util.Set, p1: java.util.Set): boolean + public method getSize(): int + public static method getSize-impl(p0: java.util.Set): int + public method hashCode(): int + public static method hashCode-impl(p0: java.util.Set): int + public method isEmpty(): boolean + public static method isEmpty-impl(p0: java.util.Set): boolean + public method iterator(): java.util.Iterator + public static method iterator-impl(p0: java.util.Set): java.util.Iterator + public bridge final method remove(p0: java.lang.Object): boolean + public method remove-C2ZI6mw(p0: IT2): boolean + public static method remove-C2ZI6mw(p0: java.util.Set, p1: IT2): boolean + public method removeAll(p0: java.util.Collection): boolean + public static method removeAll-impl(p0: java.util.Set, p1: java.util.Collection): boolean + public method retainAll(p0: java.util.Collection): boolean + public static method retainAll-impl(p0: java.util.Set, p1: java.util.Collection): boolean + public bridge final method size(): int + public method toArray(): java.lang.Object[] + public method toArray(p0: java.lang.Object[]): java.lang.Object[] + public method toString(): java.lang.String + public static method toString-impl(p0: java.util.Set): java.lang.String + public synthetic final method unbox-impl(): java.util.Set +} diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet2_ir.txt b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet2_ir.txt new file mode 100644 index 00000000000..2b408cd103b --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet2_ir.txt @@ -0,0 +1,77 @@ +public final class IT { + // source: 'mutableSet2.kt' + private final field x: int + private synthetic method (p0: int): void + public synthetic final static method box-impl(p0: int): IT + public static method constructor-impl(p0: int): int + public method equals(p0: java.lang.Object): boolean + public static method equals-impl(p0: int, p1: java.lang.Object): boolean + public final static method equals-impl0(p0: int, p1: int): boolean + public final method getX(): int + public method hashCode(): int + public static method hashCode-impl(p0: int): int + public method toString(): java.lang.String + public static method toString-impl(p0: int): java.lang.String + public synthetic final method unbox-impl(): int +} + +public final class IT2 { + // source: 'mutableSet2.kt' + private final field x: int + private synthetic method (p0: int): void + public synthetic final static method box-impl(p0: int): IT2 + public static method constructor-impl(p0: int): int + public method equals(p0: java.lang.Object): boolean + public static method equals-impl(p0: int, p1: java.lang.Object): boolean + public final static method equals-impl0(p0: int, p1: int): boolean + public final method getX-XAcLw3A(): int + public method hashCode(): int + public static method hashCode-impl(p0: int): int + public method toString(): java.lang.String + public static method toString-impl(p0: int): java.lang.String + public synthetic final method unbox-impl(): int +} + +public final class InlineMutableSet2 { + // source: 'mutableSet2.kt' + private final field ms: java.util.Set + private synthetic method (p0: java.util.Set): void + public synthetic bridge method add(p0: java.lang.Object): boolean + public method add-C2ZI6mw(p0: int): boolean + public static method add-C2ZI6mw(p0: java.util.Set, p1: int): boolean + public method addAll(p0: java.util.Collection): boolean + public static method addAll-impl(p0: java.util.Set, p1: java.util.Collection): boolean + public synthetic final static method box-impl(p0: java.util.Set): InlineMutableSet2 + public method clear(): void + public static method clear-impl(p0: java.util.Set): void + public static method constructor-impl(p0: java.util.Set): java.util.Set + public synthetic bridge method contains(p0: java.lang.Object): boolean + public method contains-C2ZI6mw(p0: int): boolean + public static method contains-C2ZI6mw(p0: java.util.Set, p1: int): boolean + public method containsAll(p0: java.util.Collection): boolean + public static method containsAll-impl(p0: java.util.Set, p1: java.util.Collection): boolean + public method equals(p0: java.lang.Object): boolean + public static method equals-impl(p0: java.util.Set, p1: java.lang.Object): boolean + public final static method equals-impl0(p0: java.util.Set, p1: java.util.Set): boolean + public method getSize(): int + public static method getSize-impl(p0: java.util.Set): int + public method hashCode(): int + public static method hashCode-impl(p0: java.util.Set): int + public method isEmpty(): boolean + public static method isEmpty-impl(p0: java.util.Set): boolean + public method iterator(): java.util.Iterator + public static method iterator-impl(p0: java.util.Set): java.util.Iterator + public bridge final method remove(p0: java.lang.Object): boolean + public method remove-C2ZI6mw(p0: IT2): boolean + public static method remove-C2ZI6mw(p0: java.util.Set, p1: IT2): boolean + public method removeAll(p0: java.util.Collection): boolean + public static method removeAll-impl(p0: java.util.Set, p1: java.util.Collection): boolean + public method retainAll(p0: java.util.Collection): boolean + public static method retainAll-impl(p0: java.util.Set, p1: java.util.Collection): boolean + public synthetic bridge method size(): int + public method toArray(): java.lang.Object[] + public method toArray(p0: java.lang.Object[]): java.lang.Object[] + public method toString(): java.lang.String + public static method toString-impl(p0: java.util.Set): java.lang.String + public synthetic final method unbox-impl(): java.util.Set +} diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet_ir.txt b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet_ir.txt new file mode 100644 index 00000000000..0724572ec0e --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet_ir.txt @@ -0,0 +1,60 @@ +public final class IT { + // source: 'mutableSet.kt' + private final field x: int + private synthetic method (p0: int): void + public synthetic final static method box-impl(p0: int): IT + public static method constructor-impl(p0: int): int + public method equals(p0: java.lang.Object): boolean + public static method equals-impl(p0: int, p1: java.lang.Object): boolean + public final static method equals-impl0(p0: int, p1: int): boolean + public final method getX(): int + public method hashCode(): int + public static method hashCode-impl(p0: int): int + public method toString(): java.lang.String + public static method toString-impl(p0: int): java.lang.String + public synthetic final method unbox-impl(): int +} + +public final class InlineMutableSet { + // source: 'mutableSet.kt' + private final field ms: java.util.Set + private synthetic method (p0: java.util.Set): void + public synthetic bridge method add(p0: java.lang.Object): boolean + public method add-jHY5zpA(p0: int): boolean + public static method add-jHY5zpA(p0: java.util.Set, p1: int): boolean + public method addAll(p0: java.util.Collection): boolean + public static method addAll-impl(p0: java.util.Set, p1: java.util.Collection): boolean + public synthetic final static method box-impl(p0: java.util.Set): InlineMutableSet + public method clear(): void + public static method clear-impl(p0: java.util.Set): void + public static method constructor-impl(p0: java.util.Set): java.util.Set + public synthetic bridge method contains(p0: java.lang.Object): boolean + public method contains-jHY5zpA(p0: int): boolean + public static method contains-jHY5zpA(p0: java.util.Set, p1: int): boolean + public method containsAll(p0: java.util.Collection): boolean + public static method containsAll-impl(p0: java.util.Set, p1: java.util.Collection): boolean + public method equals(p0: java.lang.Object): boolean + public static method equals-impl(p0: java.util.Set, p1: java.lang.Object): boolean + public final static method equals-impl0(p0: java.util.Set, p1: java.util.Set): boolean + public method getSize(): int + public static method getSize-impl(p0: java.util.Set): int + public method hashCode(): int + public static method hashCode-impl(p0: java.util.Set): int + public method isEmpty(): boolean + public static method isEmpty-impl(p0: java.util.Set): boolean + public method iterator(): java.util.Iterator + public static method iterator-impl(p0: java.util.Set): java.util.Iterator + public bridge final method remove(p0: java.lang.Object): boolean + public method remove-jHY5zpA(p0: IT): boolean + public static method remove-jHY5zpA(p0: java.util.Set, p1: IT): boolean + public method removeAll(p0: java.util.Collection): boolean + public static method removeAll-impl(p0: java.util.Set, p1: java.util.Collection): boolean + public method retainAll(p0: java.util.Collection): boolean + public static method retainAll-impl(p0: java.util.Set, p1: java.util.Collection): boolean + public synthetic bridge method size(): int + public method toArray(): java.lang.Object[] + public method toArray(p0: java.lang.Object[]): java.lang.Object[] + public method toString(): java.lang.String + public static method toString-impl(p0: java.util.Set): java.lang.String + public synthetic final method unbox-impl(): java.util.Set +} diff --git a/compiler/testData/codegen/bytecodeListing/specialBridges/mutableCollectionOfPrimitive.kt b/compiler/testData/codegen/bytecodeListing/specialBridges/mutableCollectionOfPrimitive.kt new file mode 100644 index 00000000000..40ecd15fc0d --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/specialBridges/mutableCollectionOfPrimitive.kt @@ -0,0 +1,27 @@ +class IntMutableCollection(private val mc: MutableCollection) : MutableCollection { + override val size: Int get() = mc.size + override fun contains(element: Int): Boolean = mc.contains(element) + override fun containsAll(elements: Collection): Boolean = mc.containsAll(elements) + override fun isEmpty(): Boolean = mc.isEmpty() + override fun add(element: Int): Boolean = mc.add(element) + override fun addAll(elements: Collection): Boolean = mc.addAll(elements) + override fun clear() { mc.clear() } + override fun iterator(): MutableIterator = mc.iterator() + override fun remove(element: Int): Boolean = mc.remove(element) + override fun removeAll(elements: Collection): Boolean = mc.removeAll(elements) + override fun retainAll(elements: Collection): Boolean = mc.retainAll(elements) +} + +class LongMutableCollection(private val mc: MutableCollection) : MutableCollection { + override val size: Int get() = mc.size + override fun contains(element: Long): Boolean = mc.contains(element) + override fun containsAll(elements: Collection): Boolean = mc.containsAll(elements) + override fun isEmpty(): Boolean = mc.isEmpty() + override fun add(element: Long): Boolean = mc.add(element) + override fun addAll(elements: Collection): Boolean = mc.addAll(elements) + override fun clear() { mc.clear() } + override fun iterator(): MutableIterator = mc.iterator() + override fun remove(element: Long): Boolean = mc.remove(element) + override fun removeAll(elements: Collection): Boolean = mc.removeAll(elements) + override fun retainAll(elements: Collection): Boolean = mc.retainAll(elements) +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/specialBridges/mutableCollectionOfPrimitive.txt b/compiler/testData/codegen/bytecodeListing/specialBridges/mutableCollectionOfPrimitive.txt new file mode 100644 index 00000000000..550844cf249 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/specialBridges/mutableCollectionOfPrimitive.txt @@ -0,0 +1,47 @@ +@kotlin.Metadata +public final class IntMutableCollection { + // source: 'mutableCollectionOfPrimitive.kt' + private final field mc: java.util.Collection + public method (@org.jetbrains.annotations.NotNull p0: java.util.Collection): void + public method add(p0: int): boolean + public synthetic bridge method add(p0: java.lang.Object): boolean + public method addAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public method clear(): void + public method contains(p0: int): boolean + public bridge final method contains(p0: java.lang.Object): boolean + public method containsAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public method getSize(): int + public method isEmpty(): boolean + public @org.jetbrains.annotations.NotNull method iterator(): java.util.Iterator + public method remove(@org.jetbrains.annotations.NotNull p0: java.lang.Integer): boolean + public bridge final method remove(p0: java.lang.Object): boolean + public method removeAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public method retainAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public bridge final method size(): int + public method toArray(): java.lang.Object[] + public method toArray(p0: java.lang.Object[]): java.lang.Object[] +} + +@kotlin.Metadata +public final class LongMutableCollection { + // source: 'mutableCollectionOfPrimitive.kt' + private final field mc: java.util.Collection + public method (@org.jetbrains.annotations.NotNull p0: java.util.Collection): void + public synthetic bridge method add(p0: java.lang.Object): boolean + public method add(p0: long): boolean + public method addAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public method clear(): void + public bridge final method contains(p0: java.lang.Object): boolean + public method contains(p0: long): boolean + public method containsAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public method getSize(): int + public method isEmpty(): boolean + public @org.jetbrains.annotations.NotNull method iterator(): java.util.Iterator + public bridge final method remove(p0: java.lang.Object): boolean + public method remove(p0: long): boolean + public method removeAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public method retainAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public bridge final method size(): int + public method toArray(): java.lang.Object[] + public method toArray(p0: java.lang.Object[]): java.lang.Object[] +} diff --git a/compiler/testData/codegen/bytecodeListing/specialBridges/mutableCollectionOfPrimitive_ir.txt b/compiler/testData/codegen/bytecodeListing/specialBridges/mutableCollectionOfPrimitive_ir.txt new file mode 100644 index 00000000000..5a1960203d4 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/specialBridges/mutableCollectionOfPrimitive_ir.txt @@ -0,0 +1,47 @@ +@kotlin.Metadata +public final class IntMutableCollection { + // source: 'mutableCollectionOfPrimitive.kt' + private final @org.jetbrains.annotations.NotNull field mc: java.util.Collection + public method (@org.jetbrains.annotations.NotNull p0: java.util.Collection): void + public method add(p0: int): boolean + public synthetic bridge method add(p0: java.lang.Object): boolean + public method addAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public method clear(): void + public method contains(p0: int): boolean + public bridge final method contains(p0: java.lang.Object): boolean + public method containsAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public method getSize(): int + public method isEmpty(): boolean + public @org.jetbrains.annotations.NotNull method iterator(): java.util.Iterator + public method remove(@org.jetbrains.annotations.Nullable p0: java.lang.Integer): boolean + public bridge final method remove(p0: java.lang.Object): boolean + public method removeAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public method retainAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public bridge final method size(): int + public method toArray(): java.lang.Object[] + public method toArray(p0: java.lang.Object[]): java.lang.Object[] +} + +@kotlin.Metadata +public final class LongMutableCollection { + // source: 'mutableCollectionOfPrimitive.kt' + private final @org.jetbrains.annotations.NotNull field mc: java.util.Collection + public method (@org.jetbrains.annotations.NotNull p0: java.util.Collection): void + public synthetic bridge method add(p0: java.lang.Object): boolean + public method add(p0: long): boolean + public method addAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public method clear(): void + public bridge final method contains(p0: java.lang.Object): boolean + public method contains(p0: long): boolean + public method containsAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public method getSize(): int + public method isEmpty(): boolean + public @org.jetbrains.annotations.NotNull method iterator(): java.util.Iterator + public bridge final method remove(p0: java.lang.Object): boolean + public method remove(p0: long): boolean + public method removeAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public method retainAll(@org.jetbrains.annotations.NotNull p0: java.util.Collection): boolean + public bridge final method size(): int + public method toArray(): java.lang.Object[] + public method toArray(p0: java.lang.Object[]): java.lang.Object[] +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 4d3a011370e..ebc6d7c2890 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -5063,6 +5063,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/collections/irrelevantSizeOverrideInJava.kt"); } + @TestMetadata("javaCollectionWithRemovePrimitiveInt.kt") + public void testJavaCollectionWithRemovePrimitiveInt() throws Exception { + runTest("compiler/testData/codegen/box/collections/javaCollectionWithRemovePrimitiveInt.kt"); + } + @TestMetadata("kt41123.kt") public void testKt41123() throws Exception { runTest("compiler/testData/codegen/box/collections/kt41123.kt"); @@ -15437,6 +15442,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/inlineClasses/referToUnderlyingPropertyOfInlineClass.kt"); } + @TestMetadata("removeInInlineCollectionOfInlineClassAsInt.kt") + public void testRemoveInInlineCollectionOfInlineClassAsInt() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/removeInInlineCollectionOfInlineClassAsInt.kt"); + } + @TestMetadata("resultInlining.kt") public void testResultInlining() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/resultInlining.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java index b4ac638b4dd..398a96bcc2a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java @@ -1057,6 +1057,11 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet.kt"); } + @TestMetadata("mutableSet2.kt") + public void testMutableSet2() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet2.kt"); + } + @TestMetadata("set.kt") public void testSet() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/set.kt"); @@ -1307,6 +1312,11 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { runTest("compiler/testData/codegen/bytecodeListing/specialBridges/kt41123.kt"); } + @TestMetadata("mutableCollectionOfPrimitive.kt") + public void testMutableCollectionOfPrimitive() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/specialBridges/mutableCollectionOfPrimitive.kt"); + } + @TestMetadata("mutableListOfPrimitive.kt") public void testMutableListOfPrimitive() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/specialBridges/mutableListOfPrimitive.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index fab577af33f..4414baa97ed 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -5063,6 +5063,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/collections/irrelevantSizeOverrideInJava.kt"); } + @TestMetadata("javaCollectionWithRemovePrimitiveInt.kt") + public void testJavaCollectionWithRemovePrimitiveInt() throws Exception { + runTest("compiler/testData/codegen/box/collections/javaCollectionWithRemovePrimitiveInt.kt"); + } + @TestMetadata("kt41123.kt") public void testKt41123() throws Exception { runTest("compiler/testData/codegen/box/collections/kt41123.kt"); @@ -15447,6 +15452,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/inlineClasses/referToUnderlyingPropertyOfInlineClass.kt"); } + @TestMetadata("removeInInlineCollectionOfInlineClassAsInt.kt") + public void testRemoveInInlineCollectionOfInlineClassAsInt() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/removeInInlineCollectionOfInlineClassAsInt.kt"); + } + @TestMetadata("resultInlining.kt") public void testResultInlining() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/resultInlining.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 2c7da2271c6..62bdbe554a8 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -5033,6 +5033,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/collections/irrelevantSizeOverrideInJava.kt"); } + @TestMetadata("javaCollectionWithRemovePrimitiveInt.kt") + public void testJavaCollectionWithRemovePrimitiveInt() throws Exception { + runTest("compiler/testData/codegen/box/collections/javaCollectionWithRemovePrimitiveInt.kt"); + } + @TestMetadata("kt41123.kt") public void testKt41123() throws Exception { runTest("compiler/testData/codegen/box/collections/kt41123.kt"); @@ -14042,6 +14047,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/inlineClasses/referToUnderlyingPropertyOfInlineClass.kt"); } + @TestMetadata("removeInInlineCollectionOfInlineClassAsInt.kt") + public void testRemoveInInlineCollectionOfInlineClassAsInt() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/removeInInlineCollectionOfInlineClassAsInt.kt"); + } + @TestMetadata("resultInlining.kt") public void testResultInlining() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/resultInlining.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java index 0d169d8959f..697e45dca3c 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBytecodeListingTestGenerated.java @@ -1027,6 +1027,11 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet.kt"); } + @TestMetadata("mutableSet2.kt") + public void testMutableSet2() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/mutableSet2.kt"); + } + @TestMetadata("set.kt") public void testSet() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/inlineClasses/inlineCollectionOfInlineClass/set.kt"); @@ -1277,6 +1282,11 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes runTest("compiler/testData/codegen/bytecodeListing/specialBridges/kt41123.kt"); } + @TestMetadata("mutableCollectionOfPrimitive.kt") + public void testMutableCollectionOfPrimitive() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/specialBridges/mutableCollectionOfPrimitive.kt"); + } + @TestMetadata("mutableListOfPrimitive.kt") public void testMutableListOfPrimitive() throws Exception { runTest("compiler/testData/codegen/bytecodeListing/specialBridges/mutableListOfPrimitive.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index 0f67f66bee5..9b290be8182 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -12052,6 +12052,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/inlineClasses/referToUnderlyingPropertyOfInlineClass.kt"); } + @TestMetadata("removeInInlineCollectionOfInlineClassAsInt.kt") + public void testRemoveInInlineCollectionOfInlineClassAsInt() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/removeInInlineCollectionOfInlineClassAsInt.kt"); + } + @TestMetadata("resultInlining.kt") public void testResultInlining() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/resultInlining.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index e1223cb718c..b46738ac2f9 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -12052,6 +12052,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/referToUnderlyingPropertyOfInlineClass.kt"); } + @TestMetadata("removeInInlineCollectionOfInlineClassAsInt.kt") + public void testRemoveInInlineCollectionOfInlineClassAsInt() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/removeInInlineCollectionOfInlineClassAsInt.kt"); + } + @TestMetadata("resultInlining.kt") public void testResultInlining() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/resultInlining.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 6da0b08db33..e732483745b 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -12117,6 +12117,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/inlineClasses/referToUnderlyingPropertyOfInlineClass.kt"); } + @TestMetadata("removeInInlineCollectionOfInlineClassAsInt.kt") + public void testRemoveInInlineCollectionOfInlineClassAsInt() throws Exception { + runTest("compiler/testData/codegen/box/inlineClasses/removeInInlineCollectionOfInlineClassAsInt.kt"); + } + @TestMetadata("resultInlining.kt") public void testResultInlining() throws Exception { runTest("compiler/testData/codegen/box/inlineClasses/resultInlining.kt");