Skip to content

Commit 5297dde

Browse files
committed
Kotlin: Remove support for Kotlin versions 1.6 and 1.7
This change rolls up all files from v1_6_0, v1_6_20, v1_7_0 and v_1_7_20. In addition, versioned files that are not overridden by any later Kotlin versions (i.e. files that only have one copy under utils/versions) are inlined and removed to simplify list of changes. List of removed/inlined files: allOverriddenIncludingSelf.kt copyTo.kt ExperimentalCompilerApi.kt getFileClassFqName.kt IsUnderscoreParameter.kt ReferenceEntity.kt SyntheticBodyKind.kt Types.kt withHasQuestionMark.kt
1 parent 4f1742e commit 5297dde

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+85
-244
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ open class KotlinFileExtractor(
13431343
extractTypeAccessRecursive(substitutedType, location, id, -1)
13441344
}
13451345
val syntheticParameterNames =
1346-
isUnderscoreParameter(vp) ||
1346+
vp.origin == IrDeclarationOrigin.UNDERSCORE_PARAMETER ||
13471347
((vp.parent as? IrFunction)?.let { hasSynthesizedParameterNames(it) } ?: true)
13481348
val javaParameter =
13491349
when (val callable = (vp.parent as? IrFunction)?.let { getJavaCallable(it) }) {
@@ -2836,7 +2836,7 @@ open class KotlinFileExtractor(
28362836
when {
28372837
kind == IrSyntheticBodyKind.ENUM_VALUES -> tw.writeKtSyntheticBody(callable, 1)
28382838
kind == IrSyntheticBodyKind.ENUM_VALUEOF -> tw.writeKtSyntheticBody(callable, 2)
2839-
kind == kind_ENUM_ENTRIES -> tw.writeKtSyntheticBody(callable, 3)
2839+
kind == IrSyntheticBodyKind.ENUM_ENTRIES -> tw.writeKtSyntheticBody(callable, 3)
28402840
else -> {
28412841
logger.errorElement("Unhandled synthetic body kind " + kind, b)
28422842
}
@@ -3344,7 +3344,7 @@ open class KotlinFileExtractor(
33443344
// that specified the default values, which will in turn dynamically dispatch back to the
33453345
// relevant override.
33463346
val overriddenCallTarget =
3347-
(callTarget as? IrSimpleFunction)?.allOverriddenIncludingSelf()?.firstOrNull {
3347+
(callTarget as? IrSimpleFunction)?.allOverridden(includeSelf = true)?.firstOrNull {
33483348
it.overriddenSymbols.isEmpty() &&
33493349
it.valueParameters.any { p -> p.defaultValue != null }
33503350
} ?: callTarget

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ open class KotlinUsesExtractor(
936936
return arrayInfo.componentTypeResults
937937
}
938938
owner is IrClass -> {
939-
val args = if (s.codeQlIsRawType()) null else s.arguments
939+
val args = if (s.isRawType()) null else s.arguments
940940

941941
return useSimpleTypeClass(owner, args, s.isNullableCodeQL())
942942
}

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.github.codeql
22

3-
import com.github.codeql.utils.versions.copyParameterToFunction
43
import com.github.codeql.utils.versions.createImplicitParameterDeclarationWithWrappedDescriptor
54
import java.lang.annotation.ElementType
65
import java.util.HashSet
@@ -21,7 +20,9 @@ import org.jetbrains.kotlin.ir.declarations.IrClass
2120
import org.jetbrains.kotlin.ir.declarations.IrConstructor
2221
import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
2322
import org.jetbrains.kotlin.ir.declarations.IrEnumEntry
23+
import org.jetbrains.kotlin.ir.declarations.IrFunction
2424
import org.jetbrains.kotlin.ir.declarations.IrProperty
25+
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
2526
import org.jetbrains.kotlin.ir.expressions.IrClassReference
2627
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
2728
import org.jetbrains.kotlin.ir.expressions.IrGetEnumValue
@@ -31,6 +32,7 @@ import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
3132
import org.jetbrains.kotlin.ir.types.typeWith
3233
import org.jetbrains.kotlin.ir.util.constructedClass
3334
import org.jetbrains.kotlin.ir.util.constructors
35+
import org.jetbrains.kotlin.ir.util.copyTo
3436
import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols
3537
import org.jetbrains.kotlin.ir.util.defaultType
3638
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
@@ -330,7 +332,7 @@ class MetaAnnotationSupport(
330332
)
331333
return
332334
}
333-
val newParam = copyParameterToFunction(thisReceiever, this)
335+
val newParam = thisReceiever.copyTo(this)
334336
dispatchReceiverParameter = newParam
335337
body =
336338
factory

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
1212
import org.jetbrains.kotlin.ir.util.parentClassOrNull
1313
import org.jetbrains.kotlin.load.java.sources.JavaSourceElement
1414
import org.jetbrains.kotlin.load.java.structure.impl.classFiles.BinaryJavaClass
15+
import org.jetbrains.kotlin.load.kotlin.FacadeClassSource
1516
import org.jetbrains.kotlin.load.kotlin.JvmPackagePartSource
1617
import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement
1718
import org.jetbrains.kotlin.load.kotlin.VirtualFileKotlinClass
19+
import org.jetbrains.kotlin.name.FqName
1820

1921
// Adapted from Kotlin's interpreter/Utils.kt function 'internalName'
2022
// Translates class names into their JLS section 13.1 binary name,
@@ -31,6 +33,40 @@ fun getFileClassName(f: IrFile) =
3133
.replaceFirst(Regex("""\.kt$"""), "")
3234
.replaceFirstChar { it.uppercase() }) + "Kt")
3335

36+
fun getFileClassFqName(d: IrDeclaration): FqName? {
37+
// d is in a file class.
38+
// Get the name in a similar way to the compiler's ExternalPackageParentPatcherLowering
39+
// visitMemberAccess/generateOrGetFacadeClass.
40+
41+
// But first, fields aren't IrMemberWithContainerSource, so we need
42+
// to get back to the property (if there is one)
43+
if (d is IrField) {
44+
val propSym = d.correspondingPropertySymbol
45+
if (propSym != null) {
46+
return getFileClassFqName(propSym.owner)
47+
}
48+
}
49+
50+
// Now the main code
51+
if (d is IrMemberWithContainerSource) {
52+
val containerSource = d.containerSource
53+
if (containerSource is FacadeClassSource) {
54+
val facadeClassName = containerSource.facadeClassName
55+
if (facadeClassName != null) {
56+
// TODO: This is really a multifile-class rather than a file-class,
57+
// but for now we treat them the same.
58+
return facadeClassName.fqNameForTopLevelClassMaybeWithDollars
59+
} else {
60+
return containerSource.className.fqNameForTopLevelClassMaybeWithDollars
61+
}
62+
} else {
63+
return null
64+
}
65+
} else {
66+
return null
67+
}
68+
}
69+
3470
fun getIrElementBinaryName(that: IrElement): String {
3571
if (that is IrFile) {
3672
val shortName = getFileClassName(that)

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

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,38 @@ package com.github.codeql.utils
22

33
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
44
import org.jetbrains.kotlin.ir.symbols.*
5+
import org.jetbrains.kotlin.name.CallableId
6+
import org.jetbrains.kotlin.name.ClassId
57
import org.jetbrains.kotlin.name.FqName
68
import org.jetbrains.kotlin.name.Name
79

10+
fun getClassByFqName(pluginContext: IrPluginContext, fqName: FqName): IrClassSymbol? {
11+
val id = ClassId.topLevel(fqName)
12+
return getClassByClassId(pluginContext, id)
13+
}
14+
15+
fun getClassByClassId(pluginContext: IrPluginContext, id: ClassId): IrClassSymbol? {
16+
return pluginContext.referenceClass(id)
17+
}
18+
19+
fun getFunctionsByFqName(
20+
pluginContext: IrPluginContext,
21+
pkgName: FqName,
22+
name: Name
23+
): Collection<IrSimpleFunctionSymbol> {
24+
val id = CallableId(pkgName, name)
25+
return pluginContext.referenceFunctions(id)
26+
}
27+
28+
fun getPropertiesByFqName(
29+
pluginContext: IrPluginContext,
30+
pkgName: FqName,
31+
name: Name
32+
): Collection<IrPropertySymbol> {
33+
val id = CallableId(pkgName, name)
34+
return pluginContext.referenceProperties(id)
35+
}
36+
837
fun getClassByFqName(pluginContext: IrPluginContext, fqName: String): IrClassSymbol? {
938
return getClassByFqName(pluginContext, FqName(fqName))
1039
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.github.codeql.utils
22

3-
import com.github.codeql.utils.versions.allOverriddenIncludingSelf
43
import com.github.codeql.utils.versions.CodeQLIrConst
54
import org.jetbrains.kotlin.builtins.StandardNames
65
import org.jetbrains.kotlin.ir.declarations.IrAnnotationContainer
@@ -9,6 +8,7 @@ import org.jetbrains.kotlin.ir.declarations.IrFunction
98
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
109
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
1110
import org.jetbrains.kotlin.ir.types.IrSimpleType
11+
import org.jetbrains.kotlin.ir.util.allOverridden
1212
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
1313
import org.jetbrains.kotlin.ir.util.packageFqName
1414
import org.jetbrains.kotlin.ir.util.parentClassOrNull
@@ -62,7 +62,7 @@ private val specialFunctionShortNames = specialFunctions.keys.map { it.functionN
6262

6363
private fun getSpecialJvmName(f: IrFunction): String? {
6464
if (specialFunctionShortNames.contains(f.name) && f is IrSimpleFunction) {
65-
f.allOverriddenIncludingSelf().forEach { overriddenFunc ->
65+
f.allOverridden(includeSelf = true).forEach { overriddenFunc ->
6666
overriddenFunc.parentClassOrNull?.fqNameWhenAvailable?.let { parentFqName ->
6767
specialFunctions[MethodKey(parentFqName, f.name)]?.let {
6868
return it

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.github.codeql.utils
33
import com.github.codeql.KotlinUsesExtractor
44
import com.github.codeql.Logger
55
import com.github.codeql.getJavaEquivalentClassId
6-
import com.github.codeql.utils.versions.codeQlWithHasQuestionMark
76
import com.github.codeql.utils.versions.createImplicitParameterDeclarationWithWrappedDescriptor
87
import com.github.codeql.utils.versions.*
98
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
@@ -21,6 +20,8 @@ import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
2120
import org.jetbrains.kotlin.ir.symbols.impl.DescriptorlessExternalPackageFragmentSymbol
2221
import org.jetbrains.kotlin.ir.types.addAnnotations
2322
import org.jetbrains.kotlin.ir.types.classifierOrNull
23+
import org.jetbrains.kotlin.ir.types.makeNotNull
24+
import org.jetbrains.kotlin.ir.types.makeNullable
2425
import org.jetbrains.kotlin.ir.types.typeWith
2526
import org.jetbrains.kotlin.ir.types.IrSimpleType
2627
import org.jetbrains.kotlin.ir.types.IrStarProjection
@@ -35,6 +36,14 @@ import org.jetbrains.kotlin.name.Name
3536
import org.jetbrains.kotlin.types.Variance
3637
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull
3738

39+
fun IrType.codeQlWithHasQuestionMark(b: Boolean): IrType {
40+
if (b) {
41+
return this.makeNullable()
42+
} else {
43+
return this.makeNotNull()
44+
}
45+
}
46+
3847
fun IrType.substituteTypeArguments(params: List<IrTypeParameter>, arguments: List<IrTypeArgument>) =
3948
when (this) {
4049
is IrSimpleType -> substituteTypeArguments(params.map { it.symbol }.zip(arguments).toMap())

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_6_0/ExperimentalCompilerApi.kt

Lines changed: 0 additions & 4 deletions
This file was deleted.

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_6_0/IsUnderscoreParameter.kt

Lines changed: 0 additions & 21 deletions
This file was deleted.

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_6_0/ReferenceEntity.kt

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)