Fir2Ir: add Fir2IrTypeParametersContainer
Fir2IrLazyProperty should not be a IrTypeParametersContainer.
This commit is contained in:
committed by
Alexander Udalov
parent
4b34648327
commit
f94b0bbcea
@@ -1354,8 +1354,6 @@ class Fir2IrDeclarationStorage(
|
||||
}
|
||||
}
|
||||
propertyCache[fir] = irProperty
|
||||
// NB: this is needed to prevent recursions in case of self bounds
|
||||
(irProperty as Fir2IrLazyProperty).prepareTypeParameters()
|
||||
return irProperty
|
||||
}
|
||||
|
||||
|
||||
+1
-18
@@ -7,14 +7,11 @@ package org.jetbrains.kotlin.fir.lazy
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirAnnotationContainer
|
||||
import org.jetbrains.kotlin.fir.backend.Fir2IrComponents
|
||||
import org.jetbrains.kotlin.fir.backend.toIrType
|
||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||
import org.jetbrains.kotlin.fir.symbols.Fir2IrBindableSymbol
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclaration
|
||||
import org.jetbrains.kotlin.ir.declarations.IrDeclarationParent
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFactory
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParameter
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.IrLazyDeclarationBase
|
||||
import org.jetbrains.kotlin.ir.declarations.lazy.lazyVar
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
@@ -23,7 +20,7 @@ import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||
import kotlin.properties.ReadWriteProperty
|
||||
|
||||
interface AbstractFir2IrLazyDeclaration<F, D : IrDeclaration> :
|
||||
IrDeclaration, IrDeclarationParent, IrLazyDeclarationBase, Fir2IrComponents where F : FirMemberDeclaration, F : FirAnnotationContainer {
|
||||
IrDeclaration, IrLazyDeclarationBase, Fir2IrComponents where F : FirMemberDeclaration, F : FirAnnotationContainer {
|
||||
|
||||
val fir: F
|
||||
override val symbol: Fir2IrBindableSymbol<*, D>
|
||||
@@ -31,20 +28,6 @@ interface AbstractFir2IrLazyDeclaration<F, D : IrDeclaration> :
|
||||
override val factory: IrFactory
|
||||
get() = irFactory
|
||||
|
||||
var typeParameters: List<IrTypeParameter>
|
||||
|
||||
fun prepareTypeParameters() {
|
||||
typeParameters = fir.typeParameters.mapIndexedNotNull { index, typeParameter ->
|
||||
if (typeParameter !is FirTypeParameter) return@mapIndexedNotNull null
|
||||
classifierStorage.getIrTypeParameter(typeParameter, index).apply {
|
||||
parent = this@AbstractFir2IrLazyDeclaration
|
||||
if (superTypes.isEmpty()) {
|
||||
superTypes = typeParameter.bounds.map { it.toIrType(typeConverter) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun createLazyAnnotations(): ReadWriteProperty<Any?, List<IrConstructorCall>> = lazyVar(lock) {
|
||||
fir.annotations.mapNotNull {
|
||||
callGenerator.convertToIrConstructorCall(it) as? IrConstructorCall
|
||||
|
||||
@@ -22,8 +22,6 @@ import org.jetbrains.kotlin.ir.expressions.IrBody
|
||||
import org.jetbrains.kotlin.ir.expressions.IrConstructorCall
|
||||
import org.jetbrains.kotlin.ir.symbols.IrPropertySymbol
|
||||
import org.jetbrains.kotlin.ir.types.IrType
|
||||
import org.jetbrains.kotlin.ir.util.DeclarationStubGenerator
|
||||
import org.jetbrains.kotlin.ir.util.TypeTranslator
|
||||
import org.jetbrains.kotlin.ir.util.isFacadeClass
|
||||
import org.jetbrains.kotlin.ir.util.isObject
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -37,7 +35,8 @@ abstract class AbstractFir2IrLazyFunction<F : FirCallableDeclaration>(
|
||||
override var origin: IrDeclarationOrigin,
|
||||
override val symbol: Fir2IrSimpleFunctionSymbol,
|
||||
override val isFakeOverride: Boolean
|
||||
) : IrSimpleFunction(), AbstractFir2IrLazyDeclaration<F, IrSimpleFunction>, IrLazyFunctionBase, Fir2IrComponents by components {
|
||||
) : IrSimpleFunction(), AbstractFir2IrLazyDeclaration<F, IrSimpleFunction>, Fir2IrTypeParametersContainer, IrLazyFunctionBase,
|
||||
Fir2IrComponents by components {
|
||||
|
||||
override lateinit var typeParameters: List<IrTypeParameter>
|
||||
override lateinit var parent: IrDeclarationParent
|
||||
|
||||
@@ -41,7 +41,7 @@ class Fir2IrLazyClass(
|
||||
override var origin: IrDeclarationOrigin,
|
||||
override val fir: FirRegularClass,
|
||||
override val symbol: Fir2IrClassSymbol,
|
||||
) : IrClass(), AbstractFir2IrLazyDeclaration<FirRegularClass, IrClass>,
|
||||
) : IrClass(), AbstractFir2IrLazyDeclaration<FirRegularClass, IrClass>, Fir2IrTypeParametersContainer,
|
||||
IrMaybeDeserializedClass, DeserializableClass, Fir2IrComponents by components {
|
||||
init {
|
||||
symbol.bind(this)
|
||||
|
||||
@@ -35,7 +35,8 @@ class Fir2IrLazyConstructor(
|
||||
override var origin: IrDeclarationOrigin,
|
||||
override val fir: FirConstructor,
|
||||
override val symbol: Fir2IrConstructorSymbol,
|
||||
) : IrConstructor(), AbstractFir2IrLazyDeclaration<FirConstructor, IrConstructor>, Fir2IrComponents by components {
|
||||
) : IrConstructor(), AbstractFir2IrLazyDeclaration<FirConstructor, IrConstructor>, Fir2IrTypeParametersContainer,
|
||||
Fir2IrComponents by components {
|
||||
init {
|
||||
symbol.bind(this)
|
||||
classifierStorage.preCacheTypeParameters(fir)
|
||||
|
||||
@@ -49,7 +49,6 @@ class Fir2IrLazyProperty(
|
||||
}
|
||||
|
||||
override var annotations: List<IrConstructorCall> by createLazyAnnotations()
|
||||
override var typeParameters: List<IrTypeParameter> = emptyList()
|
||||
override lateinit var parent: IrDeclarationParent
|
||||
|
||||
@ObsoleteDescriptorBasedAPI
|
||||
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2010-2022 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.lazy
|
||||
|
||||
import org.jetbrains.kotlin.fir.backend.Fir2IrComponents
|
||||
import org.jetbrains.kotlin.fir.backend.toIrType
|
||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||
import org.jetbrains.kotlin.ir.declarations.IrTypeParametersContainer
|
||||
|
||||
interface Fir2IrTypeParametersContainer : IrTypeParametersContainer, Fir2IrComponents {
|
||||
val fir: FirMemberDeclaration
|
||||
|
||||
fun prepareTypeParameters() {
|
||||
typeParameters = fir.typeParameters.mapIndexedNotNull { index, typeParameter ->
|
||||
if (typeParameter !is FirTypeParameter) return@mapIndexedNotNull null
|
||||
classifierStorage.getIrTypeParameter(typeParameter, index).apply {
|
||||
parent = this@Fir2IrTypeParametersContainer
|
||||
if (superTypes.isEmpty()) {
|
||||
superTypes = typeParameter.bounds.map { it.toIrType(typeConverter) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user