Skip to content

Commit 13fb032

Browse files
committed
Kotlin: Remove unbound symbol owner lookup
1 parent 847a64c commit 13fb032

File tree

5 files changed

+5
-95
lines changed

5 files changed

+5
-95
lines changed

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

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.github.codeql
33
import com.github.codeql.comments.CommentExtractor
44
import com.github.codeql.utils.*
55
import com.github.codeql.utils.versions.functionN
6-
import com.github.codeql.utils.versions.getIrStubFromDescriptor
76
import com.github.codeql.utils.versions.isUnderscoreParameter
87
import com.semmle.extractor.java.OdasaOutput
98
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
@@ -1788,7 +1787,7 @@ open class KotlinFileExtractor(
17881787

17891788
private fun extractCall(c: IrCall, callable: Label<out DbCallable>, stmtExprParent: StmtExprParent) {
17901789
with("call", c) {
1791-
val owner = tryGetPossiblyUnboundSymbolOwner(c.symbol, c) ?: return
1790+
val owner = getBoundSymbolOwner(c.symbol, c) ?: return
17921791
val target = tryReplaceSyntheticFunction(owner)
17931792

17941793
// The vast majority of types of call want an expr context, so make one available lazily:
@@ -2954,7 +2953,7 @@ open class KotlinFileExtractor(
29542953
tw.writeCallableEnclosingExpr(id, callable)
29552954
tw.writeStatementEnclosingExpr(id, exprParent.enclosingStmt)
29562955

2957-
val owner = tryGetPossiblyUnboundSymbolOwner(e.symbol, e) ?: return
2956+
val owner = getBoundSymbolOwner(e.symbol, e) ?: return
29582957

29592958
val vId = useEnumEntry(owner)
29602959
tw.writeVariableBinding(id, vId)
@@ -3131,7 +3130,7 @@ open class KotlinFileExtractor(
31313130
// automatically-generated `public static final MyObject INSTANCE`
31323131
// field that we are accessing here.
31333132
val exprParent = parent.expr(e, callable)
3134-
val c = tryGetPossiblyUnboundSymbolOwner(e.symbol, e) ?: return
3133+
val c = getBoundSymbolOwner(e.symbol, e) ?: return
31353134

31363135
val instance = if (c.isCompanion) useCompanionObjectClassInstance(c) else useObjectClassInstance(c)
31373136

@@ -3244,21 +3243,12 @@ open class KotlinFileExtractor(
32443243
}
32453244
}
32463245

3247-
private inline fun <D: DeclarationDescriptor, reified B: IrSymbolOwner> tryGetPossiblyUnboundSymbolOwner(symbol: IrBindableSymbol<D, B>, e: IrElement): B? {
3246+
private inline fun <D: DeclarationDescriptor, reified B: IrSymbolOwner> getBoundSymbolOwner(symbol: IrBindableSymbol<D, B>, e: IrExpression): B? {
32483247
if (symbol.isBound) {
32493248
return symbol.owner
32503249
}
32513250

3252-
logger.warnElement("Unbound symbol, trying to use owner stub from descriptor", e)
3253-
3254-
@OptIn(ObsoleteDescriptorBasedAPI::class)
3255-
val owner = getIrStubFromDescriptor() { it.generateMemberStub(symbol.descriptor) }
3256-
3257-
if (owner is B) {
3258-
return owner
3259-
}
3260-
3261-
logger.errorElement("Couldn't get owner of unbound symbol from its descriptor", e)
3251+
logger.errorElement("Unbound symbol found, skipping extraction of expression", e)
32623252
return null
32633253
}
32643254

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_4_32/Descriptors.kt

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

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_5_20/Descriptors.kt

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

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

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

java/kotlin-extractor/src/main/kotlin/utils/versions/v_1_7_0/Descriptors.kt

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

0 commit comments

Comments
 (0)