Skip to content

Commit e153f30

Browse files
committed
Kotlin: Avoid "generic specialisation" label collisions
We had a global set of labels for generic specialisations that we'd extracted, but these labels could contain references to other labels, and thus you can get false collisions between labels for different TRAP files. We now only keep the set for a single TRAP file, and live with the extra TRAP duplication that we get from that.
1 parent 3836d15 commit e153f30

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ class KotlinExtractorExtension(
138138
}
139139

140140
class KotlinExtractorGlobalState {
141-
val genericSpecialisationsExtracted = HashSet<String>()
142141
// These three record mappings of classes, functions and fields that should be replaced wherever they are found.
143142
// As of now these are only used to fix IR generated by the Gradle Android Extensions plugin, hence e.g. IrProperty
144143
// doesn't have a map as that plugin doesn't generate them. If and when these are used more widely additional maps

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ open class KotlinUsesExtractor(
407407
extractorWithCSource.extractClassInstance(c, argsIncludingOuterClasses)
408408
}
409409

410-
if (inReceiverContext && globalExtensionState.genericSpecialisationsExtracted.add(classLabelResult.classLabel)) {
410+
if (inReceiverContext && tw.lm.genericSpecialisationsExtracted.add(classLabelResult.classLabel)) {
411411
val supertypeMode = if (argsIncludingOuterClasses == null) ExtractSupertypesMode.Raw else ExtractSupertypesMode.Specialised(argsIncludingOuterClasses)
412412
extractorWithCSource.extractClassSupertypes(c, classLabel, supertypeMode, true)
413413
extractorWithCSource.extractNonPrivateMemberPrototypes(c, argsIncludingOuterClasses, classLabel)

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@ class TrapLabelManager {
4040
val anonymousTypeMapping: MutableMap<IrClass, TypeResults> = mutableMapOf()
4141

4242
val locallyVisibleFunctionLabelMapping: MutableMap<IrFunction, LocallyVisibleFunctionLabels> = mutableMapOf()
43+
44+
/**
45+
* The set of labels of generic specialisations that we have extracted
46+
* in this TRAP file.
47+
* We can't easily avoid duplication between TRAP files, as the labels
48+
* contain references to other labels, so we just accept this
49+
* duplication.
50+
*/
51+
val genericSpecialisationsExtracted = HashSet<String>()
4352
}
4453

4554
/**

0 commit comments

Comments
 (0)