Commit Graph

498 Commits

Author SHA1 Message Date
Andrei Klunnyi 527d20c7be KT-60171 K2-scripting: CLI specific providers are used in IDE context
^KT-60171 fixed

Merge-request: KT-MR-10987
Merged-by: Andrei Klunnyi <andrei.klunnyi@jetbrains.com>
2023-07-10 11:03:11 +00:00
Andrei Klunnyi c9eebffbfa KT-60193 K2 scripts: configuration discovery might fail silently
Due to possible data races configuration discovery might fail. So far,
it happened silently and we used so-called default one. This
configuration is unaware of specific implicit imports, receivers, base
class, etc. Hence, broken highlighting and navigation.

This commit introduces the following changes:
1. Having default configuration for building `FirScript` is no longer an
   option. Missing configuration means error reported via exception.
2. Every configuration usage is now logged in DEBUG mode.
   Troubleshooting becomes easier.

^KT-60193 fixed
2023-07-07 14:50:35 +02:00
Ilya Chernikov 02e2438d37 K2 Scripting: fix script this receiver handling in IR
also fix accessor lowering
2023-07-05 19:46:04 +00:00
Troels Bjerre Lund 111bb461a9 CLI: Change kotlin reflection to java reflection
The command line argument parser is using between 0.25s and 0.5s
(depending on platform) on finding annotated properties. This fix
replaces the slow kotlin reflection with java reflection, which is an
order of magnitude faster.

 #KT-58183 Fixed
2023-06-27 08:34:40 +00:00
Alexander Udalov 8653992ffc K2 CLI: wrap module name into angle brackets
This is not a user-visible change, so no issue is created and no tests
are added.

K1 uses angle brackets, and it will be very convenient to have the same
module names in K1 and K2, in particular to compare IR dumps where
almost everything is the same (up to a certain point) except the module
name.
2023-06-21 14:16:42 +00:00
Ilya Chernikov ae10eebc84 minor: scripting: fix processing of externally provided options 2023-06-20 16:38:32 +00:00
Ilya Chernikov 30131e289f minor: improve tests failure reporting 2023-06-20 16:38:32 +00:00
Ilya Chernikov 7db9f9c3ae minor: script some test cases to speedup parallel execution 2023-06-20 16:38:32 +00:00
Nikolay Lunyak 23f87eda1f [FIR] KT-57803: Report the error message for light tree
The renaming prevents the JVM clash.

^KT-57803 Fixed
2023-06-06 07:43:37 +00:00
Ilya Kirillov 78f09409b7 [Analysis API] move ClsKotlinBinaryClassCache/FileAttributeService service registration to StandaloneProjectFactory 2023-06-02 09:16:47 +00:00
Alexander Udalov 60016d3e5b Remove obsolete compiler flag -Xuse-ir 2023-05-30 14:46:09 +00:00
Alexander Udalov bb4bb58453 Remove tests on -Xuse-ir compiler flag
This flag is going to be removed because old backend is not supported
anymore, therefore there's no need to test it.
2023-05-30 14:46:09 +00:00
Andrei Klunnyi 6535278bd3 [KT-58817] Implicit receiver for code completion
Prior to this commit code completion for .kts files was supported only
partially. Script has an implicit receiver - base class representing a
script itself, the point where its basic API resides. The knowledge of
this receiver was missing.

There are at least two context where this knowledge is crucial:
1. Code highlighting (worked fine)
2. Code completion (failed)

`FirScriptConfiguratorExtension` is responsible for filling
`FirScriptBuilder` with base script class (in addition to other
properties). See usages of [1] in its implementation.

The thing is that resolution during the completion works a bit
different. Instead of converting the entire `KtFile` it's interested
in `KtScript` only. See usages of [2].
`RawFirBuilder.Visitor.visitScript` is where implicit receivers were
missing.

Code completion and inspections applied to `.kts` files already have
`FirScript` and don't require its full reconstruction with expensive
`FirScriptConfiguratorExtension`. `RawFirBuilder.Visitor` was modified
to support sometimes already existing `FirElement`.

----------------------------------------------------------------
[1]: ScriptCompilationConfiguration.baseClass
[2]: RawFirBuilder.Visitor.convertScript
2023-05-26 12:55:01 +00:00
Andrei Klunnyi 2a1d4a42ae [KT-58817] Implicit import issues cannot be reported
To be reported with [1] imports require source. It was missing for
implicit script imports.

