From 9ee7fecdd5892b5f9fac8800e4fa9797516913f3 Mon Sep 17 00:00:00 2001 From: Ivan Kochurkin Date: Mon, 6 Sep 2021 17:12:47 +0300 Subject: [PATCH] [FIR] withSuppressedDiagnostics now takes FirAnnotationContainer instead of FirElement Reduce allocations in withSuppressedDiagnostics --- .../expression/FirClassLiteralChecker.kt | 2 +- .../diagnostics/DiagnosticReporter.kt | 134 +++++++++--------- 2 files changed, 68 insertions(+), 68 deletions(-) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirClassLiteralChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirClassLiteralChecker.kt index ede3083538c..19a92f8595b 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirClassLiteralChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/FirClassLiteralChecker.kt @@ -80,7 +80,7 @@ object FirClassLiteralChecker : FirGetClassCallChecker() { @OptIn(SymbolInternals::class) val typeParameters = (symbol?.fir as? FirTypeParameterRefsOwner)?.typeParameters // Among type parameter references, only count actual type parameter while discarding [FirOuterClassTypeParameterRef] - val expectedTypeArgumentSize = typeParameters?.filterIsInstance()?.size ?: 0 + val expectedTypeArgumentSize = typeParameters?.count { it is FirTypeParameter } ?: 0 if (expectedTypeArgumentSize != argument.typeArguments.size) { // Will be reported as WRONG_NUMBER_OF_TYPE_ARGUMENTS return diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/DiagnosticReporter.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/DiagnosticReporter.kt index ca227578891..8ae0a1f417a 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/DiagnosticReporter.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/DiagnosticReporter.kt @@ -144,12 +144,77 @@ fun FirDiagnosticFactoryForDeprecation.cho } } +fun DiagnosticReporter.reportOnWithSuppression( + element: FirAnnotationContainer, + factory: FirDiagnosticFactory0, + context: CheckerContext, + positioningStrategy: SourceElementPositioningStrategy? = null +) { + withSuppressedDiagnostics(element, context) { + reportOn(element.source, factory, it, positioningStrategy) + } +} + +fun DiagnosticReporter.reportOnWithSuppression( + element: FirAnnotationContainer, + factory: FirDiagnosticFactory1, + a: A, + context: CheckerContext, + positioningStrategy: SourceElementPositioningStrategy? = null +) { + withSuppressedDiagnostics(element, context) { + reportOn(element.source, factory, a, it, positioningStrategy) + } +} + +fun DiagnosticReporter.reportOnWithSuppression( + element: FirAnnotationContainer, + factory: FirDiagnosticFactory2, + a: A, + b: B, + context: CheckerContext, + positioningStrategy: SourceElementPositioningStrategy? = null +) { + withSuppressedDiagnostics(element, context) { + reportOn(element.source, factory, a, b, it, positioningStrategy) + } +} + +fun DiagnosticReporter.reportOnWithSuppression( + element: FirAnnotationContainer, + factory: FirDiagnosticFactory3, + a: A, + b: B, + c: C, + context: CheckerContext, + positioningStrategy: SourceElementPositioningStrategy? = null +) { + withSuppressedDiagnostics(element, context) { + reportOn(element.source, factory, a, b, c, it, positioningStrategy) + } +} + +fun DiagnosticReporter.reportOnWithSuppression( + element: FirAnnotationContainer, + factory: FirDiagnosticFactory4, + a: A, + b: B, + c: C, + d: D, + context: CheckerContext, + positioningStrategy: SourceElementPositioningStrategy? = null +) { + withSuppressedDiagnostics(element, context) { + reportOn(element.source, factory, a, b, c, d, it, positioningStrategy) + } +} + inline fun withSuppressedDiagnostics( - element: FirElement, + annotationContainer: FirAnnotationContainer, context: CheckerContext, f: (CheckerContext) -> Unit ) { - val arguments = (element as? FirAnnotationContainer)?.let { AbstractDiagnosticCollector.getDiagnosticsSuppressedForContainer(it) } + val arguments = AbstractDiagnosticCollector.getDiagnosticsSuppressedForContainer(annotationContainer) if (arguments != null) { f( context.addSuppressedDiagnostics( @@ -164,68 +229,3 @@ inline fun withSuppressedDiagnostics( f(context) } -fun DiagnosticReporter.reportOnWithSuppression( - element: FirElement, - factory: FirDiagnosticFactory0, - context: CheckerContext, - positioningStrategy: SourceElementPositioningStrategy? = null -) { - withSuppressedDiagnostics(element, context) { - reportOn(element.source, factory, it, positioningStrategy) - } -} - -fun DiagnosticReporter.reportOnWithSuppression( - element: FirElement, - factory: FirDiagnosticFactory1, - a: A, - context: CheckerContext, - positioningStrategy: SourceElementPositioningStrategy? = null -) { - withSuppressedDiagnostics(element, context) { - reportOn(element.source, factory, a, it, positioningStrategy) - } -} - -fun DiagnosticReporter.reportOnWithSuppression( - element: FirElement, - factory: FirDiagnosticFactory2, - a: A, - b: B, - context: CheckerContext, - positioningStrategy: SourceElementPositioningStrategy? = null -) { - withSuppressedDiagnostics(element, context) { - reportOn(element.source, factory, a, b, it, positioningStrategy) - } -} - -fun DiagnosticReporter.reportOnWithSuppression( - element: FirElement, - factory: FirDiagnosticFactory3, - a: A, - b: B, - c: C, - context: CheckerContext, - positioningStrategy: SourceElementPositioningStrategy? = null -) { - withSuppressedDiagnostics(element, context) { - reportOn(element.source, factory, a, b, c, it, positioningStrategy) - } -} - -fun DiagnosticReporter.reportOnWithSuppression( - element: FirElement, - factory: FirDiagnosticFactory4, - a: A, - b: B, - c: C, - d: D, - context: CheckerContext, - positioningStrategy: SourceElementPositioningStrategy? = null -) { - withSuppressedDiagnostics(element, context) { - reportOn(element.source, factory, a, b, c, d, it, positioningStrategy) - } -} -