diff --git a/MODULE.bazel b/MODULE.bazel index 7f15d1e889f7..54fad012e7fc 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -278,6 +278,7 @@ use_repo( "kotlin-compiler-2.3.0", "kotlin-compiler-2.3.20", "kotlin-compiler-2.4.0", + "kotlin-compiler-2.4.20-RC3", "kotlin-compiler-embeddable-1.8.0", "kotlin-compiler-embeddable-1.9.0-Beta", "kotlin-compiler-embeddable-1.9.20-Beta", @@ -290,6 +291,7 @@ use_repo( "kotlin-compiler-embeddable-2.3.0", "kotlin-compiler-embeddable-2.3.20", "kotlin-compiler-embeddable-2.4.0", + "kotlin-compiler-embeddable-2.4.20-RC3", "kotlin-stdlib-1.8.0", "kotlin-stdlib-1.9.0-Beta", "kotlin-stdlib-1.9.20-Beta", @@ -302,6 +304,7 @@ use_repo( "kotlin-stdlib-2.3.0", "kotlin-stdlib-2.3.20", "kotlin-stdlib-2.4.0", + "kotlin-stdlib-2.4.20-RC3", ) 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 8651fa91a269..1616be29a3bb 100644 --- a/docs/codeql/reusables/supported-versions-compilers.rst +++ b/docs/codeql/reusables/supported-versions-compilers.rst @@ -21,13 +21,13 @@ Java,"Java 7 to 26 [5]_","javac (OpenJDK and Oracle JDK), Eclipse compiler for Java (ECJ) [6]_",``.java`` - Kotlin,"Kotlin 1.8.0 to 2.4.1\ *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`` + Kotlin,"Kotlin 1.8.0 to 2.4.20 [7]_","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`` [8]_" + Python [9]_,"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``" - Rust [9]_,"Rust editions 2021 and 2024","Rust compiler","``.rs``, ``Cargo.toml``" - Swift [10]_ [11]_,"Swift 5.4-6.3","Swift compiler","``.swift``" - TypeScript [12]_,"2.6-7.0",Standard TypeScript compiler,"``.ts``, ``.tsx``, ``.mts``, ``.cts``" + Rust [10]_,"Rust editions 2021 and 2024","Rust compiler","``.rs``, ``Cargo.toml``" + Swift [11]_ [12]_,"Swift 5.4-6.3","Swift compiler","``.swift``" + TypeScript [13]_,"2.6-7.0",Standard TypeScript compiler,"``.ts``, ``.tsx``, ``.mts``, ``.cts``" .. container:: footnote-group @@ -37,9 +37,10 @@ .. [4] Support for the Arm Compiler (armcc) is preliminary. .. [5] Builds that execute on Java 7 to 26 can be analyzed. The analysis understands standard language features in Java 8 to 26; "preview" and "incubator" features are not supported. Source code using Java language versions older than Java 8 are analyzed as Java 8 code. .. [6] ECJ is supported when the build invokes it via the Maven Compiler plugin or the Takari Lifecycle plugin. - .. [7] JSX and Flow code, YAML, JSON, HTML, and XML files may also be analyzed with JavaScript files. - .. [8] The extractor requires Python 3 to run. To analyze Python 2.7 you should install both versions of Python. - .. [9] Requires ``rustup`` and ``cargo`` to be installed. Features from nightly toolchains are not supported. - .. [10] Support for the analysis of Swift requires macOS. - .. [11] Embedded Swift is not supported. - .. [12] TypeScript analysis is performed by running the JavaScript extractor with TypeScript enabled. This is the default. + .. [7] Support for Kotlin 2.4.20 is preliminary. + .. [8] JSX and Flow code, YAML, JSON, HTML, and XML files may also be analyzed with JavaScript files. + .. [9] The extractor requires Python 3 to run. To analyze Python 2.7 you should install both versions of Python. + .. [10] Requires ``rustup`` and ``cargo`` to be installed. Features from nightly toolchains are not supported. + .. [11] Support for the analysis of Swift requires macOS. + .. [12] Embedded Swift is not supported. + .. [13] TypeScript analysis is performed by running the JavaScript extractor with TypeScript enabled. This is the default. diff --git a/java/kotlin-extractor/BUILD.bazel b/java/kotlin-extractor/BUILD.bazel index f33949f83914..fae93f6a2cc4 100644 --- a/java/kotlin-extractor/BUILD.bazel +++ b/java/kotlin-extractor/BUILD.bazel @@ -57,6 +57,10 @@ _compiler_plugin_registrar_service_source = "src/main/resources/META-INF/service _compiler_plugin_registrar_service_target = "META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar" +_component_registrar_service_source = "src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar" + +_component_registrar_service_target = "META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar" + py_binary( name = "generate_dbscheme", srcs = ["generate_dbscheme.py"], @@ -68,7 +72,10 @@ _resources = [ r[len("src/main/resources/"):], ) for r in glob(["src/main/resources/**"]) - if r != _compiler_plugin_registrar_service_source + if r not in ( + _compiler_plugin_registrar_service_source, + _component_registrar_service_source, + ) ] _compiler_plugin_registrar_service = ( @@ -76,6 +83,11 @@ _compiler_plugin_registrar_service = ( _compiler_plugin_registrar_service_target, ) +_component_registrar_service = ( + _component_registrar_service_source, + _component_registrar_service_target, +) + kt_javac_options( name = "javac-options", release = "8", @@ -93,7 +105,11 @@ kt_javac_options( "kotlin.RequiresOptIn", "org.jetbrains.kotlin.ir.symbols.%s" % ("IrSymbolInternals" if version_less(v, "2.0.0") else "UnsafeDuringIrConstructionAPI"), - ] + ([] if version_less(v, "2.2.20") else ["org.jetbrains.kotlin.DeprecatedForRemovalCompilerApi"]), + ] + ( + [] if version_less(v, "2.2.20") else ["org.jetbrains.kotlin.DeprecatedForRemovalCompilerApi"] + ) + ( + [] if version_less(v, "2.4.20") else ["org.jetbrains.kotlin.K1Deprecation"] + ), x_suppress_version_warnings = True, ), # * extractor.name is different for each version, so we need to put it in different output dirs @@ -103,6 +119,8 @@ kt_javac_options( name = "resources-%s" % v, srcs = [src for src, _ in _resources] + ( [_compiler_plugin_registrar_service[0]] if not version_less(v, "2.4.0") else [] + ) + ( + [_component_registrar_service[0]] if version_less(v, "2.4.20") else [] ), outs = [ "%s/com/github/codeql/extractor.name" % v, @@ -114,6 +132,11 @@ kt_javac_options( v, _compiler_plugin_registrar_service[1], )] if not version_less(v, "2.4.0") else [] + ) + ( + ["%s/%s" % ( + v, + _component_registrar_service[1], + )] if version_less(v, "2.4.20") else [] ), cmd = "\n".join([ "echo %s-%s > $(RULEDIR)/%s/com/github/codeql/extractor.name" % (_extractor_name_prefix, v, v), @@ -126,6 +149,12 @@ kt_javac_options( v, _compiler_plugin_registrar_service[1], )] if not version_less(v, "2.4.0") else [] + ) + ( + ["cp $(execpath %s) $(RULEDIR)/%s/%s" % ( + _component_registrar_service[0], + v, + _component_registrar_service[1], + )] if version_less(v, "2.4.20") else [] )), ), kt_jvm_library( diff --git a/java/kotlin-extractor/deps/kotlin-compiler-2.4.20-RC3.jar b/java/kotlin-extractor/deps/kotlin-compiler-2.4.20-RC3.jar new file mode 100644 index 000000000000..5fc806f55546 --- /dev/null +++ b/java/kotlin-extractor/deps/kotlin-compiler-2.4.20-RC3.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7a82b8fcea2bb26e0183c8d4abaa11c73d0546513778cde864afca093ebf47fc +size 60184483 diff --git a/java/kotlin-extractor/deps/kotlin-compiler-embeddable-2.4.20-RC3.jar b/java/kotlin-extractor/deps/kotlin-compiler-embeddable-2.4.20-RC3.jar new file mode 100644 index 000000000000..f0b154d6c32b --- /dev/null +++ b/java/kotlin-extractor/deps/kotlin-compiler-embeddable-2.4.20-RC3.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8b5e606e085246cf3f45e94bc5f19703330cd4336f8018a51ed5f5c41df05b48 +size 58593254 diff --git a/java/kotlin-extractor/deps/kotlin-stdlib-2.4.20-RC3.jar b/java/kotlin-extractor/deps/kotlin-stdlib-2.4.20-RC3.jar new file mode 100644 index 000000000000..dbfe536e3a28 --- /dev/null +++ b/java/kotlin-extractor/deps/kotlin-stdlib-2.4.20-RC3.jar @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:45311a8ed12064c4f8d23f54a1a79f72897f2a94ba39a15b22d73b07500078db +size 1853318 diff --git a/java/kotlin-extractor/dev/wrapper.py b/java/kotlin-extractor/dev/wrapper.py index 1b29de23f766..c2b5909c239a 100755 --- a/java/kotlin-extractor/dev/wrapper.py +++ b/java/kotlin-extractor/dev/wrapper.py @@ -27,7 +27,7 @@ import io import os -DEFAULT_VERSION = "2.4.10" +DEFAULT_VERSION = "2.4.20-RC3" def options(): diff --git a/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt b/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt index 0b975d9b829b..bef2b554d7ec 100644 --- a/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt +++ b/java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt @@ -1645,8 +1645,9 @@ open class KotlinFileExtractor( extractMethodAndParameterTypeAccesses: Boolean, typeSubstitution: TypeSubstitution?, classTypeArgsIncludingOuterClasses: List? - ) : Label = - forceExtractFunction( + ) : Label { + val sourceLoc = tw.getLocation(f.parentClassOrNull ?: f) + return forceExtractFunction( f, parentId, extractBody = false, @@ -1656,6 +1657,7 @@ open class KotlinFileExtractor( classTypeArgsIncludingOuterClasses, overriddenAttributes = OverriddenFunctionAttributes( + sourceLoc = sourceLoc, visibility = DescriptorVisibilities.PUBLIC, modality = Modality.OPEN ) @@ -1666,7 +1668,6 @@ open class KotlinFileExtractor( CompilerGeneratedKinds.INTERFACE_FORWARDER.kind ) if (extractBody) { - val realFunctionLocId = tw.getLocation(f) val inheritedDefaultFunction = f.realOverrideTarget val directlyInheritedSymbol = when (f) { @@ -1686,10 +1687,10 @@ open class KotlinFileExtractor( (directlyInheritedSymbol.owner.parentClassOrNull ?: return functionId) .typeWith() - extractExpressionBody(functionId, realFunctionLocId).also { returnId -> + extractExpressionBody(functionId, sourceLoc).also { returnId -> extractRawMethodAccess( f, - realFunctionLocId, + sourceLoc, f.returnType, functionId, returnId, @@ -1702,7 +1703,7 @@ open class KotlinFileExtractor( extractVariableAccess( syntheticParamId, param.type, - realFunctionLocId, + sourceLoc, argParentId, idxOffset + idx, functionId, @@ -1718,7 +1719,7 @@ open class KotlinFileExtractor( callId, -1, returnId, - realFunctionLocId + sourceLoc ) }, null @@ -1726,6 +1727,7 @@ open class KotlinFileExtractor( } } } + } private fun extractFunction( f: IrFunction, diff --git a/java/kotlin-extractor/src/main/kotlin/MetaAnnotationSupport.kt b/java/kotlin-extractor/src/main/kotlin/MetaAnnotationSupport.kt index e215b5ca31da..d5650389448d 100644 --- a/java/kotlin-extractor/src/main/kotlin/MetaAnnotationSupport.kt +++ b/java/kotlin-extractor/src/main/kotlin/MetaAnnotationSupport.kt @@ -96,8 +96,7 @@ class MetaAnnotationSupport( val metaAnnotations = annotationClass.annotations val jvmRepeatable = metaAnnotations.find { - it.symbol.owner.parentAsClass.fqNameWhenAvailable == - JvmAnnotationNames.REPEATABLE_ANNOTATION + it.annotationClass.fqNameWhenAvailable == JvmAnnotationNames.REPEATABLE_ANNOTATION } return if (jvmRepeatable != null) { ((jvmRepeatable.codeQlGetValueArgument(0) as? IrClassReference)?.symbol as? IrClassSymbol) diff --git a/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_4_20-RC3/Kotlin2ComponentRegistrar.kt b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_4_20-RC3/Kotlin2ComponentRegistrar.kt new file mode 100644 index 000000000000..f5091752633c --- /dev/null +++ b/java/kotlin-extractor/src/main/kotlin/utils/versions/v_2_4_20-RC3/Kotlin2ComponentRegistrar.kt @@ -0,0 +1,32 @@ +package com.github.codeql + +import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension +import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar +import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi +import org.jetbrains.kotlin.config.CompilerConfiguration + +@OptIn(ExperimentalCompilerApi::class) +abstract class Kotlin2ComponentRegistrar : CompilerPluginRegistrar() { + override val supportsK2: Boolean + get() = true + + override val pluginId: String + get() = "kotlin-extractor" + + private var extensionStorage: CompilerPluginRegistrar.ExtensionStorage? = null + + override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) { + this@Kotlin2ComponentRegistrar.extensionStorage = this + doRegisterExtensions(configuration) + } + + abstract fun doRegisterExtensions(configuration: CompilerConfiguration) + + protected fun registerExtractorExtension(extension: IrGenerationExtension) { + val storage = extensionStorage + ?: throw IllegalStateException("registerExtractorExtension called before registerExtensions") + with(storage) { + IrGenerationExtension.registerExtension(extension) + } + } +} diff --git a/java/kotlin-extractor/versions.bzl b/java/kotlin-extractor/versions.bzl index f9642c96b788..189dbc6b3819 100644 --- a/java/kotlin-extractor/versions.bzl +++ b/java/kotlin-extractor/versions.bzl @@ -12,6 +12,7 @@ VERSIONS = [ "2.3.0", "2.3.20", "2.4.0", + "2.4.20-RC3", ] def _version_to_tuple(v): 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 09429027c5d6..ff2c056ff962 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.20.", + "markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 2.4.30.", "severity": "error", "source": { "extractorName": "java", diff --git a/java/ql/lib/change-notes/2026-08-21-kotlin-2.4.20.md b/java/ql/lib/change-notes/2026-08-21-kotlin-2.4.20.md new file mode 100644 index 000000000000..c01c05552848 --- /dev/null +++ b/java/ql/lib/change-notes/2026-08-21-kotlin-2.4.20.md @@ -0,0 +1,4 @@ +--- +category: minorAnalysis +--- +* Preliminary support for Kotlin 2.4.20 has been added.