mirror of
https://github.com/github/codeql.git
synced 2025-12-16 16:53:25 +01:00
Kotlin: Fix build with 2.1.20-Beta1
This commit is contained in:
@@ -25,7 +25,19 @@ 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.*
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.types.classFqName
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrFail
|
||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||
import org.jetbrains.kotlin.ir.types.isAny
|
||||
import org.jetbrains.kotlin.ir.types.isNullableAny
|
||||
import org.jetbrains.kotlin.ir.types.typeOrNull
|
||||
import org.jetbrains.kotlin.ir.types.typeWith
|
||||
import org.jetbrains.kotlin.ir.types.typeWithArguments
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrStarProjection
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeArgument
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeProjection
|
||||
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
|
||||
@@ -2293,7 +2305,7 @@ open class KotlinFileExtractor(
|
||||
// synthesised and inherit the annotation from the delegate (which given it has
|
||||
// @NotNull, is likely written in Java)
|
||||
JvmAnnotationNames.JETBRAINS_NOT_NULL_ANNOTATION.takeUnless {
|
||||
t.isNullable() ||
|
||||
t.isNullableCodeQL() ||
|
||||
primitiveTypeMapping.getPrimitiveInfo(t) != null ||
|
||||
hasExistingAnnotation(it)
|
||||
}
|
||||
@@ -3975,7 +3987,7 @@ open class KotlinFileExtractor(
|
||||
target.parent
|
||||
} else {
|
||||
val st = extensionReceiverParameter.type as? IrSimpleType
|
||||
if (isNullable != null && st?.isNullable() != isNullable) {
|
||||
if (isNullable != null && st?.isNullableCodeQL() != isNullable) {
|
||||
verboseln("Nullablility of type didn't match")
|
||||
return false
|
||||
}
|
||||
@@ -4621,9 +4633,9 @@ open class KotlinFileExtractor(
|
||||
val isPrimitiveArrayCreation = !isBuiltinCallKotlin(c, "arrayOf")
|
||||
val elementType =
|
||||
if (isPrimitiveArrayCreation) {
|
||||
c.type.getArrayElementType(pluginContext.irBuiltIns)
|
||||
c.type.getArrayElementTypeCodeQL(pluginContext.irBuiltIns)
|
||||
} else {
|
||||
// TODO: is there any reason not to always use getArrayElementType?
|
||||
// TODO: is there any reason not to always use getArrayElementTypeCodeQL?
|
||||
if (c.typeArgumentsCount == 1) {
|
||||
c.getTypeArgument(0).also {
|
||||
if (it == null) {
|
||||
|
||||
@@ -12,7 +12,24 @@ import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.types.addAnnotations
|
||||
import org.jetbrains.kotlin.ir.types.classFqName
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrNull
|
||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||
import org.jetbrains.kotlin.ir.types.isAny
|
||||
import org.jetbrains.kotlin.ir.types.isNullableAny
|
||||
import org.jetbrains.kotlin.ir.types.isPrimitiveType
|
||||
import org.jetbrains.kotlin.ir.types.makeNullable
|
||||
import org.jetbrains.kotlin.ir.types.typeOrNull
|
||||
import org.jetbrains.kotlin.ir.types.typeWith
|
||||
import org.jetbrains.kotlin.ir.types.typeWithArguments
|
||||
import org.jetbrains.kotlin.ir.types.IrDynamicType
|
||||
import org.jetbrains.kotlin.ir.types.IrErrorType
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrStarProjection
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeArgument
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeProjection
|
||||
import org.jetbrains.kotlin.ir.types.impl.*
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.load.java.BuiltinMethodsWithSpecialGenericSignature
|
||||
@@ -679,7 +696,7 @@ open class KotlinUsesExtractor(
|
||||
private fun getInvariantNullableArrayType(arrayType: IrSimpleType): IrSimpleType =
|
||||
if (arrayType.isPrimitiveArray()) arrayType
|
||||
else {
|
||||
val componentType = arrayType.getArrayElementType(pluginContext.irBuiltIns)
|
||||
val componentType = arrayType.getArrayElementTypeCodeQL(pluginContext.irBuiltIns)
|
||||
val componentTypeBroadened =
|
||||
when (componentType) {
|
||||
is IrSimpleType ->
|
||||
@@ -690,7 +707,7 @@ open class KotlinUsesExtractor(
|
||||
val unchanged =
|
||||
componentType == componentTypeBroadened &&
|
||||
(arrayType.arguments[0] as? IrTypeProjection)?.variance == Variance.INVARIANT &&
|
||||
componentType.isNullable()
|
||||
componentType.isNullableCodeQL()
|
||||
if (unchanged) arrayType
|
||||
else
|
||||
IrSimpleTypeImpl(
|
||||
@@ -705,7 +722,7 @@ open class KotlinUsesExtractor(
|
||||
Kotlin arrays can be broken down as:
|
||||
|
||||
isArray(t)
|
||||
|- t.isBoxedArray
|
||||
|- t.isBoxedArrayCodeQL
|
||||
| |- t.isArray() e.g. Array<Boolean>, Array<Boolean?>
|
||||
| |- t.isNullableArray() e.g. Array<Boolean>?, Array<Boolean?>?
|
||||
|- t.isPrimitiveArray() e.g. BooleanArray
|
||||
@@ -715,7 +732,7 @@ open class KotlinUsesExtractor(
|
||||
Primitive arrays are represented as e.g. boolean[].
|
||||
*/
|
||||
|
||||
private fun isArray(t: IrType) = t.isBoxedArray || t.isPrimitiveArray()
|
||||
private fun isArray(t: IrType) = t.isBoxedArrayCodeQL || t.isPrimitiveArray()
|
||||
|
||||
data class ArrayInfo(
|
||||
val elementTypeResults: TypeResults,
|
||||
@@ -756,7 +773,7 @@ open class KotlinUsesExtractor(
|
||||
) {
|
||||
pluginContext.irBuiltIns.anyType
|
||||
} else {
|
||||
t.getArrayElementType(pluginContext.irBuiltIns)
|
||||
t.getArrayElementTypeCodeQL(pluginContext.irBuiltIns)
|
||||
}
|
||||
|
||||
val recInfo = useArrayType(elementType, t.isPrimitiveArray())
|
||||
@@ -844,7 +861,7 @@ open class KotlinUsesExtractor(
|
||||
if (
|
||||
(context == TypeContext.RETURN ||
|
||||
(context == TypeContext.OTHER && otherIsPrimitive)) &&
|
||||
!s.isNullable() &&
|
||||
!s.isNullableCodeQL() &&
|
||||
getKotlinType(s)?.hasEnhancedNullability() != true &&
|
||||
primitiveName != null
|
||||
) {
|
||||
@@ -860,7 +877,7 @@ open class KotlinUsesExtractor(
|
||||
val kotlinClassId = useClassInstance(kotlinClass, listOf()).typeResult.id
|
||||
val kotlinResult =
|
||||
if (true) TypeResult(fakeKotlinType(), "TODO", "TODO")
|
||||
else if (s.isNullable()) {
|
||||
else if (s.isNullableCodeQL()) {
|
||||
val kotlinSignature =
|
||||
"$kotlinPackageName.$kotlinClassName?" // TODO: Is this right?
|
||||
val kotlinLabel = "@\"kt_type;nullable;$kotlinPackageName.$kotlinClassName\""
|
||||
@@ -902,21 +919,21 @@ open class KotlinUsesExtractor(
|
||||
return extractErrorType()
|
||||
}
|
||||
}
|
||||
(s.isBoxedArray && s.arguments.isNotEmpty()) || s.isPrimitiveArray() -> {
|
||||
(s.isBoxedArrayCodeQL && s.arguments.isNotEmpty()) || s.isPrimitiveArray() -> {
|
||||
val arrayInfo = useArrayType(s, false)
|
||||
return arrayInfo.componentTypeResults
|
||||
}
|
||||
owner is IrClass -> {
|
||||
val args = if (s.codeQlIsRawType()) null else s.arguments
|
||||
|
||||
return useSimpleTypeClass(owner, args, s.isNullable())
|
||||
return useSimpleTypeClass(owner, args, s.isNullableCodeQL())
|
||||
}
|
||||
owner is IrTypeParameter -> {
|
||||
val javaResult = useTypeParameter(owner)
|
||||
val aClassId = makeClass("kotlin", "TypeParam") // TODO: Wrong
|
||||
val kotlinResult =
|
||||
if (true) TypeResult(fakeKotlinType(), "TODO", "TODO")
|
||||
else if (s.isNullable()) {
|
||||
else if (s.isNullableCodeQL()) {
|
||||
val kotlinSignature = "${javaResult.signature}?" // TODO: Wrong
|
||||
val kotlinLabel = "@\"kt_type;nullable;type_param\"" // TODO: Wrong
|
||||
val kotlinId: Label<DbKt_nullable_type> =
|
||||
@@ -1200,7 +1217,7 @@ open class KotlinUsesExtractor(
|
||||
}
|
||||
|
||||
private fun extendsAdditionAllowed(t: IrType) =
|
||||
if (t.isBoxedArray) {
|
||||
if (t.isBoxedArrayCodeQL) {
|
||||
if (t is IrSimpleType) {
|
||||
arrayExtendsAdditionAllowed(t)
|
||||
} else {
|
||||
@@ -1493,7 +1510,7 @@ open class KotlinUsesExtractor(
|
||||
}
|
||||
} else {
|
||||
t.classOrNull?.let { tCls ->
|
||||
if (t.isBoxedArray) {
|
||||
if (t.isBoxedArrayCodeQL) {
|
||||
(t.arguments.singleOrNull() as? IrTypeProjection)?.let { elementTypeArg
|
||||
->
|
||||
val elementType = elementTypeArg.type
|
||||
@@ -1506,7 +1523,7 @@ open class KotlinUsesExtractor(
|
||||
)
|
||||
return tCls
|
||||
.typeWithArguments(listOf(newArg))
|
||||
.codeQlWithHasQuestionMark(t.isNullable())
|
||||
.codeQlWithHasQuestionMark(t.isNullableCodeQL())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2086,12 +2103,12 @@ open class KotlinUsesExtractor(
|
||||
}
|
||||
|
||||
if (owner is IrClass) {
|
||||
if (t.isBoxedArray) {
|
||||
val elementType = t.getArrayElementType(pluginContext.irBuiltIns)
|
||||
if (t.isBoxedArrayCodeQL) {
|
||||
val elementType = t.getArrayElementTypeCodeQL(pluginContext.irBuiltIns)
|
||||
val erasedElementType = erase(elementType)
|
||||
return owner
|
||||
.typeWith(erasedElementType)
|
||||
.codeQlWithHasQuestionMark(t.isNullable())
|
||||
.codeQlWithHasQuestionMark(t.isNullableCodeQL())
|
||||
}
|
||||
|
||||
return if (t.arguments.isNotEmpty())
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.github.codeql.utils.versions.*
|
||||
import com.intellij.openapi.vfs.StandardFileSystems
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
|
||||
import org.jetbrains.kotlin.fir.java.JavaBinarySourceElement
|
||||
import org.jetbrains.kotlin.fir.java.VirtualFileBasedSourceElement
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
|
||||
@@ -89,8 +89,8 @@ fun getIrClassVirtualFile(irClass: IrClass): VirtualFile? {
|
||||
is BinaryJavaClass -> return element.virtualFile
|
||||
}
|
||||
}
|
||||
is JavaBinarySourceElement -> {
|
||||
return cSource.javaClass.virtualFile
|
||||
is VirtualFileBasedSourceElement -> {
|
||||
return cSource.virtualFile
|
||||
}
|
||||
is KotlinJvmBinarySourceElement -> {
|
||||
val binaryClass = cSource.binaryClass
|
||||
|
||||
@@ -5,6 +5,7 @@ import com.github.codeql.Logger
|
||||
import com.github.codeql.getJavaEquivalentClassId
|
||||
import com.github.codeql.utils.versions.codeQlWithHasQuestionMark
|
||||
import com.github.codeql.utils.versions.createImplicitParameterDeclarationWithWrappedDescriptor
|
||||
import com.github.codeql.utils.versions.*
|
||||
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.addConstructor
|
||||
@@ -18,15 +19,18 @@ import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.DescriptorlessExternalPackageFragmentSymbol
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.types.addAnnotations
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrNull
|
||||
import org.jetbrains.kotlin.ir.types.typeWith
|
||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.IrStarProjection
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeArgument
|
||||
import org.jetbrains.kotlin.ir.types.IrTypeProjection
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
||||
import org.jetbrains.kotlin.ir.util.classId
|
||||
import org.jetbrains.kotlin.ir.util.constructedClassType
|
||||
import org.jetbrains.kotlin.ir.util.constructors
|
||||
import org.jetbrains.kotlin.ir.util.kotlinFqName
|
||||
import org.jetbrains.kotlin.ir.util.parents
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.Variance
|
||||
@@ -57,7 +61,7 @@ private fun IrSimpleType.substituteTypeArguments(
|
||||
}
|
||||
}
|
||||
|
||||
return IrSimpleTypeImpl(classifier, isNullable(), newArguments, annotations)
|
||||
return IrSimpleTypeImpl(classifier, isNullableCodeQL(), newArguments, annotations)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -96,7 +100,7 @@ private fun subProjectedType(
|
||||
else {
|
||||
val newProjectedType =
|
||||
substitutedTypeArg.type.let {
|
||||
if (t.isNullable()) it.codeQlWithHasQuestionMark(true) else it
|
||||
if (t.isNullableCodeQL()) it.codeQlWithHasQuestionMark(true) else it
|
||||
}
|
||||
val newVariance = combineVariance(outerVariance, substitutedTypeArg.variance)
|
||||
makeTypeProjection(newProjectedType, newVariance)
|
||||
@@ -113,7 +117,7 @@ private fun IrTypeArgument.upperBound(context: IrPluginContext) =
|
||||
when (this.variance) {
|
||||
Variance.INVARIANT -> this.type
|
||||
Variance.IN_VARIANCE ->
|
||||
if (this.type.isNullable()) context.irBuiltIns.anyNType
|
||||
if (this.type.isNullableCodeQL()) context.irBuiltIns.anyNType
|
||||
else context.irBuiltIns.anyType
|
||||
Variance.OUT_VARIANCE -> this.type
|
||||
}
|
||||
@@ -128,7 +132,7 @@ private fun IrTypeArgument.lowerBound(context: IrPluginContext) =
|
||||
Variance.INVARIANT -> this.type
|
||||
Variance.IN_VARIANCE -> this.type
|
||||
Variance.OUT_VARIANCE ->
|
||||
if (this.type.isNullable()) context.irBuiltIns.nothingNType
|
||||
if (this.type.isNullableCodeQL()) context.irBuiltIns.nothingNType
|
||||
else context.irBuiltIns.nothingType
|
||||
}
|
||||
else -> context.irBuiltIns.nothingType
|
||||
@@ -211,7 +215,7 @@ fun IrTypeArgument.withQuestionMark(b: Boolean): IrTypeArgument =
|
||||
this.type.let {
|
||||
when (it) {
|
||||
is IrSimpleType ->
|
||||
if (it.isNullable() == b) this
|
||||
if (it.isNullableCodeQL() == b) this
|
||||
else makeTypeProjection(it.codeQlWithHasQuestionMark(b), this.variance)
|
||||
else -> this
|
||||
}
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||
|
||||
typealias IrBuiltIns = IrBuiltIns
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.jetbrains.kotlin.fir.java
|
||||
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.load.java.structure.impl.classFiles.BinaryJavaClass
|
||||
|
||||
@@ -7,5 +8,6 @@ import org.jetbrains.kotlin.load.java.structure.impl.classFiles.BinaryJavaClass
|
||||
We need this class to exist, but the compiler will never give us an
|
||||
instance of it.
|
||||
*/
|
||||
abstract class JavaBinarySourceElement private constructor(val javaClass: BinaryJavaClass) :
|
||||
SourceElement {}
|
||||
abstract class VirtualFileBasedSourceElement private constructor(val javaClass: BinaryJavaClass) : SourceElement {
|
||||
abstract val virtualFile: VirtualFile
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
|
||||
fun IrType.isNullableCodeQL(): Boolean =
|
||||
this.isNullable()
|
||||
|
||||
val IrType.isBoxedArrayCodeQL: Boolean by IrType::isBoxedArray
|
||||
|
||||
fun IrType.getArrayElementTypeCodeQL(irBuiltIns: IrBuiltIns): IrType =
|
||||
this.getArrayElementType(irBuiltIns)
|
||||
@@ -0,0 +1,5 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
|
||||
typealias IrBuiltIns = org.jetbrains.kotlin.ir.IrBuiltIns
|
||||
@@ -1,3 +0,0 @@
|
||||
/*
|
||||
The compiler provides this class, so we don't have to do anything.
|
||||
*/
|
||||
@@ -0,0 +1,3 @@
|
||||
package org.jetbrains.kotlin.fir.java
|
||||
|
||||
typealias VirtualFileBasedSourceElement = JavaBinarySourceElement
|
||||
@@ -0,0 +1 @@
|
||||
// Nothing to do
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.github.codeql.utils.versions
|
||||
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
|
||||
fun IrType.isNullableCodeQL(): Boolean =
|
||||
this.isNullable()
|
||||
|
||||
val IrType.isBoxedArrayCodeQL: Boolean by IrType::isBoxedArray
|
||||
|
||||
fun IrType.getArrayElementTypeCodeQL(irBuiltIns: IrBuiltIns): IrType =
|
||||
this.getArrayElementType(irBuiltIns)
|
||||
Reference in New Issue
Block a user