[JS IR] A bunch of fixes to make PIR mode work
- provide required mappings - fix fake overrides - fix local declaration lowering - fix DCE
This commit is contained in:
@@ -15,6 +15,9 @@ interface Mapping {
|
||||
val suspendFunctionToCoroutineConstructor: Delegate<IrFunction, IrConstructor>
|
||||
val lateInitFieldToNullableField: Delegate<IrField, IrField>
|
||||
val inlineClassMemberToStatic: Delegate<IrFunction, IrSimpleFunction>
|
||||
val capturedFields: Delegate<IrClass, Collection<IrField>>
|
||||
val capturedConstructors: Delegate<IrConstructor, IrConstructor>
|
||||
val reflectedNameAccessor: Delegate<IrClass, IrSimpleFunction>
|
||||
|
||||
abstract class Delegate<K : IrDeclaration, V> {
|
||||
abstract operator fun get(key: K): V?
|
||||
@@ -36,6 +39,9 @@ open class DefaultMapping : Mapping {
|
||||
override val suspendFunctionToCoroutineConstructor: Mapping.Delegate<IrFunction, IrConstructor> = newMapping()
|
||||
override val lateInitFieldToNullableField: Mapping.Delegate<IrField, IrField> = newMapping()
|
||||
override val inlineClassMemberToStatic: Mapping.Delegate<IrFunction, IrSimpleFunction> = newMapping()
|
||||
override val capturedFields: Mapping.Delegate<IrClass, Collection<IrField>> = newMapping()
|
||||
override val capturedConstructors: Mapping.Delegate<IrConstructor, IrConstructor> = newMapping()
|
||||
override val reflectedNameAccessor: Mapping.Delegate<IrClass, IrSimpleFunction> = newMapping()
|
||||
|
||||
protected open fun <K : IrDeclaration, V> newMapping() = object : Mapping.Delegate<K, V>() {
|
||||
private val map: MutableMap<K, V> = mutableMapOf()
|
||||
|
||||
@@ -33,9 +33,7 @@ import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.*
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeBuilder
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.buildSimpleType
|
||||
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
@@ -479,14 +477,14 @@ val IrFunction.allParameters: List<IrValueParameter>
|
||||
explicitParameters
|
||||
}
|
||||
|
||||
fun IrClass.addFakeOverrides() {
|
||||
fun IrClass.addFakeOverrides(implementedMembers: List<IrSimpleFunction> = emptyList()) {
|
||||
fun IrDeclaration.toList() = when (this) {
|
||||
is IrSimpleFunction -> listOf(this)
|
||||
is IrProperty -> listOfNotNull(getter, setter)
|
||||
else -> emptyList()
|
||||
}
|
||||
|
||||
val overriddenFunctions = declarations
|
||||
val overriddenFunctions = (declarations + implementedMembers)
|
||||
.flatMap { it.toList() }
|
||||
.flatMap { it.overriddenSymbols.map { it.owner } }
|
||||
.toSet()
|
||||
|
||||
-3
@@ -37,9 +37,6 @@ class ClosureAnnotator(body: IrBody, declaration: IrDeclaration) {
|
||||
|
||||
init {
|
||||
// Collect all closures for classes and functions. Collect call graph
|
||||
if (declaration is IrSimpleFunction && declaration.name.asString() == "arrayIterator") {
|
||||
1
|
||||
}
|
||||
body.accept(ClosureCollectorVisitor(), declaration.closureBuilderOrNull ?: declaration.parentClosureBuilder)
|
||||
}
|
||||
|
||||
|
||||
+18
-1
@@ -7,10 +7,14 @@ package org.jetbrains.kotlin.backend.common.lower
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.*
|
||||
import org.jetbrains.kotlin.backend.common.ir.addChild
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCompositeImpl
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
|
||||
//This lower takes part of old LocalDeclarationLowering job to pop up local classes from functions
|
||||
open class LocalClassPopupLowering(val context: BackendContext) : BodyLoweringPass {
|
||||
@@ -44,7 +48,20 @@ open class LocalClassPopupLowering(val context: BackendContext) : BodyLoweringPa
|
||||
|
||||
for ((local, newContainer) in extractedLocalClasses) {
|
||||
newContainer.addChild(local)
|
||||
context.extractedLocalClasses += local
|
||||
|
||||
local.acceptVoid(object : IrElementVisitorVoid {
|
||||
override fun visitElement(element: IrElement) {
|
||||
element.acceptChildrenVoid(this)
|
||||
}
|
||||
|
||||
override fun visitBody(body: IrBody) {
|
||||
}
|
||||
|
||||
override fun visitClass(declaration: IrClass) {
|
||||
super.visitClass(declaration)
|
||||
context.extractedLocalClasses += declaration
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+5
-1
@@ -90,7 +90,7 @@ object BOUND_RECEIVER_PARAMETER : IrDeclarationOriginImpl("BOUND_RECEIVER_PARAME
|
||||
to proceed nevertheless.
|
||||
*/
|
||||
class LocalDeclarationsLowering(
|
||||
val context: BackendContext,
|
||||
val context: CommonBackendContext,
|
||||
val localNameProvider: LocalNameProvider = LocalNameProvider.DEFAULT,
|
||||
val visibilityPolicy: VisibilityPolicy = VisibilityPolicy.DEFAULT
|
||||
) :
|
||||
@@ -463,6 +463,9 @@ class LocalDeclarationsLowering(
|
||||
|
||||
irClass.declarations += localClassContext.capturedValueToField.values
|
||||
|
||||
context.mapping.capturedFields[irClass] =
|
||||
(context.mapping.capturedFields[irClass] ?: emptyList()) + localClassContext.capturedValueToField.values
|
||||
|
||||
for (constructorContext in constructorsCallingSuper) {
|
||||
val blockBody = constructorContext.declaration.body as? IrBlockBody
|
||||
?: throw AssertionError("Unexpected constructor body: ${constructorContext.declaration.body}")
|
||||
@@ -733,6 +736,7 @@ class LocalDeclarationsLowering(
|
||||
newDeclaration.metadata = oldDeclaration.metadata
|
||||
|
||||
transformedDeclarations[oldDeclaration] = newDeclaration
|
||||
context.mapping.capturedConstructors[oldDeclaration] = newDeclaration
|
||||
}
|
||||
|
||||
private fun createFieldForCapturedValue(
|
||||
|
||||
Reference in New Issue
Block a user