[IR] Made signature nullable (#3860)

This commit is contained in:
LepilkinaElena
2020-10-20 21:13:40 +03:00
committed by GitHub
parent 6a9c72e77c
commit b786cf7559
16 changed files with 33 additions and 39 deletions
@@ -14,8 +14,8 @@ interface IrClassifierEqualityChecker {
object FqNameEqualityChecker : IrClassifierEqualityChecker {
override fun areEqual(left: IrClassifierSymbol, right: IrClassifierSymbol): Boolean =
left === right ||
left.isPublicApi && right.isPublicApi && left.signature == right.signature
left.signature != null && left.signature == right.signature
override fun getHashCode(symbol: IrClassifierSymbol): Int =
if (symbol.isPublicApi) symbol.signature.hashCode() else symbol.hashCode()
symbol.signature?.hashCode() ?: symbol.hashCode()
}
@@ -18,10 +18,8 @@ abstract class IrDelegatingSymbol<S : IrBindableSymbol<D, B>, B : IrSymbolOwner,
override val descriptor: D get() = delegate.descriptor
override val isBound: Boolean get() = delegate.isBound
override val isPublicApi: Boolean
get() = delegate.isPublicApi
override val signature: IdSignature
override val signature: IdSignature?
get() = delegate.signature
override fun bind(owner: B) = delegate.bind(owner)
@@ -32,9 +32,10 @@ interface IrSymbol {
val isBound: Boolean
val signature: IdSignature
val signature: IdSignature?
val isPublicApi: Boolean
get() = signature != null
}
interface IrBindableSymbol<out D : DeclarationDescriptor, B : IrSymbolOwner> : IrSymbol {
@@ -22,7 +22,7 @@ class DescriptorlessExternalPackageFragmentSymbol : IrExternalPackageFragmentSym
override val isPublicApi: Boolean
get() = TODO("Not yet implemented")
override val signature: IdSignature
override val signature: IdSignature?
get() = TODO("Not yet implemented")
override val isBound get() = _owner != null
@@ -69,10 +69,8 @@ abstract class IrBindableSymbolBase<out D : DeclarationDescriptor, B : IrSymbolO
}
}
override val isPublicApi: Boolean = false
override val signature: IdSignature
get() = error("IdSignature is allowed only for PublicApi symbols")
override val signature: IdSignature?
get() = null
override val isBound: Boolean
get() = _owner != null
@@ -52,8 +52,6 @@ abstract class IrBindablePublicSymbolBase<out D : DeclarationDescriptor, B : IrS
}
}
override val isPublicApi: Boolean = true
override val isBound: Boolean
get() = _owner != null
}
@@ -345,18 +345,18 @@ interface IrTypeSystemContext : TypeSystemContext, TypeSystemCommonSuperTypesCon
}
override fun TypeConstructorMarker.getPrimitiveType(): PrimitiveType? {
if (this !is IrClassSymbol || !isPublicApi) return null
if (this !is IrClassSymbol) return null
val signature = signature.asPublic()
val signature = signature?.asPublic()
if (signature == null || signature.packageFqName != "kotlin") return null
return PrimitiveType.getByShortName(signature.declarationFqName)
}
override fun TypeConstructorMarker.getPrimitiveArrayType(): PrimitiveType? {
if (this !is IrClassSymbol || !isPublicApi) return null
if (this !is IrClassSymbol) return null
val signature = signature.asPublic()
val signature = signature?.asPublic()
if (signature == null || signature.packageFqName != "kotlin") return null
return PrimitiveType.getByShortArrayName(signature.declarationFqName)
@@ -57,7 +57,6 @@ fun getPublicSignature(packageFqName: FqName, name: String) =
private fun IrType.isClassType(signature: IdSignature.PublicSignature, hasQuestionMark: Boolean? = null): Boolean {
if (this !is IrSimpleType) return false
if (hasQuestionMark != null && this.hasQuestionMark != hasQuestionMark) return false
if (!classifier.isPublicApi || !classifier.signature.isPublic) return false
return signature == classifier.signature
}
@@ -86,7 +86,7 @@ private val IrConstructorCall.annotationClass
get() = this.symbol.owner.constructedClass
val IrClass.packageFqName: FqName?
get() = if (symbol.isPublicApi) symbol.signature.packageFqName() else parent.getPackageFragment()?.fqName
get() = symbol.signature?.packageFqName() ?: parent.getPackageFragment()?.fqName
fun IrDeclarationWithName.hasEqualFqName(fqName: FqName): Boolean =
name == fqName.shortName() && when (val parent = parent) {
@@ -77,7 +77,10 @@ class DeclarationStubGenerator(
return generateStubBySymbol(symbol, symbol.descriptor)
}
val descriptor = if (symbol.descriptor is WrappedDeclarationDescriptor<*>)
findDescriptorBySignature(symbol.signature)
findDescriptorBySignature(
symbol.signature
?: error("Symbol is not public API. Expected signature for symbol: ${symbol.descriptor}")
)
else
symbol.descriptor
if (descriptor == null) return null
@@ -216,9 +216,9 @@ class SymbolTable(
}
override fun set(d: D, s: S) {
if (s.isPublicApi) {
idSigToSymbol[s.signature] = s
} else {
s.signature?.let {
idSigToSymbol[it] = s
} ?: run {
descriptorToSymbol[d] = s
}
}
@@ -264,10 +264,10 @@ class SymbolTable(
fun getLocal(d: D) = descriptorToSymbol[d]
operator fun set(d: D, s: S) {
if (s.isPublicApi) {
s.signature?.let {
require(d is TypeParameterDescriptor)
idSigToSymbol[s.signature] = s
} else {
idSigToSymbol[it] = s
} ?: run {
descriptorToSymbol[d] = s
}
}