Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -170,10 +170,13 @@ maven = use_extension("@rules_jvm_external//:extensions.bzl", "maven")
# from this directory after modifying the following to update maven_install.json
maven.install(
name = "maven_deps",
# The Caffeine version needs to match https://github.com/JetBrains/kotlin/blob/master/gradle/libs.versions.toml
# See also https://youtrack.jetbrains.com/issue/KT-73751/Analysis-API-Caffeine-dependency which seeks a better
# way of including the needed dependency.
artifacts = [
"org.jetbrains.kotlin:%s:2.0.20-RC2" % kotlin_lib
"org.jetbrains.kotlin:%s:2.1.0" % kotlin_lib
for kotlin_lib in ("kotlin-annotation-processing", "kotlin-compiler")
],
] + [ "com.github.ben-manes.caffeine:caffeine:2.9.3" ] ,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be worth adding a comment like

We need the version specified in https://github.com/JetBrains/kotlin/blob/master/gradle/libs.versions.toml

so we don't upgrade to the latest version without thinking.

Depending on what happens with https://youtrack.jetbrains.com/issue/KT-73751/Analysis-API-Caffeine-dependency we might be able to do better here in the future.

lock_file = "//:maven_install.json",
repositories = [
"https://repo1.maven.org/maven2",
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion java/kotlin-extractor2/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ kt_jvm_library(
"kotlin_annotation_processing",
"kotlin_compiler",
)
],
] + ["@maven_deps//:com_github_ben_manes_caffeine_caffeine"],
)

java_binary(
Expand Down
7 changes: 4 additions & 3 deletions java/kotlin-extractor2/src/main/kotlin/KotlinExtractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import kotlinx.coroutines.withContext
import org.jetbrains.kotlin.analysis.api.KaAnalysisApiInternals
import org.jetbrains.kotlin.analysis.api.KaSession
import org.jetbrains.kotlin.analysis.api.analyze
import org.jetbrains.kotlin.analysis.api.platform.lifetime.KotlinAlwaysAccessibleLifetimeTokenProvider
import org.jetbrains.kotlin.analysis.api.platform.lifetime.KotlinLifetimeTokenProvider
import org.jetbrains.kotlin.analysis.api.platform.lifetime.KotlinAlwaysAccessibleLifetimeTokenFactory
import org.jetbrains.kotlin.analysis.api.platform.lifetime.KotlinLifetimeTokenFactory
import org.jetbrains.kotlin.analysis.api.projectStructure.KaSourceModule
import org.jetbrains.kotlin.analysis.api.standalone.buildStandaloneAnalysisAPISession
import org.jetbrains.kotlin.analysis.project.structure.builder.buildKtLibraryModule
Expand Down Expand Up @@ -166,6 +166,7 @@ OLD: KE1
)
dtw.flush()
loggerBase.close()
System.exit(0) // TODO: figure out what's keeping the JVM awake
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to include the context at #18215 (comment) identifying thread-pool cleanup as the cause

}
}

Expand All @@ -187,7 +188,7 @@ private fun doAnalysis(
val ourLanguageVersionSettings = k2args.toLanguageVersionSettings(MessageCollector.NONE)

val session = buildStandaloneAnalysisAPISession {
registerProjectService(KotlinLifetimeTokenProvider::class.java, KotlinAlwaysAccessibleLifetimeTokenProvider())
registerProjectService(KotlinLifetimeTokenFactory::class.java, KotlinAlwaysAccessibleLifetimeTokenFactory())
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in Kotlin 2.1.0


// TODO: Is there a better way we can do all this directly from k2args?

Expand Down
68 changes: 2 additions & 66 deletions java/kotlin-extractor2/src/main/kotlin/KotlinFileExtractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -301,20 +301,19 @@ OLD: KE1
*/
}

// TODO: the below should be KaFunctionSymbol
is KaNamedFunctionSymbol -> {
is KaFunctionSymbol -> {
val parentId = useDeclarationParentOf(declaration, false)?.cast<DbReftype>()
if (parentId != null) {
extractFunction(
declaration,
parentId,
listOf()
/*
OLD: KE1
extractBody = extractFunctionBodies,
extractMethodAndParameterTypeAccesses = extractFunctionBodies,
extractAnnotations = extractAnnotations,
null,
listOf()
*/
)
} else
Expand Down Expand Up @@ -390,69 +389,6 @@ OLD: KE1

/*
OLD: KE1
private fun extractTypeParameter(
tp: IrTypeParameter,
apparentIndex: Int,
javaTypeParameter: JavaTypeParameter?
): Label<out DbTypevariable>? {
with("type parameter", tp) {
val parentId = getTypeParameterParentLabel(tp) ?: return null
val id = tw.getLabelFor<DbTypevariable>(getTypeParameterLabel(tp))

// Note apparentIndex does not necessarily equal `tp.index`, because at least
// constructor type parameters
// have indices offset from the type parameters of the constructed class (i.e. the
// parameter S of
// `class Generic<T> { public <S> Generic(T t, S s) { ... } }` will have `tp.index` 1,
// not 0).
tw.writeTypeVars(id, tp.name.asString(), apparentIndex, 0, parentId)
val locId = tw.getLocation(tp)
tw.writeHasLocation(id, locId)

// Annoyingly, we have no obvious way to pair up the bounds of an IrTypeParameter and a
// JavaTypeParameter
// because JavaTypeParameter provides a Collection not an ordered list, so we can only
// do our best here:
fun tryGetJavaBound(idx: Int) =
when (tp.superTypes.size) {
1 -> javaTypeParameter?.upperBounds?.singleOrNull()
else -> (javaTypeParameter?.upperBounds as? List)?.getOrNull(idx)
}

tp.superTypes.forEachIndexed { boundIdx, bound ->
if (!(bound.isAny() || bound.isNullableAny())) {
tw.getLabelFor<DbTypebound>("@\"bound;$boundIdx;{$id}\"") {
// Note we don't look for @JvmSuppressWildcards here because it doesn't seem
// to have any impact
// on kotlinc adding wildcards to type parameter bounds.
val boundWithWildcards =
addJavaLoweringWildcards(bound, true, tryGetJavaBound(tp.index))
tw.writeTypeBounds(
it,
useType(boundWithWildcards).javaResult.id.cast<DbReftype>(),
boundIdx,
id
)
}
}
}

if (tp.isReified) {
addModifiers(id, "reified")
}

if (tp.variance == Variance.IN_VARIANCE) {
addModifiers(id, "in")
} else if (tp.variance == Variance.OUT_VARIANCE) {
addModifiers(id, "out")
}

// extractAnnotations(tp, id)
// TODO: introduce annotations once they can be disambiguated from bounds, which are
// also child expressions.
return id
}
}

private fun extractVisibility(
elementForLocation: IrElement,
Expand Down
Loading
Loading