Introduce Fir2IrBuiltIns & move extension function type inside
This commit is contained in:
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* 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.fir.FirSession
|
||||||
|
import org.jetbrains.kotlin.fir.resolve.firSymbolProvider
|
||||||
|
import org.jetbrains.kotlin.fir.types.CompilerConeAttributes
|
||||||
|
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
||||||
|
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
|
||||||
|
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||||
|
import org.jetbrains.kotlin.ir.types.defaultType
|
||||||
|
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
||||||
|
|
||||||
|
class Fir2IrBuiltIns(
|
||||||
|
private val components: Fir2IrComponents,
|
||||||
|
session: FirSession
|
||||||
|
) : Fir2IrComponents by components {
|
||||||
|
private val extensionFunctionTypeAnnotationSymbol by lazy {
|
||||||
|
session.firSymbolProvider.getClassLikeSymbolByFqName(CompilerConeAttributes.ExtensionFunctionType.ANNOTATION_CLASS_ID)!!
|
||||||
|
.toSymbol(session, classifierStorage, ConversionTypeContext.DEFAULT) as IrClassSymbol
|
||||||
|
}
|
||||||
|
|
||||||
|
internal fun extensionFunctionTypeAnnotationConstructorCall() =
|
||||||
|
IrConstructorCallImpl.fromSymbolOwner(
|
||||||
|
extensionFunctionTypeAnnotationSymbol.defaultType,
|
||||||
|
extensionFunctionTypeAnnotationSymbol.owner.declarations.firstIsInstance<IrConstructor>().symbol
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -18,6 +18,7 @@ interface Fir2IrComponents {
|
|||||||
val scopeSession: ScopeSession
|
val scopeSession: ScopeSession
|
||||||
val symbolTable: SymbolTable
|
val symbolTable: SymbolTable
|
||||||
val irBuiltIns: IrBuiltIns
|
val irBuiltIns: IrBuiltIns
|
||||||
|
val builtIns: Fir2IrBuiltIns
|
||||||
val irFactory: IrFactory
|
val irFactory: IrFactory
|
||||||
val classifierStorage: Fir2IrClassifierStorage
|
val classifierStorage: Fir2IrClassifierStorage
|
||||||
val declarationStorage: Fir2IrDeclarationStorage
|
val declarationStorage: Fir2IrDeclarationStorage
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ class Fir2IrComponentsStorage(
|
|||||||
override lateinit var typeConverter: Fir2IrTypeConverter
|
override lateinit var typeConverter: Fir2IrTypeConverter
|
||||||
override lateinit var callGenerator: CallAndReferenceGenerator
|
override lateinit var callGenerator: CallAndReferenceGenerator
|
||||||
override lateinit var fakeOverrideGenerator: FakeOverrideGenerator
|
override lateinit var fakeOverrideGenerator: FakeOverrideGenerator
|
||||||
|
override lateinit var builtIns: Fir2IrBuiltIns
|
||||||
|
|
||||||
override val signatureComposer = FirBasedSignatureComposer(mangler)
|
override val signatureComposer = FirBasedSignatureComposer(mangler)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -215,26 +215,28 @@ class Fir2IrConverter(
|
|||||||
)
|
)
|
||||||
constantValueGenerator.typeTranslator = typeTranslator
|
constantValueGenerator.typeTranslator = typeTranslator
|
||||||
typeTranslator.constantValueGenerator = constantValueGenerator
|
typeTranslator.constantValueGenerator = constantValueGenerator
|
||||||
val builtIns = IrBuiltIns(moduleDescriptor.builtIns, typeTranslator, symbolTable)
|
val irBuiltIns = IrBuiltIns(moduleDescriptor.builtIns, typeTranslator, symbolTable)
|
||||||
FirBuiltinSymbols(builtIns, moduleDescriptor.builtIns, symbolTable)
|
FirBuiltinSymbols(irBuiltIns, moduleDescriptor.builtIns, symbolTable)
|
||||||
val sourceManager = PsiSourceManager()
|
val sourceManager = PsiSourceManager()
|
||||||
val components = Fir2IrComponentsStorage(session, scopeSession, symbolTable, builtIns, irFactory, mangler)
|
val components = Fir2IrComponentsStorage(session, scopeSession, symbolTable, irBuiltIns, irFactory, mangler)
|
||||||
val conversionScope = Fir2IrConversionScope()
|
val conversionScope = Fir2IrConversionScope()
|
||||||
val classifierStorage = Fir2IrClassifierStorage(components)
|
val classifierStorage = Fir2IrClassifierStorage(components)
|
||||||
val declarationStorage = Fir2IrDeclarationStorage(components, moduleDescriptor)
|
val declarationStorage = Fir2IrDeclarationStorage(components, moduleDescriptor)
|
||||||
val typeConverter = Fir2IrTypeConverter(components)
|
val typeConverter = Fir2IrTypeConverter(components)
|
||||||
|
val builtIns = Fir2IrBuiltIns(components, session)
|
||||||
components.declarationStorage = declarationStorage
|
components.declarationStorage = declarationStorage
|
||||||
components.classifierStorage = classifierStorage
|
components.classifierStorage = classifierStorage
|
||||||
components.typeConverter = typeConverter
|
components.typeConverter = typeConverter
|
||||||
|
components.builtIns = builtIns
|
||||||
val irFiles = mutableListOf<IrFile>()
|
val irFiles = mutableListOf<IrFile>()
|
||||||
|
|
||||||
val converter = Fir2IrConverter(moduleDescriptor, sourceManager, components)
|
val converter = Fir2IrConverter(moduleDescriptor, sourceManager, components)
|
||||||
for (firFile in firFiles) {
|
for (firFile in firFiles) {
|
||||||
irFiles += converter.registerFileAndClasses(firFile)
|
irFiles += converter.registerFileAndClasses(firFile)
|
||||||
}
|
}
|
||||||
val irModuleFragment = IrModuleFragmentImpl(moduleDescriptor, builtIns, irFiles)
|
val irModuleFragment = IrModuleFragmentImpl(moduleDescriptor, irBuiltIns, irFiles)
|
||||||
val irProviders =
|
val irProviders =
|
||||||
generateTypicalIrProviderList(irModuleFragment.descriptor, builtIns, symbolTable, extensions = generatorExtensions)
|
generateTypicalIrProviderList(irModuleFragment.descriptor, irBuiltIns, symbolTable, extensions = generatorExtensions)
|
||||||
val externalDependenciesGenerator = ExternalDependenciesGenerator(
|
val externalDependenciesGenerator = ExternalDependenciesGenerator(
|
||||||
symbolTable,
|
symbolTable,
|
||||||
irProviders,
|
irProviders,
|
||||||
|
|||||||
@@ -7,24 +7,20 @@ package org.jetbrains.kotlin.fir.backend
|
|||||||
|
|
||||||
import org.jetbrains.kotlin.fir.backend.generators.AnnotationGenerator
|
import org.jetbrains.kotlin.fir.backend.generators.AnnotationGenerator
|
||||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||||
import org.jetbrains.kotlin.fir.resolve.firSymbolProvider
|
|
||||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.fir.types.impl.*
|
import org.jetbrains.kotlin.fir.types.impl.*
|
||||||
import org.jetbrains.kotlin.ir.declarations.IrConstructor
|
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||||
import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl
|
|
||||||
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
import org.jetbrains.kotlin.ir.symbols.IrClassSymbol
|
||||||
import org.jetbrains.kotlin.ir.types.IrType
|
import org.jetbrains.kotlin.ir.types.IrType
|
||||||
import org.jetbrains.kotlin.ir.types.IrTypeArgument
|
import org.jetbrains.kotlin.ir.types.IrTypeArgument
|
||||||
import org.jetbrains.kotlin.ir.types.defaultType
|
|
||||||
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
import org.jetbrains.kotlin.ir.types.impl.IrSimpleTypeImpl
|
||||||
import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl
|
import org.jetbrains.kotlin.ir.types.impl.IrStarProjectionImpl
|
||||||
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection
|
||||||
import org.jetbrains.kotlin.name.ClassId
|
import org.jetbrains.kotlin.name.ClassId
|
||||||
import org.jetbrains.kotlin.types.Variance
|
import org.jetbrains.kotlin.types.Variance
|
||||||
import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance
|
|
||||||
|
|
||||||
class Fir2IrTypeConverter(
|
class Fir2IrTypeConverter(
|
||||||
private val components: Fir2IrComponents
|
private val components: Fir2IrComponents
|
||||||
@@ -62,14 +58,6 @@ class Fir2IrTypeConverter(
|
|||||||
StandardClassIds.Char to irBuiltIns.charType
|
StandardClassIds.Char to irBuiltIns.charType
|
||||||
)
|
)
|
||||||
|
|
||||||
internal val extensionFunctionTypeAnnotationConstructorCall by lazy {
|
|
||||||
val symbol =
|
|
||||||
session.firSymbolProvider.getClassLikeSymbolByFqName(CompilerConeAttributes.ExtensionFunctionType.ANNOTATION_CLASS_ID)!!
|
|
||||||
.toSymbol(session, classifierStorage, ConversionTypeContext.DEFAULT) as IrClassSymbol
|
|
||||||
val ctor = symbol.owner.declarations.firstIsInstance<IrConstructor>()
|
|
||||||
IrConstructorCallImpl(0, 0, symbol.defaultType, ctor.symbol, 0, 0, 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun FirTypeRef.toIrType(typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT): IrType {
|
fun FirTypeRef.toIrType(typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT): IrType {
|
||||||
return when (this) {
|
return when (this) {
|
||||||
!is FirResolvedTypeRef -> createErrorType()
|
!is FirResolvedTypeRef -> createErrorType()
|
||||||
@@ -98,11 +86,14 @@ class Fir2IrTypeConverter(
|
|||||||
val firSymbol = this.lookupTag.toSymbol(session) ?: return createErrorType()
|
val firSymbol = this.lookupTag.toSymbol(session) ?: return createErrorType()
|
||||||
firSymbol.toSymbol(session, classifierStorage, typeContext)
|
firSymbol.toSymbol(session, classifierStorage, typeContext)
|
||||||
}
|
}
|
||||||
|
val typeAnnotations: MutableList<IrConstructorCall> =
|
||||||
|
if (attributes.extensionFunctionType == null) mutableListOf()
|
||||||
|
else mutableListOf(builtIns.extensionFunctionTypeAnnotationConstructorCall())
|
||||||
|
typeAnnotations += with(annotationGenerator) { annotations.toIrAnnotations() }
|
||||||
IrSimpleTypeImpl(
|
IrSimpleTypeImpl(
|
||||||
irSymbol, !typeContext.definitelyNotNull && this.isMarkedNullable,
|
irSymbol, !typeContext.definitelyNotNull && this.isMarkedNullable,
|
||||||
fullyExpandedType(session).typeArguments.map { it.toIrTypeArgument() },
|
fullyExpandedType(session).typeArguments.map { it.toIrTypeArgument() },
|
||||||
annotations = with(annotationGenerator) { annotations.toIrAnnotations() } +
|
typeAnnotations
|
||||||
listOfNotNull(this.attributes.extensionFunctionType?.let { extensionFunctionTypeAnnotationConstructorCall })
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
is ConeFlexibleType -> {
|
is ConeFlexibleType -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user