[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)
|
||||
)
|
||||
|
||||
private val isMarkedNullableCommonizer = TypeNullabilityCommonizer(typeCommonizer.options)
|
||||
private val typeDistanceMeasurement = TypeDistanceMeasurement(typeCommonizer.options)
|
||||
private val isMarkedNullableCommonizer = TypeNullabilityCommonizer(typeCommonizer.context)
|
||||
private val typeDistanceMeasurement = TypeDistanceMeasurement(typeCommonizer.context)
|
||||
|
||||
override fun invoke(values: List<CirClassOrTypeAliasType>): CirClassOrTypeAliasType? {
|
||||
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
|
||||
*/
|
||||
private fun selectSubstitutionClassifierId(types: List<CirClassOrTypeAliasType>): CirEntityId? {
|
||||
val forwardSubstitutionAllowed = typeCommonizer.options.enableForwardTypeAliasSubstitution
|
||||
val backwardsSubstitutionAllowed = typeCommonizer.options.enableBackwardsTypeAliasSubstitution
|
||||
val forwardSubstitutionAllowed = typeCommonizer.context.enableForwardTypeAliasSubstitution
|
||||
val backwardsSubstitutionAllowed = typeCommonizer.context.enableBackwardsTypeAliasSubstitution
|
||||
|
||||
/* No substitution allowed in any direction */
|
||||
if (!forwardSubstitutionAllowed && !backwardsSubstitutionAllowed) {
|
||||
@@ -268,7 +268,7 @@ private interface TypeDistanceMeasurement {
|
||||
}
|
||||
|
||||
companion object {
|
||||
operator fun invoke(options: TypeCommonizer.Options): TypeDistanceMeasurement = when {
|
||||
operator fun invoke(options: TypeCommonizer.Context): TypeDistanceMeasurement = when {
|
||||
options.enableBackwardsTypeAliasSubstitution && options.enableForwardTypeAliasSubstitution -> Full
|
||||
options.enableForwardTypeAliasSubstitution -> ForwardOnly
|
||||
else -> None
|
||||
|
||||
@@ -17,7 +17,7 @@ class ReturnTypeCommonizer(
|
||||
val isTopLevel = values.all { it.containingClass == null }
|
||||
val isCovariant = values.none { it is CirProperty && it.isVar }
|
||||
return typeCommonizer
|
||||
.withOptions { withCovariantNullabilityCommonizationEnabled(isTopLevel && isCovariant) }
|
||||
.withContext { withCovariantNullabilityCommonizationEnabled(isTopLevel && isCovariant) }
|
||||
.invoke(values.map { it.returnType })
|
||||
}
|
||||
}
|
||||
@@ -19,7 +19,7 @@ class TypeAliasCommonizer(
|
||||
private val settings: CommonizerSettings,
|
||||
) : NullableSingleInvocationCommonizer<CirTypeAlias> {
|
||||
|
||||
private val typeCommonizer = typeCommonizer.withOptions {
|
||||
private val typeCommonizer = typeCommonizer.withContext {
|
||||
withBackwardsTypeAliasSubstitutionEnabled(false)
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.commonizer.utils.safeCastValues
|
||||
class TypeCommonizer(
|
||||
private val classifiers: CirKnownClassifiers,
|
||||
private val settings: CommonizerSettings,
|
||||
val options: Options = Options.default,
|
||||
val context: Context = Context.default,
|
||||
) : NullableSingleInvocationCommonizer<CirType> {
|
||||
|
||||
private val classOrTypeAliasTypeCommonizer = ClassOrTypeAliasTypeCommonizer(this, classifiers, settings)
|
||||
@@ -35,43 +35,43 @@ class TypeCommonizer(
|
||||
return null
|
||||
}
|
||||
|
||||
data class Options(
|
||||
data class Context(
|
||||
val enableCovariantNullabilityCommonization: Boolean = false,
|
||||
val enableForwardTypeAliasSubstitution: Boolean = true,
|
||||
val enableBackwardsTypeAliasSubstitution: Boolean = true,
|
||||
) {
|
||||
|
||||
fun withCovariantNullabilityCommonizationEnabled(enabled: Boolean = true): Options {
|
||||
fun withCovariantNullabilityCommonizationEnabled(enabled: Boolean = true): Context {
|
||||
return if (enableCovariantNullabilityCommonization == enabled) this
|
||||
else copy(enableCovariantNullabilityCommonization = enabled)
|
||||
}
|
||||
|
||||
fun withForwardTypeAliasSubstitutionEnabled(enabled: Boolean = true): Options {
|
||||
fun withForwardTypeAliasSubstitutionEnabled(enabled: Boolean = true): Context {
|
||||
return if (enableForwardTypeAliasSubstitution == enabled) this
|
||||
else copy(enableForwardTypeAliasSubstitution = enabled)
|
||||
}
|
||||
|
||||
fun withBackwardsTypeAliasSubstitutionEnabled(enabled: Boolean = true): Options {
|
||||
fun withBackwardsTypeAliasSubstitutionEnabled(enabled: Boolean = true): Context {
|
||||
return if (enableBackwardsTypeAliasSubstitution == enabled) this
|
||||
else copy(enableBackwardsTypeAliasSubstitution = enabled)
|
||||
}
|
||||
|
||||
fun withTypeAliasSubstitutionEnabled(enabled: Boolean = true): Options {
|
||||
fun withTypeAliasSubstitutionEnabled(enabled: Boolean = true): Context {
|
||||
return withForwardTypeAliasSubstitutionEnabled(enabled).withBackwardsTypeAliasSubstitutionEnabled(enabled)
|
||||
}
|
||||
|
||||
companion object {
|
||||
val default = Options()
|
||||
val default = Context()
|
||||
}
|
||||
}
|
||||
|
||||
fun withOptions(options: Options): TypeCommonizer {
|
||||
return if (this.options == options) this
|
||||
else TypeCommonizer(classifiers, settings, options)
|
||||
fun withContext(context: Context): TypeCommonizer {
|
||||
return if (this.context == context) this
|
||||
else TypeCommonizer(classifiers, settings, context)
|
||||
}
|
||||
|
||||
inline fun withOptions(createNewOptions: Options.() -> Options): TypeCommonizer {
|
||||
return withOptions(options.createNewOptions())
|
||||
inline fun withContext(createNewContext: Context.() -> Context): TypeCommonizer {
|
||||
return withContext(context.createNewContext())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ private typealias IsMarkedNullable = Boolean
|
||||
|
||||
internal interface TypeNullabilityCommonizer : AssociativeCommonizer<IsMarkedNullable>
|
||||
|
||||
internal fun TypeNullabilityCommonizer(options: TypeCommonizer.Options): TypeNullabilityCommonizer {
|
||||
internal fun TypeNullabilityCommonizer(options: TypeCommonizer.Context): TypeNullabilityCommonizer {
|
||||
return if (options.enableCovariantNullabilityCommonization) CovariantTypeNullabilityCommonizer
|
||||
else EqualTypeNullabilityCommonizer
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user