KT-45777: Keep only package facades whose members are looked up

to reduce the size of the shrunk classpath snapshot further.
This commit is contained in:
Hung Nguyen
2021-12-20 09:37:23 +00:00
committed by nataliya.valtman
parent a6b5339980
commit 78f10d9142
10 changed files with 193 additions and 89 deletions
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.incremental
import org.jetbrains.kotlin.metadata.ProtoBuf
import org.jetbrains.kotlin.metadata.deserialization.Flags
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
import org.jetbrains.kotlin.metadata.deserialization.supertypes
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.protobuf.MessageLite
import org.jetbrains.kotlin.serialization.deserialization.getClassId
@@ -45,11 +44,23 @@ class ChangesCollector {
fun ClassProtoData.getNonPrivateMemberNames(): Set<String> {
return proto.getNonPrivateNames(
nameResolver,
// The types below should match the logic at `DifferenceCalculatorForClass.difference`
ProtoBuf.Class::getConstructorList,
ProtoBuf.Class::getFunctionList,
ProtoBuf.Class::getPropertyList
ProtoBuf.Class::getPropertyList,
ProtoBuf.Class::getTypeAliasList
) + proto.enumEntryList.map { nameResolver.getString(it.name) }
}
fun PackagePartProtoData.getNonPrivateMemberNames(): Set<String> {
return proto.getNonPrivateNames(
nameResolver,
// The types below should match the logic at `DifferenceCalculatorForPackageFacade.difference`
ProtoBuf.Package::getFunctionList,
ProtoBuf.Package::getPropertyList,
ProtoBuf.Package::getTypeAliasList
)
}
}
fun changes(): List<ChangeInfo> {
@@ -182,13 +193,7 @@ class ChangesCollector {
}
private fun PackagePartProtoData.collectAllFromPackage(isRemoved: Boolean) {
val memberNames =
proto.getNonPrivateNames(
nameResolver,
ProtoBuf.Package::getFunctionList,
ProtoBuf.Package::getPropertyList
)
val memberNames = getNonPrivateMemberNames()
if (isRemoved) {
collectRemovedMembers(packageFqName, memberNames)
} else {
@@ -612,7 +612,7 @@ class KotlinClassInfo constructor(
val classKind: KotlinClassHeader.Kind,
val classHeaderData: Array<String>, // Can be empty
val classHeaderStrings: Array<String>, // Can be empty
val multifileClassName: String?,
val multifileClassName: String?, // Not null iff classKind == KotlinClassHeader.Kind.MULTIFILE_CLASS_PART
val constantsMap: LinkedHashMap<String, Any>,
val inlineFunctionsMap: LinkedHashMap<String, Long>
) {
@@ -637,7 +637,7 @@ class KotlinClassInfo constructor(
check(classKind != KotlinClassHeader.Kind.MULTIFILE_CLASS) {
"Proto data is not available for KotlinClassHeader.Kind.MULTIFILE_CLASS: $classId"
}
protoMapValue.toProtoData(className.packageFqName)
protoMapValue.toProtoData(classId.packageFqName)
}
companion object {
@@ -698,7 +698,7 @@ private class ConstantsClassVisitor : ClassVisitor(Opcodes.API_VERSION) {
private class InlineFunctionsClassVisitor(
private val inlineFunctionNames: Set<String>,
cv: ClassVisitor // Note: cv must not override the visitMethod (it will not be called with the current implementation below)
cv: ConstantsClassVisitor // Note: cv must not override the visitMethod (it will not be called with the current implementation below)
) : ClassVisitor(Opcodes.API_VERSION, cv) {
private val result = LinkedHashMap<String, Long>()