From 61282fcaeb5553aa7481aabbdf249bdbfd46d899 Mon Sep 17 00:00:00 2001 From: Dmitriy Dolovov Date: Mon, 18 Dec 2023 17:00:16 +0100 Subject: [PATCH] IR text tests: New tests specifically for `main` functions mangling ^KT-57755 --- .../FirLightTreeJvmIrTextTestGenerated.java | 12 ++ .../ir/FirPsiJvmIrTextTestGenerated.java | 12 ++ .../declarations/mainFunctionMangling.ir.txt | 158 +++++++++++++++++ .../declarations/mainFunctionMangling.kt | 78 +++++++++ .../declarations/mainFunctionMangling.kt.txt | 95 ++++++++++ .../mainFunctionMangling.sig.kt.txt | 165 ++++++++++++++++++ .../mainFunctionManglingInJvm.ir.txt | 20 +++ .../declarations/mainFunctionManglingInJvm.kt | 29 +++ .../mainFunctionManglingInJvm.kt.txt | 25 +++ .../mainFunctionManglingInJvm.sig.kt.txt | 49 ++++++ .../ir/ClassicJvmIrTextTestGenerated.java | 12 ++ .../klib/KlibIrTextTestCaseGenerated.java | 5 + .../FirLightTreeJsIrTextTestGenerated.java | 6 + .../test/fir/FirPsiJsIrTextTestGenerated.java | 6 + .../test/ir/ClassicJsIrTextTestGenerated.java | 6 + .../ClassicNativeIrTextTestGenerated.java | 6 + ...FirLightTreeNativeIrTextTestGenerated.java | 6 + .../FirPsiNativeIrTextTestGenerated.java | 6 + 18 files changed, 696 insertions(+) create mode 100644 compiler/testData/ir/irText/declarations/mainFunctionMangling.ir.txt create mode 100644 compiler/testData/ir/irText/declarations/mainFunctionMangling.kt create mode 100644 compiler/testData/ir/irText/declarations/mainFunctionMangling.kt.txt create mode 100644 compiler/testData/ir/irText/declarations/mainFunctionMangling.sig.kt.txt create mode 100644 compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.ir.txt create mode 100644 compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.kt create mode 100644 compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.kt.txt create mode 100644 compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.sig.kt.txt 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 f8c628fb6a9..bc8669fb14d 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 @@ -540,6 +540,18 @@ public class FirLightTreeJvmIrTextTestGenerated extends AbstractFirLightTreeJvmI runTest("compiler/testData/ir/irText/declarations/localVarInDoWhile.kt"); } + @Test + @TestMetadata("mainFunctionMangling.kt") + public void testMainFunctionMangling() throws Exception { + runTest("compiler/testData/ir/irText/declarations/mainFunctionMangling.kt"); + } + + @Test + @TestMetadata("mainFunctionManglingInJvm.kt") + public void testMainFunctionManglingInJvm() throws Exception { + runTest("compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.kt"); + } + @Test @TestMetadata("packageLevelProperties.kt") public void testPackageLevelProperties() 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 310dc56a911..833bae01988 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 @@ -540,6 +540,18 @@ public class FirPsiJvmIrTextTestGenerated extends AbstractFirPsiJvmIrTextTest { runTest("compiler/testData/ir/irText/declarations/localVarInDoWhile.kt"); } + @Test + @TestMetadata("mainFunctionMangling.kt") + public void testMainFunctionMangling() throws Exception { + runTest("compiler/testData/ir/irText/declarations/mainFunctionMangling.kt"); + } + + @Test + @TestMetadata("mainFunctionManglingInJvm.kt") + public void testMainFunctionManglingInJvm() throws Exception { + runTest("compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.kt"); + } + @Test @TestMetadata("packageLevelProperties.kt") public void testPackageLevelProperties() throws Exception { diff --git a/compiler/testData/ir/irText/declarations/mainFunctionMangling.ir.txt b/compiler/testData/ir/irText/declarations/mainFunctionMangling.ir.txt new file mode 100644 index 00000000000..77e57906571 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/mainFunctionMangling.ir.txt @@ -0,0 +1,158 @@ +FILE fqName: fileName:/a.kt + FUN name:main visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="main()" + FUN name:main visibility:public modality:FINAL (t:T of .main) returnType:T of .main + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false + VALUE_PARAMETER name:t index:0 type:T of .main + BLOCK_BODY + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="main(T): T" + RETURN type=kotlin.Nothing from='public final fun main (t: T of .main): T of .main declared in ' + GET_VAR 't: T of .main declared in .main' type=T of .main origin=null + CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.C + CONSTRUCTOR visibility:public <> () returnType:.C [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:main visibility:public modality:FINAL <> ($this:.C) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.C + BLOCK_BODY + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="C.main()" + FUN name:main visibility:public modality:FINAL ($this:.C, t:T of .C.main) returnType:T of .C.main + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false + $this: VALUE_PARAMETER name: type:.C + VALUE_PARAMETER name:t index:0 type:T of .C.main + BLOCK_BODY + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="C.main(T): T" + RETURN type=kotlin.Nothing from='public final fun main (t: T of .C.main): T of .C.main declared in .C' + GET_VAR 't: T of .C.main declared in .C.main' type=T of .C.main origin=null + 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 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:O modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.O + CONSTRUCTOR visibility:private <> () returnType:.O [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:O modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:main visibility:public modality:FINAL <> ($this:.O) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:.O + BLOCK_BODY + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="O.main()" + FUN name:main visibility:public modality:FINAL ($this:.O, t:T of .O.main) returnType:T of .O.main + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false + $this: VALUE_PARAMETER name: type:.O + VALUE_PARAMETER name:t index:0 type:T of .O.main + BLOCK_BODY + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="O.main(T): T" + RETURN type=kotlin.Nothing from='public final fun main (t: T of .O.main): T of .O.main declared in .O' + GET_VAR 't: T of .O.main declared in .O.main' type=T of .O.main origin=null + 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 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 +FILE fqName:foo fileName:/b.kt + FUN name:main visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="foo.main()" + FUN name:main visibility:public modality:FINAL (t:T of foo.main) returnType:T of foo.main + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false + VALUE_PARAMETER name:t index:0 type:T of foo.main + BLOCK_BODY + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="foo.main(T): T" + RETURN type=kotlin.Nothing from='public final fun main (t: T of foo.main): T of foo.main declared in foo' + GET_VAR 't: T of foo.main declared in foo.main' type=T of foo.main origin=null + CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:foo.C + CONSTRUCTOR visibility:public <> () returnType:foo.C [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:main visibility:public modality:FINAL <> ($this:foo.C) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:foo.C + BLOCK_BODY + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="foo.C.main()" + FUN name:main visibility:public modality:FINAL ($this:foo.C, t:T of foo.C.main) returnType:T of foo.C.main + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false + $this: VALUE_PARAMETER name: type:foo.C + VALUE_PARAMETER name:t index:0 type:T of foo.C.main + BLOCK_BODY + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="foo.C.main(T): T" + RETURN type=kotlin.Nothing from='public final fun main (t: T of foo.C.main): T of foo.C.main declared in foo.C' + GET_VAR 't: T of foo.C.main declared in foo.C.main' type=T of foo.C.main origin=null + 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 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:O modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:foo.O + CONSTRUCTOR visibility:private <> () returnType:foo.O [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:O modality:FINAL visibility:public superTypes:[kotlin.Any]' + FUN name:main visibility:public modality:FINAL <> ($this:foo.O) returnType:kotlin.Unit + $this: VALUE_PARAMETER name: type:foo.O + BLOCK_BODY + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="foo.O.main()" + FUN name:main visibility:public modality:FINAL ($this:foo.O, t:T of foo.O.main) returnType:T of foo.O.main + TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false + $this: VALUE_PARAMETER name: type:foo.O + VALUE_PARAMETER name:t index:0 type:T of foo.O.main + BLOCK_BODY + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="foo.O.main(T): T" + RETURN type=kotlin.Nothing from='public final fun main (t: T of foo.O.main): T of foo.O.main declared in foo.O' + GET_VAR 't: T of foo.O.main declared in foo.O.main' type=T of foo.O.main origin=null + 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 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/declarations/mainFunctionMangling.kt b/compiler/testData/ir/irText/declarations/mainFunctionMangling.kt new file mode 100644 index 00000000000..a8b7dbbac7d --- /dev/null +++ b/compiler/testData/ir/irText/declarations/mainFunctionMangling.kt @@ -0,0 +1,78 @@ +// FIR_IDENTICAL +// WITH_STDLIB + +// MUTE_SIGNATURE_COMPARISON_K2: JVM_IR +// ^^^ JVM K2 eagerly mangles all the functions with `main` name, which is not so in JVM K1. That's the difference that, however, +// does not cause problems when switching between K1 and K2 compilers, since signatures are not serialized in JARs. + +// FILE: a.kt +fun main() { + println("main()") +} + +// Looks like `main` but is not a main function. +fun main(t: T): T { + println("main(T): T") + return t +} + +class C { + fun main() { + println("C.main()") + } + + // Looks like `main` but is not a main function. + fun main(t: T): T { + println("C.main(T): T") + return t + } +} + +object O { + fun main() { + println("O.main()") + } + + // Looks like `main` but is not a main function. + fun main(t: T): T { + println("O.main(T): T") + return t + } +} + +// FILE: b.kt +package foo + +fun main() { + println("foo.main()") +} + +// Looks like `main` but is not a main function. +fun main(t: T): T { + println("foo.main(T): T") + return t +} + +class C { + fun main() { + println("foo.C.main()") + } + + // Looks like `main` but is not a main function. + fun main(t: T): T { + println("foo.C.main(T): T") + return t + } +} + +object O { + fun main() { + println("foo.O.main()") + } + + // Looks like `main` but is not a main function. + fun main(t: T): T { + println("foo.O.main(T): T") + return t + } +} diff --git a/compiler/testData/ir/irText/declarations/mainFunctionMangling.kt.txt b/compiler/testData/ir/irText/declarations/mainFunctionMangling.kt.txt new file mode 100644 index 00000000000..7e24cff7c26 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/mainFunctionMangling.kt.txt @@ -0,0 +1,95 @@ +// FILE: a.kt + +fun main() { + println(message = "main()") +} + +fun main(t: T): T { + println(message = "main(T): T") + return t +} + +class C { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun main() { + println(message = "C.main()") + } + + fun main(t: T): T { + println(message = "C.main(T): T") + return t + } + +} + +object O { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun main() { + println(message = "O.main()") + } + + fun main(t: T): T { + println(message = "O.main(T): T") + return t + } + +} + +// FILE: b.kt +package foo + +fun main() { + println(message = "foo.main()") +} + +fun main(t: T): T { + println(message = "foo.main(T): T") + return t +} + +class C { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun main() { + println(message = "foo.C.main()") + } + + fun main(t: T): T { + println(message = "foo.C.main(T): T") + return t + } + +} + +object O { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + fun main() { + println(message = "foo.O.main()") + } + + fun main(t: T): T { + println(message = "foo.O.main(T): T") + return t + } + +} + diff --git a/compiler/testData/ir/irText/declarations/mainFunctionMangling.sig.kt.txt b/compiler/testData/ir/irText/declarations/mainFunctionMangling.sig.kt.txt new file mode 100644 index 00000000000..2dcca58eaf7 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/mainFunctionMangling.sig.kt.txt @@ -0,0 +1,165 @@ +// FILE: a.kt + +// CHECK: +// Mangled name: C +// Public signature: /C|null[0] +class C { + // CHECK: + // Mangled name: C#(){} + // Public signature: /C.|-5645683436151566731[0] + // Public signature debug description: (){} + constructor() /* primary */ + + // CHECK: + // Mangled name: C#main(){} + // Public signature: /C.main|-4284757841571462650[0] + // Public signature debug description: main(){} + fun main(): Unit + + // CHECK JVM_IR: + // Mangled name: C#main(0:0){0§}0:0 + // Public signature: /C.main|2157137022584307775[0] + // Public signature debug description: main(0:0){0§}0:0 + // CHECK JS_IR NATIVE: + // Mangled name: C#main(0:0){0§} + // Public signature: /C.main|-6008025846492417520[0] + // Public signature debug description: main(0:0){0§} + fun main(t: T): T + +} + +// CHECK: +// Mangled name: O +// Public signature: /O|null[0] +object O { + // CHECK: + // Mangled name: O#(){} + // Public signature: /O.|-5645683436151566731[0] + // Public signature debug description: (){} + private constructor() /* primary */ + + // CHECK: + // Mangled name: O#main(){} + // Public signature: /O.main|-4284757841571462650[0] + // Public signature debug description: main(){} + fun main(): Unit + + // CHECK JVM_IR: + // Mangled name: O#main(0:0){0§}0:0 + // Public signature: /O.main|2157137022584307775[0] + // Public signature debug description: main(0:0){0§}0:0 + // CHECK JS_IR NATIVE: + // Mangled name: O#main(0:0){0§} + // Public signature: /O.main|-6008025846492417520[0] + // Public signature debug description: main(0:0){0§} + fun main(t: T): T + +} + +// CHECK JVM_IR: +// Mangled name: #main(){} +// Mangled name for the signature by IR: main(){} +// Mangled name for the signature by Frontend: main(){}%a.kt +// Public signature by IR: /main|-4284757841571462650[0] +// Public signature by IR debug description: main(){} +// Public signature by Frontend: /main|2314384220441172254[0] +// Public signature by Frontend debug description: main(){}%a.kt +// CHECK JS_IR NATIVE: +// Mangled name: #main(){} +// Public signature: /main|-4284757841571462650[0] +// Public signature debug description: main(){} +fun main(): Unit + +// CHECK JVM_IR: +// Mangled name: #main(0:0){0§}0:0 +// Public signature: /main|2157137022584307775[0] +// Public signature debug description: main(0:0){0§}0:0 +// CHECK JS_IR NATIVE: +// Mangled name: #main(0:0){0§} +// Public signature: /main|-6008025846492417520[0] +// Public signature debug description: main(0:0){0§} +fun main(t: T): T + +// FILE: b.kt +package foo + +// CHECK: +// Mangled name: foo.C +// Public signature: foo/C|null[0] +class C { + // CHECK: + // Mangled name: foo.C#(){} + // Public signature: foo/C.|-5645683436151566731[0] + // Public signature debug description: (){} + constructor() /* primary */ + + // CHECK: + // Mangled name: foo.C#main(){} + // Public signature: foo/C.main|-4284757841571462650[0] + // Public signature debug description: main(){} + fun main(): Unit + + // CHECK JVM_IR: + // Mangled name: foo.C#main(0:0){0§}0:0 + // Public signature: foo/C.main|2157137022584307775[0] + // Public signature debug description: main(0:0){0§}0:0 + // CHECK JS_IR NATIVE: + // Mangled name: foo.C#main(0:0){0§} + // Public signature: foo/C.main|-6008025846492417520[0] + // Public signature debug description: main(0:0){0§} + fun main(t: T): T + +} + +// CHECK: +// Mangled name: foo.O +// Public signature: foo/O|null[0] +object O { + // CHECK: + // Mangled name: foo.O#(){} + // Public signature: foo/O.|-5645683436151566731[0] + // Public signature debug description: (){} + private constructor() /* primary */ + + // CHECK: + // Mangled name: foo.O#main(){} + // Public signature: foo/O.main|-4284757841571462650[0] + // Public signature debug description: main(){} + fun main(): Unit + + // CHECK JVM_IR: + // Mangled name: foo.O#main(0:0){0§}0:0 + // Public signature: foo/O.main|2157137022584307775[0] + // Public signature debug description: main(0:0){0§}0:0 + // CHECK JS_IR NATIVE: + // Mangled name: foo.O#main(0:0){0§} + // Public signature: foo/O.main|-6008025846492417520[0] + // Public signature debug description: main(0:0){0§} + fun main(t: T): T + +} + +// CHECK JVM_IR: +// Mangled name: foo#main(){} +// Mangled name for the signature by IR: main(){} +// Mangled name for the signature by Frontend: main(){}%b.kt +// Public signature by IR: foo/main|-4284757841571462650[0] +// Public signature by IR debug description: main(){} +// Public signature by Frontend: foo/main|8375568780578146760[0] +// Public signature by Frontend debug description: main(){}%b.kt +// CHECK JS_IR NATIVE: +// Mangled name: foo#main(){} +// Public signature: foo/main|-4284757841571462650[0] +// Public signature debug description: main(){} +fun main(): Unit + +// CHECK JVM_IR: +// Mangled name: foo#main(0:0){0§}0:0 +// Public signature: foo/main|2157137022584307775[0] +// Public signature debug description: main(0:0){0§}0:0 +// CHECK JS_IR NATIVE: +// Mangled name: foo#main(0:0){0§} +// Public signature: foo/main|-6008025846492417520[0] +// Public signature debug description: main(0:0){0§} +fun main(t: T): T + diff --git a/compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.ir.txt b/compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.ir.txt new file mode 100644 index 00000000000..99b95513095 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.ir.txt @@ -0,0 +1,20 @@ +FILE fqName: fileName:/a.kt + FUN name:main visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="main() in a.kt" +FILE fqName: fileName:/b.kt + FUN name:main visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="main() in b.kt" +FILE fqName:foo fileName:/c.kt + FUN name:main visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="foo.main() in c.kt" +FILE fqName:foo fileName:/d.kt + FUN name:main visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun println (message: kotlin.Any?): kotlin.Unit declared in kotlin.io' type=kotlin.Unit origin=null + message: CONST String type=kotlin.String value="foo.main() in d.kt" diff --git a/compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.kt b/compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.kt new file mode 100644 index 00000000000..ff09b2a0eb0 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.kt @@ -0,0 +1,29 @@ +// TARGET_BACKEND: JVM +// ^^^ Only JVM allows `main` functions in the same package but in different files. + +// FIR_IDENTICAL +// WITH_STDLIB + +// FILE: a.kt +fun main() { + println("main() in a.kt") +} + +// FILE: b.kt +fun main() { + println("main() in b.kt") +} + +// FILE: c.kt +package foo + +fun main() { + println("foo.main() in c.kt") +} + +// FILE: d.kt +package foo + +fun main() { + println("foo.main() in d.kt") +} diff --git a/compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.kt.txt b/compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.kt.txt new file mode 100644 index 00000000000..ede63548507 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.kt.txt @@ -0,0 +1,25 @@ +// FILE: a.kt + +fun main() { + println(message = "main() in a.kt") +} + +// FILE: b.kt + +fun main() { + println(message = "main() in b.kt") +} + +// FILE: c.kt +package foo + +fun main() { + println(message = "foo.main() in c.kt") +} + +// FILE: d.kt +package foo + +fun main() { + println(message = "foo.main() in d.kt") +} diff --git a/compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.sig.kt.txt b/compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.sig.kt.txt new file mode 100644 index 00000000000..059054a6f94 --- /dev/null +++ b/compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.sig.kt.txt @@ -0,0 +1,49 @@ +// FILE: a.kt + +// CHECK JVM_IR: +// Mangled name: #main(){} +// Mangled name for the signature by IR: main(){} +// Mangled name for the signature by Frontend: main(){}%a.kt +// Public signature by IR: /main|-4284757841571462650[0] +// Public signature by IR debug description: main(){} +// Public signature by Frontend: /main|2314384220441172254[0] +// Public signature by Frontend debug description: main(){}%a.kt +fun main(): Unit + +// FILE: b.kt + +// CHECK JVM_IR: +// Mangled name: #main(){} +// Mangled name for the signature by IR: main(){} +// Mangled name for the signature by Frontend: main(){}%b.kt +// Public signature by IR: /main|-4284757841571462650[0] +// Public signature by IR debug description: main(){} +// Public signature by Frontend: /main|8375568780578146760[0] +// Public signature by Frontend debug description: main(){}%b.kt +fun main(): Unit + +// FILE: c.kt +package foo + +// CHECK JVM_IR: +// Mangled name: foo#main(){} +// Mangled name for the signature by IR: main(){} +// Mangled name for the signature by Frontend: main(){}%c.kt +// Public signature by IR: foo/main|-4284757841571462650[0] +// Public signature by IR debug description: main(){} +// Public signature by Frontend: foo/main|-6421719669605920145[0] +// Public signature by Frontend debug description: main(){}%c.kt +fun main(): Unit + +// FILE: d.kt +package foo + +// CHECK JVM_IR: +// Mangled name: foo#main(){} +// Mangled name for the signature by IR: main(){} +// Mangled name for the signature by Frontend: main(){}%d.kt +// Public signature by IR: foo/main|-4284757841571462650[0] +// Public signature by IR debug description: main(){} +// Public signature by Frontend: foo/main|-405077377165952676[0] +// Public signature by Frontend debug description: main(){}%d.kt +fun main(): Unit 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 825ae3fd6c9..f8b720e0c26 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 @@ -540,6 +540,18 @@ public class ClassicJvmIrTextTestGenerated extends AbstractClassicJvmIrTextTest runTest("compiler/testData/ir/irText/declarations/localVarInDoWhile.kt"); } + @Test + @TestMetadata("mainFunctionMangling.kt") + public void testMainFunctionMangling() throws Exception { + runTest("compiler/testData/ir/irText/declarations/mainFunctionMangling.kt"); + } + + @Test + @TestMetadata("mainFunctionManglingInJvm.kt") + public void testMainFunctionManglingInJvm() throws Exception { + runTest("compiler/testData/ir/irText/declarations/mainFunctionManglingInJvm.kt"); + } + @Test @TestMetadata("packageLevelProperties.kt") public void testPackageLevelProperties() 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 8605ff69242..386c0107755 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibIrTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibIrTextTestCaseGenerated.java @@ -423,6 +423,11 @@ public class KlibIrTextTestCaseGenerated extends AbstractKlibIrTextTestCase { runTest("compiler/testData/ir/irText/declarations/localVarInDoWhile.kt"); } + @TestMetadata("mainFunctionMangling.kt") + public void testMainFunctionMangling() throws Exception { + runTest("compiler/testData/ir/irText/declarations/mainFunctionMangling.kt"); + } + @TestMetadata("packageLevelProperties.kt") public void testPackageLevelProperties() throws Exception { runTest("compiler/testData/ir/irText/declarations/packageLevelProperties.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 b79658dae75..cf912f91b5c 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 @@ -480,6 +480,12 @@ public class FirLightTreeJsIrTextTestGenerated extends AbstractFirLightTreeJsIrT runTest("compiler/testData/ir/irText/declarations/localVarInDoWhile.kt"); } + @Test + @TestMetadata("mainFunctionMangling.kt") + public void testMainFunctionMangling() throws Exception { + runTest("compiler/testData/ir/irText/declarations/mainFunctionMangling.kt"); + } + @Test @TestMetadata("packageLevelProperties.kt") public void testPackageLevelProperties() 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 8bfef4f007e..dac08bcb0ac 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 @@ -480,6 +480,12 @@ public class FirPsiJsIrTextTestGenerated extends AbstractFirPsiJsIrTextTest { runTest("compiler/testData/ir/irText/declarations/localVarInDoWhile.kt"); } + @Test + @TestMetadata("mainFunctionMangling.kt") + public void testMainFunctionMangling() throws Exception { + runTest("compiler/testData/ir/irText/declarations/mainFunctionMangling.kt"); + } + @Test @TestMetadata("packageLevelProperties.kt") public void testPackageLevelProperties() 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 f133195def0..42333087cab 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 @@ -480,6 +480,12 @@ public class ClassicJsIrTextTestGenerated extends AbstractClassicJsIrTextTest { runTest("compiler/testData/ir/irText/declarations/localVarInDoWhile.kt"); } + @Test + @TestMetadata("mainFunctionMangling.kt") + public void testMainFunctionMangling() throws Exception { + runTest("compiler/testData/ir/irText/declarations/mainFunctionMangling.kt"); + } + @Test @TestMetadata("packageLevelProperties.kt") public void testPackageLevelProperties() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/irtext/ClassicNativeIrTextTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/irtext/ClassicNativeIrTextTestGenerated.java index 7f04bb9d618..0e9401247fc 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/irtext/ClassicNativeIrTextTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/irtext/ClassicNativeIrTextTestGenerated.java @@ -480,6 +480,12 @@ public class ClassicNativeIrTextTestGenerated extends AbstractClassicNativeIrTex runTest("compiler/testData/ir/irText/declarations/localVarInDoWhile.kt"); } + @Test + @TestMetadata("mainFunctionMangling.kt") + public void testMainFunctionMangling() throws Exception { + runTest("compiler/testData/ir/irText/declarations/mainFunctionMangling.kt"); + } + @Test @TestMetadata("packageLevelProperties.kt") public void testPackageLevelProperties() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/irtext/FirLightTreeNativeIrTextTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/irtext/FirLightTreeNativeIrTextTestGenerated.java index 75453aef47c..f9aad8df6ac 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/irtext/FirLightTreeNativeIrTextTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/irtext/FirLightTreeNativeIrTextTestGenerated.java @@ -480,6 +480,12 @@ public class FirLightTreeNativeIrTextTestGenerated extends AbstractFirLightTreeN runTest("compiler/testData/ir/irText/declarations/localVarInDoWhile.kt"); } + @Test + @TestMetadata("mainFunctionMangling.kt") + public void testMainFunctionMangling() throws Exception { + runTest("compiler/testData/ir/irText/declarations/mainFunctionMangling.kt"); + } + @Test @TestMetadata("packageLevelProperties.kt") public void testPackageLevelProperties() throws Exception { diff --git a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/irtext/FirPsiNativeIrTextTestGenerated.java b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/irtext/FirPsiNativeIrTextTestGenerated.java index d5a929c0398..c2c718fb412 100644 --- a/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/irtext/FirPsiNativeIrTextTestGenerated.java +++ b/native/native.tests/tests-gen/org/jetbrains/kotlin/konan/test/irtext/FirPsiNativeIrTextTestGenerated.java @@ -480,6 +480,12 @@ public class FirPsiNativeIrTextTestGenerated extends AbstractFirPsiNativeIrTextT runTest("compiler/testData/ir/irText/declarations/localVarInDoWhile.kt"); } + @Test + @TestMetadata("mainFunctionMangling.kt") + public void testMainFunctionMangling() throws Exception { + runTest("compiler/testData/ir/irText/declarations/mainFunctionMangling.kt"); + } + @Test @TestMetadata("packageLevelProperties.kt") public void testPackageLevelProperties() throws Exception {