From ee2ae0c4712a1d698d72f9ccc8acf8acb79f8a57 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Wed, 23 Dec 2020 19:14:00 +0100 Subject: [PATCH] JVM IR: remove obsolete -Xir-check-local-names This flag was added a long time ago, at the time when we weren't sure if we were going to keep the naming of local and anonymous classes completely equal to the naming in the old backend. Now that we've decided that we won't keep it equal and there are a lot of differences already, it's not useful anymore. --- .../kotlin/codegen/state/GenerationState.kt | 11 ++-- .../arguments/K2JVMCompilerArguments.kt | 7 --- .../kotlin/config/JvmAnalysisFlags.kt | 3 - .../jetbrains/kotlin/backend/jvm/JvmLower.kt | 2 - .../lower/CheckLocalNamesWithOldBackend.kt | 59 ------------------- compiler/testData/cli/jvm/extraHelp.out | 1 - 6 files changed, 7 insertions(+), 76 deletions(-) delete mode 100644 compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CheckLocalNamesWithOldBackend.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt index 844cfe00604..ddc5fc3e414 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt @@ -108,7 +108,7 @@ class GenerationState private constructor( fun wantsDiagnostics(v: Boolean) = apply { wantsDiagnostics = v } - var jvmBackendClassResolver: JvmBackendClassResolver = JvmBackendClassResolverForModuleWithDependencies(module); private set + private var jvmBackendClassResolver: JvmBackendClassResolver = JvmBackendClassResolverForModuleWithDependencies(module) fun jvmBackendClassResolver(v: JvmBackendClassResolver) = apply { jvmBackendClassResolver = v } @@ -153,8 +153,10 @@ class GenerationState private constructor( val deserializationConfiguration: DeserializationConfiguration = CompilerDeserializationConfiguration(configuration.languageVersionSettings) - val deprecationProvider = - DeprecationResolver(LockBasedStorageManager.NO_LOCKS, configuration.languageVersionSettings, CoroutineCompatibilitySupport.ENABLED, JavaDeprecationSettings) + val deprecationProvider = DeprecationResolver( + LockBasedStorageManager.NO_LOCKS, configuration.languageVersionSettings, CoroutineCompatibilitySupport.ENABLED, + JavaDeprecationSettings + ) init { val icComponents = configuration.get(JVMConfigurationKeys.INCREMENTAL_COMPILATION_COMPONENTS) @@ -250,6 +252,7 @@ class GenerationState private constructor( class ForScript { // quite a mess, this one is an input from repl interpreter var earlierScriptsForReplInterpreter: List? = null + // and the rest is an output from the codegen var resultFieldName: String? = null var resultTypeString: String? = null @@ -346,7 +349,7 @@ class GenerationState private constructor( fun beforeCompile() { markUsed() - if (!isIrBackend || languageVersionSettings.getFlag(JvmAnalysisFlags.irCheckLocalNames)) { + if (!isIrBackend) { CodegenBinding.initTrace(this) } } 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 25ff966572d..1ce3fb3efa4 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 @@ -88,12 +88,6 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { @Argument(value = "-Xno-use-ir", description = "Do not use the IR backend. Useful for a custom-built compiler where IR backend is enabled by default") var noUseIR: Boolean by FreezableVar(false) - @Argument( - value = "-Xir-check-local-names", - description = "Check that names of local classes and anonymous objects are the same in the IR backend as in the old backend" - ) - var irCheckLocalNames: Boolean by FreezableVar(false) - @Argument( value = "-Xallow-unstable-dependencies", description = "Do not report errors on classes in dependencies, which were compiled by an unstable version of the Kotlin compiler" @@ -446,7 +440,6 @@ class K2JVMCompilerArguments : CommonCompilerArguments() { result[JvmAnalysisFlags.inheritMultifileParts] = inheritMultifileParts result[JvmAnalysisFlags.sanitizeParentheses] = sanitizeParentheses result[JvmAnalysisFlags.suppressMissingBuiltinsError] = suppressMissingBuiltinsError - result[JvmAnalysisFlags.irCheckLocalNames] = irCheckLocalNames result[JvmAnalysisFlags.enableJvmPreview] = enableJvmPreview result[AnalysisFlags.allowUnstableDependencies] = allowUnstableDependencies || useFir result[JvmAnalysisFlags.disableUltraLightClasses] = disableUltraLightClasses diff --git a/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmAnalysisFlags.kt b/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmAnalysisFlags.kt index 38f1b62fdce..dd97e61cb3e 100644 --- a/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmAnalysisFlags.kt +++ b/compiler/config.jvm/src/org/jetbrains/kotlin/config/JvmAnalysisFlags.kt @@ -27,9 +27,6 @@ object JvmAnalysisFlags { @JvmStatic val suppressMissingBuiltinsError by AnalysisFlag.Delegates.Boolean - @JvmStatic - val irCheckLocalNames by AnalysisFlag.Delegates.Boolean - @JvmStatic val disableUltraLightClasses by AnalysisFlag.Delegates.Boolean diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt index 312247d2af8..47e43f02d84 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/JvmLower.kt @@ -374,8 +374,6 @@ private val jvmFilePhases = listOf( replaceKFunctionInvokeWithFunctionInvokePhase, kotlinNothingValueExceptionPhase, - checkLocalNamesWithOldBackendPhase, - renameFieldsPhase, fakeInliningLocalVariablesLowering, diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CheckLocalNamesWithOldBackend.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CheckLocalNamesWithOldBackend.kt deleted file mode 100644 index 37d739f5170..00000000000 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/CheckLocalNamesWithOldBackend.kt +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright 2010-2019 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.backend.jvm.lower - -import org.jetbrains.kotlin.backend.common.FileLoweringPass -import org.jetbrains.kotlin.backend.common.phaser.makeIrFilePhase -import org.jetbrains.kotlin.backend.jvm.JvmBackendContext -import org.jetbrains.kotlin.codegen.binding.CodegenBinding -import org.jetbrains.kotlin.config.JvmAnalysisFlags -import org.jetbrains.kotlin.ir.IrElement -import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI -import org.jetbrains.kotlin.ir.declarations.IrClass -import org.jetbrains.kotlin.ir.declarations.IrFile -import org.jetbrains.kotlin.ir.util.render -import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid -import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid -import org.jetbrains.kotlin.ir.visitors.acceptVoid - -val checkLocalNamesWithOldBackendPhase = makeIrFilePhase( - { context -> - if (context.state.languageVersionSettings.getFlag(JvmAnalysisFlags.irCheckLocalNames)) - CheckLocalNamesWithOldBackend(context) - else - FileLoweringPass.Empty - }, - name = "CheckLocalNamesWithOldBackend", - description = "With -Xir-check-local-names, check that names for local classes and anonymous objects are the same in the IR backend as in the old backend" -) - -class CheckLocalNamesWithOldBackend(private val context: JvmBackendContext) : FileLoweringPass, IrElementVisitorVoid { - override fun lower(irFile: IrFile) { - irFile.acceptVoid(this) - } - - @OptIn(ObsoleteDescriptorBasedAPI::class) - override fun visitClass(declaration: IrClass) { - val actualName = context.getLocalClassType(declaration)?.internalName - if (actualName != null) { - val expectedName = context.state.bindingTrace.get(CodegenBinding.ASM_TYPE, declaration.symbol.descriptor)?.internalName - if (expectedName != null && expectedName != actualName) { - throw AssertionError( - "Incorrect name for the class.\n" + - "IR: ${declaration.render()}\n" + - "Descriptor: ${declaration.descriptor}\n" + - "Expected name: $expectedName\n" + - "Actual name: $actualName" - ) - } - } - super.visitClass(declaration) - } - - override fun visitElement(element: IrElement) { - element.acceptChildrenVoid(this) - } -} diff --git a/compiler/testData/cli/jvm/extraHelp.out b/compiler/testData/cli/jvm/extraHelp.out index 111025d9443..0146bea18d5 100644 --- a/compiler/testData/cli/jvm/extraHelp.out +++ b/compiler/testData/cli/jvm/extraHelp.out @@ -31,7 +31,6 @@ where advanced options include: Works as `--enable-preview` in Java. All class files are marked as preview-generated thus it won't be possible to use them in release environment -Xfriend-paths= Paths to output directories for friend modules (whose internals should be visible) -Xmultifile-parts-inherit Compile multifile classes as a hierarchy of parts and facade - -Xir-check-local-names Check that names of local classes and anonymous objects are the same in the IR backend as in the old backend -Xmodule-path= Paths where to find Java 9+ modules -Xjava-package-prefix Package prefix for Java files -Xjava-source-roots= Paths to directories with Java source files