[FIR2IR] Support type aliases properly
This commit is contained in:
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.fir.resolve.firProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrEnumEntrySymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrTypeAliasSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.ConeClassLikeLookupTagImpl
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirClassSymbol
|
||||
@@ -19,6 +20,7 @@ import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.ir.declarations.*
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrClassImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrEnumEntryImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrTypeAliasImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrTypeParameterImpl
|
||||
import org.jetbrains.kotlin.ir.descriptors.*
|
||||
import org.jetbrains.kotlin.ir.expressions.impl.IrEnumConstructorCallImpl
|
||||
@@ -167,6 +169,28 @@ class Fir2IrClassifierStorage(
|
||||
return irClass
|
||||
}
|
||||
|
||||
fun registerTypeAlias(
|
||||
typeAlias: FirTypeAlias,
|
||||
parent: IrFile
|
||||
): IrTypeAlias {
|
||||
val signature = signatureComposer.composeSignature(typeAlias)!!
|
||||
preCacheTypeParameters(typeAlias)
|
||||
return typeAlias.convertWithOffsets { startOffset, endOffset ->
|
||||
symbolTable.declareTypeAlias(signature, { Fir2IrTypeAliasSymbol(signature) }) { symbol ->
|
||||
IrTypeAliasImpl(
|
||||
startOffset, endOffset, symbol,
|
||||
typeAlias.name, typeAlias.visibility,
|
||||
typeAlias.expandedTypeRef.toIrType(),
|
||||
typeAlias.isActual, IrDeclarationOrigin.DEFINED
|
||||
).apply {
|
||||
this.parent = parent
|
||||
setTypeParameters(typeAlias)
|
||||
parent.declarations += this
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun declareIrClass(signature: IdSignature?, factory: (IrClassSymbol) -> IrClass): IrClass {
|
||||
if (signature == null) {
|
||||
val descriptor = WrappedClassDescriptor()
|
||||
|
||||
@@ -61,8 +61,9 @@ class Fir2IrConverter(
|
||||
|
||||
fun processClassHeaders(file: FirFile) {
|
||||
file.declarations.forEach {
|
||||
if (it is FirRegularClass) {
|
||||
processClassAndNestedClassHeaders(it)
|
||||
when (it) {
|
||||
is FirRegularClass -> processClassAndNestedClassHeaders(it)
|
||||
is FirTypeAlias -> classifierStorage.registerTypeAlias(it, declarationStorage.getIrFile(file))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -35,6 +35,10 @@ class FirBasedSignatureComposer(private val mangler: FirMangler) : Fir2IrSignatu
|
||||
//platformSpecificClass(descriptor)
|
||||
}
|
||||
|
||||
override fun visitTypeAlias(typeAlias: FirTypeAlias) {
|
||||
setExpected(typeAlias.isExpect)
|
||||
}
|
||||
|
||||
override fun visitConstructor(constructor: FirConstructor) {
|
||||
hashId = mangler.run { constructor.signatureMangle }
|
||||
setExpected(constructor.isExpect)
|
||||
@@ -68,6 +72,10 @@ class FirBasedSignatureComposer(private val mangler: FirMangler) : Fir2IrSignatu
|
||||
val classId = declaration.classId
|
||||
IdSignature.PublicSignature(classId.packageFqName, classId.relativeClassName, builder.hashId, builder.mask)
|
||||
}
|
||||
declaration is FirTypeAlias -> {
|
||||
val classId = declaration.symbol.classId
|
||||
IdSignature.PublicSignature(classId.packageFqName, classId.relativeClassName, builder.hashId, builder.mask)
|
||||
}
|
||||
declaration is FirCallableMemberDeclaration<*> -> {
|
||||
val callableId = declaration.symbol.callableId
|
||||
IdSignature.PublicSignature(callableId.packageName, callableId.relativeCallableName, builder.hashId, builder.mask)
|
||||
|
||||
@@ -60,6 +60,7 @@ abstract class Fir2IrBindableSymbol<out D : DeclarationDescriptor, B : IrSymbolO
|
||||
WrappedPropertyDescriptor()
|
||||
}.apply { bind(owner) }
|
||||
is IrField -> WrappedFieldDescriptor().apply { bind(owner) }
|
||||
is IrTypeAlias -> WrappedTypeAliasDescriptor().apply { bind(owner) }
|
||||
else -> throw IllegalStateException("Unsupported owner in Fir2IrBindableSymbol: $owner")
|
||||
} as D
|
||||
}
|
||||
|
||||
@@ -15,6 +15,10 @@ class Fir2IrClassSymbol(signature: IdSignature) :
|
||||
Fir2IrBindableSymbol<ClassDescriptor, IrClass>(signature),
|
||||
IrClassSymbol
|
||||
|
||||
class Fir2IrTypeAliasSymbol(signature: IdSignature) :
|
||||
Fir2IrBindableSymbol<TypeAliasDescriptor, IrTypeAlias>(signature),
|
||||
IrTypeAliasSymbol
|
||||
|
||||
class Fir2IrEnumEntrySymbol(signature: IdSignature) :
|
||||
Fir2IrBindableSymbol<ClassDescriptor, IrEnumEntry>(signature),
|
||||
IrEnumEntrySymbol
|
||||
|
||||
@@ -722,6 +722,14 @@ open class SymbolTable(
|
||||
fun declareTypeAlias(descriptor: TypeAliasDescriptor, factory: (IrTypeAliasSymbol) -> IrTypeAlias): IrTypeAlias =
|
||||
typeAliasSymbolTable.declare(descriptor, { createTypeAliasSymbol(descriptor) }, factory)
|
||||
|
||||
fun declareTypeAlias(
|
||||
sig: IdSignature,
|
||||
symbolFactory: () -> IrTypeAliasSymbol,
|
||||
factory: (IrTypeAliasSymbol) -> IrTypeAlias
|
||||
): IrTypeAlias {
|
||||
return typeAliasSymbolTable.declare(sig, symbolFactory, factory)
|
||||
}
|
||||
|
||||
fun declareTypeAliasIfNotExists(descriptor: TypeAliasDescriptor, factory: (IrTypeAliasSymbol) -> IrTypeAlias): IrTypeAlias =
|
||||
typeAliasSymbolTable.declareIfNotExists(descriptor, { createTypeAliasSymbol(descriptor) }, factory)
|
||||
|
||||
|
||||
Vendored
+3
@@ -1,4 +1,7 @@
|
||||
FILE fqName:<root> fileName:/delegatingConstructorCallToTypeAliasConstructor.kt
|
||||
TYPEALIAS name:CT visibility:public expandedType:<root>.Cell<T of <root>.CT>
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
|
||||
TYPEALIAS name:CStr visibility:public expandedType:<root>.Cell<kotlin.String>
|
||||
CLASS CLASS name:Cell modality:OPEN visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Cell<T of <root>.Cell>
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
|
||||
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
FILE fqName:<root> fileName:/typeAliasesWithAnnotations.kt
|
||||
TYPEALIAS name:TestTypeAlias visibility:public expandedType:kotlin.String
|
||||
CLASS ANNOTATION_CLASS name:TestAnn modality:FINAL visibility:public superTypes:[kotlin.Annotation]
|
||||
annotations:
|
||||
Target(allowedTargets = GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:TYPEALIAS' type=kotlin.annotation.AnnotationTarget)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
FILE fqName:<root> fileName:/fileWithTypeAliasesOnly.kt
|
||||
@@ -1 +1,2 @@
|
||||
// FIR_IDENTICAL
|
||||
typealias Bar<T> = (T) -> String
|
||||
@@ -1,4 +1,5 @@
|
||||
FILE fqName:<root> fileName:/typeAlias.kt
|
||||
TYPEALIAS name:Test1 visibility:public expandedType:kotlin.String
|
||||
FUN name:foo visibility:public modality:FINAL <> () returnType:kotlin.Unit
|
||||
BLOCK_BODY
|
||||
BLOCK type=kotlin.Unit origin=null
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
FILE fqName:<root> fileName:/kt16905.kt
|
||||
TYPEALIAS name:OI visibility:public expandedType:<root>.Outer.Inner
|
||||
CLASS CLASS name:Outer modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Outer
|
||||
CONSTRUCTOR visibility:public <> () returnType:<root>.Outer [primary]
|
||||
|
||||
+1
@@ -1,4 +1,5 @@
|
||||
FILE fqName:<root> fileName:/specializedTypeAliasConstructorCall.kt
|
||||
TYPEALIAS name:IntAlias visibility:public expandedType:<root>.Cell<kotlin.Int>
|
||||
CLASS CLASS name:Cell modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.Cell<T of <root>.Cell>
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
FILE fqName:<root> fileName:/typeAliasConstructorReference.kt
|
||||
TYPEALIAS name:CA visibility:public expandedType:<root>.C
|
||||
TYPEALIAS name:NA visibility:public expandedType:<root>.Host.Nested
|
||||
CLASS CLASS name:C modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.C
|
||||
CONSTRUCTOR visibility:public <> (x:kotlin.Int) returnType:<root>.C [primary]
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
FILE fqName:<root> fileName:/integerCoercionToT.kt
|
||||
TYPEALIAS name:CInt32Var visibility:public expandedType:<root>.CInt32VarX<kotlin.Int>
|
||||
CLASS INTERFACE name:CPointed modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.CPointed
|
||||
FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator]
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
FILE fqName:<root> fileName:/typeAliasCtorForGenericClass.kt
|
||||
TYPEALIAS name:B visibility:public expandedType:<root>.A<X of <root>.B>
|
||||
TYPE_PARAMETER name:X index:0 variance: superTypes:[kotlin.Any?]
|
||||
TYPEALIAS name:B2 visibility:public expandedType:<root>.A<<root>.A<T of <root>.B2>>
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
|
||||
CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any]
|
||||
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:<root>.A<Q of <root>.A>
|
||||
TYPE_PARAMETER name:Q index:0 variance: superTypes:[kotlin.Any?]
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
FILE fqName:<root> fileName:/abbreviatedTypes.kt
|
||||
TYPEALIAS name:I visibility:public expandedType:kotlin.Int
|
||||
TYPEALIAS name:L visibility:public expandedType:kotlin.collections.List<T of <root>.L>
|
||||
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?]
|
||||
FUN name:test1 visibility:public modality:FINAL <> (x:kotlin.collections.List<kotlin.Int>) returnType:kotlin.collections.List<kotlin.Int>
|
||||
VALUE_PARAMETER name:x index:0 type:kotlin.collections.List<kotlin.Int>
|
||||
BLOCK_BODY
|
||||
|
||||
Reference in New Issue
Block a user