JS IR: special origins for declaration created during lowerings

Otherwise the lazy properties lowering may try to process them
This commit is contained in:
Anton Bannykh
2021-02-05 17:46:01 +03:00
parent aec498a4ea
commit df62b5e311
4 changed files with 14 additions and 5 deletions
@@ -204,6 +204,7 @@ class InteropCallableReferenceLowering(val context: JsIrBackendContext) : BodyLo
visibility = lambdaClass.visibility
returnType = expression.type
name = factoryName
origin = FACTORY_ORIGIN
}
factoryDeclaration.parent = implicitDeclarationFile
@@ -231,5 +232,6 @@ class InteropCallableReferenceLowering(val context: JsIrBackendContext) : BodyLo
companion object {
object EXPLICIT_INVOKE : IrStatementOriginImpl("EXPLICIT_INVOKE")
object FACTORY_ORIGIN : IrDeclarationOriginImpl("FACTORY_ORIGIN")
}
}
@@ -163,6 +163,7 @@ private class JsCodeOutlineTransformer(
name = Name.identifier("outlinedJsCode$")
visibility = DescriptorVisibilities.LOCAL
returnType = backendContext.dynamicType
origin = OUTLINED_ORIGIN
}
// We don't need this function's body. Using empty block body stub, because some code might expect all functions to have bodies.
outlinedFunction.body = backendContext.irFactory.createBlockBody(UNDEFINED_OFFSET, UNDEFINED_OFFSET)
@@ -215,4 +216,8 @@ private class JsCodeOutlineTransformer(
}
}
}
companion object {
object OUTLINED_ORIGIN : IrDeclarationOriginImpl("OUTLINED_ORIGIN")
}
}
@@ -282,7 +282,7 @@ private fun IrDeclaration.isCompatibleDeclaration() =
origin in compatibleOrigins
private fun IrDeclaration.assertCompatibleDeclaration() {
assert((this as? PersistentIrElementBase<*>)?.createdOn?.let { it == 0 } != false)
assert(this !is PersistentIrElementBase<*> || createdOn == 0)
}
private val compatibleOrigins = listOf(
@@ -12,10 +12,7 @@ import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
import org.jetbrains.kotlin.ir.builders.*
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
import org.jetbrains.kotlin.ir.builders.declarations.buildValueParameter
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
@@ -63,6 +60,7 @@ class PropertyReferenceLowering(private val context: JsIrBackendContext) : BodyL
endOffset = reference.endOffset
returnType = reference.type
name = Name.identifier("${property.name.asString()}\$factory")
origin = PROPERTY_REFERENCE_FACTORY
}
val boundArguments = listOfNotNull(reference.dispatchReceiver, reference.extensionReceiver)
@@ -259,4 +257,8 @@ class PropertyReferenceLowering(private val context: JsIrBackendContext) : BodyL
}
}
}
companion object {
object PROPERTY_REFERENCE_FACTORY : IrDeclarationOriginImpl("PROPERTY_REFERNCE_FACTORY")
}
}