From ad1dfd5cb90ef2b33ce52664715d085df6fb8c6c Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Mon, 22 May 2023 15:48:04 +0200 Subject: [PATCH] JVM: change logic of applying KT-57570 behavior a bit If `-Xno-unified-null-checks` is specified, do not throw exceptions, but rather revert to the old behavior, with source code in exception messages. Note that `-Xno-unified-null-checks` is a flag which enables behavior of Kotlin 1.3. It can be removed once we no longer support API version 1.3. --- .../kotlin/codegen/state/GenerationState.kt | 19 +++++++++---------- .../backend/jvm/lower/TypeOperatorLowering.kt | 2 +- 2 files changed, 10 insertions(+), 11 deletions(-) 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 bb364c59ae5..d155204df9c 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/state/GenerationState.kt @@ -315,16 +315,15 @@ class GenerationState private constructor( val assertionsMode: JVMAssertionsMode = configuration.get(JVMConfigurationKeys.ASSERTIONS_MODE, JVMAssertionsMode.DEFAULT) val isInlineDisabled: Boolean = configuration.getBoolean(CommonConfigurationKeys.DISABLE_INLINE) val useTypeTableInSerializer: Boolean = configuration.getBoolean(JVMConfigurationKeys.USE_TYPE_TABLE) - val unifiedNullChecks: Boolean = ( - languageVersionSettings.apiVersion >= ApiVersion.KOTLIN_1_4 && - !configuration.getBoolean(JVMConfigurationKeys.NO_UNIFIED_NULL_CHECKS) - ).also { - check(it || !languageVersionSettings.supportsFeature(LanguageFeature.NoSourceCodeInNotNullAssertionExceptions)) { - // This assertion is needed because we generate calls to `Intrinsics.checkNotNull` which is only available since 1.4. - "Language feature ${LanguageFeature.NoSourceCodeInNotNullAssertionExceptions.name} is not supported " + - "if -Xno-unified-null-checks is enabled." - } - } + val unifiedNullChecks: Boolean = + languageVersionSettings.apiVersion >= ApiVersion.KOTLIN_1_4 && + !configuration.getBoolean(JVMConfigurationKeys.NO_UNIFIED_NULL_CHECKS) + + val noSourceCodeInNotNullAssertionExceptions: Boolean = + languageVersionSettings.supportsFeature(LanguageFeature.NoSourceCodeInNotNullAssertionExceptions) + // This check is needed because we generate calls to `Intrinsics.checkNotNull` which is only available since 1.4 + // (when unified null checks were introduced). + && unifiedNullChecks val generateSmapCopyToAnnotation: Boolean = !configuration.getBoolean(JVMConfigurationKeys.NO_SOURCE_DEBUG_EXTENSION) val functionsWithInlineClassReturnTypesMangled: Boolean = diff --git a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt index bc5950449c9..78b4615da61 100644 --- a/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt +++ b/compiler/ir/backend.jvm/lower/src/org/jetbrains/kotlin/backend/jvm/lower/TypeOperatorLowering.kt @@ -764,7 +764,7 @@ private class TypeOperatorLowering(private val backendContext: JvmBackendContext } private fun IrBuilderWithScope.computeNotNullAssertionText(typeOperatorCall: IrTypeOperatorCall): String? { - if (backendContext.state.languageVersionSettings.supportsFeature(LanguageFeature.NoSourceCodeInNotNullAssertionExceptions)) { + if (backendContext.state.noSourceCodeInNotNullAssertionExceptions) { return when (val argument = typeOperatorCall.argument) { is IrCall -> "${argument.symbol.owner.name.asString()}(...)" is IrGetField -> argument.symbol.owner.name.asString()