Drop location parameter from ResolutionScope::definitelyDoesNotContainName
definitelyDoesNotContainName is called too eagerly sometimes and it leads to obviously redundant lookups The idea is to put responsibility for calling recordLookup to resolution itself
This commit is contained in:
@@ -241,11 +241,7 @@ class FileScopeFactory(
|
||||
|
||||
override fun computeImportedNames() = packageView.memberScope.computeAllNames()
|
||||
|
||||
override fun definitelyDoesNotContainName(name: Name, location: LookupLocation): Boolean {
|
||||
if (names?.let { name in it } != false) return false
|
||||
packageView.memberScope.recordLookup(name, location)
|
||||
return true
|
||||
}
|
||||
override fun definitelyDoesNotContainName(name: Name) = names?.let { name !in it } == true
|
||||
|
||||
override fun toString() = "Scope for current package (${filteringKind.name})"
|
||||
|
||||
|
||||
@@ -197,13 +197,7 @@ class LazyImportResolver(
|
||||
indexedImports.imports.flatMapToNullable(hashSetOf()) { getImportScope(it).computeImportedNames() }
|
||||
}
|
||||
|
||||
fun definitelyDoesNotContainName(name: Name, location: LookupLocation): Boolean {
|
||||
if (allNames?.let { name in it } != false) return false
|
||||
indexedImports.importsForName(name).forEach {
|
||||
getImportScope(it).recordLookup(name, location)
|
||||
}
|
||||
return true
|
||||
}
|
||||
fun definitelyDoesNotContainName(name: Name) = allNames?.let { name !in it } == true
|
||||
}
|
||||
|
||||
class LazyImportScope(
|
||||
@@ -283,6 +277,6 @@ class LazyImportScope(
|
||||
p.println("}")
|
||||
}
|
||||
|
||||
override fun definitelyDoesNotContainName(name: Name, location: LookupLocation) = importResolver.definitelyDoesNotContainName(name, location)
|
||||
override fun definitelyDoesNotContainName(name: Name) = importResolver.definitelyDoesNotContainName(name)
|
||||
override fun computeImportedNames() = importResolver.allNames
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ internal class MemberScopeTowerLevel(
|
||||
|
||||
fun definitelyDoesNotContainName(name: Name) =
|
||||
(dispatchReceiver.possibleTypes + dispatchReceiver.receiverValue.type)
|
||||
.all { !it.isDynamic() && it.memberScope.definitelyDoesNotContainName(name, location) }
|
||||
.all { !it.isDynamic() && it.memberScope.definitelyDoesNotContainName(name) }
|
||||
|
||||
private fun collectMembers(
|
||||
getMembers: ResolutionScope.(KotlinType?) -> Collection<CallableDescriptor>
|
||||
|
||||
@@ -199,8 +199,8 @@ class TowerResolver {
|
||||
private fun MemberScopeTowerLevel.mayFitForName(name: Name) =
|
||||
!definitelyDoesNotContainName(name) || !definitelyDoesNotContainName(OperatorNameConventions.INVOKE)
|
||||
|
||||
private fun ResolutionScope.mayFitForName(name: Name, location: LookupLocation) =
|
||||
!definitelyDoesNotContainName(name, location) || !definitelyDoesNotContainName(OperatorNameConventions.INVOKE, location)
|
||||
private fun ResolutionScope.mayFitForName(name: Name) =
|
||||
!definitelyDoesNotContainName(name) || !definitelyDoesNotContainName(OperatorNameConventions.INVOKE)
|
||||
|
||||
fun <C : Candidate> runWithEmptyTowerData(
|
||||
processor: ScopeTowerProcessor<C>,
|
||||
|
||||
@@ -125,6 +125,6 @@ abstract class LexicalScopeStorage(
|
||||
return result
|
||||
}
|
||||
|
||||
override fun definitelyDoesNotContainName(name: Name, location: LookupLocation) =
|
||||
override fun definitelyDoesNotContainName(name: Name) =
|
||||
functionsByName?.get(name) == null && variablesAndClassifiersByName?.get(name) == null
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ interface LexicalScope : HierarchicalScope {
|
||||
override val kind: LexicalScopeKind
|
||||
get() = LexicalScopeKind.EMPTY
|
||||
|
||||
override fun definitelyDoesNotContainName(name: Name, location: LookupLocation) = true
|
||||
override fun definitelyDoesNotContainName(name: Name) = true
|
||||
|
||||
override fun printStructure(p: Printer) {
|
||||
p.println("Base lexical scope with owner = $ownerDescriptor and parent = $parent")
|
||||
@@ -130,7 +130,7 @@ interface ImportingScope : HierarchicalScope {
|
||||
|
||||
override fun computeImportedNames() = emptySet<Name>()
|
||||
|
||||
override fun definitelyDoesNotContainName(name: Name, location: LookupLocation) = true
|
||||
override fun definitelyDoesNotContainName(name: Name) = true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -218,8 +218,7 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
|
||||
override fun getVariableNames() = propertyNamesLazy
|
||||
override fun getClassifierNames() = classNamesLazy
|
||||
|
||||
override fun definitelyDoesNotContainName(name: Name, location: LookupLocation): Boolean {
|
||||
recordLookup(name, location)
|
||||
override fun definitelyDoesNotContainName(name: Name): Boolean {
|
||||
return name !in functionNamesLazy && name !in propertyNamesLazy && name !in classNamesLazy
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -44,7 +44,7 @@ class InnerClassesScopeWrapper(val workerScope: MemberScope) : MemberScopeImpl()
|
||||
override fun getVariableNames() = workerScope.getVariableNames()
|
||||
override fun getClassifierNames() = workerScope.getClassifierNames()
|
||||
|
||||
override fun definitelyDoesNotContainName(name: Name, location: LookupLocation) = workerScope.definitelyDoesNotContainName(name, location)
|
||||
override fun definitelyDoesNotContainName(name: Name) = workerScope.definitelyDoesNotContainName(name)
|
||||
|
||||
override fun toString() = "Classes from $workerScope"
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ interface ResolutionScope {
|
||||
nameFilter: (Name) -> Boolean = MemberScope.ALL_NAME_FILTER
|
||||
): Collection<DeclarationDescriptor>
|
||||
|
||||
fun definitelyDoesNotContainName(name: Name, location: LookupLocation): Boolean = false
|
||||
fun definitelyDoesNotContainName(name: Name): Boolean = false
|
||||
|
||||
fun recordLookup(name: Name, location: LookupLocation) {
|
||||
getContributedFunctions(name, location)
|
||||
|
||||
@@ -83,7 +83,7 @@ class SubstitutingScope(private val workerScope: MemberScope, givenSubstitutor:
|
||||
override fun getVariableNames() = workerScope.getVariableNames()
|
||||
override fun getClassifierNames() = workerScope.getClassifierNames()
|
||||
|
||||
override fun definitelyDoesNotContainName(name: Name, location: LookupLocation) = workerScope.definitelyDoesNotContainName(name, location)
|
||||
override fun definitelyDoesNotContainName(name: Name) = workerScope.definitelyDoesNotContainName(name)
|
||||
|
||||
override fun printScopeStructure(p: Printer) {
|
||||
p.println(this::class.java.simpleName, " {")
|
||||
|
||||
@@ -231,7 +231,7 @@ public class ErrorUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean definitelyDoesNotContainName(@NotNull Name name, @NotNull LookupLocation location) {
|
||||
public boolean definitelyDoesNotContainName(@NotNull Name name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ public class ErrorUtils {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean definitelyDoesNotContainName(@NotNull Name name, @NotNull LookupLocation location) {
|
||||
public boolean definitelyDoesNotContainName(@NotNull Name name) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -107,7 +107,7 @@ class MetadataPackageFragment(
|
||||
containerSource = null, components = components, classNames = { emptyList() }
|
||||
) {
|
||||
override fun hasClass(name: Name): Boolean = hasTopLevelClass(name)
|
||||
override fun definitelyDoesNotContainName(name: Name, location: LookupLocation) = false
|
||||
override fun definitelyDoesNotContainName(name: Name) = false
|
||||
override fun getClassifierNames(): Set<Name>? = null
|
||||
})
|
||||
|
||||
|
||||
+1
-2
@@ -78,8 +78,7 @@ abstract class DeserializedMemberScope protected constructor(
|
||||
override fun getVariableNames() = variableNamesLazy
|
||||
override fun getClassifierNames(): Set<Name>? = classNames + typeAliasNames
|
||||
|
||||
override fun definitelyDoesNotContainName(name: Name, location: LookupLocation): Boolean {
|
||||
recordLookup(name, location)
|
||||
override fun definitelyDoesNotContainName(name: Name): Boolean {
|
||||
return name !in functionNamesLazy && name !in variableNamesLazy && name !in classNames && name !in typeAliasNames
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user