[JS IR BE] Remove support for dynamic symbols and descriptors
Dynamic expressions in IR are now represented as IrDynamicOperatorExpression We don't have dynamic functions, dynamic dispatch receivers anymore
This commit is contained in:
+10
@@ -126,6 +126,12 @@ class CheckIrElementVisitor(
|
||||
override fun visitCall(expression: IrCall) {
|
||||
super.visitCall(expression)
|
||||
|
||||
val function = expression.symbol.owner
|
||||
|
||||
if (function.dispatchReceiverParameter?.type is IrDynamicType) {
|
||||
reportError(expression, "Dispatch receivers with 'dynamic' type are not allowed")
|
||||
}
|
||||
|
||||
val returnType = expression.descriptor.returnType
|
||||
if (returnType == null) {
|
||||
reportError(expression, "${expression.descriptor} return type is null")
|
||||
@@ -232,6 +238,10 @@ class CheckIrElementVisitor(
|
||||
override fun visitFunction(declaration: IrFunction) {
|
||||
super.visitFunction(declaration)
|
||||
|
||||
if (declaration.dispatchReceiverParameter?.type is IrDynamicType) {
|
||||
reportError(declaration, "Dispatch receivers with 'dynamic' type are not allowed")
|
||||
}
|
||||
|
||||
for ((i, p) in declaration.valueParameters.withIndex()) {
|
||||
if (p.index != i) {
|
||||
reportError(declaration, "Inconsistent index of value parameter ${p.index} != $i")
|
||||
|
||||
+1
-3
@@ -188,9 +188,7 @@ class InlineClassLowering(val context: BackendContext) {
|
||||
override fun visitCall(call: IrCall): IrExpression {
|
||||
call.transformChildrenVoid(this)
|
||||
val function = call.symbol.owner
|
||||
if (
|
||||
function.isDynamic() ||
|
||||
function.parent !is IrClass ||
|
||||
if (function.parent !is IrClass ||
|
||||
function.isStaticMethodOfClass ||
|
||||
!function.parentAsClass.isInline ||
|
||||
(function is IrSimpleFunction && !function.isReal) ||
|
||||
|
||||
-1
@@ -20,7 +20,6 @@ class CallsLowering(val context: JsIrBackendContext) : FileLoweringPass {
|
||||
private val transformers = listOf(
|
||||
NumberOperatorCallsTransformer(context),
|
||||
NumberConversionCallsTransformer(context),
|
||||
DynamicCallsTransformer(context),
|
||||
EqualityAndComparisonCallsTransformer(context),
|
||||
PrimitiveContainerMemberCallTransformer(context),
|
||||
MethodsOfAnyCallsTransformer(context),
|
||||
|
||||
-90
@@ -1,90 +0,0 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.ir.backend.js.lower.calls
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.PropertyAccessorDescriptor
|
||||
import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
||||
import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
|
||||
import org.jetbrains.kotlin.ir.util.irCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrCall
|
||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrStatementOrigin.*
|
||||
import org.jetbrains.kotlin.ir.util.isDynamic
|
||||
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
|
||||
|
||||
class DynamicCallsTransformer(private val context: JsIrBackendContext) : CallsTransformer {
|
||||
|
||||
private val originToIrFunction =
|
||||
context.intrinsics.run {
|
||||
mapOf(
|
||||
EXCL to jsNot,
|
||||
LT to jsLt,
|
||||
GT to jsGt,
|
||||
LTEQ to jsLtEq,
|
||||
GTEQ to jsGtEq,
|
||||
EQEQ to jsEqeq,
|
||||
EQEQEQ to jsEqeqeq,
|
||||
EXCLEQ to jsNotEq,
|
||||
EXCLEQEQ to jsNotEqeq,
|
||||
ANDAND to jsAnd,
|
||||
OROR to jsOr,
|
||||
UMINUS to jsUnaryMinus,
|
||||
UPLUS to jsUnaryPlus,
|
||||
PLUS to jsPlus,
|
||||
MINUS to jsMinus,
|
||||
MUL to jsMult,
|
||||
DIV to jsDiv,
|
||||
PERC to jsMod,
|
||||
PLUSEQ to jsPlusAssign,
|
||||
MINUSEQ to jsMinusAssign,
|
||||
MULTEQ to jsMultAssign,
|
||||
DIVEQ to jsDivAssign,
|
||||
PERCEQ to jsModAssign,
|
||||
PREFIX_INCR to jsPrefixInc,
|
||||
PREFIX_DECR to jsPrefixDec,
|
||||
POSTFIX_INCR to jsPostfixInc,
|
||||
POSTFIX_DECR to jsPostfixDec,
|
||||
GET_ARRAY_ELEMENT to jsArrayGet,
|
||||
// TODO add a special statement origin, e.g. SET_ARRAY_ELEMENT
|
||||
EQ to jsArraySet
|
||||
)
|
||||
}
|
||||
|
||||
override fun transformCall(call: IrCall): IrExpression {
|
||||
val symbol = call.symbol
|
||||
val function = call.symbol.owner
|
||||
|
||||
if (function.isDynamic()) {
|
||||
when (call.origin) {
|
||||
GET_PROPERTY -> {
|
||||
val fieldSymbol = context.symbolTable.lazyWrapper.referenceField(
|
||||
(symbol.descriptor as PropertyAccessorDescriptor).correspondingProperty
|
||||
)
|
||||
return JsIrBuilder.buildGetField(fieldSymbol, call.dispatchReceiver, type = call.type)
|
||||
}
|
||||
|
||||
// assignment to a property
|
||||
EQ -> {
|
||||
if (symbol.descriptor is PropertyAccessorDescriptor) {
|
||||
val fieldSymbol = context.symbolTable.lazyWrapper.referenceField(
|
||||
(symbol.descriptor as PropertyAccessorDescriptor).correspondingProperty
|
||||
)
|
||||
return call.run {
|
||||
JsIrBuilder.buildSetField(fieldSymbol, dispatchReceiver, getValueArgument(0)!!, type)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (function.isDynamic()) {
|
||||
originToIrFunction[call.origin]?.let {
|
||||
return irCall(call, it.symbol, dispatchReceiverAsFirstArgument = true)
|
||||
}
|
||||
}
|
||||
return call
|
||||
}
|
||||
}
|
||||
+1
-27
@@ -13,15 +13,12 @@ import org.jetbrains.kotlin.ir.expressions.IrLoop
|
||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.classifierOrFail
|
||||
import org.jetbrains.kotlin.ir.util.isDynamic
|
||||
import org.jetbrains.kotlin.ir.util.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.ir.util.isInlined
|
||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||
import org.jetbrains.kotlin.js.backend.ast.JsName
|
||||
import org.jetbrains.kotlin.js.naming.isES5IdentifierPart
|
||||
import org.jetbrains.kotlin.js.naming.isES5IdentifierStart
|
||||
import org.jetbrains.kotlin.resolve.calls.tasks.isDynamic
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassDescriptor
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.ifNotEmpty
|
||||
|
||||
@@ -32,8 +29,7 @@ class SimpleNameGenerator : NameGenerator {
|
||||
private val loopCache = mutableMapOf<IrLoop, JsName>()
|
||||
|
||||
override fun getNameForSymbol(symbol: IrSymbol, context: JsGenerationContext): JsName =
|
||||
if (symbol.isBound) getNameForDeclaration(symbol.owner as IrDeclarationWithName, context) else
|
||||
declareDynamic(symbol.descriptor, context)
|
||||
getNameForDeclaration(symbol.owner as IrDeclarationWithName, context)
|
||||
|
||||
override fun getNameForLoop(loop: IrLoop, context: JsGenerationContext): JsName? = loop.label?.let {
|
||||
loopCache.getOrPut(loop) { context.currentScope.declareFreshName(sanitizeName(loop.label!!)) }
|
||||
@@ -42,24 +38,6 @@ class SimpleNameGenerator : NameGenerator {
|
||||
override fun getNameForType(type: IrType, context: JsGenerationContext) =
|
||||
getNameForDeclaration(type.classifierOrFail.owner as IrDeclarationWithName, context)
|
||||
|
||||
@Deprecated("Descriptors-based code is deprecated")
|
||||
private fun declareDynamic(descriptor: DeclarationDescriptor, context: JsGenerationContext): JsName {
|
||||
if (descriptor.isDynamic()) {
|
||||
return context.currentScope.declareName(descriptor.name.asString())
|
||||
}
|
||||
|
||||
if (descriptor is MemberDescriptor && descriptor.isEffectivelyExternal()) {
|
||||
val descriptorForName = when (descriptor) {
|
||||
is ConstructorDescriptor -> descriptor.constructedClass
|
||||
is PropertyAccessorDescriptor -> descriptor.correspondingProperty
|
||||
else -> descriptor
|
||||
}
|
||||
return context.currentScope.declareName(descriptorForName.name.asString())
|
||||
}
|
||||
|
||||
throw IllegalStateException("Unbound non-dynamic symbol")
|
||||
}
|
||||
|
||||
private val RESERVED_IDENTIFIERS = setOf(
|
||||
// keywords
|
||||
"await", "break", "case", "catch", "continue", "debugger", "default", "delete", "do", "else", "finally", "for", "function", "if",
|
||||
@@ -96,10 +74,6 @@ class SimpleNameGenerator : NameGenerator {
|
||||
var nameDeclarator: (String) -> JsName = context.currentScope::declareName
|
||||
val nameBuilder = StringBuilder()
|
||||
|
||||
if (declaration.isDynamic()) {
|
||||
return@getOrPut nameDeclarator(declaration.descriptor.name.asString())
|
||||
}
|
||||
|
||||
val declarationName = declaration.getJsNameOrKotlinName().asString()
|
||||
|
||||
if (declaration is IrSimpleFunction && declaration.origin == JsLoweredDeclarationOrigin.BRIDGE_TO_EXTERNAL_FUNCTION) {
|
||||
|
||||
@@ -424,8 +424,6 @@ fun IrDeclaration.isEffectivelyExternal(): Boolean {
|
||||
}
|
||||
}
|
||||
|
||||
fun IrDeclaration.isDynamic() = this is IrFunction && dispatchReceiverParameter?.type is IrDynamicType
|
||||
|
||||
inline fun <reified T : IrDeclaration> IrDeclarationContainer.findDeclaration(predicate: (T) -> Boolean): T? =
|
||||
declarations.find { it is T && predicate(it) } as? T
|
||||
|
||||
|
||||
Reference in New Issue
Block a user