[Commonizer] minor: rename type commonizer options
Call it `context` to make more distinguishable from the global settings
This commit is contained in:
+5
-5
@@ -25,8 +25,8 @@ internal class ClassOrTypeAliasTypeCommonizer(
|
|||||||
typeCommonizer, classifiers, settings.getSetting(OptimisticNumberCommonizationEnabledKey)
|
typeCommonizer, classifiers, settings.getSetting(OptimisticNumberCommonizationEnabledKey)
|
||||||
)
|
)
|
||||||
|
|
||||||
private val isMarkedNullableCommonizer = TypeNullabilityCommonizer(typeCommonizer.options)
|
private val isMarkedNullableCommonizer = TypeNullabilityCommonizer(typeCommonizer.context)
|
||||||
private val typeDistanceMeasurement = TypeDistanceMeasurement(typeCommonizer.options)
|
private val typeDistanceMeasurement = TypeDistanceMeasurement(typeCommonizer.context)
|
||||||
|
|
||||||
override fun invoke(values: List<CirClassOrTypeAliasType>): CirClassOrTypeAliasType? {
|
override fun invoke(values: List<CirClassOrTypeAliasType>): CirClassOrTypeAliasType? {
|
||||||
if (values.isEmpty()) return null
|
if (values.isEmpty()) return null
|
||||||
@@ -203,8 +203,8 @@ internal class ClassOrTypeAliasTypeCommonizer(
|
|||||||
* - The input [types] do not have a single distinct set of associated ids
|
* - The input [types] do not have a single distinct set of associated ids
|
||||||
*/
|
*/
|
||||||
private fun selectSubstitutionClassifierId(types: List<CirClassOrTypeAliasType>): CirEntityId? {
|
private fun selectSubstitutionClassifierId(types: List<CirClassOrTypeAliasType>): CirEntityId? {
|
||||||
val forwardSubstitutionAllowed = typeCommonizer.options.enableForwardTypeAliasSubstitution
|
val forwardSubstitutionAllowed = typeCommonizer.context.enableForwardTypeAliasSubstitution
|
||||||
val backwardsSubstitutionAllowed = typeCommonizer.options.enableBackwardsTypeAliasSubstitution
|
val backwardsSubstitutionAllowed = typeCommonizer.context.enableBackwardsTypeAliasSubstitution
|
||||||
|
|
||||||
/* No substitution allowed in any direction */
|
/* No substitution allowed in any direction */
|
||||||
if (!forwardSubstitutionAllowed && !backwardsSubstitutionAllowed) {
|
if (!forwardSubstitutionAllowed && !backwardsSubstitutionAllowed) {
|
||||||
@@ -268,7 +268,7 @@ private interface TypeDistanceMeasurement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
operator fun invoke(options: TypeCommonizer.Options): TypeDistanceMeasurement = when {
|
operator fun invoke(options: TypeCommonizer.Context): TypeDistanceMeasurement = when {
|
||||||
options.enableBackwardsTypeAliasSubstitution && options.enableForwardTypeAliasSubstitution -> Full
|
options.enableBackwardsTypeAliasSubstitution && options.enableForwardTypeAliasSubstitution -> Full
|
||||||
options.enableForwardTypeAliasSubstitution -> ForwardOnly
|
options.enableForwardTypeAliasSubstitution -> ForwardOnly
|
||||||
else -> None
|
else -> None
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ class ReturnTypeCommonizer(
|
|||||||
val isTopLevel = values.all { it.containingClass == null }
|
val isTopLevel = values.all { it.containingClass == null }
|
||||||
val isCovariant = values.none { it is CirProperty && it.isVar }
|
val isCovariant = values.none { it is CirProperty && it.isVar }
|
||||||
return typeCommonizer
|
return typeCommonizer
|
||||||
.withOptions { withCovariantNullabilityCommonizationEnabled(isTopLevel && isCovariant) }
|
.withContext { withCovariantNullabilityCommonizationEnabled(isTopLevel && isCovariant) }
|
||||||
.invoke(values.map { it.returnType })
|
.invoke(values.map { it.returnType })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -19,7 +19,7 @@ class TypeAliasCommonizer(
|
|||||||
private val settings: CommonizerSettings,
|
private val settings: CommonizerSettings,
|
||||||
) : NullableSingleInvocationCommonizer<CirTypeAlias> {
|
) : NullableSingleInvocationCommonizer<CirTypeAlias> {
|
||||||
|
|
||||||
private val typeCommonizer = typeCommonizer.withOptions {
|
private val typeCommonizer = typeCommonizer.withContext {
|
||||||
withBackwardsTypeAliasSubstitutionEnabled(false)
|
withBackwardsTypeAliasSubstitutionEnabled(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.commonizer.utils.safeCastValues
|
|||||||
class TypeCommonizer(
|
class TypeCommonizer(
|
||||||
private val classifiers: CirKnownClassifiers,
|
private val classifiers: CirKnownClassifiers,
|
||||||
private val settings: CommonizerSettings,
|
private val settings: CommonizerSettings,
|
||||||
val options: Options = Options.default,
|
val context: Context = Context.default,
|
||||||
) : NullableSingleInvocationCommonizer<CirType> {
|
) : NullableSingleInvocationCommonizer<CirType> {
|
||||||
|
|
||||||
private val classOrTypeAliasTypeCommonizer = ClassOrTypeAliasTypeCommonizer(this, classifiers, settings)
|
private val classOrTypeAliasTypeCommonizer = ClassOrTypeAliasTypeCommonizer(this, classifiers, settings)
|
||||||
@@ -35,43 +35,43 @@ class TypeCommonizer(
|
|||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
data class Options(
|
data class Context(
|
||||||
val enableCovariantNullabilityCommonization: Boolean = false,
|
val enableCovariantNullabilityCommonization: Boolean = false,
|
||||||
val enableForwardTypeAliasSubstitution: Boolean = true,
|
val enableForwardTypeAliasSubstitution: Boolean = true,
|
||||||
val enableBackwardsTypeAliasSubstitution: Boolean = true,
|
val enableBackwardsTypeAliasSubstitution: Boolean = true,
|
||||||
) {
|
) {
|
||||||
|
|
||||||
fun withCovariantNullabilityCommonizationEnabled(enabled: Boolean = true): Options {
|
fun withCovariantNullabilityCommonizationEnabled(enabled: Boolean = true): Context {
|
||||||
return if (enableCovariantNullabilityCommonization == enabled) this
|
return if (enableCovariantNullabilityCommonization == enabled) this
|
||||||
else copy(enableCovariantNullabilityCommonization = enabled)
|
else copy(enableCovariantNullabilityCommonization = enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun withForwardTypeAliasSubstitutionEnabled(enabled: Boolean = true): Options {
|
fun withForwardTypeAliasSubstitutionEnabled(enabled: Boolean = true): Context {
|
||||||
return if (enableForwardTypeAliasSubstitution == enabled) this
|
return if (enableForwardTypeAliasSubstitution == enabled) this
|
||||||
else copy(enableForwardTypeAliasSubstitution = enabled)
|
else copy(enableForwardTypeAliasSubstitution = enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun withBackwardsTypeAliasSubstitutionEnabled(enabled: Boolean = true): Options {
|
fun withBackwardsTypeAliasSubstitutionEnabled(enabled: Boolean = true): Context {
|
||||||
return if (enableBackwardsTypeAliasSubstitution == enabled) this
|
return if (enableBackwardsTypeAliasSubstitution == enabled) this
|
||||||
else copy(enableBackwardsTypeAliasSubstitution = enabled)
|
else copy(enableBackwardsTypeAliasSubstitution = enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun withTypeAliasSubstitutionEnabled(enabled: Boolean = true): Options {
|
fun withTypeAliasSubstitutionEnabled(enabled: Boolean = true): Context {
|
||||||
return withForwardTypeAliasSubstitutionEnabled(enabled).withBackwardsTypeAliasSubstitutionEnabled(enabled)
|
return withForwardTypeAliasSubstitutionEnabled(enabled).withBackwardsTypeAliasSubstitutionEnabled(enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val default = Options()
|
val default = Context()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun withOptions(options: Options): TypeCommonizer {
|
fun withContext(context: Context): TypeCommonizer {
|
||||||
return if (this.options == options) this
|
return if (this.context == context) this
|
||||||
else TypeCommonizer(classifiers, settings, options)
|
else TypeCommonizer(classifiers, settings, context)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun withOptions(createNewOptions: Options.() -> Options): TypeCommonizer {
|
inline fun withContext(createNewContext: Context.() -> Context): TypeCommonizer {
|
||||||
return withOptions(options.createNewOptions())
|
return withContext(context.createNewContext())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@ private typealias IsMarkedNullable = Boolean
|
|||||||
|
|
||||||
internal interface TypeNullabilityCommonizer : AssociativeCommonizer<IsMarkedNullable>
|
internal interface TypeNullabilityCommonizer : AssociativeCommonizer<IsMarkedNullable>
|
||||||
|
|
||||||
internal fun TypeNullabilityCommonizer(options: TypeCommonizer.Options): TypeNullabilityCommonizer {
|
internal fun TypeNullabilityCommonizer(options: TypeCommonizer.Context): TypeNullabilityCommonizer {
|
||||||
return if (options.enableCovariantNullabilityCommonization) CovariantTypeNullabilityCommonizer
|
return if (options.enableCovariantNullabilityCommonization) CovariantTypeNullabilityCommonizer
|
||||||
else EqualTypeNullabilityCommonizer
|
else EqualTypeNullabilityCommonizer
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user