JVM_IR: generate shorter names for classes in delegate initializers
#KT-41493 Fixed
This commit is contained in:
+8
-10
@@ -87,15 +87,13 @@ class InventNamesForLocalClasses(private val context: JvmBackendContext) : FileL
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun visitDeclaration(declaration: IrDeclarationBase, data: Data) {
|
override fun visitDeclaration(declaration: IrDeclarationBase, data: Data) {
|
||||||
if (declaration !is IrDeclarationWithName) {
|
if (declaration !is IrDeclarationWithName ||
|
||||||
declaration.acceptChildren(this, data)
|
// Skip temporary variables because they are not present in source code, and their names are not particularly
|
||||||
return
|
// meaningful (e.g. `tmp$1`) in any case.
|
||||||
}
|
declaration.origin == IrDeclarationOrigin.FOR_LOOP_ITERATOR ||
|
||||||
|
declaration.origin == IrDeclarationOrigin.IR_TEMPORARY_VARIABLE ||
|
||||||
// We explicitly skip temporary variables (such as a for loop iterator, or a temporary value for an elvis operator)
|
// Skip variables storing delegates for local properties because we already have the name of the property itself.
|
||||||
// because they are not present in the original source code and their names should not affect names of local entities.
|
declaration.origin == IrDeclarationOrigin.PROPERTY_DELEGATE
|
||||||
if (declaration.origin == IrDeclarationOrigin.FOR_LOOP_ITERATOR ||
|
|
||||||
declaration.origin == IrDeclarationOrigin.IR_TEMPORARY_VARIABLE
|
|
||||||
) {
|
) {
|
||||||
declaration.acceptChildren(this, data)
|
declaration.acceptChildren(this, data)
|
||||||
return
|
return
|
||||||
@@ -117,7 +115,7 @@ class InventNamesForLocalClasses(private val context: JvmBackendContext) : FileL
|
|||||||
}
|
}
|
||||||
|
|
||||||
val newData = data.withName(internalName).makeLocal()
|
val newData = data.withName(internalName).makeLocal()
|
||||||
if (declaration is IrProperty && declaration.isDelegated) {
|
if ((declaration is IrProperty && declaration.isDelegated) || declaration is IrLocalDelegatedProperty) {
|
||||||
// Old backend currently reserves a name here, in case a property reference-like anonymous object will need
|
// Old backend currently reserves a name here, in case a property reference-like anonymous object will need
|
||||||
// to be generated in the codegen later, which is now happening for local delegated properties in inline functions.
|
// to be generated in the codegen later, which is now happening for local delegated properties in inline functions.
|
||||||
// See CodegenAnnotatingVisitor.visitProperty and ExpressionCodegen.initializePropertyMetadata.
|
// See CodegenAnnotatingVisitor.visitProperty and ExpressionCodegen.initializePropertyMetadata.
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
operator fun (() -> String).getValue(thisRef: Any?, property: Any?) = this()
|
||||||
|
|
||||||
|
fun foo() {
|
||||||
|
val prop by { "OK" }
|
||||||
|
}
|
||||||
|
|
||||||
|
// METHOD : ObjectInLocalPropertyDelegateKt$foo$prop$2.invoke()Ljava/lang/String;
|
||||||
|
// VARIABLE : NAME=this TYPE=LObjectInLocalPropertyDelegateKt$foo$prop$2; INDEX=0
|
||||||
+5
@@ -109,6 +109,11 @@ public class CheckLocalVariablesTableTestGenerated extends AbstractCheckLocalVar
|
|||||||
runTest("compiler/testData/checkLocalVariablesTable/localFun.kt");
|
runTest("compiler/testData/checkLocalVariablesTable/localFun.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("objectInLocalPropertyDelegate.kt")
|
||||||
|
public void testObjectInLocalPropertyDelegate() throws Exception {
|
||||||
|
runTest("compiler/testData/checkLocalVariablesTable/objectInLocalPropertyDelegate.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("receiverParameter.kt")
|
@TestMetadata("receiverParameter.kt")
|
||||||
public void testReceiverParameter() throws Exception {
|
public void testReceiverParameter() throws Exception {
|
||||||
runTest("compiler/testData/checkLocalVariablesTable/receiverParameter.kt");
|
runTest("compiler/testData/checkLocalVariablesTable/receiverParameter.kt");
|
||||||
|
|||||||
Generated
+5
@@ -109,6 +109,11 @@ public class IrCheckLocalVariablesTableTestGenerated extends AbstractIrCheckLoca
|
|||||||
runTest("compiler/testData/checkLocalVariablesTable/localFun.kt");
|
runTest("compiler/testData/checkLocalVariablesTable/localFun.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("objectInLocalPropertyDelegate.kt")
|
||||||
|
public void testObjectInLocalPropertyDelegate() throws Exception {
|
||||||
|
runTest("compiler/testData/checkLocalVariablesTable/objectInLocalPropertyDelegate.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("receiverParameter.kt")
|
@TestMetadata("receiverParameter.kt")
|
||||||
public void testReceiverParameter() throws Exception {
|
public void testReceiverParameter() throws Exception {
|
||||||
runTest("compiler/testData/checkLocalVariablesTable/receiverParameter.kt");
|
runTest("compiler/testData/checkLocalVariablesTable/receiverParameter.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user