Skip to content

Commit a2f38ae

Browse files
committed
KTL-2962 Compilation with BTA for JVM
1 parent 76a2558 commit a2f38ae

File tree

24 files changed

+1191
-1058
lines changed

24 files changed

+1191
-1058
lines changed

.github/workflows/gradle.yml

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,4 @@ jobs:
3131
- name: Setup Gradle
3232
uses: gradle/actions/setup-gradle@v4
3333
- name: Build with Gradle
34-
run: |
35-
if [[ "${{ github.ref }}" == "refs/heads/kotlin-community/*" ]]; then
36-
./gradlew build -Pkotlin_repo_url=https://redirector.kotlinlang.org/maven/dev
37-
else
38-
./gradlew build
39-
fi
34+
run: ./gradlew build

build-settings-logic/src/main/kotlin/kotlin-compiler-server-version-catalog.settings.gradle.kts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ pluginManagement {
22
repositories {
33
gradlePluginPortal()
44
mavenCentral()
5+
mavenLocal()
56

67
val additionalRepositoryProperty = providers.gradleProperty("kotlin_repo_url")
78
if (additionalRepositoryProperty.isPresent) {
@@ -10,7 +11,9 @@ pluginManagement {
1011
}
1112
logger.info("A custom Kotlin repository ${additionalRepositoryProperty.get()} was added")
1213
}
13-
mavenLocal()
14+
15+
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
16+
maven("https://redirector.kotlinlang.org/maven/dev")
1417
}
1518
}
1619

