Get rid of 'descriptor.isInner()' call
This commit is contained in:
+1
-1
@@ -119,7 +119,7 @@ class ClosureAnnotator {
|
|||||||
closureBuilders[declaration.descriptor] = closureBuilder
|
closureBuilders[declaration.descriptor] = closureBuilder
|
||||||
|
|
||||||
closureBuilder.declareVariable(classDescriptor.thisAsReceiverParameter)
|
closureBuilder.declareVariable(classDescriptor.thisAsReceiverParameter)
|
||||||
if (classDescriptor.isInner) {
|
if (declaration.isInner) {
|
||||||
closureBuilder.declareVariable((classDescriptor.containingDeclaration as ClassDescriptor).thisAsReceiverParameter)
|
closureBuilder.declareVariable((classDescriptor.containingDeclaration as ClassDescriptor).thisAsReceiverParameter)
|
||||||
includeInParent(closureBuilder)
|
includeInParent(closureBuilder)
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-11
@@ -20,9 +20,7 @@ import org.jetbrains.kotlin.ir.expressions.*
|
|||||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
||||||
import org.jetbrains.kotlin.ir.util.createParameterDeclarations
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
import org.jetbrains.kotlin.ir.util.dump
|
|
||||||
import org.jetbrains.kotlin.ir.util.transformFlat
|
|
||||||
import org.jetbrains.kotlin.ir.visitors.*
|
import org.jetbrains.kotlin.ir.visitors.*
|
||||||
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitClassReceiver
|
import org.jetbrains.kotlin.resolve.scopes.receivers.ImplicitClassReceiver
|
||||||
import java.util.*
|
import java.util.*
|
||||||
@@ -41,7 +39,7 @@ class InnerClassesLowering(val context: BackendContext) : ClassLoweringPass {
|
|||||||
val class2Symbol = HashMap<ClassDescriptor, IrClass>()
|
val class2Symbol = HashMap<ClassDescriptor, IrClass>()
|
||||||
|
|
||||||
fun lowerInnerClass() {
|
fun lowerInnerClass() {
|
||||||
if (!irClass.descriptor.isInner) return
|
if (!irClass.isInner) return
|
||||||
rememberClassSymbols()
|
rememberClassSymbols()
|
||||||
|
|
||||||
createOuterThisField()
|
createOuterThisField()
|
||||||
@@ -161,7 +159,7 @@ class InnerClassesLowering(val context: BackendContext) : ClassLoweringPass {
|
|||||||
var innerClass = irClass
|
var innerClass = irClass
|
||||||
|
|
||||||
while (innerClass != implicitThisClass) {
|
while (innerClass != implicitThisClass) {
|
||||||
if (!innerClass.descriptor.isInner) {
|
if (!innerClass.isInner) {
|
||||||
// Captured 'this' unrelated to inner classes nesting hierarchy, leave it as is -
|
// Captured 'this' unrelated to inner classes nesting hierarchy, leave it as is -
|
||||||
// should be transformed by closures conversion.
|
// should be transformed by closures conversion.
|
||||||
return expression
|
return expression
|
||||||
@@ -202,7 +200,7 @@ class InnerClassConstructorCallsLowering(val context: BackendContext) : BodyLowe
|
|||||||
val dispatchReceiver = expression.dispatchReceiver ?: return expression
|
val dispatchReceiver = expression.dispatchReceiver ?: return expression
|
||||||
val callee = expression.symbol as? IrConstructorSymbol ?: return expression
|
val callee = expression.symbol as? IrConstructorSymbol ?: return expression
|
||||||
val parent = callee.owner.parent as? IrClass ?: return expression
|
val parent = callee.owner.parent as? IrClass ?: return expression
|
||||||
if (!parent.descriptor.isInner) return expression
|
if (!parent.isInner) return expression
|
||||||
|
|
||||||
val newCallee = context.descriptorsFactory.getInnerClassConstructorWithOuterThisParameter(callee.owner)
|
val newCallee = context.descriptorsFactory.getInnerClassConstructorWithOuterThisParameter(callee.owner)
|
||||||
val newCall = IrCallImpl(
|
val newCall = IrCallImpl(
|
||||||
@@ -223,14 +221,14 @@ class InnerClassConstructorCallsLowering(val context: BackendContext) : BodyLowe
|
|||||||
expression.transformChildrenVoid(this)
|
expression.transformChildrenVoid(this)
|
||||||
|
|
||||||
val dispatchReceiver = expression.dispatchReceiver ?: return expression
|
val dispatchReceiver = expression.dispatchReceiver ?: return expression
|
||||||
val callee = expression.symbol
|
val classConstructor = expression.symbol.owner
|
||||||
if (!callee.descriptor.containingDeclaration.isInner) return expression
|
if (!(classConstructor.parent as IrClass).isInner) return expression
|
||||||
|
|
||||||
val newCallee = context.descriptorsFactory.getInnerClassConstructorWithOuterThisParameter(callee.owner)
|
val newCallee = context.descriptorsFactory.getInnerClassConstructorWithOuterThisParameter(classConstructor)
|
||||||
val newCall = IrDelegatingConstructorCallImpl(
|
val newCall = IrDelegatingConstructorCallImpl(
|
||||||
expression.startOffset, expression.endOffset, newCallee, newCallee.descriptor,
|
expression.startOffset, expression.endOffset, newCallee, newCallee.descriptor,
|
||||||
null // TODO type arguments map
|
classConstructor.typeParameters.size
|
||||||
)
|
).apply { copyTypeArgumentsFrom(expression) }
|
||||||
|
|
||||||
newCall.putValueArgument(0, dispatchReceiver)
|
newCall.putValueArgument(0, dispatchReceiver)
|
||||||
for (i in 1..newCallee.descriptor.valueParameters.lastIndex) {
|
for (i in 1..newCallee.descriptor.valueParameters.lastIndex) {
|
||||||
|
|||||||
+8
-4
@@ -513,6 +513,7 @@ class LocalDeclarationsLowering(val context: BackendContext, val localNameProvid
|
|||||||
localFunctionContext.transformedDeclaration = with(localFunctionContext.declaration) {
|
localFunctionContext.transformedDeclaration = with(localFunctionContext.declaration) {
|
||||||
IrFunctionImpl(startOffset, endOffset, origin, newDescriptor)
|
IrFunctionImpl(startOffset, endOffset, origin, newDescriptor)
|
||||||
}.apply {
|
}.apply {
|
||||||
|
parent = localFunctionContext.declaration.parent
|
||||||
createParameterDeclarations()
|
createParameterDeclarations()
|
||||||
recordTransformedValueParameters(localFunctionContext)
|
recordTransformedValueParameters(localFunctionContext)
|
||||||
transformedDeclarations[oldDescriptor] = this.symbol
|
transformedDeclarations[oldDescriptor] = this.symbol
|
||||||
@@ -600,6 +601,7 @@ class LocalDeclarationsLowering(val context: BackendContext, val localNameProvid
|
|||||||
constructorContext.transformedDeclaration = with(constructorContext.declaration) {
|
constructorContext.transformedDeclaration = with(constructorContext.declaration) {
|
||||||
IrConstructorImpl(startOffset, endOffset, origin, newDescriptor)
|
IrConstructorImpl(startOffset, endOffset, origin, newDescriptor)
|
||||||
}.apply {
|
}.apply {
|
||||||
|
parent = constructorContext.declaration.parent
|
||||||
createParameterDeclarations()
|
createParameterDeclarations()
|
||||||
recordTransformedValueParameters(constructorContext)
|
recordTransformedValueParameters(constructorContext)
|
||||||
transformedDeclarations[oldDescriptor] = this.symbol
|
transformedDeclarations[oldDescriptor] = this.symbol
|
||||||
@@ -642,7 +644,9 @@ class LocalDeclarationsLowering(val context: BackendContext, val localNameProvid
|
|||||||
localClassContext.declaration.startOffset, localClassContext.declaration.endOffset,
|
localClassContext.declaration.startOffset, localClassContext.declaration.endOffset,
|
||||||
DECLARATION_ORIGIN_FIELD_FOR_CAPTURED_VALUE,
|
DECLARATION_ORIGIN_FIELD_FOR_CAPTURED_VALUE,
|
||||||
fieldDescriptor
|
fieldDescriptor
|
||||||
)
|
).apply {
|
||||||
|
parent = localClassContext.declaration
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -728,9 +732,9 @@ class LocalDeclarationsLowering(val context: BackendContext, val localNameProvid
|
|||||||
declaration.acceptChildrenVoid(this)
|
declaration.acceptChildrenVoid(this)
|
||||||
|
|
||||||
val descriptor = declaration.descriptor
|
val descriptor = declaration.descriptor
|
||||||
assert(descriptor.visibility != Visibilities.LOCAL)
|
assert(declaration.visibility != Visibilities.LOCAL)
|
||||||
|
|
||||||
if (descriptor.constructedClass.isInner) return
|
if ((declaration.parent as IrClass).isInner) return
|
||||||
|
|
||||||
localClassConstructors[descriptor] = LocalClassConstructorContext(declaration)
|
localClassConstructors[descriptor] = LocalClassConstructorContext(declaration)
|
||||||
}
|
}
|
||||||
@@ -740,7 +744,7 @@ class LocalDeclarationsLowering(val context: BackendContext, val localNameProvid
|
|||||||
|
|
||||||
val descriptor = declaration.descriptor
|
val descriptor = declaration.descriptor
|
||||||
|
|
||||||
if (descriptor.isInner) return
|
if (declaration.isInner) return
|
||||||
|
|
||||||
// Local nested classes can only be inner.
|
// Local nested classes can only be inner.
|
||||||
assert(descriptor.declaredInFunction())
|
assert(descriptor.declaredInFunction())
|
||||||
|
|||||||
+2
-2
@@ -44,7 +44,7 @@ class JsDescriptorsFactory(
|
|||||||
override fun getSymbolForEnumEntry(enumEntry: IrEnumEntrySymbol): IrFieldSymbol = TODO()
|
override fun getSymbolForEnumEntry(enumEntry: IrEnumEntrySymbol): IrFieldSymbol = TODO()
|
||||||
|
|
||||||
override fun getOuterThisFieldSymbol(innerClass: IrClass): IrFieldSymbol =
|
override fun getOuterThisFieldSymbol(innerClass: IrClass): IrFieldSymbol =
|
||||||
if (!innerClass.descriptor.isInner) throw AssertionError("Class is not inner: ${innerClass.dump()}")
|
if (!innerClass.isInner) throw AssertionError("Class is not inner: ${innerClass.dump()}")
|
||||||
else outerThisFieldSymbols.getOrPut(innerClass) {
|
else outerThisFieldSymbols.getOrPut(innerClass) {
|
||||||
val outerClass = innerClass.parent as? IrClass
|
val outerClass = innerClass.parent as? IrClass
|
||||||
?: throw AssertionError("No containing class for inner class ${innerClass.dump()}")
|
?: throw AssertionError("No containing class for inner class ${innerClass.dump()}")
|
||||||
@@ -78,7 +78,7 @@ class JsDescriptorsFactory(
|
|||||||
|
|
||||||
override fun getInnerClassConstructorWithOuterThisParameter(innerClassConstructor: IrConstructor): IrConstructorSymbol {
|
override fun getInnerClassConstructorWithOuterThisParameter(innerClassConstructor: IrConstructor): IrConstructorSymbol {
|
||||||
val innerClass = innerClassConstructor.parent as IrClass
|
val innerClass = innerClassConstructor.parent as IrClass
|
||||||
assert(innerClass.descriptor.isInner) { "Class is not inner: $innerClass" }
|
assert(innerClass.isInner) { "Class is not inner: $innerClass" }
|
||||||
|
|
||||||
return innerClassConstructors.getOrPut(innerClassConstructor.symbol) {
|
return innerClassConstructors.getOrPut(innerClassConstructor.symbol) {
|
||||||
createInnerClassConstructorWithOuterThisParameter(innerClassConstructor.descriptor)
|
createInnerClassConstructorWithOuterThisParameter(innerClassConstructor.descriptor)
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ class JvmLower(val context: JvmBackendContext) {
|
|||||||
InnerClassesLowering(context).runOnFilePostfix(irFile)
|
InnerClassesLowering(context).runOnFilePostfix(irFile)
|
||||||
InnerClassConstructorCallsLowering(context).runOnFilePostfix(irFile)
|
InnerClassConstructorCallsLowering(context).runOnFilePostfix(irFile)
|
||||||
|
|
||||||
|
irFile.acceptVoid(PatchDeclarationParentsVisitor())
|
||||||
LocalDeclarationsLowering(
|
LocalDeclarationsLowering(
|
||||||
context,
|
context,
|
||||||
object : LocalNameProvider {
|
object : LocalNameProvider {
|
||||||
@@ -55,7 +56,6 @@ class JvmLower(val context: JvmBackendContext) {
|
|||||||
}
|
}
|
||||||
).runOnFilePostfix(irFile)
|
).runOnFilePostfix(irFile)
|
||||||
|
|
||||||
irFile.acceptVoid(PatchDeclarationParentsVisitor())
|
|
||||||
EnumClassLowering(context).runOnFilePostfix(irFile)
|
EnumClassLowering(context).runOnFilePostfix(irFile)
|
||||||
//Should be before SyntheticAccessorLowering cause of synthetic accessor for companion constructor
|
//Should be before SyntheticAccessorLowering cause of synthetic accessor for companion constructor
|
||||||
ObjectClassLowering(context).lower(irFile)
|
ObjectClassLowering(context).lower(irFile)
|
||||||
|
|||||||
+2
-2
@@ -67,7 +67,7 @@ class JvmDescriptorsFactory(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getOuterThisFieldSymbol(innerClass: IrClass): IrFieldSymbol =
|
override fun getOuterThisFieldSymbol(innerClass: IrClass): IrFieldSymbol =
|
||||||
if (!innerClass.descriptor.isInner) throw AssertionError("Class is not inner: ${innerClass.dump()}")
|
if (!innerClass.isInner) throw AssertionError("Class is not inner: ${innerClass.dump()}")
|
||||||
else outerThisDescriptors.getOrPut(innerClass) {
|
else outerThisDescriptors.getOrPut(innerClass) {
|
||||||
val outerClass = innerClass.parent as? IrClass
|
val outerClass = innerClass.parent as? IrClass
|
||||||
?: throw AssertionError("No containing class for inner class ${innerClass.dump()}")
|
?: throw AssertionError("No containing class for inner class ${innerClass.dump()}")
|
||||||
@@ -81,7 +81,7 @@ class JvmDescriptorsFactory(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun getInnerClassConstructorWithOuterThisParameter(innerClassConstructor: IrConstructor): IrConstructorSymbol {
|
override fun getInnerClassConstructorWithOuterThisParameter(innerClassConstructor: IrConstructor): IrConstructorSymbol {
|
||||||
assert((innerClassConstructor.parent as IrClass).descriptor.isInner) { "Class is not inner: ${(innerClassConstructor.parent as IrClass).dump()}" }
|
assert((innerClassConstructor.parent as IrClass).isInner) { "Class is not inner: ${(innerClassConstructor.parent as IrClass).dump()}" }
|
||||||
|
|
||||||
return innerClassConstructors.getOrPut(innerClassConstructor.symbol) {
|
return innerClassConstructors.getOrPut(innerClassConstructor.symbol) {
|
||||||
createInnerClassConstructorWithOuterThisParameter(innerClassConstructor)
|
createInnerClassConstructorWithOuterThisParameter(innerClassConstructor)
|
||||||
|
|||||||
Reference in New Issue
Block a user