Add a fallback flag -Xno-unified-null-checks for KT-22275
#KT-41482 Fixed
This commit is contained in:
@@ -5051,7 +5051,9 @@ The "returned" value of try expression with no finally is either the last expres
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
|
||||
CodegenUtilKt.generateAsCast(v, rightKotlinType, boxedRightType, safeAs, state.getLanguageVersionSettings());
|
||||
CodegenUtilKt.generateAsCast(
|
||||
v, rightKotlinType, boxedRightType, safeAs, state.getLanguageVersionSettings(), state.getUnifiedNullChecks()
|
||||
);
|
||||
|
||||
return Unit.INSTANCE;
|
||||
});
|
||||
|
||||
@@ -98,11 +98,12 @@ fun generateAsCast(
|
||||
kotlinType: KotlinType,
|
||||
asmType: Type,
|
||||
isSafe: Boolean,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
languageVersionSettings: LanguageVersionSettings,
|
||||
unifiedNullChecks: Boolean,
|
||||
) {
|
||||
if (!isSafe) {
|
||||
if (!TypeUtils.isNullableType(kotlinType)) {
|
||||
generateNullCheckForNonSafeAs(v, kotlinType, languageVersionSettings)
|
||||
generateNullCheckForNonSafeAs(v, kotlinType, unifiedNullChecks)
|
||||
}
|
||||
} else {
|
||||
with(v) {
|
||||
@@ -122,15 +123,13 @@ fun generateAsCast(
|
||||
private fun generateNullCheckForNonSafeAs(
|
||||
v: InstructionAdapter,
|
||||
type: KotlinType,
|
||||
languageVersionSettings: LanguageVersionSettings
|
||||
unifiedNullChecks: Boolean,
|
||||
) {
|
||||
with(v) {
|
||||
dup()
|
||||
val nonnull = Label()
|
||||
ifnonnull(nonnull)
|
||||
val exceptionClass =
|
||||
if (languageVersionSettings.apiVersion >= ApiVersion.KOTLIN_1_4) "java/lang/NullPointerException"
|
||||
else "kotlin/TypeCastException"
|
||||
val exceptionClass = if (unifiedNullChecks) "java/lang/NullPointerException" else "kotlin/TypeCastException"
|
||||
AsmUtil.genThrow(
|
||||
v,
|
||||
exceptionClass,
|
||||
|
||||
@@ -41,7 +41,10 @@ class PsiInlineCodegen(
|
||||
private val actualDispatchReceiver: Type = methodOwner
|
||||
) : InlineCodegen<ExpressionCodegen>(
|
||||
codegen, state, function, methodOwner, signature, typeParameterMappings, sourceCompiler,
|
||||
ReifiedTypeInliner(typeParameterMappings, PsiInlineIntrinsicsSupport(state), codegen.typeSystem, state.languageVersionSettings),
|
||||
ReifiedTypeInliner(
|
||||
typeParameterMappings, PsiInlineIntrinsicsSupport(state), codegen.typeSystem,
|
||||
state.languageVersionSettings, state.unifiedNullChecks
|
||||
),
|
||||
), CallGenerator {
|
||||
override fun generateAssertFieldIfNeeded(info: RootInliningContext) {
|
||||
if (info.generateAssertField) {
|
||||
|
||||
@@ -53,7 +53,8 @@ class ReifiedTypeInliner<KT : KotlinTypeMarker>(
|
||||
private val parametersMapping: TypeParameterMappings<KT>?,
|
||||
private val intrinsicsSupport: IntrinsicsSupport<KT>,
|
||||
private val typeSystem: TypeSystemCommonBackendContext,
|
||||
private val languageVersionSettings: LanguageVersionSettings
|
||||
private val languageVersionSettings: LanguageVersionSettings,
|
||||
private val unifiedNullChecks: Boolean,
|
||||
) {
|
||||
enum class OperationKind {
|
||||
NEW_ARRAY, AS, SAFE_AS, IS, JAVA_CLASS, ENUM_REIFIED, TYPE_OF;
|
||||
@@ -222,7 +223,7 @@ class ReifiedTypeInliner<KT : KotlinTypeMarker>(
|
||||
if (stubCheckcast !is TypeInsnNode) return false
|
||||
|
||||
val newMethodNode = MethodNode(Opcodes.API_VERSION)
|
||||
generateAsCast(InstructionAdapter(newMethodNode), kotlinType, asmType, safe, languageVersionSettings)
|
||||
generateAsCast(InstructionAdapter(newMethodNode), kotlinType, asmType, safe, languageVersionSettings, unifiedNullChecks)
|
||||
|
||||
instructions.insert(insn, newMethodNode.instructions)
|
||||
// Keep stubCheckcast to avoid VerifyErrors on 1.8+ bytecode,
|
||||
|
||||
@@ -249,7 +249,9 @@ 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
|
||||
val unifiedNullChecks: Boolean =
|
||||
languageVersionSettings.apiVersion >= ApiVersion.KOTLIN_1_4 &&
|
||||
!configuration.getBoolean(JVMConfigurationKeys.NO_UNIFIED_NULL_CHECKS)
|
||||
val functionsWithInlineClassReturnTypesMangled: Boolean =
|
||||
languageVersionSettings.supportsFeature(LanguageFeature.MangleClassMembersReturningInlineClasses)
|
||||
|
||||
|
||||
+6
@@ -352,6 +352,12 @@ class K2JVMCompilerArguments : CommonCompilerArguments() {
|
||||
)
|
||||
var noKotlinNothingValueException: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(
|
||||
value = "-Xno-unified-null-checks",
|
||||
description = "Use pre-1.4 exception types in null checks instead of java.lang.NPE. See KT-22275 for more details"
|
||||
)
|
||||
var noUnifiedNullChecks: Boolean by FreezableVar(false)
|
||||
|
||||
@Argument(
|
||||
value = "-Xprofile",
|
||||
valueDescription = "<profilerPath:command:outputDir>",
|
||||
|
||||
@@ -166,6 +166,7 @@ fun CompilerConfiguration.configureAdvancedJvmOptions(arguments: K2JVMCompilerAr
|
||||
put(JVMConfigurationKeys.EMIT_JVM_TYPE_ANNOTATIONS, arguments.emitJvmTypeAnnotations)
|
||||
put(JVMConfigurationKeys.NO_OPTIMIZED_CALLABLE_REFERENCES, arguments.noOptimizedCallableReferences)
|
||||
put(JVMConfigurationKeys.NO_KOTLIN_NOTHING_VALUE_EXCEPTION, arguments.noKotlinNothingValueException)
|
||||
put(JVMConfigurationKeys.NO_UNIFIED_NULL_CHECKS, arguments.noUnifiedNullChecks)
|
||||
|
||||
if (!JVMConstructorCallNormalizationMode.isSupportedValue(arguments.constructorCallNormalizationMode)) {
|
||||
getNotNull(CLIConfigurationKeys.MESSAGE_COLLECTOR_KEY).report(
|
||||
|
||||
@@ -123,6 +123,9 @@ public class JVMConfigurationKeys {
|
||||
public static final CompilerConfigurationKey<Boolean> NO_KOTLIN_NOTHING_VALUE_EXCEPTION =
|
||||
CompilerConfigurationKey.create("Do not use KotlinNothingValueException available since 1.4");
|
||||
|
||||
public static final CompilerConfigurationKey<Boolean> NO_UNIFIED_NULL_CHECKS =
|
||||
CompilerConfigurationKey.create("Use pre-1.4 exception types in null checks instead of java.lang.NPE");
|
||||
|
||||
public static final CompilerConfigurationKey<Boolean> USE_OLD_SPILLED_VAR_TYPE_ANALYSIS =
|
||||
CompilerConfigurationKey.create("Use old, SourceInterpreter-based analysis for fields, used for spilled variables in coroutines");
|
||||
}
|
||||
|
||||
+2
-1
@@ -1201,7 +1201,8 @@ class ExpressionCodegen(
|
||||
mappings,
|
||||
IrInlineIntrinsicsSupport(context, typeMapper),
|
||||
IrTypeCheckerContext(context.irBuiltIns),
|
||||
state.languageVersionSettings
|
||||
state.languageVersionSettings,
|
||||
state.unifiedNullChecks,
|
||||
)
|
||||
|
||||
return IrInlineCodegen(this, state, callee, methodOwner, signature, mappings, sourceCompiler, reifiedTypeInliner)
|
||||
|
||||
+1
@@ -73,6 +73,7 @@ where advanced options include:
|
||||
Do not use optimized callable reference superclasses available from 1.4
|
||||
-Xno-param-assertions Don't generate not-null assertions on parameters of methods accessible from Java
|
||||
-Xno-receiver-assertions Don't generate not-null assertion for extension receiver arguments of platform types
|
||||
-Xno-unified-null-checks Use pre-1.4 exception types in null checks instead of java.lang.NPE. See KT-22275 for more details
|
||||
-Xno-use-ir Do not use the IR backend. Useful for a custom-built compiler where IR backend is enabled by default
|
||||
-Xprofile=<profilerPath:command:outputDir>
|
||||
Debug option: Run compiler with async profiler, save snapshots to outputDir, command is passed to async-profiler on start
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// !API_VERSION: 1.3
|
||||
// KOTLIN_CONFIGURATION_FLAGS: +JVM.NO_UNIFIED_NULL_CHECKS
|
||||
// WITH_RUNTIME
|
||||
// TARGET_BACKEND: JVM
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// !API_VERSION: 1.3
|
||||
// KOTLIN_CONFIGURATION_FLAGS: +JVM.NO_UNIFIED_NULL_CHECKS
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: A.java
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// !API_VERSION: 1.3
|
||||
// KOTLIN_CONFIGURATION_FLAGS: +JVM.NO_UNIFIED_NULL_CHECKS
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: A.java
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// !API_VERSION: 1.3
|
||||
// KOTLIN_CONFIGURATION_FLAGS: +JVM.NO_UNIFIED_NULL_CHECKS
|
||||
// TARGET_BACKEND: JVM
|
||||
// FILE: 1.kt
|
||||
// WITH_RUNTIME
|
||||
|
||||
Reference in New Issue
Block a user