From 072d1913069fa4101b762827fa510a7fa3ce5dc8 Mon Sep 17 00:00:00 2001 From: Dmitrii Gridin Date: Thu, 15 Feb 2024 00:02:32 +0100 Subject: [PATCH] [compiler] replace Enum `values()` with `entries` To fix warnings. Also, use of `Enum.entries` may improve the performance ^KT-48872 --- .../ChangeBoxingMethodTransformer.kt | 4 ++-- ...pturedVarsOptimizationMethodTransformer.kt | 17 +++------------- .../optimization/boxing/BoxingInterpreter.kt | 17 +++------------- .../cli/jvm/compiler/JavaLanguageLevel.kt | 6 +++--- .../arguments/CommonCompilerArguments.kt | 4 ++-- .../arguments/K2JVMCompilerArguments.kt | 4 ++-- .../src/org/jetbrains/kotlin/runner/Main.kt | 17 +++------------- .../jetbrains/kotlin/cli/jvm/jvmArguments.kt | 12 +++++------ .../KotlinCompilerRunnerUtils.kt | 17 +++------------- .../kotlin/config/JVMAssertionsMode.kt | 4 ++-- .../kotlin/config/JvmAbiStability.kt | 5 ++--- .../config/JvmClosureGenerationScheme.kt | 4 ++-- .../kotlin/config/JvmSerializeIrMode.kt | 4 ++-- .../kotlin/config/JvmStringConcat.kt | 4 ++-- .../kotlin/platform/jvm/JvmPlatform.kt | 8 ++++---- .../common/CompilerServicesFacadeBase.kt | 20 ++++--------------- .../kotlin/daemon/CompileServiceImpl.kt | 17 +++------------- .../kotlin/daemon/report/getICReporter.kt | 17 +++------------- .../fir/analysis/js/checkers/FirJsHelpers.kt | 5 ++--- .../fir/lightTree/fir/modifier/Modifier.kt | 6 +++--- .../lightTree/fir/modifier/ModifierFlag.kt | 3 +-- .../resolve/transformers/FirStatusResolver.kt | 2 +- .../transformers/FirTotalResolveProcessor.kt | 5 +++-- .../fir/declarations/FirResolvePhase.kt | 4 ++-- .../fir/declarations/FirResolveState.kt | 4 ++-- .../jetbrains/kotlin/utils/metadataHelpers.kt | 4 ++-- .../checkers/diagnostics/TextDiagnostic.kt | 4 ++-- .../DiagnosticReporterByTrackingStrategy.kt | 6 +++--- .../resolve/calls/GenericCandidateResolver.kt | 16 +++++++-------- .../jetbrains/kotlin/backend/common/ir/Ir.kt | 4 ++-- .../kotlin/ir/backend/js/JsIntrinsics.kt | 8 ++++---- .../serialization/JsIrAstDeserializer.kt | 12 +++++------ .../backend/jvm/lower/VarargLowering.kt | 4 ++-- .../descriptors/IrBuiltInsOverDescriptors.kt | 6 +++--- .../linkage/partial/PartialLinkageConfig.kt | 6 +++--- .../kotlin/ir/types/irTypePredicates.kt | 12 +++++------ .../jetbrains/kotlin/ir/util/IdSignature.kt | 4 ++-- .../linkage/partial/ClassifierExplorer.kt | 6 +++--- .../encodings/BinarySymbolData.kt | 4 ++-- .../encodings/BinaryTypeProjection.kt | 4 ++-- .../KtConstantExpressionElementType.kt | 4 ++-- .../psi/stubs/impl/KotlinConstantValue.kt | 6 ++---- .../impl/KotlinContractEffectStubImpl.kt | 14 ++++++------- .../psi/stubs/impl/KotlinFunctionStubImpl.kt | 17 +++------------- .../services/impl/TargetPlatformParser.kt | 8 ++++---- .../kotlin/TestExceptionsComparator.kt | 4 ++-- .../CompilerTestLanguageVersionSettings.kt | 4 ++-- .../tests/org/jetbrains/kotlin/TestsError.kt | 4 ++-- .../org/jetbrains/kotlin/codegen/TestModel.kt | 4 ++-- .../consistency/SpecTestsConsistencyTest.kt | 6 +++--- .../org/jetbrains/kotlin/spec/utils/Common.kt | 12 +++++------ .../spec/utils/SectionsJsonMapGenerator.kt | 4 ++-- .../spec/utils/TestsJsonMapGenerator.kt | 4 ++-- .../spec/utils/TestsStatisticCollector.kt | 6 +++--- .../GenerateInRangeExpressionTestData.kt | 4 ++-- .../GenerateSteppedRangesCodegenTestData.kt | 4 ++-- .../org/jetbrains/kotlin/config/ApiVersion.kt | 4 ++-- .../kotlin/config/ExplicitApiMode.kt | 6 +++--- .../kotlin/config/LanguageVersionSettings.kt | 6 +++--- .../AnalysisApiConfiguratorFactoryProvider.kt | 10 +++++----- 60 files changed, 174 insertions(+), 267 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/ChangeBoxingMethodTransformer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/ChangeBoxingMethodTransformer.kt index c743cb4e726..ddc73b4bf1d 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/ChangeBoxingMethodTransformer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/coroutines/ChangeBoxingMethodTransformer.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2019 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -25,7 +25,7 @@ object ChangeBoxingMethodTransformer : MethodTransformer() { init { val map = hashMapOf() - for (primitiveType in JvmPrimitiveType.values()) { + for (primitiveType in JvmPrimitiveType.entries) { val name = primitiveType.wrapperFqName.topLevelClassInternalName() map[name] = "box${primitiveType.javaKeywordName.replaceFirstChar(Char::uppercaseChar)}" } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/CapturedVarsOptimizationMethodTransformer.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/CapturedVarsOptimizationMethodTransformer.kt index 4c2bb60e9b8..4c834bf0b52 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/CapturedVarsOptimizationMethodTransformer.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/CapturedVarsOptimizationMethodTransformer.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2017 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.codegen.optimization @@ -236,7 +225,7 @@ internal const val INIT_METHOD_NAME = "" internal val REF_TYPE_TO_ELEMENT_TYPE = HashMap().apply { put(AsmTypes.OBJECT_REF_TYPE.internalName, AsmTypes.OBJECT_TYPE) - PrimitiveType.values().forEach { + PrimitiveType.entries.forEach { put(AsmTypes.sharedTypeForPrimitive(it).internalName, AsmTypes.valueTypeForPrimitive(it)) } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/boxing/BoxingInterpreter.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/boxing/BoxingInterpreter.kt index 039db635aa4..54115f19eab 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/boxing/BoxingInterpreter.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/optimization/boxing/BoxingInterpreter.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.codegen.optimization.boxing @@ -262,7 +251,7 @@ fun AbstractInsnNode.isPrimitiveBoxing() = private val BOXING_CLASS_INTERNAL_NAME = StandardNames.COROUTINES_JVM_INTERNAL_PACKAGE_FQ_NAME.child(Name.identifier("Boxing")).topLevelClassInternalName() -private fun isJvmPrimitiveName(name: String) = JvmPrimitiveType.values().any { it.javaKeywordName == name } +private fun isJvmPrimitiveName(name: String) = JvmPrimitiveType.entries.any { it.javaKeywordName == name } fun AbstractInsnNode.isCoroutinePrimitiveBoxing(): Boolean { return isMethodInsnWith(Opcodes.INVOKESTATIC) { diff --git a/compiler/cli/cli-base/src/org/jetbrains/kotlin/cli/jvm/compiler/JavaLanguageLevel.kt b/compiler/cli/cli-base/src/org/jetbrains/kotlin/cli/jvm/compiler/JavaLanguageLevel.kt index bf1c37218da..ac0ccb07f91 100644 --- a/compiler/cli/cli-base/src/org/jetbrains/kotlin/cli/jvm/compiler/JavaLanguageLevel.kt +++ b/compiler/cli/cli-base/src/org/jetbrains/kotlin/cli/jvm/compiler/JavaLanguageLevel.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -11,7 +11,7 @@ import com.intellij.pom.java.LanguageLevel fun Project.setupHighestLanguageLevel() { LanguageLevelProjectExtension.getInstance(this).languageLevel = - LanguageLevel.values().firstOrNull { it.name == "JDK_17" } - ?: LanguageLevel.values().firstOrNull { it.name == "JDK_15_PREVIEW" } + LanguageLevel.entries.firstOrNull { it.name == "JDK_17" } + ?: LanguageLevel.entries.firstOrNull { it.name == "JDK_15_PREVIEW" } ?: LanguageLevel.JDK_X } diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt index 224940e537e..d7a47e427fa 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/CommonCompilerArguments.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -1027,7 +1027,7 @@ The corresponding calls' declarations may not be marked with @BuilderInference." if (value == null) null else LanguageVersion.fromVersionString(value) ?: run { - val versionStrings = LanguageVersion.values().filterNot(LanguageVersion::isUnsupported).map(LanguageVersion::description) + val versionStrings = LanguageVersion.entries.filterNot(LanguageVersion::isUnsupported).map(LanguageVersion::description) val message = "Unknown $versionOf version: $value\nSupported $versionOf versions: ${versionStrings.joinToString(", ")}" collector.report(CompilerMessageSeverity.ERROR, message, null) null diff --git a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt index 5654265077b..3a70e7d4d4f 100644 --- a/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt +++ b/compiler/cli/cli-common/src/org/jetbrains/kotlin/cli/common/arguments/K2JVMCompilerArguments.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ @@ -856,7 +856,7 @@ This option is deprecated and will be deleted in future versions.""" result[JvmAnalysisFlags.jvmDefaultMode] = it } ?: collector.report( CompilerMessageSeverity.ERROR, - "Unknown -Xjvm-default mode: $jvmDefault, supported modes: ${JvmDefaultMode.values().map(JvmDefaultMode::description)}" + "Unknown -Xjvm-default mode: $jvmDefault, supported modes: ${JvmDefaultMode.entries.map(JvmDefaultMode::description)}" ) result[JvmAnalysisFlags.inheritMultifileParts] = inheritMultifileParts result[JvmAnalysisFlags.sanitizeParentheses] = sanitizeParentheses diff --git a/compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/Main.kt b/compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/Main.kt index c15b35a99ef..3e7b54fcb71 100644 --- a/compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/Main.kt +++ b/compiler/cli/cli-runner/src/org/jetbrains/kotlin/runner/Main.kt @@ -1,17 +1,6 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ package org.jetbrains.kotlin.runner @@ -45,7 +34,7 @@ object Main { val validValues = "${GUESS.argName} (default), ${CLASSFILE.argName}, ${JAR.argName}, ${SCRIPT.argName} (or .