Skip to content
Open
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
3 changes: 3 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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")
Expand Down
25 changes: 13 additions & 12 deletions docs/codeql/reusables/supported-versions-compilers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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.
33 changes: 31 additions & 2 deletions java/kotlin-extractor/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand All @@ -68,14 +72,22 @@ _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 = (
_compiler_plugin_registrar_service_source,
_compiler_plugin_registrar_service_target,
)

_component_registrar_service = (
_component_registrar_service_source,
_component_registrar_service_target,
)

kt_javac_options(
name = "javac-options",
release = "8",
Expand All @@ -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
Expand All @@ -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,
Expand All @@ -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),
Expand All @@ -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(
Expand Down
3 changes: 3 additions & 0 deletions java/kotlin-extractor/deps/kotlin-compiler-2.4.20-RC3.jar
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions java/kotlin-extractor/deps/kotlin-stdlib-2.4.20-RC3.jar
Git LFS file not shown
2 changes: 1 addition & 1 deletion java/kotlin-extractor/dev/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import io
import os

DEFAULT_VERSION = "2.4.10"
DEFAULT_VERSION = "2.4.20-RC3"


def options():
Expand Down
16 changes: 9 additions & 7 deletions java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -1645,8 +1645,9 @@ open class KotlinFileExtractor(
extractMethodAndParameterTypeAccesses: Boolean,
typeSubstitution: TypeSubstitution?,
classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?
) : Label<out DbCallable> =
forceExtractFunction(
) : Label<out DbCallable> {
val sourceLoc = tw.getLocation(f.parentClassOrNull ?: f)
Comment thread
andersfugmann marked this conversation as resolved.
return forceExtractFunction(
f,
parentId,
extractBody = false,
Expand All @@ -1656,6 +1657,7 @@ open class KotlinFileExtractor(
classTypeArgsIncludingOuterClasses,
overriddenAttributes =
OverriddenFunctionAttributes(
sourceLoc = sourceLoc,
visibility = DescriptorVisibilities.PUBLIC,
modality = Modality.OPEN
)
Expand All @@ -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) {
Expand All @@ -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,
Expand All @@ -1702,7 +1703,7 @@ open class KotlinFileExtractor(
extractVariableAccess(
syntheticParamId,
param.type,
realFunctionLocId,
sourceLoc,
argParentId,
idxOffset + idx,
functionId,
Expand All @@ -1718,14 +1719,15 @@ open class KotlinFileExtractor(
callId,
-1,
returnId,
realFunctionLocId
sourceLoc
)
},
null
)
}
}
}
}

private fun extractFunction(
f: IrFunction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why does this work with earlier Kotlin versions?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

annotationClass resolves the class though symbol.owner.constructedClass, which is available for all Kotlin versions, and is already (prior to this PR) used in groupRepeatableAnnotations.

symbol.owner.constructedClass and parentAsClass are for an  IrConstructor semantically equivalent. constructor.constructedClass is implemented as constructor.parent as IrClass. parentAsClass  also reads parent and requires it to be an IrClass. The only difference is the exception produces if its not an IrClass

Copilot has scanned all the supported versions (>= 1.8.0) to verify that its supported:

I checked every compiler variant supported by this extractor, from Kotlin 1.8.0 through 2.4.20-RC3.  constructedClass  has the same implementation in all of them. This is safe for our supported versions because an  IrConstructor  is expected to be parented by the class it constructs

}
return if (jvmRepeatable != null) {
((jvmRepeatable.codeQlGetValueArgument(0) as? IrClassReference)?.symbol as? IrClassSymbol)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.github.codeql
Comment thread
andersfugmann marked this conversation as resolved.

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)
}
}
}
1 change: 1 addition & 0 deletions java/kotlin-extractor/versions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ VERSIONS = [
"2.3.0",
"2.3.20",
"2.4.0",
"2.4.20-RC3",
]

def _version_to_tuple(v):
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 4 additions & 0 deletions java/ql/lib/change-notes/2026-08-21-kotlin-2.4.20.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* Preliminary support for Kotlin 2.4.20 has been added.
Loading