From d026cc444aeadcd21db312776043a0569f74efde Mon Sep 17 00:00:00 2001 From: Ting-Yuan Huang Date: Thu, 21 Nov 2024 12:48:52 -0800 Subject: [PATCH] KSP2: Sanitize dots to underscores in suffixes of internals (cherry picked from commit 748eb386d72d6b7d3cf6f7b0aea20d22ac26b563) --- .../devtools/ksp/impl/symbol/kotlin/util.kt | 2 +- kotlin-analysis-api/testData/mangledNames.kt | 44 +++++++++---------- test-utils/testData/api/mangledNames.kt | 44 +++++++++---------- 3 files changed, 45 insertions(+), 45 deletions(-) diff --git a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt index cfd2b0eac8..5fa4bbe2b0 100644 --- a/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt +++ b/kotlin-analysis-api/src/main/kotlin/com/google/devtools/ksp/impl/symbol/kotlin/util.kt @@ -922,7 +922,7 @@ internal val KaDeclarationSymbol.internalSuffix: String else -> {} } - fun String.toSuffix(): String = "\$$this" + fun String.toSuffix(): String = "\$$this".replace('.', '_') when (val module = containingModule) { is KaSourceModule -> module.name.toSuffix() is KaLibraryModule -> { diff --git a/kotlin-analysis-api/testData/mangledNames.kt b/kotlin-analysis-api/testData/mangledNames.kt index 04721222c8..2a09a4b7d4 100644 --- a/kotlin-analysis-api/testData/mangledNames.kt +++ b/kotlin-analysis-api/testData/mangledNames.kt @@ -34,10 +34,10 @@ // get-abstractVal -> getAbstractVal // get-abstractVar -> getAbstractVar // set-abstractVar -> setAbstractVar -// get-internalAbstractVal -> getInternalAbstractVal$mainModule -// set-internalAbstractVal -> setInternalAbstractVal$mainModule -// get-internalAbstractVar -> getInternalAbstractVar$mainModule -// set-internalAbstractVar -> setInternalAbstractVar$mainModule +// get-internalAbstractVal -> getInternalAbstractVal$mainModule_abc +// set-internalAbstractVal -> setInternalAbstractVal$mainModule_abc +// get-internalAbstractVar -> getInternalAbstractVar$mainModule_abc +// set-internalAbstractVar -> setInternalAbstractVar$mainModule_abc // mainPackage.Anno -> declarations // get-a -> a // mainPackage.Foo -> declarations @@ -46,12 +46,12 @@ // set-inlineProp -> setInlineProp-E03SJzc // inlineReceivingFun -> inlineReceivingFun-E03SJzc // inlineReturningFun -> inlineReturningFun-HRn7Rpw -// get-internalInlineProp -> getInternalInlineProp-HRn7Rpw$mainModule -// set-internalInlineProp -> setInternalInlineProp-E03SJzc$mainModule -// internalInlineReceivingFun -> internalInlineReceivingFun-E03SJzc$mainModule -// internalInlineReturningFun -> internalInlineReturningFun-HRn7Rpw$mainModule -// get-internalProp -> getInternalProp$mainModule -// set-internalProp -> setInternalProp$mainModule +// get-internalInlineProp -> getInternalInlineProp-HRn7Rpw$mainModule_abc +// set-internalInlineProp -> setInternalInlineProp-E03SJzc$mainModule_abc +// internalInlineReceivingFun -> internalInlineReceivingFun-E03SJzc$mainModule_abc +// internalInlineReturningFun -> internalInlineReturningFun-HRn7Rpw$mainModule_abc +// get-internalProp -> getInternalProp$mainModule_abc +// set-internalProp -> setInternalProp$mainModule_abc // get-jvmNameProp -> explicitGetterName // set-jvmNameProp -> explicitSetterName // normalFun -> normalFun @@ -73,12 +73,12 @@ // set-inlineProp -> setInlineProp-mQ73O9w // inlineReceivingFun -> inlineReceivingFun-mQ73O9w // inlineReturningFun -> inlineReturningFun-b_MPbnQ -// get-internalInlineProp -> getInternalInlineProp-b_MPbnQ$lib -// set-internalInlineProp -> setInternalInlineProp-mQ73O9w$lib -// internalInlineReceivingFun -> internalInlineReceivingFun-mQ73O9w$lib -// internalInlineReturningFun -> internalInlineReturningFun-b_MPbnQ$lib -// get-internalProp -> getInternalProp$lib -// set-internalProp -> setInternalProp$lib +// get-internalInlineProp -> getInternalInlineProp-b_MPbnQ$lib_xyz +// set-internalInlineProp -> setInternalInlineProp-mQ73O9w$lib_xyz +// internalInlineReceivingFun -> internalInlineReceivingFun-mQ73O9w$lib_xyz +// internalInlineReturningFun -> internalInlineReturningFun-b_MPbnQ$lib_xyz +// get-internalProp -> getInternalProp$lib_xyz +// set-internalProp -> setInternalProp$lib_xyz // get-jvmNameProp -> explicitGetterName // set-jvmNameProp -> explicitSetterName // normalFun -> normalFun @@ -88,16 +88,16 @@ // get-abstractVal -> getAbstractVal // get-abstractVar -> getAbstractVar // set-abstractVar -> setAbstractVar -// get-internalAbstractVal -> getInternalAbstractVal$lib -// set-internalAbstractVal -> setInternalAbstractVal$lib -// get-internalAbstractVar -> getInternalAbstractVar$lib -// set-internalAbstractVar -> setInternalAbstractVar$lib +// get-internalAbstractVal -> getInternalAbstractVal$lib_xyz +// set-internalAbstractVal -> setInternalAbstractVal$lib_xyz +// get-internalAbstractVar -> getInternalAbstractVar$lib_xyz +// set-internalAbstractVar -> setInternalAbstractVar$lib_xyz // libPackage.MyInterface -> declarations // get-x -> getX // get-y -> getY // set-y -> setY // END -// MODULE: lib +// MODULE: lib.xyz // FILE: input.kt /** * control group @@ -132,7 +132,7 @@ interface MyInterface { val x:Int var y:Int } -// MODULE: mainModule(lib) +// MODULE: mainModule.abc(lib.xyz) // FILE: input.kt package mainPackage; inline class Inline1(val value:String) diff --git a/test-utils/testData/api/mangledNames.kt b/test-utils/testData/api/mangledNames.kt index ceabe010ac..9dca8b53ff 100644 --- a/test-utils/testData/api/mangledNames.kt +++ b/test-utils/testData/api/mangledNames.kt @@ -34,10 +34,10 @@ // get-abstractVal -> getAbstractVal // get-abstractVar -> getAbstractVar // set-abstractVar -> setAbstractVar -// get-internalAbstractVal -> getInternalAbstractVal$mainModule -// set-internalAbstractVal -> setInternalAbstractVal$mainModule -// get-internalAbstractVar -> getInternalAbstractVar$mainModule -// set-internalAbstractVar -> setInternalAbstractVar$mainModule +// get-internalAbstractVal -> getInternalAbstractVal$mainModule_abc +// set-internalAbstractVal -> setInternalAbstractVal$mainModule_abc +// get-internalAbstractVar -> getInternalAbstractVar$mainModule_abc +// set-internalAbstractVar -> setInternalAbstractVar$mainModule_abc // mainPackage.Anno -> declarations // get-a -> a // mainPackage.Foo -> declarations @@ -46,12 +46,12 @@ // set-inlineProp -> setInlineProp-E03SJzc // inlineReceivingFun -> inlineReceivingFun-E03SJzc // inlineReturningFun -> inlineReturningFun-HRn7Rpw -// get-internalInlineProp -> getInternalInlineProp-HRn7Rpw$mainModule -// set-internalInlineProp -> setInternalInlineProp-E03SJzc$mainModule -// internalInlineReceivingFun -> internalInlineReceivingFun-E03SJzc$mainModule -// internalInlineReturningFun -> internalInlineReturningFun-HRn7Rpw$mainModule -// get-internalProp -> getInternalProp$mainModule -// set-internalProp -> setInternalProp$mainModule +// get-internalInlineProp -> getInternalInlineProp-HRn7Rpw$mainModule_abc +// set-internalInlineProp -> setInternalInlineProp-E03SJzc$mainModule_abc +// internalInlineReceivingFun -> internalInlineReceivingFun-E03SJzc$mainModule_abc +// internalInlineReturningFun -> internalInlineReturningFun-HRn7Rpw$mainModule_abc +// get-internalProp -> getInternalProp$mainModule_abc +// set-internalProp -> setInternalProp$mainModule_abc // get-jvmNameProp -> explicitGetterName // set-jvmNameProp -> explicitSetterName // normalFun -> normalFun @@ -73,12 +73,12 @@ // set-inlineProp -> setInlineProp-mQ73O9w // inlineReceivingFun -> inlineReceivingFun-mQ73O9w // inlineReturningFun -> inlineReturningFun-b_MPbnQ -// get-internalInlineProp -> getInternalInlineProp-b_MPbnQ$lib -// set-internalInlineProp -> setInternalInlineProp-mQ73O9w$lib -// internalInlineReceivingFun -> internalInlineReceivingFun-mQ73O9w$lib -// internalInlineReturningFun -> internalInlineReturningFun-b_MPbnQ$lib -// get-internalProp -> getInternalProp$lib -// set-internalProp -> setInternalProp$lib +// get-internalInlineProp -> getInternalInlineProp-b_MPbnQ$lib_xyz +// set-internalInlineProp -> setInternalInlineProp-mQ73O9w$lib_xyz +// internalInlineReceivingFun -> internalInlineReceivingFun-mQ73O9w$lib_xyz +// internalInlineReturningFun -> internalInlineReturningFun-b_MPbnQ$lib_xyz +// get-internalProp -> getInternalProp$lib_xyz +// set-internalProp -> setInternalProp$lib_xyz // get-jvmNameProp -> explicitGetterName // set-jvmNameProp -> explicitSetterName // normalFun -> normalFun @@ -88,16 +88,16 @@ // get-abstractVal -> getAbstractVal // get-abstractVar -> getAbstractVar // set-abstractVar -> setAbstractVar -// get-internalAbstractVal -> getInternalAbstractVal$lib -// set-internalAbstractVal -> setInternalAbstractVal$lib -// get-internalAbstractVar -> getInternalAbstractVar$lib -// set-internalAbstractVar -> setInternalAbstractVar$lib +// get-internalAbstractVal -> getInternalAbstractVal$lib_xyz +// set-internalAbstractVal -> setInternalAbstractVal$lib_xyz +// get-internalAbstractVar -> getInternalAbstractVar$lib_xyz +// set-internalAbstractVar -> setInternalAbstractVar$lib_xyz // libPackage.MyInterface -> declarations // get-x -> getX // get-y -> getY // set-y -> setY // END -// MODULE: lib +// MODULE: lib.xyz // FILE: input.kt /** * control group @@ -132,7 +132,7 @@ interface MyInterface { val x:Int var y:Int } -// MODULE: mainModule(lib) +// MODULE: mainModule.abc(lib.xyz) // FILE: input.kt package mainPackage; inline class Inline1(val value:String)