Wire StorageManager into a ClassTypeConstructorImpl and ClassDescriptorImpl

This commit is contained in:
Dmitry Savvinov
2018-04-11 18:55:01 +03:00
parent 1477e67076
commit 934c56a4da
19 changed files with 67 additions and 37 deletions
@@ -38,6 +38,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.getAllSuperclassesWithoutAny
import org.jetbrains.kotlin.resolve.descriptorUtil.overriddenTreeUniqueAsSequence
import org.jetbrains.kotlin.resolve.jvm.diagnostics.CollectionStub
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.KotlinTypeChecker
import org.jetbrains.kotlin.types.checker.KotlinTypeCheckerImpl
@@ -309,8 +310,16 @@ class CollectionStubMethodGenerator(
}
private fun createSyntheticSubclass(): Pair<MutableClassDescriptor, List<TypeParameterDescriptor>> {
val child = MutableClassDescriptor(descriptor.containingDeclaration, ClassKind.CLASS, /* isInner = */ false,
/* isExternal */ false, Name.special("<synthetic inheritor of ${descriptor.name}>"), descriptor.source)
val child = MutableClassDescriptor(
descriptor.containingDeclaration,
ClassKind.CLASS,
/* isInner = */ false,
/* isExternal */ false,
Name.special("<synthetic inheritor of ${descriptor.name}>"),
descriptor.source,
LockBasedStorageManager.NO_LOCKS
)
child.modality = Modality.FINAL
child.visibility = Visibilities.PUBLIC
val typeParameters = descriptor.typeConstructor.parameters
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.load.java.JvmAbi
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import java.util.*
interface InnerClassConsumer {
@@ -38,7 +39,7 @@ interface InnerClassConsumer {
val classDescriptorImpl = ClassDescriptorImpl(
descriptor, Name.identifier(JvmAbi.DEFAULT_IMPLS_CLASS_NAME),
Modality.FINAL, ClassKind.CLASS, Collections.emptyList(), SourceElement.NO_SOURCE,
/* isExternal = */ false)
/* isExternal = */ false, LockBasedStorageManager.NO_LOCKS)
classDescriptorImpl.initialize(MemberScope.Empty, emptySet(), null)
return classDescriptorImpl
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.descriptors.impl.MutablePackageFragmentDescriptor
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.KotlinType
class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSettings: LanguageVersionSettings) {
@@ -49,7 +50,7 @@ class JvmRuntimeTypes(module: ModuleDescriptor, private val languageVersionSetti
classKind: ClassKind = ClassKind.CLASS
): ClassDescriptor =
MutableClassDescriptor(packageFragment, classKind, /* isInner = */ false, /* isExternal = */ false,
Name.identifier(name), SourceElement.NO_SOURCE).apply {
Name.identifier(name), SourceElement.NO_SOURCE, LockBasedStorageManager.NO_LOCKS).apply {
modality = Modality.FINAL
visibility = Visibilities.PUBLIC
setTypeParameterDescriptors(emptyList())
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.psi.KtFile;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKt;
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.util.OperatorNameConventions;
import org.jetbrains.org.objectweb.asm.MethodVisitor;
@@ -90,7 +91,8 @@ public class SamWrapperCodegen {
ClassKind.CLASS,
Collections.singleton(samType.getType()),
SourceElement.NO_SOURCE,
/* isExternal = */ false
/* isExternal = */ false,
LockBasedStorageManager.NO_LOCKS
);
// e.g. compare(T, T)
SimpleFunctionDescriptor erasedInterfaceFunction = samType.getOriginalAbstractMethod().copy(
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtElement
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.resolve.source.toSourceElement
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.KotlinType
class SyntheticClassDescriptorForLambda(
@@ -32,7 +33,7 @@ class SyntheticClassDescriptorForLambda(
supertypes: Collection<KotlinType>,
element: KtElement
) : ClassDescriptorImpl(containingDeclaration, name, Modality.FINAL, ClassKind.CLASS, supertypes, element.toSourceElement(),
/* isExternal = */ false) {
/* isExternal = */ false, LockBasedStorageManager.NO_LOCKS) {
init {
initialize(MemberScope.Empty, emptySet(), null)
}
@@ -24,21 +24,23 @@ import org.jetbrains.kotlin.storage.LockBasedStorageManager
import java.util.*
object JvmPlatform : TargetPlatform("JVM") {
private val defaultImports = LockBasedStorageManager().createMemoizedFunction<Boolean, List<ImportPath>> { includeKotlinComparisons ->
ArrayList<ImportPath>().apply {
addAll(Common.getDefaultImports(includeKotlinComparisons))
private val defaultImports = LockBasedStorageManager().let { storageManager ->
storageManager.createMemoizedFunction<Boolean, List<ImportPath>> { includeKotlinComparisons ->
ArrayList<ImportPath>().apply {
addAll(Common.getDefaultImports(includeKotlinComparisons))
add(ImportPath.fromString("java.lang.*"))
add(ImportPath.fromString("kotlin.jvm.*"))
add(ImportPath.fromString("java.lang.*"))
add(ImportPath.fromString("kotlin.jvm.*"))
fun addAllClassifiersFromScope(scope: MemberScope) {
for (descriptor in scope.getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS, MemberScope.ALL_NAME_FILTER)) {
add(ImportPath(DescriptorUtils.getFqNameSafe(descriptor), false))
fun addAllClassifiersFromScope(scope: MemberScope) {
for (descriptor in scope.getContributedDescriptors(DescriptorKindFilter.CLASSIFIERS, MemberScope.ALL_NAME_FILTER)) {
add(ImportPath(DescriptorUtils.getFqNameSafe(descriptor), false))
}
}
}
for (builtinPackageFragment in JvmBuiltIns(LockBasedStorageManager.NO_LOCKS).builtInsPackageFragmentsImportedByDefault) {
addAllClassifiersFromScope(builtinPackageFragment.getMemberScope())
for (builtinPackageFragment in JvmBuiltIns(storageManager).builtInsPackageFragmentsImportedByDefault) {
addAllClassifiersFromScope(builtinPackageFragment.getMemberScope())
}
}
}
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.*
open class KnownPackageFragmentDescriptor(moduleDescriptor: ModuleDescriptor, fqName: FqName) :
@@ -44,7 +45,7 @@ open class KnownClassDescriptor(
fun initialize(declaredTypeParameters: List<TypeParameterDescriptor>, supertypes: List<KotlinType>) {
this.declaredTypeParameters = declaredTypeParameters
this.supertypes = supertypes
this.typeConstructor = ClassTypeConstructorImpl(this, declaredTypeParameters, supertypes)
this.typeConstructor = ClassTypeConstructorImpl(this, declaredTypeParameters, supertypes, LockBasedStorageManager.NO_LOCKS)
this.defaultType = TypeUtils.makeUnsubstitutedType(this, unsubstitutedMemberScope)
}
@@ -36,7 +36,7 @@ class JvmBuiltInClassDescriptorFactory(
ClassDescriptorImpl(
computeContainingDeclaration(moduleDescriptor),
CLONEABLE_NAME, Modality.ABSTRACT, ClassKind.INTERFACE, listOf(moduleDescriptor.builtIns.anyType),
SourceElement.NO_SOURCE, /* isExternal = */ false
SourceElement.NO_SOURCE, /* isExternal = */ false, storageManager
).apply {
initialize(CloneableClassScope(storageManager, this), emptySet(), null)
}
@@ -91,7 +91,7 @@ open class JvmBuiltInsSettings(
val mockSerializableClass = ClassDescriptorImpl(
mockJavaIoPackageFragment, Name.identifier("Serializable"), Modality.ABSTRACT, ClassKind.INTERFACE, superTypes,
SourceElement.NO_SOURCE, /* isExternal = */ false
SourceElement.NO_SOURCE, /* isExternal = */ false, this
)
mockSerializableClass.initialize(MemberScope.Empty, emptySet(), null)
@@ -17,6 +17,7 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.typeUtil.asTypeProjection
import org.jetbrains.kotlin.types.typeUtil.builtIns
@@ -25,7 +26,7 @@ val FAKE_CONTINUATION_CLASS_DESCRIPTOR_EXPERIMENTAL =
MutableClassDescriptor(
EmptyPackageFragmentDescriptor(ErrorUtils.getErrorModule(), DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_EXPERIMENTAL),
ClassKind.INTERFACE, /* isInner = */ false, /* isExternal = */ false,
DescriptorUtils.CONTINUATION_INTERFACE_FQ_NAME_EXPERIMENTAL.shortName(), SourceElement.NO_SOURCE
DescriptorUtils.CONTINUATION_INTERFACE_FQ_NAME_EXPERIMENTAL.shortName(), SourceElement.NO_SOURCE, LockBasedStorageManager.NO_LOCKS
).apply {
modality = Modality.ABSTRACT
visibility = Visibilities.PUBLIC
@@ -41,7 +42,7 @@ val FAKE_CONTINUATION_CLASS_DESCRIPTOR_RELEASE =
MutableClassDescriptor(
EmptyPackageFragmentDescriptor(ErrorUtils.getErrorModule(), DescriptorUtils.COROUTINES_PACKAGE_FQ_NAME_RELEASE),
ClassKind.INTERFACE, /* isInner = */ false, /* isExternal = */ false,
DescriptorUtils.CONTINUATION_INTERFACE_FQ_NAME_RELEASE.shortName(), SourceElement.NO_SOURCE
DescriptorUtils.CONTINUATION_INTERFACE_FQ_NAME_RELEASE.shortName(), SourceElement.NO_SOURCE, LockBasedStorageManager.NO_LOCKS
).apply {
modality = Modality.ABSTRACT
visibility = Visibilities.PUBLIC
@@ -56,7 +56,7 @@ class NotFoundClasses(private val storageManager: StorageManager, private val mo
)
}
private val typeConstructor = ClassTypeConstructorImpl(this, typeParameters, setOf(module.builtIns.anyType))
private val typeConstructor = ClassTypeConstructorImpl(this, typeParameters, setOf(module.builtIns.anyType), storageManager)
override fun getKind() = ClassKind.CLASS
override fun getModality() = Modality.FINAL
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
import org.jetbrains.kotlin.storage.StorageManager;
import org.jetbrains.kotlin.types.ClassTypeConstructorImpl;
import org.jetbrains.kotlin.types.KotlinType;
import org.jetbrains.kotlin.types.TypeConstructor;
@@ -37,14 +38,15 @@ public class ClassDescriptorImpl extends ClassDescriptorBase {
@NotNull ClassKind kind,
@NotNull Collection<KotlinType> supertypes,
@NotNull SourceElement source,
boolean isExternal
boolean isExternal,
@NotNull StorageManager storageManager
) {
super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name, source, isExternal);
super(storageManager, containingDeclaration, name, source, isExternal);
assert modality != Modality.SEALED : "Implement getSealedSubclasses() for this class: " + getClass();
this.modality = modality;
this.kind = kind;
this.typeConstructor = new ClassTypeConstructorImpl(this, Collections.<TypeParameterDescriptor>emptyList(), supertypes);
this.typeConstructor = new ClassTypeConstructorImpl(this, Collections.<TypeParameterDescriptor>emptyList(), supertypes, storageManager);
}
public final void initialize(
@@ -69,7 +69,7 @@ public class EnumEntrySyntheticClassDescriptor extends ClassDescriptorBase {
this.annotations = annotations;
this.typeConstructor = new ClassTypeConstructorImpl(
this, Collections.<TypeParameterDescriptor>emptyList(), Collections.singleton(supertype)
this, Collections.<TypeParameterDescriptor>emptyList(), Collections.singleton(supertype), storageManager
);
this.scope = new EnumEntryScope(storageManager);
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import org.jetbrains.kotlin.resolve.scopes.SubstitutingScope;
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
import org.jetbrains.kotlin.types.*;
import java.util.ArrayList;
@@ -73,7 +74,7 @@ public class LazySubstitutingClassDescriptor implements ClassDescriptor {
supertypes.add(substitutor.substitute(supertype, Variance.INVARIANT));
}
typeConstructor = new ClassTypeConstructorImpl(this, typeConstructorParameters, supertypes);
typeConstructor = new ClassTypeConstructorImpl(this, typeConstructorParameters, supertypes, LockBasedStorageManager.NO_LOCKS);
}
return typeConstructor;
@@ -11,7 +11,7 @@ import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.descriptors.annotations.Annotations;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
import org.jetbrains.kotlin.storage.StorageManager;
import org.jetbrains.kotlin.types.*;
import java.util.*;
@@ -25,6 +25,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase {
private TypeConstructor typeConstructor;
private List<TypeParameterDescriptor> typeParameters;
private final Collection<KotlinType> supertypes = new ArrayList<KotlinType>();
private final StorageManager storageManager;
public MutableClassDescriptor(
@NotNull DeclarationDescriptor containingDeclaration,
@@ -32,9 +33,11 @@ public class MutableClassDescriptor extends ClassDescriptorBase {
boolean isInner,
boolean isExternal,
@NotNull Name name,
@NotNull SourceElement source
@NotNull SourceElement source,
@NotNull StorageManager storageManager
) {
super(LockBasedStorageManager.NO_LOCKS, containingDeclaration, name, source, isExternal);
super(storageManager, containingDeclaration, name, source, isExternal);
this.storageManager = storageManager;
assert kind != ClassKind.OBJECT : "Fix isCompanionObject()";
this.kind = kind;
@@ -151,7 +154,7 @@ public class MutableClassDescriptor extends ClassDescriptorBase {
public void createTypeConstructor() {
assert typeConstructor == null : typeConstructor;
this.typeConstructor = new ClassTypeConstructorImpl(this, typeParameters, supertypes);
this.typeConstructor = new ClassTypeConstructorImpl(this, typeParameters, supertypes, storageManager);
for (FunctionDescriptor functionDescriptor : getConstructors()) {
((ClassConstructorDescriptorImpl) functionDescriptor).setReturnType(getDefaultType());
}
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.SupertypeLoopChecker;
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
import org.jetbrains.kotlin.storage.StorageManager;
import java.util.ArrayList;
import java.util.Collection;
@@ -36,9 +37,10 @@ public class ClassTypeConstructorImpl extends AbstractClassTypeConstructor imple
public ClassTypeConstructorImpl(
@NotNull ClassDescriptor classDescriptor,
@NotNull List<? extends TypeParameterDescriptor> parameters,
@NotNull Collection<KotlinType> supertypes
@NotNull Collection<KotlinType> supertypes,
@NotNull StorageManager storageManager
) {
super(LockBasedStorageManager.NO_LOCKS);
super(storageManager);
this.classDescriptor = classDescriptor;
this.parameters = Collections.unmodifiableList(new ArrayList<TypeParameterDescriptor>(parameters));
this.supertypes = Collections.unmodifiableCollection(supertypes);
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
import org.jetbrains.kotlin.resolve.scopes.DescriptorKindFilter;
import org.jetbrains.kotlin.resolve.scopes.MemberScope;
import org.jetbrains.kotlin.storage.LockBasedStorageManager;
import org.jetbrains.kotlin.types.error.ErrorSimpleFunctionDescriptorImpl;
import org.jetbrains.kotlin.utils.Printer;
@@ -343,7 +344,7 @@ public class ErrorUtils {
public ErrorClassDescriptor(@NotNull Name name) {
super(getErrorModule(), name,
Modality.OPEN, ClassKind.CLASS, Collections.<KotlinType>emptyList(), SourceElement.NO_SOURCE,
/* isExternal = */ false
/* isExternal = */ false, LockBasedStorageManager.NO_LOCKS
);
ClassConstructorDescriptorImpl
@@ -58,6 +58,7 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.annotations.JVM_FIELD_ANNOTATION_FQ_NAME
import org.jetbrains.kotlin.resolve.annotations.JVM_STATIC_ANNOTATION_FQ_NAME
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.Variance
import org.jetbrains.kotlin.types.typeUtil.supertypes
@@ -206,7 +207,8 @@ class KotlinElementActionsFactory : JvmElementActionsFactory() {
ClassKind.CLASS,
emptyList(),
SourceElement.NO_SOURCE,
false
false,
LockBasedStorageManager.NO_LOCKS
)
val typeParameterResolver = object : TypeParameterResolver {
override fun resolveTypeParameter(javaTypeParameter: JavaTypeParameter): TypeParameterDescriptor? {
@@ -48,6 +48,7 @@ import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe
import org.jetbrains.kotlin.resolve.descriptorUtil.module
import org.jetbrains.kotlin.resolve.jvm.diagnostics.JvmDeclarationOriginKind
import org.jetbrains.kotlin.resolve.scopes.MemberScope
import org.jetbrains.kotlin.storage.LockBasedStorageManager
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.Variance
@@ -288,7 +289,7 @@ open class ParcelableCodegenExtension : ExpressionCodegenExtension {
val creatorClass = ClassDescriptorImpl(
parcelableClass, Name.identifier("Creator"), Modality.FINAL, ClassKind.CLASS, emptyList(),
parcelableClass.source, false)
parcelableClass.source, false, LockBasedStorageManager.NO_LOCKS)
creatorClass.initialize(
MemberScope.Empty, emptySet(),