[FIR] Add @PrivateForInline to prevent setting to var's from inconvenient places

This commit is contained in:
Dmitriy Novozhilov
2020-02-18 16:06:11 +03:00
parent 2aeb1ea234
commit 6941cd6d28
5 changed files with 28 additions and 18 deletions
@@ -0,0 +1,9 @@
/*
* 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.fir
@Experimental(level = Experimental.Level.ERROR)
annotation class PrivateForInline
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.fir.resolve.calls
import org.jetbrains.kotlin.fir.PrivateForInline
import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents
import kotlin.coroutines.Continuation
@@ -15,17 +16,13 @@ abstract class CheckerSink {
abstract val needYielding: Boolean
@Deprecated(
"This function yields unconditionally, exposed only for yieldIfNeed",
level = DeprecationLevel.WARNING,
replaceWith = ReplaceWith("yieldIfNeed")
)
@PrivateForInline
abstract suspend fun yield()
}
@UseExperimental(PrivateForInline::class)
suspend inline fun CheckerSink.yieldIfNeed() {
if (needYielding) {
@Suppress("DEPRECATION")
yield()
}
}
@@ -37,11 +34,13 @@ suspend inline fun CheckerSink.yieldApplicability(new: CandidateApplicability) {
class CheckerSinkImpl(override val components: InferenceComponents, var continuation: Continuation<Unit>? = null) : CheckerSink() {
var current = CandidateApplicability.RESOLVED
private set
override fun reportApplicability(new: CandidateApplicability) {
if (new < current) current = new
}
@Suppress("OverridingDeprecatedMember")
@PrivateForInline
override suspend fun yield() = kotlin.coroutines.intrinsics.suspendCoroutineUninterceptedOrReturn<Unit> {
continuation = it
kotlin.coroutines.intrinsics.COROUTINE_SUSPENDED
@@ -5,10 +5,7 @@
package org.jetbrains.kotlin.fir.resolve.transformers.body.resolve
import org.jetbrains.kotlin.fir.FirCallResolver
import org.jetbrains.kotlin.fir.FirQualifiedNameResolver
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.FirSymbolOwner
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.fir.declarations.FirFile
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
@@ -28,6 +25,7 @@ import org.jetbrains.kotlin.fir.types.builder.buildImplicitTypeRef
abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAbstractPhaseTransformer<ResolutionMode>(phase) {
abstract val components: BodyResolveTransformerComponents
@set:PrivateForInline
abstract var implicitTypeOnly: Boolean
internal set
@@ -52,6 +50,7 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb
}
}
@UseExperimental(PrivateForInline::class)
internal inline fun <T> withFullBodyResolve(crossinline l: () -> T): T {
if (!implicitTypeOnly) return l()
implicitTypeOnly = false
@@ -99,6 +98,7 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb
override val noExpectedType: FirTypeRef = buildImplicitTypeRef()
@set:PrivateForInline
override lateinit var file: FirFile
internal set
@@ -128,15 +128,17 @@ abstract class FirAbstractBodyResolveTransformer(phase: FirResolvePhase) : FirAb
IntegerLiteralTypeApproximationTransformer(symbolProvider, inferenceComponents.ctx)
override val integerOperatorsTypeUpdater: IntegerOperatorsTypeUpdater = IntegerOperatorsTypeUpdater(integerLiteralTypeApproximator)
@PublishedApi
internal var containerIfAny: FirDeclaration? = null
@set:PrivateForInline
var containerIfAny: FirDeclaration? = null
override var container: FirDeclaration
get() = containerIfAny!!
private set(value) {
@UseExperimental(PrivateForInline::class)
containerIfAny = value
}
@UseExperimental(PrivateForInline::class)
inline fun <T> withContainer(declaration: FirDeclaration, crossinline f: () -> T): T {
val prevContainer = containerIfAny
containerIfAny = declaration
@@ -5,12 +5,9 @@
package org.jetbrains.kotlin.fir.resolve.transformers.body.resolve
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.FirSession
import org.jetbrains.kotlin.fir.FirTargetElement
import org.jetbrains.kotlin.fir.*
import org.jetbrains.kotlin.fir.declarations.*
import org.jetbrains.kotlin.fir.expressions.*
import org.jetbrains.kotlin.fir.render
import org.jetbrains.kotlin.fir.resolve.ResolutionMode
import org.jetbrains.kotlin.fir.resolve.ScopeSession
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
@@ -40,8 +37,9 @@ open class FirBodyResolveTransformer(
private val controlFlowStatementsTransformer = FirControlFlowStatementsResolveTransformer(this)
override fun transformFile(file: FirFile, data: ResolutionMode): CompositeTransformResult<FirFile> {
packageFqName = file.packageFqName
@UseExperimental(PrivateForInline::class)
components.file = file
packageFqName = file.packageFqName
return withScopeCleanup(components.topLevelScopes) {
components.topLevelScopes.addImportingScopes(file, session, components.scopeSession)
super.transformFile(file, data)
@@ -6,6 +6,7 @@
package org.jetbrains.kotlin.fir.resolve.transformers.body.resolve
import org.jetbrains.kotlin.fir.FirElement
import org.jetbrains.kotlin.fir.PrivateForInline
import org.jetbrains.kotlin.fir.resolve.ResolutionMode
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
@@ -15,6 +16,7 @@ abstract class FirPartialBodyResolveTransformer(
@Suppress("OVERRIDE_BY_INLINE")
final override inline val components: BodyResolveTransformerComponents get() = transformer.components
@set:PrivateForInline
override var implicitTypeOnly: Boolean
get() = transformer.implicitTypeOnly
set(value) {