Get rid of eval on daemon completely, fixes also JSR 223 examples

This commit is contained in:
Ilya Chernikov
2017-02-09 10:00:01 +01:00
parent a3a782613a
commit 63aae56b11
7 changed files with 20 additions and 52 deletions
@@ -32,7 +32,6 @@ open class KotlinRemoteReplCompilerClient(
messageCollector: MessageCollector,
templateClasspath: List<File>,
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
@@ -190,8 +190,7 @@ interface CompileService : Remote {
compilationOptions: CompilationOptions,
servicesFacade: CompilerServicesFacadeBase,
templateClasspath: List<File>,
templateClassName: String,
scriptArgsWithTypes: ScriptArgsWithTypes?
templateClassName: String
): CallResult<Int>
@Throws(RemoteException::class)
@@ -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<ReplCodeLine>?
): CompileService.CallResult<ReplEvalResult> =
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<File>,
templateClassName: String,
scriptArgsWithTypes: ScriptArgsWithTypes?
templateClassName: String
): CompileService.CallResult<Int> = 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)
@@ -44,11 +44,10 @@ open class KotlinJvmReplService(
val portForServers: Int,
templateClasspath: List<File>,
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<RemoteReplStateFacadeServer, Boolean>() // 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<ReplCodeLine>?): ReplCompileResult = compile(defaultStateFacade.state, codeLine)
@Deprecated("eval is not supported on daemon")
fun compileAndEval(codeLine: ReplCodeLine, verifyHistory: List<ReplCodeLine>?): 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)
@@ -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<String>()), arrayOf(Array<String>::class)))
@@ -609,8 +609,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
emptyArray(),
TestMessageCollector(),
classpathFromClassloader(),
ScriptWithNoParam::class.qualifiedName!!,
ScriptArgsWithTypes(emptyArray(), emptyArray()))
ScriptWithNoParam::class.qualifiedName!!)
val compilerState = replCompiler.createState()
@@ -65,8 +65,7 @@ class KotlinJsr223JvmScriptEngine4Idea(
emptyArray(),
messageCollector,
templateClasspath,
templateClassName,
ScriptArgsWithTypes(emptyArray(), emptyArray()))
templateClassName)
}
}
@@ -57,8 +57,7 @@ class KotlinJsr223JvmDaemonCompileScriptEngine(
emptyArray(),
PrintingMessageCollector(PrintStream(compilerOut), MessageRenderer.WITHOUT_PATHS, false),
templateClasspath,
templateClassName,
getScriptArgs(context, scriptArgsTypes)!!)
templateClassName)
}
}