@@ -19,6 +22,7 @@ dependencyResolutionManagement {
1922
repositories {
2023
mavenCentral()
2124
gradlePluginPortal()
25+
mavenLocal()
2226

2327
val additionalRepositoryProperty = providers.gradleProperty("kotlin_repo_url")
2428
if (additionalRepositoryProperty.isPresent) {
@@ -27,7 +31,18 @@ dependencyResolutionManagement {
2731
}
2832
logger.info("A custom Kotlin repository ${additionalRepositoryProperty.get()} was added")
2933
}
30-
mavenLocal()
34+
35+
maven("https://repo.spring.io/snapshot")
36+
maven("https://repo.spring.io/milestone")
37+
maven("https://redirector.kotlinlang.org/maven/kotlin-ide")
38+
maven("https://redirector.kotlinlang.org/maven/dev")
39+
maven("https://cache-redirector.jetbrains.com/jetbrains.bintray.com/intellij-third-party-dependencies")
40+
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/kotlin-ide-plugin-dependencies")
41+
maven("https://www.myget.org/F/rd-snapshots/maven/")
42+
maven("https://redirector.kotlinlang.org/maven/kotlin-ide")
43+
maven("https://maven.pkg.jetbrains.space/kotlin/p/kotlin/bootstrap")
44+
maven("https://maven.pkg.jetbrains.space/kotlin/p/wasm/experimental")
45+
maven("https://maven.pkg.jetbrains.space/public/p/compose/dev")
3146
}
3247

3348
versionCatalogs {

build.gradle.kts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@ allprojects {
2525
dependencies {
2626
dependencies {
2727
implementation(libs.jackson.module.kotlin)
28-
implementation(libs.kotlin.idea) {
29-
isTransitive = false
30-
}
3128
}
3229
}
3330
}
@@ -51,15 +48,14 @@ dependencies {
5148
implementation(libs.logback.logstash.encoder)
5249
implementation(libs.intellij.trove4j)
5350
implementation(libs.kotlin.reflect)
54-
implementation(libs.kotlin.stdlib)
55-
implementation(libs.kotlin.compiler)
51+
implementation(libs.bundles.kotlin.stdlib)
5652
implementation(libs.kotlin.script.runtime)
57-
implementation(libs.kotlin.compiler.ide) {
58-
isTransitive = false
59-
}
60-
implementation(libs.kotlin.core)
6153
implementation(project(":executors", configuration = "default"))
6254
implementation(project(":common", configuration = "default"))
55+
implementation("org.jetbrains.kotlin:kotlin-build-tools-api:${libs.versions.kotlin.get()}")
56+
implementation("org.jetbrains.kotlin:kotlin-build-tools-impl:${libs.versions.kotlin.get()}")
57+
implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:${libs.versions.kotlin.get()}")
58+
implementation("org.jetbrains.kotlin:kotlin-tooling-core:${libs.versions.kotlin.get()}")
6359

6460
testImplementation(libs.kotlin.test)
6561
testImplementation("org.springframework.boot:spring-boot-starter-test") {

common/build.gradle.kts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,5 @@ plugins {
33
}
44

55
dependencies {
6-
implementation(libs.kotlin.compiler)
7-
implementation(libs.kotlin.gradle.plugin.idea)
8-
implementation(libs.kotlin.base.fe10.analysis)
9-
}
6+
implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:${libs.versions.kotlin.get()}")
7+
}

common/src/main/kotlin/component/KotlinEnvironment.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package component
22

3-
import com.intellij.openapi.util.Disposer
43
import org.jetbrains.kotlin.cli.common.arguments.K2JVMCompilerArguments
54
import org.jetbrains.kotlin.cli.common.arguments.parseCommandLineArguments
65
import org.jetbrains.kotlin.cli.common.arguments.toLanguageVersionSettings
@@ -19,9 +18,10 @@ import org.jetbrains.kotlin.js.config.JSConfigurationKeys
1918
import org.jetbrains.kotlin.library.impl.isKotlinLibrary
2019
import org.jetbrains.kotlin.serialization.js.JsModuleDescriptor
2120
import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil
22-
import org.jetbrains.kotlin.serialization.js.ModuleKind
21+
import org.jetbrains.kotlin.js.config.ModuleKind
2322
import org.jetbrains.kotlin.utils.KotlinJavascriptMetadataUtils
2423
import org.jetbrains.kotlin.wasm.config.WasmConfigurationKeys
24+
import org.jetbrains.kotlin.com.intellij.openapi.util.Disposer
2525
import java.io.File
2626

2727
// NOTE: if new class paths are added, please add them to `JavaExec` task's inputs in build.gradle.kts as well

dependencies/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ dependencies {
105105
kotlinDependency(libs.hamcrest)
106106
kotlinDependency(libs.bundles.jackson)
107107
// Kotlin libraries
108-
kotlinDependency(libs.kotlin.stdlib)
108+
kotlinDependency(libs.bundles.kotlin.stdlib)
109109
kotlinDependency(libs.kotlin.test)
110110
kotlinDependency(libs.kotlin.test.junit)
111111
kotlinDependency(libs.kotlinx.coroutines.core.jvm)

gradle/libs.versions.toml

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
[versions]
2-
kotlin = "2.3.0-dev-6977"
3-
kotlinIdeVersion = "1.9.20-506"
4-
kotlinIdeVersionWithSuffix = "231-1.9.20-506-IJ8109.175"
2+
kotlin = "2.3.0-dev-9673"
53
spring-boot = "3.5.5"
64
spring-dependency-managment = "1.1.7"
75
springdoc = "2.8.13"
@@ -24,21 +22,17 @@ gradle-develocity = "3.17.5"
2422
[libraries]
2523
kotlin-reflect = { group = "org.jetbrains.kotlin", name = "kotlin-reflect", version.ref = "kotlin" }
2624
kotlin-stdlib = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref = "kotlin" }
25+
kotlin-stdlib-jdk7 = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk7", version.ref = "kotlin" }
26+
kotlin-stdlib-jdk8 = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-jdk8", version.ref = "kotlin" }
2727
kotlin-stdlib-js = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-js", version.ref = "kotlin" }
2828
kotlin-stdlib-wasm-js = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib-wasm-js", version.ref = "kotlin" }
2929
kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test", version.ref = "kotlin" }
3030
kotlin-test-junit = { group = "org.jetbrains.kotlin", name = "kotlin-test-junit", version.ref = "kotlin" }
31-
kotlin-compiler = { group = "org.jetbrains.kotlin", name = "kotlin-compiler", version.ref = "kotlin" }
3231
kotlin-compiler-arguments-description = { group = "org.jetbrains.kotlin", name = "kotlin-compiler-arguments-description", version.ref = "kotlin" }
3332
kotlin-script-runtime = { group = "org.jetbrains.kotlin", name = "kotlin-script-runtime", version.ref = "kotlin" }
3433
kotlin-gradlePlugin = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin", version.ref = "kotlin" }
35-
kotlin-gradle-plugin-idea = { group = "org.jetbrains.kotlin", name = "kotlin-gradle-plugin-idea", version.ref = "kotlin" }
3634
kotlin-dom-api-compat = { group = "org.jetbrains.kotlin", name = "kotlin-dom-api-compat", version.ref = "kotlin" }
3735
kotlin-compose-compiler-plugin = { group = "org.jetbrains.kotlin", name = "kotlin-compose-compiler-plugin", version.ref = "kotlin" }
38-
kotlin-base-fe10-analysis = { group = "org.jetbrains.kotlin", name = "base-fe10-analysis", version.ref = "kotlinIdeVersionWithSuffix" }
39-
kotlin-compiler-ide = { group = "org.jetbrains.kotlin", name = "kotlin-compiler-for-ide", version.ref = "kotlinIdeVersion" }
40-
kotlin-idea = { group = "org.jetbrains.kotlin", name = "idea", version.ref = "kotlinIdeVersionWithSuffix" }
41-
kotlin-core = { group = "org.jetbrains.kotlin", name = "core", version.ref = "kotlinIdeVersionWithSuffix" }
4236
kotlinx-coroutines-core-jvm = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core-jvm", version.ref = "kotlinx-coroutines" }
4337
kotlinx-coroutines-test = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-test", version.ref = "kotlinx-coroutines-test" }
4438
kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "kotlinx-datetime" }
@@ -74,6 +68,7 @@ spring-context-indexer = { group = "org.springframework", name = "spring-context
7468
springdoc = { group = "org.springdoc", name = "springdoc-openapi-starter-webmvc-ui", version.ref = "springdoc" }
7569

7670
[bundles]
71+
kotlin-stdlib = ["kotlin-stdlib", "kotlin-stdlib-jdk7", "kotlin-stdlib-jdk8"]
7772
jackson = ["jackson-databind", "jackson-core", "jackson-annotations"]
7873
compose = [
7974
"compose-runtime",

indexation/build.gradle.kts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@ plugins {
55

66
dependencies {
77
implementation(project(":common", configuration = "default"))
8-
implementation(libs.kotlin.compiler.ide) {
9-
isTransitive = false
10-
}
8+
implementation("org.jetbrains.kotlin:kotlin-compiler-embeddable:${libs.versions.kotlin.get()}")
119
}
1210

1311
application {

indexation/src/main/kotlin/DescriptorsUtils.kt

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ package indexation
33
import model.ImportInfo
44
import model.Icon
55
import org.jetbrains.kotlin.descriptors.*
6-
import org.jetbrains.kotlin.idea.imports.importableFqName
7-
import org.jetbrains.kotlin.idea.util.IdeDescriptorRenderers
86
import org.jetbrains.kotlin.name.FqName
97
import org.jetbrains.kotlin.renderer.ClassifierNamePolicy
108
import org.jetbrains.kotlin.renderer.ParameterNameRenderingPolicy
@@ -13,34 +11,45 @@ import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
1311
import org.jetbrains.kotlin.resolve.scopes.MemberScope
1412
import org.jetbrains.kotlin.types.asFlexibleType
1513
import org.jetbrains.kotlin.types.isFlexible
14+
import org.jetbrains.kotlin.renderer.DescriptorRenderer
1615

17-
internal val renderer = IdeDescriptorRenderers.SOURCE_CODE.withOptions {
16+
// Local replacement for IDEA's importableFqName
17+
private val DeclarationDescriptor.importableFqNameOrNull: FqName?
18+
get() = when (this) {
19+
is PackageFragmentDescriptor, is PackageViewDescriptor -> null
20+
is ConstructorDescriptor -> containingDeclaration.importableFqNameOrNull
21+
is PropertyAccessorDescriptor -> correspondingProperty.importableFqNameOrNull
22+
else -> DescriptorUtils.getFqNameSafe(this).takeIf { !it.isRoot }
23+
}
24+
25+
internal val renderer = DescriptorRenderer.COMPACT.withOptions {
1826
classifierNamePolicy = ClassifierNamePolicy.SHORT
19-
typeNormalizer = IdeDescriptorRenderers.APPROXIMATE_FLEXIBLE_TYPES
2027
parameterNameRenderingPolicy = ParameterNameRenderingPolicy.ALL
21-
typeNormalizer = {
22-
if (it.isFlexible()) it.asFlexibleType().upperBound
23-
else it
28+
// Approximate flexible types by their upper bound
29+
typeNormalizer = { type ->
30+
if (type.isFlexible()) type.asFlexibleType().upperBound else type
2431
}
2532
}
2633

2734
internal fun DeclarationDescriptor.toImportInfo(): ImportInfo? {
28-
val importName = importableFqName?.asString() ?: return null
35+
val importName = importableFqNameOrNull?.asString() ?: return null
2936
if (name.asString() == "Companion") return null
3037
return when (this) {
3138
is FunctionDescriptor -> {
3239
if (visibility.isPublicAPI) {
33-
val returnTypeVal = if (returnType != null) renderer.renderType(returnType!!)
34-
else {extensionReceiverParameter?.let { param ->
35-
" for ${renderer.renderType(param.type)} in ${DescriptorUtils.getFqName(containingDeclaration)}"
36-
} ?: "" }
37-
ImportInfo(
38-
importName = importName,
39-
shortName = name.asString(),
40-
fullName = name.asString() + renderer.renderFunctionParameters(this),
41-
returnType = returnTypeVal,
42-
icon = Icon.METHOD
43-
) } else null
40+
val returnTypeVal = if (returnType != null) renderer.renderType(returnType!!)
41+
else {extensionReceiverParameter?.let { param ->
42+
" for ${renderer.renderType(param.type)} in ${DescriptorUtils.getFqName(containingDeclaration)}"
43+
} ?: ""
44+
}
45+
ImportInfo(
46+
importName = importName,
47+
shortName = name.asString(),
48+
fullName = name.asString() + renderer.renderFunctionParameters(this),
49+
returnType = returnTypeVal,
50+
icon = Icon.METHOD
51+
)
52+
} else null
4453
}
4554

4655
is ClassDescriptor -> {
@@ -72,8 +81,10 @@ internal fun DeclarationDescriptor.toImportInfo(): ImportInfo? {
7281
internal fun DeclarationDescriptor.getInnerClassesAndAllStaticFunctions(): List<DeclarationDescriptor>? {
7382
return if (this !is ClassDescriptor || !visibility.isPublicAPI)
7483
null
75-
else (unsubstitutedInnerClassesScope.getContributedDescriptors(DescriptorKindFilter.ALL, MemberScope.ALL_NAME_FILTER) +
76-
staticScope.getContributedDescriptors(DescriptorKindFilter.ALL, MemberScope.ALL_NAME_FILTER)).distinct()
84+
else (
85+
unsubstitutedInnerClassesScope.getContributedDescriptors(DescriptorKindFilter.ALL, MemberScope.ALL_NAME_FILTER) +
86+
staticScope.getContributedDescriptors(DescriptorKindFilter.ALL, MemberScope.ALL_NAME_FILTER)
87+
).distinct()
7788
}
7889

7990
internal fun ModuleDescriptor.allImportsInfo(): List<ImportInfo> {
@@ -91,9 +102,8 @@ internal fun ModuleDescriptor.allPackages(): Collection<FqName> {
91102
val result = mutableListOf<FqName>()
92103
fun impl(pkg: FqName) {
93104
result += pkg
94-
95105
getSubPackagesOf(pkg) { true }.forEach { impl(it) }
96106
}
97107
impl(FqName.ROOT)
98108
return result
99-
}
109+
}
Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,53 @@
1-
package com.compiler.server.compiler
2-
3-
import com.intellij.openapi.project.Project
4-
import com.intellij.openapi.vfs.CharsetToolkit
5-
import com.intellij.psi.PsiElement
6-
import com.intellij.psi.PsiFileFactory
7-
import com.intellij.psi.impl.PsiFileFactoryImpl
8-
import com.intellij.testFramework.LightVirtualFile
9-
import org.jetbrains.kotlin.idea.KotlinLanguage
10-
import org.jetbrains.kotlin.psi.KtExpression
11-
import org.jetbrains.kotlin.psi.KtFile
12-
13-
class KotlinFile(val kotlinFile: KtFile) {
14-
15-
fun elementAt(
16-
line: Int,
17-
character: Int
18-
): PsiElement? = kotlinFile.findElementAt(offsetFor(line, character))?.let { expressionFor(it) }
19-
20-
fun insert(content: String, atLine: Int, atCharacter: Int): KotlinFile {
21-
val caretPositionOffset = offsetFor(atLine, atCharacter)
22-
return if (caretPositionOffset != 0) {
23-
from(
24-
project = kotlinFile.project,
25-
name = kotlinFile.name,
26-
content = StringBuilder(kotlinFile.text.substring(0, caretPositionOffset))
27-
.append(content)
28-
.append(kotlinFile.text.substring(caretPositionOffset)).toString()
29-
)
30-
} else this
31-
}
32-
33-
private fun offsetFor(line: Int, character: Int) =
34-
(kotlinFile.viewProvider.document?.getLineStartOffset(line) ?: 0) + character
35-
36-
private tailrec fun expressionFor(element: PsiElement): PsiElement =
37-
if (element is KtExpression) element else expressionFor(element.parent)
38-
39-
companion object {
40-
fun from(project: Project, name: String, content: String) =
41-
KotlinFile(
42-
(PsiFileFactory.getInstance(project) as PsiFileFactoryImpl)
43-
.trySetupPsiForFile(
44-
LightVirtualFile(
45-
if (name.endsWith(".kt")) name else "$name.kt",
46-
KotlinLanguage.INSTANCE,
47-
content
48-
).apply { charset = CharsetToolkit.UTF8_CHARSET },
49-
KotlinLanguage.INSTANCE, true, false
50-
) as KtFile
51-
)
52-
}
53-
}
1+
//package com.compiler.server.compiler
2+
//
3+
//import com.intellij.openapi.project.Project
4+
//import com.intellij.openapi.vfs.CharsetToolkit
5+
//import com.intellij.psi.PsiElement
6+
//import com.intellij.psi.PsiFileFactory
7+
//import com.intellij.psi.impl.PsiFileFactoryImpl
8+
//import com.intellij.testFramework.LightVirtualFile
9+
//import org.jetbrains.kotlin.idea.KotlinLanguage
10+
//import org.jetbrains.kotlin.psi.KtExpression
11+
//import org.jetbrains.kotlin.psi.KtFile
12+
//
13+
//class KotlinFile(val kotlinFile: KtFile) {
14+
//
15+
// fun elementAt(
16+
// line: Int,
17+
// character: Int
18+
// ): PsiElement? = kotlinFile.findElementAt(offsetFor(line, character))?.let { expressionFor(it) }
19+
//
20+
// fun insert(content: String, atLine: Int, atCharacter: Int): KotlinFile {
21+
// val caretPositionOffset = offsetFor(atLine, atCharacter)
22+
// return if (caretPositionOffset != 0) {
23+
// from(
24+
// project = kotlinFile.project,
25+
// name = kotlinFile.name,
26+
// content = StringBuilder(kotlinFile.text.substring(0, caretPositionOffset))
27+
// .append(content)
28+
// .append(kotlinFile.text.substring(caretPositionOffset)).toString()
29+
// )
30+
// } else this
31+
// }
32+
//
33+
// private fun offsetFor(line: Int, character: Int) =
34+
// (kotlinFile.viewProvider.document?.getLineStartOffset(line) ?: 0) + character
35+
//
36+
// private tailrec fun expressionFor(element: PsiElement): PsiElement =
37+
// if (element is KtExpression) element else expressionFor(element.parent)
38+
//
39+
// companion object {
40+
// fun from(project: Project, name: String, content: String) =
41+
// KotlinFile(
42+
// (PsiFileFactory.getInstance(project) as PsiFileFactoryImpl)
43+
// .trySetupPsiForFile(
44+
// LightVirtualFile(
45+
// if (name.endsWith(".kt")) name else "$name.kt",
46+
// KotlinLanguage.INSTANCE,
47+
// content
48+
// ).apply { charset = CharsetToolkit.UTF8_CHARSET },
49+
// KotlinLanguage.INSTANCE, true, false
50+
// ) as KtFile
51+
// )
52+
// }
53+
//}

0 commit comments

Comments
 (0)