Skip to content

Commit a9ecb26

Browse files
authored
Merge pull request #17555 from igfoo/igfoo/kotlin2.1
Add support for Kotlin 2.1.0-Beta1
2 parents 6a184e0 + a6fce19 commit a9ecb26

19 files changed

+58
-48
lines changed

MODULE.bazel

+3
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ use_repo(
128128
"kotlin-compiler-1.9.20-Beta",
129129
"kotlin-compiler-2.0.0-RC1",
130130
"kotlin-compiler-2.0.20-Beta2",
131+
"kotlin-compiler-2.1.0-Beta1",
131132
"kotlin-compiler-embeddable-1.5.0",
132133
"kotlin-compiler-embeddable-1.5.10",
133134
"kotlin-compiler-embeddable-1.5.20",
@@ -141,6 +142,7 @@ use_repo(
141142
"kotlin-compiler-embeddable-1.9.20-Beta",
142143
"kotlin-compiler-embeddable-2.0.0-RC1",
143144
"kotlin-compiler-embeddable-2.0.20-Beta2",
145+
"kotlin-compiler-embeddable-2.1.0-Beta1",
144146
"kotlin-stdlib-1.5.0",
145147
"kotlin-stdlib-1.5.10",
146148
"kotlin-stdlib-1.5.20",
@@ -154,6 +156,7 @@ use_repo(
154156
"kotlin-stdlib-1.9.20-Beta",
155157
"kotlin-stdlib-2.0.0-RC1",
156158
"kotlin-stdlib-2.0.20-Beta2",
159+
"kotlin-stdlib-2.1.0-Beta1",
157160
)
158161

159162
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")

docs/codeql/reusables/supported-versions-compilers.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
Java,"Java 7 to 22 [5]_","javac (OpenJDK and Oracle JDK),
2121

2222
Eclipse compiler for Java (ECJ) [6]_",``.java``
23-
Kotlin,"Kotlin 1.5.0 to 2.0.2\ *x*","kotlinc",``.kt``
23+
Kotlin,"Kotlin 1.5.0 to 2.1.0\ *x*","kotlinc",``.kt``
2424
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]_"
2525
Python [8]_,"2.7, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12",Not applicable,``.py``
2626
Ruby [9]_,"up to 3.3",Not applicable,"``.rb``, ``.erb``, ``.gemspec``, ``Gemfile``"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:2ec66b3523c69b3436b8c9777707db4da86d680d6652aeda539fff7d5a84aeab
3+
size 59837198
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:9b4581ffe576a33322fe51435a1b5ea4f4717bb6f7ce18b68106df63056e385c
3+
size 58409745
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:7ef9c5c246cd2e7d06cd5741995753c0b697107efae40657af3010c6c6311ab2
3+
size 1688722

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

+6-29
Original file line numberDiff line numberDiff line change
@@ -27,30 +27,7 @@ import org.jetbrains.kotlin.ir.expressions.impl.*
2727
import org.jetbrains.kotlin.ir.symbols.*
2828
import org.jetbrains.kotlin.ir.types.*
2929
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
30-
import org.jetbrains.kotlin.ir.util.companionObject
31-
import org.jetbrains.kotlin.ir.util.constructors
32-
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
33-
import org.jetbrains.kotlin.ir.util.hasAnnotation
34-
import org.jetbrains.kotlin.ir.util.hasInterfaceParent
35-
import org.jetbrains.kotlin.ir.util.isAnnotationClass
36-
import org.jetbrains.kotlin.ir.util.isAnonymousObject
37-
import org.jetbrains.kotlin.ir.util.isFakeOverride
38-
import org.jetbrains.kotlin.ir.util.isFunctionOrKFunction
39-
import org.jetbrains.kotlin.ir.util.isInterface
40-
import org.jetbrains.kotlin.ir.util.isLocal
41-
import org.jetbrains.kotlin.ir.util.isNonCompanionObject
42-
import org.jetbrains.kotlin.ir.util.isObject
43-
import org.jetbrains.kotlin.ir.util.isSuspend
44-
import org.jetbrains.kotlin.ir.util.isSuspendFunctionOrKFunction
45-
import org.jetbrains.kotlin.ir.util.isVararg
46-
import org.jetbrains.kotlin.ir.util.kotlinFqName
47-
import org.jetbrains.kotlin.ir.util.packageFqName
48-
import org.jetbrains.kotlin.ir.util.parentAsClass
49-
import org.jetbrains.kotlin.ir.util.parentClassOrNull
50-
import org.jetbrains.kotlin.ir.util.parents
51-
import org.jetbrains.kotlin.ir.util.primaryConstructor
52-
import org.jetbrains.kotlin.ir.util.render
53-
import org.jetbrains.kotlin.ir.util.target
30+
import org.jetbrains.kotlin.ir.util.*
5431
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
5532
import org.jetbrains.kotlin.load.java.NOT_NULL_ANNOTATIONS
5633
import org.jetbrains.kotlin.load.java.NULLABLE_ANNOTATIONS
@@ -826,7 +803,7 @@ open class KotlinFileExtractor(
826803
fun exprId() = tw.getLabelFor<DbExpr>("@\"annotationExpr;{$parent};$idx\"")
827804

828805
return when (v) {
829-
is IrConst<*> -> {
806+
is CodeQLIrConst<*> -> {
830807
extractConstant(v, parent, idx, null, null, overrideId = exprId())
831808
}
832809
is IrGetEnumValue -> {
@@ -5998,7 +5975,7 @@ open class KotlinFileExtractor(
59985975
extractExpressionExpr(a, callable, id, i, exprParent.enclosingStmt)
59995976
}
60005977
}
6001-
is IrConst<*> -> {
5978+
is CodeQLIrConst<*> -> {
60025979
val exprParent = parent.expr(e, callable)
60035980
extractConstant(
60045981
e,
@@ -6210,9 +6187,9 @@ open class KotlinFileExtractor(
62106187
if (
62116188
(isAndAnd || isOrOr) &&
62126189
e.branches.size == 2 &&
6213-
(e.branches[1].condition as? IrConst<*>)?.value == true &&
6190+
(e.branches[1].condition as? CodeQLIrConst<*>)?.value == true &&
62146191
(e.branches[if (e.origin == IrStatementOrigin.ANDAND) 1 else 0].result
6215-
as? IrConst<*>)
6192+
as? CodeQLIrConst<*>)
62166193
?.value == isOrOr
62176194
) {
62186195

@@ -6868,7 +6845,7 @@ open class KotlinFileExtractor(
68686845
}
68696846

68706847
private fun extractConstant(
6871-
e: IrConst<*>,
6848+
e: CodeQLIrConst<*>,
68726849
parent: Label<out DbExprparent>,
68736850
idx: Int,
68746851
enclosingCallable: Label<out DbCallable>?,

java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.github.codeql.utils.versions.*
55
import com.semmle.extractor.java.OdasaOutput
66
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
77
import org.jetbrains.kotlin.backend.common.ir.*
8-
import org.jetbrains.kotlin.backend.jvm.ir.propertyIfAccessor
8+
import org.jetbrains.kotlin.backend.jvm.ir.*
99
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
1010
import org.jetbrains.kotlin.descriptors.*
1111
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.load.kotlin.getJvmModuleNameForDeserializedDescripto
2424
import org.jetbrains.kotlin.name.FqName
2525
import org.jetbrains.kotlin.name.NameUtils
2626
import org.jetbrains.kotlin.name.SpecialNames
27+
import org.jetbrains.kotlin.resolve.descriptorUtil.propertyIfAccessor
2728
import org.jetbrains.kotlin.types.Variance
2829
import org.jetbrains.kotlin.util.OperatorNameConventions
2930

@@ -84,7 +85,7 @@ open class KotlinUsesExtractor(
8485
}
8586

8687
private fun extractFileClass(fqName: FqName): Label<out DbClassorinterface> {
87-
val pkg = if (fqName.isRoot()) "" else fqName.parent().asString()
88+
val pkg = if (fqName.codeQlIsRoot()) "" else fqName.parent().asString()
8889
val jvmName = fqName.shortName().asString()
8990
return extractFileClass(pkg, jvmName)
9091
}
@@ -906,7 +907,7 @@ open class KotlinUsesExtractor(
906907
return arrayInfo.componentTypeResults
907908
}
908909
owner is IrClass -> {
909-
val args = if (s.isRawType()) null else s.arguments
910+
val args = if (s.codeQlIsRawType()) null else s.arguments
910911

911912
return useSimpleTypeClass(owner, args, s.isNullable())
912913
}
@@ -1232,9 +1233,10 @@ open class KotlinUsesExtractor(
12321233
// false if it has `@JvmSuppressWildcards(false)`,
12331234
// and null if the annotation is not present.
12341235
@Suppress("UNCHECKED_CAST")
1235-
private fun getWildcardSuppressionDirective(t: IrAnnotationContainer) =
1236+
private fun getWildcardSuppressionDirective(t: IrAnnotationContainer): Boolean? =
12361237
t.getAnnotation(jvmWildcardSuppressionAnnotation)?.let {
1237-
(it.getValueArgument(0) as? IrConst<Boolean>)?.value ?: true
1238+
@Suppress("USELESS_CAST") // `as? Boolean` is not needed for Kotlin < 2.1
1239+
(it.getValueArgument(0) as? CodeQLIrConst<Boolean>)?.value as? Boolean ?: true
12381240
}
12391241

12401242
private fun addJavaLoweringArgumentWildcards(

java/kotlin-extractor/src/main/kotlin/MetaAnnotationSupport.kt

+1-7
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,7 @@ import org.jetbrains.kotlin.ir.expressions.IrClassReference
2727
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
2828
import org.jetbrains.kotlin.ir.expressions.IrGetEnumValue
2929
import org.jetbrains.kotlin.ir.expressions.IrVararg
30-
import org.jetbrains.kotlin.ir.expressions.impl.IrClassReferenceImpl
31-
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
32-
import org.jetbrains.kotlin.ir.expressions.impl.IrGetEnumValueImpl
33-
import org.jetbrains.kotlin.ir.expressions.impl.IrGetFieldImpl
34-
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
35-
import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl
36-
import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl
30+
import org.jetbrains.kotlin.ir.expressions.impl.*
3731
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
3832
import org.jetbrains.kotlin.ir.types.typeWith
3933
import org.jetbrains.kotlin.ir.util.constructedClass

java/kotlin-extractor/src/main/kotlin/utils/JvmNames.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package com.github.codeql.utils
22

33
import com.github.codeql.utils.versions.allOverriddenIncludingSelf
4+
import com.github.codeql.utils.versions.CodeQLIrConst
45
import org.jetbrains.kotlin.builtins.StandardNames
56
import org.jetbrains.kotlin.ir.declarations.IrAnnotationContainer
67
import org.jetbrains.kotlin.ir.declarations.IrClass
78
import org.jetbrains.kotlin.ir.declarations.IrFunction
89
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
9-
import org.jetbrains.kotlin.ir.expressions.IrConst
1010
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
1111
import org.jetbrains.kotlin.ir.types.IrSimpleType
1212
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
@@ -82,7 +82,7 @@ fun getJvmName(container: IrAnnotationContainer): String? {
8282
if (owner is IrClass) {
8383
val aPkg = owner.packageFqName?.asString()
8484
val name = owner.name.asString()
85-
if (aPkg == "kotlin.jvm" && name == "JvmName" && v is IrConst<*>) {
85+
if (aPkg == "kotlin.jvm" && name == "JvmName" && v is CodeQLIrConst<*>) {
8686
val value = v.value
8787
if (value is String) {
8888
return value

java/kotlin-extractor/src/main/kotlin/utils/TypeSubstitution.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer
1515
import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
1616
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
1717
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
18-
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
18+
import org.jetbrains.kotlin.ir.expressions.impl.*
1919
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
2020
import org.jetbrains.kotlin.ir.symbols.impl.DescriptorlessExternalPackageFragmentSymbol
2121
import org.jetbrains.kotlin.ir.types.*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.github.codeql.utils.versions
2+
3+
import org.jetbrains.kotlin.ir.expressions.IrConst
4+
5+
typealias CodeQLIrConst<T> = IrConst<T>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.github.codeql.utils.versions
2+
3+
import org.jetbrains.kotlin.name.FqName
4+
5+
fun FqName.codeQlIsRoot() = this.isRoot()

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_5_0/Types.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ package com.github.codeql.utils.versions
33
import org.jetbrains.kotlin.backend.jvm.codegen.isRawType
44
import org.jetbrains.kotlin.ir.types.IrSimpleType
55

6-
fun IrSimpleType.isRawType() = this.isRawType()
6+
fun IrSimpleType.codeQlIsRawType() = this.isRawType()

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_6_20/Types.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ package com.github.codeql.utils.versions
33
import org.jetbrains.kotlin.backend.jvm.ir.isRawType
44
import org.jetbrains.kotlin.ir.types.IrSimpleType
55

6-
fun IrSimpleType.isRawType() = this.isRawType()
6+
fun IrSimpleType.codeQlIsRawType() = this.isRawType()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.github.codeql.utils.versions
2+
3+
import org.jetbrains.kotlin.ir.expressions.IrConst
4+
5+
typealias CodeQLIrConst<T> = IrConst
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.github.codeql.utils.versions
2+
3+
import org.jetbrains.kotlin.name.FqName
4+
5+
fun FqName.codeQlIsRoot() = this.isRoot

java/kotlin-extractor/versions.bzl

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ VERSIONS = [
1313
"1.9.20-Beta",
1414
"2.0.0-RC1",
1515
"2.0.20-Beta2",
16+
"2.1.0-Beta1",
1617
]
1718

1819
def _version_to_tuple(v):

java/ql/integration-tests/kotlin/all-platforms/diagnostics/kotlin-version-too-new/diagnostics.expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 2.0.30.",
2+
"markdownMessage": "The Kotlin version installed (`999.999.999`) is too recent for this version of CodeQL. Install a version lower than 2.1.10.",
33
"severity": "error",
44
"source": {
55
"extractorName": "java",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: feature
3+
---
4+
* Kotlin versions up to 2.1.0\ *x* are now supported.

0 commit comments

Comments
 (0)