Reduce memory footprint for basic case of flexible types
The case is when we have a simple type constructor (not array nor collection) and type is not raw: A<T1, >..A<T1>? Actually these types are almost equal besides of nullability, but we create and resolve two different simple types, they have different arguments' lists, etc. The idea is to add NullableSimpleType subclass with delegate to another simple type It should help a lot both with common cases and with corner ones: flexibles types in spark for Function22 having exponential size because of its flexibility #KT-14375 Fixed #KT-14323 Fixed
This commit is contained in:
+15
-7
@@ -90,11 +90,11 @@ class JavaTypeResolver(
|
||||
return computeSimpleJavaClassifierType(javaType, attr) ?: errorType()
|
||||
}
|
||||
|
||||
fun computeBound(flexibility: JavaTypeFlexibility) =
|
||||
computeSimpleJavaClassifierType(javaType, attr.withFlexibility(flexibility))
|
||||
fun computeBound(flexibility: JavaTypeFlexibility, lowerResult: SimpleType? = null) =
|
||||
computeSimpleJavaClassifierType(javaType, attr.withFlexibility(flexibility), lowerResult)
|
||||
|
||||
val lower = computeBound(FLEXIBLE_LOWER_BOUND) ?: return errorType()
|
||||
val upper = computeBound(FLEXIBLE_UPPER_BOUND) ?: return errorType()
|
||||
val upper = computeBound(FLEXIBLE_UPPER_BOUND, lowerResult = lower) ?: return errorType()
|
||||
|
||||
return if (isRaw) {
|
||||
RawTypeImpl(lower, upper)
|
||||
@@ -104,12 +104,21 @@ class JavaTypeResolver(
|
||||
}
|
||||
}
|
||||
|
||||
private fun computeSimpleJavaClassifierType(javaType: JavaClassifierType, attr: JavaTypeAttributes): SimpleType? {
|
||||
val annotations = LazyJavaAnnotations(c, javaType)
|
||||
private fun computeSimpleJavaClassifierType(
|
||||
javaType: JavaClassifierType, attr: JavaTypeAttributes,
|
||||
lowerResult: SimpleType? = null
|
||||
): SimpleType? {
|
||||
val annotations =
|
||||
lowerResult?.annotations ?: LazyJavaAnnotations(c, javaType)
|
||||
val constructor = computeTypeConstructor(javaType, attr) ?: return null
|
||||
val arguments = computeArguments(javaType, attr, constructor)
|
||||
val isNullable = attr.isNullable()
|
||||
|
||||
if (lowerResult?.constructor == constructor && !javaType.isRaw && isNullable) {
|
||||
return lowerResult.makeNullableAsSpecified(true)
|
||||
}
|
||||
|
||||
val arguments = computeArguments(javaType, attr, constructor)
|
||||
|
||||
return KotlinTypeFactory.simpleType(annotations, constructor, arguments, isNullable)
|
||||
}
|
||||
|
||||
@@ -340,4 +349,3 @@ internal fun TypeParameterDescriptor.getErasedUpperBound(
|
||||
|
||||
return defaultValue()
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user