Revert "[NI] Support @OnlyInputTypes annotation. #KT-29307 fixed"

This reverts commit 90628112
With that annotation there is complex bug that breaks build of Kotlin compiler
This commit is contained in:
Dmitriy Novozhilov
2019-03-18 18:51:52 +03:00
parent 25b3f62767
commit d01b6ef900
20 changed files with 31 additions and 210 deletions
@@ -18,17 +18,13 @@ package org.jetbrains.kotlin.resolve.calls.inference.components
import org.jetbrains.kotlin.resolve.calls.NewCommonSuperTypeCalculator
import org.jetbrains.kotlin.resolve.calls.inference.components.TypeVariableDirectionCalculator.ResolveDirection
import org.jetbrains.kotlin.resolve.calls.inference.model.ArgumentConstraintPosition
import org.jetbrains.kotlin.resolve.calls.inference.model.ConstraintKind
import org.jetbrains.kotlin.resolve.calls.inference.model.VariableWithConstraints
import org.jetbrains.kotlin.resolve.calls.inference.model.checkConstraint
import org.jetbrains.kotlin.resolve.calls.model.OnlyInputTypesDiagnostic
import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstructor
import org.jetbrains.kotlin.types.*
import org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker
import org.jetbrains.kotlin.types.checker.intersectTypes
import org.jetbrains.kotlin.types.typeUtil.isPrimitiveNumberType
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
class ResultTypeResolver(
val typeApproximator: TypeApproximator,
@@ -57,6 +53,7 @@ class ResultTypeResolver(
} else {
c.resultType(superType, subType, variableWithConstraints)
}
return result
}
@@ -5,12 +5,12 @@
package org.jetbrains.kotlin.resolve.calls.inference.model
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.trimToSize
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
import org.jetbrains.kotlin.resolve.calls.tower.isSuccess
import org.jetbrains.kotlin.types.TypeConstructor
import org.jetbrains.kotlin.types.UnwrappedType
import org.jetbrains.kotlin.types.checker.NewCapturedType
import kotlin.collections.ArrayList
import kotlin.collections.LinkedHashMap
@@ -27,20 +27,6 @@ class MutableVariableWithConstraints(
return simplifiedConstraints!!
}
// see @OnlyInputTypes annotation
val projectedInputCallTypes: Collection<UnwrappedType>
get() =
mutableConstraints.filter {
val position = it.position.from
position is ArgumentConstraintPosition || position is ReceiverConstraintPosition || position is ExpectedTypeConstraintPosition
}.map {
val type = it.type
if (type is NewCapturedType)
type.constructor.projection.type.unwrap()
else
type
}
private val mutableConstraints = ArrayList(constraints)
private var simplifiedConstraints: List<Constraint>? = null
@@ -13,16 +13,12 @@ import org.jetbrains.kotlin.resolve.calls.inference.components.KotlinConstraintS
import org.jetbrains.kotlin.resolve.calls.inference.components.NewTypeSubstitutor
import org.jetbrains.kotlin.resolve.calls.inference.components.ResultTypeResolver
import org.jetbrains.kotlin.resolve.calls.model.KotlinCallDiagnostic
import org.jetbrains.kotlin.resolve.calls.model.OnlyInputTypesDiagnostic
import org.jetbrains.kotlin.types.IntersectionTypeConstructor
import org.jetbrains.kotlin.types.StubType
import org.jetbrains.kotlin.types.TypeConstructor
import org.jetbrains.kotlin.types.UnwrappedType
import org.jetbrains.kotlin.types.checker.NewKotlinTypeChecker
import org.jetbrains.kotlin.types.typeUtil.contains
import org.jetbrains.kotlin.types.typeUtil.isUnit
import org.jetbrains.kotlin.utils.SmartList
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
class NewConstraintSystemImpl(
private val constraintInjector: ConstraintInjector,
@@ -246,8 +242,7 @@ class NewConstraintSystemImpl(
checkState(State.BUILDING, State.COMPLETION)
constraintInjector.addInitialEqualityConstraint(this, variable.defaultType, resultType, FixVariableConstraintPosition(variable))
val variableWithConstraints = notFixedTypeVariables.remove(variable.freshTypeConstructor)
checkOnlyInputTypesAnnotation(variableWithConstraints, resultType)
notFixedTypeVariables.remove(variable.freshTypeConstructor)
for (variableWithConstraint in notFixedTypeVariables.values) {
variableWithConstraint.removeConstrains {
@@ -258,21 +253,6 @@ class NewConstraintSystemImpl(
storage.fixedTypeVariables[variable.freshTypeConstructor] = resultType
}
private fun checkOnlyInputTypesAnnotation(
variableWithConstraints: MutableVariableWithConstraints?,
resultType: UnwrappedType
) {
if (variableWithConstraints == null || !variableWithConstraints.typeVariable.hasOnlyInputTypesAnnotation()) return
val resultTypeIsInputType = variableWithConstraints.projectedInputCallTypes.any { inputType ->
inputType.constructor.safeAs<IntersectionTypeConstructor>()?.let { constructor ->
constructor.supertypes.any { NewKotlinTypeChecker.equalTypes(resultType, it) }
} ?: NewKotlinTypeChecker.equalTypes(resultType, inputType)
}
if (!resultTypeIsInputType) {
addError(OnlyInputTypesDiagnostic(variableWithConstraints.typeVariable))
}
}
// KotlinConstraintSystemCompleter.Context, PostponedArgumentsAnalyzer.Context
override fun canBeProper(type: UnwrappedType): Boolean {
checkState(State.BUILDING, State.COMPLETION)
@@ -22,7 +22,6 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.resolve.calls.model.LambdaKotlinCallArgument
import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns
import org.jetbrains.kotlin.resolve.descriptorUtil.hasOnlyInputTypesAnnotation
import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.KotlinTypeFactory
import org.jetbrains.kotlin.types.SimpleType
@@ -53,21 +52,15 @@ sealed class NewTypeVariable(builtIns: KotlinBuiltIns, name: String) {
nullable = false, memberScope = builtIns.any.unsubstitutedMemberScope
)
abstract fun hasOnlyInputTypesAnnotation(): Boolean
override fun toString() = freshTypeConstructor.toString()
}
class TypeVariableFromCallableDescriptor(
val originalTypeParameter: TypeParameterDescriptor
) : NewTypeVariable(originalTypeParameter.builtIns, originalTypeParameter.name.identifier) {
override fun hasOnlyInputTypesAnnotation(): Boolean = originalTypeParameter.hasOnlyInputTypesAnnotation()
}
) : NewTypeVariable(originalTypeParameter.builtIns, originalTypeParameter.name.identifier)
class TypeVariableForLambdaReturnType(
val lambdaArgument: LambdaKotlinCallArgument,
builtIns: KotlinBuiltIns,
name: String
) : NewTypeVariable(builtIns, name) {
override fun hasOnlyInputTypesAnnotation(): Boolean = false
}
) : NewTypeVariable(builtIns, name)
@@ -20,7 +20,6 @@ import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
import org.jetbrains.kotlin.resolve.calls.components.CallableReferenceCandidate
import org.jetbrains.kotlin.resolve.calls.inference.model.NewTypeVariable
import org.jetbrains.kotlin.resolve.calls.tower.ResolutionCandidateApplicability.*
import org.jetbrains.kotlin.types.TypeConstructor
import org.jetbrains.kotlin.types.UnwrappedType
@@ -180,10 +179,4 @@ class ManyCandidatesCallDiagnostic(
override fun report(reporter: DiagnosticReporter) {
reporter.onCall(this)
}
}
class OnlyInputTypesDiagnostic(val typeVariable: NewTypeVariable) : KotlinCallDiagnostic(INAPPLICABLE) {
override fun report(reporter: DiagnosticReporter) {
reporter.onCall(this)
}
}