Remove descriptors from LocalDeclarationslowering
This commit is contained in:
+6
-6
@@ -40,8 +40,8 @@ import org.jetbrains.kotlin.name.NameUtils
|
|||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
interface LocalNameProvider {
|
interface LocalNameProvider {
|
||||||
fun localName(descriptor: DeclarationDescriptor): String =
|
fun localName(declaration: IrDeclarationWithName): String =
|
||||||
descriptor.name.asString()
|
declaration.name.asString()
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
val DEFAULT = object : LocalNameProvider {}
|
val DEFAULT = object : LocalNameProvider {}
|
||||||
@@ -465,13 +465,13 @@ class LocalDeclarationsLowering(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun suggestLocalName(declaration: IrDeclaration): String {
|
private fun suggestLocalName(declaration: IrDeclarationWithName): String {
|
||||||
localFunctions[declaration]?.let {
|
localFunctions[declaration]?.let {
|
||||||
if (it.index >= 0)
|
if (it.index >= 0)
|
||||||
return "lambda-${it.index}"
|
return "lambda-${it.index}"
|
||||||
}
|
}
|
||||||
|
|
||||||
return localNameProvider.localName(declaration.descriptor)
|
return localNameProvider.localName(declaration)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun generateNameForLiftedDeclaration(
|
private fun generateNameForLiftedDeclaration(
|
||||||
@@ -481,7 +481,7 @@ class LocalDeclarationsLowering(
|
|||||||
Name.identifier(
|
Name.identifier(
|
||||||
declaration.parentsWithSelf
|
declaration.parentsWithSelf
|
||||||
.takeWhile { it != newOwner }
|
.takeWhile { it != newOwner }
|
||||||
.toList().reversed().joinToString(separator = "$") { suggestLocalName(it as IrDeclaration) }
|
.toList().reversed().joinToString(separator = "$") { suggestLocalName(it as IrDeclarationWithName) }
|
||||||
)
|
)
|
||||||
|
|
||||||
private fun createLiftedDeclaration(localFunctionContext: LocalFunctionContext) {
|
private fun createLiftedDeclaration(localFunctionContext: LocalFunctionContext) {
|
||||||
@@ -773,4 +773,4 @@ class LocalDeclarationsLowering(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -89,7 +89,7 @@ class SharedVariablesLowering(val context: BackendContext) : FunctionLoweringPas
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun rewriteSharedVariables() {
|
private fun rewriteSharedVariables() {
|
||||||
val transformedDescriptors = HashMap<IrValueSymbol, IrVariableSymbol>()
|
val transformedSymbols = HashMap<IrValueSymbol, IrVariableSymbol>()
|
||||||
|
|
||||||
irFunction.transformChildrenVoid(object : IrElementTransformerVoid() {
|
irFunction.transformChildrenVoid(object : IrElementTransformerVoid() {
|
||||||
override fun visitVariable(declaration: IrVariable): IrStatement {
|
override fun visitVariable(declaration: IrVariable): IrStatement {
|
||||||
@@ -99,7 +99,7 @@ class SharedVariablesLowering(val context: BackendContext) : FunctionLoweringPas
|
|||||||
|
|
||||||
val newDeclaration = context.sharedVariablesManager.declareSharedVariable(declaration)
|
val newDeclaration = context.sharedVariablesManager.declareSharedVariable(declaration)
|
||||||
newDeclaration.parent = irFunction
|
newDeclaration.parent = irFunction
|
||||||
transformedDescriptors[declaration.symbol] = newDeclaration.symbol
|
transformedSymbols[declaration.symbol] = newDeclaration.symbol
|
||||||
|
|
||||||
return context.sharedVariablesManager.defineSharedValue(declaration, newDeclaration)
|
return context.sharedVariablesManager.defineSharedValue(declaration, newDeclaration)
|
||||||
}
|
}
|
||||||
@@ -123,7 +123,7 @@ class SharedVariablesLowering(val context: BackendContext) : FunctionLoweringPas
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun getTransformedSymbol(oldSymbol: IrValueSymbol): IrVariableSymbol? =
|
private fun getTransformedSymbol(oldSymbol: IrValueSymbol): IrVariableSymbol? =
|
||||||
transformedDescriptors.getOrElse(oldSymbol) {
|
transformedSymbols.getOrElse(oldSymbol) {
|
||||||
assert(oldSymbol.owner !in sharedVariables) {
|
assert(oldSymbol.owner !in sharedVariables) {
|
||||||
"Shared variable is not transformed: ${oldSymbol.owner.dump()}"
|
"Shared variable is not transformed: ${oldSymbol.owner.dump()}"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,10 +24,12 @@ import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
|||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
interface IrClass : IrSymbolDeclaration<IrClassSymbol>, IrDeclarationWithVisibility, IrDeclarationContainer, IrTypeParametersContainer {
|
interface IrClass :
|
||||||
|
IrSymbolDeclaration<IrClassSymbol>, IrDeclarationWithName, IrDeclarationWithVisibility,
|
||||||
|
IrDeclarationContainer, IrTypeParametersContainer {
|
||||||
|
|
||||||
override val descriptor: ClassDescriptor
|
override val descriptor: ClassDescriptor
|
||||||
|
|
||||||
val name: Name
|
|
||||||
val kind: ClassKind
|
val kind: ClassKind
|
||||||
val modality: Modality
|
val modality: Modality
|
||||||
val isCompanion: Boolean
|
val isCompanion: Boolean
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.ir.IrElement
|
|||||||
import org.jetbrains.kotlin.ir.IrStatement
|
import org.jetbrains.kotlin.ir.IrStatement
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
|
import org.jetbrains.kotlin.name.Name
|
||||||
|
|
||||||
interface IrSymbolOwner : IrElement {
|
interface IrSymbolOwner : IrElement {
|
||||||
val symbol: IrSymbol
|
val symbol: IrSymbol
|
||||||
@@ -49,3 +50,7 @@ interface IrDeclarationWithVisibility : IrDeclaration {
|
|||||||
val visibility: Visibility
|
val visibility: Visibility
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface IrDeclarationWithName : IrDeclaration {
|
||||||
|
val name: Name
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,13 +19,10 @@ package org.jetbrains.kotlin.ir.declarations
|
|||||||
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol
|
import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
|
|
||||||
interface IrEnumEntry : IrSymbolDeclaration<IrEnumEntrySymbol> {
|
interface IrEnumEntry : IrSymbolDeclaration<IrEnumEntrySymbol>, IrDeclarationWithName {
|
||||||
override val descriptor: ClassDescriptor
|
override val descriptor: ClassDescriptor
|
||||||
|
|
||||||
val name: Name
|
|
||||||
|
|
||||||
var correspondingClass: IrClass?
|
var correspondingClass: IrClass?
|
||||||
var initializerExpression: IrExpression?
|
var initializerExpression: IrExpression?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,12 +9,10 @@ import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
|||||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrFieldSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
|
|
||||||
interface IrField : IrSymbolDeclaration<IrFieldSymbol>, IrOverridableDeclaration<IrFieldSymbol>, IrDeclarationWithVisibility, IrDeclarationParent {
|
interface IrField : IrSymbolDeclaration<IrFieldSymbol>, IrOverridableDeclaration<IrFieldSymbol>, IrDeclarationWithVisibility, IrDeclarationParent {
|
||||||
override val descriptor: PropertyDescriptor
|
override val descriptor: PropertyDescriptor
|
||||||
|
|
||||||
val name: Name
|
|
||||||
val type: IrType
|
val type: IrType
|
||||||
val isFinal: Boolean
|
val isFinal: Boolean
|
||||||
val isExternal: Boolean
|
val isExternal: Boolean
|
||||||
|
|||||||
@@ -22,13 +22,13 @@ import org.jetbrains.kotlin.ir.expressions.IrBody
|
|||||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
|
|
||||||
interface IrFunction : IrDeclarationWithVisibility, IrTypeParametersContainer, IrSymbolOwner, IrDeclarationParent, IrReturnTarget {
|
interface IrFunction :
|
||||||
|
IrDeclarationWithName, IrDeclarationWithVisibility, IrTypeParametersContainer, IrSymbolOwner, IrDeclarationParent, IrReturnTarget {
|
||||||
|
|
||||||
override val descriptor: FunctionDescriptor
|
override val descriptor: FunctionDescriptor
|
||||||
override val symbol: IrFunctionSymbol
|
override val symbol: IrFunctionSymbol
|
||||||
|
|
||||||
val name: Name
|
|
||||||
val isInline: Boolean // NB: there's an inline constructor for Array and each primitive array class
|
val isInline: Boolean // NB: there's an inline constructor for Array and each primitive array class
|
||||||
val isExternal: Boolean
|
val isExternal: Boolean
|
||||||
var returnType: IrType
|
var returnType: IrType
|
||||||
|
|||||||
+1
-3
@@ -18,12 +18,10 @@ package org.jetbrains.kotlin.ir.declarations
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors
|
import org.jetbrains.kotlin.descriptors.VariableDescriptorWithAccessors
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
|
|
||||||
interface IrLocalDelegatedProperty : IrDeclaration {
|
interface IrLocalDelegatedProperty : IrDeclarationWithName {
|
||||||
override val descriptor: VariableDescriptorWithAccessors
|
override val descriptor: VariableDescriptorWithAccessors
|
||||||
|
|
||||||
val name: Name
|
|
||||||
val type: IrType
|
val type: IrType
|
||||||
val isVar: Boolean
|
val isVar: Boolean
|
||||||
|
|
||||||
|
|||||||
@@ -18,13 +18,10 @@ package org.jetbrains.kotlin.ir.declarations
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
import org.jetbrains.kotlin.descriptors.PropertyDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.Visibility
|
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
|
|
||||||
interface IrProperty : IrDeclarationWithVisibility {
|
interface IrProperty : IrDeclarationWithName, IrDeclarationWithVisibility {
|
||||||
override val descriptor: PropertyDescriptor
|
override val descriptor: PropertyDescriptor
|
||||||
|
|
||||||
val name: Name
|
|
||||||
val modality: Modality
|
val modality: Modality
|
||||||
val isVar: Boolean
|
val isVar: Boolean
|
||||||
val isConst: Boolean
|
val isConst: Boolean
|
||||||
|
|||||||
@@ -20,13 +20,11 @@ import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
|||||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
|
|
||||||
interface IrTypeParameter : IrSymbolDeclaration<IrTypeParameterSymbol> {
|
interface IrTypeParameter : IrSymbolDeclaration<IrTypeParameterSymbol>, IrDeclarationWithName {
|
||||||
override val descriptor: TypeParameterDescriptor
|
override val descriptor: TypeParameterDescriptor
|
||||||
|
|
||||||
val name: Name
|
|
||||||
val variance: Variance
|
val variance: Variance
|
||||||
val index: Int
|
val index: Int
|
||||||
val isReified: Boolean
|
val isReified: Boolean
|
||||||
|
|||||||
@@ -8,13 +8,10 @@ package org.jetbrains.kotlin.ir.declarations
|
|||||||
import org.jetbrains.kotlin.descriptors.ValueDescriptor
|
import org.jetbrains.kotlin.descriptors.ValueDescriptor
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.name.Name
|
|
||||||
import org.jetbrains.kotlin.types.KotlinType
|
|
||||||
|
|
||||||
interface IrValueDeclaration : IrDeclaration, IrSymbolOwner {
|
interface IrValueDeclaration : IrDeclarationWithName, IrSymbolOwner {
|
||||||
override val descriptor: ValueDescriptor
|
override val descriptor: ValueDescriptor
|
||||||
override val symbol: IrValueSymbol
|
override val symbol: IrValueSymbol
|
||||||
|
|
||||||
val name: Name
|
|
||||||
val type: IrType
|
val type: IrType
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
// IGNORE_BACKEND: JVM_IR
|
||||||
|
// IGNORE_BACKEND: JS_IR
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
interface Wrapper { fun runBlock() }
|
||||||
|
|
||||||
|
inline fun crossInlineBuildWrapper(crossinline block: () -> Unit) = object : Wrapper {
|
||||||
|
override fun runBlock() {
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class Container {
|
||||||
|
val wrapper = crossInlineBuildWrapper {
|
||||||
|
object { }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
Container().wrapper.runBlock()
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+1
@@ -1,4 +1,5 @@
|
|||||||
// IGNORE_BACKEND: JVM_IR
|
// IGNORE_BACKEND: JVM_IR
|
||||||
|
// IGNORE_BACKEND: JS_IR
|
||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// COMMON_COROUTINES_TEST
|
// COMMON_COROUTINES_TEST
|
||||||
// WITH_COROUTINES
|
// WITH_COROUTINES
|
||||||
|
|||||||
+5
@@ -3686,6 +3686,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt");
|
runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("crossinlineLocalDeclaration.kt")
|
||||||
|
public void testCrossinlineLocalDeclaration() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/closures/crossinlineLocalDeclaration.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("doubleEnclosedLocalVariable.kt")
|
@TestMetadata("doubleEnclosedLocalVariable.kt")
|
||||||
public void testDoubleEnclosedLocalVariable() throws Exception {
|
public void testDoubleEnclosedLocalVariable() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/closures/doubleEnclosedLocalVariable.kt");
|
runTest("compiler/testData/codegen/box/closures/doubleEnclosedLocalVariable.kt");
|
||||||
|
|||||||
+5
@@ -3686,6 +3686,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt");
|
runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("crossinlineLocalDeclaration.kt")
|
||||||
|
public void testCrossinlineLocalDeclaration() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/closures/crossinlineLocalDeclaration.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("doubleEnclosedLocalVariable.kt")
|
@TestMetadata("doubleEnclosedLocalVariable.kt")
|
||||||
public void testDoubleEnclosedLocalVariable() throws Exception {
|
public void testDoubleEnclosedLocalVariable() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/closures/doubleEnclosedLocalVariable.kt");
|
runTest("compiler/testData/codegen/box/closures/doubleEnclosedLocalVariable.kt");
|
||||||
|
|||||||
+5
@@ -3686,6 +3686,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt");
|
runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("crossinlineLocalDeclaration.kt")
|
||||||
|
public void testCrossinlineLocalDeclaration() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/closures/crossinlineLocalDeclaration.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("doubleEnclosedLocalVariable.kt")
|
@TestMetadata("doubleEnclosedLocalVariable.kt")
|
||||||
public void testDoubleEnclosedLocalVariable() throws Exception {
|
public void testDoubleEnclosedLocalVariable() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/closures/doubleEnclosedLocalVariable.kt");
|
runTest("compiler/testData/codegen/box/closures/doubleEnclosedLocalVariable.kt");
|
||||||
|
|||||||
+5
@@ -3086,6 +3086,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt");
|
runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("crossinlineLocalDeclaration.kt")
|
||||||
|
public void testCrossinlineLocalDeclaration() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/closures/crossinlineLocalDeclaration.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("doubleEnclosedLocalVariable.kt")
|
@TestMetadata("doubleEnclosedLocalVariable.kt")
|
||||||
public void testDoubleEnclosedLocalVariable() throws Exception {
|
public void testDoubleEnclosedLocalVariable() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/closures/doubleEnclosedLocalVariable.kt");
|
runTest("compiler/testData/codegen/box/closures/doubleEnclosedLocalVariable.kt");
|
||||||
|
|||||||
+5
@@ -3086,6 +3086,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt");
|
runTest("compiler/testData/codegen/box/closures/closureWithParameterAndBoxing.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("crossinlineLocalDeclaration.kt")
|
||||||
|
public void testCrossinlineLocalDeclaration() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/closures/crossinlineLocalDeclaration.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("doubleEnclosedLocalVariable.kt")
|
@TestMetadata("doubleEnclosedLocalVariable.kt")
|
||||||
public void testDoubleEnclosedLocalVariable() throws Exception {
|
public void testDoubleEnclosedLocalVariable() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/closures/doubleEnclosedLocalVariable.kt");
|
runTest("compiler/testData/codegen/box/closures/doubleEnclosedLocalVariable.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user