Make descriptor-based API in ir:tree more granular
This commit is contained in:
+2
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.backend.common
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.DescriptorBasedIr
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
@@ -30,6 +31,7 @@ import java.util.*
|
||||
|
||||
class Closure(val capturedValues: List<ValueDescriptor>)
|
||||
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
abstract class AbstractClosureAnnotator : IrElementVisitorVoid {
|
||||
protected abstract fun recordFunctionClosure(functionDescriptor: FunctionDescriptor, closure: Closure)
|
||||
protected abstract fun recordClassClosure(classDescriptor: ClassDescriptor, closure: Closure)
|
||||
|
||||
+2
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.backend.common
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.VariableDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||
import org.jetbrains.kotlin.ir.DescriptorBasedIr
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrVariable
|
||||
import org.jetbrains.kotlin.ir.descriptors.WrappedVariableDescriptor
|
||||
@@ -29,6 +30,7 @@ import org.jetbrains.kotlin.ir.util.DescriptorsRemapper
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
fun <T : IrElement> T.deepCopyWithVariables(): T {
|
||||
val descriptorsRemapper = object : DescriptorsRemapper {
|
||||
override fun remapDeclaredVariable(descriptor: VariableDescriptor) = WrappedVariableDescriptor()
|
||||
|
||||
+2
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.backend.common
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.DescriptorBasedIr
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.descriptors.*
|
||||
@@ -50,6 +51,7 @@ object DescriptorsToIrRemapper : DescriptorsRemapper {
|
||||
WrappedValueParameterDescriptor(descriptor.annotations, descriptor.source)
|
||||
}
|
||||
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
object WrappedDescriptorPatcher : IrElementVisitorVoid {
|
||||
override fun visitElement(element: IrElement) {
|
||||
element.acceptChildrenVoid(this)
|
||||
|
||||
+4
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common
|
||||
|
||||
import org.jetbrains.kotlin.ir.DescriptorBasedIr
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.builders.Scope
|
||||
@@ -101,6 +102,7 @@ abstract class IrElementTransformerVoidWithContext : IrElementTransformerVoid()
|
||||
protected val allScopes get() = scopeStack
|
||||
protected val currentDeclarationParent get() = scopeStack.lastOrNull { it.irElement is IrDeclarationParent }?.irElement as? IrDeclarationParent
|
||||
|
||||
@DescriptorBasedIr
|
||||
fun printScopeStack() {
|
||||
scopeStack.forEach { println(it.scope.scopeOwner) }
|
||||
}
|
||||
@@ -138,6 +140,7 @@ abstract class IrElementTransformerVoidWithContext : IrElementTransformerVoid()
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
abstract class IrElementVisitorVoidWithContext : IrElementVisitorVoid {
|
||||
|
||||
private val scopeStack = mutableListOf<ScopeWithIr>()
|
||||
@@ -198,6 +201,7 @@ abstract class IrElementVisitorVoidWithContext : IrElementVisitorVoid {
|
||||
protected val parentScope get() = if (scopeStack.size < 2) null else scopeStack[scopeStack.size - 2]
|
||||
protected val allScopes get() = scopeStack
|
||||
|
||||
@DescriptorBasedIr
|
||||
fun printScopeStack() {
|
||||
scopeStack.forEach { println(it.scope.scopeOwner) }
|
||||
}
|
||||
|
||||
+2
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common
|
||||
|
||||
import org.jetbrains.kotlin.ir.DescriptorBasedIr
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
@@ -34,6 +35,7 @@ import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
* It is also not guaranteed that each returned call is detected as tail recursion by the frontend.
|
||||
* However any returned call can be correctly optimized as tail recursion.
|
||||
*/
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
fun collectTailRecursionCalls(irFunction: IrFunction): Set<IrCall> {
|
||||
if ((irFunction as? IrSimpleFunction)?.isTailrec != true) {
|
||||
return emptySet()
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.ClassDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.findClassAcrossModuleDependencies
|
||||
import org.jetbrains.kotlin.incremental.components.NoLookupLocation
|
||||
import org.jetbrains.kotlin.ir.DescriptorBasedIr
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.declarations.IrPackageFragment
|
||||
@@ -109,6 +110,8 @@ open class BuiltinSymbolsBase(protected val irBuiltIns: IrBuiltIns, protected va
|
||||
val intProgression = progression("IntProgression")
|
||||
val longProgression = progression("LongProgression")
|
||||
val progressionClasses = listOfNotNull(charProgression, intProgression, longProgression, uIntProgression, uLongProgression)
|
||||
|
||||
@DescriptorBasedIr
|
||||
val progressionClassesTypes = progressionClasses.map { it.descriptor.defaultType }.toSet()
|
||||
|
||||
val getProgressionLastElementByReturnType = builtInsPackage("kotlin", "internal")
|
||||
@@ -143,6 +146,8 @@ open class BuiltinSymbolsBase(protected val irBuiltIns: IrBuiltIns, protected va
|
||||
val long = symbolTable.referenceClass(builtIns.long)
|
||||
|
||||
val integerClasses = listOf(byte, short, int, long)
|
||||
|
||||
@DescriptorBasedIr
|
||||
val integerClassesTypes = integerClasses.map { it.descriptor.defaultType }
|
||||
|
||||
val arrayOf = getSimpleFunction(Name.identifier("arrayOf")) {
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.backend.common.ir
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.lower.VariableRemapper
|
||||
import org.jetbrains.kotlin.ir.DescriptorBasedIr
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.expressions.*
|
||||
@@ -86,6 +87,7 @@ private fun IrBody.move(
|
||||
|
||||
// TODO use a generic inliner (e.g. JS/Native's FunctionInlining.Inliner)
|
||||
// Inline simple function calls without type parameters, default parameters, or varargs.
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
fun IrFunction.inline(target: IrDeclarationParent, arguments: List<IrValueDeclaration> = listOf()): IrReturnableBlock =
|
||||
IrReturnableBlockImpl(startOffset, endOffset, returnType, IrReturnableBlockSymbolImpl(descriptor), null, symbol).apply {
|
||||
statements += body!!.move(this@inline, target, symbol, valueParameters.zip(arguments).toMap()).statements
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||
import org.jetbrains.kotlin.ir.DescriptorBasedIr
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.Scope
|
||||
@@ -130,6 +131,7 @@ fun IrCall.getAnnotationClass(): IrClass {
|
||||
|
||||
val IrTypeParametersContainer.classIfConstructor get() = if (this is IrConstructor) parentAsClass else this
|
||||
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
fun IrValueParameter.copyTo(
|
||||
irFunction: IrFunction,
|
||||
origin: IrDeclarationOrigin = this.origin,
|
||||
@@ -172,6 +174,7 @@ fun IrValueParameter.copyTo(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
fun IrTypeParameter.copyToWithoutSuperTypes(
|
||||
target: IrTypeParametersContainer,
|
||||
index: Int = this.index,
|
||||
@@ -185,6 +188,7 @@ fun IrTypeParameter.copyToWithoutSuperTypes(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
fun IrFunction.copyReceiverParametersFrom(from: IrFunction) {
|
||||
dispatchReceiverParameter = from.dispatchReceiverParameter?.let {
|
||||
IrValueParameterImpl(it.startOffset, it.endOffset, it.origin, it.descriptor, it.type, it.varargElementType).also {
|
||||
@@ -457,6 +461,7 @@ fun IrClass.createParameterDeclarations() {
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
fun IrFunction.createDispatchReceiverParameter(origin: IrDeclarationOrigin? = null) {
|
||||
assert(dispatchReceiverParameter == null)
|
||||
|
||||
@@ -479,7 +484,7 @@ val IrFunction.allParameters: List<IrValueParameter>
|
||||
get() = if (this is IrConstructor) {
|
||||
listOf(
|
||||
this.constructedClass.thisReceiver
|
||||
?: error(this.descriptor)
|
||||
?: error(this.render())
|
||||
) + explicitParameters
|
||||
} else {
|
||||
explicitParameters
|
||||
@@ -548,6 +553,7 @@ fun IrClass.addFakeOverridesViaIncorrectHeuristic(implementedMembers: List<IrSim
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
fun createStaticFunctionWithReceivers(
|
||||
irParent: IrDeclarationParent,
|
||||
name: Name,
|
||||
|
||||
+2
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.backend.common.ir.*
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.ir.DescriptorBasedIr
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
@@ -38,6 +39,7 @@ import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
@DescriptorBasedIr
|
||||
abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val context: C) : FileLoweringPass {
|
||||
|
||||
protected object STATEMENT_ORIGIN_COROUTINE_IMPL : IrStatementOriginImpl("COROUTINE_IMPL")
|
||||
|
||||
+19
-3
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.backend.common.ir.*
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.ir.DescriptorBasedIr
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.builders.declarations.addValueParameter
|
||||
@@ -282,7 +283,11 @@ open class DefaultParameterInjector(
|
||||
expression.transformChildrenVoid()
|
||||
return visitFunctionAccessExpression(expression) {
|
||||
with(expression) {
|
||||
IrDelegatingConstructorCallImpl(startOffset, endOffset, type, it as IrConstructorSymbol, typeArgumentsCount)
|
||||
IrDelegatingConstructorCallImpl(
|
||||
startOffset, endOffset, type, it as IrConstructorSymbol,
|
||||
typeArgumentsCount = typeArgumentsCount,
|
||||
valueArgumentsCount = it.owner.valueParameters.size
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -300,7 +305,11 @@ open class DefaultParameterInjector(
|
||||
expression.transformChildrenVoid()
|
||||
return visitFunctionAccessExpression(expression) {
|
||||
with(expression) {
|
||||
IrEnumConstructorCallImpl(startOffset, endOffset, type, it as IrConstructorSymbol)
|
||||
IrEnumConstructorCallImpl(
|
||||
startOffset, endOffset, type, it as IrConstructorSymbol,
|
||||
typeArgumentsCount = typeArgumentsCount,
|
||||
valueArgumentsCount = it.owner.valueParameters.size
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -309,7 +318,13 @@ open class DefaultParameterInjector(
|
||||
expression.transformChildrenVoid()
|
||||
return visitFunctionAccessExpression(expression) {
|
||||
with(expression) {
|
||||
IrCallImpl(startOffset, endOffset, type, it, typeArgumentsCount, DEFAULT_DISPATCH_CALL, superQualifierSymbol)
|
||||
IrCallImpl(
|
||||
startOffset, endOffset, type, it,
|
||||
typeArgumentsCount = typeArgumentsCount,
|
||||
valueArgumentsCount = it.owner.valueParameters.size,
|
||||
origin = DEFAULT_DISPATCH_CALL,
|
||||
superQualifierSymbol = superQualifierSymbol
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -480,6 +495,7 @@ private fun IrFunction.generateDefaultsFunction(
|
||||
return null
|
||||
}
|
||||
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
private fun IrFunction.generateDefaultsFunctionImpl(
|
||||
context: CommonBackendContext,
|
||||
newOrigin: IrDeclarationOrigin,
|
||||
|
||||
+6
-1
@@ -102,7 +102,12 @@ open class EnumWhenLowering(protected val context: CommonBackendContext) : IrEle
|
||||
else -> return super.visitCall(expression)
|
||||
}
|
||||
val subjectOrdinal = topmostOrdinalProvider.value
|
||||
return IrCallImpl(expression.startOffset, expression.endOffset, expression.type, expression.symbol).apply {
|
||||
return IrCallImpl(
|
||||
expression.startOffset, expression.endOffset,
|
||||
expression.type, expression.symbol,
|
||||
typeArgumentsCount = 0,
|
||||
valueArgumentsCount = 2
|
||||
).apply {
|
||||
putValueArgument(0, IrGetValueImpl(lhs.startOffset, lhs.endOffset, subjectOrdinal.type, subjectOrdinal.symbol))
|
||||
putValueArgument(1, IrConstImpl.int(rhs.startOffset, rhs.endOffset, context.irBuiltIns.intType, entryOrdinal))
|
||||
}
|
||||
|
||||
+7
-6
@@ -17,13 +17,11 @@ import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
|
||||
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
||||
import org.jetbrains.kotlin.ir.types.classOrNull
|
||||
import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols
|
||||
import org.jetbrains.kotlin.ir.util.dump
|
||||
import org.jetbrains.kotlin.ir.util.parentAsClass
|
||||
import org.jetbrains.kotlin.ir.util.patchDeclarationParents
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformerVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.cast
|
||||
|
||||
class InnerClassesLowering(val context: BackendContext) : DeclarationTransformer {
|
||||
|
||||
@@ -225,7 +223,9 @@ class InnerClassConstructorCallsLowering(val context: BackendContext) : BodyLowe
|
||||
|
||||
val newCallee = context.declarationFactory.getInnerClassConstructorWithOuterThisParameter(classConstructor)
|
||||
val newCall = IrDelegatingConstructorCallImpl(
|
||||
expression.startOffset, expression.endOffset, context.irBuiltIns.unitType, newCallee.symbol, expression.typeArgumentsCount
|
||||
expression.startOffset, expression.endOffset, context.irBuiltIns.unitType, newCallee.symbol,
|
||||
typeArgumentsCount = expression.typeArgumentsCount,
|
||||
valueArgumentsCount = newCallee.valueParameters.size
|
||||
).apply { copyTypeArgumentsFrom(expression) }
|
||||
|
||||
newCall.putValueArgument(0, dispatchReceiver)
|
||||
@@ -258,9 +258,10 @@ class InnerClassConstructorCallsLowering(val context: BackendContext) : BodyLowe
|
||||
endOffset,
|
||||
type,
|
||||
newCallee.symbol,
|
||||
typeArgumentsCount,
|
||||
newReflectionTarget?.symbol,
|
||||
origin
|
||||
typeArgumentsCount = typeArgumentsCount,
|
||||
valueArgumentsCount = newCallee.valueParameters.size,
|
||||
reflectionTarget = newReflectionTarget?.symbol,
|
||||
origin = origin
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
+12
-8
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.ReceiverParameterDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.ir.DescriptorBasedIr
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
@@ -47,7 +48,6 @@ import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import java.util.*
|
||||
|
||||
interface LocalNameProvider {
|
||||
@@ -229,6 +229,7 @@ class LocalDeclarationsLowering(
|
||||
abbreviation.annotations
|
||||
)
|
||||
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
private inner class LocalDeclarationsTransformer(
|
||||
val irElement: IrElement, val container: IrDeclaration, val classesToLower: Set<IrClass>?
|
||||
) {
|
||||
@@ -358,7 +359,8 @@ class LocalDeclarationsLowering(
|
||||
expression.startOffset, expression.endOffset,
|
||||
context.irBuiltIns.unitType,
|
||||
newCallee.symbol,
|
||||
expression.typeArgumentsCount
|
||||
typeArgumentsCount = expression.typeArgumentsCount,
|
||||
valueArgumentsCount = newCallee.valueParameters.size
|
||||
).also {
|
||||
it.fillArguments2(expression, newCallee)
|
||||
it.copyTypeArgumentsFrom(expression)
|
||||
@@ -416,9 +418,10 @@ class LocalDeclarationsLowering(
|
||||
expression.startOffset, expression.endOffset,
|
||||
expression.type, // TODO functional type for transformed descriptor
|
||||
newCallee.symbol,
|
||||
newCallee.typeParameters.size,
|
||||
newReflectionTarget?.symbol,
|
||||
expression.origin
|
||||
typeArgumentsCount = newCallee.typeParameters.size,
|
||||
valueArgumentsCount = newCallee.valueParameters.size,
|
||||
reflectionTarget = newReflectionTarget?.symbol,
|
||||
origin = expression.origin
|
||||
).also {
|
||||
it.fillArguments2(expression, newCallee)
|
||||
it.setLocalTypeArguments(oldCallee)
|
||||
@@ -519,9 +522,10 @@ class LocalDeclarationsLowering(
|
||||
oldCall.startOffset, oldCall.endOffset,
|
||||
newCallee.returnType,
|
||||
newCallee.symbol,
|
||||
newCallee.typeParameters.size,
|
||||
oldCall.origin,
|
||||
oldCall.superQualifierSymbol
|
||||
typeArgumentsCount = newCallee.typeParameters.size,
|
||||
valueArgumentsCount = newCallee.valueParameters.size,
|
||||
origin = oldCall.origin,
|
||||
superQualifierSymbol = oldCall.superQualifierSymbol
|
||||
).also {
|
||||
it.setLocalTypeArguments(oldCall.symbol.owner)
|
||||
it.copyTypeArgumentsFrom(oldCall, shift = newCallee.typeParameters.size - oldCall.typeArgumentsCount)
|
||||
|
||||
@@ -19,6 +19,7 @@ package org.jetbrains.kotlin.backend.common.lower
|
||||
import org.jetbrains.kotlin.backend.common.BackendContext
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl
|
||||
import org.jetbrains.kotlin.ir.DescriptorBasedIr
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
@@ -63,6 +64,7 @@ open class VariableRemapper(val mapping: Map<IrValueParameter, IrValueDeclaratio
|
||||
mapping[value]
|
||||
}
|
||||
|
||||
@DescriptorBasedIr
|
||||
class VariableRemapperDesc(val mapping: Map<ValueDescriptor, IrValueParameter>) : AbstractVariableRemapper() {
|
||||
override fun remapVariable(value: IrValueDeclaration): IrValueDeclaration? =
|
||||
mapping[value.descriptor]
|
||||
@@ -158,6 +160,7 @@ open class IrBuildingTransformer(private val context: BackendContext) : IrElemen
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
fun IrConstructor.callsSuper(irBuiltIns: IrBuiltIns): Boolean {
|
||||
val constructedClass = parent as IrClass
|
||||
val superClass = constructedClass.superTypes
|
||||
|
||||
+1
@@ -42,6 +42,7 @@ class ProvisionalFunctionExpressionLowering :
|
||||
startOffset, endOffset, type,
|
||||
function.symbol,
|
||||
typeArgumentsCount = 0,
|
||||
valueArgumentsCount = function.valueParameters.size,
|
||||
reflectionTarget = null,
|
||||
origin = origin
|
||||
)
|
||||
|
||||
+4
-5
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.backend.common.ir.Symbols
|
||||
import org.jetbrains.kotlin.backend.common.ir.createTemporaryVariableWithWrappedDescriptor
|
||||
import org.jetbrains.kotlin.backend.common.lower.createIrBuilder
|
||||
import org.jetbrains.kotlin.config.languageVersionSettings
|
||||
import org.jetbrains.kotlin.ir.DescriptorBasedIr
|
||||
import org.jetbrains.kotlin.ir.IrElement
|
||||
import org.jetbrains.kotlin.ir.IrStatement
|
||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||
@@ -36,6 +37,7 @@ interface InlineFunctionResolver {
|
||||
fun getFunctionDeclaration(symbol: IrFunctionSymbol): IrFunction
|
||||
}
|
||||
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
open class DefaultInlineFunctionResolver(open val context: CommonBackendContext) : InlineFunctionResolver {
|
||||
override fun getFunctionDeclaration(symbol: IrFunctionSymbol): IrFunction {
|
||||
val descriptor = symbol.descriptor.original
|
||||
@@ -56,6 +58,7 @@ open class DefaultInlineFunctionResolver(open val context: CommonBackendContext)
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
class FunctionInlining(
|
||||
val context: CommonBackendContext,
|
||||
val inlineFunctionResolver: InlineFunctionResolver
|
||||
@@ -164,10 +167,6 @@ class FunctionInlining(
|
||||
statements.transform { it.transform(transformer, data = null) }
|
||||
statements.addAll(0, evaluationStatements)
|
||||
|
||||
val isCoroutineIntrinsicCall = callSite.symbol.descriptor.isBuiltInSuspendCoroutineUninterceptedOrReturn(
|
||||
context.configuration.languageVersionSettings
|
||||
)
|
||||
|
||||
return IrReturnableBlockImpl(
|
||||
startOffset = callSite.startOffset,
|
||||
endOffset = callSite.endOffset,
|
||||
@@ -414,7 +413,7 @@ class FunctionInlining(
|
||||
}
|
||||
|
||||
else -> {
|
||||
val message = "Incomplete expression: call to ${callee.descriptor} " +
|
||||
val message = "Incomplete expression: call to ${callee.render()} " +
|
||||
"has no argument at index ${parameter.index}"
|
||||
throw Error(message)
|
||||
}
|
||||
|
||||
+2
@@ -12,6 +12,7 @@ import org.jetbrains.kotlin.backend.common.lower.matchers.Quantifier
|
||||
import org.jetbrains.kotlin.backend.common.lower.matchers.SimpleCalleeMatcher
|
||||
import org.jetbrains.kotlin.backend.common.lower.matchers.createIrCallMatcher
|
||||
import org.jetbrains.kotlin.backend.common.lower.matchers.singleArgumentExtension
|
||||
import org.jetbrains.kotlin.ir.DescriptorBasedIr
|
||||
import org.jetbrains.kotlin.ir.builders.*
|
||||
import org.jetbrains.kotlin.ir.declarations.IrSimpleFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrVariable
|
||||
@@ -555,6 +556,7 @@ internal class CharSequenceIndicesHandler(context: CommonBackendContext) : Indic
|
||||
}
|
||||
|
||||
/** Builds a [HeaderInfo] for calls to reverse an iterable. */
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
internal class ReversedHandler(context: CommonBackendContext, private val visitor: HeaderInfoBuilder) :
|
||||
HeaderInfoFromCallHandler<Nothing?> {
|
||||
|
||||
|
||||
+28
-5
@@ -10,6 +10,7 @@ package org.jetbrains.kotlin.backend.common.lower.loops
|
||||
import org.jetbrains.kotlin.backend.common.CommonBackendContext
|
||||
import org.jetbrains.kotlin.backend.common.ir.Symbols
|
||||
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
|
||||
import org.jetbrains.kotlin.ir.DescriptorBasedIr
|
||||
import org.jetbrains.kotlin.ir.builders.irChar
|
||||
import org.jetbrains.kotlin.ir.builders.irInt
|
||||
import org.jetbrains.kotlin.ir.builders.irLong
|
||||
@@ -48,8 +49,12 @@ internal sealed class ProgressionType(
|
||||
it.name == numberCastFunctionName &&
|
||||
it.dispatchReceiverParameter != null && it.extensionReceiverParameter == null && it.valueParameters.isEmpty()
|
||||
}
|
||||
IrCallImpl(startOffset, endOffset, castFun.returnType, castFun.symbol)
|
||||
.apply { dispatchReceiver = this@castIfNecessary }
|
||||
IrCallImpl(
|
||||
startOffset, endOffset,
|
||||
castFun.returnType, castFun.symbol,
|
||||
typeArgumentsCount = 0,
|
||||
valueArgumentsCount = 0
|
||||
).apply { dispatchReceiver = this@castIfNecessary }
|
||||
}
|
||||
|
||||
companion object {
|
||||
@@ -139,14 +144,25 @@ internal abstract class UnsignedProgressionType(
|
||||
if (type == unsignedType) return this
|
||||
|
||||
return if (unsafeCoerceIntrinsic != null) {
|
||||
IrCallImpl(startOffset, endOffset, unsignedType, unsafeCoerceIntrinsic).apply {
|
||||
IrCallImpl(
|
||||
startOffset, endOffset,
|
||||
unsignedType,
|
||||
unsafeCoerceIntrinsic,
|
||||
typeArgumentsCount = 2,
|
||||
valueArgumentsCount = 1
|
||||
).apply {
|
||||
putTypeArgument(0, fromType)
|
||||
putTypeArgument(1, unsignedType)
|
||||
putValueArgument(0, this@asUnsigned)
|
||||
}
|
||||
} else {
|
||||
// Fallback to calling `toUInt/ULong()` extension function.
|
||||
IrCallImpl(startOffset, endOffset, unsignedConversionFunction.owner.returnType, unsignedConversionFunction).apply {
|
||||
IrCallImpl(
|
||||
startOffset, endOffset, unsignedConversionFunction.owner.returnType,
|
||||
unsignedConversionFunction,
|
||||
typeArgumentsCount = 0,
|
||||
valueArgumentsCount = 0
|
||||
).apply {
|
||||
extensionReceiver = this@asUnsigned
|
||||
}
|
||||
}
|
||||
@@ -157,7 +173,12 @@ internal abstract class UnsignedProgressionType(
|
||||
if (type == toType) return this
|
||||
|
||||
return if (unsafeCoerceIntrinsic != null) {
|
||||
IrCallImpl(startOffset, endOffset, toType, unsafeCoerceIntrinsic).apply {
|
||||
IrCallImpl(
|
||||
startOffset, endOffset, toType,
|
||||
unsafeCoerceIntrinsic,
|
||||
typeArgumentsCount = 2,
|
||||
valueArgumentsCount = 1
|
||||
).apply {
|
||||
putTypeArgument(0, unsignedType)
|
||||
putTypeArgument(1, toType)
|
||||
putValueArgument(0, this@asSigned)
|
||||
@@ -169,6 +190,7 @@ internal abstract class UnsignedProgressionType(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
internal class UIntProgressionType(symbols: Symbols<CommonBackendContext>) :
|
||||
UnsignedProgressionType(
|
||||
symbols,
|
||||
@@ -186,6 +208,7 @@ internal class UIntProgressionType(symbols: Symbols<CommonBackendContext>) :
|
||||
override fun DeclarationIrBuilder.zeroStepExpression() = irInt(0)
|
||||
}
|
||||
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
internal class ULongProgressionType(symbols: Symbols<CommonBackendContext>) :
|
||||
UnsignedProgressionType(
|
||||
symbols,
|
||||
|
||||
+12
-4
@@ -8,7 +8,6 @@ package org.jetbrains.kotlin.backend.common.lower.loops
|
||||
import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
|
||||
import org.jetbrains.kotlin.ir.builders.createTmpVariable
|
||||
import org.jetbrains.kotlin.ir.builders.irGet
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueDeclaration
|
||||
import org.jetbrains.kotlin.ir.declarations.IrVariable
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConst
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstKind
|
||||
@@ -16,7 +15,6 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||
import org.jetbrains.kotlin.ir.expressions.IrGetValue
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.IrVariableSymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.getClass
|
||||
import org.jetbrains.kotlin.ir.types.isNothing
|
||||
@@ -36,7 +34,12 @@ internal fun IrExpression.negate(): IrExpression {
|
||||
it.name == OperatorNameConventions.UNARY_MINUS &&
|
||||
it.valueParameters.isEmpty()
|
||||
}
|
||||
IrCallImpl(startOffset, endOffset, type, unaryMinusFun.symbol).apply {
|
||||
IrCallImpl(
|
||||
startOffset, endOffset, type,
|
||||
unaryMinusFun.symbol,
|
||||
valueArgumentsCount = 0,
|
||||
typeArgumentsCount = 0
|
||||
).apply {
|
||||
dispatchReceiver = this@negate
|
||||
}
|
||||
}
|
||||
@@ -54,7 +57,12 @@ internal fun IrExpression.decrement(): IrExpression {
|
||||
it.name == OperatorNameConventions.DEC &&
|
||||
it.valueParameters.isEmpty()
|
||||
}
|
||||
IrCallImpl(startOffset, endOffset, type, decFun.symbol).apply {
|
||||
IrCallImpl(
|
||||
startOffset, endOffset, type,
|
||||
decFun.symbol,
|
||||
valueArgumentsCount = 0,
|
||||
typeArgumentsCount = 0
|
||||
).apply {
|
||||
dispatchReceiver = this@decrement
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.backend.common.lower.matchers
|
||||
|
||||
import org.jetbrains.kotlin.ir.DescriptorBasedIr
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFunction
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
@@ -51,6 +52,7 @@ internal class ParameterCountMatcher(
|
||||
}
|
||||
}
|
||||
|
||||
@OptIn(DescriptorBasedIr::class)
|
||||
internal class FqNameMatcher(
|
||||
val restriction: (FqName) -> Boolean
|
||||
) : IrFunctionMatcher {
|
||||
|
||||
Reference in New Issue
Block a user