FIR IDE: make KtScopeProvider thread local

This commit is contained in:
Ilya Kirillov
2020-08-07 15:30:24 +03:00
parent f62204fff1
commit 683ec2beff
2 changed files with 21 additions and 1 deletions
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.idea.fir.low.level.api.LowLevelFirApiFacade
import org.jetbrains.kotlin.idea.frontend.api.*
import org.jetbrains.kotlin.idea.frontend.api.fir.scopes.KtFirScopeProvider
import org.jetbrains.kotlin.idea.frontend.api.fir.symbols.KtFirSymbolProvider
import org.jetbrains.kotlin.idea.frontend.api.fir.utils.*
import org.jetbrains.kotlin.idea.frontend.api.scopes.KtScopeProvider
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtFunctionSymbol
import org.jetbrains.kotlin.idea.frontend.api.symbols.KtSymbol
@@ -60,8 +61,9 @@ private constructor(
private val firScopeStorage = FirScopeRegistry()
override val scopeProvider: KtScopeProvider =
override val scopeProvider: KtScopeProvider by threadLocal {
KtFirScopeProvider(token, firSymbolBuilder, project, firSession, firResolveState, firScopeStorage)
}
init {
assertIsValid()
@@ -0,0 +1,18 @@
/*
* 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.idea.frontend.api.fir.utils
import kotlin.reflect.KProperty
@Suppress("EXPERIMENTAL_FEATURE_WARNING")
internal inline class ThreadLocalValue<V>(private val threadLocal: ThreadLocal<V>) {
@Suppress("NOTHING_TO_INLINE")
inline operator fun getValue(thisRef: Any?, property: KProperty<*>): V = threadLocal.get()
}
internal inline fun <T> threadLocal(crossinline init: () -> T): ThreadLocalValue<T> =
ThreadLocalValue(ThreadLocal.withInitial { init() })