From 8b7cfcda10f8ba86bcccaa087cf6ced067397a62 Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 7 Jun 2023 15:42:38 +0300 Subject: [PATCH] [FIR] Add `toString()` methods to some ConeSubstitutor implementation This is needed only for pleasant debugging --- .../fir/types/ConeTypeVariableAndStubTypes.kt | 6 ++++- .../fir/resolve/substitution/Substitutors.kt | 27 +++++++++++++++++++ .../TypeVariableTypeRemovingSubstitutor.kt | 4 +++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypeVariableAndStubTypes.kt b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypeVariableAndStubTypes.kt index e0ec63584d9..605447ad739 100644 --- a/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypeVariableAndStubTypes.kt +++ b/compiler/fir/cones/src/org/jetbrains/kotlin/fir/types/ConeTypeVariableAndStubTypes.kt @@ -55,7 +55,11 @@ data class ConeStubTypeConstructor( val variable: ConeTypeVariable, val isTypeVariableInSubtyping: Boolean, val isForFixation: Boolean = false, -) : TypeConstructorMarker +) : TypeConstructorMarker { + override fun toString(): String { + return "Stub(${variable.typeConstructor.debugName})" + } +} sealed class ConeStubType(val constructor: ConeStubTypeConstructor, override val nullability: ConeNullability) : StubTypeMarker, ConeSimpleKotlinType() { diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt index a86b23bf840..693fe7c0865 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt @@ -183,6 +183,10 @@ data class ChainedSubstitutor(private val first: ConeSubstitutor, private val se first.substituteOrNull(type)?.let { return second.substituteOrSelf(it) } return second.substituteOrNull(type) } + + override fun toString(): String { + return "$first then $second" + } } fun ConeSubstitutor.chain(other: ConeSubstitutor): ConeSubstitutor { @@ -220,6 +224,12 @@ class ConeSubstitutorByMap( } override fun hashCode() = hashCode + + override fun toString(): String { + return substitution.entries.joinToString(prefix = "{", postfix = "}", separator = " | ") { (param, type) -> + "${param.name} -> ${type.renderForDebugging()}" + } + } } class ConeRawScopeSubstitutor( @@ -292,6 +302,12 @@ internal class ConeTypeSubstitutorByTypeConstructor( val approximatedIntegerLiteralType = if (approximateIntegerLiterals) new.approximateIntegerLiteralType() else new return approximatedIntegerLiteralType.updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type) } + + override fun toString(): String { + return map.entries.joinToString(prefix = "{", postfix = "}", separator = " | ") { (constructor, type) -> + "$constructor -> ${type.renderForDebugging()}" + } + } } // Note: builder inference uses TypeSubstitutorByTypeConstructor for not fixed type substitution @@ -304,6 +320,13 @@ class NotFixedTypeToVariableSubstitutorForDelegateInference( if (type.constructor.isTypeVariableInSubtyping) return null return bindings[type.constructor.variable].updateNullabilityIfNeeded(type) } + + override fun toString(): String { + return bindings.entries.joinToString(prefix = "{", postfix = "}", separator = " | ") { (variable, type) -> + require(variable is ConeTypeVariable) + "TV(${variable.typeConstructor.debugName}) -> ${type.renderForDebugging()}" + } + } } class ConeStubAndTypeVariableToErrorTypeSubstitutor( @@ -328,6 +351,10 @@ class ConeStubAndTypeVariableToErrorTypeSubstitutor( else -> null } } + + override fun toString(): String { + return "{ -> }" + } } fun ConeSubstitutor.replaceStubsAndTypeVariablesToErrors( diff --git a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/TypeVariableTypeRemovingSubstitutor.kt b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/TypeVariableTypeRemovingSubstitutor.kt index f6f84bad087..6190dd9a011 100644 --- a/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/TypeVariableTypeRemovingSubstitutor.kt +++ b/compiler/fir/semantics/src/org/jetbrains/kotlin/fir/resolve/calls/TypeVariableTypeRemovingSubstitutor.kt @@ -30,4 +30,8 @@ private class TypeVariableTypeRemovingSubstitutor(typeContext: ConeTypeContext) } return ConeErrorType(ConeUnknownLambdaParameterTypeDiagnostic()) } + + override fun toString(): String { + return "{ -> }" + } }