Get rid of eval on daemon completely, fixes also JSR 223 examples
This commit is contained in:
+1
-3
@@ -32,7 +32,6 @@ open class KotlinRemoteReplCompilerClient(
|
|||||||
messageCollector: MessageCollector,
|
messageCollector: MessageCollector,
|
||||||
templateClasspath: List<File>,
|
templateClasspath: List<File>,
|
||||||
templateClassName: String,
|
templateClassName: String,
|
||||||
scriptArgsWithTypes: ScriptArgsWithTypes,
|
|
||||||
port: Int = SOCKET_ANY_FREE_PORT
|
port: Int = SOCKET_ANY_FREE_PORT
|
||||||
) : ReplCompiler {
|
) : ReplCompiler {
|
||||||
val services = BasicCompilerServicesWithResultsFacadeServer(messageCollector, null, port)
|
val services = BasicCompilerServicesWithResultsFacadeServer(messageCollector, null, port)
|
||||||
@@ -48,8 +47,7 @@ open class KotlinRemoteReplCompilerClient(
|
|||||||
emptyArray()),
|
emptyArray()),
|
||||||
services,
|
services,
|
||||||
templateClasspath,
|
templateClasspath,
|
||||||
templateClassName,
|
templateClassName
|
||||||
scriptArgsWithTypes
|
|
||||||
).get()
|
).get()
|
||||||
|
|
||||||
// dispose should be called at the end of the repl lifetime to free daemon repl session and appropriate resources
|
// dispose should be called at the end of the repl lifetime to free daemon repl session and appropriate resources
|
||||||
|
|||||||
+1
-2
@@ -190,8 +190,7 @@ interface CompileService : Remote {
|
|||||||
compilationOptions: CompilationOptions,
|
compilationOptions: CompilationOptions,
|
||||||
servicesFacade: CompilerServicesFacadeBase,
|
servicesFacade: CompilerServicesFacadeBase,
|
||||||
templateClasspath: List<File>,
|
templateClasspath: List<File>,
|
||||||
templateClassName: String,
|
templateClassName: String
|
||||||
scriptArgsWithTypes: ScriptArgsWithTypes?
|
|
||||||
): CallResult<Int>
|
): CallResult<Int>
|
||||||
|
|
||||||
@Throws(RemoteException::class)
|
@Throws(RemoteException::class)
|
||||||
|
|||||||
@@ -455,7 +455,6 @@ class CompileServiceImpl(
|
|||||||
val compilerMessagesStream = PrintStream(BufferedOutputStream(RemoteOutputStreamClient(compilerMessagesOutputStream, DummyProfiler()), REMOTE_STREAM_BUFFER_SIZE))
|
val compilerMessagesStream = PrintStream(BufferedOutputStream(RemoteOutputStreamClient(compilerMessagesOutputStream, DummyProfiler()), REMOTE_STREAM_BUFFER_SIZE))
|
||||||
val messageCollector = KeepFirstErrorMessageCollector(compilerMessagesStream)
|
val messageCollector = KeepFirstErrorMessageCollector(compilerMessagesStream)
|
||||||
val repl = KotlinJvmReplService(disposable, port, templateClasspath, templateClassName,
|
val repl = KotlinJvmReplService(disposable, port, templateClasspath, templateClassName,
|
||||||
scriptArgs?.let { ScriptArgsWithTypes(it, scriptArgsTypes?.map { it.kotlin }?.toTypedArray() ?: emptyArray()) },
|
|
||||||
messageCollector, operationsTracer)
|
messageCollector, operationsTracer)
|
||||||
val sessionId = state.sessions.leaseSession(ClientOrSessionProxy(aliveFlagPath, repl, disposable))
|
val sessionId = state.sessions.leaseSession(ClientOrSessionProxy(aliveFlagPath, repl, disposable))
|
||||||
|
|
||||||
@@ -486,9 +485,7 @@ class CompileServiceImpl(
|
|||||||
history: List<ReplCodeLine>?
|
history: List<ReplCodeLine>?
|
||||||
): CompileService.CallResult<ReplEvalResult> =
|
): CompileService.CallResult<ReplEvalResult> =
|
||||||
ifAlive(minAliveness = Aliveness.Alive) {
|
ifAlive(minAliveness = Aliveness.Alive) {
|
||||||
withValidRepl(sessionId) {
|
CompileService.CallResult.Error("Eval on daemon is not supported")
|
||||||
CompileService.CallResult.Good(compileAndEval(codeLine, verifyHistory = history))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun leaseReplSession(aliveFlagPath: String?,
|
override fun leaseReplSession(aliveFlagPath: String?,
|
||||||
@@ -496,8 +493,7 @@ class CompileServiceImpl(
|
|||||||
compilationOptions: CompilationOptions,
|
compilationOptions: CompilationOptions,
|
||||||
servicesFacade: CompilerServicesFacadeBase,
|
servicesFacade: CompilerServicesFacadeBase,
|
||||||
templateClasspath: List<File>,
|
templateClasspath: List<File>,
|
||||||
templateClassName: String,
|
templateClassName: String
|
||||||
scriptArgsWithTypes: ScriptArgsWithTypes?
|
|
||||||
): CompileService.CallResult<Int> = ifAlive(minAliveness = Aliveness.Alive) {
|
): CompileService.CallResult<Int> = ifAlive(minAliveness = Aliveness.Alive) {
|
||||||
if (compilationOptions.targetPlatform != CompileService.TargetPlatform.JVM)
|
if (compilationOptions.targetPlatform != CompileService.TargetPlatform.JVM)
|
||||||
CompileService.CallResult.Error("Sorry, only JVM target platform is supported now")
|
CompileService.CallResult.Error("Sorry, only JVM target platform is supported now")
|
||||||
@@ -505,7 +501,7 @@ class CompileServiceImpl(
|
|||||||
val disposable = Disposer.newDisposable()
|
val disposable = Disposer.newDisposable()
|
||||||
val messageCollector = CompileServicesFacadeMessageCollector(servicesFacade, compilationOptions)
|
val messageCollector = CompileServicesFacadeMessageCollector(servicesFacade, compilationOptions)
|
||||||
val repl = KotlinJvmReplService(disposable, port, templateClasspath, templateClassName,
|
val repl = KotlinJvmReplService(disposable, port, templateClasspath, templateClassName,
|
||||||
scriptArgsWithTypes, messageCollector, null)
|
messageCollector, null)
|
||||||
val sessionId = state.sessions.leaseSession(ClientOrSessionProxy(aliveFlagPath, repl, disposable))
|
val sessionId = state.sessions.leaseSession(ClientOrSessionProxy(aliveFlagPath, repl, disposable))
|
||||||
|
|
||||||
CompileService.CallResult.Good(sessionId)
|
CompileService.CallResult.Good(sessionId)
|
||||||
|
|||||||
@@ -44,11 +44,10 @@ open class KotlinJvmReplService(
|
|||||||
val portForServers: Int,
|
val portForServers: Int,
|
||||||
templateClasspath: List<File>,
|
templateClasspath: List<File>,
|
||||||
templateClassName: String,
|
templateClassName: String,
|
||||||
protected val fallbackScriptArgs: ScriptArgsWithTypes?,
|
|
||||||
protected val messageCollector: MessageCollector,
|
protected val messageCollector: MessageCollector,
|
||||||
@Deprecated("drop it")
|
@Deprecated("drop it")
|
||||||
protected val operationsTracer: RemoteOperationsTracer?
|
protected val operationsTracer: RemoteOperationsTracer?
|
||||||
) : ReplCompileAction, ReplAtomicEvalAction, ReplCheckAction, CreateReplStageStateAction {
|
) : ReplCompileAction, ReplCheckAction, CreateReplStageStateAction {
|
||||||
|
|
||||||
protected val configuration = CompilerConfiguration().apply {
|
protected val configuration = CompilerConfiguration().apply {
|
||||||
addJvmClasspathRoots(PathUtil.getJdkClassesRoots())
|
addJvmClasspathRoots(PathUtil.getJdkClassesRoots())
|
||||||
@@ -90,12 +89,6 @@ open class KotlinJvmReplService(
|
|||||||
else GenericReplCompiler(disposable, scriptDef, configuration, messageCollector)
|
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()
|
protected val statesLock = ReentrantReadWriteLock()
|
||||||
// TODO: consider using values here for session cleanup
|
// TODO: consider using values here for session cleanup
|
||||||
protected val states = WeakHashMap<RemoteReplStateFacadeServer, Boolean>() // used as (missing) WeakHashSet
|
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")
|
@Deprecated("Use check(state, line) instead")
|
||||||
fun check(codeLine: ReplCodeLine): ReplCheckResult = check(defaultStateFacade.state, codeLine)
|
fun check(codeLine: ReplCodeLine): ReplCheckResult = check(defaultStateFacade.state, codeLine)
|
||||||
|
|
||||||
@Deprecated("Use compile(state, line) instead")
|
@Deprecated("Use compile(state, line) instead")
|
||||||
fun compile(codeLine: ReplCodeLine, verifyHistory: List<ReplCodeLine>?): ReplCompileResult = compile(defaultStateFacade.state, codeLine)
|
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 {
|
fun createRemoteState(port: Int = portForServers): RemoteReplStateFacadeServer = statesLock.write {
|
||||||
val id = getValidId(stateIdCounter) { id -> states.none { it.key.getId() == id} }
|
val id = getValidId(stateIdCounter) { id -> states.none { it.key.getId() == id} }
|
||||||
val stateFacade = RemoteReplStateFacadeServer(id, createState().asState(GenericReplCompilerState::class.java), port)
|
val stateFacade = RemoteReplStateFacadeServer(id, createState().asState(GenericReplCompilerState::class.java), port)
|
||||||
|
|||||||
@@ -534,12 +534,12 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
|||||||
|
|
||||||
fun testDaemonReplLocalEvalNoParams() {
|
fun testDaemonReplLocalEvalNoParams() {
|
||||||
withDaemon { daemon ->
|
withDaemon { daemon ->
|
||||||
val repl = KotlinRemoteReplCompilerClient(daemon!!, null, CompileService.TargetPlatform.JVM,
|
withDisposable { disposable ->
|
||||||
emptyArray(),
|
val repl = KotlinRemoteReplCompilerClient(daemon!!, null, CompileService.TargetPlatform.JVM,
|
||||||
TestMessageCollector(),
|
emptyArray(),
|
||||||
classpathFromClassloader(),
|
TestMessageCollector(),
|
||||||
ScriptWithNoParam::class.qualifiedName!!,
|
classpathFromClassloader(),
|
||||||
ScriptArgsWithTypes(emptyArray(), emptyArray()))
|
ScriptWithNoParam::class.qualifiedName!!)
|
||||||
|
|
||||||
val localEvaluator = GenericReplEvaluator(emptyList(), Thread.currentThread().contextClassLoader)
|
val localEvaluator = GenericReplEvaluator(emptyList(), Thread.currentThread().contextClassLoader)
|
||||||
|
|
||||||
@@ -550,11 +550,11 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
|||||||
|
|
||||||
fun testDaemonReplLocalEvalStandardTemplate() {
|
fun testDaemonReplLocalEvalStandardTemplate() {
|
||||||
withDaemon { daemon ->
|
withDaemon { daemon ->
|
||||||
val repl = KotlinRemoteReplCompilerClient(disposable, daemon!!, null, CompileService.TargetPlatform.JVM, emptyArray(),
|
withDisposable { disposable ->
|
||||||
TestMessageCollector(),
|
val repl = KotlinRemoteReplCompilerClient(daemon!!, null, CompileService.TargetPlatform.JVM, emptyArray(),
|
||||||
classpathFromClassloader(),
|
TestMessageCollector(),
|
||||||
"kotlin.script.templates.standard.ScriptTemplateWithArgs",
|
classpathFromClassloader(),
|
||||||
ScriptArgsWithTypes(emptyArray(), emptyArray()))
|
"kotlin.script.templates.standard.ScriptTemplateWithArgs")
|
||||||
|
|
||||||
val localEvaluator = GenericReplEvaluator(emptyList(), Thread.currentThread().contextClassLoader,
|
val localEvaluator = GenericReplEvaluator(emptyList(), Thread.currentThread().contextClassLoader,
|
||||||
ScriptArgsWithTypes(arrayOf(emptyArray<String>()), arrayOf(Array<String>::class)))
|
ScriptArgsWithTypes(arrayOf(emptyArray<String>()), arrayOf(Array<String>::class)))
|
||||||
@@ -609,8 +609,7 @@ class CompilerDaemonTest : KotlinIntegrationTestBase() {
|
|||||||
emptyArray(),
|
emptyArray(),
|
||||||
TestMessageCollector(),
|
TestMessageCollector(),
|
||||||
classpathFromClassloader(),
|
classpathFromClassloader(),
|
||||||
ScriptWithNoParam::class.qualifiedName!!,
|
ScriptWithNoParam::class.qualifiedName!!)
|
||||||
ScriptArgsWithTypes(emptyArray(), emptyArray()))
|
|
||||||
|
|
||||||
val compilerState = replCompiler.createState()
|
val compilerState = replCompiler.createState()
|
||||||
|
|
||||||
|
|||||||
@@ -65,8 +65,7 @@ class KotlinJsr223JvmScriptEngine4Idea(
|
|||||||
emptyArray(),
|
emptyArray(),
|
||||||
messageCollector,
|
messageCollector,
|
||||||
templateClasspath,
|
templateClasspath,
|
||||||
templateClassName,
|
templateClassName)
|
||||||
ScriptArgsWithTypes(emptyArray(), emptyArray()))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -57,8 +57,7 @@ class KotlinJsr223JvmDaemonCompileScriptEngine(
|
|||||||
emptyArray(),
|
emptyArray(),
|
||||||
PrintingMessageCollector(PrintStream(compilerOut), MessageRenderer.WITHOUT_PATHS, false),
|
PrintingMessageCollector(PrintStream(compilerOut), MessageRenderer.WITHOUT_PATHS, false),
|
||||||
templateClasspath,
|
templateClasspath,
|
||||||
templateClassName,
|
templateClassName)
|
||||||
getScriptArgs(context, scriptArgsTypes)!!)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user