From e518b81c4fb86331869aa918688d66d9fd6589db Mon Sep 17 00:00:00 2001 From: Ting-Yuan Huang Date: Mon, 15 Aug 2022 11:38:49 -0700 Subject: [PATCH] Tear ResolverImpl instance down after each round --- .../ksp/KotlinSymbolProcessingExtension.kt | 21 +++++++++++--- .../ksp/processing/impl/ResolverImpl.kt | 8 +++++- .../impl/binary/KSAnnotationDescriptorImpl.kt | 10 +++---- .../KSClassDeclarationDescriptorImpl.kt | 8 +++--- .../KSFunctionDeclarationDescriptorImpl.kt | 2 +- .../KSPropertyDeclarationDescriptorImpl.kt | 4 +-- .../symbol/impl/java/KSAnnotationJavaImpl.kt | 12 ++++---- .../KSClassDeclarationJavaEnumEntryImpl.kt | 2 +- .../impl/java/KSClassDeclarationJavaImpl.kt | 2 +- .../java/KSFunctionDeclarationJavaImpl.kt | 4 +-- .../java/KSPropertyDeclarationJavaImpl.kt | 2 +- .../impl/java/KSTypeReferenceJavaImpl.kt | 28 +++++++++---------- .../impl/java/KSTypeReferenceLiteJavaImpl.kt | 2 +- .../symbol/impl/kotlin/KSAnnotationImpl.kt | 2 +- .../impl/kotlin/KSClassDeclarationImpl.kt | 6 ++-- .../symbol/impl/kotlin/KSExpectActualImpl.kt | 2 +- .../impl/kotlin/KSFunctionDeclarationImpl.kt | 6 ++-- .../impl/kotlin/KSPropertyDeclarationImpl.kt | 8 +++--- .../KSPropertyDeclarationParameterImpl.kt | 4 +-- .../impl/kotlin/KSPropertyGetterImpl.kt | 2 +- .../impl/kotlin/KSPropertySetterImpl.kt | 2 +- .../ksp/symbol/impl/kotlin/KSTypeImpl.kt | 4 +-- .../symbol/impl/kotlin/KSTypeReferenceImpl.kt | 2 +- .../synthetic/KSConstructorSyntheticImpl.kt | 2 +- .../synthetic/KSErrorTypeClassDeclaration.kt | 4 +-- .../KSPropertyGetterSyntheticImpl.kt | 2 +- .../KSPropertySetterSyntheticImpl.kt | 2 +- .../google/devtools/ksp/symbol/impl/utils.kt | 24 ++++++++-------- 28 files changed, 98 insertions(+), 79 deletions(-) diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt index 44e107ba7e..6787cb230f 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/KotlinSymbolProcessingExtension.kt @@ -221,7 +221,10 @@ abstract class AbstractKotlinSymbolProcessingExtension( findTargetInfos(module) ) ) - }?.let { analysisResult -> return@doAnalysis analysisResult } + }?.let { analysisResult -> + resolver.tearDown() + return@doAnalysis analysisResult + } if (logger.hasError()) { return@mapNotNull null } @@ -237,7 +240,10 @@ abstract class AbstractKotlinSymbolProcessingExtension( handleException(module, project) { deferredSymbols[processor] = processor.process(resolver).filter { it.origin == Origin.KOTLIN || it.origin == Origin.JAVA } - }?.let { return it } + }?.let { + resolver.tearDown() + return it + } if (logger.hasError()) { return@processing } @@ -259,14 +265,20 @@ abstract class AbstractKotlinSymbolProcessingExtension( processors.forEach { processor -> handleException(module, project) { processor.onError() - }?.let { return it } + }?.let { + resolver.tearDown() + return it + } } } else { if (finished) { processors.forEach { processor -> handleException(module, project) { processor.finish() - }?.let { return it } + }?.let { + resolver.tearDown() + return it + } } if (deferredSymbols.isNotEmpty()) { deferredSymbols.map { entry -> @@ -289,6 +301,7 @@ abstract class AbstractKotlinSymbolProcessingExtension( if (finished) { logger.reportAll() } + resolver.tearDown() return if (finished && !options.withCompilation) { if (!options.returnOkOnError && logger.hasError()) { AnalysisResult.compilationError(BindingContext.EMPTY) diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/ResolverImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/ResolverImpl.kt index 8e0db40bf7..9684f555d9 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/ResolverImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/processing/impl/ResolverImpl.kt @@ -157,7 +157,7 @@ class ResolverImpl( } companion object { - lateinit var instance: ResolverImpl + var instance: ResolverImpl? = null } var resolveSession: ResolveSession @@ -217,6 +217,12 @@ class ResolverImpl( allKSFiles.forEach { it.accept(visitor, Unit) } } + // Mitigation for processors with memory leaks + // https://github.com/google/ksp/issues/1063 + fun tearDown() { + instance = null + } + override fun getNewFiles(): Sequence { return newKSFiles.asSequence() } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSAnnotationDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSAnnotationDescriptorImpl.kt index 5abd7c25a6..2a32b5df97 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSAnnotationDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSAnnotationDescriptorImpl.kt @@ -109,7 +109,7 @@ class KSAnnotationDescriptorImpl private constructor( private fun ClassId.findKSClassDeclaration(): KSClassDeclaration? { val ksName = KSNameImpl.getCached(this.asSingleFqName().asString().replace("$", ".")) - return ResolverImpl.instance.getClassDeclarationByName(ksName) + return ResolverImpl.instance!!.getClassDeclarationByName(ksName) } private fun ClassId.findKSType(): KSType? = findKSClassDeclaration()?.asStarProjectedType() @@ -126,9 +126,9 @@ private fun ConstantValue.toValue(parent: KSNode): Any? = when (this) { classValue.value.classId.findKSType()?.let { componentType -> var resultingType = componentType for (i in 1..classValue.arrayDimensions) { - resultingType = ResolverImpl.instance.builtIns.arrayType.replace( + resultingType = ResolverImpl.instance!!.builtIns.arrayType.replace( listOf( - ResolverImpl.instance.getTypeArgument( + ResolverImpl.instance!!.getTypeArgument( KSTypeReferenceSyntheticImpl.getCached(resultingType, null), Variance.INVARIANT ) ) @@ -250,7 +250,7 @@ fun ValueParameterDescriptor.getDefaultValue(ownerAnnotation: KSAnnotation): Any } is JavaAnnotationAsAnnotationArgument -> { AnnotationValue( - LazyJavaAnnotationDescriptor(ResolverImpl.instance.lazyJavaResolverContext, this.getAnnotation()) + LazyJavaAnnotationDescriptor(ResolverImpl.instance!!.lazyJavaResolverContext, this.getAnnotation()) ) } is JavaClassObjectAnnotationArgument -> { @@ -310,7 +310,7 @@ fun ValueParameterDescriptor.getDefaultValue(ownerAnnotation: KSAnnotation): Any } } is KtParameter -> if (!this.type.isError) { - ResolverImpl.instance.evaluateConstant(psi.defaultValue, this.type)?.toValue(ownerAnnotation) + ResolverImpl.instance!!.evaluateConstant(psi.defaultValue, this.type)?.toValue(ownerAnnotation) } else { KSErrorType } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSClassDeclarationDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSClassDeclarationDescriptorImpl.kt index 0eec168651..dd28415e6d 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSClassDeclarationDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSClassDeclarationDescriptorImpl.kt @@ -75,8 +75,8 @@ class KSClassDeclarationDescriptorImpl private constructor(val descriptor: Class } // Workaround for https://github.com/google/ksp/issues/195 - private val mockSerializableType = ResolverImpl.instance.mockSerializableType - private val javaSerializableType = ResolverImpl.instance.javaSerializableType + private val mockSerializableType = ResolverImpl.instance!!.mockSerializableType + private val javaSerializableType = ResolverImpl.instance!!.javaSerializableType override val superTypes: Sequence by lazy { @@ -155,7 +155,7 @@ class KSClassDeclarationDescriptorImpl private constructor(val descriptor: Class } internal fun ClassDescriptor.getAllFunctions(): Sequence { - ResolverImpl.instance.incrementalContext.recordLookupForGetAllFunctions(this) + ResolverImpl.instance!!.incrementalContext.recordLookupForGetAllFunctions(this) val functionDescriptors = unsubstitutedMemberScope.getDescriptorsFiltered(DescriptorKindFilter.FUNCTIONS) .asSequence() .filter { (it as FunctionDescriptor).visibility != DescriptorVisibilities.INVISIBLE_FAKE } @@ -169,7 +169,7 @@ internal fun ClassDescriptor.getAllFunctions(): Sequence } internal fun ClassDescriptor.getAllProperties(): Sequence { - ResolverImpl.instance.incrementalContext.recordLookupForGetAllProperties(this) + ResolverImpl.instance!!.incrementalContext.recordLookupForGetAllProperties(this) return unsubstitutedMemberScope.getDescriptorsFiltered(DescriptorKindFilter.VARIABLES).asSequence() .filter { (it as PropertyDescriptor).visibility != DescriptorVisibilities.INVISIBLE_FAKE } .map { diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSFunctionDeclarationDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSFunctionDeclarationDescriptorImpl.kt index e9bd1ef9aa..0749a095b6 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSFunctionDeclarationDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSFunctionDeclarationDescriptorImpl.kt @@ -110,5 +110,5 @@ class KSFunctionDeclarationDescriptorImpl private constructor(val descriptor: Fu } override fun asMemberOf(containing: KSType): KSFunction = - ResolverImpl.instance.asMemberOf(this, containing) + ResolverImpl.instance!!.asMemberOf(this, containing) } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertyDeclarationDescriptorImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertyDeclarationDescriptorImpl.kt index ad6141740b..ad9e52f316 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertyDeclarationDescriptorImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/binary/KSPropertyDeclarationDescriptorImpl.kt @@ -107,7 +107,7 @@ class KSPropertyDeclarationDescriptorImpl private constructor(val descriptor: Pr } override fun findOverridee(): KSPropertyDeclaration? { - val propertyDescriptor = ResolverImpl.instance.resolvePropertyDeclaration(this) + val propertyDescriptor = ResolverImpl.instance!!.resolvePropertyDeclaration(this) return propertyDescriptor?.findClosestOverridee()?.toKSPropertyDeclaration() } @@ -120,5 +120,5 @@ class KSPropertyDeclarationDescriptorImpl private constructor(val descriptor: Pr } override fun asMemberOf(containing: KSType): KSType = - ResolverImpl.instance.asMemberOf(this, containing) + ResolverImpl.instance!!.asMemberOf(this, containing) } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSAnnotationJavaImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSAnnotationJavaImpl.kt index 7602171812..88de93ac4e 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSAnnotationJavaImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSAnnotationJavaImpl.kt @@ -119,16 +119,16 @@ class KSAnnotationJavaImpl private constructor(val psi: PsiAnnotation) : KSAnnot private fun resolveJavaTypeSimple(psiType: PsiType): KSType { return when (psiType) { is PsiPrimitiveType -> { - ResolverImpl.instance.getClassDeclarationByName(psiType.boxedTypeName!!)!!.asStarProjectedType() + ResolverImpl.instance!!.getClassDeclarationByName(psiType.boxedTypeName!!)!!.asStarProjectedType() } is PsiArrayType -> { val componentType = resolveJavaTypeSimple(psiType.componentType) - val componentTypeRef = ResolverImpl.instance.createKSTypeReferenceFromKSType(componentType) - val typeArgs = listOf(ResolverImpl.instance.getTypeArgument(componentTypeRef, Variance.INVARIANT)) - ResolverImpl.instance.builtIns.arrayType.replace(typeArgs) + val componentTypeRef = ResolverImpl.instance!!.createKSTypeReferenceFromKSType(componentType) + val typeArgs = listOf(ResolverImpl.instance!!.getTypeArgument(componentTypeRef, Variance.INVARIANT)) + ResolverImpl.instance!!.builtIns.arrayType.replace(typeArgs) } else -> { - ResolverImpl.instance.getClassDeclarationByName(psiType.canonicalText)?.asStarProjectedType() + ResolverImpl.instance!!.getClassDeclarationByName(psiType.canonicalText)?.asStarProjectedType() ?: KSErrorType } } @@ -160,7 +160,7 @@ class KSAnnotationJavaImpl private constructor(val psi: PsiAnnotation) : KSAnnot if (containingClass?.classKind == JvmClassKind.ENUM) { // this is an enum entry containingClass.qualifiedName?.let { - ResolverImpl.instance.getClassDeclarationByName(it) + ResolverImpl.instance!!.getClassDeclarationByName(it) }?.declarations?.find { it is KSClassDeclaration && it.classKind == ClassKind.ENUM_ENTRY && it.simpleName.asString() == result.name diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSClassDeclarationJavaEnumEntryImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSClassDeclarationJavaEnumEntryImpl.kt index a7f965c422..e14b5818bb 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSClassDeclarationJavaEnumEntryImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSClassDeclarationJavaEnumEntryImpl.kt @@ -61,7 +61,7 @@ class KSClassDeclarationJavaEnumEntryImpl private constructor(val psi: PsiEnumCo override fun getSealedSubclasses(): Sequence = emptySequence() private val descriptor: ClassDescriptor? by lazy { - ResolverImpl.instance.resolveJavaDeclaration(psi) as ClassDescriptor + ResolverImpl.instance!!.resolveJavaDeclaration(psi) as ClassDescriptor } override fun getAllFunctions(): Sequence = diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSClassDeclarationJavaImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSClassDeclarationJavaImpl.kt index ea811c210f..9f60b9518b 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSClassDeclarationJavaImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSClassDeclarationJavaImpl.kt @@ -74,7 +74,7 @@ class KSClassDeclarationJavaImpl private constructor(val psi: PsiClass) : // Could the resolution ever fail? private val descriptor: ClassDescriptor? by lazy { - ResolverImpl.instance.moduleClassResolver.resolveClass(JavaClassImpl(psi)) + ResolverImpl.instance!!.moduleClassResolver.resolveClass(JavaClassImpl(psi)) } // TODO in 1.5 + jvmTarget 15, will we return Java permitted types? diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSFunctionDeclarationJavaImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSFunctionDeclarationJavaImpl.kt index 0c73c3fb17..ad175dbf06 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSFunctionDeclarationJavaImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSFunctionDeclarationJavaImpl.kt @@ -54,7 +54,7 @@ class KSFunctionDeclarationJavaImpl private constructor(val psi: PsiMethod) : } override fun findOverridee(): KSDeclaration? { - val descriptor = ResolverImpl.instance.resolveFunctionDeclaration(this) + val descriptor = ResolverImpl.instance!!.resolveFunctionDeclaration(this) return descriptor.safeAs()?.findClosestOverridee()?.toKSDeclaration() } @@ -122,5 +122,5 @@ class KSFunctionDeclarationJavaImpl private constructor(val psi: PsiMethod) : } override fun asMemberOf(containing: KSType): KSFunction = - ResolverImpl.instance.asMemberOf(this, containing) + ResolverImpl.instance!!.asMemberOf(this, containing) } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSPropertyDeclarationJavaImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSPropertyDeclarationJavaImpl.kt index 4b062dba96..80b8acf4bd 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSPropertyDeclarationJavaImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSPropertyDeclarationJavaImpl.kt @@ -96,5 +96,5 @@ class KSPropertyDeclarationJavaImpl private constructor(val psi: PsiField) : } override fun asMemberOf(containing: KSType): KSType = - ResolverImpl.instance.asMemberOf(this, containing) + ResolverImpl.instance!!.asMemberOf(this, containing) } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSTypeReferenceJavaImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSTypeReferenceJavaImpl.kt index d66d4b9b4a..d12c540b20 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSTypeReferenceJavaImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSTypeReferenceJavaImpl.kt @@ -68,15 +68,15 @@ class KSTypeReferenceJavaImpl private constructor(val psi: PsiType, override val override val element: KSReferenceElement by lazy { fun PsiPrimitiveType.toKotlinType(): KotlinType { return when (this.name) { - "int" -> ResolverImpl.instance.module.builtIns.intType - "short" -> ResolverImpl.instance.module.builtIns.shortType - "byte" -> ResolverImpl.instance.module.builtIns.byteType - "long" -> ResolverImpl.instance.module.builtIns.longType - "float" -> ResolverImpl.instance.module.builtIns.floatType - "double" -> ResolverImpl.instance.module.builtIns.doubleType - "char" -> ResolverImpl.instance.module.builtIns.charType - "boolean" -> ResolverImpl.instance.module.builtIns.booleanType - "void" -> ResolverImpl.instance.module.builtIns.unitType + "int" -> ResolverImpl.instance!!.module.builtIns.intType + "short" -> ResolverImpl.instance!!.module.builtIns.shortType + "byte" -> ResolverImpl.instance!!.module.builtIns.byteType + "long" -> ResolverImpl.instance!!.module.builtIns.longType + "float" -> ResolverImpl.instance!!.module.builtIns.floatType + "double" -> ResolverImpl.instance!!.module.builtIns.doubleType + "char" -> ResolverImpl.instance!!.module.builtIns.charType + "boolean" -> ResolverImpl.instance!!.module.builtIns.booleanType + "void" -> ResolverImpl.instance!!.module.builtIns.unitType else -> throw IllegalStateException("Unexpected primitive type ${this.name}, $ExceptionMessage") } } @@ -91,16 +91,16 @@ class KSTypeReferenceJavaImpl private constructor(val psi: PsiType, override val is PsiWildcardType -> KSClassifierReferenceJavaImpl.getCached(type.extendsBound as PsiClassType, this) is PsiPrimitiveType -> KSClassifierReferenceDescriptorImpl.getCached(type.toKotlinType(), origin, this) is PsiArrayType -> { - val componentType = ResolverImpl.instance.resolveJavaType(type.componentType, this) + val componentType = ResolverImpl.instance!!.resolveJavaType(type.componentType, this) if (type.componentType !is PsiPrimitiveType) { KSClassifierReferenceDescriptorImpl.getCached( - ResolverImpl.instance.module.builtIns.getArrayType(Variance.INVARIANT, componentType), + ResolverImpl.instance!!.module.builtIns.getArrayType(Variance.INVARIANT, componentType), origin, this ) } else { KSClassifierReferenceDescriptorImpl.getCached( - ResolverImpl.instance.module.builtIns + ResolverImpl.instance!!.module.builtIns .getPrimitiveArrayKotlinTypeByPrimitiveKotlinType(componentType)!!, origin, this ) @@ -108,14 +108,14 @@ class KSTypeReferenceJavaImpl private constructor(val psi: PsiType, override val } null -> KSClassifierReferenceDescriptorImpl.getCached( - (ResolverImpl.instance.builtIns.anyType as KSTypeImpl).kotlinType.makeNullable(), origin, this + (ResolverImpl.instance!!.builtIns.anyType as KSTypeImpl).kotlinType.makeNullable(), origin, this ) else -> throw IllegalStateException("Unexpected psi type for ${type.javaClass}, $ExceptionMessage") } } override fun resolve(): KSType { - val resolvedType = ResolverImpl.instance.resolveUserType(this) + val resolvedType = ResolverImpl.instance!!.resolveUserType(this) return if ((resolvedType.declaration as? KSClassDeclarationDescriptorImpl) ?.descriptor is NotFoundClasses.MockClassDescriptor ) { diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSTypeReferenceLiteJavaImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSTypeReferenceLiteJavaImpl.kt index 04b526f810..601c8bee53 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSTypeReferenceLiteJavaImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/java/KSTypeReferenceLiteJavaImpl.kt @@ -50,7 +50,7 @@ class KSTypeReferenceLiteJavaImpl private constructor(val psiElement: PsiElement val psiClass = psiElement.nameReferenceElement!!.resolve() as? PsiClass psiClass?.let { (psiElement.containingFile as? PsiJavaFile)?.let { - ResolverImpl.instance.incrementalContext.recordLookup(it, psiClass.qualifiedName!!) + ResolverImpl.instance!!.incrementalContext.recordLookup(it, psiClass.qualifiedName!!) } KSClassDeclarationJavaImpl.getCached(psiClass).asStarProjectedType() } ?: KSErrorType diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSAnnotationImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSAnnotationImpl.kt index 8bae2e5ea9..9b50896858 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSAnnotationImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSAnnotationImpl.kt @@ -110,7 +110,7 @@ class KSAnnotationImpl private constructor(val ktAnnotationEntry: KtAnnotationEn } private val resolved: AnnotationDescriptor? by lazy { - ResolverImpl.instance.resolveAnnotationEntry(ktAnnotationEntry) + ResolverImpl.instance!!.resolveAnnotationEntry(ktAnnotationEntry) } override fun toString(): String { diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSClassDeclarationImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSClassDeclarationImpl.kt index fc52209612..51662a1e7a 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSClassDeclarationImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSClassDeclarationImpl.kt @@ -54,7 +54,7 @@ class KSClassDeclarationImpl private constructor(val ktClassOrObject: KtClassOrO override fun getSealedSubclasses(): Sequence { return if (Modifier.SEALED in modifiers) { - ResolverImpl.instance.incrementalContext.recordGetSealedSubclasses(this) + ResolverImpl.instance!!.incrementalContext.recordGetSealedSubclasses(this) descriptor.sealedSubclassesSequence() } else { emptySequence() @@ -103,7 +103,7 @@ class KSClassDeclarationImpl private constructor(val ktClassOrObject: KtClassOrO } override val superTypes: Sequence by lazy { - val resolver = ResolverImpl.instance + val resolver = ResolverImpl.instance!! ktClassOrObject.superTypeListEntries .asSequence() .map { KSTypeReferenceImpl.getCached(it.typeReference!!) } @@ -119,7 +119,7 @@ class KSClassDeclarationImpl private constructor(val ktClassOrObject: KtClassOrO } private val descriptor: ClassDescriptor by lazy { - (ResolverImpl.instance.resolveDeclaration(ktClassOrObject) as ClassDescriptor) + (ResolverImpl.instance!!.resolveDeclaration(ktClassOrObject) as ClassDescriptor) } override fun asType(typeArguments: List): KSType { diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSExpectActualImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSExpectActualImpl.kt index c48d9a10ac..18c3f9c53f 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSExpectActualImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSExpectActualImpl.kt @@ -59,6 +59,6 @@ class KSExpectActualImpl(val declaration: KtDeclaration) : KSExpectActual { } private val descriptor: DeclarationDescriptor? by lazy { - ResolverImpl.instance.resolveDeclaration(declaration) + ResolverImpl.instance!!.resolveDeclaration(declaration) } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSFunctionDeclarationImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSFunctionDeclarationImpl.kt index 5e64fbdc2d..312d960b42 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSFunctionDeclarationImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSFunctionDeclarationImpl.kt @@ -43,7 +43,7 @@ class KSFunctionDeclarationImpl private constructor(val ktFunction: KtFunction) } override fun findOverridee(): KSDeclaration? { - val descriptor = ResolverImpl.instance.resolveFunctionDeclaration(this) + val descriptor = ResolverImpl.instance!!.resolveFunctionDeclaration(this) return descriptor.safeAs()?.findClosestOverridee()?.toKSDeclaration() } @@ -108,7 +108,7 @@ class KSFunctionDeclarationImpl private constructor(val ktFunction: KtFunction) KSTypeReferenceImpl.getCached(ktFunction.typeReference!!) } else { KSTypeReferenceDeferredImpl.getCached(this) { - val desc = ResolverImpl.instance.resolveDeclaration(ktFunction) as FunctionDescriptor + val desc = ResolverImpl.instance!!.resolveDeclaration(ktFunction) as FunctionDescriptor getKSTypeCached(desc.returnTypeOrNothing) } } @@ -119,5 +119,5 @@ class KSFunctionDeclarationImpl private constructor(val ktFunction: KtFunction) } override fun asMemberOf(containing: KSType): KSFunction = - ResolverImpl.instance.asMemberOf(this, containing) + ResolverImpl.instance!!.asMemberOf(this, containing) } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyDeclarationImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyDeclarationImpl.kt index ff77fdb68d..aebf5c2ea5 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyDeclarationImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyDeclarationImpl.kt @@ -42,7 +42,7 @@ class KSPropertyDeclarationImpl private constructor(val ktProperty: KtProperty) } private val propertyDescriptor by lazy { - ResolverImpl.instance.resolveDeclaration(ktProperty) as? PropertyDescriptor + ResolverImpl.instance!!.resolveDeclaration(ktProperty) as? PropertyDescriptor } override val annotations: Sequence by lazy { @@ -67,8 +67,8 @@ class KSPropertyDeclarationImpl private constructor(val ktProperty: KtProperty) ktProperty.initializer != null -> true ktProperty.hasModifier(KtTokens.LATEINIT_KEYWORD) -> true else -> { - val context = ResolverImpl.instance.bindingTrace.bindingContext - val descriptor = ResolverImpl.instance.resolveDeclaration(ktProperty) + val context = ResolverImpl.instance!!.bindingTrace.bindingContext + val descriptor = ResolverImpl.instance!!.resolveDeclaration(ktProperty) descriptor is PropertyDescriptor && context[BindingContext.BACKING_FIELD_REQUIRED, descriptor] == true } } @@ -116,7 +116,7 @@ class KSPropertyDeclarationImpl private constructor(val ktProperty: KtProperty) } override fun asMemberOf(containing: KSType): KSType = - ResolverImpl.instance.asMemberOf(this, containing) + ResolverImpl.instance!!.asMemberOf(this, containing) } internal fun KtAnnotated.filterUseSiteTargetAnnotations(): Sequence { diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyDeclarationParameterImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyDeclarationParameterImpl.kt index 58207b9571..474ab97897 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyDeclarationParameterImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyDeclarationParameterImpl.kt @@ -81,7 +81,7 @@ class KSPropertyDeclarationParameterImpl private constructor(val ktParameter: Kt override fun isDelegated(): Boolean = false override fun findOverridee(): KSPropertyDeclaration? { - return ResolverImpl.instance.resolvePropertyDeclaration(this)?.original?.overriddenDescriptors + return ResolverImpl.instance!!.resolvePropertyDeclaration(this)?.original?.overriddenDescriptors ?.singleOrNull { it.overriddenDescriptors.isEmpty() } ?.toKSPropertyDeclaration() } @@ -91,5 +91,5 @@ class KSPropertyDeclarationParameterImpl private constructor(val ktParameter: Kt } override fun asMemberOf(containing: KSType): KSType = - ResolverImpl.instance.asMemberOf(this, containing) + ResolverImpl.instance!!.asMemberOf(this, containing) } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyGetterImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyGetterImpl.kt index 4c2aa86175..bf328c29f1 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyGetterImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertyGetterImpl.kt @@ -38,7 +38,7 @@ class KSPropertyGetterImpl private constructor(ktPropertyGetter: KtPropertyAcces if (property.typeReference != null) { KSTypeReferenceImpl.getCached(property.typeReference!!) } else { - val desc = ResolverImpl.instance.resolveDeclaration(property) as PropertyDescriptor + val desc = ResolverImpl.instance!!.resolveDeclaration(property) as PropertyDescriptor KSTypeReferenceDescriptorImpl.getCached(desc.returnType!!, origin, this) } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertySetterImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertySetterImpl.kt index 0718a7a98e..177567b049 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertySetterImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSPropertySetterImpl.kt @@ -35,7 +35,7 @@ class KSPropertySetterImpl private constructor(ktPropertySetter: KtPropertyAcces override val parameter: KSValueParameter by lazy { ktPropertySetter.parameterList?.parameters?.singleOrNull()?.let { KSValueParameterImpl.getCached(it) } ?: KSValueParameterSyntheticImpl.getCached(this) { - ResolverImpl.instance.resolvePropertyAccessorDeclaration(this) + ResolverImpl.instance!!.resolvePropertyAccessorDeclaration(this) ?.valueParameters?.singleOrNull() } } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeImpl.kt index 487564ddc4..4a9aef7c76 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeImpl.kt @@ -57,7 +57,7 @@ class KSTypeImpl private constructor( } override val declaration: KSDeclaration by lazy { - ResolverImpl.instance.findDeclaration(kotlinType.getAbbreviation() ?: kotlinType) + ResolverImpl.instance!!.findDeclaration(kotlinType.getAbbreviation() ?: kotlinType) } override val nullability: Nullability by lazy { @@ -77,7 +77,7 @@ class KSTypeImpl private constructor( override fun isAssignableFrom(that: KSType): Boolean { val subType = (that as? KSTypeImpl)?.kotlinType?.convertKotlinType() ?: return false - ResolverImpl.instance.incrementalContext.recordLookupWithSupertypes(subType) + ResolverImpl.instance!!.incrementalContext.recordLookupWithSupertypes(subType) val thisType = (this as? KSTypeImpl)?.kotlinType?.convertKotlinType() ?: return false return subType.isSubtypeOf(thisType) } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeReferenceImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeReferenceImpl.kt index 5f24307bdd..b129612cbc 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeReferenceImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/kotlin/KSTypeReferenceImpl.kt @@ -132,7 +132,7 @@ class KSTypeReferenceImpl private constructor(val ktTypeReference: KtTypeReferen return visitor.visitTypeReference(this, data) } - override fun resolve(): KSType = ResolverImpl.instance.resolveUserType(this) + override fun resolve(): KSType = ResolverImpl.instance!!.resolveUserType(this) override fun toString(): String { return element.toString() diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSConstructorSyntheticImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSConstructorSyntheticImpl.kt index 4696cde464..c8514dbf15 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSConstructorSyntheticImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSConstructorSyntheticImpl.kt @@ -115,5 +115,5 @@ class KSConstructorSyntheticImpl(val ksClassDeclaration: KSClassDeclaration) : } override fun asMemberOf(containing: KSType): KSFunction = - ResolverImpl.instance.asMemberOf(this, containing) + ResolverImpl.instance!!.asMemberOf(this, containing) } diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSErrorTypeClassDeclaration.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSErrorTypeClassDeclaration.kt index 9671c71430..4f99bbff2b 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSErrorTypeClassDeclaration.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSErrorTypeClassDeclaration.kt @@ -61,11 +61,11 @@ object KSErrorTypeClassDeclaration : KSClassDeclaration { override fun getSealedSubclasses(): Sequence = emptySequence() override fun asStarProjectedType(): KSType { - return ResolverImpl.instance.builtIns.nothingType + return ResolverImpl.instance!!.builtIns.nothingType } override fun asType(typeArguments: List): KSType { - return ResolverImpl.instance.builtIns.nothingType + return ResolverImpl.instance!!.builtIns.nothingType } override fun findActuals(): Sequence { diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSPropertyGetterSyntheticImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSPropertyGetterSyntheticImpl.kt index 1d9424fa8b..70455bb3df 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSPropertyGetterSyntheticImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSPropertyGetterSyntheticImpl.kt @@ -37,7 +37,7 @@ class KSPropertyGetterSyntheticImpl(val ksPropertyDeclaration: KSPropertyDeclara } private val descriptor: PropertyAccessorDescriptor by lazy { - ResolverImpl.instance.resolvePropertyDeclaration(ksPropertyDeclaration)!!.getter!! + ResolverImpl.instance!!.resolvePropertyDeclaration(ksPropertyDeclaration)!!.getter!! } override val returnType: KSTypeReference? by lazy { diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSPropertySetterSyntheticImpl.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSPropertySetterSyntheticImpl.kt index 6a8f52f6de..c8120e55f9 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSPropertySetterSyntheticImpl.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/synthetic/KSPropertySetterSyntheticImpl.kt @@ -37,7 +37,7 @@ class KSPropertySetterSyntheticImpl(val ksPropertyDeclaration: KSPropertyDeclara } private val descriptor: PropertyAccessorDescriptor by lazy { - ResolverImpl.instance.resolvePropertyDeclaration(ksPropertyDeclaration)!!.setter!! + ResolverImpl.instance!!.resolvePropertyDeclaration(ksPropertyDeclaration)!!.setter!! } override val parameter: KSValueParameter by lazy { diff --git a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/utils.kt b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/utils.kt index 7f85b7c0f8..65f0b628f1 100644 --- a/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/utils.kt +++ b/compiler-plugin/src/main/kotlin/com/google/devtools/ksp/symbol/impl/utils.kt @@ -97,7 +97,7 @@ fun PsiElement.findParentDeclaration(): KSDeclaration? { fun PsiElement.toLocation(): Location { val file = this.containingFile - val document = ResolverImpl.instance.psiDocumentManager.getDocument(file) ?: return NonExistLocation + val document = ResolverImpl.instance!!.psiDocumentManager.getDocument(file) ?: return NonExistLocation return FileLocation(file.virtualFile.path, document.getLineNumber(this.textOffset) + 1) } @@ -205,7 +205,7 @@ internal inline fun T.findClosestOverride // one declared first in the code. (getOwnerForEffectiveDispatchReceiverParameter() as? ClassDescriptor)?.defaultType?.let { - ResolverImpl.instance.incrementalContext.recordLookupWithSupertypes(it) + ResolverImpl.instance!!.incrementalContext.recordLookupWithSupertypes(it) } val queue = ArrayDeque() @@ -213,12 +213,12 @@ internal inline fun T.findClosestOverride while (queue.isNotEmpty()) { val current = queue.removeFirst() - ResolverImpl.instance.incrementalContext.recordLookupForCallableMemberDescriptor(current.original) + ResolverImpl.instance!!.incrementalContext.recordLookupForCallableMemberDescriptor(current.original) val overriddenDescriptors: Collection = current.original.overriddenDescriptors.filterIsInstance() overriddenDescriptors.firstOrNull { it.kind != CallableMemberDescriptor.Kind.FAKE_OVERRIDE }?.let { - ResolverImpl.instance.incrementalContext.recordLookupForCallableMemberDescriptor(it.original) + ResolverImpl.instance!!.incrementalContext.recordLookupForCallableMemberDescriptor(it.original) return it.original as T? } // if all methods are fake, add them to the queue @@ -326,25 +326,25 @@ internal class DeclarationOrdering( // might be a property without backing field. Use method ordering instead decl.getter?.let { getter -> return@getOrPut findMethodOrder( - ResolverImpl.instance.getJvmName(getter).toString() + ResolverImpl.instance!!.getJvmName(getter).toString() ) { - ResolverImpl.instance.mapToJvmSignature(getter) + ResolverImpl.instance!!.mapToJvmSignature(getter) } } decl.setter?.let { setter -> return@getOrPut findMethodOrder( - ResolverImpl.instance.getJvmName(setter).toString() + ResolverImpl.instance!!.getJvmName(setter).toString() ) { - ResolverImpl.instance.mapToJvmSignature(setter) + ResolverImpl.instance!!.mapToJvmSignature(setter) } } orderProvider.next(decl) } is KSFunctionDeclarationDescriptorImpl -> { findMethodOrder( - ResolverImpl.instance.getJvmName(decl).toString() + ResolverImpl.instance!!.getJvmName(decl).toString() ) { - ResolverImpl.instance.mapToJvmSignature(decl).toString() + ResolverImpl.instance!!.mapToJvmSignature(decl).toString() } } else -> orderProvider.nextIgnoreSealed() @@ -488,7 +488,7 @@ internal val KSPropertyDeclaration.jvmAccessFlag: Int internal val KSFunctionDeclaration.jvmAccessFlag: Int get() = when (origin) { Origin.KOTLIN_LIB -> { - val jvmDesc = ResolverImpl.instance.mapToJvmSignatureInternal(this) + val jvmDesc = ResolverImpl.instance!!.mapToJvmSignatureInternal(this) val descriptor = (this as KSFunctionDeclarationDescriptorImpl).descriptor // Companion. doesn't have containing KotlinJvmBinaryClass. val kotlinBinaryJavaClass = descriptor.getContainingKotlinJvmBinaryClass() @@ -513,7 +513,7 @@ internal fun KotlinType.convertKotlinType(): KotlinType { val declarationDescriptor = this.constructor.declarationDescriptor val base = if (declarationDescriptor?.shouldMapToKotlinForAssignabilityCheck() == true) { JavaToKotlinClassMapper - .mapJavaToKotlin(declarationDescriptor.fqNameSafe, ResolverImpl.instance.module.builtIns) + .mapJavaToKotlin(declarationDescriptor.fqNameSafe, ResolverImpl.instance!!.module.builtIns) ?.defaultType ?.replace(this.arguments) ?: this