Refactor scripting - get rid of unused type parameter in CompiledScript
This commit is contained in:
@@ -317,13 +317,13 @@ interface ScriptCompiler {
|
||||
suspend operator fun invoke(
|
||||
script: SourceCode,
|
||||
scriptCompilationConfiguration: ScriptCompilationConfiguration
|
||||
): ResultWithDiagnostics<CompiledScript<*>>
|
||||
): ResultWithDiagnostics<CompiledScript>
|
||||
}
|
||||
|
||||
/**
|
||||
* The interface to the compiled script
|
||||
*/
|
||||
interface CompiledScript<out ScriptBase : Any> {
|
||||
interface CompiledScript {
|
||||
|
||||
/**
|
||||
* The location identifier for the script source, taken from SourceCode.locationId
|
||||
@@ -346,7 +346,7 @@ interface CompiledScript<out ScriptBase : Any> {
|
||||
/**
|
||||
* The scripts compiled along with this one in one module, imported or otherwise included into compilation
|
||||
*/
|
||||
val otherScripts: List<CompiledScript<*>>
|
||||
val otherScripts: List<CompiledScript>
|
||||
get() = emptyList()
|
||||
|
||||
/**
|
||||
|
||||
@@ -147,7 +147,7 @@ val ScriptEvaluationContextDataKeys.commandLineArgs by PropertiesCollection.key<
|
||||
* The facade to the script data for evaluation configuration refinement callbacks
|
||||
*/
|
||||
data class ScriptEvaluationConfigurationRefinementContext(
|
||||
val compiledScript: CompiledScript<*>,
|
||||
val compiledScript: CompiledScript,
|
||||
val evaluationConfiguration: ScriptEvaluationConfiguration,
|
||||
val contextData: ScriptEvaluationContextData? = null
|
||||
)
|
||||
|
||||
@@ -120,7 +120,7 @@ data class RefineEvaluationConfigurationData(
|
||||
}
|
||||
|
||||
fun ScriptEvaluationConfiguration.refineBeforeEvaluation(
|
||||
script: CompiledScript<*>,
|
||||
script: CompiledScript,
|
||||
contextData: ScriptEvaluationContextData? = null
|
||||
): ResultWithDiagnostics<ScriptEvaluationConfiguration> {
|
||||
val hostConfiguration = get(ScriptEvaluationConfiguration.hostConfiguration)
|
||||
@@ -191,7 +191,7 @@ interface ScriptEvaluator {
|
||||
* @param scriptEvaluationConfiguration evaluation configuration
|
||||
*/
|
||||
suspend operator fun invoke(
|
||||
compiledScript: CompiledScript<*>,
|
||||
compiledScript: CompiledScript,
|
||||
scriptEvaluationConfiguration: ScriptEvaluationConfiguration = ScriptEvaluationConfiguration.Default
|
||||
): ResultWithDiagnostics<EvaluationResult>
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ class JsEvaluationState(lock: ReentrantReadWriteLock, val engine: ScriptEngine)
|
||||
class JsCompiledScript(
|
||||
val jsCode: String,
|
||||
override val compilationConfiguration: ScriptCompilationConfiguration
|
||||
) : CompiledScript<Any> {
|
||||
) : CompiledScript {
|
||||
override suspend fun getClass(scriptEvaluationConfiguration: ScriptEvaluationConfiguration?): ResultWithDiagnostics<KClass<*>> {
|
||||
throw IllegalStateException("Class is not available for JS implementation")
|
||||
}
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ class JsScriptEvaluator : ScriptEvaluator {
|
||||
private val engine = ScriptEngineNashorn()
|
||||
|
||||
override suspend fun invoke(
|
||||
compiledScript: CompiledScript<*>,
|
||||
compiledScript: CompiledScript,
|
||||
scriptEvaluationConfiguration: ScriptEvaluationConfiguration
|
||||
): ResultWithDiagnostics<EvaluationResult> {
|
||||
return try {
|
||||
|
||||
+1
-1
@@ -377,7 +377,7 @@ class ScriptingHostTest : TestCase() {
|
||||
val compiler = JvmScriptCompiler(defaultJvmScriptingHostConfiguration)
|
||||
val compiledScript = runBlocking {
|
||||
val res = compiler(script.toScriptSource(), scriptCompilationConfiguration).throwOnFailure()
|
||||
(res as ResultWithDiagnostics.Success<CompiledScript<*>>).value
|
||||
(res as ResultWithDiagnostics.Success<CompiledScript>).value
|
||||
}
|
||||
val compiledScriptClass = runBlocking { compiledScript.getClass(null).throwOnFailure().valueOrNull()!! as KClass<*> }
|
||||
val classLoader = compiledScriptClass.java.classLoader
|
||||
|
||||
+3
-3
@@ -22,7 +22,7 @@ import kotlin.script.experimental.jvm.jvm
|
||||
open class CompiledScriptJarsCache(val scriptToFile: (SourceCode, ScriptCompilationConfiguration) -> File?) :
|
||||
CompiledJvmScriptsCache {
|
||||
|
||||
override fun get(script: SourceCode, scriptCompilationConfiguration: ScriptCompilationConfiguration): CompiledScript<*>? {
|
||||
override fun get(script: SourceCode, scriptCompilationConfiguration: ScriptCompilationConfiguration): CompiledScript? {
|
||||
val file = scriptToFile(script, scriptCompilationConfiguration)
|
||||
?: throw IllegalArgumentException("Unable to find a mapping to a file for the script $script")
|
||||
|
||||
@@ -42,14 +42,14 @@ open class CompiledScriptJarsCache(val scriptToFile: (SourceCode, ScriptCompilat
|
||||
}
|
||||
|
||||
override fun store(
|
||||
compiledScript: CompiledScript<*>,
|
||||
compiledScript: CompiledScript,
|
||||
script: SourceCode,
|
||||
scriptCompilationConfiguration: ScriptCompilationConfiguration
|
||||
) {
|
||||
val file = scriptToFile(script, scriptCompilationConfiguration)
|
||||
?: throw IllegalArgumentException("Unable to find a mapping to a file for the script $script")
|
||||
|
||||
val jvmScript = (compiledScript as? KJvmCompiledScript<*>)
|
||||
val jvmScript = (compiledScript as? KJvmCompiledScript)
|
||||
?: throw IllegalArgumentException("Unsupported script type ${compiledScript::class.java.name}")
|
||||
|
||||
jvmScript.saveToJar(file)
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ open class JvmScriptCompiler(
|
||||
override suspend operator fun invoke(
|
||||
script: SourceCode,
|
||||
scriptCompilationConfiguration: ScriptCompilationConfiguration
|
||||
): ResultWithDiagnostics<CompiledScript<*>> =
|
||||
): ResultWithDiagnostics<CompiledScript> =
|
||||
compilerProxy.compile(
|
||||
script,
|
||||
scriptCompilationConfiguration.with {
|
||||
|
||||
+5
-5
@@ -22,11 +22,11 @@ import kotlin.script.experimental.jvm.util.scriptCompilationClasspathFromContext
|
||||
open class BasicJvmScriptClassFilesGenerator(val outputDir: File) : ScriptEvaluator {
|
||||
|
||||
override suspend operator fun invoke(
|
||||
compiledScript: CompiledScript<*>,
|
||||
compiledScript: CompiledScript,
|
||||
scriptEvaluationConfiguration: ScriptEvaluationConfiguration
|
||||
): ResultWithDiagnostics<EvaluationResult> {
|
||||
try {
|
||||
if (compiledScript !is KJvmCompiledScript<*>)
|
||||
if (compiledScript !is KJvmCompiledScript)
|
||||
return failure("Cannot generate classes: unsupported compiled script type $compiledScript")
|
||||
val module = (compiledScript.compiledModule as? KJvmCompiledModuleInMemory)
|
||||
?: return failure("Cannot generate classes: unsupported module type ${compiledScript.compiledModule}")
|
||||
@@ -47,7 +47,7 @@ open class BasicJvmScriptClassFilesGenerator(val outputDir: File) : ScriptEvalua
|
||||
}
|
||||
}
|
||||
|
||||
fun KJvmCompiledScript<*>.saveToJar(outputJar: File) {
|
||||
fun KJvmCompiledScript.saveToJar(outputJar: File) {
|
||||
val module = (compiledModule as? KJvmCompiledModuleInMemory)
|
||||
?: throw IllegalArgumentException("Unsupported module type $compiledModule")
|
||||
val dependenciesFromScript = compilationConfiguration[ScriptCompilationConfiguration.dependencies]
|
||||
@@ -90,11 +90,11 @@ fun KJvmCompiledScript<*>.saveToJar(outputJar: File) {
|
||||
open class BasicJvmScriptJarGenerator(val outputJar: File) : ScriptEvaluator {
|
||||
|
||||
override suspend operator fun invoke(
|
||||
compiledScript: CompiledScript<*>,
|
||||
compiledScript: CompiledScript,
|
||||
scriptEvaluationConfiguration: ScriptEvaluationConfiguration
|
||||
): ResultWithDiagnostics<EvaluationResult> {
|
||||
try {
|
||||
if (compiledScript !is KJvmCompiledScript<*>)
|
||||
if (compiledScript !is KJvmCompiledScript)
|
||||
return failure("Cannot generate jar: unsupported compiled script type $compiledScript")
|
||||
compiledScript.saveToJar(outputJar)
|
||||
return ResultWithDiagnostics.Success(EvaluationResult(ResultValue.NotEvaluated, scriptEvaluationConfiguration))
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ class JvmReplEvaluator(
|
||||
): ReplEvalResult = state.lock.write {
|
||||
val evalState = state.asState(JvmReplEvaluatorState::class.java)
|
||||
val history = evalState.history as ReplStageHistoryWithReplace
|
||||
val compiledScript = (compileResult.data as? KJvmCompiledScript<*>)
|
||||
val compiledScript = (compileResult.data as? KJvmCompiledScript)
|
||||
?: return ReplEvalResult.Error.CompileTime("Unable to access compiled script: ${compileResult.data}")
|
||||
|
||||
val lastSnippetClass = history.peek()?.item?.first
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ import kotlin.script.experimental.jvm.impl.getConfigurationWithClassloader
|
||||
open class BasicJvmScriptEvaluator : ScriptEvaluator {
|
||||
|
||||
override suspend operator fun invoke(
|
||||
compiledScript: CompiledScript<*>,
|
||||
compiledScript: CompiledScript,
|
||||
scriptEvaluationConfiguration: ScriptEvaluationConfiguration
|
||||
): ResultWithDiagnostics<EvaluationResult> = try {
|
||||
val configuration = getConfigurationWithClassloader(compiledScript, scriptEvaluationConfiguration)
|
||||
|
||||
+16
-16
@@ -18,7 +18,7 @@ internal class KJvmCompiledScriptData(
|
||||
var compilationConfiguration: ScriptCompilationConfiguration,
|
||||
var scriptClassFQName: String,
|
||||
var resultField: Pair<String, KotlinType>?,
|
||||
var otherScripts: List<CompiledScript<*>> = emptyList()
|
||||
var otherScripts: List<CompiledScript> = emptyList()
|
||||
) : Serializable {
|
||||
|
||||
private fun writeObject(outputStream: ObjectOutputStream) {
|
||||
@@ -33,7 +33,7 @@ internal class KJvmCompiledScriptData(
|
||||
private fun readObject(inputStream: ObjectInputStream) {
|
||||
compilationConfiguration = inputStream.readObject() as ScriptCompilationConfiguration
|
||||
sourceLocationId = inputStream.readObject() as String?
|
||||
otherScripts = inputStream.readObject() as List<CompiledScript<*>>
|
||||
otherScripts = inputStream.readObject() as List<CompiledScript>
|
||||
scriptClassFQName = inputStream.readObject() as String
|
||||
resultField = inputStream.readObject() as Pair<String, KotlinType>?
|
||||
}
|
||||
@@ -44,17 +44,17 @@ internal class KJvmCompiledScriptData(
|
||||
}
|
||||
}
|
||||
|
||||
class KJvmCompiledScript<out ScriptBase : Any> internal constructor(
|
||||
class KJvmCompiledScript internal constructor(
|
||||
internal var data: KJvmCompiledScriptData,
|
||||
var compiledModule: KJvmCompiledModule? // module should be null for imported (other) scripts, so only one reference to the module is kept
|
||||
) : CompiledScript<ScriptBase>, Serializable {
|
||||
) : CompiledScript, Serializable {
|
||||
|
||||
constructor(
|
||||
sourceLocationId: String?,
|
||||
compilationConfiguration: ScriptCompilationConfiguration,
|
||||
scriptClassFQName: String,
|
||||
resultField: Pair<String, KotlinType>?,
|
||||
otherScripts: List<CompiledScript<*>> = emptyList(),
|
||||
otherScripts: List<CompiledScript> = emptyList(),
|
||||
compiledModule: KJvmCompiledModule? // module should be null for imported (other) scripts, so only one reference to the module is kept
|
||||
) : this(
|
||||
KJvmCompiledScriptData(sourceLocationId, compilationConfiguration, scriptClassFQName, resultField, otherScripts),
|
||||
@@ -67,7 +67,7 @@ class KJvmCompiledScript<out ScriptBase : Any> internal constructor(
|
||||
override val compilationConfiguration: ScriptCompilationConfiguration
|
||||
get() = data.compilationConfiguration
|
||||
|
||||
override val otherScripts: List<CompiledScript<*>>
|
||||
override val otherScripts: List<CompiledScript>
|
||||
get() = data.otherScripts
|
||||
|
||||
val scriptClassFQName: String
|
||||
@@ -111,7 +111,7 @@ class KJvmCompiledScript<out ScriptBase : Any> internal constructor(
|
||||
}
|
||||
}
|
||||
|
||||
fun KJvmCompiledScript<*>.getOrCreateActualClassloader(evaluationConfiguration: ScriptEvaluationConfiguration): ClassLoader =
|
||||
fun KJvmCompiledScript.getOrCreateActualClassloader(evaluationConfiguration: ScriptEvaluationConfiguration): ClassLoader =
|
||||
evaluationConfiguration[ScriptEvaluationConfiguration.jvm.actualClassLoader] ?: run {
|
||||
val module = compiledModule
|
||||
?: throw IllegalStateException("Illegal call sequence, actualClassloader should be set before calling function on the class without module")
|
||||
@@ -123,12 +123,12 @@ fun KJvmCompiledScript<*>.getOrCreateActualClassloader(evaluationConfiguration:
|
||||
}
|
||||
|
||||
fun getConfigurationWithClassloader(
|
||||
script: CompiledScript<*>, baseConfiguration: ScriptEvaluationConfiguration
|
||||
script: CompiledScript, baseConfiguration: ScriptEvaluationConfiguration
|
||||
): ScriptEvaluationConfiguration =
|
||||
if (baseConfiguration.containsKey(ScriptEvaluationConfiguration.jvm.actualClassLoader))
|
||||
baseConfiguration
|
||||
else {
|
||||
val jvmScript = (script as? KJvmCompiledScript<*>)
|
||||
val jvmScript = (script as? KJvmCompiledScript)
|
||||
?: throw IllegalArgumentException("Unexpected compiled script type: $script")
|
||||
|
||||
val classloader = jvmScript.getOrCreateActualClassloader(baseConfiguration)
|
||||
@@ -141,9 +141,9 @@ fun getConfigurationWithClassloader(
|
||||
}
|
||||
}
|
||||
|
||||
private fun CompiledScript<*>.makeClassLoaderFromDependencies(baseClassLoader: ClassLoader?): ClassLoader? {
|
||||
val processedScripts = mutableSetOf<CompiledScript<*>>()
|
||||
fun recursiveScriptsSeq(res: Sequence<CompiledScript<*>>, script: CompiledScript<*>): Sequence<CompiledScript<*>> =
|
||||
private fun CompiledScript.makeClassLoaderFromDependencies(baseClassLoader: ClassLoader?): ClassLoader? {
|
||||
val processedScripts = mutableSetOf<CompiledScript>()
|
||||
fun recursiveScriptsSeq(res: Sequence<CompiledScript>, script: CompiledScript): Sequence<CompiledScript> =
|
||||
if (processedScripts.add(script)) script.otherScripts.asSequence().fold(res + script, ::recursiveScriptsSeq)
|
||||
else res
|
||||
|
||||
@@ -188,9 +188,9 @@ const val KOTLIN_SCRIPT_METADATA_EXTENSION_WITH_DOT = ".kotlin_script"
|
||||
fun scriptMetadataPath(scriptClassFQName: String) =
|
||||
"$KOTLIN_SCRIPT_METADATA_PATH/$scriptClassFQName$KOTLIN_SCRIPT_METADATA_EXTENSION_WITH_DOT"
|
||||
|
||||
fun <T : Any> KJvmCompiledScript<T>.copyWithoutModule(): KJvmCompiledScript<T> = KJvmCompiledScript(data, null)
|
||||
fun KJvmCompiledScript.copyWithoutModule(): KJvmCompiledScript = KJvmCompiledScript(data, null)
|
||||
|
||||
fun KJvmCompiledScript<*>.toBytes(): ByteArray {
|
||||
fun KJvmCompiledScript.toBytes(): ByteArray {
|
||||
val bos = ByteArrayOutputStream()
|
||||
var oos: ObjectOutputStream? = null
|
||||
try {
|
||||
@@ -206,11 +206,11 @@ fun KJvmCompiledScript<*>.toBytes(): ByteArray {
|
||||
}
|
||||
}
|
||||
|
||||
fun createScriptFromClassLoader(scriptClassFQName: String, classLoader: ClassLoader): KJvmCompiledScript<*> {
|
||||
fun createScriptFromClassLoader(scriptClassFQName: String, classLoader: ClassLoader): KJvmCompiledScript {
|
||||
val scriptDataStream = classLoader.getResourceAsStream(scriptMetadataPath(scriptClassFQName))
|
||||
?: throw IllegalArgumentException("Cannot find metadata for script $scriptClassFQName")
|
||||
val script = ObjectInputStream(scriptDataStream).use {
|
||||
it.readObject() as KJvmCompiledScript<*>
|
||||
it.readObject() as KJvmCompiledScript
|
||||
}
|
||||
script.compiledModule = KJvmCompiledModuleFromClassLoader(classLoader)
|
||||
return script
|
||||
|
||||
@@ -11,16 +11,16 @@ import kotlin.script.experimental.api.SourceCode
|
||||
import kotlin.script.experimental.util.PropertiesCollection
|
||||
|
||||
interface CompiledJvmScriptsCache {
|
||||
fun get(script: SourceCode, scriptCompilationConfiguration: ScriptCompilationConfiguration): CompiledScript<*>?
|
||||
fun store(compiledScript: CompiledScript<*>, script: SourceCode, scriptCompilationConfiguration: ScriptCompilationConfiguration)
|
||||
fun get(script: SourceCode, scriptCompilationConfiguration: ScriptCompilationConfiguration): CompiledScript?
|
||||
fun store(compiledScript: CompiledScript, script: SourceCode, scriptCompilationConfiguration: ScriptCompilationConfiguration)
|
||||
|
||||
object NoCache : CompiledJvmScriptsCache {
|
||||
override fun get(
|
||||
script: SourceCode, scriptCompilationConfiguration: ScriptCompilationConfiguration
|
||||
): CompiledScript<*>? = null
|
||||
): CompiledScript? = null
|
||||
|
||||
override fun store(
|
||||
compiledScript: CompiledScript<*>, script: SourceCode, scriptCompilationConfiguration: ScriptCompilationConfiguration
|
||||
compiledScript: CompiledScript, script: SourceCode, scriptCompilationConfiguration: ScriptCompilationConfiguration
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -14,5 +14,5 @@ interface ScriptCompilerProxy {
|
||||
fun compile(
|
||||
script: SourceCode,
|
||||
scriptCompilationConfiguration: ScriptCompilationConfiguration
|
||||
): ResultWithDiagnostics<CompiledScript<*>>
|
||||
): ResultWithDiagnostics<CompiledScript>
|
||||
}
|
||||
+1
-1
@@ -69,7 +69,7 @@ class KJvmReplCompilerImpl(val hostConfiguration: ScriptingHostConfiguration) :
|
||||
snippetId: ReplSnippetId,
|
||||
// TODO: replace history with some interface based on CompiledScript
|
||||
history: IReplStageHistory<ScriptDescriptor>
|
||||
): ResultWithDiagnostics<CompiledScript<*>> =
|
||||
): ResultWithDiagnostics<CompiledScript> =
|
||||
withMessageCollector(snippet) { messageCollector ->
|
||||
|
||||
val context = (compilationState as? ReplCompilationState)?.context
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ class JsScriptCompilerWithDependenciesProxy(private val environment: KotlinCoreE
|
||||
override fun compile(
|
||||
script: SourceCode,
|
||||
scriptCompilationConfiguration: ScriptCompilationConfiguration
|
||||
): ResultWithDiagnostics<CompiledScript<*>> {
|
||||
): ResultWithDiagnostics<CompiledScript> {
|
||||
val parentMessageCollector = environment.configuration[CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY]
|
||||
return withMessageCollector(script = script, parentMessageCollector = parentMessageCollector) { messageCollector ->
|
||||
environment.configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, messageCollector)
|
||||
|
||||
+6
-6
@@ -37,7 +37,7 @@ class ScriptJvmCompilerIsolated(val hostConfiguration: ScriptingHostConfiguratio
|
||||
override fun compile(
|
||||
script: SourceCode,
|
||||
scriptCompilationConfiguration: ScriptCompilationConfiguration
|
||||
): ResultWithDiagnostics<CompiledScript<*>> =
|
||||
): ResultWithDiagnostics<CompiledScript> =
|
||||
withMessageCollectorAndDisposable(script = script) { messageCollector, disposable ->
|
||||
withScriptCompilationCache(script, scriptCompilationConfiguration, messageCollector) {
|
||||
val initialConfiguration = scriptCompilationConfiguration.refineBeforeParsing(script).valueOr {
|
||||
@@ -58,7 +58,7 @@ class ScriptJvmCompilerFromEnvironment(val environment: KotlinCoreEnvironment) :
|
||||
override fun compile(
|
||||
script: SourceCode,
|
||||
scriptCompilationConfiguration: ScriptCompilationConfiguration
|
||||
): ResultWithDiagnostics<CompiledScript<*>> {
|
||||
): ResultWithDiagnostics<CompiledScript> {
|
||||
val parentMessageCollector = environment.configuration[CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY]
|
||||
return withMessageCollector(script = script, parentMessageCollector = parentMessageCollector) { messageCollector ->
|
||||
withScriptCompilationCache(script, scriptCompilationConfiguration, messageCollector) {
|
||||
@@ -86,8 +86,8 @@ private fun withScriptCompilationCache(
|
||||
script: SourceCode,
|
||||
scriptCompilationConfiguration: ScriptCompilationConfiguration,
|
||||
messageCollector: ScriptDiagnosticsMessageCollector,
|
||||
body: () -> ResultWithDiagnostics<CompiledScript<*>>
|
||||
): ResultWithDiagnostics<CompiledScript<*>> {
|
||||
body: () -> ResultWithDiagnostics<CompiledScript>
|
||||
): ResultWithDiagnostics<CompiledScript> {
|
||||
val cache = scriptCompilationConfiguration[ScriptCompilationConfiguration.hostConfiguration]?.get(ScriptingHostConfiguration.jvm.compilationCache)
|
||||
|
||||
val cached = cache?.get(script, scriptCompilationConfiguration)
|
||||
@@ -104,7 +104,7 @@ private fun compileImpl(
|
||||
script: SourceCode,
|
||||
context: SharedScriptCompilationContext,
|
||||
messageCollector: ScriptDiagnosticsMessageCollector
|
||||
): ResultWithDiagnostics<CompiledScript<*>> {
|
||||
): ResultWithDiagnostics<CompiledScript> {
|
||||
val mainKtFile =
|
||||
getScriptKtFile(
|
||||
script,
|
||||
@@ -168,7 +168,7 @@ private fun doCompile(
|
||||
sourceDependencies: List<ScriptsCompilationDependencies.SourceDependencies>,
|
||||
messageCollector: ScriptDiagnosticsMessageCollector,
|
||||
getScriptConfiguration: (KtFile) -> ScriptCompilationConfiguration
|
||||
): ResultWithDiagnostics<KJvmCompiledScript<Any>> {
|
||||
): ResultWithDiagnostics<KJvmCompiledScript> {
|
||||
|
||||
registerPackageFragmentProvidersIfNeeded(getScriptConfiguration(sourceFiles.first()), context.environment)
|
||||
|
||||
|
||||
+4
-4
@@ -105,12 +105,12 @@ internal fun makeCompiledScript(
|
||||
ktFile: KtFile,
|
||||
sourceDependencies: List<ScriptsCompilationDependencies.SourceDependencies>,
|
||||
getScriptConfiguration: (KtFile) -> ScriptCompilationConfiguration
|
||||
): KJvmCompiledScript<Any> {
|
||||
): KJvmCompiledScript {
|
||||
val scriptDependenciesStack = ArrayDeque<KtScript>()
|
||||
val ktScript = ktFile.declarations.firstIsInstanceOrNull<KtScript>()
|
||||
?: throw IllegalStateException("Expecting script file: KtScript is not found in ${ktFile.name}")
|
||||
|
||||
fun makeOtherScripts(script: KtScript): List<KJvmCompiledScript<*>> {
|
||||
fun makeOtherScripts(script: KtScript): List<KJvmCompiledScript> {
|
||||
|
||||
// TODO: ensure that it is caught earlier (as well) since it would be more economical
|
||||
if (scriptDependenciesStack.contains(script))
|
||||
@@ -118,10 +118,10 @@ internal fun makeCompiledScript(
|
||||
scriptDependenciesStack.push(script)
|
||||
|
||||
val containingKtFile = script.containingKtFile
|
||||
val otherScripts: List<KJvmCompiledScript<*>> =
|
||||
val otherScripts: List<KJvmCompiledScript> =
|
||||
sourceDependencies.find { it.scriptFile == containingKtFile }?.sourceDependencies?.valueOrThrow()?.mapNotNull { sourceFile ->
|
||||
sourceFile.declarations.firstIsInstanceOrNull<KtScript>()?.let {
|
||||
KJvmCompiledScript<Any>(
|
||||
KJvmCompiledScript(
|
||||
containingKtFile.virtualFile?.path,
|
||||
getScriptConfiguration(sourceFile),
|
||||
it.fqName.asString(),
|
||||
|
||||
+1
-1
@@ -30,7 +30,7 @@ interface KJvmReplCompilerProxy {
|
||||
snippet: SourceCode,
|
||||
snippetId: ReplSnippetId,
|
||||
history: IReplStageHistory<ScriptDescriptor>
|
||||
): ResultWithDiagnostics<CompiledScript<*>>
|
||||
): ResultWithDiagnostics<CompiledScript>
|
||||
}
|
||||
|
||||
class JvmReplCompilerStageHistory(private val state: JvmReplCompilerState) :
|
||||
|
||||
Reference in New Issue
Block a user