Skip to content

Commit d6b042f

Browse files
Kotlin: support 2.4.20-RC
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent c4ac327 commit d6b042f

11 files changed

Lines changed: 88 additions & 13 deletions

File tree

MODULE.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ use_repo(
276276
"kotlin-compiler-2.3.0",
277277
"kotlin-compiler-2.3.20",
278278
"kotlin-compiler-2.4.0",
279+
"kotlin-compiler-2.4.20-RC",
279280
"kotlin-compiler-embeddable-1.8.0",
280281
"kotlin-compiler-embeddable-1.9.0-Beta",
281282
"kotlin-compiler-embeddable-1.9.20-Beta",
@@ -288,6 +289,7 @@ use_repo(
288289
"kotlin-compiler-embeddable-2.3.0",
289290
"kotlin-compiler-embeddable-2.3.20",
290291
"kotlin-compiler-embeddable-2.4.0",
292+
"kotlin-compiler-embeddable-2.4.20-RC",
291293
"kotlin-stdlib-1.8.0",
292294
"kotlin-stdlib-1.9.0-Beta",
293295
"kotlin-stdlib-1.9.20-Beta",
@@ -300,6 +302,7 @@ use_repo(
300302
"kotlin-stdlib-2.3.0",
301303
"kotlin-stdlib-2.3.20",
302304
"kotlin-stdlib-2.4.0",
305+
"kotlin-stdlib-2.4.20-RC",
303306
)
304307

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

java/kotlin-extractor/BUILD.bazel

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ _compiler_plugin_registrar_service_source = "src/main/resources/META-INF/service
5757

5858
_compiler_plugin_registrar_service_target = "META-INF/services/org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar"
5959

60+
_component_registrar_service_source = "src/main/resources/META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar"
61+
62+
_component_registrar_service_target = "META-INF/services/org.jetbrains.kotlin.compiler.plugin.ComponentRegistrar"
63+
6064
py_binary(
6165
name = "generate_dbscheme",
6266
srcs = ["generate_dbscheme.py"],
@@ -68,14 +72,22 @@ _resources = [
6872
r[len("src/main/resources/"):],
6973
)
7074
for r in glob(["src/main/resources/**"])
71-
if r != _compiler_plugin_registrar_service_source
75+
if r not in (
76+
_compiler_plugin_registrar_service_source,
77+
_component_registrar_service_source,
78+
)
7279
]
7380

7481
_compiler_plugin_registrar_service = (
7582
_compiler_plugin_registrar_service_source,
7683
_compiler_plugin_registrar_service_target,
7784
)
7885

86+
_component_registrar_service = (
87+
_component_registrar_service_source,
88+
_component_registrar_service_target,
89+
)
90+
7991
kt_javac_options(
8092
name = "javac-options",
8193
release = "8",
@@ -93,7 +105,11 @@ kt_javac_options(
93105
"kotlin.RequiresOptIn",
94106
"org.jetbrains.kotlin.ir.symbols.%s" %
95107
("IrSymbolInternals" if version_less(v, "2.0.0") else "UnsafeDuringIrConstructionAPI"),
96-
] + ([] if version_less(v, "2.2.20") else ["org.jetbrains.kotlin.DeprecatedForRemovalCompilerApi"]),
108+
] + (
109+
[] if version_less(v, "2.2.20") else ["org.jetbrains.kotlin.DeprecatedForRemovalCompilerApi"]
110+
) + (
111+
[] if version_less(v, "2.4.20") else ["org.jetbrains.kotlin.K1Deprecation"]
112+
),
97113
x_suppress_version_warnings = True,
98114
),
99115
# * extractor.name is different for each version, so we need to put it in different output dirs
@@ -103,6 +119,8 @@ kt_javac_options(
103119
name = "resources-%s" % v,
104120
srcs = [src for src, _ in _resources] + (
105121
[_compiler_plugin_registrar_service[0]] if not version_less(v, "2.4.0") else []
122+
) + (
123+
[_component_registrar_service[0]] if version_less(v, "2.4.20") else []
106124
),
107125
outs = [
108126
"%s/com/github/codeql/extractor.name" % v,
@@ -114,6 +132,11 @@ kt_javac_options(
114132
v,
115133
_compiler_plugin_registrar_service[1],
116134
)] if not version_less(v, "2.4.0") else []
135+
) + (
136+
["%s/%s" % (
137+
v,
138+
_component_registrar_service[1],
139+
)] if version_less(v, "2.4.20") else []
117140
),
118141
cmd = "\n".join([
119142
"echo %s-%s > $(RULEDIR)/%s/com/github/codeql/extractor.name" % (_extractor_name_prefix, v, v),
@@ -126,6 +149,12 @@ kt_javac_options(
126149
v,
127150
_compiler_plugin_registrar_service[1],
128151
)] if not version_less(v, "2.4.0") else []
152+
) + (
153+
["cp $(execpath %s) $(RULEDIR)/%s/%s" % (
154+
_component_registrar_service[0],
155+
v,
156+
_component_registrar_service[1],
157+
)] if version_less(v, "2.4.20") else []
129158
)),
130159
),
131160
kt_jvm_library(
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:5e2e10f209ef5a63ed70d04ab5c64a8cf346c323f356eb4241ce34ee03cf2e53
3+
size 60184229
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:fac41bf816409462e189b41b87c4a8dfb48b995b4d8d6271968d4f638ceab255
3+
size 58593000
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
version https://git-lfs.github.com/spec/v1
2+
oid sha256:540bee6d6310863014877cb4df8f087c256b22d0925955d1d20943d706bba524
3+
size 1853317

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

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,8 +1645,9 @@ open class KotlinFileExtractor(
16451645
extractMethodAndParameterTypeAccesses: Boolean,
16461646
typeSubstitution: TypeSubstitution?,
16471647
classTypeArgsIncludingOuterClasses: List<IrTypeArgument>?
1648-
) : Label<out DbCallable> =
1649-
forceExtractFunction(
1648+
) : Label<out DbCallable> {
1649+
val sourceLoc = tw.getLocation(f.parentClassOrNull ?: f)
1650+
return forceExtractFunction(
16501651
f,
16511652
parentId,
16521653
extractBody = false,
@@ -1656,6 +1657,7 @@ open class KotlinFileExtractor(
16561657
classTypeArgsIncludingOuterClasses,
16571658
overriddenAttributes =
16581659
OverriddenFunctionAttributes(
1660+
sourceLoc = sourceLoc,
16591661
visibility = DescriptorVisibilities.PUBLIC,
16601662
modality = Modality.OPEN
16611663
)
@@ -1666,7 +1668,6 @@ open class KotlinFileExtractor(
16661668
CompilerGeneratedKinds.INTERFACE_FORWARDER.kind
16671669
)
16681670
if (extractBody) {
1669-
val realFunctionLocId = tw.getLocation(f)
16701671
val inheritedDefaultFunction = f.realOverrideTarget
16711672
val directlyInheritedSymbol =
16721673
when (f) {
@@ -1686,10 +1687,10 @@ open class KotlinFileExtractor(
16861687
(directlyInheritedSymbol.owner.parentClassOrNull ?: return functionId)
16871688
.typeWith()
16881689

1689-
extractExpressionBody(functionId, realFunctionLocId).also { returnId ->
1690+
extractExpressionBody(functionId, sourceLoc).also { returnId ->
16901691
extractRawMethodAccess(
16911692
f,
1692-
realFunctionLocId,
1693+
sourceLoc,
16931694
f.returnType,
16941695
functionId,
16951696
returnId,
@@ -1702,7 +1703,7 @@ open class KotlinFileExtractor(
17021703
extractVariableAccess(
17031704
syntheticParamId,
17041705
param.type,
1705-
realFunctionLocId,
1706+
sourceLoc,
17061707
argParentId,
17071708
idxOffset + idx,
17081709
functionId,
@@ -1718,14 +1719,15 @@ open class KotlinFileExtractor(
17181719
callId,
17191720
-1,
17201721
returnId,
1721-
realFunctionLocId
1722+
sourceLoc
17221723
)
17231724
},
17241725
null
17251726
)
17261727
}
17271728
}
17281729
}
1730+
}
17291731

17301732
private fun extractFunction(
17311733
f: IrFunction,

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ class MetaAnnotationSupport(
9696
val metaAnnotations = annotationClass.annotations
9797
val jvmRepeatable =
9898
metaAnnotations.find {
99-
it.symbol.owner.parentAsClass.fqNameWhenAvailable ==
100-
JvmAnnotationNames.REPEATABLE_ANNOTATION
99+
it.annotationClass.fqNameWhenAvailable == JvmAnnotationNames.REPEATABLE_ANNOTATION
101100
}
102101
return if (jvmRepeatable != null) {
103102
((jvmRepeatable.codeQlGetValueArgument(0) as? IrClassReference)?.symbol as? IrClassSymbol)
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.github.codeql
2+
3+
import org.jetbrains.kotlin.backend.common.extensions.IrGenerationExtension
4+
import org.jetbrains.kotlin.compiler.plugin.CompilerPluginRegistrar
5+
import org.jetbrains.kotlin.compiler.plugin.ExperimentalCompilerApi
6+
import org.jetbrains.kotlin.config.CompilerConfiguration
7+
8+
@OptIn(ExperimentalCompilerApi::class)
9+
abstract class Kotlin2ComponentRegistrar : CompilerPluginRegistrar() {
10+
override val supportsK2: Boolean
11+
get() = true
12+
13+
override val pluginId: String
14+
get() = "kotlin-extractor"
15+
16+
private var extensionStorage: CompilerPluginRegistrar.ExtensionStorage? = null
17+
18+
override fun ExtensionStorage.registerExtensions(configuration: CompilerConfiguration) {
19+
this@Kotlin2ComponentRegistrar.extensionStorage = this
20+
doRegisterExtensions(configuration)
21+
}
22+
23+
abstract fun doRegisterExtensions(configuration: CompilerConfiguration)
24+
25+
protected fun registerExtractorExtension(extension: IrGenerationExtension) {
26+
val storage = extensionStorage
27+
?: throw IllegalStateException("registerExtractorExtension called before registerExtensions")
28+
with(storage) {
29+
IrGenerationExtension.registerExtension(extension)
30+
}
31+
}
32+
}

java/kotlin-extractor/versions.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ VERSIONS = [
1212
"2.3.0",
1313
"2.3.20",
1414
"2.4.0",
15+
"2.4.20-RC",
1516
]
1617

1718
def _version_to_tuple(v):

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

Lines changed: 1 addition & 1 deletion
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.4.20.",
2+
"markdownMessage": "The Kotlin version installed (`2.4.20`) is too recent for this version of CodeQL. Install a version lower than 2.4.20.",
33
"severity": "error",
44
"source": {
55
"extractorName": "java",

0 commit comments

Comments
 (0)