FIR: Get rid of obsolete local scopes optimizations

They are already filtered out (see FirTowerResolverSession#localScopes initializer)
This commit is contained in:
Denis Zharkov
2020-05-15 12:04:38 +03:00
parent e7a67c7a16
commit 475671563b
@@ -231,19 +231,15 @@ class FirTowerResolverSession internal constructor(
info: CallInfo info: CallInfo
) { ) {
processExtensionsThatHideMembers(info, explicitReceiverValue = null) processExtensionsThatHideMembers(info, explicitReceiverValue = null)
val nonEmptyLocalScopes = mutableListOf<FirScope>()
val emptyTopLevelScopes = mutableSetOf<FirScope>() val emptyTopLevelScopes = mutableSetOf<FirScope>()
val implicitReceiverValuesWithEmptyScopes = mutableSetOf<ImplicitReceiverValue<*>>() val implicitReceiverValuesWithEmptyScopes = mutableSetOf<ImplicitReceiverValue<*>>()
enumerateTowerLevels( enumerateTowerLevels(
onLocalScope = { index, scope -> onLocalScope = { index, scope ->
val result = processLevel( processLevel(
scope.toScopeTowerLevel(), info, TowerGroup.Local(index) scope.toScopeTowerLevel(), info, TowerGroup.Local(index)
) )
if (result != ProcessorAction.NONE) {
nonEmptyLocalScopes += scope
}
}, },
onNonLocalScope = l@{ index, scope -> onNonLocalScope = l@{ index, scope ->
// NB: this check does not work for variables // NB: this check does not work for variables
@@ -260,7 +256,6 @@ class FirTowerResolverSession internal constructor(
info, info,
TowerGroup.Implicit(index), TowerGroup.Implicit(index),
implicitReceiverValuesWithEmptyScopes, implicitReceiverValuesWithEmptyScopes,
nonEmptyLocalScopes,
emptyTopLevelScopes emptyTopLevelScopes
) )
} }
@@ -315,7 +310,6 @@ class FirTowerResolverSession internal constructor(
info: CallInfo, info: CallInfo,
parentGroup: TowerGroup, parentGroup: TowerGroup,
implicitReceiverValuesWithEmptyScopes: MutableSet<ImplicitReceiverValue<*>>, implicitReceiverValuesWithEmptyScopes: MutableSet<ImplicitReceiverValue<*>>,
nonEmptyLocalScopes: List<FirScope>,
emptyTopLevelScopes: MutableSet<FirScope> emptyTopLevelScopes: MutableSet<FirScope>
) { ) {
val implicitResult = processLevel( val implicitResult = processLevel(
@@ -327,7 +321,6 @@ class FirTowerResolverSession internal constructor(
} }
enumerateTowerLevels( enumerateTowerLevels(
localScopesToUse = nonEmptyLocalScopes,
onLocalScope = { index, scope -> onLocalScope = { index, scope ->
processLevel( processLevel(
scope.toScopeTowerLevel(extensionReceiver = receiver), scope.toScopeTowerLevel(extensionReceiver = receiver),
@@ -377,19 +370,14 @@ class FirTowerResolverSession internal constructor(
return return
} }
val nonEmptyLocalScopes = mutableListOf<FirScope>()
enumerateTowerLevels( enumerateTowerLevels(
onLocalScope = { index, scope -> onLocalScope = { index, scope ->
if (processScopeForExplicitReceiver( processScopeForExplicitReceiver(
scope, scope,
explicitReceiverValue, explicitReceiverValue,
info, info,
TowerGroup.Local(index) TowerGroup.Local(index)
) != ProcessorAction.NONE )
) {
nonEmptyLocalScopes += scope
}
}, },
onNonLocalScope = { index, scope -> onNonLocalScope = { index, scope ->
processScopeForExplicitReceiver( processScopeForExplicitReceiver(
@@ -400,7 +388,7 @@ class FirTowerResolverSession internal constructor(
) )
}, },
onImplicitReceiver = { index, implicitReceiverValue -> onImplicitReceiver = { index, implicitReceiverValue ->
processCombinationOfReceivers(implicitReceiverValue, explicitReceiverValue, info, index, nonEmptyLocalScopes) processCombinationOfReceivers(implicitReceiverValue, explicitReceiverValue, info, index)
} }
) )
} }
@@ -408,10 +396,9 @@ class FirTowerResolverSession internal constructor(
private inline fun enumerateTowerLevels( private inline fun enumerateTowerLevels(
onLocalScope: (Int, FirScope) -> Unit, onLocalScope: (Int, FirScope) -> Unit,
onNonLocalScope: (Int, FirScope) -> Unit, onNonLocalScope: (Int, FirScope) -> Unit,
onImplicitReceiver: (Int, ImplicitReceiverValue<*>) -> Unit, onImplicitReceiver: (Int, ImplicitReceiverValue<*>) -> Unit
localScopesToUse: List<FirScope> = localScopes
) { ) {
for ((index, localScope) in localScopesToUse.withIndex()) { for ((index, localScope) in localScopes.withIndex()) {
onLocalScope(index, localScope) onLocalScope(index, localScope)
} }
@@ -448,8 +435,7 @@ class FirTowerResolverSession internal constructor(
implicitReceiverValue: ImplicitReceiverValue<*>, implicitReceiverValue: ImplicitReceiverValue<*>,
explicitReceiverValue: ExpressionReceiverValue, explicitReceiverValue: ExpressionReceiverValue,
info: CallInfo, info: CallInfo,
depth: Int, depth: Int
nonEmptyLocalScopes: MutableList<FirScope>
) { ) {
// NB: companions are processed via implicitReceiverValues! // NB: companions are processed via implicitReceiverValues!
val parentGroup = TowerGroup.Implicit(depth) val parentGroup = TowerGroup.Implicit(depth)
@@ -465,7 +451,6 @@ class FirTowerResolverSession internal constructor(
) )
enumerateTowerLevels( enumerateTowerLevels(
localScopesToUse = nonEmptyLocalScopes,
onLocalScope = { index, scope -> onLocalScope = { index, scope ->
processLevelForPropertyWithInvoke( processLevelForPropertyWithInvoke(
scope.toScopeTowerLevel(extensionReceiver = implicitReceiverValue), scope.toScopeTowerLevel(extensionReceiver = implicitReceiverValue),