[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 {
|
||||
|
||||
+13
-3
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.psi2ir.isConstructorDelegatingToSuper
|
||||
import org.jetbrains.kotlin.resolve.BindingContext
|
||||
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.calls.util.isSingleUnderscore
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.ConstantExpressionEvaluator
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isAnnotationConstructor
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
||||
@@ -376,15 +377,24 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
|
||||
ktElement: KtPureElement?,
|
||||
irOwnerElement: IrElement,
|
||||
name: Name? = null
|
||||
) =
|
||||
context.symbolTable.declareValueParameter(
|
||||
): IrValueParameter {
|
||||
var origin: IrDeclarationOrigin = IrDeclarationOrigin.DEFINED
|
||||
if (ktElement is KtParameter) {
|
||||
if (ktElement.isSingleUnderscore) {
|
||||
origin = IrDeclarationOrigin.UNDERSCORE_PARAMETER
|
||||
} else if (ktElement.destructuringDeclaration != null) {
|
||||
origin = IrDeclarationOrigin.DESTRUCTURED_OBJECT_PARAMETER
|
||||
}
|
||||
}
|
||||
return context.symbolTable.declareValueParameter(
|
||||
ktElement?.pureStartOffset ?: irOwnerElement.startOffset,
|
||||
ktElement?.pureEndOffset ?: irOwnerElement.endOffset,
|
||||
IrDeclarationOrigin.DEFINED,
|
||||
origin,
|
||||
descriptor, descriptor.type.toIrType(),
|
||||
(descriptor as? ValueParameterDescriptor)?.varargElementType?.toIrType(),
|
||||
name
|
||||
)
|
||||
}
|
||||
|
||||
private fun generateDefaultAnnotationParameterValue(
|
||||
valueExpression: KtExpression,
|
||||
|
||||
@@ -52,6 +52,8 @@ interface IrDeclarationOrigin {
|
||||
object LOCAL_FUNCTION : IrDeclarationOriginImpl("LOCAL_FUNCTION")
|
||||
object LOCAL_FUNCTION_FOR_LAMBDA : IrDeclarationOriginImpl("LOCAL_FUNCTION_FOR_LAMBDA")
|
||||
object CATCH_PARAMETER : IrDeclarationOriginImpl("CATCH_PARAMETER")
|
||||
object UNDERSCORE_PARAMETER : IrDeclarationOriginImpl("UNDERSCORE_PARAMETER")
|
||||
object DESTRUCTURED_OBJECT_PARAMETER : IrDeclarationOriginImpl("DESTRUCTURED_OBJECT_PARAMETER")
|
||||
object INSTANCE_RECEIVER : IrDeclarationOriginImpl("INSTANCE_RECEIVER")
|
||||
object PRIMARY_CONSTRUCTOR_PARAMETER : IrDeclarationOriginImpl("PRIMARY_CONSTRUCTOR_PARAMETER")
|
||||
object IR_TEMPORARY_VARIABLE : IrDeclarationOriginImpl("IR_TEMPORARY_VARIABLE")
|
||||
|
||||
Reference in New Issue
Block a user