Disable slow assertions in type checker everywhere except for tests

This commit is contained in:
Denis Zharkov
2019-06-14 16:06:52 +03:00
parent 46d8f45c11
commit fdebb38706
6 changed files with 68 additions and 27 deletions
@@ -253,6 +253,7 @@ abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheck
AbstractTypeChecker.isSubtypeOf(this as AbstractTypeCheckerContext, subType, superType)
private fun assertInputTypes(subType: KotlinTypeMarker, superType: KotlinTypeMarker) {
if (!AbstractTypeChecker.RUN_SLOW_ASSERTIONS) return
fun correctSubType(subType: SimpleTypeMarker) =
subType.isSingleClassifierType() || subType.typeConstructor().isIntersection() || isMyTypeVariable(subType) || subType.isError() || subType.isIntegerLiteralType()
@@ -278,4 +279,4 @@ abstract class AbstractTypeCheckerContextForConstraintSystem : AbstractTypeCheck
is FlexibleTypeMarker -> f(lowerBound()) || f(upperBound())
else -> error("sealed")
}
}
}
@@ -88,13 +88,15 @@ interface NewTypeSubstitutor: TypeSubstitutorMarker {
"original lower type: '${capturedType.lowerType}"
)
typeConstructor.supertypes.forEach { supertype ->
substitute(supertype, keepAnnotation, runCapturedChecks = false)?.let {
throw IllegalStateException(
"Illegal type substitutor: $this, " +
"because for captured type '$type' supertype approximation should be null, but it is: '$supertype'," +
"original supertype: '$supertype'"
)
if (AbstractTypeChecker.RUN_SLOW_ASSERTIONS) {
typeConstructor.supertypes.forEach { supertype ->
substitute(supertype, keepAnnotation, runCapturedChecks = false)?.let {
throw IllegalStateException(
"Illegal type substitutor: $this, " +
"because for captured type '$type' supertype approximation should be null, but it is: '$supertype'," +
"original supertype: '$supertype'"
)
}
}
}
@@ -178,4 +180,4 @@ class FreshVariableNewTypeSubstitutor(val freshVariables: List<TypeVariableFromC
fun UnwrappedType.substituteTypeVariable(typeVariable: NewTypeVariable, value: UnwrappedType): UnwrappedType {
val substitutor = NewTypeSubstitutorByConstructorMap(mapOf(typeVariable.freshTypeConstructor to value))
return substitutor.safeSubstitute(this)
}
}