Minor optimization of lookup tracker records

This commit is contained in:
Alexander Udalov
2016-04-26 19:50:45 +03:00
parent 785877d1de
commit d85884426e
10 changed files with 71 additions and 33 deletions
@@ -77,7 +77,7 @@ class CompilerCallbackServicesFacadeServer(
}
}
private val lookupTracker_isDoNothing: Boolean = incrementalCompilationComponents != null && incrementalCompilationComponents.getLookupTracker() == LookupTracker.DO_NOTHING
private val lookupTracker_isDoNothing: Boolean = incrementalCompilationComponents?.getLookupTracker() === LookupTracker.DO_NOTHING
override fun lookupTracker_isDoNothing(): Boolean = lookupTracker_isDoNothing
@@ -94,7 +94,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
private fun syntheticPropertyInClassNotCached(ownerClass: ClassDescriptor, name: Name): SyntheticPropertyHolder {
fun result(descriptor: PropertyDescriptor?, getterNames: List<Name>, setterName: Name? = null): SyntheticPropertyHolder {
if (lookupTracker == LookupTracker.DO_NOTHING) {
if (lookupTracker === LookupTracker.DO_NOTHING) {
return if (descriptor == null) SyntheticPropertyHolder.EMPTY else SyntheticPropertyHolder(descriptor, emptyList())
}
@@ -17,9 +17,11 @@
package org.jetbrains.kotlin.resolve.lazy.descriptors
import com.google.common.collect.Sets
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.record
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingTrace
@@ -166,6 +168,8 @@ protected constructor(
return result.toReadOnlyList()
}
abstract fun recordLookup(name: Name, from: LookupLocation)
// Do not change this, override in concrete subclasses:
// it is very easy to compromise laziness of this class, and fail all the debugging
// a generic implementation can't do this properly
@@ -180,8 +184,4 @@ protected constructor(
p.popIndent()
p.println("}")
}
private fun recordLookup(name: Name, from: LookupLocation) {
c.lookupTracker.record(from, thisDescriptor, name)
}
}
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink
import org.jetbrains.kotlin.diagnostics.Errors
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.incremental.record
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtClassOrObject
import org.jetbrains.kotlin.psi.KtDeclaration
@@ -38,7 +39,6 @@ import org.jetbrains.kotlin.resolve.lazy.declarations.ClassMemberDeclarationProv
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.resolve.VarianceCheckerCore
import org.jetbrains.kotlin.storage.NotNullLazyValue
import org.jetbrains.kotlin.storage.NullableLazyValue
import org.jetbrains.kotlin.types.DeferredType
@@ -316,6 +316,10 @@ open class LazyClassMemberScope(
descriptor.returnType = DeferredType.create(c.storageManager, trace, { thisDescriptor.getDefaultType() })
}
override fun recordLookup(name: Name, from: LookupLocation) {
c.lookupTracker.record(from, thisDescriptor, name)
}
// Do not add details here, they may compromise the laziness during debugging
override fun toString() = "lazy scope for class ${thisDescriptor.name}"
@@ -16,8 +16,13 @@
package org.jetbrains.kotlin.resolve.lazy.descriptors
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.incremental.record
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtDeclaration
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
@@ -45,6 +50,10 @@ class LazyPackageMemberScope(
// No extra properties
}
override fun recordLookup(name: Name, from: LookupLocation) {
c.lookupTracker.record(from, thisDescriptor, name)
}
// Do not add details here, they may compromise the laziness during debugging
override fun toString() = "lazy scope for package " + thisDescriptor.name
}
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
import org.jetbrains.kotlin.incremental.record
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.BindingTrace
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
@@ -109,4 +110,8 @@ class LazyScriptClassMemberScope(
propertyDescriptor.initialize(null, null)
return propertyDescriptor
}
override fun recordLookup(name: Name, from: LookupLocation) {
c.lookupTracker.record(from, thisDescriptor, name)
}
}
@@ -1,8 +1,25 @@
/*
* Copyright 2010-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.util
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.incremental.KotlinLookupLocation
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.incremental.getScopeKind
import org.jetbrains.kotlin.incremental.record
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.resolve.DescriptorUtils
@@ -17,8 +34,13 @@ fun LookupTracker.record(expression: KtExpression, type: KotlinType) {
// Scope descriptor is function descriptor only when type is local
// Lookups for local types are not needed since all usages are compiled with the type
if (getScopeKind(scopeDescriptor) != null && !DescriptorUtils.isLocal(typeDescriptor)) {
record(KotlinLookupLocation(expression), scopeDescriptor, typeDescriptor.name)
when {
scopeDescriptor is PackageFragmentDescriptor && !DescriptorUtils.isLocal(typeDescriptor) -> {
record(KotlinLookupLocation(expression), scopeDescriptor, typeDescriptor.name)
}
scopeDescriptor is ClassDescriptor && !DescriptorUtils.isLocal(typeDescriptor) -> {
record(KotlinLookupLocation(expression), scopeDescriptor, typeDescriptor.name)
}
}
for (typeArgument in type.arguments) {
@@ -27,4 +49,3 @@ fun LookupTracker.record(expression: KtExpression, type: KotlinType) {
}
}
}
@@ -60,5 +60,5 @@ enum class NoLookupLocation : LookupLocation {
WHEN_FIND_BY_FQNAME,
WHEN_GET_COMPANION_OBJECT;
override val location: LocationInfo? = null
override val location: LocationInfo? get() = null
}
@@ -16,28 +16,27 @@
package org.jetbrains.kotlin.incremental
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
import org.jetbrains.kotlin.descriptors.ClassDescriptor
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
import org.jetbrains.kotlin.incremental.components.*
import org.jetbrains.kotlin.incremental.components.LookupLocation
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.incremental.components.Position
import org.jetbrains.kotlin.incremental.components.ScopeKind
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
import org.jetbrains.kotlin.resolve.DescriptorUtils
fun LookupTracker.record(from: LookupLocation, scopeOwner: DeclarationDescriptor, name: Name) {
if (this == LookupTracker.DO_NOTHING || from is NoLookupLocation) return
// These methods are called many times, please pay attention to performance here
fun LookupTracker.record(from: LookupLocation, scopeOwner: ClassDescriptor, name: Name) {
if (this === LookupTracker.DO_NOTHING) return
val location = from.location ?: return
val scopeKind = getScopeKind(scopeOwner) ?:
throw AssertionError("Unexpected containing declaration type: ${scopeOwner.javaClass}")
val position = if (requiresPosition) location.position else Position.NO_POSITION
record(location.filePath, position, scopeOwner.fqNameUnsafe.asString(), scopeKind, name.asString())
record(location.filePath, position, DescriptorUtils.getFqName(scopeOwner).asString(), ScopeKind.CLASSIFIER, name.asString())
}
fun getScopeKind(scopeOwner: DeclarationDescriptor) = when (scopeOwner) {
is ClassifierDescriptor -> ScopeKind.CLASSIFIER
is PackageFragmentDescriptor -> ScopeKind.PACKAGE
else -> null
}
fun LookupTracker.record(from: LookupLocation, scopeOwner: PackageFragmentDescriptor, name: Name) {
if (this === LookupTracker.DO_NOTHING) return
val location = from.location ?: return
val position = if (requiresPosition) location.position else Position.NO_POSITION
record(location.filePath, position, scopeOwner.fqName.asString(), ScopeKind.PACKAGE, name.asString())
}
@@ -271,7 +271,7 @@ class DeserializedClassDescriptor(
}
private fun recordLookup(name: Name, from: LookupLocation) {
c.components.lookupTracker.record(from, c.containingDeclaration, name)
c.components.lookupTracker.record(from, classDescriptor, name)
}
}