Avoid using TypeSystemInferenceExtensionContextDelegate in FIR

It's only needed in old FE to avoid clashes when initializing DI

The main idea is gettind rid of intermediate interfaces because
each of them adds another intermediate DefaultImpls call
This commit is contained in:
Denis Zharkov
2019-12-12 12:41:36 +03:00
parent 25fdbdfecb
commit 0064429339
4 changed files with 17 additions and 8 deletions
@@ -77,12 +77,10 @@ private fun getConstructorInfo(c: Class<*>): ConstructorInfo? {
if (Modifier.isAbstract(c.modifiers) || c.isPrimitive)
return null
val constructors = c.constructors
val hasSinglePublicConstructor = constructors.singleOrNull()?.let { Modifier.isPublic(it.modifiers) } ?: false
if (!hasSinglePublicConstructor)
return null
val publicConstructors = c.constructors.filter { Modifier.isPublic(it.modifiers) && !it.isSynthetic }
if (publicConstructors.size != 1) return null
val constructor = constructors.single()
val constructor = publicConstructors.single()
val parameterTypes =
if (c.declaringClass != null && !Modifier.isStatic(c.modifiers))
listOf(c.declaringClass, *constructor.genericParameterTypes)
@@ -126,4 +124,4 @@ private fun getRegistrations(klass: Class<*>): List<Type> {
registrations.addAll(interfaces)
registrations.remove(Any::class.java)
return registrations
}
}
@@ -51,7 +51,7 @@ class InferenceComponents(
return ConeClassErrorType(message)
}
}
val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle(ctx)
val trivialConstraintTypeInferenceOracle = TrivialConstraintTypeInferenceOracle.create(ctx)
private val incorporator = ConstraintIncorporator(approximator, trivialConstraintTypeInferenceOracle)
private val injector = ConstraintInjector(incorporator, approximator, KotlinTypeRefiner.Default)
val resultTypeResolver = ResultTypeResolver(approximator, trivialConstraintTypeInferenceOracle)
@@ -11,8 +11,11 @@ import org.jetbrains.kotlin.types.model.KotlinTypeMarker
import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContext
import org.jetbrains.kotlin.types.model.TypeSystemInferenceExtensionContextDelegate
class TrivialConstraintTypeInferenceOracle(context: TypeSystemInferenceExtensionContextDelegate) :
class TrivialConstraintTypeInferenceOracle private constructor(context: TypeSystemInferenceExtensionContext) :
TypeSystemInferenceExtensionContext by context {
// This constructor is used for injection only in old FE
constructor(context: TypeSystemInferenceExtensionContextDelegate) : this(context as TypeSystemInferenceExtensionContext)
// The idea is to add knowledge that constraint `Nothing(?) <: T` is quite useless and
// it's totally fine to go and resolve postponed argument without fixation T to Nothing(?).
// In other words, constraint `Nothing(?) <: T` is *not* proper
@@ -62,4 +65,8 @@ class TrivialConstraintTypeInferenceOracle(context: TypeSystemInferenceExtension
private fun KotlinTypeMarker.containsOnlyNonNullableNothing(): Boolean =
contains { it.isNothing() } && !contains { it.isNullableNothing() }
companion object {
fun create(context: TypeSystemInferenceExtensionContext) = TrivialConstraintTypeInferenceOracle(context)
}
}
@@ -105,6 +105,10 @@ interface TypeSystemCommonSuperTypesContext : TypeSystemContext, TypeSystemTypeF
fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker
}
// This interface is only used to declare that implementing class is supposed to be used as a TypeSystemInferenceExtensionContext component
// Otherwise clash happens during DI container initialization: there are a lot of components that extend TypeSystemInferenceExtensionContext
// but they only has it among supertypes to bring additional receiver into their scopes, i.e. they are not intended to be used as
// component implementation for TypeSystemInferenceExtensionContext
interface TypeSystemInferenceExtensionContextDelegate : TypeSystemInferenceExtensionContext
interface TypeSystemInferenceExtensionContext : TypeSystemContext, TypeSystemBuiltInsContext, TypeSystemCommonSuperTypesContext {