[FE] Introduce commonized version of expect/actual compatibility calculator

This is needed to use the same code for those checks between
  both frontends and backend

^KT-58578
This commit is contained in:
Dmitriy Novozhilov
2023-05-11 13:26:33 +03:00
committed by Space Team
parent 2c2f12d9ac
commit b26b649d4e
6 changed files with 646 additions and 8 deletions
@@ -0,0 +1,26 @@
/*
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package org.jetbrains.kotlin.mpp
/*
* Those markers are needed for implementation of common algorithm of expect/actual
* compatibility checking, implemented in
* org.jetbrains.kotlin.resolve.calls.mpp.AbstractExpectActualCompatibilityChecker
*/
interface DeclarationSymbolMarker
interface CallableSymbolMarker : DeclarationSymbolMarker
interface FunctionSymbolMarker : CallableSymbolMarker
interface ConstructorSymbolMarker : FunctionSymbolMarker
interface SimpleFunctionSymbolMarker : FunctionSymbolMarker
interface PropertySymbolMarker : CallableSymbolMarker
interface ValueParameterSymbolMarker : CallableSymbolMarker
interface ClassifierSymbolMarker : DeclarationSymbolMarker
interface TypeParameterSymbolMarker : ClassifierSymbolMarker
interface ClassLikeSymbolMarker : ClassifierSymbolMarker
interface RegularClassSymbolMarker : ClassLikeSymbolMarker
interface TypeAliasSymbolMarker : ClassLikeSymbolMarker
@@ -9,22 +9,22 @@ fun TypeVariableMarker.freshTypeConstructor(c: TypeSystemInferenceExtensionConte
fun TypeSubstitutorMarker.safeSubstitute(
c: TypeSystemInferenceExtensionContext,
type: KotlinTypeMarker
) = with(c) { safeSubstitute(type) }
): KotlinTypeMarker = with(c) { safeSubstitute(type) }
fun TypeVariableMarker.defaultType(c: TypeSystemInferenceExtensionContext) = with(c) { defaultType() }
fun TypeVariableMarker.defaultType(c: TypeSystemInferenceExtensionContext): SimpleTypeMarker = with(c) { defaultType() }
fun KotlinTypeMarker.dependsOnTypeConstructor(c: TypeSystemInferenceExtensionContext, typeConstructors: Set<TypeConstructorMarker>) =
fun KotlinTypeMarker.dependsOnTypeConstructor(c: TypeSystemInferenceExtensionContext, typeConstructors: Set<TypeConstructorMarker>): Boolean =
with(c) {
contains { it.typeConstructor() in typeConstructors }
}
fun KotlinTypeMarker.dependsOnTypeParameters(c: TypeSystemInferenceExtensionContext, typeParameters: Collection<TypeParameterMarker>) =
fun KotlinTypeMarker.dependsOnTypeParameters(c: TypeSystemInferenceExtensionContext, typeParameters: Collection<TypeParameterMarker>): Boolean =
with(c) {
val typeConstructors = typeParameters.mapTo(mutableSetOf()) { it.getTypeConstructor() }
dependsOnTypeConstructor(c, typeConstructors)
}
fun CapturedTypeMarker.captureStatus(c: TypeSystemInferenceExtensionContext) =
fun CapturedTypeMarker.captureStatus(c: TypeSystemInferenceExtensionContext): CaptureStatus =
with(c) {
captureStatus()
}
}