[FIR] Get rid of unnecessary allocations
This commit is contained in:
+2
-1
@@ -40,10 +40,11 @@ object FirRepeatableAnnotationChecker : FirBasicDeclarationChecker() {
|
|||||||
private val REPEATABLE_ANNOTATION_CONTAINER_NAME = Name.identifier(JvmAbi.REPEATABLE_ANNOTATION_CONTAINER_NAME)
|
private val REPEATABLE_ANNOTATION_CONTAINER_NAME = Name.identifier(JvmAbi.REPEATABLE_ANNOTATION_CONTAINER_NAME)
|
||||||
|
|
||||||
override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(declaration: FirDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
|
val annotations = declaration.annotations
|
||||||
|
if (annotations.isEmpty()) return
|
||||||
val annotationsMap = hashMapOf<ConeKotlinType, MutableList<AnnotationUseSiteTarget?>>()
|
val annotationsMap = hashMapOf<ConeKotlinType, MutableList<AnnotationUseSiteTarget?>>()
|
||||||
|
|
||||||
val session = context.session
|
val session = context.session
|
||||||
val annotations = declaration.annotations
|
|
||||||
for (annotation in annotations) {
|
for (annotation in annotations) {
|
||||||
val classId = annotation.classId ?: continue
|
val classId = annotation.classId ?: continue
|
||||||
val annotationClassId = annotation.toAnnotationClassId() ?: continue
|
val annotationClassId = annotation.toAnnotationClassId() ?: continue
|
||||||
|
|||||||
+1
-1
@@ -40,7 +40,7 @@ object FirPropertyInitializationAnalyzer : AbstractFirPropertyInitializationChec
|
|||||||
symbolFir == null || symbolFir.initializer == null && symbolFir.delegate == null
|
symbolFir == null || symbolFir.initializer == null && symbolFir.delegate == null
|
||||||
}
|
}
|
||||||
|
|
||||||
val localProperties = properties.filter { it.fir.initializer == null && it.fir.delegate == null }.toSet()
|
val localProperties = properties.filterTo(mutableSetOf()) { it.fir.initializer == null && it.fir.delegate == null }
|
||||||
|
|
||||||
val reporterVisitor = PropertyReporter(localData, localProperties, capturedWrites, reporter, context)
|
val reporterVisitor = PropertyReporter(localData, localProperties, capturedWrites, reporter, context)
|
||||||
graph.traverse(TraverseDirection.Forward, reporterVisitor)
|
graph.traverse(TraverseDirection.Forward, reporterVisitor)
|
||||||
|
|||||||
+6
-3
@@ -21,9 +21,12 @@ class PropertyInitializationInfoCollector(
|
|||||||
node: CFGNode<*>,
|
node: CFGNode<*>,
|
||||||
data: Collection<Pair<EdgeLabel, PathAwarePropertyInitializationInfo>>
|
data: Collection<Pair<EdgeLabel, PathAwarePropertyInitializationInfo>>
|
||||||
): PathAwarePropertyInitializationInfo {
|
): PathAwarePropertyInitializationInfo {
|
||||||
if (data.isEmpty()) return PathAwarePropertyInitializationInfo.EMPTY
|
var result: PathAwarePropertyInitializationInfo? = null
|
||||||
return data.map { (label, info) -> info.applyLabel(node, label) }
|
for ((label, info) in data) {
|
||||||
.reduce(PathAwarePropertyInitializationInfo::merge)
|
val resultItem = info.applyLabel(node, label)
|
||||||
|
result = result?.merge(resultItem) ?: resultItem
|
||||||
|
}
|
||||||
|
return result ?: PathAwarePropertyInitializationInfo.EMPTY
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitVariableAssignmentNode(
|
override fun visitVariableAssignmentNode(
|
||||||
|
|||||||
+3
-1
@@ -19,7 +19,9 @@ fun checkUnderscoreDiagnostics(
|
|||||||
reporter: DiagnosticReporter,
|
reporter: DiagnosticReporter,
|
||||||
isExpression: Boolean
|
isExpression: Boolean
|
||||||
) {
|
) {
|
||||||
if (source != null && (source.kind is KtRealSourceElementKind || source.kind is KtFakeSourceElementKind.ReferenceInAtomicQualifiedAccess)) {
|
val sourceKind = source?.kind ?: return
|
||||||
|
|
||||||
|
if (sourceKind is KtRealSourceElementKind || sourceKind is KtFakeSourceElementKind.ReferenceInAtomicQualifiedAccess) {
|
||||||
with(SourceNavigator.forSource(source)) {
|
with(SourceNavigator.forSource(source)) {
|
||||||
if (source.getRawIdentifier()?.isUnderscore == true) {
|
if (source.getRawIdentifier()?.isUnderscore == true) {
|
||||||
reporter.reportOn(
|
reporter.reportOn(
|
||||||
|
|||||||
+1
-1
@@ -18,7 +18,7 @@ import org.jetbrains.kotlin.fir.types.type
|
|||||||
object FirPropertyTypeParametersChecker : FirPropertyChecker() {
|
object FirPropertyTypeParametersChecker : FirPropertyChecker() {
|
||||||
|
|
||||||
override fun check(declaration: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) {
|
override fun check(declaration: FirProperty, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||||
val boundsByName = declaration.typeParameters.map { it.name to it.bounds }.toMap()
|
val boundsByName = declaration.typeParameters.associate { it.name to it.bounds }
|
||||||
val usedTypes = HashSet<ConeKotlinType>()
|
val usedTypes = HashSet<ConeKotlinType>()
|
||||||
fun collectAllTypes(type: ConeKotlinType) {
|
fun collectAllTypes(type: ConeKotlinType) {
|
||||||
if (usedTypes.add(type)) {
|
if (usedTypes.add(type)) {
|
||||||
|
|||||||
+4
-1
@@ -32,9 +32,12 @@ object FirExpressionAnnotationChecker : FirBasicExpressionChecker() {
|
|||||||
expression is FirBlock && expression.source?.kind == KtFakeSourceElementKind.DesugaredForLoop
|
expression is FirBlock && expression.source?.kind == KtFakeSourceElementKind.DesugaredForLoop
|
||||||
) return
|
) return
|
||||||
|
|
||||||
|
val annotations = expression.annotations
|
||||||
|
if (annotations.isEmpty()) return
|
||||||
|
|
||||||
val annotationsMap = hashMapOf<ConeKotlinType, MutableList<AnnotationUseSiteTarget?>>()
|
val annotationsMap = hashMapOf<ConeKotlinType, MutableList<AnnotationUseSiteTarget?>>()
|
||||||
|
|
||||||
for (annotation in expression.annotations) {
|
for (annotation in annotations) {
|
||||||
val useSiteTarget = annotation.useSiteTarget ?: expression.getDefaultUseSiteTarget(annotation, context)
|
val useSiteTarget = annotation.useSiteTarget ?: expression.getDefaultUseSiteTarget(annotation, context)
|
||||||
val existingTargetsForAnnotation = annotationsMap.getOrPut(annotation.annotationTypeRef.coneType) { arrayListOf() }
|
val existingTargetsForAnnotation = annotationsMap.getOrPut(annotation.annotationTypeRef.coneType) { arrayListOf() }
|
||||||
|
|
||||||
|
|||||||
+4
-2
@@ -29,8 +29,10 @@ object FirUnderscoreChecker : FirBasicExpressionChecker() {
|
|||||||
checkResolvedToUnderscoreNamedCatchParameter(expression, context, reporter)
|
checkResolvedToUnderscoreNamedCatchParameter(expression, context, reporter)
|
||||||
}
|
}
|
||||||
is FirResolvedQualifier -> {
|
is FirResolvedQualifier -> {
|
||||||
for (reservedUnderscoreDiagnostic in expression.nonFatalDiagnostics.filterIsInstance<ConeUnderscoreUsageWithoutBackticks>()) {
|
for (reservedUnderscoreDiagnostic in expression.nonFatalDiagnostics) {
|
||||||
reporter.reportOn(reservedUnderscoreDiagnostic.source, FirErrors.UNDERSCORE_USAGE_WITHOUT_BACKTICKS, context)
|
if (reservedUnderscoreDiagnostic is ConeUnderscoreUsageWithoutBackticks) {
|
||||||
|
reporter.reportOn(reservedUnderscoreDiagnostic.source, FirErrors.UNDERSCORE_USAGE_WITHOUT_BACKTICKS, context)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+17
-9
@@ -41,16 +41,24 @@ abstract class AbstractDiagnosticCollector(
|
|||||||
private val SUPPRESS_NAMES_NAME = Name.identifier("names")
|
private val SUPPRESS_NAMES_NAME = Name.identifier("names")
|
||||||
|
|
||||||
fun getDiagnosticsSuppressedForContainer(annotationContainer: FirAnnotationContainer): List<String>? {
|
fun getDiagnosticsSuppressedForContainer(annotationContainer: FirAnnotationContainer): List<String>? {
|
||||||
val annotations = annotationContainer.annotations.filter {
|
var result: MutableList<String>? = null
|
||||||
val type = it.annotationTypeRef.coneType as? ConeClassLikeType ?: return@filter false
|
|
||||||
type.lookupTag.classId == StandardClassIds.Annotations.Suppress
|
for (annotation in annotationContainer.annotations) {
|
||||||
}
|
val type = annotation.annotationTypeRef.coneType as? ConeClassLikeType ?: continue
|
||||||
if (annotations.isEmpty()) return null
|
if (type.lookupTag.classId != StandardClassIds.Annotations.Suppress) continue
|
||||||
return annotations.flatMap { annotationCall ->
|
val argumentValues = annotation.findArgumentByName(SUPPRESS_NAMES_NAME)?.unwrapVarargValue() ?: continue
|
||||||
annotationCall.findArgumentByName(SUPPRESS_NAMES_NAME)?.unwrapVarargValue()?.mapNotNull {
|
|
||||||
(it as? FirConstExpression<*>)?.value as? String?
|
for (argumentValue in argumentValues) {
|
||||||
} ?: emptyList()
|
val value = (argumentValue as? FirConstExpression<*>)?.value as? String ?: continue
|
||||||
|
|
||||||
|
if (result == null) {
|
||||||
|
result = mutableListOf()
|
||||||
|
}
|
||||||
|
result.add(value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-6
@@ -24,7 +24,7 @@ class JavaClassMembersEnhancementScope(
|
|||||||
private val overriddenFunctions = mutableMapOf<FirNamedFunctionSymbol, Collection<FirNamedFunctionSymbol>>()
|
private val overriddenFunctions = mutableMapOf<FirNamedFunctionSymbol, Collection<FirNamedFunctionSymbol>>()
|
||||||
private val overriddenProperties = mutableMapOf<FirPropertySymbol, Collection<FirPropertySymbol>>()
|
private val overriddenProperties = mutableMapOf<FirPropertySymbol, Collection<FirPropertySymbol>>()
|
||||||
|
|
||||||
private val overrideBindCache = mutableMapOf<Name, Map<FirCallableSymbol<*>?, List<FirCallableSymbol<*>>>>()
|
private val overrideBindCache = mutableMapOf<Name, Map<FirCallableSymbol<*>?, List<FirCallableDeclaration>>>()
|
||||||
private val signatureEnhancement = FirSignatureEnhancement(owner.fir, session) {
|
private val signatureEnhancement = FirSignatureEnhancement(owner.fir, session) {
|
||||||
overriddenMembers(name)
|
overriddenMembers(name)
|
||||||
}
|
}
|
||||||
@@ -66,12 +66,14 @@ class JavaClassMembersEnhancementScope(
|
|||||||
|
|
||||||
private fun FirCallableDeclaration.overriddenMembers(name: Name): List<FirCallableDeclaration> {
|
private fun FirCallableDeclaration.overriddenMembers(name: Name): List<FirCallableDeclaration> {
|
||||||
val backMap = overrideBindCache.getOrPut(name) {
|
val backMap = overrideBindCache.getOrPut(name) {
|
||||||
useSiteMemberScope
|
val result = mutableMapOf<FirCallableSymbol<*>?, MutableList<FirCallableDeclaration>>()
|
||||||
.overrideByBase
|
for ((key, value) in useSiteMemberScope.overrideByBase) {
|
||||||
.toList()
|
val resultItem = result.getOrPut(value) { mutableListOf() }
|
||||||
.groupBy({ (_, key) -> key }, { (value) -> value })
|
resultItem.add(key.fir)
|
||||||
|
}
|
||||||
|
result
|
||||||
}
|
}
|
||||||
return backMap[this.symbol]?.map { it.fir } ?: emptyList()
|
return backMap[this.symbol] ?: emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processClassifiersByNameWithSubstitution(name: Name, processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit) {
|
override fun processClassifiersByNameWithSubstitution(name: Name, processor: (FirClassifierSymbol<*>, ConeSubstitutor) -> Unit) {
|
||||||
|
|||||||
Reference in New Issue
Block a user