diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrBuiltIns.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrBuiltIns.kt new file mode 100644 index 00000000000..e1354d046ed --- /dev/null +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrBuiltIns.kt @@ -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().symbol + ) +} \ No newline at end of file diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrComponents.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrComponents.kt index ff431e8235e..9e431117c21 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrComponents.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrComponents.kt @@ -18,6 +18,7 @@ interface Fir2IrComponents { val scopeSession: ScopeSession val symbolTable: SymbolTable val irBuiltIns: IrBuiltIns + val builtIns: Fir2IrBuiltIns val irFactory: IrFactory val classifierStorage: Fir2IrClassifierStorage val declarationStorage: Fir2IrDeclarationStorage diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrComponentsStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrComponentsStorage.kt index 191898d3fbb..f49171a61a2 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrComponentsStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrComponentsStorage.kt @@ -28,6 +28,7 @@ class Fir2IrComponentsStorage( override lateinit var typeConverter: Fir2IrTypeConverter override lateinit var callGenerator: CallAndReferenceGenerator override lateinit var fakeOverrideGenerator: FakeOverrideGenerator + override lateinit var builtIns: Fir2IrBuiltIns override val signatureComposer = FirBasedSignatureComposer(mangler) } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt index 855df290fbc..4bcd16d32f3 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrConverter.kt @@ -215,26 +215,28 @@ class Fir2IrConverter( ) constantValueGenerator.typeTranslator = typeTranslator typeTranslator.constantValueGenerator = constantValueGenerator - val builtIns = IrBuiltIns(moduleDescriptor.builtIns, typeTranslator, symbolTable) - FirBuiltinSymbols(builtIns, moduleDescriptor.builtIns, symbolTable) + val irBuiltIns = IrBuiltIns(moduleDescriptor.builtIns, typeTranslator, symbolTable) + FirBuiltinSymbols(irBuiltIns, moduleDescriptor.builtIns, symbolTable) 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 classifierStorage = Fir2IrClassifierStorage(components) val declarationStorage = Fir2IrDeclarationStorage(components, moduleDescriptor) val typeConverter = Fir2IrTypeConverter(components) + val builtIns = Fir2IrBuiltIns(components, session) components.declarationStorage = declarationStorage components.classifierStorage = classifierStorage components.typeConverter = typeConverter + components.builtIns = builtIns val irFiles = mutableListOf() val converter = Fir2IrConverter(moduleDescriptor, sourceManager, components) for (firFile in firFiles) { irFiles += converter.registerFileAndClasses(firFile) } - val irModuleFragment = IrModuleFragmentImpl(moduleDescriptor, builtIns, irFiles) + val irModuleFragment = IrModuleFragmentImpl(moduleDescriptor, irBuiltIns, irFiles) val irProviders = - generateTypicalIrProviderList(irModuleFragment.descriptor, builtIns, symbolTable, extensions = generatorExtensions) + generateTypicalIrProviderList(irModuleFragment.descriptor, irBuiltIns, symbolTable, extensions = generatorExtensions) val externalDependenciesGenerator = ExternalDependenciesGenerator( symbolTable, irProviders, diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt index 88ad265e64f..e48c1ce6b66 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrTypeConverter.kt @@ -7,24 +7,20 @@ package org.jetbrains.kotlin.fir.backend import org.jetbrains.kotlin.fir.backend.generators.AnnotationGenerator 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.toSymbol import org.jetbrains.kotlin.fir.symbols.StandardClassIds import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.fir.types.impl.* -import org.jetbrains.kotlin.ir.declarations.IrConstructor -import org.jetbrains.kotlin.ir.expressions.impl.IrConstructorCallImpl +import org.jetbrains.kotlin.ir.expressions.IrConstructorCall import org.jetbrains.kotlin.ir.symbols.IrClassSymbol import org.jetbrains.kotlin.ir.types.IrType 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.IrStarProjectionImpl import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.types.Variance -import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstance class Fir2IrTypeConverter( private val components: Fir2IrComponents @@ -62,14 +58,6 @@ class Fir2IrTypeConverter( 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() - IrConstructorCallImpl(0, 0, symbol.defaultType, ctor.symbol, 0, 0, 0) - } - fun FirTypeRef.toIrType(typeContext: ConversionTypeContext = ConversionTypeContext.DEFAULT): IrType { return when (this) { !is FirResolvedTypeRef -> createErrorType() @@ -98,11 +86,14 @@ class Fir2IrTypeConverter( val firSymbol = this.lookupTag.toSymbol(session) ?: return createErrorType() firSymbol.toSymbol(session, classifierStorage, typeContext) } + val typeAnnotations: MutableList = + if (attributes.extensionFunctionType == null) mutableListOf() + else mutableListOf(builtIns.extensionFunctionTypeAnnotationConstructorCall()) + typeAnnotations += with(annotationGenerator) { annotations.toIrAnnotations() } IrSimpleTypeImpl( irSymbol, !typeContext.definitelyNotNull && this.isMarkedNullable, fullyExpandedType(session).typeArguments.map { it.toIrTypeArgument() }, - annotations = with(annotationGenerator) { annotations.toIrAnnotations() } + - listOfNotNull(this.attributes.extensionFunctionType?.let { extensionFunctionTypeAnnotationConstructorCall }) + typeAnnotations ) } is ConeFlexibleType -> {