Fir2IR: remove wrapped descriptors
This commit is contained in:
+42
@@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||||
|
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.fir.backend
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.ir.IrElement
|
||||||
|
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||||
|
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.IrElementVisitorVoid
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||||
|
|
||||||
|
// TODO: could be a lowering
|
||||||
|
internal class ExternalPackageParentPatcher(private val stubGenerator: DeclarationStubGenerator) : IrElementVisitorVoid {
|
||||||
|
override fun visitElement(element: IrElement) {
|
||||||
|
element.acceptChildrenVoid(this)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun visitMemberAccess(expression: IrMemberAccessExpression<*>) {
|
||||||
|
super.visitMemberAccess(expression)
|
||||||
|
val callee = expression.symbol.owner as? IrDeclaration ?: return
|
||||||
|
if (callee.parent is IrExternalPackageFragment) {
|
||||||
|
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||||
|
val parentClass = stubGenerator.generateOrGetFacadeClass(callee.descriptor) ?: return
|
||||||
|
callee.parent = parentClass
|
||||||
|
when (callee) {
|
||||||
|
is IrProperty -> handleProperty(callee, parentClass)
|
||||||
|
is IrSimpleFunction -> callee.correspondingPropertySymbol?.owner?.let { handleProperty(it, parentClass) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun handleProperty(property: IrProperty, newParent: IrClass) {
|
||||||
|
property.parent = newParent
|
||||||
|
property.getter?.parent = newParent
|
||||||
|
property.setter?.parent = newParent
|
||||||
|
property.backingField?.parent = newParent
|
||||||
|
}
|
||||||
|
}
|
||||||
+25
-36
@@ -21,15 +21,15 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
|||||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.UNDEFINED_PARAMETER_INDEX
|
import org.jetbrains.kotlin.ir.builders.declarations.UNDEFINED_PARAMETER_INDEX
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedClassDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedEnumEntryDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedTypeAliasDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedTypeParameterDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrEnumConstructorCallImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrEnumConstructorCallImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol
|
import org.jetbrains.kotlin.ir.symbols.IrEnumEntrySymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrTypeAliasSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrTypeAliasSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrTypeParameterSymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.impl.IrClassSymbolImpl
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.impl.IrEnumEntrySymbolImpl
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeAliasSymbolImpl
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.impl.IrTypeParameterSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||||
@@ -177,13 +177,11 @@ class Fir2IrClassifierStorage(
|
|||||||
return irClass
|
return irClass
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun declareIrTypeAlias(signature: IdSignature?, factory: (IrTypeAliasSymbol) -> IrTypeAlias): IrTypeAlias {
|
private fun declareIrTypeAlias(signature: IdSignature?, factory: (IrTypeAliasSymbol) -> IrTypeAlias): IrTypeAlias =
|
||||||
if (signature == null) {
|
if (signature == null)
|
||||||
val descriptor = WrappedTypeAliasDescriptor()
|
factory(IrTypeAliasSymbolImpl())
|
||||||
return symbolTable.declareTypeAlias(descriptor, factory).apply { descriptor.bind(this) }
|
else
|
||||||
}
|
symbolTable.declareTypeAlias(signature, { Fir2IrTypeAliasSymbol(signature) }, factory)
|
||||||
return symbolTable.declareTypeAlias(signature, { Fir2IrTypeAliasSymbol(signature) }, factory)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun registerTypeAlias(
|
fun registerTypeAlias(
|
||||||
typeAlias: FirTypeAlias,
|
typeAlias: FirTypeAlias,
|
||||||
@@ -211,13 +209,11 @@ class Fir2IrClassifierStorage(
|
|||||||
|
|
||||||
internal fun getCachedTypeAlias(firTypeAlias: FirTypeAlias): IrTypeAlias? = typeAliasCache[firTypeAlias]
|
internal fun getCachedTypeAlias(firTypeAlias: FirTypeAlias): IrTypeAlias? = typeAliasCache[firTypeAlias]
|
||||||
|
|
||||||
private fun declareIrClass(signature: IdSignature?, factory: (IrClassSymbol) -> IrClass): IrClass {
|
private fun declareIrClass(signature: IdSignature?, factory: (IrClassSymbol) -> IrClass): IrClass =
|
||||||
if (signature == null) {
|
if (signature == null)
|
||||||
val descriptor = WrappedClassDescriptor()
|
factory(IrClassSymbolImpl())
|
||||||
return symbolTable.declareClass(descriptor, factory).apply { descriptor.bind(this) }
|
else
|
||||||
}
|
symbolTable.declareClass(signature, { Fir2IrClassSymbol(signature) }, factory)
|
||||||
return symbolTable.declareClass(signature, { Fir2IrClassSymbol(signature) }, factory)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun registerIrClass(
|
fun registerIrClass(
|
||||||
regularClass: FirRegularClass,
|
regularClass: FirRegularClass,
|
||||||
@@ -305,20 +301,15 @@ class Fir2IrClassifierStorage(
|
|||||||
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT
|
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT
|
||||||
): IrTypeParameter {
|
): IrTypeParameter {
|
||||||
require(index >= 0)
|
require(index >= 0)
|
||||||
val descriptor = WrappedTypeParameterDescriptor()
|
|
||||||
val origin = IrDeclarationOrigin.DEFINED
|
val origin = IrDeclarationOrigin.DEFINED
|
||||||
val irTypeParameter = with(typeParameter) {
|
val irTypeParameter = with(typeParameter) {
|
||||||
convertWithOffsets { startOffset, endOffset ->
|
convertWithOffsets { startOffset, endOffset ->
|
||||||
symbolTable.declareGlobalTypeParameter(startOffset, endOffset, origin, descriptor) { symbol ->
|
irFactory.createTypeParameter(
|
||||||
irFactory.createTypeParameter(
|
startOffset, endOffset, origin, IrTypeParameterSymbolImpl(),
|
||||||
startOffset, endOffset, origin, symbol,
|
name, if (index < 0) 0 else index,
|
||||||
name, if (index < 0) 0 else index,
|
isReified,
|
||||||
isReified,
|
variance
|
||||||
variance
|
)
|
||||||
).apply {
|
|
||||||
descriptor.bind(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -375,13 +366,11 @@ class Fir2IrClassifierStorage(
|
|||||||
|
|
||||||
internal fun getCachedIrEnumEntry(enumEntry: FirEnumEntry): IrEnumEntry? = enumEntryCache[enumEntry]
|
internal fun getCachedIrEnumEntry(enumEntry: FirEnumEntry): IrEnumEntry? = enumEntryCache[enumEntry]
|
||||||
|
|
||||||
private fun declareIrEnumEntry(signature: IdSignature?, factory: (IrEnumEntrySymbol) -> IrEnumEntry): IrEnumEntry {
|
private fun declareIrEnumEntry(signature: IdSignature?, factory: (IrEnumEntrySymbol) -> IrEnumEntry): IrEnumEntry =
|
||||||
if (signature == null) {
|
if (signature == null)
|
||||||
val descriptor = WrappedEnumEntryDescriptor()
|
factory(IrEnumEntrySymbolImpl())
|
||||||
return symbolTable.declareEnumEntry(0, 0, IrDeclarationOrigin.DEFINED, descriptor, factory).apply { descriptor.bind(this) }
|
else
|
||||||
}
|
symbolTable.declareEnumEntry(signature, { Fir2IrEnumEntrySymbol(signature) }, factory)
|
||||||
return symbolTable.declareEnumEntry(signature, { Fir2IrEnumEntrySymbol(signature) }, factory)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createIrEnumEntry(
|
fun createIrEnumEntry(
|
||||||
enumEntry: FirEnumEntry,
|
enumEntry: FirEnumEntry,
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ import org.jetbrains.kotlin.ir.declarations.*
|
|||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrFileImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrModuleFragmentImpl
|
||||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
import org.jetbrains.kotlin.ir.descriptors.IrBuiltIns
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.util.*
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
|
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
import org.jetbrains.kotlin.psi2ir.PsiSourceManager
|
||||||
@@ -318,14 +318,7 @@ class Fir2IrConverter(
|
|||||||
|
|
||||||
externalDependenciesGenerator.generateUnboundSymbolsAsDependencies()
|
externalDependenciesGenerator.generateUnboundSymbolsAsDependencies()
|
||||||
val stubGenerator = irProviders.filterIsInstance<DeclarationStubGenerator>().first()
|
val stubGenerator = irProviders.filterIsInstance<DeclarationStubGenerator>().first()
|
||||||
for (descriptor in symbolTable.wrappedTopLevelCallableDescriptors()) {
|
irModuleFragment.acceptVoid(ExternalPackageParentPatcher(stubGenerator))
|
||||||
val parentClass = stubGenerator.generateOrGetFacadeClass(descriptor as WrappedDeclarationDescriptor<*>)
|
|
||||||
val owner = descriptor.owner
|
|
||||||
owner.parent = parentClass ?: continue
|
|
||||||
if (owner is IrProperty) {
|
|
||||||
owner.backingField?.parent = parentClass
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
evaluateConstants(irModuleFragment)
|
evaluateConstants(irModuleFragment)
|
||||||
|
|
||||||
|
|||||||
+73
-106
@@ -44,6 +44,7 @@ import org.jetbrains.kotlin.ir.expressions.IrExpression
|
|||||||
import org.jetbrains.kotlin.ir.expressions.IrSyntheticBodyKind
|
import org.jetbrains.kotlin.ir.expressions.IrSyntheticBodyKind
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
|
import org.jetbrains.kotlin.ir.expressions.impl.IrErrorExpressionImpl
|
||||||
import org.jetbrains.kotlin.ir.symbols.*
|
import org.jetbrains.kotlin.ir.symbols.*
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.impl.*
|
||||||
import org.jetbrains.kotlin.ir.types.IrErrorType
|
import org.jetbrains.kotlin.ir.types.IrErrorType
|
||||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
@@ -264,20 +265,14 @@ class Fir2IrDeclarationStorage(
|
|||||||
type: IrType,
|
type: IrType,
|
||||||
parent: IrFunction
|
parent: IrFunction
|
||||||
): IrValueParameter {
|
): IrValueParameter {
|
||||||
val descriptor = WrappedValueParameterDescriptor()
|
return irFactory.createValueParameter(
|
||||||
return symbolTable.declareValueParameter(
|
startOffset, endOffset, IrDeclarationOrigin.DEFINED, IrValueParameterSymbolImpl(),
|
||||||
startOffset, endOffset, origin, descriptor, type
|
Name.special("<set-?>"), 0, type,
|
||||||
) { symbol ->
|
varargElementType = null,
|
||||||
irFactory.createValueParameter(
|
isCrossinline = false, isNoinline = false,
|
||||||
startOffset, endOffset, IrDeclarationOrigin.DEFINED, symbol,
|
isHidden = false, isAssignable = false
|
||||||
Name.special("<set-?>"), 0, type,
|
).apply {
|
||||||
varargElementType = null,
|
this.parent = parent
|
||||||
isCrossinline = false, isNoinline = false,
|
|
||||||
isHidden = false, isAssignable = false
|
|
||||||
).apply {
|
|
||||||
this.parent = parent
|
|
||||||
descriptor.bind(this)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -404,13 +399,12 @@ class Fir2IrDeclarationStorage(
|
|||||||
signature: IdSignature?,
|
signature: IdSignature?,
|
||||||
containerSource: DeserializedContainerSource?,
|
containerSource: DeserializedContainerSource?,
|
||||||
factory: (IrSimpleFunctionSymbol) -> IrSimpleFunction
|
factory: (IrSimpleFunctionSymbol) -> IrSimpleFunction
|
||||||
): IrSimpleFunction {
|
): IrSimpleFunction =
|
||||||
if (signature == null) {
|
if (signature == null) {
|
||||||
val descriptor = WrappedSimpleFunctionDescriptor()
|
factory(IrSimpleFunctionSymbolImpl())
|
||||||
return symbolTable.declareSimpleFunction(descriptor, factory).apply { descriptor.bind(this) }
|
} else {
|
||||||
|
symbolTable.declareSimpleFunction(signature, { Fir2IrSimpleFunctionSymbol(signature, containerSource) }, factory)
|
||||||
}
|
}
|
||||||
return symbolTable.declareSimpleFunction(signature, { Fir2IrSimpleFunctionSymbol(signature, containerSource) }, factory)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getOrCreateIrFunction(
|
fun getOrCreateIrFunction(
|
||||||
function: FirSimpleFunction,
|
function: FirSimpleFunction,
|
||||||
@@ -516,13 +510,12 @@ class Fir2IrDeclarationStorage(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun declareIrConstructor(signature: IdSignature?, factory: (IrConstructorSymbol) -> IrConstructor): IrConstructor {
|
private fun declareIrConstructor(signature: IdSignature?, factory: (IrConstructorSymbol) -> IrConstructor): IrConstructor =
|
||||||
if (signature == null) {
|
if (signature == null)
|
||||||
val descriptor = WrappedClassConstructorDescriptor()
|
factory(IrConstructorSymbolImpl())
|
||||||
return symbolTable.declareConstructor(descriptor, factory).apply { descriptor.bind(this) }
|
else
|
||||||
}
|
symbolTable.declareConstructor(signature, { Fir2IrConstructorSymbol(signature) }, factory)
|
||||||
return symbolTable.declareConstructor(signature, { Fir2IrConstructorSymbol(signature) }, factory)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createIrConstructor(
|
fun createIrConstructor(
|
||||||
constructor: FirConstructor,
|
constructor: FirConstructor,
|
||||||
@@ -555,17 +548,12 @@ class Fir2IrDeclarationStorage(
|
|||||||
private fun declareIrAccessor(
|
private fun declareIrAccessor(
|
||||||
signature: IdSignature?,
|
signature: IdSignature?,
|
||||||
containerSource: DeserializedContainerSource?,
|
containerSource: DeserializedContainerSource?,
|
||||||
isGetter: Boolean,
|
|
||||||
factory: (IrSimpleFunctionSymbol) -> IrSimpleFunction
|
factory: (IrSimpleFunctionSymbol) -> IrSimpleFunction
|
||||||
): IrSimpleFunction {
|
): IrSimpleFunction =
|
||||||
if (signature == null) {
|
if (signature == null)
|
||||||
val descriptor =
|
factory(IrSimpleFunctionSymbolImpl())
|
||||||
if (isGetter) WrappedPropertyGetterDescriptor()
|
else
|
||||||
else WrappedPropertySetterDescriptor()
|
symbolTable.declareSimpleFunction(signature, { Fir2IrSimpleFunctionSymbol(signature, containerSource) }, factory)
|
||||||
return symbolTable.declareSimpleFunction(descriptor, factory).apply { descriptor.bind(this) }
|
|
||||||
}
|
|
||||||
return symbolTable.declareSimpleFunction(signature, { Fir2IrSimpleFunctionSymbol(signature, containerSource) }, factory)
|
|
||||||
}
|
|
||||||
|
|
||||||
internal fun createIrPropertyAccessor(
|
internal fun createIrPropertyAccessor(
|
||||||
propertyAccessor: FirPropertyAccessor?,
|
propertyAccessor: FirPropertyAccessor?,
|
||||||
@@ -586,8 +574,7 @@ class Fir2IrDeclarationStorage(
|
|||||||
val containerSource = (correspondingProperty as? IrProperty)?.containerSource
|
val containerSource = (correspondingProperty as? IrProperty)?.containerSource
|
||||||
return declareIrAccessor(
|
return declareIrAccessor(
|
||||||
signature,
|
signature,
|
||||||
containerSource,
|
containerSource
|
||||||
isGetter = !isSetter
|
|
||||||
) { symbol ->
|
) { symbol ->
|
||||||
val accessorReturnType = if (isSetter) irBuiltIns.unitType else propertyType
|
val accessorReturnType = if (isSetter) irBuiltIns.unitType else propertyType
|
||||||
val visibility = propertyAccessor?.visibility?.let {
|
val visibility = propertyAccessor?.visibility?.let {
|
||||||
@@ -685,15 +672,11 @@ class Fir2IrDeclarationStorage(
|
|||||||
signature: IdSignature?,
|
signature: IdSignature?,
|
||||||
containerSource: DeserializedContainerSource?,
|
containerSource: DeserializedContainerSource?,
|
||||||
factory: (IrPropertySymbol) -> IrProperty
|
factory: (IrPropertySymbol) -> IrProperty
|
||||||
): IrProperty {
|
): IrProperty =
|
||||||
if (signature == null) {
|
if (signature == null)
|
||||||
val descriptor = WrappedPropertyDescriptor()
|
factory(IrPropertySymbolImpl())
|
||||||
return symbolTable.declareProperty(0, 0, IrDeclarationOrigin.DEFINED, descriptor, isDelegated = false, factory).apply {
|
else
|
||||||
descriptor.bind(this)
|
symbolTable.declareProperty(signature, { Fir2IrPropertySymbol(signature, containerSource) }, factory)
|
||||||
}
|
|
||||||
}
|
|
||||||
return symbolTable.declareProperty(signature, { Fir2IrPropertySymbol(signature, containerSource) }, factory)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun getOrCreateIrProperty(
|
fun getOrCreateIrProperty(
|
||||||
property: FirProperty,
|
property: FirProperty,
|
||||||
@@ -859,28 +842,21 @@ class Fir2IrDeclarationStorage(
|
|||||||
field: FirField,
|
field: FirField,
|
||||||
origin: IrDeclarationOrigin = IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
|
origin: IrDeclarationOrigin = IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB
|
||||||
): IrField {
|
): IrField {
|
||||||
val descriptor = WrappedFieldDescriptor()
|
|
||||||
val type = field.returnTypeRef.toIrType()
|
val type = field.returnTypeRef.toIrType()
|
||||||
return field.convertWithOffsets { startOffset, endOffset ->
|
return field.convertWithOffsets { startOffset, endOffset ->
|
||||||
symbolTable.declareField(
|
irFactory.createField(
|
||||||
startOffset, endOffset,
|
startOffset, endOffset, origin, IrFieldSymbolImpl(),
|
||||||
origin, descriptor, type
|
field.name, type, components.visibilityConverter.convertToDescriptorVisibility(field.visibility),
|
||||||
) { symbol ->
|
isFinal = field.modality == Modality.FINAL,
|
||||||
irFactory.createField(
|
isExternal = false,
|
||||||
startOffset, endOffset, origin, symbol,
|
isStatic = field.isStatic
|
||||||
field.name, type, components.visibilityConverter.convertToDescriptorVisibility(field.visibility),
|
).apply {
|
||||||
isFinal = field.modality == Modality.FINAL,
|
field.initializer?.let {
|
||||||
isExternal = false,
|
val expression = visitor.convertToIrExpression(it)
|
||||||
isStatic = field.isStatic
|
expression.type = type
|
||||||
).apply {
|
initializer = irFactory.createExpressionBody(expression)
|
||||||
field.initializer?.let {
|
|
||||||
val expression = visitor.convertToIrExpression(it)
|
|
||||||
expression.type = type
|
|
||||||
initializer = irFactory.createExpressionBody(expression)
|
|
||||||
}
|
|
||||||
descriptor.bind(this)
|
|
||||||
fieldCache[field] = this
|
|
||||||
}
|
}
|
||||||
|
fieldCache[field] = this
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -891,33 +867,27 @@ class Fir2IrDeclarationStorage(
|
|||||||
useStubForDefaultValueStub: Boolean = true,
|
useStubForDefaultValueStub: Boolean = true,
|
||||||
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT
|
typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT
|
||||||
): IrValueParameter {
|
): IrValueParameter {
|
||||||
val descriptor = WrappedValueParameterDescriptor()
|
|
||||||
val origin = IrDeclarationOrigin.DEFINED
|
val origin = IrDeclarationOrigin.DEFINED
|
||||||
val type = valueParameter.returnTypeRef.toIrType()
|
val type = valueParameter.returnTypeRef.toIrType()
|
||||||
val irParameter = valueParameter.convertWithOffsets { startOffset, endOffset ->
|
val irParameter = valueParameter.convertWithOffsets { startOffset, endOffset ->
|
||||||
symbolTable.declareValueParameter(
|
irFactory.createValueParameter(
|
||||||
startOffset, endOffset, origin, descriptor, type
|
startOffset, endOffset, origin, IrValueParameterSymbolImpl(),
|
||||||
) { symbol ->
|
valueParameter.name, index, type,
|
||||||
irFactory.createValueParameter(
|
if (!valueParameter.isVararg) null
|
||||||
startOffset, endOffset, origin, symbol,
|
else valueParameter.returnTypeRef.coneType.arrayElementType()?.toIrType(typeContext),
|
||||||
valueParameter.name, index, type,
|
isCrossinline = valueParameter.isCrossinline, isNoinline = valueParameter.isNoinline,
|
||||||
if (!valueParameter.isVararg) null
|
isHidden = false, isAssignable = false
|
||||||
else valueParameter.returnTypeRef.coneType.arrayElementType()?.toIrType(typeContext),
|
).apply {
|
||||||
isCrossinline = valueParameter.isCrossinline, isNoinline = valueParameter.isNoinline,
|
if (valueParameter.defaultValue.let {
|
||||||
isHidden = false, isAssignable = false
|
it != null && (useStubForDefaultValueStub || it !is FirExpressionStub)
|
||||||
).apply {
|
|
||||||
descriptor.bind(this)
|
|
||||||
if (valueParameter.defaultValue.let {
|
|
||||||
it != null && (useStubForDefaultValueStub || it !is FirExpressionStub)
|
|
||||||
}
|
|
||||||
) {
|
|
||||||
this.defaultValue = factory.createExpressionBody(
|
|
||||||
IrErrorExpressionImpl(
|
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, type,
|
|
||||||
"Stub expression for default value of ${valueParameter.name}"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
) {
|
||||||
|
this.defaultValue = factory.createExpressionBody(
|
||||||
|
IrErrorExpressionImpl(
|
||||||
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET, type,
|
||||||
|
"Stub expression for default value of ${valueParameter.name}"
|
||||||
|
)
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -937,17 +907,11 @@ class Fir2IrDeclarationStorage(
|
|||||||
startOffset: Int, endOffset: Int,
|
startOffset: Int, endOffset: Int,
|
||||||
origin: IrDeclarationOrigin, name: Name, type: IrType,
|
origin: IrDeclarationOrigin, name: Name, type: IrType,
|
||||||
isVar: Boolean, isConst: Boolean, isLateinit: Boolean
|
isVar: Boolean, isConst: Boolean, isLateinit: Boolean
|
||||||
): IrVariable {
|
): IrVariable =
|
||||||
val descriptor = WrappedVariableDescriptor()
|
IrVariableImpl(
|
||||||
return symbolTable.declareVariable(startOffset, endOffset, origin, descriptor, type) { symbol ->
|
startOffset, endOffset, origin, IrVariableSymbolImpl(), name, type,
|
||||||
IrVariableImpl(
|
isVar, isConst, isLateinit
|
||||||
startOffset, endOffset, origin, symbol, name, type,
|
)
|
||||||
isVar, isConst, isLateinit
|
|
||||||
).apply {
|
|
||||||
descriptor.bind(this)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun createIrVariable(variable: FirVariable<*>, irParent: IrDeclarationParent, givenOrigin: IrDeclarationOrigin? = null): IrVariable {
|
fun createIrVariable(variable: FirVariable<*>, irParent: IrDeclarationParent, givenOrigin: IrDeclarationOrigin? = null): IrVariable {
|
||||||
val type = variable.returnTypeRef.toIrType()
|
val type = variable.returnTypeRef.toIrType()
|
||||||
@@ -974,12 +938,15 @@ class Fir2IrDeclarationStorage(
|
|||||||
val type = property.returnTypeRef.toIrType()
|
val type = property.returnTypeRef.toIrType()
|
||||||
val origin = IrDeclarationOrigin.DEFINED
|
val origin = IrDeclarationOrigin.DEFINED
|
||||||
val irProperty = property.convertWithOffsets { startOffset, endOffset ->
|
val irProperty = property.convertWithOffsets { startOffset, endOffset ->
|
||||||
val descriptor = WrappedVariableDescriptorWithAccessor()
|
irFactory.createLocalDelegatedProperty(
|
||||||
symbolTable.declareLocalDelegatedProperty(startOffset, endOffset, origin, descriptor, type) {
|
startOffset,
|
||||||
irFactory.createLocalDelegatedProperty(startOffset, endOffset, origin, it, property.name, type, property.isVar).apply {
|
endOffset,
|
||||||
descriptor.bind(this)
|
origin,
|
||||||
}
|
IrLocalDelegatedPropertySymbolImpl(),
|
||||||
}
|
property.name,
|
||||||
|
type,
|
||||||
|
property.isVar
|
||||||
|
)
|
||||||
}.apply {
|
}.apply {
|
||||||
parent = irParent
|
parent = irParent
|
||||||
metadata = FirMetadataSource.Property(property)
|
metadata = FirMetadataSource.Property(property)
|
||||||
|
|||||||
+106
-122
@@ -20,8 +20,6 @@ import org.jetbrains.kotlin.fir.types.FirTypeRef
|
|||||||
import org.jetbrains.kotlin.fir.types.coneType
|
import org.jetbrains.kotlin.fir.types.coneType
|
||||||
import org.jetbrains.kotlin.ir.builders.declarations.UNDEFINED_PARAMETER_INDEX
|
import org.jetbrains.kotlin.ir.builders.declarations.UNDEFINED_PARAMETER_INDEX
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedValueParameterDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrBlock
|
import org.jetbrains.kotlin.ir.expressions.IrBlock
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrGetValue
|
import org.jetbrains.kotlin.ir.expressions.IrGetValue
|
||||||
@@ -30,6 +28,8 @@ import org.jetbrains.kotlin.ir.expressions.impl.*
|
|||||||
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrConstructorSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrFunctionSymbol
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrSimpleFunctionSymbol
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.impl.IrSimpleFunctionSymbolImpl
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
import org.jetbrains.kotlin.ir.types.IrSimpleType
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.isUnit
|
import org.jetbrains.kotlin.ir.types.isUnit
|
||||||
@@ -187,59 +187,55 @@ internal class AdapterGenerator(
|
|||||||
): IrSimpleFunction {
|
): IrSimpleFunction {
|
||||||
val returnType = type.arguments.last().typeOrNull!!
|
val returnType = type.arguments.last().typeOrNull!!
|
||||||
val parameterTypes = type.arguments.dropLast(1).map { it.typeOrNull!! }
|
val parameterTypes = type.arguments.dropLast(1).map { it.typeOrNull!! }
|
||||||
val adapterFunctionDescriptor = WrappedSimpleFunctionDescriptor()
|
return irFactory.createFunction(
|
||||||
return symbolTable.declareSimpleFunction(adapterFunctionDescriptor) { irAdapterSymbol ->
|
startOffset, endOffset,
|
||||||
irFactory.createFunction(
|
IrDeclarationOrigin.ADAPTER_FOR_CALLABLE_REFERENCE,
|
||||||
startOffset, endOffset,
|
IrSimpleFunctionSymbolImpl(),
|
||||||
IrDeclarationOrigin.ADAPTER_FOR_CALLABLE_REFERENCE,
|
adaptee.name,
|
||||||
irAdapterSymbol,
|
DescriptorVisibilities.LOCAL,
|
||||||
adaptee.name,
|
Modality.FINAL,
|
||||||
DescriptorVisibilities.LOCAL,
|
returnType,
|
||||||
Modality.FINAL,
|
isInline = firAdaptee.isInline,
|
||||||
returnType,
|
isExternal = firAdaptee.isExternal,
|
||||||
isInline = firAdaptee.isInline,
|
isTailrec = firAdaptee.isTailRec,
|
||||||
isExternal = firAdaptee.isExternal,
|
isSuspend = firAdaptee.isSuspend || type.isSuspendFunction(),
|
||||||
isTailrec = firAdaptee.isTailRec,
|
isOperator = firAdaptee.isOperator,
|
||||||
isSuspend = firAdaptee.isSuspend || type.isSuspendFunction(),
|
isInfix = firAdaptee.isInfix,
|
||||||
isOperator = firAdaptee.isOperator,
|
isExpect = firAdaptee.isExpect,
|
||||||
isInfix = firAdaptee.isInfix,
|
isFakeOverride = false
|
||||||
isExpect = firAdaptee.isExpect,
|
).also { irAdapterFunction ->
|
||||||
isFakeOverride = false
|
irAdapterFunction.metadata = FirMetadataSource.Function(firAdaptee)
|
||||||
).also { irAdapterFunction ->
|
|
||||||
adapterFunctionDescriptor.bind(irAdapterFunction)
|
|
||||||
irAdapterFunction.metadata = FirMetadataSource.Function(firAdaptee)
|
|
||||||
|
|
||||||
symbolTable.enterScope(irAdapterFunction)
|
symbolTable.enterScope(irAdapterFunction)
|
||||||
irAdapterFunction.dispatchReceiverParameter = null
|
irAdapterFunction.dispatchReceiverParameter = null
|
||||||
val boundReceiver = boundDispatchReceiver ?: boundExtensionReceiver
|
val boundReceiver = boundDispatchReceiver ?: boundExtensionReceiver
|
||||||
when {
|
when {
|
||||||
boundReceiver == null ->
|
boundReceiver == null ->
|
||||||
irAdapterFunction.extensionReceiverParameter = null
|
irAdapterFunction.extensionReceiverParameter = null
|
||||||
boundDispatchReceiver != null && boundExtensionReceiver != null ->
|
boundDispatchReceiver != null && boundExtensionReceiver != null ->
|
||||||
error("Bound callable references can't have both receivers: ${callableReferenceAccess.render()}")
|
error("Bound callable references can't have both receivers: ${callableReferenceAccess.render()}")
|
||||||
else ->
|
else ->
|
||||||
irAdapterFunction.extensionReceiverParameter =
|
irAdapterFunction.extensionReceiverParameter =
|
||||||
createAdapterParameter(
|
createAdapterParameter(
|
||||||
irAdapterFunction,
|
irAdapterFunction,
|
||||||
Name.identifier("receiver"),
|
Name.identifier("receiver"),
|
||||||
index = UNDEFINED_PARAMETER_INDEX,
|
index = UNDEFINED_PARAMETER_INDEX,
|
||||||
boundReceiver.type,
|
boundReceiver.type,
|
||||||
IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE
|
IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE
|
||||||
)
|
)
|
||||||
}
|
|
||||||
irAdapterFunction.valueParameters += parameterTypes.mapIndexed { index, parameterType ->
|
|
||||||
createAdapterParameter(
|
|
||||||
irAdapterFunction,
|
|
||||||
Name.identifier("p$index"),
|
|
||||||
index,
|
|
||||||
parameterType,
|
|
||||||
IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE
|
|
||||||
)
|
|
||||||
}
|
|
||||||
symbolTable.leaveScope(irAdapterFunction)
|
|
||||||
|
|
||||||
irAdapterFunction.parent = conversionScope.parent()!!
|
|
||||||
}
|
}
|
||||||
|
irAdapterFunction.valueParameters += parameterTypes.mapIndexed { index, parameterType ->
|
||||||
|
createAdapterParameter(
|
||||||
|
irAdapterFunction,
|
||||||
|
Name.identifier("p$index"),
|
||||||
|
index,
|
||||||
|
parameterType,
|
||||||
|
IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_CALLABLE_REFERENCE
|
||||||
|
)
|
||||||
|
}
|
||||||
|
symbolTable.leaveScope(irAdapterFunction)
|
||||||
|
|
||||||
|
irAdapterFunction.parent = conversionScope.parent()!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -249,31 +245,23 @@ internal class AdapterGenerator(
|
|||||||
index: Int,
|
index: Int,
|
||||||
type: IrType,
|
type: IrType,
|
||||||
origin: IrDeclarationOrigin
|
origin: IrDeclarationOrigin
|
||||||
): IrValueParameter {
|
): IrValueParameter =
|
||||||
val startOffset = adapterFunction.startOffset
|
irFactory.createValueParameter(
|
||||||
val endOffset = adapterFunction.endOffset
|
adapterFunction.startOffset,
|
||||||
val descriptor = WrappedValueParameterDescriptor()
|
adapterFunction.endOffset,
|
||||||
return symbolTable.declareValueParameter(
|
origin,
|
||||||
startOffset, endOffset, origin, descriptor, type
|
IrValueParameterSymbolImpl(),
|
||||||
) { irAdapterParameterSymbol ->
|
name,
|
||||||
irFactory.createValueParameter(
|
index,
|
||||||
startOffset, endOffset,
|
type,
|
||||||
origin,
|
varargElementType = null,
|
||||||
irAdapterParameterSymbol,
|
isCrossinline = false,
|
||||||
name,
|
isNoinline = false,
|
||||||
index,
|
isHidden = false,
|
||||||
type,
|
isAssignable = false
|
||||||
varargElementType = null,
|
).also { irAdapterValueParameter ->
|
||||||
isCrossinline = false,
|
irAdapterValueParameter.parent = adapterFunction
|
||||||
isNoinline = false,
|
|
||||||
isHidden = false,
|
|
||||||
isAssignable = false
|
|
||||||
).also { irAdapterValueParameter ->
|
|
||||||
descriptor.bind(irAdapterValueParameter)
|
|
||||||
irAdapterValueParameter.parent = adapterFunction
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private fun IrValueDeclaration.toIrGetValue(startOffset: Int, endOffset: Int): IrGetValue =
|
private fun IrValueDeclaration.toIrGetValue(startOffset: Int, endOffset: Int): IrGetValue =
|
||||||
IrGetValueImpl(startOffset, endOffset, this.type, this.symbol)
|
IrGetValueImpl(startOffset, endOffset, this.type, this.symbol)
|
||||||
@@ -446,55 +434,51 @@ internal class AdapterGenerator(
|
|||||||
): IrSimpleFunction {
|
): IrSimpleFunction {
|
||||||
val returnType = type.arguments.last().typeOrNull!!
|
val returnType = type.arguments.last().typeOrNull!!
|
||||||
val parameterTypes = type.arguments.dropLast(1).map { it.typeOrNull!! }
|
val parameterTypes = type.arguments.dropLast(1).map { it.typeOrNull!! }
|
||||||
val adapterFunctionDescriptor = WrappedSimpleFunctionDescriptor()
|
return irFactory.createFunction(
|
||||||
return symbolTable.declareSimpleFunction(adapterFunctionDescriptor) { irAdapterSymbol ->
|
startOffset, endOffset,
|
||||||
irFactory.createFunction(
|
IrDeclarationOrigin.ADAPTER_FOR_SUSPEND_CONVERSION,
|
||||||
startOffset, endOffset,
|
IrSimpleFunctionSymbolImpl(),
|
||||||
IrDeclarationOrigin.ADAPTER_FOR_SUSPEND_CONVERSION,
|
// TODO: need a better way to avoid name clash
|
||||||
irAdapterSymbol,
|
Name.identifier("suspendConversion"),
|
||||||
// TODO: need a better way to avoid name clash
|
DescriptorVisibilities.LOCAL,
|
||||||
Name.identifier("suspendConversion"),
|
Modality.FINAL,
|
||||||
DescriptorVisibilities.LOCAL,
|
returnType,
|
||||||
Modality.FINAL,
|
isInline = false,
|
||||||
returnType,
|
isExternal = false,
|
||||||
isInline = false,
|
isTailrec = false,
|
||||||
isExternal = false,
|
isSuspend = true,
|
||||||
isTailrec = false,
|
isOperator = false,
|
||||||
isSuspend = true,
|
isInfix = false,
|
||||||
isOperator = false,
|
isExpect = false,
|
||||||
isInfix = false,
|
isFakeOverride = false
|
||||||
isExpect = false,
|
).also { irAdapterFunction ->
|
||||||
isFakeOverride = false
|
symbolTable.enterScope(irAdapterFunction)
|
||||||
).also { irAdapterFunction ->
|
irAdapterFunction.extensionReceiverParameter = createAdapterParameter(
|
||||||
adapterFunctionDescriptor.bind(irAdapterFunction)
|
irAdapterFunction,
|
||||||
symbolTable.enterScope(irAdapterFunction)
|
Name.identifier("callee"),
|
||||||
irAdapterFunction.extensionReceiverParameter = createAdapterParameter(
|
UNDEFINED_PARAMETER_INDEX,
|
||||||
|
argumentType,
|
||||||
|
IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION
|
||||||
|
)
|
||||||
|
irAdapterFunction.valueParameters += parameterTypes.mapIndexed { index, parameterType ->
|
||||||
|
createAdapterParameter(
|
||||||
irAdapterFunction,
|
irAdapterFunction,
|
||||||
Name.identifier("callee"),
|
Name.identifier("p$index"),
|
||||||
UNDEFINED_PARAMETER_INDEX,
|
index,
|
||||||
argumentType,
|
parameterType,
|
||||||
IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION
|
IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION
|
||||||
)
|
)
|
||||||
irAdapterFunction.valueParameters += parameterTypes.mapIndexed { index, parameterType ->
|
|
||||||
createAdapterParameter(
|
|
||||||
irAdapterFunction,
|
|
||||||
Name.identifier("p$index"),
|
|
||||||
index,
|
|
||||||
parameterType,
|
|
||||||
IrDeclarationOrigin.ADAPTER_PARAMETER_FOR_SUSPEND_CONVERSION
|
|
||||||
)
|
|
||||||
}
|
|
||||||
irAdapterFunction.body = irFactory.createBlockBody(startOffset, endOffset) {
|
|
||||||
val irCall = createAdapteeCallForArgument(startOffset, endOffset, irAdapterFunction, invokeSymbol)
|
|
||||||
if (returnType.isUnit()) {
|
|
||||||
statements.add(irCall)
|
|
||||||
} else {
|
|
||||||
statements.add(IrReturnImpl(startOffset, endOffset, irBuiltIns.nothingType, irAdapterFunction.symbol, irCall))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
symbolTable.leaveScope(irAdapterFunction)
|
|
||||||
irAdapterFunction.parent = conversionScope.parent()!!
|
|
||||||
}
|
}
|
||||||
|
irAdapterFunction.body = irFactory.createBlockBody(startOffset, endOffset) {
|
||||||
|
val irCall = createAdapteeCallForArgument(startOffset, endOffset, irAdapterFunction, invokeSymbol)
|
||||||
|
if (returnType.isUnit()) {
|
||||||
|
statements.add(irCall)
|
||||||
|
} else {
|
||||||
|
statements.add(IrReturnImpl(startOffset, endOffset, irBuiltIns.nothingType, irAdapterFunction.symbol, irCall))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
symbolTable.leaveScope(irAdapterFunction)
|
||||||
|
irAdapterFunction.parent = conversionScope.parent()!!
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
-2
@@ -49,7 +49,6 @@ internal class ClassMemberGenerator(
|
|||||||
if (irPrimaryConstructor != null) {
|
if (irPrimaryConstructor != null) {
|
||||||
with(declarationStorage) {
|
with(declarationStorage) {
|
||||||
enterScope(irPrimaryConstructor)
|
enterScope(irPrimaryConstructor)
|
||||||
irPrimaryConstructor.valueParameters.forEach { symbolTable.introduceValueParameter(it) }
|
|
||||||
irPrimaryConstructor.putParametersInScope(primaryConstructor)
|
irPrimaryConstructor.putParametersInScope(primaryConstructor)
|
||||||
convertFunctionContent(irPrimaryConstructor, primaryConstructor, containingClass = klass)
|
convertFunctionContent(irPrimaryConstructor, primaryConstructor, containingClass = klass)
|
||||||
}
|
}
|
||||||
@@ -86,7 +85,6 @@ internal class ClassMemberGenerator(
|
|||||||
// Scope for primary constructor should be entered before class declaration processing
|
// Scope for primary constructor should be entered before class declaration processing
|
||||||
with(declarationStorage) {
|
with(declarationStorage) {
|
||||||
enterScope(irFunction)
|
enterScope(irFunction)
|
||||||
irFunction.valueParameters.forEach { symbolTable.introduceValueParameter(it) }
|
|
||||||
irFunction.putParametersInScope(firFunction)
|
irFunction.putParametersInScope(firFunction)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+9
-19
@@ -30,8 +30,8 @@ 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.IrGeneratorContextBase
|
import org.jetbrains.kotlin.ir.builders.IrGeneratorContextBase
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedValueParameterDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
import org.jetbrains.kotlin.ir.expressions.IrMemberAccessExpression
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.impl.IrValueParameterSymbolImpl
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.util.*
|
import org.jetbrains.kotlin.ir.util.*
|
||||||
import org.jetbrains.kotlin.ir.util.DataClassMembersGenerator
|
import org.jetbrains.kotlin.ir.util.DataClassMembersGenerator
|
||||||
@@ -98,16 +98,14 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun generateDispatchReceiverParameter(irFunction: IrFunction, valueParameterDescriptor: WrappedValueParameterDescriptor) =
|
fun generateDispatchReceiverParameter(irFunction: IrFunction) =
|
||||||
irFunction.declareThisReceiverParameter(
|
irFunction.declareThisReceiverParameter(
|
||||||
components.symbolTable,
|
components.symbolTable,
|
||||||
irClass.defaultType,
|
irClass.defaultType,
|
||||||
origin,
|
origin,
|
||||||
UNDEFINED_OFFSET,
|
UNDEFINED_OFFSET,
|
||||||
UNDEFINED_OFFSET
|
UNDEFINED_OFFSET
|
||||||
).apply {
|
)
|
||||||
valueParameterDescriptor.bind(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private val FirSimpleFunction.matchesEqualsSignature: Boolean
|
private val FirSimpleFunction.matchesEqualsSignature: Boolean
|
||||||
@@ -223,7 +221,6 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
|||||||
returnType: IrType,
|
returnType: IrType,
|
||||||
otherParameterNeeded: Boolean = false
|
otherParameterNeeded: Boolean = false
|
||||||
): IrFunction {
|
): IrFunction {
|
||||||
val thisReceiverDescriptor = WrappedValueParameterDescriptor()
|
|
||||||
val firFunction = buildSimpleFunction {
|
val firFunction = buildSimpleFunction {
|
||||||
origin = FirDeclarationOrigin.Synthetic
|
origin = FirDeclarationOrigin.Synthetic
|
||||||
this.name = name
|
this.name = name
|
||||||
@@ -273,7 +270,7 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
|||||||
}
|
}
|
||||||
}.apply {
|
}.apply {
|
||||||
parent = irClass
|
parent = irClass
|
||||||
dispatchReceiverParameter = generateDispatchReceiverParameter(this, thisReceiverDescriptor)
|
dispatchReceiverParameter = generateDispatchReceiverParameter(this)
|
||||||
components.irBuiltIns.anyClass.descriptor.unsubstitutedMemberScope
|
components.irBuiltIns.anyClass.descriptor.unsubstitutedMemberScope
|
||||||
.getContributedFunctions(this.name, NoLookupLocation.FROM_BACKEND)
|
.getContributedFunctions(this.name, NoLookupLocation.FROM_BACKEND)
|
||||||
.singleOrNull { function -> function.name == this.name }
|
.singleOrNull { function -> function.name == this.name }
|
||||||
@@ -283,20 +280,13 @@ class DataClassMembersGenerator(val components: Fir2IrComponents) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun createSyntheticIrParameter(irFunction: IrFunction, name: Name, type: IrType, index: Int = 0): IrValueParameter {
|
private fun createSyntheticIrParameter(irFunction: IrFunction, name: Name, type: IrType, index: Int = 0): IrValueParameter =
|
||||||
val descriptor = WrappedValueParameterDescriptor()
|
components.irFactory.createValueParameter(
|
||||||
return components.symbolTable.declareValueParameter(
|
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, IrValueParameterSymbolImpl(), name, index, type, null,
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, descriptor, type
|
isCrossinline = false, isNoinline = false, isHidden = false, isAssignable = false
|
||||||
) { symbol ->
|
).apply {
|
||||||
components.irFactory.createValueParameter(
|
|
||||||
UNDEFINED_OFFSET, UNDEFINED_OFFSET, origin, symbol, name, index, type, null,
|
|
||||||
isCrossinline = false, isNoinline = false, isHidden = false, isAssignable = false
|
|
||||||
)
|
|
||||||
}.apply {
|
|
||||||
parent = irFunction
|
parent = irFunction
|
||||||
descriptor.bind(this)
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ import org.jetbrains.kotlin.ir.declarations.lazy.lazyVar
|
|||||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||||
import kotlin.properties.ReadWriteProperty
|
import kotlin.properties.ReadWriteProperty
|
||||||
|
|
||||||
interface AbstractFir2IrLazyDeclaration<F : FirMemberDeclaration, D : IrSymbolOwner> :
|
interface AbstractFir2IrLazyDeclaration<F : FirMemberDeclaration, D : IrDeclaration> :
|
||||||
IrDeclaration, IrDeclarationParent, Fir2IrComponents {
|
IrDeclaration, IrDeclarationParent, Fir2IrComponents {
|
||||||
|
|
||||||
val fir: F
|
val fir: F
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.ir.symbols.IrBindableSymbol
|
|||||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedContainerSource
|
||||||
|
|
||||||
abstract class Fir2IrBindableSymbol<out D : DeclarationDescriptor, B : IrSymbolOwner>(
|
abstract class Fir2IrBindableSymbol<out D : DeclarationDescriptor, B : IrDeclaration>(
|
||||||
override val signature: IdSignature,
|
override val signature: IdSignature,
|
||||||
private val containerSource: DeserializedContainerSource? = null
|
private val containerSource: DeserializedContainerSource? = null
|
||||||
) : IrBindableSymbol<D, B> {
|
) : IrBindableSymbol<D, B> {
|
||||||
@@ -34,31 +34,9 @@ abstract class Fir2IrBindableSymbol<out D : DeclarationDescriptor, B : IrSymbolO
|
|||||||
get() = _owner != null
|
get() = _owner != null
|
||||||
|
|
||||||
@ObsoleteDescriptorBasedAPI
|
@ObsoleteDescriptorBasedAPI
|
||||||
override val descriptor: D by lazy {
|
override val descriptor: D
|
||||||
val result = when (val owner = owner) {
|
|
||||||
is IrEnumEntry -> WrappedEnumEntryDescriptor().apply { bind(owner) }
|
|
||||||
is IrClass -> WrappedClassDescriptor().apply { bind(owner) }
|
|
||||||
is IrConstructor -> WrappedClassConstructorDescriptor().apply { bind(owner) }
|
|
||||||
is IrSimpleFunction -> when {
|
|
||||||
owner.name.isSpecial && owner.name.asString().startsWith(GETTER_PREFIX) ->
|
|
||||||
WrappedPropertyGetterDescriptor()
|
|
||||||
owner.name.isSpecial && owner.name.asString().startsWith(SETTER_PREFIX) ->
|
|
||||||
WrappedPropertySetterDescriptor()
|
|
||||||
else ->
|
|
||||||
WrappedSimpleFunctionDescriptor()
|
|
||||||
}.apply { bind(owner) }
|
|
||||||
is IrVariable -> WrappedVariableDescriptor().apply { bind(owner) }
|
|
||||||
is IrValueParameter -> WrappedValueParameterDescriptor().apply { bind(owner) }
|
|
||||||
is IrTypeParameter -> WrappedTypeParameterDescriptor().apply { bind(owner) }
|
|
||||||
is IrProperty -> WrappedPropertyDescriptor().apply { bind(owner) }
|
|
||||||
is IrField -> WrappedFieldDescriptor().apply { bind(owner) }
|
|
||||||
is IrTypeAlias -> WrappedTypeAliasDescriptor().apply { bind(owner) }
|
|
||||||
else -> throw IllegalStateException("Unsupported owner in Fir2IrBindableSymbol: $owner")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
result as D
|
get() = owner.toIrBasedDescriptor() as D
|
||||||
}
|
|
||||||
|
|
||||||
@ObsoleteDescriptorBasedAPI
|
@ObsoleteDescriptorBasedAPI
|
||||||
override val hasDescriptor: Boolean
|
override val hasDescriptor: Boolean
|
||||||
|
|||||||
+2
-1
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.descriptors.Modality
|
|||||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrBody
|
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||||
@@ -130,7 +131,7 @@ class IrFakeOverrideFunctionImpl(
|
|||||||
|
|
||||||
@ObsoleteDescriptorBasedAPI
|
@ObsoleteDescriptorBasedAPI
|
||||||
override val descriptor
|
override val descriptor
|
||||||
get() = _symbol?.descriptor ?: WrappedSimpleFunctionDescriptor()
|
get() = _symbol?.descriptor ?: this.toIrBasedDescriptor()
|
||||||
|
|
||||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||||
override fun acquireSymbol(symbol: IrSimpleFunctionSymbol): IrSimpleFunction {
|
override fun acquireSymbol(symbol: IrSimpleFunctionSymbol): IrSimpleFunction {
|
||||||
|
|||||||
+2
-1
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.descriptors.DescriptorVisibility
|
|||||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedPropertyDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedPropertyDescriptor
|
||||||
|
import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -114,7 +115,7 @@ class IrFakeOverridePropertyImpl(
|
|||||||
|
|
||||||
@ObsoleteDescriptorBasedAPI
|
@ObsoleteDescriptorBasedAPI
|
||||||
override val descriptor
|
override val descriptor
|
||||||
get() = _symbol?.descriptor ?: WrappedPropertyDescriptor()
|
get() = _symbol?.descriptor ?: this.toIrBasedDescriptor()
|
||||||
|
|
||||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||||
override fun acquireSymbol(symbol: IrPropertySymbol): IrProperty {
|
override fun acquireSymbol(symbol: IrPropertySymbol): IrProperty {
|
||||||
|
|||||||
+3
-1
@@ -12,7 +12,9 @@ import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
|||||||
import org.jetbrains.kotlin.ir.declarations.*
|
import org.jetbrains.kotlin.ir.declarations.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier
|
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier
|
||||||
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.FunctionCarrier
|
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.FunctionCarrier
|
||||||
|
import org.jetbrains.kotlin.ir.descriptors.IrBasedSimpleFunctionDescriptor
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor
|
||||||
|
import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrBody
|
import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||||
@@ -236,7 +238,7 @@ internal class PersistentIrFakeOverrideFunction(
|
|||||||
|
|
||||||
@ObsoleteDescriptorBasedAPI
|
@ObsoleteDescriptorBasedAPI
|
||||||
override val descriptor
|
override val descriptor
|
||||||
get() = _symbol?.descriptor ?: WrappedSimpleFunctionDescriptor()
|
get() = _symbol?.descriptor ?: this.toIrBasedDescriptor()
|
||||||
|
|
||||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||||
override fun acquireSymbol(symbol: IrSimpleFunctionSymbol): IrSimpleFunction {
|
override fun acquireSymbol(symbol: IrSimpleFunctionSymbol): IrSimpleFunction {
|
||||||
|
|||||||
+2
-1
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.ir.declarations.*
|
|||||||
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier
|
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.Carrier
|
||||||
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.PropertyCarrier
|
import org.jetbrains.kotlin.ir.declarations.persistent.carriers.PropertyCarrier
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedPropertyDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedPropertyDescriptor
|
||||||
|
import org.jetbrains.kotlin.ir.descriptors.toIrBasedDescriptor
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
@@ -165,7 +166,7 @@ internal class PersistentIrFakeOverrideProperty(
|
|||||||
|
|
||||||
@ObsoleteDescriptorBasedAPI
|
@ObsoleteDescriptorBasedAPI
|
||||||
override val descriptor
|
override val descriptor
|
||||||
get() = _symbol?.descriptor ?: WrappedPropertyDescriptor()
|
get() = _symbol?.descriptor ?: this.toIrBasedDescriptor()
|
||||||
|
|
||||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
||||||
override fun acquireSymbol(symbol: IrPropertySymbol): IrProperty {
|
override fun acquireSymbol(symbol: IrPropertySymbol): IrProperty {
|
||||||
|
|||||||
@@ -12,9 +12,7 @@ import org.jetbrains.kotlin.ir.declarations.impl.IrExternalPackageFragmentImpl
|
|||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrScriptImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrScriptImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl
|
import org.jetbrains.kotlin.ir.declarations.impl.IrVariableImpl
|
||||||
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazySymbolTable
|
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazySymbolTable
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedDeclarationDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.*
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedPropertyDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedSimpleFunctionDescriptor
|
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
import org.jetbrains.kotlin.ir.expressions.IrExpression
|
||||||
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
import org.jetbrains.kotlin.ir.expressions.IrExpressionBody
|
||||||
import org.jetbrains.kotlin.ir.symbols.*
|
import org.jetbrains.kotlin.ir.symbols.*
|
||||||
@@ -1046,34 +1044,6 @@ class SymbolTable(
|
|||||||
throw IllegalArgumentException("Unexpected value descriptor: $value")
|
throw IllegalArgumentException("Unexpected value descriptor: $value")
|
||||||
}
|
}
|
||||||
|
|
||||||
@OptIn(ObsoleteDescriptorBasedAPI::class)
|
|
||||||
fun wrappedTopLevelCallableDescriptors(): Set<DescriptorWithContainerSource> {
|
|
||||||
val result = mutableSetOf<DescriptorWithContainerSource>()
|
|
||||||
for (descriptor in simpleFunctionSymbolTable.descriptorToSymbol.keys) {
|
|
||||||
if (descriptor is WrappedSimpleFunctionDescriptor && descriptor.owner.parent is IrPackageFragment) {
|
|
||||||
result.add(descriptor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (symbol in simpleFunctionSymbolTable.idSigToSymbol.values) {
|
|
||||||
val descriptor = symbol.descriptor
|
|
||||||
if (descriptor is WrappedSimpleFunctionDescriptor && symbol.owner.parent is IrPackageFragment) {
|
|
||||||
result.add(descriptor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (descriptor in propertySymbolTable.descriptorToSymbol.keys) {
|
|
||||||
if (descriptor is WrappedPropertyDescriptor && descriptor.owner.parent is IrPackageFragment) {
|
|
||||||
result.add(descriptor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (symbol in propertySymbolTable.idSigToSymbol.values) {
|
|
||||||
val descriptor = symbol.descriptor
|
|
||||||
if (descriptor is WrappedPropertyDescriptor && symbol.owner.parent is IrPackageFragment) {
|
|
||||||
result.add(descriptor)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline fun <D : DeclarationDescriptor, IR : IrSymbolOwner, S : IrBindableSymbol<D, IR>> FlatSymbolTable<D, IR, S>.forEachPublicSymbolImpl(
|
private inline fun <D : DeclarationDescriptor, IR : IrSymbolOwner, S : IrBindableSymbol<D, IR>> FlatSymbolTable<D, IR, S>.forEachPublicSymbolImpl(
|
||||||
block: (IrSymbol) -> Unit
|
block: (IrSymbol) -> Unit
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -8,11 +8,12 @@ package org.jetbrains.kotlin.ir.util
|
|||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters
|
import org.jetbrains.kotlin.descriptors.ClassifierDescriptorWithTypeParameters
|
||||||
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
import org.jetbrains.kotlin.descriptors.TypeParameterDescriptor
|
||||||
|
import org.jetbrains.kotlin.ir.descriptors.IrBasedTypeParameterDescriptor
|
||||||
import org.jetbrains.kotlin.ir.descriptors.WrappedTypeParameterDescriptor
|
import org.jetbrains.kotlin.ir.descriptors.WrappedTypeParameterDescriptor
|
||||||
|
|
||||||
val TypeParameterDescriptor.originalTypeParameter: TypeParameterDescriptor
|
val TypeParameterDescriptor.originalTypeParameter: TypeParameterDescriptor
|
||||||
get() =
|
get() =
|
||||||
if (this is WrappedTypeParameterDescriptor) {
|
if (this is WrappedTypeParameterDescriptor || this is IrBasedTypeParameterDescriptor) {
|
||||||
original
|
original
|
||||||
} else {
|
} else {
|
||||||
when (val container = containingDeclaration.original) {
|
when (val container = containingDeclaration.original) {
|
||||||
|
|||||||
Reference in New Issue
Block a user