Fix race in IDE: inject proper storage manager for type parameters

With NO_LOCKS strategy we can easily end up in a situation when
 constraint system for a generic call is built incorrectly,
 producing flaky errors (or don't produce errors at all)

 Now proper storage manager is injected for all cases except:
 - IR
 - Codegen
 - Serialization plugin
 - Fake local objects

 Most likely, NO_LOCKS strategy for these cases is fine as at that point
 the compiler works in one thread

 #KT-34786 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2019-11-25 17:12:28 +03:00
parent 399667a434
commit eb73650209
21 changed files with 103 additions and 40 deletions
@@ -472,7 +472,8 @@ public class DescriptorResolver {
}
return null;
},
supertypeLoopsResolver
supertypeLoopsResolver,
storageManager
);
trace.record(BindingContext.TYPE_PARAMETER, typeParameter, typeParameterDescriptor);
return typeParameterDescriptor;
@@ -36,7 +36,7 @@ import org.jetbrains.kotlin.types.expressions.OperatorConventions
import org.jetbrains.kotlin.utils.Printer
import java.util.*
class DynamicCallableDescriptors(storageManager: StorageManager, builtIns: KotlinBuiltIns) {
class DynamicCallableDescriptors(private val storageManager: StorageManager, builtIns: KotlinBuiltIns) {
val dynamicType by storageManager.createLazyValue {
createDynamicType(builtIns)
@@ -150,7 +150,8 @@ class DynamicCallableDescriptors(storageManager: StorageManager, builtIns: Kotli
false,
Variance.INVARIANT,
Name.identifier("T$index"),
index
index,
storageManager
)
}
@@ -55,6 +55,7 @@ import org.jetbrains.kotlin.resolve.calls.tasks.TracingStrategy;
import org.jetbrains.kotlin.resolve.calls.util.CallMaker;
import org.jetbrains.kotlin.resolve.descriptorUtil.AnnotationsForResolveKt;
import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValue;
import org.jetbrains.kotlin.storage.StorageManager;
import org.jetbrains.kotlin.types.*;
import org.jetbrains.kotlin.types.typeUtil.TypeUtilsKt;
@@ -97,15 +98,18 @@ public class ControlStructureTypingUtils {
private final CallResolver callResolver;
private final DataFlowAnalyzer dataFlowAnalyzer;
private final ModuleDescriptor moduleDescriptor;
private final StorageManager storageManager;
public ControlStructureTypingUtils(
@NotNull CallResolver callResolver,
@NotNull DataFlowAnalyzer dataFlowAnalyzer,
@NotNull ModuleDescriptor moduleDescriptor
@NotNull ModuleDescriptor moduleDescriptor,
@NotNull StorageManager storageManager
) {
this.callResolver = callResolver;
this.dataFlowAnalyzer = dataFlowAnalyzer;
this.moduleDescriptor = moduleDescriptor;
this.storageManager = storageManager;
}
/*package*/ ResolvedCall<FunctionDescriptor> resolveSpecialConstructionAsCall(
@@ -202,7 +206,7 @@ public class ControlStructureTypingUtils {
TypeParameterDescriptor typeParameter = TypeParameterDescriptorImpl.createWithDefaultBound(
function, Annotations.Companion.getEMPTY(), false, Variance.INVARIANT,
construct.getSpecialTypeParameterName(), 0);
construct.getSpecialTypeParameterName(), 0, storageManager);
KotlinType type = typeParameter.getDefaultType();
KotlinType nullableType = TypeUtils.makeNullable(type);