Skip to content

Commit a78022c

Browse files
pyosmglukhikh
authored andcommitted
FIR: remove property delegation in generated error lists
The point of using delegated properties is to avoid duplicating the name of the diagnostic by using `KProperty.name`, but this is meaningless when the code is automatically generated in the first place. Generating the entire call significantly reduces the size of the class initializer. For example, FirErrors was over 420 KB with a 58 KB `<clinit>` (dangerously close to JVM's 64 KiB limit); now it's only 225 KB with a 22 KB `<clinit>`. Another option is to finally implement more delegated property optimizations - see KT-16997 - but that'll take a while, and changing the code generator is easy anyway. ^KT-68829 (cherry picked from commit f83f0e3)
1 parent 0d72352 commit a78022c

File tree

10 files changed

+983
-966
lines changed

10 files changed

+983
-966
lines changed

compiler/fir/checkers/checkers-component-generator/src/org/jetbrains/kotlin/fir/checkers/generator/diagnostics/model/ErrorListDiagnosticListRenderer.kt

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -68,30 +68,21 @@ object ErrorListDiagnosticListRenderer : DiagnosticListRenderer() {
6868
}
6969

7070
private fun SmartPrinter.printDiagnostic(diagnostic: DiagnosticData) {
71-
print("val ${diagnostic.name}: ${diagnostic.getPropertType()}")
72-
diagnostic.parameters.map { it.type }.ifNotEmpty { printTypeArguments(this) }
73-
print(" by ${diagnostic.getFactoryFunction()}")
74-
printTypeArguments(diagnostic.getAllTypeArguments())
75-
printPositioningStrategyAndLanguageFeature(diagnostic)
76-
println()
77-
}
78-
79-
private fun SmartPrinter.printPositioningStrategyAndLanguageFeature(diagnostic: DiagnosticData) {
80-
val argumentsList = buildList {
81-
if (diagnostic is DeprecationDiagnosticData) {
82-
add(diagnostic.featureForError.name)
83-
}
84-
if (!diagnostic.hasDefaultPositioningStrategy()) {
85-
add(diagnostic.positioningStrategy.expressionToCreate)
86-
}
71+
val type = diagnostic.getProperType()
72+
val escapedName = "\"${diagnostic.name}\""
73+
val severityOrFeatureForError = when (diagnostic) {
74+
is RegularDiagnosticData -> diagnostic.severity.name
75+
is DeprecationDiagnosticData -> diagnostic.featureForError.name
8776
}
88-
print(argumentsList.joinToString(", ", prefix = "(", postfix = ")"))
89-
}
77+
val positioningStrategy = diagnostic.positioningStrategy.expressionToCreate
78+
val psiTypeClass = "${diagnostic.psiType.kClass.simpleName!!}::class"
9079

91-
92-
private fun DiagnosticData.getAllTypeArguments(): List<KType> = buildList {
93-
add(psiType)
94-
parameters.mapTo(this) { it.type }
80+
print("val ${diagnostic.name}: $type")
81+
diagnostic.parameters.map { it.type }.ifNotEmpty { printTypeArguments(this) }
82+
print(" = $type(")
83+
printSeparatedWithComma(listOf(escapedName, severityOrFeatureForError, positioningStrategy, psiTypeClass)) { print(it) }
84+
print(")")
85+
println()
9586
}
9687

9788
private fun SmartPrinter.printTypeArguments(typeArguments: List<KType>) {
@@ -146,31 +137,29 @@ object ErrorListDiagnosticListRenderer : DiagnosticListRenderer() {
146137
add("$starImport.*")
147138
}
148139
}
140+
149141
diagnosticList.allDiagnostics.forEach { diagnostic ->
150-
for (typeArgument in diagnostic.getAllTypeArguments()) {
151-
typeArgument.collectClassNamesTo(this)
142+
diagnostic.psiType.collectClassNamesTo(this)
143+
for (parameter in diagnostic.parameters) {
144+
parameter.type.collectClassNamesTo(this)
152145
}
153-
if (!diagnostic.hasDefaultPositioningStrategy()) {
154-
add(PositioningStrategy.importToAdd)
146+
add("org.jetbrains.kotlin.diagnostics." + diagnostic.getProperType())
147+
when (diagnostic) {
148+
is RegularDiagnosticData ->
149+
add("org.jetbrains.kotlin.diagnostics.Severity.${diagnostic.severity.name}")
150+
is DeprecationDiagnosticData ->
151+
add("org.jetbrains.kotlin.config.LanguageFeature.${diagnostic.featureForError.name}")
155152
}
156-
add("org.jetbrains.kotlin.diagnostics." + diagnostic.getPropertType())
157-
}
158-
for (deprecationDiagnostic in diagnosticList.allDiagnostics.filterIsInstance<DeprecationDiagnosticData>()) {
159-
add("org.jetbrains.kotlin.config.LanguageFeature.${deprecationDiagnostic.featureForError.name}")
160153
}
154+
add(PositioningStrategy.importToAdd)
161155
add("org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory")
162156
}
163157

164158

165159
private val KType.kClass: KClass<*>
166160
get() = classifier as KClass<*>
167161

168-
private fun DiagnosticData.getFactoryFunction(): String = when (this) {
169-
is RegularDiagnosticData -> severity.name.lowercase()
170-
is DeprecationDiagnosticData -> "deprecationError"
171-
} + parameters.size
172-
173-
private fun DiagnosticData.getPropertType(): String = when (this) {
162+
private fun DiagnosticData.getProperType(): String = when (this) {
174163
is RegularDiagnosticData -> "KtDiagnosticFactory"
175164
is DeprecationDiagnosticData -> "KtDiagnosticFactoryForDeprecation"
176165
} + parameters.size

compiler/fir/checkers/checkers.js/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/js/FirJsErrors.kt

Lines changed: 48 additions & 46 deletions
Large diffs are not rendered by default.

compiler/fir/checkers/checkers.jvm/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/jvm/FirJvmErrors.kt

Lines changed: 81 additions & 79 deletions
Large diffs are not rendered by default.

compiler/fir/checkers/checkers.native/gen/org/jetbrains/kotlin/fir/analysis/diagnostics/native/FirNativeErrors.kt

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactory0
1212
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactory1
1313
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactory2
1414
import org.jetbrains.kotlin.diagnostics.KtDiagnosticFactoryForDeprecation1
15+
import org.jetbrains.kotlin.diagnostics.Severity.ERROR
16+
import org.jetbrains.kotlin.diagnostics.Severity.WARNING
1517
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies
1618
import org.jetbrains.kotlin.diagnostics.rendering.RootDiagnosticRendererFactory
1719
import org.jetbrains.kotlin.fir.analysis.diagnostics.*
@@ -27,43 +29,43 @@ import org.jetbrains.kotlin.psi.KtElement
2729
*/
2830
object FirNativeErrors {
2931
// All
30-
val THROWS_LIST_EMPTY: KtDiagnosticFactory0 by error0<KtElement>()
31-
val INCOMPATIBLE_THROWS_OVERRIDE: KtDiagnosticFactory1<FirRegularClassSymbol> by error1<KtElement, FirRegularClassSymbol>()
32-
val INCOMPATIBLE_THROWS_INHERITED: KtDiagnosticFactory1<Collection<FirRegularClassSymbol>> by error1<KtDeclaration, Collection<FirRegularClassSymbol>>()
33-
val MISSING_EXCEPTION_IN_THROWS_ON_SUSPEND: KtDiagnosticFactory1<FqName> by error1<KtElement, FqName>()
34-
val INAPPLICABLE_SHARED_IMMUTABLE_PROPERTY: KtDiagnosticFactory0 by error0<KtElement>()
35-
val INAPPLICABLE_SHARED_IMMUTABLE_TOP_LEVEL: KtDiagnosticFactory0 by error0<KtElement>()
36-
val INAPPLICABLE_THREAD_LOCAL: KtDiagnosticFactory0 by error0<KtElement>()
37-
val INAPPLICABLE_THREAD_LOCAL_TOP_LEVEL: KtDiagnosticFactory0 by error0<KtElement>()
38-
val INVALID_CHARACTERS_NATIVE: KtDiagnosticFactoryForDeprecation1<String> by deprecationError1<PsiElement, String>(ProhibitInvalidCharsInNativeIdentifiers, SourceElementPositioningStrategies.NAME_IDENTIFIER)
39-
val REDUNDANT_SWIFT_REFINEMENT: KtDiagnosticFactory0 by error0<KtElement>()
40-
val INCOMPATIBLE_OBJC_REFINEMENT_OVERRIDE: KtDiagnosticFactory2<FirBasedSymbol<*>, Collection<FirRegularClassSymbol>> by error2<KtElement, FirBasedSymbol<*>, Collection<FirRegularClassSymbol>>()
41-
val INAPPLICABLE_OBJC_NAME: KtDiagnosticFactory0 by error0<KtElement>()
42-
val INVALID_OBJC_NAME: KtDiagnosticFactory0 by error0<KtElement>()
43-
val INVALID_OBJC_NAME_CHARS: KtDiagnosticFactory1<String> by error1<KtElement, String>()
44-
val INVALID_OBJC_NAME_FIRST_CHAR: KtDiagnosticFactory1<String> by error1<KtElement, String>()
45-
val EMPTY_OBJC_NAME: KtDiagnosticFactory0 by error0<KtElement>()
46-
val INCOMPATIBLE_OBJC_NAME_OVERRIDE: KtDiagnosticFactory2<FirBasedSymbol<*>, Collection<FirRegularClassSymbol>> by error2<KtElement, FirBasedSymbol<*>, Collection<FirRegularClassSymbol>>()
47-
val INAPPLICABLE_EXACT_OBJC_NAME: KtDiagnosticFactory0 by error0<KtElement>()
48-
val MISSING_EXACT_OBJC_NAME: KtDiagnosticFactory0 by error0<KtElement>()
49-
val NON_LITERAL_OBJC_NAME_ARG: KtDiagnosticFactory0 by error0<KtElement>()
50-
val INVALID_OBJC_HIDES_TARGETS: KtDiagnosticFactory0 by error0<KtElement>()
51-
val INVALID_REFINES_IN_SWIFT_TARGETS: KtDiagnosticFactory0 by error0<KtElement>()
52-
val SUBTYPE_OF_HIDDEN_FROM_OBJC: KtDiagnosticFactory0 by error0<KtElement>()
53-
val CANNOT_CHECK_FOR_FORWARD_DECLARATION: KtDiagnosticFactory1<ConeKotlinType> by error1<KtElement, ConeKotlinType>()
54-
val UNCHECKED_CAST_TO_FORWARD_DECLARATION: KtDiagnosticFactory2<ConeKotlinType, ConeKotlinType> by warning2<KtElement, ConeKotlinType, ConeKotlinType>()
55-
val FORWARD_DECLARATION_AS_REIFIED_TYPE_ARGUMENT: KtDiagnosticFactory1<ConeKotlinType> by error1<KtElement, ConeKotlinType>()
56-
val FORWARD_DECLARATION_AS_CLASS_LITERAL: KtDiagnosticFactory1<ConeKotlinType> by error1<KtElement, ConeKotlinType>()
57-
val TWO_OR_LESS_PARAMETERS_ARE_SUPPORTED_HERE: KtDiagnosticFactory0 by error0<KtElement>()
58-
val PROPERTY_MUST_BE_VAR: KtDiagnosticFactory1<FqName> by error1<KtElement, FqName>()
59-
val MUST_NOT_HAVE_EXTENSION_RECEIVER: KtDiagnosticFactory1<String> by error1<KtElement, String>()
60-
val MUST_BE_OBJC_OBJECT_TYPE: KtDiagnosticFactory2<String, ConeKotlinType> by error2<KtElement, String, ConeKotlinType>()
61-
val MUST_BE_UNIT_TYPE: KtDiagnosticFactory2<String, ConeKotlinType> by error2<KtElement, String, ConeKotlinType>()
62-
val CONSTRUCTOR_OVERRIDES_ALREADY_OVERRIDDEN_OBJC_INITIALIZER: KtDiagnosticFactory1<FqName> by error1<KtElement, FqName>()
63-
val CONSTRUCTOR_DOES_NOT_OVERRIDE_ANY_SUPER_CONSTRUCTOR: KtDiagnosticFactory1<FqName> by error1<KtElement, FqName>()
64-
val CONSTRUCTOR_MATCHES_SEVERAL_SUPER_CONSTRUCTORS: KtDiagnosticFactory1<FqName> by error1<KtElement, FqName>()
65-
val CONFLICTING_OBJC_OVERLOADS: KtDiagnosticFactory1<Collection<FirBasedSymbol<*>>> by error1<PsiElement, Collection<FirBasedSymbol<*>>>()
66-
val INAPPLICABLE_OBJC_OVERRIDE: KtDiagnosticFactory0 by error0<PsiElement>()
32+
val THROWS_LIST_EMPTY: KtDiagnosticFactory0 = KtDiagnosticFactory0("THROWS_LIST_EMPTY", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
33+
val INCOMPATIBLE_THROWS_OVERRIDE: KtDiagnosticFactory1<FirRegularClassSymbol> = KtDiagnosticFactory1("INCOMPATIBLE_THROWS_OVERRIDE", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
34+
val INCOMPATIBLE_THROWS_INHERITED: KtDiagnosticFactory1<Collection<FirRegularClassSymbol>> = KtDiagnosticFactory1("INCOMPATIBLE_THROWS_INHERITED", ERROR, SourceElementPositioningStrategies.DEFAULT, KtDeclaration::class)
35+
val MISSING_EXCEPTION_IN_THROWS_ON_SUSPEND: KtDiagnosticFactory1<FqName> = KtDiagnosticFactory1("MISSING_EXCEPTION_IN_THROWS_ON_SUSPEND", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
36+
val INAPPLICABLE_SHARED_IMMUTABLE_PROPERTY: KtDiagnosticFactory0 = KtDiagnosticFactory0("INAPPLICABLE_SHARED_IMMUTABLE_PROPERTY", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
37+
val INAPPLICABLE_SHARED_IMMUTABLE_TOP_LEVEL: KtDiagnosticFactory0 = KtDiagnosticFactory0("INAPPLICABLE_SHARED_IMMUTABLE_TOP_LEVEL", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
38+
val INAPPLICABLE_THREAD_LOCAL: KtDiagnosticFactory0 = KtDiagnosticFactory0("INAPPLICABLE_THREAD_LOCAL", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
39+
val INAPPLICABLE_THREAD_LOCAL_TOP_LEVEL: KtDiagnosticFactory0 = KtDiagnosticFactory0("INAPPLICABLE_THREAD_LOCAL_TOP_LEVEL", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
40+
val INVALID_CHARACTERS_NATIVE: KtDiagnosticFactoryForDeprecation1<String> = KtDiagnosticFactoryForDeprecation1("INVALID_CHARACTERS_NATIVE", ProhibitInvalidCharsInNativeIdentifiers, SourceElementPositioningStrategies.NAME_IDENTIFIER, PsiElement::class)
41+
val REDUNDANT_SWIFT_REFINEMENT: KtDiagnosticFactory0 = KtDiagnosticFactory0("REDUNDANT_SWIFT_REFINEMENT", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
42+
val INCOMPATIBLE_OBJC_REFINEMENT_OVERRIDE: KtDiagnosticFactory2<FirBasedSymbol<*>, Collection<FirRegularClassSymbol>> = KtDiagnosticFactory2("INCOMPATIBLE_OBJC_REFINEMENT_OVERRIDE", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
43+
val INAPPLICABLE_OBJC_NAME: KtDiagnosticFactory0 = KtDiagnosticFactory0("INAPPLICABLE_OBJC_NAME", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
44+
val INVALID_OBJC_NAME: KtDiagnosticFactory0 = KtDiagnosticFactory0("INVALID_OBJC_NAME", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
45+
val INVALID_OBJC_NAME_CHARS: KtDiagnosticFactory1<String> = KtDiagnosticFactory1("INVALID_OBJC_NAME_CHARS", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
46+
val INVALID_OBJC_NAME_FIRST_CHAR: KtDiagnosticFactory1<String> = KtDiagnosticFactory1("INVALID_OBJC_NAME_FIRST_CHAR", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
47+
val EMPTY_OBJC_NAME: KtDiagnosticFactory0 = KtDiagnosticFactory0("EMPTY_OBJC_NAME", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
48+
val INCOMPATIBLE_OBJC_NAME_OVERRIDE: KtDiagnosticFactory2<FirBasedSymbol<*>, Collection<FirRegularClassSymbol>> = KtDiagnosticFactory2("INCOMPATIBLE_OBJC_NAME_OVERRIDE", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
49+
val INAPPLICABLE_EXACT_OBJC_NAME: KtDiagnosticFactory0 = KtDiagnosticFactory0("INAPPLICABLE_EXACT_OBJC_NAME", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
50+
val MISSING_EXACT_OBJC_NAME: KtDiagnosticFactory0 = KtDiagnosticFactory0("MISSING_EXACT_OBJC_NAME", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
51+
val NON_LITERAL_OBJC_NAME_ARG: KtDiagnosticFactory0 = KtDiagnosticFactory0("NON_LITERAL_OBJC_NAME_ARG", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
52+
val INVALID_OBJC_HIDES_TARGETS: KtDiagnosticFactory0 = KtDiagnosticFactory0("INVALID_OBJC_HIDES_TARGETS", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
53+
val INVALID_REFINES_IN_SWIFT_TARGETS: KtDiagnosticFactory0 = KtDiagnosticFactory0("INVALID_REFINES_IN_SWIFT_TARGETS", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
54+
val SUBTYPE_OF_HIDDEN_FROM_OBJC: KtDiagnosticFactory0 = KtDiagnosticFactory0("SUBTYPE_OF_HIDDEN_FROM_OBJC", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
55+
val CANNOT_CHECK_FOR_FORWARD_DECLARATION: KtDiagnosticFactory1<ConeKotlinType> = KtDiagnosticFactory1("CANNOT_CHECK_FOR_FORWARD_DECLARATION", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
56+
val UNCHECKED_CAST_TO_FORWARD_DECLARATION: KtDiagnosticFactory2<ConeKotlinType, ConeKotlinType> = KtDiagnosticFactory2("UNCHECKED_CAST_TO_FORWARD_DECLARATION", WARNING, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
57+
val FORWARD_DECLARATION_AS_REIFIED_TYPE_ARGUMENT: KtDiagnosticFactory1<ConeKotlinType> = KtDiagnosticFactory1("FORWARD_DECLARATION_AS_REIFIED_TYPE_ARGUMENT", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
58+
val FORWARD_DECLARATION_AS_CLASS_LITERAL: KtDiagnosticFactory1<ConeKotlinType> = KtDiagnosticFactory1("FORWARD_DECLARATION_AS_CLASS_LITERAL", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
59+
val TWO_OR_LESS_PARAMETERS_ARE_SUPPORTED_HERE: KtDiagnosticFactory0 = KtDiagnosticFactory0("TWO_OR_LESS_PARAMETERS_ARE_SUPPORTED_HERE", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
60+
val PROPERTY_MUST_BE_VAR: KtDiagnosticFactory1<FqName> = KtDiagnosticFactory1("PROPERTY_MUST_BE_VAR", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
61+
val MUST_NOT_HAVE_EXTENSION_RECEIVER: KtDiagnosticFactory1<String> = KtDiagnosticFactory1("MUST_NOT_HAVE_EXTENSION_RECEIVER", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
62+
val MUST_BE_OBJC_OBJECT_TYPE: KtDiagnosticFactory2<String, ConeKotlinType> = KtDiagnosticFactory2("MUST_BE_OBJC_OBJECT_TYPE", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
63+
val MUST_BE_UNIT_TYPE: KtDiagnosticFactory2<String, ConeKotlinType> = KtDiagnosticFactory2("MUST_BE_UNIT_TYPE", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
64+
val CONSTRUCTOR_OVERRIDES_ALREADY_OVERRIDDEN_OBJC_INITIALIZER: KtDiagnosticFactory1<FqName> = KtDiagnosticFactory1("CONSTRUCTOR_OVERRIDES_ALREADY_OVERRIDDEN_OBJC_INITIALIZER", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
65+
val CONSTRUCTOR_DOES_NOT_OVERRIDE_ANY_SUPER_CONSTRUCTOR: KtDiagnosticFactory1<FqName> = KtDiagnosticFactory1("CONSTRUCTOR_DOES_NOT_OVERRIDE_ANY_SUPER_CONSTRUCTOR", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
66+
val CONSTRUCTOR_MATCHES_SEVERAL_SUPER_CONSTRUCTORS: KtDiagnosticFactory1<FqName> = KtDiagnosticFactory1("CONSTRUCTOR_MATCHES_SEVERAL_SUPER_CONSTRUCTORS", ERROR, SourceElementPositioningStrategies.DEFAULT, KtElement::class)
67+
val CONFLICTING_OBJC_OVERLOADS: KtDiagnosticFactory1<Collection<FirBasedSymbol<*>>> = KtDiagnosticFactory1("CONFLICTING_OBJC_OVERLOADS", ERROR, SourceElementPositioningStrategies.DEFAULT, PsiElement::class)
68+
val INAPPLICABLE_OBJC_OVERRIDE: KtDiagnosticFactory0 = KtDiagnosticFactory0("INAPPLICABLE_OBJC_OVERRIDE", ERROR, SourceElementPositioningStrategies.DEFAULT, PsiElement::class)
6769

6870
init {
6971
RootDiagnosticRendererFactory.registerFactory(FirNativeErrorsDefaultMessages)

0 commit comments

Comments
 (0)