[JVM IR] Do not put destructuring params or underscores in LVT.
Putting them in the local variable table means that the debugger needs to have special handling for parameters with specific names. That forces us to generate mangled names for these. Instead of also implementing the name mangling for FIR, this change gets rid of the parameters from the LVT instead.
This commit is contained in:
+1
-1
@@ -65,7 +65,7 @@ open class JvmIrCodegenFactory(
|
||||
if (externalSymbolTable != null) externalMangler!! to externalSymbolTable
|
||||
else {
|
||||
val mangler = JvmDescriptorMangler(MainFunctionDetector(input.bindingContext, input.languageVersionSettings))
|
||||
val symbolTable = SymbolTable(JvmIdSignatureDescriptor(mangler), IrFactoryImpl, JvmNameProvider)
|
||||
val symbolTable = SymbolTable(JvmIdSignatureDescriptor(mangler), IrFactoryImpl)
|
||||
mangler to symbolTable
|
||||
}
|
||||
val psi2ir = Psi2IrTranslator(input.languageVersionSettings, Psi2IrConfiguration(input.ignoreErrors))
|
||||
|
||||
+3
-3
@@ -178,7 +178,7 @@ private class SuspendLambdaLowering(context: JvmBackendContext) : SuspendLowerin
|
||||
isFinal = false
|
||||
visibility = if (it.index < 0) DescriptorVisibilities.PRIVATE else JavaDescriptorVisibilities.PACKAGE_VISIBILITY
|
||||
} else null
|
||||
ParameterInfo(field, it.type, it.name)
|
||||
ParameterInfo(field, it.type, it.name, it.origin)
|
||||
}
|
||||
|
||||
context.continuationClassesVarsCountByType[attributeOwnerId] = varsCountByType
|
||||
@@ -219,7 +219,7 @@ private class SuspendLambdaLowering(context: JvmBackendContext) : SuspendLowerin
|
||||
parent = this,
|
||||
startOffset = UNDEFINED_OFFSET,
|
||||
endOffset = UNDEFINED_OFFSET,
|
||||
origin = IrDeclarationOrigin.DEFINED,
|
||||
origin = param.origin,
|
||||
name = param.name,
|
||||
type = param.type
|
||||
).apply {
|
||||
@@ -353,6 +353,6 @@ private class SuspendLambdaLowering(context: JvmBackendContext) : SuspendLowerin
|
||||
}
|
||||
}
|
||||
|
||||
private data class ParameterInfo(val field: IrField?, val type: IrType, val name: Name) {
|
||||
private data class ParameterInfo(val field: IrField?, val type: IrType, val name: Name, val origin: IrDeclarationOrigin) {
|
||||
val isUsed = field != null
|
||||
}
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.backend.jvm
|
||||
|
||||
import org.jetbrains.kotlin.codegen.getNameForDestructuredParameterOrNull
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.ValueParameterDescriptor
|
||||
import org.jetbrains.kotlin.ir.util.NameProvider
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtParameter
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.util.isSingleUnderscore
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
|
||||
object JvmNameProvider : NameProvider {
|
||||
override fun nameForDeclaration(descriptor: DeclarationDescriptor): Name {
|
||||
if (descriptor is ValueParameterDescriptor)
|
||||
return nameForValueParameter(descriptor)
|
||||
return NameProvider.DEFAULT.nameForDeclaration(descriptor)
|
||||
}
|
||||
|
||||
private fun nameForValueParameter(descriptor: ValueParameterDescriptor): Name {
|
||||
getNameForDestructuredParameterOrNull(descriptor)?.let { return Name.identifier(it) }
|
||||
if (DescriptorToSourceUtils.getSourceFromDescriptor(descriptor)?.safeAs<KtParameter>()?.isSingleUnderscore == true) {
|
||||
return Name.identifier("\$noName_${descriptor.index}")
|
||||
}
|
||||
return descriptor.name
|
||||
}
|
||||
}
|
||||
+8
-2
@@ -347,6 +347,8 @@ class ExpressionCodegen(
|
||||
}
|
||||
|
||||
private fun writeValueParameterInLocalVariableTable(param: IrValueParameter, startLabel: Label, endLabel: Label, isReceiver: Boolean) {
|
||||
if (!param.isVisibleInLVT) return
|
||||
|
||||
// If the parameter is an extension receiver parameter or a captured extension receiver from enclosing,
|
||||
// then generate name accordingly.
|
||||
val name = if (param.origin == BOUND_RECEIVER_PARAMETER || isReceiver) {
|
||||
@@ -389,9 +391,13 @@ class ExpressionCodegen(
|
||||
return value
|
||||
}
|
||||
|
||||
private val IrVariable.isVisibleInLVT: Boolean
|
||||
// Temporary variables, unnamed (underscore) parameters, and the object for destruction
|
||||
// in a destructuring assignment for lambda parameters do not go in the local variable table.
|
||||
private val IrValueDeclaration.isVisibleInLVT: Boolean
|
||||
get() = origin != IrDeclarationOrigin.IR_TEMPORARY_VARIABLE &&
|
||||
origin != IrDeclarationOrigin.FOR_LOOP_ITERATOR
|
||||
origin != IrDeclarationOrigin.FOR_LOOP_ITERATOR &&
|
||||
origin != IrDeclarationOrigin.UNDERSCORE_PARAMETER &&
|
||||
origin != IrDeclarationOrigin.DESTRUCTURED_OBJECT_PARAMETER
|
||||
|
||||
private fun writeLocalVariablesInTable(info: BlockInfo, endLabel: Label) {
|
||||
info.variables.forEach {
|
||||
|
||||
Reference in New Issue
Block a user