diff --git a/MODULE.bazel b/MODULE.bazel index c1c940ee744f..2f50375a4bca 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -324,6 +324,7 @@ use_repo( "kotlin-compiler-2.3.20", "kotlin-compiler-2.4.0", "kotlin-compiler-2.4.20", + "kotlin-compiler-2.5.0-RC2", "kotlin-compiler-embeddable-1.8.0", "kotlin-compiler-embeddable-1.9.0-Beta", "kotlin-compiler-embeddable-1.9.20-Beta", @@ -337,6 +338,7 @@ use_repo( "kotlin-compiler-embeddable-2.3.20", "kotlin-compiler-embeddable-2.4.0", "kotlin-compiler-embeddable-2.4.20", + "kotlin-compiler-embeddable-2.5.0-RC2", "kotlin-stdlib-1.8.0", "kotlin-stdlib-1.9.0-Beta", "kotlin-stdlib-1.9.20-Beta", @@ -350,6 +352,7 @@ use_repo( "kotlin-stdlib-2.3.20", "kotlin-stdlib-2.4.0", "kotlin-stdlib-2.4.20", + "kotlin-stdlib-2.5.0-RC2", ) go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk") diff --git a/docs/codeql/reusables/supported-versions-compilers.rst b/docs/codeql/reusables/supported-versions-compilers.rst index 9cb146a638d1..412a37f142b5 100644 --- a/docs/codeql/reusables/supported-versions-compilers.rst +++ b/docs/codeql/reusables/supported-versions-compilers.rst @@ -21,7 +21,7 @@ Java,"Java 7 to 27 [5]_","javac (OpenJDK and Oracle JDK), Eclipse compiler for Java (ECJ) [6]_",``.java`` - Kotlin,"Kotlin 1.8.0 to 2.4.2\ *x*","kotlinc",``.kt`` + Kotlin,"Kotlin 1.8.0 to 2.5.0\ *x*","kotlinc",``.kt`` JavaScript,ECMAScript 2022 or lower,Not applicable,"``.js``, ``.jsx``, ``.mjs``, ``.es``, ``.es6``, ``.htm``, ``.html``, ``.xhtm``, ``.xhtml``, ``.vue``, ``.hbs``, ``.ejs``, ``.njk``, ``.json``, ``.yaml``, ``.yml``, ``.raml``, ``.xml`` [7]_" Python [8]_,"2.7, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13, 3.14",Not applicable,``.py`` Ruby,"up to 3.3",Not applicable,"``.rb``, ``.erb``, ``.gemspec``, ``Gemfile``" diff --git a/java/kotlin-extractor/deps/kotlin-compiler-2.5.0-RC2.jar b/java/kotlin-extractor/deps/kotlin-compiler-2.5.0-RC2.jar new file mode 100644 index 000000000000..0dc83ed94fc7 --- /dev/null +++ b/java/kotlin-extractor/deps/kotlin-compiler-2.5.0-RC2.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:302015ffd351a1d7d2a6ef0c4e7cda88c1fa15d3da651ed6beedee9e5e5ba6b7 +size 60766544 diff --git a/java/kotlin-extractor/deps/kotlin-compiler-embeddable-2.5.0-RC2.jar b/java/kotlin-extractor/deps/kotlin-compiler-embeddable-2.5.0-RC2.jar new file mode 100644 index 000000000000..b3c6b25a83a3 --- /dev/null +++ b/java/kotlin-extractor/deps/kotlin-compiler-embeddable-2.5.0-RC2.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd5d5aac23d6d2d8ea8537464bd86fadb47dfb42b83fa24c353e37c26fe9d873 +size 59197160 diff --git a/java/kotlin-extractor/deps/kotlin-stdlib-2.5.0-RC2.jar b/java/kotlin-extractor/deps/kotlin-stdlib-2.5.0-RC2.jar new file mode 100644 index 000000000000..42e10a61a231 --- /dev/null +++ b/java/kotlin-extractor/deps/kotlin-stdlib-2.5.0-RC2.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:88dd3429edda2b1457d933a580e043bdcef4361a731e906b43616badfed90cd2 +size 1906670 diff --git a/java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt b/java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt index 9f524de737e2..b1a5f43d346b 100644 --- a/java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt +++ b/java/kotlin-extractor/src/main/kotlin/KotlinExtractorExtension.kt @@ -164,7 +164,7 @@ class KotlinExtractorExtension( } ?: "kotlin-extractor/src" ) srcDir.mkdirs() - val globalExtensionState = KotlinExtractorGlobalState() + val globalExtensionState = KotlinExtractorGlobalState(moduleFragment) moduleFragment.files.mapIndexed { index: Int, file: IrFile -> val fileExtractionProblems = FileExtractionProblems(invocationExtractionProblems) val fileTrapWriter = tw.makeSourceFileTrapWriter(file, true) @@ -264,7 +264,7 @@ class KotlinExtractorExtension( } } -class KotlinExtractorGlobalState { +class KotlinExtractorGlobalState(val moduleFragment: IrModuleFragment) { // These three record mappings of classes, functions and fields that should be replaced wherever // they are found. // As of now these are only used to fix IR generated by the Gradle Android Extensions plugin, @@ -331,21 +331,20 @@ This function determines whether 2 TRAP files should be considered to be equivalent. It returns `true` iff all of their non-comment lines are identical. */ -private fun equivalentTrap(r1: BufferedReader, r2: BufferedReader): Boolean { - r1.use { br1 -> - r2.use { br2 -> - while (true) { - val l1 = br1.readLine() - val l2 = br2.readLine() - if (l1 == null && l2 == null) { - return true - } else if (l1 == null || l2 == null) { - return false - } else if (l1 != l2) { - if (!l1.startsWith("//") || !l2.startsWith("//")) { - return false - } - } +private fun equivalentTrap(r1: BufferedReader, r2: BufferedReader): Boolean = + r1.use { br1 -> r2.use { br2 -> equivalentTrapLines(br1, br2) } } + +private fun equivalentTrapLines(br1: BufferedReader, br2: BufferedReader): Boolean { + while (true) { + val l1 = br1.readLine() + val l2 = br2.readLine() + if (l1 == null && l2 == null) { + return true + } else if (l1 == null || l2 == null) { + return false + } else if (l1 != l2) { + if (!l1.startsWith("//") || !l2.startsWith("//")) { + return false } } } diff --git a/java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt b/java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt index b3577858f99c..2ea5d2e09f56 100644 --- a/java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt +++ b/java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt @@ -6,7 +6,6 @@ import com.semmle.extractor.java.OdasaOutput import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext import org.jetbrains.kotlin.backend.common.ir.* import org.jetbrains.kotlin.backend.jvm.ir.* -import org.jetbrains.kotlin.codegen.JvmCodegenUtil import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI import org.jetbrains.kotlin.ir.declarations.* @@ -1055,7 +1054,7 @@ open class KotlinUsesExtractor( private fun getJvmModuleName(f: IrFunction) = NameUtils.sanitizeAsJavaIdentifier( getJvmModuleNameForDeserializedDescriptor(f.descriptor) - ?: JvmCodegenUtil.getModuleName(pluginContext.moduleDescriptor) + ?: getCurrentJvmModuleName(pluginContext, globalExtensionState.moduleFragment) ) fun getFunctionShortName(f: IrFunction): FunctionNames { diff --git a/java/kotlin-extractor/src/main/kotlin/utils/TypeSubstitution.kt b/java/kotlin-extractor/src/main/kotlin/utils/TypeSubstitution.kt index c990edc213f6..9045647ef1bc 100644 --- a/java/kotlin-extractor/src/main/kotlin/utils/TypeSubstitution.kt +++ b/java/kotlin-extractor/src/main/kotlin/utils/TypeSubstitution.kt @@ -12,7 +12,6 @@ import org.jetbrains.kotlin.ir.builders.declarations.buildClass import org.jetbrains.kotlin.ir.declarations.IrClass import org.jetbrains.kotlin.ir.declarations.IrTypeParameter import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer -import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.expressions.impl.* @@ -177,7 +176,7 @@ object RawTypeAnnotation { val annotationConstructor: IrConstructorCall by lazy { val irInternalPackage = FqName("kotlin.internal.ir") val parent = - IrExternalPackageFragmentImpl( + createExternalPackageFragment( DescriptorlessExternalPackageFragmentSymbol(), irInternalPackage ) diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/createExternalPackageFragment.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/createExternalPackageFragment.kt new file mode 100644 index 000000000000..72cae61f3596 --- /dev/null +++ b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/createExternalPackageFragment.kt @@ -0,0 +1,11 @@ +package com.github.codeql.utils.versions + +import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment +import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl +import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol +import org.jetbrains.kotlin.name.FqName + +fun createExternalPackageFragment( + symbol: IrExternalPackageFragmentSymbol, + fqName: FqName +): IrExternalPackageFragment = IrExternalPackageFragmentImpl(symbol, fqName) diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/getCurrentJvmModuleName.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/getCurrentJvmModuleName.kt new file mode 100644 index 000000000000..33f5702fb0ba --- /dev/null +++ b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_8_0/getCurrentJvmModuleName.kt @@ -0,0 +1,14 @@ +package com.github.codeql.utils.versions + +import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import org.jetbrains.kotlin.codegen.JvmCodegenUtil +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.IrModuleFragment + +@OptIn(ObsoleteDescriptorBasedAPI::class) +@Suppress("UNUSED_PARAMETER") +fun getCurrentJvmModuleName( + pluginContext: IrPluginContext, + moduleFragment: IrModuleFragment +): String = + JvmCodegenUtil.getModuleName(pluginContext.moduleDescriptor) diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_5_0-RC2/createExternalPackageFragment.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_5_0-RC2/createExternalPackageFragment.kt new file mode 100644 index 000000000000..156ada1e9ccc --- /dev/null +++ b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_5_0-RC2/createExternalPackageFragment.kt @@ -0,0 +1,16 @@ +package com.github.codeql.utils.versions + +import org.jetbrains.kotlin.ir.declarations.IrExternalPackageFragment +import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl +import org.jetbrains.kotlin.ir.symbols.IrExternalPackageFragmentSymbol +import org.jetbrains.kotlin.ir.util.IrErrorModuleFragment +import org.jetbrains.kotlin.name.FqName + +// The fragment now needs a module. As in the compiler's own +// `JvmIrSpecialAnnotationSymbolProvider`, a placeholder module is sufficient for the synthetic +// packages we create. +fun createExternalPackageFragment( + symbol: IrExternalPackageFragmentSymbol, + fqName: FqName +): IrExternalPackageFragment = + IrExternalPackageFragmentImpl(symbol, fqName, IrErrorModuleFragment) diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_5_0-RC2/getCurrentJvmModuleName.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_5_0-RC2/getCurrentJvmModuleName.kt new file mode 100644 index 000000000000..0ea4e45e5f7d --- /dev/null +++ b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_5_0-RC2/getCurrentJvmModuleName.kt @@ -0,0 +1,17 @@ +package com.github.codeql.utils.versions + +import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext +import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI +import org.jetbrains.kotlin.ir.declarations.IrModuleFragment + +// `JvmCodegenUtil` and `IrPluginContext.moduleDescriptor` no longer exist, so this mirrors what +// `JvmCodegenUtil.getModuleName(pluginContext.moduleDescriptor)` used to do. +@OptIn(ObsoleteDescriptorBasedAPI::class) +@Suppress("UNUSED_PARAMETER") +fun getCurrentJvmModuleName( + pluginContext: IrPluginContext, + moduleFragment: IrModuleFragment +): String { + val module = moduleFragment.descriptor + return (module.stableName ?: module.name).asString().removeSurrounding("<", ">") +} diff --git a/java/kotlin-extractor/versions.bzl b/java/kotlin-extractor/versions.bzl index 17c925493905..1eef44c524e2 100644 --- a/java/kotlin-extractor/versions.bzl +++ b/java/kotlin-extractor/versions.bzl @@ -13,6 +13,7 @@ VERSIONS = [ "2.3.20", "2.4.0", "2.4.20", + "2.5.0-RC2", ] def _version_to_tuple(v): @@ -42,6 +43,6 @@ def get_compatilibity_sources(version, dir): compat_version = d[len(prefix):].replace("_", ".") if version_less(version, compat_version): break - files = native.glob(["%s/*.kt" % d]) + files = native.glob(["%s/*.kt" % d], allow_empty = True) srcs |= {_basename(f): f for f in files} return srcs.values() diff --git a/java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/diagnostics.expected b/java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/diagnostics.expected index ff2c056ff962..96c3f1136c25 100644 --- a/java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/diagnostics.expected +++ b/java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/diagnostics.expected @@ -1,5 +1,5 @@ { - "markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 2.4.30.", + "markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 2.5.10.", "severity": "error", "source": { "extractorName": "java", diff --git a/java/ql/lib/change-notes/2026-11-30-kotlin-2.5.0.md b/java/ql/lib/change-notes/2026-11-30-kotlin-2.5.0.md new file mode 100644 index 000000000000..7f56919ffcf3 --- /dev/null +++ b/java/ql/lib/change-notes/2026-11-30-kotlin-2.5.0.md @@ -0,0 +1,4 @@ +--- +category: minorAnalysis +--- +* Support for Kotlin 2.5.0 has been added.