[K/N] Remove diagnostics about old Native GC ^KT-58853

This commit is contained in:
Alexander Shabalin
2023-05-31 10:54:49 +02:00
committed by Space Team
parent d2eb4a0abf
commit 2364ffb299
6 changed files with 7 additions and 170 deletions
@@ -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
}
}
<!INAPPLICABLE_THREAD_LOCAL!>@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"
@@ -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 {
<!VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL!>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 {
<!VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL!>var field1: Int = 10<!>
var field1: Int = 10
val backer2 = AtomicInt(0)
var field2: Int
get() = backer2.value
@@ -66,13 +67,13 @@ class Bar2 {
}
<!INAPPLICABLE_THREAD_LOCAL!>@ThreadLocal<!>
enum class Color(<!VARIABLE_IN_ENUM!>var rgb: Int<!>) {
enum class Color(var rgb: Int) {
RED(0xFF0000),
GREEN(0x00FF00),
BLUE(0x0000FF)
}
enum class Color1(<!VARIABLE_IN_ENUM!>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 {
<!VARIABLE_IN_ENUM!>var a = 2<!>
var a = 2
override fun foo() { a = 42 }
},
GREEN,
@@ -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"
@@ -27,14 +27,10 @@ object ErrorsNative {
@JvmField
val INAPPLICABLE_SHARED_IMMUTABLE_TOP_LEVEL = DiagnosticFactory0.create<KtElement>(Severity.ERROR)
@JvmField
val VARIABLE_IN_SINGLETON_WITHOUT_THREAD_LOCAL = DiagnosticFactory0.create<KtElement>(Severity.INFO)
@JvmField
val INAPPLICABLE_THREAD_LOCAL = DiagnosticFactory0.create<KtElement>(Severity.ERROR)
@JvmField
val INAPPLICABLE_THREAD_LOCAL_TOP_LEVEL = DiagnosticFactory0.create<KtElement>(Severity.ERROR)
@JvmField
val VARIABLE_IN_ENUM = DiagnosticFactory0.create<KtElement>(Severity.INFO)
@JvmField
val INVALID_CHARACTERS_NATIVE = DiagnosticFactoryForDeprecation1.create<PsiElement, String>(LanguageFeature.ProhibitInvalidCharsInNativeIdentifiers)
@JvmField
val INAPPLICABLE_OBJC_NAME = DiagnosticFactory0.create<KtElement>(Severity.ERROR)
@@ -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))
}
}
}
}
}
}
@@ -25,7 +25,7 @@ object NativePlatformConfigurator : PlatformConfiguratorBase(
),
additionalDeclarationCheckers = listOf(
NativeThrowsChecker, NativeSharedImmutableChecker,
NativeTopLevelSingletonChecker, NativeThreadLocalChecker,
NativeThreadLocalChecker,
NativeObjCNameChecker, NativeObjCNameOverridesChecker,
NativeObjCRefinementChecker, NativeObjCRefinementAnnotationChecker,
NativeObjCRefinementOverridesChecker, NativeHiddenFromObjCInheritanceChecker