diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/DeclarationOrigins.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/DeclarationOrigins.kt index e484c27bbd6..fdbc2ba37a1 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/DeclarationOrigins.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/DeclarationOrigins.kt @@ -33,7 +33,6 @@ interface JvmLoweredDeclarationOrigin : IrDeclarationOrigin { object STATIC_INLINE_CLASS_REPLACEMENT : IrDeclarationOriginImpl("STATIC_INLINE_CLASS_REPLACEMENT") object GENERATED_ASSERTION_ENABLED_FIELD : IrDeclarationOriginImpl("GENERATED_ASSERTION_ENABLED_FIELD", isSynthetic = true) object GENERATED_EXTENDED_MAIN : IrDeclarationOriginImpl("GENERATED_EXTENDED_MAIN", isSynthetic = true) - object SUSPEND_FUNCTION_VIEW : IrDeclarationOriginImpl("SUSPEND_FUNCTION_VIEW") object SUSPEND_IMPL_STATIC_FUNCTION : IrDeclarationOriginImpl("SUSPEND_IMPL_STATIC_FUNCTION", isSynthetic = true) object INTERFACE_COMPANION_PRIVATE_INSTANCE : IrDeclarationOriginImpl("INTERFACE_COMPANION_PRIVATE_INSTANCE", isSynthetic = true) object POLYMORPHIC_SIGNATURE_INSTANTIATION : IrDeclarationOriginImpl("POLYMORPHIC_SIGNATURE_INSTANTIATION", isSynthetic = true) diff --git a/compiler/testData/integration/smoke/helloAppFQMainIR/hello.compile.expected b/compiler/testData/integration/smoke/helloAppFQMainIR/hello.compile.expected new file mode 100644 index 00000000000..a14ac74940f --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppFQMainIR/hello.compile.expected @@ -0,0 +1 @@ +Return code: 0 diff --git a/compiler/testData/integration/smoke/helloAppFQMainIR/hello.kt b/compiler/testData/integration/smoke/helloAppFQMainIR/hello.kt new file mode 100644 index 00000000000..b6b68d62f4d --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppFQMainIR/hello.kt @@ -0,0 +1,6 @@ +package Hello + +fun main(args: kotlin.Array) { + args.size + System.out.println("Hello from fully qualified main!") +} diff --git a/compiler/testData/integration/smoke/helloAppFQMainIR/hello.run.expected b/compiler/testData/integration/smoke/helloAppFQMainIR/hello.run.expected new file mode 100644 index 00000000000..f052dde0a17 --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppFQMainIR/hello.run.expected @@ -0,0 +1,4 @@ +OUT: +Hello from fully qualified main! + +Return code: 0 diff --git a/compiler/testData/integration/smoke/helloAppIR/hello.compile.expected b/compiler/testData/integration/smoke/helloAppIR/hello.compile.expected new file mode 100644 index 00000000000..a14ac74940f --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppIR/hello.compile.expected @@ -0,0 +1 @@ +Return code: 0 diff --git a/compiler/testData/integration/smoke/helloAppIR/hello.kt b/compiler/testData/integration/smoke/helloAppIR/hello.kt new file mode 100644 index 00000000000..54674a02472 --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppIR/hello.kt @@ -0,0 +1,5 @@ +package Hello + +fun main() { + System.out.println("Hello!") +} diff --git a/compiler/testData/integration/smoke/helloAppIR/hello.run.expected b/compiler/testData/integration/smoke/helloAppIR/hello.run.expected new file mode 100644 index 00000000000..fd58d467c30 --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppIR/hello.run.expected @@ -0,0 +1,4 @@ +OUT: +Hello! + +Return code: 0 diff --git a/compiler/testData/integration/smoke/helloAppOldAndParameterlessMainIR/hello.compile.expected b/compiler/testData/integration/smoke/helloAppOldAndParameterlessMainIR/hello.compile.expected new file mode 100644 index 00000000000..a14ac74940f --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppOldAndParameterlessMainIR/hello.compile.expected @@ -0,0 +1 @@ +Return code: 0 diff --git a/compiler/testData/integration/smoke/helloAppOldAndParameterlessMainIR/hello.kt b/compiler/testData/integration/smoke/helloAppOldAndParameterlessMainIR/hello.kt new file mode 100644 index 00000000000..b5c9eb3b90e --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppOldAndParameterlessMainIR/hello.kt @@ -0,0 +1,10 @@ +package Hello + +fun main(args: Array) { + args.size + System.out.println("Hello!") +} + +fun main() { + System.out.println("Fail") +} diff --git a/compiler/testData/integration/smoke/helloAppOldAndParameterlessMainIR/hello.run.expected b/compiler/testData/integration/smoke/helloAppOldAndParameterlessMainIR/hello.run.expected new file mode 100644 index 00000000000..fd58d467c30 --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppOldAndParameterlessMainIR/hello.run.expected @@ -0,0 +1,4 @@ +OUT: +Hello! + +Return code: 0 diff --git a/compiler/testData/integration/smoke/helloAppParameterlessMainIR/hello.compile.expected b/compiler/testData/integration/smoke/helloAppParameterlessMainIR/hello.compile.expected new file mode 100644 index 00000000000..a14ac74940f --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppParameterlessMainIR/hello.compile.expected @@ -0,0 +1 @@ +Return code: 0 diff --git a/compiler/testData/integration/smoke/helloAppParameterlessMainIR/hello.kt b/compiler/testData/integration/smoke/helloAppParameterlessMainIR/hello.kt new file mode 100644 index 00000000000..54674a02472 --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppParameterlessMainIR/hello.kt @@ -0,0 +1,5 @@ +package Hello + +fun main() { + System.out.println("Hello!") +} diff --git a/compiler/testData/integration/smoke/helloAppParameterlessMainIR/hello.run.expected b/compiler/testData/integration/smoke/helloAppParameterlessMainIR/hello.run.expected new file mode 100644 index 00000000000..fd58d467c30 --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppParameterlessMainIR/hello.run.expected @@ -0,0 +1,4 @@ +OUT: +Hello! + +Return code: 0 diff --git a/compiler/testData/integration/smoke/helloAppSuspendMainIR/hello.compile.expected b/compiler/testData/integration/smoke/helloAppSuspendMainIR/hello.compile.expected new file mode 100644 index 00000000000..a14ac74940f --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppSuspendMainIR/hello.compile.expected @@ -0,0 +1 @@ +Return code: 0 diff --git a/compiler/testData/integration/smoke/helloAppSuspendMainIR/hello.kt b/compiler/testData/integration/smoke/helloAppSuspendMainIR/hello.kt new file mode 100644 index 00000000000..6d04a9e3581 --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppSuspendMainIR/hello.kt @@ -0,0 +1,35 @@ +package Hello + +import kotlin.concurrent.thread +import kotlin.coroutines.suspendCoroutine +import kotlin.coroutines.resume + +@kotlin.jvm.Volatile +private var result = "" +@kotlin.jvm.Volatile +private var callback: Function0? = null + +suspend fun appendAndSuspend(s: String) { + result += s + + suspendCoroutine { continuation -> + callback = { + continuation.resume(Unit) + } + } +} + +suspend fun main(args: Array) { + thread(isDaemon = true) { + while (true) { + val c = callback + c?.invoke() + Thread.sleep(500) + } + } + + appendAndSuspend(args[0]) + appendAndSuspend(args[1]) + println(result) + callback = null +} diff --git a/compiler/testData/integration/smoke/helloAppSuspendMainIR/hello.run.expected b/compiler/testData/integration/smoke/helloAppSuspendMainIR/hello.run.expected new file mode 100644 index 00000000000..4000785a4d1 --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppSuspendMainIR/hello.run.expected @@ -0,0 +1,4 @@ +OUT: +OK + +Return code: 0 diff --git a/compiler/testData/integration/smoke/helloAppSuspendMainInMultifileIR/hello.compile.expected b/compiler/testData/integration/smoke/helloAppSuspendMainInMultifileIR/hello.compile.expected new file mode 100644 index 00000000000..a14ac74940f --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppSuspendMainInMultifileIR/hello.compile.expected @@ -0,0 +1 @@ +Return code: 0 diff --git a/compiler/testData/integration/smoke/helloAppSuspendMainInMultifileIR/hello.kt b/compiler/testData/integration/smoke/helloAppSuspendMainInMultifileIR/hello.kt new file mode 100644 index 00000000000..f71af621f9a --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppSuspendMainInMultifileIR/hello.kt @@ -0,0 +1,37 @@ +@file:JvmMultifileClass +@file:JvmName("Foo") +package Hello + +import kotlin.concurrent.thread +import kotlin.coroutines.suspendCoroutine +import kotlin.coroutines.resume + +@kotlin.jvm.Volatile +private var result = "" +@kotlin.jvm.Volatile +private var callback: Function0? = null + +suspend fun appendAndSuspend(s: String) { + result += s + + suspendCoroutine { continuation -> + callback = { + continuation.resume(Unit) + } + } +} + +suspend fun main(args: Array) { + thread(isDaemon = true) { + while (true) { + val c = callback + c?.invoke() + Thread.sleep(500) + } + } + + appendAndSuspend(args[0]) + appendAndSuspend(args[1]) + println(result) + callback = null +} diff --git a/compiler/testData/integration/smoke/helloAppSuspendMainInMultifileIR/hello.run.expected b/compiler/testData/integration/smoke/helloAppSuspendMainInMultifileIR/hello.run.expected new file mode 100644 index 00000000000..4000785a4d1 --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppSuspendMainInMultifileIR/hello.run.expected @@ -0,0 +1,4 @@ +OUT: +OK + +Return code: 0 diff --git a/compiler/testData/integration/smoke/helloAppSuspendParameterlessMainIR/hello.compile.expected b/compiler/testData/integration/smoke/helloAppSuspendParameterlessMainIR/hello.compile.expected new file mode 100644 index 00000000000..a14ac74940f --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppSuspendParameterlessMainIR/hello.compile.expected @@ -0,0 +1 @@ +Return code: 0 diff --git a/compiler/testData/integration/smoke/helloAppSuspendParameterlessMainIR/hello.kt b/compiler/testData/integration/smoke/helloAppSuspendParameterlessMainIR/hello.kt new file mode 100644 index 00000000000..473bde1e5d8 --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppSuspendParameterlessMainIR/hello.kt @@ -0,0 +1,36 @@ +package Hello + +import kotlin.concurrent.thread +import kotlin.coroutines.suspendCoroutine +import kotlin.coroutines.resume +import kotlin.reflect.jvm.javaMethod + +@kotlin.jvm.Volatile +private var result = "" +@kotlin.jvm.Volatile +private var callback: Function0? = null + +suspend fun appendAndSuspend(s: String) { + result += s + + suspendCoroutine { continuation -> + callback = { + continuation.resume(Unit) + } + } +} + +suspend fun main() { + thread(isDaemon = true) { + while (true) { + val c = callback + c?.invoke() + Thread.sleep(500) + } + } + + appendAndSuspend("O") + appendAndSuspend("K") + println(result) + callback = null +} diff --git a/compiler/testData/integration/smoke/helloAppSuspendParameterlessMainIR/hello.run.expected b/compiler/testData/integration/smoke/helloAppSuspendParameterlessMainIR/hello.run.expected new file mode 100644 index 00000000000..4000785a4d1 --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppSuspendParameterlessMainIR/hello.run.expected @@ -0,0 +1,4 @@ +OUT: +OK + +Return code: 0 diff --git a/compiler/testData/integration/smoke/helloAppVarargMainIR/hello.compile.expected b/compiler/testData/integration/smoke/helloAppVarargMainIR/hello.compile.expected new file mode 100644 index 00000000000..a14ac74940f --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppVarargMainIR/hello.compile.expected @@ -0,0 +1 @@ +Return code: 0 diff --git a/compiler/testData/integration/smoke/helloAppVarargMainIR/hello.kt b/compiler/testData/integration/smoke/helloAppVarargMainIR/hello.kt new file mode 100644 index 00000000000..0382047311b --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppVarargMainIR/hello.kt @@ -0,0 +1,6 @@ +package Hello + +fun main(vararg args: kotlin.String) { + args.size + System.out.println("Hello from vararg main!") +} diff --git a/compiler/testData/integration/smoke/helloAppVarargMainIR/hello.run.expected b/compiler/testData/integration/smoke/helloAppVarargMainIR/hello.run.expected new file mode 100644 index 00000000000..bb985624029 --- /dev/null +++ b/compiler/testData/integration/smoke/helloAppVarargMainIR/hello.run.expected @@ -0,0 +1,4 @@ +OUT: +Hello from vararg main! + +Return code: 0 diff --git a/compiler/testData/integration/smoke/simplestSuspendMainIR/hello.compile.expected b/compiler/testData/integration/smoke/simplestSuspendMainIR/hello.compile.expected new file mode 100644 index 00000000000..a14ac74940f --- /dev/null +++ b/compiler/testData/integration/smoke/simplestSuspendMainIR/hello.compile.expected @@ -0,0 +1 @@ +Return code: 0 diff --git a/compiler/testData/integration/smoke/simplestSuspendMainIR/hello.kt b/compiler/testData/integration/smoke/simplestSuspendMainIR/hello.kt new file mode 100644 index 00000000000..602f561a07f --- /dev/null +++ b/compiler/testData/integration/smoke/simplestSuspendMainIR/hello.kt @@ -0,0 +1,10 @@ +package Hello + +suspend fun f(o: String, k: String): String { + return o + k +} + +suspend fun main(args: Array) { + val result = f(args[0], args[1]) + println(result) +} diff --git a/compiler/testData/integration/smoke/simplestSuspendMainIR/hello.run.expected b/compiler/testData/integration/smoke/simplestSuspendMainIR/hello.run.expected new file mode 100644 index 00000000000..4000785a4d1 --- /dev/null +++ b/compiler/testData/integration/smoke/simplestSuspendMainIR/hello.run.expected @@ -0,0 +1,4 @@ +OUT: +OK + +Return code: 0 diff --git a/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTest.java b/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTest.java index cec47c1a2d4..4f4f3dd337e 100644 --- a/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTest.java +++ b/compiler/tests/org/jetbrains/kotlin/integration/CompilerSmokeTest.java @@ -29,6 +29,13 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase { run("hello.run", "-cp", jar, "Hello.HelloKt"); } + public void testHelloAppIR() throws Exception { + String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar"; + + assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "-Xuse-ir", "hello.kt", "-d", jar)); + run("hello.run", "-cp", jar, "Hello.HelloKt"); + } + public void testHelloAppFQMain() throws Exception { String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar"; @@ -36,6 +43,13 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase { run("hello.run", "-cp", jar, "Hello.HelloKt"); } + public void testHelloAppFQMainIR() throws Exception { + String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar"; + + assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "-Xuse-ir", "hello.kt", "-d", jar)); + run("hello.run", "-cp", jar, "Hello.HelloKt"); + } + public void testHelloAppVarargMain() throws Exception { String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar"; @@ -43,6 +57,13 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase { run("hello.run", "-cp", jar, "Hello.HelloKt"); } + public void testHelloAppVarargMainIR() throws Exception { + String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar"; + + assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "-Xuse-ir", "hello.kt", "-d", jar)); + run("hello.run", "-cp", jar, "Hello.HelloKt"); + } + public void testHelloAppSuspendMain() throws Exception { String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar"; @@ -57,6 +78,13 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase { run("hello.run", "-cp", jar, "Hello.Foo", "O", "K"); } + public void testHelloAppSuspendMainInMultifileIR() throws Exception { + String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar"; + + assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "-Xuse-ir", "hello.kt", "-d", jar)); + run("hello.run", "-cp", jar, "Hello.Foo", "O", "K"); + } + public void testHelloAppParameterlessMain() throws Exception { String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar"; @@ -64,6 +92,13 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase { run("hello.run", "-cp", jar, "Hello.HelloKt"); } + public void testHelloAppParameterlessMainIR() throws Exception { + String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar"; + + assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "-Xuse-ir", "hello.kt", "-d", jar)); + run("hello.run", "-cp", jar, "Hello.HelloKt"); + } + public void testHelloAppOldAndParameterlessMain() throws Exception { String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar"; @@ -71,6 +106,13 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase { run("hello.run", "-cp", jar, "Hello.HelloKt"); } + public void testHelloAppOldAndParameterlessMainIR() throws Exception { + String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar"; + + assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "-Xuse-ir", "hello.kt", "-d", jar)); + run("hello.run", "-cp", jar, "Hello.HelloKt"); + } + public void testHelloAppSuspendParameterlessMain() throws Exception { String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar"; @@ -78,6 +120,20 @@ public class CompilerSmokeTest extends CompilerSmokeTestBase { run("hello.run", "-cp", jar, "Hello.HelloKt", "O", "K"); } + public void testHelloAppSuspendParameterlessMainIR() throws Exception { + String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar"; + + assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "-Xuse-ir", "hello.kt", "-d", jar)); + run("hello.run", "-cp", jar, "Hello.HelloKt", "O", "K"); + } + + public void testSimplestSuspendMainIR() throws Exception { + String jar = tmpdir.getAbsolutePath() + File.separator + "hello.jar"; + + assertEquals("compilation failed", 0, runCompiler("hello.compile", "-include-runtime", "-Xuse-ir", "hello.kt", "-d", jar)); + run("hello.run", "-cp", jar, "Hello.HelloKt", "O", "K"); + } + public void testCompilationFailed() throws Exception { String jar = tmpdir.getAbsolutePath() + File.separator + "smoke.jar";