`FirScriptConfiguratorExtensionImpl` was extended and now adds fake
source elements (users don't see imports in the source code).

Since diagnostics for implicit import statements are meaningless for
IDE, they are suppressed in `LLFirDiagnosticReporter`.

----------------------------------------------------------------------
[1]: DiagnosticReporter.reportOn()
2023-05-26 12:55:00 +00:00
Andrei Klunnyi 28ff94533a [KT-58817] Add script-related extensions for FIR session
The following two registrars were missing:
- FirScriptingCompilerExtensionIdeRegistrar
- FirScriptingSamWithReceiverExtensionRegistrar

`FirScriptingCompilerExtensionIdeRegistrar` was introduced as a copy of
`FirScriptingCompilerExtensionRegistrar` adapted for usage from IDE.

`FirRegisteredPluginAnnotations` and `FirJvmTypeMapper` are mandatory at
`FirExtensionService.registerExtensions` and reported as missing at
runtime.
2023-05-26 12:55:00 +00:00
Andrei Klunnyi 1b8fd01969 [KT-58817] Star-imports are not handled
Default imports coming from script configuration can be of "star" type.
Prior to this commit they were effectively ignored due to a bug at FQN
assembly.

Before: org.gradle.dsl.* => org.gradle.dsl.
After: org.gradle.dsl.* => org.gradle.dsl
2023-05-26 12:55:00 +00:00
Vladimir Dolzhenko 4a1552e907 Use nameSequence instead of file extensions to reduce memory allocations
#KTIJ-25470
2023-05-17 12:45:19 +00:00
Vladimir Dolzhenko 8ad781987e Optimize file extensions usage
#KTIJ-25470

Merge-request: KT-MR-10135
Merged-by: Vladimir Dolzhenko <Vladimir.Dolzhenko@jetbrains.com>
2023-05-15 13:59:24 +00:00
Roman Golyshev d4cffb8a5a [213] Switch to 213 platform
KTI-1114
2023-04-21 13:19:04 +00:00
Nikolay Krasko 57934a6870 Revert "Revert "[K2/N] KT-57026, KT-57208: Adjust Native & JS test infrastructures for MPP testing""
This reverts commit c0c692844e.
2023-03-10 14:24:49 +01:00
Nikolay Krasko c0c692844e Revert "[K2/N] KT-57026, KT-57208: Adjust Native & JS test infrastructures for MPP testing"
This reverts commit 6964121c15.
2023-03-10 13:14:10 +00:00
Vladimir Sukharev 6964121c15 [K2/N] KT-57026, KT-57208: Adjust Native & JS test infrastructures for MPP testing
Merge-request: KT-MR-9081
Merged-by: Vladimir Sukharev <Vladimir.Sukharev@jetbrains.com>
2023-03-09 18:56:30 +00:00
Sergej Jaskiewicz e3a4d6fa56 Use star-projected types for building ScriptProvidedPropertyDescriptors
Otherwise, the type parameters of the `kotlin.script.state` property
of type `AggregatedReplStageState` were undefined, which led to
building an ill-formed signature for the script class constructor.
2023-03-03 22:08:57 +00:00
Andrei Klunnyi 661a2626f3 KT-56632 Script configuration isn't loaded for embedded code snippets
From now on we load script configurations for embedded Kotlin code
snippets. Potentially this might lead to an extra load during a file
analysis.

IDEA side test for the change is here:
`HighlightingTestGenerated.Uncategorized#testKotlinInJavaInjection`

^KT-56632 fixed
2023-03-03 12:49:38 +00:00
Ilya Muradyan 10e9ef349f Scripts: fix NPE on creating KtFileScriptSource from PSI copy 2023-02-27 13:27:48 +00:00
Dmitriy Novozhilov 8ccd7c7d12 [FIR] Create context and scope for incremental compilation separately
Scope for incremental compilation refers to binaries from previous step
  of IC. It is used not only in IC context itself, but also it is
  subtracted from original libraries scope. Before previous commit there
  was such scheme:
1. create incremental compilation context for files of specific session
2. subtract IC scope from main libraries scope
3. use updated libraries scope to create library session
4. create all needed source session(s)

So here was a side effect of creating new IC context, which
1. is smelling code, because it increases mind complexity
2. hard to implement with new session utilities

So to fix this problem this commit changes the scheme above:
1. create IC scope and modify libraries scope
2. create libraries session
3. create source session(s) and IC context for them
2023-02-17 11:08:51 +00:00
Dmitriy Novozhilov 79e4df72bf [CLI] Introduce utilities for creating FirSession hierarchy in CLI for all platforms
Also support session creation and compilation for HMPP projects

^KT-56209 Fixed
2023-02-17 11:08:51 +00:00
Dmitriy Novozhilov d4bb740a62 [CLI] Store information about HMPP module for source files 2023-02-17 11:08:50 +00:00
Dmitriy Novozhilov 89c42e20c9 [FIR] Consistently use _function_ instead of _functional_ in names of classes and functions 2023-02-02 08:24:52 +00:00
Dmitriy Novozhilov d1b797ed97 [FIR] Generify resolution and inference of arguments of functional types 2023-02-02 08:24:50 +00:00
Dmitriy Novozhilov 88efa6bfb6 Update tests after switching to LV 1.9 2023-01-30 09:29:57 +00:00
Ivan Kochurkin 5f1ed56554 [FIR] Extract createFirLibraryListAndSession to cliCompilerUtils
Use it in compilerPipeline and FirKotlinToJvmBytecodeCompiler
2023-01-24 15:27:13 +00:00
Mikhail Glukhikh 0c4a0360ac Deserialization/class reading: pass chosen JvmMetadataVersion whenever possible 2023-01-16 18:16:07 +01:00
Ilya Chernikov d8650d9b04 Scripting: support compiler plugins in hosted script compiler
Now the plugin-related compiler arguments are respected then used in
the compiler configuration (only in the static part, not supported
if set in a refinement callback)
Note that the "embeddable" version of the plugin should be used if
embeddable compiler is used.
#KT-54095 fixed
2023-01-15 11:14:41 +01:00
Ivan Kochurkin 5d273ce839 [FIR & FIR2IR] Prepare test and CLI infrastructure to support MPP
- Move out getAnalyzerServices from FirFrontendFacade to TestSetupUtils
- Simplify DependencyListForCliModule. Now it takes BinaryModuleData as input
- FirOutArtifact contains several FirOutputArtifactPart
- Simplify FirFrontendFacade
2023-01-13 12:55:57 +00:00
Vladimir Dolzhenko 4542b3947b Clean up: rename Jet* to Kt* 2023-01-03 16:36:53 +01:00
Ilya Chernikov deb2d6d024 K2 Scripting: enable K2 tests in some test projects 2022-12-21 14:34:21 +00:00
Ilya Chernikov 90a4f6002e K2 Scripting: support sam-with-receiver in scripting plugin 2022-12-21 14:34:21 +00:00
Ilya Chernikov 00a28f9f49 K2 Scripting: compiler extension for script configuration 2022-12-21 14:34:20 +00:00
Ilya Chernikov 337d11d4c8 K2 Scripting: enable K2 compilation in scripting plugin 2022-12-21 14:34:19 +00:00
Ilya Chernikov 88d140527f Scripting: optimize check for allowed scripts on init 2022-12-18 16:49:41 +00:00
Alexander Udalov 60d96b7d15 Remove some leftover imports of unsafe cast functions 2022-12-06 19:44:56 +00:00
Alexander Korepanov d5e9e87538 [JS BE] Drop JS scripting support
JS scripting uses the old IR to JS transformer.
 The new IR to JS transformer can not be used for
 JS scripting out of the box. Patching the new transformer for
 JS scripting is potentially dangerous and requires a lot of effort.
 Dropping JS scripting and the old IR to JS transformer allows to
 refactor and simplify JS BE codebase.
2022-11-04 14:15:15 +00:00
Ilya Chernikov 5d968bc2f4 Fix gradle scripts detection in the sources
#KT-54325 fixed
2022-10-31 09:30:13 +00:00
Ilya Chernikov b50a803b6f Make jdk root processing more robust
#KT-54337 fixed
2022-10-21 06:11:42 +00:00
Dmitriy Dolovov 15635482aa [IR] Partial linkage: Enable it by just passing a boolean flag to IR linker constructor 2022-10-19 13:46:22 +00:00
Ilya Chernikov 6627b62c21 Fix sources extraction when processing extension is on
The latter is used e.g. for scripts in source roots handling
as implemented in the commit
"Scripting: update scripts in source roots handling"
The former implementation did not covered all the cases.

#KT-54355 fixed
2022-10-18 16:29:06 +00:00
Ilya Muradyan 7f6bd2ab1e Fix compatibility issue for kotlin.jupyter 2022-10-08 04:02:39 +02:00
Simon Ogorodnik 0fea8073ef Scripting Plugin. Update CoreFileTypeRegistry under lock
CoreFileTypeRegistry isn't thread-safe, so it should be updated under
application lock, to avoid concurrently mutating underlying structure
2022-10-03 13:36:06 +00:00
Ilya Goncharov d203dc35bf [JS IR] Add to IR keep possibility similar to legacy-dce one
It helps to:

- keep declarations even if they are not reachable and not exported
- not minify names of not exported declarations

Compiler argument: -Xir-keep=A,B

Can be used for top-level declarations or for member

^KT-54118 fixed
2022-09-20 16:06:17 +00:00