[IR] Add returnType to consturcotrs of IrFunctionBase
This commit is contained in:
@@ -122,12 +122,11 @@ fun IrClass.addSimpleDelegatingConstructor(
|
||||
)
|
||||
constructorDescriptor.returnType = superConstructorDescriptor.returnType
|
||||
|
||||
return IrConstructorImpl(startOffset, endOffset, origin, constructorDescriptor).also { constructor ->
|
||||
return IrConstructorImpl(startOffset, endOffset, origin, constructorDescriptor, this.defaultType).also { constructor ->
|
||||
|
||||
assert(superConstructor.dispatchReceiverParameter == null) // Inner classes aren't supported.
|
||||
|
||||
constructor.valueParameters += valueParameters
|
||||
constructor.returnType = this.defaultType
|
||||
|
||||
constructor.body = IrBlockBodyImpl(
|
||||
startOffset, endOffset,
|
||||
|
||||
+2
@@ -429,6 +429,7 @@ private fun buildFunctionDeclaration(irFunction: IrFunction, origin: IrDeclarati
|
||||
IrConstructorSymbolImpl(descriptor),
|
||||
irFunction.name,
|
||||
irFunction.visibility,
|
||||
irFunction.returnType,
|
||||
irFunction.isInline,
|
||||
false,
|
||||
false
|
||||
@@ -449,6 +450,7 @@ private fun buildFunctionDeclaration(irFunction: IrFunction, origin: IrDeclarati
|
||||
name,
|
||||
irFunction.visibility,
|
||||
Modality.FINAL,
|
||||
irFunction.returnType,
|
||||
irFunction.isInline,
|
||||
false,
|
||||
false,
|
||||
|
||||
+1
-1
@@ -137,10 +137,10 @@ class InitializersLowering(
|
||||
IrFunctionImpl(
|
||||
irClass.startOffset, irClass.endOffset, declarationOrigin,
|
||||
staticInitializerDescriptor,
|
||||
context.irBuiltIns.unitType,
|
||||
IrBlockBodyImpl(irClass.startOffset, irClass.endOffset,
|
||||
staticInitializerStatements.map { it.copy(irClass) })
|
||||
).apply {
|
||||
returnType = context.irBuiltIns.unitType
|
||||
accept(SetDeclarationsParentVisitor, this)
|
||||
}
|
||||
)
|
||||
|
||||
+8
-6
@@ -227,6 +227,12 @@ class InlineClassLowering(val context: BackendContext) {
|
||||
|
||||
private fun createStaticBodilessMethod(function: IrFunction): IrSimpleFunction {
|
||||
val descriptor = WrappedSimpleFunctionDescriptor()
|
||||
val returnType = when (function) {
|
||||
is IrSimpleFunction -> function.returnType
|
||||
is IrConstructor -> function.parentAsClass.defaultType
|
||||
else -> error("Unknown function type")
|
||||
}
|
||||
|
||||
return IrFunctionImpl(
|
||||
function.startOffset,
|
||||
function.endOffset,
|
||||
@@ -235,18 +241,14 @@ class InlineClassLowering(val context: BackendContext) {
|
||||
function.name.toInlineClassImplementationName(),
|
||||
function.visibility,
|
||||
Modality.FINAL,
|
||||
returnType,
|
||||
function.isInline,
|
||||
function.isExternal,
|
||||
(function is IrSimpleFunction && function.isTailrec),
|
||||
(function is IrSimpleFunction && function.isSuspend)
|
||||
).apply {
|
||||
descriptor.bind(this)
|
||||
returnType = when (function) {
|
||||
is IrSimpleFunction -> function.returnType
|
||||
is IrConstructor -> function.parentAsClass.defaultType
|
||||
else -> error("Unknown function type")
|
||||
}
|
||||
typeParameters += function.typeParameters
|
||||
copyTypeParametersFrom(function)
|
||||
annotations += function.annotations
|
||||
dispatchReceiverParameter = null
|
||||
extensionReceiverParameter = function.extensionReceiverParameter?.copyTo(this)
|
||||
|
||||
+2
-3
@@ -536,6 +536,7 @@ open class LocalDeclarationsLowering(
|
||||
// TODO: change to PRIVATE when issue with CallableReferenceLowering in Jvm BE is fixed
|
||||
if (isJVM) Visibilities.PUBLIC else Visibilities.PRIVATE,
|
||||
Modality.FINAL,
|
||||
oldDeclaration.returnType,
|
||||
oldDeclaration.isInline,
|
||||
oldDeclaration.isExternal,
|
||||
oldDeclaration.isTailrec,
|
||||
@@ -546,7 +547,6 @@ open class LocalDeclarationsLowering(
|
||||
localFunctionContext.transformedDeclaration = newDeclaration
|
||||
|
||||
newDeclaration.parent = memberOwner
|
||||
newDeclaration.returnType = oldDeclaration.returnType
|
||||
newDeclaration.copyTypeParametersFrom(oldDeclaration)
|
||||
newDeclaration.dispatchReceiverParameter = newDispatchReceiverParameter
|
||||
newDeclaration.extensionReceiverParameter = oldDeclaration.extensionReceiverParameter?.run {
|
||||
@@ -615,7 +615,7 @@ open class LocalDeclarationsLowering(
|
||||
|
||||
val newDeclaration = IrConstructorImpl(
|
||||
oldDeclaration.startOffset, oldDeclaration.endOffset, oldDeclaration.origin,
|
||||
newSymbol, oldDeclaration.name, loweredConstructorVisibility, oldDeclaration.isInline,
|
||||
newSymbol, oldDeclaration.name, loweredConstructorVisibility, oldDeclaration.returnType, oldDeclaration.isInline,
|
||||
oldDeclaration.isExternal, oldDeclaration.isPrimary
|
||||
)
|
||||
|
||||
@@ -624,7 +624,6 @@ open class LocalDeclarationsLowering(
|
||||
constructorContext.transformedDeclaration = newDeclaration
|
||||
|
||||
newDeclaration.parent = localClassContext.declaration
|
||||
newDeclaration.returnType = oldDeclaration.returnType
|
||||
newDeclaration.copyTypeParametersFrom(oldDeclaration)
|
||||
|
||||
// TODO: should dispatch receiver be copied?
|
||||
|
||||
+1
-1
@@ -95,13 +95,13 @@ class JsDeclarationFactory : DeclarationFactory {
|
||||
symbol,
|
||||
oldConstructor.name,
|
||||
oldConstructor.visibility,
|
||||
oldConstructor.returnType,
|
||||
oldConstructor.isInline,
|
||||
oldConstructor.isExternal,
|
||||
oldConstructor.isPrimary
|
||||
).also {
|
||||
descriptor.bind(it)
|
||||
it.parent = oldConstructor.parent
|
||||
it.returnType = oldConstructor.returnType
|
||||
}
|
||||
|
||||
newConstructor.copyTypeParametersFrom(oldConstructor)
|
||||
|
||||
+2
-1
@@ -33,6 +33,7 @@ import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrVariableSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||
import org.jetbrains.kotlin.ir.util.defaultType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class JsSharedVariablesManager(val builtIns: IrBuiltIns, val implicitDeclarationsFile: IrFile) : SharedVariablesManager {
|
||||
@@ -169,7 +170,7 @@ class JsSharedVariablesManager(val builtIns: IrBuiltIns, val implicitDeclaration
|
||||
|
||||
val declaration = IrConstructorImpl(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, JsLoweredDeclarationOrigin.JS_CLOSURE_BOX_CLASS_DECLARATION, symbol,
|
||||
Name.special("<init>"), Visibilities.PUBLIC, false, false, true
|
||||
Name.special("<init>"), Visibilities.PUBLIC, closureBoxClassDeclaration.defaultType, false, false, true
|
||||
)
|
||||
|
||||
descriptor.bind(declaration)
|
||||
|
||||
@@ -140,13 +140,13 @@ object JsIrBuilder {
|
||||
name,
|
||||
visibility,
|
||||
modality,
|
||||
returnType,
|
||||
isInline,
|
||||
isExternal,
|
||||
isTailrec,
|
||||
isSuspend
|
||||
).also {
|
||||
descriptor.bind(it)
|
||||
it.returnType = returnType
|
||||
it.parent = parent
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -417,13 +417,13 @@ class EnumClassTransformer(val context: JsIrBackendContext, private val irClass:
|
||||
loweredConstructorSymbol,
|
||||
enumConstructor.name,
|
||||
enumConstructor.visibility,
|
||||
enumConstructor.returnType,
|
||||
enumConstructor.isInline,
|
||||
enumConstructor.isExternal,
|
||||
enumConstructor.isPrimary
|
||||
).apply {
|
||||
loweredConstructorDescriptor.bind(this)
|
||||
parent = enumClass
|
||||
returnType = enumConstructor.returnType
|
||||
valueParameters += JsIrBuilder.buildValueParameter("name", 0, context.irBuiltIns.stringType).also { it.parent = this }
|
||||
valueParameters += JsIrBuilder.buildValueParameter("ordinal", 1, context.irBuiltIns.intType).also { it.parent = this }
|
||||
copyParameterDeclarationsFrom(enumConstructor)
|
||||
|
||||
+7
-4
@@ -498,6 +498,7 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo
|
||||
symbol,
|
||||
Name.special("<init>"),
|
||||
irFunction.visibility,
|
||||
coroutineClass.defaultType,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
@@ -505,7 +506,6 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo
|
||||
|
||||
descriptor.bind(declaration)
|
||||
declaration.parent = coroutineClass
|
||||
declaration.returnType = coroutineClass.defaultType
|
||||
|
||||
declaration.valueParameters += functionParameters.map {
|
||||
JsIrBuilder.buildValueParameter(it.name, it.index, it.type, it.origin).also { p -> p.parent = declaration }
|
||||
@@ -567,6 +567,7 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo
|
||||
symbol,
|
||||
Name.special("<init>"),
|
||||
irFunction.visibility,
|
||||
coroutineClass.defaultType,
|
||||
false,
|
||||
false,
|
||||
false
|
||||
@@ -574,7 +575,6 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo
|
||||
|
||||
descriptor.bind(declaration)
|
||||
declaration.parent = coroutineClass
|
||||
declaration.returnType = coroutineClass.defaultType
|
||||
|
||||
boundParams.mapIndexedTo(declaration.valueParameters) { i, p ->
|
||||
JsIrBuilder.buildValueParameter(p.name, i, p.type, p.origin).also { it.parent = declaration }
|
||||
@@ -627,6 +627,7 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo
|
||||
Name.identifier("create"),
|
||||
Visibilities.PRIVATE,
|
||||
Modality.FINAL,
|
||||
coroutineClass.defaultType,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
@@ -703,6 +704,7 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo
|
||||
Name.identifier("invoke"),
|
||||
Visibilities.PRIVATE,
|
||||
Modality.FINAL,
|
||||
irFunction.returnType,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
@@ -712,7 +714,7 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo
|
||||
descriptor.bind(declaration)
|
||||
declaration.parent = coroutineClass
|
||||
declaration.returnType = irFunction.returnType
|
||||
declaration.dispatchReceiverParameter = coroutineClassThis
|
||||
declaration.dispatchReceiverParameter = coroutineClassThis.copyTo(declaration)
|
||||
|
||||
declaration.overriddenSymbols += suspendFunctionInvokeFunctionDeclaration.symbol
|
||||
declaration.overriddenSymbols += functionInvokeFunctionDeclaration.symbol
|
||||
@@ -793,6 +795,7 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo
|
||||
doResumeFunction.name,
|
||||
doResumeFunction.visibility,
|
||||
Modality.FINAL,
|
||||
context.irBuiltIns.anyNType,
|
||||
doResumeFunction.isInline,
|
||||
doResumeFunction.isExternal,
|
||||
doResumeFunction.isTailrec,
|
||||
@@ -986,4 +989,4 @@ internal class SuspendFunctionsLowering(val context: JsIrBackendContext): FileLo
|
||||
scopeStack.peek()!!.add(declaration)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
@@ -516,6 +516,7 @@ internal class DeepCopyIrTreeWithDescriptors(val targetDescriptor: FunctionDescr
|
||||
endOffset = declaration.endOffset,
|
||||
origin = mapDeclarationOrigin(declaration.origin),
|
||||
descriptor = descriptor,
|
||||
returnType = declaration.returnType,
|
||||
body = declaration.body?.transform(this@InlineCopyIr, null)
|
||||
).also {
|
||||
it.setOverrides(context.symbolTable)
|
||||
|
||||
+7
-2
@@ -110,10 +110,15 @@ class JvmDeclarationFactory(
|
||||
oldDescriptor.modality,
|
||||
oldDescriptor.visibility)
|
||||
val symbol = IrConstructorSymbolImpl(newDescriptor)
|
||||
return IrConstructorImpl(oldConstructor.startOffset, oldConstructor.endOffset, oldConstructor.origin, symbol).also { constructor ->
|
||||
return IrConstructorImpl(
|
||||
oldConstructor.startOffset,
|
||||
oldConstructor.endOffset,
|
||||
oldConstructor.origin,
|
||||
symbol,
|
||||
oldConstructor.returnType
|
||||
).also { constructor ->
|
||||
newValueParameters.mapIndexedTo(constructor.valueParameters) { i, v ->
|
||||
constructor.parent = oldConstructor.parent
|
||||
constructor.returnType = oldConstructor.returnType
|
||||
if (i == 0) {
|
||||
IrValueParameterImpl(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||
|
||||
+2
-1
@@ -34,6 +34,7 @@ import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrVariableSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.createFunctionSymbol
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
|
||||
import org.jetbrains.kotlin.ir.types.toIrType
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -163,7 +164,7 @@ class JvmSharedVariablesManager(
|
||||
primitiveRefDescriptorsProvider?.refConstructorSymbol ?: createFunctionSymbol(refConstructor) as IrConstructorSymbol
|
||||
|
||||
val refConstructorDeclaration = if (refConstructorSymbol.isBound) refConstructorSymbol.owner else
|
||||
IrConstructorImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, SHARED_VARIABLE_ORIGIN, refConstructorSymbol)
|
||||
IrConstructorImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, SHARED_VARIABLE_ORIGIN, refConstructorSymbol, IrUninitializedType)
|
||||
|
||||
val refConstructorTypeArguments =
|
||||
if (primitiveRefDescriptorsProvider != null) null
|
||||
|
||||
+9
-2
@@ -171,6 +171,7 @@ class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass {
|
||||
UNDEFINED_OFFSET,
|
||||
IrDeclarationOrigin.DEFINED,
|
||||
IrSimpleFunctionSymbolImpl(descriptor),
|
||||
returnType = descriptor.returnType!!.toIrType()!!,
|
||||
visibility = visibility,
|
||||
modality = Modality.ABSTRACT
|
||||
)
|
||||
@@ -207,8 +208,14 @@ class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass {
|
||||
bridge.descriptor.returnType, Modality.OPEN, descriptor.visibility
|
||||
)
|
||||
|
||||
val irFunction = IrFunctionImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, IrDeclarationOrigin.BRIDGE, bridgeDescriptorForIrFunction)
|
||||
irFunction.returnType = bridgeDescriptorForIrFunction.returnType!!.toIrType()!!
|
||||
val returnType = bridgeDescriptorForIrFunction.returnType!!.toIrType()!!
|
||||
val irFunction = IrFunctionImpl(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
IrDeclarationOrigin.BRIDGE,
|
||||
bridgeDescriptorForIrFunction,
|
||||
returnType
|
||||
)
|
||||
irFunction.createParameterDeclarations()
|
||||
|
||||
context.createIrBuilder(irFunction.symbol).irBlockBody(irFunction) {
|
||||
|
||||
+10
-11
@@ -348,10 +348,9 @@ class CallableReferenceLowering(val context: JvmBackendContext) : FileLoweringPa
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = DECLARATION_ORIGIN_FUNCTION_REFERENCE_IMPL,
|
||||
symbol = symbol
|
||||
).apply {
|
||||
symbol = symbol,
|
||||
returnType = symbol.descriptor.returnType.toIrType()!!
|
||||
|
||||
).apply {
|
||||
val irBuilder = context.createIrBuilder(this.symbol, startOffset, endOffset)
|
||||
|
||||
createParameterDeclarations()
|
||||
@@ -432,12 +431,12 @@ class CallableReferenceLowering(val context: JvmBackendContext) : FileLoweringPa
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = DECLARATION_ORIGIN_FUNCTION_REFERENCE_IMPL,
|
||||
symbol = ourSymbol
|
||||
symbol = ourSymbol,
|
||||
returnType = ourSymbol.descriptor.returnType!!.toIrType()!!
|
||||
).apply {
|
||||
|
||||
val function = this
|
||||
val irBuilder = context.createIrBuilder(function.symbol, startOffset, endOffset)
|
||||
returnType = ourSymbol.descriptor.returnType!!.toIrType()!!
|
||||
createParameterDeclarations()
|
||||
|
||||
body = irBuilder.irBlockBody(startOffset, endOffset) {
|
||||
@@ -587,12 +586,12 @@ class CallableReferenceLowering(val context: JvmBackendContext) : FileLoweringPa
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = DECLARATION_ORIGIN_FUNCTION_REFERENCE_IMPL,
|
||||
symbol = ourSymbol
|
||||
symbol = ourSymbol,
|
||||
returnType = ourSymbol.descriptor.returnType!!.toIrType()!!
|
||||
).apply {
|
||||
|
||||
val function = this
|
||||
val irBuilder = context.createIrBuilder(function.symbol, startOffset, endOffset)
|
||||
returnType = ourSymbol.descriptor.returnType!!.toIrType()!!
|
||||
|
||||
createParameterDeclarations()
|
||||
|
||||
@@ -646,12 +645,12 @@ class CallableReferenceLowering(val context: JvmBackendContext) : FileLoweringPa
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = DECLARATION_ORIGIN_FUNCTION_REFERENCE_IMPL,
|
||||
symbol = ourSymbol
|
||||
symbol = ourSymbol,
|
||||
returnType = ourSymbol.descriptor.returnType!!.toIrType()!!
|
||||
).apply {
|
||||
|
||||
val function = this
|
||||
val irBuilder = context.createIrBuilder(function.symbol, startOffset, endOffset)
|
||||
returnType = ourSymbol.descriptor.returnType!!.toIrType()!!
|
||||
|
||||
createParameterDeclarations()
|
||||
|
||||
@@ -709,9 +708,9 @@ class CallableReferenceLowering(val context: JvmBackendContext) : FileLoweringPa
|
||||
startOffset = startOffset,
|
||||
endOffset = endOffset,
|
||||
origin = DECLARATION_ORIGIN_FUNCTION_REFERENCE_IMPL,
|
||||
symbol = ourSymbol
|
||||
).apply {
|
||||
symbol = ourSymbol,
|
||||
returnType = symbol.descriptor.returnType!!.toIrType()!!
|
||||
).apply {
|
||||
val function = this
|
||||
val irBuilder = context.createIrBuilder(function.symbol, startOffset, endOffset)
|
||||
|
||||
|
||||
+1
-1
@@ -130,10 +130,10 @@ class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringPass {
|
||||
return IrConstructorImpl(
|
||||
enumConstructor.startOffset, enumConstructor.endOffset, enumConstructor.origin,
|
||||
loweredConstructorDescriptor,
|
||||
loweredConstructorDescriptor.returnType.toIrType()!!,
|
||||
enumConstructor.body!! // will be transformed later
|
||||
).apply {
|
||||
parent = enumClass
|
||||
returnType = loweredConstructorDescriptor.returnType.toIrType()!!
|
||||
createParameterDeclarations()
|
||||
loweredEnumConstructors[constructorDescriptor] = this
|
||||
constructorDescriptor.valueParameters.forEach {
|
||||
|
||||
+1
-1
@@ -63,13 +63,13 @@ class FunctionNVarargInvokeLowering(var context: JvmBackendContext) : ClassLower
|
||||
name = Name.identifier("invoke"),
|
||||
visibility = Visibilities.PUBLIC,
|
||||
modality = Modality.OPEN,
|
||||
returnType = context.irBuiltIns.anyNType,
|
||||
isInline = false,
|
||||
isExternal = false,
|
||||
isTailrec = false,
|
||||
isSuspend = false
|
||||
).apply {
|
||||
descriptor.bind(this)
|
||||
returnType = context.irBuiltIns.anyNType
|
||||
dispatchReceiverParameter = irClass.thisReceiver
|
||||
val varargParameterDescriptor = WrappedValueParameterDescriptor()
|
||||
val varargParam = IrValueParameterImpl(
|
||||
|
||||
+1
-2
@@ -77,10 +77,9 @@ class InterfaceDelegationLowering(val context: JvmBackendContext) : IrElementTra
|
||||
UNDEFINED_OFFSET,
|
||||
IrDeclarationOrigin.DEFINED,
|
||||
inheritedFun,
|
||||
null
|
||||
defaultImplFun.returnType
|
||||
).also {
|
||||
it.createParameterDeclarations()
|
||||
it.returnType = defaultImplFun.returnType
|
||||
}
|
||||
else context.declarationFactory.getDefaultImplsFunction(
|
||||
context.ir.symbols.externalSymbolTable.referenceSimpleFunction(
|
||||
|
||||
+2
-2
@@ -123,11 +123,11 @@ internal fun FunctionDescriptor.createFunctionAndMapVariables(
|
||||
) =
|
||||
IrFunctionImpl(
|
||||
oldFunction.startOffset, oldFunction.endOffset, origin, IrSimpleFunctionSymbolImpl(this),
|
||||
visibility = visibility
|
||||
visibility = visibility,
|
||||
returnType = oldFunction.returnType
|
||||
).apply {
|
||||
parent = parentClass
|
||||
body = oldFunction.body
|
||||
returnType = oldFunction.returnType
|
||||
createParameterDeclarations(symbolTable)
|
||||
// TODO: do we really need descriptor here? This workaround is about copying `dispatchReceiver` descriptor
|
||||
val mapping: Map<ValueDescriptor, IrValueParameter> =
|
||||
|
||||
+4
-3
@@ -67,17 +67,18 @@ class JvmOverloadsAnnotationLowering(val context: JvmBackendContext) : ClassLowe
|
||||
is IrConstructorSymbol -> IrConstructorImpl(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||
JvmLoweredDeclarationOrigin.JVM_OVERLOADS_WRAPPER,
|
||||
wrapperSymbol
|
||||
wrapperSymbol,
|
||||
returnType = target.returnType
|
||||
)
|
||||
is IrSimpleFunctionSymbol -> IrFunctionImpl(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||
JvmLoweredDeclarationOrigin.JVM_OVERLOADS_WRAPPER,
|
||||
wrapperSymbol
|
||||
wrapperSymbol,
|
||||
returnType = target.returnType
|
||||
)
|
||||
else -> error("expected IrConstructorSymbol or IrSimpleFunctionSymbol")
|
||||
}
|
||||
|
||||
wrapperIrFunction.returnType = target.returnType
|
||||
wrapperIrFunction.createParameterDeclarations()
|
||||
|
||||
val call = if (target is IrConstructor)
|
||||
|
||||
+2
-2
@@ -102,9 +102,9 @@ private class CompanionObjectJvmStaticLowering(val context: JvmBackendContext) :
|
||||
val proxyIrFunction = IrFunctionImpl(
|
||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||
JvmLoweredDeclarationOrigin.JVM_STATIC_WRAPPER,
|
||||
proxyFunctionSymbol
|
||||
proxyFunctionSymbol,
|
||||
returnType = target.returnType
|
||||
)
|
||||
proxyIrFunction.returnType = target.returnType
|
||||
proxyIrFunction.createParameterDeclarations()
|
||||
|
||||
proxyIrFunction.body = createProxyBody(target, proxyIrFunction, companion)
|
||||
|
||||
+5
-2
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
|
||||
import org.jetbrains.kotlin.ir.util.*
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
@@ -104,6 +105,7 @@ class SyntheticAccessorLowering(val context: JvmBackendContext) : IrElementTrans
|
||||
IrConstructorSymbolImpl(accessorDescriptor),
|
||||
name,
|
||||
Visibilities.PUBLIC,
|
||||
IrUninitializedType,
|
||||
isInline = false,
|
||||
isExternal = false,
|
||||
isPrimary = false
|
||||
@@ -159,6 +161,7 @@ class SyntheticAccessorLowering(val context: JvmBackendContext) : IrElementTrans
|
||||
source.descriptor.accessorName(),
|
||||
Visibilities.PUBLIC,
|
||||
Modality.FINAL,
|
||||
IrUninitializedType,
|
||||
isInline = false,
|
||||
isExternal = false,
|
||||
isTailrec = false,
|
||||
@@ -198,6 +201,7 @@ class SyntheticAccessorLowering(val context: JvmBackendContext) : IrElementTrans
|
||||
fieldSymbol.descriptor.accessorNameForGetter(),
|
||||
Visibilities.PUBLIC,
|
||||
Modality.FINAL,
|
||||
fieldSymbol.owner.type,
|
||||
isInline = false,
|
||||
isExternal = false,
|
||||
isTailrec = false,
|
||||
@@ -227,7 +231,6 @@ class SyntheticAccessorLowering(val context: JvmBackendContext) : IrElementTrans
|
||||
)
|
||||
}
|
||||
|
||||
accessor.returnType = fieldSymbol.owner.type
|
||||
accessor.body = createAccessorBodyForGetter(fieldSymbol.owner, accessor)
|
||||
}.symbol
|
||||
}
|
||||
@@ -257,6 +260,7 @@ class SyntheticAccessorLowering(val context: JvmBackendContext) : IrElementTrans
|
||||
fieldSymbol.descriptor.accessorNameForSetter(),
|
||||
Visibilities.PUBLIC,
|
||||
Modality.FINAL,
|
||||
returnType = context.irBuiltIns.unitType,
|
||||
isInline = false,
|
||||
isExternal = false,
|
||||
isTailrec = false,
|
||||
@@ -303,7 +307,6 @@ class SyntheticAccessorLowering(val context: JvmBackendContext) : IrElementTrans
|
||||
}
|
||||
)
|
||||
|
||||
accessor.returnType = context.irBuiltIns.unitType
|
||||
accessor.body = createAccessorBodyForSetter(fieldSymbol.owner, accessor)
|
||||
}.symbol
|
||||
}
|
||||
|
||||
+18
-4
@@ -87,13 +87,20 @@ class ToArrayLowering(private val context: JvmBackendContext) : ClassLoweringPas
|
||||
)
|
||||
|
||||
val toArrayUtilDescriptor = createToArrayUtilDescriptor(builtIns, false)
|
||||
val toArrayType = toArrayUtilDescriptor.returnType!!.toIrType()!!
|
||||
|
||||
val irFunction = IrFunctionImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, JvmLoweredDeclarationOrigin.TO_ARRAY, toArrayDescriptor)
|
||||
val irFunction = IrFunctionImpl(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
JvmLoweredDeclarationOrigin.TO_ARRAY,
|
||||
toArrayDescriptor,
|
||||
returnType = toArrayType
|
||||
)
|
||||
irFunction.createParameterDeclarations()
|
||||
|
||||
irFunction.body = context.createIrBuilder(irFunction.symbol).irBlockBody {
|
||||
+irReturn(
|
||||
irCall(IrSimpleFunctionSymbolImpl(toArrayUtilDescriptor), toArrayUtilDescriptor.returnType!!.toIrType()!!).apply {
|
||||
irCall(IrSimpleFunctionSymbolImpl(toArrayUtilDescriptor), toArrayType).apply {
|
||||
putValueArgument(
|
||||
0,
|
||||
IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irFunction.dispatchReceiverParameter!!.symbol)
|
||||
@@ -145,13 +152,20 @@ class ToArrayLowering(private val context: JvmBackendContext) : ClassLoweringPas
|
||||
)
|
||||
|
||||
val toArrayUtilDescriptor = createToArrayUtilDescriptor(builtIns, true)
|
||||
val toArrayType = toArrayUtilDescriptor.returnType!!.toIrType()!!
|
||||
|
||||
val irFunction = IrFunctionImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, JvmLoweredDeclarationOrigin.TO_ARRAY, toArrayDescriptor)
|
||||
val irFunction = IrFunctionImpl(
|
||||
UNDEFINED_OFFSET,
|
||||
UNDEFINED_OFFSET,
|
||||
JvmLoweredDeclarationOrigin.TO_ARRAY,
|
||||
toArrayDescriptor,
|
||||
toArrayType
|
||||
)
|
||||
irFunction.createParameterDeclarations()
|
||||
|
||||
irFunction.body = context.createIrBuilder(irFunction.symbol).irBlockBody {
|
||||
+irReturn(
|
||||
irCall(IrSimpleFunctionSymbolImpl(toArrayUtilDescriptor), toArrayUtilDescriptor.returnType!!.toIrType()!!).apply {
|
||||
irCall(IrSimpleFunctionSymbolImpl(toArrayUtilDescriptor), toArrayType).apply {
|
||||
putValueArgument(
|
||||
0,
|
||||
IrGetValueImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET, irFunction.dispatchReceiverParameter!!.symbol)
|
||||
|
||||
@@ -42,10 +42,9 @@ class IrMemberFunctionBuilder(
|
||||
lateinit var irFunction: IrFunction
|
||||
|
||||
inline fun addToClass(body: IrMemberFunctionBuilder.(IrFunction) -> Unit): IrFunction {
|
||||
irFunction = IrFunctionImpl(startOffset, endOffset, origin, function)
|
||||
irFunction = IrFunctionImpl(startOffset, endOffset, origin, function, returnType)
|
||||
body(irFunction)
|
||||
irFunction.body = doBuild()
|
||||
irFunction.returnType = returnType
|
||||
irClass.declarations.add(irFunction)
|
||||
return irFunction
|
||||
}
|
||||
|
||||
+9
-4
@@ -35,13 +35,14 @@ class IrConstructorImpl(
|
||||
override val symbol: IrConstructorSymbol,
|
||||
name: Name,
|
||||
visibility: Visibility,
|
||||
returnType: IrType,
|
||||
isInline: Boolean,
|
||||
isExternal: Boolean,
|
||||
override val isPrimary: Boolean
|
||||
) :
|
||||
IrFunctionBase(
|
||||
startOffset, endOffset, origin, name,
|
||||
visibility, isInline, isExternal
|
||||
visibility, isInline, isExternal, returnType
|
||||
),
|
||||
IrConstructor {
|
||||
|
||||
@@ -50,11 +51,13 @@ class IrConstructorImpl(
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
symbol: IrConstructorSymbol,
|
||||
returnType: IrType,
|
||||
body: IrBody? = null
|
||||
) : this(
|
||||
startOffset, endOffset, origin, symbol,
|
||||
symbol.descriptor.name,
|
||||
symbol.descriptor.visibility,
|
||||
returnType,
|
||||
symbol.descriptor.isInline,
|
||||
symbol.descriptor.isEffectivelyExternal(),
|
||||
symbol.descriptor.isPrimary
|
||||
@@ -66,8 +69,9 @@ class IrConstructorImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: ClassConstructorDescriptor
|
||||
) : this(startOffset, endOffset, origin, IrConstructorSymbolImpl(descriptor))
|
||||
descriptor: ClassConstructorDescriptor,
|
||||
returnType: IrType
|
||||
) : this(startOffset, endOffset, origin, IrConstructorSymbolImpl(descriptor), returnType)
|
||||
|
||||
@Deprecated("Use constructor which takes symbol instead of descriptor")
|
||||
constructor(
|
||||
@@ -75,8 +79,9 @@ class IrConstructorImpl(
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: ClassConstructorDescriptor,
|
||||
returnType: IrType,
|
||||
body: IrBody?
|
||||
) : this(startOffset, endOffset, origin, descriptor) {
|
||||
) : this(startOffset, endOffset, origin, descriptor, returnType) {
|
||||
this.body = body
|
||||
}
|
||||
|
||||
|
||||
+10
-3
@@ -23,6 +23,7 @@ import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||
import org.jetbrains.kotlin.ir.declarations.IrValueParameter
|
||||
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
|
||||
import org.jetbrains.kotlin.ir.util.transform
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||
@@ -36,11 +37,19 @@ abstract class IrFunctionBase(
|
||||
override val name: Name,
|
||||
override val visibility: Visibility,
|
||||
override val isInline: Boolean,
|
||||
override val isExternal: Boolean
|
||||
override val isExternal: Boolean,
|
||||
returnType: IrType
|
||||
) :
|
||||
IrDeclarationBase(startOffset, endOffset, origin),
|
||||
IrFunction {
|
||||
|
||||
final override var returnType: IrType = returnType
|
||||
get() = if (field === IrUninitializedType) {
|
||||
error("Return type is not initialized")
|
||||
} else {
|
||||
field
|
||||
}
|
||||
|
||||
override val typeParameters: MutableList<IrTypeParameter> = SmartList()
|
||||
|
||||
override var dispatchReceiverParameter: IrValueParameter? = null
|
||||
@@ -49,8 +58,6 @@ abstract class IrFunctionBase(
|
||||
|
||||
final override var body: IrBody? = null
|
||||
|
||||
final override lateinit var returnType: IrType
|
||||
|
||||
override fun <D> acceptChildren(visitor: IrElementVisitor<Unit, D>, data: D) {
|
||||
typeParameters.forEach { it.accept(visitor, data) }
|
||||
|
||||
|
||||
@@ -27,12 +27,13 @@ class IrFunctionImpl(
|
||||
name: Name,
|
||||
visibility: Visibility,
|
||||
override val modality: Modality,
|
||||
returnType: IrType,
|
||||
isInline: Boolean,
|
||||
isExternal: Boolean,
|
||||
override val isTailrec: Boolean,
|
||||
override val isSuspend: Boolean
|
||||
) :
|
||||
IrFunctionBase(startOffset, endOffset, origin, name, visibility, isInline, isExternal),
|
||||
IrFunctionBase(startOffset, endOffset, origin, name, visibility, isInline, isExternal, returnType),
|
||||
IrSimpleFunction {
|
||||
|
||||
constructor(
|
||||
@@ -40,6 +41,7 @@ class IrFunctionImpl(
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
symbol: IrSimpleFunctionSymbol,
|
||||
returnType: IrType,
|
||||
visibility: Visibility = symbol.descriptor.visibility,
|
||||
modality: Modality = symbol.descriptor.modality
|
||||
) : this(
|
||||
@@ -47,6 +49,7 @@ class IrFunctionImpl(
|
||||
symbol.descriptor.name,
|
||||
visibility,
|
||||
modality,
|
||||
returnType,
|
||||
symbol.descriptor.isInline,
|
||||
symbol.descriptor.isExternal,
|
||||
symbol.descriptor.isTailrec,
|
||||
@@ -63,10 +66,11 @@ class IrFunctionImpl(
|
||||
startOffset: Int,
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: FunctionDescriptor
|
||||
descriptor: FunctionDescriptor,
|
||||
returnType: IrType
|
||||
) : this(
|
||||
startOffset, endOffset, origin,
|
||||
IrSimpleFunctionSymbolImpl(descriptor)
|
||||
IrSimpleFunctionSymbolImpl(descriptor), returnType
|
||||
)
|
||||
|
||||
constructor(
|
||||
@@ -74,8 +78,9 @@ class IrFunctionImpl(
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: FunctionDescriptor,
|
||||
returnType: IrType,
|
||||
body: IrBody?
|
||||
) : this(startOffset, endOffset, origin, descriptor) {
|
||||
) : this(startOffset, endOffset, origin, descriptor, returnType) {
|
||||
this.body = body
|
||||
}
|
||||
|
||||
|
||||
@@ -38,4 +38,9 @@ val IrType.originalKotlinType: KotlinType?
|
||||
get() = safeAs<IrTypeBase>()?.kotlinType
|
||||
|
||||
|
||||
object IrStarProjectionImpl : IrStarProjection
|
||||
object IrStarProjectionImpl : IrStarProjection
|
||||
|
||||
@Deprecated("Hack to temporary cover late type initialization")
|
||||
object IrUninitializedType : IrType {
|
||||
override val annotations: List<IrCall> = emptyList()
|
||||
}
|
||||
|
||||
@@ -116,6 +116,7 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
||||
declaration.startOffset, declaration.endOffset,
|
||||
mapDeclarationOrigin(declaration.origin),
|
||||
mapFunctionDeclaration(declaration.descriptor),
|
||||
declaration.returnType, // TODO
|
||||
declaration.body?.transform()
|
||||
).transformParameters(declaration).apply {
|
||||
transformAnnotations(declaration)
|
||||
@@ -126,7 +127,6 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
||||
else
|
||||
IrSimpleFunctionSymbolImpl(overriddenDescriptor.original)
|
||||
}
|
||||
returnType = declaration.returnType // TODO
|
||||
}
|
||||
|
||||
override fun visitConstructor(declaration: IrConstructor): IrConstructor =
|
||||
@@ -134,10 +134,10 @@ open class DeepCopyIrTree : IrElementTransformerVoid() {
|
||||
declaration.startOffset, declaration.endOffset,
|
||||
mapDeclarationOrigin(declaration.origin),
|
||||
mapConstructorDeclaration(declaration.descriptor),
|
||||
declaration.returnType, // TODO
|
||||
declaration.body?.transform()
|
||||
).transformParameters(declaration).apply {
|
||||
transformAnnotations(declaration)
|
||||
returnType = declaration.returnType // TODO
|
||||
}
|
||||
|
||||
protected fun <T : IrTypeParametersContainer> T.transformTypeParameters(
|
||||
|
||||
@@ -155,6 +155,7 @@ open class DeepCopyIrTreeWithSymbols(
|
||||
symbolRenamer.getFunctionName(declaration.symbol),
|
||||
declaration.visibility,
|
||||
declaration.modality,
|
||||
declaration.returnType,
|
||||
declaration.isInline,
|
||||
declaration.isExternal,
|
||||
declaration.isTailrec,
|
||||
@@ -173,6 +174,7 @@ open class DeepCopyIrTreeWithSymbols(
|
||||
symbolRemapper.getDeclaredConstructor(declaration.symbol),
|
||||
declaration.name,
|
||||
declaration.visibility,
|
||||
declaration.returnType,
|
||||
declaration.isInline,
|
||||
declaration.isExternal,
|
||||
declaration.isPrimary
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||
import org.jetbrains.kotlin.ir.symbols.*
|
||||
import org.jetbrains.kotlin.ir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.types.impl.IrUninitializedType
|
||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
@@ -235,7 +236,7 @@ open class SymbolTable : ReferenceSymbolTable {
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: ClassConstructorDescriptor,
|
||||
constructorFactory: (IrConstructorSymbol) -> IrConstructor = { IrConstructorImpl(startOffset, endOffset, origin, it) }
|
||||
constructorFactory: (IrConstructorSymbol) -> IrConstructor = { IrConstructorImpl(startOffset, endOffset, origin, it, IrUninitializedType) }
|
||||
): IrConstructor =
|
||||
constructorSymbolTable.declare(
|
||||
descriptor,
|
||||
@@ -299,7 +300,7 @@ open class SymbolTable : ReferenceSymbolTable {
|
||||
endOffset: Int,
|
||||
origin: IrDeclarationOrigin,
|
||||
descriptor: FunctionDescriptor,
|
||||
functionFactory: (IrSimpleFunctionSymbol) -> IrSimpleFunction = { IrFunctionImpl(startOffset, endOffset, origin, it) }
|
||||
functionFactory: (IrSimpleFunctionSymbol) -> IrSimpleFunction = { IrFunctionImpl(startOffset, endOffset, origin, it, IrUninitializedType) }
|
||||
): IrSimpleFunction {
|
||||
return simpleFunctionSymbolTable.declare(
|
||||
descriptor,
|
||||
|
||||
Reference in New Issue
Block a user