FIR2IR: cache constructors and their parents properly
This commit is contained in:
+23
-9
@@ -611,16 +611,17 @@ class Fir2IrDeclarationStorage(
|
|||||||
} ?: createIrFunction(function, irParent, shouldLeaveScope, origin)
|
} ?: createIrFunction(function, irParent, shouldLeaveScope, origin)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getIrConstructor(
|
private fun getCachedIrConstructor(
|
||||||
|
constructor: FirConstructor
|
||||||
|
): IrConstructor? {
|
||||||
|
return constructorCache[constructor]
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun createIrConstructor(
|
||||||
constructor: FirConstructor,
|
constructor: FirConstructor,
|
||||||
irParent: IrDeclarationParent? = null,
|
irParent: IrDeclarationParent,
|
||||||
shouldLeaveScope: Boolean = true
|
shouldLeaveScope: Boolean = true
|
||||||
): IrConstructor {
|
): IrConstructor {
|
||||||
val cached = constructorCache[constructor]
|
|
||||||
if (cached != null) {
|
|
||||||
return if (shouldLeaveScope) cached else cached.enterLocalScope(constructor)
|
|
||||||
}
|
|
||||||
|
|
||||||
val descriptor = WrappedClassConstructorDescriptor()
|
val descriptor = WrappedClassConstructorDescriptor()
|
||||||
val origin = IrDeclarationOrigin.DEFINED
|
val origin = IrDeclarationOrigin.DEFINED
|
||||||
val isPrimary = constructor.isPrimary
|
val isPrimary = constructor.isPrimary
|
||||||
@@ -648,6 +649,18 @@ class Fir2IrDeclarationStorage(
|
|||||||
return created
|
return created
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getIrConstructor(
|
||||||
|
constructor: FirConstructor,
|
||||||
|
irParent: IrDeclarationParent,
|
||||||
|
shouldLeaveScope: Boolean = true
|
||||||
|
): IrConstructor {
|
||||||
|
val cached = getCachedIrConstructor(constructor)
|
||||||
|
if (cached != null) {
|
||||||
|
return if (shouldLeaveScope) cached else cached.enterLocalScope(constructor)
|
||||||
|
}
|
||||||
|
return createIrConstructor(constructor, irParent, shouldLeaveScope)
|
||||||
|
}
|
||||||
|
|
||||||
private fun createIrPropertyAccessor(
|
private fun createIrPropertyAccessor(
|
||||||
propertyAccessor: FirPropertyAccessor?,
|
propertyAccessor: FirPropertyAccessor?,
|
||||||
property: FirProperty,
|
property: FirProperty,
|
||||||
@@ -969,8 +982,9 @@ class Fir2IrDeclarationStorage(
|
|||||||
irSymbolTable.referenceSimpleFunction(irDeclaration.descriptor)
|
irSymbolTable.referenceSimpleFunction(irDeclaration.descriptor)
|
||||||
}
|
}
|
||||||
is FirConstructor -> {
|
is FirConstructor -> {
|
||||||
val irParent = findIrParent(firDeclaration)
|
getCachedIrConstructor(firDeclaration)?.let { return irSymbolTable.referenceConstructor(it.descriptor) }
|
||||||
val irDeclaration = getIrConstructor(firDeclaration, irParent).apply {
|
val irParent = findIrParent(firDeclaration)!!
|
||||||
|
val irDeclaration = createIrConstructor(firDeclaration, irParent).apply {
|
||||||
setAndModifyParent(irParent)
|
setAndModifyParent(irParent)
|
||||||
}
|
}
|
||||||
irSymbolTable.referenceConstructor(irDeclaration.descriptor)
|
irSymbolTable.referenceConstructor(irDeclaration.descriptor)
|
||||||
|
|||||||
@@ -234,7 +234,7 @@ class Fir2IrVisitor(
|
|||||||
|
|
||||||
override fun visitConstructor(constructor: FirConstructor, data: Any?): IrElement {
|
override fun visitConstructor(constructor: FirConstructor, data: Any?): IrElement {
|
||||||
val irConstructor = declarationStorage.getIrConstructor(
|
val irConstructor = declarationStorage.getIrConstructor(
|
||||||
constructor, irParent = conversionScope.lastClass(), shouldLeaveScope = false
|
constructor, irParent = conversionScope.lastClass()!!, shouldLeaveScope = false
|
||||||
)
|
)
|
||||||
return conversionScope.withFunction(irConstructor) {
|
return conversionScope.withFunction(irConstructor) {
|
||||||
setFunctionContent(irConstructor.descriptor, constructor)
|
setFunctionContent(irConstructor.descriptor, constructor)
|
||||||
|
|||||||
Reference in New Issue
Block a user