[JPS] Improve JPS dumb mode

For the correct work of the compiler, some maps should be fulfilled by the build system. In the first implementation of dumb mode for JPS all maps were disabled. Now flag was introduced to determine IC behavior: to collect data needed for the compiler's code generation and disable maps and IC analysis

^KT-65043 Fixed
This commit is contained in:
Aleksei.Cherepanov
2024-01-15 17:51:23 +01:00
committed by Space Team
parent 32bc2b55ed
commit 1e7e42baf2
6 changed files with 60 additions and 34 deletions
@@ -49,7 +49,7 @@ interface IncrementalCacheCommon {
*/
abstract class AbstractIncrementalCache<ClassName>(
workingDir: File,
icContext: IncrementalCompilationContext,
val icContext: IncrementalCompilationContext,
) : BasicMapsOwner(workingDir), IncrementalCacheCommon {
companion object {
private const val CLASS_ATTRIBUTES = "class-attributes"
@@ -229,6 +229,8 @@ abstract class AbstractIncrementalCache<ClassName>(
}
override fun updateComplementaryFiles(dirtyFiles: Collection<File>, expectActualTracker: ExpectActualTrackerImpl) {
if (icContext.useCompilerMapsOnly && this is IncrementalJvmCache) return
dirtyFiles.forEach {
complementaryFilesMap.remove(it)
}
@@ -25,6 +25,7 @@ class IncrementalCompilationContext(
val trackChangesInLookupCache: Boolean = false,
val icFeatures: IncrementalCompilationFeatures = IncrementalCompilationFeatures.DEFAULT_CONFIGURATION,
val fragmentContext: FragmentContext? = null,
val useCompilerMapsOnly: Boolean = false
) {
@Deprecated("This constructor is scheduled to be removed. KSP is using it")
constructor(
@@ -41,7 +41,7 @@ import java.io.File
open class IncrementalJsCache(
cachesDir: File,
private val icContext: IncrementalCompilationContext,
icContext: IncrementalCompilationContext,
serializerProtocol: SerializerExtensionProtocol,
) : AbstractIncrementalCache<FqName>(cachesDir, icContext) {
companion object {
@@ -129,7 +129,7 @@ open class IncrementalJvmCache(
sourceFiles.forEach {
sourceToClassesMap.append(it, className)
}
internalNameToSource[className.internalName] = sourceFiles
if (!icContext.useCompilerMapsOnly) internalNameToSource[className.internalName] = sourceFiles
}
if (kotlinClassInfo.classId.isLocal) return
@@ -142,8 +142,10 @@ open class IncrementalJvmCache(
packagePartMap.addPackagePart(className)
protoMap.process(kotlinClassInfo, changesCollector)
constantsMap.process(kotlinClassInfo, changesCollector)
inlineFunctionsMap.process(kotlinClassInfo, changesCollector)
if (!icContext.useCompilerMapsOnly) {
constantsMap.process(kotlinClassInfo, changesCollector)
inlineFunctionsMap.process(kotlinClassInfo, changesCollector)
}
}
KotlinClassHeader.Kind.MULTIFILE_CLASS -> {
val partNames = kotlinClassInfo.classHeaderData.toList()
@@ -158,12 +160,15 @@ open class IncrementalJvmCache(
}
protoMap.remove(className, changesCollector)
classFqNameToSourceMap.remove(className.fqNameForClassNameWithoutDollars)
classAttributesMap.remove(className.fqNameForClassNameWithoutDollars)
internalNameToSource.remove(className.internalName)
if (!icContext.useCompilerMapsOnly) {
// TODO NO_CHANGES? (delegates only)
constantsMap.process(kotlinClassInfo, changesCollector)
inlineFunctionsMap.process(kotlinClassInfo, changesCollector)
classAttributesMap.remove(className.fqNameForClassNameWithoutDollars)
internalNameToSource.remove(className.internalName)
// TODO NO_CHANGES? (delegates only)
constantsMap.process(kotlinClassInfo, changesCollector)
inlineFunctionsMap.process(kotlinClassInfo, changesCollector)
}
}
KotlinClassHeader.Kind.MULTIFILE_CLASS_PART -> {
if (sourceFiles != null) {
@@ -171,17 +176,23 @@ open class IncrementalJvmCache(
}
packagePartMap.addPackagePart(className)
partToMultifileFacade[className] = kotlinClassInfo.multifileClassName!!
protoMap.process(kotlinClassInfo, changesCollector)
constantsMap.process(kotlinClassInfo, changesCollector)
inlineFunctionsMap.process(kotlinClassInfo, changesCollector)
if (!icContext.useCompilerMapsOnly) {
constantsMap.process(kotlinClassInfo, changesCollector)
inlineFunctionsMap.process(kotlinClassInfo, changesCollector)
}
}
KotlinClassHeader.Kind.CLASS -> {
addToClassStorage(kotlinClassInfo.protoData as ClassProtoData, sourceFiles?.let { sourceFiles.single() })
if (!icContext.useCompilerMapsOnly) {
addToClassStorage(kotlinClassInfo.protoData as ClassProtoData, sourceFiles?.let { sourceFiles.single() })
}
protoMap.process(kotlinClassInfo, changesCollector)
constantsMap.process(kotlinClassInfo, changesCollector)
inlineFunctionsMap.process(kotlinClassInfo, changesCollector)
if (!icContext.useCompilerMapsOnly) {
constantsMap.process(kotlinClassInfo, changesCollector)
inlineFunctionsMap.process(kotlinClassInfo, changesCollector)
}
}
KotlinClassHeader.Kind.UNKNOWN, KotlinClassHeader.Kind.SYNTHETIC_CLASS -> {
}
@@ -228,10 +239,15 @@ open class IncrementalJvmCache(
fun saveJavaClassProto(source: File?, serializedJavaClass: SerializedJavaClass, collector: ChangesCollector) {
val jvmClassName = JvmClassName.byClassId(serializedJavaClass.classId)
javaSourcesProtoMap.process(jvmClassName, serializedJavaClass, collector)
if (!icContext.useCompilerMapsOnly) {
javaSourcesProtoMap.process(jvmClassName, serializedJavaClass, collector)
}
source?.let { sourceToClassesMap.append(source, jvmClassName) }
addToClassStorage(serializedJavaClass.toProtoData(), source)
if (!icContext.useCompilerMapsOnly) {
addToClassStorage(serializedJavaClass.toProtoData(), source)
// collector.addJavaProto(ClassProtoData(proto, nameResolver))
}
dirtyOutputClassesMap.notDirty(jvmClassName)
}
@@ -280,13 +296,17 @@ open class IncrementalJvmCache(
packagePartMap.remove(it)
multifileFacadeToParts.remove(it)
partToMultifileFacade.remove(it)
constantsMap.remove(it)
inlineFunctionsMap.remove(it)
internalNameToSource.remove(it.internalName)
javaSourcesProtoMap.remove(it, changesCollector)
if (!icContext.useCompilerMapsOnly) {
constantsMap.remove(it)
inlineFunctionsMap.remove(it)
internalNameToSource.remove(it.internalName)
javaSourcesProtoMap.remove(it, changesCollector)
}
}
removeAllFromClassStorage(dirtyClasses.map { it.fqNameForClassNameWithoutDollars }, changesCollector)
if (!icContext.useCompilerMapsOnly) {
removeAllFromClassStorage(dirtyClasses.map { it.fqNameForClassNameWithoutDollars }, changesCollector)
}
dirtyOutputClassesMap.clear()
}
@@ -499,7 +499,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
val generatedFiles = getGeneratedFiles(context, chunk, environment.outputItemsCollector)
markDirtyComplementaryMultifileClasses(generatedFiles, kotlinContext, incrementalCaches, fsOperations)
if (!isKotlinBuilderInDumbMode) markDirtyComplementaryMultifileClasses(generatedFiles, kotlinContext, incrementalCaches, fsOperations)
val kotlinTargets = kotlinContext.targetsBinding
for ((target, outputItems) in generatedFiles) {
@@ -530,7 +530,7 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
environment
)
if (isKotlinBuilderInDumbMode || !representativeTarget.isIncrementalCompilationEnabled) {
if (!representativeTarget.isIncrementalCompilationEnabled) {
return OK
}
@@ -552,15 +552,17 @@ class KotlinBuilder : ModuleLevelBuilder(BuilderCategory.SOURCE_PROCESSOR) {
)
}
updateLookupStorage(lookupTracker, kotlinContext.lookupStorageManager, kotlinDirtyFilesHolder)
if (!isKotlinBuilderInDumbMode) {
updateLookupStorage(lookupTracker, kotlinContext.lookupStorageManager, kotlinDirtyFilesHolder)
if (!isChunkRebuilding) {
changesCollector.processChangesUsingLookups(
kotlinDirtyFilesHolder.allDirtyFiles,
kotlinContext.lookupStorageManager,
fsOperations,
incrementalCaches.values
)
if (!isChunkRebuilding) {
changesCollector.processChangesUsingLookups(
kotlinDirtyFilesHolder.allDirtyFiles,
kotlinContext.lookupStorageManager,
fsOperations,
incrementalCaches.values
)
}
}
}
@@ -84,7 +84,8 @@ class KotlinCompileContext(val jpsContext: CompileContext) {
val icContext = IncrementalCompilationContext(
pathConverterForSourceFiles = fileToPathConverter,
pathConverterForOutputFiles = fileToPathConverter
pathConverterForOutputFiles = fileToPathConverter,
useCompilerMapsOnly = KotlinBuilder.isKotlinBuilderInDumbMode
)
val lookupStorageManager = JpsLookupStorageManager(dataManager, icContext)