From 63aae56b11d498d91ba93ad6296eac4b3ca7fd61 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Thu, 9 Feb 2017 10:00:01 +0100 Subject: [PATCH] Get rid of eval on daemon completely, fixes also JSR 223 examples --- .../client/KotlinRemoteReplCompilerClient.kt | 4 +-- .../kotlin/daemon/common/CompileService.kt | 3 +-- .../kotlin/daemon/CompileServiceImpl.kt | 10 +++----- .../kotlin/daemon/KotlinRemoteReplService.kt | 24 +----------------- .../kotlin/daemon/CompilerDaemonTest.kt | 25 +++++++++---------- .../KotlinJsr223JvmScriptEngine4Idea.kt | 3 +-- ...otlinJsr223JvmDaemonCompileScriptEngine.kt | 3 +-- 7 files changed, 20 insertions(+), 52 deletions(-) diff --git a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinRemoteReplCompilerClient.kt b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinRemoteReplCompilerClient.kt index b3473721b2e..2911181a2a7 100644 --- a/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinRemoteReplCompilerClient.kt +++ b/compiler/daemon/daemon-client/src/org/jetbrains/kotlin/daemon/client/KotlinRemoteReplCompilerClient.kt @@ -32,7 +32,6 @@ open class KotlinRemoteReplCompilerClient( messageCollector: MessageCollector, templateClasspath: List, templateClassName: String, - scriptArgsWithTypes: ScriptArgsWithTypes, port: Int = SOCKET_ANY_FREE_PORT ) : ReplCompiler { val services = BasicCompilerServicesWithResultsFacadeServer(messageCollector, null, port) @@ -48,8 +47,7 @@ open class KotlinRemoteReplCompilerClient( emptyArray()), services, templateClasspath, - templateClassName, - scriptArgsWithTypes + templateClassName ).get() // dispose should be called at the end of the repl lifetime to free daemon repl session and appropriate resources diff --git a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompileService.kt b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompileService.kt index 8a667b0cc8c..af8316c7344 100644 --- a/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompileService.kt +++ b/compiler/daemon/daemon-common/src/org/jetbrains/kotlin/daemon/common/CompileService.kt @@ -190,8 +190,7 @@ interface CompileService : Remote { compilationOptions: CompilationOptions, servicesFacade: CompilerServicesFacadeBase, templateClasspath: List, - templateClassName: String, - scriptArgsWithTypes: ScriptArgsWithTypes? + templateClassName: String ): CallResult @Throws(RemoteException::class) diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt index a5219398f5b..3760749450c 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/CompileServiceImpl.kt @@ -455,7 +455,6 @@ class CompileServiceImpl( val compilerMessagesStream = PrintStream(BufferedOutputStream(RemoteOutputStreamClient(compilerMessagesOutputStream, DummyProfiler()), REMOTE_STREAM_BUFFER_SIZE)) val messageCollector = KeepFirstErrorMessageCollector(compilerMessagesStream) val repl = KotlinJvmReplService(disposable, port, templateClasspath, templateClassName, - scriptArgs?.let { ScriptArgsWithTypes(it, scriptArgsTypes?.map { it.kotlin }?.toTypedArray() ?: emptyArray()) }, messageCollector, operationsTracer) val sessionId = state.sessions.leaseSession(ClientOrSessionProxy(aliveFlagPath, repl, disposable)) @@ -486,9 +485,7 @@ class CompileServiceImpl( history: List? ): CompileService.CallResult = ifAlive(minAliveness = Aliveness.Alive) { - withValidRepl(sessionId) { - CompileService.CallResult.Good(compileAndEval(codeLine, verifyHistory = history)) - } + CompileService.CallResult.Error("Eval on daemon is not supported") } override fun leaseReplSession(aliveFlagPath: String?, @@ -496,8 +493,7 @@ class CompileServiceImpl( compilationOptions: CompilationOptions, servicesFacade: CompilerServicesFacadeBase, templateClasspath: List, - templateClassName: String, - scriptArgsWithTypes: ScriptArgsWithTypes? + templateClassName: String ): CompileService.CallResult = ifAlive(minAliveness = Aliveness.Alive) { if (compilationOptions.targetPlatform != CompileService.TargetPlatform.JVM) CompileService.CallResult.Error("Sorry, only JVM target platform is supported now") @@ -505,7 +501,7 @@ class CompileServiceImpl( val disposable = Disposer.newDisposable() val messageCollector = CompileServicesFacadeMessageCollector(servicesFacade, compilationOptions) val repl = KotlinJvmReplService(disposable, port, templateClasspath, templateClassName, - scriptArgsWithTypes, messageCollector, null) + messageCollector, null) val sessionId = state.sessions.leaseSession(ClientOrSessionProxy(aliveFlagPath, repl, disposable)) CompileService.CallResult.Good(sessionId) diff --git a/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinRemoteReplService.kt b/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinRemoteReplService.kt index 86450f02d4c..750e40e8232 100644 --- a/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinRemoteReplService.kt +++ b/compiler/daemon/src/org/jetbrains/kotlin/daemon/KotlinRemoteReplService.kt @@ -44,11 +44,10 @@ open class KotlinJvmReplService( val portForServers: Int, templateClasspath: List, templateClassName: String, - protected val fallbackScriptArgs: ScriptArgsWithTypes?, protected val messageCollector: MessageCollector, @Deprecated("drop it") protected val operationsTracer: RemoteOperationsTracer? -) : ReplCompileAction, ReplAtomicEvalAction, ReplCheckAction, CreateReplStageStateAction { +) : ReplCompileAction, ReplCheckAction, CreateReplStageStateAction { protected val configuration = CompilerConfiguration().apply { addJvmClasspathRoots(PathUtil.getJdkClassesRoots()) @@ -90,12 +89,6 @@ open class KotlinJvmReplService( else GenericReplCompiler(disposable, scriptDef, configuration, messageCollector) } - private val replEvaluator: ReplFullEvaluator? by lazy { - replCompiler?.let { compiler -> - GenericReplCompilingEvaluator(compiler, configuration.jvmClasspathRoots, null, fallbackScriptArgs, ReplRepeatingMode.NONE) - } - } - protected val statesLock = ReentrantReadWriteLock() // TODO: consider using values here for session cleanup protected val states = WeakHashMap() // used as (missing) WeakHashSet @@ -128,27 +121,12 @@ open class KotlinJvmReplService( } } - @Deprecated("eval is not supported on daemon") - override fun compileAndEval(state: IReplStageState<*>, codeLine: ReplCodeLine, scriptArgs: ScriptArgsWithTypes?, invokeWrapper: InvokeWrapper?): ReplEvalResult { - operationsTracer?.before("eval") - try { - return replEvaluator?.compileAndEval(state, codeLine, scriptArgs ?: fallbackScriptArgs, invokeWrapper) - ?: ReplEvalResult.Error.Runtime("Initialization error") - } - finally { - operationsTracer?.after("eval") - } - } - @Deprecated("Use check(state, line) instead") fun check(codeLine: ReplCodeLine): ReplCheckResult = check(defaultStateFacade.state, codeLine) @Deprecated("Use compile(state, line) instead") fun compile(codeLine: ReplCodeLine, verifyHistory: List?): ReplCompileResult = compile(defaultStateFacade.state, codeLine) - @Deprecated("eval is not supported on daemon") - fun compileAndEval(codeLine: ReplCodeLine, verifyHistory: List?): ReplEvalResult = ReplEvalResult.Error.Runtime("Eval is not supported on daemon") - fun createRemoteState(port: Int = portForServers): RemoteReplStateFacadeServer = statesLock.write { val id = getValidId(stateIdCounter) { id -> states.none { it.key.getId() == id} } val stateFacade = RemoteReplStateFacadeServer(id, createState().asState(GenericReplCompilerState::class.java), port) diff --git a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt index 95ea70567cc..34f2055e8ec 100644 --- a/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt +++ b/compiler/tests/org/jetbrains/kotlin/daemon/CompilerDaemonTest.kt @@ -534,12 +534,12 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { fun testDaemonReplLocalEvalNoParams() { withDaemon { daemon -> - val repl = KotlinRemoteReplCompilerClient(daemon!!, null, CompileService.TargetPlatform.JVM, - emptyArray(), - TestMessageCollector(), - classpathFromClassloader(), - ScriptWithNoParam::class.qualifiedName!!, - ScriptArgsWithTypes(emptyArray(), emptyArray())) + withDisposable { disposable -> + val repl = KotlinRemoteReplCompilerClient(daemon!!, null, CompileService.TargetPlatform.JVM, + emptyArray(), + TestMessageCollector(), + classpathFromClassloader(), + ScriptWithNoParam::class.qualifiedName!!) val localEvaluator = GenericReplEvaluator(emptyList(), Thread.currentThread().contextClassLoader) @@ -550,11 +550,11 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { fun testDaemonReplLocalEvalStandardTemplate() { withDaemon { daemon -> - val repl = KotlinRemoteReplCompilerClient(disposable, daemon!!, null, CompileService.TargetPlatform.JVM, emptyArray(), - TestMessageCollector(), - classpathFromClassloader(), - "kotlin.script.templates.standard.ScriptTemplateWithArgs", - ScriptArgsWithTypes(emptyArray(), emptyArray())) + withDisposable { disposable -> + val repl = KotlinRemoteReplCompilerClient(daemon!!, null, CompileService.TargetPlatform.JVM, emptyArray(), + TestMessageCollector(), + classpathFromClassloader(), + "kotlin.script.templates.standard.ScriptTemplateWithArgs") val localEvaluator = GenericReplEvaluator(emptyList(), Thread.currentThread().contextClassLoader, ScriptArgsWithTypes(arrayOf(emptyArray()), arrayOf(Array::class))) @@ -609,8 +609,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() { emptyArray(), TestMessageCollector(), classpathFromClassloader(), - ScriptWithNoParam::class.qualifiedName!!, - ScriptArgsWithTypes(emptyArray(), emptyArray())) + ScriptWithNoParam::class.qualifiedName!!) val compilerState = replCompiler.createState() diff --git a/idea/idea-repl/src/org/jetbrains/kotlin/jsr223/KotlinJsr223JvmScriptEngine4Idea.kt b/idea/idea-repl/src/org/jetbrains/kotlin/jsr223/KotlinJsr223JvmScriptEngine4Idea.kt index 801577ec6b4..185cc9168e9 100644 --- a/idea/idea-repl/src/org/jetbrains/kotlin/jsr223/KotlinJsr223JvmScriptEngine4Idea.kt +++ b/idea/idea-repl/src/org/jetbrains/kotlin/jsr223/KotlinJsr223JvmScriptEngine4Idea.kt @@ -65,8 +65,7 @@ class KotlinJsr223JvmScriptEngine4Idea( emptyArray(), messageCollector, templateClasspath, - templateClassName, - ScriptArgsWithTypes(emptyArray(), emptyArray())) + templateClassName) } } diff --git a/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/jsr223/KotlinJsr223JvmDaemonCompileScriptEngine.kt b/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/jsr223/KotlinJsr223JvmDaemonCompileScriptEngine.kt index f6cbab45b11..3838e75d261 100644 --- a/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/jsr223/KotlinJsr223JvmDaemonCompileScriptEngine.kt +++ b/libraries/tools/kotlin-script-util/src/main/kotlin/org/jetbrains/kotlin/script/jsr223/KotlinJsr223JvmDaemonCompileScriptEngine.kt @@ -57,8 +57,7 @@ class KotlinJsr223JvmDaemonCompileScriptEngine( emptyArray(), PrintingMessageCollector(PrintStream(compilerOut), MessageRenderer.WITHOUT_PATHS, false), templateClasspath, - templateClassName, - getScriptArgs(context, scriptArgsTypes)!!) + templateClassName) } }