@@ -55,6 +55,9 @@ import org.jetbrains.kotlin.analysis.api.symbols.*
55
55
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaDeclarationContainerSymbol
56
56
import org.jetbrains.kotlin.analysis.api.types.*
57
57
import org.jetbrains.kotlin.builtins.jvm.JavaToKotlinClassMap
58
+ import org.jetbrains.kotlin.codegen.state.InfoForMangling
59
+ import org.jetbrains.kotlin.codegen.state.collectFunctionSignatureForManglingSuffix
60
+ import org.jetbrains.kotlin.codegen.state.md5base64
58
61
import org.jetbrains.kotlin.fir.declarations.FirResolvePhase
59
62
import org.jetbrains.kotlin.fir.declarations.getTargetType
60
63
import org.jetbrains.kotlin.fir.expressions.FirAnnotation
@@ -923,3 +926,56 @@ fun <T : KaSymbol?> T.tryResolveToTypePhase(): T {
923
926
(this as ? KaFirSymbol <* >)?.firSymbol?.lazyResolveToPhase(FirResolvePhase .TYPES )
924
927
return this
925
928
}
929
+
930
+ private val KaType .upperBoundIfFlexible: KaType
931
+ get() = (this as ? KaFlexibleType )?.upperBound ? : this
932
+
933
+ private fun KaType.requiresMangling (): Boolean = (symbol as ? KaNamedClassSymbol )?.isInline ? : false
934
+
935
+ private fun KaType.asInfoForMangling (): InfoForMangling ? {
936
+ val upperBound = upperBoundIfFlexible
937
+ val fqName = upperBound.symbol?.classId?.asSingleFqName()?.toUnsafe() ? : return null
938
+ val isValue = upperBound.requiresMangling()
939
+ val isNullable = upperBound.nullability.isNullable
940
+ return InfoForMangling (fqName = fqName, isValue = isValue, isNullable = isNullable)
941
+ }
942
+
943
+ private fun mangleInlineSuffix (
944
+ parameters : List <KaType >,
945
+ returnType : KaType ? ,
946
+ shouldMangleReturnType : Boolean
947
+ ): String {
948
+ val signature = collectFunctionSignatureForManglingSuffix(
949
+ false ,
950
+ parameters.any { it.requiresMangling() },
951
+ parameters.map { it.asInfoForMangling() },
952
+ if (shouldMangleReturnType) returnType?.asInfoForMangling() else null
953
+ ) ? : return " "
954
+ return " -${md5base64(signature)} "
955
+ }
956
+
957
+ private val KaSymbol .isKotlin: Boolean
958
+ get() = when (origin) {
959
+ KaSymbolOrigin .SOURCE , KaSymbolOrigin .LIBRARY -> true
960
+ else -> false
961
+ }
962
+
963
+ internal val KaFunctionSymbol .inlineSuffix: String
964
+ get() = mangleInlineSuffix(
965
+ valueParameters.map { it.returnType },
966
+ returnType,
967
+ analyze {
968
+ returnType.requiresMangling() && isKotlin && this @inlineSuffix.containingSymbol is KaClassSymbol
969
+ }
970
+ )
971
+
972
+ internal val KaPropertyAccessorSymbol .inlineSuffix: String
973
+ get() = when (this ) {
974
+ is KaPropertyGetterSymbol ->
975
+ mangleInlineSuffix(
976
+ emptyList(),
977
+ returnType,
978
+ returnType.requiresMangling() && isKotlin
979
+ )
980
+ is KaPropertySetterSymbol -> mangleInlineSuffix(listOf (parameter.returnType), null , false )
981
+ }
0 commit comments