Minor optimization of lookup tracker records
This commit is contained in:
+1
-1
@@ -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
|
override fun lookupTracker_isDoNothing(): Boolean = lookupTracker_isDoNothing
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -94,7 +94,7 @@ class JavaSyntheticPropertiesScope(storageManager: StorageManager, private val l
|
|||||||
private fun syntheticPropertyInClassNotCached(ownerClass: ClassDescriptor, name: Name): SyntheticPropertyHolder {
|
private fun syntheticPropertyInClassNotCached(ownerClass: ClassDescriptor, name: Name): SyntheticPropertyHolder {
|
||||||
|
|
||||||
fun result(descriptor: PropertyDescriptor?, getterNames: List<Name>, setterName: Name? = null): 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())
|
return if (descriptor == null) SyntheticPropertyHolder.EMPTY else SyntheticPropertyHolder(descriptor, emptyList())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+6
-6
@@ -17,9 +17,11 @@
|
|||||||
package org.jetbrains.kotlin.resolve.lazy.descriptors
|
package org.jetbrains.kotlin.resolve.lazy.descriptors
|
||||||
|
|
||||||
import com.google.common.collect.Sets
|
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.components.LookupLocation
|
||||||
import org.jetbrains.kotlin.incremental.record
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.*
|
import org.jetbrains.kotlin.psi.*
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||||
@@ -166,6 +168,8 @@ protected constructor(
|
|||||||
return result.toReadOnlyList()
|
return result.toReadOnlyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract fun recordLookup(name: Name, from: LookupLocation)
|
||||||
|
|
||||||
// Do not change this, override in concrete subclasses:
|
// Do not change this, override in concrete subclasses:
|
||||||
// it is very easy to compromise laziness of this class, and fail all the debugging
|
// it is very easy to compromise laziness of this class, and fail all the debugging
|
||||||
// a generic implementation can't do this properly
|
// a generic implementation can't do this properly
|
||||||
@@ -180,8 +184,4 @@ protected constructor(
|
|||||||
p.popIndent()
|
p.popIndent()
|
||||||
p.println("}")
|
p.println("}")
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun recordLookup(name: Name, from: LookupLocation) {
|
|
||||||
c.lookupTracker.record(from, thisDescriptor, name)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
|||||||
import org.jetbrains.kotlin.diagnostics.Errors
|
import org.jetbrains.kotlin.diagnostics.Errors
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
|
import org.jetbrains.kotlin.incremental.record
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
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.DescriptorKindFilter
|
||||||
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
import org.jetbrains.kotlin.resolve.scopes.LexicalScope
|
||||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||||
import org.jetbrains.kotlin.resolve.VarianceCheckerCore
|
|
||||||
import org.jetbrains.kotlin.storage.NotNullLazyValue
|
import org.jetbrains.kotlin.storage.NotNullLazyValue
|
||||||
import org.jetbrains.kotlin.storage.NullableLazyValue
|
import org.jetbrains.kotlin.storage.NullableLazyValue
|
||||||
import org.jetbrains.kotlin.types.DeferredType
|
import org.jetbrains.kotlin.types.DeferredType
|
||||||
@@ -316,6 +316,10 @@ open class LazyClassMemberScope(
|
|||||||
descriptor.returnType = DeferredType.create(c.storageManager, trace, { thisDescriptor.getDefaultType() })
|
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
|
// Do not add details here, they may compromise the laziness during debugging
|
||||||
override fun toString() = "lazy scope for class ${thisDescriptor.name}"
|
override fun toString() = "lazy scope for class ${thisDescriptor.name}"
|
||||||
|
|
||||||
|
|||||||
+10
-1
@@ -16,8 +16,13 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.resolve.lazy.descriptors
|
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.components.NoLookupLocation
|
||||||
|
import org.jetbrains.kotlin.incremental.record
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.KtDeclaration
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||||
@@ -45,6 +50,10 @@ class LazyPackageMemberScope(
|
|||||||
// No extra properties
|
// 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
|
// Do not add details here, they may compromise the laziness during debugging
|
||||||
override fun toString() = "lazy scope for package " + thisDescriptor.name
|
override fun toString() = "lazy scope for package " + thisDescriptor.name
|
||||||
}
|
}
|
||||||
|
|||||||
+5
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.descriptors.impl.PropertyDescriptorImpl
|
|||||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||||
|
import org.jetbrains.kotlin.incremental.record
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.BindingTrace
|
import org.jetbrains.kotlin.resolve.BindingTrace
|
||||||
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
import org.jetbrains.kotlin.resolve.lazy.ResolveSession
|
||||||
@@ -109,4 +110,8 @@ class LazyScriptClassMemberScope(
|
|||||||
propertyDescriptor.initialize(null, null)
|
propertyDescriptor.initialize(null, null)
|
||||||
return propertyDescriptor
|
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
|
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.KotlinLookupLocation
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||||
import org.jetbrains.kotlin.incremental.getScopeKind
|
|
||||||
import org.jetbrains.kotlin.incremental.record
|
import org.jetbrains.kotlin.incremental.record
|
||||||
import org.jetbrains.kotlin.psi.KtExpression
|
import org.jetbrains.kotlin.psi.KtExpression
|
||||||
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
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
|
// 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
|
// Lookups for local types are not needed since all usages are compiled with the type
|
||||||
if (getScopeKind(scopeDescriptor) != null && !DescriptorUtils.isLocal(typeDescriptor)) {
|
when {
|
||||||
record(KotlinLookupLocation(expression), scopeDescriptor, typeDescriptor.name)
|
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) {
|
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_FIND_BY_FQNAME,
|
||||||
WHEN_GET_COMPANION_OBJECT;
|
WHEN_GET_COMPANION_OBJECT;
|
||||||
|
|
||||||
override val location: LocationInfo? = null
|
override val location: LocationInfo? get() = null
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,28 +16,27 @@
|
|||||||
|
|
||||||
package org.jetbrains.kotlin.incremental
|
package org.jetbrains.kotlin.incremental
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
|
||||||
import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor
|
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.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||||
|
|
||||||
fun LookupTracker.record(from: LookupLocation, scopeOwner: DeclarationDescriptor, name: Name) {
|
// These methods are called many times, please pay attention to performance here
|
||||||
if (this == LookupTracker.DO_NOTHING || from is NoLookupLocation) return
|
|
||||||
|
|
||||||
|
fun LookupTracker.record(from: LookupLocation, scopeOwner: ClassDescriptor, name: Name) {
|
||||||
|
if (this === LookupTracker.DO_NOTHING) return
|
||||||
val location = from.location ?: 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
|
val position = if (requiresPosition) location.position else Position.NO_POSITION
|
||||||
|
record(location.filePath, position, DescriptorUtils.getFqName(scopeOwner).asString(), ScopeKind.CLASSIFIER, name.asString())
|
||||||
record(location.filePath, position, scopeOwner.fqNameUnsafe.asString(), scopeKind, name.asString())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getScopeKind(scopeOwner: DeclarationDescriptor) = when (scopeOwner) {
|
fun LookupTracker.record(from: LookupLocation, scopeOwner: PackageFragmentDescriptor, name: Name) {
|
||||||
is ClassifierDescriptor -> ScopeKind.CLASSIFIER
|
if (this === LookupTracker.DO_NOTHING) return
|
||||||
is PackageFragmentDescriptor -> ScopeKind.PACKAGE
|
val location = from.location ?: return
|
||||||
else -> null
|
val position = if (requiresPosition) location.position else Position.NO_POSITION
|
||||||
}
|
record(location.filePath, position, scopeOwner.fqName.asString(), ScopeKind.PACKAGE, name.asString())
|
||||||
|
}
|
||||||
|
|||||||
+1
-1
@@ -271,7 +271,7 @@ class DeserializedClassDescriptor(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun recordLookup(name: Name, from: LookupLocation) {
|
private fun recordLookup(name: Name, from: LookupLocation) {
|
||||||
c.components.lookupTracker.record(from, c.containingDeclaration, name)
|
c.components.lookupTracker.record(from, classDescriptor, name)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user