From 9844671ded497a70cb0f6ed45d8c6c401593e73a Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Fri, 3 Sep 2021 13:54:37 +0300 Subject: [PATCH] [FIR] Add KDoc about thread safety rules of FirDeclarationAttributes --- .../kotlin/fir/declarations/FirDeclarationAttributes.kt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirDeclarationAttributes.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirDeclarationAttributes.kt index 08db07b21fb..314ce38424f 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirDeclarationAttributes.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/declarations/FirDeclarationAttributes.kt @@ -15,6 +15,14 @@ import kotlin.reflect.KProperty abstract class FirDeclarationDataKey +/** + * Please note that FirDeclarationAttributes itself is thread unsafe, so when you read + * or write some attribute you need to ensure that this operation is safe and there + * won't be any race condition. You can achieve this by + * - setting attribute to declaration before it's publication (e.g. in scopes) + * - setting attribute in one phase and reading it only in following ones (using `ensureResolve` on symbol) + * - resetting attribute under lock over specific attribute value + */ class FirDeclarationAttributes : AttributeArrayOwner { override val typeRegistry: TypeRegistry get() = FirDeclarationDataRegistry