Skip to content

Commit

Permalink
[JPS] Allow writing the subtypes map in compiler-maps-only mode
Browse files Browse the repository at this point in the history
^KTIJ-30296 Fixed

Merge-request: KT-MR-16967
Merged-by: Aleksei Cherepanov <[email protected]>

(cherry picked from commit fdff5f1)
  • Loading branch information
Aleksei.Cherepanov committed Jul 15, 2024
1 parent 3dcabe1 commit 8b47342
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ abstract class AbstractIncrementalCache<ClassName>(
*
* The `srcFile` argument may be `null` (e.g., if we are processing .class files in jars where source files are not available).
*/
protected fun addToClassStorage(classProtoData: ClassProtoData, srcFile: File?) {
protected fun addToClassStorage(classProtoData: ClassProtoData, srcFile: File?, useCompilerMapsOnly: Boolean = false) {
val (proto, nameResolver) = classProtoData

val supertypes = proto.supertypes(TypeTable(proto.typeTable))
Expand All @@ -143,11 +143,17 @@ abstract class AbstractIncrementalCache<ClassName>(
removedSupertypes.forEach { subtypesMap.removeValues(it, setOf(child)) }

supertypesMap[child] = parents
srcFile?.let { classFqNameToSourceMap[child] = it }
classAttributesMap[child] = ICClassesAttributes(ProtoBuf.Modality.SEALED == Flags.MODALITY.get(proto.flags))
if (!useCompilerMapsOnly) {
srcFile?.let { classFqNameToSourceMap[child] = it }
classAttributesMap[child] = ICClassesAttributes(ProtoBuf.Modality.SEALED == Flags.MODALITY.get(proto.flags))
}
}

protected fun removeAllFromClassStorage(removedClasses: Collection<FqName>, changesCollector: ChangesCollector) {
protected fun removeAllFromClassStorage(
removedClasses: Collection<FqName>,
changesCollector: ChangesCollector,
useCompilerMapsOnly: Boolean = false,
) {
if (removedClasses.isEmpty()) return

val removedFqNames = removedClasses.toSet()
Expand Down Expand Up @@ -179,9 +185,11 @@ abstract class AbstractIncrementalCache<ClassName>(
}
}

removedFqNames.forEach {
classFqNameToSourceMap.remove(it)
classAttributesMap.remove(it)
if (!useCompilerMapsOnly) {
removedFqNames.forEach {
classFqNameToSourceMap.remove(it)
classAttributesMap.remove(it)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,7 @@ open class IncrementalJvmCache(
}
}
KotlinClassHeader.Kind.CLASS -> {
if (!icContext.useCompilerMapsOnly) {
addToClassStorage(kotlinClassInfo.protoData as ClassProtoData, sourceFiles?.let { sourceFiles.single() })
}
addToClassStorage(kotlinClassInfo.protoData as ClassProtoData, sourceFiles?.let { sourceFiles.single() }, icContext.useCompilerMapsOnly)

protoMap.process(kotlinClassInfo, changesCollector)

Expand Down Expand Up @@ -257,10 +255,7 @@ open class IncrementalJvmCache(
javaSourcesProtoMap.process(jvmClassName, serializedJavaClass, collector)
}
source?.let { sourceToClassesMap.add(source, jvmClassName) }
if (!icContext.useCompilerMapsOnly) {
addToClassStorage(serializedJavaClass.toProtoData(), source)
// collector.addJavaProto(ClassProtoData(proto, nameResolver))
}
addToClassStorage(serializedJavaClass.toProtoData(), source, icContext.useCompilerMapsOnly)
dirtyOutputClassesMap.notDirty(jvmClassName)
}

Expand Down Expand Up @@ -317,9 +312,8 @@ open class IncrementalJvmCache(
}
}

if (!icContext.useCompilerMapsOnly) {
removeAllFromClassStorage(dirtyClasses.map { it.fqNameForClassNameWithoutDollars }, changesCollector)
}
removeAllFromClassStorage(dirtyClasses.map { it.fqNameForClassNameWithoutDollars }, changesCollector, icContext.useCompilerMapsOnly)

dirtyOutputClassesMap.clean()
}

Expand Down

0 comments on commit 8b47342

Please sign in to comment.