From 1c9f08e9861c224a3c27a357a16e24da7a6e2b3f Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Mon, 25 Jul 2016 11:24:02 +0300 Subject: [PATCH] Data flow values: STABLE_COMPLEX_EXPRESSION kind is removed, no use cases exist for them --- .../calls/smartcasts/DataFlowValueFactory.kt | 28 ++----------------- .../resolve/calls/smartcasts/DataFlowValue.kt | 4 +-- 2 files changed, 3 insertions(+), 29 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.kt index eaf0786766f..d3b4c96f1d8 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValueFactory.kt @@ -57,16 +57,6 @@ object DataFlowValueFactory { resolutionContext: ResolutionContext<*> ) = createDataFlowValue(expression, type, resolutionContext.trace.bindingContext, resolutionContext.scope.ownerDescriptor) - private fun isComplexExpression(expression: KtExpression): Boolean = when(expression) { - is KtBlockExpression, is KtIfExpression, is KtWhenExpression -> true - is KtBinaryExpression -> expression.operationToken === KtTokens.ELVIS - is KtParenthesizedExpression -> { - val deparenthesized = KtPsiUtil.deparenthesize(expression) - deparenthesized != null && isComplexExpression(deparenthesized) - } - else -> false - } - @JvmStatic fun createDataFlowValue( expression: KtExpression, @@ -95,10 +85,6 @@ object DataFlowValueFactory { Nullability.NOT_NULL) } - if (isComplexExpression(expression)) { - return createDataFlowValueForComplexExpression(expression, type) - } - val result = getIdForStableIdentifier(expression, bindingContext, containingDeclarationOrModule) return DataFlowValue(if (result === IdentifierInfo.NO) ExpressionIdentifierInfo(expression) else result, type) } @@ -136,11 +122,6 @@ object DataFlowValueFactory { variableKind(variableDescriptor, usageContainingModule, bindingContext, property)), variableDescriptor.type) - private fun createDataFlowValueForComplexExpression( - expression: KtExpression, - type: KotlinType - ) = DataFlowValue(ExpressionIdentifierInfo(expression, stableComplex = true), type) - // For only ++ and -- postfix operations private data class PostfixIdentifierInfo(val argumentInfo: IdentifierInfo, val op: KtToken) : IdentifierInfo { override val kind: DataFlowValue.Kind get() = argumentInfo.kind @@ -148,13 +129,8 @@ object DataFlowValueFactory { override fun toString() = "$argumentInfo($op)" } - class ExpressionIdentifierInfo(val expression: KtExpression, stableComplex: Boolean = false) : IdentifierInfo { - - override val kind = if (stableComplex) STABLE_COMPLEX_EXPRESSION else OTHER - - override fun equals(other: Any?) = other is ExpressionIdentifierInfo && expression == other.expression - - override fun hashCode() = expression.hashCode() + data class ExpressionIdentifierInfo(val expression: KtExpression) : IdentifierInfo { + override val kind = OTHER override fun toString() = expression.text ?: "(empty expression)" } diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValue.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValue.kt index b72a35d2441..35d9d8e34e9 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValue.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/smartcasts/DataFlowValue.kt @@ -39,8 +39,6 @@ class DataFlowValue(val identifierInfo: IdentifierInfo, // or protected / public member value from the same module without open / custom getter // Smart casts are completely safe STABLE_VALUE("stable"), - // Block, or if / else, or when, or (in future) some other complex expression - STABLE_COMPLEX_EXPRESSION("complex expression", ""), // Member value with open / custom getter // Smart casts are not safe PROPERTY_WITH_GETTER("custom getter", "property that has open or custom getter"), @@ -70,7 +68,7 @@ class DataFlowValue(val identifierInfo: IdentifierInfo, * Predictable means here we do not expect some sudden change of their values, * like accessing mutable properties in another thread, so smart casts can be used safely. */ - val isPredictable = (kind == Kind.STABLE_VALUE || kind == Kind.STABLE_COMPLEX_EXPRESSION || kind == Kind.PREDICTABLE_VARIABLE) + val isPredictable = (kind == Kind.STABLE_VALUE || kind == Kind.PREDICTABLE_VARIABLE) @JvmName("isPredictable") get override fun equals(other: Any?): Boolean {