IR: use buildConstructor where possible
This commit is contained in:
@@ -14,13 +14,12 @@ import org.jetbrains.kotlin.descriptors.Visibility
|
|||||||
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
import org.jetbrains.kotlin.descriptors.annotations.Annotations
|
||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
|
||||||
import org.jetbrains.kotlin.ir.builders.Scope
|
import org.jetbrains.kotlin.ir.builders.Scope
|
||||||
|
import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.buildReceiverParameter
|
import org.jetbrains.kotlin.ir.builders.declarations.buildReceiverParameter
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.buildTypeParameter
|
import org.jetbrains.kotlin.ir.builders.declarations.buildTypeParameter
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFunctionImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrValueParameterImpl
|
||||||
import org.jetbrains.kotlin.ir.descriptors.*
|
import org.jetbrains.kotlin.ir.descriptors.*
|
||||||
@@ -28,7 +27,6 @@ import org.jetbrains.kotlin.ir.expressions.*
|
|||||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.*
|
||||||
@@ -40,7 +38,6 @@ import org.jetbrains.kotlin.name.Name
|
|||||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DescriptorWithContainerSource
|
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DescriptorWithContainerSource
|
||||||
import java.io.StringWriter
|
import java.io.StringWriter
|
||||||
|
|
||||||
|
|
||||||
fun ir2string(ir: IrElement?): String = ir?.render() ?: ""
|
fun ir2string(ir: IrElement?): String = ir?.render() ?: ""
|
||||||
|
|
||||||
// NB: this function is used in native
|
// NB: this function is used in native
|
||||||
@@ -55,20 +52,16 @@ fun IrClass.addSimpleDelegatingConstructor(
|
|||||||
irBuiltIns: IrBuiltIns,
|
irBuiltIns: IrBuiltIns,
|
||||||
isPrimary: Boolean = false,
|
isPrimary: Boolean = false,
|
||||||
origin: IrDeclarationOrigin? = null
|
origin: IrDeclarationOrigin? = null
|
||||||
) = WrappedClassConstructorDescriptor().let { descriptor ->
|
): IrConstructor =
|
||||||
IrConstructorImpl(
|
buildConstructor {
|
||||||
startOffset, endOffset,
|
val klass = this@addSimpleDelegatingConstructor
|
||||||
origin ?: this.origin,
|
this.startOffset = klass.startOffset
|
||||||
IrConstructorSymbolImpl(descriptor),
|
this.endOffset = klass.endOffset
|
||||||
superConstructor.name,
|
this.origin = origin ?: klass.origin
|
||||||
superConstructor.visibility,
|
this.visibility = superConstructor.visibility
|
||||||
defaultType,
|
this.returnType = klass.defaultType
|
||||||
isInline = false,
|
this.isPrimary = isPrimary
|
||||||
isExternal = false,
|
}.also { constructor ->
|
||||||
isPrimary = isPrimary,
|
|
||||||
isExpect = false
|
|
||||||
).also { constructor ->
|
|
||||||
descriptor.bind(constructor)
|
|
||||||
constructor.parent = this
|
constructor.parent = this
|
||||||
declarations += constructor
|
declarations += constructor
|
||||||
|
|
||||||
@@ -92,7 +85,6 @@ fun IrClass.addSimpleDelegatingConstructor(
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
val IrCall.isSuspend get() = (symbol.owner as? IrSimpleFunction)?.isSuspend == true
|
val IrCall.isSuspend get() = (symbol.owner as? IrSimpleFunction)?.isSuspend == true
|
||||||
val IrFunctionReference.isSuspend get() = (symbol.owner as? IrSimpleFunction)?.isSuspend == true
|
val IrFunctionReference.isSuspend get() = (symbol.owner as? IrSimpleFunction)?.isSuspend == true
|
||||||
|
|||||||
+18
-33
@@ -13,12 +13,11 @@ import org.jetbrains.kotlin.descriptors.Visibilities
|
|||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||||
import org.jetbrains.kotlin.ir.builders.*
|
import org.jetbrains.kotlin.ir.builders.*
|
||||||
|
import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedClassConstructorDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedClassDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedClassDescriptor
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedFieldDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedFieldDescriptor
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
@@ -26,7 +25,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl
|
|||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.classifierOrFail
|
import org.jetbrains.kotlin.ir.types.classifierOrFail
|
||||||
@@ -378,20 +376,15 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun buildConstructor(): IrConstructor = WrappedClassConstructorDescriptor().let { d ->
|
fun buildConstructor(): IrConstructor =
|
||||||
IrConstructorImpl(
|
buildConstructor {
|
||||||
startOffset, endOffset,
|
startOffset = irFunction.startOffset
|
||||||
DECLARATION_ORIGIN_COROUTINE_IMPL,
|
endOffset = irFunction.endOffset
|
||||||
IrConstructorSymbolImpl(d),
|
origin = DECLARATION_ORIGIN_COROUTINE_IMPL
|
||||||
coroutineBaseClassConstructor.name,
|
visibility = irFunction.visibility
|
||||||
irFunction.visibility,
|
returnType = coroutineClass.defaultType
|
||||||
coroutineClass.defaultType,
|
isPrimary = true
|
||||||
isInline = false,
|
}.apply {
|
||||||
isExternal = false,
|
|
||||||
isPrimary = true,
|
|
||||||
isExpect = false
|
|
||||||
).apply {
|
|
||||||
d.bind(this)
|
|
||||||
parent = coroutineClass
|
parent = coroutineClass
|
||||||
coroutineClass.declarations += this
|
coroutineClass.declarations += this
|
||||||
coroutineConstructors += this
|
coroutineConstructors += this
|
||||||
@@ -422,22 +415,15 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun buildFactoryConstructor(boundParams: List<IrValueParameter>) = WrappedClassConstructorDescriptor().let { d ->
|
private fun buildFactoryConstructor(boundParams: List<IrValueParameter>): IrConstructor =
|
||||||
IrConstructorImpl(
|
buildConstructor {
|
||||||
startOffset, endOffset,
|
startOffset = irFunction.startOffset
|
||||||
DECLARATION_ORIGIN_COROUTINE_IMPL,
|
endOffset = irFunction.endOffset
|
||||||
IrConstructorSymbolImpl(d),
|
origin = DECLARATION_ORIGIN_COROUTINE_IMPL
|
||||||
coroutineBaseClassConstructor.name,
|
visibility = irFunction.visibility
|
||||||
irFunction.visibility,
|
returnType = coroutineClass.defaultType
|
||||||
coroutineClass.defaultType,
|
}.apply {
|
||||||
isInline = false,
|
|
||||||
isExternal = false,
|
|
||||||
isPrimary = false,
|
|
||||||
isExpect = false
|
|
||||||
).apply {
|
|
||||||
d.bind(this)
|
|
||||||
parent = coroutineClass
|
parent = coroutineClass
|
||||||
coroutineClass.declarations += this
|
coroutineClass.declarations += this
|
||||||
coroutineConstructors += this
|
coroutineConstructors += this
|
||||||
@@ -464,7 +450,6 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun buildCreateMethod(
|
private fun buildCreateMethod(
|
||||||
unboundArgs: List<IrValueParameter>,
|
unboundArgs: List<IrValueParameter>,
|
||||||
|
|||||||
+6
-20
@@ -17,19 +17,17 @@ import org.jetbrains.kotlin.ir.IrStatement
|
|||||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
import org.jetbrains.kotlin.ir.builders.Scope
|
import org.jetbrains.kotlin.ir.builders.Scope
|
||||||
|
import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.buildValueParameter
|
import org.jetbrains.kotlin.ir.builders.declarations.buildValueParameter
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedClassConstructorDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedFieldDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedFieldDescriptor
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrValueParameterSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrValueSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.*
|
import org.jetbrains.kotlin.ir.types.*
|
||||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||||
@@ -43,7 +41,6 @@ import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
|||||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||||
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import java.util.*
|
|
||||||
|
|
||||||
interface LocalNameProvider {
|
interface LocalNameProvider {
|
||||||
fun localName(declaration: IrDeclarationWithName): String =
|
fun localName(declaration: IrDeclarationWithName): String =
|
||||||
@@ -693,22 +690,11 @@ class LocalDeclarationsLowering(
|
|||||||
val localClassContext = localClasses[oldDeclaration.parent]!!
|
val localClassContext = localClasses[oldDeclaration.parent]!!
|
||||||
val capturedValues = localClassContext.closure.capturedValues
|
val capturedValues = localClassContext.closure.capturedValues
|
||||||
|
|
||||||
val newDescriptor = WrappedClassConstructorDescriptor(oldDeclaration.descriptor.annotations, oldDeclaration.descriptor.source)
|
val newDeclaration = buildConstructor(oldDeclaration.descriptor) {
|
||||||
val newSymbol = IrConstructorSymbolImpl(newDescriptor)
|
updateFrom(oldDeclaration)
|
||||||
|
visibility = visibilityPolicy.forConstructor(oldDeclaration, constructorContext.inInlineFunctionScope)
|
||||||
val loweredConstructorVisibility =
|
returnType = oldDeclaration.returnType
|
||||||
visibilityPolicy.forConstructor(oldDeclaration, constructorContext.inInlineFunctionScope)
|
}
|
||||||
|
|
||||||
val newDeclaration = IrConstructorImpl(
|
|
||||||
oldDeclaration.startOffset, oldDeclaration.endOffset, oldDeclaration.origin,
|
|
||||||
newSymbol, oldDeclaration.name, loweredConstructorVisibility, oldDeclaration.returnType,
|
|
||||||
isInline = oldDeclaration.isInline,
|
|
||||||
isExternal = oldDeclaration.isExternal,
|
|
||||||
isPrimary = oldDeclaration.isPrimary,
|
|
||||||
isExpect = oldDeclaration.isExpect
|
|
||||||
)
|
|
||||||
|
|
||||||
newDescriptor.bind(newDeclaration)
|
|
||||||
|
|
||||||
constructorContext.transformedDeclaration = newDeclaration
|
constructorContext.transformedDeclaration = newDeclaration
|
||||||
|
|
||||||
|
|||||||
+7
-4
@@ -143,8 +143,11 @@ internal fun IrFunctionBuilder.buildFunction(originalDescriptor: FunctionDescrip
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IrFunctionBuilder.buildConstructor(): IrConstructor {
|
@PublishedApi
|
||||||
val wrappedDescriptor = WrappedClassConstructorDescriptor()
|
internal fun IrFunctionBuilder.buildConstructor(originalDescriptor: ConstructorDescriptor?): IrConstructor {
|
||||||
|
val wrappedDescriptor =
|
||||||
|
if (originalDescriptor != null) WrappedClassConstructorDescriptor(originalDescriptor.annotations, originalDescriptor.source)
|
||||||
|
else WrappedClassConstructorDescriptor()
|
||||||
return IrConstructorImpl(
|
return IrConstructorImpl(
|
||||||
startOffset, endOffset, origin,
|
startOffset, endOffset, origin,
|
||||||
IrConstructorSymbolImpl(wrappedDescriptor),
|
IrConstructorSymbolImpl(wrappedDescriptor),
|
||||||
@@ -192,10 +195,10 @@ fun IrDeclarationContainer.addFunction(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun buildConstructor(builder: IrFunctionBuilder.() -> Unit): IrConstructor =
|
inline fun buildConstructor(originalDescriptor: ConstructorDescriptor? = null, builder: IrFunctionBuilder.() -> Unit): IrConstructor =
|
||||||
IrFunctionBuilder().run {
|
IrFunctionBuilder().run {
|
||||||
builder()
|
builder()
|
||||||
buildConstructor()
|
buildConstructor(originalDescriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
inline fun IrClass.addConstructor(builder: IrFunctionBuilder.() -> Unit = {}): IrConstructor =
|
inline fun IrClass.addConstructor(builder: IrFunctionBuilder.() -> Unit = {}): IrConstructor =
|
||||||
|
|||||||
+5
-20
@@ -17,12 +17,10 @@ import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
|||||||
import org.jetbrains.kotlin.ir.backend.js.JsMapping
|
import org.jetbrains.kotlin.ir.backend.js.JsMapping
|
||||||
import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
|
import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
|
||||||
import org.jetbrains.kotlin.ir.backend.js.utils.Namer
|
import org.jetbrains.kotlin.ir.backend.js.utils.Namer
|
||||||
|
import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedClassConstructorDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedFieldDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedFieldDescriptor
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.util.defaultType
|
import org.jetbrains.kotlin.ir.util.defaultType
|
||||||
@@ -99,23 +97,10 @@ class JsDeclarationFactory(mapping: JsMapping) : DeclarationFactory {
|
|||||||
val irClass = oldConstructor.parent as IrClass
|
val irClass = oldConstructor.parent as IrClass
|
||||||
val outerThisType = (irClass.parent as IrClass).defaultType
|
val outerThisType = (irClass.parent as IrClass).defaultType
|
||||||
|
|
||||||
val descriptor = WrappedClassConstructorDescriptor(oldConstructor.descriptor.annotations, oldConstructor.descriptor.source)
|
val newConstructor = buildConstructor(oldConstructor.descriptor) {
|
||||||
val symbol = IrConstructorSymbolImpl(descriptor)
|
updateFrom(oldConstructor)
|
||||||
|
returnType = oldConstructor.returnType
|
||||||
val newConstructor = IrConstructorImpl(
|
}.also {
|
||||||
oldConstructor.startOffset,
|
|
||||||
oldConstructor.endOffset,
|
|
||||||
oldConstructor.origin,
|
|
||||||
symbol,
|
|
||||||
oldConstructor.name,
|
|
||||||
oldConstructor.visibility,
|
|
||||||
oldConstructor.returnType,
|
|
||||||
isInline = oldConstructor.isInline,
|
|
||||||
isExternal = oldConstructor.isExternal,
|
|
||||||
isPrimary = oldConstructor.isPrimary,
|
|
||||||
isExpect = oldConstructor.isExpect
|
|
||||||
).also {
|
|
||||||
descriptor.bind(it)
|
|
||||||
it.parent = oldConstructor.parent
|
it.parent = oldConstructor.parent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+9
-21
@@ -22,15 +22,16 @@ import org.jetbrains.kotlin.ir.backend.js.JsIrBackendContext
|
|||||||
import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
|
import org.jetbrains.kotlin.ir.backend.js.ir.JsIrBuilder
|
||||||
import org.jetbrains.kotlin.ir.backend.js.utils.toJsArrayLiteral
|
import org.jetbrains.kotlin.ir.backend.js.utils.toJsArrayLiteral
|
||||||
import org.jetbrains.kotlin.ir.builders.*
|
import org.jetbrains.kotlin.ir.builders.*
|
||||||
|
import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.buildField
|
import org.jetbrains.kotlin.ir.builders.declarations.buildField
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedClassConstructorDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedFieldDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedFieldDescriptor
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
import org.jetbrains.kotlin.ir.expressions.impl.IrBlockBodyImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrCallImpl
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.impl.IrExpressionBodyImpl
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.impl.IrVarargImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.makeNullable
|
import org.jetbrains.kotlin.ir.types.makeNullable
|
||||||
@@ -119,23 +120,10 @@ class EnumClassConstructorLowering(val context: JsCommonBackendContext) : Declar
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun transformEnumConstructor(enumConstructor: IrConstructor, enumClass: IrClass): IrConstructor {
|
private fun transformEnumConstructor(enumConstructor: IrConstructor, enumClass: IrClass): IrConstructor {
|
||||||
val loweredConstructorDescriptor = WrappedClassConstructorDescriptor()
|
return buildConstructor {
|
||||||
val loweredConstructorSymbol = IrConstructorSymbolImpl(loweredConstructorDescriptor)
|
updateFrom(enumConstructor)
|
||||||
|
returnType = enumConstructor.returnType
|
||||||
return IrConstructorImpl(
|
}.apply {
|
||||||
enumConstructor.startOffset,
|
|
||||||
enumConstructor.endOffset,
|
|
||||||
enumConstructor.origin,
|
|
||||||
loweredConstructorSymbol,
|
|
||||||
enumConstructor.name,
|
|
||||||
enumConstructor.visibility,
|
|
||||||
enumConstructor.returnType,
|
|
||||||
isInline = enumConstructor.isInline,
|
|
||||||
isExternal = enumConstructor.isExternal,
|
|
||||||
isPrimary = enumConstructor.isPrimary,
|
|
||||||
isExpect = enumConstructor.isExpect
|
|
||||||
).apply {
|
|
||||||
loweredConstructorDescriptor.bind(this)
|
|
||||||
parent = enumClass
|
parent = enumClass
|
||||||
valueParameters += JsIrBuilder.buildValueParameter(this, "name", 0, context.irBuiltIns.stringType)
|
valueParameters += JsIrBuilder.buildValueParameter(this, "name", 0, context.irBuiltIns.stringType)
|
||||||
valueParameters += JsIrBuilder.buildValueParameter(this, "ordinal", 1, context.irBuiltIns.intType)
|
valueParameters += JsIrBuilder.buildValueParameter(this, "ordinal", 1, context.irBuiltIns.intType)
|
||||||
|
|||||||
+35
-43
@@ -14,12 +14,11 @@ import org.jetbrains.kotlin.descriptors.Visibilities
|
|||||||
import org.jetbrains.kotlin.ir.IrElement
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
import org.jetbrains.kotlin.ir.backend.js.lower.CallableReferenceLowering
|
import org.jetbrains.kotlin.ir.backend.js.lower.CallableReferenceLowering
|
||||||
import org.jetbrains.kotlin.ir.builders.*
|
import org.jetbrains.kotlin.ir.builders.*
|
||||||
|
import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFieldImpl
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedClassConstructorDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedClassDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedClassDescriptor
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedFieldDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedFieldDescriptor
|
||||||
import org.jetbrains.kotlin.ir.expressions.*
|
import org.jetbrains.kotlin.ir.expressions.*
|
||||||
@@ -27,7 +26,6 @@ import org.jetbrains.kotlin.ir.expressions.impl.IrInstanceInitializerCallImpl
|
|||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrFieldSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.classifierOrFail
|
import org.jetbrains.kotlin.ir.types.classifierOrFail
|
||||||
@@ -253,49 +251,43 @@ abstract class AbstractSuspendFunctionsLowering<C : CommonBackendContext>(val co
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return WrappedClassConstructorDescriptor().let { d ->
|
return buildConstructor {
|
||||||
IrConstructorImpl(
|
startOffset = function.startOffset
|
||||||
startOffset, endOffset,
|
endOffset = function.endOffset
|
||||||
DECLARATION_ORIGIN_COROUTINE_IMPL,
|
origin = DECLARATION_ORIGIN_COROUTINE_IMPL
|
||||||
IrConstructorSymbolImpl(d),
|
name = coroutineBaseClassConstructor.name
|
||||||
coroutineBaseClassConstructor.name,
|
visibility = function.visibility
|
||||||
function.visibility,
|
returnType = coroutineClass.defaultType
|
||||||
coroutineClass.defaultType,
|
isPrimary = true
|
||||||
isInline = false,
|
}.apply {
|
||||||
isExternal = false,
|
parent = coroutineClass
|
||||||
isPrimary = true,
|
coroutineClass.addChild(this)
|
||||||
isExpect = false
|
|
||||||
).apply {
|
|
||||||
d.bind(this)
|
|
||||||
parent = coroutineClass
|
|
||||||
coroutineClass.addChild(this)
|
|
||||||
|
|
||||||
valueParameters = functionParameters.mapIndexed { index, parameter ->
|
valueParameters = functionParameters.mapIndexed { index, parameter ->
|
||||||
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index, defaultValue = null)
|
parameter.copyTo(this, DECLARATION_ORIGIN_COROUTINE_IMPL, index, defaultValue = null)
|
||||||
|
}
|
||||||
|
val continuationParameter = coroutineBaseClassConstructor.valueParameters[0]
|
||||||
|
valueParameters += continuationParameter.copyTo(
|
||||||
|
this, DECLARATION_ORIGIN_COROUTINE_IMPL,
|
||||||
|
index = valueParameters.size,
|
||||||
|
type = continuationType,
|
||||||
|
defaultValue = null
|
||||||
|
)
|
||||||
|
|
||||||
|
val irBuilder = context.createIrBuilder(symbol, startOffset, endOffset)
|
||||||
|
body = irBuilder.irBlockBody {
|
||||||
|
val completionParameter = valueParameters.last()
|
||||||
|
+irDelegatingConstructorCall(coroutineBaseClassConstructor).apply {
|
||||||
|
putValueArgument(0, irGet(completionParameter))
|
||||||
}
|
}
|
||||||
val continuationParameter = coroutineBaseClassConstructor.valueParameters[0]
|
+IrInstanceInitializerCallImpl(startOffset, endOffset, coroutineClass.symbol, context.irBuiltIns.unitType)
|
||||||
valueParameters += continuationParameter.copyTo(
|
|
||||||
this, DECLARATION_ORIGIN_COROUTINE_IMPL,
|
|
||||||
index = valueParameters.size,
|
|
||||||
type = continuationType,
|
|
||||||
defaultValue = null
|
|
||||||
)
|
|
||||||
|
|
||||||
val irBuilder = context.createIrBuilder(symbol, startOffset, endOffset)
|
functionParameters.forEachIndexed { index, parameter ->
|
||||||
body = irBuilder.irBlockBody {
|
+irSetField(
|
||||||
val completionParameter = valueParameters.last()
|
irGet(coroutineClassThis),
|
||||||
+irDelegatingConstructorCall(coroutineBaseClassConstructor).apply {
|
argumentToPropertiesMap.getValue(parameter),
|
||||||
putValueArgument(0, irGet(completionParameter))
|
irGet(valueParameters[index])
|
||||||
}
|
)
|
||||||
+IrInstanceInitializerCallImpl(startOffset, endOffset, coroutineClass.symbol, context.irBuiltIns.unitType)
|
|
||||||
|
|
||||||
functionParameters.forEachIndexed { index, parameter ->
|
|
||||||
+irSetField(
|
|
||||||
irGet(coroutineClassThis),
|
|
||||||
argumentToPropertiesMap.getValue(parameter),
|
|
||||||
irGet(valueParameters[index])
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-20
@@ -20,6 +20,7 @@ import org.jetbrains.kotlin.config.LanguageVersionSettings
|
|||||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||||
|
import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.buildField
|
import org.jetbrains.kotlin.ir.builders.declarations.buildField
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.buildValueParameter
|
import org.jetbrains.kotlin.ir.builders.declarations.buildValueParameter
|
||||||
@@ -27,12 +28,9 @@ import org.jetbrains.kotlin.ir.builders.irCall
|
|||||||
import org.jetbrains.kotlin.ir.builders.setSourceRange
|
import org.jetbrains.kotlin.ir.builders.setSourceRange
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedClassConstructorDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedClassDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedClassDescriptor
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
|
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
|
||||||
import org.jetbrains.kotlin.ir.util.*
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
import org.jetbrains.kotlin.load.java.JavaVisibilities
|
import org.jetbrains.kotlin.load.java.JavaVisibilities
|
||||||
import org.jetbrains.kotlin.load.java.JvmAbi
|
import org.jetbrains.kotlin.load.java.JvmAbi
|
||||||
@@ -103,22 +101,11 @@ class JvmDeclarationFactory(
|
|||||||
return originalInnerClassPrimaryConstructorByClass[innerClass]
|
return originalInnerClassPrimaryConstructorByClass[innerClass]
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createInnerClassConstructorWithOuterThisParameter(oldConstructor: IrConstructor): IrConstructor {
|
private fun createInnerClassConstructorWithOuterThisParameter(oldConstructor: IrConstructor): IrConstructor =
|
||||||
val newDescriptor = WrappedClassConstructorDescriptor(oldConstructor.descriptor.annotations)
|
buildConstructor(oldConstructor.descriptor) {
|
||||||
return IrConstructorImpl(
|
updateFrom(oldConstructor)
|
||||||
oldConstructor.startOffset,
|
returnType = oldConstructor.returnType
|
||||||
oldConstructor.endOffset,
|
}.apply {
|
||||||
oldConstructor.origin,
|
|
||||||
IrConstructorSymbolImpl(newDescriptor),
|
|
||||||
oldConstructor.name,
|
|
||||||
oldConstructor.visibility,
|
|
||||||
oldConstructor.returnType,
|
|
||||||
isInline = oldConstructor.isInline,
|
|
||||||
isExternal = oldConstructor.isExternal,
|
|
||||||
isPrimary = oldConstructor.isPrimary,
|
|
||||||
isExpect = oldConstructor.isExpect
|
|
||||||
).apply {
|
|
||||||
newDescriptor.bind(this)
|
|
||||||
annotations = 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
|
||||||
@@ -133,7 +120,6 @@ class JvmDeclarationFactory(
|
|||||||
valueParameters = listOf(outerThisValueParameter) + oldConstructor.valueParameters.map { it.copyTo(this, index = it.index + 1) }
|
valueParameters = listOf(outerThisValueParameter) + oldConstructor.valueParameters.map { it.copyTo(this, index = it.index + 1) }
|
||||||
metadata = oldConstructor.metadata
|
metadata = oldConstructor.metadata
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
override fun getFieldForObjectInstance(singleton: IrClass): IrField =
|
override fun getFieldForObjectInstance(singleton: IrClass): IrField =
|
||||||
singletonFieldDeclarations.getOrPut(singleton) {
|
singletonFieldDeclarations.getOrPut(singleton) {
|
||||||
|
|||||||
+7
-17
@@ -14,12 +14,10 @@ import org.jetbrains.kotlin.backend.jvm.JvmLoweredDeclarationOrigin
|
|||||||
import org.jetbrains.kotlin.config.LanguageFeature
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.descriptors.Modality
|
import org.jetbrains.kotlin.descriptors.Modality
|
||||||
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
import org.jetbrains.kotlin.ir.UNDEFINED_OFFSET
|
||||||
|
import org.jetbrains.kotlin.ir.builders.declarations.buildConstructor
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
import org.jetbrains.kotlin.ir.builders.declarations.buildFun
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrConstructorImpl
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedClassConstructorDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.*
|
import org.jetbrains.kotlin.ir.expressions.impl.*
|
||||||
import org.jetbrains.kotlin.ir.symbols.impl.IrConstructorSymbolImpl
|
|
||||||
import org.jetbrains.kotlin.ir.types.defaultType
|
import org.jetbrains.kotlin.ir.types.defaultType
|
||||||
import org.jetbrains.kotlin.ir.util.allTypeParameters
|
import org.jetbrains.kotlin.ir.util.allTypeParameters
|
||||||
import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols
|
import org.jetbrains.kotlin.ir.util.deepCopyWithSymbols
|
||||||
@@ -119,20 +117,12 @@ private class JvmOverloadsAnnotationLowering(val context: JvmBackendContext) : C
|
|||||||
private fun generateWrapperHeader(oldFunction: IrFunction, numDefaultParametersToExpect: Int): IrFunction {
|
private fun generateWrapperHeader(oldFunction: IrFunction, numDefaultParametersToExpect: Int): IrFunction {
|
||||||
val res = when (oldFunction) {
|
val res = when (oldFunction) {
|
||||||
is IrConstructor -> {
|
is IrConstructor -> {
|
||||||
val descriptor = WrappedClassConstructorDescriptor(oldFunction.descriptor.annotations)
|
buildConstructor(oldFunction.descriptor) {
|
||||||
IrConstructorImpl(
|
origin = JvmLoweredDeclarationOrigin.JVM_OVERLOADS_WRAPPER
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET,
|
name = oldFunction.name
|
||||||
JvmLoweredDeclarationOrigin.JVM_OVERLOADS_WRAPPER,
|
visibility = oldFunction.visibility
|
||||||
IrConstructorSymbolImpl(descriptor),
|
returnType = oldFunction.returnType
|
||||||
oldFunction.name,
|
isInline = oldFunction.isInline
|
||||||
oldFunction.visibility,
|
|
||||||
returnType = oldFunction.returnType,
|
|
||||||
isInline = oldFunction.isInline,
|
|
||||||
isExternal = false,
|
|
||||||
isPrimary = false,
|
|
||||||
isExpect = false
|
|
||||||
).apply {
|
|
||||||
descriptor.bind(this)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
is IrSimpleFunction -> buildFun(oldFunction.descriptor) {
|
is IrSimpleFunction -> buildFun(oldFunction.descriptor) {
|
||||||
|
|||||||
Reference in New Issue
Block a user