Removed lock level WRITING from LexicalWritableScope.
This commit is contained in:
@@ -724,7 +724,7 @@ public class DescriptorResolver {
|
|||||||
LexicalScopeKind.PROPERTY_HEADER);
|
LexicalScopeKind.PROPERTY_HEADER);
|
||||||
typeParameterDescriptors = resolveTypeParametersForCallableDescriptor(
|
typeParameterDescriptors = resolveTypeParametersForCallableDescriptor(
|
||||||
propertyDescriptor, writableScope, scope, typeParameters, trace);
|
propertyDescriptor, writableScope, scope, typeParameters, trace);
|
||||||
writableScope.changeLockLevel(LexicalWritableScope.LockLevel.READING);
|
writableScope.freeze();
|
||||||
resolveGenericBounds(property, propertyDescriptor, writableScope, typeParameterDescriptors, trace);
|
resolveGenericBounds(property, propertyDescriptor, writableScope, typeParameterDescriptors, trace);
|
||||||
scopeWithTypeParameters = writableScope;
|
scopeWithTypeParameters = writableScope;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -143,7 +143,6 @@ class FunctionDescriptorResolver(
|
|||||||
|
|
||||||
val typeParameterDescriptors = descriptorResolver.
|
val typeParameterDescriptors = descriptorResolver.
|
||||||
resolveTypeParametersForCallableDescriptor(functionDescriptor, innerScope, scope, function.typeParameters, trace)
|
resolveTypeParametersForCallableDescriptor(functionDescriptor, innerScope, scope, function.typeParameters, trace)
|
||||||
innerScope.changeLockLevel(LexicalWritableScope.LockLevel.BOTH)
|
|
||||||
descriptorResolver.resolveGenericBounds(function, functionDescriptor, innerScope, typeParameterDescriptors, trace)
|
descriptorResolver.resolveGenericBounds(function, functionDescriptor, innerScope, typeParameterDescriptors, trace)
|
||||||
|
|
||||||
val receiverTypeRef = function.receiverTypeReference
|
val receiverTypeRef = function.receiverTypeReference
|
||||||
@@ -156,7 +155,7 @@ class FunctionDescriptorResolver(
|
|||||||
|
|
||||||
val valueParameterDescriptors = createValueParameterDescriptors(function, functionDescriptor, innerScope, trace, expectedFunctionType)
|
val valueParameterDescriptors = createValueParameterDescriptors(function, functionDescriptor, innerScope, trace, expectedFunctionType)
|
||||||
|
|
||||||
innerScope.changeLockLevel(LexicalWritableScope.LockLevel.READING)
|
innerScope.freeze()
|
||||||
|
|
||||||
val returnType = function.typeReference?.let { typeResolver.resolveType(innerScope, it, trace, true) }
|
val returnType = function.typeReference?.let { typeResolver.resolveType(innerScope, it, trace, true) }
|
||||||
|
|
||||||
@@ -283,7 +282,6 @@ class FunctionDescriptorResolver(
|
|||||||
TraceBasedLocalRedeclarationChecker(trace),
|
TraceBasedLocalRedeclarationChecker(trace),
|
||||||
LexicalScopeKind.CONSTRUCTOR_HEADER
|
LexicalScopeKind.CONSTRUCTOR_HEADER
|
||||||
)
|
)
|
||||||
parameterScope.changeLockLevel(LexicalWritableScope.LockLevel.BOTH)
|
|
||||||
val constructor = constructorDescriptor.initialize(
|
val constructor = constructorDescriptor.initialize(
|
||||||
resolveValueParameters(constructorDescriptor, parameterScope, valueParameters, trace, null),
|
resolveValueParameters(constructorDescriptor, parameterScope, valueParameters, trace, null),
|
||||||
resolveVisibilityFromModifiers(
|
resolveVisibilityFromModifiers(
|
||||||
|
|||||||
@@ -17,8 +17,6 @@
|
|||||||
package org.jetbrains.kotlin.resolve.scopes
|
package org.jetbrains.kotlin.resolve.scopes
|
||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
import org.jetbrains.kotlin.utils.Printer
|
import org.jetbrains.kotlin.utils.Printer
|
||||||
|
|
||||||
class LexicalScopeImpl @JvmOverloads constructor(
|
class LexicalScopeImpl @JvmOverloads constructor(
|
||||||
@@ -35,12 +33,6 @@ class LexicalScopeImpl @JvmOverloads constructor(
|
|||||||
InitializeHandler().initialize()
|
InitializeHandler().initialize()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getContributedClassifier(name: Name, location: LookupLocation) = getClassifier(name)
|
|
||||||
override fun getContributedVariables(name: Name, location: LookupLocation) = getVariables(name)
|
|
||||||
|
|
||||||
override fun getContributedFunctions(name: Name, location: LookupLocation) = getFunctions(name)
|
|
||||||
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean) = addedDescriptors
|
|
||||||
|
|
||||||
override fun toString(): String = kind.toString()
|
override fun toString(): String = kind.toString()
|
||||||
|
|
||||||
override fun printStructure(p: Printer) {
|
override fun printStructure(p: Printer) {
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ import org.jetbrains.kotlin.descriptors.ClassifierDescriptor
|
|||||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||||
|
import org.jetbrains.kotlin.incremental.components.LookupLocation
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.scopes.utils.takeSnapshot
|
import org.jetbrains.kotlin.resolve.scopes.utils.takeSnapshot
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -36,6 +37,14 @@ abstract class LexicalScopeStorage(
|
|||||||
private var functionsByName: MutableMap<Name, IntList>? = null
|
private var functionsByName: MutableMap<Name, IntList>? = null
|
||||||
private var variablesAndClassifiersByName: MutableMap<Name, IntList>? = null
|
private var variablesAndClassifiersByName: MutableMap<Name, IntList>? = null
|
||||||
|
|
||||||
|
override fun getContributedClassifier(name: Name, location: LookupLocation) = variableOrClassDescriptorByName(name) as? ClassifierDescriptor
|
||||||
|
override fun getContributedVariables(name: Name, location: LookupLocation) = listOfNotNull(variableOrClassDescriptorByName(name) as? VariableDescriptor)
|
||||||
|
|
||||||
|
override fun getContributedFunctions(name: Name, location: LookupLocation) = functionsByName(name)
|
||||||
|
|
||||||
|
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
|
||||||
|
= addedDescriptors
|
||||||
|
|
||||||
protected fun addVariableOrClassDescriptor(descriptor: DeclarationDescriptor) {
|
protected fun addVariableOrClassDescriptor(descriptor: DeclarationDescriptor) {
|
||||||
val name = descriptor.name
|
val name = descriptor.name
|
||||||
val descriptorIndex = addDescriptor(descriptor)
|
val descriptorIndex = addDescriptor(descriptor)
|
||||||
@@ -72,8 +81,8 @@ abstract class LexicalScopeStorage(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun functionsByName(name: Name, descriptorLimit: Int = addedDescriptors.size): List<FunctionDescriptor>? {
|
protected fun functionsByName(name: Name, descriptorLimit: Int = addedDescriptors.size): List<FunctionDescriptor> {
|
||||||
if (descriptorLimit == 0) return null
|
if (descriptorLimit == 0) return emptyList()
|
||||||
|
|
||||||
var list = functionsByName?.get(name)
|
var list = functionsByName?.get(name)
|
||||||
while (list != null) {
|
while (list != null) {
|
||||||
@@ -82,7 +91,7 @@ abstract class LexicalScopeStorage(
|
|||||||
}
|
}
|
||||||
list = list.prev
|
list = list.prev
|
||||||
}
|
}
|
||||||
return null
|
return emptyList()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun addDescriptor(descriptor: DeclarationDescriptor): Int {
|
private fun addDescriptor(descriptor: DeclarationDescriptor): Int {
|
||||||
@@ -106,14 +115,4 @@ abstract class LexicalScopeStorage(
|
|||||||
} while (rest != null)
|
} while (rest != null)
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
protected fun getClassifier(name: Name, descriptorLimit: Int = addedDescriptors.size)
|
|
||||||
= variableOrClassDescriptorByName(name, descriptorLimit) as? ClassifierDescriptor
|
|
||||||
|
|
||||||
protected fun getVariables(name: Name, descriptorLimit: Int = addedDescriptors.size): Collection<VariableDescriptor>
|
|
||||||
= listOfNotNull(variableOrClassDescriptorByName(name, descriptorLimit) as? VariableDescriptor)
|
|
||||||
|
|
||||||
protected fun getFunctions(name: Name, descriptorLimit: Int = addedDescriptors.size): Collection<FunctionDescriptor>
|
|
||||||
= functionsByName(name, descriptorLimit) ?: emptyList()
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -29,24 +29,15 @@ class LexicalWritableScope(
|
|||||||
redeclarationChecker: LocalRedeclarationChecker,
|
redeclarationChecker: LocalRedeclarationChecker,
|
||||||
override val kind: LexicalScopeKind
|
override val kind: LexicalScopeKind
|
||||||
) : LexicalScopeStorage(parent, redeclarationChecker) {
|
) : LexicalScopeStorage(parent, redeclarationChecker) {
|
||||||
enum class LockLevel {
|
|
||||||
WRITING,
|
|
||||||
BOTH,
|
|
||||||
READING
|
|
||||||
}
|
|
||||||
|
|
||||||
private var lockLevel: LockLevel = LockLevel.WRITING
|
private var canWrite: Boolean = true
|
||||||
private var lastSnapshot: Snapshot? = null
|
private var lastSnapshot: Snapshot? = null
|
||||||
|
|
||||||
fun changeLockLevel(lockLevel: LockLevel) {
|
fun freeze() {
|
||||||
if (lockLevel.ordinal < this.lockLevel.ordinal) {
|
canWrite = false
|
||||||
throw IllegalStateException("cannot lower lock level from " + this.lockLevel + " to " + lockLevel + " at " + toString())
|
|
||||||
}
|
|
||||||
this.lockLevel = lockLevel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun takeSnapshot(): LexicalScope {
|
fun takeSnapshot(): LexicalScope {
|
||||||
checkMayRead()
|
|
||||||
if (lastSnapshot == null || lastSnapshot!!.descriptorLimit != addedDescriptors.size) {
|
if (lastSnapshot == null || lastSnapshot!!.descriptorLimit != addedDescriptors.size) {
|
||||||
lastSnapshot = Snapshot(addedDescriptors.size)
|
lastSnapshot = Snapshot(addedDescriptors.size)
|
||||||
}
|
}
|
||||||
@@ -68,40 +59,21 @@ class LexicalWritableScope(
|
|||||||
addVariableOrClassDescriptor(classifierDescriptor)
|
addVariableOrClassDescriptor(classifierDescriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
|
|
||||||
= checkMayRead().addedDescriptors
|
|
||||||
|
|
||||||
override fun getContributedClassifier(name: Name, location: LookupLocation) = checkMayRead().getClassifier(name)
|
|
||||||
|
|
||||||
override fun getContributedVariables(name: Name, location: LookupLocation) = checkMayRead().getVariables(name)
|
|
||||||
|
|
||||||
override fun getContributedFunctions(name: Name, location: LookupLocation) = checkMayRead().getFunctions(name)
|
|
||||||
|
|
||||||
private fun checkMayRead(): LexicalWritableScope {
|
|
||||||
if (lockLevel != LockLevel.READING && lockLevel != LockLevel.BOTH) {
|
|
||||||
throw IllegalStateException("cannot read with lock level " + lockLevel + " at " + toString())
|
|
||||||
}
|
|
||||||
return this
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun checkMayWrite() {
|
private fun checkMayWrite() {
|
||||||
if (lockLevel != LockLevel.WRITING && lockLevel != LockLevel.BOTH) {
|
if (!canWrite) {
|
||||||
throw IllegalStateException("cannot write with lock level " + lockLevel + " at " + toString())
|
throw IllegalStateException("Cannot write into freezed scope:" + toString())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private inner class Snapshot(val descriptorLimit: Int) : LexicalScope by this {
|
private inner class Snapshot(val descriptorLimit: Int) : LexicalScope by this {
|
||||||
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
|
override fun getContributedDescriptors(kindFilter: DescriptorKindFilter, nameFilter: (Name) -> Boolean)
|
||||||
= this@LexicalWritableScope.addedDescriptors.subList(0, descriptorLimit)
|
= addedDescriptors.subList(0, descriptorLimit)
|
||||||
|
|
||||||
override fun getContributedClassifier(name: Name, location: LookupLocation)
|
override fun getContributedClassifier(name: Name, location: LookupLocation) = variableOrClassDescriptorByName(name, descriptorLimit) as? ClassifierDescriptor
|
||||||
= this@LexicalWritableScope.getClassifier(name, descriptorLimit)
|
override fun getContributedVariables(name: Name, location: LookupLocation) = listOfNotNull(variableOrClassDescriptorByName(name, descriptorLimit) as? VariableDescriptor)
|
||||||
|
|
||||||
override fun getContributedVariables(name: Name, location: LookupLocation)
|
override fun getContributedFunctions(name: Name, location: LookupLocation) = functionsByName(name, descriptorLimit)
|
||||||
= this@LexicalWritableScope.getVariables(name, descriptorLimit)
|
|
||||||
|
|
||||||
override fun getContributedFunctions(name: Name, location: LookupLocation)
|
|
||||||
= this@LexicalWritableScope.getFunctions(name, descriptorLimit)
|
|
||||||
|
|
||||||
override fun toString(): String = "Snapshot($descriptorLimit) for $kind"
|
override fun toString(): String = "Snapshot($descriptorLimit) for $kind"
|
||||||
|
|
||||||
|
|||||||
+1
-2
@@ -165,7 +165,6 @@ public class ExpressionTypingServices {
|
|||||||
DeclarationDescriptor containingDescriptor = context.scope.getOwnerDescriptor();
|
DeclarationDescriptor containingDescriptor = context.scope.getOwnerDescriptor();
|
||||||
LexicalWritableScope scope = new LexicalWritableScope(context.scope, containingDescriptor, false, null,
|
LexicalWritableScope scope = new LexicalWritableScope(context.scope, containingDescriptor, false, null,
|
||||||
new TraceBasedLocalRedeclarationChecker(context.trace), LexicalScopeKind.CODE_BLOCK);
|
new TraceBasedLocalRedeclarationChecker(context.trace), LexicalScopeKind.CODE_BLOCK);
|
||||||
scope.changeLockLevel(LexicalWritableScope.LockLevel.BOTH);
|
|
||||||
|
|
||||||
KotlinTypeInfo r;
|
KotlinTypeInfo r;
|
||||||
if (block.isEmpty()) {
|
if (block.isEmpty()) {
|
||||||
@@ -176,7 +175,7 @@ public class ExpressionTypingServices {
|
|||||||
r = getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression,
|
r = getBlockReturnedTypeWithWritableScope(scope, block, coercionStrategyForLastExpression,
|
||||||
context.replaceStatementFilter(statementFilter));
|
context.replaceStatementFilter(statementFilter));
|
||||||
}
|
}
|
||||||
scope.changeLockLevel(LexicalWritableScope.LockLevel.READING);
|
scope.freeze();
|
||||||
|
|
||||||
if (containingDescriptor instanceof ScriptDescriptor) {
|
if (containingDescriptor instanceof ScriptDescriptor) {
|
||||||
context.trace.record(BindingContext.SCRIPT_SCOPE, (ScriptDescriptor) containingDescriptor, scope);
|
context.trace.record(BindingContext.SCRIPT_SCOPE, (ScriptDescriptor) containingDescriptor, scope);
|
||||||
|
|||||||
+2
-4
@@ -81,10 +81,8 @@ public class ExpressionTypingUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static LexicalWritableScope newWritableScopeImpl(ExpressionTypingContext context, @NotNull LexicalScopeKind scopeKind) {
|
public static LexicalWritableScope newWritableScopeImpl(ExpressionTypingContext context, @NotNull LexicalScopeKind scopeKind) {
|
||||||
LexicalWritableScope scope = new LexicalWritableScope(context.scope, context.scope.getOwnerDescriptor(), false, null,
|
return new LexicalWritableScope(context.scope, context.scope.getOwnerDescriptor(), false, null,
|
||||||
new TraceBasedLocalRedeclarationChecker(context.trace), scopeKind);
|
new TraceBasedLocalRedeclarationChecker(context.trace), scopeKind);
|
||||||
scope.changeLockLevel(LexicalWritableScope.LockLevel.BOTH);
|
|
||||||
return scope;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static KtExpression createFakeExpressionOfType(
|
public static KtExpression createFakeExpressionOfType(
|
||||||
|
|||||||
Reference in New Issue
Block a user