From 839026b6fe8a587cf22be32d95ca85e2d9e480bf Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Mon, 13 Mar 2023 11:57:27 +0200 Subject: [PATCH] [FIR2IR] Generate IR declarations in classes in strict order Order is following: - declared declarations in declaration (in source) order - generated declarations in sorted order --- .../generators/ClassMemberGenerator.kt | 6 +- .../FirLightTreeJvmIrTextTestGenerated.java | 6 + .../ir/FirPsiJvmIrTextTestGenerated.java | 6 + .../extensions/generatedDeclarationsUtils.kt | 13 +- .../ir/irText/classes/declarationOrder.ir.txt | 84 +++++++ .../ir/irText/classes/declarationOrder.kt | 19 ++ .../ir/irText/classes/declarationOrder.kt.txt | 53 +++++ .../ir/ClassicJvmIrTextTestGenerated.java | 6 + .../klib/KlibIrTextTestCaseGenerated.java | 5 + .../FirLightTreeJsIrTextTestGenerated.java | 6 + .../test/fir/FirPsiJsIrTextTestGenerated.java | 6 + .../test/ir/ClassicJsIrTextTestGenerated.java | 6 + .../testData/box/serializer.fir.ir.txt | 221 ++++++++++++++++++ .../testData/box/serializer.fir.txt | 32 ++- .../testData/box/serializer.kt | 20 +- 15 files changed, 467 insertions(+), 22 deletions(-) create mode 100644 compiler/testData/ir/irText/classes/declarationOrder.ir.txt create mode 100644 compiler/testData/ir/irText/classes/declarationOrder.kt create mode 100644 compiler/testData/ir/irText/classes/declarationOrder.kt.txt create mode 100644 plugins/fir-plugin-prototype/testData/box/serializer.fir.ir.txt diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt index c0dc5d6c80d..3e46c7b3de8 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/ClassMemberGenerator.kt @@ -10,6 +10,8 @@ import org.jetbrains.kotlin.descriptors.Visibilities import org.jetbrains.kotlin.fir.backend.* import org.jetbrains.kotlin.fir.containingClassLookupTag import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.declarations.comparators.FirCallableDeclarationComparator +import org.jetbrains.kotlin.fir.declarations.comparators.FirMemberDeclarationComparator import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyGetter import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertySetter import org.jetbrains.kotlin.fir.declarations.utils.isExpect @@ -57,8 +59,8 @@ internal class ClassMemberGenerator( val allDeclarations = buildList { addAll(klass.declarations) if (session.extensionService.declarationGenerators.isNotEmpty()) { - addAll(klass.generatedMembers(session)) - addAll(klass.generatedNestedClassifiers(session)) + addAll(klass.generatedMembers(session).sortedWith(FirCallableDeclarationComparator)) + addAll(klass.generatedNestedClassifiers(session).sortedWith(FirMemberDeclarationComparator)) } } diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrTextTestGenerated.java index 6c56e1b8b0c..cac5485ef83 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirLightTreeJvmIrTextTestGenerated.java @@ -88,6 +88,12 @@ public class FirLightTreeJvmIrTextTestGenerated extends AbstractFirLightTreeJvmI runTest("compiler/testData/ir/irText/classes/companionObject.kt"); } + @Test + @TestMetadata("declarationOrder.kt") + public void testDeclarationOrder() throws Exception { + runTest("compiler/testData/ir/irText/classes/declarationOrder.kt"); + } + @Test @TestMetadata("delegatedGenericImplementation.kt") public void testDelegatedGenericImplementation() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrTextTestGenerated.java index 01072d0ef84..6098feaf0ce 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/FirPsiJvmIrTextTestGenerated.java @@ -88,6 +88,12 @@ public class FirPsiJvmIrTextTestGenerated extends AbstractFirPsiJvmIrTextTest { runTest("compiler/testData/ir/irText/classes/companionObject.kt"); } + @Test + @TestMetadata("declarationOrder.kt") + public void testDeclarationOrder() throws Exception { + runTest("compiler/testData/ir/irText/classes/declarationOrder.kt"); + } + @Test @TestMetadata("delegatedGenericImplementation.kt") public void testDelegatedGenericImplementation() throws Exception { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/generatedDeclarationsUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/generatedDeclarationsUtils.kt index 9dacd84a47e..7c5f6f923e8 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/generatedDeclarationsUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/extensions/generatedDeclarationsUtils.kt @@ -6,17 +6,22 @@ package org.jetbrains.kotlin.fir.extensions import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration import org.jetbrains.kotlin.fir.declarations.FirClass +import org.jetbrains.kotlin.fir.declarations.FirClassLikeDeclaration import org.jetbrains.kotlin.fir.declarations.FirDeclaration import org.jetbrains.kotlin.fir.scopes.impl.declaredMemberScope import org.jetbrains.kotlin.fir.scopes.processClassifiersByName +import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol -fun FirClass.generatedNestedClassifiers(session: FirSession): List { +fun FirClass.generatedNestedClassifiers(session: FirSession): List { val scope = session.declaredMemberScope(this) - val result = mutableListOf() + val result = mutableListOf() for (name in scope.getClassifierNames()) { scope.processClassifiersByName(name) { if (it.fir.origin.generated) { + // Plugins can not generate type parameters, so it's safe to cast symbol here + require(it is FirClassLikeSymbol<*>) { "Plugins can not generate type parameters, but had $it" } result += it.fir } } @@ -24,9 +29,9 @@ fun FirClass.generatedNestedClassifiers(session: FirSession): List { +fun FirClass.generatedMembers(session: FirSession): List { val scope = session.declaredMemberScope(this) - val result = mutableListOf() + val result = mutableListOf() for (name in scope.getCallableNames()) { scope.processFunctionsByName(name) { if (it.fir.origin.generated) { diff --git a/compiler/testData/ir/irText/classes/declarationOrder.ir.txt b/compiler/testData/ir/irText/classes/declarationOrder.ir.txt new file mode 100644 index 00000000000..abe5ad9c5ef --- /dev/null +++ b/compiler/testData/ir/irText/classes/declarationOrder.ir.txt @@ -0,0 +1,84 @@ +FILE fqName:test fileName:/declarationOrder.kt + CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:test.A + CONSTRUCTOR visibility:public <> () returnType:test.A [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' + CONSTRUCTOR visibility:public <> (x:kotlin.Int) returnType:test.A + VALUE_PARAMETER name:x index:0 type:kotlin.Int + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in test.A' + FUN name:b visibility:public modality:FINAL <> ($this:test.A) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:test.A + BLOCK_BODY + FUN name:a visibility:public modality:FINAL <> ($this:test.A) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:test.A + BLOCK_BODY + PROPERTY name:b visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:b type:kotlin.Int visibility:private [final] + EXPRESSION_BODY + CONST Int type=kotlin.Int value=1 + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:test.A) returnType:kotlin.Int + correspondingProperty: PROPERTY name:b visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:test.A + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in test.A' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null + receiver: GET_VAR ': test.A declared in test.A.' type=test.A origin=null + PROPERTY name:a visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.Int visibility:private [final] + EXPRESSION_BODY + CONST Int type=kotlin.Int value=2 + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:test.A) returnType:kotlin.Int + correspondingProperty: PROPERTY name:a visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:test.A + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in test.A' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null + receiver: GET_VAR ': test.A declared in test.A.' type=test.A origin=null + CONSTRUCTOR visibility:public <> (x:kotlin.String) returnType:test.A + VALUE_PARAMETER name:x index:0 type:kotlin.String + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in test.A' + PROPERTY name:b visibility:public modality:FINAL [val] + FUN name: visibility:public modality:FINAL <> ($this:test.A, $receiver:kotlin.Int) returnType:kotlin.String + correspondingProperty: PROPERTY name:b visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:test.A + $receiver: VALUE_PARAMETER name: type:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in test.A' + CONST String type=kotlin.String value="b" + FUN name:b visibility:public modality:FINAL <> ($this:test.A, $receiver:kotlin.String) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:test.A + $receiver: VALUE_PARAMETER name: type:kotlin.String + BLOCK_BODY + PROPERTY name:a visibility:public modality:FINAL [val] + FUN name: visibility:public modality:FINAL <> ($this:test.A, $receiver:kotlin.Int) returnType:kotlin.String + correspondingProperty: PROPERTY name:a visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:test.A + $receiver: VALUE_PARAMETER name: type:kotlin.Int + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.String declared in test.A' + CONST String type=kotlin.String value="a" + FUN name:a visibility:public modality:FINAL <> ($this:test.A, $receiver:kotlin.String) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:test.A + $receiver: VALUE_PARAMETER name: type:kotlin.String + BLOCK_BODY + CONSTRUCTOR visibility:public <> (x:kotlin.Double) returnType:test.A + VALUE_PARAMETER name:x index:0 type:kotlin.Double + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in test.A' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/classes/declarationOrder.kt b/compiler/testData/ir/irText/classes/declarationOrder.kt new file mode 100644 index 00000000000..2dfd1a340c3 --- /dev/null +++ b/compiler/testData/ir/irText/classes/declarationOrder.kt @@ -0,0 +1,19 @@ +// FIR_IDENTICAL +// SKIP_KLIB_TEST +// IGNORE_BACKEND_K1: JS_IR +// Ignore reason: there is a js name clash between function `a()` and property `a` +package test + +class A() { + constructor(x: Int) : this() + fun b() {} + fun a() {} + val b: Int = 1 + val a: Int = 2 + constructor(x: String) : this() + val Int.b: String get() = "b" + fun String.b() {} + val Int.a: String get() = "a" + fun String.a() {} + constructor(x: Double) : this() +} diff --git a/compiler/testData/ir/irText/classes/declarationOrder.kt.txt b/compiler/testData/ir/irText/classes/declarationOrder.kt.txt new file mode 100644 index 00000000000..d4e277aabac --- /dev/null +++ b/compiler/testData/ir/irText/classes/declarationOrder.kt.txt @@ -0,0 +1,53 @@ +package test + +class A { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + constructor(x: Int) { + this/*A*/() + } + + fun b() { + } + + fun a() { + } + + val b: Int + field = 1 + get + + val a: Int + field = 2 + get + + constructor(x: String) { + this/*A*/() + } + + val Int.b: String + get(): String { + return "b" + } + + fun String.b() { + } + + val Int.a: String + get(): String { + return "a" + } + + fun String.a() { + } + + constructor(x: Double) { + this/*A*/() + } + +} + diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrTextTestGenerated.java index 5295749e1c0..a0885528b17 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/ClassicJvmIrTextTestGenerated.java @@ -88,6 +88,12 @@ public class ClassicJvmIrTextTestGenerated extends AbstractClassicJvmIrTextTest runTest("compiler/testData/ir/irText/classes/companionObject.kt"); } + @Test + @TestMetadata("declarationOrder.kt") + public void testDeclarationOrder() throws Exception { + runTest("compiler/testData/ir/irText/classes/declarationOrder.kt"); + } + @Test @TestMetadata("delegatedGenericImplementation.kt") public void testDelegatedGenericImplementation() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibIrTextTestCaseGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibIrTextTestCaseGenerated.java index c6b00aa97bf..3f9c7dc8eff 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibIrTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibIrTextTestCaseGenerated.java @@ -87,6 +87,11 @@ public class KlibIrTextTestCaseGenerated extends AbstractKlibIrTextTestCase { runTest("compiler/testData/ir/irText/classes/companionObject.kt"); } + @TestMetadata("declarationOrder.kt") + public void testDeclarationOrder() throws Exception { + runTest("compiler/testData/ir/irText/classes/declarationOrder.kt"); + } + @TestMetadata("delegatedGenericImplementation.kt") public void testDelegatedGenericImplementation() throws Exception { runTest("compiler/testData/ir/irText/classes/delegatedGenericImplementation.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirLightTreeJsIrTextTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirLightTreeJsIrTextTestGenerated.java index 5abe0683ab7..4a10ecb4786 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirLightTreeJsIrTextTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirLightTreeJsIrTextTestGenerated.java @@ -88,6 +88,12 @@ public class FirLightTreeJsIrTextTestGenerated extends AbstractFirLightTreeJsIrT runTest("compiler/testData/ir/irText/classes/companionObject.kt"); } + @Test + @TestMetadata("declarationOrder.kt") + public void testDeclarationOrder() throws Exception { + runTest("compiler/testData/ir/irText/classes/declarationOrder.kt"); + } + @Test @TestMetadata("delegatedGenericImplementation.kt") public void testDelegatedGenericImplementation() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsIrTextTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsIrTextTestGenerated.java index 2a011d31380..3c2e27ab0a5 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsIrTextTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/fir/FirPsiJsIrTextTestGenerated.java @@ -88,6 +88,12 @@ public class FirPsiJsIrTextTestGenerated extends AbstractFirPsiJsIrTextTest { runTest("compiler/testData/ir/irText/classes/companionObject.kt"); } + @Test + @TestMetadata("declarationOrder.kt") + public void testDeclarationOrder() throws Exception { + runTest("compiler/testData/ir/irText/classes/declarationOrder.kt"); + } + @Test @TestMetadata("delegatedGenericImplementation.kt") public void testDelegatedGenericImplementation() throws Exception { diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/ClassicJsIrTextTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/ClassicJsIrTextTestGenerated.java index fa53d0b69fd..25a27be2b04 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/ClassicJsIrTextTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/ClassicJsIrTextTestGenerated.java @@ -88,6 +88,12 @@ public class ClassicJsIrTextTestGenerated extends AbstractClassicJsIrTextTest { runTest("compiler/testData/ir/irText/classes/companionObject.kt"); } + @Test + @TestMetadata("declarationOrder.kt") + public void testDeclarationOrder() throws Exception { + runTest("compiler/testData/ir/irText/classes/declarationOrder.kt"); + } + @Test @TestMetadata("delegatedGenericImplementation.kt") public void testDelegatedGenericImplementation() throws Exception { diff --git a/plugins/fir-plugin-prototype/testData/box/serializer.fir.ir.txt b/plugins/fir-plugin-prototype/testData/box/serializer.fir.ir.txt new file mode 100644 index 00000000000..772f2cc3fc3 --- /dev/null +++ b/plugins/fir-plugin-prototype/testData/box/serializer.fir.ir.txt @@ -0,0 +1,221 @@ +FILE fqName: fileName:/serializer.kt + CLASS OBJECT name:FirstSerializer modality:FINAL visibility:public superTypes:[kotlin.Any] + annotations: + CoreSerializer + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.FirstSerializer + CONSTRUCTOR visibility:private <> () returnType:.FirstSerializer [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:FirstSerializer modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:bFunction visibility:public modality:FINAL <> ($this:.FirstSerializer) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.FirstSerializer + BLOCK_BODY + FUN name:aFunction visibility:public modality:FINAL <> ($this:.FirstSerializer) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.FirstSerializer + BLOCK_BODY + PROPERTY name:bProp visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:bProp type:kotlin.Int visibility:private [final] + EXPRESSION_BODY + CONST Int type=kotlin.Int value=1 + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.FirstSerializer) returnType:kotlin.Int + correspondingProperty: PROPERTY name:bProp visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.FirstSerializer + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in .FirstSerializer' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:bProp type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null + receiver: GET_VAR ': .FirstSerializer declared in .FirstSerializer.' type=.FirstSerializer origin=null + PROPERTY name:aProp visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:aProp type:kotlin.Int visibility:private [final] + EXPRESSION_BODY + CONST Int type=kotlin.Int value=2 + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.FirstSerializer) returnType:kotlin.Int + correspondingProperty: PROPERTY name:aProp visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.FirstSerializer + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in .FirstSerializer' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:aProp type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null + receiver: GET_VAR ': .FirstSerializer declared in .FirstSerializer.' type=.FirstSerializer origin=null + FUN GENERATED[org.jetbrains.kotlin.fir.plugin.generators.MembersOfSerializerGenerator.Key] name:serializeA visibility:public modality:FINAL <> ($this:.FirstSerializer, x:.A) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.FirstSerializer + VALUE_PARAMETER GENERATED[org.jetbrains.kotlin.fir.plugin.generators.MembersOfSerializerGenerator.Key] name:x index:0 type:.A + BLOCK_BODY + FUN GENERATED[org.jetbrains.kotlin.fir.plugin.generators.MembersOfSerializerGenerator.Key] name:serializeB visibility:public modality:FINAL <> ($this:.FirstSerializer, x:.B) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.FirstSerializer + VALUE_PARAMETER GENERATED[org.jetbrains.kotlin.fir.plugin.generators.MembersOfSerializerGenerator.Key] name:x index:0 type:.B + BLOCK_BODY + FUN GENERATED[org.jetbrains.kotlin.fir.plugin.generators.MembersOfSerializerGenerator.Key] name:serializeC visibility:public modality:FINAL <> ($this:.FirstSerializer, x:.C) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.FirstSerializer + VALUE_PARAMETER GENERATED[org.jetbrains.kotlin.fir.plugin.generators.MembersOfSerializerGenerator.Key] name:x index:0 type:.C + BLOCK_BODY + FUN GENERATED[org.jetbrains.kotlin.fir.plugin.generators.MembersOfSerializerGenerator.Key] name:serializeD visibility:public modality:FINAL <> ($this:.FirstSerializer, x:.D) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.FirstSerializer + VALUE_PARAMETER GENERATED[org.jetbrains.kotlin.fir.plugin.generators.MembersOfSerializerGenerator.Key] name:x index:0 type:.D + BLOCK_BODY + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS OBJECT name:SecondSerializer modality:FINAL visibility:public superTypes:[kotlin.Any] + annotations: + CoreSerializer + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.SecondSerializer + CONSTRUCTOR visibility:private <> () returnType:.SecondSerializer [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:SecondSerializer modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN GENERATED[org.jetbrains.kotlin.fir.plugin.generators.MembersOfSerializerGenerator.Key] name:serializeA visibility:public modality:FINAL <> ($this:.SecondSerializer, x:.A) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.SecondSerializer + VALUE_PARAMETER GENERATED[org.jetbrains.kotlin.fir.plugin.generators.MembersOfSerializerGenerator.Key] name:x index:0 type:.A + BLOCK_BODY + FUN GENERATED[org.jetbrains.kotlin.fir.plugin.generators.MembersOfSerializerGenerator.Key] name:serializeB visibility:public modality:FINAL <> ($this:.SecondSerializer, x:.B) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.SecondSerializer + VALUE_PARAMETER GENERATED[org.jetbrains.kotlin.fir.plugin.generators.MembersOfSerializerGenerator.Key] name:x index:0 type:.B + BLOCK_BODY + FUN GENERATED[org.jetbrains.kotlin.fir.plugin.generators.MembersOfSerializerGenerator.Key] name:serializeC visibility:public modality:FINAL <> ($this:.SecondSerializer, x:.C) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.SecondSerializer + VALUE_PARAMETER GENERATED[org.jetbrains.kotlin.fir.plugin.generators.MembersOfSerializerGenerator.Key] name:x index:0 type:.C + BLOCK_BODY + FUN GENERATED[org.jetbrains.kotlin.fir.plugin.generators.MembersOfSerializerGenerator.Key] name:serializeD visibility:public modality:FINAL <> ($this:.SecondSerializer, x:.D) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.SecondSerializer + VALUE_PARAMETER GENERATED[org.jetbrains.kotlin.fir.plugin.generators.MembersOfSerializerGenerator.Key] name:x index:0 type:.D + BLOCK_BODY + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:D modality:FINAL visibility:public superTypes:[kotlin.Any] + annotations: + MySerializable + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.D + CONSTRUCTOR visibility:public <> () returnType:.D [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:D modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any] + annotations: + MySerializable + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.C + CONSTRUCTOR visibility:public <> () returnType:.C [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:B modality:FINAL visibility:public superTypes:[kotlin.Any] + annotations: + MySerializable + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.B + CONSTRUCTOR visibility:public <> () returnType:.B [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:B modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any] + annotations: + MySerializable + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A + CONSTRUCTOR visibility:public <> () returnType:.A [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:testFirstSerializer visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun serializeA (x: .A): kotlin.Unit declared in .FirstSerializer' type=kotlin.Unit origin=null + $this: GET_OBJECT 'CLASS OBJECT name:FirstSerializer modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.FirstSerializer + x: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .A' type=.A origin=null + CALL 'public final fun serializeB (x: .B): kotlin.Unit declared in .FirstSerializer' type=kotlin.Unit origin=null + $this: GET_OBJECT 'CLASS OBJECT name:FirstSerializer modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.FirstSerializer + x: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .B' type=.B origin=null + CALL 'public final fun serializeC (x: .C): kotlin.Unit declared in .FirstSerializer' type=kotlin.Unit origin=null + $this: GET_OBJECT 'CLASS OBJECT name:FirstSerializer modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.FirstSerializer + x: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .C' type=.C origin=null + CALL 'public final fun serializeD (x: .D): kotlin.Unit declared in .FirstSerializer' type=kotlin.Unit origin=null + $this: GET_OBJECT 'CLASS OBJECT name:FirstSerializer modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.FirstSerializer + x: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .D' type=.D origin=null + FUN name:testSecondSerializer visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun serializeA (x: .A): kotlin.Unit declared in .SecondSerializer' type=kotlin.Unit origin=null + $this: GET_OBJECT 'CLASS OBJECT name:SecondSerializer modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.SecondSerializer + x: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .A' type=.A origin=null + CALL 'public final fun serializeB (x: .B): kotlin.Unit declared in .SecondSerializer' type=kotlin.Unit origin=null + $this: GET_OBJECT 'CLASS OBJECT name:SecondSerializer modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.SecondSerializer + x: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .B' type=.B origin=null + CALL 'public final fun serializeC (x: .C): kotlin.Unit declared in .SecondSerializer' type=kotlin.Unit origin=null + $this: GET_OBJECT 'CLASS OBJECT name:SecondSerializer modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.SecondSerializer + x: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .C' type=.C origin=null + CALL 'public final fun serializeD (x: .D): kotlin.Unit declared in .SecondSerializer' type=kotlin.Unit origin=null + $this: GET_OBJECT 'CLASS OBJECT name:SecondSerializer modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.SecondSerializer + x: CONSTRUCTOR_CALL 'public constructor () [primary] declared in .D' type=.D origin=null + FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String + BLOCK_BODY + CALL 'public final fun testFirstSerializer (): kotlin.Unit declared in ' type=kotlin.Unit origin=null + CALL 'public final fun testSecondSerializer (): kotlin.Unit declared in ' type=kotlin.Unit origin=null + RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' + CONST String type=kotlin.String value="OK" diff --git a/plugins/fir-plugin-prototype/testData/box/serializer.fir.txt b/plugins/fir-plugin-prototype/testData/box/serializer.fir.txt index a940167c1d4..efdd34f3e7f 100644 --- a/plugins/fir-plugin-prototype/testData/box/serializer.fir.txt +++ b/plugins/fir-plugin-prototype/testData/box/serializer.fir.txt @@ -4,6 +4,18 @@ FILE: serializer.kt super() } + public final fun bFunction(): R|kotlin/Unit| { + } + + public final fun aFunction(): R|kotlin/Unit| { + } + + public final val bProp: R|kotlin/Int| = Int(1) + public get(): R|kotlin/Int| + + public final val aProp: R|kotlin/Int| = Int(2) + public get(): R|kotlin/Int| + public final fun serializeA(x: R|A|): R|kotlin/Unit| { } @@ -35,14 +47,8 @@ FILE: serializer.kt } } - @R|org/jetbrains/kotlin/fir/plugin/MySerializable|() public final class A : R|kotlin/Any| { - public constructor(): R|A| { - super() - } - - } - @R|org/jetbrains/kotlin/fir/plugin/MySerializable|() public final class B : R|kotlin/Any| { - public constructor(): R|B| { + @R|org/jetbrains/kotlin/fir/plugin/MySerializable|() public final class D : R|kotlin/Any| { + public constructor(): R|D| { super() } @@ -53,8 +59,14 @@ FILE: serializer.kt } } - @R|org/jetbrains/kotlin/fir/plugin/MySerializable|() public final class D : R|kotlin/Any| { - public constructor(): R|D| { + @R|org/jetbrains/kotlin/fir/plugin/MySerializable|() public final class B : R|kotlin/Any| { + public constructor(): R|B| { + super() + } + + } + @R|org/jetbrains/kotlin/fir/plugin/MySerializable|() public final class A : R|kotlin/Any| { + public constructor(): R|A| { super() } diff --git a/plugins/fir-plugin-prototype/testData/box/serializer.kt b/plugins/fir-plugin-prototype/testData/box/serializer.kt index ca5c4691b1f..9cdf136b64a 100644 --- a/plugins/fir-plugin-prototype/testData/box/serializer.kt +++ b/plugins/fir-plugin-prototype/testData/box/serializer.kt @@ -1,23 +1,31 @@ +// DUMP_IR + import org.jetbrains.kotlin.fir.plugin.CoreSerializer import org.jetbrains.kotlin.fir.plugin.MySerializable @CoreSerializer -object FirstSerializer +object FirstSerializer { + fun bFunction() {} + fun aFunction() {} + + val bProp = 1 + val aProp = 2 +} @CoreSerializer object SecondSerializer @MySerializable -class A - -@MySerializable -class B +class D @MySerializable class C @MySerializable -class D +class B + +@MySerializable +class A fun testFirstSerializer() { FirstSerializer.serializeA(A())