FIR: rearrange functions in BodyResolveContext
This commit is contained in:
@@ -137,11 +137,4 @@ class InaccessibleImplicitReceiverValue(
|
|||||||
type: ConeKotlinType,
|
type: ConeKotlinType,
|
||||||
useSiteSession: FirSession,
|
useSiteSession: FirSession,
|
||||||
scopeSession: ScopeSession
|
scopeSession: ScopeSession
|
||||||
) : ImplicitReceiverValue<FirClassSymbol<*>>(boundSymbol, type, useSiteSession, scopeSession) {
|
) : ImplicitReceiverValue<FirClassSymbol<*>>(boundSymbol, type, useSiteSession, scopeSession)
|
||||||
internal constructor(
|
|
||||||
boundSymbol: FirClassSymbol<*>, useSiteSession: FirSession, scopeSession: ScopeSession
|
|
||||||
) : this(
|
|
||||||
boundSymbol, boundSymbol.constructType(typeArguments = emptyArray(), isNullable = false),
|
|
||||||
useSiteSession, scopeSession
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|||||||
+1
-1
@@ -122,7 +122,7 @@ internal fun FirTypedDeclaration.transformTypeToArrayType() {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> withScopeCleanup(scopes: MutableList<*>, crossinline l: () -> T): T {
|
inline fun <T> withScopeCleanup(scopes: MutableList<*>, l: () -> T): T {
|
||||||
val sizeBefore = scopes.size
|
val sizeBefore = scopes.size
|
||||||
return try {
|
return try {
|
||||||
l()
|
l()
|
||||||
|
|||||||
+246
-217
@@ -45,26 +45,28 @@ class BodyResolveContext(
|
|||||||
val targetedLocalClasses: Set<FirClass<*>> = emptySet(),
|
val targetedLocalClasses: Set<FirClass<*>> = emptySet(),
|
||||||
val outerLocalClassForNested: MutableMap<FirClassLikeSymbol<*>, FirClassLikeSymbol<*>> = mutableMapOf()
|
val outerLocalClassForNested: MutableMap<FirClassLikeSymbol<*>, FirClassLikeSymbol<*>> = mutableMapOf()
|
||||||
) {
|
) {
|
||||||
private val mutableFileImportsScope: MutableList<FirScope> = mutableListOf()
|
val fileImportsScope: MutableList<FirScope> = mutableListOf()
|
||||||
|
|
||||||
val fileImportsScope: List<FirScope>
|
|
||||||
get() = mutableFileImportsScope
|
|
||||||
|
|
||||||
@set:PrivateForInline
|
@set:PrivateForInline
|
||||||
lateinit var file: FirFile
|
lateinit var file: FirFile
|
||||||
private set
|
|
||||||
|
|
||||||
@set:PrivateForInline
|
var towerDataContextsForClassParts = FirTowerDataContextsForClassParts(forMemberDeclarations = FirTowerDataContext())
|
||||||
var towerDataContextsForClassParts: FirTowerDataContextsForClassParts =
|
private set
|
||||||
FirTowerDataContextsForClassParts(forMemberDeclarations = FirTowerDataContext())
|
|
||||||
|
|
||||||
val towerDataContext: FirTowerDataContext
|
val towerDataContext: FirTowerDataContext
|
||||||
get() = towerDataContextsForClassParts.currentContext
|
get() = towerDataContextsForClassParts.currentContext
|
||||||
|
|
||||||
|
@OptIn(PrivateForInline::class)
|
||||||
|
var towerDataMode: FirTowerDataMode
|
||||||
|
get() = towerDataContextsForClassParts.mode
|
||||||
|
set(value) {
|
||||||
|
towerDataContextsForClassParts.mode = value
|
||||||
|
}
|
||||||
|
|
||||||
val implicitReceiverStack: ImplicitReceiverStack
|
val implicitReceiverStack: ImplicitReceiverStack
|
||||||
get() = towerDataContext.implicitReceiverStack
|
get() = towerDataContext.implicitReceiverStack
|
||||||
|
|
||||||
val towerDataContextForAnonymousFunctions: MutableMap<FirAnonymousFunctionSymbol, FirTowerDataContext>
|
private val towerDataContextForAnonymousFunctions: MutableMap<FirAnonymousFunctionSymbol, FirTowerDataContext>
|
||||||
get() = towerDataContextsForClassParts.towerDataContextForAnonymousFunctions
|
get() = towerDataContextsForClassParts.towerDataContextForAnonymousFunctions
|
||||||
|
|
||||||
private val towerDataContextForCallableReferences: MutableMap<FirCallableReferenceAccess, FirTowerDataContext>
|
private val towerDataContextForCallableReferences: MutableMap<FirCallableReferenceAccess, FirTowerDataContext>
|
||||||
@@ -81,6 +83,188 @@ class BodyResolveContext(
|
|||||||
|
|
||||||
val anonymousFunctionsAnalyzedInDependentContext: MutableSet<FirFunctionSymbol<*>> = mutableSetOf()
|
val anonymousFunctionsAnalyzedInDependentContext: MutableSet<FirFunctionSymbol<*>> = mutableSetOf()
|
||||||
|
|
||||||
|
private inline fun <T> withNewTowerDataForClassParts(newContexts: FirTowerDataContextsForClassParts, f: () -> T): T {
|
||||||
|
val old = towerDataContextsForClassParts
|
||||||
|
towerDataContextsForClassParts = newContexts
|
||||||
|
return try {
|
||||||
|
f()
|
||||||
|
} finally {
|
||||||
|
|
||||||
|
towerDataContextsForClassParts = old
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private inline fun <R> withLambdaBeingAnalyzedInDependentContext(lambda: FirAnonymousFunctionSymbol, l: () -> R): R {
|
||||||
|
anonymousFunctionsAnalyzedInDependentContext.add(lambda)
|
||||||
|
return try {
|
||||||
|
l()
|
||||||
|
} finally {
|
||||||
|
anonymousFunctionsAnalyzedInDependentContext.remove(lambda)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrivateForInline
|
||||||
|
inline fun <T> withContainer(declaration: FirDeclaration, f: () -> T): T {
|
||||||
|
val oldContainers = containers
|
||||||
|
containers = containers.add(declaration)
|
||||||
|
return try {
|
||||||
|
f()
|
||||||
|
} finally {
|
||||||
|
containers = oldContainers
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrivateForInline
|
||||||
|
inline fun <R> withTowerDataCleanup(l: () -> R): R {
|
||||||
|
val initialContext = towerDataContext
|
||||||
|
return try {
|
||||||
|
l()
|
||||||
|
} finally {
|
||||||
|
replaceTowerDataContext(initialContext)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrivateForInline
|
||||||
|
inline fun <T> withTowerDataMode(mode: FirTowerDataMode, f: () -> T): T {
|
||||||
|
return withTowerModeCleanup {
|
||||||
|
towerDataMode = mode
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrivateForInline
|
||||||
|
inline fun <R> withTowerModeCleanup(l: () -> R): R {
|
||||||
|
val initialMode = towerDataMode
|
||||||
|
return try {
|
||||||
|
l()
|
||||||
|
} finally {
|
||||||
|
towerDataMode = initialMode
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrivateForInline
|
||||||
|
fun replaceTowerDataContext(newContext: FirTowerDataContext) {
|
||||||
|
towerDataContextsForClassParts.currentContext = newContext
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrivateForInline
|
||||||
|
fun clear() {
|
||||||
|
towerDataContextForAnonymousFunctions.clear()
|
||||||
|
towerDataContextForCallableReferences.clear()
|
||||||
|
dataFlowAnalyzerContext.reset()
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrivateForInline
|
||||||
|
fun addNonLocalTowerDataElement(element: FirTowerDataElement) {
|
||||||
|
replaceTowerDataContext(towerDataContext.addNonLocalTowerDataElements(listOf(element)))
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrivateForInline
|
||||||
|
fun addNonLocalTowerDataElements(newElements: List<FirTowerDataElement>) {
|
||||||
|
replaceTowerDataContext(towerDataContext.addNonLocalTowerDataElements(newElements))
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrivateForInline
|
||||||
|
fun addLocalScope(localScope: FirLocalScope) {
|
||||||
|
replaceTowerDataContext(towerDataContext.addLocalScope(localScope))
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrivateForInline
|
||||||
|
fun addReceiver(name: Name?, implicitReceiverValue: ImplicitReceiverValue<*>) {
|
||||||
|
replaceTowerDataContext(towerDataContext.addReceiver(name, implicitReceiverValue))
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrivateForInline
|
||||||
|
private inline fun updateLastScope(transform: FirLocalScope.() -> FirLocalScope) {
|
||||||
|
val lastScope = towerDataContext.localScopes.lastOrNull() ?: return
|
||||||
|
replaceTowerDataContext(towerDataContext.setLastLocalScope(lastScope.transform()))
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrivateForInline
|
||||||
|
fun storeFunction(function: FirSimpleFunction) {
|
||||||
|
updateLastScope { storeFunction(function) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrivateForInline
|
||||||
|
private inline fun <T> withLabelAndReceiverType(
|
||||||
|
labelName: Name?,
|
||||||
|
owner: FirCallableDeclaration<*>,
|
||||||
|
type: ConeKotlinType?,
|
||||||
|
holder: SessionHolder,
|
||||||
|
f: () -> T
|
||||||
|
): T = withTowerDataCleanup {
|
||||||
|
if (type != null) {
|
||||||
|
val receiver = ImplicitExtensionReceiverValue(
|
||||||
|
owner.symbol,
|
||||||
|
type,
|
||||||
|
holder.session,
|
||||||
|
holder.scopeSession
|
||||||
|
)
|
||||||
|
addReceiver(labelName, receiver)
|
||||||
|
}
|
||||||
|
|
||||||
|
f()
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrivateForInline
|
||||||
|
inline fun <T> withTypeParametersOf(declaration: FirMemberDeclaration, l: () -> T): T {
|
||||||
|
if (declaration.typeParameters.isEmpty()) return l()
|
||||||
|
val scope = FirMemberTypeParameterScope(declaration)
|
||||||
|
return withTowerDataCleanup {
|
||||||
|
addNonLocalTowerDataElement(scope.asTowerDataElement(isLocal = false))
|
||||||
|
l()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun FirMemberDeclaration.typeParameterScope(): FirMemberTypeParameterScope? {
|
||||||
|
if (typeParameters.isEmpty()) return null
|
||||||
|
return FirMemberTypeParameterScope(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun buildSecondaryConstructorParametersScope(constructor: FirConstructor): FirLocalScope =
|
||||||
|
constructor.valueParameters.fold(FirLocalScope()) { acc, param -> acc.storeVariable(param) }
|
||||||
|
|
||||||
|
@PrivateForInline
|
||||||
|
fun addInaccessibleImplicitReceiverValue(
|
||||||
|
owningClass: FirRegularClass?,
|
||||||
|
holder: SessionHolder,
|
||||||
|
) {
|
||||||
|
if (owningClass == null) return
|
||||||
|
addReceiver(
|
||||||
|
name = null,
|
||||||
|
implicitReceiverValue = InaccessibleImplicitReceiverValue(
|
||||||
|
owningClass.symbol,
|
||||||
|
owningClass.defaultType(),
|
||||||
|
holder.session,
|
||||||
|
holder.scopeSession
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
@PrivateForInline
|
||||||
|
private fun storeBackingField(property: FirProperty) {
|
||||||
|
updateLastScope { storeBackingField(property) }
|
||||||
|
}
|
||||||
|
|
||||||
|
// ANALYSIS PUBLIC API
|
||||||
|
|
||||||
|
fun getPrimaryConstructorPureParametersScope(): FirLocalScope? =
|
||||||
|
towerDataContextsForClassParts.primaryConstructorPureParametersScope
|
||||||
|
|
||||||
|
fun getPrimaryConstructorAllParametersScope(): FirLocalScope? =
|
||||||
|
towerDataContextsForClassParts.primaryConstructorAllParametersScope
|
||||||
|
|
||||||
|
@OptIn(PrivateForInline::class)
|
||||||
|
fun storeClassIfNotNested(klass: FirRegularClass) {
|
||||||
|
if (containerIfAny is FirClass<*>) return
|
||||||
|
updateLastScope { storeClass(klass) }
|
||||||
|
}
|
||||||
|
|
||||||
|
@OptIn(PrivateForInline::class)
|
||||||
|
fun storeVariable(variable: FirVariable<*>) {
|
||||||
|
updateLastScope { storeVariable(variable) }
|
||||||
|
}
|
||||||
|
|
||||||
@OptIn(PrivateForInline::class)
|
@OptIn(PrivateForInline::class)
|
||||||
inline fun <R> withInferenceSession(inferenceSession: FirInferenceSession, block: () -> R): R {
|
inline fun <R> withInferenceSession(inferenceSession: FirInferenceSession, block: () -> R): R {
|
||||||
val oldSession = this.inferenceSession
|
val oldSession = this.inferenceSession
|
||||||
@@ -93,51 +277,6 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(PrivateForInline::class)
|
@OptIn(PrivateForInline::class)
|
||||||
inline fun <T> withNewTowerDataForClassParts(newContexts: FirTowerDataContextsForClassParts, f: () -> T): T {
|
|
||||||
val old = towerDataContextsForClassParts
|
|
||||||
towerDataContextsForClassParts = newContexts
|
|
||||||
return try {
|
|
||||||
f()
|
|
||||||
} finally {
|
|
||||||
|
|
||||||
towerDataContextsForClassParts = old
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getPrimaryConstructorPureParametersScope(): FirLocalScope? =
|
|
||||||
towerDataContextsForClassParts.primaryConstructorPureParametersScope
|
|
||||||
|
|
||||||
fun getPrimaryConstructorAllParametersScope(): FirLocalScope? =
|
|
||||||
towerDataContextsForClassParts.primaryConstructorAllParametersScope
|
|
||||||
|
|
||||||
@OptIn(PrivateForInline::class)
|
|
||||||
inline fun <T> withContainer(declaration: FirDeclaration, crossinline f: () -> T): T {
|
|
||||||
val oldContainers = containers
|
|
||||||
containers = containers.add(declaration)
|
|
||||||
return try {
|
|
||||||
f()
|
|
||||||
} finally {
|
|
||||||
containers = oldContainers
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(PrivateForInline::class)
|
|
||||||
inline fun <R> withTowerDataCleanup(l: () -> R): R {
|
|
||||||
val initialContext = towerDataContext
|
|
||||||
return try {
|
|
||||||
l()
|
|
||||||
} finally {
|
|
||||||
replaceTowerDataContext(initialContext)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun <T> withTowerDataMode(mode: FirTowerDataMode, f: () -> T): T {
|
|
||||||
return withTowerModeCleanup {
|
|
||||||
towerDataMode = mode
|
|
||||||
f()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun <T> withAnonymousFunctionTowerDataContext(symbol: FirAnonymousFunctionSymbol, f: () -> T): T {
|
inline fun <T> withAnonymousFunctionTowerDataContext(symbol: FirAnonymousFunctionSymbol, f: () -> T): T {
|
||||||
return withTowerModeCleanup {
|
return withTowerModeCleanup {
|
||||||
towerDataContextsForClassParts.setAnonymousFunctionContext(symbol)
|
towerDataContextsForClassParts.setAnonymousFunctionContext(symbol)
|
||||||
@@ -145,6 +284,7 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(PrivateForInline::class)
|
||||||
inline fun <T> withCallableReferenceTowerDataContext(access: FirCallableReferenceAccess, f: () -> T): T {
|
inline fun <T> withCallableReferenceTowerDataContext(access: FirCallableReferenceAccess, f: () -> T): T {
|
||||||
return withTowerModeCleanup {
|
return withTowerModeCleanup {
|
||||||
towerDataContextsForClassParts.setCallableReferenceContextIfAny(access)
|
towerDataContextsForClassParts.setCallableReferenceContextIfAny(access)
|
||||||
@@ -152,84 +292,10 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <R> withTowerModeCleanup(l: () -> R): R {
|
|
||||||
val initialMode = towerDataMode
|
|
||||||
return try {
|
|
||||||
l()
|
|
||||||
} finally {
|
|
||||||
towerDataMode = initialMode
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(PrivateForInline::class)
|
|
||||||
inline fun <R> withLambdaBeingAnalyzedInDependentContext(lambda: FirAnonymousFunctionSymbol, l: () -> R): R {
|
|
||||||
anonymousFunctionsAnalyzedInDependentContext.add(lambda)
|
|
||||||
return try {
|
|
||||||
l()
|
|
||||||
} finally {
|
|
||||||
anonymousFunctionsAnalyzedInDependentContext.remove(lambda)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
var towerDataMode: FirTowerDataMode
|
|
||||||
get() = towerDataContextsForClassParts.mode
|
|
||||||
set(value) {
|
|
||||||
towerDataContextsForClassParts.mode = value
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(PrivateForInline::class)
|
|
||||||
fun replaceTowerDataContext(newContext: FirTowerDataContext) {
|
|
||||||
towerDataContextsForClassParts.currentContext = newContext
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addNonLocalTowerDataElement(element: FirTowerDataElement) {
|
|
||||||
replaceTowerDataContext(towerDataContext.addNonLocalTowerDataElements(listOf(element)))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addNonLocalTowerDataElements(newElements: List<FirTowerDataElement>) {
|
|
||||||
replaceTowerDataContext(towerDataContext.addNonLocalTowerDataElements(newElements))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addLocalScope(localScope: FirLocalScope) {
|
|
||||||
replaceTowerDataContext(towerDataContext.addLocalScope(localScope))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun addReceiver(name: Name?, implicitReceiverValue: ImplicitReceiverValue<*>) {
|
|
||||||
replaceTowerDataContext(towerDataContext.addReceiver(name, implicitReceiverValue))
|
|
||||||
}
|
|
||||||
|
|
||||||
fun storeClassIfNotNested(klass: FirRegularClass) {
|
|
||||||
if (containerIfAny is FirClass<*>) return
|
|
||||||
updateLastScope { storeClass(klass) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun storeFunction(function: FirSimpleFunction) {
|
|
||||||
updateLastScope { storeFunction(function) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun storeVariable(variable: FirVariable<*>) {
|
|
||||||
updateLastScope { storeVariable(variable) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun storeBackingField(property: FirProperty) {
|
|
||||||
updateLastScope { storeBackingField(property) }
|
|
||||||
}
|
|
||||||
|
|
||||||
fun dropContextForAnonymousFunction(anonymousFunction: FirAnonymousFunction) {
|
fun dropContextForAnonymousFunction(anonymousFunction: FirAnonymousFunction) {
|
||||||
towerDataContextForAnonymousFunctions.remove(anonymousFunction.symbol)
|
towerDataContextForAnonymousFunctions.remove(anonymousFunction.symbol)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clear() {
|
|
||||||
towerDataContextForAnonymousFunctions.clear()
|
|
||||||
towerDataContextForCallableReferences.clear()
|
|
||||||
dataFlowAnalyzerContext.reset()
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline fun updateLastScope(transform: FirLocalScope.() -> FirLocalScope) {
|
|
||||||
val lastScope = towerDataContext.localScopes.lastOrNull() ?: return
|
|
||||||
replaceTowerDataContext(towerDataContext.setLastLocalScope(lastScope.transform()))
|
|
||||||
}
|
|
||||||
|
|
||||||
@OptIn(PrivateForInline::class)
|
@OptIn(PrivateForInline::class)
|
||||||
fun createSnapshotForLocalClasses(
|
fun createSnapshotForLocalClasses(
|
||||||
returnTypeCalculator: ReturnTypeCalculator,
|
returnTypeCalculator: ReturnTypeCalculator,
|
||||||
@@ -244,31 +310,32 @@ class BodyResolveContext(
|
|||||||
anonymousFunctionsAnalyzedInDependentContext.addAll(this@BodyResolveContext.anonymousFunctionsAnalyzedInDependentContext)
|
anonymousFunctionsAnalyzedInDependentContext.addAll(this@BodyResolveContext.anonymousFunctionsAnalyzedInDependentContext)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WITH FirElement functions
|
// withElement PUBLIC API
|
||||||
|
|
||||||
internal inline fun <T> withFile(
|
@OptIn(PrivateForInline::class)
|
||||||
|
inline fun <T> withFile(
|
||||||
file: FirFile,
|
file: FirFile,
|
||||||
holder: SessionHolder,
|
holder: SessionHolder,
|
||||||
crossinline f: () -> T
|
f: () -> T
|
||||||
): T {
|
): T {
|
||||||
clear()
|
clear()
|
||||||
@OptIn(PrivateForInline::class)
|
|
||||||
this.file = file
|
this.file = file
|
||||||
return withScopeCleanup(mutableFileImportsScope) {
|
return withScopeCleanup(fileImportsScope) {
|
||||||
withTowerDataCleanup {
|
withTowerDataCleanup {
|
||||||
val importingScopes = createImportingScopes(file, holder.session, holder.scopeSession)
|
val importingScopes = createImportingScopes(file, holder.session, holder.scopeSession)
|
||||||
mutableFileImportsScope += importingScopes
|
fileImportsScope += importingScopes
|
||||||
addNonLocalTowerDataElements(importingScopes.map { it.asTowerDataElement(isLocal = false) })
|
addNonLocalTowerDataElements(importingScopes.map { it.asTowerDataElement(isLocal = false) })
|
||||||
f()
|
f()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> withRegularClass(
|
@OptIn(PrivateForInline::class)
|
||||||
|
fun <T> withRegularClass(
|
||||||
regularClass: FirRegularClass,
|
regularClass: FirRegularClass,
|
||||||
holder: SessionHolder,
|
holder: SessionHolder,
|
||||||
forContracts: Boolean = false,
|
forContracts: Boolean = false,
|
||||||
crossinline f: () -> T
|
f: () -> T
|
||||||
): T {
|
): T {
|
||||||
storeClassIfNotNested(regularClass)
|
storeClassIfNotNested(regularClass)
|
||||||
if (forContracts) {
|
if (forContracts) {
|
||||||
@@ -291,6 +358,7 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(PrivateForInline::class)
|
||||||
inline fun <T> withAnonymousObject(
|
inline fun <T> withAnonymousObject(
|
||||||
anonymousObject: FirAnonymousObject,
|
anonymousObject: FirAnonymousObject,
|
||||||
holder: SessionHolder,
|
holder: SessionHolder,
|
||||||
@@ -301,7 +369,7 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> withScopesForClass(
|
fun <T> withScopesForClass(
|
||||||
owner: FirClass<*>,
|
owner: FirClass<*>,
|
||||||
holder: SessionHolder,
|
holder: SessionHolder,
|
||||||
f: () -> T
|
f: () -> T
|
||||||
@@ -362,7 +430,7 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun FirConstructor.scopesWithPrimaryConstructorParameters(
|
private fun FirConstructor.scopesWithPrimaryConstructorParameters(
|
||||||
ownerClass: FirClass<*>
|
ownerClass: FirClass<*>
|
||||||
): Pair<FirLocalScope, FirLocalScope> {
|
): Pair<FirLocalScope, FirLocalScope> {
|
||||||
var parameterScope = FirLocalScope()
|
var parameterScope = FirLocalScope()
|
||||||
@@ -378,9 +446,10 @@ class BodyResolveContext(
|
|||||||
return parameterScope to allScope
|
return parameterScope to allScope
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(PrivateForInline::class)
|
||||||
inline fun <T> withSimpleFunction(
|
inline fun <T> withSimpleFunction(
|
||||||
simpleFunction: FirSimpleFunction,
|
simpleFunction: FirSimpleFunction,
|
||||||
crossinline f: () -> T
|
f: () -> T
|
||||||
): T {
|
): T {
|
||||||
if (containerIfAny !is FirClass<*>) {
|
if (containerIfAny !is FirClass<*>) {
|
||||||
storeFunction(simpleFunction)
|
storeFunction(simpleFunction)
|
||||||
@@ -391,10 +460,11 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> forFunctionBody(
|
@OptIn(PrivateForInline::class)
|
||||||
|
fun <T> forFunctionBody(
|
||||||
function: FirFunction<*>,
|
function: FirFunction<*>,
|
||||||
holder: SessionHolder,
|
holder: SessionHolder,
|
||||||
crossinline f: () -> T
|
f: () -> T
|
||||||
): T {
|
): T {
|
||||||
return withTowerDataCleanup {
|
return withTowerDataCleanup {
|
||||||
addLocalScope(FirLocalScope())
|
addLocalScope(FirLocalScope())
|
||||||
@@ -407,9 +477,10 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> forConstructorBody(
|
@OptIn(PrivateForInline::class)
|
||||||
|
fun <T> forConstructorBody(
|
||||||
constructor: FirConstructor,
|
constructor: FirConstructor,
|
||||||
crossinline f: () -> T
|
f: () -> T
|
||||||
): T {
|
): T {
|
||||||
return if (constructor.isPrimary) {
|
return if (constructor.isPrimary) {
|
||||||
/*
|
/*
|
||||||
@@ -429,11 +500,12 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> withAnonymousFunction(
|
@OptIn(PrivateForInline::class)
|
||||||
|
fun <T> withAnonymousFunction(
|
||||||
anonymousFunction: FirAnonymousFunction,
|
anonymousFunction: FirAnonymousFunction,
|
||||||
holder: SessionHolder,
|
holder: SessionHolder,
|
||||||
mode: ResolutionMode,
|
mode: ResolutionMode,
|
||||||
crossinline f: () -> T
|
f: () -> T
|
||||||
): T {
|
): T {
|
||||||
if (mode !is ResolutionMode.LambdaResolution) {
|
if (mode !is ResolutionMode.LambdaResolution) {
|
||||||
towerDataContextForAnonymousFunctions[anonymousFunction.symbol] = towerDataContext
|
towerDataContextForAnonymousFunctions[anonymousFunction.symbol] = towerDataContext
|
||||||
@@ -457,9 +529,10 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(PrivateForInline::class)
|
||||||
inline fun <T> withField(
|
inline fun <T> withField(
|
||||||
field: FirField,
|
field: FirField,
|
||||||
crossinline f: () -> T
|
f: () -> T
|
||||||
): T {
|
): T {
|
||||||
return withTowerDataMode(FirTowerDataMode.CONSTRUCTOR_HEADER) {
|
return withTowerDataMode(FirTowerDataMode.CONSTRUCTOR_HEADER) {
|
||||||
withContainer(field) {
|
withContainer(field) {
|
||||||
@@ -471,13 +544,15 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(PrivateForInline::class)
|
||||||
inline fun <T> forEnumEntry(
|
inline fun <T> forEnumEntry(
|
||||||
crossinline f: () -> T
|
f: () -> T
|
||||||
): T = withTowerDataMode(FirTowerDataMode.CONSTRUCTOR_HEADER, f)
|
): T = withTowerDataMode(FirTowerDataMode.CONSTRUCTOR_HEADER, f)
|
||||||
|
|
||||||
|
@OptIn(PrivateForInline::class)
|
||||||
inline fun <T> withAnonymousInitializer(
|
inline fun <T> withAnonymousInitializer(
|
||||||
anonymousInitializer: FirAnonymousInitializer,
|
anonymousInitializer: FirAnonymousInitializer,
|
||||||
crossinline f: () -> T
|
f: () -> T
|
||||||
): T {
|
): T {
|
||||||
return withTowerDataCleanup {
|
return withTowerDataCleanup {
|
||||||
getPrimaryConstructorPureParametersScope()?.let { addLocalScope(it) }
|
getPrimaryConstructorPureParametersScope()?.let { addLocalScope(it) }
|
||||||
@@ -486,29 +561,32 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(PrivateForInline::class)
|
||||||
inline fun <T> withValueParameter(
|
inline fun <T> withValueParameter(
|
||||||
valueParameter: FirValueParameter,
|
valueParameter: FirValueParameter,
|
||||||
crossinline f: () -> T
|
f: () -> T
|
||||||
): T {
|
): T {
|
||||||
storeVariable(valueParameter)
|
storeVariable(valueParameter)
|
||||||
return withContainer(valueParameter, f)
|
return withContainer(valueParameter, f)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@OptIn(PrivateForInline::class)
|
||||||
inline fun <T> withProperty(
|
inline fun <T> withProperty(
|
||||||
property: FirProperty,
|
property: FirProperty,
|
||||||
crossinline f: () -> T
|
f: () -> T
|
||||||
): T {
|
): T {
|
||||||
return withTypeParametersOf(property) {
|
return withTypeParametersOf(property) {
|
||||||
withContainer(property, f)
|
withContainer(property, f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> withPropertyAccessor(
|
@OptIn(PrivateForInline::class)
|
||||||
|
fun <T> withPropertyAccessor(
|
||||||
property: FirProperty,
|
property: FirProperty,
|
||||||
accessor: FirPropertyAccessor,
|
accessor: FirPropertyAccessor,
|
||||||
holder: SessionHolder,
|
holder: SessionHolder,
|
||||||
forContracts: Boolean = false,
|
forContracts: Boolean = false,
|
||||||
crossinline f: () -> T
|
f: () -> T
|
||||||
): T {
|
): T {
|
||||||
if (accessor is FirDefaultPropertyAccessor || accessor.body == null) {
|
if (accessor is FirDefaultPropertyAccessor || accessor.body == null) {
|
||||||
return withContainer(accessor, f)
|
return withContainer(accessor, f)
|
||||||
@@ -527,7 +605,8 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> forPropertyInitializer(crossinline f: () -> T): T {
|
@OptIn(PrivateForInline::class)
|
||||||
|
inline fun <T> forPropertyInitializer(f: () -> T): T {
|
||||||
return withTowerDataCleanup {
|
return withTowerDataCleanup {
|
||||||
getPrimaryConstructorPureParametersScope()?.let { addLocalScope(it) }
|
getPrimaryConstructorPureParametersScope()?.let { addLocalScope(it) }
|
||||||
f()
|
f()
|
||||||
@@ -539,7 +618,7 @@ class BodyResolveContext(
|
|||||||
delegateExpression: FirExpression,
|
delegateExpression: FirExpression,
|
||||||
resolutionContext: ResolutionContext,
|
resolutionContext: ResolutionContext,
|
||||||
callCompleter: FirCallCompleter,
|
callCompleter: FirCallCompleter,
|
||||||
crossinline f: FirDelegatedPropertyInferenceSession.() -> T
|
f: FirDelegatedPropertyInferenceSession.() -> T
|
||||||
) {
|
) {
|
||||||
val inferenceSession = FirDelegatedPropertyInferenceSession(
|
val inferenceSession = FirDelegatedPropertyInferenceSession(
|
||||||
property,
|
property,
|
||||||
@@ -553,60 +632,21 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> withLabelAndReceiverType(
|
@OptIn(PrivateForInline::class)
|
||||||
labelName: Name?,
|
inline fun <T> withConstructor(constructor: FirConstructor, f: () -> T): T =
|
||||||
owner: FirCallableDeclaration<*>,
|
|
||||||
type: ConeKotlinType?,
|
|
||||||
holder: SessionHolder,
|
|
||||||
f: () -> T
|
|
||||||
): T = withTowerDataCleanup {
|
|
||||||
if (type != null) {
|
|
||||||
val receiver = ImplicitExtensionReceiverValue(
|
|
||||||
owner.symbol,
|
|
||||||
type,
|
|
||||||
holder.session,
|
|
||||||
holder.scopeSession
|
|
||||||
)
|
|
||||||
addReceiver(labelName, receiver)
|
|
||||||
}
|
|
||||||
|
|
||||||
f()
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun <T> withTypeParametersOf(declaration: FirMemberDeclaration, crossinline l: () -> T): T {
|
|
||||||
val scope = declaration.typeParameterScope()
|
|
||||||
return withTowerDataCleanup {
|
|
||||||
scope?.let { addNonLocalTowerDataElement(it.asTowerDataElement(isLocal = false)) }
|
|
||||||
l()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun FirMemberDeclaration.typeParameterScope(): FirMemberTypeParameterScope? {
|
|
||||||
if (typeParameters.isEmpty()) return null
|
|
||||||
return FirMemberTypeParameterScope(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
inline fun <T> withConstructor(constructor: FirConstructor, crossinline f: () -> T): T =
|
|
||||||
withContainer(constructor, f)
|
withContainer(constructor, f)
|
||||||
|
|
||||||
|
@OptIn(PrivateForInline::class)
|
||||||
inline fun <T> forConstructorParameters(
|
inline fun <T> forConstructorParameters(
|
||||||
constructor: FirConstructor,
|
constructor: FirConstructor,
|
||||||
owningClass: FirRegularClass?,
|
owningClass: FirRegularClass?,
|
||||||
holder: SessionHolder,
|
holder: SessionHolder,
|
||||||
crossinline f: () -> T
|
f: () -> T
|
||||||
): T {
|
): T {
|
||||||
// Default values of constructor can't access members of constructing class
|
// Default values of constructor can't access members of constructing class
|
||||||
return withTowerDataMode(FirTowerDataMode.CONSTRUCTOR_HEADER) {
|
return withTowerDataMode(FirTowerDataMode.CONSTRUCTOR_HEADER) {
|
||||||
if (owningClass != null && !constructor.isPrimary) {
|
if (!constructor.isPrimary) {
|
||||||
addReceiver(
|
addInaccessibleImplicitReceiverValue(owningClass, holder)
|
||||||
null,
|
|
||||||
InaccessibleImplicitReceiverValue(
|
|
||||||
owningClass.symbol,
|
|
||||||
owningClass.defaultType(),
|
|
||||||
holder.session,
|
|
||||||
holder.scopeSession
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
withTowerDataCleanup {
|
withTowerDataCleanup {
|
||||||
addLocalScope(FirLocalScope())
|
addLocalScope(FirLocalScope())
|
||||||
@@ -615,11 +655,12 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> forDelegatedConstructor(
|
@OptIn(PrivateForInline::class)
|
||||||
|
fun <T> forDelegatedConstructor(
|
||||||
constructor: FirConstructor,
|
constructor: FirConstructor,
|
||||||
owningClass: FirRegularClass?,
|
owningClass: FirRegularClass?,
|
||||||
holder: SessionHolder,
|
holder: SessionHolder,
|
||||||
crossinline f: () -> T
|
f: () -> T
|
||||||
): T {
|
): T {
|
||||||
return withTowerDataMode(FirTowerDataMode.CONSTRUCTOR_HEADER) {
|
return withTowerDataMode(FirTowerDataMode.CONSTRUCTOR_HEADER) {
|
||||||
if (constructor.isPrimary) {
|
if (constructor.isPrimary) {
|
||||||
@@ -630,17 +671,7 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
} ?: f()
|
} ?: f()
|
||||||
} else {
|
} else {
|
||||||
if (owningClass != null) {
|
addInaccessibleImplicitReceiverValue(owningClass, holder)
|
||||||
addReceiver(
|
|
||||||
null,
|
|
||||||
InaccessibleImplicitReceiverValue(
|
|
||||||
owningClass.symbol,
|
|
||||||
owningClass.defaultType(),
|
|
||||||
holder.session,
|
|
||||||
holder.scopeSession
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
withTowerDataCleanup {
|
withTowerDataCleanup {
|
||||||
addLocalScope(buildSecondaryConstructorParametersScope(constructor))
|
addLocalScope(buildSecondaryConstructorParametersScope(constructor))
|
||||||
constructor.valueParameters.forEach { storeVariable(it) }
|
constructor.valueParameters.forEach { storeVariable(it) }
|
||||||
@@ -650,9 +681,6 @@ class BodyResolveContext(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildSecondaryConstructorParametersScope(constructor: FirConstructor): FirLocalScope =
|
|
||||||
constructor.valueParameters.fold(FirLocalScope()) { acc, param -> acc.storeVariable(param) }
|
|
||||||
|
|
||||||
fun storeCallableReferenceContext(callableReferenceAccess: FirCallableReferenceAccess) {
|
fun storeCallableReferenceContext(callableReferenceAccess: FirCallableReferenceAccess) {
|
||||||
towerDataContextForCallableReferences[callableReferenceAccess] = towerDataContext
|
towerDataContextForCallableReferences[callableReferenceAccess] = towerDataContext
|
||||||
}
|
}
|
||||||
@@ -661,12 +689,13 @@ class BodyResolveContext(
|
|||||||
towerDataContextForCallableReferences.remove(callableReferenceAccess)
|
towerDataContextForCallableReferences.remove(callableReferenceAccess)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> withWhenExpression(whenExpression: FirWhenExpression, crossinline f: () -> T): T {
|
fun <T> withWhenExpression(whenExpression: FirWhenExpression, f: () -> T): T {
|
||||||
if (whenExpression.subjectVariable == null) return f()
|
if (whenExpression.subjectVariable == null) return f()
|
||||||
return forBlock(f)
|
return forBlock(f)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun <T> forBlock(crossinline f: () -> T): T {
|
@OptIn(PrivateForInline::class)
|
||||||
|
inline fun <T> forBlock(f: () -> T): T {
|
||||||
return withTowerDataCleanup {
|
return withTowerDataCleanup {
|
||||||
addLocalScope(FirLocalScope())
|
addLocalScope(FirLocalScope())
|
||||||
f()
|
f()
|
||||||
|
|||||||
-20
@@ -21,7 +21,6 @@ import org.jetbrains.kotlin.fir.expressions.builder.buildUnitExpression
|
|||||||
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference
|
||||||
import org.jetbrains.kotlin.fir.resolve.*
|
import org.jetbrains.kotlin.fir.resolve.*
|
||||||
import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate
|
import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate
|
||||||
import org.jetbrains.kotlin.fir.resolve.calls.ImplicitExtensionReceiverValue
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.dfa.FirControlFlowGraphReferenceImpl
|
import org.jetbrains.kotlin.fir.resolve.dfa.FirControlFlowGraphReferenceImpl
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.extractLambdaInfoFromFunctionalType
|
import org.jetbrains.kotlin.fir.resolve.inference.extractLambdaInfoFromFunctionalType
|
||||||
import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType
|
import org.jetbrains.kotlin.fir.resolve.inference.isSuspendFunctionType
|
||||||
@@ -773,25 +772,6 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
protected inline fun <T> withLabelAndReceiverType(
|
|
||||||
labelName: Name?,
|
|
||||||
owner: FirCallableDeclaration<*>,
|
|
||||||
type: ConeKotlinType?,
|
|
||||||
block: () -> T
|
|
||||||
): T = context.withTowerDataCleanup {
|
|
||||||
if (type != null) {
|
|
||||||
val receiver = ImplicitExtensionReceiverValue(
|
|
||||||
owner.symbol,
|
|
||||||
type,
|
|
||||||
components.session,
|
|
||||||
components.scopeSession
|
|
||||||
)
|
|
||||||
context.addReceiver(labelName, receiver)
|
|
||||||
}
|
|
||||||
|
|
||||||
block()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun storeVariableReturnType(variable: FirVariable<*>) {
|
private fun storeVariableReturnType(variable: FirVariable<*>) {
|
||||||
val initializer = variable.initializer
|
val initializer = variable.initializer
|
||||||
if (variable.returnTypeRef is FirImplicitTypeRef) {
|
if (variable.returnTypeRef is FirImplicitTypeRef) {
|
||||||
|
|||||||
Reference in New Issue
Block a user