[FIR] Add rendering for attribites of cone types

This commit is contained in:
Dmitriy Novozhilov
2020-09-17 17:18:35 +03:00
parent d48307ec34
commit 57a57d10da
4 changed files with 34 additions and 12 deletions
@@ -4,16 +4,16 @@ FILE: nestedExtensionFunctionType.kt
public final fun test_0(a: R|A|, f: R|A.() -> kotlin/Unit|): R|kotlin/Unit| { public final fun test_0(a: R|A|, f: R|A.() -> kotlin/Unit|): R|kotlin/Unit| {
R|<local>/f|.R|FakeOverride<kotlin/Function1.invoke: R|kotlin/Unit|>|(R|<local>/a|) R|<local>/f|.R|FakeOverride<kotlin/Function1.invoke: R|kotlin/Unit|>|(R|<local>/a|)
} }
public final fun test_1(a: R|A|, ys: R|kotlin/collections/List<kotlin/Function1<A, kotlin/Unit>>|): R|kotlin/Unit| { public final fun test_1(a: R|A|, ys: R|kotlin/collections/List<@ExtensionFunctionType kotlin/Function1<A, kotlin/Unit>>|): R|kotlin/Unit| {
lval <iterator>: R|kotlin/collections/Iterator<kotlin/Function1<A, kotlin/Unit>>| = R|<local>/ys|.R|FakeOverride<kotlin/collections/List.iterator: R|kotlin/collections/Iterator<kotlin/Function1<A, kotlin/Unit>>|>|() lval <iterator>: R|kotlin/collections/Iterator<@ExtensionFunctionType kotlin/Function1<A, kotlin/Unit>>| = R|<local>/ys|.R|FakeOverride<kotlin/collections/List.iterator: R|kotlin/collections/Iterator<@ExtensionFunctionType kotlin/Function1<A, kotlin/Unit>>|>|()
while(R|<local>/<iterator>|.R|kotlin/collections/Iterator.hasNext|()) { while(R|<local>/<iterator>|.R|kotlin/collections/Iterator.hasNext|()) {
lval y: R|(A) -> kotlin/Unit| = R|<local>/<iterator>|.R|FakeOverride<kotlin/collections/Iterator.next: R|(A) -> kotlin/Unit|>|() lval y: R|(A) -> kotlin/Unit| = R|<local>/<iterator>|.R|FakeOverride<kotlin/collections/Iterator.next: R|(A) -> kotlin/Unit|>|()
R|<local>/y|.R|FakeOverride<kotlin/Function1.invoke: R|kotlin/Unit|>|(R|<local>/a|) R|<local>/y|.R|FakeOverride<kotlin/Function1.invoke: R|kotlin/Unit|>|(R|<local>/a|)
} }
} }
public final fun test_2(a: R|A|, vararg zs: @R|kotlin/ExtensionFunctionType|() R|kotlin/Array<out kotlin/Function1<A, kotlin/Unit>>|): R|kotlin/Unit| { public final fun test_2(a: R|A|, vararg zs: @R|kotlin/ExtensionFunctionType|() R|kotlin/Array<out @ExtensionFunctionType kotlin/Function1<A, kotlin/Unit>>|): R|kotlin/Unit| {
lval <iterator>: R|kotlin/collections/Iterator<kotlin/Function1<A, kotlin/Unit>>| = R|<local>/zs|.R|FakeOverride<kotlin/Array.iterator: R|kotlin/collections/Iterator<CapturedType(out kotlin/Function1<A, kotlin/Unit>)>|>|() lval <iterator>: R|kotlin/collections/Iterator<@ExtensionFunctionType kotlin/Function1<A, kotlin/Unit>>| = R|<local>/zs|.R|FakeOverride<kotlin/Array.iterator: R|kotlin/collections/Iterator<CapturedType(out @ExtensionFunctionType kotlin/Function1<A, kotlin/Unit>)>|>|()
while(R|<local>/<iterator>|.R|kotlin/collections/Iterator.hasNext|()) { while(R|<local>/<iterator>|.R|kotlin/collections/Iterator.hasNext|()) {
lval z: R|(A) -> kotlin/Unit| = R|<local>/<iterator>|.R|FakeOverride<kotlin/collections/Iterator.next: R|(A) -> kotlin/Unit|>|() lval z: R|(A) -> kotlin/Unit| = R|<local>/<iterator>|.R|FakeOverride<kotlin/collections/Iterator.next: R|(A) -> kotlin/Unit|>|()
R|<local>/z|.R|FakeOverride<kotlin/Function1.invoke: R|kotlin/Unit|>|(R|<local>/a|) R|<local>/z|.R|FakeOverride<kotlin/Function1.invoke: R|kotlin/Unit|>|(R|<local>/a|)
@@ -19,6 +19,8 @@ object CompilerConeAttributes {
override fun isSubtypeOf(other: Exact?): Boolean = true override fun isSubtypeOf(other: Exact?): Boolean = true
override val key: KClass<out Exact> = Exact::class override val key: KClass<out Exact> = Exact::class
override fun toString(): String = "@Exact"
} }
object NoInfer : ConeAttribute<NoInfer>() { object NoInfer : ConeAttribute<NoInfer>() {
@@ -29,6 +31,8 @@ object CompilerConeAttributes {
override fun isSubtypeOf(other: NoInfer?): Boolean = true override fun isSubtypeOf(other: NoInfer?): Boolean = true
override val key: KClass<out NoInfer> = NoInfer::class override val key: KClass<out NoInfer> = NoInfer::class
override fun toString(): String = "@NoInfer"
} }
object ExtensionFunctionType : ConeAttribute<ExtensionFunctionType>() { object ExtensionFunctionType : ConeAttribute<ExtensionFunctionType>() {
@@ -39,6 +43,8 @@ object CompilerConeAttributes {
override fun isSubtypeOf(other: ExtensionFunctionType?): Boolean = true override fun isSubtypeOf(other: ExtensionFunctionType?): Boolean = true
override val key: KClass<out ExtensionFunctionType> = ExtensionFunctionType::class override val key: KClass<out ExtensionFunctionType> = ExtensionFunctionType::class
override fun toString(): String = "@ExtensionFunctionType"
} }
object UnsafeVariance : ConeAttribute<UnsafeVariance>() { object UnsafeVariance : ConeAttribute<UnsafeVariance>() {
@@ -49,6 +55,8 @@ object CompilerConeAttributes {
override fun isSubtypeOf(other: UnsafeVariance?): Boolean = true override fun isSubtypeOf(other: UnsafeVariance?): Boolean = true
override val key: KClass<out UnsafeVariance> = UnsafeVariance::class override val key: KClass<out UnsafeVariance> = UnsafeVariance::class
override fun toString(): String = "@UnsafeVariance"
} }
} }
@@ -18,11 +18,15 @@ abstract class ConeAttribute<T : ConeAttribute<T>> {
abstract fun intersect(other: @UnsafeVariance T?): T? abstract fun intersect(other: @UnsafeVariance T?): T?
abstract fun isSubtypeOf(other: @UnsafeVariance T?): Boolean abstract fun isSubtypeOf(other: @UnsafeVariance T?): Boolean
abstract override fun toString(): String
abstract val key: KClass<out T> abstract val key: KClass<out T>
} }
@OptIn(Protected::class) @OptIn(Protected::class)
class ConeAttributes private constructor(attributes: List<ConeAttribute<*>>) : AttributeArrayOwner<ConeAttribute<*>, ConeAttribute<*>>() { class ConeAttributes private constructor(attributes: List<ConeAttribute<*>>) : AttributeArrayOwner<ConeAttribute<*>, ConeAttribute<*>>(),
Iterable<ConeAttribute<*>> {
companion object : TypeRegistry<ConeAttribute<*>, ConeAttribute<*>>() { companion object : TypeRegistry<ConeAttribute<*>, ConeAttribute<*>>() {
inline fun <reified T : ConeAttribute<T>> attributeAccessor(): ReadOnlyProperty<ConeAttributes, T?> { inline fun <reified T : ConeAttribute<T>> attributeAccessor(): ReadOnlyProperty<ConeAttributes, T?> {
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
@@ -54,6 +58,10 @@ class ConeAttributes private constructor(attributes: List<ConeAttribute<*>>) : A
return perform(other) { this.intersect(it) } return perform(other) { this.intersect(it) }
} }
override fun iterator(): Iterator<ConeAttribute<*>> {
return arrayMap.iterator()
}
private inline fun perform(other: ConeAttributes, op: ConeAttribute<*>.(ConeAttribute<*>?) -> ConeAttribute<*>?): ConeAttributes { private inline fun perform(other: ConeAttributes, op: ConeAttribute<*>.(ConeAttribute<*>?) -> ConeAttribute<*>?): ConeAttributes {
if (this.isEmpty() && other.isEmpty()) return this if (this.isEmpty() && other.isEmpty()) return this
val attributes = mutableListOf<ConeAttribute<*>>() val attributes = mutableListOf<ConeAttribute<*>>()
@@ -12,12 +12,13 @@ import kotlin.contracts.contract
fun ConeKotlinType.render(): String { fun ConeKotlinType.render(): String {
val nullabilitySuffix = if (this !is ConeKotlinErrorType && this !is ConeClassErrorType) nullability.suffix else "" val nullabilitySuffix = if (this !is ConeKotlinErrorType && this !is ConeClassErrorType) nullability.suffix else ""
return when (this) { return when (this) {
is ConeTypeVariableType -> "TypeVariable(${this.lookupTag.name})" is ConeTypeVariableType -> "${renderAttributes()}TypeVariable(${this.lookupTag.name})"
is ConeDefinitelyNotNullType -> "${original.render()}!!" is ConeDefinitelyNotNullType -> "${original.render()}!!"
is ConeClassErrorType -> "ERROR CLASS: ${diagnostic.reason}" is ConeClassErrorType -> "${renderAttributes()}ERROR CLASS: ${diagnostic.reason}"
is ConeCapturedType -> "CapturedType(${constructor.projection.render()})" is ConeCapturedType -> "${renderAttributes()}CapturedType(${constructor.projection.render()})"
is ConeClassLikeType -> { is ConeClassLikeType -> {
buildString { buildString {
append(renderAttributes())
append(lookupTag.classId.asString()) append(lookupTag.classId.asString())
if (typeArguments.isNotEmpty()) { if (typeArguments.isNotEmpty()) {
append(typeArguments.joinToString(prefix = "<", postfix = ">") { append(typeArguments.joinToString(prefix = "<", postfix = ">") {
@@ -27,7 +28,7 @@ fun ConeKotlinType.render(): String {
} }
} }
is ConeLookupTagBasedType -> { is ConeLookupTagBasedType -> {
lookupTag.name.asString() "${renderAttributes()}${lookupTag.name.asString()}"
} }
is ConeFlexibleType -> { is ConeFlexibleType -> {
buildString { buildString {
@@ -41,15 +42,20 @@ fun ConeKotlinType.render(): String {
is ConeIntersectionType -> { is ConeIntersectionType -> {
intersectedTypes.joinToString( intersectedTypes.joinToString(
separator = " & ", separator = " & ",
prefix = "it(", prefix = "${renderAttributes()}it(",
postfix = ")" postfix = ")"
) )
} }
is ConeStubType -> "Stub: $variable" is ConeStubType -> "${renderAttributes()}Stub: $variable"
is ConeIntegerLiteralType -> "ILT: $value" is ConeIntegerLiteralType -> "${renderAttributes()}ILT: $value"
} + nullabilitySuffix } + nullabilitySuffix
} }
private fun ConeKotlinType.renderAttributes(): String {
if (!attributes.any()) return ""
return attributes.joinToString(" ", postfix = " ") { it.toString() }
}
private fun ConeTypeProjection.render(): String { private fun ConeTypeProjection.render(): String {
return when (this) { return when (this) {
ConeStarProjection -> "*" ConeStarProjection -> "*"