Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9fd9894

Browse files
smowtonigfoo
authored andcommitted
Move abbreviation to external-decl extractor; record full signature.
1 parent 1a656af commit 9fd9894

2 files changed

Lines changed: 11 additions & 8 deletions

File tree

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.github.codeql
33
import com.github.codeql.utils.isExternalDeclaration
44
import com.github.codeql.utils.isExternalFileClassMember
55
import com.semmle.extractor.java.OdasaOutput
6+
import com.semmle.util.data.StringDigestor
67
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
78
import org.jetbrains.kotlin.ir.declarations.*
89
import org.jetbrains.kotlin.ir.util.isFileClass
@@ -44,7 +45,12 @@ class ExternalDeclExtractor(val logger: FileLogger, val invocationTrapFile: Stri
4445
val nextBatch = ArrayList(externalDeclWorkList)
4546
externalDeclWorkList.clear()
4647
nextBatch.forEach { workPair ->
47-
val (irDecl, signature) = workPair
48+
val (irDecl, possiblyLongSignature) = workPair
49+
// In order to avoid excessively long signatures which can lead to trap file names longer than the filesystem
50+
// limit, we truncate and add a hash to preserve uniqueness if necessary.
51+
val signature = if (possiblyLongSignature.length > 100) {
52+
possiblyLongSignature.substring(0, 92) + "#" + StringDigestor.digest(possiblyLongSignature).substring(0, 8)
53+
} else { possiblyLongSignature }
4854
output.getTrapLockerForDecl(irDecl, signature).useAC { locker ->
4955
locker.trapFileManager.useAC { manager ->
5056
val shortName = when(irDecl) {
@@ -73,6 +79,9 @@ class ExternalDeclExtractor(val logger: FileLogger, val invocationTrapFile: Stri
7379
val tw = TrapWriter(logger.loggerBase, TrapLabelManager(), trapFileBW, diagnosticTrapWriter)
7480
tw.writeComment("Generated by the CodeQL Kotlin extractor for external dependencies")
7581
tw.writeComment("Part of invocation $invocationTrapFile")
82+
if (signature != possiblyLongSignature) {
83+
tw.writeComment("Function signature abbreviated; full signature is: $possiblyLongSignature")
84+
}
7685
// Now elevate to a SourceFileTrapWriter, and populate the
7786
// file information if needed:
7887
val ftw = tw.makeFileTrapWriter(binaryPath, irDecl is IrClass)

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.github.codeql
22

33
import com.github.codeql.utils.*
44
import com.semmle.extractor.java.OdasaOutput
5-
import com.semmle.util.data.StringDigestor
65
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
76
import org.jetbrains.kotlin.backend.common.lower.parentsWithSelf
87
import org.jetbrains.kotlin.backend.jvm.codegen.isRawType
@@ -258,12 +257,7 @@ open class KotlinUsesExtractor(
258257
}
259258

260259
val paramTypes = parameters.map { useType(erase(it.type)) }
261-
val possiblyLongSignature = paramTypes.joinToString(separator = ",", prefix = "(", postfix = ")") { it.javaResult.signature!! }
262-
// In order to avoid excessively long signatures which can lead to trap file names longer than the filesystem
263-
// limit, we truncate and add a hash to preserve uniqueness if necessary.
264-
val signature = if (possiblyLongSignature.length > 100) {
265-
possiblyLongSignature.substring(0, 92) + "#" + StringDigestor.digest(possiblyLongSignature).substring(0, 8)
266-
} else { possiblyLongSignature }
260+
val signature = paramTypes.joinToString(separator = ",", prefix = "(", postfix = ")") { it.javaResult.signature!! }
267261
dependencyCollector?.addDependency(f, signature)
268262
externalClassExtractor.extractLater(f, signature)
269263
}

0 commit comments

Comments
 (0)