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:
Denis Zharkov
2017-08-24 10:56:00 +03:00
parent 37440c70e2
commit 580a7e3e4d
13 changed files with 17 additions and 29 deletions
@@ -241,11 +241,7 @@ class FileScopeFactory(
override fun computeImportedNames() = packageView.memberScope.computeAllNames() override fun computeImportedNames() = packageView.memberScope.computeAllNames()
override fun definitelyDoesNotContainName(name: Name, location: LookupLocation): Boolean { override fun definitelyDoesNotContainName(name: Name) = names?.let { name !in it } == true
if (names?.let { name in it } != false) return false
packageView.memberScope.recordLookup(name, location)
return true
}
override fun toString() = "Scope for current package (${filteringKind.name})" override fun toString() = "Scope for current package (${filteringKind.name})"
@@ -197,13 +197,7 @@ class LazyImportResolver(
indexedImports.imports.flatMapToNullable(hashSetOf()) { getImportScope(it).computeImportedNames() } indexedImports.imports.flatMapToNullable(hashSetOf()) { getImportScope(it).computeImportedNames() }
} }
fun definitelyDoesNotContainName(name: Name, location: LookupLocation): Boolean { fun definitelyDoesNotContainName(name: Name) = allNames?.let { name !in it } == true
if (allNames?.let { name in it } != false) return false
indexedImports.importsForName(name).forEach {
getImportScope(it).recordLookup(name, location)
}
return true
}
} }
class LazyImportScope( class LazyImportScope(
@@ -283,6 +277,6 @@ class LazyImportScope(
p.println("}") 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 override fun computeImportedNames() = importResolver.allNames
} }
@@ -89,7 +89,7 @@ internal class MemberScopeTowerLevel(
fun definitelyDoesNotContainName(name: Name) = fun definitelyDoesNotContainName(name: Name) =
(dispatchReceiver.possibleTypes + dispatchReceiver.receiverValue.type) (dispatchReceiver.possibleTypes + dispatchReceiver.receiverValue.type)
.all { !it.isDynamic() && it.memberScope.definitelyDoesNotContainName(name, location) } .all { !it.isDynamic() && it.memberScope.definitelyDoesNotContainName(name) }
private fun collectMembers( private fun collectMembers(
getMembers: ResolutionScope.(KotlinType?) -> Collection<CallableDescriptor> getMembers: ResolutionScope.(KotlinType?) -> Collection<CallableDescriptor>
@@ -199,8 +199,8 @@ class TowerResolver {
private fun MemberScopeTowerLevel.mayFitForName(name: Name) = private fun MemberScopeTowerLevel.mayFitForName(name: Name) =
!definitelyDoesNotContainName(name) || !definitelyDoesNotContainName(OperatorNameConventions.INVOKE) !definitelyDoesNotContainName(name) || !definitelyDoesNotContainName(OperatorNameConventions.INVOKE)
private fun ResolutionScope.mayFitForName(name: Name, location: LookupLocation) = private fun ResolutionScope.mayFitForName(name: Name) =
!definitelyDoesNotContainName(name, location) || !definitelyDoesNotContainName(OperatorNameConventions.INVOKE, location) !definitelyDoesNotContainName(name) || !definitelyDoesNotContainName(OperatorNameConventions.INVOKE)
fun <C : Candidate> runWithEmptyTowerData( fun <C : Candidate> runWithEmptyTowerData(
processor: ScopeTowerProcessor<C>, processor: ScopeTowerProcessor<C>,
@@ -125,6 +125,6 @@ abstract class LexicalScopeStorage(
return result return result
} }
override fun definitelyDoesNotContainName(name: Name, location: LookupLocation) = override fun definitelyDoesNotContainName(name: Name) =
functionsByName?.get(name) == null && variablesAndClassifiersByName?.get(name) == null functionsByName?.get(name) == null && variablesAndClassifiersByName?.get(name) == null
} }
@@ -55,7 +55,7 @@ interface LexicalScope : HierarchicalScope {
override val kind: LexicalScopeKind override val kind: LexicalScopeKind
get() = LexicalScopeKind.EMPTY get() = LexicalScopeKind.EMPTY
override fun definitelyDoesNotContainName(name: Name, location: LookupLocation) = true override fun definitelyDoesNotContainName(name: Name) = true
override fun printStructure(p: Printer) { override fun printStructure(p: Printer) {
p.println("Base lexical scope with owner = $ownerDescriptor and parent = $parent") 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 computeImportedNames() = emptySet<Name>()
override fun definitelyDoesNotContainName(name: Name, location: LookupLocation) = true override fun definitelyDoesNotContainName(name: Name) = true
} }
} }
@@ -218,8 +218,7 @@ abstract class LazyJavaScope(protected val c: LazyJavaResolverContext) : MemberS
override fun getVariableNames() = propertyNamesLazy override fun getVariableNames() = propertyNamesLazy
override fun getClassifierNames() = classNamesLazy override fun getClassifierNames() = classNamesLazy
override fun definitelyDoesNotContainName(name: Name, location: LookupLocation): Boolean { override fun definitelyDoesNotContainName(name: Name): Boolean {
recordLookup(name, location)
return name !in functionNamesLazy && name !in propertyNamesLazy && name !in classNamesLazy return name !in functionNamesLazy && name !in propertyNamesLazy && name !in classNamesLazy
} }
@@ -44,7 +44,7 @@ class InnerClassesScopeWrapper(val workerScope: MemberScope) : MemberScopeImpl()
override fun getVariableNames() = workerScope.getVariableNames() override fun getVariableNames() = workerScope.getVariableNames()
override fun getClassifierNames() = workerScope.getClassifierNames() 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" override fun toString() = "Classes from $workerScope"
} }
@@ -40,7 +40,7 @@ interface ResolutionScope {
nameFilter: (Name) -> Boolean = MemberScope.ALL_NAME_FILTER nameFilter: (Name) -> Boolean = MemberScope.ALL_NAME_FILTER
): Collection<DeclarationDescriptor> ): Collection<DeclarationDescriptor>
fun definitelyDoesNotContainName(name: Name, location: LookupLocation): Boolean = false fun definitelyDoesNotContainName(name: Name): Boolean = false
fun recordLookup(name: Name, location: LookupLocation) { fun recordLookup(name: Name, location: LookupLocation) {
getContributedFunctions(name, location) getContributedFunctions(name, location)
@@ -83,7 +83,7 @@ class SubstitutingScope(private val workerScope: MemberScope, givenSubstitutor:
override fun getVariableNames() = workerScope.getVariableNames() override fun getVariableNames() = workerScope.getVariableNames()
override fun getClassifierNames() = workerScope.getClassifierNames() 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) { override fun printScopeStructure(p: Printer) {
p.println(this::class.java.simpleName, " {") p.println(this::class.java.simpleName, " {")
@@ -231,7 +231,7 @@ public class ErrorUtils {
} }
@Override @Override
public boolean definitelyDoesNotContainName(@NotNull Name name, @NotNull LookupLocation location) { public boolean definitelyDoesNotContainName(@NotNull Name name) {
return false; return false;
} }
@@ -306,7 +306,7 @@ public class ErrorUtils {
} }
@Override @Override
public boolean definitelyDoesNotContainName(@NotNull Name name, @NotNull LookupLocation location) { public boolean definitelyDoesNotContainName(@NotNull Name name) {
return false; return false;
} }
@@ -107,7 +107,7 @@ class MetadataPackageFragment(
containerSource = null, components = components, classNames = { emptyList() } containerSource = null, components = components, classNames = { emptyList() }
) { ) {
override fun hasClass(name: Name): Boolean = hasTopLevelClass(name) 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 override fun getClassifierNames(): Set<Name>? = null
}) })
@@ -78,8 +78,7 @@ abstract class DeserializedMemberScope protected constructor(
override fun getVariableNames() = variableNamesLazy override fun getVariableNames() = variableNamesLazy
override fun getClassifierNames(): Set<Name>? = classNames + typeAliasNames override fun getClassifierNames(): Set<Name>? = classNames + typeAliasNames
override fun definitelyDoesNotContainName(name: Name, location: LookupLocation): Boolean { override fun definitelyDoesNotContainName(name: Name): Boolean {
recordLookup(name, location)
return name !in functionNamesLazy && name !in variableNamesLazy && name !in classNames && name !in typeAliasNames return name !in functionNamesLazy && name !in variableNamesLazy && name !in classNames && name !in typeAliasNames
} }