FIR IDE: make KtSymbolByFirBuilder to be a weak ref in KtType to avoid memory leaks
This commit is contained in:
committed by
TeamCityServer
parent
73bb2e76f2
commit
1d1eab6947
+22
-16
@@ -27,18 +27,19 @@ internal interface KtFirType : ValidityTokenOwner {
|
|||||||
internal class KtFirUsualClassType(
|
internal class KtFirUsualClassType(
|
||||||
coneType: ConeClassLikeTypeImpl,
|
coneType: ConeClassLikeTypeImpl,
|
||||||
override val token: ValidityToken,
|
override val token: ValidityToken,
|
||||||
private val firBuilder: KtSymbolByFirBuilder,
|
_builder: KtSymbolByFirBuilder,
|
||||||
) : KtUsualClassType(), KtFirType {
|
) : KtUsualClassType(), KtFirType {
|
||||||
override val coneType by weakRef(coneType)
|
override val coneType by weakRef(coneType)
|
||||||
|
private val builder by weakRef(_builder)
|
||||||
|
|
||||||
override val classId: ClassId get() = withValidityAssertion { coneType.lookupTag.classId }
|
override val classId: ClassId get() = withValidityAssertion { coneType.lookupTag.classId }
|
||||||
override val classSymbol: KtClassLikeSymbol by cached {
|
override val classSymbol: KtClassLikeSymbol by cached {
|
||||||
firBuilder.classifierBuilder.buildClassLikeSymbolByLookupTag(coneType.lookupTag)
|
builder.classifierBuilder.buildClassLikeSymbolByLookupTag(coneType.lookupTag)
|
||||||
?: error("Class ${coneType.lookupTag} was not found")
|
?: error("Class ${coneType.lookupTag} was not found")
|
||||||
}
|
}
|
||||||
override val typeArguments: List<KtTypeArgument> by cached {
|
override val typeArguments: List<KtTypeArgument> by cached {
|
||||||
coneType.typeArguments.map { typeArgument ->
|
coneType.typeArguments.map { typeArgument ->
|
||||||
firBuilder.typeBuilder.buildTypeArgument(typeArgument)
|
builder.typeBuilder.buildTypeArgument(typeArgument)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,24 +50,25 @@ internal class KtFirUsualClassType(
|
|||||||
internal class KtFirFunctionalType(
|
internal class KtFirFunctionalType(
|
||||||
coneType: ConeClassLikeTypeImpl,
|
coneType: ConeClassLikeTypeImpl,
|
||||||
override val token: ValidityToken,
|
override val token: ValidityToken,
|
||||||
private val firBuilder: KtSymbolByFirBuilder,
|
_builder: KtSymbolByFirBuilder,
|
||||||
) : KtFunctionalType(), KtFirType {
|
) : KtFunctionalType(), KtFirType {
|
||||||
override val coneType by weakRef(coneType)
|
override val coneType by weakRef(coneType)
|
||||||
|
private val builder by weakRef(_builder)
|
||||||
|
|
||||||
override val classId: ClassId get() = withValidityAssertion { coneType.lookupTag.classId }
|
override val classId: ClassId get() = withValidityAssertion { coneType.lookupTag.classId }
|
||||||
override val classSymbol: KtClassLikeSymbol by cached {
|
override val classSymbol: KtClassLikeSymbol by cached {
|
||||||
firBuilder.classifierBuilder.buildClassLikeSymbolByLookupTag(coneType.lookupTag)
|
builder.classifierBuilder.buildClassLikeSymbolByLookupTag(coneType.lookupTag)
|
||||||
?: error("Class ${coneType.lookupTag} was not found")
|
?: error("Class ${coneType.lookupTag} was not found")
|
||||||
}
|
}
|
||||||
override val typeArguments: List<KtTypeArgument> by cached {
|
override val typeArguments: List<KtTypeArgument> by cached {
|
||||||
coneType.typeArguments.map { typeArgument ->
|
coneType.typeArguments.map { typeArgument ->
|
||||||
firBuilder.typeBuilder.buildTypeArgument(typeArgument)
|
builder.typeBuilder.buildTypeArgument(typeArgument)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val nullability: KtTypeNullability get() = withValidityAssertion { KtTypeNullability.create(coneType.isNullable) }
|
override val nullability: KtTypeNullability get() = withValidityAssertion { KtTypeNullability.create(coneType.isNullable) }
|
||||||
|
|
||||||
override val isSuspend: Boolean get() = withValidityAssertion { coneType.isSuspendFunctionType(firBuilder.rootSession) }
|
override val isSuspend: Boolean get() = withValidityAssertion { coneType.isSuspendFunctionType(builder.rootSession) }
|
||||||
override val arity: Int
|
override val arity: Int
|
||||||
get() = withValidityAssertion {
|
get() = withValidityAssertion {
|
||||||
if (coneType.isExtensionFunctionType) coneType.typeArguments.size - 2
|
if (coneType.isExtensionFunctionType) coneType.typeArguments.size - 2
|
||||||
@@ -112,11 +114,12 @@ internal class KtFirCapturedType(
|
|||||||
internal class KtFirDefinitelyNotNullType(
|
internal class KtFirDefinitelyNotNullType(
|
||||||
coneType: ConeDefinitelyNotNullType,
|
coneType: ConeDefinitelyNotNullType,
|
||||||
override val token: ValidityToken,
|
override val token: ValidityToken,
|
||||||
private val firBuilder: KtSymbolByFirBuilder,
|
_builder: KtSymbolByFirBuilder,
|
||||||
) : KtDefinitelyNotNullType(), KtFirType {
|
) : KtDefinitelyNotNullType(), KtFirType {
|
||||||
override val coneType by weakRef(coneType)
|
override val coneType by weakRef(coneType)
|
||||||
|
private val builder by weakRef(_builder)
|
||||||
|
|
||||||
override val original: KtType by cached { firBuilder.typeBuilder.buildKtType(this.coneType.original) }
|
override val original: KtType by cached { builder.typeBuilder.buildKtType(this.coneType.original) }
|
||||||
|
|
||||||
override fun asStringForDebugging(): String = withValidityAssertion { coneType.render() }
|
override fun asStringForDebugging(): String = withValidityAssertion { coneType.render() }
|
||||||
}
|
}
|
||||||
@@ -126,13 +129,14 @@ internal class KtFirDefinitelyNotNullType(
|
|||||||
internal class KtFirTypeParameterType(
|
internal class KtFirTypeParameterType(
|
||||||
coneType: ConeTypeParameterType,
|
coneType: ConeTypeParameterType,
|
||||||
override val token: ValidityToken,
|
override val token: ValidityToken,
|
||||||
private val firBuilder: KtSymbolByFirBuilder,
|
_builder: KtSymbolByFirBuilder,
|
||||||
) : KtTypeParameterType(), KtFirType {
|
) : KtTypeParameterType(), KtFirType {
|
||||||
override val coneType by weakRef(coneType)
|
override val coneType by weakRef(coneType)
|
||||||
|
private val builder by weakRef(_builder)
|
||||||
|
|
||||||
override val name: Name get() = withValidityAssertion { coneType.lookupTag.name }
|
override val name: Name get() = withValidityAssertion { coneType.lookupTag.name }
|
||||||
override val symbol: KtTypeParameterSymbol by cached {
|
override val symbol: KtTypeParameterSymbol by cached {
|
||||||
firBuilder.classifierBuilder.buildTypeParameterSymbolByLookupTag(coneType.lookupTag)
|
builder.classifierBuilder.buildTypeParameterSymbolByLookupTag(coneType.lookupTag)
|
||||||
?: error("Type parameter ${coneType.lookupTag} was not found")
|
?: error("Type parameter ${coneType.lookupTag} was not found")
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,24 +147,26 @@ internal class KtFirTypeParameterType(
|
|||||||
internal class KtFirFlexibleType(
|
internal class KtFirFlexibleType(
|
||||||
coneType: ConeFlexibleType,
|
coneType: ConeFlexibleType,
|
||||||
override val token: ValidityToken,
|
override val token: ValidityToken,
|
||||||
private val firBuilder: KtSymbolByFirBuilder,
|
_builder: KtSymbolByFirBuilder,
|
||||||
) : KtFlexibleType(), KtFirType {
|
) : KtFlexibleType(), KtFirType {
|
||||||
override val coneType by weakRef(coneType)
|
override val coneType by weakRef(coneType)
|
||||||
|
private val builder by weakRef(_builder)
|
||||||
|
|
||||||
override val lowerBound: KtType by cached { firBuilder.typeBuilder.buildKtType(coneType.lowerBound) }
|
override val lowerBound: KtType by cached { builder.typeBuilder.buildKtType(coneType.lowerBound) }
|
||||||
override val upperBound: KtType by cached { firBuilder.typeBuilder.buildKtType(coneType.upperBound) }
|
override val upperBound: KtType by cached { builder.typeBuilder.buildKtType(coneType.upperBound) }
|
||||||
override fun asStringForDebugging(): String = withValidityAssertion { coneType.render() }
|
override fun asStringForDebugging(): String = withValidityAssertion { coneType.render() }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class KtFirIntersectionType(
|
internal class KtFirIntersectionType(
|
||||||
coneType: ConeIntersectionType,
|
coneType: ConeIntersectionType,
|
||||||
override val token: ValidityToken,
|
override val token: ValidityToken,
|
||||||
private val firBuilder: KtSymbolByFirBuilder,
|
_builder: KtSymbolByFirBuilder,
|
||||||
) : KtIntersectionType(), KtFirType {
|
) : KtIntersectionType(), KtFirType {
|
||||||
override val coneType by weakRef(coneType)
|
override val coneType by weakRef(coneType)
|
||||||
|
private val builder by weakRef(_builder)
|
||||||
|
|
||||||
override val conjuncts: List<KtType> by cached {
|
override val conjuncts: List<KtType> by cached {
|
||||||
coneType.intersectedTypes.map { conjunct -> firBuilder.typeBuilder.buildKtType(conjunct) }
|
coneType.intersectedTypes.map { conjunct -> builder.typeBuilder.buildKtType(conjunct) }
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun asStringForDebugging(): String = withValidityAssertion { coneType.render() }
|
override fun asStringForDebugging(): String = withValidityAssertion { coneType.render() }
|
||||||
|
|||||||
Reference in New Issue
Block a user