From 36c4df6d99029a63bb690cf2bc402b37ebeb8415 Mon Sep 17 00:00:00 2001 From: Mark Punzalan Date: Wed, 8 Jan 2020 02:08:50 -0800 Subject: [PATCH] [JVM IR] Use names of local functions in names of local classes. This undoes changes in https://github.com/JetBrains/kotlin/commit/fbe66c3496d082d2d487b2c39673f0cd4ac5b70a which broke calculation of the simple name of local classes in reflection (the enclosing method was not a substring of the name of the local class). --- .../backend/jvm/lower/InventNamesForLocalClasses.kt | 6 ------ .../checkLocalVariablesTable/itInReturnedLambda.kt | 8 ++++++++ .../box/reflection/classes/localClassSimpleName.kt | 1 - 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InventNamesForLocalClasses.kt b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InventNamesForLocalClasses.kt index 0eb8612d89f..92126bb5437 100644 --- a/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InventNamesForLocalClasses.kt +++ b/compiler/ir/backend.jvm/src/org/jetbrains/kotlin/backend/jvm/lower/InventNamesForLocalClasses.kt @@ -108,12 +108,6 @@ class InventNamesForLocalClasses(private val context: JvmBackendContext) : FileL localFunctionNames[(declaration as IrFunction).symbol] = name } } - declaration is IrFunction && declaration.parent !is IrClass -> { - // In the old backend, only names of non-local functions are stored in names of anonymous classes. All other names - // are replaced with indices. For example, a local class `L` in a top-level function `f` will have the name `...$f$L`, - // but inside a local function `g` (which is in `f`) it will have the name `...$f$1$L` (_not_ `...$f$g$L`). - inventName(null, data) - } enclosingName != null -> "$enclosingName$$simpleName" else -> simpleName } diff --git a/compiler/testData/checkLocalVariablesTable/itInReturnedLambda.kt b/compiler/testData/checkLocalVariablesTable/itInReturnedLambda.kt index 23478ff5561..e69b36b2a8a 100644 --- a/compiler/testData/checkLocalVariablesTable/itInReturnedLambda.kt +++ b/compiler/testData/checkLocalVariablesTable/itInReturnedLambda.kt @@ -6,6 +6,14 @@ fun foo() { } } +// Names of local functions are used in names of local classes for IR, but only indices are used for non-IR. + +// JVM_TEMPLATES // METHOD : ItInReturnedLambdaKt$foo$1$1.invoke(I)V // VARIABLE : NAME=this TYPE=LItInReturnedLambdaKt$foo$1$1; INDEX=0 // VARIABLE : NAME=it TYPE=I INDEX=1 + +// JVM_IR_TEMPLATES +// METHOD : ItInReturnedLambdaKt$foo$bar$1.invoke(I)V +// VARIABLE : NAME=this TYPE=LItInReturnedLambdaKt$foo$bar$1; INDEX=0 +// VARIABLE : NAME=it TYPE=I INDEX=1 diff --git a/compiler/testData/codegen/box/reflection/classes/localClassSimpleName.kt b/compiler/testData/codegen/box/reflection/classes/localClassSimpleName.kt index 03823437f35..f31333fd816 100644 --- a/compiler/testData/codegen/box/reflection/classes/localClassSimpleName.kt +++ b/compiler/testData/codegen/box/reflection/classes/localClassSimpleName.kt @@ -1,5 +1,4 @@ // IGNORE_BACKEND_FIR: JVM_IR -// IGNORE_BACKEND: JVM_IR // IGNORE_BACKEND: NATIVE // WITH_RUNTIME