IR API: change val ... : MutableList to var ...: List for most lists
All mutable state for IR declarations should be either: - var (mutable properties) - or class member list Mutable properties are straightforward to persist. The class member list is handled in a special way.
This commit is contained in:
@@ -78,7 +78,7 @@ fun IrClass.addSimpleDelegatingConstructor(
|
|||||||
constructor.parent = this
|
constructor.parent = this
|
||||||
declarations += constructor
|
declarations += constructor
|
||||||
|
|
||||||
superConstructor.valueParameters.mapIndexedTo(constructor.valueParameters) { index, parameter ->
|
constructor.valueParameters = superConstructor.valueParameters.mapIndexed { index, parameter ->
|
||||||
parameter.copyTo(constructor, index = index)
|
parameter.copyTo(constructor, index = index)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,7 +163,7 @@ fun IrValueParameter.copyTo(
|
|||||||
descriptor.bind(it)
|
descriptor.bind(it)
|
||||||
it.parent = irFunction
|
it.parent = irFunction
|
||||||
it.defaultValue = defaultValueCopy
|
it.defaultValue = defaultValueCopy
|
||||||
it.annotations.addAll(annotations.map { it.deepCopyWithSymbols() })
|
it.annotations = annotations.map { it.deepCopyWithSymbols() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,7 +205,7 @@ fun IrFunction.copyValueParametersInsertingContinuationFrom(from: IrFunction, in
|
|||||||
insertContinuation()
|
insertContinuation()
|
||||||
additionalShift = 1
|
additionalShift = 1
|
||||||
}
|
}
|
||||||
valueParameters.add(it.copyTo(this, index = it.index + shift + additionalShift))
|
valueParameters += it.copyTo(this, index = it.index + shift + additionalShift)
|
||||||
}
|
}
|
||||||
// If there was no default argument mask and handler, the continuation goes last.
|
// If there was no default argument mask and handler, the continuation goes last.
|
||||||
if (additionalShift == 0) insertContinuation()
|
if (additionalShift == 0) insertContinuation()
|
||||||
@@ -231,7 +231,7 @@ fun IrTypeParametersContainer.copyTypeParameters(
|
|||||||
oldToNewParameterMap[sourceParameter] = it
|
oldToNewParameterMap[sourceParameter] = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
typeParameters.addAll(newTypeParameters)
|
typeParameters += newTypeParameters
|
||||||
srcTypeParameters.zip(newTypeParameters).forEach { (srcParameter, dstParameter) ->
|
srcTypeParameters.zip(newTypeParameters).forEach { (srcParameter, dstParameter) ->
|
||||||
dstParameter.copySuperTypesFrom(srcParameter, oldToNewParameterMap)
|
dstParameter.copySuperTypesFrom(srcParameter, oldToNewParameterMap)
|
||||||
}
|
}
|
||||||
@@ -273,35 +273,29 @@ fun IrFunction.copyValueParametersToStatic(
|
|||||||
target.classIfConstructor
|
target.classIfConstructor
|
||||||
)
|
)
|
||||||
|
|
||||||
target.valueParameters.add(
|
target.valueParameters += originalDispatchReceiver.copyTo(
|
||||||
originalDispatchReceiver.copyTo(
|
target,
|
||||||
target,
|
origin = originalDispatchReceiver.origin,
|
||||||
origin = originalDispatchReceiver.origin,
|
index = shift++,
|
||||||
index = shift++,
|
type = type,
|
||||||
type = type,
|
name = Name.identifier("\$this")
|
||||||
name = Name.identifier("\$this")
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
source.extensionReceiverParameter?.let { originalExtensionReceiver ->
|
source.extensionReceiverParameter?.let { originalExtensionReceiver ->
|
||||||
target.valueParameters.add(
|
target.valueParameters += originalExtensionReceiver.copyTo(
|
||||||
originalExtensionReceiver.copyTo(
|
target,
|
||||||
target,
|
origin = originalExtensionReceiver.origin,
|
||||||
origin = originalExtensionReceiver.origin,
|
index = shift++,
|
||||||
index = shift++,
|
name = Name.identifier("\$receiver")
|
||||||
name = Name.identifier("\$receiver")
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
for (oldValueParameter in source.valueParameters) {
|
for (oldValueParameter in source.valueParameters) {
|
||||||
if (oldValueParameter.index >= numValueParametersToCopy) break
|
if (oldValueParameter.index >= numValueParametersToCopy) break
|
||||||
target.valueParameters.add(
|
target.valueParameters += oldValueParameter.copyTo(
|
||||||
oldValueParameter.copyTo(
|
target,
|
||||||
target,
|
origin = origin,
|
||||||
origin = origin,
|
index = oldValueParameter.index + shift
|
||||||
index = oldValueParameter.index + shift
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -601,7 +595,7 @@ fun createStaticFunctionWithReceivers(
|
|||||||
|
|
||||||
typeParameters.forEach { it.superTypes.replaceAll { remap(it) } }
|
typeParameters.forEach { it.superTypes.replaceAll { remap(it) } }
|
||||||
|
|
||||||
annotations.addAll(oldFunction.annotations)
|
annotations = oldFunction.annotations
|
||||||
|
|
||||||
var offset = 0
|
var offset = 0
|
||||||
val dispatchReceiver = oldFunction.dispatchReceiverParameter?.copyTo(
|
val dispatchReceiver = oldFunction.dispatchReceiverParameter?.copyTo(
|
||||||
@@ -618,7 +612,7 @@ fun createStaticFunctionWithReceivers(
|
|||||||
origin = IrDeclarationOrigin.MOVED_EXTENSION_RECEIVER,
|
origin = IrDeclarationOrigin.MOVED_EXTENSION_RECEIVER,
|
||||||
remapTypeMap = typeParameterMap
|
remapTypeMap = typeParameterMap
|
||||||
)
|
)
|
||||||
valueParameters.addAll(listOfNotNull(dispatchReceiver, extensionReceiver) +
|
valueParameters = listOfNotNull(dispatchReceiver, extensionReceiver) +
|
||||||
oldFunction.valueParameters.map {
|
oldFunction.valueParameters.map {
|
||||||
it.copyTo(
|
it.copyTo(
|
||||||
this,
|
this,
|
||||||
@@ -626,7 +620,6 @@ fun createStaticFunctionWithReceivers(
|
|||||||
remapTypeMap = typeParameterMap
|
remapTypeMap = typeParameterMap
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
if (copyMetadata) metadata = oldFunction.metadata
|
if (copyMetadata) metadata = oldFunction.metadata
|
||||||
}
|
}
|
||||||
@@ -670,10 +663,11 @@ private fun IrSimpleFunction.copyAndRenameConflictingTypeParametersFrom(
|
|||||||
it.parent = this
|
it.parent = this
|
||||||
}
|
}
|
||||||
|
|
||||||
typeParameters.add(newTypeParameter)
|
|
||||||
newParameters.add(newTypeParameter)
|
newParameters.add(newTypeParameter)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
typeParameters = typeParameters + newParameters
|
||||||
|
|
||||||
return newParameters
|
return newParameters
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-13
@@ -300,7 +300,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
|||||||
d.bind(this)
|
d.bind(this)
|
||||||
parent = irFunction.parent
|
parent = irFunction.parent
|
||||||
createParameterDeclarations()
|
createParameterDeclarations()
|
||||||
irFunction.typeParameters.mapTo(typeParameters) { typeParam ->
|
typeParameters = irFunction.typeParameters.map { typeParam ->
|
||||||
typeParam.copyToWithoutSuperTypes(this).apply { superTypes += typeParam.superTypes }
|
typeParam.copyToWithoutSuperTypes(this).apply { superTypes += typeParam.superTypes }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -403,7 +403,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
|||||||
coroutineClass.declarations += this
|
coroutineClass.declarations += this
|
||||||
coroutineConstructors += this
|
coroutineConstructors += this
|
||||||
|
|
||||||
functionParameters.mapIndexedTo(valueParameters) { index, parameter ->
|
valueParameters = functionParameters.mapIndexed { index, parameter ->
|
||||||
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index)
|
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index)
|
||||||
}
|
}
|
||||||
val continuationParameter = coroutineBaseClassConstructor.valueParameters[0]
|
val continuationParameter = coroutineBaseClassConstructor.valueParameters[0]
|
||||||
@@ -449,7 +449,7 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
|||||||
coroutineClass.declarations += this
|
coroutineClass.declarations += this
|
||||||
coroutineConstructors += this
|
coroutineConstructors += this
|
||||||
|
|
||||||
boundParams.mapIndexedTo(valueParameters) { index, parameter ->
|
valueParameters = boundParams.mapIndexed { index, parameter ->
|
||||||
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index)
|
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,15 +498,14 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
|||||||
parent = coroutineClass
|
parent = coroutineClass
|
||||||
coroutineClass.declarations += this
|
coroutineClass.declarations += this
|
||||||
|
|
||||||
irFunction.typeParameters.mapTo(typeParameters) { parameter ->
|
typeParameters = irFunction.typeParameters.map { parameter ->
|
||||||
parameter.copyToWithoutSuperTypes(this, origin = DECLARATION_ORIGIN_COROUTINE_IMPL)
|
parameter.copyToWithoutSuperTypes(this, origin = DECLARATION_ORIGIN_COROUTINE_IMPL)
|
||||||
.apply { superTypes += parameter.superTypes }
|
.apply { superTypes += parameter.superTypes }
|
||||||
}
|
}
|
||||||
|
|
||||||
(unboundArgs + create1CompletionParameter)
|
valueParameters = (unboundArgs + create1CompletionParameter).mapIndexed { index, parameter ->
|
||||||
.mapIndexedTo(valueParameters) { index, parameter ->
|
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index)
|
||||||
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
this.createDispatchReceiverParameter()
|
this.createDispatchReceiverParameter()
|
||||||
|
|
||||||
@@ -566,15 +565,15 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
|||||||
parent = coroutineClass
|
parent = coroutineClass
|
||||||
coroutineClass.declarations += this
|
coroutineClass.declarations += this
|
||||||
|
|
||||||
irFunction.typeParameters.mapTo(typeParameters) { parameter ->
|
typeParameters = irFunction.typeParameters.map { parameter ->
|
||||||
parameter.copyToWithoutSuperTypes(this, origin = DECLARATION_ORIGIN_COROUTINE_IMPL)
|
parameter.copyToWithoutSuperTypes(this, origin = DECLARATION_ORIGIN_COROUTINE_IMPL)
|
||||||
.apply { superTypes += parameter.superTypes }
|
.apply { superTypes += parameter.superTypes }
|
||||||
}
|
}
|
||||||
|
|
||||||
createFunction.valueParameters
|
valueParameters = createFunction.valueParameters
|
||||||
// Skip completion - invoke() already has it implicitly as a suspend function.
|
// Skip completion - invoke() already has it implicitly as a suspend function.
|
||||||
.take(createFunction.valueParameters.size - 1)
|
.take(createFunction.valueParameters.size - 1)
|
||||||
.mapIndexedTo(valueParameters) { index, parameter ->
|
.mapIndexed { index, parameter ->
|
||||||
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index)
|
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -626,12 +625,12 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
|||||||
parent = coroutineClass
|
parent = coroutineClass
|
||||||
coroutineClass.declarations += this
|
coroutineClass.declarations += this
|
||||||
|
|
||||||
stateMachineFunction.typeParameters.mapTo(typeParameters) { parameter ->
|
typeParameters = stateMachineFunction.typeParameters.map { parameter ->
|
||||||
parameter.copyToWithoutSuperTypes(this, origin = DECLARATION_ORIGIN_COROUTINE_IMPL)
|
parameter.copyToWithoutSuperTypes(this, origin = DECLARATION_ORIGIN_COROUTINE_IMPL)
|
||||||
.apply { superTypes += parameter.superTypes }
|
.apply { superTypes += parameter.superTypes }
|
||||||
}
|
}
|
||||||
|
|
||||||
stateMachineFunction.valueParameters.mapIndexedTo(valueParameters) { index, parameter ->
|
valueParameters = stateMachineFunction.valueParameters.mapIndexed { index, parameter ->
|
||||||
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index)
|
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -364,7 +364,7 @@ private fun IrFunction.generateDefaultsFunction(
|
|||||||
}
|
}
|
||||||
if (overriddenStubs.isNotEmpty()) {
|
if (overriddenStubs.isNotEmpty()) {
|
||||||
return generateDefaultsFunctionImpl(context, IrDeclarationOrigin.FAKE_OVERRIDE, visibility).also {
|
return generateDefaultsFunctionImpl(context, IrDeclarationOrigin.FAKE_OVERRIDE, visibility).also {
|
||||||
(it as IrSimpleFunction).overriddenSymbols.addAll(overriddenStubs)
|
(it as IrSimpleFunction).overriddenSymbols += overriddenStubs
|
||||||
context.ir.defaultParameterDeclarationsCache[this] = it
|
context.ir.defaultParameterDeclarationsCache[this] = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -420,7 +420,7 @@ private fun IrFunction.generateDefaultsFunctionImpl(
|
|||||||
newFunction.dispatchReceiverParameter = dispatchReceiverParameter?.copyTo(newFunction)
|
newFunction.dispatchReceiverParameter = dispatchReceiverParameter?.copyTo(newFunction)
|
||||||
newFunction.extensionReceiverParameter = extensionReceiverParameter?.copyTo(newFunction)
|
newFunction.extensionReceiverParameter = extensionReceiverParameter?.copyTo(newFunction)
|
||||||
|
|
||||||
valueParameters.mapTo(newFunction.valueParameters) {
|
newFunction.valueParameters = valueParameters.map {
|
||||||
val newType = it.type.remapTypeParameters(classIfConstructor, newFunction.classIfConstructor)
|
val newType = it.type.remapTypeParameters(classIfConstructor, newFunction.classIfConstructor)
|
||||||
val makeNullable = it.defaultValue != null &&
|
val makeNullable = it.defaultValue != null &&
|
||||||
(context.ir.unfoldInlineClassType(it.type) ?: it.type) !in context.irBuiltIns.primitiveIrTypes
|
(context.ir.unfoldInlineClassType(it.type) ?: it.type) !in context.irBuiltIns.primitiveIrTypes
|
||||||
@@ -445,7 +445,7 @@ private fun IrFunction.generateDefaultsFunctionImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO some annotations are needed (e.g. @JvmStatic), others need different values (e.g. @JvmName), the rest are redundant.
|
// TODO some annotations are needed (e.g. @JvmStatic), others need different values (e.g. @JvmName), the rest are redundant.
|
||||||
annotations.mapTo(newFunction.annotations) { it.deepCopyWithSymbols() }
|
newFunction.annotations = annotations.map { it.deepCopyWithSymbols() }
|
||||||
return newFunction
|
return newFunction
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -613,7 +613,7 @@ class LocalDeclarationsLowering(
|
|||||||
)
|
)
|
||||||
newDeclaration.recordTransformedValueParameters(localFunctionContext)
|
newDeclaration.recordTransformedValueParameters(localFunctionContext)
|
||||||
|
|
||||||
newDeclaration.annotations.addAll(oldDeclaration.annotations)
|
newDeclaration.annotations = oldDeclaration.annotations
|
||||||
|
|
||||||
transformedDeclarations[oldDeclaration] = newDeclaration
|
transformedDeclarations[oldDeclaration] = newDeclaration
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -196,7 +196,7 @@ abstract class SingleAbstractMethodLowering(val context: CommonBackendContext) :
|
|||||||
}.apply {
|
}.apply {
|
||||||
overriddenSymbols += superMethod.symbol
|
overriddenSymbols += superMethod.symbol
|
||||||
dispatchReceiverParameter = subclass.thisReceiver!!.copyTo(this)
|
dispatchReceiverParameter = subclass.thisReceiver!!.copyTo(this)
|
||||||
superMethod.valueParameters.mapTo(valueParameters) { it.copyTo(this) }
|
valueParameters = superMethod.valueParameters.map { it.copyTo(this) }
|
||||||
body = context.createIrBuilder(symbol).irBlockBody {
|
body = context.createIrBuilder(symbol).irBlockBody {
|
||||||
+irReturn(irCall(wrappedFunctionClass.functions.single { it.name == OperatorNameConventions.INVOKE }).apply {
|
+irReturn(irCall(wrappedFunctionClass.functions.single { it.name == OperatorNameConventions.INVOKE }).apply {
|
||||||
dispatchReceiver = irGetField(irGet(dispatchReceiverParameter!!), field)
|
dispatchReceiver = irGetField(irGet(dispatchReceiverParameter!!), field)
|
||||||
|
|||||||
+2
-2
@@ -234,7 +234,7 @@ inline fun IrFunction.addValueParameter(builder: IrValueParameterBuilder.() -> U
|
|||||||
index = valueParameters.size
|
index = valueParameters.size
|
||||||
}
|
}
|
||||||
build().also { valueParameter ->
|
build().also { valueParameter ->
|
||||||
valueParameters.add(valueParameter)
|
valueParameters += valueParameter
|
||||||
valueParameter.parent = this@addValueParameter
|
valueParameter.parent = this@addValueParameter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -293,7 +293,7 @@ inline fun IrTypeParametersContainer.addTypeParameter(builder: IrTypeParameterBu
|
|||||||
index = typeParameters.size
|
index = typeParameters.size
|
||||||
}
|
}
|
||||||
build().also { typeParameter ->
|
build().also { typeParameter ->
|
||||||
typeParameters.add(typeParameter)
|
typeParameters += typeParameter
|
||||||
typeParameter.parent = this@addTypeParameter
|
typeParameter.parent = this@addTypeParameter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -137,8 +137,8 @@ class BridgesConstruction(val context: CommonBackendContext) : ClassLoweringPass
|
|||||||
extensionReceiverParameter = bridge.extensionReceiverParameter?.copyTo(this)
|
extensionReceiverParameter = bridge.extensionReceiverParameter?.copyTo(this)
|
||||||
valueParameters += bridge.valueParameters.map { p -> p.copyTo(this) }
|
valueParameters += bridge.valueParameters.map { p -> p.copyTo(this) }
|
||||||
annotations += bridge.annotations
|
annotations += bridge.annotations
|
||||||
overriddenSymbols.addAll(delegateTo.overriddenSymbols)
|
overriddenSymbols += delegateTo.overriddenSymbols
|
||||||
overriddenSymbols.add(bridge.symbol)
|
overriddenSymbols += bridge.symbol
|
||||||
}
|
}
|
||||||
|
|
||||||
context.createIrBuilder(irFunction.symbol).irBlockBody(irFunction) {
|
context.createIrBuilder(irFunction.symbol).irBlockBody(irFunction) {
|
||||||
|
|||||||
+1
-1
@@ -155,7 +155,7 @@ private fun buildInitDeclaration(constructor: IrConstructor, irClass: IrClass):
|
|||||||
).also {
|
).also {
|
||||||
it.copyTypeParametersFrom(constructor.parentAsClass)
|
it.copyTypeParametersFrom(constructor.parentAsClass)
|
||||||
|
|
||||||
constructor.valueParameters.mapTo(it.valueParameters) { p -> p.copyTo(it) }
|
it.valueParameters = constructor.valueParameters.map { p -> p.copyTo(it) }
|
||||||
it.valueParameters += JsIrBuilder.buildValueParameter("\$this", constructor.valueParameters.size, type).apply { parent = it }
|
it.valueParameters += JsIrBuilder.buildValueParameter("\$this", constructor.valueParameters.size, type).apply { parent = it }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-6
@@ -97,7 +97,7 @@ class JvmDeclarationFactory(
|
|||||||
isExpect = oldConstructor.isExpect
|
isExpect = oldConstructor.isExpect
|
||||||
).apply {
|
).apply {
|
||||||
newDescriptor.bind(this)
|
newDescriptor.bind(this)
|
||||||
annotations.addAll(oldConstructor.annotations.map { it.deepCopyWithSymbols(this) })
|
annotations = oldConstructor.annotations.map { it.deepCopyWithSymbols(this) }
|
||||||
parent = oldConstructor.parent
|
parent = oldConstructor.parent
|
||||||
returnType = oldConstructor.returnType
|
returnType = oldConstructor.returnType
|
||||||
copyTypeParametersFrom(oldConstructor)
|
copyTypeParametersFrom(oldConstructor)
|
||||||
@@ -117,9 +117,7 @@ class JvmDeclarationFactory(
|
|||||||
outerThisDescriptor.bind(it)
|
outerThisDescriptor.bind(it)
|
||||||
it.parent = this
|
it.parent = this
|
||||||
}
|
}
|
||||||
valueParameters.add(outerThisValueParameter)
|
valueParameters = listOf(outerThisValueParameter) + oldConstructor.valueParameters.map { it.copyTo(this, index = it.index + 1) }
|
||||||
|
|
||||||
oldConstructor.valueParameters.mapTo(valueParameters) { it.copyTo(this, index = it.index + 1) }
|
|
||||||
metadata = oldConstructor.metadata
|
metadata = oldConstructor.metadata
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -267,9 +265,9 @@ class JvmDeclarationFactory(
|
|||||||
).apply {
|
).apply {
|
||||||
descriptor.bind(this)
|
descriptor.bind(this)
|
||||||
parent = irClass
|
parent = irClass
|
||||||
overriddenSymbols.addAll(fakeOverride.overriddenSymbols)
|
overriddenSymbols = fakeOverride.overriddenSymbols
|
||||||
copyParameterDeclarationsFrom(fakeOverride)
|
copyParameterDeclarationsFrom(fakeOverride)
|
||||||
annotations.addAll(fakeOverride.annotations)
|
annotations = fakeOverride.annotations
|
||||||
fakeOverride.correspondingPropertySymbol?.owner?.let { fakeOverrideProperty ->
|
fakeOverride.correspondingPropertySymbol?.owner?.let { fakeOverrideProperty ->
|
||||||
// NB: property is only generated for the sake of the type mapper.
|
// NB: property is only generated for the sake of the type mapper.
|
||||||
// If both setter and getter are present, original property will be duplicated.
|
// If both setter and getter are present, original property will be duplicated.
|
||||||
|
|||||||
+4
-5
@@ -58,7 +58,7 @@ class JvmSharedVariablesManager(
|
|||||||
}.apply {
|
}.apply {
|
||||||
parent = jvmInternalPackage
|
parent = jvmInternalPackage
|
||||||
jvmInternalPackage.addChild(this)
|
jvmInternalPackage.addChild(this)
|
||||||
superTypes.add(irBuiltIns.anyType)
|
superTypes += irBuiltIns.anyType
|
||||||
}
|
}
|
||||||
|
|
||||||
private abstract class RefProvider {
|
private abstract class RefProvider {
|
||||||
@@ -96,7 +96,7 @@ class JvmSharedVariablesManager(
|
|||||||
}.apply {
|
}.apply {
|
||||||
parent = refNamespaceClass
|
parent = refNamespaceClass
|
||||||
refNamespaceClass.addMember(this)
|
refNamespaceClass.addMember(this)
|
||||||
superTypes.add(irBuiltIns.anyType)
|
superTypes += irBuiltIns.anyType
|
||||||
thisReceiver = buildValueParameter {
|
thisReceiver = buildValueParameter {
|
||||||
type = IrSimpleTypeImpl(symbol, hasQuestionMark = false, arguments = emptyList(), annotations = emptyList())
|
type = IrSimpleTypeImpl(symbol, hasQuestionMark = false, arguments = emptyList(), annotations = emptyList())
|
||||||
name = Name.identifier("$this")
|
name = Name.identifier("$this")
|
||||||
@@ -118,7 +118,7 @@ class JvmSharedVariablesManager(
|
|||||||
name = Name.identifier("ObjectRef")
|
name = Name.identifier("ObjectRef")
|
||||||
}.apply {
|
}.apply {
|
||||||
val irClass = this
|
val irClass = this
|
||||||
typeParameters.add(
|
typeParameters +=
|
||||||
IrTypeParameterImpl(
|
IrTypeParameterImpl(
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||||
SHARED_VARIABLE_ORIGIN,
|
SHARED_VARIABLE_ORIGIN,
|
||||||
@@ -132,10 +132,9 @@ class JvmSharedVariablesManager(
|
|||||||
parent = irClass
|
parent = irClass
|
||||||
superTypes.add(irBuiltIns.anyNType)
|
superTypes.add(irBuiltIns.anyNType)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
parent = refNamespaceClass
|
parent = refNamespaceClass
|
||||||
refNamespaceClass.addMember(this)
|
refNamespaceClass.addMember(this)
|
||||||
superTypes.add(irBuiltIns.anyType)
|
superTypes += irBuiltIns.anyType
|
||||||
thisReceiver = buildValueParameter {
|
thisReceiver = buildValueParameter {
|
||||||
type = IrSimpleTypeImpl(
|
type = IrSimpleTypeImpl(
|
||||||
symbol,
|
symbol,
|
||||||
|
|||||||
+9
-10
@@ -138,7 +138,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
|
|||||||
copyAttributes(info.reference)
|
copyAttributes(info.reference)
|
||||||
copyTypeParametersFrom(info.function)
|
copyTypeParametersFrom(info.function)
|
||||||
val functionNClass = context.ir.symbols.getJvmFunctionClass(info.arity + 1)
|
val functionNClass = context.ir.symbols.getJvmFunctionClass(info.arity + 1)
|
||||||
superTypes.add(
|
superTypes +=
|
||||||
IrSimpleTypeImpl(
|
IrSimpleTypeImpl(
|
||||||
functionNClass,
|
functionNClass,
|
||||||
hasQuestionMark = false,
|
hasQuestionMark = false,
|
||||||
@@ -147,7 +147,6 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
|
|||||||
.map { makeTypeProjection(it, Variance.INVARIANT) },
|
.map { makeTypeProjection(it, Variance.INVARIANT) },
|
||||||
annotations = emptyList()
|
annotations = emptyList()
|
||||||
)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
addField(COROUTINE_LABEL_FIELD_NAME, context.irBuiltIns.intType)
|
addField(COROUTINE_LABEL_FIELD_NAME, context.irBuiltIns.intType)
|
||||||
|
|
||||||
@@ -217,7 +216,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
|
|||||||
Modality.FINAL,
|
Modality.FINAL,
|
||||||
origin = JvmLoweredDeclarationOrigin.FOR_INLINE_STATE_MACHINE_TEMPLATE
|
origin = JvmLoweredDeclarationOrigin.FOR_INLINE_STATE_MACHINE_TEMPLATE
|
||||||
).apply {
|
).apply {
|
||||||
invokeSuspend.valueParameters.mapTo(valueParameters) { it.copyTo(this) }
|
valueParameters += invokeSuspend.valueParameters.map { it.copyTo(this) }
|
||||||
}.also { it.copySuspendLambdaBodyFrom(irFunction, receiverField, fields) }
|
}.also { it.copySuspendLambdaBodyFrom(irFunction, receiverField, fields) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -268,8 +267,8 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
|
|||||||
modality: Modality = Modality.FINAL
|
modality: Modality = Modality.FINAL
|
||||||
): IrSimpleFunction =
|
): IrSimpleFunction =
|
||||||
addFunction(function.name.asString(), function.returnType, modality).apply {
|
addFunction(function.name.asString(), function.returnType, modality).apply {
|
||||||
overriddenSymbols.add(function.symbol)
|
overriddenSymbols += function.symbol
|
||||||
function.valueParameters.mapTo(valueParameters) { it.copyTo(this) }
|
valueParameters += function.valueParameters.map { it.copyTo(this) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Invoke function in lambdas is responsible for
|
// Invoke function in lambdas is responsible for
|
||||||
@@ -394,7 +393,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
|
|||||||
visibility = newVisibility
|
visibility = newVisibility
|
||||||
}.also { irClass ->
|
}.also { irClass ->
|
||||||
irClass.createImplicitParameterDeclarationWithWrappedDescriptor()
|
irClass.createImplicitParameterDeclarationWithWrappedDescriptor()
|
||||||
irClass.superTypes.add(defaultType)
|
irClass.superTypes += defaultType
|
||||||
|
|
||||||
irClass.parent = parent
|
irClass.parent = parent
|
||||||
}
|
}
|
||||||
@@ -622,7 +621,7 @@ private class AddContinuationLowering(private val context: JvmBackendContext) :
|
|||||||
copyTypeParameters(view.typeParameters)
|
copyTypeParameters(view.typeParameters)
|
||||||
dispatchReceiverParameter = view.dispatchReceiverParameter?.copyTo(this)
|
dispatchReceiverParameter = view.dispatchReceiverParameter?.copyTo(this)
|
||||||
extensionReceiverParameter = view.extensionReceiverParameter?.copyTo(this)
|
extensionReceiverParameter = view.extensionReceiverParameter?.copyTo(this)
|
||||||
view.valueParameters.mapTo(valueParameters) { it.copyTo(this) }
|
valueParameters += view.valueParameters.map { it.copyTo(this) }
|
||||||
body = view.copyBodyTo(this)
|
body = view.copyBodyTo(this)
|
||||||
copyAttributes(view)
|
copyAttributes(view)
|
||||||
}
|
}
|
||||||
@@ -758,15 +757,15 @@ private fun IrFunction.suspendFunctionStub(context: JvmBackendContext): IrFuncti
|
|||||||
}.also { function ->
|
}.also { function ->
|
||||||
function.parent = parent
|
function.parent = parent
|
||||||
|
|
||||||
function.annotations.addAll(annotations)
|
function.annotations += annotations
|
||||||
function.metadata = metadata
|
function.metadata = metadata
|
||||||
|
|
||||||
function.copyAttributes(this)
|
function.copyAttributes(this)
|
||||||
function.copyTypeParametersFrom(this)
|
function.copyTypeParametersFrom(this)
|
||||||
|
|
||||||
if (origin != JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE) {
|
if (origin != JvmLoweredDeclarationOrigin.DEFAULT_IMPLS_BRIDGE) {
|
||||||
function.overriddenSymbols
|
function.overriddenSymbols +=
|
||||||
.addAll(overriddenSymbols.map { it.owner.suspendFunctionViewOrStub(context).symbol as IrSimpleFunctionSymbol })
|
overriddenSymbols.map { it.owner.suspendFunctionViewOrStub(context).symbol as IrSimpleFunctionSymbol }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Copy the value parameters and insert the continuation parameter. The continuation parameter
|
// Copy the value parameters and insert the continuation parameter. The continuation parameter
|
||||||
|
|||||||
+3
-6
@@ -137,11 +137,10 @@ private class AdditionalClassAnnotationLowering(private val context: JvmBackendC
|
|||||||
irClass.hasAnnotation(FqName("java.lang.annotation.Documented"))
|
irClass.hasAnnotation(FqName("java.lang.annotation.Documented"))
|
||||||
) return
|
) return
|
||||||
|
|
||||||
irClass.annotations.add(
|
irClass.annotations +=
|
||||||
IrConstructorCallImpl.fromSymbolOwner(
|
IrConstructorCallImpl.fromSymbolOwner(
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, documentedConstructor.returnType, documentedConstructor.symbol, 0
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET, documentedConstructor.returnType, documentedConstructor.symbol, 0
|
||||||
)
|
)
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val annotationRetentionMap = mapOf(
|
private val annotationRetentionMap = mapOf(
|
||||||
@@ -158,7 +157,7 @@ private class AdditionalClassAnnotationLowering(private val context: JvmBackendC
|
|||||||
val kotlinRetentionPolicy = kotlinRetentionPolicyName?.let { KotlinRetention.valueOf(it) }
|
val kotlinRetentionPolicy = kotlinRetentionPolicyName?.let { KotlinRetention.valueOf(it) }
|
||||||
val javaRetentionPolicy = kotlinRetentionPolicy?.let { annotationRetentionMap[it] } ?: rpRuntime
|
val javaRetentionPolicy = kotlinRetentionPolicy?.let { annotationRetentionMap[it] } ?: rpRuntime
|
||||||
|
|
||||||
irClass.annotations.add(
|
irClass.annotations +=
|
||||||
IrConstructorCallImpl.fromSymbolOwner(
|
IrConstructorCallImpl.fromSymbolOwner(
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, retentionConstructor.returnType, retentionConstructor.symbol, 0
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET, retentionConstructor.returnType, retentionConstructor.symbol, 0
|
||||||
).apply {
|
).apply {
|
||||||
@@ -169,7 +168,6 @@ private class AdditionalClassAnnotationLowering(private val context: JvmBackendC
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private val jvm6TargetMap = mutableMapOf(
|
private val jvm6TargetMap = mutableMapOf(
|
||||||
@@ -221,13 +219,12 @@ private class AdditionalClassAnnotationLowering(private val context: JvmBackendC
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
irClass.annotations.add(
|
irClass.annotations +=
|
||||||
IrConstructorCallImpl.fromSymbolOwner(
|
IrConstructorCallImpl.fromSymbolOwner(
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, targetConstructor.returnType, targetConstructor.symbol, 0
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET, targetConstructor.returnType, targetConstructor.symbol, 0
|
||||||
).apply {
|
).apply {
|
||||||
putValueArgument(0, vararg)
|
putValueArgument(0, vararg)
|
||||||
}
|
}
|
||||||
)
|
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+13
-11
@@ -205,8 +205,8 @@ private class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass
|
|||||||
// For lambda classes, we move override from the `invoke` function to its bridge. This will allow us to avoid boxing
|
// For lambda classes, we move override from the `invoke` function to its bridge. This will allow us to avoid boxing
|
||||||
// the return type of `invoke` in codegen, in case lambda's return type is primitive.
|
// the return type of `invoke` in codegen, in case lambda's return type is primitive.
|
||||||
if (method.name == OperatorNameConventions.INVOKE && irClass.origin == JvmLoweredDeclarationOrigin.LAMBDA_IMPL) {
|
if (method.name == OperatorNameConventions.INVOKE && irClass.origin == JvmLoweredDeclarationOrigin.LAMBDA_IMPL) {
|
||||||
target.overriddenSymbols.remove(method.symbol)
|
target.overriddenSymbols = target.overriddenSymbols.filter { it != method.symbol }
|
||||||
bridge.overriddenSymbols.add(method.symbol)
|
bridge.overriddenSymbols += method.symbol
|
||||||
}
|
}
|
||||||
|
|
||||||
signaturesToSkip.add(signature)
|
signaturesToSkip.add(signature)
|
||||||
@@ -227,7 +227,7 @@ private class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass
|
|||||||
parent = this@copyRenamingTo.parent
|
parent = this@copyRenamingTo.parent
|
||||||
dispatchReceiverParameter = this@copyRenamingTo.dispatchReceiverParameter?.copyTo(this)
|
dispatchReceiverParameter = this@copyRenamingTo.dispatchReceiverParameter?.copyTo(this)
|
||||||
extensionReceiverParameter = this@copyRenamingTo.extensionReceiverParameter?.copyTo(this)
|
extensionReceiverParameter = this@copyRenamingTo.extensionReceiverParameter?.copyTo(this)
|
||||||
valueParameters.addAll(this@copyRenamingTo.valueParameters.map { it.copyTo(this) })
|
valueParameters = this@copyRenamingTo.valueParameters.map { it.copyTo(this) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,8 +267,8 @@ private class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass
|
|||||||
dispatchReceiverParameter = irClass.thisReceiver?.copyTo(this, type = irClass.defaultType)
|
dispatchReceiverParameter = irClass.thisReceiver?.copyTo(this, type = irClass.defaultType)
|
||||||
extensionReceiverParameter = signatureFunction.extensionReceiverParameter
|
extensionReceiverParameter = signatureFunction.extensionReceiverParameter
|
||||||
?.copyWithTypeErasure(this)
|
?.copyWithTypeErasure(this)
|
||||||
signatureFunction.valueParameters.mapIndexed { i, param ->
|
valueParameters = signatureFunction.valueParameters.map { param ->
|
||||||
valueParameters.add(i, param.copyWithTypeErasure(this))
|
param.copyWithTypeErasure(this)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -304,12 +304,13 @@ private class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass
|
|||||||
body = irBlockBody {
|
body = irBlockBody {
|
||||||
// Change the parameter types to be Any? so that null checks are not generated. The checks
|
// Change the parameter types to be Any? so that null checks are not generated. The checks
|
||||||
// we insert here make them superfluous.
|
// we insert here make them superfluous.
|
||||||
|
val newValueParameters = ArrayList(valueParameters)
|
||||||
argumentsToCheck.forEach {
|
argumentsToCheck.forEach {
|
||||||
val parameterType = it.type
|
val parameterType = it.type
|
||||||
if (!parameterType.isNullable()) {
|
if (!parameterType.isNullable()) {
|
||||||
val newParameter = it.copyTo(this@rewriteSpecialMethodBody, type = context.irBuiltIns.anyNType)
|
val newParameter = it.copyTo(this@rewriteSpecialMethodBody, type = context.irBuiltIns.anyNType)
|
||||||
variableMap.put(valueParameters[it.index], newParameter)
|
variableMap.put(valueParameters[it.index], newParameter)
|
||||||
valueParameters[it.index] = newParameter
|
newValueParameters[it.index] = newParameter
|
||||||
addParameterTypeCheck(
|
addParameterTypeCheck(
|
||||||
newParameter,
|
newParameter,
|
||||||
parameterType,
|
parameterType,
|
||||||
@@ -318,6 +319,7 @@ private class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
valueParameters = newValueParameters
|
||||||
// After the checks, insert the orignal method body.
|
// After the checks, insert the orignal method body.
|
||||||
if (body is IrExpressionBody) {
|
if (body is IrExpressionBody) {
|
||||||
+irReturn((body as IrExpressionBody).expression)
|
+irReturn((body as IrExpressionBody).expression)
|
||||||
@@ -330,11 +332,13 @@ private class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass
|
|||||||
} else {
|
} else {
|
||||||
// If the signature of this method will be changed in the output to take a boxed argument instead of a primitive,
|
// If the signature of this method will be changed in the output to take a boxed argument instead of a primitive,
|
||||||
// rewrite the argument so that code will be generated for a boxed argument and not a primitive.
|
// rewrite the argument so that code will be generated for a boxed argument and not a primitive.
|
||||||
for ((i, p) in valueParameters.withIndex()) {
|
valueParameters = valueParameters.mapIndexed { i, p ->
|
||||||
if (AsmUtil.isPrimitive(context.typeMapper.mapType(p.type)) && ourSignature.argumentTypes[i].sort == Type.OBJECT) {
|
if (AsmUtil.isPrimitive(context.typeMapper.mapType(p.type)) && ourSignature.argumentTypes[i].sort == Type.OBJECT) {
|
||||||
val newParameter = p.copyTo(this, type = p.type.makeNullable())
|
val newParameter = p.copyTo(this, type = p.type.makeNullable())
|
||||||
variableMap[p] = newParameter
|
variableMap[p] = newParameter
|
||||||
valueParameters[i] = newParameter
|
newParameter
|
||||||
|
} else {
|
||||||
|
p
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -408,9 +412,7 @@ private class BridgeLowering(val context: JvmBackendContext) : ClassLoweringPass
|
|||||||
copyTypeParametersFrom(this@orphanedCopy)
|
copyTypeParametersFrom(this@orphanedCopy)
|
||||||
this@orphanedCopy.dispatchReceiverParameter?.let { dispatchReceiverParameter = it.copyTo(this) }
|
this@orphanedCopy.dispatchReceiverParameter?.let { dispatchReceiverParameter = it.copyTo(this) }
|
||||||
this@orphanedCopy.extensionReceiverParameter?.let { extensionReceiverParameter = it.copyTo(this) }
|
this@orphanedCopy.extensionReceiverParameter?.let { extensionReceiverParameter = it.copyTo(this) }
|
||||||
this@orphanedCopy.valueParameters.forEachIndexed { index, param ->
|
valueParameters = this@orphanedCopy.valueParameters.map { it.copyTo(this) }
|
||||||
valueParameters.add(index, param.copyTo(this))
|
|
||||||
}
|
|
||||||
/* Do NOT copy overriddenSymbols */
|
/* Do NOT copy overriddenSymbols */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-5
@@ -57,7 +57,7 @@ private class CollectionStubMethodLowering(val context: JvmBackendContext) : Cla
|
|||||||
if (existingMethod != null) {
|
if (existingMethod != null) {
|
||||||
// In the case that we find a defined method that matches the stub signature, we add the overridden symbols to that
|
// In the case that we find a defined method that matches the stub signature, we add the overridden symbols to that
|
||||||
// defined method, so that bridge lowering can still generate correct bridge for that method
|
// defined method, so that bridge lowering can still generate correct bridge for that method
|
||||||
existingMethod.overriddenSymbols.addAll(member.overriddenSymbols)
|
existingMethod.overriddenSymbols += member.overriddenSymbols
|
||||||
} else {
|
} else {
|
||||||
irClass.declarations.add(member)
|
irClass.declarations.add(member)
|
||||||
}
|
}
|
||||||
@@ -78,13 +78,11 @@ private class CollectionStubMethodLowering(val context: JvmBackendContext) : Cla
|
|||||||
}.apply {
|
}.apply {
|
||||||
// Replace Function metadata with the data from class
|
// Replace Function metadata with the data from class
|
||||||
// Add the abstract function symbol to stub function for bridge lowering
|
// Add the abstract function symbol to stub function for bridge lowering
|
||||||
overriddenSymbols.add(function.symbol)
|
overriddenSymbols = listOf(function.symbol)
|
||||||
parent = irClass
|
parent = irClass
|
||||||
dispatchReceiverParameter = function.dispatchReceiverParameter?.copyWithSubstitution(this, substitutionMap)
|
dispatchReceiverParameter = function.dispatchReceiverParameter?.copyWithSubstitution(this, substitutionMap)
|
||||||
extensionReceiverParameter = function.extensionReceiverParameter?.copyWithSubstitution(this, substitutionMap)
|
extensionReceiverParameter = function.extensionReceiverParameter?.copyWithSubstitution(this, substitutionMap)
|
||||||
for (parameter in function.valueParameters) {
|
valueParameters = function.valueParameters.map { it.copyWithSubstitution(this, substitutionMap) }
|
||||||
valueParameters.add(parameter.copyWithSubstitution(this, substitutionMap))
|
|
||||||
}
|
|
||||||
// Function body consist only of throwing UnsupportedOperationException statement
|
// Function body consist only of throwing UnsupportedOperationException statement
|
||||||
body = context.createIrBuilder(function.symbol).irBlockBody {
|
body = context.createIrBuilder(function.symbol).irBlockBody {
|
||||||
+irThrow(
|
+irThrow(
|
||||||
|
|||||||
+1
-1
@@ -119,7 +119,7 @@ private class EnumClassLowering(val context: JvmBackendContext) : ClassLoweringP
|
|||||||
addValueParameter(
|
addValueParameter(
|
||||||
"\$enum\$ordinal", context.irBuiltIns.intType, JvmLoweredDeclarationOrigin.ENUM_CONSTRUCTOR_SYNTHETIC_PARAMETER
|
"\$enum\$ordinal", context.irBuiltIns.intType, JvmLoweredDeclarationOrigin.ENUM_CONSTRUCTOR_SYNTHETIC_PARAMETER
|
||||||
)
|
)
|
||||||
declaration.valueParameters.mapTo(valueParameters) { param ->
|
valueParameters += declaration.valueParameters.map { param ->
|
||||||
param.copyTo(this, index = param.index + 2).also { newParam ->
|
param.copyTo(this, index = param.index + 2).also { newParam ->
|
||||||
loweredEnumConstructorParameters[param.symbol] = newParam
|
loweredEnumConstructorParameters[param.symbol] = newParam
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -111,7 +111,7 @@ private class FileClassLowering(val context: JvmBackendContext) : FileLoweringPa
|
|||||||
isFun = false
|
isFun = false
|
||||||
).apply {
|
).apply {
|
||||||
descriptor.bind(this)
|
descriptor.bind(this)
|
||||||
superTypes.add(context.irBuiltIns.anyType)
|
superTypes += context.irBuiltIns.anyType
|
||||||
parent = irFile
|
parent = irFile
|
||||||
declarations.addAll(fileClassMembers)
|
declarations.addAll(fileClassMembers)
|
||||||
createImplicitParameterDeclarationWithWrappedDescriptor()
|
createImplicitParameterDeclarationWithWrappedDescriptor()
|
||||||
|
|||||||
+2
-2
@@ -81,7 +81,7 @@ private class FunctionNVarargBridgeLowering(val context: JvmBackendContext) :
|
|||||||
|
|
||||||
// Fix super class
|
// Fix super class
|
||||||
val superType = bigArityFunctionSuperTypes.single()
|
val superType = bigArityFunctionSuperTypes.single()
|
||||||
declaration.superTypes.remove(superType)
|
declaration.superTypes -= superType
|
||||||
declaration.superTypes += context.ir.symbols.functionN.typeWith(
|
declaration.superTypes += context.ir.symbols.functionN.typeWith(
|
||||||
(superType.arguments.last() as IrTypeProjection).type
|
(superType.arguments.last() as IrTypeProjection).type
|
||||||
)
|
)
|
||||||
@@ -90,7 +90,7 @@ private class FunctionNVarargBridgeLowering(val context: JvmBackendContext) :
|
|||||||
val invokeFunction = declaration.functions.single {
|
val invokeFunction = declaration.functions.single {
|
||||||
it.name.asString() == "invoke" && it.valueParameters.size == superType.arguments.size - if (it.isSuspend) 0 else 1
|
it.name.asString() == "invoke" && it.valueParameters.size == superType.arguments.size - if (it.isSuspend) 0 else 1
|
||||||
}
|
}
|
||||||
invokeFunction.overriddenSymbols.clear()
|
invokeFunction.overriddenSymbols = emptyList()
|
||||||
declaration.addBridge(invokeFunction, functionNInvokeFun.owner)
|
declaration.addBridge(invokeFunction, functionNInvokeFun.owner)
|
||||||
|
|
||||||
return declaration
|
return declaration
|
||||||
|
|||||||
+3
-5
@@ -123,7 +123,7 @@ private fun generateMultifileFacades(
|
|||||||
}
|
}
|
||||||
if (shouldGeneratePartHierarchy) {
|
if (shouldGeneratePartHierarchy) {
|
||||||
val superClass = modifyMultifilePartsForHierarchy(context, partClasses)
|
val superClass = modifyMultifilePartsForHierarchy(context, partClasses)
|
||||||
superTypes.add(superClass.typeWith())
|
superTypes += superClass.typeWith()
|
||||||
|
|
||||||
addConstructor {
|
addConstructor {
|
||||||
visibility = Visibilities.PRIVATE
|
visibility = Visibilities.PRIVATE
|
||||||
@@ -165,8 +165,7 @@ private fun modifyMultifilePartsForHierarchy(context: JvmBackendContext, unsorte
|
|||||||
klass.modality = Modality.OPEN
|
klass.modality = Modality.OPEN
|
||||||
klass.visibility = JavaVisibilities.PACKAGE_VISIBILITY
|
klass.visibility = JavaVisibilities.PACKAGE_VISIBILITY
|
||||||
|
|
||||||
klass.superTypes.clear()
|
klass.superTypes = listOf(superClass.typeWith())
|
||||||
klass.superTypes.add(superClass.typeWith())
|
|
||||||
|
|
||||||
klass.addConstructor {
|
klass.addConstructor {
|
||||||
isPrimary = true
|
isPrimary = true
|
||||||
@@ -211,8 +210,7 @@ private fun IrSimpleFunction.createMultifileDelegateIfNeeded(
|
|||||||
if (shouldGeneratePartHierarchy) {
|
if (shouldGeneratePartHierarchy) {
|
||||||
function.body = null
|
function.body = null
|
||||||
function.origin = IrDeclarationOrigin.FAKE_OVERRIDE
|
function.origin = IrDeclarationOrigin.FAKE_OVERRIDE
|
||||||
function.overriddenSymbols.clear()
|
function.overriddenSymbols = listOf(symbol)
|
||||||
function.overriddenSymbols.add(symbol)
|
|
||||||
} else {
|
} else {
|
||||||
function.body = context.createIrBuilder(function.symbol).irBlockBody {
|
function.body = context.createIrBuilder(function.symbol).irBlockBody {
|
||||||
+irReturn(irCall(this@createMultifileDelegateIfNeeded).also { call ->
|
+irReturn(irCall(this@createMultifileDelegateIfNeeded).also { call ->
|
||||||
|
|||||||
+1
-1
@@ -70,7 +70,7 @@ private class InheritedDefaultMethodsOnClassesLowering(val context: JvmBackendCo
|
|||||||
// Here we use the same logic as the delegation itself (`getTargetForRedirection`) to determine
|
// Here we use the same logic as the delegation itself (`getTargetForRedirection`) to determine
|
||||||
// if the overriden symbol has been, or will be, replaced and patch it accordingly.
|
// if the overriden symbol has been, or will be, replaced and patch it accordingly.
|
||||||
override fun visitSimpleFunction(declaration: IrSimpleFunction) {
|
override fun visitSimpleFunction(declaration: IrSimpleFunction) {
|
||||||
declaration.overriddenSymbols.replaceAll { symbol ->
|
declaration.overriddenSymbols = declaration.overriddenSymbols.map { symbol ->
|
||||||
if (symbol.owner.findInterfaceImplementation() != null)
|
if (symbol.owner.findInterfaceImplementation() != null)
|
||||||
context.declarationFactory.getDefaultImplsRedirection(symbol.owner).symbol
|
context.declarationFactory.getDefaultImplsRedirection(symbol.owner).symbol
|
||||||
else symbol
|
else symbol
|
||||||
|
|||||||
+1
-1
@@ -53,7 +53,7 @@ private class JvmDefaultConstructorLowering(val context: JvmBackendContext) : Cl
|
|||||||
visibility = primaryConstructor.visibility
|
visibility = primaryConstructor.visibility
|
||||||
}.apply {
|
}.apply {
|
||||||
val irBuilder = context.createIrBuilder(this.symbol, startOffset, endOffset)
|
val irBuilder = context.createIrBuilder(this.symbol, startOffset, endOffset)
|
||||||
primaryConstructor.annotations.mapTo(annotations) { it.deepCopyWithSymbols(this) }
|
annotations += primaryConstructor.annotations.map { it.deepCopyWithSymbols(this) }
|
||||||
body = irBuilder.irBlockBody {
|
body = irBuilder.irBlockBody {
|
||||||
+irDelegatingConstructorCall(primaryConstructor).apply {
|
+irDelegatingConstructorCall(primaryConstructor).apply {
|
||||||
passTypeArgumentsFrom(irClass)
|
passTypeArgumentsFrom(irClass)
|
||||||
|
|||||||
+2
-2
@@ -165,11 +165,11 @@ private class JvmOverloadsAnnotationLowering(val context: JvmBackendContext) : C
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.parent = oldFunction.parent
|
res.parent = oldFunction.parent
|
||||||
res.annotations.addAll(oldFunction.annotations.map { it.deepCopyWithSymbols(res) })
|
res.annotations += oldFunction.annotations.map { it.deepCopyWithSymbols(res) }
|
||||||
res.copyTypeParametersFrom(oldFunction)
|
res.copyTypeParametersFrom(oldFunction)
|
||||||
res.dispatchReceiverParameter = oldFunction.dispatchReceiverParameter?.copyTo(res)
|
res.dispatchReceiverParameter = oldFunction.dispatchReceiverParameter?.copyTo(res)
|
||||||
res.extensionReceiverParameter = oldFunction.extensionReceiverParameter?.copyTo(res)
|
res.extensionReceiverParameter = oldFunction.extensionReceiverParameter?.copyTo(res)
|
||||||
res.valueParameters.addAll(res.generateNewValueParameters(oldFunction, numDefaultParametersToExpect))
|
res.valueParameters += res.generateNewValueParameters(oldFunction, numDefaultParametersToExpect)
|
||||||
return res
|
return res
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -83,7 +83,7 @@ class JvmPropertiesLowering(private val context: JvmBackendContext) : IrElementT
|
|||||||
body = IrBlockBodyImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET)
|
body = IrBlockBodyImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET)
|
||||||
parent = declaration.parent
|
parent = declaration.parent
|
||||||
|
|
||||||
annotations.addAll(declaration.annotations)
|
annotations = declaration.annotations
|
||||||
metadata = declaration.metadata
|
metadata = declaration.metadata
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -120,9 +120,9 @@ private class CompanionObjectJvmStaticLowering(val context: JvmBackendContext) :
|
|||||||
parent = irClass
|
parent = irClass
|
||||||
copyTypeParametersFrom(target)
|
copyTypeParametersFrom(target)
|
||||||
target.extensionReceiverParameter?.let { extensionReceiverParameter = it.copyTo(this) }
|
target.extensionReceiverParameter?.let { extensionReceiverParameter = it.copyTo(this) }
|
||||||
target.valueParameters.mapTo(valueParameters) { it.copyTo(this) }
|
valueParameters = target.valueParameters.map { it.copyTo(this) }
|
||||||
|
|
||||||
target.annotations.mapTo(annotations) { it.deepCopyWithSymbols() }
|
annotations = target.annotations.map { it.deepCopyWithSymbols() }
|
||||||
|
|
||||||
body = createProxyBody(target, this, companion)
|
body = createProxyBody(target, this, companion)
|
||||||
}
|
}
|
||||||
@@ -241,7 +241,7 @@ private class MakeCallsStatic(
|
|||||||
newDescriptor.bind(it)
|
newDescriptor.bind(it)
|
||||||
it.parent = parent
|
it.parent = parent
|
||||||
it.correspondingPropertySymbol = correspondingPropertySymbol
|
it.correspondingPropertySymbol = correspondingPropertySymbol
|
||||||
it.annotations.addAll(annotations)
|
it.annotations += annotations
|
||||||
it.copyParameterDeclarationsFrom(this)
|
it.copyParameterDeclarationsFrom(this)
|
||||||
it.dispatchReceiverParameter = null
|
it.dispatchReceiverParameter = null
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-6
@@ -123,10 +123,9 @@ internal class PropertyReferenceLowering(val context: JvmBackendContext) : Class
|
|||||||
modality = Modality.OPEN
|
modality = Modality.OPEN
|
||||||
origin = JvmLoweredDeclarationOrigin.GENERATED_MEMBER_IN_CALLABLE_REFERENCE
|
origin = JvmLoweredDeclarationOrigin.GENERATED_MEMBER_IN_CALLABLE_REFERENCE
|
||||||
}.apply {
|
}.apply {
|
||||||
overriddenSymbols.add(method.symbol)
|
overriddenSymbols += method.symbol
|
||||||
dispatchReceiverParameter = thisReceiver!!.copyTo(this)
|
dispatchReceiverParameter = thisReceiver!!.copyTo(this)
|
||||||
for (parameter in method.valueParameters)
|
valueParameters = method.valueParameters.map { it.copyTo(this) }
|
||||||
valueParameters.add(parameter.copyTo(this))
|
|
||||||
body = context.createIrBuilder(symbol, startOffset, endOffset).run {
|
body = context.createIrBuilder(symbol, startOffset, endOffset).run {
|
||||||
irExprBody(buildBody(listOf(dispatchReceiverParameter!!) + valueParameters))
|
irExprBody(buildBody(listOf(dispatchReceiverParameter!!) + valueParameters))
|
||||||
}
|
}
|
||||||
@@ -139,10 +138,9 @@ internal class PropertyReferenceLowering(val context: JvmBackendContext) : Class
|
|||||||
visibility = method.visibility
|
visibility = method.visibility
|
||||||
origin = IrDeclarationOrigin.FAKE_OVERRIDE
|
origin = IrDeclarationOrigin.FAKE_OVERRIDE
|
||||||
}.apply {
|
}.apply {
|
||||||
overriddenSymbols.add(method.symbol)
|
overriddenSymbols += method.symbol
|
||||||
dispatchReceiverParameter = thisReceiver!!.copyTo(this)
|
dispatchReceiverParameter = thisReceiver!!.copyTo(this)
|
||||||
for (parameter in method.valueParameters)
|
valueParameters = method.valueParameters.map { it.copyTo(this) }
|
||||||
valueParameters.add(parameter.copyTo(this))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class PropertyReferenceKind(
|
private class PropertyReferenceKind(
|
||||||
|
|||||||
+2
-2
@@ -156,8 +156,8 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
|||||||
accessor.metadata = declaration.metadata
|
accessor.metadata = declaration.metadata
|
||||||
declaration.safeAs<IrConstructorImpl>()?.metadata = null
|
declaration.safeAs<IrConstructorImpl>()?.metadata = null
|
||||||
accessor.annotations += declaration.annotations
|
accessor.annotations += declaration.annotations
|
||||||
declaration.annotations.clear()
|
declaration.annotations = emptyList()
|
||||||
declaration.valueParameters.forEach { it.annotations.clear() }
|
declaration.valueParameters.forEach { it.annotations = emptyList() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -95,7 +95,7 @@ private class ToArrayLowering(private val context: JvmBackendContext) : ClassLow
|
|||||||
irFunction.parent = irClass
|
irFunction.parent = irClass
|
||||||
|
|
||||||
typeParameter.parent = irFunction
|
typeParameter.parent = irFunction
|
||||||
irFunction.typeParameters.add(typeParameter)
|
irFunction.typeParameters += typeParameter
|
||||||
|
|
||||||
val dispatchReceiverParameterDescriptor = WrappedValueParameterDescriptor()
|
val dispatchReceiverParameterDescriptor = WrappedValueParameterDescriptor()
|
||||||
irFunction.dispatchReceiverParameter = IrValueParameterImpl(
|
irFunction.dispatchReceiverParameter = IrValueParameterImpl(
|
||||||
@@ -112,7 +112,7 @@ private class ToArrayLowering(private val context: JvmBackendContext) : ClassLow
|
|||||||
parent = irFunction
|
parent = irFunction
|
||||||
}
|
}
|
||||||
val valueParameterDescriptor = WrappedValueParameterDescriptor()
|
val valueParameterDescriptor = WrappedValueParameterDescriptor()
|
||||||
irFunction.valueParameters.add(
|
irFunction.valueParameters +=
|
||||||
IrValueParameterImpl(
|
IrValueParameterImpl(
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
||||||
JvmLoweredDeclarationOrigin.TO_ARRAY,
|
JvmLoweredDeclarationOrigin.TO_ARRAY,
|
||||||
@@ -127,7 +127,6 @@ private class ToArrayLowering(private val context: JvmBackendContext) : ClassLow
|
|||||||
valueParameterDescriptor.bind(this)
|
valueParameterDescriptor.bind(this)
|
||||||
parent = irFunction
|
parent = irFunction
|
||||||
}
|
}
|
||||||
)
|
|
||||||
|
|
||||||
irFunction.body = context.createIrBuilder(irFunction.symbol).irBlockBody {
|
irFunction.body = context.createIrBuilder(irFunction.symbol).irBlockBody {
|
||||||
+irReturn(
|
+irReturn(
|
||||||
|
|||||||
+1
-1
@@ -50,7 +50,7 @@ class TypeAliasAnnotationMethodsLowering(val context: CommonBackendContext) :
|
|||||||
origin = JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_TYPEALIAS_ANNOTATIONS
|
origin = JvmLoweredDeclarationOrigin.SYNTHETIC_METHOD_FOR_TYPEALIAS_ANNOTATIONS
|
||||||
}.apply {
|
}.apply {
|
||||||
body = IrBlockBodyImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET)
|
body = IrBlockBodyImpl(UNDEFINED_OFFSET, UNDEFINED_OFFSET)
|
||||||
annotations.addAll(alias.annotations)
|
annotations += alias.annotations
|
||||||
metadata = alias.metadata
|
metadata = alias.metadata
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-4
@@ -146,8 +146,9 @@ class MemoizedInlineClassReplacements {
|
|||||||
val parameterMap = mutableMapOf<IrValueParameterSymbol, IrValueParameter>()
|
val parameterMap = mutableMapOf<IrValueParameterSymbol, IrValueParameter>()
|
||||||
val replacement = buildReplacement(function) {
|
val replacement = buildReplacement(function) {
|
||||||
metadata = function.metadata
|
metadata = function.metadata
|
||||||
overriddenSymbols.addAll(overrides)
|
overriddenSymbols += overrides
|
||||||
|
|
||||||
|
val newValueParameters = ArrayList<IrValueParameter>()
|
||||||
for ((index, parameter) in function.explicitParameters.withIndex()) {
|
for ((index, parameter) in function.explicitParameters.withIndex()) {
|
||||||
val name = if (parameter == function.extensionReceiverParameter) Name.identifier("\$receiver") else parameter.name
|
val name = if (parameter == function.extensionReceiverParameter) Name.identifier("\$receiver") else parameter.name
|
||||||
val newParameter: IrValueParameter
|
val newParameter: IrValueParameter
|
||||||
@@ -156,13 +157,14 @@ class MemoizedInlineClassReplacements {
|
|||||||
dispatchReceiverParameter = newParameter
|
dispatchReceiverParameter = newParameter
|
||||||
} else {
|
} else {
|
||||||
newParameter = parameter.copyTo(this, index = index - 1, name = name, defaultValue = null)
|
newParameter = parameter.copyTo(this, index = index - 1, name = name, defaultValue = null)
|
||||||
valueParameters.add(newParameter)
|
newValueParameters += newParameter
|
||||||
}
|
}
|
||||||
// Assuming that constructors and non-override functions are always replaced with the unboxed
|
// Assuming that constructors and non-override functions are always replaced with the unboxed
|
||||||
// equivalent, deep-copying the value here is unnecessary. See `JvmInlineClassLowering`.
|
// equivalent, deep-copying the value here is unnecessary. See `JvmInlineClassLowering`.
|
||||||
newParameter.defaultValue = parameter.defaultValue?.patchDeclarationParents(this)
|
newParameter.defaultValue = parameter.defaultValue?.patchDeclarationParents(this)
|
||||||
parameterMap[parameter.symbol] = newParameter
|
parameterMap[parameter.symbol] = newParameter
|
||||||
}
|
}
|
||||||
|
valueParameters = newValueParameters
|
||||||
}
|
}
|
||||||
return IrReplacementFunction(replacement, parameterMap)
|
return IrReplacementFunction(replacement, parameterMap)
|
||||||
}
|
}
|
||||||
@@ -176,7 +178,8 @@ class MemoizedInlineClassReplacements {
|
|||||||
function.metadata = null
|
function.metadata = null
|
||||||
}
|
}
|
||||||
|
|
||||||
for ((index, parameter) in function.explicitParameters.withIndex()) {
|
|
||||||
|
valueParameters += function.explicitParameters.mapIndexed { index, parameter ->
|
||||||
val name = when (parameter) {
|
val name = when (parameter) {
|
||||||
function.dispatchReceiverParameter -> Name.identifier("arg$index")
|
function.dispatchReceiverParameter -> Name.identifier("arg$index")
|
||||||
function.extensionReceiverParameter -> Name.identifier("\$this\$${function.name}")
|
function.extensionReceiverParameter -> Name.identifier("\$this\$${function.name}")
|
||||||
@@ -188,10 +191,12 @@ class MemoizedInlineClassReplacements {
|
|||||||
else -> parameter.origin
|
else -> parameter.origin
|
||||||
}
|
}
|
||||||
val newParameter = parameter.copyTo(this, index = index, name = name, defaultValue = null, origin = parameterOrigin)
|
val newParameter = parameter.copyTo(this, index = index, name = name, defaultValue = null, origin = parameterOrigin)
|
||||||
valueParameters.add(newParameter)
|
valueParameters += newParameter
|
||||||
// See comment next to a similar line above.
|
// See comment next to a similar line above.
|
||||||
newParameter.defaultValue = parameter.defaultValue?.patchDeclarationParents(this)
|
newParameter.defaultValue = parameter.defaultValue?.patchDeclarationParents(this)
|
||||||
parameterMap[parameter.symbol] = newParameter
|
parameterMap[parameter.symbol] = newParameter
|
||||||
|
|
||||||
|
newParameter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return IrReplacementFunction(replacement, parameterMap)
|
return IrReplacementFunction(replacement, parameterMap)
|
||||||
|
|||||||
+4
-2
@@ -40,8 +40,10 @@ class AnnotationGenerator(context: GeneratorContext) : IrElementVisitorVoid {
|
|||||||
declaration.descriptor.backingField
|
declaration.descriptor.backingField
|
||||||
else declaration.descriptor
|
else declaration.descriptor
|
||||||
|
|
||||||
annotatedDescriptor?.annotations?.mapNotNullTo(declaration.annotations) {
|
if (annotatedDescriptor != null) {
|
||||||
constantValueGenerator.generateAnnotationConstructorCall(it)
|
declaration.annotations += annotatedDescriptor.annotations.mapNotNull {
|
||||||
|
constantValueGenerator.generateAnnotationConstructorCall(it)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class ClassGenerator(
|
|||||||
).buildWithScope { irClass ->
|
).buildWithScope { irClass ->
|
||||||
declarationGenerator.generateGlobalTypeParametersDeclarations(irClass, classDescriptor.declaredTypeParameters)
|
declarationGenerator.generateGlobalTypeParametersDeclarations(irClass, classDescriptor.declaredTypeParameters)
|
||||||
|
|
||||||
classDescriptor.typeConstructor.supertypes.mapTo(irClass.superTypes) {
|
irClass.superTypes = classDescriptor.typeConstructor.supertypes.map {
|
||||||
it.toIrType()
|
it.toIrType()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -126,7 +126,7 @@ class DeclarationGenerator(override val context: GeneratorContext) : Generator {
|
|||||||
from: List<TypeParameterDescriptor>,
|
from: List<TypeParameterDescriptor>,
|
||||||
declareTypeParameter: (Int, Int, TypeParameterDescriptor) -> IrTypeParameter
|
declareTypeParameter: (Int, Int, TypeParameterDescriptor) -> IrTypeParameter
|
||||||
) {
|
) {
|
||||||
from.mapTo(irTypeParametersOwner.typeParameters) { typeParameterDescriptor ->
|
irTypeParametersOwner.typeParameters += from.map { typeParameterDescriptor ->
|
||||||
val ktTypeParameterDeclaration = DescriptorToSourceUtils.getSourceFromDescriptor(typeParameterDescriptor)
|
val ktTypeParameterDeclaration = DescriptorToSourceUtils.getSourceFromDescriptor(typeParameterDescriptor)
|
||||||
val startOffset = ktTypeParameterDeclaration.startOffsetOrUndefined
|
val startOffset = ktTypeParameterDeclaration.startOffsetOrUndefined
|
||||||
val endOffset = ktTypeParameterDeclaration.endOffsetOrUndefined
|
val endOffset = ktTypeParameterDeclaration.endOffsetOrUndefined
|
||||||
|
|||||||
+1
-1
@@ -286,7 +286,7 @@ class FunctionGenerator(declarationGenerator: DeclarationGenerator) : Declaratio
|
|||||||
val bodyGenerator = createBodyGenerator(irFunction.symbol)
|
val bodyGenerator = createBodyGenerator(irFunction.symbol)
|
||||||
|
|
||||||
// Declare all the value parameters up first.
|
// Declare all the value parameters up first.
|
||||||
functionDescriptor.valueParameters.mapTo(irFunction.valueParameters) { valueParameterDescriptor ->
|
irFunction.valueParameters += functionDescriptor.valueParameters.map { valueParameterDescriptor ->
|
||||||
val ktParameter = DescriptorToSourceUtils.getSourceFromDescriptor(valueParameterDescriptor) as? KtParameter
|
val ktParameter = DescriptorToSourceUtils.getSourceFromDescriptor(valueParameterDescriptor) as? KtParameter
|
||||||
declareParameter(valueParameterDescriptor, ktParameter, irFunction)
|
declareParameter(valueParameterDescriptor, ktParameter, irFunction)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -71,7 +71,9 @@ class ModuleGenerator(override val context: GeneratorContext) : Generator {
|
|||||||
|
|
||||||
for (ktAnnotationEntry in ktFile.annotationEntries) {
|
for (ktAnnotationEntry in ktFile.annotationEntries) {
|
||||||
val annotationDescriptor = getOrFail(BindingContext.ANNOTATION, ktAnnotationEntry)
|
val annotationDescriptor = getOrFail(BindingContext.ANNOTATION, ktAnnotationEntry)
|
||||||
irFile.annotations.addIfNotNull(constantValueGenerator.generateAnnotationConstructorCall(annotationDescriptor))
|
constantValueGenerator.generateAnnotationConstructorCall(annotationDescriptor)?.let {
|
||||||
|
irFile.annotations += it
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (ktDeclaration in ktFile.declarations) {
|
for (ktDeclaration in ktFile.declarations) {
|
||||||
|
|||||||
+1
-1
@@ -379,7 +379,7 @@ class ReflectionReferencesGenerator(statementGenerator: StatementGenerator) : St
|
|||||||
irAdapterFun.dispatchReceiverParameter = null
|
irAdapterFun.dispatchReceiverParameter = null
|
||||||
irAdapterFun.extensionReceiverParameter = null
|
irAdapterFun.extensionReceiverParameter = null
|
||||||
|
|
||||||
ktExpectedParameterTypes.mapIndexedTo(irAdapterFun.valueParameters) { index, ktExpectedParameterType ->
|
irAdapterFun.valueParameters += ktExpectedParameterTypes.mapIndexed { index, ktExpectedParameterType ->
|
||||||
val adapterValueParameterDescriptor = WrappedValueParameterDescriptor()
|
val adapterValueParameterDescriptor = WrappedValueParameterDescriptor()
|
||||||
context.symbolTable.declareValueParameter(
|
context.symbolTable.declareValueParameter(
|
||||||
startOffset, endOffset,
|
startOffset, endOffset,
|
||||||
|
|||||||
+1
-1
@@ -12,5 +12,5 @@ interface IrAnnotationContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface IrMutableAnnotationContainer: IrAnnotationContainer {
|
interface IrMutableAnnotationContainer: IrAnnotationContainer {
|
||||||
override val annotations: MutableList<IrConstructorCall>
|
override var annotations: List<IrConstructorCall>
|
||||||
}
|
}
|
||||||
@@ -41,7 +41,7 @@ interface IrClass :
|
|||||||
val isExpect: Boolean
|
val isExpect: Boolean
|
||||||
val isFun: Boolean
|
val isFun: Boolean
|
||||||
|
|
||||||
val superTypes: MutableList<IrType>
|
var superTypes: List<IrType>
|
||||||
|
|
||||||
var thisReceiver: IrValueParameter?
|
var thisReceiver: IrValueParameter?
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ interface IrSymbolDeclaration<out S : IrSymbol> : IrDeclaration, IrSymbolOwner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
interface IrOverridableDeclaration<S : IrSymbol> : IrDeclaration {
|
interface IrOverridableDeclaration<S : IrSymbol> : IrDeclaration {
|
||||||
val overriddenSymbols: MutableList<S>
|
var overriddenSymbols: List<S>
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IrDeclarationWithVisibility : IrDeclaration {
|
interface IrDeclarationWithVisibility : IrDeclaration {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ interface IrFunction :
|
|||||||
|
|
||||||
var dispatchReceiverParameter: IrValueParameter?
|
var dispatchReceiverParameter: IrValueParameter?
|
||||||
var extensionReceiverParameter: IrValueParameter?
|
var extensionReceiverParameter: IrValueParameter?
|
||||||
val valueParameters: MutableList<IrValueParameter>
|
var valueParameters: List<IrValueParameter>
|
||||||
|
|
||||||
var body: IrBody?
|
var body: IrBody?
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -17,5 +17,5 @@
|
|||||||
package org.jetbrains.kotlin.ir.declarations
|
package org.jetbrains.kotlin.ir.declarations
|
||||||
|
|
||||||
interface IrTypeParametersContainer : IrDeclaration, IrDeclarationParent {
|
interface IrTypeParametersContainer : IrDeclaration, IrDeclarationParent {
|
||||||
val typeParameters: MutableList<IrTypeParameter>
|
var typeParameters: List<IrTypeParameter>
|
||||||
}
|
}
|
||||||
@@ -24,11 +24,12 @@ import org.jetbrains.kotlin.ir.declarations.*
|
|||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.util.transform
|
import org.jetbrains.kotlin.ir.util.transform
|
||||||
|
import org.jetbrains.kotlin.ir.util.mapOptimized
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
import org.jetbrains.kotlin.resolve.descriptorUtil.isEffectivelyExternal
|
||||||
import org.jetbrains.kotlin.utils.SmartList
|
import kotlin.collections.ArrayList
|
||||||
|
|
||||||
class IrClassImpl(
|
class IrClassImpl(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
@@ -81,9 +82,9 @@ class IrClassImpl(
|
|||||||
|
|
||||||
override val declarations: MutableList<IrDeclaration> = ArrayList()
|
override val declarations: MutableList<IrDeclaration> = ArrayList()
|
||||||
|
|
||||||
override val typeParameters: MutableList<IrTypeParameter> = SmartList()
|
override var typeParameters: List<IrTypeParameter> = emptyList()
|
||||||
|
|
||||||
override val superTypes: MutableList<IrType> = SmartList()
|
override var superTypes: List<IrType> = emptyList()
|
||||||
|
|
||||||
override var metadata: MetadataSource? = null
|
override var metadata: MetadataSource? = null
|
||||||
|
|
||||||
@@ -100,7 +101,7 @@ class IrClassImpl(
|
|||||||
|
|
||||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||||
thisReceiver = thisReceiver?.transform(transformer, data)
|
thisReceiver = thisReceiver?.transform(transformer, data)
|
||||||
typeParameters.transform { it.transform(transformer, data) }
|
typeParameters = typeParameters.mapOptimized { it.transform(transformer, data) }
|
||||||
declarations.transform { it.transform(transformer, data) }
|
declarations.transform { it.transform(transformer, data) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -39,7 +39,7 @@ abstract class IrDeclarationBase(
|
|||||||
_parent = v
|
_parent = v
|
||||||
}
|
}
|
||||||
|
|
||||||
override val annotations: MutableList<IrConstructorCall> = ArrayList()
|
override var annotations: List<IrConstructorCall> = emptyList()
|
||||||
|
|
||||||
override val metadata: MetadataSource?
|
override val metadata: MetadataSource?
|
||||||
get() = null
|
get() = null
|
||||||
|
|||||||
@@ -84,7 +84,7 @@ class IrFieldImpl(
|
|||||||
|
|
||||||
override var correspondingPropertySymbol: IrPropertySymbol? = null
|
override var correspondingPropertySymbol: IrPropertySymbol? = null
|
||||||
|
|
||||||
override val overriddenSymbols: MutableList<IrFieldSymbol> = mutableListOf()
|
override var overriddenSymbols: List<IrFieldSymbol> = emptyList()
|
||||||
|
|
||||||
override var metadata: MetadataSource.Property? = null
|
override var metadata: MetadataSource.Property? = null
|
||||||
|
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ class IrFileImpl(
|
|||||||
|
|
||||||
override val declarations: MutableList<IrDeclaration> = ArrayList()
|
override val declarations: MutableList<IrDeclaration> = ArrayList()
|
||||||
|
|
||||||
override val annotations: MutableList<IrConstructorCall> = ArrayList()
|
override var annotations: List<IrConstructorCall> = emptyList()
|
||||||
|
|
||||||
override var metadata: MetadataSource.File? = null
|
override var metadata: MetadataSource.File? = null
|
||||||
|
|
||||||
|
|||||||
@@ -20,11 +20,10 @@ import org.jetbrains.kotlin.descriptors.Visibility
|
|||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrBody
|
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.util.transform
|
import org.jetbrains.kotlin.ir.util.mapOptimized
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.utils.SmartList
|
|
||||||
|
|
||||||
abstract class IrFunctionBase(
|
abstract class IrFunctionBase(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
@@ -48,11 +47,11 @@ abstract class IrFunctionBase(
|
|||||||
field
|
field
|
||||||
}
|
}
|
||||||
|
|
||||||
override val typeParameters: MutableList<IrTypeParameter> = SmartList()
|
override var typeParameters: List<IrTypeParameter> = emptyList()
|
||||||
|
|
||||||
override var dispatchReceiverParameter: IrValueParameter? = null
|
override var dispatchReceiverParameter: IrValueParameter? = null
|
||||||
override var extensionReceiverParameter: IrValueParameter? = null
|
override var extensionReceiverParameter: IrValueParameter? = null
|
||||||
override val valueParameters: MutableList<IrValueParameter> = ArrayList()
|
override var valueParameters: List<IrValueParameter> = emptyList()
|
||||||
|
|
||||||
final override var body: IrBody? = null
|
final override var body: IrBody? = null
|
||||||
|
|
||||||
@@ -69,11 +68,12 @@ abstract class IrFunctionBase(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||||
typeParameters.transform { it.transform(transformer, data) }
|
|
||||||
|
typeParameters = typeParameters.mapOptimized { it.transform(transformer, data) }
|
||||||
|
|
||||||
dispatchReceiverParameter = dispatchReceiverParameter?.transform(transformer, data)
|
dispatchReceiverParameter = dispatchReceiverParameter?.transform(transformer, data)
|
||||||
extensionReceiverParameter = extensionReceiverParameter?.transform(transformer, data)
|
extensionReceiverParameter = extensionReceiverParameter?.transform(transformer, data)
|
||||||
valueParameters.transform { it.transform(transformer, data) }
|
valueParameters = valueParameters.mapOptimized { it.transform(transformer, data) }
|
||||||
|
|
||||||
body = body?.transform(transformer, data)
|
body = body?.transform(transformer, data)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
|||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.utils.SmartList
|
|
||||||
|
|
||||||
class IrFunctionImpl(
|
class IrFunctionImpl(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
@@ -64,7 +63,7 @@ class IrFunctionImpl(
|
|||||||
|
|
||||||
override val descriptor: FunctionDescriptor = symbol.descriptor
|
override val descriptor: FunctionDescriptor = symbol.descriptor
|
||||||
|
|
||||||
override val overriddenSymbols: MutableList<IrSimpleFunctionSymbol> = SmartList()
|
override var overriddenSymbols: List<IrSimpleFunctionSymbol> = emptyList()
|
||||||
override var attributeOwnerId: IrAttributeContainer = this
|
override var attributeOwnerId: IrAttributeContainer = this
|
||||||
|
|
||||||
override var correspondingPropertySymbol: IrPropertySymbol? = null
|
override var correspondingPropertySymbol: IrPropertySymbol? = null
|
||||||
|
|||||||
+3
-5
@@ -11,13 +11,11 @@ import org.jetbrains.kotlin.ir.declarations.IrDeclarationOrigin
|
|||||||
import org.jetbrains.kotlin.ir.declarations.IrTypeAlias
|
import org.jetbrains.kotlin.ir.declarations.IrTypeAlias
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrTypeAliasSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrTypeAliasSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeAliasSymbolImpl
|
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.util.transform
|
import org.jetbrains.kotlin.ir.util.mapOptimized
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.utils.SmartList
|
|
||||||
|
|
||||||
class IrTypeAliasImpl(
|
class IrTypeAliasImpl(
|
||||||
startOffset: Int,
|
startOffset: Int,
|
||||||
@@ -39,7 +37,7 @@ class IrTypeAliasImpl(
|
|||||||
override val descriptor: TypeAliasDescriptor
|
override val descriptor: TypeAliasDescriptor
|
||||||
get() = symbol.descriptor
|
get() = symbol.descriptor
|
||||||
|
|
||||||
override val typeParameters: MutableList<IrTypeParameter> = SmartList()
|
override var typeParameters: List<IrTypeParameter> = emptyList()
|
||||||
|
|
||||||
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
override fun <R, D> accept(visitor: IrElementVisitor<R, D>, data: D): R =
|
||||||
visitor.visitTypeAlias(this, data)
|
visitor.visitTypeAlias(this, data)
|
||||||
@@ -49,7 +47,7 @@ class IrTypeAliasImpl(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||||
typeParameters.transform { it.transform(transformer, data) }
|
typeParameters = typeParameters.mapOptimized { it.transform(transformer, data) }
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import org.jetbrains.kotlin.ir.types.IrType
|
|||||||
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
||||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||||
import org.jetbrains.kotlin.ir.util.transform
|
import org.jetbrains.kotlin.ir.util.transform
|
||||||
|
import org.jetbrains.kotlin.ir.util.mapOptimized
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -92,13 +93,13 @@ class IrLazyClass(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val typeParameters: MutableList<IrTypeParameter> by lazy {
|
override var typeParameters: List<IrTypeParameter> by lazyVar {
|
||||||
descriptor.declaredTypeParameters.mapTo(arrayListOf()) {
|
descriptor.declaredTypeParameters.mapTo(arrayListOf()) {
|
||||||
stubGenerator.generateOrGetTypeParameterStub(it)
|
stubGenerator.generateOrGetTypeParameterStub(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val superTypes: MutableList<IrType> by lazy {
|
override var superTypes: List<IrType> by lazyVar {
|
||||||
typeTranslator.buildWithScope(this) {
|
typeTranslator.buildWithScope(this) {
|
||||||
// TODO get rid of code duplication, see ClassGenerator#generateClass
|
// TODO get rid of code duplication, see ClassGenerator#generateClass
|
||||||
descriptor.typeConstructor.supertypes.mapNotNullTo(arrayListOf()) {
|
descriptor.typeConstructor.supertypes.mapNotNullTo(arrayListOf()) {
|
||||||
@@ -120,7 +121,7 @@ class IrLazyClass(
|
|||||||
|
|
||||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||||
thisReceiver = thisReceiver?.transform(transformer, data)
|
thisReceiver = thisReceiver?.transform(transformer, data)
|
||||||
typeParameters.transform { it.transform(transformer, data) }
|
typeParameters = typeParameters.mapOptimized { it.transform(transformer, data) }
|
||||||
declarations.transform { it.transform(transformer, data) }
|
declarations.transform { it.transform(transformer, data) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -58,7 +58,7 @@ class IrLazyConstructor(
|
|||||||
typeTranslator = TypeTranslator
|
typeTranslator = TypeTranslator
|
||||||
)
|
)
|
||||||
|
|
||||||
override val typeParameters: MutableList<IrTypeParameter> by lazy {
|
override var typeParameters: List<IrTypeParameter> by lazyVar {
|
||||||
typeTranslator.buildWithScope(this) {
|
typeTranslator.buildWithScope(this) {
|
||||||
stubGenerator.symbolTable.withScope(descriptor) {
|
stubGenerator.symbolTable.withScope(descriptor) {
|
||||||
val classTypeParametersCount = descriptor.constructedClass.original.declaredTypeParameters.size
|
val classTypeParametersCount = descriptor.constructedClass.original.declaredTypeParameters.size
|
||||||
|
|||||||
+1
-1
@@ -49,7 +49,7 @@ abstract class IrLazyDeclarationBase(
|
|||||||
createLazyParent()!!
|
createLazyParent()!!
|
||||||
}
|
}
|
||||||
|
|
||||||
override val annotations: MutableList<IrConstructorCall> by lazy {
|
override var annotations: List<IrConstructorCall> by lazyVar {
|
||||||
descriptor.annotations.mapNotNull(typeTranslator.constantValueGenerator::generateAnnotationConstructorCall).toMutableList()
|
descriptor.annotations.mapNotNull(typeTranslator.constantValueGenerator::generateAnnotationConstructorCall).toMutableList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class IrLazyField(
|
|||||||
symbol.bind(this)
|
symbol.bind(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val annotations: MutableList<IrConstructorCall> by lazy {
|
override var annotations: List<IrConstructorCall> by lazyVar {
|
||||||
descriptor.backingField?.annotations
|
descriptor.backingField?.annotations
|
||||||
?.mapNotNullTo(mutableListOf(), typeTranslator.constantValueGenerator::generateAnnotationConstructorCall)
|
?.mapNotNullTo(mutableListOf(), typeTranslator.constantValueGenerator::generateAnnotationConstructorCall)
|
||||||
?: mutableListOf()
|
?: mutableListOf()
|
||||||
@@ -71,7 +71,7 @@ class IrLazyField(
|
|||||||
|
|
||||||
override val descriptor: PropertyDescriptor = symbol.descriptor
|
override val descriptor: PropertyDescriptor = symbol.descriptor
|
||||||
|
|
||||||
override val overriddenSymbols: MutableList<IrFieldSymbol> by lazy {
|
override var overriddenSymbols: List<IrFieldSymbol> by lazyVar {
|
||||||
symbol.descriptor.overriddenDescriptors.map {
|
symbol.descriptor.overriddenDescriptors.map {
|
||||||
stubGenerator.generateFieldStub(it.original).symbol
|
stubGenerator.generateFieldStub(it.original).symbol
|
||||||
}.toMutableList()
|
}.toMutableList()
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class IrLazyFunction(
|
|||||||
|
|
||||||
override val descriptor: FunctionDescriptor = symbol.descriptor
|
override val descriptor: FunctionDescriptor = symbol.descriptor
|
||||||
|
|
||||||
override val typeParameters: MutableList<IrTypeParameter> by lazy {
|
override var typeParameters: List<IrTypeParameter> by lazyVar {
|
||||||
typeTranslator.buildWithScope(this) {
|
typeTranslator.buildWithScope(this) {
|
||||||
stubGenerator.symbolTable.withScope(descriptor) {
|
stubGenerator.symbolTable.withScope(descriptor) {
|
||||||
val propertyIfAccessor = descriptor.propertyIfAccessor
|
val propertyIfAccessor = descriptor.propertyIfAccessor
|
||||||
@@ -82,7 +82,7 @@ class IrLazyFunction(
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override val overriddenSymbols: MutableList<IrSimpleFunctionSymbol> by lazy {
|
override var overriddenSymbols: List<IrSimpleFunctionSymbol> by lazyVar {
|
||||||
descriptor.overriddenDescriptors.mapTo(arrayListOf()) {
|
descriptor.overriddenDescriptors.mapTo(arrayListOf()) {
|
||||||
stubGenerator.generateFunctionStub(it.original).symbol
|
stubGenerator.generateFunctionStub(it.original).symbol
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.ir.expressions.IrBody
|
|||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
||||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||||
import org.jetbrains.kotlin.ir.util.transform
|
import org.jetbrains.kotlin.ir.util.mapOptimized
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -48,7 +48,7 @@ abstract class IrLazyFunctionBase(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override val valueParameters: MutableList<IrValueParameter> by lazy {
|
override var valueParameters: List<IrValueParameter> by lazyVar {
|
||||||
typeTranslator.buildWithScope(this) {
|
typeTranslator.buildWithScope(this) {
|
||||||
descriptor.valueParameters.mapTo(arrayListOf()) {
|
descriptor.valueParameters.mapTo(arrayListOf()) {
|
||||||
stubGenerator.generateValueParameterStub(it).apply { parent = this@IrLazyFunctionBase }
|
stubGenerator.generateValueParameterStub(it).apply { parent = this@IrLazyFunctionBase }
|
||||||
@@ -75,11 +75,11 @@ abstract class IrLazyFunctionBase(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||||
typeParameters.transform { it.transform(transformer, data) }
|
typeParameters = typeParameters.mapOptimized { it.transform(transformer, data) }
|
||||||
|
|
||||||
dispatchReceiverParameter = dispatchReceiverParameter?.transform(transformer, data)
|
dispatchReceiverParameter = dispatchReceiverParameter?.transform(transformer, data)
|
||||||
extensionReceiverParameter = extensionReceiverParameter?.transform(transformer, data)
|
extensionReceiverParameter = extensionReceiverParameter?.transform(transformer, data)
|
||||||
valueParameters.transform { it.transform(transformer, data) }
|
valueParameters = valueParameters.mapOptimized { it.transform(transformer, data) }
|
||||||
|
|
||||||
body = body?.transform(transformer, data)
|
body = body?.transform(transformer, data)
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-3
@@ -14,7 +14,7 @@ import org.jetbrains.kotlin.ir.symbols.IrTypeAliasSymbol
|
|||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
||||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||||
import org.jetbrains.kotlin.ir.util.transform
|
import org.jetbrains.kotlin.ir.util.mapOptimized
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
import org.jetbrains.kotlin.ir.visitors.IrElementTransformer
|
||||||
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitor
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -40,7 +40,7 @@ class IrLazyTypeAlias(
|
|||||||
override val descriptor: TypeAliasDescriptor
|
override val descriptor: TypeAliasDescriptor
|
||||||
get() = symbol.descriptor
|
get() = symbol.descriptor
|
||||||
|
|
||||||
override val typeParameters: MutableList<IrTypeParameter> by lazy {
|
override var typeParameters: List<IrTypeParameter> by lazyVar {
|
||||||
descriptor.declaredTypeParameters.mapTo(arrayListOf()) {
|
descriptor.declaredTypeParameters.mapTo(arrayListOf()) {
|
||||||
stubGenerator.generateOrGetTypeParameterStub(it)
|
stubGenerator.generateOrGetTypeParameterStub(it)
|
||||||
}
|
}
|
||||||
@@ -60,6 +60,6 @@ class IrLazyTypeAlias(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
override fun <D> transformChildren(transformer: IrElementTransformer<D>, data: D) {
|
||||||
typeParameters.transform { it.transform(transformer, data) }
|
typeParameters = typeParameters.mapOptimized { it.transform(transformer, data) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -63,7 +63,7 @@ class IrBuiltIns(
|
|||||||
packageFragment.declarations += operator
|
packageFragment.declarations += operator
|
||||||
descriptor.bind(operator)
|
descriptor.bind(operator)
|
||||||
|
|
||||||
valueParameterTypes.mapIndexedTo(operator.valueParameters) { i, t ->
|
operator.valueParameters = valueParameterTypes.mapIndexed { i, t ->
|
||||||
val valueParameterDescriptor = WrappedValueParameterDescriptor()
|
val valueParameterDescriptor = WrappedValueParameterDescriptor()
|
||||||
val valueParameterSymbol = IrValueParameterSymbolImpl(valueParameterDescriptor)
|
val valueParameterSymbol = IrValueParameterSymbolImpl(valueParameterDescriptor)
|
||||||
IrBuiltInOperatorValueParameter(valueParameterSymbol, i, t).apply {
|
IrBuiltInOperatorValueParameter(valueParameterSymbol, i, t).apply {
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ class IrBuiltInOperator(
|
|||||||
return visitor.visitSimpleFunction(this, data)
|
return visitor.visitSimpleFunction(this, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
override val overriddenSymbols: MutableList<IrSimpleFunctionSymbol> = SmartList()
|
override var overriddenSymbols: List<IrSimpleFunctionSymbol> = emptyList()
|
||||||
override var attributeOwnerId: IrAttributeContainer = this
|
override var attributeOwnerId: IrAttributeContainer = this
|
||||||
override val mangle: String get() = "operator#$name@$suffix"
|
override val mangle: String get() = "operator#$name@$suffix"
|
||||||
|
|
||||||
|
|||||||
@@ -141,7 +141,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
).apply {
|
).apply {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
copyTypeParametersFrom(declaration)
|
copyTypeParametersFrom(declaration)
|
||||||
declaration.superTypes.mapTo(superTypes) {
|
superTypes = declaration.superTypes.map {
|
||||||
it.remapType()
|
it.remapType()
|
||||||
}
|
}
|
||||||
thisReceiver = declaration.thisReceiver?.transform()
|
thisReceiver = declaration.thisReceiver?.transform()
|
||||||
@@ -165,7 +165,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
isFakeOverride = declaration.isFakeOverride,
|
isFakeOverride = declaration.isFakeOverride,
|
||||||
isOperator = declaration.isOperator
|
isOperator = declaration.isOperator
|
||||||
).apply {
|
).apply {
|
||||||
declaration.overriddenSymbols.mapTo(overriddenSymbols) {
|
overriddenSymbols = declaration.overriddenSymbols.map {
|
||||||
symbolRemapper.getReferencedFunction(it) as IrSimpleFunctionSymbol
|
symbolRemapper.getReferencedFunction(it) as IrSimpleFunctionSymbol
|
||||||
}
|
}
|
||||||
copyAttributes(declaration)
|
copyAttributes(declaration)
|
||||||
@@ -196,13 +196,13 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
dispatchReceiverParameter = declaration.dispatchReceiverParameter?.transform()
|
dispatchReceiverParameter = declaration.dispatchReceiverParameter?.transform()
|
||||||
extensionReceiverParameter = declaration.extensionReceiverParameter?.transform()
|
extensionReceiverParameter = declaration.extensionReceiverParameter?.transform()
|
||||||
returnType = typeRemapper.remapType(declaration.returnType)
|
returnType = typeRemapper.remapType(declaration.returnType)
|
||||||
declaration.valueParameters.transformTo(valueParameters)
|
valueParameters = declaration.valueParameters.transform()
|
||||||
body = declaration.body?.transform()
|
body = declaration.body?.transform()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun IrMutableAnnotationContainer.transformAnnotations(declaration: IrAnnotationContainer) {
|
private fun IrMutableAnnotationContainer.transformAnnotations(declaration: IrAnnotationContainer) {
|
||||||
declaration.annotations.transformTo(annotations)
|
annotations = declaration.annotations.transform()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun visitProperty(declaration: IrProperty): IrProperty =
|
override fun visitProperty(declaration: IrProperty): IrProperty =
|
||||||
@@ -243,7 +243,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
isFakeOverride = declaration.isFakeOverride
|
isFakeOverride = declaration.isFakeOverride
|
||||||
).apply {
|
).apply {
|
||||||
transformAnnotations(declaration)
|
transformAnnotations(declaration)
|
||||||
declaration.overriddenSymbols.mapTo(overriddenSymbols) {
|
overriddenSymbols = declaration.overriddenSymbols.map {
|
||||||
symbolRemapper.getReferencedField(it)
|
symbolRemapper.getReferencedField(it)
|
||||||
}
|
}
|
||||||
initializer = declaration.initializer?.transform()
|
initializer = declaration.initializer?.transform()
|
||||||
@@ -318,7 +318,7 @@ open class DeepCopyIrTreeWithSymbols(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun IrTypeParametersContainer.copyTypeParametersFrom(other: IrTypeParametersContainer) {
|
private fun IrTypeParametersContainer.copyTypeParametersFrom(other: IrTypeParametersContainer) {
|
||||||
other.typeParameters.mapTo(this.typeParameters) {
|
this.typeParameters = other.typeParameters.map {
|
||||||
copyTypeParameter(it)
|
copyTypeParameter(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ fun generateOverriddenFunctionSymbols(
|
|||||||
declaration: IrSimpleFunction,
|
declaration: IrSimpleFunction,
|
||||||
symbolTable: SymbolTable
|
symbolTable: SymbolTable
|
||||||
) {
|
) {
|
||||||
declaration.descriptor.overriddenDescriptors.mapTo(declaration.overriddenSymbols) {
|
declaration.overriddenSymbols = declaration.descriptor.overriddenDescriptors.map {
|
||||||
symbolTable.referenceSimpleFunction(it.original)
|
symbolTable.referenceSimpleFunction(it.original)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ fun generateOverriddenFieldSymbols(
|
|||||||
symbolTable: SymbolTable,
|
symbolTable: SymbolTable,
|
||||||
hasBackingField: (PropertyDescriptor) -> Boolean
|
hasBackingField: (PropertyDescriptor) -> Boolean
|
||||||
) {
|
) {
|
||||||
declaration.descriptor.overriddenDescriptors.mapNotNullTo(declaration.overriddenSymbols) {
|
declaration.overriddenSymbols = declaration.descriptor.overriddenDescriptors.mapNotNull {
|
||||||
if (hasBackingField(it)) {
|
if (hasBackingField(it)) {
|
||||||
symbolTable.referenceField(it.original)
|
symbolTable.referenceField(it.original)
|
||||||
} else null
|
} else null
|
||||||
|
|||||||
@@ -63,3 +63,18 @@ fun IrDeclarationContainer.transformDeclarationsFlat(transformation: (IrDeclarat
|
|||||||
transformed
|
transformed
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Similar to `map`. Return the same List instance if no element instances have changed.
|
||||||
|
*/
|
||||||
|
internal inline fun <reified T : IrElement> List<T>.mapOptimized(transformation: (T) -> IrElement): List<T> {
|
||||||
|
var result: ArrayList<T>? = null
|
||||||
|
for ((i, item) in withIndex()) {
|
||||||
|
val transformed = transformation(item) as T
|
||||||
|
if (transformed !== item && result == null) {
|
||||||
|
result = ArrayList(this)
|
||||||
|
}
|
||||||
|
result?.set(i, transformed)
|
||||||
|
}
|
||||||
|
return result ?: this
|
||||||
|
}
|
||||||
+7
-7
@@ -908,7 +908,7 @@ abstract class IrFileDeserializer(
|
|||||||
proto.coordinates.startOffset, proto.coordinates.endOffset,
|
proto.coordinates.startOffset, proto.coordinates.endOffset,
|
||||||
deserializeIrDeclarationOrigin(proto.origin)
|
deserializeIrDeclarationOrigin(proto.origin)
|
||||||
)
|
)
|
||||||
result.annotations.addAll(deserializeAnnotations(proto.annotationList))
|
result.annotations += deserializeAnnotations(proto.annotationList)
|
||||||
result.parent = parentsStack.peek()!!
|
result.parent = parentsStack.peek()!!
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
@@ -990,9 +990,9 @@ abstract class IrFileDeserializer(
|
|||||||
|
|
||||||
thisReceiver = deserializeIrValueParameter(proto.thisReceiver)
|
thisReceiver = deserializeIrValueParameter(proto.thisReceiver)
|
||||||
|
|
||||||
proto.typeParameters.typeParameterList.mapTo(typeParameters) { deserializeIrTypeParameter(it) }
|
typeParameters = proto.typeParameters.typeParameterList.map { deserializeIrTypeParameter(it) }
|
||||||
|
|
||||||
proto.superTypeList.mapTo(superTypes) { deserializeIrType(it) }
|
superTypes = proto.superTypeList.map { deserializeIrType(it) }
|
||||||
|
|
||||||
(descriptor as? WrappedClassDescriptor)?.bind(this)
|
(descriptor as? WrappedClassDescriptor)?.bind(this)
|
||||||
}
|
}
|
||||||
@@ -1011,7 +1011,7 @@ abstract class IrFileDeserializer(
|
|||||||
origin
|
origin
|
||||||
)
|
)
|
||||||
}.usingParent {
|
}.usingParent {
|
||||||
proto.typeParameters.typeParameterList.mapTo(typeParameters) {
|
typeParameters = proto.typeParameters.typeParameterList.map {
|
||||||
deserializeIrTypeParameter(it)
|
deserializeIrTypeParameter(it)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1024,8 +1024,8 @@ abstract class IrFileDeserializer(
|
|||||||
block: (IrFunctionSymbol, Int, Int, IrDeclarationOrigin) -> T
|
block: (IrFunctionSymbol, Int, Int, IrDeclarationOrigin) -> T
|
||||||
) = withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
) = withDeserializedIrDeclarationBase(proto.base) { symbol, startOffset, endOffset, origin ->
|
||||||
block(symbol as IrFunctionSymbol, startOffset, endOffset, origin).usingParent {
|
block(symbol as IrFunctionSymbol, startOffset, endOffset, origin).usingParent {
|
||||||
proto.typeParameters.typeParameterList.mapTo(typeParameters) { deserializeIrTypeParameter(it) }
|
typeParameters = proto.typeParameters.typeParameterList.map { deserializeIrTypeParameter(it) }
|
||||||
proto.valueParameterList.mapTo(valueParameters) { deserializeIrValueParameter(it) }
|
valueParameters = proto.valueParameterList.map { deserializeIrValueParameter(it) }
|
||||||
if (proto.hasDispatchReceiver())
|
if (proto.hasDispatchReceiver())
|
||||||
dispatchReceiverParameter = deserializeIrValueParameter(proto.dispatchReceiver)
|
dispatchReceiverParameter = deserializeIrValueParameter(proto.dispatchReceiver)
|
||||||
if (proto.hasExtensionReceiver())
|
if (proto.hasExtensionReceiver())
|
||||||
@@ -1060,7 +1060,7 @@ abstract class IrFileDeserializer(
|
|||||||
isOperator = proto.isOperator
|
isOperator = proto.isOperator
|
||||||
)
|
)
|
||||||
}.apply {
|
}.apply {
|
||||||
proto.overriddenList.mapTo(overriddenSymbols) { deserializeIrSymbol(it) as IrSimpleFunctionSymbol }
|
overriddenSymbols = proto.overriddenList.map { deserializeIrSymbol(it) as IrSimpleFunctionSymbol }
|
||||||
|
|
||||||
(descriptor as? WrappedSimpleFunctionDescriptor)?.bind(this)
|
(descriptor as? WrappedSimpleFunctionDescriptor)?.bind(this)
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -410,7 +410,7 @@ abstract class KotlinIrLinker(
|
|||||||
|
|
||||||
fun deserializeFileImplicitDataIfFirstUse() {
|
fun deserializeFileImplicitDataIfFirstUse() {
|
||||||
annotations?.let {
|
annotations?.let {
|
||||||
file.annotations.addAll(deserializeAnnotations(it))
|
file.annotations += deserializeAnnotations(it)
|
||||||
annotations = null
|
annotations = null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-5
@@ -44,7 +44,7 @@ interface IrBuilderExtension {
|
|||||||
private fun IrClass.declareSimpleFunctionWithExternalOverrides(descriptor: FunctionDescriptor): IrSimpleFunction {
|
private fun IrClass.declareSimpleFunctionWithExternalOverrides(descriptor: FunctionDescriptor): IrSimpleFunction {
|
||||||
return compilerContext.symbolTable.declareSimpleFunction(startOffset, endOffset, SERIALIZABLE_PLUGIN_ORIGIN, descriptor)
|
return compilerContext.symbolTable.declareSimpleFunction(startOffset, endOffset, SERIALIZABLE_PLUGIN_ORIGIN, descriptor)
|
||||||
.also { f ->
|
.also { f ->
|
||||||
descriptor.overriddenDescriptors.mapTo(f.overriddenSymbols) {
|
f.overriddenSymbols = descriptor.overriddenDescriptors.map {
|
||||||
compilerContext.symbolTable.referenceSimpleFunction(it.original)
|
compilerContext.symbolTable.referenceSimpleFunction(it.original)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -357,16 +357,15 @@ interface IrBuilderExtension {
|
|||||||
|
|
||||||
if (!overwriteValueParameters)
|
if (!overwriteValueParameters)
|
||||||
assert(valueParameters.isEmpty())
|
assert(valueParameters.isEmpty())
|
||||||
else
|
|
||||||
valueParameters.clear()
|
valueParameters = descriptor.valueParameters.map { it.irValueParameter() }
|
||||||
valueParameters.addAll(descriptor.valueParameters.map { it.irValueParameter() })
|
|
||||||
|
|
||||||
assert(typeParameters.isEmpty())
|
assert(typeParameters.isEmpty())
|
||||||
if (copyTypeParameters) copyTypeParamsFromDescriptor()
|
if (copyTypeParameters) copyTypeParamsFromDescriptor()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IrFunction.copyTypeParamsFromDescriptor() {
|
fun IrFunction.copyTypeParamsFromDescriptor() {
|
||||||
descriptor.typeParameters.mapTo(typeParameters) {
|
typeParameters += descriptor.typeParameters.map {
|
||||||
IrTypeParameterImpl(
|
IrTypeParameterImpl(
|
||||||
startOffset, endOffset,
|
startOffset, endOffset,
|
||||||
SERIALIZABLE_PLUGIN_ORIGIN,
|
SERIALIZABLE_PLUGIN_ORIGIN,
|
||||||
|
|||||||
+1
-1
@@ -76,7 +76,7 @@ class SerializableCompanionIrGenerator(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
irSerializableClass.annotations.add(annotationCtorCall)
|
irSerializableClass.annotations += annotationCtorCall
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun generateSerializerGetter(methodDescriptor: FunctionDescriptor) {
|
override fun generateSerializerGetter(methodDescriptor: FunctionDescriptor) {
|
||||||
|
|||||||
Reference in New Issue
Block a user