Skip to content

Commit

Permalink
Kotlin: Fix build with 2.1.0-Beta1
Browse files Browse the repository at this point in the history
  • Loading branch information
igfoo committed Sep 23, 2024
1 parent e7a3e59 commit 00949e9
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 46 deletions.
35 changes: 6 additions & 29 deletions java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,7 @@ 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.impl.makeTypeProjection
import org.jetbrains.kotlin.ir.util.companionObject
import org.jetbrains.kotlin.ir.util.constructors
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
import org.jetbrains.kotlin.ir.util.hasAnnotation
import org.jetbrains.kotlin.ir.util.hasInterfaceParent
import org.jetbrains.kotlin.ir.util.isAnnotationClass
import org.jetbrains.kotlin.ir.util.isAnonymousObject
import org.jetbrains.kotlin.ir.util.isFakeOverride
import org.jetbrains.kotlin.ir.util.isFunctionOrKFunction
import org.jetbrains.kotlin.ir.util.isInterface
import org.jetbrains.kotlin.ir.util.isLocal
import org.jetbrains.kotlin.ir.util.isNonCompanionObject
import org.jetbrains.kotlin.ir.util.isObject
import org.jetbrains.kotlin.ir.util.isSuspend
import org.jetbrains.kotlin.ir.util.isSuspendFunctionOrKFunction
import org.jetbrains.kotlin.ir.util.isVararg
import org.jetbrains.kotlin.ir.util.kotlinFqName
import org.jetbrains.kotlin.ir.util.packageFqName
import org.jetbrains.kotlin.ir.util.parentAsClass
import org.jetbrains.kotlin.ir.util.parentClassOrNull
import org.jetbrains.kotlin.ir.util.parents
import org.jetbrains.kotlin.ir.util.primaryConstructor
import org.jetbrains.kotlin.ir.util.render
import org.jetbrains.kotlin.ir.util.target
import org.jetbrains.kotlin.ir.util.*
import org.jetbrains.kotlin.load.java.JvmAnnotationNames
import org.jetbrains.kotlin.load.java.NOT_NULL_ANNOTATIONS
import org.jetbrains.kotlin.load.java.NULLABLE_ANNOTATIONS
Expand Down Expand Up @@ -826,7 +803,7 @@ open class KotlinFileExtractor(
fun exprId() = tw.getLabelFor<DbExpr>("@\"annotationExpr;{$parent};$idx\"")

return when (v) {
is IrConst<*> -> {
is CodeQLIrConst<*> -> {
extractConstant(v, parent, idx, null, null, overrideId = exprId())
}
is IrGetEnumValue -> {
Expand Down Expand Up @@ -5999,7 +5976,7 @@ open class KotlinFileExtractor(
extractExpressionExpr(a, callable, id, i, exprParent.enclosingStmt)
}
}
is IrConst<*> -> {
is CodeQLIrConst<*> -> {
val exprParent = parent.expr(e, callable)
extractConstant(
e,
Expand Down Expand Up @@ -6211,9 +6188,9 @@ open class KotlinFileExtractor(
if (
(isAndAnd || isOrOr) &&
e.branches.size == 2 &&
(e.branches[1].condition as? IrConst<*>)?.value == true &&
(e.branches[1].condition as? CodeQLIrConst<*>)?.value == true &&
(e.branches[if (e.origin == IrStatementOrigin.ANDAND) 1 else 0].result
as? IrConst<*>)
as? CodeQLIrConst<*>)
?.value == isOrOr
) {

Expand Down Expand Up @@ -6869,7 +6846,7 @@ open class KotlinFileExtractor(
}

private fun extractConstant(
e: IrConst<*>,
e: CodeQLIrConst<*>,
parent: Label<out DbExprparent>,
idx: Int,
enclosingCallable: Label<out DbCallable>?,
Expand Down
12 changes: 7 additions & 5 deletions java/kotlin-extractor/src/main/kotlin/KotlinUsesExtractor.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.github.codeql.utils.versions.*
import com.semmle.extractor.java.OdasaOutput
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.backend.common.ir.*
import org.jetbrains.kotlin.backend.jvm.ir.propertyIfAccessor
import org.jetbrains.kotlin.backend.jvm.ir.*
import org.jetbrains.kotlin.codegen.JvmCodegenUtil
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
Expand All @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.load.kotlin.getJvmModuleNameForDeserializedDescripto
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.NameUtils
import org.jetbrains.kotlin.name.SpecialNames
import org.jetbrains.kotlin.resolve.descriptorUtil.propertyIfAccessor
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.util.OperatorNameConventions

Expand Down Expand Up @@ -84,7 +85,7 @@ open class KotlinUsesExtractor(
}

private fun extractFileClass(fqName: FqName): Label<out DbClassorinterface> {
val pkg = if (fqName.isRoot()) "" else fqName.parent().asString()
val pkg = if (fqName.codeQlIsRoot()) "" else fqName.parent().asString()
val jvmName = fqName.shortName().asString()
return extractFileClass(pkg, jvmName)
}
Expand Down Expand Up @@ -906,7 +907,7 @@ open class KotlinUsesExtractor(
return arrayInfo.componentTypeResults
}
owner is IrClass -> {
val args = if (s.isRawType()) null else s.arguments
val args = if (s.codeQlIsRawType()) null else s.arguments

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

private fun addJavaLoweringArgumentWildcards(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ import org.jetbrains.kotlin.ir.expressions.IrClassReference
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.expressions.IrGetEnumValue
import org.jetbrains.kotlin.ir.expressions.IrVararg
import org.jetbrains.kotlin.ir.expressions.impl.IrClassReferenceImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrGetEnumValueImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrGetFieldImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrGetValueImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrReturnImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl
import org.jetbrains.kotlin.ir.expressions.impl.*
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
import org.jetbrains.kotlin.ir.types.typeWith
import org.jetbrains.kotlin.ir.util.constructedClass
Expand Down
4 changes: 2 additions & 2 deletions java/kotlin-extractor/src/main/kotlin/utils/JvmNames.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.github.codeql.utils

import com.github.codeql.utils.versions.allOverriddenIncludingSelf
import com.github.codeql.utils.versions.CodeQLIrConst
import org.jetbrains.kotlin.builtins.StandardNames
import org.jetbrains.kotlin.ir.declarations.IrAnnotationContainer
import org.jetbrains.kotlin.ir.declarations.IrClass
import org.jetbrains.kotlin.ir.declarations.IrFunction
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.expressions.IrConst
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.types.IrSimpleType
import org.jetbrains.kotlin.ir.util.fqNameWhenAvailable
Expand Down Expand Up @@ -82,7 +82,7 @@ fun getJvmName(container: IrAnnotationContainer): String? {
if (owner is IrClass) {
val aPkg = owner.packageFqName?.asString()
val name = owner.name.asString()
if (aPkg == "kotlin.jvm" && name == "JvmName" && v is IrConst<*>) {
if (aPkg == "kotlin.jvm" && name == "JvmName" && v is CodeQLIrConst<*>) {
val value = v.value
if (value is String) {
return value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer
import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
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.*
Expand Down
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.expressions.IrConst

typealias CodeQLIrConst<T> = IrConst<T>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.github.codeql.utils.versions

import org.jetbrains.kotlin.name.FqName

fun FqName.codeQlIsRoot() = this.isRoot()
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package com.github.codeql.utils.versions
import org.jetbrains.kotlin.backend.jvm.codegen.isRawType
import org.jetbrains.kotlin.ir.types.IrSimpleType

fun IrSimpleType.isRawType() = this.isRawType()
fun IrSimpleType.codeQlIsRawType() = this.isRawType()
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package com.github.codeql.utils.versions
import org.jetbrains.kotlin.backend.jvm.ir.isRawType
import org.jetbrains.kotlin.ir.types.IrSimpleType

fun IrSimpleType.isRawType() = this.isRawType()
fun IrSimpleType.codeQlIsRawType() = this.isRawType()
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.expressions.IrConst

typealias CodeQLIrConst<T> = IrConst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.github.codeql.utils.versions

import org.jetbrains.kotlin.name.FqName

fun FqName.codeQlIsRoot() = this.isRoot

0 comments on commit 00949e9

Please sign in to comment.