From 2364ffb29903e35cc4d3d014f3804d8aa1581ddb Mon Sep 17 00:00:00 2001 From: Alexander Shabalin Date: Wed, 31 May 2023 10:54:49 +0200 Subject: [PATCH] [K/N] Remove diagnostics about old Native GC ^KT-58853 --- .../nativeTests/topLevelSingleton.fir.kt | 114 ------------------ .../nativeTests/topLevelSingleton.kt | 11 +- .../diagnostics/DefaultErrorMessagesNative.kt | 5 - .../resolve/konan/diagnostics/ErrorsNative.kt | 4 - .../NativeTopLevelSingletonChecker.kt | 41 ------- .../platform/NativePlatformConfigurator.kt | 2 +- 6 files changed, 7 insertions(+), 170 deletions(-) delete mode 100644 compiler/testData/diagnostics/nativeTests/topLevelSingleton.fir.kt delete mode 100644 native/frontend/src/org/jetbrains/kotlin/resolve/konan/diagnostics/NativeTopLevelSingletonChecker.kt diff --git a/compiler/testData/diagnostics/nativeTests/topLevelSingleton.fir.kt b/compiler/testData/diagnostics/nativeTests/topLevelSingleton.fir.kt deleted file mode 100644 index b6608b330fb..00000000000 --- a/compiler/testData/diagnostics/nativeTests/topLevelSingleton.fir.kt +++ /dev/null @@ -1,114 +0,0 @@ -// FILE: annotation.kt -package kotlin.native.concurrent - -@Target(AnnotationTarget.PROPERTY, AnnotationTarget.CLASS) -@Retention(AnnotationRetention.BINARY) -annotation class ThreadLocal - -// FILE: test.kt -import kotlin.native.concurrent.ThreadLocal - -import kotlin.reflect.KProperty - -class Delegate { - val value: Int = 10 - operator fun getValue(thisRef: Any?, property: KProperty<*>): Int { - return value - } - - operator fun setValue(thisRef: Any?, property: KProperty<*>, value: Int) { - } -} - -class AtomicInt(var value: Int) -object Foo { - var field1: Int = 10 - val backer2 = AtomicInt(0) - var field2: Int - get() = backer2.value - set(value: Int) { backer2.value = value } -} - -object Foo1 { - var field1: Int = 10 - set(value: Int) { backer2.value = value } - val backer2 = AtomicInt(0) -} - -object WithDelegate { - var field1: Int by Delegate() -} - -@ThreadLocal -object Bar { - var field1: Int = 10 - var field2: String? = null -} - -class Foo2 { - companion object { - var field1: Int = 10 - val backer2 = AtomicInt(0) - var field2: Int - get() = backer2.value - set(value: Int) { - backer2.value = value - } - } -} - -class Bar2 { - @ThreadLocal - companion object { - var field1: Int = 10 - var field2: String? = null - } -} - -@ThreadLocal -enum class Color(var rgb: Int) { - RED(0xFF0000), - GREEN(0x00FF00), - BLUE(0x0000FF) -} - -enum class Color1(var rgb: Int) { - RED(0xFF0000), - GREEN(0x00FF00), - BLUE(0x0000FF); - - init { this.rgb += 1 } -} - -@ThreadLocal -var a = 3 -enum class Color2() { - RED(), - GREEN(), - BLUE(); - - var rgb: Int = 2 - set(value: Int) { - a = value - } -} - -enum class Color3() { - RED(), - GREEN(), - BLUE(); - - var field1: Int by Delegate() -} - -enum class Color4 { - RED { - var a = 2 - override fun foo() { a = 42 } - }, - GREEN, - BLUE; - open fun foo() {} -} - -var topLevelProperty = "Global var" diff --git a/compiler/testData/diagnostics/nativeTests/topLevelSingleton.kt b/compiler/testData/diagnostics/nativeTests/topLevelSingleton.kt index 42b1b988595..16156a3d405 100644 --- a/compiler/testData/diagnostics/nativeTests/topLevelSingleton.kt +++ b/compiler/testData/diagnostics/nativeTests/topLevelSingleton.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL // FILE: annotation.kt package kotlin.native.concurrent @@ -22,7 +23,7 @@ class Delegate { class AtomicInt(var value: Int) object Foo { - var field1: Int = 10 + var field1: Int = 10 val backer2 = AtomicInt(0) var field2: Int get() = backer2.value @@ -47,7 +48,7 @@ object Bar { class Foo2 { companion object { - var field1: Int = 10 + var field1: Int = 10 val backer2 = AtomicInt(0) var field2: Int get() = backer2.value @@ -66,13 +67,13 @@ class Bar2 { } @ThreadLocal -enum class Color(var rgb: Int) { +enum class Color(var rgb: Int) { RED(0xFF0000), GREEN(0x00FF00), BLUE(0x0000FF) } -enum class Color1(var rgb: Int) { +enum class Color1(var rgb: Int) { RED(0xFF0000), GREEN(0x00FF00), BLUE(0x0000FF); @@ -103,7 +104,7 @@ enum class Color3() { enum class Color4 { RED { - var a = 2 + var a = 2 override fun foo() { a = 42 } }, GREEN, diff --git a/native/frontend/src/org/jetbrains/kotlin/resolve/konan/diagnostics/DefaultErrorMessagesNative.kt b/native/frontend/src/org/jetbrains/kotlin/resolve/konan/diagnostics/DefaultErrorMessagesNative.kt index b7bfeffd32b..a1eabba2ded 100644 --- a/native/frontend/src/org/jetbrains/kotlin/resolve/konan/diagnostics/DefaultErrorMessagesNative.kt +++ b/native/frontend/src/org/jetbrains/kotlin/resolve/konan/diagnostics/DefaultErrorMessagesNative.kt @@ -28,11 +28,6 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy { "@SharedImmutable is applicable only to val with backing field or to property with delegation" ) put(ErrorsNative.INAPPLICABLE_SHARED_IMMUTABLE_TOP_LEVEL, "@SharedImmutable is applicable only to top level declarations") - put( - ErrorsNative.VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL, - "With old Native GC, variable in singleton without @ThreadLocal can't be changed after initialization" - ) - put(ErrorsNative.VARIABLE_IN_ENUM, "With old Native GC, variable in enum class can't be changed after initialization") put( ErrorsNative.INAPPLICABLE_THREAD_LOCAL, "@ThreadLocal is applicable only to property with backing field, to property with delegation or to objects" diff --git a/native/frontend/src/org/jetbrains/kotlin/resolve/konan/diagnostics/ErrorsNative.kt b/native/frontend/src/org/jetbrains/kotlin/resolve/konan/diagnostics/ErrorsNative.kt index ee0f23a7509..fdf39d39e0f 100644 --- a/native/frontend/src/org/jetbrains/kotlin/resolve/konan/diagnostics/ErrorsNative.kt +++ b/native/frontend/src/org/jetbrains/kotlin/resolve/konan/diagnostics/ErrorsNative.kt @@ -27,14 +27,10 @@ object ErrorsNative { @JvmField val INAPPLICABLE_SHARED_IMMUTABLE_TOP_LEVEL = DiagnosticFactory0.create(Severity.ERROR) @JvmField - val VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL = DiagnosticFactory0.create(Severity.INFO) - @JvmField val INAPPLICABLE_THREAD_LOCAL = DiagnosticFactory0.create(Severity.ERROR) @JvmField val INAPPLICABLE_THREAD_LOCAL_TOP_LEVEL = DiagnosticFactory0.create(Severity.ERROR) @JvmField - val VARIABLE_IN_ENUM = DiagnosticFactory0.create(Severity.INFO) - @JvmField val INVALID_CHARACTERS_NATIVE = DiagnosticFactoryForDeprecation1.create(LanguageFeature.ProhibitInvalidCharsInNativeIdentifiers) @JvmField val INAPPLICABLE_OBJC_NAME = DiagnosticFactory0.create(Severity.ERROR) diff --git a/native/frontend/src/org/jetbrains/kotlin/resolve/konan/diagnostics/NativeTopLevelSingletonChecker.kt b/native/frontend/src/org/jetbrains/kotlin/resolve/konan/diagnostics/NativeTopLevelSingletonChecker.kt deleted file mode 100644 index 998b5cfdfdb..00000000000 --- a/native/frontend/src/org/jetbrains/kotlin/resolve/konan/diagnostics/NativeTopLevelSingletonChecker.kt +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright 2010-2020 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.resolve.konan.diagnostics - -import org.jetbrains.kotlin.descriptors.* -import org.jetbrains.kotlin.name.FqName -import org.jetbrains.kotlin.psi.KtDeclaration -import org.jetbrains.kotlin.psi.KtProperty -import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils -import org.jetbrains.kotlin.resolve.DescriptorUtils -import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker -import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext -import org.jetbrains.kotlin.resolve.hasBackingField - -object NativeTopLevelSingletonChecker : DeclarationChecker { - private val threadLocalFqName = FqName("kotlin.native.concurrent.ThreadLocal") - - override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor, context: DeclarationCheckerContext) { - // Check variables inside singletons. - if (descriptor !is PropertyDescriptor) return - (descriptor.containingDeclaration as? ClassDescriptor)?.let { parent -> - val hasBackingFieldWithDefaultSetter = descriptor.hasBackingField(context.trace.bindingContext) && - descriptor.setter?.isDefault == true - val hasDelegate = if (declaration is KtProperty) declaration.delegate != null else false - - if (descriptor.isVar && (DescriptorUtils.isEnumClass(parent) || DescriptorUtils.isEnumEntry(parent)) && - hasBackingFieldWithDefaultSetter && !hasDelegate) { - context.trace.report(ErrorsNative.VARIABLE_IN_ENUM.on(declaration)) - } else if (parent.kind.isSingleton) { - parent.annotations.findAnnotation(threadLocalFqName) ?: run { - if (descriptor.isVar && !hasDelegate && hasBackingFieldWithDefaultSetter) { - context.trace.report(ErrorsNative.VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL.on(declaration)) - } - } - } - } - } -} diff --git a/native/frontend/src/org/jetbrains/kotlin/resolve/konan/platform/NativePlatformConfigurator.kt b/native/frontend/src/org/jetbrains/kotlin/resolve/konan/platform/NativePlatformConfigurator.kt index fcb0c72171e..432fa427e6b 100644 --- a/native/frontend/src/org/jetbrains/kotlin/resolve/konan/platform/NativePlatformConfigurator.kt +++ b/native/frontend/src/org/jetbrains/kotlin/resolve/konan/platform/NativePlatformConfigurator.kt @@ -25,7 +25,7 @@ object NativePlatformConfigurator : PlatformConfiguratorBase( ), additionalDeclarationCheckers = listOf( NativeThrowsChecker, NativeSharedImmutableChecker, - NativeTopLevelSingletonChecker, NativeThreadLocalChecker, + NativeThreadLocalChecker, NativeObjCNameChecker, NativeObjCNameOverridesChecker, NativeObjCRefinementChecker, NativeObjCRefinementAnnotationChecker, NativeObjCRefinementOverridesChecker, NativeHiddenFromObjCInheritanceChecker