diff --git a/build.gradle.kts b/build.gradle.kts index 1ca02f1e0ac..a483b454646 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -708,7 +708,6 @@ tasks { register("scriptingTest") { dependsOn("scriptingJvmTest") - dependsOn(":kotlin-scripting-js-test:test") } register("compilerTest") { diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt index fb89e4e8ab1..cf17c5f1ff6 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JSCompilerArguments.kt @@ -349,6 +349,15 @@ class K2JSCompilerArguments : CommonCompilerArguments() { var legacyDeprecatedNoWarn: Boolean by FreezableVar(false) override fun configureAnalysisFlags(collector: MessageCollector, languageVersion: LanguageVersion): MutableMap, Any> { + // TODO: 'enableJsScripting' is used in intellij tests + // Drop it after removing the usage from the intellij repository: + // https://github.com/JetBrains/intellij-community/blob/master/plugins/kotlin/gradle/gradle-java/tests/test/org/jetbrains/kotlin/gradle/CompilerArgumentsCachingTest.kt#L329 + if (enableJsScripting) { + collector.report( + CompilerMessageSeverity.WARNING, "'-Xenable-js-scripting' is deprecated and will be removed in a future release" + ) + } + return super.configureAnalysisFlags(collector, languageVersion).also { it[allowFullyQualifiedNameInKClass] = wasm && wasmKClassFqn //Only enabled WASM BE supports this flag } diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt index f0c2f8560fa..4f552d95c55 100644 --- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt +++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt @@ -21,7 +21,6 @@ import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.RUNTIME_DIAGNOSTIC_EXCEPTION import org.jetbrains.kotlin.cli.common.arguments.K2JsArgumentConstants.RUNTIME_DIAGNOSTIC_LOG import org.jetbrains.kotlin.cli.common.config.addKotlinSourceRoot -import org.jetbrains.kotlin.cli.common.extensions.ScriptEvaluationExtension import org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport import org.jetbrains.kotlin.cli.common.messages.CompilerMessageLocation import org.jetbrains.kotlin.cli.common.messages.CompilerMessageSeverity.* @@ -158,29 +157,9 @@ class K2JsIrCompiler : CLICompiler() { val pluginLoadResult = loadPlugins(paths, arguments, configuration) if (pluginLoadResult != OK) return pluginLoadResult - //TODO: add to configuration everything that may come in handy at script compiler and use it there if (arguments.script) { - - if (!arguments.enableJsScripting) { - @Suppress("SpellCheckingInspection") - messageCollector.report(ERROR, "Script for K/JS should be enabled explicitly, see -Xenable-js-scripting") - return COMPILATION_ERROR - } - - configuration.put(CommonConfigurationKeys.MODULE_NAME, "repl.kts") - - val environment = KotlinCoreEnvironment.getOrCreateApplicationEnvironmentForProduction(rootDisposable, configuration) - val projectEnv = KotlinCoreEnvironment.ProjectEnvironment(rootDisposable, environment, configuration) - projectEnv.registerExtensionsFromPlugins(configuration) - - val scriptingEvaluators = ScriptEvaluationExtension.getInstances(projectEnv.project) - val scriptingEvaluator = scriptingEvaluators.find { it.isAccepted(arguments) } - if (scriptingEvaluator == null) { - messageCollector.report(ERROR, "Unable to evaluate script, no scripting plugin loaded") - return COMPILATION_ERROR - } - - return scriptingEvaluator.eval(arguments, configuration, projectEnv) + messageCollector.report(ERROR, "K/JS does not support Kotlin script (*.kts) files") + return COMPILATION_ERROR } if (arguments.freeArgs.isEmpty() && !(incrementalCompilationIsEnabledForJs(arguments))) { diff --git a/compiler/testData/ir/irJsText/scripting/arrayAssignment.kt.txt b/compiler/testData/ir/irJsText/scripting/arrayAssignment.kt.txt deleted file mode 100644 index fc8509d5628..00000000000 --- a/compiler/testData/ir/irJsText/scripting/arrayAssignment.kt.txt +++ /dev/null @@ -1 +0,0 @@ -/* ERROR: unsupported element type: IrScriptImpl */ diff --git a/compiler/testData/ir/irJsText/scripting/arrayAssignment.kts b/compiler/testData/ir/irJsText/scripting/arrayAssignment.kts deleted file mode 100644 index 26fec9c8b2b..00000000000 --- a/compiler/testData/ir/irJsText/scripting/arrayAssignment.kts +++ /dev/null @@ -1,10 +0,0 @@ -fun test() { - val x = intArrayOf(1, 2, 3) - x[1] = 0 -} - -fun foo() = 1 - -fun test2() { - intArrayOf(1, 2, 3)[foo()] = 1 -} \ No newline at end of file diff --git a/compiler/testData/ir/irJsText/scripting/arrayAssignment.txt b/compiler/testData/ir/irJsText/scripting/arrayAssignment.txt deleted file mode 100644 index 35fc1b2c22f..00000000000 --- a/compiler/testData/ir/irJsText/scripting/arrayAssignment.txt +++ /dev/null @@ -1,33 +0,0 @@ -FILE fqName: fileName:/arrayAssignment.kts - SCRIPT - FUN name:test visibility:public modality:FINAL <> ($this:.ArrayAssignment) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:.ArrayAssignment - BLOCK_BODY - VAR name:x type:kotlin.IntArray [val] - CALL 'public final fun intArrayOf (vararg elements: kotlin.Int): kotlin.IntArray declared in kotlin' type=kotlin.IntArray origin=null - elements: VARARG type=kotlin.IntArray varargElementType=kotlin.Int - CONST Int type=kotlin.Int value=1 - CONST Int type=kotlin.Int value=2 - CONST Int type=kotlin.Int value=3 - CALL 'public final fun set (index: kotlin.Int, value: kotlin.Int): kotlin.Unit [operator] declared in kotlin.IntArray' type=kotlin.Unit origin=EQ - $this: GET_VAR 'val x: kotlin.IntArray [val] declared in .ArrayAssignment.test' type=kotlin.IntArray origin=null - index: CONST Int type=kotlin.Int value=1 - value: CONST Int type=kotlin.Int value=0 - FUN name:foo visibility:public modality:FINAL <> ($this:.ArrayAssignment) returnType:kotlin.Int - $this: VALUE_PARAMETER name: type:.ArrayAssignment - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun foo (): kotlin.Int declared in .ArrayAssignment' - CONST Int type=kotlin.Int value=1 - FUN name:test2 visibility:public modality:FINAL <> ($this:.ArrayAssignment) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:.ArrayAssignment - BLOCK_BODY - CALL 'public final fun set (index: kotlin.Int, value: kotlin.Int): kotlin.Unit [operator] declared in kotlin.IntArray' type=kotlin.Unit origin=EQ - $this: CALL 'public final fun intArrayOf (vararg elements: kotlin.Int): kotlin.IntArray declared in kotlin' type=kotlin.IntArray origin=null - elements: VARARG type=kotlin.IntArray varargElementType=kotlin.Int - CONST Int type=kotlin.Int value=1 - CONST Int type=kotlin.Int value=2 - CONST Int type=kotlin.Int value=3 - index: CALL 'public final fun foo (): kotlin.Int declared in .ArrayAssignment' type=kotlin.Int origin=null - $this: GET_VAR ': .ArrayAssignment declared in .ArrayAssignment.test2' type=.ArrayAssignment origin=null - value: CONST Int type=kotlin.Int value=1 - VALUE_PARAMETER INSTANCE_RECEIVER name: type:.ArrayAssignment diff --git a/compiler/testData/ir/irJsText/scripting/fun.kt.txt b/compiler/testData/ir/irJsText/scripting/fun.kt.txt deleted file mode 100644 index fc8509d5628..00000000000 --- a/compiler/testData/ir/irJsText/scripting/fun.kt.txt +++ /dev/null @@ -1 +0,0 @@ -/* ERROR: unsupported element type: IrScriptImpl */ diff --git a/compiler/testData/ir/irJsText/scripting/fun.kts b/compiler/testData/ir/irJsText/scripting/fun.kts deleted file mode 100644 index db33117f471..00000000000 --- a/compiler/testData/ir/irJsText/scripting/fun.kts +++ /dev/null @@ -1,13 +0,0 @@ -fun test1(i: Int, j: T) {} - -fun test2(i: Int = 0, j: String = "") {} - -fun test3(vararg args: String) {} - -fun String.textExt1(i: Int, j: String) {} - -class Host { - fun String.testMembetExt1(i: Int, j: String) {} - - fun String.testMembetExt2(i: Int, j: T) {} -} \ No newline at end of file diff --git a/compiler/testData/ir/irJsText/scripting/fun.txt b/compiler/testData/ir/irJsText/scripting/fun.txt deleted file mode 100644 index 86a32b2c368..00000000000 --- a/compiler/testData/ir/irJsText/scripting/fun.txt +++ /dev/null @@ -1,60 +0,0 @@ -FILE fqName: fileName:/fun.kts - SCRIPT - FUN name:test1 visibility:public modality:FINAL ($this:.Fun, i:kotlin.Int, j:T of .Fun.test1) returnType:kotlin.Unit - TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false - $this: VALUE_PARAMETER name: type:.Fun - VALUE_PARAMETER name:i index:0 type:kotlin.Int - VALUE_PARAMETER name:j index:1 type:T of .Fun.test1 - BLOCK_BODY - FUN name:test2 visibility:public modality:FINAL <> ($this:.Fun, i:kotlin.Int, j:kotlin.String) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:.Fun - VALUE_PARAMETER name:i index:0 type:kotlin.Int - EXPRESSION_BODY - CONST Int type=kotlin.Int value=0 - VALUE_PARAMETER name:j index:1 type:kotlin.String - EXPRESSION_BODY - CONST String type=kotlin.String value="" - BLOCK_BODY - FUN name:test3 visibility:public modality:FINAL <> ($this:.Fun, args:kotlin.Array) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:.Fun - VALUE_PARAMETER name:args index:0 type:kotlin.Array varargElementType:kotlin.String [vararg] - BLOCK_BODY - FUN name:textExt1 visibility:public modality:FINAL <> ($this:.Fun, $receiver:kotlin.String, i:kotlin.Int, j:kotlin.String) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:.Fun - $receiver: VALUE_PARAMETER name: type:kotlin.String - VALUE_PARAMETER name:i index:0 type:kotlin.Int - VALUE_PARAMETER name:j index:1 type:kotlin.String - BLOCK_BODY - CLASS CLASS name:Host modality:FINAL visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Fun.Host - CONSTRUCTOR visibility:public <> () returnType:.Fun.Host [primary] - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Host modality:FINAL visibility:public superTypes:[kotlin.Any]' - FUN name:testMembetExt1 visibility:public modality:FINAL <> ($this:.Fun.Host, $receiver:kotlin.String, i:kotlin.Int, j:kotlin.String) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:.Fun.Host - $receiver: VALUE_PARAMETER name: type:kotlin.String - VALUE_PARAMETER name:i index:0 type:kotlin.Int - VALUE_PARAMETER name:j index:1 type:kotlin.String - BLOCK_BODY - FUN name:testMembetExt2 visibility:public modality:FINAL ($this:.Fun.Host, $receiver:kotlin.String, i:kotlin.Int, j:T of .Fun.Host.testMembetExt2) returnType:kotlin.Unit - TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false - $this: VALUE_PARAMETER name: type:.Fun.Host - $receiver: VALUE_PARAMETER name: type:kotlin.String - VALUE_PARAMETER name:i index:0 type:kotlin.Int - VALUE_PARAMETER name:j index:1 type:T of .Fun.Host.testMembetExt2 - BLOCK_BODY - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Fun diff --git a/compiler/testData/ir/irJsText/scripting/safeCalls.kt.txt b/compiler/testData/ir/irJsText/scripting/safeCalls.kt.txt deleted file mode 100644 index fc8509d5628..00000000000 --- a/compiler/testData/ir/irJsText/scripting/safeCalls.kt.txt +++ /dev/null @@ -1 +0,0 @@ -/* ERROR: unsupported element type: IrScriptImpl */ diff --git a/compiler/testData/ir/irJsText/scripting/safeCalls.kts b/compiler/testData/ir/irJsText/scripting/safeCalls.kts deleted file mode 100644 index 82943638a94..00000000000 --- a/compiler/testData/ir/irJsText/scripting/safeCalls.kts +++ /dev/null @@ -1,21 +0,0 @@ -class Ref(var value: Int) - -interface IHost { - fun String.extLength() = length -} - -fun test1(x: String?) = x?.length -fun test2(x: String?) = x?.hashCode() -fun test3(x: String?, y: Any?) = x?.equals(y) - -fun test4(x: Ref?) { - x?.value = 0 -} - -fun IHost.test5(s: String?) = s?.extLength() - -fun Int.foo() = 239 - -fun box() { - 42?.foo() -} diff --git a/compiler/testData/ir/irJsText/scripting/safeCalls.txt b/compiler/testData/ir/irJsText/scripting/safeCalls.txt deleted file mode 100644 index b025bf7b06a..00000000000 --- a/compiler/testData/ir/irJsText/scripting/safeCalls.txt +++ /dev/null @@ -1,183 +0,0 @@ -FILE fqName: fileName:/safeCalls.kts - SCRIPT - CLASS CLASS name:Ref modality:FINAL visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.SafeCalls.Ref - CONSTRUCTOR visibility:public <> (value:kotlin.Int) returnType:.SafeCalls.Ref [primary] - VALUE_PARAMETER name:value index:0 type:kotlin.Int - BLOCK_BODY - DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' - INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Ref modality:FINAL visibility:public superTypes:[kotlin.Any]' - PROPERTY name:value visibility:public modality:FINAL [var] - FIELD PROPERTY_BACKING_FIELD name:value type:kotlin.Int visibility:private - EXPRESSION_BODY - GET_VAR 'value: kotlin.Int declared in .SafeCalls.Ref.' type=kotlin.Int origin=INITIALIZE_PROPERTY_FROM_PARAMETER - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.SafeCalls.Ref) returnType:kotlin.Int - correspondingProperty: PROPERTY name:value visibility:public modality:FINAL [var] - $this: VALUE_PARAMETER name: type:.SafeCalls.Ref - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun (): kotlin.Int declared in .SafeCalls.Ref' - GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:value type:kotlin.Int visibility:private' type=kotlin.Int origin=null - receiver: GET_VAR ': .SafeCalls.Ref declared in .SafeCalls.Ref.' type=.SafeCalls.Ref origin=null - FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.SafeCalls.Ref, :kotlin.Int) returnType:kotlin.Unit - correspondingProperty: PROPERTY name:value visibility:public modality:FINAL [var] - $this: VALUE_PARAMETER name: type:.SafeCalls.Ref - VALUE_PARAMETER name: index:0 type:kotlin.Int - BLOCK_BODY - SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:value type:kotlin.Int visibility:private' type=kotlin.Unit origin=null - receiver: GET_VAR ': .SafeCalls.Ref declared in .SafeCalls.Ref.' type=.SafeCalls.Ref origin=null - value: GET_VAR ': kotlin.Int declared in .SafeCalls.Ref.' type=kotlin.Int origin=null - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - CLASS INTERFACE name:IHost modality:ABSTRACT visibility:public superTypes:[kotlin.Any] - $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.SafeCalls.IHost - FUN name:extLength visibility:public modality:OPEN <> ($this:.SafeCalls.IHost, $receiver:kotlin.String) returnType:kotlin.Int - $this: VALUE_PARAMETER name: type:.SafeCalls.IHost - $receiver: VALUE_PARAMETER name: type:kotlin.String - BLOCK_BODY - RETURN type=kotlin.Nothing from='public open fun extLength (): kotlin.Int declared in .SafeCalls.IHost' - CALL 'public open fun (): kotlin.Int declared in kotlin.String' type=kotlin.Int origin=GET_PROPERTY - $this: GET_VAR ': kotlin.String declared in .SafeCalls.IHost.extLength' type=kotlin.String origin=null - FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] - overridden: - public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - VALUE_PARAMETER name:other index:0 type:kotlin.Any? - FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] - overridden: - public open fun hashCode (): kotlin.Int declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] - overridden: - public open fun toString (): kotlin.String declared in kotlin.Any - $this: VALUE_PARAMETER name: type:kotlin.Any - FUN name:test1 visibility:public modality:FINAL <> ($this:.SafeCalls, x:kotlin.String?) returnType:kotlin.Int? - $this: VALUE_PARAMETER name: type:.SafeCalls - VALUE_PARAMETER name:x index:0 type:kotlin.String? - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test1 (x: kotlin.String?): kotlin.Int? declared in .SafeCalls' - BLOCK type=kotlin.Int? origin=SAFE_CALL - VAR IR_TEMPORARY_VARIABLE name:tmp_0 type:kotlin.String? [val] - GET_VAR 'x: kotlin.String? declared in .SafeCalls.test1' type=kotlin.String? origin=null - WHEN type=kotlin.Int? origin=null - BRANCH - if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ - arg0: GET_VAR 'val tmp_0: kotlin.String? [val] declared in .SafeCalls.test1' type=kotlin.String? origin=null - arg1: CONST Null type=kotlin.Nothing? value=null - then: CONST Null type=kotlin.Nothing? value=null - BRANCH - if: CONST Boolean type=kotlin.Boolean value=true - then: CALL 'public open fun (): kotlin.Int declared in kotlin.String' type=kotlin.Int origin=GET_PROPERTY - $this: GET_VAR 'val tmp_0: kotlin.String? [val] declared in .SafeCalls.test1' type=kotlin.String? origin=null - FUN name:test2 visibility:public modality:FINAL <> ($this:.SafeCalls, x:kotlin.String?) returnType:kotlin.Int? - $this: VALUE_PARAMETER name: type:.SafeCalls - VALUE_PARAMETER name:x index:0 type:kotlin.String? - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test2 (x: kotlin.String?): kotlin.Int? declared in .SafeCalls' - BLOCK type=kotlin.Int? origin=SAFE_CALL - VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:kotlin.String? [val] - GET_VAR 'x: kotlin.String? declared in .SafeCalls.test2' type=kotlin.String? origin=null - WHEN type=kotlin.Int? origin=null - BRANCH - if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ - arg0: GET_VAR 'val tmp_1: kotlin.String? [val] declared in .SafeCalls.test2' type=kotlin.String? origin=null - arg1: CONST Null type=kotlin.Nothing? value=null - then: CONST Null type=kotlin.Nothing? value=null - BRANCH - if: CONST Boolean type=kotlin.Boolean value=true - then: CALL 'public open fun hashCode (): kotlin.Int [fake_override] declared in kotlin.String' type=kotlin.Int origin=null - $this: GET_VAR 'val tmp_1: kotlin.String? [val] declared in .SafeCalls.test2' type=kotlin.String? origin=null - FUN name:test3 visibility:public modality:FINAL <> ($this:.SafeCalls, x:kotlin.String?, y:kotlin.Any?) returnType:kotlin.Boolean? - $this: VALUE_PARAMETER name: type:.SafeCalls - VALUE_PARAMETER name:x index:0 type:kotlin.String? - VALUE_PARAMETER name:y index:1 type:kotlin.Any? - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test3 (x: kotlin.String?, y: kotlin.Any?): kotlin.Boolean? declared in .SafeCalls' - BLOCK type=kotlin.Boolean? origin=SAFE_CALL - VAR IR_TEMPORARY_VARIABLE name:tmp_2 type:kotlin.String? [val] - GET_VAR 'x: kotlin.String? declared in .SafeCalls.test3' type=kotlin.String? origin=null - WHEN type=kotlin.Boolean? origin=null - BRANCH - if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ - arg0: GET_VAR 'val tmp_2: kotlin.String? [val] declared in .SafeCalls.test3' type=kotlin.String? origin=null - arg1: CONST Null type=kotlin.Nothing? value=null - then: CONST Null type=kotlin.Nothing? value=null - BRANCH - if: CONST Boolean type=kotlin.Boolean value=true - then: CALL 'public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.String' type=kotlin.Boolean origin=null - $this: GET_VAR 'val tmp_2: kotlin.String? [val] declared in .SafeCalls.test3' type=kotlin.String? origin=null - other: GET_VAR 'y: kotlin.Any? declared in .SafeCalls.test3' type=kotlin.Any? origin=null - FUN name:test4 visibility:public modality:FINAL <> ($this:.SafeCalls, x:.SafeCalls.Ref?) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:.SafeCalls - VALUE_PARAMETER name:x index:0 type:.SafeCalls.Ref? - BLOCK_BODY - BLOCK type=kotlin.Unit origin=SAFE_CALL - VAR IR_TEMPORARY_VARIABLE name:tmp_3 type:.SafeCalls.Ref? [val] - GET_VAR 'x: .SafeCalls.Ref? declared in .SafeCalls.test4' type=.SafeCalls.Ref? origin=null - WHEN type=kotlin.Unit origin=null - BRANCH - if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ - arg0: GET_VAR 'val tmp_3: .SafeCalls.Ref? [val] declared in .SafeCalls.test4' type=.SafeCalls.Ref? origin=null - arg1: CONST Null type=kotlin.Nothing? value=null - then: TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit - CONST Null type=kotlin.Nothing? value=null - BRANCH - if: CONST Boolean type=kotlin.Boolean value=true - then: CALL 'public final fun (: kotlin.Int): kotlin.Unit declared in .SafeCalls.Ref' type=kotlin.Unit origin=EQ - $this: GET_VAR 'val tmp_3: .SafeCalls.Ref? [val] declared in .SafeCalls.test4' type=.SafeCalls.Ref? origin=null - : CONST Int type=kotlin.Int value=0 - FUN name:test5 visibility:public modality:FINAL <> ($this:.SafeCalls, $receiver:.SafeCalls.IHost, s:kotlin.String?) returnType:kotlin.Int? - $this: VALUE_PARAMETER name: type:.SafeCalls - $receiver: VALUE_PARAMETER name: type:.SafeCalls.IHost - VALUE_PARAMETER name:s index:0 type:kotlin.String? - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test5 (s: kotlin.String?): kotlin.Int? declared in .SafeCalls' - BLOCK type=kotlin.Int? origin=SAFE_CALL - VAR IR_TEMPORARY_VARIABLE name:tmp_4 type:kotlin.String? [val] - GET_VAR 's: kotlin.String? declared in .SafeCalls.test5' type=kotlin.String? origin=null - WHEN type=kotlin.Int? origin=null - BRANCH - if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ - arg0: GET_VAR 'val tmp_4: kotlin.String? [val] declared in .SafeCalls.test5' type=kotlin.String? origin=null - arg1: CONST Null type=kotlin.Nothing? value=null - then: CONST Null type=kotlin.Nothing? value=null - BRANCH - if: CONST Boolean type=kotlin.Boolean value=true - then: CALL 'public open fun extLength (): kotlin.Int declared in .SafeCalls.IHost' type=kotlin.Int origin=null - $this: GET_VAR ': .SafeCalls.IHost declared in .SafeCalls.test5' type=.SafeCalls.IHost origin=null - $receiver: GET_VAR 'val tmp_4: kotlin.String? [val] declared in .SafeCalls.test5' type=kotlin.String? origin=null - FUN name:foo visibility:public modality:FINAL <> ($this:.SafeCalls, $receiver:kotlin.Int) returnType:kotlin.Int - $this: VALUE_PARAMETER name: type:.SafeCalls - $receiver: VALUE_PARAMETER name: type:kotlin.Int - BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun foo (): kotlin.Int declared in .SafeCalls' - CONST Int type=kotlin.Int value=239 - FUN name:box visibility:public modality:FINAL <> ($this:.SafeCalls) returnType:kotlin.Unit - $this: VALUE_PARAMETER name: type:.SafeCalls - BLOCK_BODY - TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit - BLOCK type=kotlin.Int? origin=SAFE_CALL - VAR IR_TEMPORARY_VARIABLE name:tmp_5 type:kotlin.Int [val] - CONST Int type=kotlin.Int value=42 - WHEN type=kotlin.Int? origin=null - BRANCH - if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ - arg0: GET_VAR 'val tmp_5: kotlin.Int [val] declared in .SafeCalls.box' type=kotlin.Int origin=null - arg1: CONST Null type=kotlin.Nothing? value=null - then: CONST Null type=kotlin.Nothing? value=null - BRANCH - if: CONST Boolean type=kotlin.Boolean value=true - then: CALL 'public final fun foo (): kotlin.Int declared in .SafeCalls' type=kotlin.Int origin=null - $this: GET_VAR ': .SafeCalls declared in .SafeCalls.box' type=.SafeCalls origin=null - $receiver: GET_VAR 'val tmp_5: kotlin.Int [val] declared in .SafeCalls.box' type=kotlin.Int origin=null - VALUE_PARAMETER INSTANCE_RECEIVER name: type:.SafeCalls diff --git a/compiler/tests-common/build.gradle.kts b/compiler/tests-common/build.gradle.kts index 17e3e7755d3..2ae9b5eb078 100644 --- a/compiler/tests-common/build.gradle.kts +++ b/compiler/tests-common/build.gradle.kts @@ -7,7 +7,6 @@ plugins { dependencies { testApi(kotlinStdlib("jdk8")) testApi(project(":kotlin-scripting-compiler")) - testApi(project(":kotlin-scripting-compiler-js")) testApi(project(":core:descriptors")) testApi(project(":core:descriptors.jvm")) testApi(project(":core:deserialization")) diff --git a/compiler/tests-common/tests/org/jetbrains/kotlin/ir/AbstractIrTextTestCase.kt b/compiler/tests-common/tests/org/jetbrains/kotlin/ir/AbstractIrTextTestCase.kt index b5908e2ea7d..77369eeeb7b 100644 --- a/compiler/tests-common/tests/org/jetbrains/kotlin/ir/AbstractIrTextTestCase.kt +++ b/compiler/tests-common/tests/org/jetbrains/kotlin/ir/AbstractIrTextTestCase.kt @@ -22,7 +22,6 @@ import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi2ir.generators.DeclarationStubGeneratorImpl -import org.jetbrains.kotlin.scripting.js.loadScriptConfiguration import org.jetbrains.kotlin.test.KotlinTestUtils import org.jetbrains.kotlin.test.testFramework.KtUsefulTestCase import org.jetbrains.kotlin.test.util.JUnit4Assertions @@ -88,7 +87,6 @@ abstract class AbstractIrTextTestCase : AbstractIrGeneratorTestCase() { override fun configureTestSpecific(configuration: CompilerConfiguration, testFiles: List) { if (testFiles.any { it.name.endsWith(".kts") }) { - loadScriptConfiguration(configuration) loadPluginsForTests(configuration) } } diff --git a/compiler/tests-gen/org/jetbrains/kotlin/ir/IrJsTextTestCaseGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/ir/IrJsTextTestCaseGenerated.java index d6d114d493e..ecfb60518f0 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/ir/IrJsTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/ir/IrJsTextTestCaseGenerated.java @@ -187,32 +187,4 @@ public class IrJsTextTestCaseGenerated extends AbstractIrJsTextTestCase { runTest("compiler/testData/ir/irJsText/native/nativeNativeKotlin.kt"); } } - - @TestMetadata("compiler/testData/ir/irJsText/scripting") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Scripting extends AbstractIrJsTextTestCase { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); - } - - public void testAllFilesPresentInScripting() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/irJsText/scripting"), Pattern.compile("^(.+)\\.kt(s)?$"), null, true); - } - - @TestMetadata("arrayAssignment.kts") - public void testArrayAssignment() throws Exception { - runTest("compiler/testData/ir/irJsText/scripting/arrayAssignment.kts"); - } - - @TestMetadata("fun.kts") - public void testFun() throws Exception { - runTest("compiler/testData/ir/irJsText/scripting/fun.kts"); - } - - @TestMetadata("safeCalls.kts") - public void testSafeCalls() throws Exception { - runTest("compiler/testData/ir/irJsText/scripting/safeCalls.kts"); - } - } } diff --git a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibJsTextTestCaseGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibJsTextTestCaseGenerated.java index 8cf580c0069..0090c632a21 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibJsTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/klib/KlibJsTextTestCaseGenerated.java @@ -188,17 +188,4 @@ public class KlibJsTextTestCaseGenerated extends AbstractKlibJsTextTestCase { runTest("compiler/testData/ir/irJsText/native/nativeNativeKotlin.kt"); } } - - @TestMetadata("compiler/testData/ir/irJsText/scripting") - @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Scripting extends AbstractKlibJsTextTestCase { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest(this::doTest, TargetBackend.JS_IR, testDataFilePath); - } - - public void testAllFilesPresentInScripting() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/irJsText/scripting"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); - } - } } diff --git a/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.kt b/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.kt index c2b1e88475e..cb1827302e1 100644 --- a/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.kt +++ b/compiler/util/src/org/jetbrains/kotlin/utils/PathUtil.kt @@ -71,8 +71,6 @@ object PathUtil { const val KOTLIN_SCRIPTING_COMMON_JAR = "$KOTLIN_SCRIPTING_COMMON_NAME.jar" const val KOTLIN_SCRIPTING_JVM_NAME = "kotlin-scripting-jvm" const val KOTLIN_SCRIPTING_JVM_JAR = "$KOTLIN_SCRIPTING_JVM_NAME.jar" - const val KOTLIN_SCRIPTING_JS_NAME = "kotlin-scripting-js" - const val KOTLIN_SCRIPTING_JS_JAR = "$KOTLIN_SCRIPTING_JS_NAME.jar" const val KOTLIN_DAEMON_NAME = "kotlin-daemon" const val KOTLIN_DAEMON_JAR = "$KOTLIN_SCRIPTING_JVM_NAME.jar" const val KOTLIN_SCRIPTING_COMPILER_PLUGIN_NAME = "kotlin-scripting-compiler" @@ -89,7 +87,7 @@ object PathUtil { KOTLIN_SCRIPTING_COMPILER_PLUGIN_JAR, KOTLIN_SCRIPTING_COMPILER_IMPL_JAR, KOTLINX_COROUTINES_CORE_JAR, KOTLIN_SCRIPTING_COMMON_JAR, KOTLIN_SCRIPTING_JVM_JAR, - KOTLIN_SCRIPTING_JS_JAR, JS_ENGINES_JAR + JS_ENGINES_JAR ) const val KOTLIN_TEST_NAME = "kotlin-test" diff --git a/jps/jps-common/test/CompilerArgumentsContentProspectorTest.kt b/jps/jps-common/test/CompilerArgumentsContentProspectorTest.kt index 133be02304f..14edff52a11 100644 --- a/jps/jps-common/test/CompilerArgumentsContentProspectorTest.kt +++ b/jps/jps-common/test/CompilerArgumentsContentProspectorTest.kt @@ -230,7 +230,6 @@ class CompilerArgumentsContentProspectorTest { K2JSCompilerArguments::typedArrays, K2JSCompilerArguments::friendModulesDisabled, K2JSCompilerArguments::metadataOnly, - K2JSCompilerArguments::enableJsScripting, K2JSCompilerArguments::fakeOverrideValidator, K2JSCompilerArguments::wasm ) @@ -277,4 +276,4 @@ class CompilerArgumentsContentProspectorTest { ) } } -} \ No newline at end of file +} diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrJsTextTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrJsTextTestGenerated.java index 0aad63cd2ec..f63e0b938b5 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrJsTextTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrJsTextTestGenerated.java @@ -198,14 +198,4 @@ public class Fir2IrJsTextTestGenerated extends AbstractFir2IrJsTextTest { runTest("compiler/testData/ir/irJsText/native/nativeNativeKotlin.kt"); } } - - @Nested - @TestMetadata("compiler/testData/ir/irJsText/scripting") - @TestDataPath("$PROJECT_ROOT") - public class Scripting { - @Test - public void testAllFilesPresentInScripting() throws Exception { - KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/ir/irJsText/scripting"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true); - } - } } diff --git a/libraries/scripting/js-test/build.gradle.kts b/libraries/scripting/js-test/build.gradle.kts deleted file mode 100644 index f3457242940..00000000000 --- a/libraries/scripting/js-test/build.gradle.kts +++ /dev/null @@ -1,35 +0,0 @@ -plugins { - kotlin("jvm") -} - -val embeddableTestRuntime by configurations.creating - -dependencies { - testApi(commonDependency("junit")) - - testApi(project(":kotlin-scripting-js")) - testApi(project(":compiler:plugin-api")) - testApi(project(":kotlin-scripting-compiler-js")) - testApi(project(":compiler:cli")) - testApi(project(":compiler:backend.js")) - testApi(project(":compiler:ir.tree")) - testApi(project(":js:js.engines")) - testApi(intellijCore()) - - testRuntimeOnly(commonDependency("org.jetbrains.intellij.deps.fastutil:intellij-deps-fastutil")) - testRuntimeOnly(commonDependency("org.jetbrains.intellij.deps:jdom")) - testRuntimeOnly(commonDependency("org.jetbrains.intellij.deps:trove4j")) -} - -optInToExperimentalCompilerApi() - -sourceSets { - "main" {} - "test" { projectDefault() } -} - -projectTest(parallel = true) { - dependsOn(":kotlin-stdlib-js-ir:compileKotlinJs") - systemProperty("kotlin.js.full.stdlib.path", "libraries/stdlib/js-ir/build/classes/kotlin/js/main") - workingDir = rootDir -} diff --git a/libraries/scripting/js-test/test/org/jetbrains/kotlin/scripting/repl/js/test/AbstractJsReplTest.kt b/libraries/scripting/js-test/test/org/jetbrains/kotlin/scripting/repl/js/test/AbstractJsReplTest.kt deleted file mode 100644 index 73129140e5a..00000000000 --- a/libraries/scripting/js-test/test/org/jetbrains/kotlin/scripting/repl/js/test/AbstractJsReplTest.kt +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -@file:Suppress("DEPRECATION") - -package org.jetbrains.kotlin.scripting.repl.js.test - -import com.intellij.openapi.util.Disposer -import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys -import org.jetbrains.kotlin.cli.common.messages.MessageCollector -import org.jetbrains.kotlin.cli.common.repl.ReplCodeLine -import org.jetbrains.kotlin.cli.common.repl.ReplCompileResult -import org.jetbrains.kotlin.cli.common.repl.ReplEvalResult -import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles -import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment -import org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar -import org.jetbrains.kotlin.config.CommonConfigurationKeys -import org.jetbrains.kotlin.config.CompilerConfiguration -import org.jetbrains.kotlin.js.config.JSConfigurationKeys -import org.jetbrains.kotlin.scripting.compiler.plugin.ScriptingCompilerConfigurationComponentRegistrar -import org.jetbrains.kotlin.scripting.configuration.ScriptingConfigurationKeys -import org.jetbrains.kotlin.scripting.definitions.ScriptDefinition -import org.jetbrains.kotlin.scripting.definitions.platform -import org.jetbrains.kotlin.scripting.js.JsReplCompiler -import org.jetbrains.kotlin.scripting.js.JsReplCompilerState -import org.jetbrains.kotlin.scripting.js.ReplMessageCollector -import org.jetbrains.kotlin.scripting.repl.js.* -import java.io.Closeable -import kotlin.script.experimental.api.ScriptCompilationConfiguration -import kotlin.script.experimental.api.baseClass -import kotlin.script.experimental.api.dependencies -import kotlin.script.experimental.host.ScriptingHostConfiguration -import kotlin.script.experimental.jvm.JsDependency - -abstract class AbstractJsReplTest : Closeable { - protected lateinit var compilerState: JsReplCompilerState - protected lateinit var evaluationState: JsEvaluationState - - protected abstract fun createCompilationState(): JsReplCompilerState - protected abstract fun createEvaluationState(): JsEvaluationState - - fun compile(codeLine: ReplCodeLine): ReplCompileResult { - return JsReplCompiler(environment).compile(compilerState, codeLine) - } - - fun evaluate(compileResult: ReplCompileResult.CompiledClasses): ReplEvalResult { - return JsReplEvaluator().eval(evaluationState, compileResult) - } - - fun reset() { - collector.clear() - compilerState = createCompilationState() - evaluationState = createEvaluationState() - } - - private val collector: MessageCollector = ReplMessageCollector() - protected val disposable = Disposer.newDisposable() - protected val environment = KotlinCoreEnvironment.createForProduction( - disposable, loadConfiguration(), EnvironmentConfigFiles.JS_CONFIG_FILES - ) - - private var snippetId: Int = 1 //index 0 for klib - fun newSnippetId(): Int = snippetId++ - - private fun loadConfiguration(): CompilerConfiguration { - val configuration = CompilerConfiguration() - configuration.add(ComponentRegistrar.PLUGIN_COMPONENT_REGISTRARS, ScriptingCompilerConfigurationComponentRegistrar()) - configuration.put(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY, collector) - configuration.put(CommonConfigurationKeys.MODULE_NAME, "repl.kts") - configuration.put(JSConfigurationKeys.GENERATE_POLYFILLS, true) - val stdlibPath = System.getProperty("kotlin.js.full.stdlib.path") - val scriptConfiguration = ScriptCompilationConfiguration { - baseClass("kotlin.Any") - dependencies.append(JsDependency(stdlibPath)) - platform.put("JS") - } - configuration.add( - ScriptingConfigurationKeys.SCRIPT_DEFINITIONS, - ScriptDefinition.FromConfigurations(ScriptingHostConfiguration(), scriptConfiguration, null) - ) - return configuration - } -} diff --git a/libraries/scripting/js-test/test/org/jetbrains/kotlin/scripting/repl/js/test/JsReplTestAgainstBinaries.kt b/libraries/scripting/js-test/test/org/jetbrains/kotlin/scripting/repl/js/test/JsReplTestAgainstBinaries.kt deleted file mode 100644 index 97765e5937f..00000000000 --- a/libraries/scripting/js-test/test/org/jetbrains/kotlin/scripting/repl/js/test/JsReplTestAgainstBinaries.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.scripting.repl.js.test - -import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor -import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc -import org.jetbrains.kotlin.ir.backend.js.utils.NameTables -import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl -import org.jetbrains.kotlin.ir.util.SymbolTable -import org.jetbrains.kotlin.js.engine.ScriptEngineNashorn -import org.jetbrains.kotlin.scripting.compiler.plugin.repl.ReplCodeAnalyzerBase -import org.jetbrains.kotlin.scripting.js.* -import org.jetbrains.kotlin.scripting.repl.js.JsEvaluationState -import org.jetbrains.kotlin.scripting.repl.js.JsReplEvaluator -import java.util.concurrent.locks.ReentrantReadWriteLock - -// 1. Compile dependencies -// 2. Save them as a binary dependency (name table and js string) -// 3. For each new state load dependency's table and js code -class JsReplTestAgainstBinaries : AbstractJsReplTest() { - private val dependencyLoader = DependencyLoader() - private val dependencies = readLibrariesFromConfiguration(environment.configuration) - - init { - val nameTable = NameTables(emptyList(), mappedNames = mutableMapOf()) - val compiler = JsScriptDependencyCompiler(environment.configuration, nameTable, createSymbolTable()) - val runtimeBinary = compiler.compile(dependencies) - - dependencyLoader.saveScriptDependencyBinary(runtimeBinary) - dependencyLoader.saveNames(nameTable) - } - - override fun createCompilationState(): JsReplCompilerState { - val replState = ReplCodeAnalyzerBase.ResettableAnalyzerState() - return JsReplCompilerState(ReentrantReadWriteLock(), dependencyLoader.loadNames(), dependencies, replState, createSymbolTable()) - } - - private fun createSymbolTable(): SymbolTable = - SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImpl) - - override fun createEvaluationState(): JsEvaluationState { - val state = JsEvaluationState(ReentrantReadWriteLock(), ScriptEngineNashorn()) - JsReplEvaluator().eval(state, createCompileResult(dependencyLoader.loadScriptDependencyBinary())) - return state - } - - override fun close() { - //do nothing - } -} diff --git a/libraries/scripting/js-test/test/org/jetbrains/kotlin/scripting/repl/js/test/JsReplTestAgainstKlib.kt b/libraries/scripting/js-test/test/org/jetbrains/kotlin/scripting/repl/js/test/JsReplTestAgainstKlib.kt deleted file mode 100644 index 513147b3789..00000000000 --- a/libraries/scripting/js-test/test/org/jetbrains/kotlin/scripting/repl/js/test/JsReplTestAgainstKlib.kt +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.scripting.repl.js.test - -import com.intellij.openapi.util.Disposer -import org.jetbrains.kotlin.backend.common.serialization.signature.IdSignatureDescriptor -import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc -import org.jetbrains.kotlin.ir.backend.js.utils.NameTables -import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl -import org.jetbrains.kotlin.ir.util.SymbolTable -import org.jetbrains.kotlin.js.engine.ScriptEngineNashorn -import org.jetbrains.kotlin.scripting.compiler.plugin.repl.ReplCodeAnalyzerBase -import org.jetbrains.kotlin.scripting.js.JsReplCompilerState -import org.jetbrains.kotlin.scripting.js.JsScriptDependencyCompiler -import org.jetbrains.kotlin.scripting.js.createCompileResult -import org.jetbrains.kotlin.scripting.js.readLibrariesFromConfiguration -import org.jetbrains.kotlin.scripting.repl.js.* -import java.util.concurrent.locks.ReentrantReadWriteLock - -class JsReplTestAgainstKlib : AbstractJsReplTest() { - - private var dependencyCode: String? = null - - override fun createCompilationState(): JsReplCompilerState { - val nameTables = NameTables(emptyList(), mappedNames = mutableMapOf()) - val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImpl) - val dependencyCompiler = JsScriptDependencyCompiler(environment.configuration, nameTables, symbolTable) - val dependencies = readLibrariesFromConfiguration(environment.configuration) - dependencyCode = dependencyCompiler.compile(dependencies) - - return JsReplCompilerState( - ReentrantReadWriteLock(), - nameTables, - dependencies, - ReplCodeAnalyzerBase.ResettableAnalyzerState(), - symbolTable - ) - } - - override fun createEvaluationState(): JsEvaluationState { - val state = JsEvaluationState(ReentrantReadWriteLock(), ScriptEngineNashorn()) - - JsReplEvaluator().eval(state, createCompileResult(dependencyCode ?: error("Dependencies has to be compiled first"))) - - dependencyCode = null - - return state - } - - override fun close() { - Disposer.dispose(disposable) - } -} diff --git a/libraries/scripting/js-test/test/org/jetbrains/kotlin/scripting/repl/js/test/ReplTest.kt b/libraries/scripting/js-test/test/org/jetbrains/kotlin/scripting/repl/js/test/ReplTest.kt deleted file mode 100644 index 09ea7c378a6..00000000000 --- a/libraries/scripting/js-test/test/org/jetbrains/kotlin/scripting/repl/js/test/ReplTest.kt +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.scripting.repl.js.test - -import junit.framework.TestCase -import org.jetbrains.kotlin.cli.common.repl.ReplCompileResult -import org.junit.Assert -import org.junit.Test -import org.jetbrains.kotlin.cli.common.repl.ReplEvalResult -import org.jetbrains.kotlin.scripting.js.makeReplCodeLine - -abstract class AbstractReplTestRunner : TestCase() { - abstract fun getTester(): AbstractJsReplTest - - @Test - fun testIndependentLines() { - val lines = listOf( - "var x = 38", - "var y = 99", - "4 + 1" - ) - Assert.assertEquals(5, compileAndEval(lines)) - } - - @Test - fun testDependentLines() { - val lines = listOf( - "var x = 7", - "var y = 32", - "x + y" - ) - Assert.assertEquals(39, compileAndEval(lines)) - } - - @Test - fun testFunctionCall() { - val lines = listOf( - "var x = 2", - "var y = 3", - "fun foo(x: Int, unused: Int) = x + y", - "foo(x, x) * foo(y, y)" - ) - Assert.assertEquals(30, compileAndEval(lines)) - } - - @Test - fun testList() { - val lines = listOf( - "var a = 4", - "var b = 6", - "listOf(a, 5, b).last()" - ) - Assert.assertEquals(6, compileAndEval(lines)) - } - - @Test - fun testMatchingNames() { - val lines = listOf( - "fun foo(i: Int) = i + 2", - "fun foo(s: String) = s", - "class C {fun foo(s: String) = s + s}", - "foo(\"x\") + foo(2) + C().foo(\"class\")" - ) - Assert.assertEquals("x4classclass", compileAndEval(lines)) - } - - @Test - fun testInline() { - val lines = listOf( - "inline fun foo(i : Int) = if (i % 2 == 0) {} else i", - """ - fun box(): String { - val a = foo(1) - if (a != 1) return "fail1: ${'$'}a" - - val b = foo(2) - if (b != Unit) return "fail2: ${'$'}b" - - return "OK" - } - """, - "box()" - ) - Assert.assertEquals("OK", compileAndEval(lines)) - } - - @Test - fun testAnonymous() { - val lines = listOf( - """ - inline fun foo(f: () -> String): () -> String { - val result = f() - return { result } - } - """, - "fun bar(f: () -> String) = foo(f)()", - "fun box(): String = bar { \"OK\" }", - "box()" - ) - Assert.assertEquals("OK", compileAndEval(lines)) - } - - @Test - fun testNoneLocalReturn() { - val lines = listOf( - """ - inline fun f(ignored: () -> Any): Any { - return ignored() - } - """, - """ - fun test(): String { - f { return "OK" }; - return "error" - } - """, - "test()" - ) - Assert.assertEquals("OK", compileAndEval(lines)) - } - - /* Ignore annotation doesn't work, so comment it - @Ignore("we use Object.assign inside type checks and nashorn does not support it") - @Test - fun testInstanceOf() { - val lines = listOf( - """ - val list = listOf(1, 2, 3) - val f: Boolean = list is List - """, - "val s = list is List", - "f.toString() + s.toString()" - ) - Assert.assertEquals("truetrue", compileAndEval(lines)) - } - */ - - @Test - fun testScopes() { - val lines = listOf( - """ - fun foo(): Int { - var t = 2 * 2 - class A(val value: Int = 5) { - fun bar(): Int { - class B(val value: Int = 4) { - fun baz(): Int = value - } - var q = B().baz() - var w = 1 - return q + w - } - } - - return A().bar() * 2 - } - foo() - """ - ) - Assert.assertEquals(10, compileAndEval(lines)) - } - - @Test - fun testEvaluateFunctionName() { - val lines = listOf( - "fun evaluateScript() = 5", - "fun foo(i: Int) = i + evaluateScript()", - "foo(5)" - ) - Assert.assertEquals(10, compileAndEval(lines)) - } - - @Test - fun testMemberDeclarations() { - val lines = listOf( - """ - val a = listOf(1, 2, 3, 4, 5) - val str = "" + kotlin.math.PI - str + a.subList(2, 3).toString() + a.lastIndexOf(4) - """ - ) - Assert.assertEquals("3.141592653589793[3]3", compileAndEval(lines)) - } - - @Test - fun testInitializeScriptFunction() { - val lines = listOf( - """ - var result = "" - - class Class(val x: Int = 10) - result += Class().x - - fun function() = "#$@" - result += function() - - val field = 123456 - result += field - - val sq: (x: Int) -> Int = { x -> x * x } - result += "_" + sq(9) - - result += if (sq(5) % 2 == 0) { - class I(val x: Int = 100) - I().x - } else { - class I(val x: String = "goo") - I().x - } - - result - """ - ) - Assert.assertEquals("10#$@123456_81goo", compileAndEval(lines)) - } - - @Test - fun testFunctionReference() { - val lines = listOf( - """ - fun foo(k: String) = "O" + k - val f = ::foo - f("K") - """ - ) - - Assert.assertEquals("OK", compileAndEval(lines)) - } - - @Test - fun testPropertyReference() { - val lines = listOf( - """ - var r = "" - val o = "O" - val ro = ::o - r += ro.get() - r += ro() - - var k = "k" - var rk = ::k - r += rk.get() - rk.set("y") - r += rk() - - r - """ - ) - - Assert.assertEquals("OOky", compileAndEval(lines)) - } - - private fun compileAndEval(lines: List): Any? { - var result: Any? = null - getTester().use { tester -> - tester.reset() - - lines.forEach { line -> - val compileResult = tester.compile(makeReplCodeLine(tester.newSnippetId(), line)) - if (compileResult !is ReplCompileResult.CompiledClasses) return compileResult.toString() - - val evalResult = tester.evaluate(compileResult) - when (evalResult) { - is ReplEvalResult.Error.Runtime -> return evalResult.cause.toString() - !is ReplEvalResult.ValueResult -> return evalResult.toString() - else -> result = evalResult.value - } - } - } - return result - } -} - -class ReplTestRunnerAgainstKLib : AbstractReplTestRunner() { - override fun getTester(): AbstractJsReplTest = JsReplTestAgainstKlib() -} - -class ReplTestRunnerAgainstBinaries : AbstractReplTestRunner() { - override fun getTester(): AbstractJsReplTest = tester - - companion object { - private val tester = JsReplTestAgainstBinaries() - } -} diff --git a/libraries/scripting/js/build.gradle.kts b/libraries/scripting/js/build.gradle.kts deleted file mode 100644 index 00387212a9a..00000000000 --- a/libraries/scripting/js/build.gradle.kts +++ /dev/null @@ -1,21 +0,0 @@ - -plugins { - kotlin("jvm") - id("jps-compatible") -} - -dependencies { - api(project(":kotlin-scripting-common")) - compileOnly(project(":compiler:backend.js")) - compileOnly(project(":compiler:cli-common")) - compileOnly(project(":js:js.engines")) -} - -sourceSets { - "main" { projectDefault() } - "test" { } -} - -publish() - -standardPublicJars() diff --git a/libraries/scripting/js/src/org/jetbrains/kotlin/scripting/repl/js/JsReplEvaluator.kt b/libraries/scripting/js/src/org/jetbrains/kotlin/scripting/repl/js/JsReplEvaluator.kt deleted file mode 100644 index 4e30e0dcb14..00000000000 --- a/libraries/scripting/js/src/org/jetbrains/kotlin/scripting/repl/js/JsReplEvaluator.kt +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.scripting.repl.js - -import org.jetbrains.kotlin.cli.common.repl.* -import org.jetbrains.kotlin.js.engine.ScriptEngineNashorn -import java.util.concurrent.locks.ReentrantReadWriteLock - -class JsReplEvaluator : ReplEvaluator { - //TODO: support println() - override fun createState(lock: ReentrantReadWriteLock): IReplStageState<*> = JsEvaluationState(lock, ScriptEngineNashorn()) - - override fun eval( - state: IReplStageState<*>, - compileResult: ReplCompileResult.CompiledClasses, - scriptArgs: ScriptArgsWithTypes?, - invokeWrapper: InvokeWrapper? - ): ReplEvalResult { - return try { - val evaluationState = state.asState(JsEvaluationState::class.java) - val evalResult = evaluationState.engine.evalWithTypedResult(compileResult.data as String) - ReplEvalResult.ValueResult("result", evalResult, "Any?") - } catch (e: Exception) { - ReplEvalResult.Error.Runtime("Error while evaluating", e) - } - } -} diff --git a/libraries/scripting/js/src/org/jetbrains/kotlin/scripting/repl/js/JsReplUtils.kt b/libraries/scripting/js/src/org/jetbrains/kotlin/scripting/repl/js/JsReplUtils.kt deleted file mode 100644 index c361a640601..00000000000 --- a/libraries/scripting/js/src/org/jetbrains/kotlin/scripting/repl/js/JsReplUtils.kt +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.scripting.repl.js - -import org.jetbrains.kotlin.cli.common.repl.IReplStageHistory -import org.jetbrains.kotlin.cli.common.repl.IReplStageState -import org.jetbrains.kotlin.js.engine.ScriptEngineWithTypedResult -import java.util.concurrent.locks.ReentrantReadWriteLock -import kotlin.reflect.KClass -import kotlin.script.experimental.api.CompiledScript -import kotlin.script.experimental.api.ResultWithDiagnostics -import kotlin.script.experimental.api.ScriptCompilationConfiguration -import kotlin.script.experimental.api.ScriptEvaluationConfiguration - -// NOTE: the state management machinery is not implemented here, since it is unused at the moment in the JS REPL (see JvmReplEvaluatorState for complete implementation, if needed) -class JsEvaluationState(override val lock: ReentrantReadWriteLock, val engine: ScriptEngineWithTypedResult) : IReplStageState { - override fun dispose() { - engine.reset() - } - - override val history: IReplStageHistory - get() = TODO("not implemented") - - override val currentGeneration: Int - get() = TODO("not implemented") -} - -class JsCompiledScript( - val jsCode: String, - override val compilationConfiguration: ScriptCompilationConfiguration -) : CompiledScript { - override suspend fun getClass(scriptEvaluationConfiguration: ScriptEvaluationConfiguration?): ResultWithDiagnostics> { - throw IllegalStateException("Class is not available for JS implementation") - } -} diff --git a/libraries/scripting/js/src/org/jetbrains/kotlin/scripting/repl/js/JsScriptEvaluator.kt b/libraries/scripting/js/src/org/jetbrains/kotlin/scripting/repl/js/JsScriptEvaluator.kt deleted file mode 100644 index 34375780fa8..00000000000 --- a/libraries/scripting/js/src/org/jetbrains/kotlin/scripting/repl/js/JsScriptEvaluator.kt +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.scripting.repl.js - -import org.jetbrains.kotlin.js.engine.ScriptEngineNashorn -import kotlin.script.experimental.api.* - -class JsScriptEvaluator : ScriptEvaluator { - //TODO: support println() - private val engine = ScriptEngineNashorn() - - override suspend fun invoke( - compiledScript: CompiledScript, - scriptEvaluationConfiguration: ScriptEvaluationConfiguration - ): ResultWithDiagnostics { - return try { - val evalResult = engine.evalWithTypedResult((compiledScript as JsCompiledScript).jsCode) - ResultWithDiagnostics.Success( - EvaluationResult( - ResultValue.Value( - name = "result", - value = evalResult, - type = "Any?", - scriptClass = null, - scriptInstance = null - ), - scriptEvaluationConfiguration - ) - ) - } catch (e: Exception) { - ResultWithDiagnostics.Failure( - ScriptDiagnostic( - ScriptDiagnostic.unspecifiedError, - message = e.localizedMessage, - severity = ScriptDiagnostic.Severity.ERROR, - exception = e - ) - ) - } - } -} diff --git a/libraries/tools/kotlin-dist-for-jps-meta/pom.xml b/libraries/tools/kotlin-dist-for-jps-meta/pom.xml index fb279d66c37..6f9ab4fbf5c 100644 --- a/libraries/tools/kotlin-dist-for-jps-meta/pom.xml +++ b/libraries/tools/kotlin-dist-for-jps-meta/pom.xml @@ -86,11 +86,6 @@ kotlin-scripting-compiler ${project.version} - - ${project.groupId} - kotlin-scripting-js - ${project.version} - ${project.groupId} kotlin-scripting-jvm @@ -154,4 +149,4 @@ ${project.version} - \ No newline at end of file + diff --git a/plugins/scripting/scripting-compiler-js/build.gradle.kts b/plugins/scripting/scripting-compiler-js/build.gradle.kts deleted file mode 100644 index a5904a2aacb..00000000000 --- a/plugins/scripting/scripting-compiler-js/build.gradle.kts +++ /dev/null @@ -1,32 +0,0 @@ -description = "Kotlin Scripting Compiler JS Plugin" - -plugins { - kotlin("jvm") - id("jps-compatible") -} - -dependencies { - compileOnly(project(":compiler:frontend")) - compileOnly(project(":compiler:psi")) - compileOnly(project(":compiler:plugin-api")) - compileOnly(project(":compiler:cli")) - compileOnly(project(":compiler:backend.js")) - compileOnly(project(":core:descriptors.runtime")) - compileOnly(project(":compiler:ir.tree")) - api(project(":kotlin-scripting-common")) - api(project(":kotlin-scripting-js")) - api(project(":kotlin-util-klib")) - api(project(":kotlin-scripting-compiler")) - api(kotlinStdlib()) - compileOnly(intellijCore()) -} - -sourceSets { - "main" { projectDefault() } -} - -tasks.withType> { - kotlinOptions { - freeCompilerArgs = freeCompilerArgs - "-progressive" + "-Xskip-metadata-version-check" - } -} \ No newline at end of file diff --git a/plugins/scripting/scripting-compiler-js/src/org/jetbrains/kotlin/scripting/js/AbstractJsScriptlikeCodeAnalyser.kt b/plugins/scripting/scripting-compiler-js/src/org/jetbrains/kotlin/scripting/js/AbstractJsScriptlikeCodeAnalyser.kt deleted file mode 100644 index 7a9e33d3f94..00000000000 --- a/plugins/scripting/scripting-compiler-js/src/org/jetbrains/kotlin/scripting/js/AbstractJsScriptlikeCodeAnalyser.kt +++ /dev/null @@ -1,87 +0,0 @@ -/* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.scripting.js - -import org.jetbrains.kotlin.builtins.KotlinBuiltIns -import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment -import org.jetbrains.kotlin.cli.jvm.compiler.NoScopeRecordCliBindingTrace -import org.jetbrains.kotlin.config.languageVersionSettings -import org.jetbrains.kotlin.context.ContextForNewModule -import org.jetbrains.kotlin.context.ProjectContext -import org.jetbrains.kotlin.descriptors.ClassDescriptorWithResolutionScopes -import org.jetbrains.kotlin.descriptors.ModuleDescriptor -import org.jetbrains.kotlin.descriptors.PackageFragmentProvider -import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl -import org.jetbrains.kotlin.diagnostics.Severity -import org.jetbrains.kotlin.frontend.js.di.createTopDownAnalyzerForJs -import org.jetbrains.kotlin.incremental.components.EnumWhenTracker -import org.jetbrains.kotlin.incremental.components.ExpectActualTracker -import org.jetbrains.kotlin.incremental.components.InlineConstTracker -import org.jetbrains.kotlin.incremental.components.LookupTracker -import org.jetbrains.kotlin.name.Name -import org.jetbrains.kotlin.psi.KtFile -import org.jetbrains.kotlin.resolve.BindingContext -import org.jetbrains.kotlin.resolve.BindingTraceContext -import org.jetbrains.kotlin.resolve.CompilerEnvironment -import org.jetbrains.kotlin.resolve.TopDownAnalysisMode -import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory - -abstract class AbstractJsScriptlikeCodeAnalyser( - private val environment: KotlinCoreEnvironment, - private val dependencies: List -) { - - protected class JsScriptAnalysisResult( - val moduleDescriptor: ModuleDescriptor, - private val scriptDescriptor: ClassDescriptorWithResolutionScopes?, - val bindingContext: BindingContext - ) { - val isSuccess: Boolean get() = scriptDescriptor != null - val script: ClassDescriptorWithResolutionScopes get() = scriptDescriptor ?: error("Error occurred") - } - - protected fun analysisImpl(psi: KtFile): JsScriptAnalysisResult { - val trace: BindingTraceContext = NoScopeRecordCliBindingTrace() - val project = environment.project - val builtIns: KotlinBuiltIns = dependencies.single { it.allDependencyModules.isEmpty() }.builtIns - val moduleContext = ContextForNewModule( - ProjectContext(project, "TopDownAnalyzer for JS Script"), - Name.special("