diff --git a/compiler/testData/codegen/bytecodeListing/contextReceivers/class.kt b/compiler/testData/codegen/bytecodeListing/contextReceivers/class.kt new file mode 100644 index 00000000000..16e5ee0ff75 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/contextReceivers/class.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +ContextReceivers +// TARGET_BACKEND: JVM_IR +// IGNORE_BACKEND_FIR: JVM_IR +// IGNORE_BACKEND: JVM + +class Outer { + val x: Int = 1 +} + +context(Outer) +class Inner(arg: Any) { + fun bar() = x +} + +fun f(outer: Outer) { + with(outer) { + Inner(3) + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/contextReceivers/class.txt b/compiler/testData/codegen/bytecodeListing/contextReceivers/class.txt new file mode 100644 index 00000000000..8fec14d19fd --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/contextReceivers/class.txt @@ -0,0 +1,21 @@ +@kotlin.Metadata +public final class ClassKt { + // source: 'class.kt' + public final static method f(@org.jetbrains.annotations.NotNull p0: Outer): void +} + +@kotlin.Metadata +public final class Inner { + // source: 'class.kt' + private synthetic final field contextReceiverField0: Outer + public method (@org.jetbrains.annotations.NotNull p0: Outer, @org.jetbrains.annotations.NotNull p1: java.lang.Object): void + public final method bar(): int +} + +@kotlin.Metadata +public final class Outer { + // source: 'class.kt' + private final field x: int + public method (): void + public final method getX(): int +} diff --git a/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/canvas.kt b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/canvas.kt new file mode 100644 index 00000000000..9a477643290 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/canvas.kt @@ -0,0 +1,22 @@ +// !LANGUAGE: +ContextReceivers +// TARGET_BACKEND: JVM_IR +// IGNORE_BACKEND_FIR: JVM_IR +// IGNORE_BACKEND: JVM + +interface Canvas { + val suffix: String +} + +interface Shape { + context(Canvas) + fun draw(): String +} + +class Circle : Shape { + context(Canvas) + override fun draw() = "OK" + suffix +} + +object MyCanvas : Canvas { + override val suffix = "" +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/canvas.txt b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/canvas.txt new file mode 100644 index 00000000000..f8150043d2a --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/canvas.txt @@ -0,0 +1,28 @@ +@kotlin.Metadata +public interface Canvas { + // source: 'canvas.kt' + public abstract @org.jetbrains.annotations.NotNull method getSuffix(): java.lang.String +} + +@kotlin.Metadata +public final class Circle { + // source: 'canvas.kt' + public method (): void + public @org.jetbrains.annotations.NotNull method draw(@org.jetbrains.annotations.NotNull p0: Canvas): java.lang.String +} + +@kotlin.Metadata +public final class MyCanvas { + // source: 'canvas.kt' + public final static @org.jetbrains.annotations.NotNull field INSTANCE: MyCanvas + private final static @org.jetbrains.annotations.NotNull field suffix: java.lang.String + static method (): void + private method (): void + public @org.jetbrains.annotations.NotNull method getSuffix(): java.lang.String +} + +@kotlin.Metadata +public interface Shape { + // source: 'canvas.kt' + public abstract @org.jetbrains.annotations.NotNull method draw(@org.jetbrains.annotations.NotNull p0: Canvas): java.lang.String +} diff --git a/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/compareTo.kt b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/compareTo.kt new file mode 100644 index 00000000000..b788972fc3d --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/compareTo.kt @@ -0,0 +1,12 @@ +// !LANGUAGE: +ContextReceivers +// TARGET_BACKEND: JVM_IR +// IGNORE_BACKEND_FIR: JVM_IR +// IGNORE_BACKEND: JVM + +data class Pair(val first: A, val second: B) + +context(Comparator) +infix operator fun T.compareTo(other: T) = compare(this, other) + +context(Comparator) +val Pair.min get() = if (first < second) first else second \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/compareTo.txt b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/compareTo.txt new file mode 100644 index 00000000000..59cfbd7c7de --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/compareTo.txt @@ -0,0 +1,23 @@ +@kotlin.Metadata +public final class CompareToKt { + // source: 'compareTo.kt' + public final static method compareTo(@org.jetbrains.annotations.NotNull p0: java.util.Comparator, p1: java.lang.Object, p2: java.lang.Object): int + public final static method getMin(@org.jetbrains.annotations.NotNull p0: java.util.Comparator, @org.jetbrains.annotations.NotNull p1: Pair): java.lang.Object +} + +@kotlin.Metadata +public final class Pair { + // source: 'compareTo.kt' + private final field first: java.lang.Object + private final field second: java.lang.Object + public method (p0: java.lang.Object, p1: java.lang.Object): void + public final method component1(): java.lang.Object + public final method component2(): java.lang.Object + public synthetic static method copy$default(p0: Pair, p1: java.lang.Object, p2: java.lang.Object, p3: int, p4: java.lang.Object): Pair + public final @org.jetbrains.annotations.NotNull method copy(p0: java.lang.Object, p1: java.lang.Object): Pair + public method equals(@org.jetbrains.annotations.Nullable p0: java.lang.Object): boolean + public final method getFirst(): java.lang.Object + public final method getSecond(): java.lang.Object + public method hashCode(): int + public @org.jetbrains.annotations.NotNull method toString(): java.lang.String +} diff --git a/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/dp.kt b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/dp.kt new file mode 100644 index 00000000000..1b2b3436887 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/dp.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +ContextReceivers +// TARGET_BACKEND: JVM_IR +// IGNORE_BACKEND_FIR: JVM_IR +// IGNORE_BACKEND: JVM + +class View { + val coefficient = 42 +} + +context(View) val Int.dp get() = coefficient * this \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/dp.txt b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/dp.txt new file mode 100644 index 00000000000..71f2882f0e7 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/dp.txt @@ -0,0 +1,13 @@ +@kotlin.Metadata +public final class DpKt { + // source: 'dp.kt' + public final static method getDp(@org.jetbrains.annotations.NotNull p0: View, p1: int): int +} + +@kotlin.Metadata +public final class View { + // source: 'dp.kt' + private final field coefficient: int + public method (): void + public final method getCoefficient(): int +} diff --git a/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/functionalType.kt b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/functionalType.kt new file mode 100644 index 00000000000..1b2d205dd32 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/functionalType.kt @@ -0,0 +1,15 @@ +// !LANGUAGE: +ContextReceivers +// TARGET_BACKEND: JVM_IR +// IGNORE_BACKEND_FIR: JVM_IR +// IGNORE_BACKEND: JVM + +class Param +class O { + val o = "O" +} +class K { + val k = "K" +} + +context(O) +fun K.f(g: context(O) K.(Param) -> T) = g(this@O, this@K, Param()) \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/functionalType.txt b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/functionalType.txt new file mode 100644 index 00000000000..0f4a1171f7d --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/functionalType.txt @@ -0,0 +1,27 @@ +@kotlin.Metadata +public final class FunctionalTypeKt { + // source: 'functionalType.kt' + public final static method f(@org.jetbrains.annotations.NotNull p0: O, @org.jetbrains.annotations.NotNull p1: K, @org.jetbrains.annotations.NotNull p2: kotlin.jvm.functions.Function3): java.lang.Object +} + +@kotlin.Metadata +public final class K { + // source: 'functionalType.kt' + private final @org.jetbrains.annotations.NotNull field k: java.lang.String + public method (): void + public final @org.jetbrains.annotations.NotNull method getK(): java.lang.String +} + +@kotlin.Metadata +public final class O { + // source: 'functionalType.kt' + private final @org.jetbrains.annotations.NotNull field o: java.lang.String + public method (): void + public final @org.jetbrains.annotations.NotNull method getO(): java.lang.String +} + +@kotlin.Metadata +public final class Param { + // source: 'functionalType.kt' + public method (): void +} diff --git a/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/monoidSum.kt b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/monoidSum.kt new file mode 100644 index 00000000000..381fcf52a87 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/monoidSum.kt @@ -0,0 +1,24 @@ +// !LANGUAGE: +ContextReceivers +// TARGET_BACKEND: JVM_IR +// IGNORE_BACKEND_FIR: JVM_IR +// IGNORE_BACKEND: JVM +// WITH_RUNTIME + +interface Semigroup { + infix fun T.combine(other: T): T +} + +interface Monoid : Semigroup { + val unit: T +} +object IntMonoid : Monoid { + override fun Int.combine(other: Int): Int = this + other + override val unit: Int = 0 +} +object StringMonoid : Monoid { + override fun String.combine(other: String): String = this + other + override val unit: String = "" +} + +context(Monoid) +fun List.sum(): T = fold(unit) { acc, e -> acc.combine(e) } \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/monoidSum.txt b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/monoidSum.txt new file mode 100644 index 00000000000..c255d165395 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/monoidSum.txt @@ -0,0 +1,43 @@ +@kotlin.Metadata +public final class IntMonoid { + // source: 'monoidSum.kt' + public final static @org.jetbrains.annotations.NotNull field INSTANCE: IntMonoid + private final static field unit: int + static method (): void + private method (): void + public @org.jetbrains.annotations.NotNull method combine(p0: int, p1: int): java.lang.Integer + public synthetic bridge method combine(p0: java.lang.Object, p1: java.lang.Object): java.lang.Object + public @org.jetbrains.annotations.NotNull method getUnit(): java.lang.Integer + public synthetic bridge method getUnit(): java.lang.Object +} + +@kotlin.Metadata +public interface Monoid { + // source: 'monoidSum.kt' + public abstract method getUnit(): java.lang.Object +} + +@kotlin.Metadata +public final class MonoidSumKt { + // source: 'monoidSum.kt' + public final static method sum(@org.jetbrains.annotations.NotNull p0: Monoid, @org.jetbrains.annotations.NotNull p1: java.util.List): java.lang.Object +} + +@kotlin.Metadata +public interface Semigroup { + // source: 'monoidSum.kt' + public abstract method combine(p0: java.lang.Object, p1: java.lang.Object): java.lang.Object +} + +@kotlin.Metadata +public final class StringMonoid { + // source: 'monoidSum.kt' + public final static @org.jetbrains.annotations.NotNull field INSTANCE: StringMonoid + private final static @org.jetbrains.annotations.NotNull field unit: java.lang.String + static method (): void + private method (): void + public @org.jetbrains.annotations.NotNull method combine(@org.jetbrains.annotations.NotNull p0: java.lang.String, @org.jetbrains.annotations.NotNull p1: java.lang.String): java.lang.String + public synthetic bridge method combine(p0: java.lang.Object, p1: java.lang.Object): java.lang.Object + public synthetic bridge method getUnit(): java.lang.Object + public @org.jetbrains.annotations.NotNull method getUnit(): java.lang.String +} diff --git a/compiler/testData/codegen/bytecodeListing/contextReceivers/function.kt b/compiler/testData/codegen/bytecodeListing/contextReceivers/function.kt new file mode 100644 index 00000000000..c76e73d2c80 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/contextReceivers/function.kt @@ -0,0 +1,19 @@ +// !LANGUAGE: +ContextReceivers +// TARGET_BACKEND: JVM_IR +// IGNORE_BACKEND_FIR: JVM_IR +// IGNORE_BACKEND: JVM + +class C { + val c = 42 +} + +context(C) +fun foo() { + c +} + +fun bar(c: C) { + with(c) { + foo() + } +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/contextReceivers/function.txt b/compiler/testData/codegen/bytecodeListing/contextReceivers/function.txt new file mode 100644 index 00000000000..d43051c9359 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/contextReceivers/function.txt @@ -0,0 +1,14 @@ +@kotlin.Metadata +public final class C { + // source: 'function.kt' + private final field c: int + public method (): void + public final method getC(): int +} + +@kotlin.Metadata +public final class FunctionKt { + // source: 'function.kt' + public final static method bar(@org.jetbrains.annotations.NotNull p0: C): void + public final static method foo(@org.jetbrains.annotations.NotNull p0: C): void +} diff --git a/compiler/testData/codegen/bytecodeListing/contextReceivers/property.kt b/compiler/testData/codegen/bytecodeListing/contextReceivers/property.kt new file mode 100644 index 00000000000..b51fda52b86 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/contextReceivers/property.kt @@ -0,0 +1,14 @@ +// !LANGUAGE: +ContextReceivers +// TARGET_BACKEND: JVM_IR +// IGNORE_BACKEND_FIR: JVM_IR +// IGNORE_BACKEND: JVM + +interface A { + fun a(): Int +} +interface B { + fun b(): Int +} + +context(A, B) +val c get() = a() + b() \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/contextReceivers/property.txt b/compiler/testData/codegen/bytecodeListing/contextReceivers/property.txt new file mode 100644 index 00000000000..eb103a3ab11 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/contextReceivers/property.txt @@ -0,0 +1,17 @@ +@kotlin.Metadata +public interface A { + // source: 'property.kt' + public abstract method a(): int +} + +@kotlin.Metadata +public interface B { + // source: 'property.kt' + public abstract method b(): int +} + +@kotlin.Metadata +public final class PropertyKt { + // source: 'property.kt' + public final static method getC(@org.jetbrains.annotations.NotNull p0: B, @org.jetbrains.annotations.NotNull p1: A): int +} diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeListingTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeListingTestGenerated.java index 5df23ba0479..b0831258beb 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BytecodeListingTestGenerated.java @@ -847,6 +847,26 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { } } + @Nested + @TestMetadata("compiler/testData/codegen/bytecodeListing/contextReceivers") + @TestDataPath("$PROJECT_ROOT") + public class ContextReceivers { + @Test + public void testAllFilesPresentInContextReceivers() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeListing/contextReceivers"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + + @Nested + @TestMetadata("compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP") + @TestDataPath("$PROJECT_ROOT") + public class FromKEEP { + @Test + public void testAllFilesPresentInFromKEEP() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true); + } + } + } + @Nested @TestMetadata("compiler/testData/codegen/bytecodeListing/coroutines") @TestDataPath("$PROJECT_ROOT") diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeListingTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeListingTestGenerated.java index 669350a8dc8..24de065542a 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeListingTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBytecodeListingTestGenerated.java @@ -895,6 +895,74 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes } } + @Nested + @TestMetadata("compiler/testData/codegen/bytecodeListing/contextReceivers") + @TestDataPath("$PROJECT_ROOT") + public class ContextReceivers { + @Test + public void testAllFilesPresentInContextReceivers() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeListing/contextReceivers"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("class.kt") + public void testClass() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/contextReceivers/class.kt"); + } + + @Test + @TestMetadata("function.kt") + public void testFunction() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/contextReceivers/function.kt"); + } + + @Test + @TestMetadata("property.kt") + public void testProperty() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/contextReceivers/property.kt"); + } + + @Nested + @TestMetadata("compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP") + @TestDataPath("$PROJECT_ROOT") + public class FromKEEP { + @Test + public void testAllFilesPresentInFromKEEP() throws Exception { + KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); + } + + @Test + @TestMetadata("canvas.kt") + public void testCanvas() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/canvas.kt"); + } + + @Test + @TestMetadata("compareTo.kt") + public void testCompareTo() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/compareTo.kt"); + } + + @Test + @TestMetadata("dp.kt") + public void testDp() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/dp.kt"); + } + + @Test + @TestMetadata("functionalType.kt") + public void testFunctionalType() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/functionalType.kt"); + } + + @Test + @TestMetadata("monoidSum.kt") + public void testMonoidSum() throws Exception { + runTest("compiler/testData/codegen/bytecodeListing/contextReceivers/fromKEEP/monoidSum.kt"); + } + } + } + @Nested @TestMetadata("compiler/testData/codegen/bytecodeListing/coroutines") @TestDataPath("$PROJECT_ROOT")