Skip to content

Add support for Kotlin 2.2.0; drop Kotlin 1.5.x #19402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
May 13, 2025
Merged
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
17 changes: 4 additions & 13 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -24,7 +24,7 @@ bazel_dep(name = "bazel_skylib", version = "1.7.1")
bazel_dep(name = "abseil-cpp", version = "20240116.1", repo_name = "absl")
bazel_dep(name = "nlohmann_json", version = "3.11.3", repo_name = "json")
bazel_dep(name = "fmt", version = "10.0.0")
bazel_dep(name = "rules_kotlin", version = "2.0.0-codeql.1")
bazel_dep(name = "rules_kotlin", version = "2.1.3-codeql.1")
bazel_dep(name = "gazelle", version = "0.40.0")
bazel_dep(name = "rules_dotnet", version = "0.17.4")
bazel_dep(name = "googletest", version = "1.14.0.bcr.1")
@@ -193,10 +193,6 @@ use_repo(
kotlin_extractor_deps,
"codeql_kotlin_defaults",
"codeql_kotlin_embeddable",
"kotlin-compiler-1.5.0",
"kotlin-compiler-1.5.10",
"kotlin-compiler-1.5.20",
"kotlin-compiler-1.5.30",
"kotlin-compiler-1.6.0",
"kotlin-compiler-1.6.20",
"kotlin-compiler-1.7.0",
@@ -208,10 +204,7 @@ use_repo(
"kotlin-compiler-2.0.20-Beta2",
"kotlin-compiler-2.1.0-Beta1",
"kotlin-compiler-2.1.20-Beta1",
"kotlin-compiler-embeddable-1.5.0",
"kotlin-compiler-embeddable-1.5.10",
"kotlin-compiler-embeddable-1.5.20",
"kotlin-compiler-embeddable-1.5.30",
"kotlin-compiler-2.2.0-Beta1",
"kotlin-compiler-embeddable-1.6.0",
"kotlin-compiler-embeddable-1.6.20",
"kotlin-compiler-embeddable-1.7.0",
@@ -223,10 +216,7 @@ use_repo(
"kotlin-compiler-embeddable-2.0.20-Beta2",
"kotlin-compiler-embeddable-2.1.0-Beta1",
"kotlin-compiler-embeddable-2.1.20-Beta1",
"kotlin-stdlib-1.5.0",
"kotlin-stdlib-1.5.10",
"kotlin-stdlib-1.5.20",
"kotlin-stdlib-1.5.30",
"kotlin-compiler-embeddable-2.2.0-Beta1",
"kotlin-stdlib-1.6.0",
"kotlin-stdlib-1.6.20",
"kotlin-stdlib-1.7.0",
@@ -238,6 +228,7 @@ use_repo(
"kotlin-stdlib-2.0.20-Beta2",
"kotlin-stdlib-2.1.0-Beta1",
"kotlin-stdlib-2.1.20-Beta1",
"kotlin-stdlib-2.2.0-Beta1",
)

go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
2 changes: 1 addition & 1 deletion docs/codeql/reusables/supported-versions-compilers.rst
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@
Java,"Java 7 to 24 [6]_","javac (OpenJDK and Oracle JDK),

Eclipse compiler for Java (ECJ) [7]_",``.java``
Kotlin,"Kotlin 1.5.0 to 2.1.2\ *x*","kotlinc",``.kt``
Kotlin,"Kotlin 1.6.0 to 2.2.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`` [8]_"
Python [9]_,"2.7, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13",Not applicable,``.py``
Ruby [10]_,"up to 3.3",Not applicable,"``.rb``, ``.erb``, ``.gemspec``, ``Gemfile``"
2 changes: 1 addition & 1 deletion java/kotlin-extractor/build.gradle
Original file line number Diff line number Diff line change
@@ -55,7 +55,7 @@ sourceSets {
}

jar {
archiveName = "${OUTPUT_JAR_NAME}"
archiveBaseName = "${OUTPUT_JAR_NAME}"
}

task getHomeDir {
3 changes: 3 additions & 0 deletions java/kotlin-extractor/deps/kotlin-compiler-2.2.0-Beta1.jar
Git LFS file not shown
Git LFS file not shown
3 changes: 3 additions & 0 deletions java/kotlin-extractor/deps/kotlin-stdlib-2.2.0-Beta1.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
@@ -27,7 +27,7 @@
import io
import os

DEFAULT_VERSION = "2.0.0"
DEFAULT_VERSION = "2.1.20"


def options():
18 changes: 3 additions & 15 deletions java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt
Original file line number Diff line number Diff line change
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.backend.js.utils.realOverrideTarget
import org.jetbrains.kotlin.ir.builders.declarations.*
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyFunction
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.*
@@ -1609,7 +1608,7 @@ open class KotlinFileExtractor(
cls.origin != IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB

private fun needsInterfaceForwarder(f: IrFunction) =
// jvmDefaultModeEnabledIsEnabled means that -Xjvm-default=all or all-compatibility was
// jvmDefaultModeIsNoCompatibility means that -Xjvm-default=all or =no-compatibility was
// used, in which case real Java default interfaces are used, and we don't need to do
// anything.
// Otherwise, for a Kotlin-defined method inheriting a Kotlin-defined default, we need to
@@ -1619,9 +1618,7 @@ open class KotlinFileExtractor(
// (NB. kotlinc's actual implementation strategy is different -- it makes an inner class
// called InterfaceWithDefault$DefaultImpls and stores the default methods
// there to allow default method usage in Java < 8, but this is hopefully niche.
!jvmDefaultModeEnabledIsEnabled(
pluginContext.languageVersionSettings
.getFlag(JvmAnalysisFlags.jvmDefaultMode)) &&
!jvmDefaultModeIsNoCompatibility(getJvmDefaultMode(pluginContext.languageVersionSettings)) &&
f.parentClassOrNull.let {
it != null &&
it.origin != IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB &&
@@ -6011,11 +6008,7 @@ open class KotlinFileExtractor(
is IrGetValue -> {
val exprParent = parent.expr(e, callable)
val owner = e.symbol.owner
if (
owner is IrValueParameter &&
owner.index == -1 &&
!owner.isExtensionReceiver()
) {
if (owner is IrValueParameter && isDispatchReceiver(owner)) {
extractThisAccess(e, owner.parent, exprParent, callable)
} else {
val isAnnotationClassParameter =
@@ -6966,11 +6959,6 @@ open class KotlinFileExtractor(
}
}

private fun IrValueParameter.isExtensionReceiver(): Boolean {
val parentFun = parent as? IrFunction ?: return false
return parentFun.extensionReceiverParameter == this
}

private open inner class GeneratedClassHelper(
protected val locId: Label<DbLocation>,
protected val ids: GeneratedClassLabels
Original file line number Diff line number Diff line change
@@ -2136,7 +2136,7 @@ open class KotlinUsesExtractor(
}
val parentId = parent ?: overriddenParentAttributes?.id ?: useDeclarationParentOf(vp, false)

val idxBase = overriddenParentAttributes?.valueParameters?.indexOf(vp) ?: vp.index
val idxBase = overriddenParentAttributes?.valueParameters?.indexOf(vp) ?: parameterIndexExcludingReceivers(vp)
val idxOffset =
if (
declarationParent is IrFunction &&
Original file line number Diff line number Diff line change
@@ -2,12 +2,18 @@ package com.github.codeql.comments

import com.github.codeql.*
import com.github.codeql.utils.isLocalFunction
import com.github.codeql.utils.versions.isDispatchReceiver
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.IrBody
import org.jetbrains.kotlin.ir.expressions.IrExpression
import org.jetbrains.kotlin.ir.util.parentClassOrNull

private fun IrValueParameter.isExtensionReceiver(): Boolean {
val parentFun = parent as? IrFunction ?: return false
return parentFun.extensionReceiverParameter == this
}

open class CommentExtractor(
protected val fileExtractor: KotlinFileExtractor,
protected val file: IrFile,
@@ -19,7 +25,7 @@ open class CommentExtractor(
protected fun getLabel(element: IrElement): Label<out DbTop>? {
if (element == file) return fileLabel

if (element is IrValueParameter && element.index == -1) {
if (element is IrValueParameter && (isDispatchReceiver(element) || element.isExtensionReceiver())) {
// Don't attribute comments to the implicit `this` parameter of a function.
return null
}
6 changes: 5 additions & 1 deletion java/kotlin-extractor/src/main/kotlin/utils/ClassNames.kt
Original file line number Diff line number Diff line change
@@ -90,7 +90,11 @@ fun getIrClassVirtualFile(irClass: IrClass): VirtualFile? {
}
}
is VirtualFileBasedSourceElement -> {
return cSource.virtualFile
if (cSource.virtualFile.name.endsWith(".class")) {
// At least lately, despite VirtualFileBasedSourceElement being constructed on a BinaryJavaClass,
// this can be a .java source file.
return cSource.virtualFile
}
}
is KotlinJvmBinarySourceElement -> {
val binaryClass = cSource.binaryClass
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package com.github.codeql.utils

import com.github.codeql.utils.versions.IrVisitor
import com.intellij.psi.PsiElement
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrFile
import org.jetbrains.kotlin.ir.util.isFakeOverride
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor

class IrVisitorLookup(
private val psi2Ir: Psi2IrFacade,
private val psi: PsiElement,
private val file: IrFile
) : IrElementVisitor<Unit, MutableCollection<IrElement>> {
) : IrVisitor<Unit, MutableCollection<IrElement>>() {
private val location = psi.getLocation()

override fun visitElement(element: IrElement, data: MutableCollection<IrElement>): Unit {
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.github.codeql.utils.versions
Copy link
Contributor

Choose a reason for hiding this comment

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

We can move the necessary bits from v_1_5* into v_1_6_0, and delete the rest, now we have dropped 1.5 support, but that can be done in a follow-up PR.


typealias IrLazyFunction = org.jetbrains.kotlin.ir.declarations.lazy.IrLazyFunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.github.codeql.utils.versions

abstract class IrVisitor<R, D> : org.jetbrains.kotlin.ir.visitors.IrElementVisitor<R, D>
abstract class IrVisitorVoid : org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.codeql.utils.versions

import org.jetbrains.kotlin.config.JvmDefaultMode

fun jvmDefaultModeIsNoCompatibility(jdm: JvmDefaultMode): Boolean {
return jdm == JvmDefaultMode.ALL_INCOMPATIBLE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.codeql.utils.versions

import org.jetbrains.kotlin.config.JvmAnalysisFlags
import org.jetbrains.kotlin.config.LanguageVersionSettings

fun getJvmDefaultMode(lvs: LanguageVersionSettings) =
lvs.getFlag(JvmAnalysisFlags.jvmDefaultMode)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.github.codeql.utils.versions

import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrValueParameter

fun isDispatchReceiver(p: IrValueParameter) = p.index == -1 && p != (p.parent as? IrFunction)?.extensionReceiverParameter
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.github.codeql.utils.versions

import org.jetbrains.kotlin.ir.declarations.IrValueParameter

fun parameterIndexExcludingReceivers(vp: IrValueParameter) = vp.index
Original file line number Diff line number Diff line change
@@ -9,7 +9,6 @@ import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.util.SYNTHETIC_OFFSET
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
import org.jetbrains.kotlin.ir.visitors.acceptVoid
import org.jetbrains.kotlin.kdoc.lexer.KDocTokens
@@ -43,7 +42,7 @@ class CommentExtractorLighterAST(

val kDocOwners = mutableMapOf<Int, MutableList<IrElement>>()
val visitor =
object : IrElementVisitorVoid {
object : IrVisitorVoid() {
override fun visitElement(element: IrElement) {
val metadata = (element as? IrMetadataSourceOwner)?.metadata
val sourceElement = (metadata as? FirMetadataSource)?.fir?.source

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.codeql.utils.versions

import org.jetbrains.kotlin.config.JvmDefaultMode

fun jvmDefaultModeIsNoCompatibility(jdm: JvmDefaultMode): Boolean {
return jdm == JvmDefaultMode.ALL
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.github.codeql.utils.versions

typealias IrLazyFunction = org.jetbrains.kotlin.psi2ir.lazy.IrLazyFunction
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.github.codeql.utils.versions

typealias IrVisitor<R, D> = org.jetbrains.kotlin.ir.visitors.IrVisitor<R, D>
typealias IrVisitorVoid = org.jetbrains.kotlin.ir.visitors.IrVisitorVoid
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.codeql.utils.versions

import org.jetbrains.kotlin.config.JvmDefaultMode

fun jvmDefaultModeIsNoCompatibility(jdm: JvmDefaultMode): Boolean {
return jdm == JvmDefaultMode.NO_COMPATIBILITY
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.codeql.utils.versions

import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.util.createThisReceiverParameter

fun IrClass.createImplicitParameterDeclarationWithWrappedDescriptor() =
this.createThisReceiverParameter()
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.github.codeql.utils.versions

import org.jetbrains.kotlin.config.LanguageVersionSettings
import org.jetbrains.kotlin.config.jvmDefaultMode

fun getJvmDefaultMode(lvs: LanguageVersionSettings) =
lvs.jvmDefaultMode
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.github.codeql.utils.versions

import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.declarations.IrParameterKind

fun isDispatchReceiver(p: IrValueParameter) = p.kind == IrParameterKind.DispatchReceiver
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.github.codeql.utils.versions

import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrValueParameter

fun parameterIndexExcludingReceivers(vp: IrValueParameter): Int {
val offset =
(vp.parent as? IrFunction)?.let { (if (it.extensionReceiverParameter != null) 1 else 0) + (if (it.dispatchReceiverParameter != null) 1 else 0) } ?: 0
return vp.indexInParameters - offset
}
5 changes: 1 addition & 4 deletions java/kotlin-extractor/versions.bzl
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
# when updating this list, `bazel mod tidy` should be run from `codeql` to update `MODULE.bazel`
VERSIONS = [
"1.5.0",
"1.5.10",
"1.5.20",
"1.5.30",
"1.6.0",
"1.6.20",
"1.7.0",
@@ -15,6 +11,7 @@ VERSIONS = [
"2.0.20-Beta2",
"2.1.0-Beta1",
"2.1.20-Beta1",
"2.2.0-Beta1",
]

def _version_to_tuple(v):
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.1.30.",
"markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 2.2.10.",
"severity": "error",
"source": {
"extractorName": "java",
Original file line number Diff line number Diff line change
@@ -8,7 +8,7 @@

plugins {
// Apply the org.jetbrains.kotlin.jvm Plugin to add support for Kotlin.
id 'org.jetbrains.kotlin.jvm' version '1.5.31'
id 'org.jetbrains.kotlin.jvm' version '1.6.0'

// Apply the application plugin to add support for building a CLI application in Java.
id 'application'
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
| hasprops.kt:3:3:3:25 | getAccessorsPublic |
| hasprops.kt:3:3:3:25 | setAccessorsPublic |
| hasprops.kt:5:3:6:15 | getSetterPrivate |
| hasprops.kt:3:3:3:21 | getAccessorsPublic |
| hasprops.kt:3:3:3:21 | setAccessorsPublic |
| hasprops.kt:5:3:5:19 | getSetterPrivate |
| hasprops.kt:6:5:6:15 | setSetterPrivate$private |
| usesprops.kt:1:1:9:1 | user |
| usesprops.kt:3:3:3:58 | useGetters |
Loading
Oops, something went wrong.
Loading
Oops, something went wrong.