Skip to content

Commit

Permalink
Partially fix mangling of internal functions
Browse files Browse the repository at this point in the history
The other part is passing the right module names for dependencies.

(cherry picked from commit 2bd017e)
  • Loading branch information
ting-yuan authored and KSP Auto Pick committed Sep 3, 2024
1 parent c30c83e commit 7a5ded4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -522,9 +522,7 @@ class ResolverAAImpl(
}

val inlineSuffix = symbol?.inlineSuffix ?: ""
val mangledName = if (accessor.modifiers.contains(Modifier.INTERNAL)) {
"\$${ktModule.name}"
} else ""
val mangledName = symbol?.internalSuffix ?: ""
return "${prefix}${accessor.receiver.simpleName.asString().capitalize()}$inlineSuffix$mangledName"
}

Expand All @@ -548,9 +546,7 @@ class ResolverAAImpl(
}

val inlineSuffix = symbol?.inlineSuffix ?: ""
val mangledName = if (declaration.modifiers.contains(Modifier.INTERNAL)) {
"\$${ktModule.name}"
} else ""
val mangledName = symbol?.internalSuffix ?: ""
return declaration.simpleName.asString() + inlineSuffix + mangledName
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ import org.jetbrains.kotlin.analysis.api.impl.base.types.KaBaseStarTypeProjectio
import org.jetbrains.kotlin.analysis.api.impl.base.types.KaBaseTypeArgumentWithVariance
import org.jetbrains.kotlin.analysis.api.platform.lifetime.KotlinAlwaysAccessibleLifetimeToken
import org.jetbrains.kotlin.analysis.api.projectStructure.KaLibraryModule
import org.jetbrains.kotlin.analysis.api.projectStructure.KaLibrarySourceModule
import org.jetbrains.kotlin.analysis.api.projectStructure.KaSourceModule
import org.jetbrains.kotlin.analysis.api.symbols.*
import org.jetbrains.kotlin.analysis.api.symbols.markers.KaDeclarationContainerSymbol
import org.jetbrains.kotlin.analysis.api.types.*
Expand Down Expand Up @@ -988,3 +990,29 @@ internal fun KaCallableSymbol.explictJvmName(): String? {
it.classId == jvmNameClassId
}?.arguments?.single()?.expression?.toValue() as? String
}

internal val KaDeclarationSymbol.internalSuffix: String
get() = analyze {
if (visibility != KaSymbolVisibility.INTERNAL)
return@analyze ""

// Skip top level functions and properties
when (this@internalSuffix) {
is KaPropertyAccessorSymbol -> {
if (containingDeclaration?.containingDeclaration == null)
return@analyze ""
}
is KaFunctionSymbol -> {
if (containingDeclaration == null)
return@analyze ""
}
else -> {}
}

fun String.toSuffix(): String = "\$$this"
when (val module = containingModule) {
is KaSourceModule -> module.name.toSuffix()
is KaLibraryModule -> module.libraryName.toSuffix()
else -> ""
}
}

0 comments on commit 7a5ded4

Please sign in to comment.